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

View File

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

View File

@ -24,8 +24,8 @@ class sitemapsCinecturlink2
$core->blog->settings->addNamespace('sitemaps');
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);
$prio = $sitemaps->getPriority($core->blog->settings->sitemaps->sitemaps_cinecturlink2_pr);
$base = $core->blog->url . $core->url->getBase('cinecturlink2');