• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List

system/handlers/admintagshandler.php

00001 <?php
00007 namespace Habari;
00008 
00014 class AdminTagsHandler extends AdminHandler
00015 {
00019   public function get_tags()
00020   {
00021     $this->theme->wsse = Utils::WSSE();
00022 
00023     $this->theme->tags = Tags::vocabulary()->get_tree( 'term_display asc' );
00024     $this->theme->max = Tags::vocabulary()->max_count();
00025 
00026     $this->display( 'tags' );
00027   }
00028 
00034   public function ajax_get_tags( $handler_vars )
00035   {
00036     Utils::check_request_method( array( 'GET', 'HEAD' ) );
00037     $response = new AjaxResponse();
00038 
00039     $wsse = Utils::WSSE( $handler_vars['nonce'], $handler_vars['timestamp'] );
00040     if ( $handler_vars['digest'] != $wsse['digest'] ) {
00041       $response->message = _t( 'WSSE authentication failed.' );
00042       $response->out();
00043       return;
00044     }
00045 
00046     $this->create_theme();
00047 
00048     $search = $handler_vars['search'];
00049 
00050     $this->theme->tags = Tags::vocabulary()->get_search( $search, 'term_display asc' );
00051     $this->theme->max = Tags::vocabulary()->max_count();
00052     $response->data = $this->theme->fetch( 'tag_collection' );
00053     $response->out();
00054   }
00055 
00060   public function ajax_tags( $handler_vars )
00061   {
00062     Utils::check_request_method( array( 'POST' ) );
00063     $response = new AjaxResponse();
00064 
00065     $wsse = Utils::WSSE( $handler_vars['nonce'], $handler_vars['timestamp'] );
00066     if ( $handler_vars['digest'] != $wsse['digest'] ) {
00067       $response->message = _t( 'WSSE authentication failed.' );
00068       $response->out();
00069       return;
00070     }
00071 
00072     $tag_names = array();
00073     $this->create_theme();
00074     $action = $this->handler_vars['action'];
00075     switch ( $action ) {
00076       case 'delete':
00077         foreach ( $_POST as $id => $delete ) {
00078           // skip POST elements which are not tag ids
00079           if ( preg_match( '/^tag_\d+/', $id ) && $delete ) {
00080             $id = substr( $id, 4 );
00081             $tag = Tags::get_by_id( $id );
00082             $tag_names[] = $tag->term_display;
00083             Tags::vocabulary()->delete_term( $tag );
00084           }
00085         }
00086         $response->message = _n( _t( 'Tag %s has been deleted.', array( implode( '', $tag_names ) ) ), _t( '%d tags have been deleted.', array( count( $tag_names ) ) ), count( $tag_names ) );
00087         break;
00088 
00089       case 'rename':
00090         if ( !isset( $this->handler_vars['master'] ) ) {
00091           $response->message = _t( 'Error: New name not specified.' );
00092           $response->out();
00093           return;
00094         }
00095         $master = $this->handler_vars['master'];
00096         $tag_names = array();
00097         foreach ( $_POST as $id => $rename ) {
00098           // skip POST elements which are not tag ids
00099           if ( preg_match( '/^tag_\d+/', $id ) && $rename ) {
00100             $id = substr( $id, 4 );
00101             $tag = Tags::get_by_id( $id );
00102             $tag_names[] = $tag->term_display;
00103           }
00104         }
00105         Tags::vocabulary()->merge( $master, $tag_names );
00106         $response->message = sprintf(
00107           _n('Tag %1$s has been renamed to %2$s.',
00108             'Tags %1$s have been renamed to %2$s.',
00109               count( $tag_names )
00110           ), implode( $tag_names, ', ' ), $master
00111         );
00112         break;
00113 
00114     }
00115     $this->theme->tags = Tags::vocabulary()->get_tree( 'term_display ASC' );
00116     $this->theme->max = Tags::vocabulary()->max_count();
00117     $response->data = $this->theme->fetch( 'tag_collection' );
00118     $response->out();
00119   }
00120 
00121 }
00122 ?>

Generated on Sun Aug 4 2013 12:51:43 for Habari by  doxygen 1.7.1