forked from PodcastGenerator/PodcastGenerator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpg-cron.php
87 lines (65 loc) · 3.03 KB
/
pg-cron.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
<?php
############################################################
# PODCAST GENERATOR
#
# Created by Alberto Betella
# http://www.podcastgenerator.net
#
# This is Free Software released under the GNU/GPL License.
############################################################
//Checks for previously uploaded episodes with a future date, and regenerate automatically RSS feed if needed
//NB. THIS SCRIPT CAN BE CALLED THROUGH A CRON OR ACT AS PSEUDO CRON CALLED BY INDEX.PHP
########### Security code, avoids cross-site scripting (Register Globals ON)
if (isset($_REQUEST['GLOBALS']) OR isset($_REQUEST['absoluteurl']) OR isset($_REQUEST['amilogged']) OR isset($_REQUEST['theme_path'])) { exit; }
########### End
ob_start();
$startTime = time();
//// Called directly throught the URL (i.e. if absoluteurl is not known)
if (!isset($absoluteurl)) {
//The unique key should be sent via GET variable and be correspond to $installationKey
include("core/includes.php");
if (!isset($_GET["key"]) OR isset($_GET["key"]) AND $_GET["key"] != $installationKey) {
exit; //Key doesn not correspond with the one in config.php
}
$includedInIndexPHP = FALSE; //called through the URL (direct call or cron)
}
//// Called via inclusion in index.php (pseudo cron)
else {
$includedInIndexPHP = TRUE;
}
//// Auto Index new Episodes uploaded to the media folder (this works just went called via cron and not index.php)
if (isset($cronAutoIndex) AND $cronAutoIndex == TRUE AND $includedInIndexPHP == FALSE) {
$episodesCounter = autoIndexingEpisodes();
if ($episodesCounter > 0 AND $includedInIndexPHP == FALSE) {
generatePodcastFeed(TRUE,NULL,FALSE); //Output in file
echo ' -- '.$episodesCounter.' '._("new episodes added"); //Output on screen
}
} // END Auto Index new Episodes uploaded
//// Regenerate automatically RSS feed (so that episodes set to future are indexed in the main RSS feed)
if (isset($cronAutoRegenerateRSS) AND $cronAutoRegenerateRSS == TRUE) {
// If called via index.php inclusion use the cache system (cache time in seconds defined in $cronAutoRegenerateRSScacheTime)
if ($includedInIndexPHP == TRUE) {
$RSSFeedURL = $absoluteurl.$feed_dir."feed.xml";
$lastRSSFeedBuild = NULL;
if (file_exists($RSSFeedURL)) {
//Timestamp last time main RSS feed was generated
$lastRSSFeedBuild = filemtime($RSSFeedURL);
}
if (isset($cronAutoRegenerateRSScacheTime) AND time() - $lastRSSFeedBuild > $cronAutoRegenerateRSScacheTime) {
$episodesinFeedCounter = generatePodcastFeed(TRUE,NULL,FALSE); //Output in file
}
}
//Called via CRON, regenerate feed now (no cache)
else {
$episodesinFeedCounter = generatePodcastFeed(TRUE,NULL,FALSE); //Output in file
if ($episodesinFeedCounter > 0 AND $includedInIndexPHP == FALSE) {
echo ' -- '._("RSS feed regenerated:").' '.$episodesinFeedCounter.' '._("episodes"); //Output on screen
}
}
} // END Regenerate automaticcaly RSS feed
if ($includedInIndexPHP == FALSE) {
$tempusFugit=time()-$startTime;
echo ' -- '._("Execution time (s):").' '.$tempusFugit; //Output on screen
}
ob_end_flush();
?>