public static function metabox_callback($post)
 {
     $listing = WPBDP_Listing::get($post->ID);
     if (!$listing) {
         return '';
     }
     $instance = new self($listing);
     return $instance->render();
 }
 public function dispatch()
 {
     $this->listing = WPBDP_Listing::get(intval($_GET['listing_id'] ? $_GET['listing_id'] : 0));
     if (!$this->listing || !wpbdp_user_can('upgrade-to-sticky', $this->listing->get_id())) {
         return wpbdp_render_msg(_x('Invalid link followed.', 'listing upgrade', 'WPBDM'), 'error');
     }
     $sticky_info = $this->upgrades_api->get_info($this->listing->get_id());
     if ($sticky_info->pending) {
         $html = '';
         $html .= wpbdp_render_msg(_x('Your listing is already pending approval for "featured" status.', 'templates', 'WPBDM'));
         $html .= sprintf('<a href="%s">%s</a>', $this->listing->get_permalink(), _x('Return to listing.', 'templates', 'WPBDM'));
         return $html;
     }
     if (isset($_POST['do_upgrade'])) {
         return $this->checkout();
     }
     return $this->upgrade_selection();
 }
示例#3
0
 public static function listing_og_description($listing_id)
 {
     if (self::is_wp_seo_enabled()) {
         $wpseo_front = null;
         if (isset($GLOBALS['wpseo_front'])) {
             $wpseo_front = $GLOBALS['wpseo_front'];
         } elseif (class_exists('WPSEO_Frontend') && method_exists('WPSEO_Frontend', 'get_instance')) {
             $wpseo_front = WPSEO_Frontend::get_instance();
         }
         global $post;
         $prev_post = $post;
         $post = get_post($listing_id);
         $desc = $wpseo_front->metadesc(false);
         $post = $prev_post;
         return $desc;
     }
     $listing = WPBDP_Listing::get($listing_id);
     return $listing->get_field_value('excerpt');
 }
 function dispatch()
 {
     $listing_id = intval($_REQUEST['listing_id']);
     if (!wpbdp_user_can('delete', $listing_id)) {
         $html .= wpbdp_render_msg(_x('Please log in to delete the listing.', 'delete listing', 'WPBDM'));
         $html .= wpbdp_render('parts/login-required', array('show_message' => false));
         return $html;
     }
     $listing = WPBDP_Listing::get($listing_id);
     $nonce = isset($_REQUEST['_wpnonce']) ? $_REQUEST['_wpnonce'] : '';
     if (!$listing) {
         die;
     }
     if ($nonce && wp_verify_nonce($nonce, 'delete listing ' . $listing->get_id())) {
         $listing->delete();
         return wpbdp_render_msg(_x('Your listing has been deleted.', 'delete listing', 'WPBDM'));
     }
     return wpbdp_render('delete-listing-confirm', array('listing' => $listing, 'has_recurring' => $this->has_recurring_fee($listing)));
 }
 private function decode_subscription_hash($hash = '')
 {
     $hash = urldecode(trim($hash));
     if (!$hash) {
         return false;
     }
     parse_str(base64_decode($hash), $hash_data);
     if (!$hash_data || !isset($hash_data['listing_id']) || !isset($hash_data['category_id'])) {
         return false;
     }
     $listing = WPBDP_Listing::get(intval($hash_data['listing_id']));
     $category_id = intval($hash_data['category_id']);
     if (!$listing || !$category_id || $listing->get_author_meta('ID') != get_current_user_id()) {
         return false;
     }
     $category_info = $listing->get_category_info($category_id);
     if (!$category_info || !$category_info->recurring) {
         return false;
     }
     return compact('listing', 'category_info');
 }
 private function obtain_renewal_info()
 {
     $renewal_id = urldecode(trim($_GET['renewal_id']));
     if (!$renewal_id) {
         return false;
     }
     parse_str(base64_decode($renewal_id), $renewal_data);
     if (!$renewal_data || !isset($renewal_data['listing_id']) || !isset($renewal_data['category_id'])) {
         return false;
     }
     $listing = WPBDP_Listing::get(intval($renewal_data['listing_id']));
     $category_id = intval($renewal_data['category_id']);
     if (!$listing) {
         return false;
     }
     $category_info = $listing->get_category_info($category_id);
     if (!$category_info) {
         return false;
     }
     $this->category = $category_info;
     $this->listing = $listing;
     return true;
 }
 public function __construct($listing_id = 0)
 {
     $this->editing = $listing_id > 0 ? true : false;
     if ($listing_id > 0) {
         $listing = WPBDP_Listing::get($listing_id);
         if (!$listing || !$listing->is_published()) {
             throw new Exception('You can not edit this listing.');
         }
         $this->listing_id = $listing_id;
         $categories = $listing->get_categories('all');
         foreach ($categories as &$category) {
             $this->categories[$category->id] = $category->fee_id;
         }
         // Image information.
         $this->images = $listing->get_images('ids');
         $this->thumbnail_id = $listing->get_thumbnail_id();
         // Fields.
         $fields = wpbdp_get_form_fields(array('association' => '-category'));
         foreach ($fields as &$f) {
             $this->fields[$f->get_id()] = $f->value($this->listing_id);
         }
         // Recover additional information.
         do_action_ref_array('wpbdp_submit_state_init', array(&$this));
     }
 }
示例#8
0
 public function cancel_recurring()
 {
     if (!$this->id) {
         return;
     }
     $listing = WPBDP_Listing::get($this->get_listing_id());
     $recurring_item = $this->get_recurring_item();
     if ($recurring_item) {
         $listing->remove_category($recurring_item->rel_id_1);
     }
 }
 public function save_post($post_id)
 {
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return;
     }
     // Handle listings saved admin-side.
     if (is_admin() && isset($_POST['post_type']) && $_POST['post_type'] == WPBDP_POST_TYPE) {
         $listing = WPBDP_Listing::get($post_id);
         if (!$listing) {
             return;
         }
         $listing->fix_categories(true);
         // Save custom fields.
         //if ( isset( $_POST['wpbdp-listing-fields-nonce'] ) && wp_verify_nonce( $_POST['wpbdp-listing-fields-nonce'], plugin_basename( __FILE__ ) ) )
         if (isset($_POST['wpbdp-listing-fields-nonce'])) {
             $formfields_api = wpbdp_formfields_api();
             $listingfields = wpbdp_getv($_POST, 'listingfields', array());
             foreach ($formfields_api->find_fields(array('association' => 'meta')) as $field) {
                 if (isset($listingfields[$field->get_id()])) {
                     $value = $field->convert_input($listingfields[$field->get_id()]);
                     $field->store_value($listing->get_id(), $value);
                 } else {
                     $field->store_value($listing->get_id(), $field->convert_input(null));
                 }
             }
             if (isset($_POST['thumbnail_id'])) {
                 $listing->set_thumbnail_id($_POST['thumbnail_id']);
             }
         }
     }
 }
 public function widget($args, $instance)
 {
     extract($args);
     $title = apply_filters('widget_title', $instance['title']);
     echo $before_widget;
     if (!empty($title)) {
         echo $before_title . $title . $after_title;
     }
     $out = $this->print_listings($instance);
     if (!$out) {
         if ($listings = $this->get_listings($instance)) {
             $show_images = in_array('images', $this->supports) && isset($instance['show_images']) && $instance['show_images'];
             $thumb_w = isset($instance['thumbnail_width']) ? $instance['thumbnail_width'] : 0;
             $thumb_h = isset($instance['thumbnail_height']) ? $instance['thumbnail_height'] : 0;
             $img_size = 'wpbdp-thumb';
             if ($show_images && ($thumb_w > 0 || $thumb_h > 0)) {
                 $img_size = array($thumb_w, $thumb_h);
             }
             $out .= '<ul class="wpbdp-listings-widget-list">';
             foreach ($listings as &$post) {
                 $listing = WPBDP_Listing::get($post->ID);
                 $out .= '<li>';
                 $out .= sprintf('<a class="listing-title" href="%s">%s</a>', get_permalink($post->ID), get_the_title($post->ID));
                 if ($show_images) {
                     if ($img_id = $listing->get_thumbnail_id()) {
                         $out .= '<a href="' . get_permalink($post->ID) . '">' . wp_get_attachment_image($img_id, $img_size, false, array('class' => 'listing-image')) . '</a>';
                     }
                 }
                 $out .= '</li>';
             }
             $out .= '</ul>';
         }
     }
     echo $out;
     echo $after_widget;
 }
示例#11
0
 private function done()
 {
     $listing = WPBDP_Listing::get($this->payment->get_listing_id());
     $html = '';
     $html .= wpbdp_render_msg(_x('Your payment was received sucessfully.', 'checkout', 'WPBDM'));
     $html .= $this->api->render_details($this->payment);
     $html .= '<p>';
     if ($listing->is_published()) {
         $html .= sprintf('<a href="%s">%s</a>', $listing->get_permalink(), _x('← Return to your listing.', 'checkout', 'WPBDM'));
     } else {
         $html .= sprintf('<a href="%s">%s</a>', wpbdp_get_page_link('main'), _x('← Return to Directory.', 'checkout', 'WPBDM'));
     }
     $html .= '</p>';
     return $html;
 }
 function listing_opentags()
 {
     $listing_id = get_query_var('listing') ? wpbdp_get_post_by_slug(get_query_var('listing'))->ID : wpbdp_getv($_GET, 'id', get_query_var('id'));
     $listing = WPBDP_Listing::get($listing_id);
     if (!$listing) {
         return;
     }
     echo '<meta property="og:type" content="website" />';
     echo '<meta property="og:title" content="' . esc_attr(WPBDP_SEO::listing_title($listing_id)) . '" />';
     echo '<meta property="og:url" content="' . esc_url($listing->get_permalink()) . '" />';
     echo '<meta property="og:description" content="' . esc_attr(WPBDP_SEO::listing_og_description($listing_id)) . '" />';
     if ($thumbnail_id = $listing->get_thumbnail_id()) {
         if ($img = wp_get_attachment_image_src($thumbnail_id, 'wpbdp-large')) {
             echo '<meta property="og:image" content="' . $img[0] . '" />';
         }
     }
 }
 public function handle_expiration($payment)
 {
     if (!class_exists('AuthorizeNetAIM')) {
         require_once WPBDP_PATH . 'vendors/anet_php_sdk/AuthorizeNet.php';
     }
     $recurring = $payment->get_recurring_item();
     $listing = WPBDP_Listing::get($payment->get_listing_id());
     if (!$listing || !$recurring) {
         return;
     }
     $recurring_id = $payment->get_data('recurring_id');
     $arb = new AuthorizeNetARB(wpbdp_get_option('authorize-net-login-id'), wpbdp_get_option('authorize-net-transaction-key'));
     if (wpbdp_get_option('payments-test-mode')) {
         $arb->setSandbox(true);
     } else {
         $arb->setSandbox(false);
     }
     $response = $arb->getSubscriptionStatus($recurring_id);
     $status = $response->isOk() ? $response->getSubscriptionStatus() : '';
     if ('active' == $status) {
         // If subscription is active, renew automatically for another period.
         $term_payment = $payment->generate_recurring_payment();
         $term_payment->set_status(WPBDP_Payment::STATUS_COMPLETED, WPBDP_Payment::HANDLER_GATEWAY);
         $term_payment->save();
     } else {
         // If subscription is not active, make item non recurring so it expires normally next time.
         $recurring_item = $payment->get_recurring_item();
         $listing->make_category_non_recurring($recurring_item->rel_id_1);
     }
 }
 private function import_row($data)
 {
     global $wpdb;
     global $wpbdp;
     if ($this->settings['test-import']) {
         return;
     }
     extract($data);
     $state = (object) array('fields' => array(), 'images' => array(), 'categories' => array());
     $errors = array();
     // Create categories.
     foreach ($categories as &$c) {
         if ($c['term_id']) {
             $state->categories[] = intval($c['term_id']);
             continue;
         }
         if ($t = term_exists(str_replace('&', '&amp;', $c['name']), WPBDP_CATEGORY_TAX)) {
             $c['term_id'] = $t['term_id'];
         } else {
             if ($t = wp_insert_term(str_replace('&amp;', '&', $c['name']), WPBDP_CATEGORY_TAX)) {
                 $c['term_id'] = $t['term_id'];
             } else {
                 $errors[] = sprintf(_x('Could not create listing category "%s"', 'admin csv-import', 'WPBDM'), $c['name']);
             }
         }
         if ($c['term_id']) {
             $state->categories[] = intval($c['term_id']);
         }
     }
     $listing_id = 0;
     // Support sequence_id.
     if ($meta['sequence_id']) {
         $listing_id = intval($wpdb->get_var($wpdb->prepare("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_wpbdp[import_sequence_id]', $meta['sequence_id'])));
         if (WPBDP_POST_TYPE != get_post_type($listing_id)) {
             $listing_id = 0;
         }
     }
     // Handle fields.
     foreach ($fields as $field_id => $field_data) {
         $f = wpbdp_get_form_field($field_id);
         if ('image' != $f->get_field_type_id()) {
             continue;
         }
         $img = trim($field_data);
         if (!$img) {
             continue;
         }
         $media_id = $this->upload_image($img);
         $fields[$field_id] = $media_id ? $media_id : '';
     }
     $state->fields = $fields;
     // Handle images.
     foreach ($data['images'] as $filename) {
         if ($img_id = $this->upload_image($filename)) {
             $state->images[] = $img_id;
         }
     }
     // Insert or update listing.
     if ($listing_id) {
         $listing = WPBDP_Listing::get($listing_id);
         $listing->update($state);
         $listing->set_post_status(wpbdp_get_option('edit-post-status'));
     } else {
         $listing = WPBDP_Listing::create($state);
         $listing->set_field_values($state->fields);
         $listing->set_images($state->images);
         $listing->set_categories($state->categories);
         $listing->set_post_status($this->settings['post-status']);
         $listing->save();
     }
     // Set username.
     if ($u = get_user_by('login', $meta['username'])) {
         wp_update_post(array('ID' => $listing->get_id(), 'post_author' => $u->ID));
     }
     // Set featured level.
     if ($meta['featured_level']) {
         if ($l = $wpbdp->listings->upgrades->get($meta['featured_level'])) {
             $wpbdp->listings->upgrades->set_sticky($listing->get_id(), $l->id);
         }
     }
     // Create permalink.
     $post = get_post($listing->get_id());
     wp_update_post(array('ID' => $post->ID, 'post_name' => wp_unique_post_slug(sanitize_title($post->post_title), $post->ID, $post->post_status, $post->post_type, $post->post_parent)));
     // Update expiration dates.
     foreach ($categories as $c) {
         if (!$c['expires_on']) {
             continue;
         }
         $wpdb->update($wpdb->prefix . 'wpbdp_listing_fees', array('expires_on' => $c['expires_on']), array('category_id' => $c['term_id'], 'listing_id' => $listing->get_id()));
     }
     // Update sequence_id.
     if ($meta['sequence_id']) {
         update_post_meta($listing->get_id(), '_wpbdp[import_sequence_id]', $meta['sequence_id']);
     }
     if ($errors) {
         $error = new WP_Error();
         foreach ($errors as $e) {
             $error->add('listing-add-error', $e);
         }
         return $error;
     }
     return $listing->get_id();
 }
示例#15
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']);
 }
示例#16
0
 public function __construct($listing_id)
 {
     $this->listing = WPBDP_Listing::get($listing_id);
 }