WordPress.org

Plugin Directory

Changeset 230099


Ignore:
Timestamp:
04/17/10 00:31:15 (4 years ago)
Author:
MrWiblog
Message:

0.8.3 (2010/04/17) Fixed bugs with expiry date, download limit and email registration. Changed Plugin Register to be opt-in.

Location:
voucherpress/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • voucherpress/trunk/readme.txt

    r228086 r230099  
    55Requires at least: 2.8 
    66Tested up to: 2.9.2 
    7 Stable tag: 0.8.2 
     7Stable tag: 0.8.3 
    88 
    99VoucherPress is a Wordpress plugin that allows you to give downloadable, printable vouchers/tickets/coupons/tokens in PDF format away on your site. 
     
    6565== Changelog == 
    6666 
     670.8.3 (2010/04/17) Fixed bugs with expiry date, download limit and email registration. Changed Plugin Register to be opt-in. 
    67680.8.2 (2010/04/12) Stopped failure of chmod() on custom templates directory causing warnings 
    68690.8.1 (2010/04/01) Added voucher code to the CSV download. Added Plugin Register code. 
  • voucherpress/trunk/voucherpress.php

    r228086 r230099  
    33 * @package VoucherPress 
    44 * @author Chris Taylor 
    5  * @version 0.8.2 
     5 * @version 0.8.3 
    66 */ 
    77/* 
    88Plugin Name: VoucherPress 
    99Plugin URI: http://www.stillbreathing.co.uk/projects/voucherpress/ 
    10 Description: VoucherPress allows you to offer downloadable, printable vouchers from your Wordpress site. Vouchers can be available to anyone, or require a name and email address before they can be downloaded. Please note: On activation this plugin will send a message to the developer with your site name and URL. This information will be kept private. If you are not happy with the developer knowing you are using their plugin, please do not use it. 
     10Description: VoucherPress allows you to offer downloadable, printable vouchers from your Wordpress site. Vouchers can be available to anyone, or require a name and email address before they can be downloaded. <strong>Please <a href="plugins.php?register=voucherpress">register this plugin</a> to tell the developer you are using it. This just sends your site name and URL to the developer.</strong> 
    1111Author: Chris Taylor 
    12 Version: 0.8.2 
     12Version: 0.8.3 
    1313Author URI: http://www.stillbreathing.co.uk/ 
    1414*/ 
     
    1616// set the current version 
    1717function voucherpress_current_version() { 
    18     return "0.8.2"; 
     18    return "0.8.3"; 
    1919} 
    2020 
     
    2323register_deactivation_hook( __FILE__, voucherpress_deactivate ); 
    2424 
    25 register_activation_hook( __FILE__, voucherpress_plugin_register ); 
    26 function voucherpress_plugin_register() { 
     25if ( isset($_GET["register"]) && $_GET["register"] == "voucherpress" ) { 
    2726    $plugin = "VoucherPress"; 
    2827    $version = voucherpress_current_version(); 
     
    3130    $register_url = "http://www.stillbreathing.co.uk/?plugin=" . urlencode( $plugin ) . "&version=" . urlencode( $version ) . "&site=" . urlencode( $site ) . "&url=" . urlencode( $url ); 
    3231    wp_remote_fopen( $register_url ); 
     32    add_action( "admin_notices", "voucherpress_register_thanks" ); 
     33} 
     34function voucherpress_register_thanks() { 
     35    echo ' 
     36    <div id="message" class="updated fade"> 
     37        <p><strong>' . __( 'Thank you for registering your use of this plugin.', "voucherpress" ) . '</strong></p> 
     38    </div> 
     39    '; 
    3340} 
    3441 
     
    7784        if ( voucherpress_voucher_exists( $voucher_guid ) ) { 
    7885            // if the email addres supplied is valid 
    79             if ( voucherpress_code_is_valid( $voucher_guid, $code ) ) { 
     86            if ( voucherpress_code_is_valid( $voucher_guid, $code ) != "unregistered" ) { 
    8087                // download the voucher 
    8188                voucherpress_download_voucher( $voucher_guid, $code ); 
     
    122129    //} else { 
    123130        wp_die( __( "Sorry, that item has run out", "voucherpress" ) ); 
     131    //} 
     132    exit(); 
     133} 
     134 
     135// show a downloaded voucher page 
     136function voucherpress_downloaded() { 
     137    global $wp_query; 
     138    $wp_query->set_404(); 
     139    //if ( file_exists( TEMPLATEPATH.'/404.php' ) ) { 
     140    //  require TEMPLATEPATH.'/404.php'; 
     141    //} else { 
     142        wp_die( __( "You have already downloaded this voucher", "voucherpress" ) ); 
    124143    //} 
    125144    exit(); 
     
    171190    $prefix = $wpdb->prefix; 
    172191    if ( $wpdb->base_prefix != "" ) { $prefix = $wpdb->base_prefix; } 
    173     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Plain black border', 1, 0);"); 
    174     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Mint chocolate', 1, 0);"); 
    175     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Red floral border', 1, 0);"); 
    176     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Single red rose (top left)', 1, 0);"); 
    177     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Red flowers', 1, 0);"); 
    178     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Pink flowers', 1, 0);"); 
    179     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Abstract green bubbles', 1, 0);"); 
    180     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('International post', 1, 0);"); 
    181     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Gold ribbon', 1, 0);"); 
    182     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Monochrome bubble border', 1, 0);"); 
    183     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Colourful swirls', 1, 0);"); 
    184     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Red gift bag', 1, 0);"); 
    185     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Blue ribbon', 1, 0);"); 
    186     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Autumn floral border', 1, 0);"); 
    187     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Yellow gift boxes', 1, 0);"); 
    188     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Wrought iron border', 1, 0);"); 
    189     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Abstract rainbow flowers', 1, 0);"); 
    190     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Christmas holly border', 1, 0);"); 
    191     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Small gold ribbon', 1, 0);"); 
    192     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Small red ribbon', 1, 0);"); 
    193     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('White gift boxes', 1, 0);"); 
    194     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Glass flowers border', 1, 0);"); 
    195     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Single red rose (bottom centre)', 1, 0);"); 
    196     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Fern border', 1, 0);"); 
    197     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Blue floral watermark', 1, 0);"); 
    198     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Monochrome ivy border', 1, 0);"); 
    199     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Ornate border', 1, 0);"); 
    200     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Winter flower corners', 1, 0);"); 
    201     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Spring flower corners', 1, 0);"); 
    202     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Pattern border', 1, 0);"); 
    203     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Orange flower with bar', 1, 0);"); 
    204     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Small coat of arms', 1, 0);"); 
    205     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Grunge border', 1, 0);"); 
    206     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Coffee beans', 1, 0);"); 
    207     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Blue gift boxes', 1, 0);"); 
    208     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Spring flowers border', 1, 0);"); 
    209     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Ornate magenta border', 1, 0);"); 
    210     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Mexico border', 1, 0);"); 
    211     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Chalk border', 1, 0);"); 
    212     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Thick border', 1, 0);"); 
    213     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Dark chalk border', 1, 0);"); 
    214     $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Ink border', 1, 0);"); 
     192    $templates = $wpdb->get_var( "select count(name) from " . $prefix . "voucherpress_templates;" ); 
     193    if ($templates == 0) { 
     194        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Plain black border', 1, 0);"); 
     195        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Mint chocolate', 1, 0);"); 
     196        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Red floral border', 1, 0);"); 
     197        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Single red rose (top left)', 1, 0);"); 
     198        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Red flowers', 1, 0);"); 
     199        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Pink flowers', 1, 0);"); 
     200        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Abstract green bubbles', 1, 0);"); 
     201        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('International post', 1, 0);"); 
     202        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Gold ribbon', 1, 0);"); 
     203        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Monochrome bubble border', 1, 0);"); 
     204        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Colourful swirls', 1, 0);"); 
     205        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Red gift bag', 1, 0);"); 
     206        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Blue ribbon', 1, 0);"); 
     207        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Autumn floral border', 1, 0);"); 
     208        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Yellow gift boxes', 1, 0);"); 
     209        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Wrought iron border', 1, 0);"); 
     210        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Abstract rainbow flowers', 1, 0);"); 
     211        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Christmas holly border', 1, 0);"); 
     212        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Small gold ribbon', 1, 0);"); 
     213        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Small red ribbon', 1, 0);"); 
     214        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('White gift boxes', 1, 0);"); 
     215        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Glass flowers border', 1, 0);"); 
     216        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Single red rose (bottom centre)', 1, 0);"); 
     217        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Fern border', 1, 0);"); 
     218        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Blue floral watermark', 1, 0);"); 
     219        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Monochrome ivy border', 1, 0);"); 
     220        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Ornate border', 1, 0);"); 
     221        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Winter flower corners', 1, 0);"); 
     222        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Spring flower corners', 1, 0);"); 
     223        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Pattern border', 1, 0);"); 
     224        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Orange flower with bar', 1, 0);"); 
     225        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Small coat of arms', 1, 0);"); 
     226        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Grunge border', 1, 0);"); 
     227        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Coffee beans', 1, 0);"); 
     228        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Blue gift boxes', 1, 0);"); 
     229        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Spring flowers border', 1, 0);"); 
     230        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Ornate magenta border', 1, 0);"); 
     231        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Mexico border', 1, 0);"); 
     232        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Chalk border', 1, 0);"); 
     233        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Thick border', 1, 0);"); 
     234        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Dark chalk border', 1, 0);"); 
     235        $wpdb->query("insert into " . $prefix . "voucherpress_templates (name, live, blog_id) values ('Ink border', 1, 0);"); 
     236    } 
    215237} 
    216238 
     
    544566    <input type="text" name="limit" id="limit" class="num" value="" /> <span>' . __( "Set the number of times this voucher can be downloaded (leave blank or 0 for unlimited)", "voucherpress" ) . '</span></p> 
    545567    <p><label for="expiryyear">' . __( "Date voucher expires", "voucherpress" ) . '</label> 
    546     ' . __( "Year:", "voucherpress" ) . ' <input type="text" name="expiryyear" id="expiryyear" class="num" value="' . date( "Y", time() ) . '" /> 
    547     ' . __( "Month:", "voucherpress" ) . ' <input type="text" name="expirymonth" id="expirymonth" class="num" value="' . date( "n", time() ) . '" /> 
    548     ' . __( "Day:", "voucherpress" ) . ' <input type="text" name="expiryday" id="expiryday" class="num" value="' . date( "j", time() ) . '" />  
     568    ' . __( "Year:", "voucherpress" ) . ' <input type="text" name="expiryyear" id="expiryyear" class="num" value="" /> 
     569    ' . __( "Month:", "voucherpress" ) . ' <input type="text" name="expirymonth" id="expirymonth" class="num" value="" /> 
     570    ' . __( "Day:", "voucherpress" ) . ' <input type="text" name="expiryday" id="expiryday" class="num" value="" />  
    549571    <span>' . __( "Enter the date on which this voucher will expire (leave blank for never)", "voucherpress" ) . '</span></p> 
    550572    <p><input type="button" name="preview" id="previewbutton" class="button" value="' . __( "Preview", "voucherpress" ) . '" /> 
     
    16401662            voucherpress_runout(); 
    16411663             
     1664        } else if ( $valid === "downloaded" )  { 
     1665         
     1666            // this voucher has been downloaded already 
     1667            voucherpress_downloaded(); 
     1668             
    16421669        } else if ( $valid === "expired" )  { 
    16431670         
     
    18801907        $blog_id = voucherpress_blog_id(); 
    18811908        global $wpdb; 
    1882         $sql = $wpdb->prepare( "select v.require_email, ifnull( d.email, '' ) as email, ifnull( d.downloaded, 0 ) as downloaded, v.`limit`, v.expiry from 
     1909        $sql = $wpdb->prepare( "select v.id, v.require_email, ifnull( d.email, '' ) as email, ifnull( d.downloaded, 0 ) as downloaded, v.`limit`, v.expiry from 
    18831910                " . $prefix . "voucherpress_vouchers v 
    18841911                left outer join " . $prefix . "voucherpress_downloads d on d.voucherid = v.id and d.guid = %s 
     
    18901917        if ( $row ) 
    18911918        { 
    1892             // if there is a limit and the limit has been reached 
    1893             if ( (int)$row->limit != 0 && (int)$row->limit > (int)$row->downloads ) 
    1894             { 
    1895              
    1896                 return "runout"; 
     1919 
     1920            // a limit has been set 
     1921            if ( (int)$row->limit != 0 ) { 
     1922                $sql = $wpdb->prepare( "select count(id) from " . $prefix . "voucherpress_downloads where voucherid = %d", $row->id ); 
     1923                $downloads = $wpdb->get_var( $sql ); 
     1924                // if the limit has been reached 
     1925                if ( (int)$downloads >= (int)$row->limit )  { 
     1926                    return "runout"; 
     1927                } 
     1928            } 
    18971929             
    18981930            // if there is an expiry and the expiry is in the past 
    1899             } else if ( (int)$row->expiry != 0 && (int)$row->expiry < time() ) { 
    1900              
     1931            if ( (int)$row->expiry != 0 && (int)$row->expiry < time() ) { 
    19011932                return "expired"; 
    1902              
     1933            } 
     1934             
     1935            // if emails are not required 
     1936            if ( $row->require_email != "1" ) { 
     1937                return "valid"; 
    19031938            } else { 
    1904              
    1905                 // if emails are not required 
    1906                 if ( $row->require_email != "1" ) 
    1907                 { 
    1908                  
     1939                // if the voucher has been downloaded 
     1940                if ( $code != "" && $row->email != "" && $row->downloaded != "0" ) { 
     1941                    return "downloaded"; 
     1942                } 
     1943                // if the voucher has not been downloaded 
     1944                if ( $code != "" && $row->email != "" && $row->downloaded == "0" ) { 
    19091945                    return "valid"; 
    1910                      
    1911                 } else { 
    1912                  
    1913                     // if this email is registered and the voucher not yet downloaded 
    1914                     if ( $row->email != "" && $row->downloaded == "0" )  
    1915                     { 
    1916                         return "valid"; 
    1917                     } 
    1918                      
    19191946                } 
    1920                  
     1947                return "unregistered"; 
    19211948            } 
    19221949        } 
Note: See TracChangeset for help on using the changeset viewer.