Example #1
0
}
?>
><?php 
_e('User based');
?>
</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-row">
                        <div class="form-label"><?php 
_e('Host');
?>
</div>
                        <div class="form-controls"><input type="text" class="xlarge" name="s_host" value="<?php 
echo osc_esc_html(osc_subdomain_host());
?>
" />
                            <div class="help-box"><?php 
_e('Your host is required to know the subdomain.');
?>
 <?php 
printf(__('Your current host is "%s". Add it without "www".'), $current_host);
?>
 <?php 
_e('Remember to enable cookies for the subdomains too.');
?>
</div>
                        </div>
                    </div>
                    <div class="clear"></div>
Example #2
0
/**
 * Gets search url given params
 *
 * @params array $params
 * @return string
 */
function osc_search_url($params = null)
{
    if (is_array($params)) {
        osc_prune_array($params);
    }
    $countP = count($params);
    if ($countP == 0) {
        $params['page'] = 'search';
    }
    $base_url = osc_base_url();
    $http_url = osc_is_ssl() ? "https://" : "http://";
    if (osc_subdomain_type() == 'category' && isset($params['sCategory'])) {
        if ($params['sCategory'] != Params::getParam('sCategory')) {
            if (is_array($params['sCategory'])) {
                $params['sCategory'] = implode(",", $params['sCategory']);
            }
            if ($params['sCategory'] != '' && strpos($params['sCategory'], ",") === false) {
                if (is_numeric($params['sCategory'])) {
                    $category = Category::newInstance()->findByPrimaryKey($params['sCategory']);
                } else {
                    $category = Category::newInstance()->findBySlug($params['sCategory']);
                }
                if (isset($category['s_slug'])) {
                    $base_url = $http_url . $category['s_slug'] . "." . osc_subdomain_host() . REL_WEB_URL;
                    unset($params['sCategory']);
                }
            }
        } else {
            if (osc_is_subdomain()) {
                unset($params['sCategory']);
            }
        }
    } else {
        if (osc_subdomain_type() == 'country' && isset($params['sCountry'])) {
            if ($params['sCountry'] != Params::getParam('sCountry')) {
                if (is_array($params['sCountry'])) {
                    $params['sCountry'] = implode(",", $params['sCountry']);
                }
                if ($params['sCountry'] != '' && strpos($params['sCountry'], ",") === false) {
                    if (is_numeric($params['sCountry'])) {
                        $country = Country::newInstance()->findByPrimaryKey($params['sCountry']);
                    } else {
                        $country = Country::newInstance()->findByCode($params['sCountry']);
                    }
                    if (isset($country['s_slug'])) {
                        $base_url = $http_url . $country['s_slug'] . "." . osc_subdomain_host() . REL_WEB_URL;
                        unset($params['sCountry']);
                    }
                }
            } else {
                if (osc_is_subdomain()) {
                    unset($params['sCountry']);
                }
            }
        } else {
            if (osc_subdomain_type() == 'region' && isset($params['sRegion'])) {
                if ($params['sRegion'] != Params::getParam('sRegion')) {
                    if (is_array($params['sRegion'])) {
                        $params['sRegion'] = implode(",", $params['sRegion']);
                    }
                    if ($params['sRegion'] != '' && strpos($params['sRegion'], ",") === false) {
                        if (is_numeric($params['sRegion'])) {
                            $region = Region::newInstance()->findByPrimaryKey($params['sRegion']);
                        } else {
                            $region = Region::newInstance()->findByName($params['sRegion']);
                        }
                        if (isset($region['s_slug'])) {
                            $base_url = $http_url . $region['s_slug'] . "." . osc_subdomain_host() . REL_WEB_URL;
                            unset($params['sRegion']);
                        }
                    }
                } else {
                    if (osc_is_subdomain()) {
                        unset($params['sRegion']);
                    }
                }
            } else {
                if (osc_subdomain_type() == 'city' && isset($params['sCity'])) {
                    if ($params['sCity'] != Params::getParam('sCity')) {
                        if (is_array($params['sCity'])) {
                            $params['sCity'] = implode(",", $params['sCity']);
                        }
                        if ($params['sCity'] != '' && strpos($params['sCity'], ",") === false) {
                            if (is_numeric($params['sCity'])) {
                                $city = City::newInstance()->findByPrimaryKey($params['sCity']);
                            } else {
                                $city = City::newInstance()->findByName($params['sCity']);
                            }
                            if (isset($city['s_slug'])) {
                                $base_url = $http_url . $city['s_slug'] . "." . osc_subdomain_host() . REL_WEB_URL;
                                unset($params['sCity']);
                            }
                        }
                    } else {
                        if (osc_is_subdomain()) {
                            unset($params['sCity']);
                        }
                    }
                } else {
                    if (osc_subdomain_type() == 'user' && isset($params['sUser'])) {
                        if ($params['sUser'] != Params::getParam('sUser')) {
                            if (is_array($params['sUser'])) {
                                $params['sUser'] = implode(",", $params['sUser']);
                            }
                            if ($params['sUser'] != '' && strpos($params['sUser'], ",") === false) {
                                if (is_numeric($params['sUser'])) {
                                    $user = User::newInstance()->findByPrimaryKey($params['sUser']);
                                } else {
                                    $user = User::newInstance()->findByUsername($params['sUser']);
                                }
                                if (isset($user['s_username'])) {
                                    $base_url = $http_url . $user['s_username'] . "." . osc_subdomain_host() . REL_WEB_URL;
                                    unset($params['sUser']);
                                }
                            }
                        } else {
                            if (osc_is_subdomain()) {
                                unset($params['sUser']);
                            }
                        }
                    }
                }
            }
        }
    }
    $countP = count($params);
    if ($countP == 0) {
        return $base_url;
    }
    unset($params['page']);
    $countP = count($params);
    if (osc_rewrite_enabled()) {
        $url = $base_url . osc_get_preference('rewrite_search_url');
        // CANONICAL URLS
        if (isset($params['sCategory']) && !is_array($params['sCategory']) && strpos($params['sCategory'], ',') === false && ($countP == 1 || $countP == 2 && isset($params['iPage']))) {
            if (osc_category_id() == $params['sCategory']) {
                $category['pk_i_id'] = osc_category_id();
                $category['s_slug'] = osc_category_slug();
            } else {
                if (is_numeric($params['sCategory'])) {
                    $category = Category::newInstance()->findByPrimaryKey($params['sCategory']);
                } else {
                    $category = Category::newInstance()->findBySlug($params['sCategory']);
                }
            }
            if (isset($category['pk_i_id'])) {
                $url = osc_get_preference('rewrite_cat_url');
                if (preg_match('|{CATEGORIES}|', $url)) {
                    $categories = Category::newInstance()->hierarchy($category['pk_i_id']);
                    $sanitized_categories = array();
                    $mCat = Category::newInstance();
                    for ($i = count($categories); $i > 0; $i--) {
                        $tmpcat = $mCat->findByPrimaryKey($categories[$i - 1]['pk_i_id']);
                        $sanitized_categories[] = $tmpcat['s_slug'];
                    }
                    $url = str_replace('{CATEGORIES}', implode("/", $sanitized_categories), $url);
                }
                $seo_prefix = '';
                if (osc_get_preference('seo_url_search_prefix') != '') {
                    $seo_prefix = osc_get_preference('seo_url_search_prefix') . '/';
                }
                $url = str_replace('{CATEGORY_NAME}', $category['s_slug'], $url);
                // DEPRECATED : CATEGORY_SLUG is going to be removed in 3.4
                $url = str_replace('{CATEGORY_SLUG}', $category['s_slug'], $url);
                $url = str_replace('{CATEGORY_ID}', $category['pk_i_id'], $url);
            } else {
                // Search by a category which does not exists (by form)
                // TODO CHANGE TO NEW ROUTES!!
                return $base_url . 'index.php?page=search&sCategory=' . urlencode($params['sCategory']);
            }
            if (isset($params['iPage']) && $params['iPage'] != '' && $params['iPage'] != 1) {
                $url .= '/' . $params['iPage'];
            }
            $url = $base_url . $seo_prefix . $url;
        } else {
            if (isset($params['sRegion']) && is_string($params['sRegion']) && strpos($params['sRegion'], ',') === false && ($countP == 1 || $countP == 2 && (isset($params['iPage']) || isset($params['sCategory'])) || $countP == 3 && isset($params['iPage']) && isset($params['sCategory']))) {
                $url = $base_url;
                if (osc_get_preference('seo_url_search_prefix') != '') {
                    $url .= osc_get_preference('seo_url_search_prefix') . '/';
                }
                if (isset($params['sCategory'])) {
                    $_auxSlug = _aux_search_category_slug($params['sCategory']);
                    if ($_auxSlug != '') {
                        $url .= $_auxSlug . '_';
                    }
                }
                if (isset($params['sRegion'])) {
                    if (osc_list_region_id() == $params['sRegion']) {
                        $url .= osc_sanitizeString(osc_list_region_slug()) . '-r' . osc_list_region_id();
                    } else {
                        if (is_numeric($params['sRegion'])) {
                            $region = Region::newInstance()->findByPrimaryKey($params['sRegion']);
                        } else {
                            $region = Region::newInstance()->findByName($params['sRegion']);
                        }
                        if (isset($region['s_slug'])) {
                            $url .= osc_sanitizeString($region['s_slug']) . '-r' . $region['pk_i_id'];
                        } else {
                            // Search by a region which does not exists (by form)
                            // TODO CHANGE TO NEW ROUTES!!
                            return $url . 'index.php?page=search&sRegion=' . urlencode($params['sRegion']);
                        }
                    }
                }
                if (isset($params['iPage']) && $params['iPage'] != '' && $params['iPage'] != 1) {
                    $url .= '/' . $params['iPage'];
                }
            } else {
                if (isset($params['sCity']) && !is_array($params['sCity']) && strpos($params['sCity'], ',') === false && ($countP == 1 || $countP == 2 && (isset($params['iPage']) || isset($params['sCategory'])) || $countP == 3 && isset($params['iPage']) && isset($params['sCategory']))) {
                    $url = $base_url;
                    if (osc_get_preference('seo_url_search_prefix') != '') {
                        $url .= osc_get_preference('seo_url_search_prefix') . '/';
                    }
                    if (isset($params['sCategory'])) {
                        $_auxSlug = _aux_search_category_slug($params['sCategory']);
                        if ($_auxSlug != '') {
                            $url .= $_auxSlug . '_';
                        }
                    }
                    if (isset($params['sCity'])) {
                        if (osc_list_city_id() == $params['sCity']) {
                            $url .= osc_sanitizeString(osc_list_city_slug()) . '-c' . osc_list_city_id();
                        } else {
                            if (is_numeric($params['sCity'])) {
                                $city = City::newInstance()->findByPrimaryKey($params['sCity']);
                            } else {
                                $city = City::newInstance()->findByName($params['sCity']);
                            }
                            if (isset($city['s_slug'])) {
                                $url .= osc_sanitizeString($city['s_slug']) . '-c' . $city['pk_i_id'];
                            } else {
                                // Search by a city which does not exists (by form)
                                // TODO CHANGE TO NEW ROUTES!!
                                return $url . 'index.php?page=search&sCity=' . urlencode($params['sCity']);
                            }
                        }
                    }
                    if (isset($params['iPage']) && $params['iPage'] != '' && $params['iPage'] != 1) {
                        $url .= '/' . $params['iPage'];
                    }
                } else {
                    if ($params != null && is_array($params)) {
                        foreach ($params as $k => $v) {
                            switch ($k) {
                                case 'sCountry':
                                    $k = osc_get_preference('rewrite_search_country');
                                    break;
                                case 'sRegion':
                                    $k = osc_get_preference('rewrite_search_region');
                                    break;
                                case 'sCity':
                                    $k = osc_get_preference('rewrite_search_city');
                                    break;
                                case 'sCityArea':
                                    $k = osc_get_preference('rewrite_search_city_area');
                                    break;
                                case 'sCategory':
                                    $k = osc_get_preference('rewrite_search_category');
                                    if (is_array($v)) {
                                        $v = implode(",", $v);
                                    }
                                    break;
                                case 'sUser':
                                    $k = osc_get_preference('rewrite_search_user');
                                    if (is_array($v)) {
                                        $v = implode(",", $v);
                                    }
                                    break;
                                case 'sPattern':
                                    $k = osc_get_preference('rewrite_search_pattern');
                                    break;
                                case 'meta':
                                    // meta(@id),value/meta(@id),value2/...
                                    foreach ($v as $key => $value) {
                                        if (is_array($value)) {
                                            foreach ($value as $_key => $_value) {
                                                if ($value != '') {
                                                    $url .= '/meta' . $key . '-' . $_key . ',' . urlencode($_value);
                                                }
                                            }
                                        } else {
                                            if ($value != '') {
                                                $url .= '/meta' . $key . ',' . urlencode($value);
                                            }
                                        }
                                    }
                                    break;
                                default:
                                    break;
                            }
                            if (!is_array($v) && $v != '') {
                                $url .= "/" . $k . "," . urlencode($v);
                            }
                        }
                    }
                }
            }
        }
    } else {
        $url = $base_url . 'index.php?page=search';
        if ($params != null && is_array($params)) {
            foreach ($params as $k => $v) {
                if ($k == 'meta') {
                    if (is_array($v)) {
                        foreach ($v as $_k => $aux) {
                            if (is_array($aux)) {
                                foreach (array_keys($aux) as $aux_k) {
                                    $url .= "&" . $k . "[{$_k}][{$aux_k}]=" . urlencode($aux[$aux_k]);
                                }
                            } else {
                                $url .= "&" . $_k . "[]=" . urlencode($aux);
                            }
                        }
                    }
                } else {
                    if (is_array($v)) {
                        $v = implode(",", $v);
                    }
                    $url .= "&" . $k . "=" . urlencode($v);
                }
            }
        }
    }
    return str_replace('%2C', ',', $url);
}
Example #3
0
 private function subdomain_params($host)
 {
     $subdomain_type = osc_subdomain_type();
     $subhost = osc_subdomain_host();
     // strpos is used to check if the domain is different, useful when accessing the website by diferent domains
     if ($subdomain_type != '' && $subhost != '' && strpos($host, $subhost) !== false) {
         if (preg_match('|^(www\\.)?(.+)\\.' . $subhost . '$|i', $host, $match)) {
             $subdomain = $match[2];
             if ($subdomain != '' && $subdomain != 'www') {
                 if ($subdomain_type == 'category') {
                     $category = Category::newInstance()->findBySlug($subdomain);
                     if (isset($category['pk_i_id'])) {
                         View::newInstance()->_exportVariableToView('subdomain_name', $category['s_name']);
                         View::newInstance()->_exportVariableToView('subdomain_slug', $category['s_slug']);
                         Params::setParam('sCategory', $category['pk_i_id']);
                         if (Params::getParam('page') == '') {
                             Params::setParam('page', 'search');
                         }
                     } else {
                         $this->do400();
                     }
                 } else {
                     if ($subdomain_type == 'country') {
                         $country = Country::newInstance()->findBySlug($subdomain);
                         if (isset($country['pk_c_code'])) {
                             View::newInstance()->_exportVariableToView('subdomain_name', $country['s_name']);
                             View::newInstance()->_exportVariableToView('subdomain_slug', $country['s_slug']);
                             Params::setParam('sCountry', $country['pk_c_code']);
                         } else {
                             $this->do400();
                         }
                     } else {
                         if ($subdomain_type == 'region') {
                             $region = Region::newInstance()->findBySlug($subdomain);
                             if (isset($region['pk_i_id'])) {
                                 View::newInstance()->_exportVariableToView('subdomain_name', $region['s_name']);
                                 View::newInstance()->_exportVariableToView('subdomain_slug', $region['s_slug']);
                                 Params::setParam('sRegion', $region['pk_i_id']);
                             } else {
                                 $this->do400();
                             }
                         } else {
                             if ($subdomain_type == 'city') {
                                 $city = City::newInstance()->findBySlug($subdomain);
                                 if (isset($city['pk_i_id'])) {
                                     View::newInstance()->_exportVariableToView('subdomain_name', $city['s_name']);
                                     View::newInstance()->_exportVariableToView('subdomain_slug', $city['s_slug']);
                                     Params::setParam('sCity', $city['pk_i_id']);
                                 } else {
                                     $this->do400();
                                 }
                             } else {
                                 if ($subdomain_type == 'user') {
                                     $user = User::newInstance()->findByUsername($subdomain);
                                     if (isset($user['pk_i_id'])) {
                                         View::newInstance()->_exportVariableToView('subdomain_name', $user['s_name']);
                                         View::newInstance()->_exportVariableToView('subdomain_slug', $user['s_username']);
                                         Params::setParam('sUser', $user['pk_i_id']);
                                     } else {
                                         $this->do400();
                                     }
                                 } else {
                                     $this->do400();
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }