/** * 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; }
/** * 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; }
/** * 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; }
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; }
/** * @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(); }
/** * 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; } }
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; }
/** * 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; }
public function actionReorderNav() { $this->requirePostRequest(); $this->requireAjaxRequest(); $navIds = JsonHelper::decode(craft()->request->getRequiredPost('ids')); $navs = craft()->cpNav_nav->reorderNav($navIds); $this->returnJson(array('success' => true, 'navs' => $navs)); }
/** * Reorders widgets. */ public function actionReorderUserWidgets() { $this->requirePostRequest(); $this->requireAjaxRequest(); $widgetIds = JsonHelper::decode(craft()->request->getRequiredPost('ids')); craft()->dashboard->reorderUserWidgets($widgetIds); $this->returnJson(array('success' => true)); }
/** * 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)); }
/** * Saves the new locale order. * * @return null */ public function actionReorderLocales() { $this->requirePostRequest(); $this->requireAjaxRequest(); $localeIds = JsonHelper::decode(craft()->request->getRequiredPost('ids')); $success = craft()->i18n->reorderSiteLocales($localeIds); $this->returnJson(array('success' => $success)); }
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); }
/** * Updates the announcements sort order. * * @return null */ public function actionReorderAnnouncements() { $this->requirePostRequest(); $this->requireAjaxRequest(); $announcementIds = JsonHelper::decode(craft()->request->getRequiredPost('ids')); $announcementIds = array_reverse($announcementIds); craft()->maintenance->reorderAnnouncements($announcementIds); $this->returnJson(array('success' => true)); }
/** * Save Settings to the Database * * @return mixed Return to Page */ public function actionSettingsIndexTemplate() { $settingsModel = new SproutForms_SettingsModel(); $settings = craft()->db->createCommand()->select('settings')->from('plugins')->where('class=:class', array(':class' => 'SproutForms'))->queryScalar(); $settings = JsonHelper::decode($settings); $settingsModel->setAttributes($settings); $variables['settings'] = $settingsModel; // Load our template $this->renderTemplate('sproutforms/settings', $variables); }
/** * Returns the element index settings for a given element type. * * @param string $elementTypeClass The element type class * * @return array|null */ public function getSettings($elementTypeClass) { if ($this->_indexSettings === null || !array_key_exists($elementTypeClass, $this->_indexSettings)) { $result = craft()->db->createCommand()->select('settings')->from('elementindexsettings')->where('type = :type', array(':type' => $elementTypeClass))->queryScalar(); if ($result) { $this->_indexSettings[$elementTypeClass] = JsonHelper::decode($result); } else { $this->_indexSettings[$elementTypeClass] = null; } } return $this->_indexSettings[$elementTypeClass]; }
/** * 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; }
/** * Save Settings to the Database * * @return mixed Return to Page */ public function actionSettingsIndex() { $settingsModel = new SproutSeo_SettingsModel(); // Create any variables you want available in your template // $variables['items'] = craft()->pluginName->getAllItems(); $settings = craft()->db->createCommand()->select('settings')->from('plugins')->where('class=:class', array(':class' => 'SproutSeo'))->queryScalar(); $settings = JsonHelper::decode($settings); $settingsModel->setAttributes($settings); $variables['settings'] = $settingsModel; // Load a particular template and with all of the variables you've created $this->renderTemplate('sproutseo/settings', $variables); }
/** * 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; }
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); }
/** * 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; }
/** * 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; }
/** * Returns the routes defined in the CP. * * @return array */ public function getDbRoutes() { $routes = array(); $results = craft()->db->createCommand()->select('id, locale, urlParts, template')->from('routes')->order('sortOrder')->queryAll(); foreach ($results as $result) { $urlDisplayHtml = ''; $urlParts = JsonHelper::decode($result['urlParts']); foreach ($urlParts as $part) { if (is_string($part)) { $urlDisplayHtml .= $part; } else { $urlDisplayHtml .= '<span class="token" data-name="' . $part[0] . '" data-value="' . $part[1] . '"><span>' . $part[0] . '</span></span>'; } } $routes[] = array('id' => $result['id'], 'locale' => $result['locale'], 'urlDisplayHtml' => $urlDisplayHtml, 'template' => $result['template']); } return $routes; }
/** * Returns all routes. */ public function getAllRoutes() { $return = array(); $routes = RouteRecord::model()->ordered()->findAll(); foreach ($routes as $route) { $urlDisplayHtml = ''; $urlParts = JsonHelper::decode($route->urlParts); foreach ($urlParts as $part) { if (is_string($part)) { $urlDisplayHtml .= $part; } else { $urlDisplayHtml .= '<span class="token" data-name="' . $part[0] . '" data-value="' . $part[1] . '">' . $part[0] . '</span>'; } } $return[] = array('id' => $route->id, 'urlDisplayHtml' => $urlDisplayHtml, 'template' => $route->template); } return $return; }
public function getFeed($url, $primaryElement) { if (false === ($raw_content = craft()->feedMe_feed->getRawData($url))) { craft()->userSession->setError(Craft::t('Unable to parse Feed URL.')); FeedMePlugin::log('Unable to parse Feed URL.', LogLevel::Error, true); return false; } // Parse the JSON string - using Yii's built-in cleanup $json_array = JsonHelper::decode($raw_content, true); // Look for and return only the items for primary element $json_array = craft()->feedMe_feed->findPrimaryElement($primaryElement, $json_array); if (!is_array($json_array)) { $error = 'Invalid JSON - ' . $this->getJsonError(); craft()->userSession->setError(Craft::t($error)); FeedMePlugin::log($error, LogLevel::Error, true); return false; } return $json_array; }
/** * 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; }
/** * 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; }
/** * Any migration code in here is wrapped inside of a transaction. * * @return bool */ public function safeUp() { // Migrate old settings across $settings = craft()->db->createCommand()->select('settings')->from('plugins')->where('class = :class', array(':class' => 'PimpMyMatrix'))->queryScalar(); if ($settings) { $decodedSettings = JsonHelper::decode($settings); if (isset($decodedSettings['buttonConfig'])) { PimpMyMatrixPlugin::log('Migrating old settings', LogLevel::Info, true); $buttonConfig = JsonHelper::decode($decodedSettings['buttonConfig']); foreach ($buttonConfig as $row) { $field = craft()->fields->getFieldByHandle($row['fieldHandle']); $blockTypes = craft()->matrix->getBlockTypesByFieldId($field->id); foreach ($row['config'] as $config) { $selectedBlocktypeId = null; foreach ($blockTypes as $blockType) { if ($blockType->handle == $config['blockType']['handle']) { $selectedBlocktypeId = $blockType->id; } } $pimpedBlockType = new PimpMyMatrix_BlockTypeModel(); $pimpedBlockType->fieldId = $field->id; $pimpedBlockType->matrixBlockTypeId = $selectedBlocktypeId; $pimpedBlockType->fieldLayoutId = null; $pimpedBlockType->groupName = urldecode($config['group']); $pimpedBlockType->context = 'global'; $success = craft()->pimpMyMatrix_blockTypes->saveBlockType($pimpedBlockType); if (!$success) { PimpMyMatrixPlugin::log("Config for the field {$row['fieldHandle']} could not be migrated", LogLevel::Info, true); } } } PimpMyMatrixPlugin::log('Done migrating old settings', LogLevel::Info, true); } } return true; }
/** * Loads the enabled plugins. * * @return null */ public function loadPlugins() { if (!$this->_pluginsLoaded && !$this->_loadingPlugins) { if (craft()->isInstalled()) { // Prevent this function from getting called twice. $this->_loadingPlugins = true; // Find all of the enabled plugins $rows = craft()->db->createCommand()->select('id, class, version, settings, installDate')->from('plugins')->where('enabled=1')->queryAll(); $names = array(); foreach ($rows as $row) { $plugin = $this->_getPlugin($row['class']); if ($plugin) { $this->_autoloadPluginClasses($plugin); // Clean it up a bit $row['settings'] = JsonHelper::decode($row['settings']); $row['installDate'] = DateTime::createFromString($row['installDate']); $this->_enabledPluginInfo[$row['class']] = $row; $lcPluginHandle = mb_strtolower($plugin->getClassHandle()); $this->_plugins[$lcPluginHandle] = $plugin; $this->_enabledPlugins[$lcPluginHandle] = $plugin; $names[] = $plugin->getName(); $plugin->setSettings($row['settings']); $plugin->isInstalled = true; $plugin->isEnabled = true; } } // Sort plugins by name array_multisort($names, $this->_enabledPlugins); // Now that all of the components have been imported, initialize all the plugins foreach ($this->_enabledPlugins as $plugin) { $plugin->init(); } $this->_loadingPlugins = false; } $this->_pluginsLoaded = true; // Fire an 'onLoadPlugins' event $this->onLoadPlugins(new Event($this)); } }
/** * Returns versions by an entry ID. * * @param int $entryId The entry ID to search for. * @param string $localeId The locale ID to search for. * @param int|null $limit The limit on the number of versions to retrieve. * @param bool $includeCurrent Whether to include the current "top" version of the entry. * * @return array */ public function getVersionsByEntryId($entryId, $localeId, $limit = null, $includeCurrent = false) { if (!$localeId) { $localeId = craft()->i18n->getPrimarySiteLocale(); } $versions = array(); $query = craft()->db->createCommand()->select('*')->from('entryversions')->where(array('and', 'entryId = :entryId', 'locale = :locale'), array(':entryId' => $entryId, ':locale' => $localeId))->order('dateCreated desc')->limit($limit); if (!$includeCurrent) { $query->offset(1); } $results = $query->queryAll(); foreach ($results as $result) { $result['data'] = JsonHelper::decode($result['data']); // Don't initialize the content unset($result['data']['fields']); $versions[] = EntryVersionModel::populateModel($result); } return $versions; }