'',
'tips' => '',
'class' => 'coupon',
'id' => '',
'title' => '',
'description' => '',
'target' => '_blank',
'label' => __('Coupon Code', WPUS_COUPON_CODE_TXTDOMAIN),
'expired' => '',
'start' => '',
'hidden' => '0', //1 - Hidden after expiration
), $atts ) );
if (preg_match("/^\d{4}-\d{1,2}-\d{1,2}$/", $start)) {
list($year, $month, $day) = explode("-", $start);
if ( mktime(0, 0, 0, $month, $day, $year) > time() ) {
return "";
}
}
if ($hidden) {
if (preg_match("/^\d{4}-\d{1,2}-\d{1,2}$/", $expired)) {
list($year, $month, $day) = explode("-", $expired);
if ( mktime(23, 59, 59, $month, $day, $year) < time() ) {
return "";
}
}
}
$coupon = $content;
$html = '';
if ($coupon)
{
//$html = wpus_coupon_get_html($coupon, $url, $tips, $class, $id, $target, $title);
$html = wpus_coupon_get_html($coupon, $url, $tips, $class, $id, $title, $description, $target, $label, $expired);
}
return $html;
}
}
if (!function_exists('wpus_coupon_get_html'))
{
function wpus_coupon_get_html($coupon, $url='', $tips='', $class='', $id='', $title='', $description='', $target='_blank', $label='', $expired='')
{
global $wpus_coupon_add_js;
static $count = 0;
$count++;
$wpus_coupon_add_js = true;
$label_arr = array (
__('Coupon Code', WPUS_COUPON_CODE_TXTDOMAIN),
__('Discount Coupon', WPUS_COUPON_CODE_TXTDOMAIN),
__('Discount Code', WPUS_COUPON_CODE_TXTDOMAIN),
__('Promo Code', WPUS_COUPON_CODE_TXTDOMAIN),
__('Coupon', WPUS_COUPON_CODE_TXTDOMAIN),
__('Promotion Code', WPUS_COUPON_CODE_TXTDOMAIN),
__('Voucher Code', WPUS_COUPON_CODE_TXTDOMAIN),
__('Promotional Code', WPUS_COUPON_CODE_TXTDOMAIN),
__('Voucher', WPUS_COUPON_CODE_TXTDOMAIN),
__('Discount Voucher', WPUS_COUPON_CODE_TXTDOMAIN)
);
$html = "
";
if ($title) {
$html .= "
$title
";
}
$html .= "
";
//$html .= "
$label:
";
$html .= "
" . $label_arr[(($count-1)%count($label_arr))] . ":
";
$html .= "
"; //
$html .= "
"; //
$html .= "
";
if ($description) {
if ($expired) {
$description = "
" . __('Expired Date: ', WPUS_COUPON_CODE_TXTDOMAIN) . wpus_coupon_date_format($expired) ."$description";
}
$html .= "
$description
";
}
$html .= "
"; //
if ($count == 6) {
$html .= '
';
}
return $html;
}
}
if (!function_exists('wpus_deal_shortcode'))
{
function wpus_deal_shortcode($atts, $content=null, $code="")
{
// $atts ::= array of attributes
// $content ::= text within enclosing form of shortcode element
// $code ::= the shortcode found, when == callback name
// examples: [wpusgames id=1 type='mochi' style='auto']
global $wpdb;
extract( shortcode_atts( array(
'url' => '',
'id' => '',
'title' => '',
'target' => '_blank',
'label' => __('Sale: ', WPUS_COUPON_CODE_TXTDOMAIN),
'expired' => '',
), $atts ) );
$deal = $content;
$html = '';
if ($deal)
{
//$html = wpus_coupon_get_html($coupon, $url, $tips, $class, $id, $target, $title);
$html = '
'. wpus_deal_get_html($deal, $url, $id, $title, $target, $label) .'
';
}
return $html;
}
}
if (!function_exists('wpus_deal_get_html'))
{
function wpus_deal_get_html($deal, $url='', $id='', $title='', $target='_blank', $label='', $expired='')
{
static $count = 0;
$count++;
$url = wpus_url_redirect($url);
if ($title) {
$html = "
";
}
$html .= "
";
if ($deal) {
if ($expired) {
$deal = "$deal
" . __('End Date: ', WPUS_COUPON_CODE_TXTDOMAIN) . wpus_coupon_date_format($expired) ."";
}
$html .= "
$deal
";
}
return $html;
}
}
if (!function_exists('wpus_coupon_add_footer'))
{
function wpus_coupon_add_footer($add_jquery = true)
{
global $wpus_coupon_plugin_url_base;
global $wpus_coupon_add_js;
if (!$wpus_coupon_add_js)
{
return;
}
$wpus_coupon_add_js = false;
$coupontips = __('Click to copy code and open coupon link.', WPUS_COUPON_CODE_TXTDOMAIN);
echo <<
$coupontips
EOF;
}
}
if (!function_exists('wpus_coupon_date_format'))
{
function wpus_coupon_date_format($date)
{
$month_txt = array (
__('January', WPUS_COUPON_CODE_TXTDOMAIN),
__('February', WPUS_COUPON_CODE_TXTDOMAIN),
__('March', WPUS_COUPON_CODE_TXTDOMAIN),
__('April', WPUS_COUPON_CODE_TXTDOMAIN),
__('May', WPUS_COUPON_CODE_TXTDOMAIN),
__('June', WPUS_COUPON_CODE_TXTDOMAIN),
__('July', WPUS_COUPON_CODE_TXTDOMAIN),
__('August', WPUS_COUPON_CODE_TXTDOMAIN),
__('September', WPUS_COUPON_CODE_TXTDOMAIN),
__('October', WPUS_COUPON_CODE_TXTDOMAIN),
__('November', WPUS_COUPON_CODE_TXTDOMAIN),
__('December', WPUS_COUPON_CODE_TXTDOMAIN)
);
if (!isset($date) || strlen(trim($date)) == 0 || strtolower(trim($date)) =='unk' || strtolower(trim($date)) =='unknown') {
return __('unknown', WPUS_COUPON_CODE_TXTDOMAIN);
}
if (preg_match("/^\d{4}-\d{1,2}-\d{1,2}$/", $date)) {
list($year, $month, $day) = explode("-", $date);
$month = $month - 1;
$day = $day + 0;
return sprintf( __('%2$s %1$s, %3$s',WPUS_COUPON_CODE_TXTDOMAIN), $day, $month_txt[$month], $year );
}
return $date;
}
}
?>