function ym_fire_shortcode_parse($args, $content, $tag)
{
    global $firetypes, $wpdb;
    switch ($tag) {
        case 'app_counter':
            $html = '';
            //			$html = '<p>Pricing Models</p>';
            if (isset($args['pid'])) {
                // get pid counter
                $targets[] = ym_firesale_get_single($args['pid']);
            } else {
                $targets = ym_firesale_get_all_enabled();
            }
            // get all counters
            foreach ($targets as $fire) {
                if ($fire->fire_enable) {
                    // get current tier
                    $tier = ym_firesale_get_current_tier($fire->fire_id);
                    $tier = $tier[0];
                    // left till expire
                    // ignore type 2 as type 2 on actovates nbecome types 1
                    //what
                    $what = $firetypes[$fire->fire_type];
                    $which = $fire->fire_type_id;
                    // how long
                    if ($tier->fire_limit_by) {
                        //$tier->fire_tier_started
                        $left = $tier->fire_limit_var - time();
                        // hours
                        $hours = $left / 3600;
                        list($hours, $left) = explode('.', $hours);
                        $left = $hours . ' Hours Left';
                    } else {
                        // get sales
                        if ($fire->fire_type) {
                            // subs
                            $left = $tier->fire_limit_var - ym_fire_sales_subscription_since($tier->fire_tier_started, $which);
                        } else {
                            // ppp
                            $left = $tier->fire_limit_var - ym_fire_sales_ppp_since($tier->fire_tier_started, $which);
                        }
                        $left .= ' Sales Left';
                    }
                    if ($fire->fire_type) {
                        $pack = ym_get_pack($which);
                        $what = $pack['account_type'];
                        $link = '?ym_subscribe=1&ud=1';
                    } else {
                        // what is the post title
                        $what = 'SELECT post_title FROM ' . $wpdb->posts . ' WHERE ID = ' . $which;
                        $what = $wpdb->get_var($what);
                        $link = get_permalink($which);
                    }
                    $html .= '<p><a href="' . $link . '"><strong>' . $what . '</strong></a> ' . $left . '</p>';
                }
            }
            return $html;
        default:
            // not defined
    }
}
Esempio n. 2
0
function ym_firesale_maintain_tiers()
{
    global $wpdb;
    // both the next two foreachs make the assumption that two sales based tiers
    // won't invalidate at the same moment for a individual fire sale
    // do sales based ppp
    $fires = ym_firesale_get_all_enabled(false, YM_APP_TYPE_POST);
    // get each fire current tier
    foreach ($fires as $fire) {
        $sql = 'SELECT fire_tier_id, fire_limit_by, fire_limit_var, fire_tier_started, fire_type_id
			FROM ' . $wpdb->ym_app_models_tiers . ' t
			LEFT JOIN ' . $wpdb->ym_app_models . ' f
			ON f.fire_id = t.fire_id
			WHERE t.fire_id = ' . $fire->fire_id . '
			ORDER BY fire_order ASC LIMIT 1';
        $tier = $wpdb->get_results($sql);
        // one result
        if ($tier = $tier[0]) {
            $tier_id = $tier->fire_tier_id;
            $limit = $tier->fire_limit_var;
            $started = $tier->fire_tier_started;
            // post id
            $post_id = $tier->fire_type_id;
            // sales since
            $sales = ym_fire_sales_ppp_since($started, $post_id);
            if ($sales >= $limit) {
                ym_fire_tier_end($tier_id);
            }
        }
    }
    // do sales base ppp packs
    $fires = ym_firesale_get_all_enabled(false, YM_APP_TYPE_POST);
    foreach ($fires as $fire) {
        $sql = 'SELECT fire_tier_id, fire_limit_by, fire_limit_var, fire_tier_started, fire_type_id
			FROM ' . $wpdb->ym_app_models_tiers . ' t
			LEFT JOIN ' . $wpdb->ym_app_models . ' f
			ON f.fire_id = t.fire_id
			WHERE t.fire_id = ' . $fire->fire_id . '
			ORDER BY fire_order ASC LIMIT 1';
        $tier = $wpdb->get_results($sql);
        if ($tier = $tier[0]) {
            $tier_id = $tier->fire_tier_id;
            $limit = $tier->fire_limit_var;
            $started = $tier->fire_tier_started;
            // pack id
            $pack_id = $tier->fire_type_id;
            $sales = ym_fire_sales_ppp_packs_since($started, $pack_id);
            if ($sales >= $limit) {
                ym_fire_tier_end($tier_id);
            }
        }
    }
    // do sales based subs
    $fires = ym_firesale_get_all_enabled(false, YM_APP_TYPE_SUB);
    foreach ($fires as $fire) {
        $sql = 'SELECT fire_tier_id, fire_limit_by, fire_limit_var, fire_tier_started, fire_type_id
			FROM ' . $wpdb->ym_app_models_tiers . ' t
			LEFT JOIN ' . $wpdb->ym_app_models . ' f
			ON f.fire_id = t.fire_id
			WHERE t.fire_id = ' . $fire->fire_id . '
			ORDER BY fire_order ASC LIMIT 1';
        $tier = $wpdb->get_results($sql);
        if ($tier = $tier[0]) {
            $tier_id = $tier->fire_tier_id;
            $limit = $tier->fire_limit_var;
            $started = $tier->fire_tier_started;
            // subscription id
            $subs_id = $tier->fire_type_id;
            $sales = ym_fire_sales_subscription_since($started, $subs_id);
            if ($sales >= $limit) {
                ym_fire_tier_end($tier_id);
            }
        }
    }
    // do time based kills all tiers
    // both subs and sales based
    $tiers = ym_firesale_get_all_tiers();
    foreach ($tiers as $tier) {
        if ($tier->fire_limit_by == 1) {
            // its a time based type
            if ($tier->fire_limit_var < time()) {
                ym_fire_tier_end($tier->fire_tier_id);
            }
        }
    }
    // firesales without tiers
    // this is a garbage collection function
    //
    // even tho the other end scripts will kill a firesale
    // they wont delete from the db
    // so they dont call sale end like we do here!
    //
    $fires = ym_firesale_get_all();
    foreach ($fires as $fire) {
        if ($fire->tiers == 0 && $fire->fire_id) {
            ym_fire_sale_end($fire->fire_id);
        }
    }
}