本文整理汇总了PHP中Search::newInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Search::newInstance方法的具体用法?PHP Search::newInstance怎么用?PHP Search::newInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Search
的用法示例。
在下文中一共展示了Search::newInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
function __construct()
{
parent::__construct();
$this->mSearch = Search::newInstance();
$this->uri = preg_replace('|^' . REL_WEB_URL . '|', '', $_SERVER['REQUEST_URI']);
$this->nice_url = false;
if (!stripos($_SERVER['REQUEST_URI'], 'search') && osc_rewrite_enabled()) {
$this->nice_url = true;
}
if ($this->nice_url) {
// redirect if it ends with a slash
if (preg_match('|/$|', $this->uri)) {
$redirectURL = osc_base_url() . $this->uri;
$redirectURL = preg_replace('|/$|', '', $redirectURL);
$this->redirectTo($redirectURL);
}
$search_uri = preg_replace('|/[0-9]+$|', '', $this->uri);
$this->_exportVariableToView('search_uri', $search_uri);
// remove seo_url_search_prefix
if (osc_get_preference('seo_url_search_prefix') != '') {
$this->uri = str_replace(osc_get_preference('seo_url_search_prefix') . '/', '', $this->uri);
}
// get page if it's set in the url
$iPage = preg_replace('|.*/([0-9]+)$|', '$01', $this->uri);
if ($iPage > 0) {
Params::setParam('iPage', $iPage);
// redirect without number of pages
if ($iPage == 1) {
$this->redirectTo(osc_base_url() . $search_uri);
}
}
if (Params::getParam('iPage') > 1) {
$this->_exportVariableToView('canonical', osc_base_url() . $search_uri);
}
$params = preg_split('|_|', preg_replace('|.*?/|', '', $search_uri));
if (preg_match('|r([0-9]+)$|', $params[0], $r)) {
$region = Region::newInstance()->findByPrimaryKey($r[1]);
Params::setParam('sRegion', $region['pk_i_id']);
} else {
if (preg_match('|c([0-9]+)$|', $params[0], $c)) {
$city = City::newInstance()->findByPrimaryKey($c[1]);
Params::setParam('sCity', $city['pk_i_id']);
} else {
Params::setParam('sCategory', $search_uri);
}
}
if (count($params) == 2) {
$location = $params[1];
if (preg_match('|r([0-9]+)$|', $location, $r)) {
$region = Region::newInstance()->findByPrimaryKey($r[1]);
Params::setParam('sRegion', $region['pk_i_id']);
}
if (preg_match('|c([0-9]+)$|', $location, $c)) {
$city = City::newInstance()->findByPrimaryKey($c[1]);
Params::setParam('sCity', $city['pk_i_id']);
}
}
}
}
示例2: osc_runAlert
function osc_runAlert($type = null, $last_exec = null)
{
if (!in_array($type, array('HOURLY', 'DAILY', 'WEEKLY', 'INSTANT'))) {
return;
}
if ($last_exec == null) {
$cron = Cron::newInstance()->getCronByType($type);
if (is_array($cron)) {
$last_exec = $cron['d_last_exec'];
} else {
$last_exec = '0000-00-00 00:00:00';
}
}
$internal_name = 'alert_email_hourly';
switch ($type) {
case 'HOURLY':
$internal_name = 'alert_email_hourly';
break;
case 'DAILY':
$internal_name = 'alert_email_daily';
break;
case 'WEEKLY':
$internal_name = 'alert_email_weekly';
break;
case 'INSTANT':
$internal_name = 'alert_email_instant';
break;
}
$active = TRUE;
$searches = Alerts::newInstance()->findByTypeGroup($type, $active);
foreach ($searches as $s_search) {
// Get if there're new ads on this search
$json = $s_search['s_search'];
$array_conditions = (array) json_decode($json);
$new_search = Search::newInstance();
$new_search->setJsonAlert($array_conditions);
$new_search->addConditions(sprintf(" %st_item.dt_pub_date > '%s' ", DB_TABLE_PREFIX, $last_exec));
$items = $new_search->doSearch();
$totalItems = $new_search->count();
if (count($items) > 0) {
// If we have new items from last check
// Catch the user subscribed to this search
$users = Alerts::newInstance()->findUsersBySearchAndType($s_search['s_search'], $type, $active);
if (count($users) > 0) {
$ads = '';
foreach ($items as $item) {
$ads .= '<a href="' . osc_item_url_ns($item['pk_i_id']) . '">' . $item['s_title'] . '</a><br/>';
}
foreach ($users as $user) {
osc_run_hook('hook_' . $internal_name, $user, $ads, $s_search, $items, $totalItems);
AlertsStats::newInstance()->increase(date('Y-m-d'));
}
}
}
}
}
示例3: chosen_region_select
function chosen_region_select()
{
View::newInstance()->_exportVariableToView('list_regions', Search::newInstance()->listRegions('%%%%', '>=', 'region_name ASC'));
if (osc_count_list_regions() > 0) {
echo '<select name="sRegion" data-placeholder="' . __('Select a region...', 'twitter') . '" style="width: 200px;" class="chzn-select"">';
echo '<option></option>';
while (osc_has_list_regions()) {
echo '<option value="' . osc_list_region_name() . '">' . osc_list_region_name() . '</option>';
}
echo '</select>';
}
View::newInstance()->_erase('list_regions');
}
示例4: osc_get_premiums
/**
* Gets new premiums ads
*
* @return array $premiums
*/
function osc_get_premiums($max = 2)
{
if (View::newInstance()->_exists('search')) {
$mSearch = View::newInstance()->_get('search');
} else {
$mSearch = Search::newInstance();
View::newInstance()->_exportVariableToView('search', $mSearch);
}
// juanramon: it should be fixed, little hack to get alerts work in search layout
$mSearch->reconnect();
$premiums = $mSearch->getPremiums($max);
View::newInstance()->_exportVariableToView('premiums', $premiums);
return $premiums;
}
示例5: osc_count_list_cities
/**
* Gets the total number of cities in list_cities
*
* @param string $region
* @return int
*/
function osc_count_list_cities($region = '%%%%')
{
if (!View::newInstance()->_exists('list_cities')) {
View::newInstance()->_exportVariableToView('list_cities', Search::newInstance()->listCities($region));
}
return View::newInstance()->_count('list_cities');
}
示例6: __construct
function __construct()
{
parent::__construct();
$this->mSearch = Search::newInstance();
}
示例7: osc_logged_user_id
<?php
$i_userId = osc_logged_user_id();
if (Params::getParam('delete') != '' && osc_is_web_user_logged_in()) {
delete_item(Params::getParam('delete'), $i_userId);
}
$itemsPerPage = Params::getParam('itemsPerPage') != '' ? Params::getParam('itemsPerPage') : 5;
$iPage = Params::getParam('iPage') != '' ? Params::getParam('iPage') : 0;
Search::newInstance()->addConditions(sprintf("%st_item_watchlist.fk_i_user_id = %d", DB_TABLE_PREFIX, $i_userId));
Search::newInstance()->addConditions(sprintf("%st_item_watchlist.fk_i_item_id = %st_item.pk_i_id", DB_TABLE_PREFIX, DB_TABLE_PREFIX));
Search::newInstance()->addTable(sprintf("%st_item_watchlist", DB_TABLE_PREFIX));
Search::newInstance()->page($iPage, $itemsPerPage);
$aItems = Search::newInstance()->doSearch();
$iTotalItems = Search::newInstance()->count();
$iNumPages = ceil($iTotalItems / $itemsPerPage);
View::newInstance()->_exportVariableToView('items', $aItems);
View::newInstance()->_exportVariableToView('search_total_pages', $iNumPages);
View::newInstance()->_exportVariableToView('search_page', $iPage);
// delete item from watchlist
function delete_item($item, $uid)
{
$conn = getConnection();
$conn->osc_dbExec("DELETE FROM %st_item_watchlist WHERE fk_i_item_id = %d AND fk_i_user_id = %d LIMIT 1", DB_TABLE_PREFIX, $item, $uid);
}
?>
<div class="row">
<?php
osc_current_web_theme_path('user-sidebar.php');
?>
<div class="col-sm-8 col-md-9">
<h1 class="title">
示例8: osc_count_latest_items
/**
* Gets number of latest items
*
* @return int
*/
function osc_count_latest_items($total_latest_items = null, $category = array())
{
if (!View::newInstance()->_exists('latestItems')) {
$search = Search::newInstance();
if (!is_numeric($total_latest_items)) {
$total_latest_items = osc_max_latest_items();
}
View::newInstance()->_exportVariableToView('latestItems', $search->getLatestItems($total_latest_items, $category));
}
return (int) View::newInstance()->_count('latestItems');
}
示例9: doModel
//.........这里部分代码省略.........
} else {
$p_sRegion = explode(",", $p_sRegion);
}
}
$p_sCountry = Params::getParam('sCountry');
if (!is_array($p_sCountry)) {
if ($p_sCountry == '') {
$p_sCountry = array();
} else {
$p_sCountry = explode(",", $p_sCountry);
}
}
$p_sUser = Params::getParam('sUser');
if (!is_array($p_sUser)) {
if ($p_sUser == '') {
$p_sUser = '';
} else {
$p_sUser = explode(",", $p_sUser);
}
}
$p_sLocale = Params::getParam('sLocale');
if (!is_array($p_sLocale)) {
if ($p_sLocale == '') {
$p_sLocale = '';
} else {
$p_sLocale = explode(",", $p_sLocale);
}
}
$p_sPattern = trim(strip_tags(Params::getParam('sPattern')));
// ADD TO THE LIST OF LAST SEARCHES
if (osc_save_latest_searches() && (!Params::existParam('iPage') || Params::getParam('iPage') == 1)) {
$savePattern = osc_apply_filter('save_latest_searches_pattern', $p_sPattern);
if ($savePattern != '') {
LatestSearches::newInstance()->insert(array('s_search' => $savePattern, 'd_date' => date('Y-m-d H:i:s')));
}
}
$p_bPic = Params::getParam('bPic');
$p_bPic = $p_bPic == 1 ? 1 : 0;
$p_bPremium = Params::getParam('bPremium');
$p_bPremium = $p_bPremium == 1 ? 1 : 0;
$p_sPriceMin = Params::getParam('sPriceMin');
$p_sPriceMax = Params::getParam('sPriceMax');
//WE CAN ONLY USE THE FIELDS RETURNED BY Search::getAllowedColumnsForSorting()
$p_sOrder = Params::getParam('sOrder');
if (!in_array($p_sOrder, Search::getAllowedColumnsForSorting())) {
$p_sOrder = osc_default_order_field_at_search();
}
$old_order = $p_sOrder;
//ONLY 0 ( => 'asc' ), 1 ( => 'desc' ) AS ALLOWED VALUES
$p_iOrderType = Params::getParam('iOrderType');
$allowedTypesForSorting = Search::getAllowedTypesForSorting();
$orderType = osc_default_order_type_at_search();
foreach ($allowedTypesForSorting as $k => $v) {
if ($p_iOrderType == $v) {
$orderType = $k;
break;
}
}
$p_iOrderType = $orderType;
$p_sFeed = Params::getParam('sFeed');
$p_iPage = 0;
if (is_numeric(Params::getParam('iPage')) && Params::getParam('iPage') > 0) {
$p_iPage = intval(Params::getParam('iPage')) - 1;
}
if ($p_sFeed != '') {
$p_sPageSize = 1000;
示例10: osclasswizards_popular_cities
function osclasswizards_popular_cities($limit = 20)
{
View::newInstance()->_exportVariableToView('list_cities', Search::newInstance()->listCities('%%%%', '>='));
if (osc_count_list_cities() > 0) {
$array = array();
while (osc_has_list_cities()) {
if (osc_list_city_items() > 0) {
$city_name = osc_list_city_name();
$array[$city_name] = osc_list_city_items();
}
}
arsort($array);
return array_slice($array, 0, $limit);
} else {
return false;
}
}
示例11: doModel
function doModel()
{
switch ($this->action) {
case 'change_email_confirm':
//change email confirm
if (Params::getParam('userId') && Params::getParam('code')) {
$userManager = new User();
$user = $userManager->findByPrimaryKey(Params::getParam('userId'));
if ($user['s_pass_code'] == Params::getParam('code') && $user['b_enabled'] == 1) {
$userEmailTmp = UserEmailTmp::newInstance()->findByPk(Params::getParam('userId'));
$code = osc_genRandomPassword(50);
$userManager->update(array('s_email' => $userEmailTmp['s_new_email']), array('pk_i_id' => $userEmailTmp['fk_i_user_id']));
Item::newInstance()->update(array('s_contact_email' => $userEmailTmp['s_new_email']), array('fk_i_user_id' => $userEmailTmp['fk_i_user_id']));
ItemComment::newInstance()->update(array('s_author_email' => $userEmailTmp['s_new_email']), array('fk_i_user_id' => $userEmailTmp['fk_i_user_id']));
Alerts::newInstance()->update(array('s_email' => $userEmailTmp['s_new_email']), array('fk_i_user_id' => $userEmailTmp['fk_i_user_id']));
Session::newInstance()->_set('userEmail', $userEmailTmp['s_new_email']);
UserEmailTmp::newInstance()->delete(array('s_new_email' => $userEmailTmp['s_new_email']));
osc_add_flash_ok_message(_m('Your email has been changed successfully'));
$this->redirectTo(osc_user_profile_url());
} else {
osc_add_flash_error_message(_m('Sorry, the link is not valid'));
$this->redirectTo(osc_base_url());
}
} else {
osc_add_flash_error_message(_m('Sorry, the link is not valid'));
$this->redirectTo(osc_base_url());
}
break;
case 'activate_alert':
$email = Params::getParam('email');
$secret = Params::getParam('secret');
$result = 0;
if ($email != '' && $secret != '') {
$result = Alerts::newInstance()->activate($email, $secret);
}
if ($result == 1) {
osc_add_flash_ok_message(_m('Alert activated'));
} else {
osc_add_flash_error_message(_m('Oops! There was a problem trying to activate your alert. Please contact an administrator'));
}
$this->redirectTo(osc_base_url());
break;
case 'unsub_alert':
$email = Params::getParam('email');
$secret = Params::getParam('secret');
if ($email != '' && $secret != '') {
Alerts::newInstance()->delete(array('s_email' => $email, 's_secret' => $secret));
osc_add_flash_ok_message(_m('Unsubscribed correctly'));
} else {
osc_add_flash_error_message(_m('Oops! There was a problem trying to unsubscribe you. Please contact an administrator'));
}
$this->redirectTo(osc_base_url());
break;
case 'pub_profile':
$userID = Params::getParam('id');
$user = User::newInstance()->findByPrimaryKey($userID);
// user doesn't exist, show 404 error
if (!$user) {
$this->do404();
return;
}
View::newInstance()->_exportVariableToView('user', $user);
$mSearch = Search::newInstance();
$mSearch->fromUser($userID);
$items = $mSearch->doSearch();
$count = $mSearch->count();
View::newInstance()->_exportVariableToView('items', $items);
View::newInstance()->_exportVariableToView('search_total_items', $count);
$this->doView('user-public-profile.php');
break;
case 'contact_post':
$user = User::newInstance()->findByPrimaryKey(Params::getParam('id'));
View::newInstance()->_exportVariableToView('user', $user);
if (osc_recaptcha_private_key() != '' && Params::existParam("recaptcha_challenge_field")) {
if (!osc_check_recaptcha()) {
osc_add_flash_error_message(_m('The Recaptcha code is wrong'));
Session::newInstance()->_setForm("yourEmail", Params::getParam('yourEmail'));
Session::newInstance()->_setForm("yourName", Params::getParam('yourName'));
Session::newInstance()->_setForm("phoneNumber", Params::getParam('phoneNumber'));
Session::newInstance()->_setForm("message_body", Params::getParam('message'));
$this->redirectTo(osc_user_public_profile_url());
return false;
// BREAK THE PROCESS, THE RECAPTCHA IS WRONG
}
}
osc_run_hook('hook_email_contact_user', Params::getParam('id'), Params::getParam('yourEmail'), Params::getParam('yourName'), Params::getParam('phoneNumber'), Params::getParam('message'));
$this->redirectTo(osc_user_public_profile_url());
break;
default:
$this->redirectTo(osc_user_login_url());
break;
}
}
示例12: osc_runAlert
function osc_runAlert($type = null)
{
if ($type == null) {
return;
}
$internal_name = 'alert_email_hourly';
switch ($type) {
case 'HOURLY':
$internal_name = 'alert_email_hourly';
break;
case 'DAILY':
$internal_name = 'alert_email_daily';
break;
case 'WEEKLY':
$internal_name = 'alert_email_weekly';
break;
case 'INSTANT':
$internal_name = 'alert_email_instant';
break;
}
$searches = Alerts::newInstance()->getAlertsByTypeGroup($type);
foreach ($searches as $s_search) {
$a_search = Search::newInstance();
// Get if there're new ads on this search
$a_search = osc_unserialize(base64_decode($s_search['s_search']));
$crons = Cron::newInstance()->getCronByType($type);
if (isset($crons[0])) {
$last_exec = $crons[0]['d_last_exec'];
} else {
$last_exec = '0000-00-00 00:00:00';
}
$a_search->addConditions(sprintf(" %st_item.dt_pub_date > '%s' ", DB_TABLE_PREFIX, $last_exec));
$totalItems = $a_search->count();
$items = $a_search->doSearch();
if (count($items) > 0) {
//If we have new items from last check
//Catch the user subscribed to this search
$users = Alerts::newInstance()->getUsersBySearchAndType($s_search['s_search'], $type);
if (count($users) > 0) {
$prefLocale = osc_language();
$page = Page::newInstance()->findByInternalName($internal_name);
$page = Page::newInstance()->findByInternalName($internal_name);
$page_description = $page['locale'];
$_title = $page_description[$prefLocale]['s_title'];
$_body = $page_description[$prefLocale]['s_text'];
$ads = "";
foreach ($items as $item) {
$ads .= '<a href="' . osc_item_url_ns($item['pk_i_id']) . '">' . $item['s_title'] . '</a><br/>';
}
foreach ($users as $user) {
if ($user['fk_i_user_id'] != 0) {
$user = User::newInstance()->findByPrimaryKey($user['fk_i_user_id']);
} else {
$user['s_name'] = $user['s_email'];
}
$unsub_link = osc_user_unsubscribe_alert_url($user['s_email'], $s_search['s_search']);
//osc_create_url(array('file' => 'user', 'action' => 'unsub_alert', 'email' => $user['s_email'], 'alert' => $s_search['s_search'])) ;
$unsub_link = '<a href="' . $unsub_link . '">unsubscribe alert</a>';
$words = array();
$words[] = array('{USER_NAME}', '{USER_EMAIL}', '{ADS}', '{UNSUB_LINK}');
$words[] = array($user['s_name'], $user['s_email'], $ads, $unsub_link);
$title = osc_mailBeauty($_title, $words);
$body = osc_mailBeauty($_body, $words);
$params = array('subject' => $title, 'to' => $user['s_email'], 'to_name' => $user['s_name'], 'body' => $body, 'alt_body' => $body);
osc_sendMail($params);
}
}
}
}
}
示例13: osc_count_latest_items
/**
* Gets number of latest items
*
* @return int
*/
function osc_count_latest_items($total_latest_items = null, $options = array())
{
if (!View::newInstance()->_exists('latestItems')) {
$search = Search::newInstance();
if (!is_numeric($total_latest_items)) {
$total_latest_items = osc_max_latest_items();
}
if (is_array($options) && empty($options)) {
$options = osc_get_subdomain_params();
} else {
if ($options == null) {
$options = array();
}
}
View::newInstance()->_exportVariableToView('latestItems', $search->getLatestItems($total_latest_items, $options));
}
return (int) View::newInstance()->_count('latestItems');
}
示例14: osc_query_item
/**
* Perform a search based on custom filters and conditions
* export the results to a variable to be able to manage it
* from custom_items' helpers
*
*
* @param params This could be a string or and array
* Examples:
* Only one keyword
* osc_query_item("keyword=value1,value2,value3,...")
*
* Multiple keywords
* osc_query_item(array(
* 'keyword1' => 'value1,value2',
* 'keyword2' => 'value3,value4'
* ))
*
* Real live examples:
* osc_query_item('category_name=cars,houses');
* osc_query_item(array(
* 'category_name' => 'cars,houses',
* 'city' => 'Madrid'
* ))
*
* Possible keywords:
* author
* country
* country_name
* region
* region_name
* city
* city_name
* city_area
* city_area_name
* category
* category_name
* results_per_page
* page
* offset
*
* Any other keyword will be passed to the hook "custom_query"
* osc_run_hook("custom_query", $keyword, $value);
* A plugin could be created to handle those extra situation
*
* @since 3.0
*/
function osc_query_item($params = null)
{
$mSearch = Search::newInstance();
if ($params == null) {
$params = array();
} else {
if (is_string($params)) {
$keyvalue = explode("=", $params);
$params = array($keyvalue[0] => $keyvalue[1]);
}
}
foreach ($params as $key => $value) {
switch ($key) {
case 'author':
$tmp = explode(",", $value);
foreach ($tmp as $t) {
$mSearch->fromUser($t);
}
break;
case 'category':
case 'category_name':
$tmp = explode(",", $value);
foreach ($tmp as $t) {
$mSearch->addCategory($t);
}
break;
case 'country':
case 'country_name':
$tmp = explode(",", $value);
foreach ($tmp as $t) {
$mSearch->addCountry($t);
}
break;
case 'region':
case 'region_name':
$tmp = explode(",", $value);
foreach ($tmp as $t) {
$mSearch->addRegion($t);
}
break;
case 'city':
case 'city_name':
$tmp = explode(",", $value);
foreach ($tmp as $t) {
$mSearch->addCity($t);
}
break;
case 'city_area':
case 'city_area_name':
$tmp = explode(",", $value);
foreach ($tmp as $t) {
$mSearch->addCityArea($t);
}
case 'results_per_page':
//.........这里部分代码省略.........
示例15: osc_contact_url
<?php
}
?>
<li><a href="<?php
echo osc_contact_url();
?>
"><?php
_e('Contact', 'twitter');
?>
</a></li>
</ul>
</div>
</div>
<?php
if (!View::newInstance()->_exists('list_contries')) {
View::newInstance()->_exportVariableToView('list_regions', Search::newInstance()->listRegions('%%%%', '>=', 'region_name ASC'));
}
if (osc_count_list_regions()) {
?>
<div class="row">
<div class="span4 columns">
<h3><?php
_e('Regions', 'twitter');
?>
</h3>
<ul class="unstyled">
<?php
while (osc_has_list_regions()) {
?>
<li>
<a href="<?php