private function tab_generalinfo()
 {
     $upgrades_api = wpbdp_listing_upgrades_api();
     echo '<strong>' . _x('General Info', 'admin infometabox', 'WPBDM') . '</strong>';
     echo '<dl>';
     echo '<dt>' . _x('Total Listing Cost', 'admin infometabox', 'WPBDM') . '</dt>';
     echo '<dd>' . wpbdp_format_currency($this->listing->get_total_cost()) . '</dd>';
     echo '<dt>' . _x('Payment Status', 'admin infometabox', 'WPBDM') . '</dt>';
     echo '<dd>';
     echo sprintf('<span class="tag paymentstatus %1$s">%1$s</span>', $this->listing->get_payment_status());
     echo '</dd>';
     echo '<dt>' . _x('Featured (Sticky) Status', 'admin infometabox', 'WPBDM') . '</dt>';
     echo '<dd>';
     // sticky information
     $sticky_info = $upgrades_api->get_info($this->listing->get_id());
     echo '<span><b>';
     if ($sticky_info->pending) {
         echo _x('Pending Upgrade', 'admin metabox', 'WPBDM');
     } else {
         echo esc_attr($sticky_info->level->name);
     }
     echo '</b> </span><br />';
     if (current_user_can('administrator')) {
         if ($sticky_info->upgradeable) {
             echo sprintf('<span><a href="%s">%s</a></span>', esc_url(add_query_arg(array('wpbdmaction' => 'changesticky', 'u' => $sticky_info->upgrade->id, 'post' => $this->listing->get_id()))), '<b>↑</b> ' . sprintf(__('Upgrade to %s', 'WPBDM'), esc_attr($sticky_info->upgrade->name)));
         }
         if ($sticky_info->downgradeable) {
             echo '<br />';
             echo sprintf('<span><a href="%s">%s</a></span>', esc_url(add_query_arg(array('wpbdmaction' => 'changesticky', 'u' => $sticky_info->downgrade->id, 'post' => $this->listing->get_id()))), '<b>↓</b> ' . sprintf(__('Downgrade to %s', 'WPBDM'), esc_attr($sticky_info->downgrade->name)));
         }
     }
     $import_id = get_post_meta($this->listing->get_id(), '_wpbdp[import_sequence_id]', true);
     if (current_user_can('administrator') && $import_id) {
         echo '<dt>' . _x('CSV Import Sequence ID', 'admin infometabox', 'WPBDM') . '</dt>';
         echo '<dd>' . $import_id . '</dd>';
     }
     echo '</dd>';
     do_action('wpbdp_admin_metabox_generalinfo_list', $this->listing->get_id());
     echo '</dl>';
     if (current_user_can('administrator') && 'ok' != $this->listing->get_payment_status()) {
         echo sprintf('<a href="%s" class="button-primary">%s</a> ', esc_url(add_query_arg('wpbdmaction', 'setaspaid')), _x('Mark listing as Paid', 'admin infometabox', 'WPBDM'));
     }
     echo wpbdp_render_page(WPBDP_PATH . 'admin/templates/listing-metabox-feesummary.tpl.php', array('categories' => $this->listing->get_categories('all'), 'listing' => $this->listing));
 }
 function listing_column_sticky_status($post_id)
 {
     $upgrades_api = wpbdp_listing_upgrades_api();
     $sticky_info = $upgrades_api->get_info($post_id);
     echo sprintf('<span class="tag status %s">%s</span><br />', str_replace(' ', '', $sticky_info->status), $sticky_info->pending ? __('Pending Upgrade', 'WPBDM') : esc_attr($sticky_info->level->name));
     echo '<div class="row-actions">';
     if (current_user_can('administrator')) {
         if ($sticky_info->upgradeable) {
             echo sprintf('<span><a href="%s">%s</a></span>', esc_url(add_query_arg(array('wpbdmaction' => 'changesticky', 'u' => $sticky_info->upgrade->id, 'post' => $post_id))), '<b>↑</b> ' . sprintf(__('Upgrade to %s', 'WPBDM'), esc_attr($sticky_info->upgrade->name)));
             echo '<br />';
         }
         if ($sticky_info->downgradeable) {
             echo sprintf('<span><a href="%s">%s</a></span>', esc_url(add_query_arg(array('wpbdmaction' => 'changesticky', 'u' => $sticky_info->downgrade->id, 'post' => $post_id))), '<b>↓</b> ' . sprintf(__('Downgrade to %s', 'WPBDM'), esc_attr($sticky_info->downgrade->name)));
         }
     } elseif (current_user_can('contributor') && wpbdp_user_can('upgrade-to-sticky', $post_id)) {
         echo sprintf('<span><a href="%s"><b>↑</b> %s</a></span>', wpbdp_get_page_link('upgradetostickylisting', $post_id), _x('Upgrade to Featured', 'admin actions', 'WPBDM'));
     }
     echo '</div>';
 }
 public function __construct()
 {
     $this->upgrades_api = wpbdp_listing_upgrades_api();
 }
 protected function step_fee_selection()
 {
     global $wpbdp;
     if (!$this->state->categories) {
         die;
     }
     $fee_selection = $this->setup_fee_selection();
     if ($this->skip_fee_selection($fee_selection)) {
         foreach (array_keys($this->state->categories) as $cat_id) {
             $this->state->categories[$cat_id] = $fee_selection[$cat_id]['fee_id'];
         }
         $this->state->upgrade_to_sticky = false;
         $this->state->advance(false);
         return $this->dispatch();
     }
     if (isset($_POST['fees'])) {
         $validates = true;
         foreach (array_keys($this->state->categories) as $cat_id) {
             $selected_fee_id = wpbdp_getv($_POST['fees'], $cat_id, null);
             if (null === $selected_fee_id) {
                 $this->errors[] = sprintf(_x('Please select a fee option for the "%s" category.', 'templates', 'WPBDM'), esc_html($fee_selection[$cat_id]['term']->name));
                 $validates = false;
             } else {
                 $this->state->categories[$cat_id] = $selected_fee_id;
             }
         }
         if ($validates) {
             $this->state->upgrade_to_sticky = isset($_POST['upgrade-listing']) && $_POST['upgrade-listing'] == 'upgrade' ? true : false;
             $this->state->autorenew_fees = false;
             if (isset($_POST['autorenew_fees']) && 'autorenew' == $_POST['autorenew_fees'] && 1 == count($this->state->categories)) {
                 $fee = wpbdp_get_fee(end($this->state->categories));
                 if ($fee->amount > 0.0 && $fee->days > 0) {
                     $this->state->autorenew_fees = true;
                 }
             }
             $this->state->advance();
             return $this->dispatch();
         }
     }
     $upgrade_option = false;
     if (!$this->state->editing && wpbdp_get_option('featured-on') && wpbdp_get_option('featured-offer-in-submit')) {
         $upgrade_option = wpbdp_listing_upgrades_api()->get('sticky');
     }
     return $this->render('fee-selection', array('fee_selection' => $fee_selection, 'upgrade_option' => $upgrade_option, 'allow_recurring' => count($this->state->categories) <= 1 && wpbdp_get_option('listing-renewal-auto') && $wpbdp->payments->check_capability('recurring')));
 }
Example #5
0
/**
 * Checks if a given user can perform some action to a listing.
 * @param string $action the action to be checked. available actions are 'view', 'edit', 'delete' and 'upgrade-to-sticky'
 * @param (object|int) $listing_id the listing ID. if null, the current post ID will be used
 * @param int $user_id the user ID. if null, the current user will be used
 * @return boolean
 * @since 2.1
 */
function wpbdp_user_can($action, $listing_id = null, $user_id = null)
{
    $listing_id = $listing_id ? is_object($listing_id) ? $listing_id->ID : intval($listing_id) : get_the_ID();
    $user_id = $user_id ? $user_id : wp_get_current_user()->ID;
    $post = get_post($listing_id);
    if ($post->post_type != WPBDP_POST_TYPE) {
        return false;
    }
    if (isset($_GET['preview'])) {
        return false;
    }
    switch ($action) {
        case 'view':
            return true;
            break;
        case 'edit':
        case 'delete':
            return user_can($user_id, 'administrator') || $post->post_author && $post->post_author == $user_id;
            break;
        case 'upgrade-to-sticky':
            if (!wpbdp_get_option('featured-on') || !wpbdp_get_option('payments-on')) {
                return false;
            }
            if (!wpbdp_payments_possible()) {
                return false;
            }
            $sticky_info = wpbdp_listing_upgrades_api()->get_info($listing_id);
            return $sticky_info->upgradeable && (user_can($user_id, 'administrator') || $post->post_author == $user_id);
            break;
    }
    return false;
}
Example #6
0
 function handle_actions()
 {
     if (!isset($_REQUEST['wpbdmaction']) || !isset($_REQUEST['post'])) {
         return;
     }
     $action = $_REQUEST['wpbdmaction'];
     $posts = is_array($_REQUEST['post']) ? $_REQUEST['post'] : array($_REQUEST['post']);
     $listings_api = wpbdp_listings_api();
     $upgrades_api = wpbdp_listing_upgrades_api();
     if (!current_user_can('administrator')) {
         exit;
     }
     switch ($action) {
         case 'publish':
             foreach ($posts as $post_id) {
                 wp_update_post(array('ID' => $post_id, 'post_status' => 'publish'));
             }
             $this->messages[] = _nx('The listing has been published.', 'The listings have been published.', count($posts), 'admin', 'WPBDM');
             break;
         case 'setaspaid':
             foreach ($posts as $post_id) {
                 $listing = WPBDP_Listing::get($post_id);
                 $listing->mark_as_paid();
             }
             $this->messages[] = _nx('The listing status has been set as paid.', 'The listings status has been set as paid.', count($posts), 'admin', 'WPBDM');
             break;
         case 'changesticky':
             foreach ($posts as $post_id) {
                 $upgrades_api->set_sticky($post_id, wpbdp_getv($_GET, 'u'));
             }
             $this->messages[] = _nx('The listing has been modified.', 'The listings have been modified.', count($posts), 'admin', 'WPBDM');
             break;
         case 'upgradefeatured':
             foreach ($posts as $post_id) {
                 $upgrades_api->set_sticky($post_id, 'sticky', true);
             }
             $this->messages[] = _nx('The listing has been upgraded.', 'The listings have been upgraded.', count($posts), 'admin', 'WPBDM');
             break;
         case 'cancelfeatured':
             foreach ($posts as $post_id) {
                 $upgrades_api->set_sticky($post_id, 'normal');
             }
             $this->messages[] = _nx('The listing has been downgraded.', 'The listings have been downgraded.', count($posts), 'admin', 'WPBDM');
             break;
         case 'approvetransaction':
             $transaction = WPBDP_Payment::get($_GET['transaction_id']);
             $transaction->set_status(WPBDP_Payment::STATUS_COMPLETED, 'admin');
             $transaction->save();
             $this->messages[] = _x('The transaction has been approved.', 'admin', 'WPBDM');
             break;
         case 'rejecttransaction':
             $transaction = WPBDP_Payment::get($_GET['transaction_id']);
             $transaction->set_status(WPBDP_Payment::STATUS_REJECTED, 'admin');
             $transaction->save();
             $this->messages[] = _x('The transaction has been rejected.', 'admin', 'WPBDM');
             break;
         case 'assignfee':
             $listing = WPBDP_Listing::get($posts[0]);
             $listing->add_category($_GET['category_id'], $_GET['fee_id']);
             $this->messages[] = _x('The fee was successfully assigned.', 'admin', 'WPBDM');
             break;
         case 'renewlisting':
             foreach ($posts as $post_id) {
                 $listings_api->auto_renew($post_id);
             }
             $this->messages[] = _nx('Listing was renewed.', 'Listings were renewed.', count($posts), 'admin', 'WPBDM');
             break;
         case 'send-renewal-email':
             $renewal_id = intval($_GET['renewal_id']);
             if ($listings_api->send_renewal_email($renewal_id)) {
                 $this->messages[] = _x('Renewal email sent.', 'admin', 'WPBDM');
             }
             break;
         default:
             do_action('wpbdp_admin_directory_handle_action', $action);
             break;
     }
     $_SERVER['REQUEST_URI'] = remove_query_arg(array('wpbdmaction', 'wpbdmfilter', 'transaction_id', 'category_id', 'fee_id', 'u', 'renewal_id'), $_SERVER['REQUEST_URI']);
 }
Example #7
0
 private function extract_data($post_id)
 {
     $post = get_post($post_id);
     if (!$post || $post->post_type != WPBDP_POST_TYPE) {
         return false;
     }
     $listings_api = wpbdp_listings_api();
     $upgrades_api = wpbdp_listing_upgrades_api();
     $data = array();
     foreach ($this->columns as $colname => &$col) {
         $association = is_object($col) ? $col->get_association() : $col;
         $value = '';
         switch ($association) {
             case 'sequence_id':
                 $value = $listings_api->calculate_sequence_id($post->ID);
                 break;
                 /* Special columns. */
             /* Special columns. */
             case 'images':
                 $upload_dir = wp_upload_dir();
                 $listing_images = array();
                 if ($images = $listings_api->get_images($post->ID)) {
                     foreach ($images as &$img) {
                         $img_metadata = wp_get_attachment_metadata($img->ID);
                         if (!isset($img_metadata['file'])) {
                             continue;
                         }
                         $img_path = realpath($upload_dir['basedir'] . DIRECTORY_SEPARATOR . $img_metadata['file']);
                         if (!is_readable($img_path)) {
                             continue;
                         }
                         $this->images_archive = !isset($this->images_archive) ? new PclZip($this->workingdir . 'images.zip') : $this->images_archive;
                         if ($res = $this->images_archive->add($img_path, PCLZIP_OPT_REMOVE_ALL_PATH)) {
                             $listing_images[] = basename($img_path);
                         }
                     }
                 }
                 if ($listing_images) {
                     $value = implode($this->settings['images-separator'], $listing_images);
                 }
                 break;
             case 'username':
                 $value = get_the_author_meta('user_login', $post->post_author);
                 break;
             case 'featured_level':
                 $listing_level = $upgrades_api->get_listing_level($post->ID);
                 $value = $listing_level->id;
                 break;
             case 'expires_on':
                 $terms = wp_get_post_terms($post->ID, WPBDP_CATEGORY_TAX, 'fields=ids');
                 $expiration_dates = array();
                 foreach ($terms as $term_id) {
                     if ($fee = $listings_api->get_listing_fee_for_category($post->ID, $term_id)) {
                         $expiration_dates[] = $fee->expires_on;
                     } else {
                         $expiration_dates[] = '';
                     }
                 }
                 $value = implode('/', $expiration_dates);
                 break;
                 /* Standard associations. */
             /* Standard associations. */
             case 'category':
             case 'tags':
                 $terms = wp_get_post_terms($post->ID, $col->get_association() == 'tags' ? WPBDP_TAGS_TAX : WPBDP_CATEGORY_TAX, 'fields=names');
                 if ($terms) {
                     $value = implode($this->settings['category-separator'], $terms);
                 }
                 break;
             case 'meta':
             default:
                 $value = $col->csv_value($post->ID);
                 break;
         }
         if (!is_string($value)) {
             if (is_array($value)) {
                 $value = '';
             } else {
                 $value = strval($value);
             }
         }
         $data[$colname] = '"' . str_replace('"', '""', $value) . '"';
     }
     return $data;
 }