SEO Smart Links - Version 1.3

Version Description

Download this release

Release Info

Developer freediver
Plugin Icon 128x128 SEO Smart Links
Version 1.3
Comparing to
See all releases

Code changes from version 1.2 to 1.3

Files changed (2) hide show
  1. readme.txt +8 -0
  2. seo-links.php +42 -10
readme.txt CHANGED
@@ -19,6 +19,14 @@ It also give your visitors an opportunity to visit other sections of your site t
19
  Everything happens completely transparent, and you can edit the options from the administration settings panel.
20
 
21
 
 
 
 
 
 
 
 
 
22
  v1.2:
23
  - Added limits options
24
  - Fixed small bugs
19
  Everything happens completely transparent, and you can edit the options from the administration settings panel.
20
 
21
 
22
+ v1.3:
23
+ - Enabled caching for speeding queries up. Make sure you have
24
+ define(ENABLE_CACHE, true);
25
+
26
+ set in your wp-config.php
27
+
28
+
29
+
30
  v1.2:
31
  - Added limits options
32
  - Fixed small bugs
seo-links.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  /*
4
  Plugin Name: SEO Smart Links
5
- Version: 1.2
6
  Plugin URI: http://www.prelovac.com/vladimir/wordpress-plugins/seo-smart-links
7
  Author: Vladimir Prelovac
8
  Author URI: http://www.prelovac.com
@@ -31,6 +31,11 @@ class SEOLinks {
31
  if ($options['comment'])
32
  add_filter('comment_text', array(&$this, 'SEOLinks_comment_text_filter'), 10);
33
  }
 
 
 
 
 
34
  // Add Options Page
35
  add_action('admin_menu', array(&$this, 'SEOLinks_admin_menu'));
36
 
@@ -76,9 +81,14 @@ $text = " $text ";
76
 
77
  if ($options['lposts'] || $options['lpages'])
78
  {
79
-
80
- $query="SELECT post_title, ID, guid, post_type FROM $wpdb->posts WHERE post_status = 'publish'";
81
- $posts = $wpdb->get_results($query);
 
 
 
 
 
82
 
83
  foreach ($posts as $postitem)
84
  {
@@ -110,8 +120,14 @@ if ($options['lposts'] || $options['lpages'])
110
 
111
  if ($options['lcats'])
112
  {
113
- $query="SELECT wp_terms.name, wp_terms.term_id FROM wp_terms LEFT JOIN wp_term_taxonomy ON wp_terms.term_id = wp_term_taxonomy.term_id WHERE wp_term_taxonomy.taxonomy = 'category'";
114
- $categories = $wpdb->get_results($query);
 
 
 
 
 
 
115
  foreach ($categories as $cat)
116
  {
117
  $name= preg_quote($cat->name, '/');
@@ -138,8 +154,14 @@ if ($options['lcats'])
138
  if ($options['ltags'])
139
  {
140
 
141
- $query="SELECT wp_terms.name, wp_terms.term_id FROM wp_terms LEFT JOIN wp_term_taxonomy ON wp_terms.term_id = wp_term_taxonomy.term_id WHERE wp_term_taxonomy.taxonomy = 'post_tag'";
142
- $tags = $wpdb->get_results($query);
 
 
 
 
 
 
143
  foreach ($tags as $tag)
144
  {
145
  $name = preg_quote($tag->name, '/');
@@ -252,6 +274,7 @@ function explode_trim($separator, $text)
252
 
253
 
254
  update_option($this->SEOLinks_DB_option, $options);
 
255
  echo '<div class="updated fade"><p>Plugin settings saved.</p></div>';
256
  }
257
 
@@ -317,8 +340,8 @@ function explode_trim($separator, $text)
317
  <p>Select automatic link targets.</p>
318
  <input type="checkbox" name="lposts" $lposts /><label for="lposts"> Posts</label> <br>
319
  <input type="checkbox" name="lpages" $lpages /><label for="lpages"> Pages</label> <br>
320
- <input type="checkbox" name="lcats" $lcats /><label for="lcats"> Categories</label> <br>
321
- <input type="checkbox" name="ltags" $ltags /><label for="ltags"> Tags</label> <br>
322
 
323
  <h4>Ignore</h4>
324
  <p>You may wish to ignore certain words or phrases. Seperate them by comma.</p>
@@ -352,6 +375,15 @@ END;
352
  add_options_page('SEO Smart Links Options', 'SEO Smart Links', 8, basename(__FILE__), array(&$this, 'handle_options'));
353
  }
354
 
 
 
 
 
 
 
 
 
 
355
  }
356
 
357
  endif;
2
 
3
  /*
4
  Plugin Name: SEO Smart Links
5
+ Version: 1.3
6
  Plugin URI: http://www.prelovac.com/vladimir/wordpress-plugins/seo-smart-links
7
  Author: Vladimir Prelovac
8
  Author URI: http://www.prelovac.com
31
  if ($options['comment'])
32
  add_filter('comment_text', array(&$this, 'SEOLinks_comment_text_filter'), 10);
33
  }
34
+
35
+ add_action( 'create_category', array(&$this, 'SEOLinks_delete_cache'));
36
+ add_action( 'edit_category', array(&$this,'SEOLinks_delete_cache'));
37
+ add_action( 'edit_post', array(&$this,'SEOLinks_delete_cache'));
38
+ add_action( 'save_post', array(&$this,'SEOLinks_delete_cache'));
39
  // Add Options Page
40
  add_action('admin_menu', array(&$this, 'SEOLinks_admin_menu'));
41
 
81
 
82
  if ($options['lposts'] || $options['lpages'])
83
  {
84
+ if ( !$posts = wp_cache_get( 'seo-links-posts', 'seo-smart-links' ) ) {
85
+
86
+ $query="SELECT post_title, ID, guid, post_type FROM $wpdb->posts WHERE post_status = 'publish'";
87
+ $posts = $wpdb->get_results($query);
88
+
89
+ wp_cache_add( 'seo-links-posts', $posts, 'seo-smart-links',86400 );
90
+ }
91
+
92
 
93
  foreach ($posts as $postitem)
94
  {
120
 
121
  if ($options['lcats'])
122
  {
123
+ if ( !$categories = wp_cache_get( 'seo-links-categories', 'seo-smart-links' ) ) {
124
+
125
+ $query="SELECT wp_terms.name, wp_terms.term_id FROM wp_terms LEFT JOIN wp_term_taxonomy ON wp_terms.term_id = wp_term_taxonomy.term_id WHERE wp_term_taxonomy.taxonomy = 'category'";
126
+ $categories = $wpdb->get_results($query);
127
+
128
+ wp_cache_add( 'seo-links-categories', $categories, 'seo-smart-links',86400 );
129
+ }
130
+
131
  foreach ($categories as $cat)
132
  {
133
  $name= preg_quote($cat->name, '/');
154
  if ($options['ltags'])
155
  {
156
 
157
+ if ( !$tags = wp_cache_get( 'seo-links-tags', 'seo-smart-links' ) ) {
158
+
159
+ $query="SELECT wp_terms.name, wp_terms.term_id FROM wp_terms LEFT JOIN wp_term_taxonomy ON wp_terms.term_id = wp_term_taxonomy.term_id WHERE wp_term_taxonomy.taxonomy = 'post_tag'";
160
+ $tags = $wpdb->get_results($query);
161
+
162
+ wp_cache_add( 'seo-links-tags', $tags, 'seo-smart-links',86400 );
163
+ }
164
+
165
  foreach ($tags as $tag)
166
  {
167
  $name = preg_quote($tag->name, '/');
274
 
275
 
276
  update_option($this->SEOLinks_DB_option, $options);
277
+ $this->SEOLinks_delete_cache(0);
278
  echo '<div class="updated fade"><p>Plugin settings saved.</p></div>';
279
  }
280
 
340
  <p>Select automatic link targets.</p>
341
  <input type="checkbox" name="lposts" $lposts /><label for="lposts"> Posts</label> <br>
342
  <input type="checkbox" name="lpages" $lpages /><label for="lpages"> Pages</label> <br>
343
+ <input type="checkbox" name="lcats" $lcats /><label for="lcats"> Categories (can slow down big sites)</label> <br>
344
+ <input type="checkbox" name="ltags" $ltags /><label for="ltags"> Tags (can slow down big sites)</label> <br>
345
 
346
  <h4>Ignore</h4>
347
  <p>You may wish to ignore certain words or phrases. Seperate them by comma.</p>
375
  add_options_page('SEO Smart Links Options', 'SEO Smart Links', 8, basename(__FILE__), array(&$this, 'handle_options'));
376
  }
377
 
378
+ function SEOLinks_delete_cache($id) {
379
+ wp_cache_delete( 'seo-links-categories', 'seo-smart-links' );
380
+ wp_cache_delete( 'seo-links-tags', 'seo-smart-links' );
381
+ wp_cache_delete( 'seo-links-posts', 'seo-smart-links' );
382
+ }
383
+ //add_action( 'comment_post', 'SEOLinks_delete_cache');
384
+ //add_action( 'wp_set_comment_status', 'SEOLinks_delete_cache');
385
+
386
+
387
  }
388
 
389
  endif;