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;
}
 private function force_secure_urls()
 {
     $force_secure_url = false;
     $pages = array('place-ad-page-name', 'subscriptions-page-name', 'renew-ad-page-name');
     foreach ($pages as $page) {
         $page_id = awpcp_get_page_id_by_ref($page);
         if ($page_id && is_page($page_id)) {
             $force_secure_url = true;
             break;
         }
     }
     if (!$force_secure_url) {
         global $post;
         $shortcodes = array('AWPCPPLACEAD', 'AWPCP-BUY-SUBSCRIPTION', 'AWPCP-RENEW-AD', 'AWPCPBUYCREDITS');
         $regexp = '/\\[' . join('\\]|\\[', $shortcodes) . '\\]/';
         if (preg_match($regexp, $post->post_content)) {
             $force_secure_url = true;
         }
     }
     if ($force_secure_url && wp_redirect(set_url_scheme(awpcp_current_url(), 'https'))) {
         exit;
     }
 }
Example #3
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 #4
0
/**
 * @since 3.2.1
 */
function awpcp_rel_canonical_url()
{
    global $wp_the_query;
    if (!is_singular()) {
        return false;
    }
    if (!($page_id = $wp_the_query->get_queried_object_id())) {
        return false;
    }
    if ($page_id != awpcp_get_page_id_by_ref('show-ads-page-name')) {
        return false;
    }
    $ad_id = intval(awpcp_request_param('id', ''));
    $ad_id = empty($ad_id) ? intval(get_query_var('id')) : $ad_id;
    if (empty($ad_id)) {
        $url = get_permalink($page_id);
    } else {
        $url = url_showad($ad_id);
    }
    return $url;
}
Example #5
0
 private function upgrade_to_2_0_5($version)
 {
     global $wpdb, $awpcp;
     $translations = array('userpagename' => 'main-page-name', 'showadspagename' => 'show-ads-page-name', 'placeadpagename' => 'place-ad-page-name', 'editadpagename' => 'edit-ad-page-name', 'page-name-renew-ad' => 'renew-ad-page-name', 'replytoadpagename' => 'reply-to-ad-page-name', 'browseadspagename' => 'browse-ads-page-name', 'searchadspagename' => 'search-ads-page-name', 'browsecatspagename' => 'browse-categories-page-name', 'categoriesviewpagename' => 'view-categories-page-name', 'paymentthankyoupagename' => 'payment-thankyou-page-name', 'paymentcancelpagename' => 'payment-cancel-page-name');
     // Users who upgraded from 1.8.9.4 to 2.0.4 have an installation
     // with no AWPCP pages. The pages exist, but are not recognized
     // by the plugin.
     foreach ($translations as $old => $new) {
         $page_id = awpcp_get_page_id_by_ref($new);
         if ($page_id > 0) {
             continue;
         }
         // Let's try to find the pages using the old AND new names
         foreach (array($old, $new) as $option) {
             // The setting doesn't exist. Nothing to do.
             $name = $awpcp->settings->get_option($option, null);
             if ($name == null) {
                 continue;
             }
             $sanitized = sanitize_title($name);
             $sql = "SELECT ID FROM {$wpdb->posts} WHERE post_name = %s AND post_type = 'page'";
             $id = intval($wpdb->get_var($wpdb->prepare($sql, $sanitized)));
             $id = $id > 0 ? $id : -1;
             awpcp_update_plugin_page_id($new, $id);
             if ($id > 0) {
                 $awpcp->settings->update_option($new, $name, true);
                 break;
             }
         }
     }
     // Since pages automatic creation is not enabled, we need to create the
     // Renew Ad page manually.
     awpcp_create_subpage('renew-ad-page-name', $awpcp->settings->get_option('renew-ad-page-name'), '[AWPCP-RENEW-AD]');
 }
Example #6
0
/**
 * Creates a subpage of the main AWPCP page.
 * 
 * This functions takes care of checking if the main AWPCP
 * page exists, finding its id and verifying that the new
 * page doesn't exist already. Useful for module plugins.
 */
function awpcp_create_subpage($refname, $name, $shortcode, $awpcp_page_id = null)
{
    global $wpdb;
    $id = 0;
    if (!empty($name)) {
        // it is possible that the main AWPCP page does not exist, in that case
        // we should create Subpages without a parent.
        if (is_null($awpcp_page_id) && awpcp_find_page('main-page-name')) {
            $awpcp_page_id = awpcp_get_page_id_by_ref('main-page-name');
        } else {
            if (is_null($awpcp_page_id)) {
                $awpcp_page_id = '';
            }
        }
        if (!awpcp_find_page($refname)) {
            $id = maketheclassifiedsubpage($name, $awpcp_page_id, $shortcode);
        }
    }
    if ($id > 0) {
        awpcp_update_plugin_page_id($refname, $id);
    }
    return $id;
}
Example #7
0
/**
 * @since 3.0.2
 */
function awpcp_get_view_categories_url()
{
    $permalinks = get_option('permalink_structure');
    $main_page_id = awpcp_get_page_id_by_ref('main-page-name');
    $page_name = get_awpcp_option('view-categories-page-name');
    $slug = sanitize_title($page_name);
    if (!empty($permalinks)) {
        $url = sprintf('%s/%s', trim(home_url(get_page_uri($main_page_id)), '/'), $slug);
        $url = user_trailingslashit($url);
    } else {
        $url = add_query_arg(array('page_id' => $main_page_id, 'layout' => 2), home_url('/'));
    }
    return $url;
}
Example #8
0
 private function is_browse_categories_page()
 {
     // we want't to use the original query but calling wp_reset_query
     // breaks things for Events Manager and maybe other plugins
     if (!isset($GLOBALS['wp_the_query'])) {
         return false;
     }
     $query = $GLOBALS['wp_the_query'];
     if (!$query->is_page(awpcp_get_page_id_by_ref('browse-categories-page-name'))) {
         return false;
     }
     if (empty($this->category_id)) {
         return false;
     }
     return true;
 }