forked from brol/zoneclearFeedServer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcron-script.php
More file actions
93 lines (75 loc) · 2.07 KB
/
cron-script.php
File metadata and controls
93 lines (75 loc) · 2.07 KB
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
#!/usr/bin/env php
<?php
# This file is highly based cron-script.php
# From Dotclear extension called planet
# By Olivier Meunier and contributors
# Licensed under the GPL version 2.0 license
use Dotclear\App;
$opts = getopt('d:c:b:u:h');
function zchelp(string|int $status = 0): void
{
echo
"Options: \n" .
" -h shows this help\n" .
" -d DotClear root path\n" .
" -c DotClear conf path\n" .
" -b Blog ID\n" .
" -u User ID\n\n";
exit($status);
}
if (isset($opts['h'])) {
zchelp();
}
$dc_root = null;
$dc_conf = null;
$blog_id = null;
if (isset($opts['d'])) {
$dc_root = $opts['d'];
} elseif (isset($_SERVER['DC_ROOT'])) {
$dc_root = $_SERVER['DC_ROOT'];
}
if (isset($opts['c']) && is_string($opts['c'])) {
$dc_conf = realpath($opts['c']);
} elseif (isset($_SERVER['DC_RC_PATH'])) {
$dc_conf = realpath($_SERVER['DC_RC_PATH']);
}
if (isset($opts['b'])) {
$blog_id = $opts['b'];
} elseif (isset($_SERVER['DC_BLOG_ID'])) {
$blog_id = $_SERVER['DC_BLOG_ID'];
}
if (!$dc_root || !is_dir($dc_root)) {
fwrite(STDERR, "DotClear root path is not defined\n\n");
zchelp(1);
}
if (!$dc_conf || !is_readable($dc_conf)) {
fwrite(STDERR, "DotClear configuration not found\n\n");
zchelp(1);
}
if (!$blog_id || !is_string($blog_id)) {
fwrite(STDERR, "Blog ID is not defined\n\n");
zchelp(1);
}
$_SERVER['DC_RC_PATH'] = $dc_conf;
unset($dc_conf);
define('DC_BLOG_ID', $blog_id);
unset($blog_id);
require $dc_root . '/inc/prepend.php';
unset($dc_root);
App::blog()->loadFromBlog(is_string(DC_BLOG_ID) ? DC_BLOG_ID : '');
if (!App::blog()->isDefined() || '' == App::blog()->id()) {
fwrite(STDERR, "Blog is not defined\n");
exit(1);
}
if (!isset($opts['u']) || !App::auth()->checkUser(is_string($opts['u']) ? $opts['u'] : '')) {
fwrite(STDERR, "Unable to set user\n");
exit(1);
}
App::plugins()->loadModules(DC_PLUGINS_ROOT);
try {
$zc = Dotclear\Plugin\zoneclearFeedServer\ZoneclearFeedServer::instance();
$zc->checkFeedsUpdate();
} catch (Exception $e) {
fwrite(STDERR, $e->getMessage() . "\n");
exit(1);
}