Dotclear

Changeset 3733:ee69b09370ec for plugins


Ignore:
Timestamp:
03/15/18 11:48:54 (8 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Add latest (associated entry date) and oldest (associated entry date) info when request list of metadata: it will provide a way to sort these metadata.

Plugin Tags updated in order to use this new feature (widget and templates)

Location:
plugins/tags
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • plugins/tags/_define.php

    r3731 r3733  
    1616    "Tags for posts",  // Description 
    1717    "Olivier Meunier", // Author 
    18     '1.4',             // Version 
     18    '1.5',             // Version 
    1919    array( 
    2020        'permissions' => 'usage,contentadmin', 
  • plugins/tags/_public.php

    r3731 r3733  
    9494        $limit = isset($attr['limit']) ? (integer) $attr['limit'] : 'null'; 
    9595 
     96        $combo = array('meta_id_lower', 'count', 'latest', 'oldest'); 
     97 
    9698        $sortby = 'meta_id_lower'; 
    97         if (isset($attr['sortby']) && $attr['sortby'] == 'count') { 
    98             $sortby = 'count'; 
     99        if (isset($attr['sortby']) && in_array($attr['sortby'], $combo)) { 
     100            $sortby = strtolower($attr['sortby']); 
    99101        } 
    100102 
     
    107109            "<?php\n" . 
    108110            "\$_ctx->meta = \$core->meta->computeMetaStats(\$core->meta->getMetadata(array('meta_type'=>'" 
    109             . $type . "','limit'=>" . $limit . "))); " . 
     111            . $type . "','limit'=>" . $limit . 
     112            ($sortby != 'meta_id_lower' ? ",'order'=>'" . $sortby . ' ' . ($order == 'asc' ? 'ASC' : 'DESC' ) : '') . "'" . 
     113            "))); " . 
    110114            "\$_ctx->meta->sort('" . $sortby . "','" . $order . "'); " . 
    111115            '?>'; 
     
    138142        $type = isset($attr['type']) ? addslashes($attr['type']) : 'tag'; 
    139143 
     144        $combo = array('meta_id_lower', 'count', 'latest', 'oldest'); 
     145 
    140146        $sortby = 'meta_id_lower'; 
    141         if (isset($attr['sortby']) && $attr['sortby'] == 'count') { 
    142             $sortby = 'count'; 
     147        if (isset($attr['sortby']) && in_array($attr['sortby'], $combo)) { 
     148            $sortby = strtolower($attr['sortby']); 
    143149        } 
    144150 
     
    239245        } 
    240246 
    241         $params = array('meta_type' => 'tag'); 
    242  
    243         if ($w->limit !== '') { 
    244             $params['limit'] = abs((integer) $w->limit); 
    245         } 
    246  
    247         $rs = $core->meta->computeMetaStats( 
    248             $core->meta->getMetadata($params)); 
    249  
    250         if ($rs->isEmpty()) { 
    251             return; 
    252         } 
     247        $combo = array('meta_id_lower', 'count', 'latest', 'oldest'); 
    253248 
    254249        $sort = $w->sortby; 
    255         if (!in_array($sort, array('meta_id_lower', 'count'))) { 
     250        if (!in_array($sort, $combo)) { 
    256251            $sort = 'meta_id_lower'; 
    257252        } 
     
    262257        } 
    263258 
    264         $rs->sort($sort, $order); 
     259        $params = array('meta_type' => 'tag'); 
     260 
     261        if ($sort != 'meta_id_lower') { 
     262            // As optional limit may restrict result, we should set order (if not computed after) 
     263            $params['order'] = $sort . ' ' . ($order == 'asc' ? 'ASC' : 'DESC'); 
     264        } 
     265 
     266        if ($w->limit !== '') { 
     267            $params['limit'] = abs((integer) $w->limit); 
     268        } 
     269 
     270        $rs = $core->meta->computeMetaStats( 
     271            $core->meta->getMetadata($params)); 
     272 
     273        if ($rs->isEmpty()) { 
     274            return; 
     275        } 
     276 
     277        if ($sort == 'meta_id_lower') { 
     278            // Sort resulting recordset on cleaned id 
     279            $rs->sort($sort, $order); 
     280        } 
    265281 
    266282        $res = 
  • plugins/tags/_widgets.php

    r3731 r3733  
    1919    public static function initWidgets($w) 
    2020    { 
     21        $combo = array( 
     22            __('Tag name')       => 'meta_id_lower', 
     23            __('Entries count')  => 'count', 
     24            __('Newest entry')   => 'latest', 
     25            __('Oldest entry')   => 'oldest' 
     26        ); 
     27 
    2128        $w->create('tags', __('Tags'), array('tplTags', 'tagsWidget'), null, 'Tags cloud'); 
    2229        $w->tags->setting('title', __('Title (optional)') . ' :', __('Tags')); 
    2330        $w->tags->setting('limit', __('Limit (empty means no limit):'), '20'); 
    24         $w->tags->setting('sortby', __('Order by:'), 'meta_id_lower', 'combo', 
    25             array(__('Tag name') => 'meta_id_lower', __('Entries count') => 'count') 
    26         ); 
     31        $w->tags->setting('sortby', __('Order by:'), 'meta_id_lower', 'combo', $combo); 
    2732        $w->tags->setting('orderby', __('Sort:'), 'asc', 'combo', 
    2833            array(__('Ascending') => 'asc', __('Descending') => 'desc') 
Note: See TracChangeset for help on using the changeset viewer.

Sites map