NGG_Tag_Manager

Tag management page.

Defined (1)

The class is defined in the following location(s).

/admin/class-ngg-tag-manager.php  
  1. class NGG_Tag_Manager implements NGG_Displayable { 
  2.  
  3. public function display() { 
  4. $action_status = array('message' => '', 'status' => 'ok'); 
  5.  
  6. if ( isset($_POST['tag_action']) ) { 
  7.  
  8. check_admin_referer('nggallery_admin_tags'); 
  9.  
  10. if ( $_POST['tag_action'] == 'renametag' ) { 
  11. $oldtag = (isset($_POST['renametag_old'])) ? $_POST['renametag_old'] : ''; 
  12. $newtag = (isset($_POST['renametag_new'])) ? $_POST['renametag_new'] : ''; 
  13. $action_status = nggTags::rename_tags( $oldtag, $newtag ); 
  14. } elseif ( $_POST['tag_action'] == 'deletetag' ) { 
  15. $todelete = (isset($_POST['deletetag_name'])) ? $_POST['deletetag_name'] : ''; 
  16. $action_status = nggTags::delete_tags( $todelete ); 
  17. } elseif ( $_POST['tag_action'] == 'editslug' ) { 
  18. $matchtag = (isset($_POST['tagname_match'])) ? $_POST['tagname_match'] : ''; 
  19. $newslug = (isset($_POST['tagslug_new'])) ? $_POST['tagslug_new'] : ''; 
  20. $action_status = nggTags::edit_tag_slug( $matchtag, $newslug ); 
  21.  
  22. // Some useful variables 
  23. $admin_base_url = admin_url() . 'admin.php?page=nggallery-tags'; 
  24. $nb_tags = 50; // Number of tags to show on a single page 
  25.  
  26. // Manage URL 
  27. $sort_order = ( isset($_GET['tag_sortorder']) ) ? esc_attr( stripslashes($_GET['tag_sortorder']) ) : 'desc'; 
  28. $search_url = ( isset($_GET['search']) ) ? '&search=' . esc_attr ( stripslashes($_GET['search']) ) : ''; 
  29. $action_url = $admin_base_url . '&tag_sortorder=' . $sort_order. $search_url; 
  30.  
  31. // Tags Filters 
  32. $order_array = array( 
  33. 'desc' => __('Most popular', 'nggallery'),  
  34. 'asc' => __('Least used', 'nggallery'),  
  35. 'natural' => __('Alphabetical', 'nggallery')); 
  36.  
  37. // Build Tags Param 
  38. $param = 'hide_empty=false'; 
  39. switch ($sort_order) { 
  40. case 'natural' : 
  41. $param .= '&number='.$nb_tags.'&orderby=name&order=asc'; 
  42. break; 
  43. case 'asc' : 
  44. $param .= '&number='.$nb_tags.'&orderby=count&order=asc'; 
  45. break; 
  46. default : 
  47. $param .= '&number='.$nb_tags.'&orderby=count&order=desc'; 
  48. break; 
  49.  
  50.  
  51. // Search 
  52. if ( !empty($_GET['search']) ) { 
  53. $search = stripslashes($_GET['search']); 
  54. $param .= '&name__like=' . $search; 
  55.  
  56. // Offset 
  57. if ( !empty($_GET['offset']) ) { 
  58. $param .= '&offset=' . intval( $_GET['offset'] ); 
  59.  
  60. // Navigation urls 
  61. if ( empty($_GET['offset']) ) { 
  62. $offset = 0; 
  63. } else { 
  64. $offset = intval( $_GET['offset'] ); 
  65.  
  66. $tag_count = (int)wp_count_terms('ngg_tag', 'ignore_empty=true'); 
  67.  
  68. if ($offset + $nb_tags < $tag_count) { 
  69. $next_offset = '' . min($offset + $nb_tags, $tag_count - $nb_tags); 
  70. } else { 
  71. $next_offset = ''; 
  72.  
  73. if ($nb_tags < $tag_count && $offset>0) { 
  74. $prev_offset = '' . max($offset - $nb_tags, 0); 
  75. } else { 
  76. $prev_offset = ''; 
  77.  
  78. ?> 
  79. <style> 
  80. .disabled, .disabled:hover { border-color: #E5E5E5; color: #999999; cursor: default; } 
  81. </style> 
  82.  
  83. <div class="wrap ngg-tag-wrap"> 
  84. <h2><?php _e('Tags', 'nggallery'); ?></h2> 
  85.  
  86. <?php if ($action_status['message']!='') : ?> 
  87. <div id="message" class="<?php echo ($action_status['status']=='ok' ? 'updated' : $action_status['status']); ?> fade"> 
  88. <p><strong><?php echo $action_status['message']; ?></strong></p> 
  89. </div> 
  90. <?php endif; ?> 
  91.  
  92. <table> 
  93. <tr> 
  94. <td class="list_tags"> 
  95. <fieldset class="options" id="taglist"> 
  96. <h3><?php _e('Existing Tags', 'nggallery'); ?></h3> 
  97.  
  98. <form method="get"> 
  99. <p> 
  100. <label for="search"><?php _e('Search tags', 'nggallery'); ?></label><br /> 
  101. <input type="hidden" name="page" value="<?php echo esc_attr( stripslashes($_GET['page']) ); ?>" /> 
  102. <input type="hidden" name="tag_sortorder" value="<?php echo $sort_order; ?>" /> 
  103. <input type="text" name="search" id="search" size="10" value="<?php if (isset($_GET['search'])) echo esc_attr( stripslashes($_GET['search']) ); ?>" /> 
  104. <input class="button" type="submit" value="<?php _e('Go', 'nggallery'); ?>" /> 
  105. </p> 
  106. </form> 
  107.  
  108. <div class="sort_order"> 
  109. <h3><?php _e('Sort Order:', 'nggallery'); ?></h3> 
  110. <?php 
  111. $output = array(); 
  112. foreach( $order_array as $sort => $title ) { 
  113. $output[] = ($sort == $sort_order) ? '<span style="color: red;">'.$title.'</span>' : '<a href="'. $admin_base_url . '&tag_sortorder=' . $sort . $search_url .'">'.$title.'</a>'; 
  114. echo implode('<br />', $output); 
  115. $output = array(); 
  116. unset($output); 
  117. ?> 
  118. </div> 
  119.  
  120. <div id="ajax_area_tagslist"> 
  121. <ul> 
  122. <?php 
  123. $tags = (array) nggTags::find_tags($param, true); 
  124. foreach( $tags as $tag ) { 
  125. //TODO:Tag link should be call a list of images in manage gallery 
  126. //echo '<li><span>' . $tag->name . '</span> <a href="'.(ngg_get_tag_link( $tag->term_id )).'" title="'.sprintf(__('View all images tagged with %s', 'nggallery'), $tag->name).'">('.$tag->count.')</a></li>'."\n"; 
  127. echo '<li><span>' . esc_html( $tag->name ). '</span> '.'('. esc_html( $tag->count ).')</li>'."\n"; 
  128.  
  129. unset($tags); 
  130. ?> 
  131. </ul> 
  132.  
  133. <?php if ( $prev_offset!='' || $next_offset!='' ) : ?> 
  134. <div class="navigation"> 
  135.  
  136. <?php if ($prev_offset!='') { ?> 
  137. <form method="get" style="display: inline;"> 
  138. <span> 
  139. <input type="hidden" name="page" value="<?php echo esc_attr( stripslashes($_GET['page']) ); ?>" /> 
  140. <input type="hidden" name="tag_sortorder" value="<?php echo $sort_order; ?>" /> 
  141. <input type="hidden" name="offset" value="<?php echo $prev_offset; ?>" /> 
  142. <input class="button" type="submit" value="« <?php _e('Previous tags', 'nggallery'); ?>" /> 
  143. </span> 
  144. </form> 
  145. <?php } else { ?> 
  146. <span><span class="button disabled">« <?php _e('Previous tags', 'nggallery'); ?></span></span> 
  147. <?php } ?> 
  148.  
  149. <?php if ($next_offset!='') { ?> 
  150. <form method="get" style="display: inline;"> 
  151. <span> 
  152. <input type="hidden" name="page" value="<?php echo esc_attr( stripslashes($_GET['page']) ); ?>" /> 
  153. <input type="hidden" name="tag_sortorder" value="<?php echo $sort_order; ?>" /> 
  154. <input type="hidden" name="offset" value="<?php echo $next_offset; ?>" /> 
  155. <input class="button" type="submit" value="<?php _e('Next tags', 'nggallery'); ?> »" /> 
  156. </span> 
  157. </form> 
  158. <?php } else { ?> 
  159. <span><span class="button disabled"><?php _e('Previous tags', 'nggallery'); ?> »</span></span> 
  160. <?php } ?> 
  161. </div> 
  162. <?php endif; ?> 
  163. </div> 
  164. </fieldset> 
  165. </td> 
  166. <td class="forms_manage"> 
  167. <h3><?php _e('Rename Tag', 'nggallery'); ?></h3> 
  168. <form action="<?php echo $action_url; ?>" method="post"> 
  169. <input type="hidden" name="tag_action" value="renametag" /> 
  170. <?php wp_nonce_field('nggallery_admin_tags'); ?> 
  171.  
  172. <table class="form-table"> 
  173. <tr valign="top"> 
  174. <td colspan="2"> 
  175. <p><?php _e('Enter the tag to rename and its new value. You can use this feature to merge tags too. Click "Rename" and all posts which use this tag will be updated.', 'nggallery'); ?></p> 
  176. <p><?php _e('You can specify multiple tags to rename by separating them with commas.', 'nggallery'); ?></p> 
  177. </td> 
  178. </tr> 
  179. <tr valign="top"> 
  180. <th scope="row"><label for="renametag_old"><?php _e('Tag(s) to rename:', 'nggallery'); ?></label></th> 
  181. <td><input type="text" id="renametag_old" name="renametag_old" value="" size="40" /></td> 
  182. </tr> 
  183. <tr valign="top"> 
  184. <th scope="row"><label for="renametag_new"><?php _e('New tag name(s):', 'nggallery'); ?></label></th> 
  185. <td> 
  186. <input type="text" id="renametag_new" name="renametag_new" value="" size="40" /> 
  187. <input class="button" type="submit" name="rename" value="<?php _e('Rename', 'nggallery'); ?>" /> 
  188. </td> 
  189. </tr> 
  190. </table> 
  191. </form> 
  192.  
  193. <h3><?php _e('Delete Tag', 'nggallery'); ?></h3> 
  194. <form action="<?php echo $action_url; ?>" method="post"> 
  195. <input type="hidden" name="tag_action" value="deletetag" /> 
  196. <?php wp_nonce_field('nggallery_admin_tags'); ?> 
  197.  
  198. <table class="form-table"> 
  199. <tr valign="top"> 
  200. <td colspan="2"> 
  201. <p><?php _e('Enter the name of the tag to delete. This tag will be removed from all posts.', 'nggallery'); ?></p> 
  202. <p><?php _e('You can specify multiple tags to delete by separating them with commas', 'nggallery'); ?>.</p> 
  203. </td> 
  204. </tr> 
  205. <tr valign="top"> 
  206. <th scope="row"><label for="deletetag_name"><?php _e('Tag(s) to delete:', 'nggallery'); ?></label></th> 
  207. <td> 
  208. <input type="text" id="deletetag_name" name="deletetag_name" value="" size="40" /> 
  209. <input class="button" type="submit" name="delete" value="<?php _e('Delete', 'nggallery'); ?>" /> 
  210. </td> 
  211. </tr> 
  212. </table> 
  213. </form> 
  214.  
  215. <h3><?php _e('Edit Tag Slug', 'nggallery'); ?></h3> 
  216. <form action="<?php echo $action_url; ?>" method="post"> 
  217. <input type="hidden" name="tag_action" value="editslug" /> 
  218. <?php wp_nonce_field('nggallery_admin_tags'); ?> 
  219.  
  220. <table class="form-table"> 
  221. <tr valign="top"> 
  222. <td colspan="2"> 
  223. <p><?php _e('Enter the tag name to edit and its new slug. <a href="http://codex.wordpress.org/Glossary#Slug">Slug definition</a>', 'nggallery'); ?></p> 
  224. <p><?php _e('You can specify multiple tags to rename by separating them with commas.', 'nggallery'); ?></p> 
  225. </td> 
  226. </tr> 
  227. <tr valign="top"> 
  228. <th scope="row"><label for="tagname_match"><?php _e('Tag(s) to match:', 'nggallery'); ?></label></th> 
  229. <td><input type="text" id="tagname_match" name="tagname_match" value="" size="40" /></td> 
  230. </tr> 
  231. <tr valign="top"> 
  232. <th scope="row"><label for="tagslug_new"><?php _e('Slug(s) to set:', 'nggallery'); ?></label></th> 
  233. <td> 
  234. <input type="text" id="tagslug_new" name="tagslug_new" value="" size="40" /> 
  235. <input class="button" type="submit" name="edit" value="<?php _e('Edit', 'nggallery'); ?>" /> 
  236. </td> 
  237. </tr> 
  238. </table> 
  239. </form> 
  240. </td> 
  241. </tr> 
  242. </table> 
  243. <script type="text/javascript"> 
  244. // <![CDATA[ 
  245. // Register onclick event 
  246. function registerClick() { 
  247. jQuery('#taglist').find('ul li span').bind("click", function() { 
  248. addTag(this.innerHTML, "renametag_old"); 
  249. addTag(this.innerHTML, "deletetag_name"); 
  250. addTag(this.innerHTML, "tagname_match"); 
  251. }); 
  252.  
  253. // Register initial event 
  254. jQuery(document).ready(function() { 
  255. registerClick(); 
  256. }); 
  257.  
  258. // Add tag into input 
  259. function addTag( tag, name_element ) { 
  260. var input_element = document.getElementById( name_element ); 
  261.  
  262. if ( input_element.value.length > 0 && !input_element.value.match(/, \s*$/) ) 
  263. input_element.value += ", "; 
  264.  
  265. var re = new RegExp(tag + ", "); 
  266. if ( !input_element.value.match(re) ) 
  267. input_element.value += tag + ", "; 
  268.  
  269. return true; 
  270. // ]]> 
  271. </script> 
  272. </div> 
  273.  
  274. <?php