/**
  * Sends an email submitted through a contact form.
  *
  * @param ContactFormModel $message
  * @throws Exception
  * @return bool
  */
 public function sendMessage(ContactFormModel $message)
 {
     $settings = craft()->plugins->getPlugin('contactform')->getSettings();
     if (!$settings->toEmail) {
         throw new Exception('The "To Email" address is not set on the plugin’s settings page.');
     }
     // Fire an 'onBeforeSend' event
     Craft::import('plugins.contactform.events.ContactFormEvent');
     $event = new ContactFormEvent($this, array('message' => $message));
     $this->onBeforeSend($event);
     if ($event->isValid) {
         if (!$event->fakeIt) {
             $toEmails = ArrayHelper::stringToArray($settings->toEmail);
             foreach ($toEmails as $toEmail) {
                 $email = new EmailModel();
                 $emailSettings = craft()->email->getSettings();
                 $email->fromEmail = $emailSettings['emailAddress'];
                 $email->replyTo = $message->fromEmail;
                 $email->sender = $emailSettings['emailAddress'];
                 $email->fromName = $settings->prependSender . ($settings->prependSender && $message->fromName ? ' ' : '') . $message->fromName;
                 $email->toEmail = $toEmail;
                 $email->subject = $settings->prependSubject . ($settings->prependSubject && $message->subject ? ' - ' : '') . $message->subject;
                 $email->body = $message->message;
                 if ($message->attachment) {
                     $email->addAttachment($message->attachment->getTempName(), $message->attachment->getName(), 'base64', $message->attachment->getType());
                 }
                 craft()->email->sendEmail($email);
             }
         }
         return true;
     }
     return false;
 }
예제 #2
0
 public function addTwigExtension()
 {
     Craft::import('plugins.kindling.twigextensions.PathingVariablesExtension');
     Craft::import('plugins.kindling.twigextensions.CookieExtension');
     Craft::import('plugins.kindling.twigextensions.ArrayExtension');
     return [new PathingVariablesExtension(), new CookieExtension(), new ArrayExtension()];
 }
예제 #3
0
 /**
  * Processes resource requests before anything else has a chance to initialize.
  */
 public function init()
 {
     // Set default timezone to UTC
     date_default_timezone_set('UTC');
     // Import all the built-in components
     foreach ($this->componentAliases as $alias) {
         Craft::import($alias);
     }
     // Initialize HttpRequestService and LogRouter right away
     $this->getComponent('request');
     $this->getComponent('log');
     // Set our own custom runtime path.
     $this->setRuntimePath($this->path->getRuntimePath());
     // Attach our own custom Logger
     Craft::setLogger(new Logger());
     // If we're not in devMode or this is a resource request, we're going to remove some logging routes.
     if (!$this->config->get('devMode') || ($resourceRequest = $this->request->isResourceRequest()) == true) {
         // If it's a resource request, we don't want any logging routes, including craft.log
         // If it's not a resource request, we'll keep the FileLogRoute around.
         if ($resourceRequest) {
             $this->log->removeRoute('FileLogRoute');
         }
         // Don't need either of these if not in devMode or it's a resource request.
         $this->log->removeRoute('WebLogRoute');
         $this->log->removeRoute('ProfileLogRoute');
     }
     parent::init();
 }
예제 #4
0
 /**
  * Initializes the console app by creating the command runner.
  *
  * @return null
  */
 public function init()
 {
     // Set default timezone to UTC
     date_default_timezone_set('UTC');
     // Import all the built-in components
     foreach ($this->componentAliases as $alias) {
         Craft::import($alias);
     }
     // Attach our Craft app behavior.
     $this->attachBehavior('AppBehavior', new AppBehavior());
     // Initialize Cache and LogRouter right away (order is important)
     $this->getComponent('cache');
     $this->getComponent('log');
     // So we can try to translate Yii framework strings
     $this->coreMessages->attachEventHandler('onMissingTranslation', array('Craft\\LocalizationHelper', 'findMissingTranslation'));
     // Set our own custom runtime path.
     $this->setRuntimePath(craft()->path->getRuntimePath());
     // Attach our own custom Logger
     Craft::setLogger(new Logger());
     // No need for these.
     craft()->log->removeRoute('WebLogRoute');
     craft()->log->removeRoute('ProfileLogRoute');
     // Load the plugins
     craft()->plugins->loadPlugins();
     // Validate some basics on the database configuration file.
     craft()->validateDbConfigFile();
     // Call parent::init before the plugin console command logic so craft()->commandRunner will be available to us.
     parent::init();
     foreach (craft()->plugins->getPlugins() as $plugin) {
         $commandsPath = craft()->path->getPluginsPath() . StringHelper::toLowerCase($plugin->getClassHandle()) . '/consolecommands/';
         if (IOHelper::folderExists($commandsPath)) {
             craft()->commandRunner->addCommands(rtrim($commandsPath, '/'));
         }
     }
 }
 public function addTwigExtension()
 {
     Craft::import('plugins.minify.twigextensions.MinifyTwigExtension');
     Craft::import('plugins.minify.twigextensions.MinifyTwigTokenParser');
     Craft::import('plugins.minify.twigextensions.MinifyTwigNode');
     return new MinifyTwigExtension();
 }
예제 #6
0
 public function addTwigExtension()
 {
     Craft::import('plugins.venti.twigextensions.VentiTwigExtension');
     Craft::import('plugins.venti.twigextensions.Calendar_TokenParser');
     Craft::import('plugins.venti.twigextensions.Calendar_Node');
     return new VentiTwigExtension();
 }
 public function addTwigExtension()
 {
     Craft::import('plugins.foxycart.twigextensions.Hmac_Node');
     Craft::import('plugins.foxycart.twigextensions.Hmac_TokenParser');
     Craft::import('plugins.foxycart.twigextensions.FoxyCartTwigExtension');
     return new FoxyCartTwigExtension();
 }
예제 #8
0
 public function init()
 {
     Craft::import('plugins.golive.tasks.GoLive_DeployTask', true);
     Craft::import('plugins.golive.etc.db.GoLive_DbBackup', true);
     Craft::import('plugins.golive.vendor.autoload', true);
     if (craft()->request->isCpRequest() && craft()->goLive_settings->isPluginEnabled()) {
         craft()->templates->includeCssResource('golive/css/golive.css');
     }
 }
 /**
  * Init
  *
  * @return void
  */
 public function init()
 {
     Craft::import('plugins.httpmessages.middleware.*', true);
     Craft::import('plugins.httpmessages.etc.*.*', true);
     $autoload = dirname(__FILE__) . '/../../../vendor/autoload.php';
     if (!is_file($autoload)) {
         throw new HttpMessages_Exception("`/vendor/autoload.php` could not be loaded by `craft/plugins/httpmessages/HttpMessagesPlugin.php`. Try running `composer install` in the root of the project.");
     }
     require_once $autoload;
     craft()->httpMessages_config->loadConfigFiles();
 }
 /**
  * {@inheritDoc}
  */
 public function parse(\Twig_Token $token)
 {
     Craft::import('plugins.stow.twigextensions.Node.CacheNode');
     $lineno = $token->getLine();
     $stream = $this->parser->getStream();
     $key = $this->parser->getExpressionParser()->parseExpression();
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     $body = $this->parser->subparse(array($this, 'decideCacheEnd'), true);
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     return new CacheNode('', $key, $body, $lineno, $this->getTag());
 }
 public function init()
 {
     Craft::import('plugins.sproutseo.helpers.SproutSeoMetaHelper');
     if (craft()->request->isSiteRequest() && !craft()->request->isLivePreview()) {
         $url = craft()->request->getUrl();
         // check if the request url needs redirect
         $redirect = sproutSeo()->redirects->getRedirect($url);
         if ($redirect) {
             craft()->request->redirect($redirect->newUrl, true, $redirect->method);
         }
     }
 }
예제 #12
0
 /**
  * @param string $name
  *
  * @return mixed
  */
 public function __get($name)
 {
     $plugin = craft()->plugins->getPlugin($name);
     if ($plugin && $plugin->isEnabled) {
         $pluginName = $plugin->getClassHandle();
         $className = __NAMESPACE__ . '\\' . $pluginName . 'Variable';
         // Variables should already be imported by the plugin service, but let's double check.
         if (!class_exists($className)) {
             Craft::import('plugins.' . StringHelper::toLowerCase($pluginName) . '.variables.' . $pluginName . 'Variable');
         }
         return new $className();
     }
 }
 public function parse(\Twig_Token $token)
 {
     Craft::import('plugins.premailer.twigextensions.Node.Premailer_Node');
     $lineno = $token->getLine();
     $stream = $this->parser->getStream();
     $nodes = array("body" => null, "options" => null);
     $attributes = array();
     if ($stream->test(\Twig_Token::NAME_TYPE, 'with')) {
         $stream->next();
         $nodes['options'] = $this->parser->getExpressionParser()->parseExpression();
     }
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     $nodes['body'] = $this->parser->subparse(array($this, 'decidePremailerEnd'), true);
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     return new Premailer_Node($nodes, $attributes, $lineno, $this->getTag());
 }
예제 #14
0
 public function init()
 {
     Craft::import('plugins.supercooltools.tools.*');
     if (craft()->request->isCpRequest() && craft()->userSession->isLoggedIn()) {
         craft()->templates->includeCssResource('supercooltools/css/supercooltools.css');
         craft()->templates->includeJsResource('supercooltools/js/supercooltools.js');
         if (craft()->config->get('openInstructionLinksInNewWindow', 'SupercoolTools')) {
             craft()->templates->includeJs('new SupercoolTools.TargetBlankInstructionLinks();');
         }
         craft()->templates->includeJsFile('//assets.zendesk.com/embeddable_framework/main.js');
         $zendeskHandle = craft()->config->get('zendeskHandle', 'SupercoolTools');
         if (!is_null($zendeskHandle)) {
             craft()->templates->includeJs('new SupercoolTools.Zendesk("' . $zendeskHandle . '");');
         }
     }
 }
예제 #15
0
 /**
  *
  */
 public function init()
 {
     // Set default timezone to UTC
     date_default_timezone_set('UTC');
     foreach ($this->componentAliases as $alias) {
         Craft::import($alias);
     }
     craft()->getComponent('log');
     // Set our own custom runtime path.
     $this->setRuntimePath(craft()->path->getRuntimePath());
     // No need for these.
     craft()->log->removeRoute('WebLogRoute');
     craft()->log->removeRoute('ProfileLogRoute');
     // Load the plugins
     craft()->plugins->loadPlugins();
     parent::init();
 }
예제 #16
0
 /**
  * @param string $name
  *
  * @return mixed
  */
 public function __get($name)
 {
     $plugin = craft()->plugins->getPlugin($name);
     if ($plugin && $plugin->isEnabled) {
         $pluginName = $plugin->getClassHandle();
         $className = __NAMESPACE__ . '\\' . $pluginName . 'Variable';
         // Variables should already be imported by the plugin service, but let's double check.
         if (!class_exists($className)) {
             Craft::import('plugins.' . StringHelper::toLowerCase($pluginName) . '.variables.' . $pluginName . 'Variable');
         }
         // If we haven't done this one yet, create it and save it for later.
         if (!isset($this->_pluginVariableInstances[$className])) {
             $this->_pluginVariableInstances[$className] = new $className();
         }
         return $this->_pluginVariableInstances[$className];
     }
 }
예제 #17
0
 /**
  * Sends an email submitted through a contact form.
  *
  * @param ContactFormModel $message
  * @throws Exception
  * @return bool
  */
 public function sendMessage(ContactFormModel $message)
 {
     $settings = craft()->plugins->getPlugin('contactform')->getSettings();
     if (!$settings->toEmail) {
         throw new Exception('The "To Email" address is not set on the plugin’s settings page.');
     }
     // Fire an 'onBeforeSend' event
     Craft::import('plugins.contactform.events.ContactFormEvent');
     $event = new ContactFormEvent($this, array('message' => $message));
     $this->onBeforeSend($event);
     if ($event->isValid) {
         if (!$event->fakeIt) {
             // Grab any "to" emails set in the plugin settings.
             $toEmails = ArrayHelper::stringToArray($settings->toEmail);
             foreach ($toEmails as $toEmail) {
                 $variables = array();
                 $email = new EmailModel();
                 $emailSettings = craft()->email->getSettings();
                 $email->fromEmail = $emailSettings['emailAddress'];
                 $email->replyTo = $message->fromEmail;
                 $email->sender = $emailSettings['emailAddress'];
                 $email->fromName = $settings->prependSender . ($settings->prependSender && $message->fromName ? ' ' : '') . $message->fromName;
                 $email->toEmail = $toEmail;
                 $email->subject = '{{ emailSubject }}';
                 $email->body = '{{ emailBody }}';
                 $variables['emailSubject'] = $settings->prependSubject . ($settings->prependSubject && $message->subject ? ' - ' : '') . $message->subject;
                 $variables['emailBody'] = $message->message;
                 if (!empty($message->htmlMessage)) {
                     // Prevent Twig tags from getting parsed
                     $email->htmlBody = str_replace(array('{', '}'), array('{', '}'), $message->htmlMessage);
                 }
                 if (!empty($message->attachment)) {
                     foreach ($message->attachment as $attachment) {
                         if ($attachment) {
                             $email->addAttachment($attachment->getTempName(), $attachment->getName(), 'base64', $attachment->getType());
                         }
                     }
                 }
                 craft()->email->sendEmail($email, $variables);
             }
         }
         return true;
     }
     return false;
 }
 /**
  * Saves a "guest" entry.
  *
  * @throws Exception
  */
 public function actionSaveEntry()
 {
     $this->requirePostRequest();
     // Only allow from the front-end.
     if (!craft()->request->isSiteRequest()) {
         throw new HttpException(404);
     }
     $settings = craft()->plugins->getPlugin('guestentries')->getSettings();
     // Grab the data posted data.
     $entry = $this->_populateEntryModel($settings);
     // See if they want validation. Note that this usually doesn't occur if the entry is set to disabled by default.
     if ($settings->validateEntry[$this->_section->handle]) {
         // Does the entry type have dynamic titles?
         $entryType = $entry->getType();
         if (!$entryType->hasTitleField) {
             // Have to pre-set the dynamic Title value here, so Title validation doesn't fail.
             $entry->getContent()->title = craft()->templates->renderObjectTemplate($entryType->titleFormat, $entry);
         }
         // Now validate any content
         if (!craft()->content->validateContent($entry)) {
             $entry->addErrors($entry->getContent()->getErrors());
         }
         if ($entry->hasErrors()) {
             $this->_returnError($entry);
         }
     }
     // Fire an 'onBeforeSave' event
     Craft::import('plugins.guestentries.events.GuestEntriesEvent');
     $event = new GuestEntriesEvent($this, array('entry' => $entry));
     craft()->guestEntries->onBeforeSave($event);
     if ($event->isValid) {
         if (!$event->fakeIt) {
             if (craft()->entries->saveEntry($entry)) {
                 $this->_returnSuccess($entry);
             } else {
                 $this->_returnError($entry);
             }
         } else {
             // Pretend it worked.
             $this->_returnSuccess($entry);
         }
     }
     $this->_returnError($entry);
 }
예제 #19
0
 /**
  * Sends an email submitted through a contact form.
  *
  * @param ContactFormModel $message
  * @throws Exception
  * @return bool
  */
 public function sendMessage(ContactFormModel $message)
 {
     $settings = craft()->plugins->getPlugin('contactform')->getSettings();
     // Fire an 'onBeforeSend' event
     Craft::import('plugins.contactform.events.ContactFormEvent');
     $event = new ContactFormEvent($this, array('message' => $message));
     $this->onBeforeSend($event);
     if ($event->isValid) {
         if (!$event->fakeIt) {
             // Get the relevant email address(es) for the message subject
             foreach ($settings->toEmail as $row) {
                 if ($message->subject == $row['subject']) {
                     if (!$row['email']) {
                         throw new Exception('The "To Email" address is not set on the plugin’s settings page.');
                     }
                     $toEmails = ArrayHelper::stringToArray($row['email']);
                 }
             }
             foreach ($toEmails as $toEmail) {
                 $email = new EmailModel();
                 $emailSettings = craft()->email->getSettings();
                 $email->fromEmail = $emailSettings['emailAddress'];
                 $email->replyTo = $message->fromEmail;
                 $email->sender = $emailSettings['emailAddress'];
                 $email->fromName = $settings->prependSender . ($settings->prependSender && $message->fromName ? ' ' : '') . $message->fromName;
                 $email->toEmail = $toEmail;
                 $email->subject = $settings->prependSubject . ($settings->prependSubject && $message->subject ? ' - ' : '') . $message->subject;
                 $email->body = "An email has been sent by {$message->fromName} ({$message->fromEmail}) using the contact form on the website. Here is the message:\n\n" . $message->message;
                 if (!empty($message->attachment)) {
                     foreach ($message->attachment as $attachment) {
                         if ($attachment) {
                             $email->addAttachment($attachment->getTempName(), $attachment->getName(), 'base64', $attachment->getType());
                         }
                     }
                 }
                 craft()->email->sendEmail($email);
             }
         }
         return true;
     }
     return false;
 }
예제 #20
0
 /**
  * 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);
     });
 }
예제 #21
0
 public function optimizeImage($imageToOptimize)
 {
     $this->setToolAvailability();
     Craft::import('plugins.amtools.libraries.PHPImageOptim.PHPImageOptim', true);
     Craft::import('plugins.amtools.libraries.PHPImageOptim.Tools.Common', true);
     Craft::import('plugins.amtools.libraries.PHPImageOptim.Tools.ToolsInterface', true);
     $imageOptim = new \PHPImageOptim\PHPImageOptim();
     $imageOptim->setImage($imageToOptimize);
     switch (strtolower(pathinfo($imageToOptimize, PATHINFO_EXTENSION))) {
         case 'gif':
             return $this->optimizeGif($imageOptim);
             break;
         case 'png':
             return $this->optimizePng($imageOptim);
             break;
         case 'jpg':
         case 'jpeg':
             return $this->optimizeJpeg($imageOptim);
             break;
     }
     return false;
 }
 /**
  * @param string $name command name (case-insensitive)
  * @return \CConsoleCommand the command object. Null if the name is invalid.
  */
 public function createCommand($name)
 {
     $name = strtolower($name);
     $command = null;
     if (isset($this->commands[$name])) {
         $command = $this->commands[$name];
     } else {
         $commands = array_change_key_case($this->commands);
         if (isset($commands[$name])) {
             $command = $commands[$name];
         }
     }
     if ($command !== null) {
         if (is_string($command)) {
             if (strpos($command, '/') !== false || strpos($command, '\\') !== false) {
                 $className = IOHelper::getFileName($command, false);
                 // If it's a default framework command, don't namespace it.
                 if (strpos($command, 'framework') === false) {
                     $className = __NAMESPACE__ . '\\' . $className;
                 }
                 if (!class_exists($className, false)) {
                     require_once $command;
                 }
             } else {
                 $className = Craft::import($command);
             }
             return new $className($name, $this);
         } else {
             return Craft::createComponent($command, $name, $this);
         }
     } else {
         if ($name === 'help') {
             return new \CHelpCommand('help', $this);
         } else {
             return null;
         }
     }
 }
예제 #23
0
 /**
  * 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 addTwigExtension()
 {
     Craft::import('plugins.assetmetadata.twigextensions.AssetMetadataTwigExtension');
     return new AssetMetadataTwigExtension();
 }
 public function getTokenParsers()
 {
     Craft::import('plugins.stow.twigextensions.TokenParser.CacheTokenParser');
     return array(new CacheTokenParser());
 }
<?php

namespace Craft;

Craft::import('plugins.httpmessagesrestmiddleware.vendor.autoload', true);
class HttpMessagesRestMiddlewarePlugin extends BasePlugin
{
    /**
     * Get Name
     *
     * @return string Name
     */
    public function getName()
    {
        return Craft::t('Http Messages - Rest Middleware');
    }
    /**
     * Get Version
     *
     * @return string Version
     */
    public function getVersion()
    {
        return '0.0.0';
    }
    /**
     * Get Developer
     *
     * @return string Developer
     */
    public function getDeveloper()
예제 #27
0
 public function hookAddTwigExtension()
 {
     Craft::import('plugins.slugify.twigextensions.SlugifyTwigExtension');
     return new SlugifyTwigExtension();
 }
 /**
  * Registers the Twig extension.
  *
  * @return LeverPostingsTwigExtension
  */
 public function addTwigExtension()
 {
     Craft::import('plugins.leverpostings.twigextensions.LeverPostingsTwigExtension');
     return new LeverPostingsTwigExtension();
 }
 /**
  * Registers the Twig extension.
  *
  * @return FacebookFeedTwigExtension
  */
 public function addTwigExtension()
 {
     Craft::import('plugins.timeagoinwords.twigextensions.TimeAgoInWordsTwigExtension');
     return new TimeAgoInWordsTwigExtension();
 }
 public function addTwigExtension()
 {
     Craft::import('plugins.twigbettersort.twigextensions.TwigBetterSortTwigExtension');
     return new TwigBetterSortTwigExtension();
 }