4
4
*
5
5
* Holt und speichert die Astronomy Pictures of the Day (APOD)
6
6
*
7
- * @author [z]biko
8
- * @date 01.01.2004
7
+ * @version 1.0
8
+ * @since 1.0 `01.01.2004` `[z]biko` File added
9
+ *
9
10
* @package zorg\APOD
10
11
*/
11
12
/**
16
17
* @include gallery.inc.php Gallery and Pic functions
17
18
* @include util.inc.php Various Helper Functions
18
19
*/
19
- require_once dirname ( __FILE__ ) .'/config.inc.php ' ;
20
+ require_once __DIR__ .'/config.inc.php ' ;
20
21
require_once INCLUDES_DIR .'mysql.inc.php ' ;
21
22
require_once INCLUDES_DIR .'forum.inc.php ' ;
22
23
require_once INCLUDES_DIR .'gallery.inc.php ' ;
36
37
* hd | bool | False | Retrieve the URL for the high resolution image
37
38
* api_key | string | DEMO_KEY | api.nasa.gov key for expanded usage
38
39
*
39
- * @author [z]biko
40
- * @author IneX
41
- * @version 4.1
42
- * @since 1.0 `01.01.2004` function added
43
- * @since 2.0 `06.08.2018` function refactored to use NASA APOD API
44
- * @since 3.0 `09.08.2018` enhanced function so an APOD date can be passed
45
- * @since 4.0 `14.09.2018` added processing of videos & website links passed from the APOD API
46
- * @since 4.1 `26.06.2023` fixes code quality issue "Unreachable code ('cleanup:')"
40
+ * @version 4.2
41
+ * @since 1.0 `01.01.2004` `[z]biko` function added
42
+ * @since 2.0 `06.08.2018` `IneX` function refactored to use NASA APOD API
43
+ * @since 3.0 `09.08.2018` `IneX` enhanced function so an APOD date can be passed
44
+ * @since 4.0 `14.09.2018` `IneX` added processing of videos & website links passed from the APOD API
45
+ * @since 4.1 `26.06.2023` `IneX` fixes code quality issue "Unreachable code ('cleanup:')"
46
+ * @since 4.2 `24.02.2024` `IneX` replaces deprecated $MAX_PIC_SIZE, fixes SQL INSERT with empty 'extension'
47
47
*
48
- * @uses APOD_API, APOD_TEMP_IMGPATH, APOD_GALLERY_ID, $ MAX_PIC_SIZE
48
+ * @uses APOD_API, APOD_TEMP_IMGPATH, APOD_GALLERY_ID, MAX_PIC_SIZE
49
49
* @uses cURLfetchJSON(), createPic(), getYoutubeVideoThumbnail(), getVimeoVideoThumbnail(), Comment::post()
50
50
* @param string $apod_date (Optional) A valid date after June 16 1995, formatted as: yyyy-mm-dd (2018-08-06)
51
- * @global object $db Globales Class-Object mit allen MySQL-Methoden
52
- * @global array $MAX_PIC_SIZE Globales Array im Scope von gallery.inc.php mit den Image-Width & -Height Grössen für Pics und Thumbnails
51
+ * @global object $db Globales Class-Object mit allen MySQL-Methoden
53
52
* @return boolean Returns true or false, depening on if the function was processed successfully or not
54
53
*/
55
54
function get_apod ($ apod_date_input =NULL )
56
55
{
57
- global $ db, $ MAX_PIC_SIZE ;
56
+ global $ db ;
58
57
59
58
/** Validate $apod_date if passed */
60
- if ( DEVELOPMENT ) error_log ( sprintf ( ' [DEBUG] <%s:%d> $apod_date_input: %s ' , __FUNCTION__ , __LINE__ , $ apod_date_input) );
59
+ zorgDebugger:: log ()-> debug ( ' $apod_date_input: %s ' , [ $ apod_date_input] );
61
60
if (empty ($ apod_date_input ) || strtotime ($ apod_date_input ) === false ) $ apod_date_input = NULL ;
62
61
63
62
/** Retrieve the APOD data from the APOD_API */
@@ -82,10 +81,10 @@ function get_apod($apod_date_input=NULL)
82
81
* [url] => https://apod.nasa.gov/apod/http://nusoft.fnal.gov/nova/public/img/FD-evt-echo.gif
83
82
* )
84
83
*/
85
- if ( DEVELOPMENT && $ apod_date_input != NULL ) error_log ( sprintf ( ' [DEBUG] <%s:%d> date("ymd",$apod_date_input): %s ' , __FUNCTION__ , __LINE__ , date ('ymd ' ,strtotime ($ apod_date_input ))) );
86
- if ( DEVELOPMENT && $ apod_date_input == NULL ) error_log ( sprintf ( ' [DEBUG] <%s:%d> date("ymd",strtotime($apod_data[date])): %s ' , __FUNCTION__ , __LINE__ , date ('ymd ' ,strtotime ($ apod_data ['date ' ]))) );
84
+ zorgDebugger:: log ()-> debug ( ' date("ymd",$apod_date_input): %s ' , [ date ('ymd ' ,strtotime ($ apod_date_input ))] );
85
+ zorgDebugger:: log ()-> debug ( ' date("ymd",strtotime($apod_data[date])): %s ' , [ date ('ymd ' ,strtotime ($ apod_data ['date ' ]))] );
87
86
$ new_apod_date = ( $ apod_date_input != NULL ? date ('ymd ' ,strtotime ($ apod_date_input )) : date ('ymd ' ,strtotime ($ apod_data ['date ' ])) );
88
- if ( DEVELOPMENT ) error_log ( sprintf ( ' [DEBUG] <%s:%d> $new_apod_date: %s ' , __FUNCTION__ , __LINE__ , $ new_apod_date) );
87
+ zorgDebugger:: log ()-> debug ( ' $new_apod_date: %s ' , [ $ new_apod_date] );
89
88
$ new_apod_title = $ apod_data ['title ' ];
90
89
$ new_apod_explanation = $ apod_data ['explanation ' ];
91
90
$ new_apod_copyright = $ apod_data ['copyright ' ];
@@ -94,7 +93,7 @@ function get_apod($apod_date_input=NULL)
94
93
$ new_apod_img_large = str_replace ('https://apod.nasa.gov/apod/http ' , 'http ' , $ apod_data ['hdurl ' ]); // with fix for malformed url (APOD API issue)
95
94
$ new_apod_archive_url = APOD_SOURCE . 'ap ' .$ new_apod_date .'.html ' ; // E.g.: https://apod.nasa.gov/apod/ap180714.html
96
95
$ new_apod_urlparts = pathinfo ($ new_apod_img_small );
97
- if ( DEVELOPMENT ) error_log ( sprintf ( ' [DEBUG] <%s:%d> pathinfo(): %s ' , __FUNCTION__ , __LINE__ , print_r ($ new_apod_urlparts ,true )) );
96
+ zorgDebugger:: log ()-> debug ( ' pathinfo(): %s ' , [ print_r ($ new_apod_urlparts ,true )] );
98
97
$ new_apod_fileext = $ new_apod_urlparts ['extension ' ];
99
98
$ new_apod_filename = $ apod_data ['date ' ] . '. ' . $ new_apod_fileext ;
100
99
$ new_apod_temp_filepath = APOD_TEMP_IMGPATH . $ new_apod_filename ;
@@ -109,13 +108,14 @@ function get_apod($apod_date_input=NULL)
109
108
if (!empty ($ new_apod_title ))
110
109
{
111
110
if ($ new_apod_mediatype === 'image ' ) $ new_apod_fileext = '. ' .$ new_apod_fileext ;
112
- $ new_apod_picid = $ db ->insert ('gallery_pics ' , [
113
- 'album ' =>APOD_GALLERY_ID
114
- ,'extension ' =>$ new_apod_fileext
115
- ,'pic_added ' =>$ new_apod_date
116
- ,'name ' =>$ new_apod_title .($ new_apod_mediatype == 'video ' ? ' [video] ' : '' )
117
- ], __FILE__ , __LINE__ , __FUNCTION__ );
118
- if (DEVELOPMENT ) error_log (sprintf ('[DEBUG] <%s:%d> $new_apod_picid: %s ' , __FUNCTION__ , __LINE__ , $ new_apod_picid ));
111
+ $ new_apod_basedata = [
112
+ 'album ' =>APOD_GALLERY_ID
113
+ ,'pic_added ' =>$ new_apod_date
114
+ ,'name ' =>$ new_apod_title .($ new_apod_mediatype == 'video ' ? ' [video] ' : '' )
115
+ ];
116
+ if (!empty ($ new_apod_fileext ) && is_string ($ new_apod_fileext )) $ new_apod_basedata ['extension ' ] = $ new_apod_fileext ;
117
+ $ new_apod_picid = $ db ->insert ('gallery_pics ' , $ new_apod_basedata , __FILE__ , __LINE__ , __FUNCTION__ );
118
+ zorgDebugger::log ()->debug ('$new_apod_picid: %s ' , [$ new_apod_picid ]);
119
119
120
120
/** If $new_apod_title is empty, abort */
121
121
} else {
@@ -142,8 +142,8 @@ function get_apod($apod_date_input=NULL)
142
142
$ new_apod_filepath_pic_tn = tnPath (APOD_GALLERY_ID , $ new_apod_picid , $ new_apod_fileext ); // Fix eventual double-slashes in path
143
143
144
144
/** Create APOD gallery pic */
145
- if ( DEVELOPMENT ) error_log ( sprintf ( ' [DEBUG] <%s:%d> createPic(): %s ' , __FUNCTION__ , __LINE__ , $ new_apod_filepath_pic) );
146
- if (!createPic ($ new_apod_temp_filepath , $ new_apod_filepath_pic , $ MAX_PIC_SIZE ['picWidth ' ], $ MAX_PIC_SIZE ['picHeight ' ]))
145
+ zorgDebugger:: log ()-> debug ( ' image createPic(): %s ' , [ $ new_apod_filepath_pic] );
146
+ if (!createPic ($ new_apod_temp_filepath , $ new_apod_filepath_pic , MAX_PIC_SIZE ['width ' ], MAX_PIC_SIZE ['height ' ]))
147
147
{
148
148
error_log (sprintf ('[ERROR] <%s:%d> %s createPic() ERROR: %s ' , __FILE__ , __LINE__ , __FUNCTION__ , $ new_apod_filepath_pic ));
149
149
/** Goto: cleanup */
@@ -152,8 +152,8 @@ function get_apod($apod_date_input=NULL)
152
152
}
153
153
154
154
/** Create APOD gallery pic-thumbnail */
155
- if ( DEVELOPMENT ) error_log ( sprintf ( ' [DEBUG] <%s:%d> createPic() thumbnail: %s ' , __FUNCTION__ , __LINE__ , $ new_apod_filepath_pic_tn) );
156
- if (!createPic ($ new_apod_temp_filepath , $ new_apod_filepath_pic_tn , $ MAX_PIC_SIZE [ ' tnWidth ' ], $ MAX_PIC_SIZE [ ' tnHeight ' ]))
155
+ zorgDebugger:: log ()-> debug ( ' image createPic() thumbnail: %s ' , [ $ new_apod_filepath_pic_tn] );
156
+ if (!createPic ($ new_apod_temp_filepath , $ new_apod_filepath_pic_tn , MAX_THUMBNAIL_SIZE [ ' width ' ], MAX_THUMBNAIL_SIZE [ ' height ' ]))
157
157
{
158
158
error_log (sprintf ('[ERROR] <%s:%d> %s createPic() thumbnail ERROR: %s ' , __FILE__ , __LINE__ , __FUNCTION__ , $ new_apod_filepath_pic_tn ));
159
159
/** Goto: cleanup */
@@ -171,6 +171,7 @@ function get_apod($apod_date_input=NULL)
171
171
*/
172
172
case 'video ' :
173
173
/* Find out what 'video'-type exactly we're dealing with... */
174
+ $ media_type = null ;
174
175
$ video_services = [
175
176
[
176
177
'service ' => 'youtube '
@@ -186,14 +187,14 @@ function get_apod($apod_date_input=NULL)
186
187
if (strpos ($ service ['identifier ' ], $ new_apod_urlparts ['dirname ' ]) !== false )
187
188
{
188
189
$ media_type = $ service ['service ' ];
190
+ zorgDebugger::log ()->debug ('$service[identifier] found: %s ' , [$ media_type ]);
189
191
/** Video type found, let's exit the foreach{}-loop */
190
- if (DEVELOPMENT ) error_log (sprintf ('[DEBUG] <%s:%d> $service[identifier] found: %s ' , __FUNCTION__ , __LINE__ , $ media_type ));
191
192
break ;
192
193
}
193
194
}
194
195
195
196
/** No matching $media_type found, let's Goto: cleanup */
196
- if ( DEVELOPMENT ) error_log ( sprintf ( ' [DEBUG] <%s:%d> $media_type: %s ' , __FUNCTION__ , __LINE__ , print_r ($ media_type ,true )) );
197
+ zorgDebugger:: log ()-> debug ( ' $media_type: NOT FOUND --> %s ' , [ print_r ($ media_type ,true )] );
197
198
if (empty ($ media_type ) || is_array ($ media_type ))
198
199
{
199
200
/** Goto: cleanup */
@@ -204,7 +205,7 @@ function get_apod($apod_date_input=NULL)
204
205
/** Get Video-Thumbnail image */
205
206
$ new_apod_img_thumbnail = getVideoThumbnail ($ media_type , $ new_apod_urlparts ['filename ' ]);
206
207
$ new_apod_temp_filepath = $ new_apod_temp_filepath .pathinfo ($ new_apod_img_thumbnail , PATHINFO_EXTENSION );
207
- if ( DEVELOPMENT ) error_log ( sprintf ( ' [DEBUG] <%s:%d> cURLfetchUrl(): %s ' , __FUNCTION__ , __LINE__ , $ new_apod_temp_filepath) );
208
+ zorgDebugger:: log ()-> debug ( ' video cURLfetchUrl(): %s ' , [ $ new_apod_temp_filepath] );
208
209
if (!cURLfetchUrl ($ new_apod_img_thumbnail , $ new_apod_temp_filepath ))
209
210
{
210
211
remove_apod_id_from_db ($ new_apod_picid );
@@ -213,8 +214,8 @@ function get_apod($apod_date_input=NULL)
213
214
214
215
/** Create APOD gallery pic-thumbnail for 'video' */
215
216
$ new_apod_filepath_pic_tn = tnPath (APOD_GALLERY_ID , $ new_apod_picid , '. ' .pathinfo ($ new_apod_img_thumbnail , PATHINFO_EXTENSION ));
216
- if ( DEVELOPMENT ) error_log ( sprintf ( ' [DEBUG] <%s:%d> createPic() thumbnail: %s ' , __FUNCTION__ , __LINE__ , $ new_apod_filepath_pic_tn) );
217
- if (!createPic ($ new_apod_temp_filepath , $ new_apod_filepath_pic_tn , $ MAX_PIC_SIZE ['tnWidth ' ], $ MAX_PIC_SIZE ['tnHeight ' ]))
217
+ zorgDebugger:: log ()-> debug ( ' video createPic() thumbnail: %s ' , [ $ new_apod_filepath_pic_tn] );
218
+ if (!createPic ($ new_apod_temp_filepath , $ new_apod_filepath_pic_tn , MAX_PIC_SIZE ['width ' ], MAX_PIC_SIZE ['height ' ]))
218
219
{
219
220
error_log (sprintf ('[ERROR] <%s:%d> %s createPic() thumbnail ERROR: %s ' , __FILE__ , __LINE__ , __FUNCTION__ , $ new_apod_filepath_pic_tn ));
220
221
remove_apod_id_from_db ($ new_apod_picid );
@@ -223,7 +224,7 @@ function get_apod($apod_date_input=NULL)
223
224
224
225
/** Update APOD 'video' entry in gallery_pics table */
225
226
$ result = $ db ->update ('gallery_pics ' , ['id ' , $ new_apod_picid ], ['extension ' => $ media_type , 'picsize ' => $ new_apod_img_small ], __FILE__ , __LINE__ , __FUNCTION__ );
226
- if ( DEVELOPMENT ) error_log ( sprintf ( ' [DEBUG] <%s:%d> $db->update(gallery_pics): (%s) %s ' , __FUNCTION__ , __LINE__ , $ result , ($ result >0 ? 'true ' : 'false ' )) );
227
+ zorgDebugger:: log ()-> debug ( ' $db->update(gallery_pics): (%s) %s ' , [ $ result , ($ result >0 ? 'true ' : 'false ' )] );
227
228
if ($ result === 0 ) {
228
229
remove_apod_id_from_db ($ new_apod_picid );
229
230
return false ;
@@ -238,10 +239,10 @@ function get_apod($apod_date_input=NULL)
238
239
case 'website ' :
239
240
/** Create APOD gallery pic-thumbnail for 'video' or 'website' */
240
241
$ new_apod_temp_filepath = PHP_IMAGES_DIR . 'apod/tn_website.png ' ;
241
- if ( DEVELOPMENT ) error_log ( sprintf ( ' [DEBUG] <%s:%d> $new_apod_temp_filepath: %s ' , __FUNCTION__ , __LINE__ , $ new_apod_temp_filepath) );
242
+ zorgDebugger:: log ()-> debug ( ' $new_apod_temp_filepath: %s ' , [ $ new_apod_temp_filepath] );
242
243
$ new_apod_filepath_pic_tn = tnPath (APOD_GALLERY_ID , $ new_apod_picid , '. ' .pathinfo ($ new_apod_temp_filepath , PATHINFO_EXTENSION ));
243
- if ( DEVELOPMENT ) error_log ( sprintf ( ' [DEBUG] <%s:%d> createPic() thumbnail: %s ' , __FUNCTION__ , __LINE__ , $ new_apod_filepath_pic_tn) );
244
- if (!createPic ($ new_apod_temp_filepath , $ new_apod_filepath_pic_tn , $ MAX_PIC_SIZE ['tnWidth ' ], $ MAX_PIC_SIZE ['tnHeight ' ]))
244
+ zorgDebugger:: log ()-> debug ( ' website createPic() thumbnail: %s ' , [ $ new_apod_filepath_pic_tn] );
245
+ if (!createPic ($ new_apod_temp_filepath , $ new_apod_filepath_pic_tn , MAX_PIC_SIZE ['width ' ], MAX_PIC_SIZE ['height ' ]))
245
246
{
246
247
error_log (sprintf ('[ERROR] <%s:%d> %s createPic() thumbnail ERROR: %s ' , __FILE__ , __LINE__ , __FUNCTION__ , $ new_apod_filepath_pic_tn ));
247
248
remove_apod_id_from_db ($ new_apod_picid );
@@ -250,7 +251,7 @@ function get_apod($apod_date_input=NULL)
250
251
251
252
/** Update APOD 'website' entry in gallery_pics table */
252
253
$ result = $ db ->update ('gallery_pics ' , ['id ' , $ new_apod_picid ], ['extension ' => $ new_apod_mediatype , 'picsize ' => $ new_apod_img_small ], __FILE__ , __LINE__ , __FUNCTION__ );
253
- if ( DEVELOPMENT ) error_log ( sprintf ( ' [DEBUG] <%s:%d> $db->update(gallery_pics): (%s) %s ' , __FUNCTION__ , __LINE__ , $ result , ($ result >0 ? 'true ' : 'false ' )) );
254
+ zorgDebugger:: log ()-> debug ( ' $db->update(gallery_pics): (%s) %s ' , [ ($ result >0 ? 'true ' : 'false ' )] );
254
255
if ($ result === 0 ) {
255
256
remove_apod_id_from_db ($ new_apod_picid );
256
257
return false ;
0 commit comments