source: trunk/www.guidonia.net/wp/wp-content/plugins/simple-tags/2.7/inc/simple-tags.admin.php@ 44

Last change on this file since 44 was 44, checked in by luciano, 14 years ago
File size: 87.3 KB
Line 
1<?php
2class SimpleTagsAdmin {
3 var $version = '';
4
5 var $info;
6 var $options;
7 var $default_options;
8 var $db_options = 'simpletags';
9
10 var $posts_base_url = '';
11 var $options_base_url = '';
12
13 // Error management
14 var $message = '';
15 var $status = '';
16
17 // Tags for Editor
18 var $all_tags = false;
19
20 // Tags list (management)
21 var $nb_tags = 50;
22
23 /**
24 * PHP4 Constructor - Intialize Admin
25 *
26 * @return SimpleTagsAdmin
27 */
28 function SimpleTagsAdmin( $default_options = array(), $version = '', $info = array() ) {
29 // 1. load version number
30 $this->version = $version;
31 unset($version);
32
33 // 2. Set class property for default options
34 $this->default_options = $default_options;
35
36 // 3. Get options from WP
37 $options_from_table = get_option( $this->db_options );
38
39 // 4. Update default options by getting not empty values from options table
40 foreach( (array) $default_options as $default_options_name => $default_options_value ) {
41 if ( !is_null($options_from_table[$default_options_name]) ) {
42 if ( is_int($default_options_value) ) {
43 $default_options[$default_options_name] = (int) $options_from_table[$default_options_name];
44 } else {
45 $default_options[$default_options_name] = $options_from_table[$default_options_name];
46 }
47 }
48 }
49
50 // 5. Set the class property and unset no used variable
51 $this->options = $default_options;
52 unset($default_options);
53 unset($options_from_table);
54 unset($default_options_value);
55
56 // 6. Get info data from constructor
57 $this->info = $info;
58 unset($info);
59
60 // 8. Admin URL for Pagination and target
61 $this->posts_base_url = $this->info['siteurl'] . '/wp-admin/edit.php?page=';
62 $this->options_base_url = $this->info['siteurl'] . '/wp-admin/options-general.php?page=';
63
64 // 9. Admin Capabilities
65 add_action('init', array(&$this, 'initRoles'));
66
67 // 10. Admin menu
68 add_action('admin_menu', array(&$this, 'adminMenu'));
69 add_action('admin_notices', array(&$this, 'displayMessage'));
70
71 // 11. Ajax action, JS Helper and admin action
72 add_action('admin_init', array(&$this, 'ajaxCheck'));
73 add_action('admin_init', array(&$this, 'checkFormMassEdit'));
74
75 // 12. Embedded Tags
76 if ( $this->options['use_embed_tags'] == 1 ) {
77 add_actions( array('save_post', 'publish_post', 'post_syndicated_item'), array(&$this, 'saveEmbedTags') );
78 }
79
80 // 13. Auto tags
81 if ( $this->options['use_auto_tags'] == 1 ) {
82 add_actions( array('save_post', 'publish_post', 'post_syndicated_item'), array(&$this, 'saveAutoTags') );
83 }
84
85 // 14. Save tags from advanced input
86 if ( $this->options['use_autocompletion'] == 1 ) {
87 add_actions( array('save_post', 'publish_post'), array(&$this, 'saveAdvancedTagsInput') );
88 add_action('do_meta_boxes', array(&$this, 'removeOldTagsInput'), 1 );
89 }
90
91 // 15. Box for post
92 add_action('admin_menu', array(&$this, 'helperClickTags_Post'), 1);
93 add_action('admin_menu', array(&$this, 'helperSuggestTags_Post'), 1);
94 add_action('admin_menu', array(&$this, 'helperAdvancedTags_Post'), 1);
95
96 // 16. Box for Page
97 if ( $this->options['use_tag_pages'] == 1 ) {
98 add_action('admin_menu', array(&$this, 'helperClickTags_Page'), 1);
99 add_action('admin_menu', array(&$this, 'helperSuggestTags_Page'), 1);
100 add_action('admin_menu', array(&$this, 'helperAdvancedTags_Page'), 1);
101 }
102
103 // 17. Load JavaScript and CSS
104 $this->initJavaScript();
105 }
106
107 function removeOldTagsInput() {
108 remove_meta_box('tagsdiv', 'post', 'side');
109 }
110
111 function initJavaScript() {
112 global $pagenow;
113
114 // Register pages
115 $st_pages = array('st_manage', 'st_mass_tags', 'st_auto', 'st_options');
116 $wp_post_pages = array('post.php', 'post-new.php');
117 $wp_page_pages = array('page.php', 'page-new.php');
118
119 // Register all JS
120 wp_register_script('st-helper-js-collection', $this->info['siteurl'].'/wp-admin/admin.php?st_ajax_action=helper_js_collection', array('jquery', 'st-helper-add-tags'), $this->version);
121 wp_register_script('st-bcomplete', $this->info['install_url'].'/inc/js/bcomplete.js', array('jquery', 'prototype', 'st-helper-add-tags', 'st-helper-js-collection'), $this->version);
122 wp_register_script('st-helper-bcomplete', $this->info['install_url'].'/inc/js/helper-bcomplete.js', array('st-bcomplete'), $this->version);
123 wp_register_script('st-helper-add-tags', $this->info['install_url'].'/inc/js/helper-add-tags.js', array('jquery'), $this->version);
124 wp_register_script('jquery-cookie', $this->info['install_url'].'/inc/js/jquery.cookie.js', array('jquery'), '1.0.0');
125 wp_register_script('st-helper-manage', $this->info['install_url'].'/inc/js/helper-manage.js', array('jquery'), $this->version);
126 wp_register_script('st-helper-options', $this->info['install_url'].'/inc/js/helper-options.js', array('jquery'), $this->version);
127 wp_register_script('st-helper-click-tags', $this->info['install_url'].'/inc/js/helper-click-tags.js', array('jquery', 'st-helper-add-tags'), $this->version);
128 wp_localize_script('st-helper-click-tags', 'stHelperClickTagsL10n', array(
129 'site_url' => $this->info['siteurl'],
130 'show_txt' => __('Display click tags', 'simpletags'),
131 'hide_txt' => __('Hide click tags', 'simpletags') ) );
132 wp_register_script('st-helper-suggested-tags', $this->info['install_url'].'/inc/js/helper-suggested-tags.js', array('jquery', 'st-helper-add-tags'), $this->version);
133 wp_localize_script('st-helper-suggested-tags', 'stHelperSuggestedTagsL10n', array(
134 'site_url' => $this->info['siteurl'],
135 'title_bloc' => $this->getSuggestTagsTitle(),
136 'content_bloc' => __('Choose a provider to get suggested tags (local, yahoo or tag the net).', 'simpletags') ) );
137
138 // Register all CSS
139 wp_register_style ('st-admin', $this->info['install_url'].'/inc/css/simple-tags.admin.css', array(), $this->version, false );
140 wp_register_style ('st-bcomplete', $this->info['install_url'].'/inc/css/bcomplete.css', array(), $this->version, false );
141 wp_register_style ('st-bcomplete-rtl', $this->info['install_url'].'/inc/css/bcomplete-rtl.css', array('st-bcomplete'), $this->version, false );
142
143 // Common Helper for Post, Page and Plugin Page
144 if ( in_array($pagenow, $wp_post_pages) ||
145 (in_array($pagenow, $wp_page_pages) && $this->options['use_tag_pages'] == 1) ||
146 in_array($_GET['page'], $st_pages) ) {
147
148 wp_enqueue_style ('st-admin');
149 }
150
151 // Helper for posts/pages
152 if ( in_array($pagenow, $wp_post_pages) || (in_array($pagenow, $wp_page_pages) && $this->options['use_tag_pages'] == 1 ) ) {
153 if ( ((int) wp_count_terms('post_tag', 'ignore_empty=true')) != 0 ) {
154
155 if ( $this->options['use_autocompletion'] == 1 ) {
156 wp_enqueue_script('st-helper-bcomplete');
157 wp_enqueue_style ('st-bcomplete' );
158 if ( 'rtl' == get_bloginfo( 'text_direction' ) ) {
159 wp_enqueue_style ('st-bcomplete-rtl');
160 }
161 }
162
163 if ( $this->options['use_click_tags'] == 1 )
164 wp_enqueue_script('st-helper-click-tags');
165
166 if ( $this->options['use_suggested_tags'] == 1 )
167 wp_enqueue_script('st-helper-suggested-tags');
168
169 }
170 }
171
172 // add jQuery tabs for options page. Use jQuery UI Tabs from WP
173 if ( $_GET['page'] == 'st_options' ) {
174 wp_enqueue_script('jquery-ui-tabs');
175 wp_enqueue_script('jquery-cookie');
176 wp_enqueue_script('st-helper-options');
177 }
178
179 // add JS for manage tages page
180 if ( $_GET['page'] == 'st_manage' ) {
181 wp_enqueue_script('st-helper-manage');
182 }
183
184 // add JS for auto tags page
185 if ( $_GET['page'] == 'st_auto' ) {
186 wp_enqueue_script('st-helper-bcomplete');
187 wp_enqueue_style ('st-bcomplete' );
188 if ( 'rtl' == get_bloginfo( 'text_direction' ) ) {
189 wp_enqueue_style ('st-bcomplete-rtl');
190 }
191 }
192
193 // add JS for Mass Edit Tags
194 if ( $_GET['page'] == 'st_mass_tags' ) {
195 if ( ((int) wp_count_terms('post_tag', 'ignore_empty=true')) != 0 ) { // If tags exist, load JS.
196 $this->all_tags = true;
197
198 wp_enqueue_script('st-bcomplete');
199 wp_enqueue_style ('st-bcomplete' );
200 if ( 'rtl' == get_bloginfo( 'text_direction' ) ) {
201 wp_enqueue_style ('st-bcomplete-rtl');
202 }
203 }
204 }
205 }
206
207 function initRoles() {
208 if ( function_exists('get_role') ) {
209 $role = get_role('administrator');
210 if( $role != null && !$role->has_cap('simple_tags') ) {
211 $role->add_cap('simple_tags');
212 }
213 if( $role != null && !$role->has_cap('admin_simple_tags') ) {
214 $role->add_cap('admin_simple_tags');
215 }
216 // Clean var
217 unset($role);
218
219 $role = get_role('editor');
220 if( $role != null && !$role->has_cap('simple_tags') ) {
221 $role->add_cap('simple_tags');
222 }
223 // Clean var
224 unset($role);
225 }
226 }
227
228 /**
229 * Add WP admin menu for Tags
230 *
231 */
232 function adminMenu() {
233 add_posts_page( __('Simple Tags: Manage Tags', 'simpletags'), __('Manage Tags', 'simpletags'), 'simple_tags', 'st_manage', array(&$this, 'pageManageTags'));
234 add_posts_page( __('Simple Tags: Mass Edit Tags', 'simpletags'), __('Mass Edit Tags', 'simpletags'), 'simple_tags', 'st_mass_tags', array(&$this, 'pageMassEditTags'));
235 add_posts_page( __('Simple Tags: Auto Tags', 'simpletags'), __('Auto Tags', 'simpletags'), 'simple_tags', 'st_auto', array(&$this, 'pageAutoTags'));
236 add_options_page( __('Simple Tags: Options', 'simpletags'), __('Simple Tags', 'simpletags'), 'admin_simple_tags', 'st_options', array(&$this, 'pageOptions'));
237 }
238
239 /**
240 * WP Page - Auto Tags
241 *
242 */
243 function pageAutoTags() {
244 $action = false;
245 if ( isset($_POST['update_auto_list']) ) {
246 // Tags list
247 $tags_list = stripslashes($_POST['auto_list']);
248 $tags = explode(',', $tags_list);
249
250 // Remove empty and duplicate elements
251 $tags = array_filter($tags, array(&$this, 'deleteEmptyElement'));
252 $tags = array_unique($tags);
253
254 $this->setOption( 'auto_list', maybe_serialize($tags) );
255
256 // Active auto tags ?
257 if ( $_POST['use_auto_tags'] == '1' ) {
258 $this->setOption( 'use_auto_tags', '1' );
259 } else {
260 $this->setOption( 'use_auto_tags', '0' );
261 }
262
263 // All tags ?
264 if ( $_POST['at_all'] == '1' ) {
265 $this->setOption( 'at_all', '1' );
266 } else {
267 $this->setOption( 'at_all', '0' );
268 }
269
270 // Empty only ?
271 if ( $_POST['at_empty'] == '1' ) {
272 $this->setOption( 'at_empty', '1' );
273 } else {
274 $this->setOption( 'at_empty', '0' );
275 }
276
277 $this->saveOptions();
278 $this->message = __('Auto tags options updated !', 'simpletags');
279 } elseif ( $_GET['action'] == 'auto_tag' ) {
280 $action = true;
281 $n = ( isset($_GET['n']) ) ? intval($_GET['n']) : 0;
282 }
283
284 $tags_list = '';
285 $tags = maybe_unserialize($this->options['auto_list']);
286 if ( is_array($tags) ) {
287 $tags_list = implode(', ', $tags);
288 }
289 $this->displayMessage();
290 ?>
291 <div class="wrap st_wrap">
292 <h2><?php _e('Auto Tags', 'simpletags'); ?></h2>
293 <p><?php _e('Visit the <a href="http://code.google.com/p/simple-tags/">plugin\'s homepage</a> for further details. If you find a bug, or have a fantastic idea for this plugin, <a href="mailto:amaury@wordpress-fr.net">ask me</a> !', 'simpletags'); ?></p>
294
295 <?php if ( $action === false ) : ?>
296
297 <h3><?php _e('Auto tags list', 'simpletags'); ?></h3>
298 <p><?php _e('This feature allows Wordpress to look into post content and title for specified tags when saving posts. If your post content or title contains the word "WordPress" and you have "wordpress" in auto tags list, Simple Tags will add automatically "wordpress" as tag for this post.', 'simpletags'); ?></p>
299
300 <h3><?php _e('Options', 'simpletags'); ?></h3>
301 <form action="<?php echo $this->posts_base_url.'st_auto'; ?>" method="post">
302 <table class="form-table">
303 <tr valign="top">
304 <th scope="row"><?php _e('Activation', 'simpletags'); ?></th>
305 <td>
306 <input type="checkbox" id="use_auto_tags" name="use_auto_tags" value="1" <?php echo ( $this->options['use_auto_tags'] == 1 ) ? 'checked="checked"' : ''; ?> />
307 <label for="use_auto_tags"><?php _e('Active Auto Tags.', 'simpletags'); ?></label>
308 </td>
309 </tr>
310 <tr valign="top">
311 <th scope="row"><?php _e('Tags database', 'simpletags'); ?></th>
312 <td>
313 <input type="checkbox" id="at_all" name="at_all" value="1" <?php echo ( $this->options['at_all'] == 1 ) ? 'checked="checked"' : ''; ?> />
314 <label for="at_all"><?php _e('Use also local tags database with auto tags. (Warning, this option can increases the CPU consumption a lot if you have many tags)', 'simpletags'); ?></label>
315 </td>
316 </tr>
317 <tr valign="top">
318 <th scope="row"><?php _e('Target', 'simpletags'); ?></th>
319 <td>
320 <input type="checkbox" id="at_empty" name="at_empty" value="1" <?php echo ( $this->options['at_empty'] == 1 ) ? 'checked="checked"' : ''; ?> />
321 <label for="at_empty"><?php _e('Autotag only posts without tags.', 'simpletags'); ?></label>
322 </td>
323 </tr>
324 <tr valign="top">
325 <th scope="row"><label for="adv-tags-input"><?php _e('Keywords list', 'simpletags'); ?></label></th>
326 <td>
327 <input type="text" id="adv-tags-input" class="adv-tags-input" name="auto_list" value="<?php echo $tags_list; ?>" />
328 <br /><?php _e('Separated with a comma', 'simpletags'); ?>
329 </td>
330 </tr>
331 </table>
332
333 <p class="submit"><input class="button" type="submit" name="update_auto_list" value="<?php _e('Update options &raquo;', 'simpletags'); ?>" />
334 </form>
335
336 <h3><?php _e('Auto tags old content', 'simpletags'); ?></h3>
337 <p><?php _e('Simple Tags can also tag all existing contents of your blog. This feature use auto tags list above-mentioned.', 'simpletags'); ?> <a class="button" style="font-weight:700;" href="<?php echo $this->posts_base_url.'st_auto'; ?>&amp;action=auto_tag"><?php _e('Auto tags all content &raquo;', 'simpletags'); ?></a></p>
338
339 <?php else:
340 // Counter
341 if ( $n == 0 ) {
342 update_option('tmp_auto_tags_st', 0);
343 }
344
345 // Page or not ?
346 $post_type_sql = ( $this->options['use_tag_pages'] == '1' ) ? "post_type IN('page', 'post')" : "post_type = 'post'";
347
348 // Get objects
349 global $wpdb;
350 $objects = (array) $wpdb->get_results("SELECT p.ID, p.post_title, p.post_content FROM {$wpdb->posts} p WHERE {$post_type_sql} ORDER BY ID DESC LIMIT {$n}, 20");
351
352 if( !empty($objects) ) {
353 echo '<ul>';
354 foreach( $objects as $object ) {
355 $this->autoTagsPost( $object );
356
357 echo '<li>#'. $object->ID .' '. $object->post_title .'</li>';
358 unset($object);
359 }
360 echo '</ul>';
361 ?>
362 <p><?php _e("If your browser doesn't start loading the next page automatically click this link:", 'simpletags'); ?> <a href="<?php echo $this->posts_base_url.'st_auto'; ?>&amp;action=auto_tag&amp;n=<?php echo ($n + 20) ?>"><?php _e('Next content', 'simpletags'); ?></a></p>
363 <script type="text/javascript">
364 // <![CDATA[
365 function nextPage() {
366 location.href = '<?php echo $this->posts_base_url.'st_auto'; ?>&action=auto_tag&n=<?php echo ($n + 20) ?>';
367 }
368 window.setTimeout( 'nextPage()', 300 );
369 // ]]>
370 </script>
371 <?php
372 } else {
373 $counter = get_option('tmp_auto_tags_st');
374 delete_option('tmp_auto_tags_st');
375 echo '<p><strong>'.sprintf(__('All done! %s tags added.', 'simpletags'), $counter).'</strong></p>';
376 }
377
378 endif;
379 $this->printAdminFooter(); ?>
380 </div>
381 <?php
382 }
383
384 /**
385 * WP Page - Tags options
386 *
387 */
388 function pageOptions() {
389 $option_data = array(
390 'general' => array(
391 array('use_tag_pages', __('Active tags for page:', 'simpletags'), 'checkbox', '1',
392 __('This feature allow page to be tagged. This option add pages in tags search. Also this feature add tag management in write page.', 'simpletags')),
393 array('allow_embed_tcloud', __('Allow tag cloud in post/page content:', 'simpletags'), 'checkbox', '1',
394 __('Enabling this will allow Wordpress to look for tag cloud marker <code>&lt;!--st_tag_cloud--&gt;</code> when displaying posts. WP replace this marker by a tag cloud.', 'simpletags')),
395 array('no_follow', __('Add the rel="nofollow" on each tags link ?', 'simpletags'), 'checkbox', '1',
396 __("Nofollow is a non-standard HTML attribute value used to instruct search engines that a hyperlink should not influence the link target's ranking in the search engine's index.",'simpletags'))
397 ),
398 'administration' => array(
399 array('use_click_tags', __('Activate click tags feature:', 'simpletags'), 'checkbox', '1',
400 __('This feature add a link allowing you to display all the tags of your database. Once displayed, you can click over to add tags to post.', 'simpletags')),
401 array('use_autocompletion', __('Activate autocompletion feature:', 'simpletags'), 'checkbox', '1',
402 __('This feature displays a visual help allowing to enter tags more easily. As well add tags is easier than the autocompletion default of WordPress', 'simpletags')),
403 array('use_suggested_tags', __('Activate suggested tags feature: (Yahoo! Term Extraction API, Tag The Net, Local DB)', 'simpletags'), 'checkbox', '1',
404 __('This feature add a box allowing you get suggested tags, by comparing post content and various sources of tags. (external and internal)', 'simpletags'))
405 ),
406 'auto-links' => array(
407 array('auto_link_tags', __('Active auto link tags into post content:', 'simpletags'), 'checkbox', '1',
408 __('Example: You have a tag called "WordPress" and your post content contains "wordpress", this feature will replace "wordpress" by a link to "wordpress" tags page. (http://myblog.net/tag/wordpress/)', 'simpletags')),
409 array('auto_link_min', __('Min usage for auto link tags:', 'simpletags'), 'text', '1',
410 __('This parameter allows to fix a minimal value of use of tags. Default: 1.', 'simpletags')),
411 array('auto_link_max_by_post', __('Maximum number of links per article:', 'simpletags'), 'text', '10',
412 __('This setting determines the maximum number of links created by article. Default: 10.', 'simpletags')),
413 array('auto_link_case', __('Ignore case for auto link feature ?', 'simpletags'), 'checkbox', '1',
414 __('Example: If you ignore case, auto link feature will replace the word "wordpress" by the tag link "WordPress".', 'simpletags'))
415 ),
416 'metakeywords' => array(
417 array('meta_autoheader', __('Automatically include in header:', 'simpletags'), 'checkbox', '1',
418 __('Includes the meta keywords tag automatically in your header (most, but not all, themes support this). These keywords are sometimes used by search engines.<br /><strong>Warning:</strong> If the plugin "All in One SEO Pack" is installed and enabled. This feature is automatically disabled.', 'simpletags')),
419 array('meta_always_include', __('Always add these keywords:', 'simpletags'), 'text', 80),
420 array('meta_keywords_qty', __('Max keywords display:', 'simpletags'), 'text', 10,
421 __('You must set zero (0) for display all keywords in HTML header.', 'simpletags'))
422 ),
423 'embeddedtags' => array(
424 array('use_embed_tags', __('Use embedded tags:', 'simpletags'), 'checkbox', '1',
425 __('Enabling this will allow Wordpress to look for embedded tags when saving and displaying posts. Such set of tags is marked <code>[tags]like this, and this[/tags]</code>, and is added to the post when the post is saved, but does not display on the post.', 'simpletags')),
426 array('start_embed_tags', __('Prefix for embedded tags:', 'simpletags'), 'text', 40),
427 array('end_embed_tags', __('Suffix for embedded tags:', 'simpletags'), 'text', 40)
428 ),
429 'tagspost' => array(
430 array('tt_feed', __('Automatically display tags list into feeds', 'simpletags'), 'checkbox', '1'),
431 array('tt_embedded', __('Automatically display tags list into post content:', 'simpletags'), 'dropdown', 'no/all/blogonly/feedonly/homeonly/singularonly/pageonly/singleonly',
432 '<ul>
433 <li>'.__('<code>no</code> &ndash; Nowhere (default)', 'simpletags').'</li>
434 <li>'.__('<code>all</code> &ndash; On your blog and feeds.', 'simpletags').'</li>
435 <li>'.__('<code>blogonly</code> &ndash; Only on your blog.', 'simpletags').'</li>
436 <li>'.__('<code>homeonly</code> &ndash; Only on your home page.', 'simpletags').'</li>
437 <li>'.__('<code>singularonly</code> &ndash; Only on your singular view (single & page).', 'simpletags').'</li>
438 <li>'.__('<code>singleonly</code> &ndash; Only on your single view.', 'simpletags').'</li>
439 <li>'.__('<code>pageonly</code> &ndash; Only on your page view.', 'simpletags').'</li>
440 </ul>'),
441 array('tt_separator', __('Post tag separator string:', 'simpletags'), 'text', 10),
442 array('tt_before', __('Text to display before tags list:', 'simpletags'), 'text', 40),
443 array('tt_after', __('Text to display after tags list:', 'simpletags'), 'text', 40),
444 array('tt_number', __('Max tags display:', 'simpletags'), 'text', 10,
445 __('You must set zero (0) for display all tags.', 'simpletags')),
446 array('tt_inc_cats', __('Include categories in result ?', 'simpletags'), 'checkbox', '1'),
447 array('tt_xformat', __('Tag link format:', 'simpletags'), 'text', 80,
448 __('You can find markers and explanations <a href="http://code.google.com/p/simple-tags/wiki/ThemeIntegration">in the online documentation.</a>', 'simpletags')),
449 array('tt_notagstext', __('Text to display if no tags found:', 'simpletags'), 'text', 80),
450 array('tt_adv_usage', __('<strong>Advanced usage</strong>:', 'simpletags'), 'text', 80,
451 __('You can use the same syntax as <code>st_the_tags()</code> function to customize display. See <a href="http://code.google.com/p/simple-tags/wiki/ThemeIntegration">documentation</a> for more details.', 'simpletags'))
452 ),
453 'relatedposts' => array(
454 array('rp_feed', __('Automatically display related posts into feeds', 'simpletags'), 'checkbox', '1'),
455 array('rp_embedded', __('Automatically display related posts into post content', 'simpletags'), 'dropdown', 'no/all/blogonly/feedonly/homeonly/singularonly/pageonly/singleonly',
456 '<ul>
457 <li>'.__('<code>no</code> &ndash; Nowhere (default)', 'simpletags').'</li>
458 <li>'.__('<code>all</code> &ndash; On your blog and feeds.', 'simpletags').'</li>
459 <li>'.__('<code>blogonly</code> &ndash; Only on your blog.', 'simpletags').'</li>
460 <li>'.__('<code>homeonly</code> &ndash; Only on your home page.', 'simpletags').'</li>
461 <li>'.__('<code>singularonly</code> &ndash; Only on your singular view (single & page).', 'simpletags').'</li>
462 <li>'.__('<code>singleonly</code> &ndash; Only on your single view.', 'simpletags').'</li>
463 <li>'.__('<code>pageonly</code> &ndash; Only on your page view.', 'simpletags').'</li>
464 </ul>'),
465 array('rp_order', __('Related Posts Order:', 'simpletags'), 'dropdown', 'count-asc/count-desc/date-asc/date-desc/name-asc/name-desc/random',
466 '<ul>
467 <li>'.__('<code>date-asc</code> &ndash; Older Entries.', 'simpletags').'</li>
468 <li>'.__('<code>date-desc</code> &ndash; Newer Entries.', 'simpletags').'</li>
469 <li>'.__('<code>count-asc</code> &ndash; Least common tags between posts', 'simpletags').'</li>
470 <li>'.__('<code>count-desc</code> &ndash; Most common tags between posts (default)', 'simpletags').'</li>
471 <li>'.__('<code>name-asc</code> &ndash; Alphabetical.', 'simpletags').'</li>
472 <li>'.__('<code>name-desc</code> &ndash; Inverse Alphabetical.', 'simpletags').'</li>
473 <li>'.__('<code>random</code> &ndash; Random.', 'simpletags').'</li>
474 </ul>'),
475 array('rp_xformat', __('Post link format:', 'simpletags'), 'text', 80,
476 __('You can find markers and explanations <a href="http://code.google.com/p/simple-tags/wiki/ThemeIntegration">in the online documentation.</a>', 'simpletags')),
477 array('rp_limit_qty', __('Maximum number of related posts to display: (default: 5)', 'simpletags'), 'text', 10),
478 array('rp_notagstext', __('Enter the text to show when there is no related post:', 'simpletags'), 'text', 80),
479 array('rp_title', __('Enter the positioned title before the list, leave blank for no title:', 'simpletags'), 'text', 80),
480 array('rp_adv_usage', __('<strong>Advanced usage</strong>:', 'simpletags'), 'text', 80,
481 __('You can use the same syntax as <code>st_related_posts()</code>function to customize display. See <a href="http://code.google.com/p/simple-tags/wiki/ThemeIntegration">documentation</a> for more details.', 'simpletags'))
482 ),
483 'relatedtags' => array(
484 array('rt_number', __('Maximum number of related tags to display: (default: 5)', 'simpletags'), 'text', 10),
485 array('rt_order', __('Order related tags:', 'simpletags'), 'dropdown', 'count-asc/count-desc/name-asc/name-desc/random',
486 '<ul>
487 <li>'.__('<code>count-asc</code> &ndash; Least used.', 'simpletags').'</li>
488 <li>'.__('<code>count-desc</code> &ndash; Most popular. (default)', 'simpletags').'</li>
489 <li>'.__('<code>name-asc</code> &ndash; Alphabetical.', 'simpletags').'</li>
490 <li>'.__('<code>name-desc</code> &ndash; Inverse Alphabetical.', 'simpletags').'</li>
491 <li>'.__('<code>random</code> &ndash; Random.', 'simpletags').'</li>
492 </ul>'),
493 array('rt_format', __('Related tags type format:', 'simpletags'), 'dropdown', 'list/flat',
494 '<ul>
495 <li>'.__('<code>list</code> &ndash; Display a formatted list (ul/li).', 'simpletags').'</li>
496 <li>'.__('<code>flat</code> &ndash; Display inline (no list, just a div)', 'simpletags').'</li>
497 </ul>'),
498 array('rt_method', __('Method of tags intersections and unions used to build related tags link:', 'simpletags'), 'dropdown', 'OR/AND',
499 '<ul>
500 <li>'.__('<code>OR</code> &ndash; Fetches posts with either the "Tag1" <strong>or</strong> the "Tag2" tag. (default)', 'simpletags').'</li>
501 <li>'.__('<code>AND</code> &ndash; Fetches posts with both the "Tag1" <strong>and</strong> the "Tag2" tag.', 'simpletags').'</li>
502 </ul>'),
503 array('rt_xformat', __('Related tags link format:', 'simpletags'), 'text', 80,
504 __('You can find markers and explanations <a href="http://code.google.com/p/simple-tags/wiki/ThemeIntegration">in the online documentation.</a>', 'simpletags')),
505 array('rt_separator', __('Related tags separator:', 'simpletags'), 'text', 10,
506 __('Leave empty for list format.', 'simpletags')),
507 array('rt_notagstext', __('Enter the text to show when there is no related tags:', 'simpletags'), 'text', 80),
508 array('rt_title', __('Enter the positioned title before the list, leave blank for no title:', 'simpletags'), 'text', 80),
509 array('rt_adv_usage', __('<strong>Advanced usage</strong>:', 'simpletags'), 'text', 80,
510 __('You can use the same syntax as <code>st_related_tags()</code>function to customize display. See <a href="http://code.google.com/p/simple-tags/wiki/ThemeIntegration">documentation</a> for more details.', 'simpletags')),
511 // Remove related tags
512 array('text_helper', 'text_helper', 'helper', '', '<h3>'.__('Remove related Tags', 'simpletags').'</h3>'),
513 array('rt_format', __('Remove related Tags type format:', 'simpletags'), 'dropdown', 'list/flat',
514 '<ul>
515 <li>'.__('<code>list</code> &ndash; Display a formatted list (ul/li).', 'simpletags').'</li>
516 <li>'.__('<code>flat</code> &ndash; Display inline (no list, just a div)', 'simpletags').'</li>
517 </ul>'),
518 array('rt_remove_separator', __('Remove related tags separator:', 'simpletags'), 'text', 10,
519 __('Leave empty for list format.', 'simpletags')),
520 array('rt_remove_notagstext', __('Enter the text to show when there is no remove related tags:', 'simpletags'), 'text', 80),
521 array('rt_remove_xformat', __('Remove related tags link format:', 'simpletags'), 'text', 80,
522 __('You can find markers and explanations <a href="http://code.google.com/p/simple-tags/wiki/ThemeIntegration">in the online documentation.</a>', 'simpletags')),
523 ),
524 'tagcloud' => array(
525 array('text_helper', 'text_helper', 'helper', '', __('Which difference between <strong>&#8216;Order tags selection&#8217;</strong> and <strong>&#8216;Order tags display&#8217;</strong> ?<br />', 'simpletags')
526 . '<ul style="list-style:square;">
527 <li>'.__('<strong>&#8216;Order tags selection&#8217;</strong> is the first step during tag\'s cloud generation, corresponding to collect tags.', 'simpletags').'</li>
528 <li>'.__('<strong>&#8216;Order tags display&#8217;</strong> is the second. Once tags choosen, you can reorder them before display.', 'simpletags').'</li>
529 </ul>'.
530 __('<strong>Example:</strong> You want display randomly the 100 tags most popular.<br />', 'simpletags').
531 __('You must set &#8216;Order tags selection&#8217; to <strong>count-desc</strong> for retrieve the 100 tags most popular and &#8216;Order tags display&#8217; to <strong>random</strong> for randomize cloud.', 'simpletags')),
532 array('cloud_selection', __('Order tags selection:', 'simpletags'), 'dropdown', 'count-asc/count-desc/name-asc/name-desc/random',
533 '<ul>
534 <li>'.__('<code>count-asc</code> &ndash; Least used.', 'simpletags').'</li>
535 <li>'.__('<code>count-desc</code> &ndash; Most popular. (default)', 'simpletags').'</li>
536 <li>'.__('<code>name-asc</code> &ndash; Alphabetical.', 'simpletags').'</li>
537 <li>'.__('<code>name-desc</code> &ndash; Inverse Alphabetical.', 'simpletags').'</li>
538 <li>'.__('<code>random</code> &ndash; Random.', 'simpletags').'</li>
539 </ul>'),
540 array('cloud_sort', __('Order tags display:', 'simpletags'), 'dropdown', 'count-asc/count-desc/name-asc/name-desc/random',
541 '<ul>
542 <li>'.__('<code>count-asc</code> &ndash; Least used.', 'simpletags').'</li>
543 <li>'.__('<code>count-desc</code> &ndash; Most popular.', 'simpletags').'</li>
544 <li>'.__('<code>name-asc</code> &ndash; Alphabetical.', 'simpletags').'</li>
545 <li>'.__('<code>name-desc</code> &ndash; Inverse Alphabetical.', 'simpletags').'</li>
546 <li>'.__('<code>random</code> &ndash; Random. (default)', 'simpletags').'</li>
547 </ul>'),
548 array('cloud_inc_cats', __('Include categories in tag cloud ?', 'simpletags'), 'checkbox', '1'),
549 array('cloud_format', __('Tags cloud type format:', 'simpletags'), 'dropdown', 'list/flat',
550 '<ul>
551 <li>'.__('<code>list</code> &ndash; Display a formatted list (ul/li).', 'simpletags').'</li>
552 <li>'.__('<code>flat</code> &ndash; Display inline (no list, just a div)', 'simpletags').'</li>
553 </ul>'),
554 array('cloud_xformat', __('Tag link format:', 'simpletags'), 'text', 80,
555 __('You can find markers and explanations <a href="http://code.google.com/p/simple-tags/wiki/ThemeIntegration">in the online documentation.</a>', 'simpletags')),
556 array('cloud_limit_qty', __('Maximum number of tags to display: (default: 45)', 'simpletags'), 'text', 10),
557 array('cloud_notagstext', __('Enter the text to show when there is no tag:', 'simpletags'), 'text', 80),
558 array('cloud_title', __('Enter the positioned title before the list, leave blank for no title:', 'simpletags'), 'text', 80),
559 array('cloud_max_color', __('Most popular color:', 'simpletags'), 'text-color', 10,
560 __("The colours are hexadecimal colours, and need to have the full six digits (#eee is the shorthand version of #eeeeee).", 'simpletags')),
561 array('cloud_min_color', __('Least popular color:', 'simpletags'), 'text-color', 10),
562 array('cloud_max_size', __('Most popular font size:', 'simpletags'), 'text', 10,
563 __("The two font sizes are the size of the largest and smallest tags.", 'simpletags')),
564 array('cloud_min_size', __('Least popular font size:', 'simpletags'), 'text', 10),
565 array('cloud_unit', __('The units to display the font sizes with, on tag clouds:', 'simpletags'), 'dropdown', 'pt/px/em/%',
566 __("The font size units option determines the units that the two font sizes use.", 'simpletags')),
567 array('cloud_adv_usage', __('<strong>Advanced usage</strong>:', 'simpletags'), 'text', 80,
568 __('You can use the same syntax as <code>st_tag_cloud()</code> function to customize display. See <a href="http://code.google.com/p/simple-tags/wiki/ThemeIntegration">documentation</a> for more details.', 'simpletags'))
569 ),
570 );
571
572 // Update or reset options
573 if ( isset($_POST['updateoptions']) ) {
574 foreach((array) $this->options as $key => $value) {
575 $newval = ( isset($_POST[$key]) ) ? stripslashes($_POST[$key]) : '0';
576 $skipped_options = array('use_auto_tags', 'auto_list');
577 if ( $newval != $value && !in_array($key, $skipped_options) ) {
578 $this->setOption( $key, $newval );
579 }
580 }
581 $this->saveOptions();
582 $this->message = __('Options saved', 'simpletags');
583 $this->status = 'updated';
584 } elseif ( isset($_POST['reset_options']) ) {
585 $this->resetToDefaultOptions();
586 $this->message = __('Simple Tags options resetted to default options!', 'simpletags');
587 }
588
589 $this->displayMessage();
590 ?>
591 <div class="wrap st_wrap">
592 <h2><?php _e('Simple Tags: Options', 'simpletags'); ?></h2>
593 <p><?php _e('Visit the <a href="http://code.google.com/p/simple-tags/">plugin\'s homepage</a> for further details. If you find a bug, or have a fantastic idea for this plugin, <a href="mailto:amaury@wordpress-fr.net">ask me</a> !', 'simpletags'); ?></p>
594 <form action="<?php echo $this->options_base_url.'st_options'; ?>" method="post">
595 <p>
596 <input class="button" type="submit" name="updateoptions" value="<?php _e('Update options &raquo;', 'simpletags'); ?>" />
597 <input class="button" type="submit" name="reset_options" onclick="return confirm('<?php _e('Do you really want to restore the default options?', 'simpletags'); ?>');" value="<?php _e('Reset Options', 'simpletags'); ?>" /></p>
598
599 <div id="printOptions">
600 <ul class="st_submenu">
601 <?php foreach ( $option_data as $key => $val ) {
602 echo '<li><a href="#'. sanitize_title ( $key ) .'">'.$this->getNiceTitleOptions($key).'</a></li>';
603 } ?>
604 </ul>
605
606 <?php echo $this->printOptions( $option_data ); ?>
607 </div>
608
609 <p>
610 <input class="button" type="submit" name="updateoptions" value="<?php _e('Update options &raquo;', 'simpletags'); ?>" />
611 <input class="button" type="submit" name="reset_options" onclick="return confirm('<?php _e('Do you really want to restore the default options?', 'simpletags'); ?>');" value="<?php _e('Reset Options', 'simpletags'); ?>" /></p>
612 </form>
613 <?php $this->printAdminFooter(); ?>
614 </div>
615 <?php
616 }
617
618 /**
619 * WP Page - Manage tags
620 *
621 */
622 function pageManageTags() {
623 // Control Post data
624 if ( isset($_POST['tag_action']) ) {
625 // Origination and intention
626 if ( !wp_verify_nonce($_POST['tag_nonce'], 'simpletags_admin') ) {
627 $this->message = __('Security problem. Try again. If this problem persist, contact <a href="mailto:amaury@wordpress-fr.net">plugin author</a>.', 'simpletags');
628 $this->status = 'error';
629 }
630 elseif ( $_POST['tag_action'] == 'renametag' ) {
631 $oldtag = (isset($_POST['renametag_old'])) ? $_POST['renametag_old'] : '';
632 $newtag = (isset($_POST['renametag_new'])) ? $_POST['renametag_new'] : '';
633 $this->renameTags( $oldtag, $newtag );
634 }
635 elseif ( $_POST['tag_action'] == 'deletetag' ) {
636 $todelete = (isset($_POST['deletetag_name'])) ? $_POST['deletetag_name'] : '';
637 $this->deleteTagsByTagList( $todelete );
638 }
639 elseif ( $_POST['tag_action'] == 'addtag' ) {
640 $matchtag = (isset($_POST['addtag_match'])) ? $_POST['addtag_match'] : '';
641 $newtag = (isset($_POST['addtag_new'])) ? $_POST['addtag_new'] : '';
642 $this->addMatchTags( $matchtag, $newtag );
643 }
644 elseif ( $_POST['tag_action'] == 'editslug' ) {
645 $matchtag = (isset($_POST['tagname_match'])) ? $_POST['tagname_match'] : '';
646 $newslug = (isset($_POST['tagslug_new'])) ? $_POST['tagslug_new'] : '';
647 $this->editTagSlug( $matchtag, $newslug );
648 } elseif ( $_POST['tag_action'] == 'cleandb' ) {
649 $this->cleanDatabase();
650 }
651 }
652
653 // Manage URL
654 $sort_order = ( isset($_GET['tag_sortorder']) ) ? attribute_escape(stripslashes($_GET['tag_sortorder'])) : 'desc';
655 $search_url = ( isset($_GET['search']) ) ? '&amp;search=' . stripslashes($_GET['search']) : '';
656 $action_url = $this->posts_base_url . attribute_escape(stripslashes($_GET['page'])) . '&amp;tag_sortorder=' . $sort_order. $search_url;
657
658 // TagsFilters
659 $order_array = array(
660 'desc' => __('Most popular', 'simpletags'),
661 'asc' => __('Least used', 'simpletags'),
662 'natural' => __('Alphabetical', 'simpletags'));
663
664 // Build Tags Param
665 switch ($sort_order) {
666 case 'natural' :
667 $param = 'number='.$this->nb_tags.'&hide_empty=false&cloud_selection=name-asc';
668 break;
669 case 'asc' :
670 $param = 'number='.$this->nb_tags.'&hide_empty=false&cloud_selection=count-asc';
671 break;
672 default :
673 $param = 'number='.$this->nb_tags.'&hide_empty=false&cloud_selection=count-desc';
674 break;
675 }
676
677
678 // Search
679 if ( !empty($_GET['search']) ) {
680 $search = stripslashes($_GET['search']);
681 $param = str_replace('number='.$this->nb_tags, 'number=200&st_name_like='.$search, $param );
682 }
683
684 $this->displayMessage();
685 ?>
686 <div class="wrap st_wrap">
687 <h2><?php _e('Simple Tags: Manage Tags', 'simpletags'); ?></h2>
688 <p><?php _e('Visit the <a href="http://code.google.com/p/simple-tags/wiki/ThemeIntegration">plugin\'s homepage</a> for further details. If you find a bug, or have a fantastic idea for this plugin, <a href="mailto:amaury@wordpress-fr.net">ask me</a> !', 'simpletags'); ?></p>
689 <table>
690 <tr>
691 <td class="list_tags">
692 <fieldset class="options" id="taglist">
693 <legend><?php _e('Existing Tags', 'simpletags'); ?></legend>
694
695 <form method="get">
696 <p>
697 <label for="search"><?php _e('Search tags', 'simpletags'); ?></label><br />
698 <input type="hidden" name="page" value="<?php echo attribute_escape(stripslashes($_GET['page'])); ?>" />
699 <input type="hidden" name="tag_sortorder" value="<?php echo $sort_order; ?>" />
700 <input type="text" name="search" id="search" size="10" value="<?php echo stripslashes($_GET['search']); ?>" />
701 <input class="button" type="submit" value="<?php _e('Go', 'simpletags'); ?>" /></p>
702 </form>
703
704 <div class="sort_order">
705 <h3><?php _e('Sort Order:', 'simpletags'); ?></h3>
706 <?php
707 $output = array();
708 foreach( $order_array as $sort => $title ) {
709 $output[] = ($sort == $sort_order) ? '<span style="color: red;">'.$title.'</span>' : '<a href="'.$this->posts_base_url.attribute_escape(stripslashes($_GET['page'])).'&amp;tag_sortorder='.$sort.$search_url.'">'.$title.'</a>';
710 }
711 echo implode('<br />', $output);
712 $output = array();
713 unset($output);
714 ?>
715 </div>
716
717 <div id="ajax_area_tagslist">
718 <ul>
719 <?php
720 global $simple_tags;
721 $tags = (array) $simple_tags->getTags($param, true);
722 foreach( $tags as $tag ) {
723 echo '<li><span>'.$tag->name.'</span>&nbsp;<a href="'.(get_tag_link( $tag->term_id )).'" title="'.sprintf(__('View all posts tagged with %s', 'simpletags'), $tag->name).'">('.$tag->count.')</a></li>'."\n";
724 }
725 unset($tags);
726 ?>
727 </ul>
728
729 <?php if ( empty($_GET['search']) && ( ((int)wp_count_terms('post_tag', 'ignore_empty=true')) > $this->nb_tags ) ) : ?>
730 <div class="navigation">
731 <a href="<?php echo get_option('siteurl'). '/wp-admin/admin.php?st_ajax_action=get_tags&amp;pagination=1'. ( (isset($_GET['tag_sortorder'])) ? '&amp;order='.$sort_order : '' ); ?>"><?php _e('Previous tags', 'simpletags'); ?></a> | <?php _e('Next tags', 'simpletags'); ?>
732 </div>
733 <?php endif; ?>
734 </div>
735 </fieldset>
736 </td>
737 <td class="forms_manage">
738 <h3><?php _e('Rename Tag', 'simpletags'); ?></h3>
739 <form action="<?php echo $action_url; ?>" method="post">
740 <input type="hidden" name="tag_action" value="renametag" />
741 <input type="hidden" name="tag_nonce" value="<?php echo wp_create_nonce('simpletags_admin'); ?>" />
742
743 <table class="form-table">
744 <tr valign="top">
745 <td colspan="2">
746 <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.', 'simpletags'); ?></p>
747 <p><?php _e('You can specify multiple tags to rename by separating them with commas.', 'simpletags'); ?></p>
748 </td>
749 </tr>
750 <tr valign="top">
751 <th scope="row"><label for="renametag_old"><?php _e('Tag(s) to rename:', 'simpletags'); ?></label></th>
752 <td><input type="text" id="renametag_old" name="renametag_old" value="" size="40" /></td>
753 </tr>
754 <tr valign="top">
755 <th scope="row"><label for="renametag_new"><?php _e('New tag name(s):', 'simpletags'); ?></label></th>
756 <td>
757 <input type="text" id="renametag_new" name="renametag_new" value="" size="40" />
758 <input class="button" type="submit" name="rename" value="<?php _e('Rename', 'simpletags'); ?>" />
759 </td>
760 </tr>
761 </table>
762 </form>
763
764 <h3><?php _e('Delete Tag', 'simpletags'); ?></h3>
765 <form action="<?php echo $action_url; ?>" method="post">
766 <input type="hidden" name="tag_action" value="deletetag" />
767 <input type="hidden" name="tag_nonce" value="<?php echo wp_create_nonce('simpletags_admin'); ?>" />
768
769 <table class="form-table">
770 <tr valign="top">
771 <td colspan="2">
772 <p><?php _e('Enter the name of the tag to delete. This tag will be removed from all posts.', 'simpletags'); ?></p>
773 <p><?php _e('You can specify multiple tags to delete by separating them with commas', 'simpletags'); ?>.</p>
774 </td>
775 </tr>
776 <tr valign="top">
777 <th scope="row"><label for="deletetag_name"><?php _e('Tag(s) to delete:', 'simpletags'); ?></label></th>
778 <td>
779 <input type="text" id="deletetag_name" name="deletetag_name" value="" size="40" />
780 <input class="button" type="submit" name="delete" value="<?php _e('Delete', 'simpletags'); ?>" />
781 </td>
782 </tr>
783 </table>
784 </form>
785
786 <h3><?php _e('Add Tag', 'simpletags'); ?></h3>
787 <form action="<?php echo $action_url; ?>" method="post">
788 <input type="hidden" name="tag_action" value="addtag" />
789 <input type="hidden" name="tag_nonce" value="<?php echo wp_create_nonce('simpletags_admin'); ?>" />
790
791 <table class="form-table">
792 <tr valign="top">
793 <td colspan="2">
794 <p><?php _e('This feature lets you add one or more new tags to all posts which match any of the tags given.', 'simpletags'); ?></p>
795 <p><?php _e('You can specify multiple tags to add by separating them with commas. If you want the tag(s) to be added to all posts, then don\'t specify any tags to match.', 'simpletags'); ?></p>
796 </td>
797 </tr>
798 <tr valign="top">
799 <th scope="row"><label for="addtag_match"><?php _e('Tag(s) to match:', 'simpletags'); ?></label></th>
800 <td><input type="text" id="addtag_match" name="addtag_match" value="" size="40" /></td>
801 </tr>
802 <tr valign="top">
803 <th scope="row"><label for="addtag_new"><?php _e('Tag(s) to add:', 'simpletags'); ?></label></th>
804 <td>
805 <input type="text" id="addtag_new" name="addtag_new" value="" size="40" />
806 <input class="button" type="submit" name="Add" value="<?php _e('Add', 'simpletags'); ?>" />
807 </td>
808 </tr>
809 </table>
810 </form>
811
812 <h3><?php _e('Edit Tag Slug', 'simpletags'); ?></h3>
813 <form action="<?php echo $action_url; ?>" method="post">
814 <input type="hidden" name="tag_action" value="editslug" />
815 <input type="hidden" name="tag_nonce" value="<?php echo wp_create_nonce('simpletags_admin'); ?>" />
816
817 <table class="form-table">
818 <tr valign="top">
819 <td colspan="2">
820 <p><?php _e('Enter the tag name to edit and its new slug. <a href="http://codex.wordpress.org/Glossary#Slug">Slug definition</a>', 'simpletags'); ?></p>
821 <p><?php _e('You can specify multiple tags to rename by separating them with commas.', 'simpletags'); ?></p>
822 </td>
823 </tr>
824 <tr valign="top">
825 <th scope="row"><label for="tagname_match"><?php _e('Tag(s) to match:', 'simpletags'); ?></label></th>
826 <td><input type="text" id="tagname_match" name="tagname_match" value="" size="40" /></td>
827 </tr>
828 <tr valign="top">
829 <th scope="row"><label for="tagslug_new"><?php _e('Slug(s) to set:', 'simpletags'); ?></label></th>
830 <td>
831 <input type="text" id="tagslug_new" name="tagslug_new" value="" size="40" />
832 <input class="button" type="submit" name="edit" value="<?php _e('Edit', 'simpletags'); ?>" />
833 </td>
834 </tr>
835 </table>
836 </form>
837
838 <h3><?php _e('Remove empty terms', 'simpletags'); ?></h3>
839 <form action="<?php echo $action_url; ?>" method="post">
840 <input type="hidden" name="tag_action" value="cleandb" />
841 <input type="hidden" name="tag_nonce" value="<?php echo wp_create_nonce('simpletags_admin'); ?>" />
842
843 <table class="form-table">
844 <tr valign="top">
845 <td colspan="2">
846 <p><?php _e('WordPress 2.3 have a small bug and can create empty terms. Remove it !', 'simpletags'); ?></p>
847 <p><input class="button" type="submit" name="clean" value="<?php _e('Clean !', 'simpletags'); ?>" /></p>
848 </td>
849 </tr>
850 </table>
851 </form>
852 </td>
853 </tr>
854 </table>
855 <?php $this->printAdminFooter(); ?>
856 </div>
857 <?php
858 }
859
860 function edit_data_query( $q = false ) {
861 if ( false === $q ) {
862 $q = $_GET;
863 }
864
865 // Date
866 $q['m'] = (int) $q['m'];
867
868 // Category
869 $q['cat'] = (int) $q['cat'];
870
871 // Quantity
872 $q['posts_per_page'] = (int) $q['posts_per_page'];
873 if ( $q['posts_per_page'] == 0 ) {
874 $q['posts_per_page'] = 15;
875 }
876
877 // Content type
878 if ( $q['post_type'] == 'page' ) {
879 $q['post_type'] = 'page';
880 } else {
881 $q['post_type'] = 'post';
882 }
883
884 // Post status
885 $post_stati = array( // array( adj, noun )
886 'publish' => array(__('Published'), __('Published posts'), __ngettext_noop('Published (%s)', 'Published (%s)')),
887 'future' => array(__('Scheduled'), __('Scheduled posts'), __ngettext_noop('Scheduled (%s)', 'Scheduled (%s)')),
888 'pending' => array(__('Pending Review'), __('Pending posts'), __ngettext_noop('Pending Review (%s)', 'Pending Review (%s)')),
889 'draft' => array(__('Draft'), _c('Drafts|manage posts header'), __ngettext_noop('Draft (%s)', 'Drafts (%s)')),
890 'private' => array(__('Private'), __('Private posts'), __ngettext_noop('Private (%s)', 'Private (%s)')),
891 );
892
893 $post_stati = apply_filters('post_stati', $post_stati);
894 $avail_post_stati = get_available_post_statuses('post');
895
896 $post_status_q = '';
897 if ( isset($q['post_status']) && in_array( $q['post_status'], array_keys($post_stati) ) ) {
898 $post_status_q = '&post_status=' . $q['post_status'];
899 $post_status_q .= '&perm=readable';
900 }
901
902 if ( 'pending' === $q['post_status'] ) {
903 $order = 'ASC';
904 $orderby = 'modified';
905 } elseif ( 'draft' === $q['post_status'] ) {
906 $order = 'DESC';
907 $orderby = 'modified';
908 } else {
909 $order = 'DESC';
910 $orderby = 'date';
911 }
912
913 wp("post_type={$q['post_type']}&what_to_show=posts$post_status_q&posts_per_page={$q['posts_per_page']}&order=$order&orderby=$orderby");
914
915 return array($post_stati, $avail_post_stati);
916 }
917
918 /**
919 * WP Page - Mass edit tags
920 *
921 */
922 function pageMassEditTags() {
923 global $wpdb, $wp_locale, $wp_query;
924 list($post_stati, $avail_post_stati) = $this->edit_data_query();
925
926 if ( !isset( $_GET['paged'] ) ) {
927 $_GET['paged'] = 1;
928 }
929
930 ?>
931 <div class="wrap">
932 <form id="posts-filter" action="" method="get">
933 <input type="hidden" name="page" value="st_mass_tags" />
934 <h2><?php _e('Mass edit tags', 'simpletags'); ?></h2>
935
936 <ul class="subsubsub">
937 <?php
938 $status_links = array();
939 $num_posts = wp_count_posts('post', 'readable');
940 $class = (empty($_GET['post_status']) && empty($_GET['post_type'])) ? ' class="current"' : '';
941 $status_links[] = "<li><a href=\"edit.php?page=st_mass_tags\"$class>".__('All Posts', 'simpletags')."</a>";
942 foreach ( $post_stati as $status => $label ) {
943 $class = '';
944
945 if ( !in_array($status, $avail_post_stati) ) {
946 continue;
947 }
948
949 if ( empty($num_posts->$status) )
950 continue;
951 if ( $status == $_GET['post_status'] )
952 $class = ' class="current"';
953
954 $status_links[] = "<li><a href=\"edit.php?page=st_mass_tags&amp;post_status=$status\"$class>" .
955 sprintf(__ngettext($label[2][0], $label[2][1], $num_posts->$status), number_format_i18n( $num_posts->$status )) . '</a>';
956 }
957 echo implode(' |</li>', $status_links) . ' |</li>';
958 unset($status_links);
959
960 $class = (!empty($_GET['post_type'])) ? ' class="current"' : '';
961 ?>
962 <li><a href="edit.php?page=st_mass_tags&amp;post_type=page" <?php echo $class; ?>><?php _e('All Pages', 'simpletags'); ?></a>
963 </ul>
964
965 <?php if ( isset($_GET['post_status'] ) ) : ?>
966 <input type="hidden" name="post_status" value="<?php echo attribute_escape($_GET['post_status']) ?>" />
967 <?php endif; ?>
968
969 <p id="post-search">
970 <input type="text" id="post-search-input" name="s" value="<?php the_search_query(); ?>" />
971 <input type="submit" value="<?php _e( 'Search Posts', 'simpletags' ); ?>" class="button" />
972 </p>
973
974 <div class="tablenav">
975 <?php
976 $posts_per_page = (int) $_GET['posts_per_page'];
977 if ( $posts_per_page == 0 ) {
978 $posts_per_page = 15;
979 }
980
981 $page_links = paginate_links( array(
982 'base' => add_query_arg( 'paged', '%#%' ),
983 'format' => '',
984 'total' => ceil($wp_query->found_posts / $posts_per_page ),
985 'current' => ((int) $_GET['paged'])
986 ));
987
988 if ( $page_links )
989 echo "<div class='tablenav-pages'>$page_links</div>";
990 ?>
991
992 <div style="float: left">
993 <?php
994 if ( !is_singular() ) {
995 $arc_query = "SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = 'post' ORDER BY post_date DESC";
996
997 $arc_result = $wpdb->get_results( $arc_query );
998
999 $month_count = count($arc_result);
1000
1001 if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { ?>
1002 <select name='m'>
1003 <option<?php selected( @$_GET['m'], 0 ); ?> value='0'><?php _e('Show all dates', 'simpletags'); ?></option>
1004 <?php
1005 foreach ($arc_result as $arc_row) {
1006 if ( $arc_row->yyear == 0 )
1007 continue;
1008 $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 );
1009
1010 if ( $arc_row->yyear . $arc_row->mmonth == $_GET['m'] )
1011 $default = ' selected="selected"';
1012 else
1013 $default = '';
1014
1015 echo "<option$default value='$arc_row->yyear$arc_row->mmonth'>";
1016 echo $wp_locale->get_month($arc_row->mmonth) . " $arc_row->yyear";
1017 echo "</option>\n";
1018 }
1019 ?>
1020 </select>
1021 <?php } ?>
1022
1023 <?php wp_dropdown_categories('show_option_all='.__('View all categories', 'simpletags').'&hide_empty=1&hierarchical=1&show_count=1&selected='.$_GET['cat']);?>
1024
1025 <select name="posts_per_page" id="posts_per_page">
1026 <option <?php if ( !isset($_GET['posts_per_page']) ) echo 'selected="selected"'; ?> value=""><?php _e('Quantity&hellip;', 'simpletags'); ?></option>
1027 <option <?php if ( $posts_per_page == 10 ) echo 'selected="selected"'; ?> value="10">10</option>
1028 <option <?php if ( $posts_per_page == 20 ) echo 'selected="selected"'; ?> value="20">20</option>
1029 <option <?php if ( $posts_per_page == 30 ) echo 'selected="selected"'; ?> value="30">30</option>
1030 <option <?php if ( $posts_per_page == 40 ) echo 'selected="selected"'; ?> value="40">40</option>
1031 <option <?php if ( $posts_per_page == 50 ) echo 'selected="selected"'; ?> value="50">50</option>
1032 <option <?php if ( $posts_per_page == 100 ) echo 'selected="selected"'; ?> value="100">100</option>
1033 <option <?php if ( $posts_per_page == 200 ) echo 'selected="selected"'; ?> value="200">200</option>
1034 </select>
1035
1036 <input type="submit" id="post-query-submit" value="<?php _e('Filter', 'simpletags'); ?>" class="button-secondary" />
1037 <?php } ?>
1038 </div>
1039
1040 <br style="clear:both;" />
1041 </div>
1042 </form>
1043
1044 <br style="clear:both;" />
1045
1046 <?php if ( have_posts() ) :
1047 add_filter('the_title','wp_specialchars');
1048 ?>
1049 <form name="post" id="post" method="post">
1050 <table class="widefat post fixed">
1051 <thead>
1052 <tr>
1053 <th class="manage-column"><?php _e('Post title', 'simpletags'); ?></th>
1054 <th class="manage-column"><?php _e('Tags', 'simpletags'); ?></th>
1055 </tr>
1056 </thead>
1057 <tbody>
1058 <?php
1059 $class = 'alternate';
1060 while (have_posts()) {
1061 the_post();
1062 $class = ( $class == 'alternate' ) ? '' : 'alternate';
1063 ?>
1064 <tr valign="top" class="<?php echo $class; ?>">
1065 <th scope="row"><a href="post.php?action=edit&amp;post=<?php the_ID(); ?>" title="<?php _e('Edit', 'simpletags'); ?>"><?php the_title(); ?></a></th>
1066 <td><input id="tags-input<?php the_ID(); ?>" class="tags_input" type="text" size="100" name="tags[<?php the_ID(); ?>]" value="<?php echo $this->getTagsToEdit( get_the_ID() ); ?>" /></td>
1067 </tr>
1068 <?php
1069 }
1070 ?>
1071 </tbody>
1072 </table>
1073
1074 <p class="submit">
1075 <input class="button" type="hidden" name="secure_mass" value="<?php echo wp_create_nonce('st_mass_tags'); ?>" />
1076 <input class="button" type="submit" name="update_mass" value="<?php _e('Update all &raquo;', 'simpletags'); ?>" /></p>
1077 </form>
1078 <?php if ( $this->all_tags === true ) : ?>
1079 <script type="text/javascript">
1080 // <![CDATA[
1081 jQuery(document).ready(function() {
1082 <?php
1083 while ( have_posts() ) { the_post(); ?>
1084 if ( document.getElementById('tags-input<?php the_ID(); ?>') ) {
1085 var tag_<?php the_ID(); ?> = new BComplete('tags-input<?php the_ID(); ?>');
1086 tag_<?php the_ID(); ?>.setData(collection);
1087 }
1088 <?php } ?>
1089 });
1090 // ]]>
1091 </script>
1092 <?php endif; ?>
1093
1094 <?php else: ?>
1095
1096 <p><?php _e('No content to edit.', 'simpletags'); ?>
1097
1098 <?php endif; ?>
1099 <p><?php _e('Visit the <a href="http://code.google.com/p/simple-tags/">plugin\'s homepage</a> for further details. If you find a bug, or have a fantastic idea for this plugin, <a href="mailto:amaury@wordpress-fr.net">ask me</a> !', 'simpletags'); ?></p>
1100 <?php $this->printAdminFooter(); ?>
1101 </div>
1102 <?php
1103 }
1104
1105 function getTagsToEdit( $post_id ) {
1106 $post_id = (int) $post_id;
1107 if ( !$post_id )
1108 return false;
1109
1110 $tags = wp_get_post_tags($post_id);
1111
1112 if ( !$tags )
1113 return false;
1114
1115 foreach ( $tags as $tag )
1116 $tag_names[] = $tag->name;
1117 $tags_to_edit = join( ', ', $tag_names );
1118 $tags_to_edit = attribute_escape( $tags_to_edit );
1119 $tags_to_edit = apply_filters( 'tags_to_edit', $tags_to_edit );
1120
1121 return $tags_to_edit;
1122 }
1123
1124 function saveAdvancedTagsInput( $post_id = null, $post_data = null ) {
1125 $object = get_post($post_id);
1126 if ( $object == false || $object == null ) {
1127 return false;
1128 }
1129
1130 if ( isset($_POST['adv-tags-input']) ) {
1131 // Post data
1132 $tags = stripslashes($_POST['adv-tags-input']);
1133
1134 // Trim data
1135 $tags = trim(stripslashes($tags));
1136
1137 // String to array
1138 $tags = explode( ',', $tags );
1139
1140 // Remove empty and trim tag
1141 $tags = array_filter($tags, array(&$this, 'deleteEmptyElement'));
1142
1143 // Add new tag (no append ! replace !)
1144 wp_set_object_terms( $post_id, $tags, 'post_tag' );
1145
1146 // Clean cache
1147 if ( 'page' == $object->post_type ) {
1148 clean_page_cache($post_id);
1149 } else {
1150 clean_post_cache($post_id);
1151 }
1152
1153 return true;
1154 }
1155 return false;
1156 }
1157
1158 /**
1159 * Save embedded tags
1160 *
1161 * @param integer $post_id
1162 * @param array $post_data
1163 */
1164 function saveEmbedTags( $post_id = null, $post_data = null ) {
1165 $object = get_post($post_id);
1166 if ( $object == false || $object == null ) {
1167 return false;
1168 }
1169
1170 // Return Tags
1171 $matches = $tags = array();
1172 preg_match_all('/(' . $this->regexEscape($this->options['start_embed_tags']) . '(.*?)' . $this->regexEscape($this->options['end_embed_tags']) . ')/is', $object->post_content, $matches);
1173
1174 foreach ( $matches[2] as $match) {
1175 foreach( (array) explode(',', $match) as $tag) {
1176 $tags[] = $tag;
1177 }
1178 }
1179
1180 if( !empty($tags) ) {
1181 // Remove empty and duplicate elements
1182 $tags = array_filter($tags, array(&$this, 'deleteEmptyElement'));
1183 $tags = array_unique($tags);
1184
1185 wp_set_post_tags( $post_id, $tags, true ); // Append tags
1186
1187 // Clean cache
1188 if ( 'page' == $object->post_type ) {
1189 clean_page_cache($post_id);
1190 } else {
1191 clean_post_cache($post_id);
1192 }
1193
1194 return true;
1195 }
1196 return false;
1197 }
1198
1199 /**
1200 * Check post/page content for auto tags
1201 *
1202 * @param integer $post_id
1203 * @param array $post_data
1204 * @return boolean
1205 */
1206 function saveAutoTags( $post_id = null, $post_data = null ) {
1207 $object = get_post($post_id);
1208 if ( $object == false || $object == null ) {
1209 return false;
1210 }
1211
1212 $result = $this->autoTagsPost( $object );
1213 if ( $result == true ) {
1214 // Clean cache
1215 if ( 'page' == $object->post_type ) {
1216 clean_page_cache($post_id);
1217 } else {
1218 clean_post_cache($post_id);
1219 }
1220 }
1221 return true;
1222 }
1223
1224 /**
1225 * Automatically tag a post/page from the database tags
1226 *
1227 * @param object $object
1228 * @return boolean
1229 */
1230 function autoTagsPost( $object ) {
1231 if ( get_the_tags($object->ID) != false && $this->options['at_empty'] == 1 ) {
1232 return false; // Skip post with tags, if tag only empty post option is checked
1233 }
1234
1235 $tags_to_add = array();
1236
1237 // Merge title + content + excerpt to compare with tags
1238 $content = $object->post_content. ' ' . $object->post_title. ' ' . $object->post_excerpt;
1239 $content = trim($content);
1240 if ( empty($content) ) {
1241 return false;
1242 }
1243
1244 // Auto tag with specifik auto tags list
1245 $tags = (array) maybe_unserialize($this->options['auto_list']);
1246 foreach ( $tags as $tag ) {
1247 if ( is_string($tag) && !empty($tag) && stristr($content, $tag) ) {
1248 $tags_to_add[] = $tag;
1249 }
1250 }
1251 unset($tags, $tag);
1252
1253 // Auto tags with all posts
1254 if ( $this->options['at_all'] == 1 ) {
1255 // Get all terms
1256 global $wpdb;
1257 $terms = $wpdb->get_col("
1258 SELECT DISTINCT name
1259 FROM {$wpdb->terms} AS t
1260 INNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id
1261 WHERE tt.taxonomy = 'post_tag'
1262 ");
1263 $terms = array_unique($terms);
1264
1265 foreach ( $terms as $term ) {
1266 $term = stripslashes($term);
1267 if ( is_string($term) && !empty($term) && stristr($content, $term) ) {
1268 $tags_to_add[] = $term;
1269 }
1270 }
1271
1272 // Clean memory
1273 $terms = array();
1274 unset($terms, $term);
1275 }
1276
1277 // Append tags if tags to add
1278 if ( !empty($tags_to_add) ) {
1279 // Remove empty and duplicate elements
1280 $tags_to_add = array_filter($tags_to_add, array(&$this, 'deleteEmptyElement'));
1281 $tags_to_add = array_unique($tags_to_add);
1282
1283 // Increment counter
1284 $counter = ((int) get_option('tmp_auto_tags_st')) + count($tags_to_add);
1285 update_option('tmp_auto_tags_st', $counter);
1286
1287 // Add tags to posts
1288 wp_set_object_terms( $object->ID, $tags_to_add, 'post_tag', true );
1289
1290 // Clean cache
1291 if ( 'page' == $object->post_type ) {
1292 clean_page_cache($object->ID);
1293 } else {
1294 clean_post_cache($object->ID);
1295 }
1296
1297 return true;
1298 }
1299 return false;
1300 }
1301
1302 ############## Helper Advanced Tags ##############
1303 function helperAdvancedTags_Page() {
1304 if ( $this->options['use_autocompletion'] == 1 )
1305 add_meta_box('adv-tagsdiv', __('Tags (Simple Tags)', 'simpletags'), array(&$this, 'boxTags'), 'page', 'side', 'core');
1306 }
1307
1308 function helperAdvancedTags_Post() {
1309 if ( $this->options['use_autocompletion'] == 1 )
1310 add_meta_box('adv-tagsdiv', __('Tags (Simple Tags)', 'simpletags'), array(&$this, 'boxTags'), 'post', 'side', 'core');
1311 }
1312
1313 function boxTags( $post ) {
1314 ?>
1315 <input type="text" name="adv-tags-input" id="adv-tags-input" size="40" tabindex="3" value="<?php echo $this->getTagsToEdit( $post->ID ); ?>" />
1316 <?php
1317 _e('Separate tags with commas', 'simpletags');
1318 }
1319
1320 ############## Manages Tags Pages ##############
1321 /*
1322 * Rename or merge tags
1323 *
1324 * @param string $old
1325 * @param string $new
1326 */
1327 function renameTags( $old = '', $new = '' ) {
1328 if ( trim( str_replace(',', '', stripslashes($new)) ) == '' ) {
1329 $this->message = __('No new tag specified!', 'simpletags');
1330 $this->status = 'error';
1331 return;
1332 }
1333
1334 // String to array
1335 $old_tags = explode(',', $old);
1336 $new_tags = explode(',', $new);
1337
1338 // Remove empty element and trim
1339 $old_tags = array_filter($old_tags, array(&$this, 'deleteEmptyElement'));
1340 $new_tags = array_filter($new_tags, array(&$this, 'deleteEmptyElement'));
1341
1342 // If old/new tag are empty => exit !
1343 if ( empty($old_tags) || empty($new_tags) ) {
1344 $this->message = __('No new/old valid tag specified!', 'simpletags');
1345 $this->status = 'error';
1346 return;
1347 }
1348
1349 $counter = 0;
1350 if( count($old_tags) == count($new_tags) ) { // Rename only
1351 foreach ( (array) $old_tags as $i => $old_tag ) {
1352 $new_name = $new_tags[$i];
1353
1354 // Get term by name
1355 $term = get_term_by('name', $old_tag, 'post_tag');
1356 if ( !$term ) {
1357 continue;
1358 }
1359
1360 // Get objects from term ID
1361 $objects_id = get_objects_in_term( $term->term_id, 'post_tag', array('fields' => 'all_with_object_id'));
1362
1363 // Delete old term
1364 wp_delete_term( $term->term_id, 'post_tag' );
1365
1366 // Set objects to new term ! (Append no replace)
1367 foreach ( (array) $objects_id as $object_id ) {
1368 wp_set_object_terms( $object_id, $new_name, 'post_tag', true );
1369 }
1370
1371 // Clean cache
1372 clean_object_term_cache( $objects_id, 'post_tag');
1373 clean_term_cache($term->term_id, 'post_tag');
1374
1375 // Increment
1376 $counter++;
1377 }
1378
1379 if ( $counter == 0 ) {
1380 $this->message = __('No tag renamed.', 'simpletags');
1381 } else {
1382 $this->message = sprintf(__('Renamed tag(s) &laquo;%1$s&raquo; to &laquo;%2$s&raquo;', 'simpletags'), $old, $new);
1383 }
1384 }
1385 elseif ( count($new_tags) == 1 ) { // Merge
1386 // Set new tag
1387 $new_tag = $new_tags[0];
1388 if ( empty($new_tag) ) {
1389 $this->message = __('No valid new tag.', 'simpletags');
1390 $this->status = 'error';
1391 return;
1392 }
1393
1394 // Get terms ID from old terms names
1395 $terms_id = array();
1396 foreach ( (array) $old_tags as $old_tag ) {
1397 $term = get_term_by('name', addslashes($old_tag), 'post_tag');
1398 $terms_id[] = (int) $term->term_id;
1399 }
1400
1401 // Get objects from terms ID
1402 $objects_id = get_objects_in_term( $terms_id, 'post_tag', array('fields' => 'all_with_object_id'));
1403
1404 // No objects ? exit !
1405 if ( !$objects_id ) {
1406 $this->message = __('No objects (post/page) found for specified old tags.', 'simpletags');
1407 $this->status = 'error';
1408 return;
1409 }
1410
1411 // Delete old terms
1412 foreach ( (array) $terms_id as $term_id ) {
1413 wp_delete_term( $term_id, 'post_tag' );
1414 }
1415
1416 // Set objects to new term ! (Append no replace)
1417 foreach ( (array) $objects_id as $object_id ) {
1418 wp_set_object_terms( $object_id, $new_tag, 'post_tag', true );
1419 $counter++;
1420 }
1421
1422 // Test if term is also a category
1423 if ( is_term($new_tag, 'category') ) {
1424 // Edit the slug to use the new term
1425 $this->editTagSlug( $new_tag, sanitize_title($new_tag) );
1426 }
1427
1428 // Clean cache
1429 clean_object_term_cache( $objects_id, 'post_tag');
1430 clean_term_cache($terms_id, 'post_tag');
1431
1432 if ( $counter == 0 ) {
1433 $this->message = __('No tag merged.', 'simpletags');
1434 } else {
1435 $this->message = sprintf(__('Merge tag(s) &laquo;%1$s&raquo; to &laquo;%2$s&raquo;. %3$s objects edited.', 'simpletags'), $old, $new, $counter);
1436 }
1437 } else { // Error
1438 $this->message = sprintf(__('Error. No enough tags for rename. Too for merge. Choose !', 'simpletags'), $old);
1439 $this->status = 'error';
1440 }
1441 return;
1442 }
1443
1444 /**
1445 * trim and remove empty element
1446 *
1447 * @param string $element
1448 * @return string
1449 */
1450 function deleteEmptyElement( &$element ) {
1451 $element = stripslashes($element);
1452 $element = trim($element);
1453 if ( !empty($element) ) {
1454 return $element;
1455 }
1456 }
1457
1458 /**
1459 * Delete list of tags
1460 *
1461 * @param string $delete
1462 */
1463 function deleteTagsByTagList( $delete ) {
1464 if ( trim( str_replace(',', '', stripslashes($delete)) ) == '' ) {
1465 $this->message = __('No tag specified!', 'simpletags');
1466 $this->status = 'error';
1467 return;
1468 }
1469
1470 // In array + filter
1471 $delete_tags = explode(',', $delete);
1472 $delete_tags = array_filter($delete_tags, array(&$this, 'deleteEmptyElement'));
1473
1474 // Delete tags
1475 $counter = 0;
1476 foreach ( (array) $delete_tags as $tag ) {
1477 $term = get_term_by('name', $tag, 'post_tag');
1478 $term_id = (int) $term->term_id;
1479
1480 if ( $term_id != 0 ) {
1481 wp_delete_term( $term_id, 'post_tag');
1482 clean_term_cache( $term_id, 'post_tag');
1483 $counter++;
1484 }
1485 }
1486
1487 if ( $counter == 0 ) {
1488 $this->message = __('No tag deleted.', 'simpletags');
1489 } else {
1490 $this->message = sprintf(__('%1s tag(s) deleted.', 'simpletags'), $counter);
1491 }
1492 }
1493
1494 /**
1495 * Add tags for all or specified posts
1496 *
1497 * @param string $match
1498 * @param string $new
1499 */
1500 function addMatchTags( $match, $new ) {
1501 if ( trim( str_replace(',', '', stripslashes($new)) ) == '' ) {
1502 $this->message = __('No new tag(s) specified!', 'simpletags');
1503 $this->status = 'error';
1504 return;
1505 }
1506
1507 $match_tags = explode(',', $match);
1508 $new_tags = explode(',', $new);
1509
1510 $match_tags = array_filter($match_tags, array(&$this, 'deleteEmptyElement'));
1511 $new_tags = array_filter($new_tags, array(&$this, 'deleteEmptyElement'));
1512
1513 $counter = 0;
1514 if ( !empty($match_tags) ) { // Match and add
1515 // Get terms ID from old match names
1516 $terms_id = array();
1517 foreach ( (array) $match_tags as $match_tag ) {
1518 $term = get_term_by('name', $match_tag, 'post_tag');
1519 $terms_id[] = (int) $term->term_id;
1520 }
1521
1522 // Get object ID with terms ID
1523 $objects_id = get_objects_in_term( $terms_id, 'post_tag', array('fields' => 'all_with_object_id') );
1524
1525 // Add new tags for specified post
1526 foreach ( (array) $objects_id as $object_id ) {
1527 wp_set_object_terms( $object_id, $new_tags, 'post_tag', true ); // Append tags
1528 $counter++;
1529 }
1530
1531 // Clean cache
1532 clean_object_term_cache( $objects_id, 'post_tag');
1533 clean_term_cache($terms_id, 'post_tag');
1534 } else { // Add for all posts
1535 // Page or not ?
1536 $post_type_sql = ( $this->options['use_tag_pages'] == '1' ) ? "post_type IN('page', 'post')" : "post_type = 'post'";
1537
1538 // Get all posts ID
1539 global $wpdb;
1540 $objects_id = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE {$post_type_sql}");
1541
1542 // Add new tags for all posts
1543 foreach ( (array) $objects_id as $object_id ) {
1544 wp_set_object_terms( $object_id, $new_tags, 'post_tag', true ); // Append tags
1545 $counter++;
1546 }
1547
1548 // Clean cache
1549 clean_object_term_cache( $objects_id, 'post_tag');
1550 }
1551
1552 if ( $counter == 0 ) {
1553 $this->message = __('No tag added.', 'simpletags');
1554 } else {
1555 $this->message = sprintf(__('Tag(s) added to %1s post(s).', 'simpletags'), $counter);
1556 }
1557 }
1558
1559 /**
1560 * Edit one or lots tags slugs
1561 *
1562 * @param string $names
1563 * @param string $slugs
1564 */
1565 function editTagSlug( $names = '', $slugs = '') {
1566 if ( trim( str_replace(',', '', stripslashes($slugs)) ) == '' ) {
1567 $this->message = __('No new slug(s) specified!', 'simpletags');
1568 $this->status = 'error';
1569 return;
1570 }
1571
1572 $match_names = explode(',', $names);
1573 $new_slugs = explode(',', $slugs);
1574
1575 $match_names = array_filter($match_names, array(&$this, 'deleteEmptyElement'));
1576 $new_slugs = array_filter($new_slugs, array(&$this, 'deleteEmptyElement'));
1577
1578 if ( count($match_names) != count($new_slugs) ) {
1579 $this->message = __('Tags number and slugs number isn\'t the same!', 'simpletags');
1580 $this->status = 'error';
1581 return;
1582 } else {
1583 $counter = 0;
1584 foreach ( (array) $match_names as $i => $match_name ) {
1585 // Sanitize slug + Escape
1586 $new_slug = sanitize_title($new_slugs[$i]);
1587
1588 // Get term by name
1589 $term = get_term_by('name', $match_name, 'post_tag');
1590 if ( !$term ) {
1591 continue;
1592 }
1593
1594 // Increment
1595 $counter++;
1596
1597 // Update term
1598 wp_update_term($term->term_id, 'post_tag', array('slug' => $new_slug));
1599
1600 // Clean cache
1601 clean_term_cache($term->term_id, 'post_tag');
1602 }
1603 }
1604
1605 if ( $counter == 0 ) {
1606 $this->message = __('No slug edited.', 'simpletags');
1607 } else {
1608 $this->message = sprintf(__('%s slug(s) edited.', 'simpletags'), $counter);
1609 }
1610 return;
1611 }
1612
1613 /**
1614 * Clean database - Remove empty terms
1615 *
1616 */
1617 function cleanDatabase() {
1618 global $wpdb;
1619
1620 // Counter
1621 $counter = 0;
1622
1623 // Get terms id empty
1624 $terms_id = $wpdb->get_col("SELECT term_id FROM {$wpdb->terms} WHERE name IN ('', ' ', ' ', '&nbsp;') GROUP BY term_id");
1625 if ( empty($terms_id) ) {
1626 $this->message = __('Nothing to muck. Good job !', 'simpletags');
1627 return;
1628 }
1629
1630 // Prepare terms SQL List
1631 $terms_list = "'" . implode("', '", $terms_id) . "'";
1632
1633 // Remove term empty
1634 $counter += $wpdb->query("DELETE FROM {$wpdb->terms} WHERE term_id IN ( {$terms_list} )");
1635
1636 // Get term_taxonomy_id from term_id on term_taxonomy table
1637 $tts_id = $wpdb->get_col("SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id IN ( {$terms_list} ) GROUP BY term_taxonomy_id");
1638
1639 if ( !empty($tts_id) ) {
1640 // Clean term_taxonomy table
1641 $counter += $wpdb->query("DELETE FROM {$wpdb->term_taxonomy} WHERE term_id IN ( {$terms_list} )");
1642
1643 // Prepare terms SQL List
1644 $tts_list = "'" . implode("', '", $tts_id) . "'";
1645
1646 // Clean term_relationships table
1647 $counter += $wpdb->query("DELETE FROM {$wpdb->term_relationships} WHERE term_taxonomy_id IN ( {$tts_list} )");
1648 }
1649
1650 // Delete cache
1651 clean_term_cache($terms_id, array('category', 'post_tag'));
1652 clean_object_term_cache($tts_list, 'post');
1653
1654 $this->message = sprintf(__('%s rows deleted. WordPress DB is clean now !', 'simpletags'), $counter);
1655 return;
1656 }
1657
1658 /**
1659 * Click tags
1660 *
1661 */
1662 function helperClickTags_Page() {
1663 if ( $this->options['use_click_tags'] == 1 )
1664 add_meta_box('st-clicks-tags', __('Click tags', 'simpletags'), array(&$this, 'boxClickTags'), 'page', 'advanced', 'core');
1665 }
1666
1667 function helperClickTags_Post() {
1668 if ( $this->options['use_click_tags'] == 1 )
1669 add_meta_box('st-clicks-tags', __('Click tags', 'simpletags'), array(&$this, 'boxClickTags'), 'post', 'advanced', 'core');
1670 }
1671
1672 function boxClickTags() {
1673 _e('This feature works only with activated JavaScript. Activate it in your Web browser so you can!', 'simpletags');
1674 }
1675
1676 /**
1677 * Suggested tags
1678 *
1679 */
1680 function getSuggestTagsTitle() {
1681 $title = '<img style="float:right; display:none;" id="st_ajax_loading" src="'.$this->info['install_url'].'/inc/images/ajax-loader.gif" alt="' .__('Ajax loading', 'simpletags').'" />';
1682 $title .= __('Suggested tags from :', 'simpletags').'&nbsp;&nbsp;';
1683 $title .= '<a class="local_db" href="#suggestedtags">'.__('Local tags', 'simpletags').'</a>&nbsp;&nbsp;-&nbsp;&nbsp;';
1684 $title .= '<a class="yahoo_api" href="#suggestedtags">'.__('Yahoo', 'simpletags').'</a>&nbsp;&nbsp;-&nbsp;&nbsp;';
1685 $title .= '<a class="ttn_api" href="#suggestedtags">'.__('Tag The Net', 'simpletags').'</a>';
1686 return $title;
1687 }
1688
1689 function helperSuggestTags_Post() {
1690 if ( $this->options['use_suggested_tags'] == 1 )
1691 add_meta_box('suggestedtags', __('Suggested tags', 'simpletags'), array(&$this, 'boxSuggestTags'), 'post', 'advanced', 'core');
1692 }
1693
1694 function helperSuggestTags_Page() {
1695 if ( $this->options['use_suggested_tags'] == 1 )
1696 add_meta_box('suggestedtags', __('Suggested tags', 'simpletags'), array(&$this, 'boxSuggestTags'), 'page', 'advanced', 'core');
1697 }
1698
1699 function boxSuggestTags() {
1700 ?>
1701 <span class="container_clicktags">
1702 <?php _e('This feature works only with activated JavaScript. Activate it in your Web browser so you can!', 'simpletags'); ?>
1703 <div class="clear"></div>
1704 </span>
1705 <?php
1706 }
1707
1708
1709 /**
1710 * Control POST data for mass edit tags
1711 *
1712 * @param string $type
1713 */
1714 function checkFormMassEdit() {
1715 if ( !current_user_can('simple_tags') ) {
1716 return false;
1717 }
1718
1719 // Get GET data
1720 $type = stripslashes($_GET['post_type']);
1721
1722 if ( isset($_POST['update_mass']) ) {
1723 // origination and intention
1724 if ( ! ( wp_verify_nonce($_POST['secure_mass'], 'st_mass_tags') ) ) {
1725 $this->message = __('Security problem. Try again. If this problem persist, contact <a href="mailto:amaury@wordpress-fr.net">plugin author</a>.', 'simpletags');
1726 $this->status = 'error';
1727 return false;
1728 }
1729
1730 if ( isset($_POST['tags']) ) {
1731 $counter = 0;
1732 foreach ( (array) $_POST['tags'] as $object_id => $tag_list ) {
1733 // Trim data
1734 $tag_list = trim(stripslashes($tag_list));
1735
1736 // String to array
1737 $tags = explode( ',', $tag_list );
1738
1739 // Remove empty and trim tag
1740 $tags = array_filter($tags, array(&$this, 'deleteEmptyElement'));
1741
1742 // Add new tag (no append ! replace !)
1743 wp_set_object_terms( $object_id, $tags, 'post_tag' );
1744 $counter++;
1745
1746 // Clean cache
1747 if ( 'page' == $type ) {
1748 clean_page_cache($object_id);
1749 } else {
1750 clean_post_cache($object_id);
1751 }
1752 }
1753
1754 if ( $type == 'page' ) {
1755 $this->message = sprintf(__('%s page(s) tags updated with success !', 'simpletags'), (int) $counter);
1756 } else {
1757 $this->message = sprintf(__('%s post(s) tags updated with success !', 'simpletags'), (int) $counter);
1758 }
1759 return true;
1760 }
1761 }
1762 return false;
1763 }
1764
1765 ############## WP Options ##############
1766 /**
1767 * Update an option value -- note that this will NOT save the options.
1768 *
1769 * @param string $optname
1770 * @param string $optval
1771 */
1772 function setOption($optname, $optval) {
1773 $this->options[$optname] = $optval;
1774 }
1775
1776 /**
1777 * Save all current options
1778 *
1779 */
1780 function saveOptions() {
1781 update_option($this->db_options, $this->options);
1782 }
1783
1784 /**
1785 * Reset to default options
1786 *
1787 */
1788 function resetToDefaultOptions() {
1789 update_option($this->db_options, $this->default_options);
1790 $this->options = $this->default_options;
1791 }
1792
1793 ############## Ajax ##############
1794 /**
1795 * Ajax Dispatcher
1796 *
1797 */
1798 function ajaxCheck() {
1799 if ( $_GET['st_ajax_action'] == 'get_tags' ) {
1800 $this->ajaxListTags();
1801 } elseif ( $_GET['st_ajax_action'] == 'tags_from_yahoo' ) {
1802 $this->ajaxYahooTermExtraction();
1803 } elseif ( $_GET['st_ajax_action'] == 'tags_from_tagthenet' ) {
1804 $this->ajaxTagTheNet();
1805 } elseif ( $_GET['st_ajax_action'] == 'helper_js_collection' ) {
1806 $this->ajaxLocalTags( 'js_collection' );
1807 } elseif ( $_GET['st_ajax_action'] == 'tags_from_local_db' ) {
1808 $this->ajaxSuggestLocal();
1809 } elseif ( $_GET['st_ajax_action'] == 'click_tags' ) {
1810 $this->ajaxLocalTags( 'html_span' );
1811 }
1812 }
1813
1814 /**
1815 * Get tags list for manage tags page.
1816 *
1817 */
1818 function ajaxListTags() {
1819 status_header( 200 );
1820 header("Content-Type: text/javascript; charset=" . get_bloginfo('charset'));
1821
1822 // Build param for tags
1823 $sort_order = attribute_escape(stripslashes($_GET['order']));
1824 switch ($sort_order) {
1825 case 'natural' :
1826 $param = 'hide_empty=false&cloud_selection=name-asc';
1827 break;
1828 case 'asc' :
1829 $param = 'hide_empty=false&cloud_selection=count-asc';
1830 break;
1831 default :
1832 $param = 'hide_empty=false&cloud_selection=count-desc';
1833 break;
1834 }
1835
1836 // Build pagination
1837 $current_page = (int) $_GET['pagination'];
1838 $param .= '&number=LIMIT '. $current_page * $this->nb_tags . ', '.$this->nb_tags;
1839
1840 // Get tags
1841 global $simple_tags;
1842 $tags = $simple_tags->getTags($param, true, 'post_tag', true);
1843
1844 // Build output
1845 echo '<ul class="ajax_list">';
1846 foreach( (array) $tags as $tag ) {
1847 echo '<li><span>'.$tag->name.'</span>&nbsp;<a href="'.(get_tag_link( $tag->term_id )).'" title="'.sprintf(__('View all posts tagged with %s', 'simpletags'), $tag->name).'">('.$tag->count.')</a></li>'."\n";
1848 }
1849 unset($tags);
1850 echo '</ul>';
1851
1852 // Build pagination
1853 $ajax_url = $this->info['siteurl']. '/wp-admin/admin.php?st_ajax_action=get_tags';
1854
1855 // Order
1856 if ( isset($_GET['order']) ) {
1857 $ajax_url = $ajax_url . '&amp;order='.$sort_order ;
1858 }
1859 ?>
1860 <div class="navigation">
1861 <?php if ( ($current_page * $this->nb_tags) + $this->nb_tags > ((int) wp_count_terms('post_tag', 'ignore_empty=true')) ) : ?>
1862 <?php _e('Previous tags', 'simpletags'); ?>
1863 <?php else : ?>
1864 <a href="<?php echo $ajax_url. '&amp;pagination='. ($current_page + 1); ?>"><?php _e('Previous tags', 'simpletags'); ?></a>
1865 <?php endif; ?>
1866 |
1867 <?php if ( $current_page == 0 ) : ?>
1868 <?php _e('Next tags', 'simpletags'); ?>
1869 <?php else : ?>
1870 <a href="<?php echo $ajax_url. '&amp;pagination='. ($current_page - 1) ?>"><?php _e('Next tags', 'simpletags'); ?></a>
1871 <?php endif; ?>
1872 </div>
1873 <?php
1874 exit();
1875 }
1876
1877 /**
1878 * Suggest tags from Yahoo Term Extraction
1879 *
1880 */
1881 function ajaxYahooTermExtraction() {
1882 status_header( 200 );
1883 header("Content-Type: text/javascript; charset=" . get_bloginfo('charset'));
1884
1885 // Get data
1886 $content = stripslashes($_POST['content']) .' '. stripslashes($_POST['title']);
1887 $content = trim($content);
1888 if ( empty($content) ) {
1889 echo '<p>'.__('No text was sent.', 'simpletags').'</p>';
1890 exit();
1891 }
1892
1893 // Application entrypoint -> http://code.google.com/p/simple-tags/
1894 // Yahoo ID : h4c6gyLV34Fs7nHCrHUew7XDAU8YeQ_PpZVrzgAGih2mU12F0cI.ezr6e7FMvskR7Vu.AA--
1895 $yahoo_id = 'h4c6gyLV34Fs7nHCrHUew7XDAU8YeQ_PpZVrzgAGih2mU12F0cI.ezr6e7FMvskR7Vu.AA--';
1896
1897 // Build params
1898 $param = 'appid='.$yahoo_id; // Yahoo ID
1899 $param .= '&context='.urlencode($content); // Post content
1900 if ( !empty($_POST['tags']) ) {
1901 $param .= '&query='.urlencode(stripslashes($_POST['tags'])); // Existing tags
1902 }
1903 $param .= '&output=php'; // Get PHP Array !
1904
1905 $data = array();
1906 $reponse = wp_remote_post( 'http://search.yahooapis.com/ContentAnalysisService/V1/termExtraction?'.$param );
1907 if( !is_wp_error($reponse) && $reponse != null ) {
1908 $code = wp_remote_retrieve_response_code($reponse);
1909 if ( $code == 200 ) {
1910 $data = maybe_unserialize( wp_remote_retrieve_body($reponse) );
1911 }
1912 }
1913
1914 if ( empty($data) || empty($data['ResultSet']) || is_wp_error($data) ) {
1915 echo '<p>'.__('No results from Yahoo! service.', 'simpletags').'</p>';
1916 exit();
1917 }
1918
1919 // Get result value
1920 $data = (array) $data['ResultSet']['Result'];
1921
1922 // Remove empty terms
1923 $data = array_filter($data, array(&$this, 'deleteEmptyElement'));
1924 $data = array_unique($data);
1925
1926 foreach ( (array) $data as $term ) {
1927 echo '<span class="yahoo">'.$term.'</span>'."\n";
1928 }
1929 echo '<div class="clear"></div>';
1930 exit();
1931 }
1932
1933 /**
1934 * Suggest tags from Tag The Net
1935 *
1936 */
1937 function ajaxTagTheNet() {
1938 // Send good header HTTP
1939 status_header( 200 );
1940 header("Content-Type: text/javascript; charset=" . get_bloginfo('charset'));
1941
1942 // Get data
1943 $content = stripslashes($_POST['content']) .' '. stripslashes($_POST['title']);
1944 $content = trim($content);
1945 if ( empty($content) ) {
1946 echo '<p>'.__('No text was sent.', 'simpletags').'</p>';
1947 exit();
1948 }
1949
1950 $data = '';
1951 $reponse = wp_remote_post( 'http://tagthe.net/api/?text='.urlencode($content).'&view=json&count=200' );
1952 if( !is_wp_error($reponse) ) {
1953 $code = wp_remote_retrieve_response_code($reponse);
1954 if ( $code == 200 ) {
1955 $data = maybe_unserialize( wp_remote_retrieve_body($reponse) );
1956 }
1957 }
1958
1959 require_once( dirname(__FILE__) . '/class/JSON.php' );
1960 $data = json_decode($data);
1961 $data = $data->memes[0];
1962 $data = $data->dimensions;
1963
1964 if ( !isset($data->topic) && !isset($data->location) && !isset($data->person) ) {
1965 echo '<p>'.__('No results from Tag The Net service.', 'simpletags').'</p>';
1966 exit();
1967 }
1968
1969 $terms = array();
1970 // Get all topics
1971 foreach ( (array) $data->topic as $topic ) {
1972 $terms[] = '<span class="ttn_topic">'.$topic.'</span>';
1973 }
1974
1975 // Get all locations
1976 foreach ( (array) $data->location as $location ) {
1977 $terms[] = '<span class="ttn_location">'.$location.'</span>';
1978 }
1979
1980 // Get all persons
1981 foreach ( (array) $data->person as $person ) {
1982 $terms[] = '<span class="ttn_person">'.$person.'</span>';
1983 }
1984
1985 // Remove empty terms
1986 $terms = array_filter($terms, array(&$this, 'deleteEmptyElement'));
1987 $terms = array_unique($terms);
1988
1989 echo implode("\n", $terms);
1990 echo '<div class="clear"></div>';
1991 exit();
1992 }
1993
1994 /**
1995 * Suggest tags from local database
1996 *
1997 */
1998 function ajaxSuggestLocal() {
1999 // Send good header HTTP
2000 status_header( 200 );
2001 header("Content-Type: text/javascript; charset=" . get_bloginfo('charset'));
2002
2003 if ( ((int) wp_count_terms('post_tag', 'ignore_empty=true')) == 0) { // No tags to suggest
2004 echo '<p>'.__('No tags in your WordPress database.', 'simpletags').'</p>';
2005 exit();
2006 }
2007
2008 // Get data
2009 $content = stripslashes($_POST['content']) .' '. stripslashes($_POST['title']);
2010 $content = trim($content);
2011
2012 if ( empty($content) ) {
2013 echo '<p>'.__('No text was sent.', 'simpletags').'</p>';
2014 exit();
2015 }
2016
2017 // Get all terms
2018 global $wpdb;
2019 $terms = $this->getAllTerms();
2020
2021 if ( empty($terms) || $terms == false ) {
2022 echo '<p>'.__('No results from your WordPress database.', 'simpletags').'</p>';
2023 exit();
2024 }
2025
2026 $terms = array_unique($terms);
2027 foreach ( (array) $terms as $term ) {
2028 $term = stripslashes($term);
2029 if ( is_string($term) && !empty($term) && stristr($content, $term) ) {
2030 echo '<span class="local">'.$term.'</span>'."\n";
2031 }
2032 }
2033
2034 echo '<div class="clear"></div>';
2035 exit();
2036 }
2037
2038 /**
2039 * Display a span list for click tags or a javascript collection for autocompletion script !
2040 *
2041 * @param string $format
2042 */
2043 function ajaxLocalTags( $format = 'html_span' ) {
2044 // Send good header HTTP
2045 status_header( 200 );
2046 header("Content-Type: text/javascript; charset=" . get_bloginfo('charset'));
2047
2048 if ((int) wp_count_terms('post_tag', 'ignore_empty=true') == 0 ) { // No tags to suggest
2049 if ( $format == 'html_span' ) {
2050 echo '<p>'.__('No tags in your WordPress database.', 'simpletags').'</p>';
2051 } else {
2052 echo 'collection = [ ];';
2053 }
2054 exit();
2055 }
2056
2057 // Get all terms
2058 $terms = $this->getAllTerms();
2059 if ( empty($terms) || $terms == false ) {
2060 if ( $format == 'html_span' ) {
2061 echo '<p>'.__('No results from your WordPress database.', 'simpletags').'</p>';
2062 } else {
2063 echo 'collection = [ ];';
2064 }
2065 exit();
2066 }
2067
2068 // Remove duplicate
2069 $terms = array_unique($terms);
2070
2071 switch ($format) {
2072 case 'html_span' :
2073
2074 foreach ( (array) $terms as $term ) {
2075 $term = stripslashes($term);
2076 echo '<span class="local">'.$term.'</span>'."\n";
2077 }
2078 echo '<div class="clear"></div>';
2079 break;
2080
2081 case 'js_collection' :
2082 default:
2083
2084 echo 'collection = [';
2085 $flag = false;
2086 foreach ( (array) $terms as $term ) {
2087
2088 // Clean up tags
2089 $term = stripslashes($term);
2090 $term = str_replace( "\r\n", '', $term );
2091 $term = str_replace( "\r", '', $term );
2092 $term = str_replace( "\n", '', $term );
2093
2094 if ( $flag === false) {
2095 echo '"'.str_replace('"', '\"', $term).'"';
2096 $flag = true;
2097 } else {
2098 echo ', "'.str_replace('"', '\"', $term).'"';
2099 }
2100 }
2101 echo '];';
2102 break;
2103
2104 }
2105
2106 exit();
2107 }
2108
2109 function getAllTerms() {
2110 global $wpdb;
2111 return $wpdb->get_col("
2112 SELECT DISTINCT name
2113 FROM {$wpdb->terms} AS t
2114 INNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id
2115 WHERE tt.taxonomy = 'post_tag'
2116 ");
2117 }
2118
2119 ############## Admin WP Helper ##############
2120 /**
2121 * Display plugin Copyright
2122 *
2123 */
2124 function printAdminFooter() {
2125 ?>
2126 <p class="footer_st"><?php printf(__('&copy; Copyright 2008 <a href="http://www.herewithme.fr/" title="Here With Me">Amaury Balmer</a> | <a href="http://wordpress.org/extend/plugins/simple-tags">Simple Tags</a> | Version %s', 'simpletags'), $this->version); ?></p>
2127 <?php
2128 }
2129
2130 /**
2131 * Display WP alert
2132 *
2133 */
2134 function displayMessage() {
2135 if ( $this->message != '') {
2136 $message = $this->message;
2137 $status = $this->status;
2138 $this->message = $this->status = ''; // Reset
2139 }
2140
2141 if ( $message ) {
2142 ?>
2143 <div id="message" class="<?php echo ($status != '') ? $status :'updated'; ?> fade">
2144 <p><strong><?php echo $message; ?></strong></p>
2145 </div>
2146 <?php
2147 }
2148 }
2149
2150 /**
2151 * Ouput formatted options
2152 *
2153 * @param array $option_data
2154 * @return string
2155 */
2156 function printOptions( $option_data ) {
2157 // Get actual options
2158 $option_actual = (array) $this->options;
2159
2160 // Generate output
2161 $output = '';
2162 foreach( $option_data as $section => $options) {
2163 $output .= "\n" . '<div id="'. sanitize_title($section) .'"><fieldset class="options"><legend>' . $this->getNiceTitleOptions($section) . '</legend><table class="form-table">' . "\n";
2164 foreach((array) $options as $option) {
2165 // Helper
2166 if ( $option[2] == 'helper' ) {
2167 $output .= '<tr style="vertical-align: middle;"><td class="helper" colspan="2">' . $option[4] . '</td></tr>' . "\n";
2168 continue;
2169 }
2170
2171 switch ( $option[2] ) {
2172 case 'checkbox':
2173 $input_type = '<input type="checkbox" id="' . $option[0] . '" name="' . $option[0] . '" value="' . htmlspecialchars($option[3]) . '" ' . ( ($option_actual[ $option[0] ]) ? 'checked="checked"' : '') . ' />' . "\n";
2174 break;
2175
2176 case 'dropdown':
2177 $selopts = explode('/', $option[3]);
2178 $seldata = '';
2179 foreach( (array) $selopts as $sel) {
2180 $seldata .= '<option value="' . $sel . '" ' .(($option_actual[ $option[0] ] == $sel) ? 'selected="selected"' : '') .' >' . ucfirst($sel) . '</option>' . "\n";
2181 }
2182 $input_type = '<select id="' . $option[0] . '" name="' . $option[0] . '">' . $seldata . '</select>' . "\n";
2183 break;
2184
2185 case 'text-color':
2186 $input_type = '<input type="text" ' . (($option[3]>50) ? ' style="width: 95%" ' : '') . 'id="' . $option[0] . '" name="' . $option[0] . '" value="' . htmlspecialchars($option_actual[ $option[0] ]) . '" size="' . $option[3] .'" /><div class="box_color ' . $option[0] . '"></div>' . "\n";
2187 break;
2188
2189 case 'text':
2190 default:
2191 $input_type = '<input type="text" ' . (($option[3]>50) ? ' style="width: 95%" ' : '') . 'id="' . $option[0] . '" name="' . $option[0] . '" value="' . htmlspecialchars($option_actual[ $option[0] ]) . '" size="' . $option[3] .'" />' . "\n";
2192 break;
2193 }
2194
2195 // Additional Information
2196 $extra = '';
2197 if( !empty($option[4]) ) {
2198 $extra = '<div class="stpexplan">' . __($option[4]) . '</div>' . "\n";
2199 }
2200
2201 // Output
2202 $output .= '<tr style="vertical-align: top;"><th scope="row"><label for="'.$option[0].'">' . __($option[1]) . '</label></th><td>' . $input_type . ' ' . $extra . '</td></tr>' . "\n";
2203 }
2204 $output .= '</table>' . "\n";
2205 $output .= '</fieldset></div>' . "\n";
2206 }
2207 return $output;
2208 }
2209
2210 /**
2211 * Get nice title for tabs title option
2212 *
2213 * @param string $id
2214 * @return string
2215 */
2216 function getNiceTitleOptions( $id = '' ) {
2217 switch ( $id ) {
2218 case 'administration':
2219 return __('Administration', 'simpletags');
2220 break;
2221 case 'auto-links':
2222 return __('Auto link', 'simpletags');
2223 break;
2224 case 'general':
2225 return __('General', 'simpletags');
2226 break;
2227 case 'metakeywords':
2228 return __('Meta Keyword', 'simpletags');
2229 break;
2230 case 'embeddedtags':
2231 return __('Embedded Tags', 'simpletags');
2232 break;
2233 case 'tagspost':
2234 return __('Tags for Current Post', 'simpletags');
2235 break;
2236 case 'relatedposts':
2237 return __('Related Posts', 'simpletags');
2238 break;
2239 case 'relatedtags':
2240 return __('Related Tags', 'simpletags');
2241 break;
2242 case 'tagcloud':
2243 return __('Tag cloud', 'simpletags');
2244 break;
2245 }
2246 return '';
2247 }
2248
2249 /**
2250 * Escape string so that it can used in Regex. E.g. used for [tags]...[/tags]
2251 *
2252 * @param string $content
2253 * @return string
2254 */
2255 function regexEscape( $content ) {
2256 return strtr($content, array("\\" => "\\\\", "/" => "\\/", "[" => "\\[", "]" => "\\]"));
2257 }
2258
2259 /**
2260 * Add initial ST options in DB
2261 *
2262 */
2263 function installSimpleTags() {
2264 $options_from_table = get_option( $this->db_options );
2265 if ( !$options_from_table ) {
2266 $this->resetToDefaultOptions();
2267 }
2268 }
2269
2270 /**
2271 * Remove ST options when user delete plugin (use WP API Uninstall)
2272 *
2273 */
2274 function uninstall() {
2275 delete_option($this->db_options, $this->default_options);
2276 delete_option('widget_stags_cloud');
2277 }
2278}
2279
2280// Future of WP ?
2281if ( !function_exists('add_filters') ) :
2282function add_filters($tags, $function_to_add, $priority = 10, $accepted_args = 1) {
2283 if ( is_array($tags) ) {
2284 foreach ( (array) $tags as $tag ) {
2285 add_filter($tag, $function_to_add, $priority, $accepted_args);
2286 }
2287 return true;
2288 } else {
2289 return add_filter($tags, $function_to_add, $priority, $accepted_args);
2290 }
2291}
2292endif;
2293
2294if ( !function_exists('add_actions') ) :
2295function add_actions($tags, $function_to_add, $priority = 10, $accepted_args = 1) {
2296 return add_filters($tags, $function_to_add, $priority, $accepted_args);
2297}
2298endif;
2299?>
Note: See TracBrowser for help on using the repository browser.