zoneclearFeedServer/cron-script.php

94 lines
2.1 KiB
PHP
Raw Normal View History

2015-04-25 19:25:03 +00:00
#!/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
2023-10-14 13:41:43 +00:00
use Dotclear\App;
2015-04-25 19:25:03 +00:00
$opts = getopt('d:c:b:u:h');
2023-05-07 22:40:58 +00:00
function zchelp(string|int $status = 0): void
2015-04-25 19:25:03 +00:00
{
echo
2021-11-06 15:30:19 +00:00
"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);
2015-04-25 19:25:03 +00:00
}
if (isset($opts['h'])) {
2022-11-15 20:05:21 +00:00
zchelp();
2015-04-25 19:25:03 +00:00
}
$dc_root = null;
$dc_conf = null;
$blog_id = null;
if (isset($opts['d'])) {
$dc_root = $opts['d'];
2015-04-25 19:25:03 +00:00
} elseif (isset($_SERVER['DC_ROOT'])) {
$dc_root = $_SERVER['DC_ROOT'];
2015-04-25 19:25:03 +00:00
}
2023-05-07 22:40:58 +00:00
if (isset($opts['c']) && is_string($opts['c'])) {
$dc_conf = realpath($opts['c']);
2015-04-25 19:25:03 +00:00
} elseif (isset($_SERVER['DC_RC_PATH'])) {
$dc_conf = realpath($_SERVER['DC_RC_PATH']);
2015-04-25 19:25:03 +00:00
}
if (isset($opts['b'])) {
$blog_id = $opts['b'];
2015-04-25 19:25:03 +00:00
} elseif (isset($_SERVER['DC_BLOG_ID'])) {
$blog_id = $opts['DC_BLOG_ID'];
2015-04-25 19:25:03 +00:00
}
if (!$dc_root || !is_dir($dc_root)) {
2021-11-06 15:30:19 +00:00
fwrite(STDERR, "DotClear root path is not defined\n\n");
2022-11-15 20:05:21 +00:00
zchelp(1);
2015-04-25 19:25:03 +00:00
}
if (!$dc_conf || !is_readable($dc_conf)) {
2021-11-06 15:30:19 +00:00
fwrite(STDERR, "DotClear configuration not found\n\n");
2022-11-15 20:05:21 +00:00
zchelp(1);
2015-04-25 19:25:03 +00:00
}
2023-05-07 22:40:58 +00:00
if (!$blog_id || !is_string($blog_id)) {
2021-11-06 15:30:19 +00:00
fwrite(STDERR, "Blog ID is not defined\n\n");
2022-11-15 20:05:21 +00:00
zchelp(1);
2015-04-25 19:25:03 +00:00
}
$_SERVER['DC_RC_PATH'] = $dc_conf;
unset($dc_conf);
2021-11-06 15:30:19 +00:00
define('DC_BLOG_ID', $blog_id);
2015-04-25 19:25:03 +00:00
unset($blog_id);
2021-11-06 15:30:19 +00:00
require $dc_root . '/inc/prepend.php';
2015-04-25 19:25:03 +00:00
unset($dc_root);
2023-10-14 13:41:43 +00:00
App::blog()->loadFromBlog(is_string(DC_BLOG_ID) ? DC_BLOG_ID : '');
if (!App::blog()->isDefined() || '' == App::blog()->id()) {
2021-11-06 15:30:19 +00:00
fwrite(STDERR, "Blog is not defined\n");
exit(1);
2015-04-25 19:25:03 +00:00
}
2023-10-14 13:41:43 +00:00
if (!isset($opts['u']) || !App::auth()->checkUser(is_string($opts['u']) ? $opts['u'] : '')) {
2021-11-06 15:30:19 +00:00
fwrite(STDERR, "Unable to set user\n");
exit(1);
2015-04-25 19:25:03 +00:00
}
2023-10-14 13:41:43 +00:00
App::plugins()->loadModules(DC_PLUGINS_ROOT);
2015-04-25 19:25:03 +00:00
try {
2023-05-07 22:40:58 +00:00
$zc = Dotclear\Plugin\zoneclearFeedServer\ZoneclearFeedServer::instance();
$zc->checkFeedsUpdate();
2015-04-25 19:25:03 +00:00
} catch (Exception $e) {
2021-11-06 15:30:19 +00:00
fwrite(STDERR, $e->getMessage() . "\n");
exit(1);
2021-11-06 15:30:19 +00:00
}