move to PSR-2 coding style and short array
This commit is contained in:
parent
ac274d3349
commit
f64f1f6157
@ -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
|
||||
|
@ -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
|
||||
@ -27,3 +27,9 @@ 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.
|
||||
|
||||
## 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)
|
24
_define.php
24
_define.php
@ -12,25 +12,19 @@
|
||||
# -- END LICENSE BLOCK ------------------------------------
|
||||
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->registerModule(
|
||||
/* Name */
|
||||
"saba",
|
||||
/* Description*/
|
||||
"Search across blog's archive",
|
||||
/* Author */
|
||||
"Jean-Christian Denis",
|
||||
/* Version */
|
||||
'2021.08.20.3',
|
||||
/* Properies */
|
||||
array(
|
||||
'saba',
|
||||
'Search across blog archive',
|
||||
'Jean-Christian Denis and Contributors',
|
||||
'2021.08.20.5',
|
||||
[
|
||||
'permissions' => 'admin',
|
||||
'type' => 'plugin',
|
||||
'dc_min' => '2.6',
|
||||
'support' => 'http://jcd.lv/q=saba',
|
||||
'details' => 'http://plugins.dotaddict.org/dc2/details/saba'
|
||||
)
|
||||
'dc_min' => '2.18',
|
||||
'support' => 'https://github.com/JcDenis/saba',
|
||||
'details' => 'https://plugins.dotaddict.org/dc2/details/saba'
|
||||
]
|
||||
);
|
128
_public.php
128
_public.php
@ -12,21 +12,22 @@
|
||||
# -- END LICENSE BLOCK ------------------------------------
|
||||
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
# Admin behaviors
|
||||
$core->blog->settings->addNamespace('saba');
|
||||
|
||||
if ($core->blog->settings->saba->active) {
|
||||
if (!$core->blog->settings->saba->active) {
|
||||
return null;
|
||||
}
|
||||
|
||||
# Register saba handler
|
||||
$core->url->register(
|
||||
'search',
|
||||
'search',
|
||||
'^search(/.+)?$',
|
||||
array('urlSaba', 'saba')
|
||||
['urlSaba', 'saba']
|
||||
);
|
||||
|
||||
# Add saba templates path
|
||||
@ -38,74 +39,75 @@ if ($core->blog->settings->saba->active) {
|
||||
# templates
|
||||
$core->tpl->addBlock(
|
||||
'SabaIf',
|
||||
array('tplSaba', 'SabaIf')
|
||||
['tplSaba', 'SabaIf']
|
||||
);
|
||||
$core->tpl->addBlock(
|
||||
'SabaEntries',
|
||||
array('tplSaba', 'SabaEntries')
|
||||
['tplSaba', 'SabaEntries']
|
||||
);
|
||||
$core->tpl->addBlock(
|
||||
'SabaFormIf',
|
||||
array('tplSaba', 'SabaFormIf')
|
||||
['tplSaba', 'SabaFormIf']
|
||||
);
|
||||
$core->tpl->addValue(
|
||||
'SabaFormSearch',
|
||||
array('tplSaba', 'SabaFormSearch')
|
||||
['tplSaba', 'SabaFormSearch']
|
||||
);
|
||||
$core->tpl->addValue(
|
||||
'SabaFormOptions',
|
||||
array('tplSaba', 'SabaFormOptions')
|
||||
['tplSaba', 'SabaFormOptions']
|
||||
);
|
||||
$core->tpl->addValue(
|
||||
'SabaFormCategories',
|
||||
array('tplSaba', 'SabaFormCategories')
|
||||
['tplSaba', 'SabaFormCategories']
|
||||
);
|
||||
$core->tpl->addValue(
|
||||
'SabaFormTypes',
|
||||
array('tplSaba', 'SabaFormTypes')
|
||||
['tplSaba', 'SabaFormTypes']
|
||||
);
|
||||
$core->tpl->addValue(
|
||||
'SabaFormAges',
|
||||
array('tplSaba', 'SabaFormAges')
|
||||
['tplSaba', 'SabaFormAges']
|
||||
);
|
||||
$core->tpl->addValue(
|
||||
'SabaFormOrders',
|
||||
array('tplSaba', 'SabaFormOrders')
|
||||
['tplSaba', 'SabaFormOrders']
|
||||
);
|
||||
$core->tpl->addValue(
|
||||
'SabaFormAuthors',
|
||||
array('tplSaba', 'SabaFormAuthors')
|
||||
['tplSaba', 'SabaFormAuthors']
|
||||
);
|
||||
$core->tpl->addValue(
|
||||
'SabaPaginationURL',
|
||||
array('tplSaba', 'SabaPaginationURL')
|
||||
['tplSaba', 'SabaPaginationURL']
|
||||
);
|
||||
$core->tpl->addValue(
|
||||
'SabaURL',
|
||||
array('tplSaba','SabaURL')
|
||||
['tplSaba', 'SabaURL']
|
||||
);
|
||||
|
||||
# behavior
|
||||
$core->addBehavior(
|
||||
'templateCustomSortByAlias',
|
||||
array('pubSaba', 'templateCustomSortByAlias')
|
||||
['pubSaba', 'templateCustomSortByAlias']
|
||||
);
|
||||
$core->addBehavior(
|
||||
'urlHandlerBeforeGetData',
|
||||
array('pubSaba', 'urlHandlerBeforeGetData')
|
||||
['pubSaba', 'urlHandlerBeforeGetData']
|
||||
);
|
||||
$core->addBehavior(
|
||||
'corePostSearch',
|
||||
array('pubSaba', 'corePostSearch')
|
||||
['pubSaba', 'corePostSearch']
|
||||
);
|
||||
$core->url->registerError(array('urlSaba','error'));
|
||||
}
|
||||
|
||||
# url
|
||||
$core->url->registerError(['urlSaba', 'error']);
|
||||
|
||||
class pubSaba
|
||||
{
|
||||
public static function templateCustomSortByAlias($alias)
|
||||
{
|
||||
$alias['post'] = array(
|
||||
$alias['post'] = [
|
||||
'title' => 'post_title',
|
||||
'selected' => 'post_selected',
|
||||
'author' => 'user_id',
|
||||
@ -114,23 +116,23 @@ class pubSaba
|
||||
'id' => 'post_id',
|
||||
'comment' => 'nb_comment',
|
||||
'trackback' => 'nb_trackback'
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
public static function urlHandlerBeforeGetData($_ctx)
|
||||
{
|
||||
global $core;
|
||||
|
||||
$options = array(
|
||||
$options = [
|
||||
'q'=> '',
|
||||
'q_opt' => array(),
|
||||
'q_cat' => array(),
|
||||
'q_opt' => [],
|
||||
'q_cat' => [],
|
||||
'q_age' => '0,0',
|
||||
'q_user' => array(),
|
||||
'q_user'=> [],
|
||||
'q_order'=> 'date',
|
||||
'q_rev' => '0',
|
||||
'q_type' => array()
|
||||
);
|
||||
'q_type'=> []
|
||||
];
|
||||
|
||||
if (!empty($_GET['q']) && 1 < strlen($_GET['q'])) {
|
||||
# move to saba
|
||||
@ -142,10 +144,10 @@ class pubSaba
|
||||
$qs = preg_replace('#(^|/)page/([0-9]+)#', '', $qs);
|
||||
parse_str($qs, $get);
|
||||
|
||||
$params = array(
|
||||
$params = [
|
||||
'sql'=>'',
|
||||
'post_type' => array()
|
||||
);
|
||||
'post_type' => []
|
||||
];
|
||||
|
||||
# search string
|
||||
$params['search'] = rawurldecode($_GET['q']);
|
||||
@ -206,10 +208,12 @@ class pubSaba
|
||||
$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])."' ";
|
||||
$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])."' ";
|
||||
$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'];
|
||||
$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
|
||||
@ -248,7 +254,7 @@ class pubSaba
|
||||
# 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']);
|
||||
$params['limit'] = [(($_page_number - 1) * $params['limit']), $params['limit']];
|
||||
|
||||
# get posts
|
||||
$_ctx->post_params = $params;
|
||||
@ -263,10 +269,9 @@ class pubSaba
|
||||
{
|
||||
$sentences = explode(',', $p[2]['search']);
|
||||
|
||||
$OR = array();
|
||||
foreach($sentences as $sentence)
|
||||
{
|
||||
$AND = array();
|
||||
$OR = [];
|
||||
foreach($sentences as $sentence) {
|
||||
$AND = [];
|
||||
$words = text::splitWords($sentence);
|
||||
foreach($words as $word) {
|
||||
$AND[] = "post_words LIKE '%" . $core->con->escape($word) . "%'";
|
||||
@ -291,7 +296,6 @@ class urlSaba extends dcUrlHandlers
|
||||
if ($e->getCode() == 404) {
|
||||
$q = explode('/', $args);
|
||||
if (empty($q)) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -333,7 +337,7 @@ class tplSaba
|
||||
|
||||
public static function SabaIf($a, $c)
|
||||
{
|
||||
$if = array();
|
||||
$if = [];
|
||||
|
||||
$operator = isset($a['operator']) ? $GLOBALS['core']->tpl->getOperator($a['operator']) : '&&';
|
||||
|
||||
@ -361,7 +365,7 @@ class tplSaba
|
||||
|
||||
public static function SabaFormIf($a, $c)
|
||||
{
|
||||
$if = array();
|
||||
$if = [];
|
||||
|
||||
$operator = isset($a['operator']) ? $GLOBALS['core']->tpl->getOperator($a['operator']) : '&&';
|
||||
|
||||
@ -380,7 +384,7 @@ class tplSaba
|
||||
|
||||
public static function SabaFormOptions($a)
|
||||
{
|
||||
$dis = !empty($a['remove']) ? explode(',', $a['remove']) : array();
|
||||
$dis = !empty($a['remove']) ? explode(',', $a['remove']) : [];
|
||||
|
||||
$res = '';
|
||||
$li = '<li><label><input name="q_opt[]" type="checkbox" value="%s" %s/> %s</label></li>';
|
||||
@ -395,14 +399,13 @@ class tplSaba
|
||||
}
|
||||
|
||||
if (!empty($res)) {
|
||||
|
||||
return '<div class="saba_opt_otp"><h3>' . __('Filter options') . '</h3><ul>' . $res . '</ul></div>';
|
||||
}
|
||||
}
|
||||
|
||||
public static function SabaFormOrders($a)
|
||||
{
|
||||
$dis = !empty($a['remove']) ? explode(',',$a['remove']) : array();
|
||||
$dis = !empty($a['remove']) ? explode(',',$a['remove']) : [];
|
||||
|
||||
$res = '';
|
||||
$li = '<li><label><input name="q_order" type="radio" value="%s" %s/> %s</label></li>';
|
||||
@ -428,7 +431,7 @@ class tplSaba
|
||||
{
|
||||
global $core;
|
||||
|
||||
$dis = !empty($a['remove']) ? explode(',', $a['remove']) : array();
|
||||
$dis = !empty($a['remove']) ? explode(',', $a['remove']) : [];
|
||||
|
||||
$res = '';
|
||||
$li = '<li><label><input name="q_cat[]" type="checkbox" value="%s" %s/> %s</label></li>';
|
||||
@ -443,7 +446,6 @@ class tplSaba
|
||||
}
|
||||
|
||||
if (!empty($res)) {
|
||||
|
||||
return '<div class="saba_opt_cat"><h3>' . __('Filter by category') . '</h3><ul>' . $res . '</ul></div>';
|
||||
}
|
||||
}
|
||||
@ -452,7 +454,7 @@ class tplSaba
|
||||
{
|
||||
global $core;
|
||||
|
||||
$dis = !empty($a['remove']) ? explode(',',$a['remove']) : array();
|
||||
$dis = !empty($a['remove']) ? explode(',',$a['remove']) : [];
|
||||
|
||||
$res = '';
|
||||
$li = '<li><label><input name="q_type[]" type="checkbox" value="%s" %s/>%s</label></li>';
|
||||
@ -467,7 +469,6 @@ class tplSaba
|
||||
}
|
||||
|
||||
if (!empty($res)) {
|
||||
|
||||
return '<div class="saba_opt_type"><h3>' . __('Filter by type') . '</h3><ul>' . $res . '</ul></div>';
|
||||
}
|
||||
}
|
||||
@ -484,7 +485,6 @@ class tplSaba
|
||||
}
|
||||
|
||||
if (!empty($res)) {
|
||||
|
||||
return '<div class="saba_opt_age"><h3>' . __('Filter by age') . '</h3><ul>' . $res . '</ul></div>';
|
||||
}
|
||||
}
|
||||
@ -493,7 +493,7 @@ class tplSaba
|
||||
{
|
||||
global $core;
|
||||
|
||||
$dis = !empty($a['remove']) ? explode(',',$a['remove']) : array();
|
||||
$dis = !empty($a['remove']) ? explode(',',$a['remove']) : [];
|
||||
|
||||
$res = '';
|
||||
$li = '<li><label><input name="q_user[]" type="checkbox" value="%s" %s/> %s</label></li>';
|
||||
@ -508,7 +508,6 @@ class tplSaba
|
||||
}
|
||||
|
||||
if (!empty($res)) {
|
||||
|
||||
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()
|
||||
{
|
||||
return array(
|
||||
return [
|
||||
'options',
|
||||
'orders',
|
||||
'ages',
|
||||
'categories',
|
||||
'authors',
|
||||
'types'
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
public static function getSabaFormOptions()
|
||||
{
|
||||
return array(
|
||||
return [
|
||||
__('Selected entry') => 'selected',
|
||||
__('With comments') => 'comment',
|
||||
__('With trackbacks') => 'trackback'
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
public static function getSabaFormOrders()
|
||||
{
|
||||
return array(
|
||||
return [
|
||||
__('Title') => 'title',
|
||||
__('Selected entry') => 'selected',
|
||||
__('Author') => 'author',
|
||||
@ -556,30 +555,31 @@ class tplSaba
|
||||
__('Update') => 'update',
|
||||
__('Comments count') => 'comment',
|
||||
__('Trackbacks count') => 'trackback'
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
public static function getSabaFormAges()
|
||||
{
|
||||
return array(
|
||||
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'
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
public static function getSabaFormTypes()
|
||||
{
|
||||
$know = array(
|
||||
$know = [
|
||||
'post' => __('Entry'),
|
||||
'page' => __('Page'),
|
||||
'pollsfactory' => __('Poll'),
|
||||
'eventhandler' => __('Event')
|
||||
);
|
||||
];
|
||||
// todo: add behavior for unknow types
|
||||
|
||||
$rs = array();
|
||||
$rs = [];
|
||||
$types = $GLOBALS['core']->getPostTypes();
|
||||
|
||||
foreach($types as $k => $v) {
|
||||
@ -597,7 +597,7 @@ class tplSaba
|
||||
$filters = (string) $GLOBALS['core']->blog->settings->saba->filters;
|
||||
$filters = @unserialize($filters);
|
||||
if (!is_array($filters)) {
|
||||
$filters = array();
|
||||
$filters = [];
|
||||
}
|
||||
|
||||
return !in_array($f, $filters);
|
||||
|
@ -12,7 +12,6 @@
|
||||
# -- END LICENSE BLOCK ------------------------------------
|
||||
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user