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


PHP DbHelper::escapeParam方法代码示例

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


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

示例1: literalFilter

 /**
  * Escapes commas and asterisks in a string so they are not treated as special characters in
  * {@link DbHelper::parseParam()}.
  *
  * @param string $value The param value.
  *
  * @return string The escaped param value.
  */
 public function literalFilter($value)
 {
     return DbHelper::escapeParam($value);
 }
开发者ID:vescoyez,项目名称:portfolio_v2,代码行数:12,代码来源:CraftTwigExtension.php

示例2: prepTags

 public function prepTags($data, $field)
 {
     $fieldData = array();
     if (!empty($data)) {
         $settings = $field->getFieldType()->getSettings();
         // Get tag group id
         $source = $settings->getAttribute('source');
         list($type, $groupId) = explode(':', $source);
         $tags = ArrayHelper::stringToArray($data);
         foreach ($tags as $tag) {
             $tagArray = array();
             if (!empty($tag)) {
                 // Find existing tag
                 $criteria = craft()->elements->getCriteria(ElementType::Tag);
                 $criteria->title = DbHelper::escapeParam($tag);
                 $criteria->limit = 1;
                 $criteria->groupId = $groupId;
                 if (!$criteria->total()) {
                     // Create tag if one doesn't already exist
                     $newtag = new TagModel();
                     $newtag->getContent()->title = $tag;
                     $newtag->groupId = $groupId;
                     // Save tag
                     if (craft()->tags->saveTag($newtag)) {
                         $tagArray = array($newtag->id);
                     }
                 } else {
                     $tagArray = $criteria->ids();
                 }
             }
             // Add tags to data array
             $fieldData = array_merge($fieldData, $tagArray);
         }
     }
     return $fieldData;
 }
开发者ID:Tcheu,项目名称:FeedMe,代码行数:36,代码来源:FeedMe_FieldsService.php

示例3: importSingleNode

 public function importSingleNode($node, $feed, $settings)
 {
     $canSaveEntry = true;
     $existingEntry = false;
     $fieldData = array();
     $entry = array();
     $fields = $settings['fields'];
     //
     // Lets get started!
     //
     $criteria = craft()->feedMe_entry->setCriteria($feed);
     // Start looping through all the mapped fields - grab their data from the feed node
     foreach ($fields as $itemNode => $handle) {
         // Fetch the value for the field from the feed node. Deep-search.
         $data = craft()->feedMe_feed->getValueForNode($itemNode, $node);
         // While we're in the loop, lets check for unique data to match existing entries on.
         if (isset($feed['fieldUnique'][$itemNode]) && intval($feed['fieldUnique'][$itemNode]) == 1 && !empty($data)) {
             $criteria->{$handle} = DbHelper::escapeParam($data);
         }
         //
         // Each field needs special processing, sort that out here
         //
         try {
             // Grab the field's content - formatted specifically for it
             $content = craft()->feedMe_fields->prepForFieldType($data, $handle);
             // The first key of $content will always be the field handle - grab that to create our field data.
             $contentKeys = array_keys($content);
             $fieldHandle = $contentKeys[0];
             // Then, we check if we've already got any partial content for the field. Most commongly, this is
             // the case for Matrix and Table fields, but also likely other Third-Party fields. So its important to
             // combine values, rather than overwriting or omitting as each feed node contains just part of the data.
             if (array_key_exists($fieldHandle, $fieldData) && is_array($fieldData[$fieldHandle])) {
                 $fieldData[$fieldHandle] = array_replace_recursive($fieldData[$fieldHandle], $content[$fieldHandle]);
             } else {
                 $fieldData[$fieldHandle] = $content[$fieldHandle];
             }
         } catch (\Exception $e) {
             FeedMePlugin::log($feed->name . ': FeedMeError: ' . $e->getMessage() . '.', LogLevel::Error, true);
             return array('result' => false);
         }
     }
     $existingEntry = $criteria->first();
     //
     // Check for Add/Update/Delete for existing entries
     //
     // If there's an existing matching entry
     if ($existingEntry && $feed['duplicateHandle']) {
         // If we're deleting
         if ($feed['duplicateHandle'] == FeedMe_Duplicate::Delete) {
             // Fill new EntryModel with match
             $entry = $existingEntry;
         }
         // If we're updating
         if ($feed['duplicateHandle'] == FeedMe_Duplicate::Update) {
             // Fill new EntryModel with match
             $entry = $existingEntry;
         }
         // If we're adding, make sure not to overwrite existing entry
         if ($feed['duplicateHandle'] == FeedMe_Duplicate::Add) {
             $canSaveEntry = false;
         }
     } else {
         // Prepare a new EntryModel (for this section and entrytype)
         $entry = craft()->feedMe_entry->setModel($feed);
     }
     //
     //
     //
     if ($canSaveEntry && $entry) {
         // Any post-processing on our nice collection of entry-ready data.
         craft()->feedMe_fields->postForFieldType($fieldData, $entry);
         // Prepare Element model (the default stuff)
         $entry = craft()->feedMe_entry->prepForElementModel($fieldData, $entry);
         // Set our data for this EntryModel (our mapped data)
         if (!$feed['locale']) {
             $entry->setContentFromPost($fieldData);
         }
         //echo '<pre>';
         //print_r($fieldData);
         //echo '</pre>';
         // Set enabled based on feed settings
         $entry->enabled = (bool) $feed->status;
         try {
             // Save the entry!
             if (!craft()->entries->saveEntry($entry)) {
                 FeedMePlugin::log($feed->name . ': ' . json_encode($entry->getErrors()), LogLevel::Error, true);
                 return array('result' => false);
             } else {
                 // If we're importing into a specific locale, we need to create this entry if it doesn't already exist
                 // completely blank of custom field content. After thats saved, we then re-fetch the entry for the specific
                 // locale and then add our field data. Doing this ensures its not copied across all locales.
                 if ($feed['locale']) {
                     $entryLocale = craft()->entries->getEntryById($entry->id, $feed['locale']);
                     $entryLocale->setContentFromPost($fieldData);
                     if (!craft()->entries->saveEntry($entryLocale)) {
                         FeedMePlugin::log($feed->name . ': ' . json_encode($entryLocale->getErrors()), LogLevel::Error, true);
                         return array('result' => false);
                     } else {
                         // Successfully saved/added entry
                         if ($feed['duplicateHandle'] == FeedMe_Duplicate::Update) {
//.........这里部分代码省略.........
开发者ID:Tcheu,项目名称:FeedMe,代码行数:101,代码来源:FeedMeService.php

示例4: actionSearchForElements

 /**
  * Fork of tags/searchForTags adjusted to cope with any element
  */
 public function actionSearchForElements()
 {
     $this->requirePostRequest();
     $this->requireAjaxRequest();
     $search = craft()->request->getPost('search');
     $excludeIds = craft()->request->getPost('excludeIds', array());
     // Get the post data
     $elementType = craft()->request->getPost('elementType');
     $sources = craft()->request->getPost('sources');
     // Deal with Entries
     if ($elementType == ElementType::Entry) {
         // Start the criteria
         $criteria = craft()->elements->getCriteria(ElementType::Entry);
         // Fangle the sections out of the sources
         $sections = array();
         if (is_array($sources)) {
             foreach ($sources as $source) {
                 switch ($source) {
                     case 'singles':
                         $sections = array_merge($sections, craft()->sections->getSectionsByType(SectionType::Single));
                         break;
                     default:
                         if (preg_match('/^section:(\\d+)$/', $source, $matches)) {
                             $section = craft()->sections->getSectionById($matches[1]);
                             if ($section) {
                                 $sections = array_merge($sections, array($section));
                             }
                         }
                 }
             }
         }
         $criteria->section = $sections;
     } else {
         if ($elementType == ElementType::Category) {
             // Start the criteria
             $criteria = craft()->elements->getCriteria(ElementType::Category);
         }
     }
     // Add and exclude ids
     $notIds = array('and');
     foreach ($excludeIds as $id) {
         $notIds[] = 'not ' . $id;
     }
     // Set the rest of the criteria
     $criteria->title = '*' . DbHelper::escapeParam($search) . '*';
     $criteria->id = $notIds;
     $criteria->status = null;
     $criteria->limit = 20;
     $elements = $criteria->find();
     $return = array();
     $exactMatches = array();
     $exactMatch = false;
     $normalizedSearch = StringHelper::normalizeKeywords($search);
     foreach ($elements as $element) {
         if ($elementType == ElementType::Entry) {
             if (!is_array($sources)) {
                 $sourceKey = "*";
             } else {
                 if ($element->section->type == SectionType::Single) {
                     $sourceKey = "singles";
                 } else {
                     $sourceKey = "section:" . $element->section->id;
                 }
             }
             $return[$sourceKey][] = array('id' => $element->id, 'title' => $element->getContent()->title, 'status' => $element->status, 'sourceName' => $element->section->name);
         } else {
             if ($elementType == ElementType::Category) {
                 $sourceKey = "group:" . $element->group->id;
                 $return[$sourceKey][] = array('id' => $element->id, 'title' => $element->getContent()->title, 'status' => $element->status, 'sourceName' => $element->group->name);
             }
         }
         $normalizedTitle = StringHelper::normalizeKeywords($element->getContent()->title);
         if ($normalizedTitle == $normalizedSearch) {
             $exactMatches[] = 1;
             $exactMatch = true;
         } else {
             $exactMatches[] = 0;
         }
     }
     // NOTE: We’ve lost the sorting by exact match
     // array_multisort($exactMatches, SORT_DESC, $return);
     $this->returnJson(array('elements' => $return, 'exactMatch' => $exactMatch));
 }
开发者ID:supercool,项目名称:Tools,代码行数:86,代码来源:SupercoolToolsController.php

示例5: importSingleNode

 public function importSingleNode($node, $feed, $settings)
 {
     $canSaveEntry = true;
     $existingEntry = false;
     $fieldData = array();
     $entry = array();
     $fields = $settings['fields'];
     //
     // Lets get started!
     //
     $criteria = craft()->feedMe_entry->setCriteria($feed);
     // Start looping through all the mapped fields - grab their data from the feed node
     foreach ($fields as $itemNode => &$destination) {
         // Fetch the value for the field from the feed node. Deep-search.
         $data = craft()->feedMe_feed->getValueForNode($itemNode, $node);
         // While we're in the loop, lets check for unique data to match existing entries on.
         if (isset($feed['fieldUnique'][$itemNode]) && intval($feed['fieldUnique'][$itemNode]) == 1 && !empty($data)) {
             $criteria->{$destination} = DbHelper::escapeParam($data);
         }
         //
         // Each field needs special processing, sort that out here
         //
         try {
             // The field handle needs to be modified in some cases (Matrix and Table). Here, we don't override
             // the original handle for future iterations. We use the original handle to identify Matrix/Table fields.
             $handle = $destination;
             // Grab the field's content - formatted specifically for it
             $content = craft()->feedMe_fields->prepForFieldType($data, $handle);
             // Check to see if this is a Matrix field - need to merge any other fields mapped elsewhere in the feed
             // along with fields we've processed already. Involved due to multiple blocks can be defined at once.
             if (substr($destination, 0, 10) == '__matrix__') {
                 $content = craft()->feedMe_fields->handleMatrixData($fieldData, $handle, $content);
             }
             // And another special case for Table data
             if (substr($destination, 0, 9) == '__table__') {
                 $content = craft()->feedMe_fields->handleTableData($fieldData, $handle, $content);
             }
             // And another special case for SuperTable data
             if (substr($destination, 0, 14) == '__supertable__') {
                 $content = craft()->feedMe_fields->handleSuperTableData($fieldData, $handle, $content);
             }
             // Finally - we have our mapped data, formatted for the particular field as required
             $fieldData[$handle] = $content;
         } catch (\Exception $e) {
             FeedMePlugin::log($feed->name . ': FeedMeError: ' . $e->getMessage() . '.', LogLevel::Error, true);
             return false;
         }
     }
     $existingEntry = $criteria->first();
     //
     // Check for Add/Update/Delete for existing entries
     //
     // If there's an existing matching entry
     if ($existingEntry && $feed['duplicateHandle'] != FeedMe_Duplicate::Delete) {
         // If we're updating
         if ($feed['duplicateHandle'] == FeedMe_Duplicate::Update) {
             // Fill new EntryModel with match
             $entry = $existingEntry;
             // If we're adding, make sure not to overwrite existing entry
         } else {
             if ($feed['duplicateHandle'] == FeedMe_Duplicate::Add) {
                 $canSaveEntry = false;
             }
         }
     } else {
         // Prepare a new EntryModel (for this section and entrytype)
         $entry = craft()->feedMe_entry->setModel($feed);
     }
     //
     //
     //
     if ($canSaveEntry && $entry) {
         // Prepare Element model (the default stuff)
         $entry = craft()->feedMe_entry->prepForElementModel($fieldData, $entry);
         // Set our data for this EntryModel (our mapped data)
         $entry->setContentFromPost($fieldData);
         //echo '<pre>';
         //print_r($entry->title);
         //echo '</pre>';
         try {
             // Save the entry!
             if (!craft()->entries->saveEntry($entry)) {
                 FeedMePlugin::log($feed->name . ': ' . json_encode($entry->getErrors()), LogLevel::Error, true);
                 return false;
             } else {
                 // Successfully saved/added entry
                 if ($feed['duplicateHandle'] == FeedMe_Duplicate::Update) {
                     FeedMePlugin::log($feed->name . ': Entry successfully updated: ' . $entry->id, LogLevel::Info, true);
                 } else {
                     FeedMePlugin::log($feed->name . ': Entry successfully added: ' . $entry->id, LogLevel::Info, true);
                 }
                 return true;
             }
         } catch (\Exception $e) {
             FeedMePlugin::log($feed->name . ': Entry FeedMeError: ' . $e->getMessage() . '.', LogLevel::Error, true);
             return false;
         }
     }
 }
开发者ID:am-impact,项目名称:FeedMe,代码行数:99,代码来源:FeedMeService.php

示例6: actionSearchForTags

 /**
  * Searches for tags.
  *
  * @return null
  */
 public function actionSearchForTags()
 {
     $this->requirePostRequest();
     $this->requireAjaxRequest();
     $search = craft()->request->getPost('search');
     $tagGroupId = craft()->request->getPost('tagGroupId');
     $excludeIds = craft()->request->getPost('excludeIds', array());
     $notIds = array('and');
     foreach ($excludeIds as $id) {
         $notIds[] = 'not ' . $id;
     }
     $criteria = craft()->elements->getCriteria(ElementType::Tag);
     $criteria->groupId = $tagGroupId;
     $criteria->title = DbHelper::escapeParam($search) . '*';
     $criteria->id = $notIds;
     $tags = $criteria->find();
     $return = array();
     $exactMatches = array();
     $tagTitleLengths = array();
     $exactMatch = false;
     $normalizedSearch = StringHelper::normalizeKeywords($search);
     foreach ($tags as $tag) {
         $return[] = array('id' => $tag->id, 'title' => $tag->getContent()->title);
         $tagTitleLengths[] = mb_strlen($tag->getContent()->title);
         $normalizedTitle = StringHelper::normalizeKeywords($tag->getContent()->title);
         if ($normalizedTitle == $normalizedSearch) {
             $exactMatches[] = 1;
             $exactMatch = true;
         } else {
             $exactMatches[] = 0;
         }
     }
     array_multisort($exactMatches, SORT_DESC, $tagTitleLengths, $return);
     $this->returnJson(array('tags' => $return, 'exactMatch' => $exactMatch));
 }
开发者ID:jmstan,项目名称:craft-website,代码行数:40,代码来源:TagsController.php


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