move to PSR-2 coding style and short array

This commit is contained in:
Jean-Christian Denis 2021-08-22 00:06:07 +02:00
parent ac274d3349
commit f64f1f6157
5 changed files with 543 additions and 543 deletions

View file

@ -2,6 +2,7 @@
* update license * update license
* fix query * fix query
* change template titles to h3 * change template titles to h3
* move to PSR-2 coding style and short array
2013.10.28 2013.10.28
* Switch to Dotclear 2.6 * Switch to Dotclear 2.6

View file

@ -13,7 +13,7 @@ show related entries to visitor.
saba requires: saba requires:
* administrator permissions * administrator permissions
* Dotclear 2.6 * Dotclear 2.18
* Custom templates if default theme is not used. * Custom templates if default theme is not used.
## USAGE ## USAGE
@ -27,3 +27,9 @@ go to ''configure plugin'', fill in form.
If you use a custom theme (not Dotclear's default theme) If you use a custom theme (not Dotclear's default theme)
you must create custom templates that match yours. you must create custom templates that match yours.
You can find exemple in saba/default-tempaltes. 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)

View file

@ -12,25 +12,19 @@
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
$this->registerModule( $this->registerModule(
/* Name */ 'saba',
"saba", 'Search across blog archive',
/* Description*/ 'Jean-Christian Denis and Contributors',
"Search across blog's archive", '2021.08.20.5',
/* Author */ [
"Jean-Christian Denis",
/* Version */
'2021.08.20.3',
/* Properies */
array(
'permissions' => 'admin', 'permissions' => 'admin',
'type' => 'plugin', 'type' => 'plugin',
'dc_min' => '2.6', 'dc_min' => '2.18',
'support' => 'http://jcd.lv/q=saba', 'support' => 'https://github.com/JcDenis/saba',
'details' => 'http://plugins.dotaddict.org/dc2/details/saba' 'details' => 'https://plugins.dotaddict.org/dc2/details/saba'
) ]
); );

View file

@ -12,21 +12,22 @@
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
# Admin behaviors # Admin behaviors
$core->blog->settings->addNamespace('saba'); $core->blog->settings->addNamespace('saba');
if ($core->blog->settings->saba->active) { if (!$core->blog->settings->saba->active) {
return null;
}
# Register saba handler # Register saba handler
$core->url->register( $core->url->register(
'search', 'search',
'search', 'search',
'^search(/.+)?$', '^search(/.+)?$',
array('urlSaba', 'saba') ['urlSaba', 'saba']
); );
# Add saba templates path # Add saba templates path
@ -38,74 +39,75 @@ if ($core->blog->settings->saba->active) {
# templates # templates
$core->tpl->addBlock( $core->tpl->addBlock(
'SabaIf', 'SabaIf',
array('tplSaba', 'SabaIf') ['tplSaba', 'SabaIf']
); );
$core->tpl->addBlock( $core->tpl->addBlock(
'SabaEntries', 'SabaEntries',
array('tplSaba', 'SabaEntries') ['tplSaba', 'SabaEntries']
); );
$core->tpl->addBlock( $core->tpl->addBlock(
'SabaFormIf', 'SabaFormIf',
array('tplSaba', 'SabaFormIf') ['tplSaba', 'SabaFormIf']
); );
$core->tpl->addValue( $core->tpl->addValue(
'SabaFormSearch', 'SabaFormSearch',
array('tplSaba', 'SabaFormSearch') ['tplSaba', 'SabaFormSearch']
); );
$core->tpl->addValue( $core->tpl->addValue(
'SabaFormOptions', 'SabaFormOptions',
array('tplSaba', 'SabaFormOptions') ['tplSaba', 'SabaFormOptions']
); );
$core->tpl->addValue( $core->tpl->addValue(
'SabaFormCategories', 'SabaFormCategories',
array('tplSaba', 'SabaFormCategories') ['tplSaba', 'SabaFormCategories']
); );
$core->tpl->addValue( $core->tpl->addValue(
'SabaFormTypes', 'SabaFormTypes',
array('tplSaba', 'SabaFormTypes') ['tplSaba', 'SabaFormTypes']
); );
$core->tpl->addValue( $core->tpl->addValue(
'SabaFormAges', 'SabaFormAges',
array('tplSaba', 'SabaFormAges') ['tplSaba', 'SabaFormAges']
); );
$core->tpl->addValue( $core->tpl->addValue(
'SabaFormOrders', 'SabaFormOrders',
array('tplSaba', 'SabaFormOrders') ['tplSaba', 'SabaFormOrders']
); );
$core->tpl->addValue( $core->tpl->addValue(
'SabaFormAuthors', 'SabaFormAuthors',
array('tplSaba', 'SabaFormAuthors') ['tplSaba', 'SabaFormAuthors']
); );
$core->tpl->addValue( $core->tpl->addValue(
'SabaPaginationURL', 'SabaPaginationURL',
array('tplSaba', 'SabaPaginationURL') ['tplSaba', 'SabaPaginationURL']
); );
$core->tpl->addValue( $core->tpl->addValue(
'SabaURL', 'SabaURL',
array('tplSaba','SabaURL') ['tplSaba', 'SabaURL']
); );
# behavior # behavior
$core->addBehavior( $core->addBehavior(
'templateCustomSortByAlias', 'templateCustomSortByAlias',
array('pubSaba', 'templateCustomSortByAlias') ['pubSaba', 'templateCustomSortByAlias']
); );
$core->addBehavior( $core->addBehavior(
'urlHandlerBeforeGetData', 'urlHandlerBeforeGetData',
array('pubSaba', 'urlHandlerBeforeGetData') ['pubSaba', 'urlHandlerBeforeGetData']
); );
$core->addBehavior( $core->addBehavior(
'corePostSearch', 'corePostSearch',
array('pubSaba', 'corePostSearch') ['pubSaba', 'corePostSearch']
); );
$core->url->registerError(array('urlSaba','error'));
} # url
$core->url->registerError(['urlSaba', 'error']);
class pubSaba class pubSaba
{ {
public static function templateCustomSortByAlias($alias) public static function templateCustomSortByAlias($alias)
{ {
$alias['post'] = array( $alias['post'] = [
'title' => 'post_title', 'title' => 'post_title',
'selected' => 'post_selected', 'selected' => 'post_selected',
'author' => 'user_id', 'author' => 'user_id',
@ -114,23 +116,23 @@ class pubSaba
'id' => 'post_id', 'id' => 'post_id',
'comment' => 'nb_comment', 'comment' => 'nb_comment',
'trackback' => 'nb_trackback' 'trackback' => 'nb_trackback'
); ];
} }
public static function urlHandlerBeforeGetData($_ctx) public static function urlHandlerBeforeGetData($_ctx)
{ {
global $core; global $core;
$options = array( $options = [
'q'=> '', 'q'=> '',
'q_opt' => array(), 'q_opt' => [],
'q_cat' => array(), 'q_cat' => [],
'q_age' => '0,0', 'q_age' => '0,0',
'q_user' => array(), 'q_user'=> [],
'q_order'=> 'date', 'q_order'=> 'date',
'q_rev' => '0', 'q_rev' => '0',
'q_type' => array() 'q_type'=> []
); ];
if (!empty($_GET['q']) && 1 < strlen($_GET['q'])) { if (!empty($_GET['q']) && 1 < strlen($_GET['q'])) {
# move to saba # move to saba
@ -142,10 +144,10 @@ class pubSaba
$qs = preg_replace('#(^|/)page/([0-9]+)#', '', $qs); $qs = preg_replace('#(^|/)page/([0-9]+)#', '', $qs);
parse_str($qs, $get); parse_str($qs, $get);
$params = array( $params = [
'sql'=>'', 'sql'=>'',
'post_type' => array() 'post_type' => []
); ];
# search string # search string
$params['search'] = rawurldecode($_GET['q']); $params['search'] = rawurldecode($_GET['q']);
@ -206,10 +208,12 @@ class pubSaba
$options['q_age'] = $get['q_age']; $options['q_age'] = $get['q_age'];
if ($age[0]) { if ($age[0]) {
$params['sql'] .= "AND P.post_dt < '".dt::str('%Y-%m-%d %H:%m:%S', $ts-$age[0])."' "; $params['sql'] .= "AND P.post_dt < '" .
dt::str('%Y-%m-%d %H:%m:%S', $ts - $age[0]) . "' ";
} }
if ($age[1]) { if ($age[1]) {
$params['sql'] .= "AND P.post_dt > '".dt::str('%Y-%m-%d %H:%m:%S', $ts-$age[1])."' "; $params['sql'] .= "AND P.post_dt > '" .
dt::str('%Y-%m-%d %H:%m:%S', $ts - $age[1]) . "' ";
} }
} }
@ -236,7 +240,9 @@ class pubSaba
$options['q_order'] = $get['q_order']; $options['q_order'] = $get['q_order'];
$params['order'] = $core->tpl->getSortByStr( $params['order'] = $core->tpl->getSortByStr(
array('sortby'=>$get['q_order'], 'order'=>$sort),'post'); //?! post_type ['sortby' => $get['q_order'], 'order' => $sort],
'post'
); //?! post_type
} }
# count # count
@ -248,7 +254,7 @@ class pubSaba
# pagintaion # pagintaion
$_page_number = !isset($GLOBALS['_page_number']) ? 1 : $GLOBALS['_page_number']; $_page_number = !isset($GLOBALS['_page_number']) ? 1 : $GLOBALS['_page_number'];
$params['limit'] = $_ctx->nb_entry_per_page; $params['limit'] = $_ctx->nb_entry_per_page;
$params['limit'] = array((($_page_number-1)*$params['limit']), $params['limit']); $params['limit'] = [(($_page_number - 1) * $params['limit']), $params['limit']];
# get posts # get posts
$_ctx->post_params = $params; $_ctx->post_params = $params;
@ -263,10 +269,9 @@ class pubSaba
{ {
$sentences = explode(',', $p[2]['search']); $sentences = explode(',', $p[2]['search']);
$OR = array(); $OR = [];
foreach($sentences as $sentence) foreach($sentences as $sentence) {
{ $AND = [];
$AND = array();
$words = text::splitWords($sentence); $words = text::splitWords($sentence);
foreach($words as $word) { foreach($words as $word) {
$AND[] = "post_words LIKE '%" . $core->con->escape($word) . "%'"; $AND[] = "post_words LIKE '%" . $core->con->escape($word) . "%'";
@ -291,7 +296,6 @@ class urlSaba extends dcUrlHandlers
if ($e->getCode() == 404) { if ($e->getCode() == 404) {
$q = explode('/', $args); $q = explode('/', $args);
if (empty($q)) { if (empty($q)) {
return false; return false;
} }
@ -333,7 +337,7 @@ class tplSaba
public static function SabaIf($a, $c) public static function SabaIf($a, $c)
{ {
$if = array(); $if = [];
$operator = isset($a['operator']) ? $GLOBALS['core']->tpl->getOperator($a['operator']) : '&&'; $operator = isset($a['operator']) ? $GLOBALS['core']->tpl->getOperator($a['operator']) : '&&';
@ -361,7 +365,7 @@ class tplSaba
public static function SabaFormIf($a, $c) public static function SabaFormIf($a, $c)
{ {
$if = array(); $if = [];
$operator = isset($a['operator']) ? $GLOBALS['core']->tpl->getOperator($a['operator']) : '&&'; $operator = isset($a['operator']) ? $GLOBALS['core']->tpl->getOperator($a['operator']) : '&&';
@ -380,7 +384,7 @@ class tplSaba
public static function SabaFormOptions($a) public static function SabaFormOptions($a)
{ {
$dis = !empty($a['remove']) ? explode(',', $a['remove']) : array(); $dis = !empty($a['remove']) ? explode(',', $a['remove']) : [];
$res = ''; $res = '';
$li = '<li><label><input name="q_opt[]" type="checkbox" value="%s" %s/> %s</label></li>'; $li = '<li><label><input name="q_opt[]" type="checkbox" value="%s" %s/> %s</label></li>';
@ -395,14 +399,13 @@ class tplSaba
} }
if (!empty($res)) { if (!empty($res)) {
return '<div class="saba_opt_otp"><h3>' . __('Filter options') . '</h3><ul>' . $res . '</ul></div>'; return '<div class="saba_opt_otp"><h3>' . __('Filter options') . '</h3><ul>' . $res . '</ul></div>';
} }
} }
public static function SabaFormOrders($a) public static function SabaFormOrders($a)
{ {
$dis = !empty($a['remove']) ? explode(',',$a['remove']) : array(); $dis = !empty($a['remove']) ? explode(',',$a['remove']) : [];
$res = ''; $res = '';
$li = '<li><label><input name="q_order" type="radio" value="%s" %s/> %s</label></li>'; $li = '<li><label><input name="q_order" type="radio" value="%s" %s/> %s</label></li>';
@ -428,7 +431,7 @@ class tplSaba
{ {
global $core; global $core;
$dis = !empty($a['remove']) ? explode(',', $a['remove']) : array(); $dis = !empty($a['remove']) ? explode(',', $a['remove']) : [];
$res = ''; $res = '';
$li = '<li><label><input name="q_cat[]" type="checkbox" value="%s" %s/> %s</label></li>'; $li = '<li><label><input name="q_cat[]" type="checkbox" value="%s" %s/> %s</label></li>';
@ -443,7 +446,6 @@ class tplSaba
} }
if (!empty($res)) { if (!empty($res)) {
return '<div class="saba_opt_cat"><h3>' . __('Filter by category') . '</h3><ul>' . $res . '</ul></div>'; return '<div class="saba_opt_cat"><h3>' . __('Filter by category') . '</h3><ul>' . $res . '</ul></div>';
} }
} }
@ -452,7 +454,7 @@ class tplSaba
{ {
global $core; global $core;
$dis = !empty($a['remove']) ? explode(',',$a['remove']) : array(); $dis = !empty($a['remove']) ? explode(',',$a['remove']) : [];
$res = ''; $res = '';
$li = '<li><label><input name="q_type[]" type="checkbox" value="%s" %s/>%s</label></li>'; $li = '<li><label><input name="q_type[]" type="checkbox" value="%s" %s/>%s</label></li>';
@ -467,7 +469,6 @@ class tplSaba
} }
if (!empty($res)) { if (!empty($res)) {
return '<div class="saba_opt_type"><h3>' . __('Filter by type') . '</h3><ul>' . $res . '</ul></div>'; return '<div class="saba_opt_type"><h3>' . __('Filter by type') . '</h3><ul>' . $res . '</ul></div>';
} }
} }
@ -484,7 +485,6 @@ class tplSaba
} }
if (!empty($res)) { if (!empty($res)) {
return '<div class="saba_opt_age"><h3>' . __('Filter by age') . '</h3><ul>' . $res . '</ul></div>'; return '<div class="saba_opt_age"><h3>' . __('Filter by age') . '</h3><ul>' . $res . '</ul></div>';
} }
} }
@ -493,7 +493,7 @@ class tplSaba
{ {
global $core; global $core;
$dis = !empty($a['remove']) ? explode(',',$a['remove']) : array(); $dis = !empty($a['remove']) ? explode(',',$a['remove']) : [];
$res = ''; $res = '';
$li = '<li><label><input name="q_user[]" type="checkbox" value="%s" %s/> %s</label></li>'; $li = '<li><label><input name="q_user[]" type="checkbox" value="%s" %s/> %s</label></li>';
@ -508,7 +508,6 @@ class tplSaba
} }
if (!empty($res)) { if (!empty($res)) {
return '<div class="saba_opt_user"><h3>' . __('Filter by author') . '</h3><ul>' . $res . '</ul></div>'; return '<div class="saba_opt_user"><h3>' . __('Filter by author') . '</h3><ul>' . $res . '</ul></div>';
} }
} }
@ -527,28 +526,28 @@ class tplSaba
public static function getSabaFormFilters() public static function getSabaFormFilters()
{ {
return array( return [
'options', 'options',
'orders', 'orders',
'ages', 'ages',
'categories', 'categories',
'authors', 'authors',
'types' 'types'
); ];
} }
public static function getSabaFormOptions() public static function getSabaFormOptions()
{ {
return array( return [
__('Selected entry') => 'selected', __('Selected entry') => 'selected',
__('With comments') => 'comment', __('With comments') => 'comment',
__('With trackbacks') => 'trackback' __('With trackbacks') => 'trackback'
); ];
} }
public static function getSabaFormOrders() public static function getSabaFormOrders()
{ {
return array( return [
__('Title') => 'title', __('Title') => 'title',
__('Selected entry') => 'selected', __('Selected entry') => 'selected',
__('Author') => 'author', __('Author') => 'author',
@ -556,30 +555,31 @@ class tplSaba
__('Update') => 'update', __('Update') => 'update',
__('Comments count') => 'comment', __('Comments count') => 'comment',
__('Trackbacks count') => 'trackback' __('Trackbacks count') => 'trackback'
); ];
} }
public static function getSabaFormAges() public static function getSabaFormAges()
{ {
return array( return [
__('All') => '0,0', __('All') => '0,0',
__('Less than a month') => '0,2592000', __('Less than a month') => '0,2592000',
__('From 1 to 6 month') => '2592000,15552000', __('From 1 to 6 month') => '2592000,15552000',
__('From 6 to 12 month') => '15552000,31536000', __('From 6 to 12 month') => '15552000,31536000',
__('More than a year') => '31536000,0' __('More than a year') => '31536000,0'
); ];
} }
public static function getSabaFormTypes() public static function getSabaFormTypes()
{ {
$know = array( $know = [
'post' => __('Entry'), 'post' => __('Entry'),
'page' => __('Page'), 'page' => __('Page'),
'pollsfactory' => __('Poll'), 'pollsfactory' => __('Poll'),
'eventhandler' => __('Event') 'eventhandler' => __('Event')
); ];
// todo: add behavior for unknow types
$rs = array(); $rs = [];
$types = $GLOBALS['core']->getPostTypes(); $types = $GLOBALS['core']->getPostTypes();
foreach($types as $k => $v) { foreach($types as $k => $v) {
@ -597,7 +597,7 @@ class tplSaba
$filters = (string) $GLOBALS['core']->blog->settings->saba->filters; $filters = (string) $GLOBALS['core']->blog->settings->saba->filters;
$filters = @unserialize($filters); $filters = @unserialize($filters);
if (!is_array($filters)) { if (!is_array($filters)) {
$filters = array(); $filters = [];
} }
return !in_array($f, $filters); return !in_array($f, $filters);

View file

@ -12,7 +12,6 @@
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }