My favorites | Sign in
Project Home Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
<?php
/*
Plugin Name: I Like Dare
Description: Modified version of "I Like This" by Benoit "LeBen" Burgener
Version: 1.0 (based on I Like This 1.7.1)
Author: Mike Kasprzak

Copyright 2009 BENOIT LEBEN BURGENER (email : CONTACT@BENOITBURGENER.COM)

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/

#### LOAD TRANSLATIONS ####
load_plugin_textdomain('i-like-dare', 'wp-content/plugins/i-like-dare/lang/', 'i-like-dare/lang/');
####


#### INSTALL PROCESS ####
$ilt_dbVersion = "1.0";

// NOTE: plugin is named incorrectly, so this is never called
// so the index creation below I did by hand on Ludumdare.com
function setOptionsILT() {
global $wpdb;
global $ilt_dbVersion;

$table_name = $wpdb->prefix . "ilikethis_votes";
if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
$sql = "CREATE TABLE " . $table_name . " (
id MEDIUMINT(9) NOT NULL AUTO_INCREMENT,
time TIMESTAMP NOT NULL,
post_id BIGINT(20) NOT NULL,
ip VARCHAR(15) NOT NULL,
UNIQUE KEY id (id)
);";

require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);

add_option("ilt_dbVersion", $ilt_dbVersion);
}
if ($ilt_dbVersion != "1.1") {
$wpdb->get_results("create index idx_wp_ilikethis_votes_post_id on wp_ilikethis_votes (post_id)");
$wpdb->get_results("create index idx_wp_ilikethis_votes_ip on wp_ilikethis_votes (ip)");
update_option("ilt_dbVersion","1.1");
}

add_option('ilt_jquery', '1', '', 'yes');
add_option('ilt_onPage', '1', '', 'yes');
add_option('ilt_textOrImage', 'image', '', 'yes');
add_option('ilt_text', 'I like This', '', 'yes');
}

register_activation_hook(__FILE__, 'setOptionsILT');

function unsetOptionsILT() {
global $wpdb;
/* $wpdb->query("DROP TABLE IF EXISTS ".$wpdb->prefix."ilikethis_votes");

delete_option('ilt_jquery');
delete_option('ilt_onPage');
delete_option('ilt_textOrImage');
delete_option('ilt_text');
delete_option('most_liked_posts');
delete_option('ilt_dbVersion');*/
}

register_uninstall_hook(__FILE__, 'unsetOptionsILT');
####


#### ADMIN OPTIONS ####
function ILikeDareAdminMenu() {
add_options_page('I Like Dare', 'I Like Dare', '10', 'ILikeDareAdminMenu', 'ILikeDareAdminContent');
}
add_action('admin_menu', 'ILikeDareAdminMenu');

function ILikeDareAdminRegisterSettings() { // whitelist options
register_setting( 'ilt_options', 'ilt_jquery' );
register_setting( 'ilt_options', 'ilt_onPage' );
register_setting( 'ilt_options', 'ilt_textOrImage' );
register_setting( 'ilt_options', 'ilt_text' );
}
add_action('admin_init', 'ILikeDareAdminRegisterSettings');

function ILikeDareAdminContent() {
?>
<div class="wrap">
<h2>"I Like Dare" Options</h2>
<br class="clear" />

<div id="poststuff" class="ui-sortable meta-box-sortables">
<div id="ilikedareoptions" class="postbox">
<h3><?php _e('Configuration'); ?></h3>
<div class="inside">
<form method="post" action="options.php">
<?php settings_fields('ilt_options'); ?>
<table class="form-table">
<tr valign="top">
<th scope="row"><label for="ilt_jquery"><?php _e('jQuery framework', 'i-like-dare'); ?></label></th>
<td>
<select name="ilt_jquery" id="ilt_jquery">
<?php echo get_option('ilt_jquery') == '1' ? '<option value="1" selected="selected">'.__('Enabled', 'i-like-dare').'</option><option value="0">'.__('Disabled', 'i-like-dare').'</option>' : '<option value="1">'.__('Enabled', 'i-like-dare').'</option><option value="0" selected="selected">'.__('Disabled', 'i-like-dare').'</option>'; ?>
</select>
<span class="description"><?php _e('Disable it if you already have the jQuery framework enabled in your theme.', 'i-like-dare'); ?></span>
</td>
</tr>
<tr valign="top">
<th scope="row"><legend><?php _e('Image or text?', 'i-like-dare'); ?></legend></th>
<td>
<label for="ilt_textOrImage" style="padding:3px 20px 3px 0; margin-right:20px; background: url(<?php echo WP_PLUGIN_URL.'/i-like-dare/css/add.png'; ?>) no-repeat right center;">
<?php echo get_option('ilt_textOrImage') == 'image' ? '<input type="radio" name="ilt_textOrImage" id="ilt_textOrImage" value="image" checked="checked">' : '<input type="radio" name="ilt_textOrImage" id="ilt_textOrImage" value="image">'; ?>
</label>
<label for="ilt_text">
<?php echo get_option('ilt_textOrImage') == 'text' ? '<input type="radio" name="ilt_textOrImage" id="ilt_textOrImage" value="text" checked="checked">' : '<input type="radio" name="ilt_textOrImage" id="ilt_textOrImage" value="text">'; ?>
<input type="text" name="ilt_text" id="ilt_text" value="<?php echo get_option('ilt_text'); ?>" />
</label>
</td>
</tr>
<tr valign="top">
<th scope="row"><legend><?php _e('Automatic display', 'i-like-dare'); ?></legend></th>
<td>
<label for="ilt_onPage">
<?php echo get_option('ilt_onPage') == '1' ? '<input type="checkbox" name="ilt_onPage" id="ilt_onPage" value="1" checked="checked">' : '<input type="checkbox" name="ilt_onPage" id="ilt_onPage" value="1">'; ?>
<?php _e('<strong>On all posts</strong> (home, archives, search) at the bottom of the post', 'i-like-dare'); ?>
</label>
<p class="description"><?php _e('If you disable this option, you have to put manually the code', 'i-like-dare'); ?><code>&lt;?php if(function_exists(getILikeDare)) getILikeDare('get'); ?&gt;</code> <?php _e('wherever you want in your template.', 'i-like-dare'); ?></p>
</td>
</tr>
<tr valign="top">
<th scope="row"><input class="button-primary" type="submit" name="Save" value="<?php _e('Save Options', 'i-like-dare'); ?>" /></th>
<td></td>
</tr>
</table>
</form>
</div>
</div>
</div>

<div id="poststuff" class="ui-sortable meta-box-sortables">
<div id="ilikedareoptions" class="postbox">
<h3><?php _e('You like this plugin?'); ?></h3>
<div class="inside">
<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="benoit.burgener@gmail.com">
<input type="hidden" name="item_name" value="Wordpress plugin">
<input type="image" src="http://www.paypal.com/en_US/i/btn/btn_donate_SM.gif" border="0" name="submit">
</form>
</div>
</div>
</div>
</div>
<?php
}
####


#### WIDGET ####
/*
function most_liked_posts($numberOf, $before, $after, $show_count) {
global $wpdb;

$request = "SELECT ID, post_title, meta_value FROM $wpdb->posts, $wpdb->postmeta";
$request .= " WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id";
$request .= " AND post_status='publish' AND post_type='post' AND meta_key='_liked'";
$request .= " ORDER BY $wpdb->postmeta.meta_value+0 DESC LIMIT $numberOf";
$posts = $wpdb->get_results($request);

foreach ($posts as $post) {
$post_title = stripslashes($post->post_title);
$permalink = get_permalink($post->ID);
$post_count = $post->meta_value;

echo $before.'<a href="' . $permalink . '" title="' . $post_title.'" rel="nofollow">' . $post_title . '</a>';
echo $show_count == '1' ? ' ('.$post_count.')' : '';
echo $after;
}
}

function add_widget_most_liked_posts() {
function widget_most_liked_posts($args) {
extract($args);
$options = get_option("most_liked_posts");
if (!is_array( $options )) {
$options = array(
'title' => 'Most liked posts',
'number' => '5',
'show_count' => '0'
);
}
$title = $options['title'];
$numberOf = $options['number'];
$show_count = $options['show_count'];

echo $before_widget;
echo $before_title . $title . $after_title;
echo '<ul class="mostlikedposts">';

most_liked_posts($numberOf, '<li>', '</li>', $show_count);

echo '</ul>';
echo $after_widget;
}
register_sidebar_widget('Most liked posts', 'widget_most_liked_posts');

function options_widget_most_liked_posts() {
$options = get_option("most_liked_posts");

if (!is_array( $options )) {
$options = array(
'title' => 'Most liked posts',
'number' => '5',
'show_count' => '0'
);
}

if ($_POST['mlp-submit']) {
$options['title'] = htmlspecialchars($_POST['mlp-title']);
$options['number'] = htmlspecialchars($_POST['mlp-number']);
$options['show_count'] = $_POST['mlp-show-count'];
if ( $options['number'] > 15) { $options['number'] = 15; }

update_option("most_liked_posts", $options);
}
?>
<p><label for="mlp-title"><?php _e('Title:', 'i-like-dare'); ?><br />
<input class="widefat" type="text" id="mlp-title" name="mlp-title" value="<?php echo $options['title'];?>" /></label></p>

<p><label for="mlp-number"><?php _e('Number of posts to show:', 'i-like-dare'); ?><br />
<input type="text" id="mlp-number" name="mlp-number" style="width: 25px;" value="<?php echo $options['number'];?>" /> <small>(max. 15)</small></label></p>

<p><label for="mlp-show-count"><input type="checkbox" id="mlp-show-count" name="mlp-show-count" value="1"<?php if($options['show_count'] == '1') echo 'checked="checked"'; ?> /> <?php _e('Show post count', 'i-like-dare'); ?></label></p>

<input type="hidden" id="mlp-submit" name="mlp-submit" value="1" />
<?php
}
register_widget_control('Most liked posts', 'options_widget_most_liked_posts');
}

add_action('init', 'add_widget_most_liked_posts');
*/
####


#### FRONT-END VIEW ####
function getILikeDare($arg) {
global $wpdb;
$post_ID = get_the_ID();
$ip = $_SERVER['REMOTE_ADDR'];

$liked = get_post_meta($post_ID, '_liked', true) != '' ? get_post_meta($post_ID, '_liked', true) : '0';
// $voteStatusByIp = $wpdb->get_var("SELECT COUNT(*) FROM ".$wpdb->prefix."ilikethis_votes WHERE post_id = '$post_ID' AND ip = '$ip'");
$voteStatusByIp = 0;

if (!isset($_COOKIE['liked-'.$post_ID]) && $voteStatusByIp == 0) {
if (get_option('ilt_textOrImage') == 'image') {
$counter = '<a onclick="likeThis('.$post_ID.');" class="image">'.$liked.'</a>';
}
else {
$counter = $liked.' <a onclick="likeThis('.$post_ID.');">'.get_option('ilt_text').'</a>';
}
}
else {
$counter = $liked;
}

$iLikeThis = '<div id="iLikeThis-'.$post_ID.'" class="iLikeThis">';

if ( $liked == 0 ) {
$iLikeThis .= '<span class="counter-off">'.$counter.'</span>';
// $iLikeThis .= '<span class="counter" style="background:url(wp-content/plugins/i-like-dare/css/heart-none.png) center left no-repeat">'.$counter.'</span>';
}
else {
$iLikeThis .= '<span class="counter">'.$counter.'</span>';
}
$iLikeThis .= '</div>';

if ($arg == 'put') {
return $iLikeThis;
}
else {
echo $iLikeThis;
}
}

function getILikeThis($arg) {
return getILikeDare($arg);
}

if (get_option('ilt_onPage') == '1') {
function putILikeDare($content) {
if(!is_feed() && !is_page()) {
$content.= getILikeDare('put');
}
return $content;
}

add_filter('the_content', putILikeDare);
}

function enqueueScripts() {
if (get_option('ilt_jquery') == '1') {
wp_enqueue_script('iLikeThis', WP_PLUGIN_URL.'/i-like-dare/js/i-like-this.js', array('jquery'));
}
else {
wp_enqueue_script('iLikeThis', WP_PLUGIN_URL.'/i-like-dare/js/i-like-this.js');
}
}

function addHeaderLinks() {
echo '<link rel="stylesheet" type="text/css" href="'.WP_PLUGIN_URL.'/i-like-dare/css/i-like-this.css" media="screen" />'."\n";
echo '<script type="text/javascript">var blogUrl = \''.get_bloginfo('wpurl').'\'</script>'."\n";
}

add_action('init', enqueueScripts);
add_action('wp_head', addHeaderLinks);
?>

Change log

r757 by mikekasprzak on Aug 26, 2011   Diff
tweaks... I WANT THIS FIXED FOR REAL!
Go to: 
Project members, sign in to write a code review

Older revisions

r755 by mikekasprzak on Aug 24, 2011   Diff
Final I-Like-Dare tweak, and removed
the widget.
r753 by mikekasprzak on Aug 24, 2011   Diff
oops... did I say left? I meant left.
r752 by mikekasprzak on Aug 24, 2011   Diff
should fix the thing.
All revisions of this file

File info

Size: 11984 bytes, 326 lines
Powered by Google Project Hosting