/**
  * Render a single message content element.
  *
  * @param RenderMessageContentEvent $event
  *
  * @return string
  */
 public function renderContent(RenderMessageContentEvent $event)
 {
     global $container;
     $content = $event->getMessageContent();
     if ($content->getType() != 'downloads' || $event->getRenderedContent()) {
         return;
     }
     /** @var EntityAccessor $entityAccessor */
     $entityAccessor = $container['doctrine.orm.entityAccessor'];
     $context = $entityAccessor->getProperties($content);
     $context['files'] = array();
     foreach ($context['downloadSources'] as $index => $downloadSource) {
         $context['downloadSources'][$index] = $downloadSource = \Compat::resolveFile($downloadSource);
         $file = new \File($downloadSource, true);
         if (!$file->exists()) {
             unset($context['downloadSources'][$index]);
             continue;
         }
         $context['files'][$index] = array('url' => $downloadSource, 'size' => \System::getReadableSize(filesize(TL_ROOT . DIRECTORY_SEPARATOR . $downloadSource)), 'icon' => 'assets/contao/images/' . $file->icon, 'title' => basename($downloadSource));
     }
     if (empty($context['files'])) {
         return;
     }
     $template = new \TwigTemplate('avisota/message/renderer/default/mce_downloads', 'html');
     $buffer = $template->parse($context);
     $event->setRenderedContent($buffer);
 }
Exemplo n.º 2
0
 /**
  * Builds a full URL based on parameters
  *
  * @param string $baseURL Base URL
  * @param string|array $requestURI Request URI
  * @param string|array $queryString Query String
  *
  * @return string
  */
 public static function build($baseURL, $requestURI = null, $queryString = null)
 {
     $baseURL = rtrim($baseURL, '/');
     if (is_array($requestURI)) {
         $count = count($requestURI) - 1;
         for ($i = 0; $i < $count; $i++) {
             $requestURI[$i] = trim($requestURI[$i], '/');
         }
         $requestURI[$count] = ltrim($requestURI[$count], '/');
         $requestURI = implode('/', $requestURI);
     } elseif (!empty($requestURI)) {
         $requestURI = ltrim($requestURI, '/');
     }
     if (empty($queryString)) {
         return "{$baseURL}/{$requestURI}";
     }
     if (is_array($queryString)) {
         $queryString = Compat::buildQuery($queryString);
     }
     $queryString = ltrim($queryString, '?');
     return "{$baseURL}/{$requestURI}?{$queryString}";
 }
Exemplo n.º 3
0
 public function createRecipientSource(RecipientSource $recipientSourceData)
 {
     $file = \Compat::resolveFile($recipientSourceData->getCsvFileSrc());
     $columns = array();
     $delimiter = $recipientSourceData->getCsvFileDelimiter();
     $enclosure = $recipientSourceData->getCsvFileEnclosure();
     foreach ($recipientSourceData->getCsvColumnAssignment() as $item) {
         $columns[$item['column'] - 1] = $item['field'];
     }
     switch ($delimiter) {
         case 'semicolon':
             $delimiter = ';';
             break;
         case 'space':
             $delimiter = ' ';
             break;
         case 'tabulator':
             $delimiter = "\t";
             break;
         case 'linebreak':
             $delimiter = "\n";
             break;
         default:
             $delimiter = ',';
     }
     switch ($enclosure) {
         case 'single':
             $enclosure = "'";
             break;
         default:
             $enclosure = '"';
     }
     $recipientSource = new CSVFile(TL_ROOT . DIRECTORY_SEPARATOR . $file, $columns, $delimiter, $enclosure);
     /** @var EventDispatcherInterface $eventDispatcher */
     $eventDispatcher = $GLOBALS['container']['event-dispatcher'];
     $event = new CreateRecipientSourceEvent($recipientSourceData, $recipientSource);
     $eventDispatcher->dispatch(CoreEvents::CREATE_RECIPIENT_SOURCE, $event);
     return $event->getRecipientSource();
 }
 /**
  * Render a single message content element.
  *
  * @param RenderMessageContentEvent $event
  *
  * @return string
  */
 public function renderContent(RenderMessageContentEvent $event)
 {
     global $container;
     $content = $event->getMessageContent();
     if ($content->getType() != 'download' || $event->getRenderedContent()) {
         return;
     }
     /** @var EntityAccessor $entityAccessor */
     $entityAccessor = $container['doctrine.orm.entityAccessor'];
     $context = $entityAccessor->getProperties($content);
     $context['downloadSource'] = \Compat::resolveFile($context['downloadSource']);
     $file = new \File($context['downloadSource'], true);
     if (!$file->exists()) {
         return;
     }
     $context['downloadSize'] = \System::getReadableSize(filesize(TL_ROOT . DIRECTORY_SEPARATOR . $context['downloadSource']));
     $context['downloadIcon'] = 'assets/contao/images/' . $file->icon;
     if (empty($context['downloadTitle'])) {
         $context['downloadTitle'] = basename($context['downloadSource']);
     }
     $template = new \TwigTemplate('avisota/message/renderer/default/mce_download', 'html');
     $buffer = $template->parse($context);
     $event->setRenderedContent($buffer);
 }
Exemplo n.º 5
0
 /**
  * Constructor. Load parent constructor.
  */
 protected function __construct()
 {
     parent::__construct();
 }
 /**
  * Render a single message content element.
  *
  * @param RenderMessageContentEvent $event
  *
  * @return string
  * @internal param MessageContent $content
  * @internal param RecipientInterface $recipient
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function renderContent(RenderMessageContentEvent $event)
 {
     global $container;
     $content = $event->getMessageContent();
     if ($content->getType() != 'gallery' || $event->getRenderedContent()) {
         return;
     }
     /** @var EventDispatcher $eventDispatcher */
     $eventDispatcher = $container['event-dispatcher'];
     /** @var EntityAccessor $entityAccessor */
     $entityAccessor = $container['doctrine.orm.entityAccessor'];
     $context = $entityAccessor->getProperties($content);
     $size = $content->getImageSize();
     $images = array();
     $sorting = array();
     $imageSources = 'imageSources';
     if ($content->getSortBy() === 'custom') {
         $imageSources = 'orderSRC';
     }
     foreach ($context[$imageSources] as $index => $file) {
         $context[$imageSources][$index] = $file = \Compat::resolveFile($file);
         switch ($content->getSortBy()) {
             case 'name_asc':
             case 'name_desc':
                 $sorting[] = basename($file);
                 break;
             case 'date_asc':
             case 'date_desc':
                 $sorting[] = filemtime(TL_ROOT . DIRECTORY_SEPARATOR . $file);
                 break;
             case 'random':
                 $sorting[] = rand(-PHP_INT_MAX, PHP_INT_MAX);
         }
         $resizeImageEvent = new ResizeImageEvent($file, $size[0], $size[1], $size[2]);
         $eventDispatcher->dispatch(ContaoEvents::IMAGE_RESIZE, $resizeImageEvent);
         $images[] = $resizeImageEvent->getResultImage();
     }
     switch ($content->getSortBy()) {
         case 'name_asc':
             uasort($sorting, 'strnatcasecmp');
             break;
         case 'name_desc':
             uasort($sorting, 'strnatcasecmp');
             $sorting = array_reverse($sorting, true);
             break;
         case 'random':
         case 'date_asc':
             asort($sorting);
             break;
         case 'date_desc':
             arsort($sorting);
             break;
         default:
             $sorting = false;
     }
     if ($sorting) {
         $sorting = array_keys($sorting);
         uksort($images, function ($primary, $secondary) use($sorting) {
             return array_search($primary, $sorting) - array_search($secondary, $sorting);
         });
     }
     $context['rows'] = array();
     while (count($images)) {
         $row = array_slice($images, 0, $content->getPerRow());
         $images = array_slice($images, $content->getPerRow());
         while (count($row) < $content->getPerRow()) {
             $row[] = false;
         }
         $context['rows'][] = $row;
     }
     $styles = array();
     $margins = $content->getImagemargin();
     foreach (array('top', 'right', 'bottom', 'left') as $property) {
         if (!empty($margins[$property])) {
             $styles[] = sprintf('padding-%s:%s%s', $property, $margins[$property], $margins['unit']);
         }
     }
     $context['styles'] = implode(';', $styles);
     $template = new \TwigTemplate('avisota/message/renderer/default/mce_gallery', 'html');
     $buffer = $template->parse($context);
     $event->setRenderedContent($buffer);
 }
Exemplo n.º 7
0
 /**
  * Initializes the framework
  */
 public function init()
 {
     // Requires WordPress 4.1
     if (version_compare($GLOBALS['wp_version'], self::MIN_WP_VER, '<')) {
         Compat::loadNotices();
     }
     // core actions
     add_action('after_setup_theme', [$this->theme, 'addThemeSupports']);
     add_action('widgets_init', [$this->theme, 'registerWidgets']);
     add_action('wp_enqueue_scripts', [$this->assets, 'loadSiteScripts']);
     add_action('wp_enqueue_scripts', [$this->assets, 'loadSiteStyles']);
     add_action('admin_enqueue_scripts', [$this->assets, 'loadAdminScripts']);
     add_action('admin_enqueue_scripts', [$this->assets, 'loadAdminStyles']);
     add_action('login_enqueue_scripts', [$this->assets, 'loadLoginScripts']);
     add_action('login_enqueue_scripts', [$this->assets, 'loadLoginStyles']);
     // meta elements
     add_action('wp_head', [$this->viewMeta, 'render'], 1);
     // theme customizations
     add_action('customize_register', [$this->customizer, 'register']);
     add_action('customize_preview_init', [$this->assets, 'loadCustomizeScript']);
 }
Exemplo n.º 8
0
    {
    }
    function rtrim($chars = false)
    {
    }
    // ArrayAccess interface
    function offsetExists($offset)
    {
        return $this->length() > $offset;
    }
    function offsetGet($offset)
    {
        return $this->substr($offset, 1, 1);
    }
    function offsetSet($offset, $value)
    {
        return $this->splice($offset, 1, $value);
    }
    function offsetUnset($offset)
    {
        return $this->splice($offset, 1, "");
    }
}
if (!function_exists('mb_convert_encoding')) {
    require_once dirname(__FILE__) . '/Compat.php';
    \Compat::shim();
}
function u($what, $encoding = false)
{
    return new Unicode($what, $encoding);
}
Exemplo n.º 9
0
    /**
     * Add yaml css to layout.
     *
     * @param Database_Result $objPage
     * @param Database_Result $objLayout
     * @param PageRegular $objPageRegular
     */
    public function hookGetPageLayout($objPage, $objLayout, $objPageRegular)
    {
        $autoInclude = $objLayout->xyaml_auto_include || $GLOBALS['TL_CONFIG']['yaml_auto_include'];
        $path = $objLayout->xyaml_auto_include ? $objLayout->xyaml_path : $GLOBALS['TL_CONFIG']['yaml_path'];
        if ($autoInclude && $objLayout->xyaml && !empty($path)) {
            $mode = $objLayout->xyaml_auto_include ? $objLayout->xyaml_mode : $GLOBALS['TL_CONFIG']['yaml_mode'];
            $filter = $objLayout->xyaml_auto_include ? $objLayout->xyaml_compass_filter : $GLOBALS['TL_CONFIG']['yaml_compass_filter'];
            $path = \Compat::resolveFile($path, false);
            if ($path) {
                if (!is_array($GLOBALS['TL_CSS'])) {
                    $GLOBALS['TL_CSS'] = array();
                }
                if (!is_array($GLOBALS['TL_JAVASCRIPT'])) {
                    $GLOBALS['TL_JAVASCRIPT'] = array();
                }
                $useSass = $mode == 'sass';
                if ($useSass) {
                    $activeModules = \Config::getInstance()->getActiveModules();
                    if (!in_array('assetic', $activeModules)) {
                        throw new \RuntimeException('Cannot use YAML SASS without assetic extension');
                    }
                    global $container;
                    /** @var AsseticFactory $factory */
                    $factory = $container['assetic.factory'];
                    $filters = array($factory->createFilterOrChain($filter));
                } else {
                    $filters = array();
                }
                // add yaml addons
                $addons = deserialize($objLayout->xyaml_addons, true);
                $this->addFiles($objPage, $objLayout, $addons, $GLOBALS['YAML_ADDONS'], $path, $useSass, $filters);
                // add yaml forms
                $forms = deserialize($objLayout->xyaml_forms, true);
                $this->addFiles($objPage, $objLayout, $forms, $GLOBALS['YAML_FORMS'], $path, $useSass, $filters);
                // add yaml navigation
                $navigations = deserialize($objLayout->xyaml_navigation, true);
                $this->addFiles($objPage, $objLayout, $navigations, $GLOBALS['YAML_NAVIGATION'], $path, $useSass, $filters);
                // add yaml print
                $prints = deserialize($objLayout->xyaml_print, true);
                $this->addFiles($objPage, $objLayout, $prints, $GLOBALS['YAML_PRINT'], $path, $useSass, $filters);
                // add yaml screen
                $screens = deserialize($objLayout->xyaml_screen, true);
                $this->addFiles($objPage, $objLayout, $screens, $GLOBALS['YAML_SCREEN'], $path, $useSass, $filters);
                // add yaml base
                $this->addStyleSheets($objPage, $objLayout, array('core/base.css'), $path, $useSass, $filters);
                // add yaml iehacks
                if ($objLayout->xyaml_iehacks) {
                    $ieHacks = $path . '/core/iehacks.min.css';
                    if ($useSass) {
                        $targetPath = 'assets/css/iehacks-' . substr(md5($path), 0, 8) . '.css';
                        if (!file_exists(TL_ROOT . '/' . $targetPath)) {
                            // load asset
                            $asset = new FileAsset(TL_ROOT . '/' . $path . '/core/_iehacks.scss', $filters, TL_ROOT, $path . '/core/_iehacks.scss');
                            $asset->setTargetPath(TL_ROOT . '/' . $targetPath);
                            $asset->dump();
                        }
                        $ieHacks = $targetPath;
                    }
                    $GLOBALS['TL_HEAD']['xyaml_iehacks'] = <<<EOF
<!--[if lte IE 7]>
<link rel="stylesheet" href="{$ieHacks}" type="text/css"/>
<![endif]-->
EOF;
                }
                // linearize level
                if ($objLayout->xyaml_subcolumns_linearize) {
                    $cssClass = ' linearize-level-' . $objLayout->xyaml_subcolumns_linearize;
                    $GLOBALS['TL_SUBCL']['yaml4']['scclass'] .= $cssClass;
                    $GLOBALS['TL_SUBCL']['yaml4_additional']['scclass'] .= $cssClass;
                }
            }
        }
        return false;
    }
 /**
  * Render a message for the given recipient.
  *
  * @param RecipientInterface $recipient
  * @param array              $additionalData
  *
  * @return \Avisota\Message\MessageInterface
  * @internal param array $newsletterData Additional newsletter data.
  *
  * @internal param RecipientInterface $recipientEmail The main recipient.
  * @SuppressWarnings(PHPMD.Superglobals)
  */
 public function render(RecipientInterface $recipient = null, array $additionalData = array())
 {
     /** @var EventDispatcher $eventDispatcher */
     $eventDispatcher = $GLOBALS['container']['event-dispatcher'];
     // dispatch a pre render event
     $event = new PreRenderMessageTemplateEvent($this->message, $this, $recipient, $additionalData);
     $eventDispatcher->dispatch($event::NAME, $event);
     // fetch updates on additional data
     $additionalData = $event->getAdditionalData();
     $content = $this->parseContent($recipient, $additionalData);
     $swiftMessage = new \Swift_Message();
     $name = trim($recipient->get('forename') . ' ' . $recipient->get('surname'));
     $swiftMessage->setTo($recipient->getEmail(), $name);
     $swiftMessage->setSubject($this->message->getSubject());
     $swiftMessage->setBody($content, $this->getContentType(), $this->getContentEncoding());
     $swiftMessage->setDescription($this->message->getDescription());
     if ($this->message->getAddFile()) {
         $files = deserialize($this->message->getFiles(), true);
         foreach ($files as $file) {
             $file = \Compat::resolveFile($file);
             if ($file) {
                 $attachment = \Swift_Attachment::fromPath(TL_ROOT . '/' . $file);
                 $swiftMessage->attach($attachment);
             }
         }
     }
     $message = new ContaoAwareNativeMessage($swiftMessage, $this->message, array($recipient));
     // dispatch a post render event
     $event = new PostRenderMessageTemplateEvent($this->message, $this, $recipient, $additionalData, $message);
     $eventDispatcher->dispatch($event::NAME, $event);
     return $message;
 }