From f64f1f615778fb33c2bbbc3348bbd90f48784f0f Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sun, 22 Aug 2021 00:06:07 +0200 Subject: [PATCH] move to PSR-2 coding style and short array --- CHANGELOG.md | 1 + README.md | 10 +- _define.php | 32 +- _public.php | 1036 +++++++++++++++++++------------------- locales/fr/resources.php | 7 +- 5 files changed, 543 insertions(+), 543 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6bbf5e..b93c0d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * update license * fix query * change template titles to h3 + * move to PSR-2 coding style and short array 2013.10.28 * Switch to Dotclear 2.6 diff --git a/README.md b/README.md index 5b5c2d1..4def6cd 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ show related entries to visitor. saba requires: * administrator permissions - * Dotclear 2.6 + * Dotclear 2.18 * Custom templates if default theme is not used. ## USAGE @@ -26,4 +26,10 @@ go to ''configure plugin'', fill in form. If you use a custom theme (not Dotclear's default theme) you must create custom templates that match yours. -You can find exemple in saba/default-tempaltes. \ No newline at end of file +You can find exemple in saba/default-tempaltes. + +## MORE + + * License : GNU GPL v2 + * Source & contribution : [GitHub Page](https://github.com/JcDenis/saba) + * Packages & details: [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/saba) \ No newline at end of file diff --git a/_define.php b/_define.php index 49c5af3..8e3b37a 100644 --- a/_define.php +++ b/_define.php @@ -12,25 +12,19 @@ # -- END LICENSE BLOCK ------------------------------------ if (!defined('DC_RC_PATH')) { - - return null; + return null; } $this->registerModule( - /* Name */ - "saba", - /* Description*/ - "Search across blog's archive", - /* Author */ - "Jean-Christian Denis", - /* Version */ - '2021.08.20.3', - /* Properies */ - array( - 'permissions' => 'admin', - 'type' => 'plugin', - 'dc_min' => '2.6', - 'support' => 'http://jcd.lv/q=saba', - 'details' => 'http://plugins.dotaddict.org/dc2/details/saba' - ) -); + 'saba', + 'Search across blog archive', + 'Jean-Christian Denis and Contributors', + '2021.08.20.5', + [ + 'permissions' => 'admin', + 'type' => 'plugin', + 'dc_min' => '2.18', + 'support' => 'https://github.com/JcDenis/saba', + 'details' => 'https://plugins.dotaddict.org/dc2/details/saba' + ] +); \ No newline at end of file diff --git a/_public.php b/_public.php index 11b6107..f62f3a8 100644 --- a/_public.php +++ b/_public.php @@ -12,623 +12,623 @@ # -- END LICENSE BLOCK ------------------------------------ if (!defined('DC_RC_PATH')) { - - return null; + return null; } # Admin behaviors $core->blog->settings->addNamespace('saba'); -if ($core->blog->settings->saba->active) { - - # Register saba handler - $core->url->register( - 'search', - 'search', - '^search(/.+)?$', - array('urlSaba', 'saba') - ); - - # Add saba templates path - $core->tpl->setPath( - $core->tpl->getPath(), - dirname(__FILE__).'/default-templates/' - ); - - # templates - $core->tpl->addBlock( - 'SabaIf', - array('tplSaba', 'SabaIf') - ); - $core->tpl->addBlock( - 'SabaEntries', - array('tplSaba', 'SabaEntries') - ); - $core->tpl->addBlock( - 'SabaFormIf', - array('tplSaba', 'SabaFormIf') - ); - $core->tpl->addValue( - 'SabaFormSearch', - array('tplSaba', 'SabaFormSearch') - ); - $core->tpl->addValue( - 'SabaFormOptions', - array('tplSaba', 'SabaFormOptions') - ); - $core->tpl->addValue( - 'SabaFormCategories', - array('tplSaba', 'SabaFormCategories') - ); - $core->tpl->addValue( - 'SabaFormTypes', - array('tplSaba', 'SabaFormTypes') - ); - $core->tpl->addValue( - 'SabaFormAges', - array('tplSaba', 'SabaFormAges') - ); - $core->tpl->addValue( - 'SabaFormOrders', - array('tplSaba', 'SabaFormOrders') - ); - $core->tpl->addValue( - 'SabaFormAuthors', - array('tplSaba', 'SabaFormAuthors') - ); - $core->tpl->addValue( - 'SabaPaginationURL', - array('tplSaba', 'SabaPaginationURL') - ); - $core->tpl->addValue( - 'SabaURL', - array('tplSaba','SabaURL') - ); - - # behavior - $core->addBehavior( - 'templateCustomSortByAlias', - array('pubSaba', 'templateCustomSortByAlias') - ); - $core->addBehavior( - 'urlHandlerBeforeGetData', - array('pubSaba', 'urlHandlerBeforeGetData') - ); - $core->addBehavior( - 'corePostSearch', - array('pubSaba', 'corePostSearch') - ); - $core->url->registerError(array('urlSaba','error')); +if (!$core->blog->settings->saba->active) { + return null; } +# Register saba handler +$core->url->register( + 'search', + 'search', + '^search(/.+)?$', + ['urlSaba', 'saba'] +); + +# Add saba templates path +$core->tpl->setPath( + $core->tpl->getPath(), + dirname(__FILE__) . '/default-templates/' +); + +# templates +$core->tpl->addBlock( + 'SabaIf', + ['tplSaba', 'SabaIf'] +); +$core->tpl->addBlock( + 'SabaEntries', + ['tplSaba', 'SabaEntries'] +); +$core->tpl->addBlock( + 'SabaFormIf', + ['tplSaba', 'SabaFormIf'] +); +$core->tpl->addValue( + 'SabaFormSearch', + ['tplSaba', 'SabaFormSearch'] +); +$core->tpl->addValue( + 'SabaFormOptions', + ['tplSaba', 'SabaFormOptions'] +); +$core->tpl->addValue( + 'SabaFormCategories', + ['tplSaba', 'SabaFormCategories'] +); +$core->tpl->addValue( + 'SabaFormTypes', + ['tplSaba', 'SabaFormTypes'] +); +$core->tpl->addValue( + 'SabaFormAges', + ['tplSaba', 'SabaFormAges'] +); +$core->tpl->addValue( + 'SabaFormOrders', + ['tplSaba', 'SabaFormOrders'] +); +$core->tpl->addValue( + 'SabaFormAuthors', + ['tplSaba', 'SabaFormAuthors'] +); +$core->tpl->addValue( + 'SabaPaginationURL', + ['tplSaba', 'SabaPaginationURL'] +); +$core->tpl->addValue( + 'SabaURL', + ['tplSaba', 'SabaURL'] +); + +# behavior +$core->addBehavior( + 'templateCustomSortByAlias', + ['pubSaba', 'templateCustomSortByAlias'] +); +$core->addBehavior( + 'urlHandlerBeforeGetData', + ['pubSaba', 'urlHandlerBeforeGetData'] +); +$core->addBehavior( + 'corePostSearch', + ['pubSaba', 'corePostSearch'] +); + +# url +$core->url->registerError(['urlSaba', 'error']); + class pubSaba { - public static function templateCustomSortByAlias($alias) - { - $alias['post'] = array( - 'title' => 'post_title', - 'selected' => 'post_selected', - 'author' => 'user_id', - 'date' => 'post_dt', - 'update' => 'post_upddt', - 'id' => 'post_id', - 'comment' => 'nb_comment', - 'trackback' => 'nb_trackback' - ); - } + public static function templateCustomSortByAlias($alias) + { + $alias['post'] = [ + 'title' => 'post_title', + 'selected' => 'post_selected', + 'author' => 'user_id', + 'date' => 'post_dt', + 'update' => 'post_upddt', + 'id' => 'post_id', + 'comment' => 'nb_comment', + 'trackback' => 'nb_trackback' + ]; + } - public static function urlHandlerBeforeGetData($_ctx) - { - global $core; + public static function urlHandlerBeforeGetData($_ctx) + { + global $core; - $options = array( - 'q' => '', - 'q_opt' => array(), - 'q_cat' => array(), - 'q_age' => '0,0', - 'q_user' => array(), - 'q_order' => 'date', - 'q_rev' => '0', - 'q_type' => array() - ); + $options = [ + 'q'=> '', + 'q_opt' => [], + 'q_cat' => [], + 'q_age' => '0,0', + 'q_user'=> [], + 'q_order'=> 'date', + 'q_rev' => '0', + 'q_type'=> [] + ]; - if (!empty($_GET['q']) && 1 < strlen($_GET['q'])) { - # move to saba - $_ctx->current_tpl = null; - $_ctx->current_tpl = 'saba_search.html'; + if (!empty($_GET['q']) && 1 < strlen($_GET['q'])) { + # move to saba + $_ctx->current_tpl = null; + $_ctx->current_tpl = 'saba_search.html'; - # retreive _GET - $qs = $_SERVER['QUERY_STRING']; - $qs = preg_replace('#(^|/)page/([0-9]+)#', '', $qs); - parse_str($qs, $get); + # retreive _GET + $qs = $_SERVER['QUERY_STRING']; + $qs = preg_replace('#(^|/)page/([0-9]+)#', '', $qs); + parse_str($qs, $get); - $params = array( - 'sql'=>'', - 'post_type' => array() - ); + $params = [ + 'sql'=>'', + 'post_type' => [] + ]; - # search string - $params['search'] = rawurldecode($_GET['q']); - $options['q'] = rawurldecode($_GET['q']); + # search string + $params['search'] = rawurldecode($_GET['q']); + $options['q'] = rawurldecode($_GET['q']); - # options - if (!empty($get['q_opt'])) { - - if (in_array('selected', $get['q_opt'])) { - $options['q_opt'][] = 'selected'; - $params['post_selected'] = 1; - } - if (in_array('comment', $get['q_opt'])) { - $options['q_opt'][] = 'comment'; - $params['sql'] = "AND nb_comment > 0 "; - } - if (in_array('trackback', $get['q_opt'])) { - $options['q_opt'][] = 'trackback'; - $params['sql'] = "AND nb_trackback > 0"; - } - } + # options + if (!empty($get['q_opt'])) { + + if (in_array('selected', $get['q_opt'])) { + $options['q_opt'][] = 'selected'; + $params['post_selected'] = 1; + } + if (in_array('comment', $get['q_opt'])) { + $options['q_opt'][] = 'comment'; + $params['sql'] = "AND nb_comment > 0 "; + } + if (in_array('trackback', $get['q_opt'])) { + $options['q_opt'][] = 'trackback'; + $params['sql'] = "AND nb_trackback > 0"; + } + } - # categories - if (!empty($get['q_cat'])) { - $cats = array(); - foreach($get['q_cat'] as $v) { - $v = abs((integer) $v); - if (!$v) { - continue; - } - $cats[] = "C.cat_id = '".$v."'"; - $options['q_cat'][] = $v; - } - if (!empty($cats)) { - $params['sql'] .= 'AND ('.implode(' OR ', $cats).') '; - } - } + # categories + if (!empty($get['q_cat'])) { + $cats = array(); + foreach($get['q_cat'] as $v) { + $v = abs((integer) $v); + if (!$v) { + continue; + } + $cats[] = "C.cat_id = '" . $v . "'"; + $options['q_cat'][] = $v; + } + if (!empty($cats)) { + $params['sql'] .= 'AND (' . implode(' OR ', $cats) . ') '; + } + } - # post types - if (!empty($get['q_type'])) { - $types = $core->getPostTypes(); - foreach($get['q_type'] as $v) { - if (!$types[$v]) { - continue; - } - $options['q_type'][] = $v; - $params['post_type'][] = $v; - } - } else { - $params['post_type'][] = 'post'; - } + # post types + if (!empty($get['q_type'])) { + $types = $core->getPostTypes(); + foreach($get['q_type'] as $v) { + if (!$types[$v]) { + continue; + } + $options['q_type'][] = $v; + $params['post_type'][] = $v; + } + } else { + $params['post_type'][] = 'post'; + } - # age - $ages = tplSaba::getSabaFormAges(); - if (!empty($get['q_age']) && in_array($get['q_age'], $ages)) { - $age = explode(',', $get['q_age']); - $ts = time(); - $options['q_age'] = $get['q_age']; - - if ($age[0]) { - $params['sql'] .= "AND P.post_dt < '".dt::str('%Y-%m-%d %H:%m:%S', $ts-$age[0])."' "; - } - if ($age[1]) { - $params['sql'] .= "AND P.post_dt > '".dt::str('%Y-%m-%d %H:%m:%S', $ts-$age[1])."' "; - } - } + # age + $ages = tplSaba::getSabaFormAges(); + if (!empty($get['q_age']) && in_array($get['q_age'], $ages)) { + $age = explode(',', $get['q_age']); + $ts = time(); + $options['q_age'] = $get['q_age']; + + if ($age[0]) { + $params['sql'] .= "AND P.post_dt < '" . + dt::str('%Y-%m-%d %H:%m:%S', $ts - $age[0]) . "' "; + } + if ($age[1]) { + $params['sql'] .= "AND P.post_dt > '" . + dt::str('%Y-%m-%d %H:%m:%S', $ts - $age[1]) . "' "; + } + } - # user - if (!empty($get['q_user'])) { - $users = array(); - foreach($get['q_user'] as $v) { - $users[] = "U.user_id = '".$core->con->escape($v)."'"; - $options['q_user'][] = $v; - } - if (!empty($users)) { - $params['sql'] .= 'AND ('.implode(' OR ', $users).') '; - } - } + # user + if (!empty($get['q_user'])) { + $users = array(); + foreach($get['q_user'] as $v) { + $users[] = "U.user_id = '" . $core->con->escape($v) . "'"; + $options['q_user'][] = $v; + } + if (!empty($users)) { + $params['sql'] .= 'AND (' . implode(' OR ', $users) . ') '; + } + } - #order - $sort = 'desc'; - if (!empty($get['q_rev'])) { - $options['q_rev'] = '1'; - $sort = 'asc'; - } - $orders = tplSaba::getSabaFormOrders(); - if (!empty($get['q_order']) && in_array($get['q_order'], $orders)) { + #order + $sort = 'desc'; + if (!empty($get['q_rev'])) { + $options['q_rev'] = '1'; + $sort = 'asc'; + } + $orders = tplSaba::getSabaFormOrders(); + if (!empty($get['q_order']) && in_array($get['q_order'], $orders)) { - $options['q_order'] = $get['q_order']; - $params['order'] = $core->tpl->getSortByStr( - array('sortby'=>$get['q_order'], 'order'=>$sort),'post'); //?! post_type - } + $options['q_order'] = $get['q_order']; + $params['order'] = $core->tpl->getSortByStr( + ['sortby' => $get['q_order'], 'order' => $sort], + 'post' + ); //?! post_type + } - # count - $GLOBALS['_search'] = rawurldecode($_GET['q']); - if ($GLOBALS['_search']) { - $GLOBALS['_search_count'] = $core->blog->getPosts($params, true)->f(0); - } + # count + $GLOBALS['_search'] = rawurldecode($_GET['q']); + if ($GLOBALS['_search']) { + $GLOBALS['_search_count'] = $core->blog->getPosts($params, true)->f(0); + } - # pagintaion - $_page_number = !isset($GLOBALS['_page_number']) ? 1 : $GLOBALS['_page_number']; - $params['limit'] = $_ctx->nb_entry_per_page; - $params['limit'] = array((($_page_number-1)*$params['limit']), $params['limit']); + # pagintaion + $_page_number = !isset($GLOBALS['_page_number']) ? 1 : $GLOBALS['_page_number']; + $params['limit'] = $_ctx->nb_entry_per_page; + $params['limit'] = [(($_page_number - 1) * $params['limit']), $params['limit']]; - # get posts - $_ctx->post_params = $params; - $_ctx->posts = $core->blog->getPosts($params); - unset($params); - } - $_ctx->saba_options = $options; - } + # get posts + $_ctx->post_params = $params; + $_ctx->posts = $core->blog->getPosts($params); + unset($params); + } + $_ctx->saba_options = $options; + } - # Ajouter la condition "ou" à la recherche - public static function corePostSearch($core, $p) - { - $sentences = explode(',', $p[2]['search']); + # Ajouter la condition "ou" à la recherche + public static function corePostSearch($core, $p) + { + $sentences = explode(',', $p[2]['search']); - $OR = array(); - foreach($sentences as $sentence) - { - $AND = array(); - $words = text::splitWords($sentence); - foreach($words as $word) { - $AND[] = "post_words LIKE '%".$core->con->escape($word)."%'"; - } - if (!empty($AND)) { - $OR[] = " (".implode (' AND ',$AND).") "; - } - } - if (!empty($OR)) { - $p[0] = ''; - $p[2]['sql'] = (isset($p[2]['sql']) ? $p[2]['sql'] : '') . "AND (" . implode (' OR ', $OR) . ") "; - } - } + $OR = []; + foreach($sentences as $sentence) { + $AND = []; + $words = text::splitWords($sentence); + foreach($words as $word) { + $AND[] = "post_words LIKE '%" . $core->con->escape($word) . "%'"; + } + if (!empty($AND)) { + $OR[] = " (" . implode (' AND ', $AND) . ") "; + } + } + if (!empty($OR)) { + $p[0] = ''; + $p[2]['sql'] = (isset($p[2]['sql']) ? $p[2]['sql'] : '') . "AND (" . implode (' OR ', $OR) . ") "; + } + } } class urlSaba extends dcUrlHandlers { - public static function error($args, $type, $e) - { - global $core, $_ctx; + public static function error($args, $type, $e) + { + global $core, $_ctx; - if ($e->getCode() == 404) { - $q = explode('/', $args); - if (empty($q)) { + if ($e->getCode() == 404) { + $q = explode('/', $args); + if (empty($q)) { + return false; + } - return false; - } + # Clean URI + $_GET['q'] = implode('%20', $q); + $_SERVER['QUERY_STRING'] = ''; - # Clean URI - $_GET['q'] = implode('%20', $q); - $_SERVER['QUERY_STRING'] = ''; + # Claim comes from 404 + $GLOBALS['_from_error'] = true; - # Claim comes from 404 - $GLOBALS['_from_error'] = true; + # Serve saba + self::serveDocument('saba_search.html'); - # Serve saba - self::serveDocument('saba_search.html'); + return true; + } + } + + public static function saba($args) + { + $_ctx =& $GLOBALS['_ctx']; + $core =& $GLOBALS['core']; - return true; - } - } - - public static function saba($args) - { - $_ctx =& $GLOBALS['_ctx']; - $core =& $GLOBALS['core']; - - self::serveDocument('saba_search.html'); - } + self::serveDocument('saba_search.html'); + } } class tplSaba { - public static function SabaEntries($a, $c) - { - return - 'exists("posts")) : while ($_ctx->posts->fetch()) : ?>'.$c.''; - } + public static function SabaEntries($a, $c) + { + return + 'exists("posts")) : while ($_ctx->posts->fetch()) : ?>'.$c.''; + } - public static function SabaFormSearch($a) - { - return 'saba_options["q"]); ?>'; - } + public static function SabaFormSearch($a) + { + return 'saba_options["q"]); ?>'; + } - public static function SabaIf($a, $c) - { - $if = array(); + public static function SabaIf($a, $c) + { + $if = []; - $operator = isset($a['operator']) ? $GLOBALS['core']->tpl->getOperator($a['operator']) : '&&'; - - if (isset($a['has_search'])) { - $sign = (boolean) $a['has_search'] ? '' : '!'; - $if[] = $sign.'isset($_search_count)'; - } + $operator = isset($a['operator']) ? $GLOBALS['core']->tpl->getOperator($a['operator']) : '&&'; + + if (isset($a['has_search'])) { + $sign = (boolean) $a['has_search'] ? '' : '!'; + $if[] = $sign . 'isset($_search_count)'; + } - if (isset($a['from_error'])) { - $sign = (boolean) $a['from_error'] ? '' : '!'; - $if[] = $sign.'isset($_from_error)'; - } + if (isset($a['from_error'])) { + $sign = (boolean) $a['from_error'] ? '' : '!'; + $if[] = $sign . 'isset($_from_error)'; + } - return !empty($if) ? - ''.$c.'' - : $c; - } + return !empty($if) ? + '' . $c . '' + : $c; + } - public static function SabaURL($a) - { - $f = $GLOBALS['core']->tpl->getFilters($a); + public static function SabaURL($a) + { + $f = $GLOBALS['core']->tpl->getFilters($a); - return 'blog->url.$core->url->getBase("search")').'; ?>'; - } + return 'blog->url.$core->url->getBase("search")') . '; ?>'; + } - public static function SabaFormIf($a,$c) - { - $if = array(); + public static function SabaFormIf($a, $c) + { + $if = []; - $operator = isset($a['operator']) ? $GLOBALS['core']->tpl->getOperator($a['operator']) : '&&'; + $operator = isset($a['operator']) ? $GLOBALS['core']->tpl->getOperator($a['operator']) : '&&'; - $fl = self::getSabaFormFilters(); - foreach($fl as $filter) { - if (isset($a['filter_'.$filter])) { - $sign = (boolean) $a['filter_'.$filter] ? '' : '!'; - $if[] = $sign.'tplSaba::isSabaFormFilter(\''.$filter.'\')'; - } - } + $fl = self::getSabaFormFilters(); + foreach($fl as $filter) { + if (isset($a['filter_' . $filter])) { + $sign = (boolean) $a['filter_' . $filter] ? '' : '!'; + $if[] = $sign . 'tplSaba::isSabaFormFilter(\'' . $filter . '\')'; + } + } - return !empty($if) ? - ''.$c.'' - : $c; - } + return !empty($if) ? + '' . $c . '' + : $c; + } - public static function SabaFormOptions($a) - { - $dis = !empty($a['remove']) ? explode(',', $a['remove']) : array(); + public static function SabaFormOptions($a) + { + $dis = !empty($a['remove']) ? explode(',', $a['remove']) : []; - $res = ''; - $li = '
  • '; + $res = ''; + $li = '
  • '; - $rs = self::getSabaFormOptions(); - foreach($rs as $k => $v) { - if (in_array($v,$dis)) { - continue; - } - $chk = 'saba_options["q_opt"]) ? \'checked="checked" \' : ""; ?>'; - $res .= sprintf($li, $v, $chk, html::escapeHTML($k)); - } + $rs = self::getSabaFormOptions(); + foreach($rs as $k => $v) { + if (in_array($v, $dis)) { + continue; + } + $chk = 'saba_options["q_opt"]) ? \'checked="checked" \' : ""; ?>'; + $res .= sprintf($li, $v, $chk, html::escapeHTML($k)); + } - if (!empty($res)) { + if (!empty($res)) { + return '

    ' . __('Filter options') . '

    '; + } + } - return '

    '.__('Filter options').'

    '; - } - } + public static function SabaFormOrders($a) + { + $dis = !empty($a['remove']) ? explode(',',$a['remove']) : []; - public static function SabaFormOrders($a) - { - $dis = !empty($a['remove']) ? explode(',',$a['remove']) : array(); + $res = ''; + $li = '
  • '; - $res = ''; - $li = '
  • '; + $rs = self::getSabaFormOrders($dis); + foreach($rs as $k => $v) { + if (in_array($v, $dis)) { + continue; + } + $chk = 'saba_options["q_order"] ? \'checked="checked" \' : ""; ?>'; + $res .= sprintf($li, $v, $chk, html::escapeHTML($k)); + } - $rs = self::getSabaFormOrders($dis); - foreach($rs as $k => $v) { - if (in_array($v,$dis)) { - continue; - } - $chk = 'saba_options["q_order"] ? \'checked="checked" \' : ""; ?>'; - $res .= sprintf($li, $v, $chk, html::escapeHTML($k)); - } + if (!empty($res)) { + $chk = 'saba_options["q_rev"]) ? \'checked="checked" \' : ""; ?>'; + $res .= '
  • '; - if (!empty($res)) { - $chk = 'saba_options["q_rev"]) ? \'checked="checked" \' : ""; ?>'; - $res .= '
  • '; + return '

    ' . __('Filter order') . '

    '; + } + } - return '

    '.__('Filter order').'

    '; - } - } + public static function SabaFormCategories($a) + { + global $core; - public static function SabaFormCategories($a) - { - global $core; + $dis = !empty($a['remove']) ? explode(',', $a['remove']) : []; - $dis = !empty($a['remove']) ? explode(',', $a['remove']) : array(); + $res = ''; + $li = '
  • '; - $res = ''; - $li = '
  • '; + $rs = $core->blog->getCategories(); + while ($rs->fetch()) { + if (in_array($rs->cat_id, $dis) || in_array($rs->cat_url, $dis)) { + continue; + } + $chk = 'cat_id . '",$_ctx->saba_options["q_cat"]) ? \'checked="checked" \' : ""; ?>'; + $res .= sprintf($li, $rs->cat_id, $chk, html::escapeHTML($rs->cat_title)); + } - $rs = $core->blog->getCategories(); - while ($rs->fetch()) { - if (in_array($rs->cat_id,$dis) || in_array($rs->cat_url,$dis)) { - continue; - } - $chk = 'cat_id.'",$_ctx->saba_options["q_cat"]) ? \'checked="checked" \' : ""; ?>'; - $res .= sprintf($li,$rs->cat_id,$chk,html::escapeHTML($rs->cat_title)); - } + if (!empty($res)) { + return '

    ' . __('Filter by category') . '

    '; + } + } - if (!empty($res)) { + public static function SabaFormTypes($a) + { + global $core; - return '

    '.__('Filter by category').'

    '; - } - } + $dis = !empty($a['remove']) ? explode(',',$a['remove']) : []; - public static function SabaFormTypes($a) - { - global $core; + $res = ''; + $li = '
  • '; - $dis = !empty($a['remove']) ? explode(',',$a['remove']) : array(); + $rs = self::getSabaFormTypes(); + foreach($rs as $k => $v) { + if (in_array($v, $dis)) { + continue; + } + $chk = 'saba_options["q_type"]) ? \'checked="checked" \' : ""; ?>'; + $res .= sprintf($li, $v, $chk, html::escapeHTML($k)); + } - $res = ''; - $li = '
  • '; + if (!empty($res)) { + return '

    ' . __('Filter by type') . '

    '; + } + } - $rs = self::getSabaFormTypes(); - foreach($rs as $k => $v) { - if (in_array($v,$dis)) { - continue; - } - $chk = 'saba_options["q_type"]) ? \'checked="checked" \' : ""; ?>'; - $res .= sprintf($li,$v,$chk,html::escapeHTML($k)); - } + public static function SabaFormAges($a) + { + $res = ''; + $li = '
  • '; - if (!empty($res)) { + $rs = self::getSabaFormAges(); + foreach($rs as $k => $v) { + $chk = 'saba_options["q_age"] ? \'checked="checked" \' : ""; ?>'; + $res .= sprintf($li, $v, $chk, html::escapeHTML($k)); + } - return '

    '.__('Filter by type').'

    '; - } - } + if (!empty($res)) { + return '

    ' . __('Filter by age') . '

    '; + } + } - public static function SabaFormAges($a) - { - $res = ''; - $li = '
  • '; + public static function SabaFormAuthors($a) + { + global $core; - $rs = self::getSabaFormAges(); - foreach($rs as $k => $v) { - $chk = 'saba_options["q_age"] ? \'checked="checked" \' : ""; ?>'; - $res .= sprintf($li, $v, $chk, html::escapeHTML($k)); - } + $dis = !empty($a['remove']) ? explode(',',$a['remove']) : []; - if (!empty($res)) { + $res = ''; + $li = '
  • '; - return '

    '.__('Filter by age').'

    '; - } - } + $rs = $core->blog->getPostsUsers(); + while ($rs->fetch()) { + if (in_array($rs->user_id, $dis)) { + continue; + } + $chk = 'user_id . '",$_ctx->saba_options["q_user"]) ? \'checked="checked" \' : ""; ?>'; + $res .= sprintf($li, $rs->user_id, $chk, html::escapeHTML(dcUtils::getUserCN($rs->user_id, $rs->user_name, $rs->user_firstname, $rs->user_displayname))); + } - public static function SabaFormAuthors($a) - { - global $core; + if (!empty($res)) { + return '

    ' . __('Filter by author') . '

    '; + } + } - $dis = !empty($a['remove']) ? explode(',',$a['remove']) : array(); + public static function SabaPaginationURL($attr) + { + $offset = 0; + if (isset($attr['offset'])) { + $offset = (integer) $attr['offset']; + } + + $f = $GLOBALS['core']->tpl->getFilters($attr); - $res = ''; - $li = '
  • '; + return ''; + } - $rs = $core->blog->getPostsUsers(); - while ($rs->fetch()) { - if (in_array($rs->user_id,$dis)) { - continue; - } - $chk = 'user_id.'",$_ctx->saba_options["q_user"]) ? \'checked="checked" \' : ""; ?>'; - $res .= sprintf($li,$rs->user_id,$chk,html::escapeHTML(dcUtils::getUserCN($rs->user_id,$rs->user_name,$rs->user_firstname, $rs->user_displayname))); - } + public static function getSabaFormFilters() + { + return [ + 'options', + 'orders', + 'ages', + 'categories', + 'authors', + 'types' + ]; + } - if (!empty($res)) { + public static function getSabaFormOptions() + { + return [ + __('Selected entry') => 'selected', + __('With comments') => 'comment', + __('With trackbacks') => 'trackback' + ]; + } - return '

    '.__('Filter by author').'

    '; - } - } + public static function getSabaFormOrders() + { + return [ + __('Title') => 'title', + __('Selected entry') => 'selected', + __('Author') => 'author', + __('Date') => 'date', + __('Update') => 'update', + __('Comments count') => 'comment', + __('Trackbacks count') => 'trackback' + ]; + } - public static function SabaPaginationURL($attr) - { - $offset = 0; - if (isset($attr['offset'])) { - $offset = (integer) $attr['offset']; - } - - $f = $GLOBALS['core']->tpl->getFilters($attr); + public static function getSabaFormAges() + { + return [ + __('All') => '0,0', + __('Less than a month') => '0,2592000', + __('From 1 to 6 month') => '2592000,15552000', + __('From 6 to 12 month') => '15552000,31536000', + __('More than a year') => '31536000,0' + ]; + } - return ''; - } + public static function getSabaFormTypes() + { + $know = [ + 'post' => __('Entry'), + 'page' => __('Page'), + 'pollsfactory' => __('Poll'), + 'eventhandler' => __('Event') + ]; + // todo: add behavior for unknow types - public static function getSabaFormFilters() - { - return array( - 'options', - 'orders', - 'ages', - 'categories', - 'authors', - 'types' - ); - } + $rs = []; + $types = $GLOBALS['core']->getPostTypes(); - public static function getSabaFormOptions() - { - return array( - __('Selected entry') => 'selected', - __('With comments') => 'comment', - __('With trackbacks') => 'trackback' - ); - } + foreach($types as $k => $v) { + if (!$v['public_url']) { + continue; + } + $rs[isset($know[$k]) ? $know[$k] : __($k)] = $k; + } - public static function getSabaFormOrders() - { - return array( - __('Title') => 'title', - __('Selected entry') => 'selected', - __('Author') => 'author', - __('Date') => 'date', - __('Update') => 'update', - __('Comments count') => 'comment', - __('Trackbacks count') => 'trackback' - ); - } + return $rs; + } - public static function getSabaFormAges() - { - return array( - __('All') => '0,0', - __('Less than a month') => '0,2592000', - __('From 1 to 6 month') => '2592000,15552000', - __('From 6 to 12 month') => '15552000,31536000', - __('More than a year') => '31536000,0' - ); - } + public static function isSabaFormFilter($f) + { + $filters = (string) $GLOBALS['core']->blog->settings->saba->filters; + $filters = @unserialize($filters); + if (!is_array($filters)) { + $filters = []; + } - public static function getSabaFormTypes() - { - $know = array( - 'post' => __('Entry'), - 'page' => __('Page'), - 'pollsfactory' => __('Poll'), - 'eventhandler' => __('Event') - ); - - $rs = array(); - $types = $GLOBALS['core']->getPostTypes(); - - foreach($types as $k => $v) { - if (!$v['public_url']) { - continue; - } - $rs[isset($know[$k]) ? $know[$k] : __($k)] = $k; - } - - return $rs; - } - - public static function isSabaFormFilter($f) - { - $filters = (string) $GLOBALS['core']->blog->settings->saba->filters; - $filters = @unserialize($filters); - if (!is_array($filters)) { - $filters = array(); - } - - return !in_array($f,$filters); - } + return !in_array($f, $filters); + } } class ctxSaba extends context { - public static function PaginationURL($offset=0) - { - $args = $_SERVER['URL_REQUEST_PART']; + public static function PaginationURL($offset = 0) + { + $args = $_SERVER['URL_REQUEST_PART']; - $n = self::PaginationPosition($offset); + $n = self::PaginationPosition($offset); - $args = preg_replace('#(^|/)page/([0-9]+)$#', '', $args); + $args = preg_replace('#(^|/)page/([0-9]+)$#', '', $args); - $url = $GLOBALS['core']->blog->url.$args; + $url = $GLOBALS['core']->blog->url . $args; - if ($n > 1) { - $url = preg_replace('#/$#', '', $url); - $url .= '/page/'.$n; - } + if ($n > 1) { + $url = preg_replace('#/$#', '', $url); + $url .= '/page/' . $n; + } - $qs = preg_replace('#(^|/)page/([0-9]+)(&?)#', '', $_SERVER['QUERY_STRING']); + $qs = preg_replace('#(^|/)page/([0-9]+)(&?)#', '', $_SERVER['QUERY_STRING']); - # If search param - if (!empty($_GET['q'])) { - $s = strpos($url, '?') !== false ? '&' : '?'; - $url .= $s.$qs; - } + # If search param + if (!empty($_GET['q'])) { + $s = strpos($url, '?') !== false ? '&' : '?'; + $url .= $s . $qs; + } - return $url; - } -} + return $url; + } +} \ No newline at end of file diff --git a/locales/fr/resources.php b/locales/fr/resources.php index d91b24b..fefca59 100644 --- a/locales/fr/resources.php +++ b/locales/fr/resources.php @@ -12,10 +12,9 @@ # -- END LICENSE BLOCK ------------------------------------ if (!defined('DC_RC_PATH')) { - - return null; + return null; } if (!empty($_REQUEST['module']) && $_REQUEST['module'] == 'saba') { - $__resources['help']['core_plugins_conf'] = dirname(__FILE__).'/help/help.html'; -} + $__resources['help']['core_plugins_conf'] = dirname(__FILE__) . '/help/help.html'; +} \ No newline at end of file