-
Notifications
You must be signed in to change notification settings - Fork 0
/
oik-themer.php
206 lines (181 loc) · 5.59 KB
/
oik-themer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?php
/**
* @copyright (C) Copyright Bobbing Wide 2021, 2022
* @package oik-update
*/
/**
* oik batch process to improve the registration of FSE themes listed in blocks.wp-a2z.org
* Syntax: oikwp oik-themer.php [theme] [version|n]
*
* eg
* Update or create a theme called slug. Version 'n' means to use the currently installed version of the theme.
* Should work for both themes from wordpress.org and locally installed Git repos
*
* oikwp oik-themer.php slug n url=blocks.wp.a2z
*
* Update all FSE ( block based ) themes registered in wordpress.org
*
* oikwp oik-themer.php url=blocks.wp.a2z
*
*/
if ( PHP_SAPI !== 'cli' ) {
die();
}
/**
* Manual process.
*
* [ ] 1. Download theme to \apache\htdocs\downloads\themes
* [ ] 2. Run 7-zip to open the .zip file and extract to WP_THEMES_DIR
* [ ] 3. Determine the theme's fields - fetch theme info using WordPress API
* [ ] 4. Create / update the oik-theme
* [ ] 5. Set featured image to screenshot
* [ ] 6. Find patterns folder
* [ ] 7. Test everything's OK
* [ ] 8. Clone oik-theme to blocks.wp-a2z.org
* [ ] 9. Install theme on wp-a2z.org
*/
function oik_themer_autoload() {
$autloaded = false;
$lib_autoload = oik_require_lib( "oik-autoload" );
if ( $lib_autoload && !is_wp_error( $lib_autoload ) ) {
add_filter( "oik_query_autoload_classes" , "oik_themer_query_autoload_classes" );
oik_autoload();
$autoloaded = true;
} else {
bw_trace2( $lib_autoload, "oik-autoload not loaded", false );
}
return $autoloaded;
}
function oik_themer_query_autoload_classes( $classes ) {
$classes[] = array( "class" => "OIK_themer"
, "plugin" => "oik-update"
, "path" => "classes"
, 'file' => 'classes/class-OIK-themer.php'
);
$classes[] = array( 'class' => 'OIK_wp_a2z'
, 'plugin' => 'oik-update'
, 'path' => 'classes'
, 'file' => 'classes/class-OIK-wp-a2z.php'
);
$classes[] = array( "class" => "Git" ,
"plugin" => "oik-batch",
"path" => "includes",
"file" => "includes/class-git.php"
);
$classes[] = array( 'class' => 'WP_org_v12_downloads',
'plugin' => 'wp-top12',
'path' => null,
'file' => 'class-wp-org-v12-downloads.php'
);
$classes[] = array( 'class' => 'oik_remote',
'plugin' => 'oik',
'path' => 'libs',
'file' => 'libs/class-oik-remote.php'
);
$classes[] = array( 'class' => 'OIK_block_updater'
, 'plugin' => 'oik-update'
, 'path' => 'classes'
, 'file' => 'classes/class-OIK-block-updater.php'
);
$classes[] = array( "class" => "OIK_component_update"
, "plugin" => "oik-update"
, "path" => "classes"
, 'file' => 'classes/class-OIK-component-update.php'
);
$classes[] = array( "class" => "WP_org_downloads_themes"
, "plugin" => "wp-top12"
, "path" => "libs"
, 'file' => 'libs/class-wp-org-downloads-themes.php'
);
return( $classes );
}
/**
* Checks if the component is a Git repository.
*
* @param string $component the name of the component ( plugin ).
* @return bool true if it's a Git repository
*
*/
function oik_themer_component_is_git_repo( $component ) {
// oik_path assumes it's a plugin!
//$path = oik_path( null, $component );
//$path = untrailingslashit( $path );
$path = get_theme_root() . '/' . $component;
echo $path;
$git = new Git();
$has_dot_git = $git->has_dot_git( $path );
$is_git_repo = $has_dot_git !== null;
return $is_git_repo;
}
/**
* Updates a single theme or does the lot.
*/
function oik_themer() {
$autoloaded = oik_themer_autoload();
if ( $autoloaded ) {
$oik_themer = new OIK_themer();
$component = oik_batch_query_value_from_argv( 1, 'unknown' );
$new_version = oik_batch_query_value_from_argv( 2, '');
if ( $component !== 'unknown') {
oik_themer_update_component_version( $oik_themer, $component, $new_version );
} else {
oik_themer_update_components_that_need_it( $oik_themer );
}
} else {
echo "oik-autoload not available";
}
}
function oik_themer_update_component_version( $oik_themer, $component, $new_version ) {
//echo $component;
//echo $new_version;
//$component_type = oik_batch_query_value_from_argv( 3, 'plugin' );
$oik_themer->set_component( $component );
$oik_themer->get_theme_info();
// $oik_blocker->set_component_type( $component_type );
// Don't update the plugin if it's a git repo.
// Don't update the plugin if new version is 'n'
if ( false === oik_themer_component_is_git_repo( $component )) {
if ( 'n' !== $new_version ) {
//$oik_themer->perform_update();
$oik_themer->download_theme_version();
} else {
gob();
}
} else {
echo "Component is a Git repo: " . $component . PHP_EOL;
}
$oik_themer->update_oik_theme();
$oik_themer->preview_theme();
}
/**
* Processes all themes that have updates available.
*
*/
function oik_themer_update_components_that_need_it( $oik_themer ) {
$wpodt = new WP_org_downloads_themes();
if ( null === $wpodt ) {
gob();
}
$wpodt->maybe_query_all_themes();
$wpodt->load_all_themes();
$themes = $wpodt->get_fse_themes();
//print_r( $themes );
if ( $themes && count( $themes )) {
foreach ( $themes as $theme => $theme_info ) {
echo $theme;
// Only update themes which have new versions.
//
$new_version = $oik_themer->is_new_version( $theme_info );
if ( $new_version ) {
echo " ";
echo $new_version;
echo PHP_EOL;
//$new_version = $theme_info->version;
oik_themer_update_component_version( $oik_themer, $theme, $new_version );
} else {
echo PHP_EOL;
}
}
}
}
oik_themer();