Dotclear

Changeset 2039:783f5dbdf165


Ignore:
Timestamp:
09/23/13 15:06:50 (11 years ago)
Author:
Dsls
Branch:
default
Message:

tags plugin now uses new pages actions form.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inc/admin/actions/class.dcaction.php

    r2015 r2039  
    213213          return $this->uri.'?'.http_build_query($redir_args); 
    214214     } 
    215  
     215      
    216216     /** 
    217217     * redirect - redirects to redirection page 
     
    226226      
    227227     /** 
     228     * getURI - returns current form URI, if any 
     229     * 
     230     * @access public 
     231      * 
     232     * @return string the form URI 
     233     */ 
     234     public function getURI() { 
     235          return $this->uri; 
     236     } 
     237 
     238     /** 
    228239     * getAction - returns current action, if any 
    229240     * 
    230       * @see getRedirection for arguments details 
    231       * 
    232241     * @access public 
    233242      * 
  • plugins/tags/_admin.php

    r1874 r2039  
    2424 
    2525$core->addBehavior('adminPostHeaders',array('tagsBehaviors','postHeaders')); 
    26 $core->addBehavior('adminPostsActionsHeaders',array('tagsBehaviors','postsActionsHeaders')); 
    27  
    28 $core->addBehavior('adminPostsActionsCombo',array('tagsBehaviors','adminPostsActionsCombo')); 
    29 $core->addBehavior('adminPostsActions',array('tagsBehaviors','adminPostsActions')); 
    30 $core->addBehavior('adminPostsActionsContent',array('tagsBehaviors','adminPostsActionsContent')); 
     26 
     27$core->addBehavior('adminPostsActionsPage',array('tagsBehaviors','adminPostsActionsPage')); 
    3128 
    3229$core->addBehavior('adminPreferencesForm',array('tagsBehaviors','adminUserForm')); 
     
    9895               } 
    9996          } 
     97     } 
     98      
     99      
     100     public static function adminPostsActionsPage($core,$ap) 
     101     { 
     102          $ap->addAction( 
     103               array(__('Tags') => array(__('Add tags') => 'tags')), 
     104               array('tagsBehaviors','adminAddTags') 
     105          ); 
     106           
     107          if ($core->auth->check('delete,contentadmin',$core->blog->id)) { 
     108               $ap->addAction( 
     109                    array(__('Tags') => array(__('Remove tags') => 'tags_remove')), 
     110                    array('tagsBehaviors','adminRemoveTags') 
     111               ); 
     112          } 
     113     } 
     114      
     115     public static function adminAddTags($core, dcPostsActionsPage $ap, $post) 
     116     { 
     117          if (!empty($post['new_tags'])) 
     118          { 
     119               $meta =& $core->meta; 
     120               $tags = $meta->splitMetaValues($post['new_tags']); 
     121               $posts = $ap->getRS(); 
     122               while ($posts->fetch()) 
     123               { 
     124                    echo "post_id".$posts->post_id; 
     125                    # Get tags for post 
     126                    $post_meta = $meta->getMetadata(array( 
     127                         'meta_type' => 'tag', 
     128                         'post_id' => $posts->post_id)); 
     129                    $pm = array(); 
     130                    while ($post_meta->fetch()) { 
     131                         $pm[] = $post_meta->meta_id; 
     132                    } 
     133                    foreach ($tags as $t) { 
     134                         if (!in_array($t,$pm)) { 
     135                              $meta->setPostMeta($posts->post_id,'tag',$t); 
     136                         } 
     137                    } 
     138               } 
     139               $ap->redirect(array('upd' => 1),true); 
     140          }  
     141          else  
     142          { 
     143               $tag_url = $core->blog->url.$core->url->getURLFor('tag'); 
     144 
     145               $opts = $core->auth->getOptions(); 
     146               $type = isset($opts['tag_list_format']) ? $opts['tag_list_format'] : 'more'; 
     147 
     148                
     149               $ap->beginPage( 
     150                    dcPage::breadcrumb( 
     151                         array( 
     152                              html::escapeHTML($core->blog->name) => '', 
     153                              __('Entries') => 'posts.php', 
     154                              '<span class="page-title">'.__('Add tags to entries').'</span>' => '' 
     155                    )), 
     156                    dcPage::jsLoad('js/jquery/jquery.autocomplete.js'). 
     157                    dcPage::jsMetaEditor(). 
     158                    '<script type="text/javascript" src="index.php?pf=tags/js/jquery.autocomplete.js"></script>'. 
     159                    '<script type="text/javascript" src="index.php?pf=tags/js/posts_actions.js"></script>'. 
     160                    '<script type="text/javascript">'."\n". 
     161                    "//<![CDATA[\n". 
     162                    "metaEditor.prototype.meta_url = 'plugin.php?p=tags&m=tag_posts&amp;tag=';\n". 
     163                    "metaEditor.prototype.meta_type = '".html::escapeJS($type)."';\n". 
     164                    "metaEditor.prototype.text_confirm_remove = '".html::escapeJS(__('Are you sure you want to remove this %s?'))."';\n". 
     165                    "metaEditor.prototype.text_add_meta = '".html::escapeJS(__('Add a %s to this entry'))."';\n". 
     166                    "metaEditor.prototype.text_choose = '".html::escapeJS(__('Choose from list'))."';\n". 
     167                    "metaEditor.prototype.text_all = '".html::escapeJS(__('all'))."';\n". 
     168                    "metaEditor.prototype.text_separation = '".html::escapeJS(__('Enter tags separated by coma'))."';\n". 
     169                    "dotclear.msg.tags_autocomplete = '".html::escapeJS(__('used in %e - frequency %p%'))."';\n". 
     170                    "dotclear.msg.entry = '".html::escapeJS(__('entry'))."';\n". 
     171                    "dotclear.msg.entries = '".html::escapeJS(__('entries'))."';\n". 
     172                    "\n//]]>\n". 
     173                    "</script>\n". 
     174                    '<link rel="stylesheet" type="text/css" href="index.php?pf=tags/style.css" />' 
     175               ); 
     176               echo 
     177                    '<form action="'.$ap->getURI().'" method="post">'. 
     178                    $ap->getCheckboxes(). 
     179                    '<div><label for="new_tags" class="area">'.__('Tags to add:').'</label> '. 
     180                    form::textarea('new_tags',60,3). 
     181                    '</div>'. 
     182                    $core->formNonce(). 
     183                    form::hidden(array('action'),'tags'). 
     184                    '<p><input type="submit" value="'.__('Save').'" '. 
     185                    'name="save_tags" /></p>'. 
     186                    '</form>'; 
     187               $ap->endPage(); 
     188          } 
     189     } 
     190     public static function adminRemoveTags($core, dcPostsActionsPage $ap, $post) 
     191     { 
     192          if (!empty($post['meta_id']) &&  
     193               $core->auth->check('delete,contentadmin',$core->blog->id)) 
     194          { 
     195               $meta =& $core->meta; 
     196               $posts = $ap->getRS(); 
     197               while ($posts->fetch()) 
     198               { 
     199                    foreach ($_POST['meta_id'] as $v) 
     200                    { 
     201                         $meta->delPostMeta($posts->post_id,'tag',$v); 
     202                    } 
     203               } 
     204               $ap->redirect(array('upd' => 1),true); 
     205          } 
     206          else 
     207          { 
     208               $meta =& $core->meta; 
     209               $tags = array(); 
     210                
     211               foreach ($ap->getIDS() as $id) { 
     212                    $post_tags = $meta->getMetadata(array( 
     213                         'meta_type' => 'tag', 
     214                         'post_id' => (integer) $id))->toStatic()->rows(); 
     215                    foreach ($post_tags as $v) { 
     216                         if (isset($tags[$v['meta_id']])) { 
     217                              $tags[$v['meta_id']]++; 
     218                         } else { 
     219                              $tags[$v['meta_id']] = 1; 
     220                         } 
     221                    } 
     222               } 
     223               $ap->beginPage( 
     224                    dcPage::breadcrumb( 
     225                         array( 
     226                              html::escapeHTML($core->blog->name) => '', 
     227                              __('Entries') => 'posts.php', 
     228                              '<span class="page-title">'.__('Remove selected tags from entries').'</span>' => '' 
     229               ))); 
     230                
     231               if (empty($tags)) { 
     232                    echo '<p>'.__('No tags for selected entries').'</p>'; 
     233                    return; 
     234               } 
     235                
     236               $posts_count = count($_POST['entries']); 
     237                
     238               echo 
     239               '<form action="'.$ap->getURI().'" method="post">'. 
     240               $ap->getCheckboxes(). 
     241               '<div><p>'.__('Following tags have been found in selected entries:').'</p>'; 
     242                
     243               foreach ($tags as $k => $n) { 
     244                    $label = '<label class="classic">%s %s</label>'; 
     245                    if ($posts_count == $n) { 
     246                         $label = sprintf($label,'%s','<strong>%s</strong>'); 
     247                    } 
     248                    echo '<p>'.sprintf($label, 
     249                              form::checkbox(array('meta_id[]'),html::escapeHTML($k)), 
     250                              html::escapeHTML($k)). 
     251                         '</p>'; 
     252               } 
     253                
     254               echo 
     255               '<p><input type="submit" value="'.__('ok').'" />'. 
     256                
     257               $core->formNonce(). 
     258               form::hidden(array('action'),'tags_remove'). 
     259               '</p></div></form>'; 
     260               $ap->endPage(); 
     261          } 
     262           
    100263     } 
    101264      
     
    129292     } 
    130293      
    131      public static function postsActionsHeaders() 
    132      { 
    133           if (($_POST['action'] == 'tags') || ($_POST['action'] == 'tags_remove')) { 
    134                $tag_url = $GLOBALS['core']->blog->url.$GLOBALS['core']->url->getURLFor('tag'); 
    135  
    136                $opts = $GLOBALS['core']->auth->getOptions(); 
    137                $type = isset($opts['tag_list_format']) ? $opts['tag_list_format'] : 'more'; 
    138  
    139                return  
    140                '<script type="text/javascript" src="index.php?pf=tags/js/jquery.autocomplete.js"></script>'. 
    141                '<script type="text/javascript" src="index.php?pf=tags/js/posts_actions.js"></script>'. 
    142                '<script type="text/javascript">'."\n". 
    143                "//<![CDATA[\n". 
    144                "metaEditor.prototype.meta_url = 'plugin.php?p=tags&m=tag_posts&amp;tag=';\n". 
    145                "metaEditor.prototype.meta_type = '".html::escapeJS($type)."';\n". 
    146                "metaEditor.prototype.text_confirm_remove = '".html::escapeJS(__('Are you sure you want to remove this %s?'))."';\n". 
    147                "metaEditor.prototype.text_add_meta = '".html::escapeJS(__('Add a %s to this entry'))."';\n". 
    148                "metaEditor.prototype.text_choose = '".html::escapeJS(__('Choose from list'))."';\n". 
    149                "metaEditor.prototype.text_all = '".html::escapeJS(__('all'))."';\n". 
    150                "metaEditor.prototype.text_separation = '".html::escapeJS(__('Enter tags separated by coma'))."';\n". 
    151                "dotclear.msg.tags_autocomplete = '".html::escapeJS(__('used in %e - frequency %p%'))."';\n". 
    152                "dotclear.msg.entry = '".html::escapeJS(__('entry'))."';\n". 
    153                "dotclear.msg.entries = '".html::escapeJS(__('entries'))."';\n". 
    154                "\n//]]>\n". 
    155                "</script>\n". 
    156                '<link rel="stylesheet" type="text/css" href="index.php?pf=tags/style.css" />'; 
    157           } 
    158      } 
    159       
    160      public static function adminPostsActionsCombo($args) 
    161      { 
    162           $args[0][__('Tags')] = array(__('Add tags') => 'tags'); 
    163            
    164           if ($GLOBALS['core']->auth->check('delete,contentadmin',$GLOBALS['core']->blog->id)) { 
    165                $args[0][__('Tags')] = array_merge($args[0][__('Tags')], 
    166                     array(__('Remove tags') => 'tags_remove')); 
    167           } 
    168      } 
    169       
    170      public static function adminPostsActions($core,$posts,$action,$redir) 
    171      { 
    172           if ($action == 'tags' && !empty($_POST['new_tags'])) 
    173           { 
    174                try 
    175                { 
    176  
    177                     $meta =& $GLOBALS['core']->meta; 
    178                     $tags = $meta->splitMetaValues($_POST['new_tags']); 
    179                      
    180                     while ($posts->fetch()) 
    181                     { 
    182                          # Get tags for post 
    183                          $post_meta = $meta->getMetadata(array( 
    184                               'meta_type' => 'tag', 
    185                               'post_id' => $posts->post_id)); 
    186                          $pm = array(); 
    187                          while ($post_meta->fetch()) { 
    188                               $pm[] = $post_meta->meta_id; 
    189                          } 
    190                           
    191                          foreach ($tags as $t) { 
    192                               if (!in_array($t,$pm)) { 
    193                                    $meta->setPostMeta($posts->post_id,'tag',$t); 
    194                               } 
    195                          } 
    196                     } 
    197                      
    198                     http::redirect($redir); 
    199                } 
    200                catch (Exception $e) 
    201                { 
    202                     $core->error->add($e->getMessage()); 
    203                } 
    204           } 
    205           elseif ($action == 'tags_remove' && !empty($_POST['meta_id']) && $core->auth->check('delete,contentadmin',$core->blog->id)) 
    206           { 
    207                try 
    208                { 
    209                     $meta =& $GLOBALS['core']->meta; 
    210                     while ($posts->fetch()) 
    211                     { 
    212                          foreach ($_POST['meta_id'] as $v) 
    213                          { 
    214                               $meta->delPostMeta($posts->post_id,'tag',$v); 
    215                          } 
    216                     } 
    217                      
    218                     http::redirect($redir); 
    219                } 
    220                catch (Exception $e) 
    221                { 
    222                     $core->error->add($e->getMessage()); 
    223                } 
    224           } 
    225      } 
    226       
    227      public static function adminPostsActionsContent($core,$action,$hidden_fields,$form_uri="posts_actions.php") 
    228      { 
    229           if ($action == 'tags') 
    230           { 
    231                echo dcPage::breadcrumb( 
    232                     array( 
    233                          html::escapeHTML($core->blog->name) => '', 
    234                          __('Entries') => 'posts.php', 
    235                          '<span class="page-title">'.__('Add tags to entries').'</span>' => '' 
    236                )). 
    237                '<form action="'.$form_uri.'" method="post">'. 
    238                //$hidden_fields->getEntries(). 
    239                '<div><label for="new_tags" class="area">'.__('Tags to add:').'</label> '. 
    240                form::textarea('new_tags',60,3). 
    241                '</div>'. 
    242                $hidden_fields. 
    243                $core->formNonce(). 
    244                form::hidden(array('action'),'tags'). 
    245                '<p><input type="submit" value="'.__('Save').'" '. 
    246                'name="save_tags" /></p>'. 
    247                '</form>'; 
    248           } 
    249           elseif ($action == 'tags_remove') 
    250           { 
    251                $meta =& $GLOBALS['core']->meta; 
    252                $tags = array(); 
    253                 
    254                foreach ($_POST['entries'] as $id) { 
    255                     $post_tags = $meta->getMetadata(array( 
    256                          'meta_type' => 'tag', 
    257                          'post_id' => (integer) $id))->toStatic()->rows(); 
    258                     foreach ($post_tags as $v) { 
    259                          if (isset($tags[$v['meta_id']])) { 
    260                               $tags[$v['meta_id']]++; 
    261                          } else { 
    262                               $tags[$v['meta_id']] = 1; 
    263                          } 
    264                     } 
    265                } 
    266                echo dcPage::breadcrumb( 
    267                     array( 
    268                          html::escapeHTML($core->blog->name) => '', 
    269                          __('Entries') => 'posts.php', 
    270                          '<span class="page-title">'.__('Remove selected tags from entries').'</span>' => '' 
    271                )); 
    272                 
    273                if (empty($tags)) { 
    274                     echo '<p>'.__('No tags for selected entries').'</p>'; 
    275                     return; 
    276                } 
    277                 
    278                $posts_count = count($_POST['entries']); 
    279                 
    280                echo 
    281                '<form action="'.$form_uri.'" method="post">'. 
    282                '<fieldset><legend>'.__('Following tags have been found in selected entries:').'</legend>'; 
    283                 
    284                foreach ($tags as $k => $n) { 
    285                     $label = '<label class="classic">%s %s</label>'; 
    286                     if ($posts_count == $n) { 
    287                          $label = sprintf($label,'%s','<strong>%s</strong>'); 
    288                     } 
    289                     echo '<p>'.sprintf($label, 
    290                               form::checkbox(array('meta_id[]'),html::escapeHTML($k)), 
    291                               html::escapeHTML($k)). 
    292                          '</p>'; 
    293                } 
    294                 
    295                echo 
    296                '<p><input type="submit" value="'.__('ok').'" /></p>'. 
    297                $hidden_fields. 
    298                $core->formNonce(). 
    299                form::hidden(array('action'),'tags_remove'). 
    300                '</fieldset></form>'; 
    301           } 
    302      } 
    303       
    304294     public static function adminUserForm($args) 
    305295     { 
Note: See TracChangeset for help on using the changeset viewer.

Sites map