public function __construct() { if (!wpbdp_get_option('tracking-on', false)) { return; } if (!wp_next_scheduled('wpbdp_site_tracking')) { wp_schedule_event(current_time('timestamp'), 'daily', 'wpbdp_site_tracking'); } add_action('wpbdp_site_tracking', array($this, 'tracking')); // do_action( 'wpbdp_site_tracking' ); }
function __construct() { $this->public_key = trim(wpbdp_get_option('recaptcha-public-key')); $this->private_key = trim(wpbdp_get_option('recaptcha-private-key')); if (empty($this->public_key) || empty($this->private_key)) { return; } add_action('wp_enqueue_scripts', array(&$this, '_enqueue_js_api')); if (wpbdp_get_option('recaptcha-for-comments')) { add_filter('comment_form_field_comment', array(&$this, '_recaptcha_in_comments')); add_filter('preprocess_comment', array(&$this, '_check_comment_recaptcha'), 0); add_action('comment_post_redirect', array(&$this, '_comment_relative_redirect'), 0, 2); } }
public function dispatch() { if (!wpbdp_get_option('listing-renewal')) { return wpbdp_render_msg(_x('Listing renewal is disabled at this moment. Please try again later.', 'renewal', 'WPBDM'), 'error'); } if (!$this->obtain_renewal_info()) { return wpbdp_render_msg(_x('Your renewal ID is invalid. Please use the URL you were given on the renewal e-mail message.', 'renewal', 'WPBDM'), 'error'); } if (!wpbdp_user_can('edit', $this->listing->get_id())) { $html = ''; // $html .= wpbdp_render_msg( _x( 'You don\'t have permission to access this page. Please login.', 'renewal', 'WPBDM' ), 'error' ); $html .= wpbdp_render('parts/login-required', array(), false); return $html; } if ($this->category->recurring) { return $this->recurring_management(); } if ($this->category->payment_id) { return $this->checkout(); } return $this->fee_selection(); }
public function search() { $_REQUEST = stripslashes_deep($_REQUEST); $search_args = array(); $results = array(); if (isset($_GET['dosrch'])) { $search_args['q'] = wpbdp_getv($_GET, 'q', null); $search_args['fields'] = array(); // standard search fields $search_args['extra'] = array(); // search fields added by plugins foreach (wpbdp_getv($_GET, 'listingfields', array()) as $field_id => $field_search) { $search_args['fields'][] = array('field_id' => $field_id, 'q' => $field_search); } foreach (wpbdp_getv($_GET, '_x', array()) as $label => $field) { $search_args['extra'][$label] = $field; } $listings_api = wpbdp_listings_api(); if ($search_args['q'] && !$search_args['fields'] && !$search_args['extra']) { $results = $listings_api->quick_search($search_args['q']); } else { $results = $listings_api->search($search_args); } } $form_fields = wpbdp_get_form_fields(array('display_flags' => 'search', 'validators' => '-email')); $fields = ''; foreach ($form_fields as &$field) { $field_value = isset($_REQUEST['listingfields']) && isset($_REQUEST['listingfields'][$field->get_id()]) ? $field->convert_input($_REQUEST['listingfields'][$field->get_id()]) : $field->convert_input(null); $fields .= $field->render($field_value, 'search'); } $args = array('post_type' => WPBDP_POST_TYPE, 'posts_per_page' => wpbdp_get_option('listings-per-page') > 0 ? wpbdp_get_option('listings-per-page') : -1, 'paged' => get_query_var('paged') ? get_query_var('paged') : 1, 'post__in' => $results ? $results : array(0), 'orderby' => wpbdp_get_option('listings-order-by', 'date'), 'order' => wpbdp_get_option('listings-sort', 'ASC')); $args = apply_filters('wpbdp_search_query_posts_args', $args, $search_args); query_posts($args); wpbdp_push_query($GLOBALS['wp_query']); $html = wpbdp_render('search', array('fields' => $fields, 'searching' => isset($_GET['dosrch']) ? true : false, 'show_form' => !isset($_GET['dosrch']) || wpbdp_get_option('show-search-form-in-results')), false); wp_reset_query(); wpbdp_pop_query(); return $html; }
public function sortbar_orderby($orderby) { global $wpdb; $sort = wpbdp_get_current_sort_option(); if (!$sort || !in_array(str_replace('field-', '', $sort->option), wpbdp_get_option('listings-sortbar-fields'))) { return $orderby; } $sname = str_replace('field-', '', $sort->option); $qn = ''; switch ($sname) { case 'user_login': case 'user_registered': $qn = $sname; break; case 'date': case 'modified': $qn = "{$wpdb->posts}.post_{$sname}"; break; default: $field = wpbdp_get_form_field($sname); if (!$field) { break; } switch ($field->get_association()) { case 'title': case 'excerpt': case 'content': $qn = "{$wpdb->posts}.post_" . $field->get_association(); break; case 'meta': $qn = "field_{$sname}"; break; } break; } if ($qn) { return $orderby . ', ' . $qn . ' ' . $sort->order; } else { return $orderby; } }
function dispatch($plain = false) { global $wpdb; $debug_info = array(); // basic BD setup info & tests $debug_info['basic']['_title'] = _x('BD Info', 'debug-info', 'WPBDM'); $debug_info['basic']['BD version'] = WPBDP_VERSION; $debug_info['basic']['BD database revision (current)'] = WPBDP_Installer::DB_VERSION; $debug_info['basic']['BD database revision (installed)'] = get_option('wpbdp-db-version'); $tables = apply_filters('wpbdp_debug_info_tables_check', array('wpbdp_form_fields', 'wpbdp_fees', 'wpbdp_payments', 'wpbdp_listing_fees')); $missing_tables = array(); foreach ($tables as &$t) { if ($wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $wpdb->prefix . $t)) == '') { $missing_tables[] = $t; } } $debug_info['basic']['Table check'] = $missing_tables ? sprintf(_('Missing tables: %s', 'debug-info', 'WPBDM'), implode(',', $missing_tables)) : _x('OK', 'debug-info', 'WPBDM'); $debug_info['basic']['Main Page'] = sprintf('%d (%s)', wpbdp_get_page_id('main'), get_post_status(wpbdp_get_page_id('main'))); $debug_info['basic'] = apply_filters('wpbdp_debug_info_section', $debug_info['basic'], 'basic'); // BD options $blacklisted = array('googlecheckout-merchant', 'paypal-business-email', 'wpbdp-2checkout-seller', 'recaptcha-public-key', 'recaptcha-private-key'); $debug_info['options']['_title'] = _x('BD Options', 'debug-info', 'WPBDM'); $settings_api = wpbdp_settings_api(); foreach ($settings_api->settings as &$s) { if ($s->type == 'core' || in_array($s->name, $blacklisted)) { continue; } $value = wpbdp_get_option($s->name); $debug_info['options'][$s->name] = is_array($value) ? implode(',', $value) : $value; } $debug_info['options'] = apply_filters('wpbdp_debug_info_section', $debug_info['options'], 'options'); // environment info $debug_info['environment']['_title'] = _x('Environment', 'debug-info', 'WPBDM'); $debug_info['environment']['WordPress version'] = get_bloginfo('version', 'raw'); $debug_info['environment']['OS'] = php_uname('s') . ' ' . php_uname('r') . ' ' . php_uname('m'); if (function_exists('apache_get_version')) { $apache_version = apache_get_version(); $debug_info['environment']['Apache version'] = $apache_version; } $debug_info['environment']['PHP version'] = phpversion(); $mysql_version = $wpdb->get_var('SELECT @@version'); if ($sql_mode = $wpdb->get_var('SELECT @@sql_mode')) { $mysql_version .= ' ( ' . $sql_mode . ' )'; } $debug_info['environment']['MySQL version'] = $mysql_version ? $mysql_version : 'N/A'; $sqlite_version = class_exists('SQLite3') ? wpbdp_getv(SQLite3::version(), 'versionString', '') : (function_exists('sqlite_libversion') ? sqlite_libversion() : null); $debug_info['environment']['SQLite version'] = $sqlite_version ? $sqlite_version : 'N/A'; $debug_info['environment']['cURL version'] = function_exists('curl_init') ? wpbdp_getv(curl_version(), 'version') : 'N/A'; $debug_info['environment'] = apply_filters('wpbdp_debug_info_section', $debug_info['environment'], 'environment'); $debug_info = apply_filters('wpbdp_debug_info', $debug_info); if ($plain) { foreach ($debug_info as &$section) { foreach ($section as $k => $v) { if ($k == '_title') { printf('== %s ==', $v); print PHP_EOL; continue; } printf("%-33s = %s", $k, $v); print PHP_EOL; } print str_repeat(PHP_EOL, 2); } return; } echo wpbdp_render_page(WPBDP_PATH . 'admin/templates/debug-info.tpl.php', array('debug_info' => $debug_info)); }
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); } }
/** * Displays the listing main image. * @since 2.3 */ function wpbdp_listing_thumbnail($listing_id = null, $args = array()) { if (!$listing_id) { $listing_id = get_the_ID(); } $args = wp_parse_args($args, array('link' => 'picture', 'class' => '', 'echo' => false)); $main_image = false; $image_img = ''; $image_link = ''; $image_classes = 'wpbdp-thumbnail attachment-wpbdp-thumb ' . $args['class']; if ($thumbnail_id = wpbdp_listings_api()->get_thumbnail_id($listing_id)) { $main_image = get_post($thumbnail_id); } else { $images = wpbdp_listings_api()->get_images($listing_id); if ($images) { $main_image = $images[0]; } } if (!$main_image && function_exists('has_post_thumbnail') && has_post_thumbnail($listing_id)) { $image_img = get_the_post_thumbnail($listing_id, 'wpbdp-thumb'); } elseif (!$main_image && wpbdp_get_option('use-default-picture')) { $image_img = sprintf('<img src="%s" alt="%s" title="%s" border="0" width="%d" class="%s" />', WPBDP_URL . 'core/images/default-image-big.gif', get_the_title($listing_id), get_the_title($listing_id), wpbdp_get_option('thumbnail-width'), $image_classes); $image_link = $args['link'] == 'picture' ? WPBDP_URL . 'core/images/default-image-big.gif' : ''; } elseif ($main_image) { _wpbdp_resize_image_if_needed($main_image->ID); $image_img = wp_get_attachment_image($main_image->ID, 'wpbdp-thumb', false, array('alt' => get_the_title($listing_id), 'title' => get_the_title($listing_id), 'class' => $image_classes)); if ($args['link'] == 'picture') { $full_image_data = wp_get_attachment_image_src($main_image->ID, 'wpbdp-large'); $image_link = $full_image_data[0]; } } if (!$image_link && $args['link'] == 'listing') { $image_link = get_permalink($listing_id); } if ($image_img) { if (!$image_link) { return $image_img; } else { return sprintf('<div class="listing-thumbnail"><a href="%s" class="%s" %s>%s</a></div>', $image_link, $args['link'] == 'picture' ? 'thickbox' : '', $args['link'] == 'picture' ? 'data-lightbox="wpbdpgal" rel="wpbdpgal"' : '', $image_img); } } return ''; }
/** * Returns HTML apt for display of this field's value. * @param int|object $post_id post ID or object * @param string $display_context the display context. defaults to 'listing'. * @return string */ public function display($post_id, $display_context = 'listing') { if (in_array('email', $this->validators, true) && !wpbdp_get_option('override-email-blocking')) { return ''; } if ($this->type->is_empty_value($this->value($post_id))) { return ''; } $html = $this->type->display_field($this, $post_id, $display_context); $html = apply_filters_ref_array('wpbdp_form_field_display', array($html, &$this, $display_context, $post_id)); return $html; }
echo wpbdp_render_msg(_x("You are not currently logged in. Please login or register first. When registering, you will receive an activation email. Be sure to check your spam if you don't see it in your email within 60 minutes.", 'templates', 'WPBDM')); } ?> <p></p> <h2><?php _ex('Login', 'templates', 'WPBDM'); ?> </h2> <?php wp_login_form(); ?> <?php $registration_url = trim(wpbdp_get_option('registration-url', '')); if (!$registration_url && get_option('users_can_register')) { if (function_exists('wp_registration_url')) { $registration_url = wp_registration_url(); } else { $registration_url = site_url('wp-login.php?action=register', 'login'); } } $current_url = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $registration_url = $registration_url ? add_query_arg(array('redirect_to' => urlencode($current_url)), $registration_url) : ''; $lost_password_url = add_query_arg('redirect_to', urlencode($current_url), wp_lostpassword_url()); ?> <p> <?php if ($registration_url) {
public function render_field_inner(&$field, $value, $context, &$extra = null) { $options = $field->data('options') ? $field->data('options') : array(); if ($field->get_association() == 'tags' && !$options) { $tags = get_terms(WPBDP_TAGS_TAX, array('hide_empty' => false, 'fields' => 'names')); $options = array_combine($tags, $tags); } elseif ($field->get_association() == 'category') { $html = wp_list_categories(array('taxonomy' => WPBDP_CATEGORY_TAX, 'orderby' => wpbdp_get_option('categories-order-by'), 'order' => wpbdp_get_option('categories-sort'), 'hide_empty' => 0, 'echo' => 0, 'depth' => 0, 'walker' => new CategoryFormInputWalker('checkbox', $value, $field), 'show_option_none' => '', 'title_li' => '')); return $html; } $html = ''; $i = 1; foreach ($options as $option_key => $label) { $css_classes = array(); $css_classes[] = 'wpbdp-inner-checkbox'; $css_classes[] = 'wpbdp-inner-checkbox-' . $i; $css_classes[] = 'wpbdp-inner-checkbox-' . WPBDP_Form_Field_Type::normalize_name($label); $html .= sprintf('<div class="wpbdmcheckboxclass %s"><input type="checkbox" class="%s" name="%s" value="%s" %s/> %s</div>', implode(' ', $css_classes), $field->is_required() ? 'required' : '', 'listingfields[' . $field->get_id() . '][]', $option_key, in_array($option_key, is_array($value) ? $value : array($value)) ? 'checked="checked"' : '', esc_attr($label)); $i++; } $html .= '<div style="clear:both;"></div>'; return $html; }
<?php echo _x('Unlimited', 'templates', 'WPBDM'); ?> <?php } else { ?> <?php echo sprintf(_nx('%d day', '%d days', $fee->days, 'templates', 'WPBDM'), $fee->days); ?> <?php } ?> </td> <td class="fee-images"> <?php echo wpbdp_get_option('allow-images') ? $fee->images : '—'; ?> </td> <?php // do_action( 'wpbdp_fee_selection_extra_columns', $fee ); ?> </tr> <?php if ($fee_description = apply_filters('wpbdp_fee_selection_fee_description', '', $fee)) { ?> <tr class="fee-description fee-id-<?php echo $fee->id; ?> "> <td></td> <td colspan="4"><?php
<label><input type="checkbox" name="upgrade-listing" value="upgrade" <?php echo wpbdp_getv($_POST, 'upgrade-listing', '') == 'upgrade' ? 'checked="checked"' : ''; ?> /> <?php _ex('Yes, upgrade my listing now.', 'templates', 'WPBDM'); ?> </label> </p> </div> <?php } ?> <?php if ($allow_recurring) { if (wpbdp_get_option('listing-renewal-auto-dontask')) { ?> <input type="hidden" name="autorenew_fees" value="autorenew" /> <?php } else { ?> <div class="make-charges-recurring-option"> <b><?php echo _x('Would you like to make your fee renew automatically at the end of the period?', 'submit', 'WPBDM'); ?> </b> <input type="checkbox" name="autorenew_fees" value="autorenew" <?php echo wpbdp_getv($_POST, 'autorenew_fees') == 'autorenew' ? 'checked="checked"' : ''; ?> /> </div>
public function dispatch() { $listing_id = intval(isset($_REQUEST['listing_id']) ? $_REQUEST['listing_id'] : 0); if (!$listing_id) { return ''; } if (!$this->can_submit($listing_id, $error_msg)) { return wpbdp_render_msg($error_msg, 'error'); } $this->listing_id = $listing_id; $this->prepare_input(); if (!$this->validate()) { return $this->render_form($listing_id, $this->errors); } // Compose e-mail message. $replacements = array('listing-url' => get_permalink($listing_id), 'listing' => get_the_title($listing_id), 'name' => $this->name, 'email' => $this->email, 'message' => $this->message, 'date' => date_i18n(__('l F j, Y \\a\\t g:i a'), current_time('timestamp'))); $email = wpbdp_email_from_template('email-templates-contact', $replacements); $email->from = "{$this->name} <{$this->email}>"; $email->to = wpbusdirman_get_the_business_email($listing_id); $email->reply_to = $this->email; $email->template = 'businessdirectory-email'; if (in_array('listing-contact', wpbdp_get_option('admin-notifications'), true)) { $email->cc[] = get_bloginfo('admin_email'); if (wpbdp_get_option('admin-notifications-cc')) { $email->cc[] = wpbdp_get_option('admin-notifications-cc'); } } $html = ''; if ($email->send()) { $html .= wpbdp_render_msg('Your message has been sent.', 'contact-message', 'WPBDM'); $this->update_contacts($listing_id); } else { $html .= wpbdp_render_msg(_x("There was a problem encountered. Your message has not been sent", 'contact-message', "WPBDM"), 'error'); } $html .= sprintf('<p><a href="%s">%s</a></p>', get_permalink($listing_id), _x('Return to listing.', 'contact-message', "WPBDM")); return $html; }
function wpbdp_format_currency($amount, $decimals = 2, $currency = null) { if ($amount == 0.0) { return '—'; } return (!$currency ? wpbdp_get_option('currency-symbol') : $currency) . ' ' . number_format($amount, $decimals); }
?> <form action="<?php echo wpbdp_get_page_link('deletelisting', $listing_id); ?> " method="post"><input type="submit" name="" value="<?php _ex('Delete', 'templates', 'WPBDM'); ?> " class="button delete-listing" data-confirmation-message="<?php _ex('Are you sure you wish to delete this listing?', 'templates', 'WPBDM'); ?> " /></form> <?php } ?> <?php if (wpbdp_get_option('show-directory-button')) { ?> <input type="button" value="<?php echo __('← Back to Directory', 'WPBDM'); ?> " onclick="window.location.href = '<?php echo wpbdp_get_page_link('main'); ?> '" class="wpbdp-hide-on-mobile button back-to-dir" /> <input type="button" value="←" onclick="window.location.href = '<?php echo wpbdp_get_page_link('main'); ?> '" class="wpbdp-show-on-mobile button back-to-dir" /> <?php } } elseif ($view == 'excerpt') {
private function pending_verification() { $message = wpbdp_get_option('payment-message'); if (!$message) { $message .= wpbdp_render_msg(_x('Your payment is being verified. This usually takes a few minutes but can take up to 24 hours.', 'checkout', 'WPBDM')); } $html = ''; $html .= $message; $html .= $this->api->render_details($this->payment); $html .= '<p>'; $html .= sprintf('<a href="%s">%s</a>', wpbdp_get_page_link('main'), _x('← Return to Directory.', 'checkout', 'WPBDM')); $html .= '</p>'; return $html; }
<h3><?php _ex('Upgrade listing', 'templates', 'WPBDM'); ?> </h3> <?php if ($featured_text = wpbdp_get_option('featured-description')) { ?> <p><?php echo $featured_text; ?> </p> <?php } ?> <form action="" method="POST"> <input type="hidden" name="action" value="upgradetostickylisting" /> <input type="hidden" name="listing_id" value="<?php echo $listing->get_id(); ?> " /> <input type="submit" name="do_upgrade" value="<?php echo sprintf(_x('Upgrade listing to %s for %s.', 'templates', 'WPBDM'), esc_attr($featured_level->name), wpbdp_get_option('currency-symbol') . $featured_level->cost); ?> " /> </form>
<?php echo wpbdp_admin_header(null, 'admin-fees', wpbdp_get_option('payments-on') ? array(array(_x('Add New Listing Fee', 'fees admin', 'WPBDM'), esc_url(add_query_arg('action', 'addfee')))) : null); ?> <?php wpbdp_admin_notices(); ?> <?php if (!wpbdp_get_option('payments-on')) { ?> <div class="wpbdp-note"><p> <?php _ex('Payments are currently turned off.', 'fees admin', 'WPBDM'); ?> <br /> <?php echo str_replace('<a>', '<a href="' . admin_url('admin.php?page=wpbdp_admin_settings&groupid=payment') . '">', _x('To manage fees you need to go to the <a>Manage Options - Payment</a> page and check the box next to \'Turn On Payments\' under \'Payment Settings\'.', 'fees admin', 'WPBDM')); ?> </p> </div> <?php } else { ?> <div class="fees-order"> <form> <input type="hidden" name="action" value="wpbdp-admin-fees-set-order" /> <?php wp_nonce_field('change fees order'); ?> <b><?php
/** * @deprecated * @since 2.3 */ function wpbusdirman_get_the_business_email($post_id) { $email_mode = wpbdp_get_option('listing-email-mode'); $email_field_value = ''; if ($email_field = wpbdp_get_form_fields('validators=email&unique=1')) { $email_field_value = trim($email_field->plain_value($post_id)); } if ($email_mode == 'field' && !empty($email_field_value)) { return $email_field_value; } $author_email = ''; $post = get_post($post_id); $author_email = trim(get_the_author_meta('user_email', $post->post_author)); if (empty($author_email) && !empty($email_field_value)) { return $email_field_value; } return $author_email ? $author_email : ''; }
private function feesTable() { $table = new WPBDP_FeesTable(); $table->prepare_items(); $order_options = array(); foreach (array('label' => _x('Label', 'fees order', 'WPBDM'), 'amount' => _x('Amount', 'fees order', 'WPBDM'), 'days' => _x('Duration', 'fees order', 'WPBDM'), 'images' => _x('Images', 'fees order', 'WPBDM'), 'custom' => _x('Custom Order', 'fees order', 'WPBDM')) as $k => $l) { $order_options[$k] = $l; } wpbdp_render_page(WPBDP_PATH . 'admin/templates/fees.tpl.php', array('table' => $table, 'order_options' => $order_options, 'current_order' => wpbdp_get_option('fee-order')), true); }
private function validate_jwt(&$jwt, &$payment) { if (!isset($jwt->request) || !isset($jwt->response)) { return false; } if (!isset($jwt->iss) || $jwt->iss != 'Google') { return false; } if (!isset($jwt->aud) || $jwt->aud != wpbdp_get_option('googlewallet-seller-id')) { return false; } // Check seller data. $seller_data = isset($jwt->request->sellerData) ? $jwt->request->sellerData : null; if (!$seller_data) { return false; } parse_str($seller_data, $data); if ($data['payment_id'] != $payment->get_id() || $data['listing_id'] != $payment->get_listing_id()) { return false; } // Check price. if (round($payment->get_total(), 0) != $jwt->request->price) { return false; } // Check order ID. if (!isset($jwt->response->orderId)) { return false; } return true; }
public function get_checkout_url($force_http = false) { $payment_id = $this->id; $payment_q = base64_encode('payment_id=' . $payment_id . '&verify=0'); // TODO: add a 'verify' parameter to avoid false links being generated. $base_url = wpbdp_get_page_link('main'); if (!$force_http && !is_ssl() && wpbdp_get_option('payments-use-https')) { $base_url = set_url_scheme($base_url, 'https'); } return add_query_arg(array('action' => 'checkout', 'payment' => urlencode($payment_q)), $base_url); }
function _wpbdp_render_excerpt() { global $post; static $counter = 0; $sticky_status = wpbdp_listings_api()->get_sticky_status($post->ID); $html = ''; $html .= sprintf('<div id="wpbdp-listing-%d" class="wpbdp-listing excerpt wpbdp-listing-excerpt %s %s %s cf">', $post->ID, $sticky_status, $counter & 1 ? 'odd' : 'even', apply_filters('wpbdp_excerpt_view_css', '', $post->ID)); $html .= wpbdp_capture_action('wpbdp_before_excerpt_view', $post->ID); $d = WPBDP_ListingFieldDisplayItem::prepare_set($post->ID, 'excerpt'); $listing_fields = implode('', WPBDP_ListingFieldDisplayItem::walk_set('html', $d->fields)); $social_fields = implode('', WPBDP_ListingFieldDisplayItem::walk_set('html', $d->social)); $vars = array('is_sticky' => $sticky_status == 'sticky', 'thumbnail' => wpbdp_get_option('allow-images') && wpbdp_get_option('show-thumbnail') ? wpbdp_listing_thumbnail(null, 'link=listing&class=wpbdmthumbs wpbdp-excerpt-thumbnail') : '', 'title' => get_the_title(), 'listing_fields' => apply_filters('wpbdp_excerpt_listing_fields', $listing_fields, $post->ID), 'fields' => $d->fields, 'listing_id' => $post->ID); $vars = apply_filters('wpbdp_listing_template_vars', $vars, $post->ID); $vars = apply_filters('wpbdp_excerpt_template_vars', $vars, $post->ID); $html .= wpbdp_render('businessdirectory-excerpt', $vars, true); $social_fields = apply_filters('wpbdp_excerpt_social_fields', $social_fields, $post->ID); if ($social_fields) { $html .= '<div class="social-fields cf">' . $social_fields . '</div>'; } $html .= wpbdp_capture_action('wpbdp_after_excerpt_view', $post->ID); $html .= wpbdp_render('parts/listing-buttons', array('listing_id' => $post->ID, 'view' => 'excerpt'), false); $html .= '</div>'; $counter++; return $html; }
protected function step_save() { $listing = $this->state->editing ? WPBDP_Listing::get($this->state->listing_id) : WPBDP_Listing::create($this->state); $listing->set_field_values($this->state->fields); $listing->set_images($this->state->images); $listing->set_thumbnail_id($this->state->thumbnail_id); if (!$this->state->editing) { // Generate payment for the listing. $payment = new WPBDP_Payment(array('listing_id' => $listing->get_id())); if (!$this->state->editing) { $payment->tag('initial'); } foreach ($this->state->categories as $cat_id => $fee_id) { $category_info = $listing->get_category_info($cat_id); if (!$category_info) { $fee = wpbdp_get_fee($fee_id); if (!$fee) { continue; } $payment->add_item($this->state->autorenew_fees ? 'recurring_fee' : 'fee', $fee->amount, sprintf(_x('Fee "%s" for category "%s"%s', 'listings', 'WPBDM'), $fee->label, wpbdp_get_term_name($cat_id), $this->state->autorenew_fees ? ' ' . _x('(recurring)', 'listings', 'WPBDM') : ''), array('fee_id' => $fee_id, 'fee_days' => $fee->days, 'fee_images' => $fee->images), $cat_id, $fee_id); } } if ($this->state->upgrade_to_sticky) { $payment->add_item('upgrade', wpbdp_get_option('featured-price'), _x('Listing upgrade to featured', 'submit', 'WPBDM')); } $payment->set_submit_state_id($this->state->id); if (current_user_can('administrator')) { $payment->set_status(WPBDP_Payment::STATUS_COMPLETED); } $payment->save(); $this->state->listing_id = $listing->get_id(); $this->state->payment_id = $payment->get_id(); } do_action_ref_array('wpbdp_listing_form_extra_sections_save', array(&$this->state)); $listing->save(); $listing->set_post_status($this->state->editing ? wpbdp_get_option('edit-post-status') : wpbdp_get_option('new-post-status')); $this->state->advance(false); // This step is 'invisible'. return $this->dispatch(); }
echo $message; ?> </p> <?php } ?> <?php if ($payment_methods && $transaction) { ?> <?php foreach ($payment_methods as $method) { ?> <h4 class="paymentheader"> <?php echo sprintf($item_text, wpbdp_get_option('currency-symbol') . $transaction->amount, $method->name); ?> </h4> <div class="paymentbuttondiv payment-gateway-<?php echo $method->id; ?> "> <?php echo call_user_func($method->html_callback, $transaction->id); ?> </div> <?php } } else { ?> <?php
public function register_default_levels() { // register default levels $this->register('normal', null, array('name' => _x('Normal Listing', 'listings-api', 'WPBDM'), 'is_sticky' => false)); $this->register('sticky', 'normal', array('name' => _x('Featured Listing', 'listings-api', 'WPBDM'), 'cost' => wpbdp_get_option('featured-price'), 'description' => wpbdp_get_option('featured-description'), 'is_sticky' => true)); }
/** * @since 3.5.4 */ function wpbdp_email_from_template($setting, $replacements = array(), $args = array()) { global $wpbdp; $setting = $wpbdp->settings->get_setting($setting); if (!$setting || 'email_template' != $setting->type) { return false; } if (!class_exists('WPBDP_Email')) { require_once WPBDP_PATH . 'core/class-email.php'; } $placeholders = isset($setting->args['placeholders']) && is_array($setting->args['placeholders']) ? $setting->args['placeholders'] : array(); $value = wpbdp_get_option($setting->name); // Add core replacements. $replacements = array_merge($replacements, array('site-title' => get_bloginfo('name'), 'site-link' => sprintf('<a href="%s">%s</a>', get_bloginfo('url'), get_bloginfo('name')), 'site-url' => sprintf('<a href="%s">%s</a>', get_bloginfo('url'), get_bloginfo('url')), 'directory-url' => sprintf('<a href="%1$s">%1$s</a>', wpbdp_get_page_link('main')), 'today' => date_i18n(get_option('date_format')), 'now' => date_i18n(get_option('time_format')))); // Support old-style settings. if (!is_array($value)) { $subject = $setting->default['subject']; $body = $setting->default['body']; } else { $subject = $value['subject']; $body = $value['body']; } $email = new WPBDP_Email(); $email->subject = $subject; $email->body = $body; foreach (array_keys($placeholders) as $placeholder) { if (!isset($replacements[$placeholder])) { continue; } $email->subject = str_replace('[' . $placeholder . ']', $replacements[$placeholder], $email->subject); $email->body = str_replace('[' . $placeholder . ']', $replacements[$placeholder], $email->body); } return $email; }
public static function create(&$state) { $title = 'Untitled Listing'; if (isset($state->title)) { $title = $state->title; } else { $title_field = wpbdp_get_form_fields(array('association' => 'title', 'unique' => true)); if (isset($state->fields[$title_field->get_id()])) { $title = $state->fields[$title_field->get_id()]; } } $title = trim(strip_tags($title)); $post_data = array('post_title' => $title, 'post_status' => 'pending', 'post_type' => WPBDP_POST_TYPE); $post_id = wp_insert_post($post_data); // Create author user if needed. $current_user = wp_get_current_user(); if ($current_user->ID == 0) { if (wpbdp_get_option('require-login')) { throw new Exception('Login required.'); } // Create user. if ($email_field = wpbdp_get_form_fields(array('validators' => 'email', 'unique' => 1))) { $email = $state->fields[$email_field->get_id()]; if (email_exists($email)) { $post_author = get_user_by('email', $email); $post_author = $post_author->ID; } else { $post_author = wp_insert_user(array('user_login' => 'guest_' . wp_generate_password(5, false, false), 'user_email' => $email, 'user_pass' => wp_generate_password())); } wp_update_post(array('ID' => $post_id, 'post_author' => $post_author)); } } return new self($post_id); }
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('&', '&', $c['name']), WPBDP_CATEGORY_TAX)) { $c['term_id'] = $t['term_id']; } else { if ($t = wp_insert_term(str_replace('&', '&', $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(); }