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();
 }
 /**
  * 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();');
     }
 }
 /**
  * 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;
 }
    /**
     * @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);
    }
    /**
     * @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);
    }
 /**
  * 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;
 }
 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);
 }
 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();
 }
 /**
  * @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
0
 /**
  * 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']);
     }
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 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);
 }
 /**
  * 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()));
 }
 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);
         }
     }
 }
 /**
  * Any migration code in here is wrapped inside of a transaction.
  *
  * @return bool
  */
 public function safeUp()
 {
     $results = craft()->db->createCommand()->select('settings, id')->from('widgets')->where('type = :type', array(':type' => 'Feed'))->queryAll();
     foreach ($results as $result) {
         $settings = JsonHelper::decode($result['settings']);
         if (isset($settings['url']) && $settings['url'] == 'http://feeds.feedburner.com/blogandtonic') {
             Craft::log('Updating Feeds widget setting to new craftcms.com URL', LogLevel::Info, true);
             $settings['url'] = 'https://craftcms.com/news.rss';
             $settings['title'] = 'Craft News';
             $settings = JsonHelper::encode($settings);
             craft()->db->createCommand()->update('widgets', array('settings' => $settings), 'id = :id', array(':id' => $result['id']));
         }
     }
     return true;
 }
 /**
  * Any migration code in here is wrapped inside of a transaction.
  *
  * @return bool
  */
 public function safeUp()
 {
     // Find all the PlainText Fields
     $fields = craft()->db->createCommand()->select('id,settings')->from('fields')->where(array('type' => 'PlainText'))->queryAll();
     foreach ($fields as $field) {
         $fieldSettings = JsonHelper::decode($field['settings']);
         if (isset($fieldSettings['hint'])) {
             $fieldSettings['placeholder'] = $fieldSettings['hint'];
             unset($fieldSettings['hint']);
         }
         $this->update('fields', array('settings' => JsonHelper::encode($fieldSettings)), array('id' => $field['id']));
     }
     Craft::log('Successfully changed `hint` setting to the `placeholder` setting.', LogLevel::Info, true);
     return true;
 }
示例#18
0
 /**
  * Re-runs a failed task.
  *
  * @return null
  */
 public function actionRerunTask()
 {
     $this->requireAjaxRequest();
     $this->requirePostRequest();
     craft()->userSession->requirePermission('accessCp');
     $taskId = craft()->request->getRequiredPost('taskId');
     $task = craft()->tasks->rerunTaskById($taskId);
     if (!craft()->tasks->isTaskRunning()) {
         JsonHelper::sendJsonHeaders();
         craft()->request->close(JsonHelper::encode($task->getInfo()));
         craft()->tasks->runPendingTasks();
     } else {
         $this->returnJson($task->getInfo());
     }
     craft()->end();
 }
 /**
  * Any migration code in here is wrapped inside of a transaction.
  *
  * @return bool
  */
 public function safeUp()
 {
     Craft::log('Adding the publicURLs settings to Assets Sources that defaults to true', LogLevel::Info, true);
     $sourceRows = craft()->db->createCommand()->select('id, settings')->from('assetsources')->queryAll();
     foreach ($sourceRows as $source) {
         $settings = JsonHelper::decode($source['settings']);
         // This should always be true, but to be on the safe side.
         if (!isset($settings['publicURLs'])) {
             $settings['publicURLs'] = true;
             $settings = JsonHelper::encode($settings);
             craft()->db->createCommand()->update('assetsources', array('settings' => $settings), 'id = :id', array(':id' => $source['id']));
         }
     }
     Craft::log('Done adding the publicURLs settings to Assets Sources that defaults to true', LogLevel::Info, true);
     return true;
 }
示例#20
0
 /**
  * Logs a new deprecation error.
  *
  * @param string $key
  * @param string $message
  *
  * @return bool
  */
 public function log($key, $message)
 {
     $log = new DeprecationErrorModel();
     $log->key = $key;
     $log->message = $message;
     $log->lastOccurrence = DateTimeHelper::currentTimeForDb();
     $log->template = craft()->request->isSiteRequest() ? craft()->templates->getRenderingTemplate() : null;
     // Everything else requires the stack trace
     $this->_populateLogWithStackTraceData($log);
     // Don't log the same key/fingerprint twice in the same request
     if (!isset($this->_fingerprints[$log->key]) || !in_array($log->fingerprint, $this->_fingerprints[$log->key])) {
         craft()->db->createCommand()->insertOrUpdate(static::$_tableName, array('key' => $log->key, 'fingerprint' => $log->fingerprint), array('lastOccurrence' => DateTimeHelper::formatTimeForDb($log->lastOccurrence), 'file' => $log->file, 'line' => $log->line, 'class' => $log->class, 'method' => $log->method, 'template' => $log->template, 'templateLine' => $log->templateLine, 'message' => $log->message, 'traces' => JsonHelper::encode($log->traces)));
         $this->_fingerprints[$key][] = $log->fingerprint;
     }
     return true;
 }
示例#21
0
 /**
  * Return entry fields.
  *
  * @param array $settings
  * @param bool  $reset
  *
  * @return array
  */
 public function getFields(array $settings, $reset)
 {
     // Set criteria
     $criteria = new \CDbCriteria();
     $criteria->condition = 'settings = :settings';
     $criteria->params = array(':settings' => JsonHelper::encode($settings));
     // Check if we have a map already
     $stored = Export_MapRecord::model()->find($criteria);
     if (!count($stored) || $reset) {
         // Get section id
         $section = $settings['elementvars']['section'];
         // Get entrytype id(s)
         $entrytype = $settings['elementvars']['entrytype'];
         // If "All"
         if (empty($entrytype)) {
             // Get entrytype models
             $entrytypes = craft()->sections->getEntryTypesBySectionId($section);
         } else {
             // Get entrytype model
             $entrytypes = array(craft()->sections->getEntryTypeById($entrytype));
         }
         // Create a nice field map
         $fields = array();
         // With multiple or one entry type
         foreach ($entrytypes as $entrytype) {
             // Set the static fields for this type
             $layout = array(ExportModel::HandleId => array('name' => Craft::t('ID'), 'checked' => 0), ExportModel::HandleTitle . '_' . $entrytype->id => array('name' => $entrytype->hasTitleField ? $entrytype->titleLabel : Craft::t('Title'), 'checked' => 1, 'entrytype' => $entrytype->id), ExportModel::HandleSlug => array('name' => Craft::t('Slug'), 'checked' => 0), ExportModel::HandleParent => array('name' => Craft::t('Parent'), 'checked' => 0), ExportModel::HandleAncestors => array('name' => Craft::t('Ancestors'), 'checked' => 0), ExportModel::HandleAuthor => array('name' => Craft::t('Author'), 'checked' => 0), ExportModel::HandlePostDate => array('name' => Craft::t('Post Date'), 'checked' => 0), ExportModel::HandleExpiryDate => array('name' => Craft::t('Expiry Date'), 'checked' => 0), ExportModel::HandleEnabled => array('name' => Craft::t('Enabled'), 'checked' => 0), ExportModel::HandleStatus => array('name' => Craft::t('Status'), 'checked' => 0));
             // Set the dynamic fields for this type
             $tabs = craft()->fields->getLayoutById($entrytype->fieldLayoutId)->getTabs();
             foreach ($tabs as $tab) {
                 $fieldData = array();
                 foreach ($tab->getFields() as $field) {
                     $data = $field->getField();
                     $fieldData[$data->handle] = array('name' => $data->name, 'checked' => 1);
                 }
                 $layout += $fieldData;
             }
             // Set the static fields also
             $fields += $layout;
         }
     } else {
         // Get the stored map
         $fields = $stored->map;
     }
     // Return fields
     return $fields;
 }
 public function getMatrixInputHtml($fieldType, $name, $value)
 {
     $id = craft()->templates->formatInputId($name);
     $settings = $fieldType->getSettings();
     if ($value instanceof ElementCriteriaModel) {
         $value->limit = null;
         $value->status = null;
         $value->localeEnabled = null;
     }
     $html = craft()->templates->render('_components/fieldtypes/Matrix/input', array('id' => $id, 'name' => $name, 'blockTypes' => $settings->getBlockTypes(), 'blocks' => $value, 'static' => false));
     // Get the block types data
     $blockTypeInfo = $this->_getBlockTypeInfoForInput($fieldType, $name);
     craft()->templates->includeJsResource('supertable/js/MatrixInputAlt.js');
     craft()->templates->includeJs('new Craft.MatrixInputAlt(' . '"' . craft()->templates->namespaceInputId($id) . '", ' . JsonHelper::encode($blockTypeInfo) . ', ' . '"' . craft()->templates->namespaceInputName($name) . '", ' . ($settings->maxBlocks ? $settings->maxBlocks : 'null') . ');');
     craft()->templates->includeTranslations('Disabled', 'Actions', 'Collapse', 'Expand', 'Disable', 'Enable', 'Add {type} above', 'Add a block');
     return $html;
 }
 /**
  * @inheritDoc IWidget::getBodyHtml()
  *
  * @return string|false
  */
 public function getBodyHtml()
 {
     if (craft()->getEdition() != Craft::Pro) {
         return false;
     }
     $settings = $this->getSettings();
     $groupId = $settings->userGroupId;
     $userGroup = craft()->userGroups->getGroupById($groupId);
     $options = $settings->getAttributes();
     $options['orientation'] = craft()->locale->getOrientation();
     craft()->templates->includeJsResource('js/NewUsersWidget.js');
     craft()->templates->includeJs('new Craft.NewUsersWidget(' . $this->model->id . ', ' . JsonHelper::encode($options) . ');');
     $dateRange = false;
     $dateRanges = ChartHelper::getDateRanges();
     if (isset($dateRanges[$settings->dateRange])) {
         $dateRange = $dateRanges[$settings->dateRange];
     }
     return '<div></div>';
 }
示例#24
0
 /**
  * Returns the field's settings HTML.
  *
  * @return string|null
  */
 public function getSettingsHtml()
 {
     $columns = $this->getSettings()->columns;
     $defaults = $this->getSettings()->defaults;
     if (!$columns) {
         $columns = array('col1' => array('heading' => '', 'handle' => '', 'type' => 'singleline'));
         // Update the actual settings model for getInputHtml()
         $this->getSettings()->columns = $columns;
     }
     if (!$defaults) {
         $defaults = array('row1' => array());
     }
     $columnSettings = array('heading' => array('heading' => Craft::t('Column Heading'), 'type' => 'singleline', 'autopopulate' => 'handle'), 'handle' => array('heading' => Craft::t('Handle'), 'class' => 'code', 'type' => 'singleline'), 'width' => array('heading' => Craft::t('Width'), 'class' => 'code', 'type' => 'singleline', 'width' => 50), 'type' => array('heading' => Craft::t('Type'), 'class' => 'thin', 'type' => 'select', 'options' => array('singleline' => Craft::t('Single-line Text'), 'multiline' => Craft::t('Multi-line text'), 'number' => Craft::t('Number'), 'checkbox' => Craft::t('Checkbox'))));
     craft()->templates->includeJsResource('js/TableFieldSettings.js');
     craft()->templates->includeJs('new Craft.TableFieldSettings(' . JsonHelper::encode($columns) . ', ' . JsonHelper::encode($defaults) . ', ' . JsonHelper::encode($columnSettings) . ');');
     $columnsField = craft()->templates->renderMacro('_includes/forms', 'editableTableField', array(array('label' => Craft::t('Table Columns'), 'instructions' => Craft::t('Define the columns your table should have.'), 'id' => 'columns', 'name' => 'columns', 'cols' => $columnSettings, 'rows' => $columns, 'addRowLabel' => Craft::t('Add a column'), 'initJs' => false)));
     $defaultsField = craft()->templates->renderMacro('_includes/forms', 'editableTableField', array(array('label' => Craft::t('Default Values'), 'instructions' => Craft::t('Define the default values for the field.'), 'id' => 'defaults', 'name' => 'defaults', 'cols' => $columns, 'rows' => $defaults, 'initJs' => false)));
     return $columnsField . $defaultsField;
 }
 /**
  * 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_Reports'))->queryAll();
     if ($rows) {
         foreach ($rows as $row) {
             $settings = JsonHelper::decode($row['settings']);
             if (!empty($settings['type'])) {
                 switch ($settings['type']) {
                     case 'visits':
                         $newSettings = array('menu' => "audienceOverview", 'dimension' => "", 'metric' => 'ga:sessions', 'chart' => "area", 'period' => "month");
                         break;
                     case 'geo':
                         $newSettings = array("menu" => "location", "dimension" => "ga:country", "metric" => "ga:pageviewsPerSession", "chart" => "geo", "period" => "month");
                         break;
                     case 'mobile':
                         $newSettings = array("menu" => "mobile", "dimension" => "ga:deviceCategory", "metric" => "ga:sessions", "chart" => "pie", "period" => "week");
                         break;
                     case 'pages':
                         $newSettings = array("menu" => "allPages", "dimension" => "ga:pagePath", "metric" => "ga:pageviews", "chart" => "table", "period" => "week");
                         break;
                     case 'acquisition':
                         $newSettings = array("menu" => "allChannels", "dimension" => "ga:channelGrouping", "metric" => "ga:sessions", "chart" => "table", "period" => "week");
                         break;
                     case 'technology':
                         $newSettings = array("menu" => "browserOs", "dimension" => "ga:browser", "metric" => "ga:sessions", "chart" => "pie", "period" => "week");
                         break;
                     case 'conversions':
                         $newSettings = array("menu" => "goals", "dimension" => "ga:goalCompletionLocation", "metric" => "ga:goalCompletionsAll", "chart" => "area", "period" => "week");
                         break;
                     case 'counts':
                     case 'custom':
                     case 'realtime':
                         $newSettings = array('menu' => "audienceOverview", 'dimension' => "", 'metric' => 'ga:sessions', 'chart' => "area", 'period' => "month");
                         break;
                 }
                 // update rows
                 $newSettings = JsonHelper::encode($newSettings);
                 $updateCmd = craft()->db->createCommand()->update('widgets', array('type' => 'Analytics_Explorer', 'settings' => $newSettings), 'id=:id', array('id' => $row['id']));
             }
         }
     }
     return true;
 }
 public function getInputHtml($name, $value)
 {
     // Settings
     $settings = $this->getSettings();
     $aceBasePath = UrlHelper::getResourceUrl('aceeditor/vendor/ace/');
     $inputId = craft()->templates->formatInputId($name);
     // Data
     $data = (include CRAFT_PLUGINS_PATH . 'aceeditor/data/AceEditorData.php');
     // Resources
     craft()->templates->includeCssResource('aceeditor/stylesheets/editor.css');
     craft()->templates->includeJsFile('https://cloud9ide.github.io/emmet-core/emmet.js');
     craft()->templates->includeJsResource('aceeditor/vendor/ace/ace.js');
     craft()->templates->includeJsResource('aceeditor/vendor/ace/theme-twilight.js');
     craft()->templates->includeJsResource('aceeditor/vendor/ace/ext-emmet.js');
     craft()->templates->includeJsResource('aceeditor/vendor/ace/ext-language_tools.js');
     craft()->templates->includeJsResource('aceeditor/javascripts/editor.js');
     craft()->templates->includeJs('new Craft.AceEditorFT("' . craft()->templates->namespaceInputId($inputId) . '","' . $aceBasePath . '",' . JsonHelper::encode($settings) . ');');
     // Template
     return craft()->templates->render('aceeditor/_fieldtype/index', array("name" => $name, "id" => $inputId, "value" => $value, "settings" => $settings, "modes" => $data['modes']));
 }
示例#27
0
 /**
  * Saves an export map to the database.
  *
  * @param array $settings
  * @param array $map
  */
 public function saveMap(array $settings, array $map)
 {
     // Unset non-map settings
     unset($settings['limit'], $settings['offset']);
     ksort($settings);
     // Set criteria
     $criteria = new \CDbCriteria();
     $criteria->condition = 'settings = :settings';
     $criteria->params = array(':settings' => JsonHelper::encode($settings));
     // Check if we have a map already
     $mapRecord = Export_MapRecord::model()->find($criteria);
     if (!count($mapRecord) || $mapRecord->settings != $settings) {
         // Save settings and map to database
         $mapRecord = new Export_MapRecord();
         $mapRecord->settings = $settings;
     }
     // Save new map to db
     $mapRecord->map = $map;
     $mapRecord->save(false);
 }
示例#28
0
 public function getSettingsHtml()
 {
     $columns = $this->getSettings()->columns;
     $tableData = $this->getSettings()->tableData;
     if (!$columns) {
         $columns = array('col1' => array('heading' => '', 'handle' => '', 'type' => 'singleline'));
         // Update the actual settings model for getInputHtml()
         $this->getSettings()->columns = $columns;
     }
     if ($tableData === null) {
         $tableData = array('row1' => array());
     }
     $columnSettings = array('heading' => array('heading' => Craft::t('Column Heading'), 'type' => 'singleline', 'autopopulate' => 'handle'), 'handle' => array('heading' => Craft::t('Handle'), 'class' => 'code', 'type' => 'singleline'), 'width' => array('heading' => Craft::t('Width'), 'class' => 'code', 'type' => 'singleline', 'width' => 50), 'type' => array('heading' => Craft::t('Type'), 'class' => 'thin', 'type' => 'select', 'options' => array('label' => Craft::t('Label'), 'singleline' => Craft::t('Single-line Text'), 'multiline' => Craft::t('Multi-line text'), 'number' => Craft::t('Number'), 'checkbox' => Craft::t('Checkbox'))));
     craft()->templates->includeCssResource('settable/css/settable.css');
     craft()->templates->includeJsResource('js/TableFieldSettings.js');
     craft()->templates->includeJs('new Craft.TableFieldSettings(' . '"' . craft()->templates->namespaceInputName('columns') . '", ' . '"' . craft()->templates->namespaceInputName('tableData') . '", ' . JsonHelper::encode($columns) . ', ' . JsonHelper::encode($tableData) . ', ' . JsonHelper::encode($columnSettings) . ');');
     $columnsField = craft()->templates->render('settable/settings', array('label' => Craft::t('Table Columns'), 'instructions' => Craft::t('Define the columns your table should have.'), 'id' => 'columns', 'name' => 'columns', 'cols' => $columnSettings, 'rows' => $columns, 'addRowLabel' => Craft::t('Add a column'), 'initJs' => false));
     $tableDataField = craft()->templates->render('settable/settings', array('label' => Craft::t('Table Values'), 'instructions' => Craft::t('Define the set values for the field.'), 'id' => 'tableData', 'name' => 'tableData', 'cols' => $columns, 'rows' => $tableData, 'initJs' => false));
     return $columnsField . $tableDataField;
 }
 /**
  * Any migration code in here is wrapped inside of a transaction.
  *
  * @return bool
  */
 public function safeUp()
 {
     MigrationHelper::refresh();
     $addFkBack = false;
     if (craft()->db->tableExists('tagsets')) {
         // A couple people have had failed updates that resulted in tagsets *and* taggroups tables lying around
         // causing a MySQL error if trying to rename the tagsets table
         // so let's make sure it's gone first.
         if (craft()->db->tableExists('taggroups')) {
             MigrationHelper::dropForeignKeyIfExists('taggroups', array('fieldLayoutId'));
             if (craft()->db->columnExists('tags', 'groupId')) {
                 MigrationHelper::dropForeignKeyIfExists('tags', array('groupId'));
                 MigrationHelper::renameColumn('tags', 'groupId', 'setId');
                 $addFkBack = true;
             }
             $this->dropTable('taggroups');
             // ...and refresh the schema cache
             craft()->db->getSchema()->refresh();
         }
         Craft::log('Renaming the tagsets table to taggroups.', LogLevel::Info, true);
         MigrationHelper::renameTable('tagsets', 'taggroups');
     }
     if (craft()->db->columnExists('tags', 'setId')) {
         Craft::log('Renaming the tags.setId column to groupId.', LogLevel::Info, true);
         MigrationHelper::renameColumn('tags', 'setId', 'groupId');
     }
     if ($addFkBack) {
         $this->addForeignKey('tags', 'groupId', 'taggroups', 'id', null, 'CASCADE');
     }
     Craft::log('Updating the Tags fields\' settings.', LogLevel::Info, true);
     $fields = craft()->db->createCommand()->select('id, settings')->from('fields')->where('type="Tags"')->queryAll();
     foreach ($fields as $field) {
         $settings = JsonHelper::decode($field['settings']);
         if (isset($settings['source']) && strncmp($settings['source'], 'tagset:', 7) === 0) {
             $settings['source'] = 'taggroup:' . substr($settings['source'], 7);
             $this->update('fields', array('settings' => JsonHelper::encode($settings)), array('id' => $field['id']));
         }
     }
     return true;
 }
    /**
     * @inheritDoc IElementAction::getTriggerHtml()
     *
     * @return string|null
     */
    public function getTriggerHtml()
    {
        $undeletableIds = JsonHelper::encode($this->_getUndeletableUserIds());
        $js = <<<EOT
(function()
{
\tvar trigger = new Craft.ElementActionTrigger({
\t\thandle: 'DeleteUsers',
\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 (\$.inArray(\$selectedItems.eq(i).find('.element').data('id').toString(), {$undeletableIds}) != -1)
\t\t\t\t{
\t\t\t\t\treturn false;
\t\t\t\t}
\t\t\t}

\t\t\treturn true;
\t\t},
\t\tactivate: function(\$selectedItems)
\t\t{
\t\t\tvar modal = new Craft.DeleteUserModal(Craft.elementIndex.getSelectedElementIds(), {
\t\t\t\tonSubmit: function()
\t\t\t\t{
\t\t\t\t\tCraft.elementIndex.submitAction('DeleteUsers', Garnish.getPostData(modal.\$container));
\t\t\t\t\tmodal.hide();

\t\t\t\t\treturn false;
\t\t\t\t}
\t\t\t});
\t\t}
\t});
})();
EOT;
        craft()->templates->includeJs($js);
    }