2015-04-25 19:25:03 +00:00
|
|
|
<?php
|
2021-09-11 09:56:57 +00:00
|
|
|
/**
|
|
|
|
* @brief zoneclearFeedServer, a plugin for Dotclear 2
|
2021-11-06 15:30:19 +00:00
|
|
|
*
|
2021-09-11 09:56:57 +00:00
|
|
|
* @package Dotclear
|
|
|
|
* @subpackage Plugin
|
2021-11-06 15:30:19 +00:00
|
|
|
*
|
2021-09-11 09:56:57 +00:00
|
|
|
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
|
2021-11-06 15:30:19 +00:00
|
|
|
*
|
2021-09-11 09:56:57 +00:00
|
|
|
* @copyright Jean-Christian Denis
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
*/
|
2015-04-25 19:25:03 +00:00
|
|
|
if (!defined('DC_RC_PATH')) {
|
2021-09-11 09:56:57 +00:00
|
|
|
return null;
|
2015-04-25 19:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup DC_PLUGIN_ZONECLEARFEEDSERVER
|
|
|
|
* @brief Feeds server - main methods
|
|
|
|
* @since 2.6
|
|
|
|
*/
|
|
|
|
class zoneclearFeedServer
|
|
|
|
{
|
2021-11-06 15:30:19 +00:00
|
|
|
public static $nethttp_timeout = 5;
|
|
|
|
public static $nethttp_agent = 'zoneclearFeedServer - http://zoneclear.org';
|
2021-09-11 09:56:57 +00:00
|
|
|
public static $nethttp_maxredirect = 2;
|
|
|
|
|
|
|
|
public $con;
|
|
|
|
private $blog;
|
|
|
|
private $table;
|
|
|
|
private $lock = null;
|
2022-11-15 20:05:21 +00:00
|
|
|
private $user = null;
|
2021-09-11 09:56:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*/
|
2022-11-15 20:05:21 +00:00
|
|
|
public function __construct()
|
2021-09-11 09:56:57 +00:00
|
|
|
{
|
2022-11-15 20:05:21 +00:00
|
|
|
$this->con = dcCore::app()->con;
|
|
|
|
$this->blog = dcCore::app()->con->escape(dcCore::app()->blog->id);
|
2022-12-10 16:16:41 +00:00
|
|
|
$this->table = dcCore::app()->prefix . initZoneclearFeedServer::TABLE_NAME;
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Short openCursor.
|
2021-11-06 15:30:19 +00:00
|
|
|
*
|
2021-09-11 09:56:57 +00:00
|
|
|
* @return cursor cursor instance
|
|
|
|
*/
|
|
|
|
public function openCursor()
|
|
|
|
{
|
|
|
|
return $this->con->openCursor($this->table);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update feed record.
|
2021-11-06 15:30:19 +00:00
|
|
|
*
|
2021-09-11 09:56:57 +00:00
|
|
|
* @param integer $id Feed id
|
|
|
|
* @param cursor $cur cursor instance
|
|
|
|
*/
|
|
|
|
public function updFeed($id, cursor $cur)
|
|
|
|
{
|
|
|
|
$this->con->writeLock($this->table);
|
|
|
|
|
|
|
|
try {
|
2021-11-06 15:30:19 +00:00
|
|
|
$id = (int) $id;
|
2021-09-11 09:56:57 +00:00
|
|
|
|
|
|
|
if ($id < 1) {
|
|
|
|
throw new Exception(__('No such ID'));
|
|
|
|
}
|
2021-09-12 20:32:21 +00:00
|
|
|
|
2021-09-11 09:56:57 +00:00
|
|
|
$cur->feed_upddt = date('Y-m-d H:i:s');
|
|
|
|
|
|
|
|
$cur->update(sprintf(
|
|
|
|
"WHERE feed_id = %s AND blog_id = '%s' ",
|
|
|
|
$id,
|
|
|
|
$this->blog
|
|
|
|
));
|
|
|
|
$this->con->unlock();
|
|
|
|
$this->trigger();
|
2021-09-12 20:32:21 +00:00
|
|
|
} catch (Exception $e) {
|
2021-09-11 09:56:57 +00:00
|
|
|
$this->con->unlock();
|
2021-11-06 15:30:19 +00:00
|
|
|
|
2021-09-11 09:56:57 +00:00
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
|
|
|
|
# --BEHAVIOR-- zoneclearFeedServerAfterUpdFeed
|
2022-11-15 20:05:21 +00:00
|
|
|
dcCore::app()->callBehavior('zoneclearFeedServerAfterUpdFeed', $cur, $id);
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add feed record.
|
|
|
|
*
|
|
|
|
* @param cursor $cur cursor instance
|
|
|
|
*/
|
|
|
|
public function addFeed(cursor $cur)
|
|
|
|
{
|
|
|
|
$this->con->writeLock($this->table);
|
|
|
|
|
|
|
|
try {
|
2021-11-06 15:30:19 +00:00
|
|
|
$cur->feed_id = $this->getNextId();
|
|
|
|
$cur->blog_id = $this->blog;
|
2021-09-11 09:56:57 +00:00
|
|
|
$cur->feed_creadt = date('Y-m-d H:i:s');
|
2021-11-06 15:30:19 +00:00
|
|
|
$cur->feed_upddt = date('Y-m-d H:i:s');
|
2021-09-11 09:56:57 +00:00
|
|
|
|
|
|
|
//add getFeedCursor here
|
|
|
|
|
|
|
|
$cur->insert();
|
|
|
|
$this->con->unlock();
|
|
|
|
$this->trigger();
|
2021-09-12 20:32:21 +00:00
|
|
|
} catch (Exception $e) {
|
2021-09-11 09:56:57 +00:00
|
|
|
$this->con->unlock();
|
2021-11-06 15:30:19 +00:00
|
|
|
|
2021-09-11 09:56:57 +00:00
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
|
|
|
|
# --BEHAVIOR-- zoneclearFeedServerAfterAddFeed
|
2022-11-15 20:05:21 +00:00
|
|
|
dcCore::app()->callBehavior('zoneclearFeedServerAfterAddFeed', $cur);
|
2021-09-11 09:56:57 +00:00
|
|
|
|
|
|
|
return $cur->feed_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Quick enable / disable feed.
|
2021-11-06 15:30:19 +00:00
|
|
|
*
|
2021-09-11 09:56:57 +00:00
|
|
|
* @param integer $id Feed Id
|
|
|
|
* @param boolean $enable Enable or disable feed
|
|
|
|
* @param integer $time Force update time
|
|
|
|
*/
|
2021-09-12 20:32:21 +00:00
|
|
|
public function enableFeed($id, $enable = true, $time = null)
|
2021-09-11 09:56:57 +00:00
|
|
|
{
|
|
|
|
try {
|
2021-11-06 15:30:19 +00:00
|
|
|
$id = (int) $id;
|
2021-09-11 09:56:57 +00:00
|
|
|
|
|
|
|
if ($id < 1) {
|
|
|
|
throw new Exception(__('No such ID'));
|
|
|
|
}
|
2021-09-12 20:32:21 +00:00
|
|
|
|
2021-09-11 09:56:57 +00:00
|
|
|
$cur = $this->openCursor();
|
|
|
|
$this->con->writeLock($this->table);
|
|
|
|
|
2021-11-06 15:30:19 +00:00
|
|
|
$cur->feed_upddt = date('Y-m-d H:i:s');
|
|
|
|
$cur->feed_status = (int) $enable;
|
2021-09-11 09:56:57 +00:00
|
|
|
if (null !== $time) {
|
2021-11-06 15:30:19 +00:00
|
|
|
$cur->feed_upd_last = (int) $time;
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$cur->update(sprintf(
|
|
|
|
"WHERE feed_id = %s AND blog_id = '%s' ",
|
|
|
|
$id,
|
|
|
|
$this->blog
|
|
|
|
));
|
|
|
|
$this->con->unlock();
|
|
|
|
$this->trigger();
|
2021-09-12 20:32:21 +00:00
|
|
|
} catch (Exception $e) {
|
2021-09-11 09:56:57 +00:00
|
|
|
$this->con->unlock();
|
2021-11-06 15:30:19 +00:00
|
|
|
|
2021-09-11 09:56:57 +00:00
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
|
|
|
|
# --BEHAVIOR-- zoneclearFeedServerAfterEnableFeed
|
2022-11-15 20:05:21 +00:00
|
|
|
dcCore::app()->callBehavior('zoneclearFeedServerAfterEnableFeed', $id, $enable, $time);
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
|
2021-11-06 15:30:19 +00:00
|
|
|
#
|
2021-09-11 09:56:57 +00:00
|
|
|
/**
|
|
|
|
* Delete record (this not deletes post).
|
2021-11-06 15:30:19 +00:00
|
|
|
*
|
2021-09-11 09:56:57 +00:00
|
|
|
* @param integer $id Feed Id
|
|
|
|
*/
|
|
|
|
public function delFeed($id)
|
|
|
|
{
|
2021-11-06 15:30:19 +00:00
|
|
|
$id = (int) $id;
|
2021-09-11 09:56:57 +00:00
|
|
|
|
|
|
|
if ($id < 1) {
|
|
|
|
throw new Exception(__('No such ID'));
|
|
|
|
}
|
|
|
|
|
|
|
|
# --BEHAVIOR-- zoneclearFeedServerBeforeDelFeed
|
2022-11-15 20:05:21 +00:00
|
|
|
dcCore::app()->callBehavior('zoneclearFeedServerBeforeDelFeed', $id);
|
2021-09-11 09:56:57 +00:00
|
|
|
|
|
|
|
$this->con->execute(sprintf(
|
|
|
|
"DELETE FROM %s WHERE feed_id = %s AND blog_id = '%s' ",
|
|
|
|
$this->table,
|
|
|
|
$id,
|
|
|
|
$this->blog
|
|
|
|
));
|
|
|
|
$this->trigger();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get related posts.
|
2021-11-06 15:30:19 +00:00
|
|
|
*
|
2021-09-11 09:56:57 +00:00
|
|
|
* @param array $params Query params
|
|
|
|
* @param boolean $count_only Return only result count
|
2022-11-15 20:05:21 +00:00
|
|
|
* @return null|dcRecord record instance
|
2021-09-11 09:56:57 +00:00
|
|
|
*/
|
2021-11-06 15:30:19 +00:00
|
|
|
public function getPostsByFeed($params = [], $count_only = false)
|
2021-09-11 09:56:57 +00:00
|
|
|
{
|
|
|
|
if (!isset($params['feed_id'])) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-11-15 20:05:21 +00:00
|
|
|
$sql = new dcSelectStatement();
|
|
|
|
$sql->join(
|
|
|
|
(new dcJoinStatement())
|
2022-02-13 20:42:39 +00:00
|
|
|
->type('LEFT')
|
2022-11-15 20:05:21 +00:00
|
|
|
->from(dcCore::app()->prefix . dcMeta::META_TABLE_NAME . ' F')
|
2022-02-13 20:42:39 +00:00
|
|
|
->on('P.post_id = F.post_id')
|
|
|
|
->statement()
|
|
|
|
);
|
|
|
|
|
2021-11-06 15:30:19 +00:00
|
|
|
$params['sql'] = "AND P.blog_id = '" . $this->blog . "' " .
|
2021-09-12 20:32:21 +00:00
|
|
|
"AND F.meta_type = 'zoneclearfeed_id' " .
|
|
|
|
"AND F.meta_id = '" . $this->con->escape($params['feed_id']) . "' ";
|
2021-09-11 09:56:57 +00:00
|
|
|
|
|
|
|
unset($params['feed_id']);
|
|
|
|
|
2022-11-15 20:05:21 +00:00
|
|
|
return dcCore::app()->blog->getPosts($params, $count_only, $sql);
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get feed record.
|
2021-11-06 15:30:19 +00:00
|
|
|
*
|
2021-09-11 09:56:57 +00:00
|
|
|
* @param array $params Query params
|
|
|
|
* @param boolean $count_only Return only result count
|
2022-11-15 20:05:21 +00:00
|
|
|
* @return dcRecord record instance
|
2021-09-11 09:56:57 +00:00
|
|
|
*/
|
2021-11-06 15:30:19 +00:00
|
|
|
public function getFeeds($params = [], $count_only = false)
|
2021-09-11 09:56:57 +00:00
|
|
|
{
|
|
|
|
if ($count_only) {
|
|
|
|
$strReq = 'SELECT count(Z.feed_id) ';
|
2021-09-12 20:32:21 +00:00
|
|
|
} else {
|
2021-09-11 09:56:57 +00:00
|
|
|
$content_req = '';
|
|
|
|
if (!empty($params['columns']) && is_array($params['columns'])) {
|
2021-09-12 20:32:21 +00:00
|
|
|
$content_req .= implode(', ', $params['columns']) . ', ';
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
|
2021-11-06 15:30:19 +00:00
|
|
|
$strReq = 'SELECT Z.feed_id, Z.feed_creadt, Z.feed_upddt, Z.feed_type, ' .
|
2021-09-12 20:32:21 +00:00
|
|
|
'Z.blog_id, Z.cat_id, ' .
|
|
|
|
'Z.feed_upd_int, Z.feed_upd_last, Z.feed_status, ' .
|
|
|
|
$content_req .
|
|
|
|
'LOWER(Z.feed_name) as lowername, Z.feed_name, Z.feed_desc, ' .
|
|
|
|
'Z.feed_url, Z.feed_feed, Z.feed_get_tags, ' .
|
|
|
|
'Z.feed_tags, Z.feed_owner, Z.feed_tweeter, Z.feed_lang, ' .
|
|
|
|
'Z.feed_nb_out, Z.feed_nb_in, ' .
|
2021-09-11 09:56:57 +00:00
|
|
|
'C.cat_title, C.cat_url, C.cat_desc ';
|
|
|
|
}
|
|
|
|
|
2021-11-06 15:30:19 +00:00
|
|
|
$strReq .= 'FROM ' . $this->table . ' Z ' .
|
2022-11-30 20:54:14 +00:00
|
|
|
'LEFT OUTER JOIN ' . dcCore::app()->prefix . dcCategories::CATEGORY_TABLE_NAME . ' C ON Z.cat_id = C.cat_id ';
|
2021-09-11 09:56:57 +00:00
|
|
|
|
|
|
|
if (!empty($params['from'])) {
|
2021-09-12 20:32:21 +00:00
|
|
|
$strReq .= $params['from'] . ' ';
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
|
2021-09-12 20:32:21 +00:00
|
|
|
$strReq .= "WHERE Z.blog_id = '" . $this->blog . "' ";
|
2021-09-11 09:56:57 +00:00
|
|
|
|
|
|
|
if (isset($params['feed_type'])) {
|
2021-09-12 20:32:21 +00:00
|
|
|
$strReq .= "AND Z.feed_type = '" . $this->con->escape($params['type']) . "' ";
|
|
|
|
} else {
|
2021-09-11 09:56:57 +00:00
|
|
|
$strReq .= "AND Z.feed_type = 'feed' ";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($params['feed_id'])) {
|
|
|
|
if (is_array($params['feed_id'])) {
|
2021-11-06 15:30:19 +00:00
|
|
|
array_walk($params['feed_id'], function (&$v, $k) { if ($v !== null) { $v = (int) $v; }});
|
2021-09-12 20:32:21 +00:00
|
|
|
} else {
|
2021-11-06 15:30:19 +00:00
|
|
|
$params['feed_id'] = [(int) $params['feed_id']];
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
2021-09-12 20:32:21 +00:00
|
|
|
$strReq .= 'AND Z.feed_id ' . $this->con->in($params['feed_id']);
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($params['feed_feed'])) {
|
2021-09-12 20:32:21 +00:00
|
|
|
$strReq .= "AND Z.feed_feed = '" . $this->con->escape($params['feed_feed']) . "' ";
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
if (isset($params['feed_url'])) {
|
2021-09-12 20:32:21 +00:00
|
|
|
$strReq .= "AND Z.feed_url = '" . $this->con->escape($params['feed_url']) . "' ";
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
if (isset($params['feed_status'])) {
|
2021-11-06 15:30:19 +00:00
|
|
|
$strReq .= 'AND Z.feed_status = ' . ((int) $params['feed_status']) . ' ';
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
|
2021-10-10 09:23:02 +00:00
|
|
|
if (!empty($params['q'])) {
|
|
|
|
$q = $this->con->escape(str_replace('*', '%', strtolower($params['q'])));
|
|
|
|
$strReq .= "AND LOWER(Z.feed_name) LIKE '" . $q . "' ";
|
|
|
|
}
|
|
|
|
|
2021-09-11 09:56:57 +00:00
|
|
|
if (!empty($params['sql'])) {
|
2021-09-12 20:32:21 +00:00
|
|
|
$strReq .= $params['sql'] . ' ';
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$count_only) {
|
|
|
|
if (!empty($params['order'])) {
|
2021-09-12 20:32:21 +00:00
|
|
|
$strReq .= 'ORDER BY ' . $this->con->escape($params['order']) . ' ';
|
|
|
|
} else {
|
2021-09-11 09:56:57 +00:00
|
|
|
$strReq .= 'ORDER BY Z.feed_upddt DESC ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$count_only && !empty($params['limit'])) {
|
|
|
|
$strReq .= $this->con->limit($params['limit']);
|
|
|
|
}
|
|
|
|
|
2022-11-20 21:18:34 +00:00
|
|
|
$rs = $this->con->select($strReq);
|
2021-09-11 09:56:57 +00:00
|
|
|
|
|
|
|
return $rs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get next table id.
|
2021-11-06 15:30:19 +00:00
|
|
|
*
|
2022-11-15 20:05:21 +00:00
|
|
|
* @return integer Next id
|
2021-09-11 09:56:57 +00:00
|
|
|
*/
|
|
|
|
private function getNextId()
|
|
|
|
{
|
|
|
|
return $this->con->select(
|
2021-09-12 20:32:21 +00:00
|
|
|
'SELECT MAX(feed_id) FROM ' . $this->table
|
2021-09-11 09:56:57 +00:00
|
|
|
)->f(0) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lock a file to see if an update is ongoing.
|
2021-11-06 15:30:19 +00:00
|
|
|
*
|
2021-09-11 09:56:57 +00:00
|
|
|
* @return boolean True if file is locked
|
|
|
|
*/
|
|
|
|
public function lockUpdate()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
# Need flock function
|
|
|
|
if (!function_exists('flock')) {
|
2021-11-06 15:30:19 +00:00
|
|
|
throw new Exception("Can't call php function named flock");
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
# Cache writable ?
|
|
|
|
if (!is_writable(DC_TPL_CACHE)) {
|
|
|
|
throw new Exception("Can't write in cache fodler");
|
|
|
|
}
|
|
|
|
# Set file path
|
2021-11-06 15:30:19 +00:00
|
|
|
$f_md5 = md5($this->blog);
|
2021-09-11 09:56:57 +00:00
|
|
|
$cached_file = sprintf(
|
|
|
|
'%s/%s/%s/%s/%s.txt',
|
|
|
|
DC_TPL_CACHE,
|
|
|
|
'periodical',
|
|
|
|
substr($f_md5, 0, 2),
|
|
|
|
substr($f_md5, 2, 2),
|
|
|
|
$f_md5
|
|
|
|
);
|
|
|
|
# Real path
|
|
|
|
$cached_file = path::real($cached_file, false);
|
|
|
|
# Make dir
|
|
|
|
if (!is_dir(dirname($cached_file))) {
|
|
|
|
files::makeDir(dirname($cached_file), true);
|
|
|
|
}
|
|
|
|
# Make file
|
|
|
|
if (!file_exists($cached_file)) {
|
|
|
|
!$fp = @fopen($cached_file, 'w');
|
|
|
|
if ($fp === false) {
|
2021-11-06 15:30:19 +00:00
|
|
|
throw new Exception("Can't create file");
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
fwrite($fp, '1', strlen('1'));
|
|
|
|
fclose($fp);
|
|
|
|
}
|
|
|
|
# Open file
|
|
|
|
if (!($fp = @fopen($cached_file, 'r+'))) {
|
2021-11-06 15:30:19 +00:00
|
|
|
throw new Exception("Can't open file");
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
# Lock file
|
|
|
|
if (!flock($fp, LOCK_EX)) {
|
2021-11-06 15:30:19 +00:00
|
|
|
throw new Exception("Can't lock file");
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
$this->lock = $fp;
|
|
|
|
|
|
|
|
return true;
|
2021-09-12 20:32:21 +00:00
|
|
|
} catch (Exception $e) {
|
2021-09-11 09:56:57 +00:00
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unlock file of update process.
|
|
|
|
*/
|
|
|
|
public function unlockUpdate()
|
|
|
|
{
|
|
|
|
@fclose($this->lock);
|
|
|
|
$this->lock = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check and add/update post related to record if needed.
|
2021-11-06 15:30:19 +00:00
|
|
|
*
|
2021-09-11 09:56:57 +00:00
|
|
|
* @param integer $id Feed Id
|
|
|
|
* @param boolean $throw Throw exception or end silently
|
|
|
|
* @return boolean True if process succeed
|
|
|
|
*/
|
2021-09-12 20:32:21 +00:00
|
|
|
public function checkFeedsUpdate($id = null, $throw = false)
|
2021-09-11 09:56:57 +00:00
|
|
|
{
|
2022-12-10 16:16:41 +00:00
|
|
|
$s = dcCore::app()->blog->settings->__get(basename(dirname('../' . __DIR__)));
|
2022-11-26 20:19:55 +00:00
|
|
|
|
|
|
|
# Not configured
|
|
|
|
if (!$s->zoneclearFeedServer_active || !$s->zoneclearFeedServer_user) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-09-11 09:56:57 +00:00
|
|
|
# Limit to one update at a time
|
|
|
|
try {
|
|
|
|
$this->lockUpdate();
|
2021-09-12 20:32:21 +00:00
|
|
|
} catch (Exception $e) {
|
2021-09-11 09:56:57 +00:00
|
|
|
if ($throw) {
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-11-15 20:05:21 +00:00
|
|
|
dt::setTZ(dcCore::app()->blog->settings->system->blog_timezone);
|
2021-09-11 09:56:57 +00:00
|
|
|
$time = time();
|
|
|
|
|
|
|
|
# All feeds or only one (from admin)
|
|
|
|
$f = !$id ?
|
2021-11-06 15:30:19 +00:00
|
|
|
$this->getFeeds(['feed_status' => 1, 'order' => 'feed_upd_last ASC']) :
|
2021-09-12 20:32:21 +00:00
|
|
|
$this->getFeeds(['feed_id' => $id]);
|
2021-09-11 09:56:57 +00:00
|
|
|
|
|
|
|
# No feed
|
|
|
|
if ($f->isEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-12-10 23:07:50 +00:00
|
|
|
$enabled = false;
|
2021-11-06 15:30:19 +00:00
|
|
|
$updates = false;
|
2021-09-12 20:32:21 +00:00
|
|
|
$loop_mem = [];
|
2021-09-11 09:56:57 +00:00
|
|
|
|
2021-11-06 15:30:19 +00:00
|
|
|
$limit = abs((int) $s->zoneclearFeedServer_update_limit);
|
2021-09-11 09:56:57 +00:00
|
|
|
if ($limit < 1) {
|
|
|
|
$limit = 10;
|
|
|
|
}
|
|
|
|
$i = 0;
|
|
|
|
|
2022-11-15 20:05:21 +00:00
|
|
|
$cur_post = $this->con->openCursor(dcCore::app()->prefix . dcBlog::POST_TABLE_NAME);
|
|
|
|
$cur_meta = $this->con->openCursor(dcCore::app()->prefix . dcMeta::META_TABLE_NAME);
|
2021-09-11 09:56:57 +00:00
|
|
|
|
2021-11-06 15:30:19 +00:00
|
|
|
while ($f->fetch()) {
|
2021-09-11 09:56:57 +00:00
|
|
|
# Check if feed need update
|
2022-12-10 23:07:50 +00:00
|
|
|
if ($id
|
|
|
|
|| $i < $limit && $f->feed_status == 1 && ($time > $f->feed_upd_last + $f->feed_upd_int)
|
2021-09-11 09:56:57 +00:00
|
|
|
) {
|
2022-12-10 23:07:50 +00:00
|
|
|
if (!$enabled) {
|
|
|
|
# Set feeds user
|
|
|
|
$this->enableUser(true);
|
|
|
|
$enabled = true;
|
|
|
|
}
|
2021-09-11 09:56:57 +00:00
|
|
|
$i++;
|
|
|
|
$feed = self::readFeed($f->feed_feed);
|
|
|
|
|
|
|
|
# Nothing to parse
|
|
|
|
if (!$feed) {
|
|
|
|
# Keep active empty feed or disable it ?
|
|
|
|
if (!$s->zoneclearFeedServer_keep_empty_feed) {
|
|
|
|
$this->enableFeed($f->feed_id, false);
|
2021-09-12 20:32:21 +00:00
|
|
|
} else {
|
2021-09-11 09:56:57 +00:00
|
|
|
# Set update time of this feed
|
|
|
|
$this->enableFeed($f->feed_id, true, $time);
|
|
|
|
}
|
|
|
|
$i++;
|
2021-09-12 20:32:21 +00:00
|
|
|
|
2021-09-11 09:56:57 +00:00
|
|
|
# Not updated since last visit
|
2021-11-06 15:30:19 +00:00
|
|
|
} elseif (!$id
|
|
|
|
&& '' != $feed->pubdate
|
2021-09-12 20:32:21 +00:00
|
|
|
&& strtotime($feed->pubdate) < $f->feed_upd_last
|
2021-09-11 09:56:57 +00:00
|
|
|
) {
|
|
|
|
# Set update time of this feed
|
|
|
|
$this->enableFeed($f->feed_id, true, $time);
|
|
|
|
$i++;
|
2021-09-12 20:32:21 +00:00
|
|
|
} else {
|
2021-09-11 09:56:57 +00:00
|
|
|
# Set update time of this feed
|
|
|
|
$this->enableFeed($f->feed_id, $f->feed_status, $time);
|
|
|
|
|
|
|
|
$this->con->begin();
|
|
|
|
|
|
|
|
foreach ($feed->items as $item) {
|
|
|
|
$item_TS = $item->TS ? $item->TS : $time;
|
|
|
|
|
|
|
|
// I found that mercurial atom feed did not repect standard
|
|
|
|
$item_link = @$item->link;
|
|
|
|
if (!$item_link) {
|
|
|
|
$item_link = @$item->guid;
|
|
|
|
}
|
|
|
|
# Unknow feed item link
|
|
|
|
if (!$item_link) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-11-06 15:30:19 +00:00
|
|
|
$item_link = $this->con->escape($item_link);
|
2021-09-11 09:56:57 +00:00
|
|
|
$is_new_published_entry = false;
|
|
|
|
|
|
|
|
# Not updated since last visit
|
|
|
|
if (!$id && $item_TS < $f->feed_upd_last) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Fix loop twin
|
|
|
|
if (in_array($item_link, $loop_mem)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$loop_mem[] = $item_link;
|
|
|
|
|
|
|
|
# Check if entry exists
|
|
|
|
$old_post = $this->con->select(
|
2021-09-12 20:32:21 +00:00
|
|
|
'SELECT P.post_id, P.post_status ' .
|
2022-11-15 20:05:21 +00:00
|
|
|
'FROM ' . dcCore::app()->prefix . dcBlog::POST_TABLE_NAME . ' P ' .
|
|
|
|
'INNER JOIN ' . dcCore::app()->prefix . dcMeta::META_TABLE_NAME . ' M ' .
|
2021-09-12 20:32:21 +00:00
|
|
|
'ON P.post_id = M.post_id ' .
|
2021-11-06 15:30:19 +00:00
|
|
|
"WHERE blog_id='" . $this->blog . "' " .
|
2021-09-12 20:32:21 +00:00
|
|
|
"AND meta_type = 'zoneclearfeed_url' " .
|
|
|
|
"AND meta_id = '" . $item_link . "' "
|
2021-09-11 09:56:57 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
# Prepare entry cursor
|
|
|
|
$cur_post->clean();
|
|
|
|
$cur_post->post_dt = date('Y-m-d H:i:s', $item_TS);
|
|
|
|
if ($f->cat_id) {
|
|
|
|
$cur_post->cat_id = $f->cat_id;
|
|
|
|
}
|
2021-11-06 15:30:19 +00:00
|
|
|
$post_content = $item->content ? $item->content : $item->description;
|
2022-11-15 20:05:21 +00:00
|
|
|
$cur_post->post_format = 'xhtml';
|
2021-11-06 15:30:19 +00:00
|
|
|
$cur_post->post_content = html::absoluteURLs($post_content, $feed->link);
|
|
|
|
$cur_post->post_title = $item->title ? $item->title : text::cutString(html::clean($cur_post->post_content), 60);
|
|
|
|
$creator = $item->creator ? $item->creator : $f->feed_owner;
|
2021-09-11 09:56:57 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
# Create entry
|
|
|
|
if ($old_post->isEmpty()) {
|
|
|
|
# Post
|
2022-11-15 20:05:21 +00:00
|
|
|
$cur_post->user_id = dcCore::app()->auth->userID();
|
2021-11-06 15:30:19 +00:00
|
|
|
$cur_post->post_format = 'xhtml';
|
|
|
|
$cur_post->post_status = (int) $s->zoneclearFeedServer_post_status_new;
|
2021-09-11 09:56:57 +00:00
|
|
|
$cur_post->post_open_comment = 0;
|
2021-11-06 15:30:19 +00:00
|
|
|
$cur_post->post_open_tb = 0;
|
2021-09-11 09:56:57 +00:00
|
|
|
|
|
|
|
# --BEHAVIOR-- zoneclearFeedServerBeforePostCreate
|
2022-11-15 20:05:21 +00:00
|
|
|
dcCore::app()->callBehavior(
|
2021-09-11 09:56:57 +00:00
|
|
|
'zoneclearFeedServerBeforePostCreate',
|
|
|
|
$cur_post
|
|
|
|
);
|
|
|
|
|
2022-11-15 20:05:21 +00:00
|
|
|
$post_id = dcCore::app()->auth->sudo(
|
|
|
|
[dcCore::app()->blog, 'addPost'],
|
2021-09-11 09:56:57 +00:00
|
|
|
$cur_post
|
|
|
|
);
|
|
|
|
|
|
|
|
# --BEHAVIOR-- zoneclearFeedServerAfterPostCreate
|
2022-11-15 20:05:21 +00:00
|
|
|
dcCore::app()->callBehavior(
|
2021-09-11 09:56:57 +00:00
|
|
|
'zoneclearFeedServerAfterPostCreate',
|
|
|
|
$cur_post,
|
|
|
|
$post_id
|
|
|
|
);
|
|
|
|
|
|
|
|
# Auto tweet new post
|
|
|
|
if ($cur_post->post_status == 1) {
|
|
|
|
$is_new_published_entry = true;
|
|
|
|
}
|
2021-09-12 20:32:21 +00:00
|
|
|
|
2022-11-15 20:05:21 +00:00
|
|
|
# Update entry
|
2021-09-12 20:32:21 +00:00
|
|
|
} else {
|
2021-09-11 09:56:57 +00:00
|
|
|
$post_id = $old_post->post_id;
|
|
|
|
|
|
|
|
# --BEHAVIOR-- zoneclearFeedServerBeforePostUpdate
|
2022-11-15 20:05:21 +00:00
|
|
|
dcCore::app()->callBehavior(
|
2021-09-11 09:56:57 +00:00
|
|
|
'zoneclearFeedServerBeforePostUpdate',
|
|
|
|
$cur_post,
|
|
|
|
$post_id
|
|
|
|
);
|
|
|
|
|
2022-11-15 20:05:21 +00:00
|
|
|
dcCore::app()->auth->sudo(
|
|
|
|
[dcCore::app()->blog, 'updPost'],
|
2021-09-11 09:56:57 +00:00
|
|
|
$post_id,
|
|
|
|
$cur_post
|
|
|
|
);
|
|
|
|
|
|
|
|
# Quick delete old meta
|
|
|
|
$this->con->execute(
|
2022-11-15 20:05:21 +00:00
|
|
|
'DELETE FROM ' . dcCore::app()->prefix . dcMeta::META_TABLE_NAME . ' ' .
|
2021-11-06 15:30:19 +00:00
|
|
|
'WHERE post_id = ' . $post_id . ' ' .
|
2021-09-11 09:56:57 +00:00
|
|
|
"AND meta_type LIKE 'zoneclearfeed_%' "
|
|
|
|
);
|
2022-11-15 20:05:21 +00:00
|
|
|
|
2021-09-11 09:56:57 +00:00
|
|
|
# Delete old tags
|
2022-11-15 20:05:21 +00:00
|
|
|
dcCore::app()->auth->sudo(
|
|
|
|
[dcCore::app()->meta, 'delPostMeta'],
|
2021-09-11 09:56:57 +00:00
|
|
|
$post_id,
|
|
|
|
'tag'
|
|
|
|
);
|
|
|
|
|
|
|
|
# --BEHAVIOR-- zoneclearFeedServerAfterPostUpdate
|
2022-11-15 20:05:21 +00:00
|
|
|
dcCore::app()->callBehavior(
|
2021-09-11 09:56:57 +00:00
|
|
|
'zoneclearFeedServerAfterPostUpdate',
|
|
|
|
$cur_post,
|
|
|
|
$post_id
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Quick add new meta
|
2021-11-06 15:30:19 +00:00
|
|
|
$meta = new ArrayObject();
|
2021-09-11 09:56:57 +00:00
|
|
|
$meta->tweeter = $f->feed_tweeter;
|
|
|
|
|
|
|
|
$cur_meta->clean();
|
2021-11-06 15:30:19 +00:00
|
|
|
$cur_meta->post_id = $post_id;
|
2021-09-11 09:56:57 +00:00
|
|
|
$cur_meta->meta_type = 'zoneclearfeed_url';
|
2022-11-15 20:05:21 +00:00
|
|
|
$cur_meta->meta_id = $meta->url = $item_link;
|
2021-09-11 09:56:57 +00:00
|
|
|
$cur_meta->insert();
|
|
|
|
|
|
|
|
$cur_meta->clean();
|
2021-11-06 15:30:19 +00:00
|
|
|
$cur_meta->post_id = $post_id;
|
2021-09-11 09:56:57 +00:00
|
|
|
$cur_meta->meta_type = 'zoneclearfeed_author';
|
2022-11-15 20:05:21 +00:00
|
|
|
$cur_meta->meta_id = $meta->author = $creator;
|
2021-09-11 09:56:57 +00:00
|
|
|
$cur_meta->insert();
|
|
|
|
|
|
|
|
$cur_meta->clean();
|
2021-11-06 15:30:19 +00:00
|
|
|
$cur_meta->post_id = $post_id;
|
2021-09-11 09:56:57 +00:00
|
|
|
$cur_meta->meta_type = 'zoneclearfeed_site';
|
2022-11-15 20:05:21 +00:00
|
|
|
$cur_meta->meta_id = $meta->site = $f->feed_url;
|
2021-09-11 09:56:57 +00:00
|
|
|
$cur_meta->insert();
|
|
|
|
|
|
|
|
$cur_meta->clean();
|
2021-11-06 15:30:19 +00:00
|
|
|
$cur_meta->post_id = $post_id;
|
2021-09-11 09:56:57 +00:00
|
|
|
$cur_meta->meta_type = 'zoneclearfeed_sitename';
|
2022-11-15 20:05:21 +00:00
|
|
|
$cur_meta->meta_id = $meta->sitename = $f->feed_name;
|
2021-09-11 09:56:57 +00:00
|
|
|
$cur_meta->insert();
|
|
|
|
|
|
|
|
$cur_meta->clean();
|
2021-11-06 15:30:19 +00:00
|
|
|
$cur_meta->post_id = $post_id;
|
2021-09-11 09:56:57 +00:00
|
|
|
$cur_meta->meta_type = 'zoneclearfeed_id';
|
2022-11-15 20:05:21 +00:00
|
|
|
$cur_meta->meta_id = $meta->id = $f->feed_id;
|
2021-09-11 09:56:57 +00:00
|
|
|
$cur_meta->insert();
|
|
|
|
|
|
|
|
# Add new tags
|
2022-11-15 20:05:21 +00:00
|
|
|
$tags = dcCore::app()->meta->splitMetaValues($f->feed_tags);
|
2021-09-11 09:56:57 +00:00
|
|
|
if ($f->feed_get_tags) {
|
|
|
|
# Some feed subjects contains more than one tag
|
2021-11-06 15:30:19 +00:00
|
|
|
foreach ($item->subject as $subjects) {
|
2022-11-15 20:05:21 +00:00
|
|
|
$tmp = dcCore::app()->meta->splitMetaValues($subjects);
|
2021-09-11 09:56:57 +00:00
|
|
|
$tags = array_merge($tags, $tmp);
|
|
|
|
}
|
|
|
|
$tags = array_unique($tags);
|
|
|
|
}
|
2021-09-12 20:32:21 +00:00
|
|
|
$formated_tags = [];
|
2021-09-11 09:56:57 +00:00
|
|
|
foreach ($tags as $tag) {
|
|
|
|
# Change tags case
|
2021-11-06 15:30:19 +00:00
|
|
|
switch ((int) $s->zoneclearFeedServer_tag_case) {
|
|
|
|
case 3: $tag = strtoupper($tag);
|
|
|
|
|
2022-11-15 20:05:21 +00:00
|
|
|
break;
|
2021-11-06 15:30:19 +00:00
|
|
|
case 2: $tag = strtolower($tag);
|
|
|
|
|
2022-11-15 20:05:21 +00:00
|
|
|
break;
|
2021-11-06 15:30:19 +00:00
|
|
|
case 1: $tag = ucfirst(strtolower($tag));
|
|
|
|
|
2022-11-15 20:05:21 +00:00
|
|
|
break;
|
2021-09-12 20:32:21 +00:00
|
|
|
default: /* do nothing */ break;
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
if (!in_array($tag, $formated_tags)) {
|
|
|
|
$formated_tags[] = $tag;
|
2022-11-15 20:05:21 +00:00
|
|
|
dcCore::app()->auth->sudo(
|
|
|
|
[dcCore::app()->meta, 'delPostMeta'],
|
|
|
|
$post_id,
|
|
|
|
'tag',
|
|
|
|
dcMeta::sanitizeMetaID($tag)
|
|
|
|
);
|
|
|
|
dcCore::app()->auth->sudo(
|
|
|
|
[dcCore::app()->meta, 'setPostMeta'],
|
2021-09-11 09:56:57 +00:00
|
|
|
$post_id,
|
|
|
|
'tag',
|
|
|
|
dcMeta::sanitizeMetaID($tag)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$meta->tags = $formated_tags;
|
|
|
|
|
|
|
|
# --BEHAVIOR-- zoneclearFeedServerAfterFeedUpdate
|
2022-11-15 20:05:21 +00:00
|
|
|
dcCore::app()->callBehavior(
|
2021-09-11 09:56:57 +00:00
|
|
|
'zoneclearFeedServerAfterFeedUpdate',
|
|
|
|
$is_new_published_entry,
|
|
|
|
$cur_post,
|
|
|
|
$meta
|
|
|
|
);
|
2021-09-12 20:32:21 +00:00
|
|
|
} catch (Exception $e) {
|
2021-09-11 09:56:57 +00:00
|
|
|
$this->con->rollback();
|
|
|
|
$this->enableUser(false);
|
|
|
|
$this->unlockUpdate();
|
2021-11-06 15:30:19 +00:00
|
|
|
|
2021-09-11 09:56:57 +00:00
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
$updates = true;
|
|
|
|
}
|
|
|
|
$this->con->commit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-10 23:07:50 +00:00
|
|
|
if ($enabled) {
|
|
|
|
$this->enableUser(false);
|
|
|
|
}
|
2021-09-11 09:56:57 +00:00
|
|
|
$this->unlockUpdate();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set permission to update post table.
|
2021-11-06 15:30:19 +00:00
|
|
|
*
|
2021-09-11 09:56:57 +00:00
|
|
|
* @param boolean $enable Enable or disable perm
|
|
|
|
*/
|
2021-09-12 20:32:21 +00:00
|
|
|
public function enableUser($enable = false)
|
2021-09-11 09:56:57 +00:00
|
|
|
{
|
|
|
|
# Enable
|
|
|
|
if ($enable) {
|
2022-12-10 22:21:08 +00:00
|
|
|
// backup current user
|
2022-11-15 20:05:21 +00:00
|
|
|
$this->user = dcCore::app()->auth->userID();
|
2022-12-10 22:21:08 +00:00
|
|
|
// set zcfs posts user
|
|
|
|
if (!dcCore::app()->auth->checkUser((string) dcCore::app()->blog->settings->__get(basename(dirname('../' . __DIR__)))->zoneclearFeedServer_user)) {
|
2021-09-11 09:56:57 +00:00
|
|
|
throw new Exception('Unable to set user');
|
|
|
|
}
|
2022-11-15 20:05:21 +00:00
|
|
|
# Disable
|
2021-09-12 20:32:21 +00:00
|
|
|
} else {
|
2022-11-15 20:05:21 +00:00
|
|
|
dcCore::app()->auth = null;
|
|
|
|
dcCore::app()->auth = new dcAuth();
|
2022-12-10 22:21:08 +00:00
|
|
|
// restore current user
|
2022-11-30 23:49:34 +00:00
|
|
|
dcCore::app()->auth->checkUser($this->user ?? '');
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read and parse external feeds.
|
2021-11-06 15:30:19 +00:00
|
|
|
*
|
2021-09-11 09:56:57 +00:00
|
|
|
* @param string $f Feed URL
|
2022-12-10 22:02:38 +00:00
|
|
|
* @return feedParser|false Parsed feed
|
2021-09-11 09:56:57 +00:00
|
|
|
*/
|
|
|
|
public static function readFeed($f)
|
|
|
|
{
|
|
|
|
try {
|
2021-11-06 15:30:19 +00:00
|
|
|
$feed_reader = new feedReader();
|
2021-09-11 09:56:57 +00:00
|
|
|
$feed_reader->setCacheDir(DC_TPL_CACHE);
|
|
|
|
$feed_reader->setTimeout(self::$nethttp_timeout);
|
|
|
|
$feed_reader->setMaxRedirects(self::$nethttp_maxredirect);
|
|
|
|
$feed_reader->setUserAgent(self::$nethttp_agent);
|
|
|
|
|
|
|
|
return $feed_reader->parse($f);
|
2021-09-12 20:32:21 +00:00
|
|
|
} catch (Exception $e) {
|
2022-12-10 22:02:38 +00:00
|
|
|
return false;
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Trigger.
|
|
|
|
*/
|
|
|
|
private function trigger()
|
|
|
|
{
|
2022-11-15 20:05:21 +00:00
|
|
|
dcCore::app()->blog->triggerBlog();
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if an URL is well formed
|
2021-11-06 15:30:19 +00:00
|
|
|
*
|
2021-09-11 09:56:57 +00:00
|
|
|
* @param string $url URL
|
|
|
|
* @return Boolean True if URL is allowed
|
|
|
|
*/
|
|
|
|
public static function validateURL($url)
|
|
|
|
{
|
2021-11-06 15:30:19 +00:00
|
|
|
return false !== strpos($url, 'http://')
|
2021-09-12 20:32:21 +00:00
|
|
|
|| false !== strpos($url, 'https://');
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get full URL.
|
|
|
|
*
|
|
|
|
* Know bugs: anchor is not well parsed.
|
2021-11-06 15:30:19 +00:00
|
|
|
*
|
2021-09-11 09:56:57 +00:00
|
|
|
* @param string $root Root URL
|
|
|
|
* @param string $url An URL
|
|
|
|
* @return string Parse URL
|
|
|
|
*/
|
|
|
|
public static function absoluteURL($root, $url)
|
|
|
|
{
|
|
|
|
$host = preg_replace(
|
|
|
|
'|^([a-z]{3,}://)(.*?)/(.*)$|',
|
|
|
|
'$1$2',
|
|
|
|
$root
|
|
|
|
);
|
|
|
|
|
|
|
|
$parse = parse_url($url);
|
|
|
|
|
|
|
|
if (empty($parse['scheme'])) {
|
2021-09-12 20:32:21 +00:00
|
|
|
if (strpos($url, '/') === 0) {
|
|
|
|
$url = $host . $url;
|
|
|
|
} elseif (strpos($url, '#') === 0) {
|
|
|
|
$url = $root . $url;
|
|
|
|
} elseif (preg_match('|/$|', $root)) {
|
|
|
|
$url = $root . $url;
|
|
|
|
} else {
|
|
|
|
$url = dirname($root) . '/' . $url;
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get list of feeds status.
|
2021-11-06 15:30:19 +00:00
|
|
|
*
|
2021-09-11 09:56:57 +00:00
|
|
|
* @return array List of names/values of feeds status
|
|
|
|
*/
|
|
|
|
public static function getAllStatus()
|
|
|
|
{
|
2021-09-12 20:32:21 +00:00
|
|
|
return [
|
|
|
|
__('Disabled') => '0',
|
2022-11-15 20:05:21 +00:00
|
|
|
__('Enabled') => '1',
|
2021-09-12 20:32:21 +00:00
|
|
|
];
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get list of predefined interval.
|
2021-11-06 15:30:19 +00:00
|
|
|
*
|
2021-09-11 09:56:57 +00:00
|
|
|
* @return array List of Name/time of intervals
|
|
|
|
*/
|
|
|
|
public static function getAllUpdateInterval()
|
|
|
|
{
|
2021-09-12 20:32:21 +00:00
|
|
|
return [
|
2021-09-11 09:56:57 +00:00
|
|
|
__('Every hour') => 3600,
|
2021-09-12 20:32:21 +00:00
|
|
|
__('Every two hours') => 7200,
|
|
|
|
__('Two times per day') => 43200,
|
|
|
|
__('Every day') => 86400,
|
2021-09-11 09:56:57 +00:00
|
|
|
__('Every two days') => 172800,
|
2022-11-15 20:05:21 +00:00
|
|
|
__('Every week') => 604800,
|
2021-09-12 20:32:21 +00:00
|
|
|
];
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get list of (super)admins of current blog.
|
2021-11-06 15:30:19 +00:00
|
|
|
*
|
2021-09-11 09:56:57 +00:00
|
|
|
* @return array List of UserCNs/UserIds
|
|
|
|
*/
|
|
|
|
public function getAllBlogAdmins()
|
|
|
|
{
|
2021-09-12 20:32:21 +00:00
|
|
|
$admins = [];
|
2021-09-11 09:56:57 +00:00
|
|
|
|
|
|
|
# Get super admins
|
|
|
|
$rs = $this->con->select(
|
2021-09-12 20:32:21 +00:00
|
|
|
'SELECT user_id, user_super, user_name, user_firstname, user_displayname ' .
|
2022-11-30 20:59:20 +00:00
|
|
|
'FROM ' . $this->con->escapeSystem(dcCore::app()->prefix . dcAuth::USER_TABLE_NAME) . ' ' .
|
2021-09-11 09:56:57 +00:00
|
|
|
'WHERE user_super = 1 AND user_status = 1 '
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!$rs->isEmpty()) {
|
|
|
|
while ($rs->fetch()) {
|
|
|
|
$user_cn = dcUtils::getUserCN(
|
|
|
|
$rs->user_id,
|
|
|
|
$rs->user_name,
|
|
|
|
$rs->user_firstname,
|
|
|
|
$rs->user_displayname
|
|
|
|
);
|
2021-09-12 20:32:21 +00:00
|
|
|
$admins[$user_cn . ' (super admin)'] = $rs->user_id;
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get admins
|
|
|
|
$rs = $this->con->select(
|
2021-09-12 20:32:21 +00:00
|
|
|
'SELECT U.user_id, U.user_super, U.user_name, U.user_firstname, U.user_displayname ' .
|
2022-11-30 20:59:20 +00:00
|
|
|
'FROM ' . $this->con->escapeSystem(dcCore::app()->prefix . dcAuth::USER_TABLE_NAME) . ' U ' .
|
2022-11-30 20:54:14 +00:00
|
|
|
'LEFT JOIN ' . $this->con->escapeSystem(dcCore::app()->prefix . dcAuth::PERMISSIONS_TABLE_NAME) . ' P ' .
|
2021-09-12 20:32:21 +00:00
|
|
|
'ON U.user_id=P.user_id ' .
|
2021-11-06 15:30:19 +00:00
|
|
|
'WHERE U.user_status = 1 ' .
|
|
|
|
"AND P.blog_id = '" . $this->blog . "' " .
|
2021-09-11 09:56:57 +00:00
|
|
|
"AND P.permissions LIKE '%|admin|%' "
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!$rs->isEmpty()) {
|
|
|
|
while ($rs->fetch()) {
|
|
|
|
$user_cn = dcUtils::getUserCN(
|
|
|
|
$rs->user_id,
|
|
|
|
$rs->user_name,
|
|
|
|
$rs->user_firstname,
|
|
|
|
$rs->user_displayname
|
|
|
|
);
|
2021-09-12 20:32:21 +00:00
|
|
|
$admins[$user_cn . ' (admin)'] = $rs->user_id;
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $admins;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get list of urls where entries could be hacked.
|
2021-11-06 15:30:19 +00:00
|
|
|
*
|
2021-09-11 09:56:57 +00:00
|
|
|
* @return array List of names/types of URLs
|
|
|
|
*/
|
2022-11-15 20:05:21 +00:00
|
|
|
public static function getPublicUrlTypes()
|
2021-09-11 09:56:57 +00:00
|
|
|
{
|
2021-11-06 15:30:19 +00:00
|
|
|
$types = [];
|
2021-09-11 09:56:57 +00:00
|
|
|
|
|
|
|
# --BEHAVIOR-- zoneclearFeedServerPublicUrlTypes
|
2022-11-15 20:05:21 +00:00
|
|
|
dcCore::app()->callBehavior('zoneclearFeedServerPublicUrlTypes', $types);
|
2021-09-11 09:56:57 +00:00
|
|
|
|
2021-09-12 20:32:21 +00:00
|
|
|
$types[__('Home page')] = 'default';
|
|
|
|
$types[__('Entries pages')] = 'post';
|
|
|
|
$types[__('Tags pages')] = 'tag';
|
|
|
|
$types[__('Archives pages')] = 'archive';
|
|
|
|
$types[__('Category pages')] = 'category';
|
|
|
|
$types[__('Entries feed')] = 'feed';
|
2021-09-11 09:56:57 +00:00
|
|
|
|
|
|
|
return $types;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Take care about plugin tweakurls (thanks Mathieu M.).
|
2021-11-06 15:30:19 +00:00
|
|
|
*
|
2021-09-11 09:56:57 +00:00
|
|
|
* @param cursor $cur cursor instance
|
|
|
|
* @param integer $id Post Id
|
|
|
|
*/
|
|
|
|
public static function tweakurlsAfterPostCreate(cursor $cur, $id)
|
|
|
|
{
|
2022-12-10 22:02:38 +00:00
|
|
|
if (version_compare(dcCore::app()->plugins->moduleInfo('tweakurls', 'version'), '0.8', '>=')) {
|
|
|
|
$cur->post_url = tweakUrls::tweakBlogURL($cur->post_url);
|
|
|
|
dcCore::app()->auth->sudo([dcCore::app()->blog, 'updPost'], $id, $cur);
|
|
|
|
}
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
2021-11-06 15:30:19 +00:00
|
|
|
}
|