Example #1
0
 protected function get_posted_data()
 {
     $posted_data = array('awpcp_sender_name' => awpcp_request_param('awpcp_sender_name'), 'awpcp_sender_email' => awpcp_request_param('awpcp_sender_email'), 'awpcp_contact_message' => awpcp_request_param('awpcp_contact_message'));
     if (is_user_logged_in()) {
         $posted_data = $this->overwrite_sender_information($posted_data);
     }
     return $posted_data;
 }
 private function validate_transaction($transaction)
 {
     $x_amount = number_format(awpcp_request_param('x_amount'), 2);
     $x_Login = awpcp_request_param('x_login');
     $payer_email = awpcp_request_param('email', awpcp_request_param('x_Email'));
     $x_2checked = awpcp_request_param('x_2checked');
     $x_MD5_Hash = awpcp_request_param('x_MD5_Hash');
     $x_trans_id = awpcp_request_param('x_trans_id');
     $card_holder_name = awpcp_request_param('card_holder_name');
     $x_Country = awpcp_request_param('x_Country');
     $x_City = awpcp_request_param('x_City');
     $x_State = awpcp_request_param('x_State');
     $x_Zip = awpcp_request_param('x_Zip');
     $x_Address = awpcp_request_param('x_Address');
     $x_Phone = awpcp_request_param('x_Phone');
     $demo = awpcp_request_param('demo');
     $x_response_code = awpcp_request_param('x_response_code');
     $x_response_reason_code = awpcp_request_param('x_response_reason_code');
     $x_response_reason_text = awpcp_request_param('x_response_reason_text');
     $x_item_number = awpcp_request_param('x_item_number');
     $x_custom = awpcp_request_param('x_custom');
     $x_twocorec = awpcp_request_param('x_twocorec');
     $x_order_number = awpcp_request_param('order_number');
     $x_sid = awpcp_request_param('sid');
     $totals = $transaction->get_totals();
     $amount = number_format($totals['money'], 2);
     if ($amount !== $x_amount) {
         $msg = __("The amount you have paid does not match the required amount for this transaction. Please contact us to clarify the problem.", "AWPCP");
         $transaction->errors['validation'] = $msg;
         $transaction->payment_status = AWPCP_Payment_Transaction::PAYMENT_STATUS_INVALID;
         awpcp_payment_failed_email($transaction, $message);
         return false;
     }
     if (strcasecmp($x_Login, get_awpcp_option('2checkout')) !== 0) {
         $msg = __("There was an error processing your transaction. If funds have been deducted from your account, they have not been processed to our account. You will need to contact PayPal about the matter.", "AWPCP");
         $transaction->errors['validation'] = $msg;
         $transaction->payment_status = AWPCP_Payment_Transaction::PAYMENT_STATUS_INVALID;
         awpcp_payment_failed_email($transaction, $message);
         return false;
     }
     // TODO: handle this filter for Ads and Subscriptions
     $duplicated = apply_filters('awpcp-payments-is-duplicated-transaction', false, $txn_id);
     if ($duplicated) {
         $msg = __("It appears this transaction has already been processed. If you do not see your ad in the system please contact the site adminstrator for assistance.", "AWPCP");
         $transaction->errors['validation'] = $msg;
         $transaction->payment_status = AWPCP_Payment_Transaction::PAYMENT_STATUS_INVALID;
         awpcp_payment_failed_email($transaction, $message);
         return false;
     }
     $transaction->payment_status = AWPCP_Payment_Transaction::PAYMENT_STATUS_PENDING;
     // at this point the validation was successful, any previously stored
     // errors are irrelevant
     unset($transaction->errors['validation']);
     $transaction->set('validated', true);
     $transaction->payment_gateway = $this->slug;
     $transaction->payer_email = $payer_email;
     return true;
 }
 public function dispatch()
 {
     global $awpcp;
     $groups = $awpcp->settings->groups;
     unset($groups['private-settings']);
     $group = $groups[awpcp_request_param('g', 'pages-settings')];
     ob_start();
     include AWPCP_DIR . '/admin/templates/admin-panel-settings.tpl.php';
     $content = ob_get_contents();
     ob_end_clean();
     echo $content;
 }
function awpcp_render_category_selector($params = array())
{
    $browse_categories_page_url = get_permalink(awpcp_get_page_id_by_ref('browse-categories-page-name'));
    $category_id = (int) awpcp_request_param('category_id', -1);
    $category_id = $category_id === -1 ? (int) get_query_var('cid') : $category_id;
    $category_dropdown_params = wp_parse_args($params, array('context' => 'search', 'name' => 'category_id', 'selected' => $category_id));
    $hidden = array('a' => 'browsecat', 'results' => awpcp_request_param('results'), 'offset' => awpcp_request_param('offset'));
    ob_start();
    include AWPCP_DIR . '/templates/frontend/category-selector.tpl.php';
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
}
 public function dispatch()
 {
     global $awpcp, $message;
     $action = awpcp_request_param('action', 'confirm');
     $url = awpcp_current_url();
     $dirname = AWPCPUPLOADDIR;
     if (strcmp($action, 'uninstall') == 0) {
         $awpcp->installer->uninstall();
     }
     $template = AWPCP_DIR . '/admin/templates/admin-panel-uninstall.tpl.php';
     $params = compact('action', 'url', 'dirname');
     echo $this->render($template, $params);
 }
Example #6
0
/**
 * @since 3.4
 */
function awpcp_display_listings($query, $context, $options)
{
    $options = wp_parse_args($options, array('show_intro_message' => false, 'show_menu_items' => false, 'show_category_selector' => false, 'show_pagination' => false, 'before_content' => '', 'before_pagination' => '', 'before_list' => '', 'after_pagination' => '', 'after_content' => ''));
    if (has_action('awpcp_browse_ads_template_action') || has_filter('awpcp_browse_ads_template_filter')) {
        do_action('awpcp_browse_ads_template_action');
        return apply_filters('awpcp_browse_ads_template_filter');
    }
    $results_per_page = absint(awpcp_request_param('results', get_awpcp_option('adresultsperpage', 10)));
    $results_offset = absint(awpcp_request_param('offset', 0));
    if (empty($query['limit']) && $results_per_page) {
        $query['limit'] = $results_per_page;
    }
    if (empty($query['offset']) && $query['limit']) {
        $query['offset'] = $results_offset;
    }
    $listings_collection = awpcp_listings_collection();
    $listings = $listings_collection->find_enabled_listings_with_query($query);
    $listings_count = $listings_collection->count_enabled_listings_with_query($query);
    $before_content = apply_filters('awpcp-content-before-listings-page', $options['before_content'], $context);
    $before_pagination = array();
    if ($options['show_category_selector']) {
        $before_pagination[15]['category-selector'] = awpcp_render_category_selector(array('required' => false));
    }
    if (is_array($options['before_pagination'])) {
        $before_pagination = awpcp_array_merge_recursive($before_pagination, $options['before_pagination']);
    } else {
        $before_pagination[20]['user-content'] = $options['before_pagination'];
    }
    $before_pagination = apply_filters('awpcp-listings-before-content', $before_pagination, $context);
    ksort($before_pagination);
    $before_pagination = awpcp_flatten_array($before_pagination);
    $before_list = apply_filters('awpcp-display-ads-before-list', $options['before_list'], $context);
    if ($listings_count > 0) {
        $pagination_options = array('results' => $results_per_page, 'offset' => $results_offset, 'total' => $listings_count);
        $pagination = $options['show_pagination'] ? awpcp_pagination($pagination_options, awpcp_current_url()) : '';
        $items = awpcp_render_listings_items($listings, $context);
    } else {
        $pagination = '';
        $items = array();
    }
    $after_pagination = array('user-content' => $options['after_pagination']);
    $after_pagination = apply_filters('awpcp-listings-after-content', $after_pagination, $context);
    $after_content = apply_filters('awpcp-content-after-listings-page', $options['after_content'], $context);
    ob_start();
    include AWPCP_DIR . '/templates/frontend/listings.tpl.php';
    $content = ob_get_contents();
    ob_end_clean();
    return $content;
}
Example #7
0
 /**
  * Allow users to download Debug Info as an HTML file.
  *
  * @since 2.0.7
  */
 public function download()
 {
     global $pagenow;
     if (!awpcp_current_user_is_admin()) {
         return;
     }
     if ($pagenow == 'admin.php' && awpcp_request_param('page') === 'awpcp-debug' && awpcp_request_param('download') === 'debug-info') {
         $filename = sprintf('awpcp-debug-info-%s.html', date('Y-m-d-Hi', current_time('timestamp')));
         header('Content-Description: File Transfer');
         header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
         header('Content-Disposition: attachment; filename=' . $filename);
         header("Pragma: no-cache");
         die($this->render(true));
     }
 }
 private function parse_query()
 {
     global $wpdb;
     $user = wp_get_current_user();
     $ipp = (int) get_user_meta($user->ID, 'fees-items-per-page', true);
     $this->items_per_page = awpcp_request_param('items-per-page', $ipp === 0 ? 10 : $ipp);
     update_user_meta($user->ID, 'fees-items-per-page', $this->items_per_page);
     $params = shortcode_atts(array('orderby' => '', 'order' => 'desc', 'paged' => 1), $_REQUEST);
     $params['order'] = strcasecmp($params['order'], 'DESC') === 0 ? 'DESC' : 'ASC';
     $params['pages'] = (int) $params['paged'];
     switch ($params['orderby']) {
         case 'duration':
             $orderby = sprintf('rec_period %1$s, adterm_name', $params['order']);
             break;
         case 'interval':
             $orderby = sprintf('rec_increment %1$s, adterm_name', $params['order']);
             break;
         case 'images':
             $orderby = sprintf('imagesallowed %1$s, adterm_name', $params['order']);
             break;
         case 'title-characters':
             $orderby = sprintf('title_characters %1$s, adterm_name', $params['order']);
             break;
         case 'characters':
             $orderby = sprintf('characters_allowed %1$s, adterm_name', $params['order']);
             break;
         case 'price':
             $orderby = sprintf('amount %1$s, adterm_name', $params['order']);
             break;
         case 'credits':
             $orderby = sprintf('credits %1$s, adterm_name', $params['order']);
             break;
         case 'categories':
             $orderby = sprintf('categories %1$s, adterm_name', $params['order']);
             break;
         case 'featured':
             $orderby = sprintf('is_featured_ad_pricing %1$s, adterm_name', $params['order']);
             break;
         case 'private':
             $orderby = sprintf('private %1$s, adterm_name', $params['order']);
             break;
         case 'name':
         default:
             $orderby = 'adterm_name';
             break;
     }
     return array('orderby' => $orderby, 'order' => $params['order'], 'offset' => $this->items_per_page * ($params['paged'] - 1), 'limit' => $this->items_per_page);
 }
Example #9
0
 public function get_current_action($default = null)
 {
     $blacklist = $this->params_blacklist();
     // return current bulk-action, if one was selected
     if (!$this->action) {
         $this->action = $this->get_table()->current_action();
     }
     if (!$this->action) {
         $this->action = awpcp_request_param('action', 'index');
     }
     if (!isset($this->params) || empty($this->params)) {
         wp_parse_str($_SERVER['QUERY_STRING'], $_params);
         $this->params = array_diff_key($_params, array_combine($blacklist, $blacklist));
     }
     return $this->action;
 }
Example #10
0
 public function dispatch($page)
 {
     $this->page = $page;
     $action = $page->get_current_action();
     $ad = AWPCP_Ad::find_by_id(awpcp_request_param('id', awpcp_request_param('adid', false)));
     $media = awpcp_media_api()->find_by_id(awpcp_request_param('picid'));
     $current_user_id = get_current_user_id();
     $is_admin_user = awpcp_current_user_is_admin();
     $ad_belongs_to_user = AWPCP_Ad::belongs_to_user($ad->ad_id, $current_user_id);
     if (!$is_admin_user && !$ad_belongs_to_user) {
         $message = _x("You don't have sufficient permissions to modify that Ad's media", 'media manager', 'AWPCP');
         return $this->page->render('content', awpcp_print_error($message));
     }
     if (!is_null($media) && $ad->ad_id != $media->ad_id) {
         $message = _x('The specified file does not belongs to the specified Ad. No action will be performed.', 'media managear', 'AWPCP');
         awpcp_flash($message, 'error');
         $action = 'show_images';
     }
     $media_actions = array('deletepic', 'rejectpic', 'approvepic', 'set-primary-image');
     if (is_null($media) && in_array($action, $media_actions)) {
         $message = _x('The specified file does not exists. No action will be performed.', 'media managear', 'AWPCP');
         awpcp_flash($message, 'error');
         $action = 'show_images';
     }
     switch ($action) {
         case 'deletepic':
             return $this->delete_file($ad, $media);
         case 'rejectpic':
             return $this->disable_picture($ad, $media);
         case 'approvepic':
             return $this->enable_picture($ad, $media);
         case 'approve-file':
             return $this->approve_file($ad, $media);
         case 'reject-file':
             return $this->reject_file($ad, $media);
         case 'set-primary-image':
             return $this->set_primary_image($ad, $media);
         case 'add-image':
             return $this->add_image($ad, $media);
         default:
             return $this->show_images($ad);
     }
 }
 private function parse_query()
 {
     $user = wp_get_current_user();
     $ipp = (int) get_user_meta($user->ID, 'credit-plans-items-per-page', true);
     $this->items_per_page = awpcp_request_param('items-per-page', $ipp === 0 ? 10 : $ipp);
     update_user_meta($user->ID, 'credit-plans-items-per-page', $this->items_per_page);
     $params = shortcode_atts(array('orderby' => '', 'order' => 'DESC', 'paged' => 1), $_REQUEST);
     $params['order'] = strtoupper($params['order']) == 'ASC' ? 'ASC' : 'DESC';
     switch ($params['orderby']) {
         case 'price':
             $orderby = sprintf('price %1$s, name %1$s, id', $params['order']);
             break;
         case 'credits':
             $orderby = sprintf('credits %1$s, name %1$s, id', $params['order']);
             break;
         case 'name':
         default:
             $orderby = 'name';
             break;
     }
     return array('orderby' => $orderby, 'order' => $params['order'], 'offset' => $this->items_per_page * (absint($params['paged']) - 1), 'limit' => $this->items_per_page);
 }
 public function get_current_action($default = 'browsecat')
 {
     return awpcp_request_param('a', $default);
 }
Example #13
0
 public function get_current_action($default = null)
 {
     return awpcp_post_param('step', awpcp_request_param('step', $default));
 }
Example #14
0
 protected function render_all_listings()
 {
     $query = array('context' => 'public-listings', 'limit' => absint(awpcp_request_param('results', get_awpcp_option('adresultsperpage', 10))), 'offset' => absint(awpcp_request_param('offset', 0)), 'orderby' => get_awpcp_option('groupbrowseadsby'));
     return awpcp_display_listings_in_page($query, 'browse-listings');
 }
Example #15
0
 public function delete()
 {
     $id = awpcp_request_param('id', 0);
     $fee = AWPCP_Fee::find_by_id($id);
     if (is_null($fee)) {
         awpcp_flash(__("The specified Fee doesn't exists.", 'AWPCP'), 'error');
         return $this->index();
     }
     $errors = array();
     if (AWPCP_Fee::delete($fee->id, $errors)) {
         awpcp_flash(__('The Fee was successfully deleted.', 'AWPCP'));
     } else {
         $where = sprintf("adterm_id = %d AND payment_term_type = 'fee'", $fee->id);
         $ads = AWPCP_Ad::find($where);
         if (empty($ads)) {
             foreach ($errors as $error) {
                 awpcp_flash($error, 'error');
             }
         } else {
             $fees = AWPCP_Fee::query();
             if (count($fees) > 1) {
                 $message = __("The Fee couldn't be deleted because there are active Ads in the system that are associated with the Fee ID. You need to switch the Ads to a different Fee before you can delete the plan.", "AWPCP");
                 awpcp_flash($message, 'error');
                 $params = array('fee' => $fee, 'fees' => $fees);
                 $template = AWPCP_DIR . '/admin/templates/admin-panel-fees-delete.tpl.php';
                 echo $this->render($template, $params);
                 return;
             } else {
                 $message = __("The Fee couldn't be deleted because there are active Ads in the system that are associated with the Fee ID. Please create a new Fee and try the delete operation again. AWPCP will help you to switch existing Ads to the new fee.", "AWPCP");
                 awpcp_flash($message, 'error');
             }
         }
     }
     return $this->index();
 }
Example #16
0
/**
 * @deprecated 3.4
 */
function awpcp_display_ads($where, $byl, $hidepager, $grouporderby, $adorcat, $before_content = '')
{
    _deprecated_function(__FUNCTION__, '3.4', 'awpcp_display_listings');
    global $wpdb;
    global $awpcp_plugin_path;
    global $hasregionsmodule;
    $output = '';
    $awpcp_browsecats_pageid = awpcp_get_page_id_by_ref('browse-categories-page-name');
    $browseadspageid = awpcp_get_page_id_by_ref('browse-ads-page-name');
    $searchadspageid = awpcp_get_page_id_by_ref('search-ads-page-name');
    // filters to provide alternative method of storing custom layouts (e.g. can be outside of this plugin's directory)
    if (has_action('awpcp_browse_ads_template_action') || has_filter('awpcp_browse_ads_template_filter')) {
        do_action('awpcp_browse_ads_template_action');
        $output = apply_filters('awpcp_browse_ads_template_filter');
        return;
    } else {
        if (file_exists("{$awpcp_plugin_path}/awpcp_display_ads_my_layout.php") && get_awpcp_option('activatemylayoutdisplayads')) {
            include "{$awpcp_plugin_path}/awpcp_display_ads_my_layout.php";
        } else {
            $output .= "<div id=\"classiwrapper\">";
            $uiwelcome = stripslashes_deep(get_awpcp_option('uiwelcome'));
            $output .= apply_filters('awpcp-content-before-listings-page', '');
            $output .= "<div class=\"uiwelcome\">{$uiwelcome}</div>";
            $output .= awpcp_menu_items();
            if ($hasregionsmodule == 1) {
                // Do not show Region Control form when showing Search Ads page
                // search result. Changing the current location will redirect the user
                // to the form instead of a filterd version of the form and that's confusing
                if (is_page(awpcp_get_page_id_by_ref('search-ads-page-name')) && isset($_POST['a']) && $_POST['a'] == 'dosearch') {
                    // do nothing
                } else {
                    $output .= awpcp_region_control_selector();
                }
            }
            $output .= $before_content;
            $tbl_ads = $wpdb->prefix . "awpcp_ads";
            $from = "{$tbl_ads}";
            $ads_exist = ads_exist();
            if (!$ads_exist) {
                $showcategories = "<p style=\"padding:10px\">";
                $showcategories .= __("There are currently no ads in the system", "AWPCP");
                $showcategories .= "</p>";
                $pager1 = '';
                $pager2 = '';
            } else {
                $awpcp_image_display_list = array();
                if ($adorcat == 'cat') {
                    $tpname = get_permalink($awpcp_browsecats_pageid);
                } elseif ($adorcat == 'search') {
                    $tpname = get_permalink($searchadspageid);
                } elseif (preg_match('/^custom:/', $adorcat)) {
                    $tpname = str_replace('custom:', '', $adorcat);
                } else {
                    $tpname = get_permalink($browseadspageid);
                }
                $results = get_awpcp_option('adresultsperpage', 10);
                $results = absint(awpcp_request_param('results', $results));
                $offset = absint(awpcp_request_param('offset', 0));
                if ($results === 0) {
                    $results = 10;
                }
                $args = array('order' => AWPCP_Ad::get_order_conditions($grouporderby), 'offset' => $offset, 'limit' => $results);
                $ads = AWPCP_Ad::get_enabled_ads($args, array($where));
                // get_where_conditions() is called from get_enabled_ads(), we need the
                // WHERE conditions here to pass them to create_pager()
                $where = AWPCP_Ad::get_where_conditions(array($where));
                if (!isset($hidepager) || empty($hidepager)) {
                    //Unset the page and action here...these do the wrong thing on display ad
                    unset($_GET['page_id']);
                    unset($_POST['page_id']);
                    //unset($params['page_id']);
                    $pager1 = create_pager($from, join(' AND ', $where), $offset, $results, $tpname);
                    $pager2 = create_pager($from, join(' AND ', $where), $offset, $results, $tpname);
                } else {
                    $pager1 = '';
                    $pager2 = '';
                }
                $items = awpcp_render_listings_items($ads, 'listings');
                $opentable = "";
                $closetable = "";
                if (empty($ads)) {
                    $showcategories = "<p style=\"padding:20px;\">";
                    $showcategories .= __("There were no ads found", "AWPCP");
                    $showcategories .= "</p>";
                    $pager1 = '';
                    $pager2 = '';
                } else {
                    $showcategories = smart_table($items, intval($results / $results), $opentable, $closetable);
                }
            }
            $show_category_id = absint(awpcp_request_param('category_id'));
            if (!isset($url_browsecatselect) || empty($url_browsecatselect)) {
                $url_browsecatselect = get_permalink($awpcp_browsecats_pageid);
            }
            if ($ads_exist) {
                $category_id = (int) awpcp_request_param('category_id', -1);
                $category_id = $category_id === -1 ? (int) get_query_var('cid') : $category_id;
                $output .= "<div class=\"changecategoryselect\"><form method=\"post\" action=\"{$url_browsecatselect}\">";
                $output .= '<div class="awpcp-category-dropdown-container">';
                $dropdown = new AWPCP_CategoriesDropdown();
                $output .= $dropdown->render(array('context' => 'search', 'name' => 'category_id', 'selected' => $category_id));
                $output .= '</div>';
                $output .= "<input type=\"hidden\" name=\"a\" value=\"browsecat\" />&nbsp;<input class=\"button\" type=\"submit\" value=\"";
                $output .= __("Change Category", "AWPCP");
                $output .= "\" /></form></div>";
                $output .= "<div class=\"pager\">{$pager1}</div><div class=\"fixfloat\"></div>";
                $output .= "<div id='awpcpcatname' class=\"fixfloat\">";
                if ($category_id > 0) {
                    $output .= "<h3>" . __("Category: ", "AWPCP") . get_adcatname($category_id) . "</h3>";
                }
                $output .= "</div>";
            }
            $output .= apply_filters('awpcp-display-ads-before-list', '');
            $output .= "{$showcategories}";
            if ($ads_exist) {
                $output .= "&nbsp;<div class=\"pager\">{$pager2}</div>";
            }
            $output .= apply_filters('awpcp-content-after-listings-page', '');
            $output .= "</div>";
        }
    }
    return $output;
}
Example #17
0
/**
 * Handles AWPCPSHOWAD shortcode.
 *
 * @param $adid An Ad ID.
 * @param $omitmenu
 * @param $preview true if the function is used to show an ad just after
 *				   it was posted to the website.
 * @param $send_email if true and $preview=true, a success email will be send
 * 					  to the admin and poster user.
 *
 * @return Show Ad page content.
 */
function showad($adid = null, $omitmenu = false, $preview = false, $send_email = true, $show_messages = true)
{
    global $wpdb;
    awpcp_maybe_add_thickbox();
    wp_enqueue_script('awpcp-page-show-ad');
    $awpcp = awpcp();
    $awpcp->js->set('page-show-ad-flag-ad-nonce', wp_create_nonce('flag_ad'));
    $awpcp->js->localize('page-show-ad', array('flag-confirmation-message' => __('Are you sure you want to flag this ad?', 'AWPCP'), 'flag-success-message' => __('This Ad has been flagged.', 'AWPCP'), 'flag-error-message' => __('An error occurred while trying to flag the Ad.', 'AWPCP')));
    $preview = $preview === true || 'preview' == awpcp_array_data('adstatus', '', $_GET);
    $is_moderator = awpcp_current_user_is_moderator();
    $messages = array();
    $permastruc = get_option('permalink_structure');
    if (!isset($adid) || empty($adid)) {
        if (isset($_REQUEST['adid']) && !empty($_REQUEST['adid'])) {
            $adid = $_REQUEST['adid'];
        } elseif (isset($_REQUEST['id']) && !empty($_REQUEST['id'])) {
            $adid = $_REQUEST['id'];
        } else {
            if (isset($permastruc) && !empty($permastruc)) {
                $adid = get_query_var('id');
            } else {
                $adid = 0;
            }
        }
    }
    $adid = absint($adid);
    if (!empty($adid)) {
        // filters to provide alternative method of storing custom
        // layouts (e.g. can be outside of this plugin's directory)
        $prefix = 'awpcp_single_ad_template';
        if (has_action("{$prefix}_action") || has_filter("{$prefix}_filter")) {
            do_action("{$prefix}_action");
            return apply_filters("{$prefix}_filter");
        } else {
            $results = AWPCP_Ad::query(array('where' => $wpdb->prepare('ad_id = %d', $adid)));
            if (count($results) === 1) {
                $ad = array_shift($results);
            } else {
                $ad = null;
            }
            if (is_null($ad)) {
                $message = __('Sorry, that listing is not available. Please try browsing or searching existing listings.', 'AWPCP');
                return '<div id="classiwrapper">' . awpcp_print_error($message) . '</div><!--close classiwrapper-->';
            }
            if ($ad->user_id > 0 && $ad->user_id == wp_get_current_user()->ID) {
                $is_ad_owner = true;
            } else {
                $is_ad_owner = false;
            }
            $content_before_page = apply_filters('awpcp-content-before-listing-page', '');
            $content_after_page = apply_filters('awpcp-content-after-listing-page', '');
            $output = '<div id="classiwrapper">%s%s<!--awpcp-single-ad-layout-->%s</div><!--close classiwrapper-->';
            $output = sprintf($output, $content_before_page, $omitmenu ? '' : awpcp_menu_items(), $content_after_page);
            if (!$is_moderator && !$is_ad_owner && !$preview && $ad->disabled == 1) {
                $message = __('The Ad you are trying to view is pending approval. Once the Administrator approves it, it will be active and visible.', 'AWPCP');
                return str_replace('<!--awpcp-single-ad-layout-->', awpcp_print_error($message), $output);
            }
            if (awpcp_request_param('verified') && $ad->verified) {
                $messages[] = awpcp_print_message(__('Your email address was successfully verified.', 'AWPCP'));
            }
            if ($show_messages && $is_moderator && $ad->disabled == 1) {
                $message = __('This Ad is currently disabled until the Administrator approves it. Only you (the Administrator) and the author can see it.', 'AWPCP');
                $messages[] = awpcp_print_error($message);
            } else {
                if ($show_messages && ($is_ad_owner || $preview) && !$ad->verified) {
                    $message = __('This Ad is currently disabled until you verify the email address used for the contact information. Only you (the author) can see it.', 'AWPCP');
                    $messages[] = awpcp_print_error($message);
                } else {
                    if ($show_messages && ($is_ad_owner || $preview) && $ad->disabled == 1) {
                        $message = __('This Ad is currently disabled until the Administrator approves it. Only you (the author) can see it.', 'AWPCP');
                        $messages[] = awpcp_print_error($message);
                    }
                }
            }
            $layout = awpcp_get_listing_single_view_layout($ad);
            $layout = awpcp_do_placeholders($ad, $layout, 'single');
            $output = str_replace('<!--awpcp-single-ad-layout-->', join('', $messages) . $layout, $output);
            $output = apply_filters('awpcp-show-ad', $output, $adid);
            if (!awpcp_request()->is_bot()) {
                $ad->visit();
            }
            $ad->save();
        }
    } else {
        $query = array('limit' => absint(awpcp_request_param('results', get_awpcp_option('adresultsperpage', 10))), 'offset' => absint(awpcp_request_param('offset', 0)), 'orderby' => get_awpcp_option('groupbrowseadsby'));
        $output = awpcp_display_listings_in_page($query, 'show-listing');
    }
    return $output;
}
Example #18
0
 public function ajax_flag_ad()
 {
     $response = 0;
     if (check_ajax_referer('flag_ad', 'nonce')) {
         $ad = AWPCP_Ad::find_by_id(intval(awpcp_request_param('ad', 0)));
         if (!is_null($ad)) {
             $response = awpcp_listings_api()->flag_listing($ad);
         }
     }
     echo $response;
     die;
 }
Example #19
0
 /**
  * A hack to show the WP Users associated to a submenu under
  * Classifieds menu.
  *
  * @since 3.0.2
  */
 public function parent_file($parent_file)
 {
     global $current_screen, $submenu_file, $typenow;
     if ($current_screen->base == 'users' && awpcp_request_param('action') == 'awpcp-manage-credits') {
         // make Classifieds menu the current menu
         $parent_file = 'awpcp.php';
         // highlight Manage Credits submenu in Classifieds menu
         $submenu_file = $this->get_manage_credits_section_url();
         // make $typenow non empty so Users menu is not highlighted
         // in _wp_menu_output, despite the fact we are showing the
         // All Users page.
         $typenow = 'hide-users-menu';
     }
     return $parent_file;
 }
 public function get_posted_data($data = array(), $context = false)
 {
     if ($context == 'search') {
         $conditions = awpcp_get_extra_fields_conditions(array('hide_private' => true, 'context' => 'search'));
         $fields = awpcp_get_extra_fields('WHERE ' . join(' AND ', $conditions));
         $data['keywordphrase'] = stripslashes(awpcp_request_param('keywordphrase', null));
         foreach ($fields as $field) {
             $field_slug = "awpcp-{$field->field_name}";
             if (isset($_REQUEST["awpcp-{$field->field_name}-min"])) {
                 $min = $this->parse_field_posted_data($field, awpcp_request_param("awpcp-{$field->field_name}-min", null));
                 $max = $this->parse_field_posted_data($field, awpcp_request_param("awpcp-{$field->field_name}-max", null));
                 if (!is_null($min) || !is_null($max)) {
                     $data[$field_slug] = array('min' => $min, 'max' => $max);
                 }
             } else {
                 if (isset($_REQUEST["awpcp-{$field->field_name}-from"])) {
                     $from_date = $this->parse_field_posted_data($field, awpcp_request_param("awpcp-{$field->field_name}-from", null));
                     $to_date = $this->parse_field_posted_data($field, awpcp_request_param("awpcp-{$field->field_name}-to", null));
                     if (!is_null($from_date) || !is_null($to_date)) {
                         $data[$field_slug] = array('from_date' => $from_date, 'to_date' => $to_date);
                     }
                 } else {
                     $data[$field_slug] = $this->parse_field_posted_data($field, awpcp_request_param($field_slug, null));
                 }
             }
         }
     }
     return $data;
 }
Example #21
0
 function widget($args, $instance)
 {
     extract($args);
     $instance = wp_parse_args($instance, $this->defaults());
     if (!empty($instance['subtitle'])) {
         $title = $instance['title'] . '<br/><span class="widgetstitle">' . $instance['subtitle'] . '</span>';
     } else {
         $title = $instance['title'] . '</span>';
     }
     echo '<div class="awpcp-search-listings-widget">';
     echo $before_widget . $before_title . $title . $after_title;
     echo '<div align="center"><form method=\'get\' action="' . url_searchads() . '">';
     $url_params = wp_parse_args(parse_url(url_searchads(), PHP_URL_QUERY));
     foreach ($url_params as $param => $value) {
         echo '<input type="hidden" name="' . esc_attr($param) . '" value="' . esc_attr($value) . '" />';
     }
     echo '<input type="hidden" name="a" value="dosearch"/>';
     $keywordphrase = stripslashes_deep(awpcp_request_param('keywordphrase'));
     if ($instance['show_keyword'] == 1) {
         echo '<label for="awpcp-search-keywordphrase">' . __('Search by keyword', "AWPCP") . '</label>';
         echo '<input id="awpcp-search-keywordphrase" type="text" name="keywordphrase" value="' . esc_attr($keywordphrase) . '">';
     }
     if ($instance['show_by'] == 1) {
         echo $this->render_find_by_contact_name_field();
     }
     echo $this->render_region_fields($instance);
     if ($instance['show_category'] == 1) {
         $label = __('Search by Category', "AWPCP");
         $name = 'searchcategory';
         $selected = stripslashes_deep(awpcp_request_param($name, null));
         $dropdown = new AWPCP_CategoriesDropdown();
         echo $dropdown->render(array('context' => 'search', 'selected' => $selected, 'required' => false, 'name' => $name, 'label' => $label));
     }
     echo '<div class="submit"><input class="button" type="submit" value="' . __('Search', 'AWPCP') . '"></div>';
     echo '</form></div>';
     echo '</div>';
     echo $after_widget;
 }
Example #22
0
 /**
  * Handler for AJAX request from the Multiple Region Selector to get new options
  * for a given field.
  *
  * @since 3.0.2
  */
 public function get_regions_options()
 {
     $type = awpcp_request_param('type', '', $_GET);
     $parent_type = awpcp_request_param('parent_type', '', $_GET);
     $parent = awpcp_request_param('parent', '', $_GET);
     $context = awpcp_request_param('context', '', $_GET);
     $options = apply_filters('awpcp-get-regions-options', false, $type, $parent_type, $parent, $context);
     if ($options === false) {
         $options = array();
         if ($context === 'search' && get_awpcp_option('buildsearchdropdownlists')) {
             $regions = awpcp_basic_regions_api()->find_by_parent_name($parent, $parent_type, $type);
         } else {
             $regions = array();
         }
         $regions = array_filter($regions, 'strlen');
         foreach ($regions as $key => $option) {
             $options[] = array('id' => $option, 'name' => $option);
         }
     }
     $response = array('status' => 'ok', 'options' => $options);
     header("Content-Type: application/json");
     echo json_encode($response);
     die;
 }
 public function delete_selected_ads()
 {
     if (!wp_verify_nonce(awpcp_request_param('_wpnonce'), 'bulk-awpcp-listings')) {
         return $this->index();
     }
     $user = wp_get_current_user();
     $selected = awpcp_request_param('selected');
     $deleted = 0;
     $failed = 0;
     $non_existent = 0;
     $unauthorized = 0;
     $total = count($selected);
     foreach ($selected as $id) {
         try {
             $listing = awpcp_listings_collection()->get($id);
         } catch (AWPCP_Exception $e) {
             $non_existent = $non_existent + 1;
             continue;
         }
         if (!awpcp_listing_authorization()->is_current_user_allowed_to_edit_listing($listing)) {
             $unauthorized = $unauthorized + 1;
             continue;
         }
         $errors = array();
         deletead($id, '', '', $force = true, $errors);
         if (empty($errors)) {
             $deleted = $deleted + 1;
         } else {
             $failed = $failed + 1;
         }
     }
     if ($deleted > 0 && $failed > 0) {
         awpcp_flash(sprintf(__('%d of %d Ads were deleted. %d generated errors.', 'AWPCP'), $deleted, $total, $failed));
     } else {
         if ($deleted > 0) {
             awpcp_flash(sprintf(__('%d of %d Ads were deleted.', 'AWPCP'), $deleted, $total));
         }
     }
     if ($non_existent > 0) {
         awpcp_flash(sprintf(__("%d of %d Ads don't exist.", 'AWPCP'), $non_existent, $total), 'error');
     }
     if ($unauthorized > 0) {
         awpcp_flash(sprintf(__("%d of %d Ads weren't deleted because you are not authorized.", 'AWPCP'), $non_existent, $total), 'error');
     }
     return $this->redirect('index');
 }
Example #24
0
 protected function request_includes_authorized_hash($ad)
 {
     return wp_verify_nonce(awpcp_request_param('edit-hash'), "edit-ad-{$ad->ad_id}");
 }
Example #25
0
<?php

if (awpcp_request_param('register', false)) {
    ?>
	<?php 
    echo awpcp_print_message(__('Please check your email for the password and then return to log in.', 'AWPCP'));
} elseif (awpcp_request_param('reset', false)) {
    ?>
	<?php 
    echo awpcp_print_message(__('Please check your email to reset your password.', 'AWPCP'));
} elseif ($message) {
    ?>
	<?php 
    echo awpcp_print_message($message);
}
?>

<div class="awpcp-login-form">
	<?php 
wp_login_form(array('redirect' => $redirect));
?>

	<p id="nav" class="nav">
	<?php 
if (isset($_GET['checkemail']) && in_array($_GET['checkemail'], array('confirm', 'newpass'))) {
    ?>
	<!-- nothing here -->
	<?php 
} elseif (get_option('users_can_register')) {
    ?>
	<a href="<?php 
 public function get_search_by_box()
 {
     if (empty($_REQUEST['s']) && !$this->has_items()) {
         return;
     }
     $id = 'search-by';
     $label = __('Search by', 'AWPCP');
     $options['id'] = __('Ad ID', 'AWPCP');
     $options['title'] = __('Ad Title', 'AWPCP');
     $options['keyword'] = __('Keyword', 'AWPCP');
     $options['location'] = __('Location', 'AWPCP');
     if (awpcp_current_user_is_admin()) {
         $options['payer-email'] = __('Payer Email', 'AWPCP');
     }
     $options['user'] = __('User', 'AWPCP');
     $search_by = awpcp_request_param('search-by', 'title');
     $html = '<p class="search-by-box">';
     $html .= '<label>' . $label . ':</label>&nbsp;&nbsp;';
     foreach ($options as $value => $text) {
         $id = 'search-by-' . $value;
         $selected = $search_by == $value ? 'checked="checked"' : '';
         $html .= '<input type="radio" id="' . $id . '" name="search-by" ' . $selected . ' value="' . $value . '" />&nbsp;';
         $html .= '<label for="' . $id . '">' . $text . '</label>&nbsp;';
     }
     $html .= '</p>';
     echo $html;
 }
Example #27
0
/**
 * TODO: replace usage of this function with awpcp_pagination()
 */
function _create_pager($item_count, $offset, $results, $tpname)
{
    $permastruc = get_option('permalink_structure');
    if (isset($permastruc) && !empty($permastruc)) {
        $awpcpoffset_set = "?offset=";
    } else {
        if (is_admin()) {
            $awpcpoffset_set = "?offset=";
        } else {
            $awpcpoffset_set = "&offset=";
        }
    }
    mt_srand(create_awpcp_random_seed());
    $radius = 5;
    global $accepted_results_per_page;
    $accepted_results_per_page = awpcp_pagination_options($results);
    // TODO: remove all fields that belongs to the Edit Ad form (including extra fields and others?)
    $params = array_merge($_GET, $_POST);
    unset($params['page_id'], $params['offset'], $params['results']);
    unset($params['PHPSESSID'], $params['aeaction'], $params['category_id']);
    unset($params['cat_ID'], $params['action'], $params['aeaction']);
    unset($params['category_name'], $params['category_parent_id']);
    unset($params['createeditadcategory'], $params['deletemultiplecategories']);
    unset($params['movedeleteads'], $params['moveadstocategory']);
    unset($params['category_to_delete'], $params['tpname']);
    unset($params['category_icon'], $params['sortby'], $params['adid']);
    unset($params['picid'], $params['adkey'], $params['editemail']);
    unset($params['awpcp_ads_to_action'], $params['post_type']);
    $cid = intval(awpcp_request_param('category_id'));
    $cid = empty($cid) ? get_query_var('cid') : $cid;
    if ($cid > 0) {
        $params['category_id'] = intval($cid);
    }
    $myrand = mt_rand(1000, 2000);
    $form = "<form id=\"pagerform{$myrand}\" name=\"pagerform{$myrand}\" action=\"\" method=\"get\">\n";
    $form .= "<table>\n";
    $form .= "<tr>\n";
    $form .= "\t<td>\n";
    $totalrows = $item_count;
    $total_pages = ceil($totalrows / $results);
    $dotsbefore = false;
    $dotsafter = false;
    $current_page = 0;
    $myreturn = '';
    for ($i = 1; $i <= $total_pages; $i++) {
        if (($i - 1) * $results <= $offset && $offset < $i * $results) {
            $myreturn .= "{$i}&nbsp;";
            $current_page = $i;
        } elseif (($i - 1 + $radius) * $results < $offset) {
            if (!$dotsbefore) {
                $myreturn .= "...";
                $dotsbefore = true;
            }
        } elseif (($i - 1 - $radius) * $results > $offset) {
            if (!$dotsafter) {
                $myreturn .= "...";
                $dotsafter = true;
            }
        } else {
            $href_params = array_merge($params, array('offset' => ($i - 1) * $results, 'results' => $results));
            $href = add_query_arg(urlencode_deep($href_params), $tpname);
            $myreturn .= sprintf('<a href="%s">%d</a>&nbsp;', esc_url($href), esc_attr($i));
        }
    }
    if ($offset != 0) {
        //Subtract 2, page is 1-based index, results is 0-based, must compensate for 2 pages here
        if (($current_page - 2) * $results < $results) {
            $href_params = array_merge($params, array('offset' => 0, 'results' => $results));
            $href = add_query_arg(urlencode_deep($href_params), $tpname);
        } else {
            $href_params = array_merge($params, array('offset' => ($current_page - 2) * $results, 'results' => $results));
            $href = add_query_arg(urlencode_deep($href_params), $tpname);
        }
        $prev = sprintf('<a href="%s">&laquo;</a>&nbsp;', esc_url($href));
    } else {
        $prev = '';
    }
    if ($offset != ($total_pages - 1) * $results) {
        $href_params = array_merge($params, array('offset' => $current_page * $results, 'results' => $results));
        $href = add_query_arg(urlencode_deep($href_params), $tpname);
        $next = sprintf('<a href="%s">&raquo;</a>&nbsp;', esc_url($href));
    } else {
        $next = '';
    }
    if (isset($_REQUEST['page_id']) && !empty($_REQUEST['page_id'])) {
        $form .= "\t\t<input type=\"hidden\" name=\"page_id\" value='" . esc_attr($_REQUEST['page_id']) . "' />\n";
    }
    $form = $form . $prev . $myreturn . $next;
    $form .= "\t</td>\n";
    if (count($accepted_results_per_page) > 1) {
        $form .= "\t<td>\n";
        $form .= "\t\t<input type=\"hidden\" name=\"offset\" value=\"{$offset}\" />\n";
        $flat_params = awpcp_flatten_array($params);
        while (list($k, $v) = each($flat_params)) {
            if (is_array($v)) {
                $v = count($v) > 0 ? reset($v) : '';
            }
            $form .= "\t\t<input type=\"hidden\" name=\"" . esc_attr($k) . "\" value=\"" . esc_attr($v) . "\" />\n";
        }
        $form .= "\t\t<select name=\"results\" onchange=\"document.pagerform{$myrand}.submit()\">\n";
        $form .= vector2options($accepted_results_per_page, $results);
        $form .= "\t\t</select>\n";
        $form .= "\t</td>\n";
    }
    $form .= "</tr>\n";
    $form .= "</table>\n";
    $form .= "</form>\n";
    return $form;
}
Example #28
0
 public function verify_renew_ad_hash($ad)
 {
     return awpcp_verify_renew_ad_hash($ad->ad_id, awpcp_request_param('awpcprah'));
 }
Example #29
0
 private function search_listings($form)
 {
     $query = array_merge($form, array('keyword' => $form['query'], 'category_id' => $form['category'], 'contact_name' => $form['name'], 'min_price' => $form['min_price'], 'max_price' => $form['max_price'], 'regions' => $form['regions'], 'disabled' => false, 'limit' => absint(awpcp_request_param('results', get_awpcp_option('adresultsperpage', 10))), 'offset' => absint(awpcp_request_param('offset', 0)), 'orderby' => get_awpcp_option('search-results-order')));
     return awpcp_display_listings($query, 'search', array('show_intro_message' => true, 'show_menu_items' => true, 'show_category_selector' => false, 'show_pagination' => true, 'before_list' => $this->build_return_link()));
 }