Contextual Related Posts - Version 1.0.1

Version Description

Download this release

Release Info

Developer Ajay
Plugin Icon 128x128 Contextual Related Posts
Version 1.0.1
Comparing to
See all releases

Version 1.0.1

Files changed (4) hide show
  1. admin.inc.php +116 -0
  2. contextual-related-posts.php +144 -0
  3. readme.txt +44 -0
  4. uninstall.php +11 -0
admin.inc.php ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**********************************************************************
3
+ * Admin Page *
4
+ *********************************************************************/
5
+ function crp_options() {
6
+
7
+ global $wpdb;
8
+ $poststable = $wpdb->posts;
9
+
10
+ $crp_settings = crp_read_options();
11
+
12
+ if($_POST['crp_save']){
13
+ $crp_settings[title] = ($_POST['title']);
14
+ $crp_settings[limit] = ($_POST['limit']);
15
+ $crp_settings[add_to_content] = (($_POST['add_to_content']) ? true : false);
16
+ $crp_settings[add_to_feed] = (($_POST['add_to_feed']) ? true : false);
17
+
18
+ update_option('ald_crp_settings', $crp_settings);
19
+
20
+ $str = '<div id="message" class="updated fade"><p>'. __('Options saved successfully.','ald_crp_plugin') .'</p></div>';
21
+ echo $str;
22
+ }
23
+
24
+ if ($_POST['crp_default']){
25
+ delete_option('ald_crp_settings');
26
+ $crp_settings = crp_default_options();
27
+ update_option('ald_crp_settings', $crp_settings);
28
+
29
+ $str = '<div id="message" class="updated fade"><p>'. __('Options set to Default.','ald_crp_plugin') .'</p></div>';
30
+ echo $str;
31
+ }
32
+ ?>
33
+
34
+ <div class="wrap">
35
+ <h2>Contextual Related Posts </h2>
36
+ <div style="border: #ccc 1px solid; padding: 10px">
37
+ <fieldset class="options">
38
+ <legend>
39
+ <h3>
40
+ <?php _e('Support the Development','ald_crp_plugin'); ?>
41
+ </h3>
42
+ </legend>
43
+ <p>
44
+ <?php _e('If you find ','ald_crp_plugin'); ?>
45
+ <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a>
46
+ <?php _e('useful, please do','ald_crp_plugin'); ?>
47
+ <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&amp;business=donate@ajaydsouza.com&amp;item_name=Related%20Posts%20(From%20WP-Admin)&amp;no_shipping=1&amp;return=http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/&amp;cancel_return=http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/&amp;cn=Note%20to%20Author&amp;tax=0&amp;currency_code=USD&amp;bn=PP-DonationsBF&amp;charset=UTF-8" title="Donate via PayPal"><?php _e('drop in your contribution','ald_crp_plugin'); ?></a>.
48
+ (<a href="http://ajaydsouza.com/donate/"><?php _e('Some reasons why you should.','ald_crp_plugin'); ?></a>)</p>
49
+ </fieldset>
50
+ </div>
51
+ <form method="post" id="crp_options" name="crp_options" style="border: #ccc 1px solid; padding: 10px">
52
+ <fieldset class="options">
53
+ <legend>
54
+ <h3>
55
+ <?php _e('Options:','ald_crp_plugin'); ?>
56
+ </h3>
57
+ </legend>
58
+ <p>
59
+ <label>
60
+ <?php _e('Number of related posts to display: ','ald_crp_plugin'); ?>
61
+ <input type="textbox" name="limit" id="limit" value="<?php echo stripslashes($crp_settings[limit]); ?>">
62
+ </label>
63
+ </p>
64
+ <p>
65
+ <label>
66
+ <?php _e('Title of related posts: ','ald_crp_plugin'); ?>
67
+ <input type="textbox" name="title" id="title" value="<?php echo stripslashes($crp_settings[title]); ?>">
68
+ </label>
69
+ </p>
70
+ <p>
71
+ <label>
72
+ <input type="checkbox" name="add_to_content" id="add_to_content" <?php if ($crp_settings[add_to_content]) echo 'checked="checked"' ?> />
73
+ <?php _e('Add related posts to the post content on single pages. <br />If you choose to disable this, please add <code>&lt;?php if(function_exists(\'ald_crp\')) echo_ald_crp(); ?&gt;</code> to your template file where you want it displayed','ald_crp_plugin'); ?>
74
+ </label>
75
+ </p>
76
+ <p>
77
+ <label>
78
+ <input type="checkbox" name="add_to_feed" id="add_to_feed" <?php if ($crp_settings[add_to_feed]) echo 'checked="checked"' ?> />
79
+ <?php _e('Add related posts to feed','ald_crp_plugin'); ?>
80
+ </label>
81
+ </p>
82
+ <p>
83
+ <input type="submit" name="crp_save" id="crp_save" value="Save Options" style="border:#00CC00 1px solid" />
84
+ <input name="crp_default" type="submit" id="crp_default" value="Default Options" style="border:#FF0000 1px solid" onclick="if (!confirm('<?php _e('Do you want to set options to Default? If you don\'t have a copy of the username, please hit Cancel and copy it first.','ald_crp_plugin'); ?>')) return false;" />
85
+ </p>
86
+ </fieldset>
87
+ </form>
88
+ </div>
89
+ <?php
90
+
91
+ }
92
+
93
+
94
+ function crp_adminmenu() {
95
+ if (function_exists('current_user_can')) {
96
+ // In WordPress 2.x
97
+ if (current_user_can('manage_options')) {
98
+ $crp_is_admin = true;
99
+ }
100
+ } else {
101
+ // In WordPress 1.x
102
+ global $user_ID;
103
+ if (user_can_edit_user($user_ID, 0)) {
104
+ $crp_is_admin = true;
105
+ }
106
+ }
107
+
108
+ if ((function_exists('add_options_page'))&&($crp_is_admin)) {
109
+ add_options_page(__("Related Posts", 'myald_crp_plugin'), __("Related Posts", 'myald_crp_plugin'), 9, 'crp_options', 'crp_options');
110
+ }
111
+ }
112
+
113
+
114
+ add_action('admin_menu', 'crp_adminmenu');
115
+
116
+ ?>
contextual-related-posts.php ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Contextual Related Posts
4
+ Version: 1.0.1
5
+ Plugin URI: http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/
6
+ Description: Show user defined number of contextually related posts. Based on the plugin by <a href="http://weblogtoolscollection.com">Mark Ghosh</a>. <a href="options-general.php?page=crp_options">Configure...</a>
7
+ Author: Ajay D'Souza
8
+ Author URI: http://ajaydsouza.com/
9
+ */
10
+
11
+ if (!defined('ABSPATH')) die("Aren't you supposed to come here via WP-Admin?");
12
+
13
+ function ald_crp_init() {
14
+ load_plugin_textdomain('myald_crp_plugin', PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)));
15
+ }
16
+ add_action('init', 'ald_crp_init');
17
+
18
+ define('ALD_crp_DIR', dirname(__FILE__));
19
+
20
+ /*********************************************************************
21
+ * Main Function (Do not edit) *
22
+ ********************************************************************/
23
+ function ald_crp() {
24
+ global $wpdb, $post, $single;
25
+ $poststable = $wpdb->posts;
26
+ $crp_settings = crp_read_options();
27
+ $limit = $crp_settings['limit'];
28
+
29
+ // Make sure the post is not from the future
30
+ $time_difference = get_settings('gmt_offset');
31
+ $now = gmdate("Y-m-d H:i:s",(time()+($time_difference*3600)));
32
+
33
+ $stuff = addslashes($post->post_title);
34
+ $sql = "SELECT ID,post_title,post_content,post_excerpt,post_date,"
35
+ . "MATCH(post_title,post_content) AGAINST ('$stuff') AS score "
36
+ . "FROM $poststable WHERE "
37
+ . "MATCH (post_title,post_content) AGAINST ('$stuff') "
38
+ . "AND post_date <= '$now' "
39
+ . "AND post_status = 'publish' "
40
+ . "AND id != $post->ID "
41
+ . "LIMIT 0,$limit";
42
+
43
+ $search_counter = 0;
44
+ $searches = $wpdb->get_results($sql);
45
+
46
+ $output = '<div id="crp_related">'.$crp_settings['title'];
47
+
48
+ if($searches){
49
+ $output .= '<ul>';
50
+ foreach($searches as $search) {
51
+ $title = trim(stripslashes($search->post_title));
52
+ if ($search_counter <= $limit) {
53
+ $output .= '<li><a href="'.get_permalink($search->ID).'" rel="bookmark">'.$title.'</a></li>';
54
+ } //end of search_counter loop
55
+ $search_counter++;
56
+ } //end of foreach loop
57
+ $output .= '</ul>';
58
+ }else{
59
+ $output .= '<p>'.__('No related posts found').'</p>';
60
+ }
61
+
62
+ $output .= '</div><br/><br/>';
63
+
64
+ return $output;
65
+ }
66
+
67
+ function ald_crp_content($content) {
68
+
69
+ global $single;
70
+ $crp_settings = crp_read_options();
71
+ $output = ald_crp();
72
+
73
+ if((is_feed())&&($crp_settings['add_to_feed'])) {
74
+ return $content.$output;
75
+ } elseif(($single)&&($crp_settings['add_to_content'])) {
76
+ return $content.$output;
77
+ } else {
78
+ return $content;
79
+ }
80
+ }
81
+ add_filter('the_content', 'ald_crp_content');
82
+
83
+ function echo_ald_crp() {
84
+ $output = ald_crp();
85
+ echo $output;
86
+ }
87
+
88
+ // Default Options
89
+ function crp_default_options() {
90
+ $title = __('<h2>Related Posts:</h2>');
91
+
92
+ $crp_settings = Array (
93
+ title => $title, // Add before the content
94
+ add_to_content => true, // Add related posts to content (only on single pages)
95
+ add_to_feed => true, // Add related posts to feed
96
+ limit => '5' // How many posts to display?
97
+ );
98
+ return $crp_settings;
99
+ }
100
+
101
+ // Function to read options from the database
102
+ function crp_read_options()
103
+ {
104
+ $crp_settings_changed = false;
105
+
106
+ //ald_crp_activate();
107
+
108
+ $defaults = crp_default_options();
109
+
110
+ $crp_settings = array_map('stripslashes',(array)get_option('ald_crp_settings'));
111
+ unset($crp_settings[0]); // produced by the (array) casting when there's nothing in the DB
112
+
113
+ foreach ($defaults as $k=>$v) {
114
+ if (!isset($crp_settings[$k]))
115
+ $crp_settings[$k] = $v;
116
+ $crp_settings_changed = true;
117
+ }
118
+ if ($crp_settings_changed == true)
119
+ update_option('ald_crp_settings', $crp_settings);
120
+
121
+ return $crp_settings;
122
+
123
+ }
124
+
125
+ // Create full text index
126
+ function ald_crp_activate() {
127
+ global $wpdb;
128
+
129
+ $wpdb->hide_errors();
130
+ $wpdb->query('ALTER TABLE '.$wpdb->posts.' ENGINE = MYISAM;');
131
+ $wpdb->query('ALTER TABLE '.$wpdb->posts.' ADD FULLTEXT crp_related (post_title, post_content);');
132
+ $wpdb->show_errors();
133
+ }
134
+ if (function_exists('register_activation_hook')) {
135
+ register_activation_hook(__FILE__,'ald_crp_activate');
136
+ }
137
+
138
+ // This function adds an Options page in WP Admin
139
+ if (is_admin() || strstr($_SERVER['PHP_SELF'], 'wp-admin/')) {
140
+ require_once(ALD_crp_DIR . "/admin.inc.php");
141
+ }
142
+
143
+
144
+ ?>
readme.txt ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Contextual Related Posts ===
2
+ Tags: related posts, similar posts
3
+ Contributors: Ajay D'Souza, Mark Ghosh
4
+ Donate link: http://ajaydsouza.com/donate/
5
+ Stable tag: trunk
6
+ Requires at least: 1.5
7
+ Tested up to: 2.7
8
+
9
+
10
+ Show user defined number of contextually related posts
11
+
12
+ == Description ==
13
+
14
+ Display a list of contextually related posts for the current post. You can select the number of posts to display and if you want to automatically display the related posts in your content / feed.
15
+
16
+ == Installation ==
17
+
18
+ 1. Download the plugin
19
+
20
+ 2. Extract the contents of contextual-related-posts.zip to wp-content/plugins/ folder. You should get a folder called contextual-related-posts.
21
+
22
+ 4. Activate the Plugin in WP-Admin.
23
+
24
+ 5. Goto Settings > Related Posts to configure
25
+
26
+
27
+ == Frequently Asked Questions ==
28
+
29
+ = What are the requirements for this plugin? =
30
+
31
+ WordPress 2.0 or above
32
+
33
+
34
+ = Can I customize what is displayed? =
35
+
36
+ All options can be customized within the Options page in WP-Admin itself
37
+
38
+ For more information, please visit http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/
39
+
40
+ = Support =
41
+
42
+ All questions need to be redirected at the Support Forum at http://ajaydsouza.org/
43
+
44
+ No support questions will be entertained in the comments or via email.
uninstall.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( !defined('ABSPATH') && !defined('WP_UNINSTALL_PLUGIN') ) {
3
+ exit();
4
+ }
5
+ global $wpdb;
6
+ $poststable = $wpdb->posts;
7
+
8
+ $sql = "ALTER TABLE $poststable DROP INDEX crp_related";
9
+ $wpdb->query($sql);
10
+ delete_option('ald_crp_settings');
11
+ ?>