Yet Another Related Posts Plugin (YARPP) - Version 3.4b6

Version Description

Download this release

Release Info

Developer mitchoyoshitaka
Plugin Icon 128x128 Yet Another Related Posts Plugin (YARPP)
Version 3.4b6
Comparing to
See all releases

Code changes from version 3.4b5 to 3.4b6

cache-postmeta.php CHANGED
@@ -15,8 +15,6 @@ class YARPP_Cache_Postmeta {
15
16
private $yarpp_time = false;
17
public $demo_time = false;
18
- public $score_override = false;
19
- public $online_limit = false;
20
21
/**
22
* SETUP/STATUS
@@ -28,6 +26,8 @@ class YARPP_Cache_Postmeta {
28
add_filter('posts_fields',array(&$this,'fields_filter'));
29
add_filter('posts_request',array(&$this,'demo_request_filter'));
30
add_filter('post_limits',array(&$this,'limit_filter'));
31
}
32
33
public function is_enabled() {
15
16
private $yarpp_time = false;
17
public $demo_time = false;
18
19
/**
20
* SETUP/STATUS
26
add_filter('posts_fields',array(&$this,'fields_filter'));
27
add_filter('posts_request',array(&$this,'demo_request_filter'));
28
add_filter('post_limits',array(&$this,'limit_filter'));
29
+ // sets the score override flag.
30
+ add_action('parse_query',array(&$this,'set_score_override_flag'));
31
}
32
33
public function is_enabled() {
cache-tables.php CHANGED
@@ -9,8 +9,6 @@ class YARPP_Cache_Tables extends YARPP_Cache {
9
public $name = "custom tables";
10
private $yarpp_time = false;
11
public $demo_time = false;
12
- public $score_override = false; // @todo: should be private
13
- public $online_limit = false; // @todo: should be private
14
15
/**
16
* SETUP/STATUS
@@ -23,6 +21,8 @@ class YARPP_Cache_Tables extends YARPP_Cache {
23
add_filter('posts_fields',array(&$this,'fields_filter'));
24
add_filter('posts_request',array(&$this,'demo_request_filter'));
25
add_filter('post_limits',array(&$this,'limit_filter'));
26
}
27
28
public function is_enabled() {
9
public $name = "custom tables";
10
private $yarpp_time = false;
11
public $demo_time = false;
12
13
/**
14
* SETUP/STATUS
21
add_filter('posts_fields',array(&$this,'fields_filter'));
22
add_filter('posts_request',array(&$this,'demo_request_filter'));
23
add_filter('post_limits',array(&$this,'limit_filter'));
24
+ // sets the score override flag.
25
+ add_action('parse_query',array(&$this,'set_score_override_flag'));
26
}
27
28
public function is_enabled() {
class-admin.php ADDED
@@ -0,0 +1,71 @@
1
+ <?php
2
+
3
+ class YARPP_Admin {
4
+ public $core;
5
+ public $hook;
6
+
7
+ function __construct( &$core ) {
8
+ $this->core = &$core;
9
+
10
+ add_action( 'admin_menu', array( $this, 'register' ) );
11
+ // new in 3.3: set default meta boxes to show:
12
+ add_filter( 'default_hidden_meta_boxes', array( $this, 'default_hidden_meta_boxes' ), 10, 2 );
13
+ }
14
+
15
+ function register() {
16
+ // setup admin
17
+ $this->hook = add_options_page(__('Related Posts (YARPP)','yarpp'),__('Related Posts (YARPP)','yarpp'), 'manage_options', 'yarpp', array( $this, 'options_page' ) );
18
+ // new in 3.3: load options page sections as metaboxes
19
+ require_once('options-meta-boxes.php');
20
+
21
+ // new in 3.0.12: add settings link to the plugins page
22
+ add_filter('plugin_action_links', array( $this, 'settings_link' ), 10, 2);
23
+
24
+ // new in 3.0: add meta box
25
+ add_meta_box( 'yarpp_relatedposts', __( 'Related Posts' , 'yarpp') . ' <span class="postbox-title-action"><a href="' . esc_url( admin_url('options-general.php?page=yarpp') ) . '" class="edit-box open-box">' . __( 'Configure' ) . '</a></span>', array( $this, 'metabox' ), 'post', 'normal' );
26
+
27
+ // new in 3.3: properly enqueue scripts for admin:
28
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
29
+ }
30
+
31
+ // since 3.3
32
+ function enqueue() {
33
+ global $current_screen;
34
+ if (is_object($current_screen) && $current_screen->id == 'settings_page_yarpp') {
35
+ wp_enqueue_script( 'postbox' );
36
+ wp_enqueue_style( 'yarpp_options', plugins_url( 'options.css', __FILE__ ), array(), YARPP_VERSION );
37
+ wp_enqueue_script( 'yarpp_options', plugins_url( 'options.js', __FILE__ ), array('jquery'), YARPP_VERSION );
38
+ // wp_enqueue_script( 'thickbox' );
39
+ // wp_enqueue_style( 'thickbox' );
40
+ }
41
+ }
42
+
43
+ function settings_link($links, $file) {
44
+ $this_plugin = dirname(plugin_basename(__FILE__)) . '/yarpp.php';
45
+ if($file == $this_plugin) {
46
+ $links[] = '<a href="options-general.php?page=yarpp">' . __('Settings', 'yarpp') . '</a>';
47
+ }
48
+ return $links;
49
+ }
50
+
51
+ function options_page() {
52
+ // for proper metabox support:
53
+ require(YARPP_DIR.'/options.php');
54
+ }
55
+
56
+ function metabox() {
57
+ echo '<style>#yarpp_relatedposts h3 .postbox-title-action { right: 30px; top: 5px; position: absolute; padding: 0 }</style><div id="yarpp-related-posts">';
58
+ if ( get_the_ID() )
59
+ yarpp_related(array('post'),array('limit'=>1000),true,false,'metabox');
60
+ else
61
+ echo "<p>".__("Related entries may be displayed once you save your entry",'yarpp').".</p>";
62
+ echo '</div>';
63
+ }
64
+
65
+ // since 3.3: default metaboxes to show:
66
+ function default_hidden_meta_boxes($hidden, $screen) {
67
+ if ( 'settings_page_yarpp' == $screen->id )
68
+ $hidden = array( 'yarpp_pool', 'yarpp_relatedness' );
69
+ return $hidden;
70
+ }
71
+ }
class-cache.php ADDED
@@ -0,0 +1,269 @@
1
+ <?php
2
+
3
+ abstract class YARPP_Cache {
4
+
5
+ public $core;
6
+ public $score_override = false;
7
+ public $online_limit = false;
8
+
9
+ function __construct( &$core ) {
10
+ $this->core = &$core;
11
+ $this->name = __($this->name, 'yarpp');
12
+ }
13
+
14
+ // Note: return value changed in 3.4
15
+ // return YARPP_NO_RELATED | YARPP_RELATED | YARPP_DONT_RUN | false if no good input
16
+ function enforce($reference_ID, $force = false) {
17
+ if ( !$reference_ID = absint($reference_ID) )
18
+ return false;
19
+
20
+ $status = $this->is_cached($reference_ID);
21
+ $status = apply_filters( 'yarpp_cache_enforce_status', $status, $reference_ID );
22
+
23
+ // There's a stop signal:
24
+ if ( YARPP_DONT_RUN === $status )
25
+ return YARPP_DONT_RUN;
26
+
27
+ // If not cached, process now:
28
+ if ( YARPP_NOT_CACHED == $status || $force ) {
29
+ $status = $this->update($reference_ID);
30
+ // if still not cached, there's a problem, but for the time being return NO RELATED
31
+ if ( YARPP_NOT_CACHED === $status )
32
+ return YARPP_NO_RELATED;
33
+ }
34
+
35
+ // There are no related posts
36
+ if ( YARPP_NO_RELATED === $status )
37
+ return YARPP_NO_RELATED;
38
+
39
+ // There are results
40
+ return YARPP_RELATED;
41
+ }
42
+
43
+ /*
44
+ * POST STATUS INTERACTIONS
45
+ */
46
+
47
+ function save_post($post_ID, $force=true) {
48
+ global $wpdb;
49
+
50
+ // new in 3.2: don't compute cache during import
51
+ if ( defined( 'WP_IMPORTING' ) )
52
+ return;
53
+
54
+ $sql = "select post_parent from $wpdb->posts where ID='$post_ID'";
55
+ $parent_ID = $wpdb->get_var($sql);
56
+
57
+ if ( $parent_ID != $post_ID && $parent_ID )
58
+ $post_ID = $parent_ID;
59
+
60
+ $this->enforce((int) $post_ID, $force);
61
+ }
62
+
63
+ // Clear the cache for this entry and for all posts which are "related" to it.
64
+ // New in 3.2: This is called when a post is deleted.
65
+ function delete_post($post_ID) {
66
+ // Clear the cache for this post.
67
+ $this->clear($post_ID);
68
+
69
+ // Find all "peers" which list this post as a related post.
70
+ $peers = $this->related(null, $post_ID);
71
+ // Clear the peers' caches.
72
+ $this->clear($peers);
73
+ }
74
+
75
+ // New in 3.2.1: handle various post_status transitions
76
+ function transition_post_status($new_status, $old_status, $post) {
77
+ switch ($new_status) {
78
+ case "draft":
79
+ $this->delete_post($post->ID);
80
+ break;
81
+ case "publish":
82
+ // find everything which is related to this post, and clear them, so that this
83
+ // post might show up as related to them.
84
+ $related = $this->related($post->ID, null);
85
+ $this->clear($related);
86
+ }
87
+ }
88
+
89
+ function set_score_override_flag($q) {
90
+ if ( $this->is_yarpp_time() ) {
91
+ $this->score_override = ($q->query_vars['orderby'] == 'score');
92
+
93
+ if (!empty($q->query_vars['showposts'])) {
94
+ $this->online_limit = $q->query_vars['showposts'];
95
+ } else {
96
+ $this->online_limit = false;
97
+ }
98
+ } else {
99
+ $this->score_override = false;
100
+ $this->online_limit = false;
101
+ }
102
+ }
103
+
104
+ /*
105
+ * KEYWORDS
106
+ */
107
+
108
+ public function title_keywords($ID,$max = 20) {
109
+ return $this->extract_keywords(get_the_title($ID),$max);
110
+ }
111
+
112
+ public function body_keywords( $ID, $max = 20 ) {
113
+ $post = get_post( $ID );
114
+ if ( empty($post) )
115
+ return '';
116
+ $content = $this->apply_filters_if_white( 'the_content', $post->post_content );
117
+ return $this->extract_keywords( $content, $max );
118
+ }
119
+
120
+ private function extract_keywords($html, $max = 20) {
121
+
122
+ $lang = 'en_US';
123
+ if ( defined('WPLANG') ) {
124
+ $lang = substr(WPLANG, 0, 2);
125
+ switch ( $lang ) {
126
+ case 'de':
127
+ $lang = 'de_DE';
128
+ case 'it':
129
+ $lang = 'it_IT';
130
+ case 'pl':
131
+ $lang = 'pl_PL';
132
+ case 'bg':
133
+ $lang = 'bg_BG';
134
+ case 'fr':
135
+ $lang = 'fr_FR';
136
+ case 'cs':
137
+ $lang = 'cs_CZ';
138
+ case 'nl':
139
+ $lang = 'nl_NL';
140
+ }
141
+ }
142
+
143
+ $words_file = YARPP_DIR . '/lang/words-' . $lang . '.php';
144
+ if ( file_exists($words_file) )
145
+ include( $words_file );
146
+ if ( !isset($overusedwords) )
147
+ $overusedwords = array();
148
+
149
+ // strip tags and html entities
150
+ $text = preg_replace('/&(#x[0-9a-f]+|#[0-9]+|[a-zA-Z]+);/', '', strip_tags($html) );
151
+
152
+ // 3.2.2: ignore soft hyphens
153
+ // Requires PHP 5: http://bugs.php.net/bug.php?id=25670
154
+ $softhyphen = html_entity_decode('&#173;',ENT_NOQUOTES,'UTF-8');
155
+ $text = str_replace($softhyphen, '', $text);
156
+
157
+ $charset = get_option('blog_charset');
158
+ if ( function_exists('mb_split') && !empty($charset) ) {
159
+ mb_regex_encoding($charset);
160
+ $wordlist = mb_split('\s*\W+\s*', mb_strtolower($text, $charset));
161
+ } else
162
+ $wordlist = preg_split('%\s*\W+\s*%', strtolower($text));
163
+
164
+ // Build an array of the unique words and number of times they occur.
165
+ $tokens = array_count_values($wordlist);
166
+
167
+ // Remove the stop words from the list.
168
+ $overusedwords = apply_filters( 'yarpp_keywords_overused_words', $overusedwords );
169
+ if ( is_array($overusedwords) ) {
170
+ foreach ($overusedwords as $word) {
171
+ unset($tokens[$word]);
172
+ }
173
+ }
174
+ // Remove words which are only a letter
175
+ $mb_strlen_exists = function_exists('mb_strlen');
176
+ foreach (array_keys($tokens) as $word) {
177
+ if ($mb_strlen_exists)
178
+ if (mb_strlen($word) < 2) unset($tokens[$word]);
179
+ else
180
+ if (strlen($word) < 2) unset($tokens[$word]);
181
+ }
182
+
183
+ arsort($tokens, SORT_NUMERIC);
184
+
185
+ $types = array_keys($tokens);
186
+
187
+ if (count($types) > $max)
188
+ $types = array_slice($types, 0, $max);
189
+ return implode(' ', $types);
190
+ }
191
+
192
+ /* new in 2.0! apply_filters_if_white (previously apply_filters_without) now has a blacklist.
193
+ * It can be modified via the yarpp_blacklist and yarpp_blackmethods filters.
194
+ */
195
+ /* blacklisted so far:
196
+ - diggZ-Et
197
+ - reddZ-Et
198
+ - dzoneZ-Et
199
+ - WP-Syntax
200
+ - Viper's Video Quicktags
201
+ - WP-CodeBox
202
+ - WP shortcodes
203
+ - WP Greet Box
204
+ //- Tweet This - could not reproduce problem.
205
+ */
206
+ function white( $filter ) {
207
+ static $blacklist, $blackmethods;
208
+
209
+ if ( is_null($blacklist) || is_null($blackmethods) ) {
210
+ $yarpp_blacklist = array('yarpp_default', 'diggZEt_AddBut', 'reddZEt_AddBut', 'dzoneZEt_AddBut', 'wp_syntax_before_filter', 'wp_syntax_after_filter', 'wp_codebox_before_filter', 'wp_codebox_after_filter', 'do_shortcode');//,'insert_tweet_this'
211
+ $yarpp_blackmethods = array('addinlinejs', 'replacebbcode', 'filter_content');
212
+
213
+ $blacklist = (array) apply_filters( 'yarpp_blacklist', $yarpp_blacklist );
214
+ $blackmethods = (array) apply_filters( 'yarpp_blackmethods', $yarpp_blackmethods );
215
+ }
216
+
217
+ if ( is_array($filter) && in_array( $filter[1], $blackmethods ) )
218
+ return false;
219
+ return !in_array( $filter, $blacklist );
220
+ }
221
+
222
+ /* FYI, apply_filters_if_white was used here to avoid a loop in apply_filters('the_content') > yarpp_default() > yarpp_related() > current_post_keywords() > apply_filters('the_content').*/
223
+ function apply_filters_if_white($tag, $value) {
224
+ global $wp_filter, $merged_filters, $wp_current_filter;
225
+
226
+ $args = array();
227
+
228
+ // Do 'all' actions first
229
+ if ( isset($wp_filter['all']) ) {
230
+ $wp_current_filter[] = $tag;
231
+ $args = func_get_args();
232
+ _wp_call_all_hook($args);
233
+ }
234
+
235
+ if ( !isset($wp_filter[$tag]) ) {
236
+ if ( isset($wp_filter['all']) )
237
+ array_pop($wp_current_filter);
238
+ return $value;
239
+ }
240
+
241
+ if ( !isset($wp_filter['all']) )
242
+ $wp_current_filter[] = $tag;
243
+
244
+ // Sort
245
+ if ( !isset( $merged_filters[ $tag ] ) ) {
246
+ ksort($wp_filter[$tag]);
247
+ $merged_filters[ $tag ] = true;
248
+ }
249
+
250
+ reset( $wp_filter[ $tag ] );
251
+
252
+ if ( empty($args) )
253
+ $args = func_get_args();
254
+
255
+ do {
256
+ foreach( (array) current($wp_filter[$tag]) as $the_ )
257
+ if ( !is_null($the_['function'])
258
+ and $this->white($the_['function'])){ // HACK
259
+ $args[1] = $value;
260
+ $value = call_user_func_array($the_['function'], array_slice($args, 1, (int) $the_['accepted_args']));
261
+ }
262
+
263
+ } while ( next($wp_filter[$tag]) !== false );
264
+
265
+ array_pop( $wp_current_filter );
266
+
267
+ return $value;
268
+ }
269
+ }
class-core.php ADDED
@@ -0,0 +1,291 @@
1
+ <?php
2
+
3
+ // new in 3.4: put everything YARPP into an object, expected to be a singleton global $yarpp
4
+ class YARPP {
5
+
6
+ public $debug = false;
7
+
8
+ public $cache;
9
+ public $admin;
10
+ private $storage_class;
11
+
12
+ function __construct() {
13
+ // register text domain
14
+ load_plugin_textdomain( 'yarpp', false, dirname(plugin_basename(__FILE__)) . '/lang' );
15
+
16
+ // load cache object
17
+ require_once(YARPP_DIR . '/class-cache.php');
18
+ require_once(YARPP_DIR . '/cache-' . YARPP_CACHE_TYPE . '.php');
19
+ $this->storage_class = $yarpp_storage_class;
20
+ $this->cache = new $this->storage_class( $this );
21
+
22
+ register_activation_hook( __FILE__, array($this, 'activate') );
23
+ add_action( 'admin_init', array($this, 'admin_init') );
24
+
25
+ // update cache on save
26
+ add_action( 'save_post', array($this->cache, 'save_post') );
27
+ // new in 3.2: update cache on delete
28
+ add_action( 'delete_post', array($this->cache, 'delete_post') );
29
+ // new in 3.2.1: handle post_status transitions
30
+ add_action( 'transition_post_status', array($this->cache, 'transition_post_status'), 10, 3);
31
+
32
+ // automatic display hooks:
33
+ add_filter( 'the_content', array( $this, 'the_content' ), 1200 );
34
+ add_filter( 'the_content_rss', array( $this, 'the_content_rss' ), 600 );
35
+ add_filter( 'the_excerpt_rss', array( $this, 'the_excerpt_rss' ), 600 );
36
+
37
+ if ( isset($_REQUEST['yarpp_debug']) )
38
+ $yarpp->debug = true;
39
+
40
+ // new in 3.4: only load UI if we're in the admin
41
+ if ( is_admin() ) {
42
+ require_once(YARPP_DIR . '/class-admin.php');
43
+ $this->admin = new YARPP_Admin( $this );
44
+ }
45
+ }
46
+
47
+ function admin_init() {
48
+ // Register AJAX services
49
+ if ( defined('DOING_AJAX') && DOING_AJAX ) {
50
+ add_action( 'wp_ajax_yarpp_display_exclude_terms', array( $this, 'ajax_display_exclude_terms' ) );
51
+ add_action( 'wp_ajax_yarpp_display_demo', array( $this, 'ajax_display_demo' ) );
52
+ }
53
+ }
54
+
55
+ /*
56
+ * INFRASTRUCTURE
57
+ */
58
+
59
+ function enabled() {
60
+ global $wpdb;
61
+ if ( $this->cache->is_enabled() === false )
62
+ return false;
63
+ $indexdata = $wpdb->get_results("show index from $wpdb->posts");
64
+ foreach ($indexdata as $index) {
65
+ if ($index->Key_name == 'yarpp_title')
66
+ return true;
67
+ }
68
+ return false;
69
+ }
70
+
71
+ function activate() {
72
+ global $yarpp_version, $wpdb;
73
+
74
+ $wpdb->get_results("show index from $wpdb->posts where Key_name='yarpp_title'");
75
+ if (!$wpdb->num_rows)
76
+ $wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `yarpp_title` ( `post_title` )");
77
+
78
+ $wpdb->get_results("show index from $wpdb->posts where Key_name='yarpp_content'");
79
+ if (!$wpdb->num_rows)
80
+ $wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `yarpp_content` ( `post_content` )");
81
+
82
+ if ( !$this->enabled() ) {
83
+ // If we are still not enabled, run the cache abstraction's setup method.
84
+ $this->cache->setup();
85
+ // If we're still not enabled, give up.
86
+ if ( !$this->enabled() )
87
+ return 0;
88
+ }
89
+
90
+ if ( !get_option('yarpp_version') ) {
91
+ add_option( 'yarpp_version', YARPP_VERSION );
92
+ $this->version_info(true);
93
+ } else {
94
+ $this->upgrade_check();
95
+ }
96
+
97
+ return 1;
98
+ }
99
+
100
+ function myisam_check() {
101
+ global $wpdb;
102
+ $tables = $wpdb->get_results("show table status like '{$wpdb->posts}'");
103
+ foreach ($tables as $table) {
104
+ if ($table->Engine == 'MyISAM') return true;
105
+ else return $table->Engine;
106
+ }
107
+ return 'UNKNOWN';
108
+ }
109
+
110
+ function upgrade_check() {
111
+ $last_version = get_option( 'yarpp_version' );
112
+ if (version_compare(YARPP_VERSION, $last_version) === 0)
113
+ return;
114
+
115
+ if ( $last_version && version_compare('3.4b2', $last_version) > 0 )
116
+ $this->upgrade_3_4b2();
117
+ if ( $last_version && version_compare('3.4b5', $last_version) > 0 )
118
+ $this->upgrade_3_4b5();
119
+
120
+ $this->cache->upgrade($last_version);
121
+
122
+ $this->version_info(true);
123
+
124
+ update_option('yarpp_version',YARPP_VERSION);
125
+ }
126
+
127
+ function upgrade_3_4b2() {
128
+ global $wpdb, $yarpp_value_options, $yarpp_binary_options;
129
+
130
+ $yarpp_options = array();
131
+ foreach ( $yarpp_value_options as $key => $default ) {
132
+ $value = get_option( "yarpp_$key", null );
133
+ if ( is_null($value) )
134
+ continue;
135
+
136
+ // value options used to be stored with a bajillion slashes...
137
+ $value = stripslashes(stripslashes($value));
138
+ // value options used to be stored with a blank space at the end... don't ask.
139
+ $value = rtrim($value, ' ');
140
+
141
+ if ( is_int($default) )
142
+ $yarpp_options[$key] = absint($value);
143
+ else
144
+ $yarpp_options[$key] = $value;
145
+ }
146
+ foreach ( $yarpp_binary_options as $key => $default ) {
147
+ $value = get_option( "yarpp_$key", null );
148
+ if ( is_null($value) )
149
+ continue;
150
+ $yarpp_options[$key] = (boolean) $value;
151
+ }
152
+
153
+ // add the options directly first, then call set_option which will ensure defaults,
154
+ // in case any new options have been added.
155
+ update_option( 'yarpp', $yarpp_options );
156
+ yarpp_set_option( $yarpp_options );
157
+
158
+ $option_keys = array_keys( $yarpp_options );
159
+ // append some keys for options which are long deprecated:
160
+ $option_keys[] = 'ad_hoc_caching';
161
+ $option_keys[] = 'excerpt_len';
162
+ $option_keys[] = 'show_score';
163
+ if ( count($option_keys) ) {
164
+ $in = "('yarpp_" . join("', 'yarpp_", $option_keys) . "')";
165
+ $wpdb->query("delete from {$wpdb->options} where option_name in {$in}");
166
+ }
167
+ }
168
+
169
+ function upgrade_3_4b5() {
170
+ $options = yarpp_get_option();
171
+ $options['exclude'] = array(
172
+ 'post_tag' => $options['distags'],
173
+ 'category' => $options['discats']
174
+ );
175
+ unset( $options['distags'] );
176
+ unset( $options['discats'] );
177
+ update_option( 'yarpp', $options );
178
+ }
179
+
180
+ /*
181
+ * DEFAULT CONTENT FILTERS
182
+ */
183
+
184
+ function the_content($content) {
185
+ global $post;
186
+
187
+ if (is_feed())
188
+ return $this->the_content_rss($content);
189
+
190
+ $type = ($post->post_type == 'page' ? array('page') : array('post'));
191
+ if ( yarpp_get_option('cross_relate') )
192
+ $type = array('post','page');
193
+
194
+ if ( yarpp_get_option('auto_display') && is_single() )
195
+ return $content . yarpp_related($type,array(),false,false,'website');
196
+ else
197
+ return $content;
198
+ }
199
+
200
+ function the_content_rss($content) {
201
+ global $post;
202
+
203
+ $type = ($post->post_type == 'page' ? array('page') : array('post'));
204
+ if ( yarpp_get_option('cross_relate') )
205
+ $type = array('post','page');
206
+
207
+ if ( yarpp_get_option('rss_display') )
208
+ return $content . yarpp_related($type,array(),false,false,'rss');
209
+ else
210
+ return $content;
211
+ }
212
+
213
+ function the_excerpt_rss($content) {
214
+ global $post;
215
+
216
+ $type = ($post->post_type == 'page' ? array('page') : array('post'));
217
+ if ( yarpp_get_option('cross_relate') )
218
+ $type = array('post','page');
219
+
220
+ if ( yarpp_get_option('rss_excerpt_display') && yarpp_get_option('rss_display') )
221
+ return $content . clean_pre(yarpp_related($type,array(),false,false,'rss'));
222
+ else
223
+ return $content;
224
+ }
225
+
226
+ /*
227
+ * UTILS
228
+ */
229
+
230
+ // new in 3.3: use PHP serialized format instead of JSON
231
+ function version_info( $enforce_cache = false ) {
232
+ if (false === ($result = get_transient('yarpp_version_info')) || $enforce_cache) {
233
+ $version = YARPP_VERSION;
234
+ $remote = wp_remote_post("http://mitcho.com/code/yarpp/checkversion.php?format=php&version={$version}");
235
+
236
+ if (is_wp_error($remote))
237
+ return false;
238
+
239
+ $result = unserialize($remote['body']);
240
+ set_transient('yarpp_version_info', $result, 60*60*12);
241
+ }
242
+ return $result;
243
+ }
244
+
245
+ /*
246
+ * AJAX SERVICES
247
+ */
248
+
249
+ function ajax_display_exclude_terms() {
250
+ if ( !isset($_REQUEST['taxonomy']) )
251
+ return;
252
+
253
+ $taxonomy = (string) $_REQUEST['taxonomy'];
254
+
255
+ header("HTTP/1.1 200");
256
+ header("Content-Type: text/html; charset=UTF-8");
257
+
258
+ $exclude = yarpp_get_option('exclude');
259
+ if ( !isset($exclude[$taxonomy]) )
260
+ $exclude[$taxonomy] = array();
261
+ $terms = get_terms($taxonomy, array(
262
+ 'exclude' => $exclude[$taxonomy],
263
+ 'number' => 100,
264
+ 'offset' => $_REQUEST['offset']
265
+ ));
266
+
267
+ if ( !count($terms) ) {
268
+ echo ':('; // no more :(
269
+ exit;
270
+ }
271
+
272
+ foreach ($terms as $term) {
273
+ echo "<input type='checkbox' name='exclude[$taxonomy][$term->term_id]' value='true' /> <label>" . esc_html($term->name) . "</label> ";
274
+ //for='exclude[$taxonomy][$cat->term_id]' it's not HTML. :(
275
+ }
276
+ exit;
277
+ }
278
+
279
+ function ajax_display_demo() {
280
+ header("HTTP/1.1 200");
281
+ header("Content-Type: text/html; charset=UTF-8");
282
+
283
+ $domain = 'demo_web';
284
+ if ( isset($_REQUEST['domain']) )
285
+ $domain = $_REQUEST['domain'];
286
+
287
+ $return = yarpp_related(array('post'), array(), false, false, $domain);
288
+ echo ereg_replace("[\n\r]",'',nl2br(htmlspecialchars($return)));
289
+ exit;
290
+ }
291
+ }
class-widget.php ADDED
@@ -0,0 +1,97 @@
1
+ <?php
2
+
3
+ // vaguely based on code by MK Safi
4
+ // http://msafi.com/fix-yet-another-related-posts-plugin-yarpp-widget-and-add-it-to-the-sidebar/
5
+ class YARPP_Widget extends WP_Widget {
6
+ function YARPP_Widget() {
7
+ parent::WP_Widget(false, $name = __('Related Posts (YARPP)','yarpp'));
8
+ }
9
+
10
+ function widget($args, $instance) {
11
+ global $post;
12
+ if (!is_singular())
13
+ return;
14
+
15
+ extract($args);
16
+
17
+ $type = ($post->post_type == 'page' ? array('page') : array('post'));
18
+ if (yarpp_get_option('cross_relate'))
19
+ $type = array('post','page');
20
+
21
+ $title = apply_filters('widget_title', $instance['title']);
22
+ echo $before_widget;
23
+ if ( !$instance['use_template'] ) {
24
+ echo $before_title;
25
+ if ($title)
26
+ echo $title;
27
+ else
28
+ _e('Related Posts (YARPP)','yarpp');
29
+ echo $after_title;
30
+ }
31
+ echo yarpp_related($type,$instance,false,false,'widget');
32
+ echo $after_widget;
33
+ }
34
+
35
+ function update($new_instance, $old_instance) {
36
+ // this starts with default values.
37
+ $instance = array( 'promote_yarpp' => 0, 'use_template' => 0 );
38
+ foreach ( $instance as $field => $val ) {
39
+ if ( isset($new_instance[$field]) )
40
+ $instance[$field] = 1;
41
+ }
42
+ if ($instance['use_template']) {
43
+ $instance['template_file'] = $new_instance['template_file'];
44
+ $instance['title'] = $old_instance['title'];
45
+ } else {
46
+ $instance['template_file'] = $old_instance['template_file'];
47
+ $instance['title'] = $new_instance['title'];
48
+ }
49
+ return $instance;
50
+ }
51
+
52
+ function form($instance) {
53
+ $title = esc_attr($instance['title']);
54
+ $template_file = $instance['template_file'];
55
+ ?>
56
+ <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></label></p>
57
+
58
+ <?php // if there are YARPP templates installed...
59
+
60
+ $templates = glob(STYLESHEETPATH . '/yarpp-template-*.php');
61
+ if ( is_array($templates) && count($templates) ): ?>
62
+
63
+ <p><input class="checkbox" id="<?php echo $this->get_field_id('use_template'); ?>" name="<?php echo $this->get_field_name('use_template'); ?>" type="checkbox" <?php checked($instance['use_template'], true) ?> /> <label for="<?php echo $this->get_field_id('use_template'); ?>"><?php _e("Display using a custom template file",'yarpp');?></label></p>
64
+ <p id="<?php echo $this->get_field_id('template_file_p'); ?>"><label for="<?php echo $this->get_field_id('template_file'); ?>"><?php _e("Template file:",'yarpp');?></label> <select name="<?php echo $this->get_field_name('template_file'); ?>" id="<?php echo $this->get_field_id('template_file'); ?>">
65
+ <?php foreach ($templates as $template): ?>
66
+ <option value='<?php echo htmlspecialchars(basename($template))?>'<?php echo (basename($template)==$template_file)?" selected='selected'":'';?>><?php echo htmlspecialchars(basename($template))?></option>
67
+ <?php endforeach; ?>
68
+ </select><p>
69
+
70
+ <?php endif; ?>
71
+
72
+ <p><input class="checkbox" id="<?php echo $this->get_field_id('promote_yarpp'); ?>" name="<?php echo $this->get_field_name('promote_yarpp'); ?>" type="checkbox" <?php checked($instance['images'], true) ?> /> <label for="<?php echo $this->get_field_id('promote_yarpp'); ?>"><?php _e("Help promote Yet Another Related Posts Plugin?",'yarpp'); ?></label></p>
73
+
74
+ <script type="text/javascript">
75
+ jQuery(function($) {
76
+ function ensureTemplateChoice() {
77
+ if ($('#<?php echo $this->get_field_id('use_template'); ?>').attr('checked')) {
78
+ $('#<?php echo $this->get_field_id('title'); ?>').attr('disabled',true);
79
+ $('#<?php echo $this->get_field_id('template_file_p'); ?>').show();
80
+ } else {
81
+ $('#<?php echo $this->get_field_id('title'); ?>').attr('disabled',false);
82
+ $('#<?php echo $this->get_field_id('template_file_p'); ?>').hide();
83
+ }
84
+ }
85
+ $('#<?php echo $this->get_field_id('use_template'); ?>').change(ensureTemplateChoice);
86
+ ensureTemplateChoice();
87
+ });
88
+ </script>
89
+
90
+ <?php
91
+ }
92
+ }
93
+ // new in 2.0: add as a widget
94
+ function yarpp_widget_init() {
95
+ register_widget( 'YARPP_Widget' );
96
+ }
97
+ add_action( 'widgets_init', 'yarpp_widget_init' );
includes.php CHANGED
@@ -1,426 +1,5 @@
1
<?php
2
3
- // new in 3.4: put everything YARPP into an object, expected to be a singleton global $yarpp
4
- class YARPP {
5
-
6
- public $debug = false;
7
-
8
- public $cache;
9
- private $storage_class;
10
-
11
- function __construct() {
12
- require_once(YARPP_DIR . '/cache-' . YARPP_CACHE_TYPE . '.php');
13
- $this->storage_class = $yarpp_storage_class;
14
- $this->cache = new $this->storage_class( $this );
15
-
16
- // update cache on save
17
- add_action('save_post', array($this->cache, 'save_post') );
18
- // new in 3.2: update cache on delete
19
- add_action('delete_post', array($this->cache, 'delete_post') );
20
- // new in 3.2.1: handle post_status transitions
21
- add_action('transition_post_status', array($this->cache, 'transition_post_status'), 10, 3);
22
- }
23
-
24
- /*
25
- * INFRASTRUCTURE
26
- */
27
-
28
- function enabled() {
29
- global $wpdb;
30
- if ( $this->cache->is_enabled() === false )
31
- return false;
32
- $indexdata = $wpdb->get_results("show index from $wpdb->posts");
33
- foreach ($indexdata as $index) {
34
- if ($index->Key_name == 'yarpp_title')
35
- return true;
36
- }
37
- return false;
38
- }
39
-
40
- function activate() {
41
- global $yarpp_version, $wpdb;
42
-
43
- $wpdb->get_results("show index from $wpdb->posts where Key_name='yarpp_title'");
44
- if (!$wpdb->num_rows)
45
- $wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `yarpp_title` ( `post_title` )");
46
-
47
- $wpdb->get_results("show index from $wpdb->posts where Key_name='yarpp_content'");
48
- if (!$wpdb->num_rows)
49
- $wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `yarpp_content` ( `post_content` )");
50
-
51
- if ( !$this->enabled() ) {
52
- // If we are still not enabled, run the cache abstraction's setup method.
53
- $this->cache->setup();
54
- // If we're still not enabled, give up.
55
- if ( !$this->enabled() )
56
- return 0;
57
- }
58
-
59
- if ( !get_option('yarpp_version') ) {
60
- add_option( 'yarpp_version', YARPP_VERSION );
61
- $this->version_info(true);
62
- } else {
63
- $this->upgrade_check();
64
- }
65
-
66
- return 1;
67
- }
68
-
69
- function myisam_check() {
70
- global $wpdb;
71
- $tables = $wpdb->get_results("show table status like '{$wpdb->posts}'");
72
- foreach ($tables as $table) {
73
- if ($table->Engine == 'MyISAM') return true;
74
- else return $table->Engine;
75
- }
76
- return 'UNKNOWN';
77
- }
78
-
79
- function upgrade_check() {
80
- $last_version = get_option( 'yarpp_version' );
81
- if (version_compare(YARPP_VERSION, $last_version) === 0)
82
- return;
83
-
84
- if ( $last_version && version_compare('3.4b2', $last_version) > 0 )
85
- $this->upgrade_3_4b2();
86
- if ( $last_version && version_compare('3.4b5', $last_version) > 0 )
87
- $this->upgrade_3_4b5();
88
-
89
- $this->cache->upgrade($last_version);
90
-
91
- $this->version_info(true);
92
-
93
- update_option('yarpp_version',YARPP_VERSION);
94
- }
95
-
96
- function upgrade_3_4b2() {
97
- global $wpdb, $yarpp_value_options, $yarpp_binary_options;
98
-
99
- $yarpp_options = array();
100
- foreach ( $yarpp_value_options as $key => $default ) {
101
- $value = get_option( "yarpp_$key", null );
102
- if ( is_null($value) )
103
- continue;
104
-
105
- // value options used to be stored with a bajillion slashes...
106
- $value = stripslashes(stripslashes($value));
107
- // value options used to be stored with a blank space at the end... don't ask.
108
- $value = rtrim($value, ' ');
109
-
110
- if ( is_int($default) )
111
- $yarpp_options[$key] = absint($value);
112
- else
113
- $yarpp_options[$key] = $value;
114
- }
115
- foreach ( $yarpp_binary_options as $key => $default ) {
116
- $value = get_option( "yarpp_$key", null );
117
- if ( is_null($value) )
118
- continue;
119
- $yarpp_options[$key] = (boolean) $value;
120
- }
121
-
122
- // add the options directly first, then call set_option which will ensure defaults,
123
- // in case any new options have been added.
124
- update_option( 'yarpp', $yarpp_options );
125
- yarpp_set_option( $yarpp_options );
126
-
127
- $option_keys = array_keys( $yarpp_options );
128
- // append some keys for options which are long deprecated:
129
- $option_keys[] = 'ad_hoc_caching';
130
- $option_keys[] = 'excerpt_len';
131
- $option_keys[] = 'show_score';
132
- if ( count($option_keys) ) {
133
- $in = "('yarpp_" . join("', 'yarpp_", $option_keys) . "')";
134
- $wpdb->query("delete from {$wpdb->options} where option_name in {$in}");
135
- }
136
- }
137
-
138
- function upgrade_3_4b5() {
139
- $options = yarpp_get_option();
140
- $options['exclude'] = array(
141
- 'post_tag' => $options['distags'],
142
- 'category' => $options['discats']
143
- );
144
- unset( $options['distags'] );
145
- unset( $options['discats'] );
146
- update_option( 'yarpp', $options );
147
- }
148
-
149
- /*
150
- * UTILS
151
- */
152
-
153
- // new in 3.3: use PHP serialized format instead of JSON
154
- function version_info( $enforce_cache = false ) {
155
- if (false === ($result = get_transient('yarpp_version_info')) || $enforce_cache) {
156
- $version = YARPP_VERSION;
157
- $remote = wp_remote_post("http://mitcho.com/code/yarpp/checkversion.php?format=php&version={$version}");
158
-
159
- if (is_wp_error($remote))
160
- return false;
161
-
162
- $result = unserialize($remote['body']);
163
- set_transient('yarpp_version_info', $result, 60*60*12);
164
- }
165
- return $result;
166
- }
167
-
168
- }
169
-
170
- abstract class YARPP_Cache {
171
-
172
- public $core;
173
-
174
- function __construct( &$core ) {
175
- $this->core = &$core;
176
- $this->name = __($this->name, 'yarpp');
177
- }
178
-
179
- // Note: return value changed in 3.4
180
- // return YARPP_NO_RELATED | YARPP_RELATED | YARPP_DONT_RUN | false if no good input
181
- function enforce($reference_ID, $force = false) {
182
- if ( !$reference_ID = absint($reference_ID) )
183
- return false;
184
-
185
- $status = $this->is_cached($reference_ID);
186
- $status = apply_filters( 'yarpp_cache_enforce_status', $status, $reference_ID );
187
-
188
- // There's a stop signal:
189
- if ( YARPP_DONT_RUN === $status )
190
- return YARPP_DONT_RUN;
191
-
192
- // If not cached, process now:
193
- if ( YARPP_NOT_CACHED == $status || $force ) {
194
- $status = $this->update($reference_ID);
195
- // if still not cached, there's a problem, but for the time being return NO RELATED
196
- if ( YARPP_NOT_CACHED === $status )
197
- return YARPP_NO_RELATED;
198
- }
199
-
200
- // There are no related posts
201
- if ( YARPP_NO_RELATED === $status )
202
- return YARPP_NO_RELATED;
203
-
204
- // There are results
205
- return YARPP_RELATED;
206
- }
207
-
208
- /*
209
- * POST STATUS INTERACTIONS
210
- */
211
-
212
- function save_post($post_ID, $force=true) {
213
- global $wpdb;
214
-
215
- // new in 3.2: don't compute cache during import
216
- if ( defined( 'WP_IMPORTING' ) )
217
- return;
218
-
219
- $sql = "select post_parent from $wpdb->posts where ID='$post_ID'";
220
- $parent_ID = $wpdb->get_var($sql);
221
-
222
- if ( $parent_ID != $post_ID && $parent_ID )
223
- $post_ID = $parent_ID;
224
-
225
- $this->enforce((int) $post_ID, $force);
226
- }
227
-
228
- // Clear the cache for this entry and for all posts which are "related" to it.
229
- // New in 3.2: This is called when a post is deleted.
230
- function delete_post($post_ID) {
231
- // Clear the cache for this post.
232
- $this->clear($post_ID);
233
-
234
- // Find all "peers" which list this post as a related post.
235
- $peers = $this->related(null, $post_ID);
236
- // Clear the peers' caches.
237
- $this->clear($peers);
238
- }
239
-
240
- // New in 3.2.1: handle various post_status transitions
241
- function transition_post_status($new_status, $old_status, $post) {
242
- switch ($new_status) {
243
- case "draft":
244
- $this->delete_post($post->ID);
245
- break;
246
- case "publish":
247
- // find everything which is related to this post, and clear them, so that this
248
- // post might show up as related to them.
249
- $related = $this->related($post->ID, null);
250
- $this->clear($related);
251
- }
252
- }
253
-
254
- /*
255
- * KEYWORDS
256
- */
257
-
258
- public function title_keywords($ID,$max = 20) {
259
- return $this->extract_keywords(get_the_title($ID),$max);
260
- }
261
-
262
- public function body_keywords( $ID, $max = 20 ) {
263
- $post = get_post( $ID );
264
- if ( empty($post) )
265
- return '';
266
- $content = $this->apply_filters_if_white( 'the_content', $post->post_content );
267
- return $this->extract_keywords( $content, $max );
268
- }
269
-
270
- private function extract_keywords($html, $max = 20) {
271
-
272
- $lang = 'en_US';
273
- if ( defined('WPLANG') ) {
274
- $lang = substr(WPLANG, 0, 2);
275
- switch ( $lang ) {
276
- case 'de':
277
- $lang = 'de_DE';
278
- case 'it':
279
- $lang = 'it_IT';
280
- case 'pl':
281
- $lang = 'pl_PL';
282
- case 'bg':
283
- $lang = 'bg_BG';
284
- case 'fr':
285
- $lang = 'fr_FR';
286
- case 'cs':
287
- $lang = 'cs_CZ';
288
- case 'nl':
289
- $lang = 'nl_NL';
290
- }
291
- }
292
-
293
- $words_file = YARPP_DIR . '/lang/words-' . $lang . '.php';
294
- if ( file_exists($words_file) )
295
- include( $words_file );
296
- if ( !isset($overusedwords) )
297
- $overusedwords = array();
298
-
299
- // strip tags and html entities
300
- $text = preg_replace('/&(#x[0-9a-f]+|#[0-9]+|[a-zA-Z]+);/', '', strip_tags($html) );
301
-
302
- // 3.2.2: ignore soft hyphens
303
- // Requires PHP 5: http://bugs.php.net/bug.php?id=25670
304
- $softhyphen = html_entity_decode('&#173;',ENT_NOQUOTES,'UTF-8');
305
- $text = str_replace($softhyphen, '', $text);
306
-
307
- $charset = get_option('blog_charset');
308
- if ( function_exists('mb_split') && !empty($charset) ) {
309
- mb_regex_encoding($charset);
310
- $wordlist = mb_split('\s*\W+\s*', mb_strtolower($text, $charset));
311
- } else
312
- $wordlist = preg_split('%\s*\W+\s*%', strtolower($text));
313
-
314
- // Build an array of the unique words and number of times they occur.
315
- $tokens = array_count_values($wordlist);
316
-
317
- // Remove the stop words from the list.
318
- $overusedwords = apply_filters( 'yarpp_keywords_overused_words', $overusedwords );
319
- if ( is_array($overusedwords) ) {
320
- foreach ($overusedwords as $word) {
321
- unset($tokens[$word]);
322
- }
323
- }
324
- // Remove words which are only a letter
325
- $mb_strlen_exists = function_exists('mb_strlen');
326
- foreach (array_keys($tokens) as $word) {
327
- if ($mb_strlen_exists)
328
- if (mb_strlen($word) < 2) unset($tokens[$word]);
329
- else
330
- if (strlen($word) < 2) unset($tokens[$word]);
331
- }
332
-
333
- arsort($tokens, SORT_NUMERIC);
334
-
335
- $types = array_keys($tokens);
336
-
337
- if (count($types) > $max)
338
- $types = array_slice($types, 0, $max);
339
- return implode(' ', $types);
340
- }
341
-
342
- /* new in 2.0! apply_filters_if_white (previously apply_filters_without) now has a blacklist.
343
- * It can be modified via the yarpp_blacklist and yarpp_blackmethods filters.
344
- */
345
- /* blacklisted so far:
346
- - diggZ-Et
347
- - reddZ-Et
348
- - dzoneZ-Et
349
- - WP-Syntax
350
- - Viper's Video Quicktags
351
- - WP-CodeBox
352
- - WP shortcodes
353
- - WP Greet Box
354
- //- Tweet This - could not reproduce problem.
355
- */
356
- function white( $filter ) {
357
- static $blacklist, $blackmethods;
358
-
359
- if ( is_null($blacklist) || is_null($blackmethods) ) {
360
- $yarpp_blacklist = array('yarpp_default', 'diggZEt_AddBut', 'reddZEt_AddBut', 'dzoneZEt_AddBut', 'wp_syntax_before_filter', 'wp_syntax_after_filter', 'wp_codebox_before_filter', 'wp_codebox_after_filter', 'do_shortcode');//,'insert_tweet_this'
361
- $yarpp_blackmethods = array('addinlinejs', 'replacebbcode', 'filter_content');
362
-
363
- $blacklist = (array) apply_filters( 'yarpp_blacklist', $yarpp_blacklist );
364
- $blackmethods = (array) apply_filters( 'yarpp_blackmethods', $yarpp_blackmethods );
365
- }
366
-
367
- if ( is_array($filter) && in_array( $filter[1], $blackmethods ) )
368
- return false;
369
- return !in_array( $filter, $blacklist );
370
- }
371
-
372
- /* FYI, apply_filters_if_white was used here to avoid a loop in apply_filters('the_content') > yarpp_default() > yarpp_related() > current_post_keywords() > apply_filters('the_content').*/
373
- function apply_filters_if_white($tag, $value) {
374
- global $wp_filter, $merged_filters, $wp_current_filter;
375
-
376
- $args = array();
377
-
378
- // Do 'all' actions first
379
- if ( isset($wp_filter['all']) ) {
380
- $wp_current_filter[] = $tag;
381
- $args = func_get_args();
382
- _wp_call_all_hook($args);
383
- }
384
-
385
- if ( !isset($wp_filter[$tag]) ) {
386
- if ( isset($wp_filter['all']) )
387
- array_pop($wp_current_filter);
388
- return $value;
389
- }
390
-
391
- if ( !isset($wp_filter['all']) )
392
- $wp_current_filter[] = $tag;
393
-
394
- // Sort
395
- if ( !isset( $merged_filters[ $tag ] ) ) {
396
- ksort($wp_filter[$tag]);
397
- $merged_filters[ $tag ] = true;
398
- }
399
-
400
- reset( $wp_filter[ $tag ] );
401
-
402
- if ( empty($args) )
403
- $args = func_get_args();
404
-
405
- do {
406
- foreach( (array) current($wp_filter[$tag]) as $the_ )
407
- if ( !is_null($the_['function'])
408
- and $this->white($the_['function'])){ // HACK
409
- $args[1] = $value;
410
- $value = call_user_func_array($the_['function'], array_slice($args, 1, (int) $the_['accepted_args']));
411
- }
412
-
413
- } while ( next($wp_filter[$tag]) !== false );
414
-
415
- array_pop( $wp_current_filter );
416
-
417
- return $value;
418
- }
419
- }
420
-
421
- require_once(YARPP_DIR.'/magic.php');
422
- require_once(YARPP_DIR.'/services.php');
423
-
424
if ( !defined('WP_CONTENT_URL') )
425
define('WP_CONTENT_URL', get_option('siteurl') . '/wp-content');
426
if ( !defined('WP_CONTENT_DIR') )
@@ -478,181 +57,6 @@ $yarpp_clear_cache_options = array(
478
'show_pass_post','recent_only','threshold','title','body','categories',
479
'tags');
480
481
- function yarpp_admin_menu() {
482
- $hook = add_options_page(__('Related Posts (YARPP)','yarpp'),__('Related Posts (YARPP)','yarpp'), 'manage_options', 'yarpp', 'yarpp_options_page');
483
- add_action("load-$hook",'yarpp_load_thickbox');
484
- // new in 3.3: load options page sections as metaboxes
485
- include('options-meta-boxes.php');
486
- // new in 3.0.12: add settings link to the plugins page
487
- add_filter('plugin_action_links', 'yarpp_settings_link', 10, 2);
488
- }
489
-
490
- // since 3.3
491
- function yarpp_admin_enqueue() {
492
- global $current_screen;
493
- if (is_object($current_screen) && $current_screen->id == 'settings_page_yarpp') {
494
- wp_enqueue_script( 'postbox' );
495
- wp_enqueue_style( 'yarpp_options', plugins_url( 'options.css', __FILE__ ), array(), YARPP_VERSION );
496
- wp_enqueue_script( 'yarpp_options', plugins_url( 'options.js', __FILE__ ), array('jquery'), YARPP_VERSION );
497
- }
498
- }
499
-
500
- function yarpp_settings_link($links, $file) {
501
- $this_plugin = dirname(plugin_basename(__FILE__)) . '/yarpp.php';
502
- if($file == $this_plugin) {
503
- $links[] = '<a href="options-general.php?page=yarpp">' . __('Settings', 'yarpp') . '</a>';
504
- }
505
- return $links;
506
- }
507
-
508
- function yarpp_load_thickbox() {
509
- wp_enqueue_script( 'thickbox' );
510
- wp_enqueue_style( 'thickbox' );
511
- }
512
-
513
- function yarpp_options_page() {
514
- // for proper metabox support:
515
- require(YARPP_DIR.'/options.php');
516
- }
517
-
518
- function widget_yarpp_init() {
519
- register_widget( 'YARPP_Widget' );
520
- }
521
-
522
- // vaguely based on code by MK Safi
523
- // http://msafi.com/fix-yet-another-related-posts-plugin-yarpp-widget-and-add-it-to-the-sidebar/
524
- class YARPP_Widget extends WP_Widget {
525
- function YARPP_Widget() {
526
- parent::WP_Widget(false, $name = __('Related Posts (YARPP)','yarpp'));
527
- }
528
-
529
- function widget($args, $instance) {
530
- global $post;
531
- if (!is_singular())
532
- return;
533
-
534
- extract($args);
535
-
536
- $type = ($post->post_type == 'page' ? array('page') : array('post'));
537
- if (yarpp_get_option('cross_relate'))
538
- $type = array('post','page');
539
-
540
- $title = apply_filters('widget_title', $instance['title']);
541
- echo $before_widget;
542
- if ( !$instance['use_template'] ) {
543
- echo $before_title;
544
- if ($title)
545
- echo $title;
546
- else
547
- _e('Related Posts (YARPP)','yarpp');
548
- echo $after_title;
549
- }
550
- echo yarpp_related($type,$instance,false,false,'widget');
551
- echo $after_widget;
552
- }
553
-
554
- function update($new_instance, $old_instance) {
555
- // this starts with default values.
556
- $instance = array( 'promote_yarpp' => 0, 'use_template' => 0 );
557
- foreach ( $instance as $field => $val ) {
558
- if ( isset($new_instance[$field]) )
559
- $instance[$field] = 1;
560
- }
561
- if ($instance['use_template']) {
562
- $instance['template_file'] = $new_instance['template_file'];
563
- $instance['title'] = $old_instance['title'];
564
- } else {
565
- $instance['template_file'] = $old_instance['template_file'];
566
- $instance['title'] = $new_instance['title'];
567
- }
568
- return $instance;
569
- }
570
-
571
- function form($instance) {
572
- $title = esc_attr($instance['title']);
573
- $template_file = $instance['template_file'];
574
- ?>
575
- <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></label></p>
576
-
577
- <?php // if there are YARPP templates installed...
578
-
579
- $templates = glob(STYLESHEETPATH . '/yarpp-template-*.php');
580
- if ( is_array($templates) && count($templates) ): ?>
581
-
582
- <p><input class="checkbox" id="<?php echo $this->get_field_id('use_template'); ?>" name="<?php echo $this->get_field_name('use_template'); ?>" type="checkbox" <?php checked($instance['use_template'], true) ?> /> <label for="<?php echo $this->get_field_id('use_template'); ?>"><?php _e("Display using a custom template file",'yarpp');?></label></p>
583
- <p id="<?php echo $this->get_field_id('template_file_p'); ?>"><label for="<?php echo $this->get_field_id('template_file'); ?>"><?php _e("Template file:",'yarpp');?></label> <select name="<?php echo $this->get_field_name('template_file'); ?>" id="<?php echo $this->get_field_id('template_file'); ?>">
584
- <?php foreach ($templates as $template): ?>
585
- <option value='<?php echo htmlspecialchars(basename($template))?>'<?php echo (basename($template)==$template_file)?" selected='selected'":'';?>><?php echo htmlspecialchars(basename($template))?></option>
586
- <?php endforeach; ?>
587
- </select><p>
588
-
589
- <?php endif; ?>
590
-
591
- <p><input class="checkbox" id="<?php echo $this->get_field_id('promote_yarpp'); ?>" name="<?php echo $this->get_field_name('promote_yarpp'); ?>" type="checkbox" <?php checked($instance['images'], true) ?> /> <label for="<?php echo $this->get_field_id('promote_yarpp'); ?>"><?php _e("Help promote Yet Another Related Posts Plugin?",'yarpp'); ?></label></p>
592
-
593
- <script type="text/javascript">
594
- jQuery(function() {
595
- function ensureTemplateChoice() {
596
- if (jQuery('#<?php echo $this->get_field_id('use_template'); ?>').attr('checked')) {
597
- jQuery('#<?php echo $this->get_field_id('title'); ?>').attr('disabled',true);
598
- jQuery('#<?php echo $this->get_field_id('template_file_p'); ?>').show();
599
- } else {
600
- jQuery('#<?php echo $this->get_field_id('title'); ?>').attr('disabled',false);
601
- jQuery('#<?php echo $this->get_field_id('template_file_p'); ?>').hide();
602
- }
603
- }
604
- jQuery('#<?php echo $this->get_field_id('use_template'); ?>').change(ensureTemplateChoice);
605
- ensureTemplateChoice();
606
- });
607
- </script>
608
-
609
- <?php
610
- }
611
- }
612
-
613
-
614
- function yarpp_default($content) {
615
- global $wpdb, $post;
616
-
617
- if (is_feed())
618
- return yarpp_rss($content);
619
-
620
- $type = ($post->post_type == 'page' ? array('page') : array('post'));
621
- if (yarpp_get_option('cross_relate'))
622
- $type = array('post','page');
623
-
624
- if (yarpp_get_option('auto_display') && is_single())
625
- return $content . yarpp_related($type,array(),false,false,'website');
626
- else
627
- return $content;
628
- }
629
-
630
- function yarpp_rss($content) {
631
- global $wpdb, $post;
632
-
633
- $type = ($post->post_type == 'page' ? array('page') : array('post'));
634
- if (yarpp_get_option('cross_relate'))
635
- $type = array('post','page');
636
-
637
- if (yarpp_get_option('rss_display'))
638
- return $content.yarpp_related($type,array(),false,false,'rss');
639
- else
640
- return $content;
641
- }
642
-
643
- function yarpp_rss_excerpt($content) {
644
- global $wpdb, $post;
645
-
646
- $type = ($post->post_type == 'page' ? array('page') : array('post'));
647
- if (yarpp_get_option('cross_relate'))
648
- $type = array('post','page');
649
-
650
- if (yarpp_get_option('rss_excerpt_display') && yarpp_get_option('rss_display'))
651
- return $content.clean_pre(yarpp_related($type,array(),false,false,'rss'));
652
- else
653
- return $content;
654
- }
655
-
656
// Used only in demo mode
657
if (!defined('LOREMIPSUM'))
658
define('LOREMIPSUM','Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Cras tincidunt justo a urna. Ut turpis. Phasellus convallis, odio sit amet cursus convallis, eros orci scelerisque velit, ut sodales neque nisl at ante. Suspendisse metus. Curabitur auctor pede quis mi. Pellentesque lorem justo, condimentum ac, dapibus sit amet, ornare et, erat. Quisque velit. Etiam sodales dui feugiat neque suscipit bibendum. Integer mattis. Nullam et ante non sem commodo malesuada. Pellentesque ultrices fermentum lectus. Maecenas hendrerit neque ac est. Fusce tortor mi, tristique sed, cursus at, pellentesque non, dui. Suspendisse potenti.');
@@ -693,26 +97,6 @@ function yarpp_get_option($option = null) {
693
return null;
694
}
695
696
- function yarpp_add_metabox() {
697
- add_meta_box( 'yarpp_relatedposts', __( 'Related Posts' , 'yarpp') . ' <span class="postbox-title-action"><a href="' . esc_url( admin_url('options-general.php?page=yarpp') ) . '" class="edit-box open-box">' . __( 'Configure' ) . '</a></span>', 'yarpp_metabox', 'post', 'normal' );
698
- }
699
- function yarpp_metabox() {
700
- global $post;
701
- echo '<style>#yarpp_relatedposts h3 .postbox-title-action { right: 30px; top: 5px; position: absolute; padding: 0 }</style><div id="yarpp-related-posts">';
702
- if ( $post->ID )
703
- yarpp_related(array('post'),array('limit'=>1000),true,false,'metabox');
704
- else
705
- echo "<p>".__("Related entries may be displayed once you save your entry",'yarpp').".</p>";
706
- echo '</div>';
707
- }
708
-
709
- // since 3.3: default metaboxes to show:
710
- function yarpp_default_hidden_meta_boxes($hidden, $screen) {
711
- if ( 'settings_page_yarpp' == $screen->id )
712
- $hidden = array( 'yarpp_pool', 'yarpp_relatedness' );
713
- return $hidden;
714
- }
715
-
716
// since 3.3.2: fix for WP 3.0.x
717
if ( !function_exists( 'self_admin_url' ) ) {
718
function self_admin_url($path = '', $scheme = 'admin') {
1
<?php
2
3
if ( !defined('WP_CONTENT_URL') )
4
define('WP_CONTENT_URL', get_option('siteurl') . '/wp-content');
5
if ( !defined('WP_CONTENT_DIR') )
57
'show_pass_post','recent_only','threshold','title','body','categories',
58
'tags');
59
60
// Used only in demo mode
61
if (!defined('LOREMIPSUM'))
62
define('LOREMIPSUM','Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Cras tincidunt justo a urna. Ut turpis. Phasellus convallis, odio sit amet cursus convallis, eros orci scelerisque velit, ut sodales neque nisl at ante. Suspendisse metus. Curabitur auctor pede quis mi. Pellentesque lorem justo, condimentum ac, dapibus sit amet, ornare et, erat. Quisque velit. Etiam sodales dui feugiat neque suscipit bibendum. Integer mattis. Nullam et ante non sem commodo malesuada. Pellentesque ultrices fermentum lectus. Maecenas hendrerit neque ac est. Fusce tortor mi, tristique sed, cursus at, pellentesque non, dui. Suspendisse potenti.');
97
return null;
98
}
99
100
// since 3.3.2: fix for WP 3.0.x
101
if ( !function_exists( 'self_admin_url' ) ) {
102
function self_admin_url($path = '', $scheme = 'admin') {
magic.php CHANGED
@@ -1,23 +1,5 @@
1
<?php
2
3
- //=TEMPLATING/DISPLAY===========
4
-
5
- function yarpp_set_score_override_flag($q) {
6
- global $yarpp;
7
- if ( $yarpp->cache->is_yarpp_time() ) {
8
- $yarpp->cache->score_override = ($q->query_vars['orderby'] == 'score');
9
-
10
- if (!empty($q->query_vars['showposts'])) {
11
- $yarpp->cache->online_limit = $q->query_vars['showposts'];
12
- } else {
13
- $yarpp->cache->online_limit = false;
14
- }
15
- } else {
16
- $yarpp->cache->score_override = false;
17
- $yarpp->cache->online_limit = false;
18
- }
19
- }
20
-
21
//=CACHING===========
22
23
function yarpp_sql( $reference_ID = false ) {
@@ -227,6 +209,7 @@ function yarpp_related($type,$args,$echo = true,$reference_ID=false,$domain = 'w
227
// make sure we get the right is_single value
228
// (see http://wordpress.org/support/topic/288230)
229
$wp_query->is_single = false;
230
231
if ($domain == 'metabox') {
232
include(YARPP_DIR.'/template-metabox.php');
@@ -250,7 +233,7 @@ function yarpp_related($type,$args,$echo = true,$reference_ID=false,$domain = 'w
250
}
251
252
// restore the older wp_query.
253
- $wp_query = $current_query; unset($current_query);
254
wp_reset_postdata();
255
$pagenow = $current_pagenow; unset($current_pagenow);
256
1
<?php
2
3
//=CACHING===========
4
5
function yarpp_sql( $reference_ID = false ) {
209
// make sure we get the right is_single value
210
// (see http://wordpress.org/support/topic/288230)
211
$wp_query->is_single = false;
212
+ $related_query = $wp_query; // backwards compatibility
213
214
if ($domain == 'metabox') {
215
include(YARPP_DIR.'/template-metabox.php');
233
}
234
235
// restore the older wp_query.
236
+ $wp_query = $current_query; unset($current_query); unset($related_query);
237
wp_reset_postdata();
238
$pagenow = $current_pagenow; unset($current_pagenow);
239
options.js CHANGED
@@ -23,8 +23,28 @@ jQuery(function($) {
23
}
24
$('.show_excerpt,.template').click(excerpt);
25
26
var loaded_demo_rss = false;
27
function rss_display() {
28
if ($('.rss_display').attr('checked')) {
29
$('.rss_displayed').show();
30
if ( !loaded_demo_rss ) {
@@ -32,17 +52,17 @@ jQuery(function($) {
32
var demo_rss = $('#display_demo_rss');
33
$.ajax({type:'POST',
34
url: ajaxurl,
35
- data:'action=yarpp_display_demo_rss',
36
beforeSend:function(){demo_rss.html(loading)},
37
success:function(html){demo_rss.html('<pre>'+html+'</pre>')},
38
dataType:'html'});
39
}
40
} else {
41
$('.rss_displayed').hide();
42
}
43
- rss_template();
44
}
45
- $('.rss_display').click(rss_display);
46
rss_display();
47
48
function rss_template() {
@@ -118,12 +138,4 @@ jQuery(function($) {
118
}
119
$('#yarpp_pool .handlediv, #yarpp_pool-hide').click(load_disallows);
120
load_disallows();
121
-
122
- var demo_web = $('#display_demo_web');
123
- $.ajax({type:'POST',
124
- url: ajaxurl,
125
- data:'action=yarpp_display_demo_web',
126
- beforeSend:function(){demo_web.html(loading)},
127
- success:function(html){demo_web.html('<pre>'+html+'</pre>')},
128
- dataType:'html'});
129
});
23
}
24
$('.show_excerpt,.template').click(excerpt);
25
26
+ var loaded_demo_web = false;
27
+ function display() {
28
+ if ( !$('#yarpp_display_web .inside').is(':visible') )
29
+ return;
30
+ if ( !loaded_demo_web ) {
31
+ loaded_demo_web = true;
32
+ var demo_web = $('#display_demo_web');
33
+ $.ajax({type:'POST',
34
+ url: ajaxurl,
35
+ data:'action=yarpp_display_demo&domain=demo_web',
36
+ beforeSend:function(){demo_web.html(loading)},
37
+ success:function(html){demo_web.html('<pre>'+html+'</pre>')},
38
+ dataType:'html'});
39
+ }
40
+ }
41
+ $('#yarpp_display_web .handlediv, #yarpp_display_web-hide').click(display);
42
+ display();
43
+
44
var loaded_demo_rss = false;
45
function rss_display() {
46
+ if ( !$('#yarpp_display_rss .inside').is(':visible') )
47
+ return;
48
if ($('.rss_display').attr('checked')) {
49
$('.rss_displayed').show();
50
if ( !loaded_demo_rss ) {
52
var demo_rss = $('#display_demo_rss');
53
$.ajax({type:'POST',
54
url: ajaxurl,
55
+ data:'action=yarpp_display_demo&domain=demo_rss',
56
beforeSend:function(){demo_rss.html(loading)},
57
success:function(html){demo_rss.html('<pre>'+html+'</pre>')},
58
dataType:'html'});
59
}
60
+ rss_template();
61
} else {
62
$('.rss_displayed').hide();
63
}
64
}
65
+ $('.rss_display, #yarpp_display_rss .handlediv, #yarpp_display_rss-hide').click(rss_display);
66
rss_display();
67
68
function rss_template() {
138
}
139
$('#yarpp_pool .handlediv, #yarpp_pool-hide').click(load_disallows);
140
load_disallows();
141
});
services.php DELETED
@@ -1,56 +0,0 @@
1
- <?php
2
-
3
- // setup the ajax action hooks
4
- add_action('wp_ajax_yarpp_display_exclude_terms', 'yarpp_ajax_display_exclude_terms');
5
- add_action('wp_ajax_yarpp_display_demo_web', 'yarpp_ajax_display_demo_web');
6
- add_action('wp_ajax_yarpp_display_demo_rss', 'yarpp_ajax_display_demo_rss');
7
-
8
- function yarpp_ajax_display_exclude_terms() {
9
- global $wpdb;
10
-
11
- if ( !isset($_REQUEST['taxonomy']) )
12
- return;
13
-
14
- $taxonomy = (string) $_REQUEST['taxonomy'];
15
-
16
- header("HTTP/1.1 200");
17
- header("Content-Type: text/html; charset=UTF-8");
18
-
19
- $exclude = yarpp_get_option('exclude');
20
- if ( !isset($exclude[$taxonomy]) )
21
- $exclude[$taxonomy] = array();
22
- $terms = get_terms($taxonomy, array(
23
- 'exclude' => $exclude[$taxonomy],
24
- 'number' => 100,
25
- 'offset' => $_REQUEST['offset']
26
- ));
27
-
28
- if ( !count($terms) ) {
29
- echo ':('; // no more :(
30
- exit;
31
- }
32
-
33
- foreach ($terms as $term) {
34
- echo "<input type='checkbox' name='exclude[$taxonomy][$term->term_id]' value='true' /> <label>" . esc_html($term->name) . "</label> ";
35
- //for='exclude[$taxonomy][$cat->term_id]' it's not HTML. :(
36
- }
37
- exit;
38
- }
39
-
40
- function yarpp_ajax_display_demo_web() {
41
- header("HTTP/1.1 200");
42
- header("Content-Type: text/html; charset=UTF-8");
43
-
44
- $return = yarpp_related(array('post'),array(),false,false,'demo_web');
45
- echo ereg_replace("[\n\r]",'',nl2br(htmlspecialchars($return)));
46
- exit;
47
- }
48
-
49
- function yarpp_ajax_display_demo_rss() {
50
- header("HTTP/1.1 200");
51
- header("Content-Type: text/html; charset=UTF-8");
52
-
53
- $return = yarpp_related(array('post'),array(),false,false,'demo_rss');
54
- echo ereg_replace("[\n\r]",'',nl2br(htmlspecialchars($return)));
55
- exit;
56
- }
yarpp-templates/yarpp-template-example.php CHANGED
@@ -3,9 +3,9 @@ Example template
3
Author: mitcho (Michael Yoshitaka Erlewine)
4
*/
5
?><h3>Related Posts</h3>
6
- <?php if ($related_query->have_posts()):?>
7
<ol>
8
- <?php while ($related_query->have_posts()) : $related_query->the_post(); ?>
9
<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a><!-- (<?php the_score(); ?>)--></li>
10
<?php endwhile; ?>
11
</ol>
3
Author: mitcho (Michael Yoshitaka Erlewine)
4
*/
5
?><h3>Related Posts</h3>
6
+ <?php if (have_posts()):?>
7
<ol>
8
+ <?php while (have_posts()) : the_post(); ?>
9
<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a><!-- (<?php the_score(); ?>)--></li>
10
<?php endwhile; ?>
11
</ol>
yarpp-templates/yarpp-template-list.php CHANGED
@@ -5,9 +5,9 @@ Author: mitcho (Michael Yoshitaka Erlewine)
5
*/
6
?><h3>Related Posts</h3>
7
8
- <?php if ($related_query->have_posts()):
9
$postsArray = array();
10
- while ($related_query->have_posts()) : $related_query->the_post();
11
$postsArray[] = '<a href="'.get_permalink().'" rel="bookmark">'.get_the_title().'</a><!-- ('.get_the_score().')-->';
12
endwhile;
13
5
*/
6
?><h3>Related Posts</h3>
7
8
+ <?php if (have_posts()):
9
$postsArray = array();
10
+ while (have_posts()) : the_post();
11
$postsArray[] = '<a href="'.get_permalink().'" rel="bookmark">'.get_the_title().'</a><!-- ('.get_the_score().')-->';
12
endwhile;
13
yarpp-templates/yarpp-template-photoblog.php CHANGED
@@ -3,9 +3,9 @@ Example photoblog template for use with Yet Another Photoblog
3
Author: mitcho (Michael Yoshitaka Erlewine)
4
*/ ?>
5
<h3>Related Photos</h3>
6
- <?php if ($related_query->have_posts()):?>
7
<ol>
8
- <?php while ($related_query->have_posts()) : $related_query->the_post(); ?>
9
<?php if (function_exists('yapb_is_photoblog_post')): if (yapb_is_photoblog_post()):?>
10
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php yapb_get_thumbnail(); ?></a></li>
11
<?php endif; endif; ?>
3
Author: mitcho (Michael Yoshitaka Erlewine)
4
*/ ?>
5
<h3>Related Photos</h3>
6
+ <?php if (have_posts()):?>
7
<ol>
8
+ <?php while (have_posts()) : the_post(); ?>
9
<?php if (function_exists('yapb_is_photoblog_post')): if (yapb_is_photoblog_post()):?>
10
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php yapb_get_thumbnail(); ?></a></li>
11
<?php endif; endif; ?>
yarpp-templates/yarpp-template-random.php CHANGED
@@ -4,15 +4,15 @@ This template gives you some random other post in case there are no related post
4
Author: mitcho (Michael Yoshitaka Erlewine)
5
*/ ?>
6
<h3>Related Posts</h3>
7
- <?php if ($related_query->have_posts()):?>
8
<ol>
9
- <?php while ($related_query->have_posts()) : $related_query->the_post(); ?>
10
<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a><!-- (<?php the_score(); ?>)--></li>
11
<?php endwhile; ?>
12
</ol>
13
14
<?php else:
15
- $related_query->query("orderby=rand&order=asc&limit=1");
16
- $related_query->the_post();?>
17
<p>No related posts were found, so here's a consolation prize: <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>.</p>
18
<?php endif; ?>
4
Author: mitcho (Michael Yoshitaka Erlewine)
5
*/ ?>
6
<h3>Related Posts</h3>
7
+ <?php if (have_posts()):?>
8
<ol>
9
+ <?php while (have_posts()) : the_post(); ?>
10
<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a><!-- (<?php the_score(); ?>)--></li>
11
<?php endwhile; ?>
12
</ol>
13
14
<?php else:
15
+ query("orderby=rand&order=asc&limit=1");
16
+ the_post();?>
17
<p>No related posts were found, so here's a consolation prize: <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>.</p>
18
<?php endif; ?>
yarpp-templates/yarpp-template-thumbnail.php CHANGED
@@ -1,12 +1,12 @@
1
<?php /*
2
Example template for use with post thumbnails
3
- Requires WordPress 2.9 and a theme which supports post thumbnails
4
Author: mitcho (Michael Yoshitaka Erlewine)
5
*/ ?>
6
<h3>Related Photos</h3>
7
- <?php if ($related_query->have_posts()):?>
8
<ol>
9
- <?php while ($related_query->have_posts()) : $related_query->the_post(); ?>
10
<?php if (has_post_thumbnail()):?>
11
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail(); ?></a></li>
12
<?php endif; ?>
1
<?php /*
2
Example template for use with post thumbnails
3
+ Requires a theme which supports post thumbnails
4
Author: mitcho (Michael Yoshitaka Erlewine)
5
*/ ?>
6
<h3>Related Photos</h3>
7
+ <?php if (have_posts()):?>
8
<ol>
9
+ <?php while (have_posts()) : the_post(); ?>
10
<?php if (has_post_thumbnail()):?>
11
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail(); ?></a></li>
12
<?php endif; ?>
yarpp-templates/yarpp-template-wpml.php CHANGED
@@ -9,9 +9,9 @@ if (function_exists("icl_register_string")) {
9
}
10
11
?><h3><?php echo (function_exists("icl_t") ? icl_t("Yet Another Related Posts Plugin","related posts header","Related Posts") : "Related Posts B") ?></h3>
12
- <?php if ($related_query->have_posts()):?>
13
<ol>
14
- <?php while ($related_query->have_posts()) : $related_query->the_post(); ?>
15
<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
16
<?php endwhile; ?>
17
</ol>
9
}
10
11
?><h3><?php echo (function_exists("icl_t") ? icl_t("Yet Another Related Posts Plugin","related posts header","Related Posts") : "Related Posts B") ?></h3>
12
+ <?php if (have_posts()):?>
13
<ol>
14
+ <?php while (have_posts()) : the_post(); ?>
15
<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
16
<?php endwhile; ?>
17
</ol>
yarpp.php CHANGED
@@ -3,22 +3,25 @@
3
Plugin Name: Yet Another Related Posts Plugin
4
Plugin URI: http://yarpp.org/
5
Description: Returns a list of related entries based on a unique algorithm for display on your blog and RSS feeds. A templating feature allows customization of the display.
6
- Version: 3.4b5
7
Author: mitcho (Michael Yoshitaka Erlewine)
8
Author URI: http://mitcho.com/
9
Donate link: http://tinyurl.com/donatetomitcho
10
*/
11
12
- define('YARPP_VERSION', '3.4b5');
13
define('YARPP_DIR', dirname(__FILE__));
14
define('YARPP_NO_RELATED', ':(');
15
define('YARPP_RELATED', ':)');
16
define('YARPP_NOT_CACHED', ':/');
17
define('YARPP_DONT_RUN', 'X(');
18
19
require_once(YARPP_DIR.'/includes.php');
20
require_once(YARPP_DIR.'/related-functions.php');
21
require_once(YARPP_DIR.'/template-functions.php');
22
23
// New in 3.2: load YARPP cache engine
24
// By default, this is tables, which uses custom db tables.
@@ -31,38 +34,9 @@ if (!defined('YARPP_CACHE_TYPE'))
31
add_action( 'init', 'yarpp_init' );
32
function yarpp_init() {
33
global $yarpp;
34
-
35
- if ( isset($_REQUEST['yarpp_debug']) )
36
- $yarpp->debug = true;
37
-
38
- register_activation_hook( __FILE__, 'yarpp_activate' );
39
-
40
- // register text domain
41
- load_plugin_textdomain( 'yarpp', false, dirname(plugin_basename(__FILE__)) . '/lang' );
42
-
43
- // setup admin
44
- add_action('admin_menu','yarpp_admin_menu');
45
- // new in 3.3: properly enqueue scripts for admin:
46
- add_action( 'admin_enqueue_scripts', 'yarpp_admin_enqueue' );
47
- // new in 3.3: set default meta boxes to show:
48
- add_filter( 'default_hidden_meta_boxes', 'yarpp_default_hidden_meta_boxes', 10, 2 );
49
-
50
- // automatic display hooks:
51
- add_filter('the_content','yarpp_default',1200);
52
- add_filter('the_content_rss','yarpp_rss',600);
53
- add_filter('the_excerpt_rss','yarpp_rss_excerpt',600);
54
-
55
- // new in 3.0: add meta box
56
- add_action( 'admin_menu', 'yarpp_add_metabox');
57
-
58
- // sets the score override flag.
59
- add_action('parse_query','yarpp_set_score_override_flag');
60
-
61
$yarpp = new YARPP;
62
63
// new in 3.3: include BlogGlue meta box
64
if ( file_exists( YARPP_DIR . '/blogglue.php' ) )
65
include_once( YARPP_DIR . '/blogglue.php' );
66
}
67
- // new in 2.0: add as a widget
68
- add_action('widgets_init', 'widget_yarpp_init');
3
Plugin Name: Yet Another Related Posts Plugin
4
Plugin URI: http://yarpp.org/
5
Description: Returns a list of related entries based on a unique algorithm for display on your blog and RSS feeds. A templating feature allows customization of the display.
6
+ Version: 3.4b6
7
Author: mitcho (Michael Yoshitaka Erlewine)
8
Author URI: http://mitcho.com/
9
Donate link: http://tinyurl.com/donatetomitcho
10
*/
11
12
+ define('YARPP_VERSION', '3.4b6');
13
define('YARPP_DIR', dirname(__FILE__));
14
define('YARPP_NO_RELATED', ':(');
15
define('YARPP_RELATED', ':)');
16
define('YARPP_NOT_CACHED', ':/');
17
define('YARPP_DONT_RUN', 'X(');
18
19
+ require_once(YARPP_DIR.'/class-core.php');
20
require_once(YARPP_DIR.'/includes.php');
21
+ require_once(YARPP_DIR.'/magic.php');
22
require_once(YARPP_DIR.'/related-functions.php');
23
require_once(YARPP_DIR.'/template-functions.php');
24
+ require_once(YARPP_DIR.'/class-widget.php');
25
26
// New in 3.2: load YARPP cache engine
27
// By default, this is tables, which uses custom db tables.
34
add_action( 'init', 'yarpp_init' );
35
function yarpp_init() {
36
global $yarpp;
37
$yarpp = new YARPP;
38
39
// new in 3.3: include BlogGlue meta box
40
if ( file_exists( YARPP_DIR . '/blogglue.php' ) )
41
include_once( YARPP_DIR . '/blogglue.php' );
42
}