/
voteitup.php
285 lines (255 loc) · 10.9 KB
/
voteitup.php
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
<?php
/*
Plugin Name: Vote It Up
Plugin URI: http://www.onfry.com/projects/voteitup/
Description: Vote It Up enables bloggers to add voting functionality to their posts.
Version: 1.2.2
Author: Nicholas Kwan (multippt)
Author URI: http://www.onfry.com/
*/
/* Copyright 2007 Nicholas Kwan (email : ready725@gmail.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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
//Installs plugin options and database
include_once('voteinstall.php');
VoteItUp_InstallOptions();
VoteItUp_dbinstall();
//register_activation_hook( basename(__FILE__), 'VoteItUp_dbinstall'); //doesn't seem to work at times..., but I'll put it here
//External configuration file
@include_once('compat.php');
//Declare paths used by plugin
function VoteItUp_Path() {
global $voteitupint_path;
if ($voteitupint_path == '') {
$dir = dirname(__FILE__);
$dir = str_replace("\\", "/", $dir); //For Linux
return $dir;
} else {
return $voteitup_path;
}
}
function VoteItUp_ExtPath() {
global $voteitup_path;
if ($voteitup_path == '') {
$dir = VoteItUp_Path();
$base = ABSPATH;
$base = str_replace("\\", "/", $base);
$edir = str_replace($base, "", $dir);
$edir = get_bloginfo('url')."/".$edir;
$edir = str_replace("\\", "/", $edir);
return $edir;
} else {
return $voteitup_path;
}
}
//Includes other functions of the plugin
include_once(VoteItUp_Path()."/votingfunctions.php");
include_once(VoteItUp_Path()."/skin.php");
//Installs configuration page
include("voteconfig.php");
function VoteItUp_header() {
$voteiu_skin = get_option('voteiu_skin');
//If no skin is selected, only include default theme/script to prevent conflicts.
if ($voteiu_skin == '') {
?>
<link rel="stylesheet" href="<?php echo VoteItUp_ExtPath(); ?>/votestyles.css" type="text/css" />
<script type="text/javascript" src="<?php echo VoteItUp_ExtPath(); ?>/voterajax.js"></script>
<?php
} else {
LoadSkinHeader($voteiu_skin);
}
/* These are things always used by voteitup */
?>
<link rel="stylesheet" href="<?php echo VoteItUp_ExtPath(); ?>/voteitup.css" type="text/css" />
<script type="text/javascript" src="<?php echo VoteItUp_ExtPath(); ?>/userregister.js"></script>
<?php
}
function VoteItUp_footer() {
if (!get_option('voteiu_allowguests')) {
?><div class="regcontainer" id="regbox">
<div class="regcontainerbackground"> </div>
<div class="regpopup">
<a href="javascript:regclose();" title="Close"><img class="regclosebutton" src="<?php echo VoteItUp_ExtPath(); ?>/closebutton.png" /></a>
<h3>You need to log in to vote</h3>
<p>The blog owner requires users to be <a href="<?php echo get_option('siteurl').'/wp-login.php'; ?>" title="Log in">logged in</a> to be able to vote for this post.</p>
<p>Alternatively, if you do not have an account yet you can <a href="<?php echo get_option('siteurl').'/wp-login.php?action=register'; ?>" title="Register account">create one here</a>.</p>
<p class="regsmalltext">Powered by <a href="http://www.onfry.com/projects/voteitup/" title="Vote It Up plugin">Vote It Up</a></p></div></div>
<?php
}
}
//Displays the widget, theme supported
function MostVotedAllTime($skinname = '', $mode = '') {
$voteiu_skin = get_option('voteiu_skin');
$tempvar = $voteiu_skin;
if ($skinname != '') {
$tempvar = $skinname;
}
if ($tempvar == '' | $tempvar == 'default') {
if ($mode == 'sidebar') {
MostVotedAllTime_SidebarWidget();
} else {
MostVotedAllTime_Widget(); //Use default bar
}
} else {
if (!LoadSkinWidget($tempvar, $mode)) {
if ($mode == 'sidebar') {
MostVotedAllTime_SidebarWidget();
} else {
MostVotedAllTime_Widget(); //Use default bar
}
}
}
}
//Display the votes as a bar
function DisplayVotes($postID, $type = '') {
global $user_ID, $guest_votes, $vote_text, $use_votetext, $allow_sinks, $voteiu_skin, $user_login;
$voteiu_skin = get_option('voteiu_skin');
$votes = GetVotes($postID);
$barvotes = GetBarVotes($postID);
switch ($type) {
case '':
if ($voteiu_skin == '') {
DisplayVotes($postID, 'bar'); //Use default bar
} else {
if (!LoadSkin($voteiu_skin)) {
DisplayVotes($postID, 'bar'); //Use default bar
}
}
break;
case 'bar':
?>
<span class="barcontainer"><span class="barfill" id="votecount<?php echo $postID ?>" style="width:<?php echo round($barvotes[0] * 2.5); ?>%;"> </span></span>
<?php if ($user_ID != '') {
if (!($user_login == get_the_author_meta('login') && !get_option('voteiu_allowownvote'))) { ?>
<span>
<?php if(!UserVoted($postID,$user_ID)) { ?><span class="bartext" id="voteid<?php the_ID(); ?>">
<a href="javascript:vote('votecount<?php the_ID(); ?>','voteid<?php the_ID(); ?>','<?php echo get_option('voteiu_aftervotetext'); ?>',<?php the_ID(); ?>,<?php echo $user_ID; ?>,'<?php echo VoteItUp_ExtPath(); ?>');"><?php echo get_option('voteiu_votetext'); ?></a><?php if (get_option('voteiu_sinktext') != '') { ?><a href="javascript:sink('votecount<?php the_ID(); ?>','voteid<?php the_ID(); ?>','<?php echo get_option('voteiu_aftervotetext'); ?>',<?php the_ID(); ?>,<?php echo $user_ID; ?>,'<?php echo VoteItUp_ExtPath(); ?>');"><?php echo get_option('voteiu_sinktext'); ?></a>
<?php } ?>
</span>
<?php } else { ?>
<?php if (get_option('voteiu_aftervotetext') != '') { ?><span class="bartext" id="voteid<?php the_ID(); ?>"><?php echo get_option('voteiu_aftervotetext'); ?></span><?php } ?>
<?php } ?>
</span>
<?php } } else {
if (get_option('voteiu_allowguests') == 'true') { ?>
<span>
<?php if(!GuestVoted($postID,md5($_SERVER['REMOTE_ADDR']))) { ?><span class="bartext" id="voteid<?php the_ID(); ?>">
<a href="javascript:vote('votecount<?php the_ID(); ?>','voteid<?php the_ID(); ?>','<?php echo get_option('voteiu_aftervotetext'); ?>',<?php the_ID(); ?>,0,'<?php echo VoteItUp_ExtPath(); ?>');"><?php echo get_option('voteiu_votetext'); ?></a><?php if (get_option('voteiu_sinktext') != '') { ?><a href="javascript:sink('votecount<?php the_ID(); ?>','voteid<?php the_ID(); ?>','<?php echo get_option('voteiu_aftervotetext'); ?>',<?php the_ID(); ?>,0,'<?php echo VoteItUp_ExtPath(); ?>');"><?php echo get_option('voteiu_sinktext'); ?></a>
<?php } ?>
</span>
<?php } ?>
</span>
<?php } }
break;
case 'ticker':
?>
<span class="tickercontainer" id="votes<?php the_ID(); ?>"><?php echo $votes; ?></span>
<?php if ($user_ID != '') { ?>
<span id="voteid<?php the_ID(); ?>">
<?php if(!UserVoted($postID,$user_ID)) { ?><span class="tickertext">
<?php if ($use_votetext == 'true') { ?>
<a class="votelink" href="javascript:vote_ticker(<?php echo $postID ?>,<?php echo $postID ?>,<?php echo $user_ID; ?>,'<?php echo VoteItUp_ExtPath(); ?>');"><?php echo $vote_text; ?></a>
<?php } else { ?>
<span class="imagecontainer">
<?php if ($allow_sinks == 'true') { ?>
<a href="javascript:sink_ticker(<?php echo $postID ?>,<?php echo $postID ?>,<?php echo $user_ID; ?>,'<?php echo VoteItUp_ExtPath(); ?>');">
<img class="votedown" src="<?php echo VoteItUp_ExtPath(); ?>/votedown.png" alt="Vote down" border="0" />
</a>
<?php } ?>
<a href="javascript:vote_ticker(<?php echo $postID ?>,<?php echo $postID ?>,<?php echo $user_ID; ?>,'<?php echo VoteItUp_ExtPath(); ?>');">
<img class="voteup" src="<?php echo VoteItUp_ExtPath(); ?>/voteup.png" alt="Vote up" border="0" />
</a>
</span>
<?php } ?>
</span>
<?php } ?>
</span>
<?php } else {
if ($guest_votes == 'true') { ?>
<span id="voteid<?php the_ID(); ?>">
<?php if(!GuestVoted($postID,md5($_SERVER['REMOTE_ADDR']))) { ?>
<span class="tickertext">
<?php if ($use_votetext == 'true') { ?>
<a class="votelink" href="javascript:vote_ticker(<?php echo $postID ?>,<?php echo $postID ?>,0,'<?php echo VoteItUp_ExtPath(); ?>');"><?php echo $vote_text; ?></a></span>
<?php } else { ?>
<span class="imagecontainer">
<?php if ($allow_sinks == 'true') { ?>
<a href="javascript:sink_ticker(<?php echo $postID ?>,<?php echo $postID ?>,0,'<?php echo VoteItUp_ExtPath(); ?>');">
<img class="votedown" src="<?php echo VoteItUp_ExtPath(); ?>/votedown.png" alt="Vote down" border="0" />
</a>
<?php } ?>
<a href="javascript:vote_ticker(<?php echo $postID ?>,<?php echo $postID ?>,0,'<?php echo VoteItUp_ExtPath(); ?>');">
<img class="voteup" src="<?php echo VoteItUp_ExtPath(); ?>/voteup.png" alt="Vote up" border="0" />
</a>
</span>
<?php } ?>
</span>
<?php } ?>
</span>
<?php
}
}
break;
}
}
/* Widget examples can be found in widget.php of wp-includes.*/
function widget_MostVotedAllTime_init() {
if (function_exists('wp_register_sidebar_widget')) {
function widget_MostVotedAllTime($args) {
$options = get_option("widget_MostVotedAllTime");
if ($options['title'] != '') {
$title = $options['title'];
} else {
$title = 'Most Voted Posts';
}
extract($args);
?>
<?php echo $before_widget; ?>
<?php echo $before_title
. $title
. $after_title; ?>
<?php MostVotedAllTime('', 'sidebar'); ?>
<?php echo $after_widget; ?>
<?php
}
wp_register_sidebar_widget(sanitize_title('Most Voted Posts'), 'Most Voted Posts', 'widget_MostVotedAllTime');
//$widget_ops = array('classname' => 'widget_MostVotedAllTime', 'description' => __( "Displays the most voted up posts") );
//@wp_register_sidebar_widget('widget_MostVotedAllTime', __('Most Voted Posts'), 'widget_MostVotedAllTime', $widget_ops);
function widget_MostVotedAllTime_Control() {
$options = $newoptions = get_option("widget_MostVotedAllTime");
if ($_POST)
{
$newoptions['title'] = strip_tags(stripslashes($_POST['widget_MostVotedAllTime_title']));
}
if ( $options != $newoptions ) {
$options = $newoptions;
update_option('widget_MostVotedAllTime', $options);
}
$title = esc_attr($options['title']);
?>
<p>
<label for="widget_MostVotedAllTime_title">Title: </label>
<input type="text" class="widefat" id="widget_MostVotedAllTime_title" name="widget_MostVotedAllTime_title" value="<?php echo $title; ?>" />
<input type="hidden" id="voteitup-submit" name="voteitup-submit" value="1" />
</p>
<?php
}
wp_register_widget_control(sanitize_title('Most Voted Posts'), 'Most Voted Posts', 'widget_MostVotedAllTime_Control', 0, 0 );
}
}
//Runs the plugin
add_action('wp_head', 'VoteItUp_header');
add_action('get_footer', 'VoteItUp_footer');
add_action('admin_menu', 'VoteItUp_options');
add_action('init', 'widget_MostVotedAllTime_init');
?>