11<?php
2-
32namespace Cbx \Careertoolkit ;
43
5- class PDUpdater {
4+ class PDUpdater
5+ {
66 private $ file ;
77 private $ plugin ;
88 private $ basename ;
@@ -12,131 +12,142 @@ class PDUpdater {
1212 private $ authorize_token ;
1313 private $ github_response ;
1414
15- public function __construct ( $ file ) {
15+ public function __construct ($ file )
16+ {
1617 $ this ->file = $ file ;
17- add_action ( 'admin_init ' , [ $ this , 'set_plugin_properties ' ] );
18+ add_action ('admin_init ' , [$ this , 'set_plugin_properties ' ] );
1819
1920 return $ this ;
2021 }
2122
22- public function set_plugin_properties () {
23- $ this ->plugin = get_plugin_data ( $ this ->file );
24- $ this ->basename = plugin_basename ( $ this ->file );
25- $ this ->active = is_plugin_active ( $ this ->basename );
23+ public function set_plugin_properties ()
24+ {
25+ $ this ->plugin = get_plugin_data ($ this ->file );
26+ $ this ->basename = plugin_basename ($ this ->file );
27+ $ this ->active = is_plugin_active ($ this ->basename );
2628 }
2729
28- public function set_username ( $ username ) {
30+ public function set_username ($ username )
31+ {
2932 $ this ->username = $ username ;
3033 }
3134
32- public function set_repository ( $ repository ) {
35+ public function set_repository ($ repository )
36+ {
3337 $ this ->repository = $ repository ;
3438 }
3539
36- public function authorize ( $ token ) {
40+ public function authorize ($ token )
41+ {
3742 $ this ->authorize_token = $ token ;
3843 }
3944
40- private function get_repository_info () {
41- if ( is_null ( $ this ->github_response ) ) {
42- $ request_uri = sprintf ( 'https://api.github.com/repos/%s/%s/releases ' , $ this ->username , $ this ->repository );
45+ private function get_repository_info ()
46+ {
47+ if (is_null ($ this ->github_response )) {
48+ $ request_uri = sprintf ('https://api.github.com/repos/%s/%s/releases ' , $ this ->username , $ this ->repository );
4349
4450 // Switch to HTTP Basic Authentication for GitHub API v3
4551 $ curl = curl_init ();
4652
47- curl_setopt_array ( $ curl , [
48- CURLOPT_URL => $ request_uri ,
53+ curl_setopt_array ($ curl , [
54+ CURLOPT_URL => $ request_uri ,
4955 CURLOPT_RETURNTRANSFER => true ,
50- CURLOPT_ENCODING => "" ,
51- CURLOPT_MAXREDIRS => 10 ,
52- CURLOPT_TIMEOUT => 0 ,
56+ CURLOPT_ENCODING => "" ,
57+ CURLOPT_MAXREDIRS => 10 ,
58+ CURLOPT_TIMEOUT => 0 ,
5359 CURLOPT_FOLLOWLOCATION => true ,
54- CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1 ,
55- CURLOPT_CUSTOMREQUEST => "GET " ,
56- CURLOPT_HTTPHEADER => [
60+ CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1 ,
61+ CURLOPT_CUSTOMREQUEST => "GET " ,
62+ CURLOPT_HTTPHEADER => [
5763 "Authorization: token " . $ this ->authorize_token ,
5864 "User-Agent: PDUpdater/1.2.3 "
5965 ]
60- ] );
66+ ]);
6167
62- $ response = curl_exec ( $ curl );
68+ $ response = curl_exec ($ curl );
6369
64- //print_r($response);
65- //exit;
70+ // print_r($response);
71+ // exit;
6672
67- curl_close ( $ curl );
73+ curl_close ($ curl );
6874
69- $ response = json_decode ( $ response , true );
75+ $ response = json_decode ($ response , true );
7076
71- if ( is_array ( $ response ) ) {
72- $ response = current ( $ response );
77+ if (is_array ($ response) ) {
78+ $ response = current ($ response );
7379 }
7480
75- if ( $ this ->authorize_token ) {
76- $ response ['zipball_url ' ] = add_query_arg ( 'access_token ' , $ this ->authorize_token , $ response ['zipball_url ' ] );
81+ if ($ this ->authorize_token ) {
82+ $ response ['zipball_url ' ] = add_query_arg ('access_token ' , $ this ->authorize_token , $ response ['zipball_url ' ]);
7783 }
7884
7985 $ this ->github_response = $ response ;
8086 }
8187 }
8288
83- public function initialize () {
84- add_filter ( 'pre_set_site_transient_update_plugins ' , [ $ this , 'modify_transient ' ], 10 , 1 );
85- add_filter ( 'plugins_api ' , [ $ this , 'plugin_popup ' ], 10 , 3 );
86- add_filter ( 'upgrader_post_install ' , [ $ this , 'after_install ' ], 10 , 3 );
89+ public function initialize ()
90+ {
91+
92+ add_filter ('pre_set_site_transient_update_plugins ' , [$ this , 'modify_transient ' ], 10 , 1 );
93+ add_filter ('plugins_api ' , [$ this , 'plugin_popup ' ], 10 , 3 );
94+ add_filter ('upgrader_post_install ' , [$ this , 'after_install ' ], 10 , 3 );
8795 }
8896
89- public function modify_transient ( $ transient ) {
90- if ( property_exists ( $ transient , 'checked ' ) ) {
91- if ( $ checked = $ transient ->checked ) {
97+ public function modify_transient ($ transient )
98+ {
99+ if (property_exists ($ transient , 'checked ' )) {
100+ if ($ checked = $ transient ->checked ) {
92101 $ this ->get_repository_info ();
93-
94- $ out_of_date = version_compare ( $ this ->github_response ['tag_name ' ], $ checked [ $ this ->basename ], 'gt ' );
95-
96- if ( $ out_of_date ) {
102+ write_log (str_replace ("v " , "" , $ this ->github_response ['tag_name ' ]));
103+ write_log ($ checked [$ this ->basename ]);
104+ $ out_of_date = version_compare (str_replace ("v " , "" , $ this ->github_response ['tag_name ' ]), $ checked [$ this ->basename ], 'gt ' );
105+ write_log ($ out_of_date );
106+ if ($ out_of_date ) {
97107 $ new_files = $ this ->github_response ['zipball_url ' ];
98- $ slug = current ( explode ( '/ ' , $ this ->basename ) );
108+ $ slug = current (explode ('/ ' , $ this ->basename ) );
99109
100110 $ plugin = [
101- 'url ' => $ this ->plugin ['PluginURI ' ],
102- 'slug ' => $ slug ,
103- 'package ' => $ new_files ,
111+ 'url ' => $ this ->plugin ['PluginURI ' ],
112+ 'slug ' => $ slug ,
113+ 'package ' => $ new_files ,
104114 'new_version ' => $ this ->github_response ['tag_name ' ]
105115 ];
106116
107- $ transient ->response [ $ this ->basename ] = (object ) $ plugin ;
117+ $ transient ->response [$ this ->basename ] = (object ) $ plugin ;
108118 }
109119 }
110120 }
111121
112122 return $ transient ;
113123 }
114124
115- public function plugin_popup ( $ result , $ action , $ args ) {
116- if ( $ action !== 'plugin_information ' ) {
125+ public function plugin_popup ($ result , $ action , $ args )
126+ {
127+ if ($ action !== 'plugin_information ' ) {
117128 return false ;
118129 }
119130
120- if ( ! empty ( $ args ->slug ) ) {
121- if ( $ args ->slug == current ( explode ( '/ ' , $ this ->basename ) ) ) {
131+ if (! empty ($ args ->slug ) ) {
132+ if ($ args ->slug == current (explode ('/ ' , $ this ->basename )) ) {
122133 $ this ->get_repository_info ();
123134
124135 $ plugin = [
125- 'name ' => $ this ->plugin ['Name ' ],
126- 'slug ' => $ this ->basename ,
127- 'requires ' => '5.3 ' ,
128- 'tested ' => '5.4 ' ,
129- 'version ' => $ this ->github_response ['tag_name ' ],
130- 'author ' => $ this ->plugin ['AuthorName ' ],
131- 'author_profile ' => $ this ->plugin ['AuthorURI ' ],
132- 'last_updated ' => $ this ->github_response ['published_at ' ],
133- 'homepage ' => $ this ->plugin ['PluginURI ' ],
136+ 'name ' => $ this ->plugin ['Name ' ],
137+ 'slug ' => $ this ->basename ,
138+ 'requires ' => '5.3 ' ,
139+ 'tested ' => '5.4 ' ,
140+ 'version ' => $ this ->github_response ['tag_name ' ],
141+ 'author ' => $ this ->plugin ['AuthorName ' ],
142+ 'author_profile ' => $ this ->plugin ['AuthorURI ' ],
143+ 'last_updated ' => $ this ->github_response ['published_at ' ],
144+ 'homepage ' => $ this ->plugin ['PluginURI ' ],
134145 'short_description ' => $ this ->plugin ['Description ' ],
135- 'sections ' => [
146+ 'sections ' => [
136147 'Description ' => $ this ->plugin ['Description ' ],
137- 'Updates ' => $ this ->github_response ['body ' ],
148+ 'Updates ' => $ this ->github_response ['body ' ],
138149 ],
139- 'download_link ' => $ this ->github_response ['zipball_url ' ]
150+ 'download_link ' => $ this ->github_response ['zipball_url ' ]
140151 ];
141152
142153 return (object ) $ plugin ;
@@ -146,15 +157,16 @@ public function plugin_popup( $result, $action, $args ) {
146157 return $ result ;
147158 }
148159
149- public function after_install ( $ response , $ hook_extra , $ result ) {
160+ public function after_install ($ response , $ hook_extra , $ result )
161+ {
150162 global $ wp_filesystem ;
151163
152- $ install_directory = plugin_dir_path ( $ this ->file );
153- $ wp_filesystem ->move ( $ result ['destination ' ], $ install_directory );
164+ $ install_directory = plugin_dir_path ($ this ->file );
165+ $ wp_filesystem ->move ($ result ['destination ' ], $ install_directory );
154166 $ result ['destination ' ] = $ install_directory ;
155167
156- if ( $ this ->active ) {
157- activate_plugin ( $ this ->basename );
168+ if ($ this ->active ) {
169+ activate_plugin ($ this ->basename );
158170 }
159171
160172 return $ result ;
0 commit comments