Plugin Directory

Changeset 827445


Ignore:
Timestamp:
12/23/2013 01:20:15 PM (12 years ago)
Author:
shauno
Message:

2.7 release.
Fixed gallery voting on NGG v2, and added fix for NGG Public Uploader compatibility

Location:
nextgen-gallery-voting
Files:
34 added
2 edited

Legend:

Unmodified
Added
Removed
  • nextgen-gallery-voting/trunk/ngg-voting.php

    r769709 r827445  
    44Plugin URI: http://shauno.co.za/wordpress/nextgen-gallery-voting/
    55Description: This plugin allows you to add user voting and rating to NextGEN Galleries and Images
    6 Version: 2.6.1.1
     6Version: 2.7
    77Author: Shaun Alberts
    88Author URI: http://shauno.co.za
     
    112112        add_action('ngg_add_new_gallery_form', array(&$this, 'newGalleryForm')); //new in ngg 1.4.0a
    113113        add_action('ngg_created_new_gallery', array(&$this, 'onCreateGallery')); //new in ngg 1.4.0a
     114        /* deprecated in NGG v2, manually call func in gallery template
     115       
    114116        //gallery voting hooks - user
    115         add_filter('ngg_show_gallery_content', array(&$this, 'showGallery'), 10, 2);
     117        //add_filter('ngg_show_gallery_content', array(&$this, 'showGallery'), 10, 2);
     118        */
    116119       
    117120        add_action('init', array(&$this, 'wpInit'));
     
    17401743                    exit;
    17411744                }
     1745            }else if((isset($_GET['nggv_gid']) && $_GET['nggv_gid']) || isset($_POST['nggv']['vote_gid_id']) && $_POST['nggv']['vote_gid_id']) {
     1746                if(isset($_GET['nggv_gid'])) {
     1747                    $options = $this->getVotingOptions($_GET['nggv_gid']);
     1748                }else if(isset($_POST['nggv']['vote_gid_id'])) {
     1749                    $options = $this->getVotingOptions($_POST['nggv']['vote_gid_id']);
     1750                }
     1751                $voteFuncs = $this->types[$options->voting_type]['galleryCallback'];
     1752                $votedOrErr = @call_user_func_array(array($voteFuncs['class'], $voteFuncs['catch']), array($this, $options));
     1753               
     1754                //store in class var, so we have it for this page execution
     1755                $this->initCatchVote[$options->gid] = array(
     1756                    'gid'=>$options->gid,
     1757                    'result'=>$votedOrErr,
     1758                    'dateadded'=>date('Y-m-d H:i:s', time())
     1759                    );
     1760               
     1761                do_action('nggv_catch_gallery_vote', $options->gid, $this->initCatchVote);
     1762               
     1763                if($_GET['ajaxify']) { //catch the ajax vote
     1764                    $form = $this->getGalleryVoteMarkup($options);
     1765
     1766                    //echo '<!-- NGGV START AJAX RESPONSE -->';
     1767                    //echo '<script>';
     1768                    echo 'var nggv_ajax_ver = 2;'; //new in 2.6.1 to help js minification messing up ajac voting
     1769                    echo 'var nggv_js = {};';
     1770                    echo 'nggv_js.options = {};';
     1771                    echo 'nggv_js.saved = '.($votedOrErr === true ? '1' : '0').';';
     1772                    echo 'nggv_js.msg = "'.addslashes($votedOrErr).'";';
     1773                    echo 'nggv_js.voting_form = "'.addslashes($form['form']).'";';
     1774                    //echo '<script><!-- NGGV END AJAX RESPONSE -->';
     1775                    exit;
     1776                }
    17421777            }
    17431778           
     
    18921927       
    18931928        /**
     1929         * DEPRECATED
    18941930         * Hook: ngg_show_gallery_content
    18951931         * The function adds the voting form/results to the gallery content
     
    19011937        function showGallery($out, $gid) {
    19021938            return $out.$this->galleryVoteForm($gid);
     1939        }
     1940       
     1941        function getGalleryVoteMarkup($options) {
     1942            $gid = $options->gid;
     1943            $voteFuncs = $this->types[$options->voting_type]['galleryCallback'];
     1944           
     1945            //is there a vote happing for this gid right now?
     1946            $votedOrErr = isset($this->initCatchVote[$gid]['result']) ? $this->initCatchVote[$gid]['result'] : '';
     1947
     1948            $form = array();
     1949            if((($canVote = $this->canVote($gid)) === true) && !$votedOrErr) { //they can vote, show the form
     1950                //$return = apply_filters('nggv_gallery_vote_form', $nggv, $options);
     1951                $form = @call_user_func_array(array($voteFuncs['class'], $voteFuncs['form']), array($this, $options));
     1952            }else{ //ok, they cant vote.  what next?
     1953                if($options->enable) {
     1954                    if($canVote === 'NOT LOGGED IN') { //the api wants them to login to vote
     1955                        $form['form'] = nggVoting::msg('Only registered users can vote. Please login to cast your vote.');
     1956                    }else if($canVote === 'USER HAS VOTED'
     1957                        || $canVote === 'IP HAS VOTED' || $canVote == 'IP HAS VOTED TODAY' || $canVote == 'IP HAS VOTED THIS WEEK' || $canVote == 'IP HAS VOTED THIS MONTH' || $canVote == 'IP HAS VOTED THIS YEAR'
     1958                        || $canVote === 'USER HAS VOTED' || $canVote == 'USER HAS VOTED TODAY' || $canVote == 'USER HAS VOTED THIS WEEK' || $canVote == 'USER HAS VOTED THIS MONTH' || $canVote == 'USER HAS VOTED THIS YEAR'
     1959                        || $canVote === 'COOKIE HAS VOTED' || $canVote == 'COOKIE HAS VOTED TODAY' || $canVote == 'COOKIE HAS VOTED THIS WEEK' || $canVote == 'COOKIE HAS VOTED THIS MONTH' || $canVote == 'COOKIE HAS VOTED THIS YEAR'
     1960                        || $canVote === true) { //api tells us they have voted, can they see results? (canVote will be true if they have just voted successfully)
     1961                        if($options->user_results) { //yes! show it
     1962                            $form = @call_user_func_array(array($voteFuncs['class'], $voteFuncs['results']), array($this, $options));
     1963                        }else{ //nope, but thanks for trying
     1964                            $form['form'] = nggVoting::msg('Thank you for casting your vote.');
     1965                        }
     1966                    }
     1967                }
     1968            }
     1969           
     1970            return $form;
    19031971        }
    19041972       
     
    19261994                }
    19271995               
    1928                 $url = $_SERVER['REQUEST_URI'];
    1929                 $url .= (strpos($url, '?') === false ? '?' : (substr($url, -1) == '&' ? '' : '&')); //make sure the url ends in '?' or '&' correctly
    1930                
    1931                
    1932                 //$votedOrErr = nggvGalleryVote::checkVoteData($this, $options);
    1933                 $voteFuncs = $this->types[$options->voting_type]['galleryCallback'];
    1934                 $votedOrErr = @call_user_func_array(array($voteFuncs['class'], $voteFuncs['catch']), array($this, $options));
    1935                
    1936                 if(isset($_GET['ajaxify']) && $_GET['ajaxify'] && isset($_GET['nggv_gid']) && $_GET['nggv_gid'] == $gid) {
    1937                     $out .= '<!-- NGGV START AJAX RESPONSE -->';
    1938                     $out .= '<script>';
    1939                     $out .= 'var nggv_js = {};';
    1940                     $out .= 'nggv_js.options = {};';
    1941                     $out .= 'nggv_js.saved = '.($votedOrErr === true ? '1' : '0').';';
    1942                     $out .= 'nggv_js.msg = "'.addslashes($votedOrErr).'";';
    1943                 }
    1944                
    1945                 //$form = nggvGalleryVote::showVoteForm($this, $options, $votedOrErr);
    1946                
    1947                 if((($canVote = $this->canVote($gid)) === true) && !$votedOrErr) { //they can vote, show the form
    1948                     //$return = apply_filters('nggv_gallery_vote_form', $nggv, $options);
    1949                     $form = @call_user_func_array(array($voteFuncs['class'], $voteFuncs['form']), array($this, $options));
    1950                 }else{ //ok, they cant vote.  what next?
    1951                     if($options->enable) {
    1952                         if($canVote === 'NOT LOGGED IN') { //the api wants them to login to vote
    1953                             $form['form'] = nggVoting::msg('Only registered users can vote. Please login to cast your vote.');
    1954                         }else if($canVote === 'USER HAS VOTED' || $canVote === 'IP HAS VOTED' || $canVote === true) { //api tells us they have voted, can they see results? (canVote will be true if they have just voted successfully)
    1955                             if($options->user_results) { //yes! show it
    1956                                 $form = @call_user_func_array(array($voteFuncs['class'], $voteFuncs['results']), array($this, $options));
    1957                             }else{ //nope, but thanks for trying
    1958                                 $form['form'] = nggVoting::msg('Thank you for casting your vote.');
    1959                             }
    1960                         }
    1961                     }
    1962                 }
    1963                
    1964                 if(isset($_GET['ajaxify']) && $_GET['ajaxify']) {
    1965                     $out .= 'nggv_js.voting_form = "'.addslashes($form['form']).'";';
    1966                 }else{
    1967                     $out .= '<div class="nggv_container">';
     1996                $form = $this->getGalleryVoteMarkup($options);
     1997               
     1998                $out .= '<div class="nggv_container">';
     1999                    $out .= (isset($form['scripts']) ?  $form['scripts'] : '');
     2000                   
     2001                    //make sure the generic err is only every output once. hackity, but needs to be in for backwards compat with premium releases blah blah etc
     2002                    global $_nggv_generic_err;
     2003                    if(!$_nggv_generic_err) {
    19682004                        $out .= '<input type="hidden" id="ngg-genric-err-msg" value="'.esc_attr(nggVoting::msg('There was a problem saving your vote, please try again in a few moments.')).'" />';
    1969                         $out .= isset($form['scripts']) ? $form['scripts'] : '';
    1970                         $out .= '<div class="nggv-error" style="'.(!$votedOrErr || $votedOrErr === true ? 'display:none;' : '').' border: 1px solid red;">';
    1971                             $out .= $votedOrErr;
    1972                         $out .= '</div>';
    1973                        
    1974                         $out .= '<div class="nggv-vote-form">';
    1975                             $out .= $form['form'];
    1976                         $out .= '</div>';
     2005                        $_nggv_generic_err = true;
     2006                    }
     2007                   
     2008                    $votedOrErr = isset($this->initCatchVote[$gid]['result']) ? $this->initCatchVote[$gid]['result'] : '';
     2009       
     2010                    $out .= '<div class="nggv-error" style="'.(!$votedOrErr || $votedOrErr === true ? 'display:none;' : '').' border: 1px solid red;">';
     2011                        $out .= $votedOrErr;
    19772012                    $out .= '</div>';
    1978                 }
    1979                
    1980                 if(isset($_GET['ajaxify']) && $_GET['ajaxify'] && isset($_GET['nggv_gid']) && $_GET['nggv_gid'] == $gid) {
    1981                     $out .= '<script><!-- NGGV END AJAX RESPONSE -->';
    1982                 }
     2013                   
     2014                    $out .= '<div class="nggv-vote-form">';
     2015                        $out .= $form['form'];
     2016                    $out .= '</div>';
     2017                $out .= '</div>';
     2018               
     2019                do_action('nggv_gallery_vote_bottom', $options);               
    19832020            }
    19842021           
     
    19962033    return $officalNggVoting->imageVoteForm($pid, $criteriaId);
    19972034}
     2035
     2036function nggv_galleryVoteForm($displayed_gallery, $gallery) {
     2037    global $officalNggVoting;
     2038   
     2039    $gid = 0;
     2040   
     2041    //'new' templates
     2042    if(is_object($displayed_gallery) && isset($displayed_gallery->container_ids)) {
     2043        if(count($displayed_gallery->container_ids) == 1 && is_numeric($displayed_gallery->container_ids[0])) {
     2044            $gid = $displayed_gallery->container_ids[0];
     2045        }
     2046    }
     2047   
     2048    //'legacy' templates
     2049    if(!$gid && $gallery) {
     2050        if(isset($gallery->displayed_gallery) && isset($gallery->displayed_gallery->container_ids)) {
     2051            if(count($gallery->displayed_gallery->container_ids) == 1 && is_numeric($gallery->displayed_gallery->container_ids[0])) {
     2052                $gid = $gallery->displayed_gallery->container_ids[0];
     2053            }
     2054        }
     2055    }
     2056   
     2057    if($gid) {
     2058        return $officalNggVoting->galleryVoteForm($gid);
     2059    }
     2060}
    19982061//}
    19992062?>
  • nextgen-gallery-voting/trunk/readme.txt

    r755230 r827445  
    44Tags: nextgen-gallery, nextgen, gallery, voting, rating, ratings, nextgen-gallery-voting
    55Requires at least: 2.9.1
    6 Tested up to: 3.6
    7 Stable tag: 2.6.1
     6Tested up to: 3.8
     7Stable tag: 2.7
    88
    99Adds the ability for users to vote and rate your NextGEN Images. Simple options give you the ability to limit who can vote on what.
    1010
    1111== Description ==
    12 **PLEASE NOTE:** This plugin was written for NextGEN Gallery 1.x, but recently NGG have released version 2.x.
    13 I am working on bringing all the voting features up to date, but currently only the **Image** options work with NGG 2.x
    1412
    1513= Features =
     
    2927== Frequently Asked Questions ==
    3028
    31 = Important note about NextGEN Gallery version 2.x =
    32 This plugin was written for NGG 1.x. The recent release of NGG 2.x has lead to the gallery voting functions not being applicable anymore.
    33 I am working on an update to fix this in the future, but please be aware that they currently DO NOT WORK. You can ignore any reference to
    34 the gallery options in the FAQ below
    35 
    3629= In a nutshell, what is this? =
    3730This plugin adds options that can allow your users to vote on (more like rate) your Galleries and Images. There are options to limit which
     
    3932current results.
    4033
    41 = How do I make the voting form appear for images? =
    42 You need to add a small tag, `<?php echo nggv_imageVoteForm($image->pid); ?>`, to the gallery output template to get the voting showing in
    43 the galllery.
     34= How do I show the voting form? =
     35You need to add a small tag to the gallery display template.
     36
     37**For image voting:**
     38For image voting, add the following tag: `<?php echo nggv_imageVoteForm($image->pid); ?>`, to the gallery display template.
     39
     40**For gallery voting:**
     41For gallery voting, add the following tag: `<?php echo nggv_galleryVoteForm($displayed_gallery, $gallery); ?>`, to the gallery display template.
    4442
    4543For NGG 1.x, you can find the gallery templates in the `/plugins/nextgen-gallery/view/` directory. For the default shortcode, `[nggallery id=x]`, you
     
    4947For NGG version 2.x, you need to add the tag to the `/nextgen-gallery/products/photocrati_nextgen/modules/nextgen_basic_gallery/templates/thumbnails/index.php`
    5048template. This will only work for galleries inserted WITHOUT selectiong a template from the gallery display options.
    51 
    52 Please be aware, the voting form needs to be placed inside the `foreach()` loop in those templates, as that loop is outputting each image.
     49NGG v2.x templating system can be confusing for some users. Please see [this page](http://shauno.co.za/nextgen-gallery-v2-display-template-locations/) for more info on which templates are used.
     50
     51Please be aware, for **image voting**, the form needs to be placed inside the `foreach()` loop in those templates, as that loop is outputting each image.
    5352I find the best place to put the tag is AFTER the `<div class="ngg-gallery-thumbnail">` is CLOSED.
     53For **gallery voting**, be sure to place the tag outside of the foreach, or it will show more than once on the page.
    5454
    5555= Can I style it? =
     
    7777
    7878== Changelog ==
     79
     80= 2.7 =
     81* Added code to fix NGG Publuc Uploader bug, allowing it to be used with NGG Voting.
     82* Fixed gallery voting when using NGG v2.x.
    7983
    8084= 2.6.1 =
     
    211215== Upgrade Notice ==
    212216
     217= 2.7 =
     218Fixed gallery voting on NGG v2.x. Also added code to make NGG Voting work with NGG Public Uploader
     219
    213220= 2.6.1 =
    214221Minor updates to improve NextGEN Gallery version 2 compatibilty, and installs in a sub directory
Note: See TracChangeset for help on using the changeset viewer.