public function actionCheckRequirements()
 {
     $dependencies = craft()->socialPoster_plugin->checkRequirements();
     if ($dependencies) {
         $this->renderTemplate('socialposter/_special/dependencies', array('dependencies' => $dependencies));
     }
 }
 /**
  * Action Handle
  *
  * @param array $variables Variables
  *
  * @return void
  */
 public function actionHandle(array $variables = [])
 {
     $request = craft()->httpMessages->getRequest($variables);
     $response = craft()->httpMessages->getResponse();
     $response = craft()->httpMessages->handle($request, $response);
     $response->send();
 }
 private function updateAdminbarSettings(array $settings = array())
 {
     $plugin = craft()->plugins->getPlugin('Adminbar');
     $savedSettings = $plugin->getSettings()->getAttributes();
     $newSettingsRow = array_merge($savedSettings, $settings);
     return craft()->plugins->savePluginSettings($plugin, $newSettingsRow);
 }
    /**
     * @inheritDoc IElementAction::getTriggerHtml()
     *
     * @return string|null
     */
    public function getTriggerHtml()
    {
        $js = <<<EOT
(function()
{
\tvar trigger = new Craft.ElementActionTrigger({
\t\thandle: 'View',
\t\tbatch: false,
\t\tvalidateSelection: function(\$selectedItems)
\t\t{
\t\t\tvar \$element = \$selectedItems.find('.element');

\t\t\treturn (
\t\t\t\t\$element.data('url') &&
\t\t\t\t(\$element.data('status') == 'enabled' || \$element.data('status') == 'live')
\t\t\t);
\t\t},
\t\tactivate: function(\$selectedItems)
\t\t{
\t\t\twindow.open(\$selectedItems.find('.element').data('url'));
\t\t}
\t});
})();
EOT;
        craft()->templates->includeJs($js);
    }
 protected function getMinElapsedTime()
 {
     if ($elapsedTime = craft()->sproutInvisibleCaptcha->getMethodOption('elapsedTime')) {
         return $elapsedTime;
     }
     return self::MIN_ELAPSED_TIME;
 }
 /**
  * Normalize Submission For Elements Table
  *
  */
 public function normalizeDataForElementsTable()
 {
     $data = json_decode($this->submission, true);
     // Pop off the first (4) items from the data array
     $data = array_slice($data, 0, 4);
     $newData = '<ul>';
     foreach ($data as $key => $value) {
         $fieldHandle = craft()->fields->getFieldByHandle($key);
         $capitalize = ucfirst($key);
         $removeUnderscore = str_replace('_', ' ', $key);
         $valueArray = is_array($value);
         if ($valueArray == '1') {
             $newData .= '<li class="left icon" style="margin-right:10px;"><strong>' . $fieldHandle . '</strong>: ';
             foreach ($value as $item) {
                 if ($item != '') {
                     $newData .= $item;
                     if (next($value) == true) {
                         $newData .= ', ';
                     }
                 }
             }
         } else {
             if ($value != '') {
                 $newData .= '<li class="left icon" style="margin-right:10px;"><strong>' . $fieldHandle . '</strong>: ' . $value . '</li>';
             }
         }
     }
     $newData .= '</ul>';
     $this->__set('submission', $newData);
     return $this;
 }
Ejemplo n.º 7
0
 /**
  * Returns an element type.
  *
  * @param string $class
  *
  * @return ElementTypeVariable|null
  */
 public function getElementType($class)
 {
     $elementType = craft()->elements->getElementType($class);
     if ($elementType) {
         return new ElementTypeVariable($elementType);
     }
 }
Ejemplo n.º 8
0
 /**
  * Returns a new ParsedownExtra instance.
  *
  * @access private
  * @return \ParsedownExtra
  */
 private function _getParsedown()
 {
     if (!class_exists('\\ParsedownExtra')) {
         require_once craft()->path->getPluginsPath() . 'markdown/vendor/autoload.php';
     }
     return new \ParsedownExtra();
 }
 /**
  * Prioritize our meta data
  * ------------------------------------------------------------
  *
  * Loop through and select the highest ranking value for each attribute in our SproutSeo_MetaData model
  *
  * 1) Entry Override (Set by adding `id` override in Twig template code and using Meta Fields)
  * 2) On-Page Override (Set in Twig template code)
  * 3) Default (Set in control panel)
  * 4) Global Fallback (Set in control panel)
  * 5) Blank (Automatic)
  *
  * Once we have added all the content we need to be outputting to our array we will loop through that array and create the HTML we will output to our page.
  *
  * While we don't define HTML in our PHP as much as possible, the goal here is to be as easy to use as possible on the front end so we want to simplify the front end code to a single function and wrangle what we need to here.
  *
  * @return array
  * @throws \Exception
  */
 public function getOptimizedMeta()
 {
     $entryOverrideMetaModel = new SproutSeo_MetaModel();
     $codeOverrideMetaModel = new SproutSeo_MetaModel();
     $defaultMetaModel = new SproutSeo_MetaModel();
     $globalFallbackMetaModel = new SproutSeo_MetaModel();
     // Prepare a SproutSeo_MetaModel for each of our levels of priority
     $entryOverrideMetaModel = $entryOverrideMetaModel->setMeta('entry', $this->getMeta());
     $codeOverrideMetaModel = $codeOverrideMetaModel->setMeta('code', $this->getMeta());
     $defaultMetaModel = $defaultMetaModel->setMeta('default', $this->getMeta());
     $globalFallbackMetaModel = $globalFallbackMetaModel->setMeta('fallback');
     $prioritizedMetaModel = new SproutSeo_MetaModel();
     $this->divider = craft()->plugins->getPlugin('sproutseo')->getSettings()->seoDivider;
     // Default to the Current URL
     $prioritizedMetaModel->canonical = SproutSeoMetaHelper::prepareCanonical($prioritizedMetaModel);
     foreach ($prioritizedMetaModel->getAttributes() as $key => $value) {
         // Test for a value on each of our models in their order of priority
         if ($entryOverrideMetaModel->getAttribute($key)) {
             $prioritizedMetaModel[$key] = $entryOverrideMetaModel[$key];
         } elseif ($codeOverrideMetaModel->getAttribute($key)) {
             $prioritizedMetaModel[$key] = $codeOverrideMetaModel[$key];
         } elseif ($defaultMetaModel->getAttribute($key)) {
             $prioritizedMetaModel[$key] = $defaultMetaModel->getAttribute($key);
         } elseif ($globalFallbackMetaModel->getAttribute($key)) {
             $prioritizedMetaModel[$key] = $globalFallbackMetaModel->getAttribute($key);
         } else {
             $prioritizedMetaModel[$key] = $prioritizedMetaModel->getAttribute($key);
         }
     }
     // @todo - reorganize how this stuff works / robots need love.
     $prioritizedMetaModel->title = SproutSeoMetaHelper::prepareAppendedSiteName($prioritizedMetaModel, $defaultMetaModel, $globalFallbackMetaModel);
     $prioritizedMetaModel->robots = SproutSeoMetaHelper::prepRobotsAsString($prioritizedMetaModel->robots);
     return $prioritizedMetaModel;
 }
Ejemplo n.º 10
0
 /**
  * Mock ElementsService.
  */
 private function setMockElementsService()
 {
     $mock = $this->getMockBuilder('Craft\\ElementsService')->disableOriginalConstructor()->setMethods(array('getCriteria'))->getMock();
     $criteria = $this->getMockElementCriteriaModel();
     $mock->expects($this->any())->method('getCriteria')->willReturn($criteria);
     $this->setComponent(craft(), 'elements', $mock);
 }
Ejemplo n.º 11
0
 function init()
 {
     if (craft()->request->isCpRequest() && craft()->userSession->isLoggedIn()) {
         craft()->templates->includeJsResource("zipassets/js/zipassets.js");
         craft()->templates->includeCssResource("zipassets/css/zipassets.css");
     }
 }
Ejemplo n.º 12
0
 /**
  * Download zipfile.
  *
  * @param array  $files
  * @param string $filename
  *
  * @return string
  */
 public function download($files, $filename)
 {
     // Get assets
     $criteria = craft()->elements->getCriteria(ElementType::Asset);
     $criteria->id = $files;
     $criteria->limit = null;
     $assets = $criteria->find();
     // Set destination zip
     $destZip = craft()->path->getTempPath() . $filename . '_' . time() . '.zip';
     // Create the zipfile
     IOHelper::createFile($destZip);
     // Loop through assets
     foreach ($assets as $asset) {
         // Get asset source
         $source = $asset->getSource();
         // Get asset source type
         $sourceType = $source->getSourceType();
         // Get asset file
         $file = $sourceType->getLocalCopy($asset);
         // Add to zip
         Zip::add($destZip, $file, dirname($file));
     }
     // Return zip destination
     return $destZip;
 }
 /**
  * Any migration code in here is wrapped inside of a transaction.
  *
  * @return bool
  */
 public function safeUp()
 {
     if (!craft()->db->columnExists('entryversions', 'num')) {
         // Add the `num` column
         $columnConfig = array('maxLength' => 6, 'decimals' => 0, 'column' => 'smallint', 'unsigned' => true);
         $this->addColumnAfter('entryversions', 'num', $columnConfig, 'locale');
         $versionCountsByEntryIdAndLocale = array();
         // Populate it in batches
         $offset = 0;
         do {
             $versions = craft()->db->createCommand()->select('id, entryId, locale')->from('entryversions')->order('dateCreated asc')->offset($offset)->limit(100)->queryAll();
             foreach ($versions as $version) {
                 $entryId = $version['entryId'];
                 $locale = $version['locale'];
                 if (!isset($versionCountsByEntryIdAndLocale[$entryId][$locale])) {
                     $versionCountsByEntryIdAndLocale[$entryId][$locale] = 1;
                 } else {
                     $versionCountsByEntryIdAndLocale[$entryId][$locale]++;
                 }
                 $this->update('entryversions', array('num' => $versionCountsByEntryIdAndLocale[$entryId][$locale]), array('id' => $version['id']));
             }
             $offset += 100;
         } while (count($versions) == 100);
         // Set the `num` column to NOT NULL
         $columnConfig['null'] = false;
         $this->alterColumn('entryversions', 'num', $columnConfig);
     }
     return true;
 }
 /**
  * Given a path, look for an obsolete URL from the revisions
  *
  * @return EntryModel or null
  */
 public function locateEntry($path)
 {
     $slug = array_pop($path);
     $prefix = join("/", $path);
     // Check that there's even a slug to work with
     if ($slug === '') {
         return false;
     }
     // Element conditions
     $element_conditions = array('and', 'elements_i18n.enabled = 1', 'elements.enabled = 1', 'elements.archived = 0');
     // Slug conditions
     $slug_conditions = array('like', 'entryversions.data', '%"slug":"' . $slug . '"%');
     // Query for (or against) a path prefix
     if (empty($prefix)) {
         // Ensure the prefixed segments do NOT exist in the URI
         $path_conditions = array('not like', 'elements_i18n.uri', '%/%');
     } else {
         // Ensure the prefixed segments DO exist in the URI
         $path_conditions = array('like', 'elements_i18n.uri', $prefix . '/%');
     }
     // Query for matching revisions
     $query = craft()->db->createCommand()->select('elements.id')->from('elements elements')->join('elements_i18n elements_i18n', 'elements_i18n.elementId = elements.id')->join('entryversions entryversions', 'entryversions.entryId = elements.id')->where($element_conditions)->andWhere($slug_conditions)->andWhere($path_conditions)->order('entryversions.dateUpdated DESC')->limit(1);
     // ObsoleteRedirectPlugin::log($query->text);
     $result = $query->queryRow();
     if ($result) {
         // Get the element's EntryModel
         $criteria = craft()->elements->getCriteria(ElementType::Entry);
         $criteria->id = $result['id'];
         // Return the actual element
         return $criteria->first();
     }
 }
 public function safeUp()
 {
     $tableName = 'plainform_entries';
     if (!craft()->db->columnExists($tableName, 'ip')) {
         $this->addColumn($tableName, 'ip', array('column' => ColumnType::Varchar, 'null' => true, 'default' => null));
     }
 }
Ejemplo n.º 16
0
 /**
  * Enforces all Edit Entry permissions.
  *
  * @param EntryModel $entry
  *
  * @return null
  */
 protected function enforceEditEntryPermissions(EntryModel $entry)
 {
     $userSessionService = craft()->userSession;
     $permissionSuffix = ':' . $entry->sectionId;
     if (craft()->isLocalized()) {
         // Make sure they have access to this locale
         $userSessionService->requirePermission('editLocale:' . $entry->locale);
     }
     // Make sure the user is allowed to edit entries in this section
     $userSessionService->requirePermission('editEntries' . $permissionSuffix);
     // Is it a new entry?
     if (!$entry->id) {
         // Make sure they have permission to create new entries in this section
         $userSessionService->requirePermission('createEntries' . $permissionSuffix);
     } else {
         switch ($entry->getClassHandle()) {
             case 'Entry':
                 // If it's another user's entry (and it's not a Single), make sure they have permission to edit those
                 if ($entry->authorId != $userSessionService->getUser()->id && $entry->getSection()->type != SectionType::Single) {
                     $userSessionService->requirePermission('editPeerEntries' . $permissionSuffix);
                 }
                 break;
             case 'EntryDraft':
                 // If it's another user's draft, make sure they have permission to edit those
                 if ($entry->getClassHandle() == 'EntryDraft' && $entry->creatorId != $userSessionService->getUser()->id) {
                     $userSessionService->requirePermission('editPeerEntryDrafts' . $permissionSuffix);
                 }
                 break;
         }
     }
 }
 public function enabled($feature = '')
 {
     $baseState = false;
     if ($feature == '') {
         return true;
     }
     $enabled = craft()->config->get('featureEnabled');
     $user = craft()->userSession->getUser();
     if (!isset($enabled[$feature])) {
         $baseState = false;
     } elseif ($enabled[$feature]) {
         $baseState = true;
     }
     // If they're not logged in
     // return the base state
     if ($user == null) {
         return $baseState;
     }
     // They're logged in.
     // We have a few options here
     // Admins see all the things
     // Certain users can have features enabled for them
     if (craft()->userSession->isAdmin()) {
         $baseState = true;
     } else {
         // They might have specific options to see this feature
         // Check out special permissions
         if ($user->can('betaTester')) {
             $baseState = true;
         }
     }
     return $baseState;
 }
 /**
  * Any migration code in here is wrapped inside of a transaction.
  *
  * @return bool
  */
 public function safeUp()
 {
     if (!craft()->db->columnExists('assettransforms', 'quality')) {
         $this->addColumnAfter('assettransforms', 'quality', array('column' => ColumnType::Int, 'required' => false), 'width');
     }
     return true;
 }
 /**
  * Reset count
  */
 public function actionReset()
 {
     $entryId = craft()->request->getRequiredParam('entryId');
     craft()->entryCount->reset($entryId);
     craft()->userSession->setNotice(Craft::t('Entry count reset.'));
     $this->redirect('entrycount');
 }
Ejemplo n.º 20
0
 /**
  * @inheritDoc IFieldType::getInputHtml()
  *
  * @param string $name
  * @param mixed  $value
  *
  * @return string
  */
 public function getInputHtml($name, $value)
 {
     if ($this->isFresh() && ($value < $this->settings->min || $value > $this->settings->max)) {
         $value = $this->settings->min;
     }
     return craft()->templates->render('_includes/forms/text', array('name' => $name, 'value' => craft()->numberFormatter->formatDecimal($value, false), 'size' => 5));
 }
Ejemplo n.º 21
0
 public function init()
 {
     if (craft()->request->isCpRequest()) {
         // Get settings
         $settings = $this->getSettings();
         if ($settings->scriptButtons === "1") {
             craft()->templates->includeJsResource('redactorextras/plugins/scriptbuttons.js');
         }
         if ($settings->counter === "1") {
             craft()->templates->includeJsResource('redactorextras/plugins/counter.js');
         }
         if ($settings->alignment === "1") {
             craft()->templates->includeJsResource('redactorextras/plugins/alignment.js');
             craft()->templates->includeCssResource('redactorextras/plugins/alignment.css');
         }
         if ($settings->limiter === "1") {
             craft()->templates->includeJsResource('redactorextras/plugins/limiter.js');
         }
         if ($settings->extraPluginJs != "") {
             craft()->templates->includeJsFile($settings->extraPluginJs);
         }
         if ($settings->extraPluginCss != "") {
             craft()->templates->includeCssFile($settings->extraPluginCss);
         }
     }
 }
 public function actionAdd()
 {
     $this->requirePostRequest();
     //required fields
     $listId = craft()->request->getParam('listId');
     $email = craft()->request->getParam('email');
     //optional fields with defaults
     $name = craft()->request->getParam('name') ?: '';
     $customFields = craft()->request->getParam('customFields') ?: array();
     $resubscribe = craft()->request->getParam('resubscribe') ?: true;
     $error = null;
     try {
         craft()->oneCampaignMonitor_subscribers->add($listId, $email, $name, $customFields, $resubscribe);
     } catch (Exception $e) {
         $error = $e->getMessage();
     }
     //return json for ajax requests, redirect to posted url otherwise
     if (craft()->request->isAjaxRequest()) {
         $this->returnJson(['success' => is_null($error), 'error' => $error]);
     } else {
         craft()->userSession->setFlash('oneCampaignMonitor_addSubscriberSuccess', is_null($error));
         craft()->userSession->setFlash('oneCampaignMonitor_addSubscriberMessage', Craft::t($error ?: 'Success!'));
         $this->redirectToPostedUrl();
     }
 }
Ejemplo n.º 23
0
 /**
  * Settings
  *
  * @return null
  */
 public function actionSettings()
 {
     craft()->twitter_plugin->requireDependencies();
     $plugin = craft()->plugins->getPlugin('twitter');
     $variables = array('provider' => false, 'account' => false, 'token' => false, 'error' => false);
     $provider = craft()->oauth->getProvider('twitter');
     if ($provider && $provider->isConfigured()) {
         $token = craft()->twitter_oauth->getToken();
         if ($token) {
             try {
                 $account = craft()->twitter_cache->get(['getAccount', $token]);
                 if (!$account) {
                     $account = $provider->getAccount($token);
                     craft()->twitter_cache->set(['getAccount', $token], $account);
                 }
                 if ($account) {
                     Craft::log("Twitter OAuth Account:\r\n" . print_r($account, true), LogLevel::Info);
                     $variables['account'] = $account;
                     $variables['settings'] = $plugin->getSettings();
                 }
             } catch (\Exception $e) {
                 if (method_exists($e, 'getResponse')) {
                     Craft::log("Couldn’t get account: " . $e->getResponse(), LogLevel::Error);
                 } else {
                     Craft::log("Couldn’t get account: " . $e->getMessage(), LogLevel::Error);
                 }
                 $variables['error'] = $e->getMessage();
             }
         }
         $variables['token'] = $token;
         $variables['provider'] = $provider;
     }
     $this->renderTemplate('twitter/settings', $variables);
 }
 /**
  * Any migration code in here is wrapped inside of a transaction.
  *
  * @return bool
  */
 public function safeUp()
 {
     if (!craft()->db->columnExists('elements_i18n', 'slug')) {
         Craft::log('Creating an elements_i18n.slug column.', LogLevel::Info, true);
         $this->addColumnAfter('elements_i18n', 'slug', ColumnType::Varchar, 'locale');
     }
     if (craft()->db->tableExists('entries_i18n')) {
         Craft::log('Copying the slugs from entries_i18n into elements_i18n.', LogLevel::Info, true);
         $rows = craft()->db->createCommand()->select('entryId, locale, slug')->from('entries_i18n')->queryAll();
         foreach ($rows as $row) {
             $this->update('elements_i18n', array('slug' => $row['slug']), array('elementId' => $row['entryId'], 'locale' => $row['locale']));
         }
         Craft::log('Dropping the entries_i18n table.');
         $this->dropTable('entries_i18n');
     }
     if (!craft()->db->columnExists('elements_i18n', 'enabled')) {
         Craft::log('Creating an elements_i18n.enabled column.', LogLevel::Info, true);
         $this->addColumnAfter('elements_i18n', 'enabled', array('column' => ColumnType::Bool, 'default' => true), 'uri');
     }
     MigrationHelper::refresh();
     MigrationHelper::dropIndexIfExists('elements_i18n', array('slug', 'locale'));
     MigrationHelper::dropIndexIfExists('elements_i18n', array('enabled'));
     $this->createIndex('elements_i18n', 'slug,locale');
     $this->createIndex('elements_i18n', 'enabled');
     return true;
 }
 /**
  * Any migration code in here is wrapped inside of a transaction.
  *
  * @return bool
  */
 public function safeUp()
 {
     // Create the categorygroups table
     if (!craft()->db->tableExists('categorygroups')) {
         Craft::log('Creating the categorygroups table', LogLevel::Info, true);
         $this->createTable('categorygroups', array('structureId' => array('column' => ColumnType::Int, 'null' => false), 'fieldLayoutId' => array('column' => ColumnType::Int), 'name' => array('column' => ColumnType::Varchar, 'required' => true), 'handle' => array('column' => ColumnType::Varchar, 'required' => true), 'hasUrls' => array('column' => ColumnType::Bool, 'required' => true, 'default' => true), 'template' => array('column' => ColumnType::Varchar, 'maxLength' => 500)));
         $this->createIndex('categorygroups', 'name', true);
         $this->createIndex('categorygroups', 'handle', true);
         $this->addForeignKey('categorygroups', 'structureId', 'structures', 'id', 'CASCADE');
         $this->addForeignKey('categorygroups', 'fieldLayoutId', 'fieldlayouts', 'id', 'SET NULL');
     }
     // Create the categorygroups_i18n table
     if (!craft()->db->tableExists('categorygroups_i18n')) {
         Craft::log('Creating the categorygroups_i18n table', LogLevel::Info, true);
         $this->createTable('categorygroups_i18n', array('groupId' => array('column' => ColumnType::Int, 'required' => true), 'locale' => array('column' => ColumnType::Locale, 'required' => true), 'urlFormat' => array('column' => ColumnType::Varchar), 'nestedUrlFormat' => array('column' => ColumnType::Varchar)));
         $this->createIndex('categorygroups_i18n', 'groupId,locale', true);
         $this->addForeignKey('categorygroups_i18n', 'groupId', 'categorygroups', 'id', 'CASCADE');
         $this->addForeignKey('categorygroups_i18n', 'locale', 'locales', 'locale', 'CASCADE', 'CASCADE');
     }
     // Create the categories table
     if (!craft()->db->tableExists('categories')) {
         Craft::log('Creating the categories table', LogLevel::Info, true);
         $this->createTable('categories', array('id' => array('column' => ColumnType::Int, 'required' => true, 'primaryKey' => true), 'groupId' => array('column' => ColumnType::Int, 'required' => true)), null, false);
         $this->addForeignKey('categories', 'id', 'elements', 'id', 'CASCADE');
         $this->addForeignKey('categories', 'groupId', 'categorygroups', 'id', 'CASCADE');
     }
     return true;
 }
 /**
  * Any migration code in here is wrapped inside of a transaction.
  *
  * @return bool
  */
 public function safeUp()
 {
     // Make sure an "assignUserPermissions" permission doesn't already exist
     $permissionExists = (bool) craft()->db->createCommand()->from('userpermissions')->where('name = "assignuserpermissions"')->count('id');
     if (!$permissionExists) {
         // Find all of the users that have the "administrateUsers" permission
         $userIds = craft()->db->createCommand()->select('up_u.userId')->from('userpermissions_users up_u')->join('userpermissions up', 'up.id = up_u.permissionId')->where('up.name = "administrateusers"')->queryColumn();
         // Find all of the user groups that have the "administrateUsers" permission
         $groupIds = craft()->db->createCommand()->select('up_g.groupId')->from('userpermissions_usergroups up_g')->join('userpermissions up', 'up.id = up_g.permissionId')->where('up.name = "administrateusers"')->queryColumn();
         if ($userIds || $groupIds) {
             // Add the new permission row and get its ID
             $this->insert('userpermissions', array('name' => 'assignuserpermissions'));
             $permissionId = craft()->db->getLastInsertID();
             // Assign any users with administrateUsers permission to the new one
             if ($userIds) {
                 $values = array();
                 foreach ($userIds as $userId) {
                     $values[] = array($permissionId, $userId);
                 }
                 $this->insertAll('userpermissions_users', array('permissionId', 'userId'), $values);
             }
             // Assign any user groups with administrateUsers permission to the new one
             if ($groupIds) {
                 $values = array();
                 foreach ($groupIds as $groupId) {
                     $values[] = array($permissionId, $groupId);
                 }
                 $this->insertAll('userpermissions_usergroups', array('permissionId', 'groupId'), $values);
             }
         }
     }
     return true;
 }
Ejemplo n.º 27
0
 /**
  * {@inheritdoc}
  */
 protected function fire()
 {
     $caches = '*';
     $tool = craft()->components->getComponentByTypeAndClass(ComponentType::Tool, 'ClearCaches');
     if ($this->option('select')) {
         $reflectionMethod = new ReflectionMethod($tool, '_getFolders');
         $reflectionMethod->setAccessible(true);
         $values = $reflectionMethod->invoke($tool);
         $values['assetTransformIndex'] = Craft::t('Asset transform index');
         $values['assetIndexingData'] = Craft::t('Asset indexing data');
         $values['templateCaches'] = Craft::t('Template caches');
         $keys = array_keys($values);
         $options = array_values($values);
         $dialog = $this->getHelper('dialog');
         $selected = $dialog->select($this->output, 'Select which caches to clear (separate multiple by comma)', $options, null, false, 'Value "%s" is invalid', true);
         $caches = array();
         foreach ($selected as $index) {
             $caches[] = $keys[$index];
         }
     }
     $this->suppressOutput(function () use($tool, $caches) {
         $tool->performAction(compact('caches'));
     });
     $this->info('Cache(s) cleared.');
 }
 /**
  * Returns the URL to a specific page
  *
  * @param int $page
  *
  * @return string|null
  */
 public function getPageUrl($page)
 {
     if ($page >= 1 && $page <= $this->totalPages) {
         $path = craft()->request->getPath();
         $params = array();
         if ($page != 1) {
             $pageTrigger = craft()->config->get('pageTrigger');
             if (!is_string($pageTrigger) || !strlen($pageTrigger)) {
                 $pageTrigger = 'p';
             }
             // Is this query string-based pagination?
             if ($pageTrigger[0] === '?') {
                 $pageTrigger = trim($pageTrigger, '?=');
                 if ($pageTrigger === 'p') {
                     // Avoid conflict with the main 'p' param
                     $pageTrigger = 'pg';
                 }
                 $params = array($pageTrigger => $page);
             } else {
                 if ($path) {
                     $path .= '/';
                 }
                 $path .= $pageTrigger . $page;
             }
         }
         return UrlHelper::getUrl($path, $params);
     }
 }
 /**
  * Initialize draft listeners
  */
 public function init()
 {
     craft()->on('entryRevisions.saveDraft', array(craft()->draftNotifications_eventCallback, 'saveDraftCallBack'));
     craft()->on('entryRevisions.deleteDraft', array(craft()->draftNotifications_eventCallback, 'deleteDraftCallBack'));
     craft()->on('entries.saveEntry', array(craft()->draftNotifications_eventCallback, 'saveEntryCallBack'));
     craft()->on('entries.deleteEntry', array(craft()->draftNotifications_eventCallback, 'deleteEntryCallBack'));
 }
Ejemplo n.º 30
0
 /**
  * @return DoxterPlugin|null
  */
 public function getPlugin()
 {
     if ($this->doxter === null) {
         $this->doxter = craft()->plugins->getPlugin('doxter');
     }
     return $this->doxter;
 }