Ejemplo n.º 1
0
/**
 * Returns user dashboard ad listing actions.
 *
 * @param int $listing_id (optional)
 *
 * @return string
 */
function cp_get_dashboard_listing_actions($listing_id = 0)
{
    global $cp_options;
    $actions = array();
    $listing_id = $listing_id ? $listing_id : get_the_ID();
    $listing = get_post($listing_id);
    $listing_status = cp_get_listing_status_name($listing_id);
    // edit button
    if ($cp_options->ad_edit) {
        $edit_attr = array('title' => __('Edit Ad', APP_TD), 'href' => add_query_arg(array('listing_edit' => $listing->ID), CP_EDIT_URL));
        if (in_array($listing_status, array('live', 'offline'))) {
            $actions['edit'] = $edit_attr;
        }
        if ($cp_options->moderate_edited_ads && in_array($listing_status, array('pending_moderation', 'pending_payment'))) {
            $actions['edit'] = $edit_attr;
        }
    }
    // delete button
    $actions['delete'] = array('title' => __('Delete Ad', APP_TD), 'href' => add_query_arg(array('aid' => $listing->ID, 'action' => 'delete'), CP_DASHBOARD_URL), 'onclick' => 'return confirmBeforeDeleteAd();');
    // pause button
    if ($listing_status == 'live') {
        $actions['pause'] = array('title' => __('Pause Ad', APP_TD), 'href' => add_query_arg(array('aid' => $listing->ID, 'action' => 'pause'), CP_DASHBOARD_URL));
    }
    // restart button
    if ($listing_status == 'offline') {
        $actions['restart'] = array('title' => __('Restart ad', APP_TD), 'href' => add_query_arg(array('aid' => $listing->ID, 'action' => 'restart'), CP_DASHBOARD_URL));
    }
    // set/unset sold links
    if (in_array($listing_status, array('live', 'offline'))) {
        $sold = get_post_meta($listing->ID, 'cp_ad_sold', true);
        if ($sold != 'yes') {
            // set sold
            $actions['set_sold'] = array('title' => __('Mark Sold', APP_TD), 'href' => add_query_arg(array('aid' => $listing->ID, 'action' => 'setSold'), CP_DASHBOARD_URL));
        } else {
            // unset sold
            $actions['unset_sold'] = array('title' => __('Unmark Sold', APP_TD), 'href' => add_query_arg(array('aid' => $listing->ID, 'action' => 'unsetSold'), CP_DASHBOARD_URL));
        }
    }
    // relist link
    if ($cp_options->allow_relist && in_array($listing_status, array('ended', 'live_expired'))) {
        $actions['relist'] = array('title' => __('Relist Ad', APP_TD), 'href' => add_query_arg(array('listing_renew' => $listing->ID), get_permalink(CP_Renew_Listing::get_id())));
    }
    // payment links
    if ($listing_status == 'pending_payment') {
        $order = appthemes_get_order_connected_to($listing->ID);
        // pay order
        $actions['pay_order'] = array('title' => __('Pay now', APP_TD), 'href' => appthemes_get_order_url($order->get_id()));
        if ($order->get_gateway()) {
            // reset gateway
            $actions['reset_gateway'] = array('title' => __('Reset Gateway', APP_TD), 'href' => get_the_order_cancel_url($order->get_id()));
        }
    }
    return apply_filters('cp_dashboard_listing_actions', $actions, $listing);
}
Ejemplo n.º 2
0
 function template_redirect()
 {
     global $cp_options;
     appthemes_require_login(array('login_text' => __('You must first login to edit an ad listing.', APP_TD), 'login_register_text' => __('You must first login or <a href="%s">register</a> to edit an ad listing.', APP_TD)));
     if (!current_user_can('edit_posts')) {
         appthemes_add_notice('denied-listing-edit', __('You are not allowed to edit ad listings.', APP_TD), 'error');
         wp_redirect(CP_DASHBOARD_URL);
         exit;
     }
     // redirect to dashboard if can't edit ad
     self::can_edit_ad();
     // redirect to renew page
     if (isset($_GET['listing_renew'])) {
         wp_redirect(add_query_arg('listing_renew', $_GET['listing_renew'], get_permalink(CP_Renew_Listing::get_id())));
         exit;
     }
     // add js files to wp_head. tiny_mce and validate
     add_action('wp_enqueue_scripts', 'cp_load_form_scripts');
 }
Ejemplo n.º 3
0
/**
 * Update orders to include urls, checkout type, and hash.
 *
 * @since 3.4
 */
function cp_upgrade_340_orders()
{
    $order_ids = get_option('cp_upgrade_340_orders');
    if (!$order_ids || $order_ids == 'done') {
        return;
    }
    $i = 0;
    $left_orders = $order_ids;
    foreach ($order_ids as $key => $order_id) {
        $i++;
        // all orders updated, quit the loop
        if (empty($left_orders)) {
            break;
        }
        // save current progress, and continue on next page load (memory and execution time have limits)
        if ($i > 50) {
            echo scb_admin_notice(sprintf(__('Orders Update Progress: %d orders left.', APP_TD), count($left_orders)));
            update_option('cp_upgrade_340_orders', $left_orders);
            return;
        }
        unset($left_orders[$key]);
        // updated order check
        if ($checkout_hash = get_post_meta($order_id, 'checkout_hash', true)) {
            continue;
        }
        // retrieve order object
        $order = appthemes_get_order($order_id);
        if (!$order) {
            continue;
        }
        // determine checkout type and url
        if ($item = $order->get_item(CP_ITEM_LISTING)) {
            $listing_orders_args = array('connected_type' => APPTHEMES_ORDER_CONNECTION, 'connected_query' => array('post_status' => 'any'), 'connected_to' => $item['post_id'], 'post_status' => 'any', 'fields' => 'ids', 'nopaging' => true);
            $listing_orders = new WP_Query($listing_orders_args);
            if (empty($listing_orders->posts) || $order_id == min($listing_orders->posts)) {
                $checkout_type = 'create-listing';
                $checkout_url = get_permalink(CP_Add_New::get_id());
            } else {
                $checkout_type = 'renew-listing';
                $checkout_url = add_query_arg('listing_renew', $item['post_id'], get_permalink(CP_Renew_Listing::get_id()));
            }
        } else {
            if ($item = $order->get_item(CP_ITEM_MEMBERSHIP)) {
                $checkout_type = 'membership-purchase';
                $checkout_url = get_permalink(CP_Membership::get_id());
            } else {
                // unknown/invalid order
                continue;
            }
        }
        // generate new checkout hash
        $hash = substr(sha1(time() . mt_rand(0, 1000)), 0, 20);
        // if url set, get the hash
        if ($complete_url = get_post_meta($order_id, 'complete_url', true)) {
            $parsed_url = parse_url($complete_url);
            parse_str($parsed_url['query'], $url_args);
            if (!empty($url_args['hash'])) {
                $hash = $url_args['hash'];
            }
        }
        $complete_url = add_query_arg(array('step' => 'order-summary', 'hash' => $hash), $checkout_url);
        $cancel_url = add_query_arg(array('step' => 'gateway-select', 'hash' => $hash), $checkout_url);
        update_post_meta($order_id, 'complete_url', $complete_url);
        update_post_meta($order_id, 'cancel_url', $cancel_url);
        update_post_meta($order_id, 'checkout_type', $checkout_type);
        update_post_meta($order_id, 'checkout_hash', $hash);
    }
    // mark this upgrage as completed
    update_option('cp_upgrade_340_orders', 'done');
}