Dotclear

Changeset 3267


Ignore:
Timestamp:
11/16/13 14:46:51 (10 years ago)
Author:
JcDenis
Message:

Switch to DC 2.6, fixes lots of bugs

Location:
plugins/hum
Files:
3 added
2 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • plugins/hum/_admin.php

    r2611 r3267  
    11<?php 
    22# -- BEGIN LICENSE BLOCK ---------------------------------- 
     3# 
    34# This file is part of hum, a plugin for Dotclear 2. 
    45#  
    5 # Copyright (c) 2009-2010 JC Denis and contributors 
    6 # jcdenis@gdwd.com 
     6# Copyright (c) 2009-2013 Jean-Christian Denis and contributors 
     7# contact@jcdenis.fr http://jcd.lv 
    78#  
    89# Licensed under the GPL version 2.0 license. 
    910# A copy of this license is available in LICENSE file or at 
    1011# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 
     12# 
    1113# -- END LICENSE BLOCK ------------------------------------ 
    1214 
    13 if (!defined('DC_CONTEXT_ADMIN')){return;} 
     15if (!defined('DC_CONTEXT_ADMIN')) { 
     16 
     17     return null; 
     18} 
    1419 
    1520$core->blog->settings->addNamespace('hum'); 
    1621 
    17 # Plugin menu 
    18 $_menu['Plugins']->addItem( 
    19      __('Useless comments'), 
    20      'plugin.php?p=hum','index.php?pf=hum/icon.png', 
    21      preg_match('/plugin.php\?p=hum(&.*)?$/',$_SERVER['REQUEST_URI']), 
    22      $core->auth->check('admin',$core->blog->id) 
    23 ); 
    24  
    2522if ($core->blog->settings->hum->active) { 
    26      # admin/comments.php Add actions on comments combo 
    27      $core->addBehavior('adminCommentsActionsCombo',array('adminHum','adminCommentsActionsCombo')); 
    28      # admin/comments_actions.php Save actions on comments 
    29      $core->addBehavior('adminCommentsActions',array('adminHum','adminCommentsActions')); 
    30      # admin/comment.php Action on comments 
    31      $core->addBehavior('adminBeforeCommentCreate',array('adminHum','adminBeforeCommentSave')); 
    32      $core->addBehavior('adminBeforeCommentUpdate',array('adminHum','adminBeforeCommentSave')); 
    33      $core->addBehavior('adminAfterCommentDesc',array('adminHum','adminAfterCommentDesc')); 
    34      # inc/blog.php Extend core blog getComments() 
    35      $core->addBehavior('coreBlogGetComments',array('adminHum','coreBlogGetComments')); 
    36      $core->addBehavior('coreBeforeCommentCreate',array('adminHum','coreBeforeCommentCreate')); 
     23 
     24     $core->addBehavior( 
     25          'adminCommentsActionsPage', 
     26          array('adminHum', 'adminCommentsActionsPage') 
     27     ); 
     28     $core->addBehavior( 
     29          'adminBeforeCommentCreate', 
     30          array('adminHum', 'adminBeforeCommentSave') 
     31     ); 
     32     $core->addBehavior( 
     33          'adminBeforeCommentUpdate', 
     34          array('adminHum', 'adminBeforeCommentSave') 
     35     ); 
     36     $core->addBehavior( 
     37          'adminAfterCommentDesc', 
     38          array('adminHum', 'adminAfterCommentDesc') 
     39     ); 
     40 
     41     $core->addBehavior( 
     42          'coreBlogGetComments', 
     43          array('adminHum', 'coreBlogGetComments') 
     44     ); 
     45     $core->addBehavior( 
     46          'coreBeforeCommentCreate', 
     47          array('adminHum', 'coreBeforeCommentCreate') 
     48     ); 
     49 
     50     $core->addBehavior( 
     51          'adminPostsActionsPage', 
     52          array('adminHum', 'adminPostsActionsPage') 
     53     ); 
     54     $core->addBehavior( 
     55          'adminPagesActionsPage', 
     56          array('adminHum', 'adminPostsActionsPage') 
     57     ); 
     58 
    3759     # admin/posts.php Add actions on comments combo of entries 
    38      $core->addBehavior('adminPostsActionsCombo',array('adminHum','adminPostsActionsCombo')); 
     60     //$core->addBehavior('adminPostsActionsCombo',array('adminHum','adminPostsActionsCombo')); 
    3961     # admin/posts_actions.php Save actions on comments of entries 
    40      $core->addBehavior('adminPostsActions',array('adminHum','adminPostsActions')); 
     62     //$core->addBehavior('adminPostsActions',array('adminHum','adminPostsActions')); 
    4163} 
    4264 
    43 # Extends getComments() only on admin side 
     65/** 
     66 * @ingroup DC_PLUGIN_HUM 
     67 * @brief Extends getComments() only on admin side. 
     68 * @since 2.6 
     69 */ 
    4470class rsExtHum extends rsExtComment 
    4571{ 
    4672     public static function is_selected($rs) 
    4773     { 
    48           # On bloc "Comments" on public side we have it. 
    49           if ($rs->exists('comment_selected')) { 
    50                return (boolean) $rs->comment_selected; 
    51           } 
    52           # Or create a memory array (to prevent multiple requests on same id) 
    53           if (!$rs->exists('comment_selected_memory')) { 
    54                $rs->comment_selected_memory = array(); 
    55           } 
    56           # Check memory array to see if it has it 
    57           if (empty($rs->comment_selected_memory[$rs->comment_id])) { 
    58                $res = $rs->core->con->select( 
    59                     'SELECT comment_selected FROM '.$rs->core->prefix.'comment '. 
    60                     'WHERE comment_id = '.$rs->comment_id.' '. 
    61                     'LIMIT 1' 
    62                ); 
    63                # Put info into memory array 
    64                if ($res->isEmpty()) { 
    65                     $rs->comment_selected_memory[$rs->comment_id] = 0; 
    66                } 
    67                else { 
    68                     $rs->comment_selected_memory[$rs->comment_id] = $res->f(0); 
    69                } 
    70           } 
    71           # Then return info 
    72           return (boolean) $rs->comment_selected_memory[$rs->comment_id]; 
     74          $res = $rs->core->con->select( 
     75               'SELECT comment_selected FROM '.$rs->core->prefix.'comment '. 
     76               'WHERE comment_id = '.$rs->comment_id.' '. 
     77               'LIMIT 1' 
     78          ); 
     79 
     80          return $res->isEmpty() ? null : $res->f(0); 
    7381     } 
    7482} 
    7583 
     84/** 
     85 * @ingroup DC_PLUGIN_HUM 
     86 * @brief Admin methods to add comments actions. 
     87 * @since 2.6 
     88 */ 
    7689class adminHum 
    7790{ 
    78      public static function coreBlogGetComments($rs) 
     91     /** 
     92      * Add comment selection to record ressource 
     93      *  
     94      * @param  record $rs record instance 
     95      */ 
     96     public static function coreBlogGetComments(record $rs) 
    7997     { 
    8098          $rs->extend('rsExtHum'); 
    8199     } 
    82       
    83      public static function coreBeforeCommentCreate($blog,$cur) 
     100 
     101     /** 
     102      * Add default selction of comment on comment creation 
     103      *  
     104      * @param  dcBlog $blog dcBlog instance 
     105      * @param  cursor $cur  cursor instance 
     106      */ 
     107     public static function coreBeforeCommentCreate(dcBlog $blog, cursor $cur) 
    84108     { 
    85109          if (null === $cur->comment_selected) { 
     
    87111          } 
    88112     } 
    89       
    90      public static function adminCommentsActionsCombo($args) 
    91      { 
    92           if ($GLOBALS['core']->auth->check('publish,contentadmin',$GLOBALS['core']->blog->id)) 
    93           { 
    94                $args[0][__('Mark as selected')] = 'selected'; 
    95                $args[0][__('Mark as unselected')] = 'unselected'; 
    96           } 
    97      } 
    98       
    99      public static function adminCommentsActions($core,$co,$action,$redir) 
    100      { 
    101           if (preg_match('/^(selected|unselected)$/',$action)) 
    102           { 
    103                switch ($action) { 
    104                     case 'selected' : $selected = 1; break; 
    105                     default : $selected = 0; break; 
    106                } 
    107                 
    108                while ($co->fetch()) 
    109                { 
    110                     try { 
    111                          $cur = $core->con->openCursor($core->prefix.'comment'); 
    112                          $cur->comment_selected = (integer) $selected; 
    113                          $core->blog->updComment($co->comment_id,$cur); 
    114                     } catch (Exception $e) { 
    115                          $core->error->add($e->getMessage()); 
    116                     } 
    117                } 
    118                 
    119                if (!$core->error->flag()) { 
    120                     http::redirect($redir); 
    121                } 
    122           } 
    123      } 
    124       
    125      public static function adminBeforeCommentSave($cur,$comment_id=null) 
    126      { 
    127           $cur->comment_selected = (integer) !empty($_POST['comment_selected']); 
    128      } 
    129       
    130      public static function adminAfterCommentDesc($rs) 
    131      { 
    132           if (!empty($GLOBALS['core']->rest) && !empty($GLOBALS['core']->rest->functions['getCommentById'])) { 
     113 
     114     /** 
     115      * Add actions to coments page combo 
     116      *  
     117      * @param  dcCore                $core dcCore instance 
     118      * @param  dcCommentsActionsPage $ap   dcCommentsActionsPage instance 
     119      */ 
     120     public static function adminCommentsActionsPage(dcCore $core, dcCommentsActionsPage $pa) 
     121     { 
     122          if (!$core->auth->check('publish,contentadmin',$core->blog->id)) { 
     123 
     124               return null; 
     125          } 
     126 
     127          $pa->addAction( 
     128               array( 
     129                    __('Useless comments') => array( 
     130                         __('Mark as selected') => 'hum_selected' 
     131                    ) 
     132               ), 
     133               array('adminHum', 'callbackCommentsAction') 
     134          ); 
     135 
     136          $pa->addAction( 
     137               array( 
     138                    __('Useless comments') => array( 
     139                         __('Mark as unselected') => 'hum_unselected' 
     140                    ) 
     141               ), 
     142               array('adminHum', 'callbackCommentsAction') 
     143          ); 
     144     } 
     145 
     146     /** 
     147      * Comments actions callback to add hum actions 
     148      *  
     149      * @param  dcCore                $core dcCore instance 
     150      * @param  dcCommentsActionsPage $ap   dcCommentsActionsPage instance 
     151      * @param  ArrayObject           $post POST actions 
     152      */ 
     153     public static function callbackCommentsAction(dcCore $core, dcCommentsActionsPage $ap, ArrayObject $post) 
     154     { 
     155          # No entry 
     156          $ids = $ap->getIDs(); 
     157          if (empty($ids)) { 
     158               throw new Exception(__('No comment selected')); 
     159          } 
     160 
     161          # No action 
     162          if (!in_array($ap->getAction(), array('hum_selected', 'hum_unselected'))) { 
     163 
     164               $ap->redirect(false); 
     165               return null; 
     166          } 
     167 
     168          $selected = $ap->getAction() == 'hum_selected'; 
     169 
     170          foreach($posts_ids as $post_id) { 
     171               self::selectComment($core, $id, $selected); 
     172          } 
     173 
     174          dcPage::addSuccessNotice(__('Comments selection changed.')); 
     175          $ap->redirect(true); 
     176     } 
     177 
     178     /** 
     179      * Add comment selection to cursor 
     180      *  
     181      * @param  cursor $cur         cursor insatnce 
     182      * @param  integer $comment_id Comment Id or null 
     183      */ 
     184     public static function adminBeforeCommentSave(cursor $cur, $comment_id=null) 
     185     { 
     186          $cur->comment_selected = (integer) !empty($_POST['hum_selected']); 
     187     } 
     188 
     189     /** 
     190      * Add hum to comment details page 
     191      *  
     192      * @param  record $rs record instance 
     193      * @return string     Form field or info about comment selection 
     194      */ 
     195     public static function adminAfterCommentDesc(record $rs) 
     196     { 
     197          if (!empty($rs->core->rest) && !empty($rs->core->rest->functions['getCommentById'])) { 
    133198               return '<br /><strong>'.__('Selected:').' </strong> '. 
    134199               ($rs->is_selected() ? __('yes') : __('no')).'<br />'; 
     
    136201          else { 
    137202               return  
    138                '<p><label class="classic">'.form::checkbox('comment_selected',1,$rs->is_selected(),'',3).' '. 
     203               '<p><label class="classic" for="hum_selected">'. 
     204               form::checkbox('hum_selected', 1, $rs->is_selected()). 
    139205               __('Selected comment').'</label></p>'; 
    140206          } 
    141207     } 
    142       
    143      public static function adminPostsActionsCombo($args) 
    144      { 
    145           if ($GLOBALS['core']->auth->check('publish,contentadmin',$GLOBALS['core']->blog->id)) 
    146           { 
    147                $args[0][__('Comments')][__('Mark as selected')] = 'commentselected'; 
    148                $args[0][__('Comments')][__('Mark as unselected')] = 'commentunselected'; 
    149           } 
    150      } 
    151       
    152      public static function adminPostsActions($core,$posts,$action,$redir) 
    153      { 
    154           if (preg_match('/^(commentselected|commentunselected)$/',$action)) 
    155           { 
    156                switch ($action) { 
    157                     case 'commentselected' : $selected = 1; break; 
    158                     default : $selected = 0; break; 
    159                } 
    160                 
    161                while ($posts->fetch()) 
    162                { 
    163                     try { 
    164                          $co_params['post_id'] = $posts->post_id; 
    165                          $co_params['comment_trackback'] = 0; 
    166                          $co = $core->blog->getComments($co_params); 
    167                          while($co->fetch()) { 
    168                               $cur = $core->con->openCursor($core->prefix.'comment'); 
    169                               $cur->comment_selected = (integer) $selected; 
    170                               $core->blog->updComment($co->comment_id,$cur); 
    171                          } 
    172                     } catch (Exception $e) {exit(1); 
    173                          $core->error->add($e->getMessage()); 
    174                     } 
    175                } 
    176                 
    177                if (!$core->error->flag()) { 
    178                     http::redirect($redir); 
    179                } 
     208 
     209     /** 
     210      * Add actions to posts page combo 
     211      *  
     212      * @param  dcCore             $core dcCore instance 
     213      * @param  dcPostsActionsPage $ap   dcPostsActionsPage instance 
     214      */ 
     215     public static function adminPostsActionsPage(dcCore $core, dcPostsActionsPage $ap) 
     216     { 
     217          if (!$core->auth->check('publish,contentadmin', $core->blog->id)) { 
     218 
     219               return null; 
     220          } 
     221 
     222          $ap->addAction( 
     223               array( 
     224                    __('Useless comments') => array( 
     225                         __('Mark as selected') => 'hum_selected' 
     226                    ) 
     227               ), 
     228               array('adminHum', 'callbackPostsAction') 
     229          ); 
     230 
     231          $ap->addAction( 
     232               array( 
     233                    __('Useless comments') => array( 
     234                         __('Mark as unselected') => 'hum_unselected' 
     235                    ) 
     236               ), 
     237               array('adminHum', 'callbackPostsAction') 
     238          ); 
     239     } 
     240 
     241     /** 
     242      * Posts actions callback to add hum actions 
     243      *  
     244      * @param  dcCore             $core dcCore instance 
     245      * @param  dcPostsActionsPage $ap   dcPostsActionsPage instance 
     246      * @param  ArrayObject        $post POST actions 
     247      */ 
     248     public static function callbackPostsAction(dcCore $core, dcPostsActionsPage $ap, ArrayObject $post) 
     249     { 
     250          # No entry 
     251          $ids = $ap->getIDs(); 
     252          if (empty($ids)) { 
     253               throw new Exception(__('No entries selected')); 
     254          } 
     255 
     256          # No action 
     257          if (!in_array($ap->getAction(), array('hum_selected', 'hum_unselected'))) { 
     258 
     259               $ap->redirect(true); 
     260               return null; 
     261          } 
     262 
     263          $rs = $core->blog->getComments(array( 
     264               'sql' => 'AND P.post_id '.$core->con->in($ids), 
     265               'comment_trackback' => 0 
     266          )); 
     267 
     268          if ($rs->isEmpty()) { 
     269               throw new Exception(__('No comments')); 
     270          } 
     271 
     272          $selected = $ap->getAction() == 'hum_selected'; 
     273 
     274          while($rs->fetch()) { 
     275               self::selectComment($core, $rs->comment_id, $selected); 
     276          } 
     277 
     278          dcPage::addSuccessNotice(__('Comments selection changed.')); 
     279          $ap->redirect(true); 
     280     } 
     281 
     282     /** 
     283      * Save comment selection in db 
     284      *  
     285      * @param  dcCore  $core     dcCore instance 
     286      * @param  integer $id       Comment Id 
     287      * @param  boolean $selected Comment selection 
     288      */ 
     289     protected static function selectComment(dcCore $core, $id, $selected) 
     290     { 
     291          try { 
     292               $cur = $core->con->openCursor($core->prefix.'comment'); 
     293               $cur->comment_selected = abs((integer) $selected); 
     294               $core->blog->updComment($co->comment_id, $cur); 
     295          } 
     296          catch (Exception $e) { 
     297               $core->error->add($e->getMessage()); 
    180298          } 
    181299     } 
    182300} 
    183 ?> 
  • plugins/hum/_define.php

    r2611 r3267  
    11<?php 
    22# -- BEGIN LICENSE BLOCK ---------------------------------- 
     3# 
    34# This file is part of hum, a plugin for Dotclear 2. 
    45#  
    5 # Copyright (c) 2009-2010 JC Denis and contributors 
    6 # jcdenis@gdwd.com 
     6# Copyright (c) 2009-2013 Jean-Christian Denis and contributors 
     7# contact@jcdenis.fr http://jcd.lv 
    78#  
    89# Licensed under the GPL version 2.0 license. 
    910# A copy of this license is available in LICENSE file or at 
    1011# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 
     12# 
    1113# -- END LICENSE BLOCK ------------------------------------ 
    1214 
    13 if (!defined('DC_RC_PATH')){return;} 
     15if (!defined('DC_RC_PATH')) { 
     16 
     17     return null; 
     18} 
    1419 
    1520$this->registerModule( 
    16      /* Name */               "Hide useless messages", 
    17      /* Description*/         "Select and highlight interresting comments", 
    18      /* Author */             "JC Denis", 
    19      /* Version */            '0.1', 
    20      /* Permissions */        'contentadmin' 
     21     /* Name */ 
     22     "Hide useless messages", 
     23     /* Description*/ 
     24     "Select and highlight interresting comments", 
     25     /* Author */ 
     26     "Jean-Christian Denis", 
     27     /* Version */ 
     28     '0.2', 
     29     /* Properies */ 
     30     array( 
     31          'permissions' => 'contentadmin', 
     32          'type' => 'plugin', 
     33          'dc_min' => '2.6', 
     34          'support' => 'http://jcd.lv/q=hum', 
     35          'details' => 'http://plugins.dotaddict.org/dc2/details/hum' 
     36     ) 
    2137); 
    22      /* date */          #20100901 
    23 ?> 
  • plugins/hum/_install.php

    r2607 r3267  
    11<?php 
    22# -- BEGIN LICENSE BLOCK ---------------------------------- 
     3# 
    34# This file is part of hum, a plugin for Dotclear 2. 
    45#  
    5 # Copyright (c) 2009-2010 JC Denis and contributors 
    6 # jcdenis@gdwd.com 
     6# Copyright (c) 2009-2013 Jean-Christian Denis and contributors 
     7# contact@jcdenis.fr http://jcd.lv 
    78#  
    89# Licensed under the GPL version 2.0 license. 
    910# A copy of this license is available in LICENSE file or at 
    1011# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 
     12# 
    1113# -- END LICENSE BLOCK ------------------------------------ 
    1214 
    13 if (!defined('DC_CONTEXT_ADMIN')){return;} 
     15if (!defined('DC_CONTEXT_ADMIN')) { 
    1416 
    15 # Get new version 
    16 $new_version = $core->plugins->moduleInfo('hum','version'); 
    17 $old_version = $core->getVersion('hum'); 
     17     return null; 
     18} 
    1819 
    19 # Compare versions 
    20 if (version_compare($old_version,$new_version,'>=')) {return;} 
     20$dc_min = '2.6'; 
     21$mod_id = 'hum'; 
    2122 
    2223# Install or update 
    2324try { 
    24      if (version_compare(DC_VERSION,'2.2-alpha','<')) { 
    25           throw new Exception('Plugin called hum requires Dotclear 2.2 or higher.'); 
     25     # Check module version 
     26     if (version_compare( 
     27          $core->getVersion($mod_id), 
     28          $core->plugins->moduleInfo($mod_id, 'version'), 
     29          '>=' 
     30     )) { 
     31 
     32          return null; 
    2633     } 
    27       
    28      # Table 
    29      $t = new dbStruct($core->con,$core->prefix); 
    30      $t->comment->comment_selected('smallint',0,false,0);    
    31      $ti = new dbStruct($core->con,$core->prefix); 
     34 
     35     # Check Dotclear version 
     36     if (!method_exists('dcUtils', 'versionsCompare')  
     37      || dcUtils::versionsCompare(DC_VERSION, $dc_min, '<', false)) { 
     38          throw new Exception(sprintf( 
     39               '%s requires Dotclear %s', $mod_id, $dc_min 
     40          )); 
     41     } 
     42 
     43     # Edit comment table structure 
     44     $t = new dbStruct($core->con, $core->prefix); 
     45     $t->comment->comment_selected('smallint', 0, false, 0);      
     46     $ti = new dbStruct($core->con, $core->prefix); 
    3247     $changes = $ti->synchronize($t); 
    33       
     48 
    3449     $css_extra = "#comments dt a.read-it { font-size: 0.8em; padding: 5px; font-style: italic; } "; 
    35       
    36      # Settings 
    37      $core->blog->settings->addNamespace('hum'); 
    38      $s = $core->blog->settings->hum; 
    39      $s->put('active',false,'boolean','Enabled hum plugin',false,true); 
    40      $s->put('comment_selected',false,'boolean','Select new comment by default',false,true); 
    41      $s->put('jquery_hide',true,'boolean','Hide comments with jQuery fonction',false,true); 
    42      $s->put('title_tag','dt','string','HTML tag of comment title block',false,true); 
    43      $s->put('content_tag','dd','string','HTML tag of comment content block',false,true); 
    44      $s->put('css_extra',$css_extra,'string','Additionnal style sheet',false,true); 
    45       
    46      # Version 
    47      $core->setVersion('hum',$new_version); 
    48       
     50 
     51     # Set module settings 
     52     $core->blog->settings->addNamespace($mod_id); 
     53     $s = $core->blog->settings->{$mod_id}; 
     54     $s->put('active', false, 'boolean', 'Enabled hum plugin', false, true); 
     55     $s->put('comment_selected', false, 'boolean', 'Select new comment by default', false, true); 
     56     $s->put('jquery_hide', true, 'boolean', 'Hide comments with jQuery fonction', false, true); 
     57     $s->put('title_tag', 'dt', 'string', 'HTML tag of comment title block', false, true); 
     58     $s->put('content_tag', 'dd', 'string', 'HTML tag of comment content block', false, true); 
     59     $s->put('css_extra', $css_extra, 'string', 'Additionnal style sheet', false, true); 
     60 
     61     # Set module version 
     62     $core->setVersion( 
     63          $mod_id, 
     64          $core->plugins->moduleInfo($mod_id, 'version') 
     65     ); 
     66 
    4967     return true; 
    5068} 
    5169catch (Exception $e) { 
    5270     $core->error->add($e->getMessage()); 
     71 
    5372     return false; 
    5473} 
    55 ?> 
  • plugins/hum/_public.php

    r2607 r3267  
    11<?php 
    22# -- BEGIN LICENSE BLOCK ---------------------------------- 
     3# 
    34# This file is part of hum, a plugin for Dotclear 2. 
    45#  
    5 # Copyright (c) 2009-2010 JC Denis and contributors 
    6 # jcdenis@gdwd.com 
     6# Copyright (c) 2009-2013 Jean-Christian Denis and contributors 
     7# contact@jcdenis.fr http://jcd.lv 
    78#  
    89# Licensed under the GPL version 2.0 license. 
    910# A copy of this license is available in LICENSE file or at 
    1011# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 
     12# 
    1113# -- END LICENSE BLOCK ------------------------------------ 
    1214 
    13 if (!defined('DC_RC_PATH')){return;} 
     15if (!defined('DC_RC_PATH')) { 
     16 
     17     return null; 
     18} 
    1419 
    1520$core->blog->settings->addNamespace('hum'); 
    1621 
    1722if ($core->blog->settings->hum->active) { 
    18      # Default value of new comments 
    19      $core->addBehavior('coreBeforeCommentCreate',array('publicHum','coreBeforeCommentCreate')); 
    20      # CSS and JS 
    21      $core->addBehavior('publicHeadContent',array('publicHum','publicHeadContent')); 
    22      # Add comment_selected field to Comments tag 
    23      $core->addBehavior('templateBeforeBlock',array('publicHum','templateBeforeBlock')); 
    24      # Tags 
    25      $core->tpl->addBlock('CommentSelectedIf',array('tplHum','CommentSelectedIf')); 
    26      $core->tpl->addValue('CommentIfSelected',array('tplHum','CommentIfSelected')); 
    27      $core->tpl->addValue('CommentIfNotSelected',array('tplHum','CommentIfNotSelected')); 
    28 } 
    29  
    30 class tplHum 
    31 { 
    32      public function CommentSelectedIf($attr,$content) 
    33      { 
    34           $if = array(); 
    35            
    36           if (isset($attr['is_selected'])) { 
    37                $sign = (boolean) $attr['is_selected'] ? '' : '!'; 
    38                $if[] = $sign.'$_ctx->comments->comment_selected'; 
    39           } 
    40            
    41           if (!empty($if)) { 
    42                return '<?php if('.implode(' && ',$if).') : ?>'.$content.'<?php endif; ?>'; 
    43           } else { 
    44                return $content; 
    45           } 
    46      } 
    47       
    48      public function CommentIfSelected($attr) 
    49      { 
    50           $ret = isset($attr['return']) ? $attr['return'] : 'selected'; 
    51           $ret = html::escapeHTML($ret); 
    52            
    53           return 
    54           '<?php if ($_ctx->comments->comment_selected) { '. 
    55           "echo '".addslashes($ret)."'; } ?>"; 
    56      } 
    57       
    58      public function CommentIfNotSelected($attr) 
    59      { 
    60           $ret = isset($attr['return']) ? $attr['return'] : 'unselected'; 
    61           $ret = html::escapeHTML($ret); 
    62            
    63           return 
    64           '<?php if (!$_ctx->comments->comment_selected) { '. 
    65           "echo '".addslashes($ret)."'; } ?>"; 
    66      } 
    67 } 
    68  
     23 
     24     $core->addBehavior( 
     25          'coreBeforeCommentCreate', 
     26          array('publicHum', 'coreBeforeCommentCreate') 
     27     ); 
     28     $core->addBehavior( 
     29          'publicHeadContent', 
     30          array('publicHum', 'publicHeadContent') 
     31     ); 
     32     $core->addBehavior( 
     33          'templateBeforeBlock', 
     34          array('publicHum', 'templateBeforeBlock') 
     35     ); 
     36 
     37     $core->tpl->addBlock( 
     38          'CommentSelectedIf', 
     39          array('tplHum', 'CommentSelectedIf') 
     40     ); 
     41     $core->tpl->addValue( 
     42          'CommentIfSelected', 
     43          array('tplHum', 'CommentIfSelected') 
     44     ); 
     45     $core->tpl->addValue( 
     46          'CommentIfNotSelected', 
     47          array('tplHum', 'CommentIfNotSelected') 
     48     ); 
     49} 
     50else { 
     51     $core->tpl->addBlock( 
     52          'CommentSelectedIf', 
     53          array('tplHum', 'disabled') 
     54     ); 
     55     $core->tpl->addValue( 
     56          'CommentIfSelected', 
     57          array('tplHum', 'disabled') 
     58     ); 
     59     $core->tpl->addValue( 
     60          'CommentIfNotSelected', 
     61          array('tplHum', 'disabled') 
     62     ); 
     63} 
     64 
     65/** 
     66 * @ingroup DC_PLUGIN_HUM 
     67 * @brief Plublic methods for JS, CSS and sql queries. 
     68 * @since 2.6 
     69 */ 
    6970class publicHum 
    7071{ 
    71      public static function publicHeadContent($core) 
     72     /** 
     73      * Add hum JS and CSS to theme header 
     74      *  
     75      * @param  dcCore $core dcCore instance 
     76      */ 
     77     public static function publicHeadContent(dcCore $core) 
    7278     {          
    7379          $css_extra = $core->blog->settings->hum->css_extra; 
     
    7985               "</style>\n"; 
    8086          } 
    81            
     87 
    8288          if ($core->blog->settings->hum->jquery_hide){ 
    8389                
    8490               $title_tag = $core->blog->settings->hum->title_tag; 
    85                if (!preg_match('#^[a-zA-Z0-9]{2,}$#',$title_tag)) $title_tag = 'dt'; 
     91               if (!preg_match('#^[a-zA-Z0-9]{2,}$#', $title_tag)) { 
     92                    $title_tag = 'dt'; 
     93               } 
     94 
    8695               $content_tag = $core->blog->settings->hum->content_tag; 
    87                if (!preg_match('#^[a-zA-Z0-9]{2,}$#',$content_tag)) $content_tag = 'dd'; 
    88                 
     96               if (!preg_match('#^[a-zA-Z0-9]{2,}$#', $content_tag)) { 
     97                    $content_tag = 'dd'; 
     98               } 
     99 
    89100               echo  
    90101               "\n<!-- JS for plugin hum --> \n". 
     
    95106               "  var title=$(this); \n". 
    96107               "  \$(this).next('".$content_tag."').hide(); \n". 
    97                "  \$(this).append(". 
    98                  
    99                 "\$('<a href=\"#\" title=\"".html::escapeJS(__('Click to show this commnet')). 
    100                 "\" class=\"read-it\">".html::escapeJS(__('Read this comment'))."</a>'". 
    101                 ").click(function(){\$(title).next('".$content_tag."').toggle();\$(this).parent().children('.read-it').remove();return false;})". 
    102                 ").append(". 
    103                  
    104                 "$('<a href=\"#\" title=\"".html::escapeJS(__('Show all comments')). 
    105                 "\" class=\"read-it\">".html::escapeJS(__('All'))."</a>'". 
    106                 ").click(function(){\$('#comments ".$content_tag."').show();\$('#comments ".$title_tag.".unselected .read-it').remove();return false;})". 
    107                  
    108                 "); \n". 
     108               "  \$(this).append(".  
     109                    "\$('<a>').attr('href','#').attr('title','".html::escapeJS(__('Click to show this commnet'))."').attr('class','read-it').text('".html::escapeJS(__('Read this comment'))."').click(function(){\$(title).next('".$content_tag."').toggle();\$(this).parent().children('.read-it').remove();return false;})". 
     110                 ").append(". 
     111                    "$('<a>').attr('href','#').attr('title','".html::escapeJS(__('Show all comments'))."').attr('class','read-it').text('".html::escapeJS(__('All'))."').click(function(){\$('#comments ".$content_tag."').show();\$('#comments ".$title_tag.".unselected .read-it').remove();return false;})". 
     112                 "); \n". 
    109113               " }); \n". 
    110114               "}); \n". 
     
    113117          } 
    114118     } 
    115       
    116      public static function templateBeforeBlock($core,$tag,$attr) 
    117      { 
    118           if ($tag != 'Comments') {return;} 
    119            
     119 
     120     /** 
     121      * Add column to sql queries 
     122      *  
     123      * @param  dcCore $core dcCore instance 
     124      * @param  string $tag  Template block name 
     125      * @param  array  $attr Tempalte block attributes 
     126      * @return string       HTML PHP part to add query params 
     127      */ 
     128     public static function templateBeforeBlock(dcCore $core, $tag, $attr) 
     129     { 
     130          if ($tag != 'Comments') { 
     131 
     132               return null; 
     133          } 
     134 
    120135          $res = "\$params['columns'][] = 'comment_selected'; "; 
    121            
     136 
    122137          if (isset($attr['selected'])) { 
    123138               $selected = (boolean) $attr['selected'] ? '0' : '1'; 
    124139               $res .= "@\$params['sql'] .= 'AND comment_selected = ".((integer) $selected)."'; "; 
    125140          } 
     141 
    126142          return '<?php '.$res.' ?>'; 
    127143     } 
    128       
    129      public static function coreBeforeCommentCreate($blog,$cur) 
     144 
     145     /** 
     146      * Add default value to cursor 
     147      *  
     148      * @param  dcBlog $blog dcCore instance 
     149      * @param  cursor $cur  cursor 
     150      */ 
     151     public static function coreBeforeCommentCreate(dcBlog $blog, cursor $cur) 
    130152     { 
    131153          if (null === $cur->comment_selected) { 
     
    134156     } 
    135157} 
    136 ?> 
     158 
     159/** 
     160 * @ingroup DC_PLUGIN_HUM 
     161 * @brief Public methods for tempate tag and block. 
     162 * @since 2.6 
     163 */ 
     164class tplHum 
     165{ 
     166     /** 
     167      * Template block to add comment selection condition 
     168      *  
     169      * @param array  $attr    Template block attributes 
     170      * @param string $content Tempalde block content 
     171      */ 
     172     public static function CommentSelectedIf($attr, $content) 
     173     { 
     174          $if = array(); 
     175           
     176          if (isset($attr['is_selected'])) { 
     177               $sign = (boolean) $attr['is_selected'] ? '' : '!'; 
     178               $if[] = $sign.'$_ctx->comments->comment_selected'; 
     179          } 
     180 
     181          return empty($if) ? 
     182               $content : 
     183               '<?php if('.implode(' && ',$if).') : ?>'.$content.'<?php endif; ?>'; 
     184     } 
     185 
     186     /** 
     187      * Template value to add something if comment is selected 
     188      *  
     189      * @param  array $attr Template value attributes 
     190      * @return string      Something 
     191      */ 
     192     public static function CommentIfSelected($attr) 
     193     { 
     194          $ret = isset($attr['return']) ? $attr['return'] : 'selected'; 
     195          $ret = html::escapeHTML($ret); 
     196 
     197          return 
     198          '<?php if ($_ctx->comments->comment_selected) { '. 
     199          "echo '".addslashes($ret)."'; } ?>"; 
     200     } 
     201 
     202     /** 
     203      * Template value to add something if comment is not selected 
     204      *  
     205      * @param  array $attr Template value attributes 
     206      * @return string      Something 
     207      */ 
     208     public static function CommentIfNotSelected($attr) 
     209     { 
     210          $ret = isset($attr['return']) ? $attr['return'] : 'unselected'; 
     211          $ret = html::escapeHTML($ret); 
     212 
     213          return 
     214          '<?php if (!$_ctx->comments->comment_selected) { '. 
     215          "echo '".addslashes($ret)."'; } ?>"; 
     216     } 
     217 
     218     /** 
     219      * Disable hum template blck and value 
     220      *  
     221      * @param  array  $attr Template value attributes 
     222      * @return string       Nothing 
     223      */ 
     224     public static function disabled($attr, $content='') 
     225     { 
     226          return ''; 
     227     } 
     228} 
  • plugins/hum/locales/en/resources.php

    r2607 r3267  
    11<?php 
    22# -- BEGIN LICENSE BLOCK ---------------------------------- 
     3# 
    34# This file is part of hum, a plugin for Dotclear 2. 
    45#  
    5 # Copyright (c) 2009-2010 JC Denis and contributors 
    6 # jcdenis@gdwd.com 
     6# Copyright (c) 2009-2013 Jean-Christian Denis and contributors 
     7# contact@jcdenis.fr http://jcd.lv 
    78#  
    89# Licensed under the GPL version 2.0 license. 
    910# A copy of this license is available in LICENSE file or at 
    1011# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 
     12# 
    1113# -- END LICENSE BLOCK ------------------------------------ 
    1214 
  • plugins/hum/locales/fr/main.lang.php

    r2611 r3267  
    11<?php 
    22// Language: Français  
    3 // Module: hum - 0.1 
    4 // Date: 2010-08-31 22:17:23  
    5 // Translated with dcTranslater - 1.4.1  
     3// Module: hum - 0.2 
     4// Date: 2013-11-16 13:27:15  
     5// Translated with dcTranslater - 2013.05.11  
    66 
    7 #_admin.php:19 
     7#_admin.php:127 
     8#_admin.php:136 
     9#_admin.php:222 
     10#_admin.php:231 
    811$GLOBALS['__l10n']['Useless comments'] = 'Commentaires inutiles'; 
    912 
    10 #_admin.php:139 
     13#_admin.php:172 
     14#_admin.php:276 
     15$GLOBALS['__l10n']['Comments selection changed.'] = 'Selection de commentaires changée.'; 
     16 
     17#_admin.php:203 
    1118$GLOBALS['__l10n']['Selected comment'] = 'Commentaire sélectionné'; 
    1219 
    13 #_public.php:99 
     20#_admin.php:251 
     21$GLOBALS['__l10n']['No entries selected'] = 'Pas de billets selectionné'; 
     22 
     23#_admin.php:267 
     24$GLOBALS['__l10n']['No comments'] = 'Aucun commantaire'; 
     25 
     26#_config.php:87 
     27$GLOBALS['__l10n']['By default, mark new comments as selected'] = 'Par défaut, marquer les nouveaux commentaires comme selectionnés'; 
     28 
     29#_config.php:93 
     30$GLOBALS['__l10n']['Public'] = 'Publique'; 
     31 
     32#_config.php:101 
     33$GLOBALS['__l10n']['Use jQuery to hide unselected comments'] = 'Utiliser jQuery pour cacher les commentaires non sélectionnés'; 
     34 
     35#_config.php:105 
     36$GLOBALS['__l10n']['HTML tag of comment title block:'] = 'Balise HTML du titre d\'un commentaire :'; 
     37 
     38#_config.php:116 
     39$GLOBALS['__l10n']['HTML tag of comment content block:'] = 'Balise HTML du contenu d\'un commentaire :'; 
     40 
     41#_config.php:127 
     42$GLOBALS['__l10n']['Additionnal style sheet:'] = 'Feuille de style additionnelle'; 
     43 
     44#_public.php:107 
    1445$GLOBALS['__l10n']['Click to show this commnet'] = 'Cliquer pour voir ce commentaire'; 
    1546 
    16 #_public.php:100 
     47#_public.php:107 
    1748$GLOBALS['__l10n']['Read this comment'] = 'Lire ce commentaire'; 
    1849 
    19 #_public.php:104 
     50#_public.php:109 
    2051$GLOBALS['__l10n']['Show all comments'] = 'Afficher tous les commentaires'; 
    2152 
    22 #_public.php:105 
     53#_public.php:109 
    2354$GLOBALS['__l10n']['All'] = 'Tous'; 
    2455 
    25 #index.php:59 
    26 $GLOBALS['__l10n']['Settings'] = 'Paramètres'; 
     56$GLOBALS['__l10n']['Select and highlight interresting comments'] = 'Selection et mise en avant des commentaires interressants'; 
    2757 
    28 #index.php:62 
    29 $GLOBALS['__l10n']['Administration'] = 'Administration'; 
    30  
    31 #index.php:65 
    32 $GLOBALS['__l10n']['Enable extension'] = 'Activer l\'extension'; 
    33  
    34 #index.php:68 
    35 $GLOBALS['__l10n']['By default, mark new comments as selected'] = 'Par défaut, marquer les nouveaux commentaires comme selectionnés'; 
    36  
    37 #index.php:70 
    38 $GLOBALS['__l10n']['Public'] = 'Publique'; 
    39  
    40 #index.php:73 
    41 $GLOBALS['__l10n']['Use jQuery to hide unselected comments'] = 'Utiliser jQuery pour cacher les commentaires non sélectionnés'; 
    42  
    43 #index.php:75 
    44 $GLOBALS['__l10n']['HTML tag of comment title block:'] = 'Balise HTML du titre d\'un commentaire :'; 
    45  
    46 #index.php:78 
    47 $GLOBALS['__l10n']['HTML tag of comment content block:'] = 'Balise HTML du contenu d\'un commentaire :'; 
    48  
    49 #index.php:81 
    50 $GLOBALS['__l10n']['Additionnal style sheet:'] = 'Feuille de style additionnelle'; 
     58$GLOBALS['__l10n']['Hide useless messages'] = 'Cacher les messages inutiles'; 
    5159 
    5260?> 
  • plugins/hum/locales/fr/main.po

    r2611 r3267  
    11# Language: Français 
    2 # Module: hum - 0.1 
    3 # Date: 2010-08-31 22:17:23 
    4 # Translated with translater 1.4.1 
     2# Module: hum - 0.2 
     3# Date: 2013-11-16 13:27:15 
     4# Translated with translater 2013.05.11 
    55 
    66msgid "" 
    77msgstr "" 
    88"Content-Type: text/plain; charset=UTF-8\n" 
    9 "Project-Id-Version: hum 0.1\n" 
     9"Project-Id-Version: hum 0.2\n" 
    1010"POT-Creation-Date: \n" 
    11 "PO-Revision-Date: 2010-08-31T22:17:23+00:00\n" 
    12 "Last-Translator: JC Denis\n" 
     11"PO-Revision-Date: 2013-11-16T13:27:15+00:00\n" 
     12"Last-Translator: Jean-Christian Denis\n" 
    1313"Language-Team: \n" 
    1414"MIME-Version: 1.0\n" 
    1515"Content-Transfer-Encoding: 8bit\n" 
    1616 
    17 #: _admin.php:19 
     17#: _admin.php:127 
     18#: _admin.php:136 
     19#: _admin.php:222 
     20#: _admin.php:231 
    1821msgid "Useless comments" 
    1922msgstr "Commentaires inutiles" 
    2023 
    21 #: _admin.php:139 
     24#: _admin.php:172 
     25#: _admin.php:276 
     26msgid "Comments selection changed." 
     27msgstr "Selection de commentaires changée." 
     28 
     29#: _admin.php:203 
    2230msgid "Selected comment" 
    2331msgstr "Commentaire sélectionné" 
    2432 
    25 #: _public.php:99 
     33#: _admin.php:251 
     34msgid "No entries selected" 
     35msgstr "Pas de billets selectionné" 
     36 
     37#: _admin.php:267 
     38msgid "No comments" 
     39msgstr "Aucun commantaire" 
     40 
     41#: _config.php:87 
     42msgid "By default, mark new comments as selected" 
     43msgstr "Par défaut, marquer les nouveaux commentaires comme selectionnés" 
     44 
     45#: _config.php:93 
     46msgid "Public" 
     47msgstr "Publique" 
     48 
     49#: _config.php:101 
     50msgid "Use jQuery to hide unselected comments" 
     51msgstr "Utiliser jQuery pour cacher les commentaires non sélectionnés" 
     52 
     53#: _config.php:105 
     54msgid "HTML tag of comment title block:" 
     55msgstr "Balise HTML du titre d'un commentaire :" 
     56 
     57#: _config.php:116 
     58msgid "HTML tag of comment content block:" 
     59msgstr "Balise HTML du contenu d'un commentaire :" 
     60 
     61#: _config.php:127 
     62msgid "Additionnal style sheet:" 
     63msgstr "Feuille de style additionnelle" 
     64 
     65#: _public.php:107 
    2666msgid "Click to show this commnet" 
    2767msgstr "Cliquer pour voir ce commentaire" 
    2868 
    29 #: _public.php:100 
     69#: _public.php:107 
    3070msgid "Read this comment" 
    3171msgstr "Lire ce commentaire" 
    3272 
    33 #: _public.php:104 
     73#: _public.php:109 
    3474msgid "Show all comments" 
    3575msgstr "Afficher tous les commentaires" 
    3676 
    37 #: _public.php:105 
     77#: _public.php:109 
    3878msgid "All" 
    3979msgstr "Tous" 
    4080 
    41 #: index.php:59 
    42 msgid "Settings" 
    43 msgstr "Paramètres" 
     81msgid "Select and highlight interresting comments" 
     82msgstr "Selection et mise en avant des commentaires interressants" 
    4483 
    45 #: index.php:62 
    46 msgid "Administration" 
    47 msgstr "Administration" 
     84msgid "Hide useless messages" 
     85msgstr "Cacher les messages inutiles" 
    4886 
    49 #: index.php:65 
    50 msgid "Enable extension" 
    51 msgstr "Activer l'extension" 
    52  
    53 #: index.php:68 
    54 msgid "By default, mark new comments as selected" 
    55 msgstr "Par défaut, marquer les nouveaux commentaires comme selectionnés" 
    56  
    57 #: index.php:70 
    58 msgid "Public" 
    59 msgstr "Publique" 
    60  
    61 #: index.php:73 
    62 msgid "Use jQuery to hide unselected comments" 
    63 msgstr "Utiliser jQuery pour cacher les commentaires non sélectionnés" 
    64  
    65 #: index.php:75 
    66 msgid "HTML tag of comment title block:" 
    67 msgstr "Balise HTML du titre d'un commentaire :" 
    68  
    69 #: index.php:78 
    70 msgid "HTML tag of comment content block:" 
    71 msgstr "Balise HTML du contenu d'un commentaire :" 
    72  
    73 #: index.php:81 
    74 msgid "Additionnal style sheet:" 
    75 msgstr "Feuille de style additionnelle" 
    76  
  • plugins/hum/locales/fr/resources.php

    r2607 r3267  
    11<?php 
    22# -- BEGIN LICENSE BLOCK ---------------------------------- 
     3# 
    34# This file is part of hum, a plugin for Dotclear 2. 
    45#  
    5 # Copyright (c) 2009-2010 JC Denis and contributors 
    6 # jcdenis@gdwd.com 
     6# Copyright (c) 2009-2013 Jean-Christian Denis and contributors 
     7# contact@jcdenis.fr http://jcd.lv 
    78#  
    89# Licensed under the GPL version 2.0 license. 
    910# A copy of this license is available in LICENSE file or at 
    1011# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 
     12# 
    1113# -- END LICENSE BLOCK ------------------------------------ 
    1214 
Note: See TracChangeset for help on using the changeset viewer.

Sites map