@@ -181,7 +181,7 @@ public function getBibleBookNamesInLang($lang = null)
181
181
if ($ lang === null ) {
182
182
$ lang = $ this ->locale ;
183
183
}
184
- if (strlen ($ lang ) == 2 ) {
184
+ if (strlen ($ lang ) === 2 ) {
185
185
//we have a two-letter ISO code, we need to get the full language name in English
186
186
if (extension_loaded ('intl ' ) === true ) {
187
187
$ lang = Locale::getDisplayLanguage ($ lang , "en " );
@@ -264,7 +264,7 @@ public function register_settings()
264
264
265
265
public function admin_print_styles ($ hook )
266
266
{
267
- if ($ hook == 'settings_page_bibleget-settings-admin ' ) {
267
+ if ($ hook === 'settings_page_bibleget-settings-admin ' ) {
268
268
wp_enqueue_style ('admin-css ' , plugins_url ('../css/admin.css ' , __FILE__ ));
269
269
}
270
270
}
@@ -288,35 +288,40 @@ public function admin_print_scripts($hook)
288
288
wp_localize_script ('admin-js ' , 'bibleGetOptionsFromServer ' , $ obj );
289
289
wp_enqueue_script ('admin-js ' );
290
290
291
- if ($ this ->gfontsAPIkeyCheckResult == "SUCCESS " ) {
291
+ if ($ this ->gfontsAPIkeyCheckResult === "SUCCESS " ) {
292
292
//We only want the transient to be set from the bibleget settings page, so we wait until now
293
293
// instead of doing it in the gfontsAPIkeyCheck (which is called on any admin interface)
294
294
set_transient (md5 ($ this ->options ['googlefontsapi_key ' ]), $ this ->gfontsAPIkeyCheckResult , 90 * 24 * HOUR_IN_SECONDS ); // 90 giorni
295
295
296
- $ plugin_path = "" ;
297
296
// bibleGetWriteLog("about to initialize creation of admin page...");
298
297
if (get_filesystem_method () === 'direct ' ) {
299
- $ creds = request_filesystem_credentials (site_url () . '/wp-admin/ ' , '' , false , false , array ());
298
+ $ gfontsDir = str_replace ('\\' ,'/ ' , wp_upload_dir ()["basedir " ] ) . "/gfonts_preview/ " ;
299
+ $ creds = request_filesystem_credentials (site_url () . '/wp-admin/ ' , '' , false , false , array ());
300
300
/* initialize the API */
301
301
if (WP_Filesystem ($ creds )) {
302
302
global $ wp_filesystem ;
303
- $ plugin_path = str_replace ('\\' ,'/ ' , plugin_dir_path ( __FILE__ ) );
304
- if (!$ wp_filesystem ->is_dir ($ plugin_path . '../gfonts_preview/ ' )) {
303
+ if (!$ wp_filesystem ->is_dir ($ gfontsDir )) {
305
304
/* directory didn't exist, so let's create it */
306
- if ($ wp_filesystem ->mkdir ($ plugin_path . ' ../gfonts_preview/ ' ) === false ) {
305
+ if ($ wp_filesystem ->mkdir ($ gfontsDir ) === false ) {
307
306
$ this ->gfontsAPI_errors [] = "Could not create directory gfonts_preview " ;
308
- }
309
- }
310
- if (!$ wp_filesystem ->is_dir ($ plugin_path . '../css/gfonts_preview/ ' )) {
311
- /* directory didn't exist, so let's create it */
312
- if ($ wp_filesystem ->mkdir ($ plugin_path . '../css/gfonts_preview/ ' ) === false ) {
313
- $ this ->gfontsAPI_errors [] = "Could not create directory css/gfonts_preview " ;
307
+ } else {
308
+ //let's make sure the necessary subfolders are also created
309
+ if (!$ wp_filesystem ->is_dir ($ gfontsDir . "ttf/ " )) {
310
+ if ( $ wp_filesystem ->mkdir ($ gfontsDir . "ttf/ " ) === false ) {
311
+ $ this ->gfontsAPI_errors [] = "Could not create directory gfonts_preview/ttf " ;
312
+ }
313
+ }
314
+ if (!$ wp_filesystem ->is_dir ($ gfontsDir . "css/ " )) {
315
+ if ( $ wp_filesystem ->mkdir ($ gfontsDir . "css/ " ) === false ) {
316
+ $ this ->gfontsAPI_errors [] = "Could not create directory gfonts_preview/css " ;
317
+ }
318
+ }
314
319
}
315
320
}
316
321
317
322
//let's also cache the results from the Google Fonts API in a local file so we don't have to keep calling
318
323
if ($ wp_filesystem ->put_contents (
319
- $ plugin_path . '../gfonts_preview/ gfontsWeblist.json ' ,
324
+ $ gfontsDir . 'gfontsWeblist.json ' ,
320
325
json_encode ($ this ->gfonts_weblist ),
321
326
FS_CHMOD_FILE // predefined mode settings for WP files
322
327
) === false ) {
@@ -329,7 +334,19 @@ public function admin_print_scripts($hook)
329
334
$ this ->gfontsAPI_errors [] = "You do not have direct access permissions to the wordpress filesystem " ;
330
335
}
331
336
if (count ($ this ->gfontsAPI_errors ) > 0 ){
332
- add_action ( 'admin_notices ' , function (){ printf ( '<div class="%1$s"><p>%2$s</p></div> ' , esc_attr ( 'notice notice-error ' ), esc_html ( __ ( 'Impossible to write data to the BibleGet plugin directory, please check permissions! ' , 'bibleget-io ' ) ) ); } );
337
+ add_action (
338
+ 'admin_notices ' ,
339
+ function (){
340
+ printf (
341
+ '<div class="%1$s"><p>%2$s</p></div> ' ,
342
+ esc_attr ( 'notice notice-error ' ),
343
+ esc_html (
344
+ __ ( 'Impossible to write data to the BibleGet plugin directory, please check permissions! ' , 'bibleget-io ' )
345
+ . "\n" . implode ("\n" ,$ this ->gfontsAPI_errors )
346
+ )
347
+ );
348
+ }
349
+ );
333
350
}
334
351
wp_enqueue_script ('jquery-ui-progressbar ' );
335
352
if (!wp_style_is ('jquery-ui-css ' , 'registered ' ) || !wp_style_is ('jquery-ui-css ' , 'enqueued ' )) {
@@ -570,7 +587,7 @@ public function googlefontsapikey_callback()
570
587
/* translators: refers to the outcome of the validity check of the Google Fonts API key */
571
588
echo '<span style="color:DarkViolet;font-weight:bold;margin-left:12px;"> ' . __ ("CURL ERROR WHEN SENDING REQUEST " , "bibleget-io " ) . '</span><br /> ' ;
572
589
foreach ($ this ->gfontsAPI_errors as $ er ) {
573
- if ($ er == 403 ) {
590
+ if ($ er === 403 ) {
574
591
echo '<br /><i style="color:DarkViolet;margin-left:12px;"> ' ;
575
592
echo __ ("This server's IP address has not been given access to the Google Fonts API using this key. " , "bibleget-io " );
576
593
echo " " . __ ("Please verify that access has been given to the correct IP addresses. " , "bibleget-io " );
@@ -658,12 +675,12 @@ public function gfontsAPIkeyCheck() {
658
675
}
659
676
$ response = curl_exec ($ ch );
660
677
$ status = (int ) curl_getinfo ($ ch , CURLINFO_HTTP_CODE );
661
- if ($ response && !curl_errno ($ ch ) && $ status == 200 ) {
678
+ if ($ response && !curl_errno ($ ch ) && $ status === 200 ) {
662
679
//let's see what was returned, and if it's what we're looking for
663
680
$ json_response = json_decode ($ response );
664
681
if ($ json_response !== null && json_last_error () === JSON_ERROR_NONE ) {
665
682
//So far so good, let's keep these results for other functions to access
666
- if (property_exists ($ json_response , "kind " ) && $ json_response ->kind == "webfonts#webfontList " && property_exists ($ json_response , "items " )) {
683
+ if (property_exists ($ json_response , "kind " ) && $ json_response ->kind === "webfonts#webfontList " && property_exists ($ json_response , "items " )) {
667
684
$ this ->gfonts_weblist = $ json_response ;
668
685
$ result = "SUCCESS " ;
669
686
}
@@ -679,7 +696,7 @@ public function gfontsAPIkeyCheck() {
679
696
$ this ->gfontsAPI_errors [] = curl_error ($ ch );
680
697
}
681
698
if ($ status != 200 ) {
682
- if ($ status == 403 ) {
699
+ if ($ status === 403 ) {
683
700
$ this ->gfontsAPI_errors [] = $ status ;
684
701
} else {
685
702
/* translators: refers to the status of the http response during communication with the Google Fonts API */
@@ -722,17 +739,25 @@ public function store_gfonts_preview()
722
739
$ familyurlname = "" ;
723
740
$ familyfilename = "" ;
724
741
$ errorinfo = [];
725
- $ gfontsDir = str_replace ('\\' ,'/ ' , plugin_dir_path ( __FILE__ ) ) . "../gfonts_preview/ " ;
742
+ $ gfontsDir = str_replace ('\\' ,'/ ' , wp_upload_dir ()["basedir " ] ) . "/gfonts_preview/ " ;
743
+ $ gfontsWeblistFile = $ gfontsDir . "gfontsWeblist.json " ;
726
744
$ gfontsWeblist = new stdClass ();
727
745
$ returnInfo = new stdClass ();
728
746
729
- if (file_exists ($ gfontsDir . " gfontsWeblist.json " )) {
730
- $ gfontsWeblistFile = file_get_contents ($ gfontsDir . " gfontsWeblist.json " );
731
- $ gfontsWeblist = json_decode ($ gfontsWeblistFile );
747
+ if (file_exists ($ gfontsWeblistFile )) {
748
+ $ gfontsWeblistFileContents = file_get_contents ($ gfontsWeblistFile );
749
+ $ gfontsWeblist = json_decode ($ gfontsWeblistFileContents );
732
750
}
733
751
if (
734
- isset ($ _POST ["gfontsCount " ], $ _POST ["batchLimit " ], $ _POST ["startIdx " ], $ _POST ["lastBatchLimit " ], $ _POST ["numRuns " ], $ _POST ["currentRun " ])
735
- && property_exists ($ gfontsWeblist , "items " )) {
752
+ isset (
753
+ $ _POST ["gfontsCount " ],
754
+ $ _POST ["batchLimit " ],
755
+ $ _POST ["startIdx " ],
756
+ $ _POST ["lastBatchLimit " ],
757
+ $ _POST ["numRuns " ],
758
+ $ _POST ["currentRun " ]
759
+ ) && property_exists ($ gfontsWeblist , "items " ))
760
+ {
736
761
//$gfontsCount = intval($_POST["gfontsCount"]);
737
762
$ batchLimit = intval ($ _POST ["batchLimit " ]);
738
763
$ startIdx = intval ($ _POST ["startIdx " ]);
@@ -747,13 +772,11 @@ public function store_gfonts_preview()
747
772
wp_die ();
748
773
}
749
774
750
- $ plugin_path = "" ;
751
775
if (get_filesystem_method () === 'direct ' ) {
752
776
$ creds = request_filesystem_credentials (site_url () . '/wp-admin/ ' , '' , false , false , array ());
753
777
/* initialize the API */
754
778
if (WP_Filesystem ($ creds )) {
755
779
global $ wp_filesystem ;
756
- $ plugin_path = str_replace ('\\' ,'/ ' , plugin_dir_path ( __FILE__ ) );
757
780
758
781
foreach ($ gfontsWeblist ->items as $ idx => $ googlefont ) {
759
782
if ($ idx >= $ startIdx && $ idx < ($ startIdx + $ batchLimit )) {
@@ -763,7 +786,7 @@ public function store_gfonts_preview()
763
786
$ errorinfo [] = "Now dealing with font-family " . $ thisfamily ;
764
787
$ fnttype = 'ttf ' ; //'woff', 'woff2', 'ttf'
765
788
766
- if (!file_exists ($ gfontsDir . "{$ familyfilename }. {$ fnttype }" )) { //$idx < $idxlimit &&
789
+ if (!file_exists ($ gfontsDir . "ttf/ {$ familyfilename }. {$ fnttype }" )) { //$idx < $idxlimit &&
767
790
$ ch2 = curl_init ("https://fonts.googleapis.com/css2?family= {$ familyurlname }&text= {$ familyfilename }" );
768
791
curl_setopt ($ ch2 , CURLOPT_SSL_VERIFYPEER , TRUE );
769
792
curl_setopt ($ ch2 , CURLOPT_SSL_VERIFYHOST , 2 );
@@ -779,12 +802,12 @@ public function store_gfonts_preview()
779
802
$ response2 = curl_exec ($ ch2 );
780
803
$ status2 = (int ) curl_getinfo ($ ch2 , CURLINFO_HTTP_CODE );
781
804
$ returnInfo ->httpStatus2 = $ status2 ;
782
- if ($ response2 && !curl_errno ($ ch2 ) && $ status2 == 200 ) {
783
- if (preg_match ('/url\((.*?)\)/ ' , $ response2 , $ match ) == 1 ) {
805
+ if ($ response2 && !curl_errno ($ ch2 ) && $ status2 === 200 ) {
806
+ if (preg_match ('/url\((.*?)\)/ ' , $ response2 , $ match ) === 1 ) {
784
807
$ thisfonturl = $ match [1 ];
785
808
$ errorinfo [] = "font retrieval url for {$ thisfamily } = {$ thisfonturl }" ;
786
809
787
- // $ch3_headers = [];
810
+ //$ch3_headers = [];
788
811
$ ch3 = curl_init ($ thisfonturl );
789
812
curl_setopt ($ ch3 , CURLOPT_SSL_VERIFYPEER , TRUE );
790
813
curl_setopt ($ ch3 , CURLOPT_SSL_VERIFYHOST , 2 );
@@ -801,27 +824,28 @@ public function store_gfonts_preview()
801
824
curl_setopt ($ ch3 , CURLOPT_AUTOREFERER , TRUE );
802
825
}
803
826
$ response3 = curl_exec ($ ch3 );
804
- // $errorinfo[] = print_r($ch3_headers,TRUE);
827
+ //$errorinfo[] = print_r($ch3_headers,TRUE);
805
828
$ status3 = (int ) curl_getinfo ($ ch3 , CURLINFO_HTTP_CODE );
806
829
$ returnInfo ->httpStatus3 = $ status3 ;
807
- if ($ response3 && !curl_errno ($ ch3 ) && $ status3 == 200 ) {
830
+ if ($ response3 && !curl_errno ($ ch3 ) && $ status3 === 200 ) {
808
831
if ($ wp_filesystem ) {
809
- //if(!file_exists($plugin_path . "../gfonts_preview /{$familyfilename}.{$fnttype}") ){
832
+ //if(!file_exists($gfontsDir . "ttf /{$familyfilename}.{$fnttype}") ){
810
833
if (!$ wp_filesystem ->put_contents (
811
- $ gfontsDir . "{$ familyfilename }. {$ fnttype }" ,
834
+ $ gfontsDir . "ttf/ {$ familyfilename }. {$ fnttype }" ,
812
835
$ response3 ,
813
836
FS_CHMOD_FILE
814
837
)) {
815
- $ errorinfo [] = "Cannot write file " . $ plugin_path . "../gfonts_preview / {$ familyfilename }. {$ fnttype } with wordpress filesystem api, sorry " ;
838
+ $ errorinfo [] = "Cannot write file " . $ gfontsDir . "ttf / {$ familyfilename }. {$ fnttype } with wordpress filesystem api, sorry " ;
816
839
} else {
817
- $ gfont_stylesheet = preg_replace ('/url\((.*?)\)/ ' , 'url( ' . esc_url (plugins_url ("../gfonts_preview/ {$ familyfilename }. {$ fnttype }" , __FILE__ )) . ') ' , $ response2 );
818
- if (!file_exists ($ plugin_path . "../css/gfonts_preview/ {$ familyfilename }.css " )) {
840
+ $ uploadURL = wp_upload_dir ()["baseurl " ];
841
+ $ gfont_stylesheet = preg_replace ('/url\((.*?)\)/ ' , 'url( ' . esc_url ("{$ uploadURL }/gfonts_preview/ttf/ {$ familyfilename }. {$ fnttype }" ) . ') ' , $ response2 );
842
+ if (!file_exists ($ gfontsDir . "css/ {$ familyfilename }.css " )) {
819
843
if (!$ wp_filesystem ->put_contents (
820
- $ plugin_path . "../ css/gfonts_preview / {$ familyfilename }.css " ,
844
+ $ gfontsDir . "css/ {$ familyfilename }.css " ,
821
845
$ gfont_stylesheet ,
822
846
FS_CHMOD_FILE
823
847
)) {
824
- $ errorinfo [] = "Cannot write file " . $ plugin_path . "../ css/gfonts_preview / {$ familyfilename }.css with wordpress filesystem api, sorry " ;
848
+ $ errorinfo [] = "Cannot write file " . $ gfontsDir . "css/ {$ familyfilename }.css with wordpress filesystem api, sorry " ;
825
849
}
826
850
}
827
851
}
@@ -862,17 +886,16 @@ public function store_gfonts_preview()
862
886
}
863
887
864
888
865
- // echo print_r($errorinfo);
889
+ //echo print_r($errorinfo);
866
890
if (($ startIdx + ($ batchLimit - 1 )) < ($ totalFonts - 1 )) {
867
891
$ returnInfo ->state = "RUN_PROCESSED " ;
868
892
$ returnInfo ->run = $ currentRun ;
869
893
} else {
870
894
$ returnInfo ->state = "COMPLETE " ;
871
895
872
896
//LAST STEP IS TO MINIFY ALL OF THE CSS FILES INTO ONE SINGLE FILE
873
- $ cssdirectory = str_replace ( '\\' , ' / ' , plugin_dir_path ( __FILE__ ) ) . "../ css/gfonts_preview " ;
897
+ $ cssdirectory = $ gfontsDir . "css " ;
874
898
$ cssfiles = array_diff (scandir ($ cssdirectory ), array ('.. ' , '. ' , 'gfonts_preview.css ' ));
875
-
876
899
$ minifier = new MatthiasMullie \Minify \CSS ($ cssdirectory . "/ " . (array_shift ($ cssfiles )));
877
900
while (count ($ cssfiles ) > 0 ) {
878
901
$ minifier ->add ($ cssdirectory . "/ " . (array_shift ($ cssfiles )));
0 commit comments