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

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