Skip to content

Commit

Permalink
Adding [s2Member-Gift-Codes /]. See: wpsharks/s2member#285, wpshark…
Browse files Browse the repository at this point in the history
  • Loading branch information
jaswsinc committed Jan 29, 2015
1 parent 3d4eb2d commit 1b5e35a
Show file tree
Hide file tree
Showing 13 changed files with 352 additions and 104 deletions.
40 changes: 27 additions & 13 deletions s2member-pro/includes/classes/coupons.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function list_to_coupons($list, $update = TRUE)

$_coupon['max_uses'] = !empty($_coupon_parts[6]) ? (integer)$_coupon_parts[6] : 0;

if(strpos((string)$update, 'counters') !== FALSE && isset($_coupon_parts[7]))
if($update && strpos((string)$update, 'counters') !== FALSE && isset($_coupon_parts[7]))
$this->update_uses($_coupon['code'], $_coupon_parts[7]);

$_coupon['is_gift'] = FALSE; // Hard-coded coupons are never gifts.
Expand Down Expand Up @@ -200,6 +200,8 @@ public function coupons_to_list($coupons, $update = TRUE)

# Line ending; always.

// `code|discount|dates|directive|singulars|users|max uses`.

$list .= "\n"; // One coupon per line.
}
unset($_coupon); // Housekeeping.
Expand Down Expand Up @@ -520,27 +522,39 @@ public function get_gift($coupon_code)
return is_array($gift) && !empty($gift['code']) ? $gift : array();
}

public function generate_gifts_based_on($coupon_code, $quantity = 1)
public function generate_gifts($args)
{
if(!($coupon_code = trim((string)$coupon_code)))
return array(); // Not possible.

if(!($coupon_code = $this->n_code($coupon_code)))
return array(); // Not possible.
$default_args = array(
'quantity' => 0,
'discount' => '',
'directive' => '',
'singulars' => '',
);
$args = array_merge($default_args, $args);
$args = array_intersect_key($args, $default_args);

if(empty($this->coupons[$coupon_code]))
return array(); // Not possible.
$quantity = (integer)$args['quantity'];
$discount = trim((string)$args['discount']);
$directive = trim((string)$args['directive']);
$singulars = trim((string)$args['singulars']);

if(!($quantity = (integer)$quantity) || $quantity < 1)
return array(); // Not possible.

for($_i = 1, $gifts = array(); $_i <= $quantity; $_i++)
for($_i = 0, $gifts = array(); $_i < $quantity; $_i++)
{
$_gift_code = $this->n_code(c_ws_plugin__s2member_utils_encryption::uunnci_key_20_max());
$gifts[$_gift_code] = array_merge($this->coupons[$coupon_code], array('code' => $_gift_code, 'is_gift' => TRUE));
$_gift_code = c_ws_plugin__s2member_utils_encryption::uunnci_key_20_max();
$_gift_code = $this->n_code('GC'.str_pad($_gift_code, 20, '0', STR_PAD_LEFT));
$_gift_list = $_gift_code.'|'.$discount.'||'.$directive.'|'.$singulars.'||1';
// `code|discount|dates|directive|singulars|users|max uses`.

$_gift = $this->list_to_coupons($_gift_list, FALSE);
$_gift = array_merge(array_pop($_gift), array('is_gift' => TRUE));
$gifts[$_gift_code] = $_gift; // A coupon code that's a gift.

add_option($this->gift_option_key($_gift_code), $gifts[$_gift_code], '', 'no');
}
unset($_i, $_gift_code); // Housekeeping.
unset($_i, $_gift_code, $_gift_list, $_gift); // Housekeeping.

return $gifts;
}
Expand Down
122 changes: 61 additions & 61 deletions s2member-pro/includes/classes/return-templates.inc.php
Original file line number Diff line number Diff line change
@@ -1,70 +1,70 @@
<?php
/**
* Return Templates (introduced by s2Member Pro).
*
* Copyright: © 2009-2011
* {@link http://www.websharks-inc.com/ WebSharks, Inc.}
* (coded in the USA)
*
* This WordPress plugin (s2Member Pro) is comprised of two parts:
*
* o (1) Its PHP code is licensed under the GPL license, as is WordPress.
* You should have received a copy of the GNU General Public License,
* along with this software. In the main directory, see: /licensing/
* If not, see: {@link http://www.gnu.org/licenses/}.
*
* o (2) All other parts of (s2Member Pro); including, but not limited to:
* the CSS code, some JavaScript code, images, and design;
* are licensed according to the license purchased.
* See: {@link http://www.s2member.com/prices/}
*
* Unless you have our prior written consent, you must NOT directly or indirectly license,
* sub-license, sell, resell, or provide for free; part (2) of the s2Member Pro Module;
* or make an offer to do any of these things. All of these things are strictly
* prohibited with part (2) of the s2Member Pro Module.
*
* Your purchase of s2Member Pro includes free lifetime upgrades via s2Member.com
* (i.e. new features, bug fixes, updates, improvements); along with full access
* to our video tutorial library: {@link http://www.s2member.com/videos/}
*
* @package s2Member\Return_Templates
* @since 110720
*/
* Return Templates (introduced by s2Member Pro).
*
* Copyright: © 2009-2011
* {@link http://www.websharks-inc.com/ WebSharks, Inc.}
* (coded in the USA)
*
* This WordPress plugin (s2Member Pro) is comprised of two parts:
*
* o (1) Its PHP code is licensed under the GPL license, as is WordPress.
* You should have received a copy of the GNU General Public License,
* along with this software. In the main directory, see: /licensing/
* If not, see: {@link http://www.gnu.org/licenses/}.
*
* o (2) All other parts of (s2Member Pro); including, but not limited to:
* the CSS code, some JavaScript code, images, and design;
* are licensed according to the license purchased.
* See: {@link http://www.s2member.com/prices/}
*
* Unless you have our prior written consent, you must NOT directly or indirectly license,
* sub-license, sell, resell, or provide for free; part (2) of the s2Member Pro Module;
* or make an offer to do any of these things. All of these things are strictly
* prohibited with part (2) of the s2Member Pro Module.
*
* Your purchase of s2Member Pro includes free lifetime upgrades via s2Member.com
* (i.e. new features, bug fixes, updates, improvements); along with full access
* to our video tutorial library: {@link http://www.s2member.com/videos/}
*
* @package s2Member\Return_Templates
* @since 110720
*/
if(!defined('WPINC')) // MUST have WordPress.
exit("Do not access this file directly.");
exit('Do not access this file directly.');

if (!class_exists ("c_ws_plugin__s2member_pro_return_templates"))
if(!class_exists('c_ws_plugin__s2member_pro_return_templates'))
{
/**
* Return Templates (introduced by s2Member Pro).
*
* @package s2Member\Return_Templates
* @since 110720
*/
class c_ws_plugin__s2member_pro_return_templates
{
/**
* Return Templates (introduced by s2Member Pro).
*
* @package s2Member\Return_Templates
* @since 110720
*/
class c_ws_plugin__s2member_pro_return_templates
* Applies custom Return Template Headers.
*
* @package s2Member\Return_Templates
* @since 110720
*
* @attaches-to ``add_filter('ws_plugin__s2member_return_template_header');``
*
* @param string $default_header The default header *(i.e. HTML code)*, passed through by the Filter.
* @param array $vars An array of defined variables, passed through by the Filter.
*
* @return string A custom Return Template Header, if configured, else the ``$default_header``.
*/
public static function return_template_header($default_header = '', $vars = array())
{
if(!empty($GLOBALS['WS_PLUGIN__']['s2member']['o']['pro_'.$vars['template'].'_return_template_header']))
{
/**
* Applies custom Return Template Headers.
*
* @package s2Member\Return_Templates
* @since 110720
*
* @attaches-to ``add_filter("ws_plugin__s2member_return_template_header");``
*
* @param string $default_header The default header *(i.e. HTML code)*, passed through by the Filter.
* @param array $vars An array of defined variables, passed through by the Filter.
* @return string A custom Return Template Header, if configured, else the ``$default_header``.
*/
public static function return_template_header ($default_header = FALSE, $vars = FALSE)
{
if (!empty($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_" . $vars["template"] . "_return_template_header"]))
{
$code = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_" . $vars["template"] . "_return_template_header"];
$code = (!is_multisite () || !c_ws_plugin__s2member_utils_conds::is_multisite_farm () || is_main_site ()) ? c_ws_plugin__s2member_utilities::evl ($code) : $code;
return ($custom_header = $code);
}
return $default_header;
}
$code = $GLOBALS['WS_PLUGIN__']['s2member']['o']['pro_'.$vars['template'].'_return_template_header'];
$code = (!is_multisite() || !c_ws_plugin__s2member_utils_conds::is_multisite_farm() || is_main_site()) ? c_ws_plugin__s2member_utilities::evl($code) : $code;
return ($custom_header = $code);
}
return $default_header;
}
}
?>
}
43 changes: 21 additions & 22 deletions s2member-pro/includes/classes/sc-drip.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,35 @@
* @since 140328
*/
if(!defined('WPINC')) // MUST have WordPress.
exit("Do not access this file directly.");
exit('Do not access this file directly.');

if(!class_exists("c_ws_plugin__s2member_pro_sc_drip"))
if(!class_exists('c_ws_plugin__s2member_pro_sc_drip'))
{
/**
* [s2Drip] Shortcode.
*
* @package s2Member\Shortcodes
* @since 140328
*/
class c_ws_plugin__s2member_pro_sc_drip
{
/**
* [s2Drip] Shortcode.
*
* @package s2Member\Shortcodes
* @since 140328
*
* @attaches-to ``add_shortcode('s2Drip');``
*
* @param array $attr An array of Attributes.
* @param string $content Content inside the Shortcode.
* @param string $shortcode The actual Shortcode name itself.
*
* @return string Return-value of inner routine.
*/
class c_ws_plugin__s2member_pro_sc_drip
public static function shortcode($attr = array(), $content = '', $shortcode = '')
{
/**
* [s2Drip] Shortcode.
*
* @package s2Member\Shortcodes
* @since 140328
*
* @attaches-to ``add_shortcode("s2Drip");``
*
* @param array $attr An array of Attributes.
* @param string $content Content inside the Shortcode.
* @param string $shortcode The actual Shortcode name itself.
*
* @return inner Return-value of inner routine.
*/
public static function shortcode($attr = FALSE, $content = FALSE, $shortcode = FALSE)
{
return c_ws_plugin__s2member_pro_sc_drip_in::shortcode($attr, $content, $shortcode);
}
return c_ws_plugin__s2member_pro_sc_drip_in::shortcode($attr, $content, $shortcode);
}
}
?>
}
Loading

0 comments on commit 1b5e35a

Please sign in to comment.