本文整理汇总了PHP中JsonHelper::encode方法的典型用法代码示例。如果您正苦于以下问题:PHP JsonHelper::encode方法的具体用法?PHP JsonHelper::encode怎么用?PHP JsonHelper::encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonHelper
的用法示例。
在下文中一共展示了JsonHelper::encode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __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();
}
示例2: 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();');
}
}
示例3: 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
示例4: 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);
}
示例5: 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);
}
示例6: 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;
}
示例7: _updateSaveUserOptions
private function _updateSaveUserOptions($options)
{
$oldOptions = JsonHelper::decode($options);
$whenNew = isset($oldOptions['usersSaveUserOnlyWhenNew']) ? $oldOptions['usersSaveUserOnlyWhenNew'] : '';
$userGroupIds = isset($oldOptions['usersSaveUserGroupIds']) ? $oldOptions['usersSaveUserGroupIds'] : '';
$newOptions = array('craft' => array('saveUser' => array('whenNew' => $whenNew, 'whenUpdated' => '', 'userGroupIds' => $userGroupIds)));
return JsonHelper::encode($newOptions);
}
开发者ID:aladrach,项目名称:Bluefoot-Craft-Starter,代码行数:8,代码来源:m150629_000000_sproutEmail_updateNotificationOptionsFormat.php
示例8: __toString
function __toString()
{
$this->setAttribute('class', 'tinymce_textarea');
$this->innerHTML = HtmlHelper::escape($this->_value);
$config = JsonHelper::encode($this->config);
$script = HtmlHelper::inlineJavascript('tinyMCE.init(' . $config . ');');
$this->afterHTML = $script;
self::$instances_included++;
return parent::__toString();
}
示例9: getBodyHtml
/**
* @inheritDoc IWidget::getBodyHtml()
*
* @return string|false
*/
public function getBodyHtml()
{
$id = $this->model->id;
$url = JsonHelper::encode($this->getSettings()->url);
$limit = $this->getSettings()->limit;
$js = "new Craft.FeedWidget({$id}, {$url}, {$limit});";
craft()->templates->includeJsResource('js/FeedWidget.js');
craft()->templates->includeJs($js);
return craft()->templates->render('_components/widgets/Feed/body', array('limit' => $limit));
}
示例10: pluginInit
/**
* Separate initialisation function to be called inside the NeoPlugin init method.
*/
public function pluginInit()
{
if (craft()->plugins->getPlugin('reasons') && craft()->request->isCpRequest() && !craft()->isConsole()) {
if (craft()->request->isAjaxRequest()) {
// TODO
} else {
$data = ['conditionals' => $this->getConditionals()];
craft()->templates->includeJs('if(window.Craft && Craft.ReasonsPlugin) Craft.ReasonsPlugin.Neo = ' . JsonHelper::encode($data));
}
craft()->on('fields.saveFieldLayout', [$this, 'onSaveFieldLayout']);
}
}
示例11: safeUp
/**
* Any migration code in here is wrapped inside of a transaction.
*
* @return bool
*/
public function safeUp()
{
$matrixFields = craft()->db->createCommand()->select('id, settings')->from('fields')->where('type = "Matrix"')->queryAll();
foreach ($matrixFields as $field) {
$settings = JsonHelper::decode($field['settings']);
if (isset($settings['__model__'])) {
unset($settings['__model__']);
$this->update('fields', array('settings' => JsonHelper::encode($settings)), array('id' => $field['id']));
}
}
return true;
}
示例12: safeUp
/**
* Any migration code in here is wrapped inside of a transaction.
*
* @return bool
*/
public function safeUp()
{
if (!craft()->db->tableExists('tagsets')) {
// Create the tagsets table
craft()->db->createCommand()->createTable('tagsets', array('name' => array('maxLength' => 100, 'column' => ColumnType::Varchar, 'null' => false), 'handle' => array('maxLength' => 45, 'column' => ColumnType::Char, 'null' => false), 'fieldLayoutId' => array('column' => ColumnType::Int, 'length' => 10, 'unsigned' => false)));
$this->createIndex('tagsets', 'name', true);
$this->createIndex('tagsets', 'handle', true);
// Create the Default tag group
$this->insert('tagsets', array('name' => 'Default', 'handle' => 'default'));
$tagSetId = craft()->db->getLastInsertID();
// Rename the entrytags table
MigrationHelper::renameTable('entrytags', 'tags');
// Convert the tags to elements
MigrationHelper::makeElemental('tags', 'Tag');
// Make some tweaks on the tags table
$this->alterColumn('tags', 'name', array('column' => ColumnType::Varchar, 'null' => false));
$this->dropColumn('tags', 'count');
$this->addColumnBefore('tags', 'setId', array('column' => ColumnType::Int, 'null' => false), 'name');
$this->dropIndex('tags', 'name', true);
// Place all current tags into the Default group
$this->update('tags', array('setId' => $tagSetId));
$this->createIndex('tags', 'setId, name', true);
$this->addForeignKey('tags', 'setId', 'tagsets', 'id', 'CASCADE', null);
// Create a new field group
$this->insert('fieldgroups', array('name' => 'Tags (Auto-created)'));
$groupId = craft()->db->getLastInsertID();
// Create a new Tags field
// Find a unique handle
for ($i = 0; true; $i++) {
$handle = 'tags' . ($i != 0 ? "-{$i}" : '');
$totalFields = craft()->db->createCommand()->from('fields')->where(array('handle' => $handle))->count('id');
if ($totalFields == 0) {
break;
}
}
$this->insert('fields', array('groupId' => $groupId, 'name' => 'Tags', 'handle' => $handle, 'type' => 'Tags', 'settings' => JsonHelper::encode(array('source' => 'tagset:' . $tagSetId))));
$fieldId = craft()->db->getLastInsertID();
// Migrate entrytags_enrtries data into relations
$tagRelations = craft()->db->createCommand()->select('entryId, tagId, dateCreated, dateUpdated, uid')->from('entrytags_entries')->queryAll(false);
foreach ($tagRelations as &$relation) {
array_unshift($relation, $fieldId);
}
$this->insertAll('relations', array('fieldId', 'parentId', 'childId', 'dateCreated', 'dateUpdated', 'uid'), $tagRelations, false);
// Update the search indexes
$this->update('searchindex', array('attribute' => 'field', 'fieldId' => $fieldId), array('attribute' => 'tags'), array(), false);
// Drop the old entrytags_entries table
$this->dropTable('entrytags_entries');
} else {
Craft::log('Tried to add the `tagsets` table, but it already exists.', LogLevel::Warning);
}
return true;
}
示例13: _updateSaveFormEntryOptions
private function _updateSaveFormEntryOptions($options)
{
if (substr($options, 0, 1) === '[') {
// Older versions of Sprout Forms just saved an
// array of IDs ["3"] so we make it work
$whenNew = 1;
$sectionIds = $options;
} else {
$oldOptions = JsonHelper::decode($options);
$whenNew = isset($oldOptions['entriesSaveEntryOnlyWhenNew']) ? $oldOptions['entriesSaveEntryOnlyWhenNew'] : '';
$sectionIds = isset($oldOptions['entriesSaveEntrySectionIds']) ? $oldOptions['entriesSaveEntrySectionIds'] : '';
}
$newOptions = array('sproutForms' => array('saveEntry' => array('whenNew' => $whenNew, 'formIds' => $sectionIds)));
return JsonHelper::encode($newOptions);
}
开发者ID:aladrach,项目名称:Bluefoot-Craft-Starter,代码行数:15,代码来源:m150629_000000_sproutForms_updateSproutEmailNotificationOptionsFormat.php
示例14: getBodyHtml
/**
* Gets the widget's body HTML.
*
* @return string
*/
public function getBodyHtml()
{
$params = array();
if (Craft::hasPackage(CraftPackage::PublishPro)) {
$sectionId = $this->getSettings()->section;
if (is_numeric($sectionId)) {
$params['sectionId'] = (int) $sectionId;
}
}
$js = 'new Craft.RecentEntriesWidget(' . $this->model->id . ', ' . JsonHelper::encode($params) . ');';
craft()->templates->includeJsResource('js/RecentEntriesWidget.js');
craft()->templates->includeJs($js);
craft()->templates->includeTranslations('by {author}');
return craft()->templates->render('_components/widgets/RecentEntries/body', array('settings' => $this->getSettings()));
}
示例15: init
public function init()
{
if (!craft()->isConsole()) {
if (craft()->request->isCpRequest()) {
craft()->templates->includeCssResource('redactorclips/clips.css');
craft()->templates->includeJsResource('redactorclips/clips.js');
$clips = array();
foreach ($this->getSettings()->clips as $clip) {
$clips[] = array($clip['name'], $clip['html']);
}
$js = 'RedactorPlugins.clips.items = ' . JsonHelper::encode($clips) . ';';
craft()->templates->includeJs($js);
}
}
}