function appthemes_process_membership_order($current_user, $order) { //if order ID matches pending membership id suffix, then process the order by extendning the date and setting the ID if (isset($current_user->active_membership_pack)) { $user_active_pack_id = get_pack_id($current_user->active_membership_pack); } else { $user_active_pack_id = false; } if (isset($current_user->membership_expires)) { $user_active_pack_expiration = $current_user->membership_expires; } else { $user_active_pack_expiration = strtotime(current_time('mysql')); } if ($order['total_cost'] == 0 || $order['order_id'] == $_REQUEST['oid'] || $order['order_id'] == $_REQUEST['custom'] || $order['order_id'] == $_REQUEST['invoice']) { //update the user profile to current order pack_id taking it off "pending" status and setup the membership object update_user_meta($current_user->ID, 'active_membership_pack', $order['pack_id']); $membership = get_pack($order['pack_id']); //extend membership if its still active, so long as its not free (otherwise free extentions could be infinite) $expires_in_days = appthemes_seconds_to_days(strtotime($user_active_pack_expiration) - strtotime(current_time('mysql'))); $purchase = $order['pack_duration'] . ' ' . __('days', 'appthemes'); if ($expires_in_days > 0 && $order['total_cost'] > 0 && $order['pack_id'] == $user_active_pack_id) { $updated_expires_date = appthemes_mysql_date($user_active_pack_expiration, $order['pack_duration']); } else { $updated_expires_date = appthemes_mysql_date(current_time('mysql'), $order['pack_duration']); } update_user_meta($current_user->ID, 'membership_expires', $updated_expires_date); $order['updated_expires_date'] = $updated_expires_date; delete_option($order['option_order_id']); //return the order information in case its needed return $order; } else { //get orders of the user $the_order = get_user_orders($current_user->ID, $order['order_id']); return false; } }
<?php /** * popular posts on blog for tabbed sidebar * shows most popular posts within the last 3 months * or overall if any found based on page views */ global $post; // give us the most popular blog posts based on page views, last 3 months $lastmonths = appthemes_mysql_date(current_time('mysql'), -90); $args = array('post_type' => 'post', 'posts_per_page' => 5, 'paged' => 1, 'no_found_rows' => true, 'date_start' => $lastmonths); $popular = new CP_Popular_Posts_Query($args); // give us the most popular blog posts based on page views, overall if (!$popular->have_posts()) { unset($args['date_start']); $popular = new CP_Popular_Posts_Query($args); } ?> <ul class="pop-blog"> <?php if ($popular->have_posts()) { while ($popular->have_posts()) { $popular->the_post(); ?> <li> <div class="post-thumb">
function cp_dashboard_charts() { global $wpdb, $cp_options; $sql = "SELECT COUNT(post_title) as total, post_date FROM {$wpdb->posts} WHERE post_type = %s AND post_date > %s GROUP BY DATE(post_date) DESC"; $results = $wpdb->get_results($wpdb->prepare($sql, APP_POST_TYPE, appthemes_mysql_date(current_time('mysql'), -30))); $listings = array(); // put the days and total posts into an array foreach ((array) $results as $result) { $the_day = date('Y-m-d', strtotime($result->post_date)); $listings[$the_day] = $result->total; } // setup the last 30 days for ($i = 0; $i < 30; $i++) { $each_day = date('Y-m-d', strtotime('-' . $i . ' days')); // if there's no day with posts, insert a goose egg if (!in_array($each_day, array_keys($listings))) { $listings[$each_day] = 0; } } // sort the values by date ksort($listings); // Get sales - completed orders with a cost $results = array(); $currency_symbol = $cp_options->curr_symbol; if (current_theme_supports('app-payments')) { $sql = "SELECT sum( m.meta_value ) as total, p.post_date FROM {$wpdb->postmeta} m INNER JOIN {$wpdb->posts} p ON m.post_id = p.ID WHERE m.meta_key = 'total_price' AND p.post_status IN ( '" . APPTHEMES_ORDER_COMPLETED . "', '" . APPTHEMES_ORDER_ACTIVATED . "' ) AND p.post_date > %s GROUP BY DATE(p.post_date) DESC"; $results = $wpdb->get_results($wpdb->prepare($sql, appthemes_mysql_date(current_time('mysql'), -30))); $currency_symbol = APP_Currencies::get_current_symbol(); } $sales = array(); // put the days and total posts into an array foreach ((array) $results as $result) { $the_day = date('Y-m-d', strtotime($result->post_date)); $sales[$the_day] = $result->total; } // setup the last 30 days for ($i = 0; $i < 30; $i++) { $each_day = date('Y-m-d', strtotime('-' . $i . ' days')); // if there's no day with posts, insert a goose egg if (!in_array($each_day, array_keys($sales))) { $sales[$each_day] = 0; } } // sort the values by date ksort($sales); ?> <div id="placeholder"></div> <script language="javascript" type="text/javascript"> // <![CDATA[ jQuery(function() { var posts = [ <?php foreach ($listings as $day => $value) { $sdate = strtotime($day); $sdate = $sdate * 1000; // js timestamps measure milliseconds vs seconds $newoutput = "[{$sdate}, {$value}],\n"; echo $newoutput; } ?> ]; var sales = [ <?php foreach ($sales as $day => $value) { $sdate = strtotime($day); $sdate = $sdate * 1000; // js timestamps measure milliseconds vs seconds $newoutput = "[{$sdate}, {$value}],\n"; echo $newoutput; } ?> ]; var placeholder = jQuery("#placeholder"); var output = [ { data: posts, label: "<?php _e('New Ad Listings', APP_TD); ?> ", symbol: '' }, { data: sales, label: "<?php _e('Total Sales', APP_TD); ?> ", symbol: '<?php echo $currency_symbol; ?> ', yaxis: 2 } ]; var options = { series: { lines: { show: true }, points: { show: true } }, grid: { tickColor:'#f4f4f4', hoverable: true, clickable: true, borderColor: '#f4f4f4', backgroundColor:'#FFFFFF' }, xaxis: { mode: 'time', timeformat: "%m/%d" }, yaxis: { min: 0 }, y2axis: { min: 0, tickFormatter: function(v, axis) { return "<?php echo $currency_symbol; ?> " + v.toFixed(axis.tickDecimals) } }, legend: { position: 'nw' } }; jQuery.plot(placeholder, output, options); // reload the plot when browser window gets resized jQuery(window).resize(function() { jQuery.plot(placeholder, output, options); }); function showChartTooltip(x, y, contents) { jQuery('<div id="charttooltip">' + contents + '</div>').css( { position: 'absolute', display: 'none', top: y + 5, left: x + 5, opacity: 1 } ).appendTo("body").fadeIn(200); } var previousPoint = null; jQuery("#placeholder").bind("plothover", function (event, pos, item) { jQuery("#x").text(pos.x.toFixed(2)); jQuery("#y").text(pos.y.toFixed(2)); if (item) { if (previousPoint != item.datapoint) { previousPoint = item.datapoint; jQuery("#charttooltip").remove(); var x = new Date(item.datapoint[0]), y = item.datapoint[1]; var xday = x.getDate(), xmonth = x.getMonth()+1; // jan = 0 so we need to offset month showChartTooltip(item.pageX, item.pageY, xmonth + "/" + xday + " - <b>" + item.series.symbol + y + "</b> " + item.series.label); } } else { jQuery("#charttooltip").remove(); previousPoint = null; } }); }); // ]]> </script> <?php }
echo appthemes_display_date($current_user->membership_expires); ?> </div> <div class="clr"></div> </li> <li> <div class="labelwrapper"><label><strong><?php _e('New Expiration:', 'appthemes'); ?> </strong></label></div> <div id="active_membership_pack"> <?php if ($membership->pack_membership_price > 0) { echo appthemes_display_date(appthemes_mysql_date($current_user->membership_expires, $membership->pack_duration)); } else { echo appthemes_display_date(appthemes_mysql_date(current_time('mysql'), $membership->pack_duration)); } ?> </div> <div class="clr"></div> </li> <?php } ?> <li> <div class="labelwrapper"> <label><?php _e('Membership Purchase Fee', 'appthemes'); ?> :</label>
function cp_default_ad() { global $wpdb; $posts = get_posts(array('posts_per_page' => 1, 'post_type' => APP_POST_TYPE, 'no_found_rows' => true)); if (!empty($posts)) { return; } $cat = appthemes_maybe_insert_term('Misc', APP_TAX_CAT); $description = '<p>This is your first ClassiPress ad listing. It is a placeholder ad just so you can see how it works. Delete this before launching your new classified ads site.</p>Duis arcu turpis, varius nec sagittis id, ultricies ac arcu. Etiam sagittis rutrum nunc nec viverra. Etiam egestas congue mi vel sollicitudin.</p><p>Vivamus ac libero massa. Cras pellentesque volutpat dictum. Ut blandit dapibus augue, lobortis cursus mi blandit sed. Fusce vulputate hendrerit sapien id aliquet.</p>'; $default_ad = array('post_title' => 'My First Classified Ad', 'post_name' => 'my-first-classified-ad', 'post_content' => $description, 'post_status' => 'publish', 'post_type' => APP_POST_TYPE, 'post_author' => 1); // insert the default ad $post_id = wp_insert_post($default_ad); //set the custom post type categories wp_set_post_terms($post_id, $cat['term_id'], APP_TAX_CAT, false); //set the custom post type tags $new_tags = array('ad tag1', 'ad tag2', 'ad tag3'); wp_set_post_terms($post_id, $new_tags, APP_TAX_TAG, false); // set some default meta values $ad_expire_date = appthemes_mysql_date(current_time('mysql'), 30); $advals['cp_sys_expire_date'] = $ad_expire_date; $advals['cp_sys_ad_duration'] = '30'; $advals['cp_sys_ad_conf_id'] = '3624e0d2963459d2'; $advals['cp_sys_userIP'] = '153.247.194.375'; $advals['cp_daily_count'] = '0'; $advals['cp_total_count'] = '0'; $advals['cp_price'] = '250'; $advals['cp_street'] = '153 Townsend St'; $advals['cp_city'] = 'San Francisco'; $advals['cp_state'] = 'California'; $advals['cp_country'] = 'United States'; $advals['cp_zipcode'] = '94107'; $advals['cp_sys_total_ad_cost'] = '5.00'; // now add the custom fields into WP post meta fields foreach ($advals as $meta_key => $meta_value) { add_post_meta($post_id, $meta_key, $meta_value, true); } // set coordinates of new ad cp_update_geocode($post_id, '', '37.779633', '-122.391762'); }
/** * Processes ad listing activation on order activation. * * @param object $order */ function cp_payments_handle_ad_listing_activated($order) { global $cp_options; foreach ($order->get_items(CP_ITEM_LISTING) as $item) { $ad_id = wp_update_post(array('ID' => $item['post_id'], 'post_status' => 'publish')); $ad_length = get_post_meta($ad_id, 'cp_sys_ad_duration', true); if (empty($ad_length)) { $ad_length = $cp_options->prun_period; } $ad_expire_date = appthemes_mysql_date(current_time('mysql'), $ad_length); update_post_meta($ad_id, 'cp_sys_expire_date', $ad_expire_date); } }
/** * Processes ad listing activation on order activation. * * @param object $order * * @return void */ function cp_payments_handle_ad_listing_activated($order) { global $cp_options; foreach ($order->get_items() as $item) { if (APP_POST_TYPE != $item['post']->post_type) { continue; } // update listing status $listing_args = array('ID' => $item['post_id'], 'post_status' => 'publish', 'post_date' => current_time('mysql'), 'post_date_gmt' => current_time('mysql', 1)); $listing_id = wp_update_post($listing_args); $ad_length = get_post_meta($listing_id, 'cp_sys_ad_duration', true); if (empty($ad_length)) { $ad_length = $cp_options->prun_period; } $ad_expire_date = appthemes_mysql_date(current_time('mysql'), $ad_length); update_post_meta($listing_id, 'cp_sys_expire_date', $ad_expire_date); } }
/** * Processing form. * * @param object $order * @param object $checkout * * return void */ public function process($order, $checkout) { global $cp_options; $listing = $this->get_listing_obj(); // set listing expire date $length = get_post_meta($listing->ID, 'cp_sys_ad_duration', true); if (empty($length)) { $length = $cp_options->prun_period; } $expire_date = appthemes_mysql_date(current_time('mysql'), $length); update_post_meta($listing->ID, 'cp_sys_expire_date', $expire_date); }
</strong></label></div> <div id="active_membership_pack" class="ad-static-field"><?php echo appthemes_display_date($current_user->membership_expires); ?> </div> <div class="clr"></div> </li> <li> <div class="labelwrapper"><label><strong><?php _e('New Expiration:', APP_TD); ?> </strong></label></div> <div id="active_membership_pack" class="ad-static-field"> <?php echo appthemes_display_date(appthemes_mysql_date($current_user->membership_expires, $membership->duration)); ?> </div> <div class="clr"></div> </li> <?php } ?> <li> <div class="labelwrapper"><label><?php _e('Price:', APP_TD); ?> </label></div> <div id="review" class="ad-static-field"><?php appthemes_display_price($membership->price);
/** * Updates user membership. * * @param int $user_id * @param object $package * * @return bool */ function cp_update_user_membership($user_id, $package) { $user = get_user_by('id', $user_id); if (!$user || !$package) { return false; } $current_membership = cp_get_user_membership_package($user_id); if ($current_membership && $current_membership->ID == $package->ID) { // user have active that same membership, so extend date $base_date = $user->membership_expires; } else { $base_date = current_time('mysql'); } $new_expiration_date = appthemes_mysql_date($base_date, $package->duration); // update user membership package id and expiration date update_user_meta($user_id, 'active_membership_pack', $package->ID); update_user_meta($user_id, 'membership_expires', $new_expiration_date); return true; }