I Recommend This - Version 1.4

Version Description

Download this release

Release Info

Developer hchouhan
Plugin Icon 128x128 I Recommend This
Version 1.4
Comparing to
See all releases

Code changes from version 1.3.1 to 1.4

Files changed (3) hide show
  1. i-recommend-this.php +365 -0
  2. readme.txt +5 -2
  3. recommend.php +6 -3
i-recommend-this.php CHANGED
@@ -3,6 +3,371 @@
3
  Plugin Name: I Recommend This
4
  Plugin URI: http://www.harishchouhan.com/personal-projects/i-recommend-this/
5
  Description: This plugin allows your visitors to simply recommend or like your posts instead of commment it.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  Version: 1.3.1
7
  Author: Harish Chouhan
8
  Author URI: http://www.harishchouhan.com
3
  Plugin Name: I Recommend This
4
  Plugin URI: http://www.harishchouhan.com/personal-projects/i-recommend-this/
5
  Description: This plugin allows your visitors to simply recommend or like your posts instead of commment it.
6
+ Version: 1.4
7
+ Author: Harish Chouhan
8
+ Author URI: http://www.harishchouhan.com
9
+
10
+ Copyright 2012 Harish Chouhan (email : me@harishchouhan.com)
11
+
12
+ This program is free software; you can redistribute it and/or modify
13
+ it under the terms of the GNU General Public License as published by
14
+ the Free Software Foundation; either version 2 of the License, or
15
+ (at your option) any later version.
16
+
17
+ This program is distributed in the hope that it will be useful,
18
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
+ GNU General Public License for more details.
21
+ */
22
+
23
+
24
+
25
+ #### INSTALL PROCESS ####
26
+ $irt_dbVersion = "1.0";
27
+
28
+ function setOptionsIRT() {
29
+ global $wpdb;
30
+ global $irt_dbVersion;
31
+
32
+ $table_name = $wpdb->prefix . "irecommendthis_votes";
33
+ if($wpdb->get_var("show tables recommend '$table_name'") != $table_name) {
34
+ $sql = "CREATE TABLE " . $table_name . " (
35
+ id MEDIUMINT(9) NOT NULL AUTO_INCREMENT,
36
+ time TIMESTAMP NOT NULL,
37
+ post_id BIGINT(20) NOT NULL,
38
+ ip VARCHAR(15) NOT NULL,
39
+ UNIQUE KEY id (id)
40
+ );";
41
+
42
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
43
+ dbDelta($sql);
44
+
45
+ add_option("irt_dbVersion", $irt_dbVersion);
46
+ }
47
+
48
+ add_option('irt_jquery', '1', '', 'yes');
49
+ add_option('irt_onPage', '1', '', 'yes');
50
+ add_option('irt_textOrNotext', 'notext', '', 'yes');
51
+ add_option('irt_text', 'I recommend This', '', 'yes');
52
+ add_option('irt_textOnclick', 'recommends', '', 'yes');
53
+
54
+ }
55
+
56
+ register_activation_hook(__FILE__, 'setOptionsIRT');
57
+
58
+ function unsetOptionsIRT() {
59
+ global $wpdb;
60
+ $wpdb->query("DROP TABLE IF EXISTS ".$wpdb->prefix."irecommendthis_votes");
61
+
62
+ delete_option('irt_jquery');
63
+ delete_option('irt_onPage');
64
+ delete_option('irt_textOrNotext');
65
+ delete_option('irt_text');
66
+ delete_option('irt_textOnclick');
67
+ delete_option('most_recommended_posts');
68
+ delete_option('irt_dbVersion');
69
+ }
70
+
71
+ register_uninstall_hook(__FILE__, 'unsetOptionsIRT');
72
+ ####
73
+
74
+
75
+ #### ADMIN OPTIONS ####
76
+ function IRecommendThisAdminMenu() {
77
+ add_options_page('I Recommend This', 'I Recommend This', '10', 'IRecommendThisAdminMenu', 'IRecommendThisAdminContent');
78
+ }
79
+ add_action('admin_menu', 'IRecommendThisAdminMenu');
80
+
81
+ function IRecommendThisAdminRegisterSettings() { // whitelist options
82
+ register_setting( 'irt_options', 'irt_jquery' );
83
+ register_setting( 'irt_options', 'irt_onPage' );
84
+ register_setting( 'irt_options', 'irt_textOrNotext' );
85
+ register_setting( 'irt_options', 'irt_text' );
86
+ register_setting( 'irt_options', 'irt_textOnclick' );
87
+ }
88
+ add_action('admin_init', 'IRecommendThisAdminRegisterSettings');
89
+
90
+ function IRecommendThisAdminContent() {
91
+ ?>
92
+ <div class="wrap">
93
+ <h2>"I Recommend This" Options</h2>
94
+ <br class="clear" />
95
+
96
+ <div id="poststuff" class="ui-sortable meta-box-sortables">
97
+ <div id="irecommendthisoptions" class="postbox">
98
+ <h3><?php _e('Configuration'); ?></h3>
99
+ <div class="inside">
100
+ <form method="post" action="options.php">
101
+ <?php settings_fields('irt_options'); ?>
102
+ <table class="form-table">
103
+ <tr valign="top">
104
+ <th scope="row"><label for="irt_jquery"><?php _e('jQuery framework', 'i-recommend-this'); ?></label></th>
105
+ <td>
106
+ <select name="irt_jquery" id="irt_jquery">
107
+ <?php echo get_option('irt_jquery') == '1' ? '<option value="1" selected="selected">'.__('Enabled', 'i-recommend-this').'</option><option value="0">'.__('Disabled', 'i-recommend-this').'</option>' : '<option value="1">'.__('Enabled', 'i-recommend-this').'</option><option value="0" selected="selected">'.__('Disabled', 'i-recommend-this').'</option>'; ?>
108
+ </select>
109
+ <span class="description"><?php _e('Disable it if you already have the jQuery framework enabled in your theme.', 'i-recommend-this'); ?></span>
110
+ </td>
111
+ </tr>
112
+ <tr valign="top">
113
+ <th scope="row"><legend><?php _e('No Text or Text?', 'i-recommend-this'); ?></legend></th>
114
+ <td>
115
+ <label for="irt_textOrNotext" style="padding:3px 20px 0 0; margin-right:20px;">
116
+ <?php echo get_option('irt_textOrNotext') == 'notext' ? '<input type="radio" name="irt_textOrNotext" id="irt_textOrNotext" value="image" checked="checked">' : '<input type="radio" name="irt_textOrNotext" id="irt_textOrNotext" value="notext">'; ?> No Text
117
+ </label>
118
+ <label for="irt_text">
119
+ <?php echo get_option('irt_textOrNotext') == 'text' ? '<input type="radio" name="irt_textOrNotext" id="irt_textOrNotext" value="text" checked="checked">' : '<input type="radio" name="irt_textOrNotext" id="irt_textOrNotext" value="text">'; ?>
120
+ <input type="text" name="irt_text" id="irt_text" value="<?php echo get_option('irt_text'); ?>" />
121
+ </label>
122
+ </td>
123
+ </tr>
124
+ <tr valign="top">
125
+ <th scope="row"><legend><?php _e('Text displayed on click', 'i-recommend-this'); ?></legend></th>
126
+ <td>
127
+ <label for="irt_textOnclick">
128
+ <input type="text" name="irt_textOnclick" id="irt_textOnclick" value="<?php echo get_option('irt_textOnclick'); ?>" />
129
+ </label>
130
+ </td>
131
+ </tr>
132
+ <tr valign="top">
133
+ <th scope="row"><legend><?php _e('Automatic display', 'i-recommend-this'); ?></legend></th>
134
+ <td>
135
+ <label for="irt_onPage">
136
+ <?php echo get_option('irt_onPage') == '1' ? '<input type="checkbox" name="irt_onPage" id="ilt_onPage" value="1" checked="checked">' : '<input type="checkbox" name="irt_onPage" id="irt_onPage" value="1">'; ?>
137
+ <?php _e('<strong>On all posts</strong> (home, archives, search) at the bottom of the post', 'i-recommend-this'); ?>
138
+ </label>
139
+ <p class="description"><?php _e('If you disable this option, you have to put manually the code', 'i-recommend-this'); ?><code>&lt;?php if(function_exists(getIRecommendThis)) getIRecommendThis('get'); ?&gt;</code> <?php _e('wherever you want in your template.', 'i-recommend-this'); ?></p>
140
+ </td>
141
+ </tr>
142
+ <tr valign="top">
143
+ <th scope="row"><input class="button-primary" type="submit" name="Save" value="<?php _e('Save Options', 'i-recommend-this'); ?>" /></th>
144
+ <td></td>
145
+ </tr>
146
+ </table>
147
+ </form>
148
+ </div>
149
+ </div>
150
+ </div>
151
+ </div>
152
+ <?php
153
+ }
154
+ ####
155
+
156
+
157
+ #### WIDGET ####
158
+ function most_recommended_posts($numberOf, $before, $after, $show_count, $post_type="post", $raw=false) {
159
+ global $wpdb;
160
+
161
+ $request = "SELECT * FROM $wpdb->posts, $wpdb->postmeta";
162
+ $request .= " WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id";
163
+ $request .= " AND post_status='publish' AND post_type='$post_type' AND meta_key='_recommended'";
164
+ $request .= " ORDER BY $wpdb->postmeta.meta_value+0 DESC LIMIT $numberOf";
165
+ $posts = $wpdb->get_results($request);
166
+
167
+ if ($raw):
168
+ return $posts;
169
+ else:
170
+ foreach ($posts as $item) {
171
+ $post_title = stripslashes($item->post_title);
172
+ $permalink = get_permalink($item->ID);
173
+ $post_count = $item->meta_value;
174
+ echo $before.'<a href="' . $permalink . '" title="' . $post_title.'" rel="nofollow">' . $post_title . '</a>';
175
+ echo $show_count == '1' ? ' ('.$post_count.')' : '';
176
+ echo $after;
177
+ }
178
+ endif;
179
+ }
180
+
181
+ /**
182
+ * Mini counter widget
183
+ */
184
+ function most_recommended_recommend_widget(){
185
+ global $wpdb;
186
+ $post_ID = get_the_ID();
187
+ $ip = $_SERVER['REMOTE_ADDR'];
188
+
189
+ $liked = get_post_meta($post_ID, '_recommended', true) != '' ? get_post_meta($post_ID, '_recommended', true) : '0';
190
+ $voteStatusByIp = $wpdb->get_var("SELECT COUNT(*) FROM ".$wpdb->prefix."irecommendthis_votes WHERE post_id = '$post_ID' AND ip = '$ip'");
191
+
192
+
193
+ $return='<div class="irt_counter_widget">';
194
+ if (!isset($_COOKIE['recommended-'.$post_ID]) && $voteStatusByIp == 0) {
195
+ $return.='<p class="irt_counter_widget_btn"><a onclick="recommendThis('.$post_ID.');">Vote!</a></p>';
196
+ }
197
+ else {
198
+ $return.='<p class="irt_counter_widget_btn recommended">Voted</p>';
199
+ }
200
+ $return.= '<p class="irt_counter_widget_counter" id="'.$post_ID.'">'.$recommended.' lights</p>';
201
+ $return.= '</div>';
202
+ echo $return;
203
+ }
204
+
205
+ /**
206
+ * SIDEBAR WIDGET
207
+ */
208
+ function add_widget_most_recommended_posts() {
209
+ function widget_most_recommended_posts($args) {
210
+ extract($args);
211
+ $options = get_option("most_recommended_posts");
212
+ if (!is_array( $options )) {
213
+ $options = array(
214
+ 'title' => 'Most recommended posts',
215
+ 'number' => '5',
216
+ 'show_count' => '0'
217
+ );
218
+ }
219
+ $title = $options['title'];
220
+ $numberOf = $options['number'];
221
+ $show_count = $options['show_count'];
222
+
223
+ echo $before_widget;
224
+ echo $before_title . $title . $after_title;
225
+ echo '<ul class="mostrecommendedposts">';
226
+
227
+ most_recommended_posts($numberOf, '<li>', '</li>', $show_count);
228
+
229
+ echo '</ul>';
230
+ echo $after_widget;
231
+ }
232
+ wp_register_sidebar_widget('most_recommended_posts', 'Most recommended posts', 'widget_most_recommended_posts');
233
+
234
+ function options_widget_most_recommended_posts() {
235
+ $options = get_option("most_recommended_posts");
236
+
237
+ if (!is_array( $options )) {
238
+ $options = array(
239
+ 'title' => 'Most recommended posts',
240
+ 'number' => '5',
241
+ 'show_count' => '0'
242
+ );
243
+ }
244
+
245
+ if ($_POST['mrp-submit']) {
246
+ $options['title'] = htmlspecialchars($_POST['mrp-title']);
247
+ $options['number'] = htmlspecialchars($_POST['mrp-number']);
248
+ $options['show_count'] = $_POST['mrp-show-count'];
249
+ if ( $options['number'] > 15) { $options['number'] = 15; }
250
+
251
+ update_option("most_recommended_posts", $options);
252
+ }
253
+ ?>
254
+ <p><label for="mrp-title"><?php _e('Title:', 'i-recommend-this'); ?><br />
255
+ <input class="widefat" type="text" id="mrp-title" name="mrp-title" value="<?php echo $options['title'];?>" /></label></p>
256
+
257
+ <p><label for="mrp-number"><?php _e('Number of posts to show:', 'i-recommend-this'); ?><br />
258
+ <input type="text" id="mrp-number" name="mrp-number" style="width: 25px;" value="<?php echo $options['number'];?>" /> <small>(max. 15)</small></label></p>
259
+
260
+ <p><label for="mrp-show-count"><input type="checkbox" id="mrp-show-count" name="mrp-show-count" value="1"<?php if($options['show_count'] == '1') echo 'checked="checked"'; ?> /> <?php _e('Show post count', 'i-recommend-this'); ?></label></p>
261
+
262
+ <input type="hidden" id="mrp-submit" name="mrp-submit" value="1" />
263
+ <?php
264
+ }
265
+ wp_register_widget_control('most_recommended_posts', 'Most recommended posts', 'options_widget_most_recommended_posts');
266
+ }
267
+
268
+ add_action('init', 'add_widget_most_recommended_posts');
269
+ ####
270
+
271
+
272
+ #### FRONT-END VIEW ####
273
+ function getIRecommendThis($arg) {
274
+ global $wpdb;
275
+ $post_ID = get_the_ID();
276
+ $ip = $_SERVER['REMOTE_ADDR'];
277
+
278
+ $recommended = get_post_meta($post_ID, '_recommended', true) != '' ? get_post_meta($post_ID, '_recommended', true) : '0';
279
+ $voteStatusByIp = $wpdb->get_var("SELECT COUNT(*) FROM ".$wpdb->prefix."irecommendthis_votes WHERE post_id = '$post_ID' AND ip = '$ip'");
280
+
281
+ /*
282
+ if (!isset($_COOKIE['recommended-'.$post_ID]) && $voteStatusByIp == 0) {
283
+ //$counter = '<a onclick="likeThis('.$post_ID.');">'.$liked.'';
284
+ //$counter = '<a onclick="likeThis('.$post_ID.');" class"image">'.$liked.'</a>';
285
+ $counter = $recommended;
286
+ $recommend_status = "";
287
+ }
288
+ else {
289
+ $counter = $recommended;
290
+ $recommend_status = "active";
291
+ }
292
+ */
293
+ if (!isset($_COOKIE['recommended-'.$post_ID]) && $voteStatusByIp == 0) {
294
+ if (get_option('irt_textOrNotext') == 'notext') {
295
+ $counter = '<a onclick="recommendThis('.$post_ID.');" class="recommendThis">'.$recommended.'</a>';
296
+ }
297
+ else {
298
+ $counter = '<a onclick="recommendThis('.$post_ID.');" class="recommendThis">'.$recommended.' - '.get_option('irt_text').'</a>';
299
+ }
300
+ }
301
+ else {
302
+ $counter = '<a onclick="return(false);" class="recommendThis active">'.$recommended.'</a>';
303
+ }
304
+ //END of modifed part
305
+
306
+
307
+ /*
308
+ $iRecommendThis = '<div id="iRecommendThis-'.$post_ID.'" class="iRecommendThis"><a onclick="recommendThis('.$post_ID.');" class="'.$recommend_status.'">';
309
+ $iRecommendThis .= '<span class="counter">'.$counter.'</span>';
310
+ $iRecommendThis .= '</a></div>';
311
+ */
312
+ $iRecommendThis = '<div id="iRecommendThis-'.$post_ID.'" class="iRecommendThis">';
313
+ $iRecommendThis .= $counter;
314
+ $iRecommendThis .= '</div>';
315
+
316
+ //END of modifed part
317
+ /*
318
+ if ($arg == 'put') {
319
+ return $iRecommendThis;
320
+ }
321
+ else {
322
+ echo $iRecommendThis;
323
+ }
324
+ }
325
+ */
326
+
327
+ if ($arg == 'put') {
328
+ return $iRecommendThis;
329
+ }
330
+ else if ($arg == 'count'){
331
+ echo $recommended;
332
+ }
333
+ else {
334
+ echo $iRecommendThis;
335
+ }
336
+ }
337
+ //END of modifed part
338
+
339
+ if (get_option('irt_onPage') == '1') {
340
+ function putIRecommendThis($content) {
341
+ if(!is_feed() && !is_page()) {
342
+ $content.= getIRecommendThis('put');
343
+ }
344
+ return $content;
345
+ }
346
+
347
+ add_filter('the_content', putIRecommendThis);
348
+ }
349
+
350
+ function enqueueScripts() {
351
+ if (get_option('irt_jquery') == '1') {
352
+ wp_enqueue_script('iRecommendThis', WP_PLUGIN_URL.'/i-recommend-this/js/i-recommend-this.js', array('jquery'));
353
+ }
354
+ else {
355
+ wp_enqueue_script('iRecommendThis', WP_PLUGIN_URL.'/i-recommend-this/js/i-recommend-this.js');
356
+ }
357
+ }
358
+
359
+ function addHeaderLinks() {
360
+ echo '<link rel="stylesheet" type="text/css" href="'.WP_PLUGIN_URL.'/i-recommend-this/css/i-recommend-this.css" media="screen" />'."\n";
361
+ echo '<script type="text/javascript">var blogUrl = \''.get_bloginfo('wpurl').'\'</script>'."\n";
362
+ }
363
+
364
+ add_action('init', enqueueScripts);
365
+ add_action('wp_head', addHeaderLinks);
366
+ ?><?php
367
+ /*
368
+ Plugin Name: I Recommend This
369
+ Plugin URI: http://www.harishchouhan.com/personal-projects/i-recommend-this/
370
+ Description: This plugin allows your visitors to simply recommend or like your posts instead of commment it.
371
  Version: 1.3.1
372
  Author: Harish Chouhan
373
  Author URI: http://www.harishchouhan.com
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.designerskiosk.com
4
  Tags: recommend, like, love, post, rate, rating, heart
5
  Requires at least: 3.0
6
  Tested up to: 3.2.2
7
- Stable tag: 1.3.1
8
  Last Updated: 2012-May-7
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -29,7 +29,7 @@ Please report any bugs you find via http://www.harishchouhan.com/personal-projec
29
 
30
  = Examples of how the plugin has been used =
31
 
32
- * [Harish's blog](http://www.harishchouhan.com/blog/)
33
  * [Designers Kiosk](http://www.designerskiosk.com)
34
 
35
 
@@ -60,6 +60,9 @@ You can also visit the [support center](http://www.harishchouhan.com/personal-pr
60
 
61
  == Changelog ==
62
 
 
 
 
63
  = 1.3
64
  * Removed 2 functions "register_widget_control()" & "register_sidebar_widget()" deprecated in version 2.8 with latest functions
65
 
4
  Tags: recommend, like, love, post, rate, rating, heart
5
  Requires at least: 3.0
6
  Tested up to: 3.2.2
7
+ Stable tag: 1.4
8
  Last Updated: 2012-May-7
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
29
 
30
  = Examples of how the plugin has been used =
31
 
32
+ * [Harish's blog](http://www.harishchouhan.com/blog/) - Please leave your suggestions here.
33
  * [Designers Kiosk](http://www.designerskiosk.com)
34
 
35
 
60
 
61
  == Changelog ==
62
 
63
+ = 1.4
64
+ * Added feature to display custom text when a post is liked.
65
+
66
  = 1.3
67
  * Removed 2 functions "register_widget_control()" & "register_sidebar_widget()" deprecated in version 2.8 with latest functions
68
 
recommend.php CHANGED
@@ -4,6 +4,7 @@ require_once '../../../wp-config.php';
4
  global $wpdb;
5
  $post_ID = $_POST['id'];
6
  $ip = $_SERVER['REMOTE_ADDR'];
 
7
  $recommend = get_post_meta($post_ID, '_recommended', true);
8
 
9
  if($post_ID != '') {
@@ -13,13 +14,15 @@ if($post_ID != '') {
13
  $recommendNew = $recommend + 1;
14
  update_post_meta($post_ID, '_recommended', $recommendNew);
15
 
16
- setcookie('liked-'.$post_ID, time(), time()+3600*24*365, '/');
17
  $wpdb->query("INSERT INTO ".$wpdb->prefix."irecommendthis_votes VALUES ('', NOW(), '$post_ID', '$ip')");
18
 
19
- echo $recommendNew.' recommends'; // .' lights' is added new
 
20
  }
21
  else {
22
- echo $recommend.' recommends'; // .' lights' is added new
 
23
  }
24
  }
25
  ?>
4
  global $wpdb;
5
  $post_ID = $_POST['id'];
6
  $ip = $_SERVER['REMOTE_ADDR'];
7
+ $irt_textOnclick = get_option('irt_textOnclick');
8
  $recommend = get_post_meta($post_ID, '_recommended', true);
9
 
10
  if($post_ID != '') {
14
  $recommendNew = $recommend + 1;
15
  update_post_meta($post_ID, '_recommended', $recommendNew);
16
 
17
+ setcookie('recommended-'.$post_ID, time(), time()+3600*24*365, '/');
18
  $wpdb->query("INSERT INTO ".$wpdb->prefix."irecommendthis_votes VALUES ('', NOW(), '$post_ID', '$ip')");
19
 
20
+ $return_text = $recommendNew . ' ' . $irt_textOnclick;
21
+ echo $return_text; //$recommendNew; //
22
  }
23
  else {
24
+ $return_text = $recommend . ' ' . $irt_textOnclick;
25
+ echo $return_text; //$recommendNew; //
26
  }
27
  }
28
  ?>