EscapeString() public method

public EscapeString ( $string )
示例#1
0
 /**
  *
  * @param string $query
  * @return array of integers - taskIds
  */
 public static function searchTasks($query)
 {
     $fieldWeights = array('description' => 10, 'note' => 6);
     $indexName = 'plancake_tasks';
     $client = new SphinxClient();
     // $client->SetServer (sfConfig::get('app_sphinx_host'), sfConfig::get('app_sphinx_port'));
     $client->SetFilter("author_id", array(PcUserPeer::getLoggedInUser()->getId()));
     $client->SetConnectTimeout(1);
     $client->SetMatchMode(SPH_MATCH_ANY);
     $client->SetSortMode(SPH_SORT_RELEVANCE);
     $client->SetRankingMode(SPH_RANK_PROXIMITY_BM25);
     $client->SetArrayResult(true);
     $client->SetFieldWeights($fieldWeights);
     $client->setLimits(0, 100);
     $results = $client->query($client->EscapeString($query), $indexName);
     if ($results === false) {
         $error = "Sphinx Error - " . $client->GetLastError();
         sfErrorNotifier::alert($error);
     }
     $ids = array();
     if (isset($results['matches']) && count($results['matches'])) {
         foreach ($results['matches'] as $match) {
             $ids[] = $match['id'];
         }
     }
     return PcTaskPeer::retrieveByPKs($ids);
 }
 public function escape($string)
 {
     return $this->sphinxClient->EscapeString((string) $string);
 }
示例#3
0
 public function index()
 {
     // Init variables
     $data = array();
     $breadcrumbs = array();
     $filter_data = array('order' => 'DESC');
     $title = tt('Products');
     $meta_title = '';
     $breadcrumbs[] = array('name' => tt('Home'), 'href' => $this->url->link('common/home'), 'active' => false);
     $breadcrumbs[] = array('name' => tt('Search'), 'href' => $this->url->link('catalog/search'), 'active' => true);
     // Filter by user
     if (isset($this->request->get['user_id']) && ($user_info = $this->model_account_user->getUser((int) $this->request->get['user_id']))) {
         $title .= sprintf(' ' . tt('by %s'), $user_info->username);
         $meta_title .= sprintf(' ' . tt('by %s'), $user_info->username);
         $filter_data['user_id'] = (int) $this->request->get['user_id'];
     }
     // Filter by search term
     if (isset($this->request->get['q']) && !empty($this->request->get['q']) && ValidatorProduct::titleValid($this->request->get['q'])) {
         $title .= sprintf(' ' . tt('containing %s'), ucfirst($this->request->get['q']));
         $meta_title .= sprintf(' ' . tt('Buy %s Thematic with Bitcoin | %s Thematic Store'), ucfirst($this->request->get['q']), ucfirst($this->request->get['q']));
         // Sphinx search begin
         $sphinx = new SphinxClient();
         $search = $sphinx->EscapeString($this->request->get['q']);
         $result = $sphinx->Query("({$search} | *{$search})*");
         // If something found
         if ($result !== false && !empty($result['matches'])) {
             foreach ($result['matches'] as $product_id => $info) {
                 $filter_data['filter_product_ids'][] = (int) $product_id;
             }
             // If products not found
         } else {
             $filter_data['filter_product_ids'][] = 0;
         }
     }
     // Filter by favorites
     if (isset($this->request->get['favorites'])) {
         $title .= ' ' . tt('favorites');
         $meta_title .= $title;
         $filter_data['favorites'] = true;
     }
     // Filter by purchased
     if (isset($this->request->get['purchased'])) {
         $title .= ' ' . tt('purchased');
         $meta_title .= $title;
         $filter_data['purchased'] = true;
     }
     // Load products
     $data['products'] = array();
     $products_total = 0;
     foreach ($this->model_catalog_product->getProducts($filter_data, $this->language->getId(), $this->auth->getId(), ORDER_APPROVED_STATUS_ID) as $product_info) {
         $products_total++;
         // Prepare special counter
         if ($product_info->special_date_end) {
             $special_left_seconds = strtotime($product_info->special_date_end) - time();
             $special_left_minutes = floor($special_left_seconds / 60);
             $special_left_hours = floor($special_left_minutes / 60);
             $special_left_days = floor($special_left_hours / 24);
             if ($special_left_minutes < 60) {
                 $special_expires = sprintf(tt('%s %s left'), $special_left_minutes, plural($special_left_minutes, array(tt('minute'), tt('minutes'), tt('minutes '))));
             } else {
                 if ($special_left_hours < 24) {
                     $special_expires = sprintf(tt('%s %s left'), $special_left_hours, plural($special_left_hours, array(tt('hour'), tt('hours'), tt('hours '))));
                 } else {
                     $special_expires = sprintf(tt('%s %s left'), $special_left_days, plural($special_left_days, array(tt('day'), tt('days'), tt('days '))));
                 }
             }
         } else {
             $special_expires = false;
         }
         switch ($product_info->order_status_id) {
             case ORDER_APPROVED_STATUS_ID:
                 $product_order_status = 'approved';
                 break;
             case ORDER_PROCESSED_STATUS_ID:
                 $product_order_status = 'processed';
                 break;
             default:
                 $product_order_status = $product_info->user_id == $this->auth->getId() ? 'approved' : false;
         }
         // Generate products
         $data['products'][] = array('product_order_status' => $product_order_status, 'favorite' => $product_info->favorite, 'demo' => $product_info->main_product_demo_id ? true : false, 'product_id' => $product_info->product_id, 'title' => $product_info->title, 'favorites' => $product_info->favorites ? $product_info->favorites : false, 'status' => $product_info->status, 'src' => $this->cache->image($product_info->main_product_image_id, $product_info->user_id, 144, 144), 'href_view' => $this->url->link('catalog/product', 'product_id=' . $product_info->product_id), 'href_download' => $this->url->link('catalog/product/download', 'product_id=' . $product_info->product_id), 'href_demo' => $this->url->link('catalog/product/demo', 'product_demo_id=' . $product_info->main_product_demo_id), 'special_expires' => $special_expires, 'special_regular_price' => $product_info->special_regular_price > 0 ? $this->currency->format($product_info->special_regular_price, $product_info->currency_id) : 0, 'special_exclusive_price' => $product_info->special_exclusive_price > 0 ? $this->currency->format($product_info->special_exclusive_price, $product_info->currency_id) : 0, 'regular_price' => $this->currency->format($product_info->regular_price, $product_info->currency_id), 'exclusive_price' => $this->currency->format($product_info->exclusive_price, $product_info->currency_id), 'has_regular_price' => $product_info->regular_price > 0 ? true : false, 'has_exclusive_price' => $product_info->exclusive_price > 0 ? true : false, 'has_special_regular_price' => $product_info->special_regular_price > 0 ? true : false, 'has_special_exclusive_price' => $product_info->special_exclusive_price > 0 ? true : false);
     }
     // Log search request
     if (isset($this->request->get['q']) && !empty($this->request->get['q']) && ValidatorProduct::titleValid($this->request->get['q'])) {
         $this->model_common_log->createLogSearch($this->auth->getId(), $this->request->get['q'], $products_total);
     }
     // Load layout
     $this->document->setTitle($meta_title);
     $data['title'] = $title;
     $data['footer'] = $this->load->controller('common/footer');
     $data['header'] = $this->load->controller('common/header');
     $data['module_breadcrumbs'] = $this->load->controller('module/breadcrumbs', $breadcrumbs);
     $data['module_search'] = $this->load->controller('module/search');
     $data['user_is_logged'] = $this->auth->isLogged();
     // Renter the template
     $this->response->setOutput($this->load->view('catalog/list.tpl', $data));
 }
示例#4
0
 /**
  * Clean up a search word/phrase/term for Sphinx.
  *
  * @param string $sphinx_term
  * @param SphinxClient $sphinx_client
  */
 private function _cleanWordSphinx($sphinx_term, $sphinx_client)
 {
     // Multiple quotation marks in a row can cause fatal errors, so handle them
     $sphinx_term = preg_replace('/""+/', '"', $sphinx_term);
     // Unmatched (i.e. odd number of) quotation marks also cause fatal errors, so handle them
     if (substr_count($sphinx_term, '"') % 2) {
         // Using preg_replace since it supports limiting the number of replacements
         $sphinx_term = preg_replace('/"/', '', $sphinx_term, 1);
     }
     // Use the Sphinx API's built-in EscapeString function to escape special characters
     $sphinx_term = $sphinx_client->EscapeString($sphinx_term);
     // Since it escapes quotation marks and we don't want that, unescape them
     $sphinx_term = str_replace('\\"', '"', $sphinx_term);
     return $sphinx_term;
 }
 /**
  * @{inheritDoc}
  */
 public function clean_string($string)
 {
     return $this->client->EscapeString($string);
 }
示例#6
0
 /**
  * 转义特殊字符
  *
  * @param string $string The string to be escaped.
  *
  * @return string The escaped string.
  */
 function escapeString($string)
 {
     return $this->sphinx->EscapeString($string);
 }
$category_id = $simpla->request->get('category', 'integer');
$limit_get = $simpla->request->get('limit', 'integer');
if (!empty($limit_get)) {
    $limit = $limit_get;
}
$q = $keyword . '*';
$Sphinx = new SphinxClient();
$Sphinx->SetServer('127.0.0.1', 9312);
$Sphinx->SetConnectTimeout(1);
$Sphinx->SetArrayResult(true);
$Sphinx->SetSortMode(SPH_SORT_EXTENDED, 'rank ASC, date_created DESC');
$Sphinx->SetLimits(0, $limit);
$ids = array();
$total = 0;
$indexName = 'moda_product';
$q = $Sphinx->EscapeString($q);
$search = $Sphinx->Query($q, $indexName);
$count = $search['total'];
if ($search !== FALSE) {
    if (!empty($search['matches'])) {
        foreach ($search['matches'] as $match) {
            $ids[] = (int) $match['id'];
        }
        $total = $search['total'];
    }
}
$category_id_filter = '';
$group_by = '';
if ($category_id > 0) {
    $category = $simpla->categories->get_category($category_id);
    $category_ids = !empty($category->children) ? $category->children : array();