public function preSave(PropelPDO $con = null) { if ((string) $this->getPriority() === '') { $this->setPriority($this->getAutoPriority($con)); } return parent::preSave($con); }
public function init() { require_once CRAFT_PLUGINS_PATH . 'oauth/vendor/autoload.php'; require_once CRAFT_PLUGINS_PATH . 'oauth/etc/providers/IOauth_Provider.php'; require_once CRAFT_PLUGINS_PATH . 'oauth/providers/BaseProvider.php'; parent::init(); }
public function init() { parent::init(); $user = craft()->userSession->getUser(); if (craft()->request->isCpRequest()) { $allNavs = craft()->cpNav_nav->getDefaultOrUserNavs(); if ($user) { if ($this->getSettings()->showQuickAddMenu && $user->can('quickAddMenu')) { $this->insertJsForQuickMenuAdd($allNavs); } } if ($allNavs) { foreach ($allNavs as $nav) { // Allow links to be opened in new window - insert some small JS if ($nav->newWindow) { $this->insertJsForNewWindow($nav); } // Check to ensure this page is enabled - otherwise simply redirect to first available menu item if (craft()->request->path == $nav->url) { if (!$nav->enabled) { $enabledNavs = craft()->cpNav_nav->getAllNavsByAttributes(array('enabled' => true)); // We're on a page that's disabled - redirect to the first enabled one! craft()->request->redirect(UrlHelper::getUrl($enabledNavs[0]->url)); } } else { if (craft()->request->path == preg_replace(sprintf('/^(https?:\\/\\/)?(%s)?\\/?%s\\//', preg_quote(craft()->getSiteUrl(''), '/'), preg_quote(craft()->config->get('cpTrigger')), '/'), '', $nav->url) && $nav->enabled && $nav->manualNav) { // Add some JavaScript to correct the selected nav item for manually added navigation items. // Have to do this with JavaScript for now as the nav item selection is made after the modifyCpNav hook. $this->insertJsForManualNavSelection($nav); } } } } } }
public function init() { parent::init(); if (craft()->request->isCpRequest()) { $this->_colorBlocks(); } }
public function init() { parent::init(); if ($this->isCraftRequiredVersion()) { $this->includeResources(); } }
public function init() { parent::init(); craft()->on('content.onSaveContent', function (Event $event) { craft()->recurringDate->contentSaved($event->params['content'], $event->params['isNewContent']); }); }
public function init() { parent::init(); if (craft()->request->isCpRequest()) { $this->_renderCss(); } }
public function init() { parent::init(); if (craft()->request->isCpRequest() && $this->isCraftRequiredVersion()) { $this->includeResources(); } }
public function init() { parent::init(); craft()->on('users.saveUser', function (Event $event) { // Set target group $targetGroups = craft()->plugins->getPlugin('autoAssignUserGroup')->getSettings()->userGroups; // Ensure all target groups exist $this->_ensureGroupsExist($targetGroups); // If target groups exist if ($targetGroups) { // If new user if ($event->params['isNewUser']) { // If "groups" is in POST if (isset($_POST['groups'])) { // If not an array, it's an empty string if (!is_array($_POST['groups'])) { // Set it to an array with the user group ID $_POST['groups'] = $targetGroups; } else { // Merge in the user group ID with any existing ones. $_POST['groups'] = array_merge($_POST['groups'], $targetGroups); } } } } }); }
public function init() { parent::init(); if (craft()->request->isCpRequest()) { craft()->templates->includeJsResource('manytomany/js/hide-input.js'); } }
public function init() { parent::init(); if (!craft()->request->isCpRequest() && craft()->userSession->getUser()) { craft()->templates->includeCssResource('anvil/css/main.css'); craft()->templates->includeJsResource('anvil/js/main.js'); craft()->anvil->renderEditBar(); } }
public function init() { parent::init(); $request = craft()->request; if (!$request->isCpRequest() || $request->isAjaxRequest() || craft()->isConsole() || !$this->isCraftRequiredVersion()) { return false; } $this->addResources(); }
public function init() { parent::init(); $request = craft()->request; if (!$request->isCpRequest() || $request->isAjaxRequest() || !craft()->config->get('devMode')) { return false; } $this->addResources(); }
public function init() { parent::init(); if (!craft()->request->isCpRequest() || !$this->isCraftRequiredVersion()) { return false; } $this->_addEventListeners(); $this->_addResources(); }
public function init() { parent::init(); if (craft()->varnishpurge->getSetting('varnishPurgeEnabled')) { // element saved craft()->on('elements.onSaveElement', function (Event $event) { craft()->varnishpurge->purgeElement($event->params['element'], craft()->varnishpurge->getSetting('varnishPurgeRelated')); }); } }
function Kuaidi100Plugin($data, $plugin_info) { $this->_config = $plugin_info; $this->_data = $data; $this->_url = 'http://api.kuaidi100.com/api?id=' . $this->_config['AppKey']; // 此接口返回 json,xml格式,自由配置高 $this->_url_spare = 'http://www.kuaidi100.com/applyurl?key=' . $this->_config['AppKey']; // 此接口返回固定格式的html,并带广告 parent::__construct($data, $plugin_info); }
public function init() { parent::init(); if (!$this->isCraftRequiredVersion()) { return false; } if (craft()->request->isCpRequest() && craft()->userSession->getUser()) { craft()->dashCols_layouts->init(); $this->includeResources(); } }
public function init() { parent::init(); craft()->on('sections.onSaveEntryType', function (Event $event) { if ($event->params['entryType']->handle == 'structure') { foreach (craft()->teamManager->getAllTeams() as $team) { $team->updateEntryType($event->params['entryType']->fieldLayoutId); } } }); }
public static function log($msg, $level = LogLevel::Info, $force = false) { if (self::$settings['debug']) { $force = true; } if (is_string($msg)) { $msg = "\n\n" . $msg . "\n"; } else { $msg = "\n\n" . print_r($msg, true) . "\n"; } parent::log($msg, $level, $force); }
public function init() { parent::init(); Craft::import('plugins.sproutemail.enums.*'); Craft::import('plugins.sproutemail.contracts.*'); Craft::import('plugins.sproutemail.integrations.sproutemail.*'); if (sproutEmailDefaultMailer()->enableDynamicLists()) { craft()->on('sproutCommerce.saveProduct', array(sproutEmailDefaultMailer(), 'handleSaveProduct')); craft()->on('sproutCommerce.checkoutEnd', array(sproutEmailDefaultMailer(), 'handleCheckoutEnd')); } sproutEmail()->notifications->registerDynamicEventHandler(); }
public function init() { parent::init(); if (!craft()->isConsole()) { if (craft()->request->isCpRequest() && craft()->request->getSegment(1) == 'mailer') { //Include JS craft()->templates->includeJsFile(UrlHelper::getResourceUrl('mailer/mailer.js')); //Turn Profiler off craft()->log->removeRoute('WebLogRoute'); craft()->log->removeRoute('ProfileLogRoute'); } } }
public function init() { parent::init(); if (craft()->request->isCpRequest()) { // get data for custom links $this->_customLinks(); } craft()->on('plugins.onLoadPlugins', array($this, 'onLoadPlugins')); // update settings if new settings aren't set if (!isset($this->getSettings()->externalLinksString)) { $this->defineSettings(); } }
public function getSettings() { $settings = parent::getSettings(); foreach ($settings as $name => $value) { $configValue = craft()->config->get($name, 'usermanual'); $settings->{$name} = is_null($configValue) ? $value : $configValue; } // Allow handles from config if (!is_numeric($settings->section)) { $section = craft()->sections->getSectionByHandle('homepage'); if ($section) { $settings->section = $section->id; } } return $settings; }
/** * @param array|BaseModel $values */ public function setSettings($values) { if (!$values) { $values = array(); } if (is_array($values)) { // Merge in any values that are stored in craft/config/contactform.php foreach ($this->getSettings() as $key => $value) { $configValue = craft()->config->get($key, 'contactform'); if ($configValue !== null) { $values[$key] = $configValue; } } } parent::setSettings($values); }
public function init() { parent::init(); if (craft()->request->isCpRequest()) { // get data for custom links $this->_customLinks(); } // add event listeners craft()->on('plugins.onLoadPlugins', function (Event $event) { $plugin = craft()->plugins->getPlugin('Adminbar'); if ($this->_canEmbed($plugin)) { // show adminbar in template $element = craft()->urlManager->getMatchedElement(); craft()->adminbar->show($element, $plugin->getSettings()->defaultColor, 'primary'); } }); }
public function init() { parent::init(); require_once "vendor/class.rc4crypt.php"; require_once "vendor/foxycart.cart_validation.php"; $settings = craft()->plugins->getPlugin('foxycart')->getSettings(); \FoxyCart_Helper::setSecret($settings->apikey); \FoxyCart_Helper::setCartUrl("https://" . $settings->storedomain . "/cart"); if (craft()->request->isCpRequest()) { craft()->templates->includeCssFile(UrlHelper::getResourceUrl('foxycart/css/foxycart.css')); } craft()->on('users.onSaveUser', function (Event $event) { if (craft()->getEdition() == Craft::Pro) { $customerId = craft()->foxyCart->updateFoxyCartCustomer($event->params['user']); if ($customerId) { craft()->foxyCart->saveCustomerId($event->params['user'], $customerId); } } }); }
/** * Loads dependencies and registers default shortcodes * * @throws \Exception */ public function init() { parent::init(); Craft::import('plugins.doxter.common.DoxterBaseParser'); Craft::import('plugins.doxter.common.DoxterMarkdownParser'); Craft::import('plugins.doxter.common.DoxterHeaderParser'); Craft::import('plugins.doxter.common.DoxterCodeBlockParser'); Craft::import('plugins.doxter.common.DoxterShortcodeParser'); Craft::import('plugins.doxter.common.DoxterReferenceTagParser'); Craft::import('plugins.doxter.common.shortcodes.DoxterShortcodes'); Craft::import('plugins.doxter.twigextensions.DoxterTwigExtension'); Craft::import('plugins.doxter.models.DoxterShortcodeModel'); require_once dirname(__FILE__) . '/common/parsedown/Parsedown.php'; require_once dirname(__FILE__) . '/common/parsedown/ParsedownExtra.php'; require_once dirname(__FILE__) . '/common/parsedown/Typography.php'; // Registers default shortcodes on the fly before parsing craft()->on('doxter.beforeShortcodeParsing', function () { $shortcodes = array('image' => 'Craft\\DoxterShortcodes@image', 'audio' => 'Craft\\DoxterShortcodes@audio', 'updates' => 'Craft\\DoxterShortcodes@updates', 'vimeo:youtube' => 'Craft\\DoxterShortcodes@video'); doxter()->registerShortcodes($shortcodes); }); }
public function init() { // delete social user when craft user is deleted craft()->on('users.onBeforeDeleteUser', function (Event $event) { $user = $event->params['user']; craft()->social->deleteSocialUserByUserId($user->id); }); // update hasEmail and hasPassword when user is saved craft()->on('users.onSaveUser', function (Event $event) { $user = $event->params['user']; $socialAccount = craft()->social->getAccountByUserId($user->id); if ($socialAccount) { if (!$socialAccount->hasEmail || !$socialAccount->hasPassword) { if ($socialAccount->temporaryEmail != $user->email) { $socialAccount->hasEmail = true; } $currentHashedPassword = $user->password; $currentPassword = $socialAccount->temporaryPassword; if (!craft()->users->validatePassword($currentHashedPassword, $currentPassword)) { $socialAccount->hasPassword = true; } craft()->social->saveAccount($socialAccount); } } }); // update hasEmail when user is activated craft()->on('users.onActivateUser', function (Event $event) { $user = $event->params['user']; $socialAccount = craft()->social->getAccountByUserId($user->id); if ($socialAccount) { if (!$socialAccount->hasEmail) { if ($socialAccount->temporaryEmail != $user->email || $socialAccount->temporaryEmail != $user->unverifiedEmail) { $socialAccount->hasEmail = true; } craft()->social->saveAccount($socialAccount); } } }); parent::init(); }
/** * Returns whether a plugin class exists. * * @param BasePlugin $plugin The plugin. * @param string $classSubfolder The subfolder to search. * @param string $class The class suffix we’re looking for. * @param bool $autoload Whether the found class should be imported for the autoloader. * * @return bool Whether the class exists. */ public function doesPluginClassExist(BasePlugin $plugin, $classSubfolder, $class, $autoload = true) { $pluginFolder = mb_strtolower($plugin->getClassHandle()); $classPath = craft()->path->getPluginsPath() . $pluginFolder . '/' . $classSubfolder . '/' . $class . '.php'; if (IOHelper::fileExists($classPath)) { if ($autoload) { Craft::import("plugins.{$pluginFolder}.{$classSubfolder}.{$class}"); } return true; } else { return false; } }
public function delete(PropelPDO $con = null) { $author = $this->getAuthor(); if ($author) { $author->setPluginsCount(intval($author->getPluginsCount()) - 1); $author->save(); } return parent::delete($con); }