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