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


PHP JsonHelper类代码示例

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


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

示例1: safeUp

 /**
  * Convert allowed source storage format from just an integer to "folder:X" format.
  *
  * @return bool
  */
 public function safeUp()
 {
     // Grab all the Assets fields.
     $fields = craft()->db->createCommand()->select('id, settings')->from('fields')->where('type = :type', array(':type' => "Assets"))->queryAll();
     if ($fields) {
         // Grab all of the top-level folder IDs
         $folders = craft()->db->createCommand()->select('id, sourceId')->from('assetfolders')->where('parentId is null')->queryAll();
         if ($folders) {
             // Create an associative array of them by source ID
             $folderIdsBySourceId = array();
             foreach ($folders as $folder) {
                 $folderIdsBySourceId[$folder['sourceId']] = $folder['id'];
             }
             // Now update the fields
             foreach ($fields as $field) {
                 $settings = JsonHelper::decode($field['settings']);
                 if (isset($settings['sources']) && is_array($settings['sources'])) {
                     // Are there any source IDs?
                     $anySourceIds = false;
                     foreach ($settings['sources'] as $key => $source) {
                         if (isset($folderIdsBySourceId[$source])) {
                             $settings['sources'][$key] = 'folder:' . $folderIdsBySourceId[$source];
                             $anySourceIds = true;
                         }
                     }
                     if ($anySourceIds) {
                         $this->update('fields', array('settings' => JsonHelper::encode($settings)), array('id' => $field['id']));
                     }
                 }
             }
         }
     }
     return true;
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:39,代码来源:m140603_000005_asset_sources.php

示例2: safeUp

 /**
  * Any migration code in here is wrapped inside of a transaction.
  *
  * @return bool
  */
 public function safeUp()
 {
     // Get all of the Tags fields
     $tagFields = craft()->db->createCommand()->select('id, settings')->from('fields')->where(array('type' => 'Tags'))->queryAll();
     foreach ($tagFields as $field) {
         $settings = JsonHelper::decode($field['settings']);
         if (!empty($settings['source']) && strncmp($settings['source'], 'tagset:', 7) == 0) {
             $tagSetId = (int) mb_substr($settings['source'], 7);
             // Does that tag set still exist?
             $count = craft()->db->createCommand()->from('tagsets')->where(array('id' => $tagSetId))->count('id');
             if ($count) {
                 // Now make sure all of the tags connected to this field actually belong to that set.
                 // Otherwise we should duplicate the tag into the correct set
                 $tags = craft()->db->createCommand()->select('r.id relationId, t.name')->from('relations r')->join('tags t', 't.id = r.childId')->where(array('and', 'r.fieldId = :fieldId', 't.setId != :setId'), array(':fieldId' => $field['id'], ':setId' => $tagSetId))->queryAll();
                 foreach ($tags as $tag) {
                     // Is there already a tag in the correct tag set with that name?
                     $newTagId = craft()->db->createCommand()->select('id')->from('tags')->where(array('setId' => $tagSetId, 'name' => $tag['name']))->queryScalar();
                     if (!$newTagId) {
                         // Create a new row in elements
                         craft()->db->createCommand()->insert('elements', array('type' => ElementType::Tag, 'enabled' => 1, 'archived' => 0));
                         // Get the new element ID
                         $newTagId = craft()->db->getLastInsertID();
                         $this->insert('tags', array('id' => $newTagId, 'setId' => $tagSetId, 'name' => $tag['name']));
                     }
                     // Update the relation
                     $this->update('relations', array('childId' => $newTagId), array('id' => $tag['relationId']));
                 }
             } else {
                 // Just delete any relations with this field
                 $this->delete('relations', array('fieldId' => $field['id']));
             }
         }
     }
     return true;
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:40,代码来源:m130909_000000_fix_tags.php

示例3: safeUp

 /**
  * Any migration code in here is wrapped inside of a transaction.
  *
  * @return bool
  */
 public function safeUp()
 {
     // Get all Assets fields
     $fields = craft()->db->createCommand()->select('fields.id, fields.settings')->from('fields fields')->where('fields.type = "Assets"')->queryAll();
     $affectedFields = array();
     // Select those, that have a dynamic default upload location set.
     foreach ($fields as $field) {
         $settings = JsonHelper::decode($field['settings']);
         if (empty($settings['useSingleFolder']) && !empty($settings['defaultUploadLocationSubpath']) && strpos($settings['defaultUploadLocationSubpath'], '{') !== false) {
             $affectedFields[] = $field;
         }
     }
     $affectedElements = array();
     // Get the element ids, that have Assets linked to them via affected fields that still reside in a temporary source.
     if (!empty($affectedFields)) {
         foreach ($affectedFields as $field) {
             $data = $this->_getAffectedElements($field);
             foreach ($data as $row) {
                 $affectedElements[$row['type']][] = $row['elementId'];
             }
         }
     }
     foreach ($affectedElements as $elementType => $ids) {
         $criteria = craft()->elements->getCriteria($elementType);
         $criteria->status = null;
         $criteria->limit = null;
         $criteria->id = $ids;
         craft()->tasks->createTask('ResaveElements', Craft::t('Resaving {element} elements affected by Assets bug', array('element' => $elementType)), array('elementType' => $elementType, 'criteria' => $criteria->getAttributes()));
     }
     return true;
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:36,代码来源:m140731_000001_resave_elements_with_assets_in_temp_sources.php

示例4: __toString

 function __toString()
 {
     $json_config = JsonHelper::encode($this->config);
     $this->afterHTML = HtmlHelper::inlineJavascript('jQuery(function(){$("#' . $this->getId() . '").datepicker(' . $json_config . ')});');
     $this->setAttribute('class', 'form_input_text form_ycalendar');
     return parent::__toString();
 }
开发者ID:RNKushwaha022,项目名称:orange-php,代码行数:7,代码来源:datepicker.input.php

示例5: getRecipients

 /**
  * @param mixed|null $element
  *
  * @throws \Exception
  * @return array|string
  */
 public function getRecipients($element = null)
 {
     $recipientsString = $this->getAttribute('recipients');
     // Possibly called from entry edit screen
     if (is_null($element)) {
         return $recipientsString;
     }
     // Previously converted to array somehow?
     if (is_array($recipientsString)) {
         return $recipientsString;
     }
     // Previously stored as JSON string?
     if (stripos($recipientsString, '[') === 0) {
         return JsonHelper::decode($recipientsString);
     }
     // Still a string with possible twig generator code?
     if (stripos($recipientsString, '{') !== false) {
         try {
             $recipients = craft()->templates->renderObjectTemplate($recipientsString, $element);
             return array_unique(ArrayHelper::filterEmptyStringsFromArray(ArrayHelper::stringToArray($recipients)));
         } catch (\Exception $e) {
             throw $e;
         }
     }
     // Just a regular CSV list
     if (!empty($recipientsString)) {
         return ArrayHelper::filterEmptyStringsFromArray(ArrayHelper::stringToArray($recipientsString));
     }
     return array();
 }
开发者ID:aladrach,项目名称:Bluefoot-Craft-Starter,代码行数:36,代码来源:SproutEmail_EntryModel.php

示例6: Decode

 public static function Decode($object, $data)
 {
     foreach ($data as $value) {
         $object->{$value} = JsonHelper::JsonDecode($object->{$value});
     }
     return $object;
 }
开发者ID:younginnovations,项目名称:aidstream,代码行数:7,代码来源:JsonHelper.php

示例7: getTriggerHtml

    /**
     * @inheritDoc IElementAction::getTriggerHtml()
     *
     * @return string|null
     */
    public function getTriggerHtml()
    {
        $maxLevels = JsonHelper::encode($this->getParams()->maxLevels);
        $newChildUrl = JsonHelper::encode($this->getParams()->newChildUrl);
        $js = <<<EOT
(function()
{
\tvar trigger = new Craft.ElementActionTrigger({
\t\thandle: 'NewChild',
\t\tbatch: false,
\t\tvalidateSelection: function(\$selectedItems)
\t\t{
\t\t\treturn (!{$maxLevels} || {$maxLevels} > \$selectedItems.find('.element').data('level'));
\t\t},
\t\tactivate: function(\$selectedItems)
\t\t{
\t\t\tCraft.redirectTo(Craft.getUrl({$newChildUrl}, 'parentId='+\$selectedItems.find('.element').data('id')));
\t\t}
\t});

\tif (Craft.elementIndex.view.structureTableSort)
\t{
\t\tCraft.elementIndex.view.structureTableSort.on('positionChange', \$.proxy(trigger, 'updateTrigger'));
\t}
})();
EOT;
        craft()->templates->includeJs($js);
    }
开发者ID:jmstan,项目名称:craft-website,代码行数:33,代码来源:NewChildElementAction.php

示例8: safeUp

 /**
  * Any migration code in here is wrapped inside of a transaction.
  *
  * @return bool
  */
 public function safeUp()
 {
     $rows = craft()->db->createCommand()->select('*')->from('widgets')->where('type=:type', array(':type' => 'Analytics_Explorer'))->queryAll();
     if ($rows) {
         foreach ($rows as $row) {
             $oldSettings = JsonHelper::decode($row['settings']);
             // old to new
             $newSettings = [];
             if (isset($oldSettings['chart'])) {
                 $newSettings['chart'] = $oldSettings['chart'];
             }
             if (isset($oldSettings['period'])) {
                 $newSettings['period'] = $oldSettings['period'];
             }
             $newSettings['options'] = [];
             if (isset($oldSettings['dimension'])) {
                 $newSettings['options']['dimension'] = $oldSettings['dimension'];
             }
             if (isset($oldSettings['metric'])) {
                 $newSettings['options']['metric'] = $oldSettings['metric'];
             }
             switch ($oldSettings['menu']) {
                 case 'realtimeVisitors':
                     $type = 'Analytics_Realtime';
                     break;
                 default:
                     $type = 'Analytics_Report';
             }
             // update row
             $newSettings = JsonHelper::encode($newSettings);
             $updateCmd = craft()->db->createCommand()->update('widgets', array('type' => $type, 'settings' => $newSettings), 'id=:id', array('id' => $row['id']));
         }
     }
     return true;
 }
开发者ID:codeforamerica,项目名称:oakland-beta,代码行数:40,代码来源:m150921_000001_explorer_widget_to_realtime_and_reports.php

示例9: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($request->method() == 'POST' && $request->input('api_key') != getenv('API_KEY')) {
         return response()->json(\JsonHelper::getErrorResponse(\HttpResponse::HTTP_UNAUTHORIZED, 'API key is invalid.'), \HttpResponse::HTTP_UNAUTHORIZED);
     }
     return $next($request);
 }
开发者ID:peterwcm,项目名称:l5-app,代码行数:14,代码来源:VerifyApiKey.php

示例10: getTokenRoute

 /**
  * Searches for a token, and possibly returns a route for the request.
  *
  * @param string $token
  *
  * @return array|false
  */
 public function getTokenRoute($token)
 {
     // Take the opportunity to delete any expired tokens
     $this->deleteExpiredTokens();
     $result = craft()->db->createCommand()->select('id, route, usageLimit, usageCount')->from('tokens')->where('token = :token', array(':token' => $token))->queryRow();
     if ($result) {
         // Usage limit enforcement (for future requests)
         if ($result['usageLimit']) {
             // Does it have any more life after this?
             if ($result['usageCount'] < $result['usageLimit'] - 1) {
                 // Increment its count
                 $this->incrementTokenUsageCountById($result['id']);
             } else {
                 // Just delete it
                 $this->deleteTokenById($result['id']);
             }
         }
         // Figure out where we should route the request
         $route = $result['route'];
         if (is_string($route) && mb_strlen($route) && ($route[0] == '[' || $route[0] == '{')) {
             $route = JsonHelper::decode($route);
         }
         return $route;
     } else {
         return false;
     }
 }
开发者ID:scisahaha,项目名称:generator-craft,代码行数:34,代码来源:TokensService.php

示例11: populateFromAsset

 public static function populateFromAsset(AssetFileModel $asset)
 {
     if ($asset->kind === 'json' && strpos($asset->filename, EmbeddedAssetsPlugin::getFileNamePrefix(), 0) === 0) {
         try {
             $url = $asset->getUrl();
             if (!UrlHelper::isAbsoluteUrl($url)) {
                 $protocol = craft()->request->isSecureConnection() ? 'https' : 'http';
                 $url = UrlHelper::getUrlWithProtocol($url, $protocol);
             }
             // See http://stackoverflow.com/questions/272361/how-can-i-handle-the-warning-of-file-get-contents-function-in-php
             $rawData = @file_get_contents($url);
             if ($rawData) {
                 $data = JsonHelper::decode($rawData);
                 if ($data['__embeddedasset__']) {
                     unset($data['__embeddedasset__']);
                     $embed = new EmbeddedAssetsModel();
                     $embed->id = $asset->id;
                     foreach ($data as $key => $value) {
                         $embed->{$key} = $value;
                     }
                     return $embed;
                 }
             }
         } catch (\Exception $e) {
             return null;
         }
     }
     return null;
 }
开发者ID:jonleesmith,项目名称:jonleesmith,代码行数:29,代码来源:EmbeddedAssetsModel.php

示例12: getTriggerHtml

    /**
     * @inheritDoc IElementAction::getTriggerHtml()
     *
     * @return string|null
     */
    public function getTriggerHtml()
    {
        $userId = JsonHelper::encode(craft()->userSession->getUser()->id);
        $js = <<<EOT
(function()
{
\tvar trigger = new Craft.ElementActionTrigger({
\t\thandle: 'SuspendUsers',
\t\tbatch: true,
\t\tvalidateSelection: function(\$selectedItems)
\t\t{
\t\t\tfor (var i = 0; i < \$selectedItems.length; i++)
\t\t\t{
\t\t\t\tif (\$selectedItems.eq(i).find('.element').data('id') == {$userId})
\t\t\t\t{
\t\t\t\t\treturn false;
\t\t\t\t}
\t\t\t}

\t\t\treturn true;
\t\t}
\t});
})();
EOT;
        craft()->templates->includeJs($js);
    }
开发者ID:jmstan,项目名称:craft-website,代码行数:31,代码来源:SuspendUsersElementAction.php

示例13: includeCpResources

 /**
  * Includes the plugin's resources for the Control Panel.
  */
 protected function includeCpResources()
 {
     // Prepare config
     $config = [];
     $config['iconMapping'] = craft()->config->get('iconMapping', 'redactoriconbuttons');
     $iconAdminPath = craft()->path->getConfigPath() . 'redactoriconbuttons/icons.svg';
     $iconPublicPath = craft()->config->get('iconFile', 'redactoriconbuttons');
     if (IOHelper::fileExists($iconAdminPath)) {
         $config['iconFile'] = UrlHelper::getResourceUrl('config/redactoriconbuttons/icons.svg');
     } elseif ($iconPublicPath) {
         $config['iconFile'] = craft()->config->parseEnvironmentString($iconPublicPath);
     } else {
         $config['iconFile'] = UrlHelper::getResourceUrl('redactoriconbuttons/icons/redactor-i.svg');
     }
     // Include JS
     $config = JsonHelper::encode($config);
     $js = "var RedactorIconButtons = {}; RedactorIconButtons.config = {$config};";
     craft()->templates->includeJs($js);
     craft()->templates->includeJsResource('redactoriconbuttons/redactoriconbuttons.js');
     // Include CSS
     craft()->templates->includeCssResource('redactoriconbuttons/redactoriconbuttons.css');
     // Add external spritemap support for IE9+ and Edge 12
     $ieShim = craft()->config->get('ieShim', 'redactoriconbuttons');
     if (filter_var($ieShim, FILTER_VALIDATE_BOOLEAN)) {
         craft()->templates->includeJsResource('redactoriconbuttons/lib/svg4everybody.min.js');
         craft()->templates->includeJs('svg4everybody();');
     }
 }
开发者ID:carlcs,项目名称:craft-redactoriconbuttons,代码行数:31,代码来源:RedactorIconButtonsPlugin.php

示例14: populateFromAsset

 public static function populateFromAsset(AssetFileModel $asset)
 {
     if ($asset->kind === 'json' && strpos($asset->filename, EmbeddedAssetsPlugin::getFileNamePrefix(), 0) === 0) {
         try {
             $rawData = craft()->embeddedAssets->readAssetFile($asset);
             if ($rawData) {
                 $data = JsonHelper::decode($rawData);
                 if ($data['__embeddedasset__']) {
                     unset($data['__embeddedasset__']);
                     $embed = new EmbeddedAssetsModel();
                     $embed->id = $asset->id;
                     foreach ($embed->attributeNames() as $key) {
                         if (isset($data[$key])) {
                             $embed->{$key} = $data[$key];
                         }
                     }
                     // For embedded assets saved with version 0.2.1 or below, this will provide a usable fallback
                     if (empty($embed->requestUrl)) {
                         $embed->requestUrl = $embed->url;
                     }
                     return $embed;
                 }
             }
         } catch (\Exception $e) {
             EmbeddedAssetsPlugin::log("Error reading embedded asset data on asset {$asset->id} (\"{$e->getMessage()}\")", LogLevel::Error);
             return null;
         }
     }
     return null;
 }
开发者ID:benjamminf,项目名称:craft-embedded-assets,代码行数:30,代码来源:EmbeddedAssetsModel.php

示例15: actionReorderRules

 /**
  * Updates the rules sort order.
  *
  * @return null
  */
 public function actionReorderRules()
 {
     $this->requirePostRequest();
     $this->requireAjaxRequest();
     $ruleIds = JsonHelper::decode(craft()->request->getRequiredPost('ids'));
     craft()->autoExpire->reorderRules($ruleIds);
     $this->returnJson(array('success' => true));
 }
开发者ID:carlcs,项目名称:craft-autoexpire,代码行数:13,代码来源:AutoExpireController.php


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