clean up class, fix php7.3+

This commit is contained in:
Jean-Christian Paul Denis 2021-09-08 01:47:45 +02:00
parent 02d56c5c96
commit 0f17585cad
3 changed files with 97 additions and 113 deletions

View File

@ -12,7 +12,6 @@
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -54,12 +53,11 @@ class cinecturlink2
* @param boolean $count_only Count only result * @param boolean $count_only Count only result
* @return record record instance * @return record record instance
*/ */
public function getLinks($params=array(), $count_only=false) public function getLinks($params = [], $count_only = false)
{ {
if ($count_only) { if ($count_only) {
$strReq = 'SELECT count(L.link_id) '; $strReq = 'SELECT count(L.link_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']) . ', ';
@ -90,31 +88,27 @@ class cinecturlink2
if (isset($params['link_type'])) { if (isset($params['link_type'])) {
if (is_array($params['link_type']) && !empty($params['link_type'])) { if (is_array($params['link_type']) && !empty($params['link_type'])) {
$strReq .= 'AND L.link_type ' . $this->con->in($params['link_type']); $strReq .= 'AND L.link_type ' . $this->con->in($params['link_type']);
} } elseif ($params['link_type'] != '') {
elseif ($params['link_type'] != '') {
$strReq .= "AND L.link_type = '" . $this->con->escape($params['link_type']) . "' "; $strReq .= "AND L.link_type = '" . $this->con->escape($params['link_type']) . "' ";
} }
} } else {
else {
$strReq .= "AND L.link_type = 'cinecturlink' "; $strReq .= "AND L.link_type = 'cinecturlink' ";
} }
if (!empty($params['link_id'])) { if (!empty($params['link_id'])) {
if (is_array($params['link_id'])) { if (is_array($params['link_id'])) {
array_walk($params['link_id'], create_function('&$v,$k', 'if($v!==null){$v=(integer)$v;}')); array_walk($params['link_id'], function(&$v, $k'){ if($v !== null) { $v = (integer) $v;}});
} } else {
else { $params['link_id'] = [(integer) $params['link_id']];
$params['link_id'] = array((integer) $params['link_id']);
} }
$strReq .= 'AND L.link_id ' . $this->con->in($params['link_id']); $strReq .= 'AND L.link_id ' . $this->con->in($params['link_id']);
} }
if (!empty($params['cat_id'])) { if (!empty($params['cat_id'])) {
if (is_array($params['cat_id'])) { if (is_array($params['cat_id'])) {
array_walk($params['cat_id'], create_function('&$v,$k', 'if($v!==null){$v=(integer)$v;}')); array_walk($params['cat_id'], function(&$v, $k) { if($v !== null) { $v = (integer) $v;}});
} } else {
else { $params['cat_id'] = [(integer) $params['cat_id']];
$params['cat_id'] = array((integer) $params['cat_id']);
} }
$strReq .= 'AND L.cat_id ' . $this->con->in($params['cat_id']); $strReq .= 'AND L.cat_id ' . $this->con->in($params['cat_id']);
} }
@ -137,8 +131,7 @@ class cinecturlink2
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 L.link_upddt DESC '; $strReq .= 'ORDER BY L.link_upddt DESC ';
} }
} }
@ -182,8 +175,7 @@ class cinecturlink2
$cur->link_count = 0; $cur->link_count = 0;
$cur->insert(); $cur->insert();
$this->con->unlock(); $this->con->unlock();
} } catch (Exception $e) {
catch (Exception $e) {
$this->con->unlock(); $this->con->unlock();
throw $e; throw $e;
} }
@ -265,7 +257,7 @@ class cinecturlink2
* @param boolean $count_only Count only result * @param boolean $count_only Count only result
* @return record record instance * @return record record instance
*/ */
public function getCategories($params=array(), $count_only=false) public function getCategories($params = [], $count_only = false)
{ {
if ($count_only) { if ($count_only) {
$strReq = 'SELECT count(C.cat_id) '; $strReq = 'SELECT count(C.cat_id) ';
@ -292,14 +284,22 @@ class cinecturlink2
if (!empty($params['cat_id'])) { if (!empty($params['cat_id'])) {
if (is_array($params['cat_id'])) { if (is_array($params['cat_id'])) {
array_walk($params['cat_id'], create_function('&$v,$k', 'if($v!==null){$v=(integer)$v;}')); array_walk($params['cat_id'], function(&$v, $k) { if($v !== null) { $v = (integer) $v; }});
} } else {
else { $params['cat_id'] = [(integer) $params['cat_id']];
$params['cat_id'] = array((integer) $params['cat_id']);
} }
$strReq .= 'AND C.cat_id ' . $this->con->in($params['cat_id']); $strReq .= 'AND C.cat_id ' . $this->con->in($params['cat_id']);
} }
if (isset($params['exclude_cat_id']) && $params['exclude_cat_id'] !== '') {
if (is_array($params['exclude_cat_id'])) {
array_walk($params['exclude_cat_id'], function (&$v, $k) { if ($v !== null) {$v = (integer) $v;}});
} else {
$params['exclude_cat_id'] = [(integer) $params['exclude_cat_id']];
}
$strReq .= 'AND C.cat_id NOT ' . $this->con->in($params['exclude_cat_id']);
}
if (!empty($params['cat_title'])) { if (!empty($params['cat_title'])) {
$strReq .= "AND C.cat_title = '" . $this->con->escape($params['cat_title']) . "' "; $strReq .= "AND C.cat_title = '" . $this->con->escape($params['cat_title']) . "' ";
} }
@ -311,8 +311,7 @@ class cinecturlink2
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 cat_pos ASC '; $strReq .= 'ORDER BY cat_pos ASC ';
} }
} }
@ -349,8 +348,7 @@ class cinecturlink2
$cur->cat_upddt = date('Y-m-d H:i:s'); $cur->cat_upddt = date('Y-m-d H:i:s');
$cur->insert(); $cur->insert();
$this->con->unlock(); $this->con->unlock();
} } catch (Exception $e) {
catch (Exception $e) {
$this->con->unlock(); $this->con->unlock();
throw $e; throw $e;
} }
@ -455,11 +453,9 @@ class cinecturlink2
if ($throw) { if ($throw) {
throw new Exception(__('Failed to create public folder for images.')); throw new Exception(__('Failed to create public folder for images.'));
} }
return false; return false;
} }
} }
return true; return true;
} }
} }

View File

@ -18,13 +18,10 @@ class cinecturlink2Context
global $_ctx; global $_ctx;
if ($_ctx->c2_pagination === null) { if ($_ctx->c2_pagination === null) {
return false; return false;
} }
$nb_posts = $_ctx->c2_pagination->f(0); $nb_posts = $_ctx->c2_pagination->f(0);
$nb_per_page = $_ctx->c2_params['limit'][1]; $nb_per_page = $_ctx->c2_params['limit'][1];
$nb_pages = ceil($nb_posts/$nb_per_page); $nb_pages = ceil($nb_posts/$nb_per_page);
return $nb_pages; return $nb_pages;
@ -34,39 +31,30 @@ class cinecturlink2Context
{ {
if (isset($GLOBALS['c2_page_number'])) { if (isset($GLOBALS['c2_page_number'])) {
$p = $GLOBALS['c2_page_number']; $p = $GLOBALS['c2_page_number'];
} } else {
else {
$p = 1; $p = 1;
} }
$p = $p+$offset; $p = $p+$offset;
$n = self::PaginationNbPages(); $n = self::PaginationNbPages();
if (!$n) { if (!$n) {
return $p; return $p;
} }
return $p > $n || $p <= 0 ? 1 : $p; return $p > $n || $p <= 0 ? 1 : $p;
} }
public static function PaginationStart() public static function PaginationStart()
{ {
if (isset($GLOBALS['c2_page_number'])) { if (isset($GLOBALS['c2_page_number'])) {
return self::PaginationPosition() == 1; return self::PaginationPosition() == 1;
} }
return true; return true;
} }
public static function PaginationEnd() public static function PaginationEnd()
{ {
if (isset($GLOBALS['c2_page_number'])) { if (isset($GLOBALS['c2_page_number'])) {
return self::PaginationPosition() == self::PaginationNbPages(); return self::PaginationPosition() == self::PaginationNbPages();
} }
return false; return false;
} }
@ -84,13 +72,11 @@ class cinecturlink2Context
$url = preg_replace('#/$#', '', $url); $url = preg_replace('#/$#', '', $url);
$url .= '/c2page/' . $n; $url .= '/c2page/' . $n;
} }
# If search param # If search param
if (!empty($_GET['q'])) { if (!empty($_GET['q'])) {
$s = strpos($url,'?') !== false ? '&amp;' : '?'; $s = strpos($url,'?') !== false ? '&amp;' : '?';
$url .= $s . 'q=' . rawurlencode($_GET['q']); $url .= $s . 'q=' . rawurlencode($_GET['q']);
} }
return $url; return $url;
} }
@ -98,19 +84,21 @@ class cinecturlink2Context
{ {
global $_ctx; global $_ctx;
if (!isset($_ctx->c2_page_params['cat_id']) && !isset($_ctx->c2_page_params['cat_title'])) { if (!isset($_ctx->c2_page_params['cat_id'])
&& !isset($_ctx->c2_page_params['cat_title'])
) {
return false; return false;
} }
if (isset($_ctx->c2_page_params['cat_id']) && $_ctx->c2_page_params['cat_id'] == $_ctx->c2_categories->cat_id) { if (isset($_ctx->c2_page_params['cat_id'])
&& $_ctx->c2_page_params['cat_id'] == $_ctx->c2_categories->cat_id
) {
return true; return true;
} }
if (isset($_ctx->c2_page_params['cat_title']) && $_ctx->c2_page_params['cat_title'] == $_ctx->c2_categories->cat_title) { if (isset($_ctx->c2_page_params['cat_title'])
&& $_ctx->c2_page_params['cat_title'] == $_ctx->c2_categories->cat_title
) {
return true; return true;
} }
return false; return false;
} }
} }

View File

@ -24,8 +24,8 @@ class sitemapsCinecturlink2
$core->blog->settings->addNamespace('sitemaps'); $core->blog->settings->addNamespace('sitemaps');
if ($core->plugins->moduleExists('cinecturlink2') if ($core->plugins->moduleExists('cinecturlink2')
&& $core->blog->settings->sitemaps->sitemaps_cinecturlink2_url) { && $core->blog->settings->sitemaps->sitemaps_cinecturlink2_url
) {
$freq = $sitemaps->getFrequency($core->blog->settings->sitemaps->sitemaps_cinecturlink2_fq); $freq = $sitemaps->getFrequency($core->blog->settings->sitemaps->sitemaps_cinecturlink2_fq);
$prio = $sitemaps->getPriority($core->blog->settings->sitemaps->sitemaps_cinecturlink2_pr); $prio = $sitemaps->getPriority($core->blog->settings->sitemaps->sitemaps_cinecturlink2_pr);
$base = $core->blog->url . $core->url->getBase('cinecturlink2'); $base = $core->blog->url . $core->url->getBase('cinecturlink2');