Autodoc
  • Namespace
  • Class
  • Tree

Namespaces

  • BlueTihi
    • Context
  • Brickrouge
    • Element
      • Nodes
    • Renderer
    • Widget
  • ICanBoogie
    • ActiveRecord
    • AutoConfig
    • CLDR
    • Composer
    • Core
    • Event
    • Exception
    • HTTP
      • Dispatcher
      • Request
    • I18n
      • Translator
    • Mailer
    • Modules
      • Taxonomy
        • Support
      • Thumbnailer
        • Versions
    • Object
    • Operation
      • Dispatcher
    • Prototype
    • Routes
    • Routing
      • Dispatcher
    • Session
  • Icybee
    • ActiveRecord
      • Model
    • ConfigOperation
    • Document
    • EditBlock
    • Element
      • ActionbarContextual
      • ActionbarSearch
      • ActionbarToolbar
    • FormBlock
    • Installer
    • ManageBlock
    • Modules
      • Articles
      • Cache
        • Collection
        • ManageBlock
      • Comments
        • ManageBlock
      • Contents
        • ManageBlock
      • Dashboard
      • Editor
        • Collection
      • Files
        • File
        • ManageBlock
      • Forms
        • Form
        • ManageBlock
      • I18n
      • Images
        • ManageBlock
      • Members
      • Modules
        • ManageBlock
      • Nodes
        • ManageBlock
        • Module
      • Pages
        • BreadcrumbElement
        • LanguagesElement
        • ManageBlock
        • NavigationBranchElement
        • NavigationElement
        • Page
        • PageController
      • Registry
      • Search
      • Seo
      • Sites
        • ManageBlock
      • Taxonomy
        • Terms
          • ManageBlock
        • Vocabulary
          • ManageBlock
      • Users
        • ManageBlock
        • NonceLogin
        • Roles
      • Views
        • ActiveRecordProvider
        • Collection
        • View
    • Operation
      • ActiveRecord
      • Constructor
      • Module
      • Widget
    • Rendering
  • None
  • Patron
  • PHP

Classes

  • ChangeOperation
  • Collection
  • FeedEditor
  • FeedEditorElement
  • ImageEditor
  • ImageEditorElement
  • Module
  • MultiEditorElement
  • NodeEditor
  • NodeEditorElement
  • PatronEditor
  • PatronEditorElement
  • PHPEditor
  • PHPEditorElement
  • RawEditor
  • RawEditorElement
  • RTEEditor
  • RTEEditorElement
  • SelectorElement
  • TabbableEditor
  • TabbableEditorElement
  • TabbableEditorRenderer
  • TabbableNewPaneOperation
  • TextEditor
  • TextEditorElement
  • TextmarkEditor
  • TextmarkEditorElement
  • WidgetsEditor
  • WidgetsEditorElement

Interfaces

  • Editor
  • EditorElement

Exceptions

  • EditorAlreadyInstantiated
  • EditorNotDefined
  1 <?php
  2 
  3 /*
  4  * This file is part of the Icybee package.
  5  *
  6  * (c) Olivier Laviale <olivier.laviale@gmail.com>
  7  *
  8  * For the full copyright and license information, please view the LICENSE
  9  * file that was distributed with this source code.
 10  */
 11 
 12 namespace Icybee\Modules\Editor;
 13 
 14 use ICanBoogie\Modules\Thumbnailer\Thumbnail;
 15 use ICanBoogie\Operation;
 16 
 17 use Brickrouge\Element;
 18 
 19 /**
 20  * RTE editor.
 21  */
 22 class RTEEditor implements Editor
 23 {
 24     /**
 25      * Returns the content as is.
 26      *
 27      * @see Icybee\Modules\Editor.Editor::serialize()
 28      */
 29     public function serialize($content)
 30     {
 31         return $content;
 32     }
 33 
 34     /**
 35      * Returns the serialized content as is.
 36      *
 37      * @see Icybee\Modules\Editor.Editor::unserialize()
 38      */
 39     public function unserialize($serialized_content)
 40     {
 41         return $serialized_content;
 42     }
 43 
 44     /**
 45      * Replaces managed images with width or height attributes by thumbnails, and transform markup
 46      * when the original image can be displayed in a lightbox.
 47      *
 48      * @see Icybee\Modules\Editor.Editor::render()
 49      */
 50     public function render($content)
 51     {
 52         return preg_replace_callback
 53         (
 54             '#<img\s+[^>]+>#', function($match)
 55             {
 56                 global $core;
 57 
 58                 preg_match_all('#([\w\-]+)\s*=\s*\"([^"]+)#', $match[0], $attributes);
 59 
 60                 $attributes = array_combine($attributes[1], $attributes[2]);
 61                 $attributes = array_map(function($v) { return html_entity_decode($v, ENT_COMPAT, \ICanBoogie\CHARSET); }, $attributes);
 62                 $attributes += array
 63                 (
 64                     'width' => null,
 65                     'height' => null,
 66                     'data-nid' => null
 67                 );
 68 
 69                 $w = $attributes['width'];
 70                 $h = $attributes['height'];
 71                 $nid = $attributes['data-nid'];
 72 
 73                 if ($w && $h && $nid)
 74                 {
 75                     $attributes['src'] = Operation::encode('images/' . $nid . '/' . $w . 'x' . $h);
 76                 }
 77                 else if (($w || $h) && preg_match('#^/repository/files/image/(\d+)#', $attributes['src'], $matches))
 78                 {
 79                     $nid = $matches[1];
 80 
 81                     $options = $attributes;
 82 
 83                     unset($options['src']);
 84 
 85                     $thumbnail = new Thumbnail($core->models['images'][$nid], $options);
 86 
 87                     $attributes['src'] = $thumbnail->url;
 88                 }
 89 
 90                 $path = null;
 91 
 92                 if (isset($attributes['data-lightbox']) && $nid)
 93                 {
 94                     $attributes['src'] = preg_replace('#\&amp;lightbox=true#', '', $attributes['src']);
 95                     $path = $core->models['images']->select('path')->filter_by_nid($nid)->rc;
 96                 }
 97 
 98                 unset($attributes['data-nid']);
 99                 unset($attributes['data-lightbox']);
100 
101                 $rc = (string) new Element('img', $attributes);
102 
103                 if ($path)
104                 {
105                     $rc = '<a href="' . \ICanBoogie\escape($path) . '" rel="lightbox[]">' . $rc . '</a>';
106                 }
107 
108                 return $rc;
109             },
110 
111             $content
112         );
113     }
114 
115     /**
116      * @return RTEEditorElement
117      *
118      * @see Icybee\Modules\Editor.Editor::from()
119      */
120     public function from(array $attributes)
121     {
122         return new RTEEditorElement($attributes);
123     }
124 }
Autodoc API documentation generated by ApiGen 2.8.0