当前位置: 首页>>代码示例>>PHP>>正文


PHP waModel::escape方法代码示例

本文整理汇总了PHP中waModel::escape方法的典型用法代码示例。如果您正苦于以下问题:PHP waModel::escape方法的具体用法?PHP waModel::escape怎么用?PHP waModel::escape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在waModel的用法示例。


在下文中一共展示了waModel::escape方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: escape

 /**
  * Escapes special characters in a string for use in an SQL statement
  *
  * @param string
  * @return string
  */
 public function escape($value)
 {
     if (is_float($value)) {
         return str_replace(',', '.', (double) $value);
     }
     return $this->model->escape($value);
 }
开发者ID:nowaym,项目名称:webasyst-framework,代码行数:13,代码来源:waDbStatement.class.php

示例2: getSql

 protected function getSql()
 {
     $model = new waModel();
     $where = array();
     if ($discountcard = waRequest::get('discountcard')) {
         $where[] = "discountcard LIKE '" . $model->escape($discountcard) . "'";
     }
     $sql = "FROM `shop_discountcards`" . ($where ? " WHERE " . implode(" AND ", $where) : "") . " ORDER BY `id` DESC";
     return $sql;
 }
开发者ID:klxqz,项目名称:discountcards,代码行数:10,代码来源:shopDiscountcardsPluginBackendList.action.php

示例3: getTables

 protected function getTables($prefix)
 {
     // @todo: use db adapter to get tables
     $tables = array();
     $prefix = $this->model->escape($prefix, 'l');
     $sql = "SHOW TABLES LIKE '{$prefix}'";
     $tables = array_merge($tables, $this->model->query($sql)->fetchAll(null, true));
     $sql = "SHOW TABLES LIKE '{$prefix}\\_%'";
     $tables = array_merge($tables, $this->model->query($sql)->fetchAll(null, true));
     return $tables;
 }
开发者ID:cjmaximal,项目名称:webasyst-framework,代码行数:11,代码来源:webasystGenerateDb.cli.php

示例4: execute

 public function execute()
 {
     $term = waRequest::request('term');
     $limit = waRequest::request('limit', 30, 'int');
     if (mb_strlen($term) < 2) {
         return;
     }
     $type = waRequest::request('type', null, waRequest::TYPE_STRING_TRIM);
     $model = new waModel();
     if (strpos($term, '@') !== FALSE) {
         $contacts = new contactsCollection('/search/email*=' . $term);
     } else {
         $contacts = new contactsCollection();
         $t_a = preg_split("/\\s+/", $term);
         $cond = array();
         foreach ($t_a as $t) {
             $t = trim($t);
             if ($t) {
                 $t = $model->escape($t, 'like');
                 if ($type === 'person') {
                     $cond[] = "(c.firstname LIKE '{$t}%' OR c.middlename LIKE '{$t}%' OR c.lastname LIKE '{$t}%')";
                 } else {
                     if ($type === 'company') {
                         $cond[] = "c.name LIKE '{$t}%'";
                     } else {
                         $cond[] = "(c.firstname LIKE '{$t}%' OR c.middlename LIKE '{$t}%' OR c.lastname LIKE '{$t}%' OR c.name LIKE '{$t}%')";
                     }
                 }
             }
         }
         if ($cond) {
             $contacts->addWhere(implode(" AND ", $cond));
         }
     }
     if ($type) {
         if ($type === 'person') {
             $contacts->addWhere("is_company = 0");
         } else {
             if ($type === 'company') {
                 $contacts->addWhere("is_company = 1");
             }
         }
     }
     $this->response = array();
     $term_safe = htmlspecialchars($term);
     foreach ($contacts->getContacts('id,name,company,email', 0, $limit) as $c) {
         $name = $this->prepare($c['name'], $term_safe);
         $email = $this->prepare(ifset($c['email'][0], ''), $term_safe);
         $company = $this->prepare($c['company'], $term_safe);
         $this->response[] = array('label' => implode(', ', array_filter(array($name, $company, $email))), 'value' => $c['id'], 'name' => $c['name'], 'email' => ifset($c['email'][0], ''), 'company' => $c['company']);
     }
 }
开发者ID:Lazary,项目名称:webasyst,代码行数:52,代码来源:contactsBackendAutocomplete.controller.php

示例5: getSql

 protected function getSql()
 {
     $model = new waModel();
     $where = array();
     if ($discountcard = waRequest::get('discountcard')) {
         $where[] = "`discountcard` LIKE '" . $model->escape($discountcard) . "'";
     }
     if ($order_id = waRequest::get('order_id')) {
         $order_id = $this->decodeOrderId($order_id);
         $where[] = "`order_id` = '" . $order_id . "'";
     }
     $sql = "FROM `shop_discountcards_order`" . ($where ? " WHERE " . implode(" AND ", $where) : "") . " ORDER BY `order_id` DESC";
     return $sql;
 }
开发者ID:klxqz,项目名称:discountcards,代码行数:14,代码来源:shopDiscountcardsPluginBackendOrders.action.php

示例6: getUserCategoryId

 public static function getUserCategoryId($contact_id = null)
 {
     if ($contact_id === null) {
         $contact_id = wa()->getUser()->getId();
     }
     $model = new waModel();
     $sql = "SELECT * FROM `wa_contact_categories` WHERE `contact_id` = '" . $model->escape($contact_id) . "'";
     $categories = $model->query($sql)->fetchAll();
     $category_ids = array();
     $category_ids[] = 0;
     foreach ($categories as $category) {
         $category_ids[] = $category['category_id'];
     }
     return $category_ids;
 }
开发者ID:klxqz,项目名称:price,代码行数:15,代码来源:shopPrice.plugin.php

示例7: execute

 public function execute()
 {
     if (file_exists($this->getConfig()->getPath('config', 'db'))) {
         $this->redirect($this->getConfig()->getBackendUrl(true));
     }
     if ($config = waRequest::post()) {
         $database = $config['database'];
         $error = false;
         try {
             $config['database'] = null;
             $model = new waModel($config);
         } catch (waDbException $e) {
             $error = _w('Failed to connect to specified MySQL database server.');
         }
         $config['database'] = $database;
         if (!$error) {
             if (!$model->database($database)) {
                 try {
                     // try create database
                     $sql = "CREATE DATABASE " . $model->escape($database);
                     $model->exec($sql);
                 } catch (waDbException $e) {
                     $error = sprintf(_w('Failed to connect to the “%s” database.'), $database);
                 }
             }
         }
         if (!$error) {
             // try save config
             $file = $this->getConfig()->getPath('config');
             if (!is_writable($file)) {
                 $error = sprintf(_w("Not enough access permissions to write in the folder %s"), $file);
             } else {
                 $data = array('default' => $config);
                 if (!waUtils::varExportToFile($data, $file . '/db.php')) {
                     $error = sprintf(_w("Error creating file %s"), $file . '/routing.php');
                 } else {
                     // check routing.php
                     if (!file_exists($file . '/routing.php')) {
                         $apps = wa()->getApps();
                         $data = array();
                         $domain = $this->getConfig()->getDomain();
                         $site = false;
                         foreach ($apps as $app_id => $app) {
                             if ($app_id == 'site') {
                                 $site = true;
                             } elseif (!empty($app['frontend'])) {
                                 $data[$domain][] = array('url' => $app_id . '/', 'app' => $app_id);
                             }
                         }
                         if ($site) {
                             $data[$domain][] = array('url' => '*', 'app' => 'site');
                         }
                         waUtils::varExportToFile($data, $file . '/routing.php');
                     }
                     // redirect to backend
                     $this->redirect($this->getConfig()->getBackendUrl(true));
                 }
             }
         }
         if ($error) {
             $this->view->assign('error', $error);
         }
     }
 }
开发者ID:Lazary,项目名称:webasyst,代码行数:64,代码来源:webasystLoginConfig.action.php

示例8: genUniqueUrl

 /**
  * @param $url
  * @param waModel $context
  * @param int $length
  * @param string $field
  * @return string
  */
 public static function genUniqueUrl($url, $context, &$counter = 0, $length = 512, $field = 'url')
 {
     $counter = 0;
     $url = preg_replace('/\\s+/', '-', $url);
     $url = shopHelper::transliterate($url);
     if (strlen($url) == 0) {
         $url = (time() << 24) + $counter++;
     } else {
         $url = mb_substr($url, 0, $length);
     }
     $url = mb_strtolower($url);
     $pattern = mb_substr($context->escape($url, 'like'), 0, $length - 3) . '%';
     $sql = "SELECT `{$field}` FROM {$context->getTableName()} WHERE url LIKE '{$pattern}' ORDER BY LENGTH(`{$field}`)";
     $alike = $context->query($sql)->fetchAll('url');
     if (is_array($alike) && isset($alike[$url])) {
         $last = array_shift($alike);
         $counter = 1;
         do {
             $modifier = "-{$counter}";
             $_length = mb_strlen($modifier);
             $url = mb_substr($last['url'], 0, $length - $_length) . $modifier;
         } while (isset($alike[$url]) && ++$counter < 100);
         if (isset($alike[$url])) {
             $short_uuid = (time() << 24) + $counter++;
             $_length = mb_strlen($short_uuid);
             $url = mb_substr($last['url'], 0, $length - $_length) . $short_uuid;
         }
     }
     return mb_strtolower($url);
 }
开发者ID:Lazary,项目名称:webasyst,代码行数:37,代码来源:shopHelper.class.php

示例9: contactsAutocomplete

 public function contactsAutocomplete($q, $limit = null)
 {
     $m = new waModel();
     // The plan is: try queries one by one (starting with fast ones),
     // until we find 5 rows total.
     $sqls = array();
     // Name starts with requested string
     $sqls[] = "SELECT c.id, c.name\n                   FROM wa_contact AS c\n                   WHERE c.name LIKE '" . $m->escape($q, 'like') . "%'\n                   LIMIT {LIMIT}";
     // Email starts with requested string
     $sqls[] = "SELECT c.id, c.name, e.email\n                   FROM wa_contact AS c\n                       JOIN wa_contact_emails AS e\n                           ON e.contact_id=c.id\n                   WHERE e.email LIKE '" . $m->escape($q, 'like') . "%'\n                   LIMIT {LIMIT}";
     // Phone contains requested string
     if (preg_match('~^[wp0-9\\-\\+\\#\\*\\(\\)\\. ]+$~', $q)) {
         $dq = preg_replace("/[^\\d]+/", '', $q);
         $sqls[] = "SELECT c.id, c.name, d.value as phone\n                       FROM wa_contact AS c\n                           JOIN wa_contact_data AS d\n                               ON d.contact_id=c.id AND d.field='phone'\n                       WHERE d.value LIKE '%" . $m->escape($dq, 'like') . "%'\n                       LIMIT {LIMIT}";
     }
     // Name contains requested string
     $sqls[] = "SELECT c.id, c.name\n                   FROM wa_contact AS c\n                   WHERE c.name LIKE '_%" . $m->escape($q, 'like') . "%'\n                   LIMIT {LIMIT}";
     // Email contains requested string
     $sqls[] = "SELECT c.id, c.name, e.email\n                   FROM wa_contact AS c\n                       JOIN wa_contact_emails AS e\n                           ON e.contact_id=c.id\n                   WHERE e.email LIKE '_%" . $m->escape($q, 'like') . "%'\n                   LIMIT {LIMIT}";
     $limit = $limit !== null ? $limit : 5;
     $result = array();
     $term_safe = htmlspecialchars($q);
     foreach ($sqls as $sql) {
         if (count($result) >= $limit) {
             break;
         }
         foreach ($m->query(str_replace('{LIMIT}', $limit, $sql)) as $c) {
             if (empty($result[$c['id']])) {
                 $name = $this->prepare($c['name'], $term_safe);
                 $email = $this->prepare(ifset($c['email'], ''), $term_safe);
                 $phone = $this->prepare(ifset($c['phone'], ''), $term_safe);
                 $phone && ($phone = '<i class="icon16 phone"></i>' . $phone);
                 $email && ($email = '<i class="icon16 email"></i>' . $email);
                 $result[$c['id']] = array('id' => $c['id'], 'value' => $c['id'], 'name' => $c['name'], 'label' => implode(' ', array_filter(array($name, $email, $phone))));
                 if (count($result) >= $limit) {
                     break 2;
                 }
             }
         }
     }
     foreach ($result as &$c) {
         $contact = new waContact($c['id']);
         $c['label'] = "<i class='icon16 userpic20' style='background-image: url(\"" . $contact->getPhoto(20) . "\");'></i>" . $c['label'];
     }
     unset($c);
     return array_values($result);
 }
开发者ID:Lazary,项目名称:webasyst,代码行数:47,代码来源:shopBackendAutocomplete.controller.php

示例10: waModel

<?php

$model = new waModel();
// remove characters +-()
$model->exec("UPDATE wa_contact_data SET value = REPLACE(value, '+', '') WHERE field = 'phone' AND value LIKE '%+%'");
$model->exec("UPDATE wa_contact_data SET value = REPLACE(value, '-', '') WHERE field = 'phone' AND value LIKE '%-%'");
$model->exec("UPDATE wa_contact_data SET value = REPLACE(value, '(', '') WHERE field = 'phone' AND value LIKE '%(%'");
$model->exec("UPDATE wa_contact_data SET value = REPLACE(value, ')', '') WHERE field = 'phone' AND value LIKE '%)%'");
// remove spaces between digits
$rows = $model->query("SELECT id, value FROM wa_contact_data WHERE field='phone' AND value LIKE '% %'");
foreach ($rows as $row) {
    $sql = "UPDATE wa_contact_data SET value = '" . $model->escape(preg_replace('/(\\d)\\s+(\\d)/i', '$1$2', trim($row['value']))) . "' WHERE id = " . (int) $row['id'];
    $model->exec($sql);
}
开发者ID:Lazary,项目名称:webasyst,代码行数:14,代码来源:1385444995.php

示例11: search

 public function search($query)
 {
     $model = new waModel();
     return array('where' => array("p.name LIKE '" . $model->escape($query, 'like') . "'"));
 }
开发者ID:Lazary,项目名称:webasyst,代码行数:5,代码来源:shopSearch.class.php


注:本文中的waModel::escape方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。