fix php 8 deprecated function, clean code

This commit is contained in:
Jean-Christian Denis 2021-09-12 22:32:21 +02:00
parent 0ae0ca03d1
commit 234a496ac4
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951

View file

@ -12,7 +12,6 @@
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -72,6 +71,7 @@ class zoneclearFeedServer
if ($id < 1) { if ($id < 1) {
throw new Exception(__('No such ID')); throw new Exception(__('No such ID'));
} }
$cur->feed_upddt = date('Y-m-d H:i:s'); $cur->feed_upddt = date('Y-m-d H:i:s');
$cur->update(sprintf( $cur->update(sprintf(
@ -81,8 +81,7 @@ class zoneclearFeedServer
)); ));
$this->con->unlock(); $this->con->unlock();
$this->trigger(); $this->trigger();
} } catch (Exception $e) {
catch (Exception $e) {
$this->con->unlock(); $this->con->unlock();
throw $e; throw $e;
} }
@ -115,8 +114,7 @@ class zoneclearFeedServer
$cur->insert(); $cur->insert();
$this->con->unlock(); $this->con->unlock();
$this->trigger(); $this->trigger();
} } catch (Exception $e) {
catch (Exception $e) {
$this->con->unlock(); $this->con->unlock();
throw $e; throw $e;
} }
@ -145,11 +143,11 @@ class zoneclearFeedServer
if ($id < 1) { if ($id < 1) {
throw new Exception(__('No such ID')); throw new Exception(__('No such ID'));
} }
$cur = $this->openCursor(); $cur = $this->openCursor();
$this->con->writeLock($this->table); $this->con->writeLock($this->table);
$cur->feed_upddt = date('Y-m-d H:i:s'); $cur->feed_upddt = date('Y-m-d H:i:s');
$cur->feed_status = (integer) $enable; $cur->feed_status = (integer) $enable;
if (null !== $time) { if (null !== $time) {
$cur->feed_upd_last = (integer) $time; $cur->feed_upd_last = (integer) $time;
@ -162,8 +160,7 @@ class zoneclearFeedServer
)); ));
$this->con->unlock(); $this->con->unlock();
$this->trigger(); $this->trigger();
} } catch (Exception $e) {
catch (Exception $e) {
$this->con->unlock(); $this->con->unlock();
throw $e; throw $e;
} }
@ -216,7 +213,6 @@ class zoneclearFeedServer
public function getPostsByFeed($params = array(), $count_only = false) public function getPostsByFeed($params = array(), $count_only = false)
{ {
if (!isset($params['feed_id'])) { if (!isset($params['feed_id'])) {
return null; return null;
} }
@ -244,8 +240,7 @@ class zoneclearFeedServer
{ {
if ($count_only) { if ($count_only) {
$strReq = 'SELECT count(Z.feed_id) '; $strReq = 'SELECT count(Z.feed_id) ';
} } else {
else {
$content_req = ''; $content_req = '';
if (!empty($params['columns']) && is_array($params['columns'])) { if (!empty($params['columns']) && is_array($params['columns'])) {
$content_req .= implode(', ', $params['columns']) . ', '; $content_req .= implode(', ', $params['columns']) . ', ';
@ -275,17 +270,15 @@ class zoneclearFeedServer
if (isset($params['feed_type'])) { if (isset($params['feed_type'])) {
$strReq .= "AND Z.feed_type = '" . $this->con->escape($params['type']) . "' "; $strReq .= "AND Z.feed_type = '" . $this->con->escape($params['type']) . "' ";
} } else {
else {
$strReq .= "AND Z.feed_type = 'feed' "; $strReq .= "AND Z.feed_type = 'feed' ";
} }
if (!empty($params['feed_id'])) { if (!empty($params['feed_id'])) {
if (is_array($params['feed_id'])) { if (is_array($params['feed_id'])) {
array_walk($params['feed_id'],create_function('&$v,$k','if($v!==null){$v=(integer)$v;}')); array_walk($params['feed_id'], function(&$v, $k) { if($v !== null) { $v = (integer) $v; }});
} } else {
else { $params['feed_id'] = [(integer) $params['feed_id']];
$params['feed_id'] = array((integer) $params['feed_id']);
} }
$strReq .= 'AND Z.feed_id ' . $this->con->in($params['feed_id']); $strReq .= 'AND Z.feed_id ' . $this->con->in($params['feed_id']);
} }
@ -307,8 +300,7 @@ class zoneclearFeedServer
if (!$count_only) { if (!$count_only) {
if (!empty($params['order'])) { if (!empty($params['order'])) {
$strReq .= 'ORDER BY ' . $this->con->escape($params['order']) . ' '; $strReq .= 'ORDER BY ' . $this->con->escape($params['order']) . ' ';
} } else {
else {
$strReq .= 'ORDER BY Z.feed_upddt DESC '; $strReq .= 'ORDER BY Z.feed_upddt DESC ';
} }
} }
@ -387,8 +379,7 @@ class zoneclearFeedServer
$this->lock = $fp; $this->lock = $fp;
return true; return true;
} } catch (Exception $e) {
catch (Exception $e) {
throw $e; throw $e;
} }
@ -417,8 +408,7 @@ class zoneclearFeedServer
# Limit to one update at a time # Limit to one update at a time
try { try {
$this->lockUpdate(); $this->lockUpdate();
} } catch (Exception $e) {
catch (Exception $e) {
if ($throw) { if ($throw) {
throw $e; throw $e;
} }
@ -432,17 +422,11 @@ class zoneclearFeedServer
# All feeds or only one (from admin) # All feeds or only one (from admin)
$f = !$id ? $f = !$id ?
$this->getFeeds(array( $this->getFeeds(['feed_status' => 1, 'order' => 'feed_upd_last ASC']) :
'feed_status'=>1, $this->getFeeds(['feed_id' => $id]);
'order'=>'feed_upd_last ASC'
)) :
$this->getFeeds(array(
'feed_id'=>$id
));
# No feed # No feed
if ($f->isEmpty()) { if ($f->isEmpty()) {
return false; return false;
} }
@ -450,7 +434,7 @@ class zoneclearFeedServer
$this->enableUser($s->zoneclearFeedServer_user); $this->enableUser($s->zoneclearFeedServer_user);
$updates = false; $updates = false;
$loop_mem = array(); $loop_mem = [];
$limit = abs((integer) $s->zoneclearFeedServer_update_limit); $limit = abs((integer) $s->zoneclearFeedServer_update_limit);
if ($limit < 1) { if ($limit < 1) {
@ -474,23 +458,21 @@ class zoneclearFeedServer
# Keep active empty feed or disable it ? # Keep active empty feed or disable it ?
if (!$s->zoneclearFeedServer_keep_empty_feed) { if (!$s->zoneclearFeedServer_keep_empty_feed) {
$this->enableFeed($f->feed_id, false); $this->enableFeed($f->feed_id, false);
} } else {
else {
# Set update time of this feed # Set update time of this feed
$this->enableFeed($f->feed_id, true, $time); $this->enableFeed($f->feed_id, true, $time);
} }
$i++; $i++;
}
# Not updated since last visit # Not updated since last visit
elseif (!$id } elseif (!$id
&& '' != $feed->pubdate && '' != $feed->pubdate
&& strtotime($feed->pubdate) < $f->feed_upd_last && strtotime($feed->pubdate) < $f->feed_upd_last
) { ) {
# Set update time of this feed # Set update time of this feed
$this->enableFeed($f->feed_id, true, $time); $this->enableFeed($f->feed_id, true, $time);
$i++; $i++;
} } else {
else {
# Set update time of this feed # Set update time of this feed
$this->enableFeed($f->feed_id, $f->feed_status, $time); $this->enableFeed($f->feed_id, $f->feed_status, $time);
@ -562,7 +544,7 @@ class zoneclearFeedServer
); );
$post_id = $this->core->auth->sudo( $post_id = $this->core->auth->sudo(
array($this->core->blog, 'addPost'), [$this->core->blog, 'addPost'],
$cur_post $cur_post
); );
@ -577,9 +559,9 @@ class zoneclearFeedServer
if ($cur_post->post_status == 1) { if ($cur_post->post_status == 1) {
$is_new_published_entry = true; $is_new_published_entry = true;
} }
}
# Update entry # Update entry
else { } else {
$post_id = $old_post->post_id; $post_id = $old_post->post_id;
# --BEHAVIOR-- zoneclearFeedServerBeforePostUpdate # --BEHAVIOR-- zoneclearFeedServerBeforePostUpdate
@ -590,7 +572,7 @@ class zoneclearFeedServer
); );
$this->core->auth->sudo( $this->core->auth->sudo(
array($this->core->blog, 'updPost'), [$this->core->blog, 'updPost'],
$post_id, $post_id,
$cur_post $cur_post
); );
@ -603,7 +585,7 @@ class zoneclearFeedServer
); );
# Delete old tags # Delete old tags
$this->core->auth->sudo( $this->core->auth->sudo(
array($this->core->meta, 'delPostMeta'), [$this->core->meta, 'delPostMeta'],
$post_id, $post_id,
'tag' 'tag'
); );
@ -661,7 +643,7 @@ class zoneclearFeedServer
} }
$tags = array_unique($tags); $tags = array_unique($tags);
} }
$formated_tags = array(); $formated_tags = [];
foreach ($tags as $tag) { foreach ($tags as $tag) {
# Change tags case # Change tags case
@ -674,7 +656,7 @@ class zoneclearFeedServer
if (!in_array($tag, $formated_tags)) { if (!in_array($tag, $formated_tags)) {
$formated_tags[] = $tag; $formated_tags[] = $tag;
$this->core->auth->sudo( $this->core->auth->sudo(
array($this->core->meta, 'setPostMeta'), [$this->core->meta, 'setPostMeta'],
$post_id, $post_id,
'tag', 'tag',
dcMeta::sanitizeMetaID($tag) dcMeta::sanitizeMetaID($tag)
@ -692,8 +674,7 @@ class zoneclearFeedServer
$meta $meta
); );
} } catch (Exception $e) {
catch (Exception $e) {
$this->con->rollback(); $this->con->rollback();
$this->enableUser(false); $this->enableUser(false);
$this->unlockUpdate(); $this->unlockUpdate();
@ -723,9 +704,8 @@ class zoneclearFeedServer
if (!$this->core->auth->checkUser($enable)) { if (!$this->core->auth->checkUser($enable)) {
throw new Exception('Unable to set user'); throw new Exception('Unable to set user');
} }
}
# Disable # Disable
else { } else {
$this->core->auth = null; $this->core->auth = null;
$this->core->auth = new dcAuth($this->core); $this->core->auth = new dcAuth($this->core);
} }
@ -747,9 +727,7 @@ class zoneclearFeedServer
$feed_reader->setUserAgent(self::$nethttp_agent); $feed_reader->setUserAgent(self::$nethttp_agent);
return $feed_reader->parse($f); return $feed_reader->parse($f);
} } catch (Exception $e) {
catch (Exception $e) {
return null; return null;
} }
} }
@ -796,14 +774,11 @@ class zoneclearFeedServer
if (empty($parse['scheme'])) { if (empty($parse['scheme'])) {
if (strpos($url, '/') === 0) { if (strpos($url, '/') === 0) {
$url = $host . $url; $url = $host . $url;
} } elseif (strpos($url, '#') === 0) {
elseif (strpos($url, '#') === 0) {
$url = $root . $url; $url = $root . $url;
} } elseif (preg_match('|/$|', $root)) {
elseif (preg_match('|/$|', $root)) {
$url = $root . $url; $url = $root . $url;
} } else {
else {
$url = dirname($root) . '/' . $url; $url = dirname($root) . '/' . $url;
} }
} }
@ -818,10 +793,10 @@ class zoneclearFeedServer
*/ */
public static function getAllStatus() public static function getAllStatus()
{ {
return array( return [
__('Disabled') => '0', __('Disabled') => '0',
__('Enabled') => '1' __('Enabled') => '1'
); ];
} }
/** /**
@ -831,14 +806,14 @@ class zoneclearFeedServer
*/ */
public static function getAllUpdateInterval() public static function getAllUpdateInterval()
{ {
return array( return [
__('Every hour') => 3600, __('Every hour') => 3600,
__('Every two hours') => 7200, __('Every two hours') => 7200,
__('Two times per day') => 43200, __('Two times per day') => 43200,
__('Every day') => 86400, __('Every day') => 86400,
__('Every two days') => 172800, __('Every two days') => 172800,
__('Every week') => 604800 __('Every week') => 604800
); ];
} }
/** /**
@ -848,7 +823,7 @@ class zoneclearFeedServer
*/ */
public function getAllBlogAdmins() public function getAllBlogAdmins()
{ {
$admins = array(); $admins = [];
# Get super admins # Get super admins
$rs = $this->con->select( $rs = $this->con->select(