Example #1
0
 public static function install()
 {
     $config = DI::get('Config');
     // add twig function / filter
     if ((bool) $config->get('plugins.config.markdown.twig', false)) {
         Hook::attach('twigInitialized', function ($twig) {
             $options = ['is_safe' => ['html']];
             $twig->addFunction(new \Twig_SimpleFunction('markdown', ['MarkdownPlugin', 'parseMarkdown'], $options));
             $twig->addFilter(new \Twig_SimpleFilter('markdown', ['MarkdownPlugin', 'parseMarkdown'], $options));
         });
     }
     // add shortcode
     if ((bool) $config->get('plugins.config.markdown.shortcode', true)) {
         #Hook::attach('shortcodeInitialized', function($shortcode) {
         #    $shortcode->add('markdown', ['MarkdownPlugin', 'markdownShortcode']);
         #});
         Hook::attach('shortcodeInitialized', ['MarkdownPlugin', 'addShortcode']);
     }
     Hook::attach('renderContent', function ($content, array $attributes) {
         if (!in_array($attributes['format'], ['markdown', 'md'])) {
             return $content;
         }
         return MarkdownPlugin::parseMarkdown($content);
     });
 }
Example #2
0
 /**
  * Initialize plugin
  */
 public static function install()
 {
     $config = DI::get('Config');
     if ((bool) $config->get('plugins.config.gist.twig', false)) {
         Hook::attach('twigInitialized', ['GistPlugin', 'addTwigFunction']);
     }
     if ((bool) $config->get('plugins.config.gist.shortcode', true)) {
         Hook::attach('shortcodeInitialized', ['GistPlugin', 'addShortcode']);
     }
 }
Example #3
0
 /**
  * @return array
  */
 public function install()
 {
     $config = DI::get('Config');
     if ((bool) $config->get('plugins.config.textile.twig', false)) {
         Hook::attach('twigInitialized', [$this, 'addTwigFunctionAndFilter']);
     }
     if ((bool) $config->get('plugins.config.textile.shortcode', true)) {
         Hook::attach('shortcodeInitialized', [$this, 'addSortcode']);
     }
     Hook::attach('renderContent', [$this, 'renderContent']);
 }
Example #4
0
 public function initTwig()
 {
     $config = DI::get('Config');
     // Add custom namespace path to Imagine lib
     $vendorDir = $config->get('site.path') . '/../vendor';
     $autoload = (require $vendorDir . '/autoload.php');
     $autoload->add('Twig_', __DIR__ . '/vendor/twig/lib');
     $this->twig = new Twig($config);
     $this->twig->init();
     Di::set('Twig', $this->twig);
     Hook::trigger(Hook::ACTION, 'twigInitialized', $this->twig->getEnvironment());
 }
Example #5
0
 public static function imagineShortcode($options)
 {
     try {
         $options = array_merge(['path' => empty($options[0]) ? '' : $options[0], 'filter' => '', 'attributes' => [], 'alt' => '', 'class' => '', 'id' => '', 'style' => '', 'title' => '', 'width' => 0, 'height' => 0, 'media' => 1], $options);
         $config = DI::get('Config');
         $basePath = DI::get('Request')->getBasePath();
         $extension = new ImagineExtension($config, $basePath);
         return call_user_func_array([$extension, 'imagineFunction'], $options);
     } catch (\Exception $e) {
         // @todo return a default (fallback) image
         return '';
     }
 }
 public static function install()
 {
     // default config
     $defaults = DI::get('Config')->get('plugins.config.smartypants', []);
     static::$config = array_merge(['twig_filter' => 1, 'process_title' => 1, 'process_content' => true, 'options' => 'qDew'], $defaults);
     if (!empty(static::$config['twig_filter'])) {
         Hook::attach('twigInitialized', ['SmartypantsPlugin', 'addTwigFilter']);
     }
     if (!empty(static::$config['process_title'])) {
         Hook::attach('pageLoaded', ['SmartypantsPlugin', 'filterPageTitle']);
     }
     if (!empty(static::$config['process_content'])) {
         Hook::attach('renderContent', ['SmartypantsPlugin', 'renderContent']);
     }
 }
Example #7
0
 /**
  * @param array $options
  * @return string
  */
 public static function asciiMathjax($options, $content)
 {
     $page = DI::get('Page');
     if (isset($page->mathjax)) {
         if ($page->mathjax == false) {
             return $content;
         }
     }
     static $addedJS;
     if (is_null($addedJS)) {
         if (!empty(static::$config['cdn_url'])) {
             DI::get('Assets')->addJs(static::$config['cdn_url']);
         }
         if (!empty(static::$config['built_in_js'])) {
             DI::get('Assets')->addJs("@plugin/mathjax/assets/mathjax.js");
         }
         $addedJS = true;
     }
     return '$' . $content . '$';
 }
 public static function install()
 {
     // config
     $defaults = DI::get('Config')->get('plugins.config.highlightjs', []);
     $config = array_merge(['stylesheets' => '@plugin/highlightjs/assets/styles/', 'javascript' => '@plugin/highlightjs/assets/highlight.pack.js', 'javascript_init' => '@plugin/highlightjs/assets/highlightjs.js', 'html' => '<pre><code class="{class}">{content}</code></pre>', 'style' => 'default'], $defaults);
     static::$config = $config;
     /** @var Herbie\Assets $assets */
     $assets = DI::get('Assets');
     if (false !== $config['stylesheets']) {
         $style = empty($config['style']) ? 'default' : $config['style'];
         $stylesheet = sprintf('%s/%s.css', rtrim($config['stylesheets']) . '/', $style);
         $assets->addCss($stylesheet);
     }
     if (false !== $config['javascript']) {
         $assets->addJs($config['javascript']);
     }
     if (false !== $config['javascript_init']) {
         $assets->addJs($config['javascript_init']);
     }
     Hook::attach('shortcodeInitialized', ['HighlightJsPlugin', 'addShortcode']);
 }
Example #9
0
 public static function install()
 {
     self::$templates = DI::get('Config')->get('plugins.config.grid.templates', []);
     Hook::attach('renderContent', ['GridPlugin', 'renderContent']);
 }
Example #10
0
 protected function addBlocksTag()
 {
     $this->add('blocks', function ($options) {
         $options = array_merge(['path' => Herbie\DI::get('Page')->getDefaultBlocksPath(), 'sort' => '', 'shuffle' => 'false'], (array) $options);
         // collect pages
         $extensions = $this->config->get('pages.extensions', []);
         $path = $options['path'];
         $paths = [$path => Herbie\DI::get('Alias')->get($path)];
         $pageBuilder = new Herbie\Menu\Page\Builder($paths, $extensions);
         $collection = $pageBuilder->buildCollection();
         if (!empty($options['sort'])) {
             list($field, $direction) = explode('|', $options['sort']);
             $collection = $collection->sort($field, $direction);
         }
         if ('true' == strtolower($options['shuffle'])) {
             $collection = $collection->shuffle();
         }
         $twig = Herbie\DI::get('Twig');
         ob_start();
         foreach ($collection as $i => $item) {
             $block = Herbie\Page::create($item->path);
             if (!empty($block->layout) && $block->layout == 'default.html') {
                 $block->layout = false;
             }
             if (empty($block->layout)) {
                 echo $twig->renderPageSegment(0, $block);
             } else {
                 $twig->getEnvironment()->getExtension('herbie')->setPage($block);
                 echo $twig->render($block->layout);
             }
             ob_flush();
         }
         return ob_get_clean();
     });
 }
Example #11
0
 public static function addTwigExtension($twig)
 {
     $assets = DI::get('Assets');
     $testExtension = new TestExtension($assets);
     $twig->addExtension($testExtension);
 }
Example #12
0
 /**
  * @param string $id
  * @param int $width
  * @param int $height
  * @param int $responsive
  * @return string
  * @see http://embedresponsively.com/
  */
 public static function youtube($id, $width = 480, $height = 320, $responsive = 1)
 {
     self::$youtubeInstances++;
     $template = static::$config->get('plugins.config.video.template.youtube', '@plugin/video/templates/youtube.twig');
     return DI::get('Twig')->render($template, ['src' => sprintf('//www.youtube.com/embed/%s?rel=0', $id), 'width' => $width, 'height' => $height, 'responsive' => $responsive, 'class' => $responsive ? 'video-youtube-responsive' : '', 'instances' => self::$youtubeInstances]);
 }
Example #13
0
 protected function addLinkTag()
 {
     $this->add('link', function ($options) {
         $options = array_merge(['href' => empty($options[0]) ? '' : $options[0], 'text' => '', 'title' => '', 'class' => '', 'target' => ''], $options);
         $attribs = [];
         $attribs['title'] = $options['title'];
         $attribs['class'] = $options['class'];
         $attribs['target'] = $options['target'];
         $attribs = array_filter($attribs, 'strlen');
         // Interner Link
         if (strpos($options['href'], 'http') !== 0) {
             $options['href'] = DI::get('Url\\UrlGenerator')->generate($options['href']);
         }
         $replace = ['{href}' => $options['href'], '{attribs}' => $this->buildHtmlAttributes($attribs), '{text}' => empty($options['text']) ? $options['href'] : $options['text']];
         return strtr('<a href="{href}" {attribs}>{text}</a>', $replace);
     });
 }
 /**
  * @param string $action
  */
 protected function redirect($action)
 {
     $route = DI::get('Request')->getRoute() . ':' . $action;
     $twigExt = DI::get('Twig')->getEnvironment()->getExtension('herbie');
     $twigExt->functionRedirect($route);
 }
Example #15
0
<?php

use Herbie\DI;
use Herbie\Hook;
Hook::attach('pageLoaded', function ($page) {
    if (!empty($page->random)) {
        $menuItemCollection = DI::get('Menu\\Page\\Collection');
        $excludeRoutes = empty($page->random['excludes']) ? [] : $page->random['excludes'];
        do {
            $menuItem = $menuItemCollection->getRandom();
            $invalid = $menuItem->hidden == true || $menuItem->path == $page->path || in_array($menuItem->route, $excludeRoutes);
        } while ($invalid);
        if (isset($menuItem)) {
            $page->load($menuItem->getPath());
        }
    }
});
 protected function isAdmin()
 {
     return !empty(DI::get('Page')->adminpanel);
 }
 /**
  * @param string $id
  * @param int $width
  * @param int $height
  * @param string $type
  * @param string $class
  * @param int $zoom
  * @param string $address
  * @return string
  */
 public static function googlemapsTwig($id = 'gmap', $width = 600, $height = 450, $type = 'roadmap', $class = 'gmap', $zoom = 15, $address = '')
 {
     self::$instances++;
     $template = self::$config->get('plugins.config.googlemaps.template', '@plugin/googlemaps/templates/googlemaps.twig');
     return DI::get('Twig')->render($template, ['id' => $id . '-' . self::$instances, 'width' => $width, 'height' => $height, 'type' => $type, 'class' => $class, 'zoom' => $zoom, 'address' => $address, 'instances' => self::$instances]);
 }
Example #18
0
 /**
  * @param string $shortname
  * @return string
  */
 public static function disqusTwig($shortname)
 {
     $template = self::$config->get('plugins.config.disqus.template', '@plugin/disqus/templates/disqus.twig');
     return DI::get('Twig')->render($template, ['shortname' => $shortname]);
 }
 /**
  * @param $query
  * @return array
  */
 protected function search($query)
 {
     if (empty($query)) {
         return [];
     }
     $i = 1;
     $max = 100;
     $results = [];
     $usePageCache = $this->config->get('cache.page.enable', false);
     $usePageCache &= $this->config->get('plugins.config.simplesearch.use_page_cache', false);
     $appendIterator = new \AppendIterator();
     $appendIterator->append(DI::get('Menu\\Page\\Collection')->getIterator());
     $appendIterator->append(DI::get('Menu\\Post\\Collection')->getIterator());
     foreach ($appendIterator as $item) {
         if ($i > $max || empty($item->title) || !empty($item->no_search)) {
             continue;
         }
         $data = $this->loadPageData($item, $usePageCache);
         if ($this->match($query, $data)) {
             $results[] = $item;
             $i++;
         }
     }
     return $results;
 }
Example #20
0
 /**
  * @param string $alias
  * @return static
  */
 public static function create($alias)
 {
     $loader = DI::get('Loader\\PageLoader');
     $page = new static();
     $page->setLoader($loader);
     $page->load($alias);
     return $page;
 }
Example #21
0
 /**
  * @param string $route
  * @param string $label
  * @param array $htmlAttributes
  * @return string
  */
 protected static function createLink($route, $label, $htmlAttributes = [])
 {
     $url = DI::get('Url\\UrlGenerator')->generate($route);
     $attributesAsString = static::buildHtmlAttributes($htmlAttributes);
     return sprintf('<a href="%s"%s>%s</a>', $url, $attributesAsString, $label);
 }