Plugin Directory

Changeset 969632


Ignore:
Timestamp:
08/21/2014 11:25:22 AM (11 years ago)
Author:
multippt
Message:

Reindent code for better readability
Fix: Sidebar widget votecount class style can now be overriden by stylesheet

Location:
vote-it-up/trunk
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • vote-it-up/trunk/readme.txt

    r246420 r969632  
    44Requires at least: 1.5
    55Tested up to: 2.8
    6 Stable tag: 1.1.1
     6Stable tag: 1.2.4
    77Donate link: http://www.onfry.com/donate.php
    88
     
    1111== Description ==
    1212
    13 **Note**: Version 1.2.x has been re-classified as unstable pending recent issues with the plugin by several users. Version 1.1.1 is the current stable version
    14 
    1513This plugin adds voting functionality for posts. This function is similar to Reddit or Digg, in that visitors can vote for and against.
    1614
     
    1917A widget can be displayed showing the most voted posts on your blog, giving further exposure to your popular posts.
    2018
    21 **Features in 1.1.1**
    2219
    2320A brief summary of what the plugin has to offer:
     
    3128* Top voted post widget gives greater exposure of posts your readers like
    3229
    33 **Additional Features in latest (unstable) version 1.2.2**
    34 
    35 * Bug fixes
    36 * Speed optimizations in counting votes
    3730
    3831== Installation ==
     
    157150
    158151Bug fix: Fixed existing problems on the plugin
     152
     153    1.2.4
     154    [Bug Fix] - Patch XSS vulnerability
     155    [Bug Fix] - Default skin option now checked properly
     156
     157    1.2.3
     158    Re-designate 1.2.x plugin as unstable.
    159159
    160160    1.2.2
  • vote-it-up/trunk/skin.php

    r127318 r969632  
    3535
    3636function IsChecked($name) {
    37 if (get_option('voteiu_skin') == $name) {
    38 echo 'checked';
    39 }
    40 if ($name == '') {
    41 if (get_option('voteiu_skin') == 'none' | get_option('voteiu_skin') == '') {
    42 echo 'checked';
    43 }
    44 }
     37    if (get_option('voteiu_skin') == $name) {
     38        echo 'checked';
     39        return;
     40    }
     41    if ($name == '') {
     42        if (get_option('voteiu_skin') == 'none' || get_option('voteiu_skin') == '') {
     43            echo 'checked';
     44            return;
     45        }
     46    }
    4547}
    4648
  • vote-it-up/trunk/voteconfig.php

    r129749 r969632  
    44function VoteItUp_options() {
    55    if (function_exists('add_options_page')) {
    6     add_options_page("Vote It Up", "Vote It Up", 8, "voteitupconfig", "VoteItUp_optionspage");
    7     add_options_page("Edit Votes", "Edit Votes", 8, "voteitupeditvotes", "VoteItUp_editvotespage");
     6        add_options_page("Vote It Up", "Vote It Up", 8, "voteitupconfig", "VoteItUp_optionspage");
     7        add_options_page("Edit Votes", "Edit Votes", 8, "voteitupeditvotes", "VoteItUp_editvotespage");
    88    }
    99}
     
    1111/* Wordpress MU fix, options whitelist */
    1212if(function_exists('wpmu_create_blog')) {
    13 add_filter('whitelist_options','voteitup_alter_whitelist_options');
    14 function voteitup_alter_whitelist_options($whitelist) {
    15 if(is_array($whitelist)) {
    16 $option_array = array('voteitup' => array('voteiu_initialoffset','voteiu_votetext','voteiu_sinktext','voteiu_aftervotetext','voteiu_allowguests','voteiu_allowownvote','voteiu_limit','voteiu_widgetcount','voteiu_skin'));
    17 $whitelist = array_merge($whitelist,$option_array);
    18 }
    19 return $whitelist;
    20 }
    21 
     13    add_filter('whitelist_options','voteitup_alter_whitelist_options');
     14    function voteitup_alter_whitelist_options($whitelist) {
     15        if(is_array($whitelist)) {
     16            $option_array = array('voteitup' => array('voteiu_initialoffset','voteiu_votetext','voteiu_sinktext','voteiu_aftervotetext','voteiu_allowguests','voteiu_allowownvote','voteiu_limit','voteiu_widgetcount','voteiu_skin'));
     17            $whitelist = array_merge($whitelist,$option_array);
     18        }
     19        return $whitelist;
     20    }
    2221}
    2322
    2423//Page meant for administrators
    2524function VoteItUp_optionspage() {
    26 
    27 ?>
    28 <div class="wrap">
     25    ?>
     26    <div class="wrap">
    2927    <div id="icon-options-general" class="icon32"><br /></div>
    30 <h2><?php _e('Voting options'); ?></h2>
    31 <?php
    32 include('importdb.php');
    33 if (Voteiu_Dbneedupdate()) { ?>
     28    <h2><?php _e('Voting options'); ?></h2>
     29    <?php
     30    include('importdb.php');
     31    if (Voteiu_Dbneedupdate()) { ?>
    3432<form method="get" action="">
    3533<input type="hidden" name="page" value="voteitupconfig" />
     
    145143
    146144function VoteItUp_editvotespage() {
    147 VoteBulkEdit();
    148 ?>
    149 <div class="wrap">
    150 <div id="icon-edit" class="icon32"><br /></div>
    151 <h2><?php _e('Edit Votes'); ?></h2>
    152 <?php DisplayPageList($_GET['pageno']); ?>
    153 <form method="post" action="">
    154 <?php /* wp_nonce_field('update-options'); */ ?>
    155 <div class="tablenav">
     145    VoteBulkEdit();
     146    ?>
     147    <div class="wrap">
     148    <div id="icon-edit" class="icon32"><br /></div>
     149    <h2><?php _e('Edit Votes'); ?></h2>
     150    <?php DisplayPageList($_GET['pageno']); ?>
     151    <form method="post" action="">
     152    <?php /* wp_nonce_field('update-options'); */ ?>
     153    <div class="tablenav">
    156154
    157 <div class="alignleft actions">
     155    <div class="alignleft actions">
    158156
    159 <select name="action1">
    160 <option value="-1" selected="selected">Bulk Actions</option>
    161 <option value="delete">Reset Votes</option>
    162 <option value="deleteuser">Reset User Votes</option>
    163 <option value="deleteguest">Reset Guest Votes</option>
    164 </select>
    165 <input type="submit" value="Apply" name="doaction1" id="doaction1" class="button-secondary action" />
    166 </div></div>
     157    <select name="action1">
     158    <option value="-1" selected="selected">Bulk Actions</option>
     159    <option value="delete">Reset Votes</option>
     160    <option value="deleteuser">Reset User Votes</option>
     161    <option value="deleteguest">Reset Guest Votes</option>
     162    </select>
     163    <input type="submit" value="Apply" name="doaction1" id="doaction1" class="button-secondary action" />
     164    </div></div>
    167165
    168 <?php
    169 if ($_GET['pageno'] == '') {
    170 DisplayPostList();
    171 } else {
    172 DisplayPostList($_GET['pageno']);
    173 }?>
     166    <?php
     167    if ($_GET['pageno'] == '') {
     168        DisplayPostList();
     169    } else {
     170        DisplayPostList($_GET['pageno']);
     171    }?>
    174172
    175 <div class="tablenav">
     173    <div class="tablenav">
    176174
    177175
    178 <div class="alignleft actions">
    179 <select name="action2">
    180 <option value="-1" selected="selected">Bulk Actions</option>
    181 <option value="delete">Reset Votes</option>
    182 <option value="deleteuser">Reset User Votes</option>
    183 <option value="deleteguest">Reset Guest Votes</option>
    184 </select>
     176    <div class="alignleft actions">
     177    <select name="action2">
     178    <option value="-1" selected="selected">Bulk Actions</option>
     179    <option value="delete">Reset Votes</option>
     180    <option value="deleteuser">Reset User Votes</option>
     181    <option value="deleteguest">Reset Guest Votes</option>
     182    </select>
    185183
    186 <input type="submit" value="Apply" name="doaction2" id="doaction2" class="button-secondary action" />
    187 <br class="clear" />
    188 </div>
    189 <br class="clear" />
    190 </div>
     184    <input type="submit" value="Apply" name="doaction2" id="doaction2" class="button-secondary action" />
     185    <br class="clear" />
     186    </div>
     187    <br class="clear" />
     188    </div>
    191189
    192 </form>
     190    </form>
    193191
    194 </div>
    195 <?php
     192    </div>
     193    <?php
    196194}
    197195
  • vote-it-up/trunk/voteinstall.php

    r127318 r969632  
    55
    66function VoteItUp_InstallOptions() {
    7 global $voteitup_dbversion;
     7    global $voteitup_dbversion;
    88
    9 //Default options for install
    10 $voteiu_votetext = 'Vote';
    11 $voteiu_sinktext = '';
    12 $voteiu_aftervotetext = '';
    13 $voteiu_allowguests = true;
    14 $voteiu_allowownvote = true;
    15 $voteiu_limit = 100;
    16 $voteiu_widgetcount = 10;
    17 $voteiu_skin = '';
    18 $voteiu_initialoffset = 0;
     9    //Default options for install
     10    $voteiu_votetext = 'Vote';
     11    $voteiu_sinktext = '';
     12    $voteiu_aftervotetext = '';
     13    $voteiu_allowguests = true;
     14    $voteiu_allowownvote = true;
     15    $voteiu_limit = 100;
     16    $voteiu_widgetcount = 10;
     17    $voteiu_skin = '';
     18    $voteiu_initialoffset = 0;
    1919
    20 //Begins adding options if not available
    21 //3rd parameter is deprecated, but added for compatibility
    22 add_option('voteiu_votetext', $voteiu_votetext, 'The vote text');
    23 add_option('voteiu_sinktext', $voteiu_sinktext, 'The sink text');
    24 add_option('voteiu_aftervotetext', $voteiu_aftervotetext, 'The after vote text');
    25 add_option('voteiu_allowguests', $voteiu_allowguests, 'Allows guests to vote');
    26 add_option('voteiu_allowownvote', $voteiu_allowownvote, 'Allows authors to vote own posts');
    27 add_option('voteiu_limit', $voteiu_limit, 'The number of latest posts to include in the widget');
    28 add_option('voteiu_widgetcount', $voteiu_widgetcount, 'The number of posts shown in the widget');
    29 add_option('voteiu_skin', $voteiu_skin, 'The current theme for vote widget');
    30 add_option('voteiu_dbversion', $voteitup_dbversion, 'Vote It Up db version');
    31 add_option('voteiu_initialoffset', $voteiu_initialoffset, 'Vote offset');
     20    //Begins adding options if not available
     21    //3rd parameter is deprecated, but added for compatibility
     22    add_option('voteiu_votetext', $voteiu_votetext, 'The vote text');
     23    add_option('voteiu_sinktext', $voteiu_sinktext, 'The sink text');
     24    add_option('voteiu_aftervotetext', $voteiu_aftervotetext, 'The after vote text');
     25    add_option('voteiu_allowguests', $voteiu_allowguests, 'Allows guests to vote');
     26    add_option('voteiu_allowownvote', $voteiu_allowownvote, 'Allows authors to vote own posts');
     27    add_option('voteiu_limit', $voteiu_limit, 'The number of latest posts to include in the widget');
     28    add_option('voteiu_widgetcount', $voteiu_widgetcount, 'The number of posts shown in the widget');
     29    add_option('voteiu_skin', $voteiu_skin, 'The current theme for vote widget');
     30    add_option('voteiu_dbversion', $voteitup_dbversion, 'Vote It Up db version');
     31    add_option('voteiu_initialoffset', $voteiu_initialoffset, 'Vote offset');
    3232
    33 //Change setting to default values if user left these fields blank
    34 if (get_option('voteiu_initialoffset') == '') {
    35 update_option('voteiu_initialoffset', $voteiu_initialoffset);
    36 }
    37 if (get_option('voteiu_limit') == '') {
    38 update_option('voteiu_limit', $voteiu_limit);
    39 }
    40 if (get_option('voteiu_widgetcount') == '10') {
    41 update_option('voteiu_widgetcount', $voteiu_widgetcount);
    42 }
    43 
     33    //Change setting to default values if user left these fields blank
     34    if (get_option('voteiu_initialoffset') == '') {
     35        update_option('voteiu_initialoffset', $voteiu_initialoffset);
     36    }
     37    if (get_option('voteiu_limit') == '') {
     38        update_option('voteiu_limit', $voteiu_limit);
     39    }
     40    if (get_option('voteiu_widgetcount') == '10') {
     41        update_option('voteiu_widgetcount', $voteiu_widgetcount);
     42    }
    4443}
    4544
    4645//Updates options and remove unused ones
    4746function VoteItUp_UpgradeOptions() {
    48 global $voteiu_dbversion;
     47    global $voteiu_dbversion;
     48    $currentdbversion = 0;
     49    if (get_option('voteiu_dbversion')) {
     50        $currentdbversion = get_option('voteiu_dbversion');
     51    }
    4952
    50 $currentdbversion = 0;
    51 if (get_option('voteiu_dbversion')) {
    52 $currentdbversion = get_option('voteiu_dbversion');
    53 }
    54 
    55 if ($voteiu_dbversion > $currentdbversion) {
    56 
    57 //Update options here
    58 
    59 }
    60 
     53    if ($voteiu_dbversion > $currentdbversion) {
     54        //Update options here
     55    }
    6156}
    6257
    6358//Deletes old unused options
    6459function VoteItUp_DeleteOldOptions() {
    65 delete_option('voteiu_allowsinks');
    66 delete_option('voteiu_excluded');
    67 delete_option('voteiu_usevotetext');
     60    delete_option('voteiu_allowsinks');
     61    delete_option('voteiu_excluded');
     62    delete_option('voteiu_usevotetext');
    6863}
    6964
    70 
    7165//Installs DB tables
    72 
    7366function VoteItUp_dbinstall() {
    7467    global $wpdb, $voteitup_dbversion;
    7568    $table_name = $wpdb->prefix.'voteiu_data';
    7669    if($wpdb->get_var("SHOW TABLES LIKE '".$table_name."'") != $table_name) {
    77     //Table does not exist, so create it
    78     //3000
    79     $querycreatetable = "CREATE TABLE ".$wpdb->prefix."voteiu_data (
    80     ID int(11) NOT NULL auto_increment,
    81     post int(11) NOT NULL,
    82     vote text NOT NULL,
    83     type text NOT NULL,
    84     PRIMARY KEY (ID) );";
    85     $wpdb->query($querycreatetable);
    86     update_option('voteiu_dbversion', $voteitup_dbversion);
     70        //Table does not exist, so create it
     71        //3000
     72        $querycreatetable = "CREATE TABLE ".$wpdb->prefix."voteiu_data (
     73        ID int(11) NOT NULL auto_increment,
     74        post int(11) NOT NULL,
     75        vote text NOT NULL,
     76        type text NOT NULL,
     77        PRIMARY KEY (ID) );";
     78        $wpdb->query($querycreatetable);
     79        update_option('voteiu_dbversion', $voteitup_dbversion);
    8780    }
    8881}
  • vote-it-up/trunk/voteinterface.php

    r969327 r969632  
    11<?php
     2// This is an API to perform voting and to obtain voting scores
     3
     4define('WP_USE_THEMES', false);
    25include_once("../../../wp-blog-header.php");
    36include_once("votingfunctions.php");
  • vote-it-up/trunk/voteitup.css

    r98190 r969632  
    77/* Registration box */
    88.regcontainerbackground {
    9 background-color: #CCCCCC;
    10 opacity:0.4;
    11 filter:alpha(opacity=40);
    12 position: fixed;
    13 width: 100%;
    14 height: 100%;
    15 top: 0%;
    16 left: 0px;
     9    background-color: #CCCCCC;
     10    opacity:0.4;
     11    filter:alpha(opacity=40);
     12    position: fixed;
     13    width: 100%;
     14    height: 100%;
     15    top: 0%;
     16    left: 0px;
    1717}
    1818.regcontainer {
    19 display: none; /* do not show immediately */
    20 position: fixed; /* align with browser window */
    21 width: 100%;
    22 height: 100%;
    23 top: 0%;
    24 left: 0px;
    25 text-align: center;
     19    display: none; /* do not show immediately */
     20    position: fixed; /* align with browser window */
     21    width: 100%;
     22    height: 100%;
     23    top: 0%;
     24    left: 0px;
     25    text-align: center;
    2626}
    2727.regpopup {
    28 position: relative;
    29 margin: auto;
    30 width: 40%;
    31 /*height: 20%;*/
    32 padding: 4px;
    33 top: 30%;
    34 border: 1px solid #CCCCCC;
    35 background-color: #FFFFFF;
    36 color: #333333;
    37 font-size: 16px;
    38 font-family: arial;
     28    position: relative;
     29    margin: auto;
     30    width: 40%;
     31    /*height: 20%;*/
     32    padding: 4px;
     33    top: 30%;
     34    border: 1px solid #CCCCCC;
     35    background-color: #FFFFFF;
     36    color: #333333;
     37    font-size: 16px;
     38    font-family: arial;
    3939}
    4040.regpopup a {
    41 /*color: #0000FF;*/
     41
    4242}
    4343.regpopup h3 {
    44 font-size: 18px;
    45 font-weight: normal;
    46 color: #E37400;
    47 padding: 0px;
    48 margin: 4px;
     44    font-size: 18px;
     45    font-weight: normal;
     46    color: #E37400;
     47    padding: 0px;
     48    margin: 4px;
    4949}
    5050.regclosebutton {
    51 float: right;
    52 width: 16px;
    53 height: 16px;
    54 border: 0px;
    55 padding: 1px;
     51    float: right;
     52    width: 16px;
     53    height: 16px;
     54    border: 0px;
     55    padding: 1px;
    5656}
    5757.regsmalltext {
    58 font-size: 8px;
    59 text-align: right;
    60 padding: 0px;
    61 margin: 0px;
     58    font-size: 8px;
     59    text-align: right;
     60    padding: 0px;
     61    margin: 0px;
    6262}
     63.votewidget .votecount {
     64    width: 1em;
     65    color: #555;
     66    font-weight: bold;
     67}
  • vote-it-up/trunk/voteitup.php

    r969327 r969632  
    44Plugin URI: http://www.onfry.com/projects/voteitup/
    55Description: Vote It Up enables bloggers to add voting functionality to their posts.
    6 Version: 1.2.3
     6Version: 1.2.4
    77Author: Nicholas Kwan (multippt)
    88Author URI: http://www.onfry.com/
     
    2525//Declare paths used by plugin
    2626function VoteItUp_Path() {
    27 global $voteitupint_path;
    28 if ($voteitupint_path == '') {
    29     $dir = dirname(__FILE__);
    30     $dir = str_replace("\\", "/", $dir); //For Linux
    31     return $dir;
    32 } else {
    33     return $voteitup_path;
    34 }
     27    global $voteitupint_path;
     28    if ($voteitupint_path == '') {
     29        $dir = dirname(__FILE__);
     30        $dir = str_replace("\\", "/", $dir); //For Linux
     31        return $dir;
     32    } else {
     33        return $voteitup_path;
     34    }
    3535}
    3636
    3737function VoteItUp_ExtPath() {
    38 global $voteitup_path;
    39 if ($voteitup_path == '') {
    40     $dir = VoteItUp_Path();
    41     $base = ABSPATH;
    42     $base = str_replace("\\", "/", $base);
    43     $edir = str_replace($base, "", $dir);
    44     $edir = get_bloginfo('url')."/".$edir;
    45     $edir = str_replace("\\", "/", $edir);
    46     return $edir;
    47 } else {
    48     return $voteitup_path;
    49 }
     38    global $voteitup_path;
     39    if ($voteitup_path == '') {
     40        $dir = VoteItUp_Path();
     41        $base = ABSPATH;
     42        $base = str_replace("\\", "/", $base);
     43        $edir = str_replace($base, "", $dir);
     44        $edir = get_bloginfo('url')."/".$edir;
     45        $edir = str_replace("\\", "/", $edir);
     46        return $edir;
     47    } else {
     48        return $voteitup_path;
     49    }
    5050}
    5151
     
    5858
    5959function VoteItUp_header() {
    60 $voteiu_skin = get_option('voteiu_skin');
    61 //If no skin is selected, only include default theme/script to prevent conflicts.
    62 if ($voteiu_skin == '') {
    63 ?>
    64 <link rel="stylesheet" href="<?php echo VoteItUp_ExtPath(); ?>/votestyles.css" type="text/css" />
    65 <script type="text/javascript" src="<?php echo VoteItUp_ExtPath(); ?>/voterajax.js"></script>
    66 <?php
    67 } else {
    68     LoadSkinHeader($voteiu_skin);
    69 }
    70 /* These are things always used by voteitup */
    71 ?>
    72 <link rel="stylesheet" href="<?php echo VoteItUp_ExtPath(); ?>/voteitup.css" type="text/css" />
    73 <script type="text/javascript" src="<?php echo VoteItUp_ExtPath(); ?>/userregister.js"></script>
    74 <?php
     60    $voteiu_skin = get_option('voteiu_skin');
     61    //If no skin is selected, only include default theme/script to prevent conflicts.
     62    if ($voteiu_skin == '') {
     63        ?><link rel="stylesheet" href="<?php echo VoteItUp_ExtPath(); ?>/votestyles.css" type="text/css" />
     64        <script type="text/javascript" src="<?php echo VoteItUp_ExtPath(); ?>/voterajax.js"></script><?php
     65    } else {
     66        LoadSkinHeader($voteiu_skin);
     67    }
     68    /* These are things always used by voteitup */
     69    ?><link rel="stylesheet" href="<?php echo VoteItUp_ExtPath(); ?>/voteitup.css" type="text/css" />
     70    <script type="text/javascript" src="<?php echo VoteItUp_ExtPath(); ?>/userregister.js"></script><?php
    7571}
    7672
    7773function VoteItUp_footer() {
    78 if (!get_option('voteiu_allowguests')) {
    79 ?><div class="regcontainer" id="regbox">
    80 <div class="regcontainerbackground">&nbsp;</div>
    81 <div class="regpopup">
    82 <a href="javascript:regclose();" title="Close"><img class="regclosebutton" src="<?php echo VoteItUp_ExtPath(); ?>/closebutton.png" /></a>
    83 <h3>You need to log in to vote</h3>
    84 
    85 <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>
    86 <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>
    87 <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>
    88 <?php
    89 }
     74    if (!get_option('voteiu_allowguests')) {
     75        ?><div class="regcontainer" id="regbox">
     76        <div class="regcontainerbackground">&nbsp;</div>
     77        <div class="regpopup">
     78        <a href="javascript:regclose();" title="Close"><img class="regclosebutton" src="<?php echo VoteItUp_ExtPath(); ?>/closebutton.png" /></a>
     79        <h3>You need to log in to vote</h3>
     80
     81        <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>
     82        <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>
     83        <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
     84    }
    9085}
    9186
    9287//Displays the widget, theme supported
    9388function MostVotedAllTime($skinname = '', $mode = '') {
    94 $voteiu_skin = get_option('voteiu_skin');
    95 $tempvar = $voteiu_skin;
    96 if ($skinname != '') {
    97 $tempvar = $skinname;
    98 }
    99 if ($tempvar == '' | $tempvar == 'default') {
    100 if ($mode == 'sidebar') {
    101 MostVotedAllTime_SidebarWidget();
    102 } else {
    103 MostVotedAllTime_Widget(); //Use default bar
    104 }
    105 } else {
    106 if (!LoadSkinWidget($tempvar, $mode)) {
    107 if ($mode == 'sidebar') {
    108 MostVotedAllTime_SidebarWidget();
    109 } else {
    110 MostVotedAllTime_Widget(); //Use default bar
    111 }
    112 }
    113 }
    114 
    115 }
    116 
    117 
    118 //Display the votes as a bar
     89    $voteiu_skin = get_option('voteiu_skin');
     90    $tempvar = $voteiu_skin;
     91    if ($skinname != '') {
     92        $tempvar = $skinname;
     93    }
     94    if ($tempvar == '' || $tempvar == 'default') {
     95        if ($mode == 'sidebar') {
     96            MostVotedAllTime_SidebarWidget();
     97        } else {
     98            MostVotedAllTime_Widget(); //Use default bar
     99        }
     100    } else {
     101        if (!LoadSkinWidget($tempvar, $mode)) {
     102            if ($mode == 'sidebar') {
     103                MostVotedAllTime_SidebarWidget();
     104            } else {
     105                MostVotedAllTime_Widget(); //Use default bar
     106            }
     107        }
     108    }
     109}
     110
     111
     112//Display the votes
    119113function DisplayVotes($postID, $type = '') {
    120 global $user_ID, $guest_votes, $vote_text, $use_votetext, $allow_sinks, $voteiu_skin;
    121 
    122 $voteiu_skin = get_option('voteiu_skin');
    123 $votes = GetVotes($postID);
    124 $barvotes = GetBarVotes($postID);
    125 switch ($type) {
    126 case '':
    127 if ($voteiu_skin == '') {
    128 DisplayVotes($postID, 'bar'); //Use default bar
    129 } else {
    130 if (!LoadSkin($voteiu_skin)) {
    131 DisplayVotes($postID, 'bar'); //Use default bar
    132 }
    133 }
    134 break;
    135 case 'bar':
    136 ?>
    137 <span class="barcontainer"><span class="barfill" id="votecount<?php echo $postID ?>" style="width:<?php echo round($barvotes[0] * 2.5); ?>%;">&nbsp;</span></span>
    138 <?php if ($user_ID != '') {
    139  if (!($user_login == get_the_author_login() && !get_option('voteiu_allowownvote'))) { ?>
    140     <span>
    141     <?php if(!UserVoted($postID,$user_ID)) { ?><span class="bartext" id="voteid<?php the_ID(); ?>">
    142             <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>
    143             <?php } ?>
    144 
    145         </span>
    146     <?php } else { ?>
    147     <?php if (get_option('voteiu_aftervotetext') != '') { ?><span class="bartext" id="voteid<?php the_ID(); ?>"><?php echo get_option('voteiu_aftervotetext'); ?></span><?php } ?>
    148     <?php } ?>
    149     </span>
    150 <?php } } else {
    151 if (get_option('voteiu_allowguests') == 'true') { ?>
    152     <span>
    153     <?php if(!GuestVoted($postID,md5($_SERVER['REMOTE_ADDR']))) { ?><span class="bartext" id="voteid<?php the_ID(); ?>">
    154             <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>
    155             <?php } ?>
    156 
    157         </span>
    158     <?php } ?>
    159     </span>
    160     <?php } }
    161 break;
    162 case 'ticker':
    163 ?>
    164 <span class="tickercontainer" id="votes<?php the_ID(); ?>"><?php echo $votes; ?></span>
    165 <?php if ($user_ID != '') { ?>
    166 <span id="voteid<?php the_ID(); ?>">
    167     <?php if(!UserVoted($postID,$user_ID)) { ?><span class="tickertext">
    168         <?php if ($use_votetext == 'true') { ?>
    169         <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>
    170         <?php } else { ?>
    171             <span class="imagecontainer">
    172             <?php if ($allow_sinks == 'true') { ?>
    173             <a href="javascript:sink_ticker(<?php echo $postID ?>,<?php echo $postID ?>,<?php echo $user_ID; ?>,'<?php echo VoteItUp_ExtPath(); ?>');">
    174             <img class="votedown" src="<?php echo VoteItUp_ExtPath(); ?>/votedown.png" alt="Vote down" border="0" />
    175             </a>
    176             <?php } ?>
    177             <a href="javascript:vote_ticker(<?php echo $postID ?>,<?php echo $postID ?>,<?php echo $user_ID; ?>,'<?php echo VoteItUp_ExtPath(); ?>');">
    178             <img class="voteup" src="<?php echo VoteItUp_ExtPath(); ?>/voteup.png" alt="Vote up" border="0" />
    179             </a>
    180             </span>
    181         <?php } ?>
    182         </span>
    183     <?php } ?>
    184 </span>
    185 <?php } else {
    186 if ($guest_votes == 'true') { ?>
    187     <span id="voteid<?php the_ID(); ?>">
    188     <?php if(!GuestVoted($postID,md5($_SERVER['REMOTE_ADDR']))) { ?>
    189         <span class="tickertext">
    190         <?php if ($use_votetext == 'true') { ?>
    191             <a class="votelink" href="javascript:vote_ticker(<?php echo $postID ?>,<?php echo $postID ?>,0,'<?php echo VoteItUp_ExtPath(); ?>');"><?php echo $vote_text; ?></a></span>
    192         <?php } else { ?>
    193             <span class="imagecontainer">
    194             <?php if ($allow_sinks == 'true') { ?>
    195             <a href="javascript:sink_ticker(<?php echo $postID ?>,<?php echo $postID ?>,0,'<?php echo VoteItUp_ExtPath(); ?>');">
    196             <img class="votedown" src="<?php echo VoteItUp_ExtPath(); ?>/votedown.png" alt="Vote down" border="0" />
    197             </a>
    198             <?php } ?>
    199             <a href="javascript:vote_ticker(<?php echo $postID ?>,<?php echo $postID ?>,0,'<?php echo VoteItUp_ExtPath(); ?>');">
    200             <img class="voteup" src="<?php echo VoteItUp_ExtPath(); ?>/voteup.png" alt="Vote up" border="0" />
    201             </a>
    202             </span>
    203         <?php } ?>
    204         </span>
    205     <?php } ?>
    206 </span>
    207 
    208 <?php
    209 }
    210 }
    211 break;
    212 }
     114    global $user_ID, $guest_votes, $vote_text, $use_votetext, $allow_sinks, $voteiu_skin;
     115
     116    $voteiu_skin = get_option('voteiu_skin');
     117    $votes = GetVotes($postID);
     118    $barvotes = GetBarVotes($postID);
     119    switch ($type) {
     120        case '': // In the event no theme selected, use the default theme
     121            if ($voteiu_skin == '') {
     122                DisplayVotes($postID, 'bar');
     123            } else if (!LoadSkin($voteiu_skin)) {
     124                DisplayVotes($postID, 'bar');
     125            }
     126            break;
     127        case 'bar':
     128            ?><span class="barcontainer"><span class="barfill" id="votecount<?php echo $postID ?>" style="width:<?php echo round($barvotes[0] * 2.5); ?>%;">&nbsp;</span></span><?php
     129            if ($user_ID != '') {
     130                if (!($user_login == get_the_author_login() && !get_option('voteiu_allowownvote'))) {
     131                    ?><span><?php
     132                    if(!UserVoted($postID,$user_ID)) {
     133                        ?><span class="bartext" id="voteid<?php the_ID(); ?>">
     134                        <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
     135                        if (get_option('voteiu_sinktext') != '') {
     136                            ?><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
     137                        }
     138                        ?></span><?php
     139                    } else {
     140                        if (get_option('voteiu_aftervotetext') != '') {
     141                            ?><span class="bartext" id="voteid<?php the_ID(); ?>"><?php echo get_option('voteiu_aftervotetext'); ?></span><?php
     142                        }
     143                    }
     144                    ?></span><?php
     145                }
     146            } else {
     147                if (get_option('voteiu_allowguests') == 'true') {
     148                    ?><span><?php
     149                    if(!GuestVoted($postID,md5($_SERVER['REMOTE_ADDR']))) { ?><span class="bartext" id="voteid<?php the_ID(); ?>">
     150                        <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
     151                        if (get_option('voteiu_sinktext') != '') {
     152                            ?><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
     153                        }
     154                        ?></span><?php
     155                    }
     156                    ?></span><?php
     157                }
     158            }
     159            break;
     160        case 'ticker':
     161            ?><span class="tickercontainer" id="votes<?php the_ID(); ?>"><?php echo $votes; ?></span><?php
     162            if ($user_ID != '') {
     163                ?><span id="voteid<?php the_ID(); ?>"><?php
     164                if(!UserVoted($postID,$user_ID)) {
     165                    ?><span class="tickertext"><?php
     166                    if ($use_votetext == 'true') {
     167                        ?><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
     168                    } else {
     169                        ?><span class="imagecontainer"><?php
     170                        if ($allow_sinks == 'true') {
     171                            ?><a href="javascript:sink_ticker(<?php echo $postID ?>,<?php echo $postID ?>,<?php echo $user_ID; ?>,'<?php echo VoteItUp_ExtPath(); ?>');">
     172                            <img class="votedown" src="<?php echo VoteItUp_ExtPath(); ?>/votedown.png" alt="Vote down" border="0" />
     173                            </a><?php
     174                        }
     175                        ?><a href="javascript:vote_ticker(<?php echo $postID ?>,<?php echo $postID ?>,<?php echo $user_ID; ?>,'<?php echo VoteItUp_ExtPath(); ?>');">
     176                        <img class="voteup" src="<?php echo VoteItUp_ExtPath(); ?>/voteup.png" alt="Vote up" border="0" />
     177                        </a>
     178                        </span><?php
     179                    }
     180                    ?></span><?php
     181                }
     182                ?></span><?php
     183            } else {
     184                if ($guest_votes == 'true') {
     185                    ?><span id="voteid<?php the_ID(); ?>"><?php
     186                    if(!GuestVoted($postID,md5($_SERVER['REMOTE_ADDR']))) {
     187                        ?><span class="tickertext"><?php
     188                        if ($use_votetext == 'true') {
     189                            ?><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
     190                        } else {
     191                            ?><span class="imagecontainer"><?php
     192                            if ($allow_sinks == 'true') {
     193                                ?><a href="javascript:sink_ticker(<?php echo $postID ?>,<?php echo $postID ?>,0,'<?php echo VoteItUp_ExtPath(); ?>');">
     194                                <img class="votedown" src="<?php echo VoteItUp_ExtPath(); ?>/votedown.png" alt="Vote down" border="0" />
     195                                </a><?php
     196                            }
     197                            ?><a href="javascript:vote_ticker(<?php echo $postID ?>,<?php echo $postID ?>,0,'<?php echo VoteItUp_ExtPath(); ?>');">
     198                            <img class="voteup" src="<?php echo VoteItUp_ExtPath(); ?>/voteup.png" alt="Vote up" border="0" />
     199                            </a>
     200                            </span><?php
     201                        }
     202                        ?></span><?php
     203                    }
     204                    ?></span><?php
     205                }
     206            }
     207            break;
     208    }
    213209}
    214210
    215211/* Widget examples can be found in widget.php of wp-includes.*/
    216212function widget_MostVotedAllTime_init() {
    217 
    218 if (function_exists('register_sidebar_widget')) {
    219 function widget_MostVotedAllTime($args) {
    220 $options = get_option("widget_MostVotedAllTime");
    221 if ($options['title'] != '') {
    222 $title = $options['title'];
    223 } else {
    224 $title = 'Most Voted Posts';
    225 }
    226     extract($args);
    227 ?>
    228         <?php echo $before_widget; ?>
    229             <?php echo $before_title
    230                 . $title
    231                 . $after_title; ?>
    232             <?php MostVotedAllTime('', 'sidebar'); ?>
    233         <?php echo $after_widget; ?>
    234 <?php
    235 }
    236 register_sidebar_widget('Most Voted Posts', 'widget_MostVotedAllTime');
    237 //$widget_ops = array('classname' => 'widget_MostVotedAllTime', 'description' => __( "Displays the most voted up posts") );
    238 //@wp_register_sidebar_widget('widget_MostVotedAllTime', __('Most Voted Posts'), 'widget_MostVotedAllTime', $widget_ops);
    239 
    240 function widget_MostVotedAllTime_Control() {
    241 $options = $newoptions = get_option("widget_MostVotedAllTime");
    242 
    243 if ($_POST)
    244 {
    245 $newoptions['title'] = strip_tags(stripslashes($_POST['widget_MostVotedAllTime_title']));
    246 }
    247 if ( $options != $newoptions ) {
    248         $options = $newoptions;
    249         update_option('widget_MostVotedAllTime', $options);
    250 }
    251 $title = attribute_escape($options['title']);
    252 ?>
    253 <p>
    254     <label for="widget_MostVotedAllTime_title">Title: </label>
    255     <input type="text" class="widefat" id="widget_MostVotedAllTime_title" name="widget_MostVotedAllTime_title" value="<?php echo $title; ?>" />
    256     <input type="hidden" id="voteitup-submit" name="voteitup-submit" value="1" />
    257   </p>
    258 <?php
    259 }
    260 
    261 register_widget_control('Most Voted Posts', 'widget_MostVotedAllTime_Control', 0, 0 );
    262 
    263 }
     213    if (function_exists('register_sidebar_widget')) {
     214        function widget_MostVotedAllTime($args) {
     215            $options = get_option("widget_MostVotedAllTime");
     216            if ($options['title'] != '') {
     217                $title = $options['title'];
     218            } else {
     219                $title = 'Most Voted Posts';
     220            }
     221            extract($args);
     222            echo $before_widget;
     223            echo $before_title.$title.$after_title;
     224            MostVotedAllTime('', 'sidebar');
     225            echo $after_widget;
     226        }
     227        register_sidebar_widget('Most Voted Posts', 'widget_MostVotedAllTime');
     228        //$widget_ops = array('classname' => 'widget_MostVotedAllTime', 'description' => __( "Displays the most voted up posts") );
     229        //@wp_register_sidebar_widget('widget_MostVotedAllTime', __('Most Voted Posts'), 'widget_MostVotedAllTime', $widget_ops);
     230
     231        function widget_MostVotedAllTime_Control() {
     232            $options = $newoptions = get_option("widget_MostVotedAllTime");
     233            if (isset($_POST['widget_MostVotedAllTime_title'])) {
     234                $newoptions['title'] = strip_tags(stripslashes($_POST['widget_MostVotedAllTime_title']));
     235            }
     236            if ($options != $newoptions ) {
     237                $options = $newoptions;
     238                update_option('widget_MostVotedAllTime', $options);
     239            }
     240            $title = attribute_escape($options['title']);
     241            ?>
     242            <p>
     243                <label for="widget_MostVotedAllTime_title">Title: </label>
     244                <input type="text" class="widefat" id="widget_MostVotedAllTime_title" name="widget_MostVotedAllTime_title" value="<?php echo $title; ?>" />
     245                <input type="hidden" id="voteitup-submit" name="voteitup-submit" value="1" />
     246            </p>
     247            <?php
     248        }
     249        register_widget_control('Most Voted Posts', 'widget_MostVotedAllTime_Control', 0, 0 );
     250    }
    264251}
    265252
  • vote-it-up/trunk/votingfunctions.php

    r129736 r969632  
    11<?php
    2 /*
    3 This script is designed to be run from wordpress. It will work if placed in the root directory of a wordpress install.
    4 Revision: 6
    5 
    6 -Uses database v3
    7 -Now uses sql to count votes instead of php for faster script exectution
    8 -Technical limit on guest votes now raised. Technical limit is now based on maximum size of the database.
    9 -Fixes wrong vote counts as a result of deleting votes
    10 -Excludes private, drafts, and pages from appearing in widget
    11 -Offset feature enhanced
    12 -Fixes duplicate voting issues arising from caching
    13 
    14 This file is not compatible with database v1. Please use importdb.php to upgrade your database from v1 to v3.
    15 
    16 */
    172
    183if (get_option('voteiu_dbversion') >= 3000) {
    19 
    20 //Testing purposes
    21 //if (true) {
    22 
    23 //Variables
    24 global $wpdb;
    25 $voteiu_databasetable = $wpdb->prefix."voteiu_data";
    26 
    27 //Functions SetPost, SetUser are removed as they are no longer needed.
    28 
    29 //Returns the vote count
    30 //Format: ''= Overall vote count, 'array'= Array[total,vote,sink,guestvote,guestsink], 'percent'= Percentage of positive votes out of total
    31 function GetVotes($post_ID, $format = '') {
    32     global $wpdb, $voteiu_databasetable;
    33    
    34     //prevents SQL injection
    35     $p_ID = $wpdb->escape($post_ID);
    36 
    37     //Usual format for getting row count with condition: "SELECT COUNT(*) FROM wp_voteiuvotes WHERE post = ".$postid
    38     //Use COUNT(*) to get MySQL to count the rows
    39     //Use COUNT(DISTINCT(*)) to avoid counting duplicate votes
    40     //Example:
    41     /*
    42     //Deprecated
    43     $votes = $wpdb->get_var("SELECT COUNT(distinct(vote)) FROM ".$voteiu_databasetable." WHERE post='".$p_ID."' AND type='vote'");
    44     $sinks = $wpdb->get_var("SELECT COUNT(distinct(vote)) FROM ".$voteiu_databasetable." WHERE post='".$p_ID."' AND type='sink'");
    45     $guestvotes = $wpdb->get_var("SELECT COUNT(distinct(vote)) FROM ".$voteiu_databasetable." WHERE post='".$p_ID."' AND type='guestvote'");
    46     $guestsinks = $wpdb->get_var("SELECT COUNT(distinct(vote)) FROM ".$voteiu_databasetable." WHERE post='".$p_ID."' AND type='guestsink'");
    47     $offset = $wpdb->get_var("SELECT vote FROM ".$voteiu_databasetable." WHERE post='".$p_ID."' AND type='offset'");
    48     $offset = $offset + get_option('voteiu_initialoffset');
    49     */
    50     //New query reduces number of queries to database by 5 times.
    51     //Associative array created
    52     //[0]=post,[1]=votes,[2]=sinks,[3]=guestvotes,[4]=guestsinks,[5]=offset
    53     $query = "SELECT post, count(distinct (case when type='vote' then vote else null end)), count(distinct (case when type='sink' then vote else null end)), count(distinct (case when type='guestvote' then vote else null end)), count(distinct (case when type='guestsink' then vote else null end)), sum(case when type='offset' then vote else 0 end) FROM `wp_voteiu_data` WHERE post='".$p_ID."' GROUP BY post";
    54     $querydata = $votes = $wpdb->get_row($query, ARRAY_N, 0);
    55     //Use round to convert '' to 0;
    56     $votes = round($querydata[1]);
    57     $sinks = round($querydata[2]);
    58     $guestvotes = round($querydata[3]);
    59     $guestsinks = round($querydata[4]);
    60     $offset = round($querydata[5]);
    61     $offset = $offset + get_option('voteiu_initialoffset');
    62 
    63     //The mathematics
    64     switch ($format) {
    65     case "percent":
    66         //Make $votecount into a percent
    67         $totalcount = $votes + $sinks + $guestvotes + $guestsinks + $offset;
    68         $forcount = $votes + $guestvotes + $offset;
    69         $againstcount = $sinks + $guestsinks; //unused
    70 
    71         if ($totalcount > 0) {
    72             $votecount = number_format(100*($forcount / $totalcount), 0) . "%";
    73         } else {
    74             return "0%";
    75         }
    76         return $votecount;
    77         //Uncomment this line below if you want to test
    78         //return count($votes) . " " . count($sinks) . " " . count($guestvotes) . " " . count($guestsinks) . " " . count($uservotes) . " " . count($usersinks) . " " . get_option('voteiu_initialoffset') . " " . $p_ID;
    79     break;
    80     case "array":
    81         $votecount = $votes - $sinks + $guestvotes - $guestsinks + $offset;
    82         $votearray = array("total" => $votecount, "votes" => $votes, "sinks" => $sinks, "guestvotes" => $guestvotes, "guestsinks" => $guestsinks, "offset" => $offset);
    83         return $votearray;
    84     break;
    85     default:
    86         //Normal vote count
    87         $votecount = $votes - $sinks + $guestvotes - $guestsinks + $offset;
    88         return $votecount;
    89     break;
    90     }
    91 }
    92 
    93 //Returns Votes as a percentage
    94 function GetVotesPercent($post_ID) {
    95     return GetVotes($post_ID, "percent");
    96 }
    97 
    98 //Returns positive vote count, considering offset
    99 function GetPostVotes($post_ID) {
    100     $votearray = GetVotes($post_ID, "array");
    101     return $votearray['votes'] + $votearray['guestvotes'] + $votearray['offset'];
    102 }
    103 
    104 //Returns negative vote count
    105 function GetPostSinks($post_ID) {
    106     $votearray = GetVotes($post_ID, "array");
    107     return $votearray['sinks'] + $votearray['guestsinks'];
    108 }
    109 
    110 //Returns vote count for bar theme
    111 function GetBarVotes($post_ID, $limiter = 40) {
    112 
    113     $max_displayed_votes = $limiter;
    114     $vote_threshold = 30;
    115 
    116     $votes = GetVotes($post_ID);
    117     $votemax = $max_displayed_votes;
    118     $votebreak =  30; //votes at which bar changes color
    119     $bar[0] = 0; //The length of the bar
    120     $bar[1] = 0; //The state of the bar
    121     if ($votes > $votemax && $votes > -1) {
    122         $bar[0] = $votemax;
    123     } else {
    124         if ($votes > -1) {
    125             $bar[0] = $votes;
    126         } else {
    127             $bar[0] = 0;
    128         }
    129     }
    130     if ($votes > $votebreak) {
    131         $bar[1] = 1;
    132     }
    133     return $bar;
    134 }
    135 
    136 //Checks if the user voted
    137 function UserVoted($post_ID, $user_ID) {
    138     global $wpdb, $voteiu_databasetable;
    139    
    140     //prevents SQL injection
    141     $p_ID = $wpdb->escape($post_ID);
    142     $u_ID = $wpdb->escape($user_ID);
    143    
    144     //Check if vote exists
    145     $id_raw = $wpdb->get_var("SELECT ID FROM ".$voteiu_databasetable." WHERE vote='".$u_ID."' AND post='".$p_ID."'");
    146     if ($id_raw != '') {
    147         //entry exists
    148         return true;
    149     } else {
    150         //entry does not exist
    151         return false;
    152     }
    153 }
    154 
    155 //Checks if the guest voted (exactly same as UserVoted)
    156 function GuestVoted($post_ID, $user_ID) {
    157     global $wpdb, $voteiu_databasetable;
    158    
    159     //prevents SQL injection
    160     $p_ID = $wpdb->escape($post_ID);
    161     $u_ID = $wpdb->escape($user_ID);
    162    
    163     //Check if vote exists
    164     $id_raw = $wpdb->get_var("SELECT ID FROM ".$voteiu_databasetable." WHERE vote='".$u_ID."' AND post='".$p_ID."'");
    165     if ($id_raw != '') {
    166         //entry exists
    167         return true;
    168     } else {
    169         //entry does not exist
    170         return false;
    171     }
    172 }
    173 
    174 //Checks the key to see if it is valid.
    175 function CheckKey($key, $id) {
    176     global $wpdb;
    177     $userdata = $wpdb->get_results("SELECT display_name, user_email, user_url, user_registered FROM $wpdb->users WHERE ID = '".$id."'", ARRAY_N);
    178     $chhash = md5($userdata[0][0].$userdata[0][3]);
    179     if ($chhash == $key) {
    180         return true;
    181     } else {
    182         return false;
    183     }
    184 }
    185 
    186 //Inserts a vote. Does not check if user has voted or not
    187 function InsertVote($post_ID, $user_ID, $type) {
    188     global $wpdb, $voteiu_databasetable;
    189 
    190 $queryinsert = "INSERT INTO ".$voteiu_databasetable." (post, vote, type) VALUES ("
    191 ."'".$post_ID."', "
    192 ."'".$user_ID."', "
    193 ."'".$type."'"
    194 .")";
    195 $wpdb->query($queryinsert) or die(mysql_error());
    196 }
    197 
    198 //Saves the vote of a user to the database.
    199 function Vote($post_ID, $user_ID, $type = 'vote') {
    200     global $wpdb, $voteiu_databasetable;
    201 
    202     $result = false;
    203 
    204     //Prevents SQL injection
    205     $p_ID = $wpdb->escape($post_ID);
    206     $u_ID = $wpdb->escape($user_ID);
    207 
    208     if (!UserVoted($post_ID,$user_ID)) {
    209     InsertVote($p_ID, $u_ID, $type);
    210     $result = true;
    211     }
    212     return $result; //returns true if the vote is saved, false if no changes were made
    213 }
    214 
    215 //Saves the vote of a guest to the database.
    216 function GuestVote($post_ID, $type = 'vote') {
    217     global $wpdb, $voteiu_databasetable;
    218 
    219     $result = false;
    220     $user_ID = md5($_SERVER['REMOTE_ADDR']);
    221 
    222     //Prevents SQL injection
    223     $p_ID = $wpdb->escape($post_ID);
    224     $u_ID = $wpdb->escape($user_ID);
    225 
    226     if (!UserVoted($post_ID,$user_ID)) {
    227     if ($type == 'vote') {
    228     InsertVote($p_ID, $u_ID, 'guestvote');
    229     } else {
    230     InsertVote($p_ID, $u_ID, 'guestsink');
    231     }
    232     $result = true;
    233     }
    234     return $result; //returns true if the vote is saved, false if no changes were made
    235 }
    236 
    237 //Gets an array of posts with vote count
    238 //Identical to SortVotes() except that it is sorted by post ID in descending order, and has more information on votes
    239 function GetVoteArray($page = 0) {
    240     global $wpdb, $voteiu_databasetable;
    241    
    242     //First page is 0
    243     $postsperpage = 50;
    244     $upperlimit = $postsperpage * ($page + 1);
    245     $lowerlimit = $postsperpage * ($page);
    246     //Get the posts available for vote editing
    247     //Use wordpress posts table
    248     //For posts to be available for vote editing, they must be published posts.
    249     mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die(mysql_error());
    250     mysql_select_db(DB_NAME) or die(mysql_error());
    251     $posttablecontents = mysql_query("SELECT ID FROM ".$wpdb->prefix."posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT ".$lowerlimit.", ".$upperlimit."") or die(mysql_error());
    252     //$posttablecontents = mysql_query("SELECT ID FROM ".$wpdb->prefix."posts WHERE post_type = 'post'") or die(mysql_error());
    253     $returnarray = array();
    254     while ($row = mysql_fetch_array($posttablecontents)) {
    255         $post_id = $row['ID'];
    256         $vote_array = GetVotes($post_id, "array");
    257         $returnarray[count($returnarray)] = array($post_id, $vote_array);
    258     }
    259 
    260     return $returnarray;
    261 }
    262 
    263 //Used in options page
    264 function DisplayPageList($page = 0) {
    265     global $wpdb;
    266     $query = "SELECT count(*) FROM ".$wpdb->prefix."posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date_gmt DESC";
    267     $postcount = $wpdb->get_var($query);
    268     $postsperpage = 50;
    269     $pagecount = ceil($postcount / $postsperpage);
    270 ?>
    271 <div class="alignright actions">
    272 <form action="" method="get">
    273 <input type="hidden" name="page" value="voteitupeditvotes" />
    274 Page <select name="pageno">
    275 <?php
    276 $i = 0;
    277 while ($i < $pagecount) {
    278 if ($page != $i) {
    279 echo "<option value='".$i."'>".($i + 1)."</option>";
     4    include('votingfunctions_v3.php');
    2805} else {
    281 echo "<option value='".$i."' selected='selected'>".($i + 1)."</option>";
    282 }
    283 $i++;
     6    //Compatibility
     7    include('votingfunctions_v1.php');
    2848}
    2859?>
    286 </select>
    287 <input type="submit" name="pagesubmit" value="Go" class="button-secondary action" />
    288 </form>
    289 </div>
    290 <?php
    291 }
    292 
    293 //Used in options page
    294 function DisplayPostList($page = 0) {
    295     $a = GetVoteArray($page);
    296 //print_r($a);
    297     $i = 0;
    298 
    299 //Begin table
    300 ?>
    301 <table class="widefat post fixed" id="formtable" style="clear: both;" cellspacing="0">
    302     <thead>
    303     <tr>
    304 
    305     <th scope="col" id="cb" class="manage-column column-cb check-column" style=""><input type="checkbox" name="multiselect[]" onclick="javascript:CheckUncheck()" /></th>
    306     <th scope="col" id="title" class="manage-column column-title" style="">Post</th>
    307 <?php /*?>  <th scope="col" id="author" class="manage-column column-author" style="">Author</th><?php */ ?>
    308     <th scope="col" id="votes" class="manage-column column-categories" style="width: 40%">Votes</th>
    309 
    310 
    311     </tr>
    312     </thead>
    313 
    314     <tfoot>
    315     <tr>
    316     <th scope="col"  class="manage-column column-cb check-column" style=""><input type="checkbox" name="multiselect[]" onclick="javascript:CheckUncheck()" /></th>
    317     <th scope="col"  class="manage-column column-title" style="">Post</th>
    318 <?php /* ?> <th scope="col"  class="manage-column column-author" style="">Author</th><?php */ ?>
    319 
    320     <th scope="col"  class="manage-column column-categories" style="">Votes</th>
    321 
    322     </tr>
    323     </tfoot>
    324     <tbody>
    325 <?php
    326 
    327     while ($i < count($a)) {
    328     $postdat = get_post($a[$i][0]);
    329     if (!empty($postdat)) {
    330 ?>
    331     <tr id='post-<?php echo $a[$i][0]; ?>' class='alternate author-other status-publish iedit' valign="top">
    332         <th scope="row" class="check-column"><input type="checkbox" name="post[]" value="<?php echo $a[$i][0]; ?>" /></th>
    333 <td class="post-title column-title"><strong><a class="row-title" href="<?php echo $postdat->guid; ?>" title="<?php echo $postdat->post_title; ?>"><?php echo $postdat->post_title; ?></a></strong></td>
    334 <?php /* ?><td class="author column-author"><?php echo $postdat->post_author; ?></td><?php */ ?>
    335 <td class="categories column-categories"><?php echo $a[$i][1]["total"]; ?> (Users: <span style="color:#00CC00">+<?php echo $a[$i][1]["votes"]; ?></span>/<span style="color:#CC0000">-<?php echo $a[$i][1]["sinks"]; ?></span>, Guests: <span style="color:#00CC00">+<?php echo $a[$i][1]["guestvotes"]; ?></span>/<span style="color:#CC0000">-<?php echo $a[$i][1]["guestsinks"]; ?></span><?php
    336 if($a[$i][1]["offset"] != '0') {
    337 echo ', Offset: ';
    338 if ($a[$i][1]["offset"] > 0) {
    339 echo '<span style="color:#00CC00">+'.$a[$i][1]["offset"].'</span>';
    340 } else {
    341 echo '<span style="color:#CC0000">'.$a[$i][1]["offset"].'</span>';
    342 } } ?>)</td>
    343 <?php
    344 
    345 /*
    346     echo $postdat->post_title;
    347     echo ' - ';
    348     echo $a[1][$i][0];
    349     echo '<br />';
    350 */
    351 
    352 ?>
    353 </tr>
    354 <?php
    355     }
    356     $i++;
    357     }
    358 
    359 
    360 //End table
    361 ?>
    362     </tbody>
    363     </table>
    364 <?php
    365 }
    366 
    367 
    368 //Handles the deleting of votes, used to read the POST when the page is submitted
    369 function VoteBulkEdit() {
    370 //error_reporting(E_ALL);
    371 /*print_r($_POST);*/
    372 $buttonnumber = 0; //Determines which apply button was clicked on. 0 if no button was clicked.
    373 $action = 'none'; //Determines what should be done
    374 if (array_key_exists('doaction1', $_POST)) {
    375 $buttonnumber = 1;
    376 }
    377 if (array_key_exists('doaction2', $_POST)) {
    378 $buttonnumber = 2;
    379 }
    380 if ($buttonnumber != 0 && array_key_exists('action'.$buttonnumber, $_POST)) {
    381     if ($_POST['action'.$buttonnumber] != -1) {
    382         //Assigns action to be done
    383         $action = $_POST['action'.$buttonnumber];
    384     }
    385 }
    386 
    387 if (!array_key_exists('post', $_POST)) {
    388 $action = 'none'; //set action to none if there are no posts to modify
    389 }
    390 
    391 //Begin modifying votes
    392 if ($action != 'none' && $action != '') {
    393 ResetVote($_POST['post'], $action);
    394 }
    395 
    396 }
    397 
    398 //Resets vote counts
    399 function ResetVote($postids, $action) {
    400 /*
    401 Testing stuff...
    402 echo 'Posts: '.implode(', ',$_POST['post']);
    403 echo '<br />';
    404 echo "Action: ".$action;
    405 */
    406 global $wpdb, $voteiu_databasetable;
    407 //$wpdb->show_errors();
    408 
    409 switch ($action) {
    410 
    411 case 'none':
    412 //do nothing
    413 break;
    414 case 'delete':
    415 //reset all votes for the post
    416 $i = 0;
    417 while ($i < count($postids)) {
    418 $wpdb->query("DELETE FROM ".$voteiu_databasetable." WHERE `post`=".$postids[$i]." ;");
    419 $i++;
    420 }
    421 EditVoteSuccess();
    422 break;
    423 case 'deleteuser':
    424 //reset all votes for users
    425 $i = 0;
    426 while ($i < count($postids)) {
    427 $wpdb->query("DELETE FROM ".$voteiu_databasetable." WHERE type = 'vote' post=".$postids[$i]." ;");
    428 $wpdb->query("DELETE FROM ".$voteiu_databasetable." WHERE type = 'sink' post=".$postids[$i]." ;");
    429 $i++;
    430 }
    431 EditVoteSuccess();
    432 break;
    433 case 'deleteguest':
    434 //reset all votes for guests
    435 $i = 0;
    436 while ($i < count($postids)) {
    437 $wpdb->query("DELETE FROM ".$voteiu_databasetable." WHERE type = 'guestvote' post=".$postids[$i]." ;");
    438 $wpdb->query("DELETE FROM ".$voteiu_databasetable." WHERE type = 'guestsink' post=".$postids[$i]." ;");
    439 $i++;
    440 }
    441 EditVoteSuccess();
    442 break;
    443 }
    444 }
    445 
    446 //Indicates that votes were edited successfully
    447 function EditVoteSuccess() {
    448 ?><div id="message" class="updated fade"><p><strong>Votes edited</strong></p></div><?php
    449 }
    450 
    451 
    452 //Used to sort votes for widgets
    453 //Excludes pages, private and draft posts
    454 //Returns an array sorted by vote count in descending order.
    455 //Array[#rank] = {[post id], [vote count], [user vote count], [user sink count], [guest vote count], [guest sink count]}
    456 function SortVotes() {
    457     global $wpdb, $voteiu_databasetable;
    458 
    459     mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die(mysql_error());
    460     mysql_select_db(DB_NAME) or die(mysql_error());
    461     //Set a limit to reduce time taken for script to run
    462     $upperlimit = get_option('voteiu_limit');
    463     if ($upperlimit == '') {
    464         $upperlimit = 100;
    465     }
    466     $lowerlimit = 0;
    467 
    468     $postarray = array();
    469     $votesarray = array();
    470 
    471     //Use wordpress posts table
    472     //For posts to be available for vote editing, they must be published posts.
    473     mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die(mysql_error());
    474     mysql_select_db(DB_NAME) or die(mysql_error());
    475     //Sorts by date instead of ID for more accurate representation
    476     $posttablecontents = mysql_query("SELECT ID FROM ".$wpdb->prefix."posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT ".$lowerlimit.", ".$upperlimit."") or die(mysql_error());
    477 
    478     $returnarray = array();
    479     while ($row = mysql_fetch_array($posttablecontents)) {
    480         $post_id = $row['ID'];
    481         $vote_array = GetVotes($post_id, "array");
    482         array_push($postarray, array($post_id));
    483         array_push($votesarray, array(GetVotes($post_id)));
    484     }
    485     array_multisort($votesarray, SORT_DESC, $postarray);
    486     $output = array($postarray, $votesarray);
    487     return $output;
    488 
    489 }
    490 
    491 
    492 //Displays the widget
    493 function MostVotedAllTime_Widget() {
    494     $a = SortVotes();
    495     //Before
    496 
    497 ?>
    498 <div class="votewidget">
    499 <div class="title">Most Voted</div>
    500 <?php
    501     $rows = 0;
    502 
    503 //Now does not include deleted posts
    504 $i = 0;
    505 while ($rows < get_option('voteiu_widgetcount')) {
    506     if ($a[0][$i][0] != '') {
    507             $postdat = get_post($a[0][$i][0]);
    508         if (!empty($postdat)) {
    509             $rows++;
    510 
    511             if (round($rows / 2) == ($rows / 2)) {
    512                 echo '<div class="fore">';
    513             } else {
    514                 echo '<div class="back">';
    515             }
    516             echo '<div class="votecount">'.$a[1][$i][0].' '.Pluralize($a[1][$i][0], 'votes', 'vote').' </div><div><a href="'.$postdat->guid.'" title="'.$postdat->post_title.'">'.$postdat->post_title.'</a></div>';
    517             echo '</div>';
    518         }
    519     }
    520     if ($i < count($a[0])) {
    521     $i++;
    522     } else {
    523     break; //exit the loop
    524     }
    525 }
    526 
    527 //End
    528 ?>
    529 
    530 </div>
    531 <?php
    532 
    533 }
    534 
    535 //Displays the widget optimised for sidebar
    536 function MostVotedAllTime_SidebarWidget() {
    537     $a = SortVotes();
    538     //Before
    539 
    540 ?>
    541 <div class="votewidget">
    542 <?php
    543     $rows = 0;
    544 
    545 //Now does not include deleted posts
    546 $i = 0;
    547 while ($rows < get_option('voteiu_widgetcount')) {
    548     if ($a[0][$i][0] != '') {
    549             $postdat = get_post($a[0][$i][0]);
    550         if (!empty($postdat)) {
    551             $rows++;
    552                 if (round($rows / 2) == ($rows / 2)) {
    553                     echo '<div class="fore">';
    554                 } else {
    555                     echo '<div class="back">';
    556                 }
    557                 echo '<div class="votecount" style="width: 1em; color: #555555; font-weight: bold;">'.$a[1][$i][0].' </div><div><a href="'.$postdat->guid.'" title="'.$postdat->post_title.'">'.$postdat->post_title.'</a></div>';
    558                 echo '</div>';
    559         }
    560     }
    561     if ($i < count($a[0])) {
    562     $i++;
    563     } else {
    564     break; //exit the loop
    565     }
    566 }
    567 
    568 //End
    569 ?>
    570 
    571 </div>
    572 <?php
    573 
    574 }
    575 
    576 //For those particular with English
    577 function Pluralize($number, $plural, $singular) {
    578     if ($number == 1) {
    579         return $singular;
    580     } else {
    581         return $plural;
    582     }
    583 }
    584 
    585 //Not used yet
    586 function IsExcluded($id) {
    587     global $excludedid;
    588     $clean = str_replace("\r", "", $excludedid);
    589     $excluded = explode("\n", $clean);
    590 }
    591 
    592 } else {
    593 //Compatibility
    594 include('votingfunctions_v1.php');
    595 }
    596 ?>
Note: See TracChangeset for help on using the changeset viewer.