PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/nextgen-gallery/admin/tags.php

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