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\Exception;
 15 
 16 /**
 17  * "Widgets" editor.
 18  */
 19 class WidgetsEditor implements Editor
 20 {
 21     /**
 22      * Returns a JSON string.
 23      *
 24      * @see Icybee\Modules\Editor.Editor::serialize()
 25      */
 26     public function serialize($content)
 27     {
 28         return json_encode(array_keys($content));
 29     }
 30 
 31     /**
 32      * Returns unserialized JSON content.
 33      *
 34      * @see Icybee\Modules\Editor.Editor::unserialize()
 35      */
 36     public function unserialize($serialized_content)
 37     {
 38         return (array) json_decode($serialized_content);
 39     }
 40     /**
 41      * @return WidgetsEditorElement
 42      *
 43      * @see Icybee\Modules\Editor.Editor::from()
 44      */
 45     public function from(array $attributes)
 46     {
 47         return new WidgetsEditorElement($attributes);
 48     }
 49 
 50     /**
 51      * Renders selected widgets.
 52      *
 53      * @see Icybee\Modules\Editor.Editor::render()
 54      */
 55     public function render($content)
 56     {
 57         global $core;
 58 
 59         if (!$content)
 60         {
 61             return;
 62         }
 63 
 64         $availables = $core->configs->synthesize('widgets', 'merge');
 65 
 66         if (!$availables)
 67         {
 68             return;
 69         }
 70 
 71         $selected = array_flip($content);
 72         $undefined = array_diff_key($selected, $availables);
 73 
 74         if ($undefined)
 75         {
 76             throw new Exception('Undefined widget(s): :list', array(':list' => implode(', ', array_keys($undefined))));
 77         }
 78 
 79         $list = array_intersect_key($availables, $selected);
 80 
 81         if (!$list)
 82         {
 83             return;
 84         }
 85 
 86         $html = '';
 87         $list = array_merge($selected, $list);
 88 
 89         foreach ($list as $id => $widget)
 90         {
 91             $html .= '<div id="widget-' . \ICanBoogie\normalize($id) . '" class="widget">' . $this->render_widget($widget, $id) . '</div>';
 92         }
 93 
 94         return $html;
 95     }
 96 
 97     private function render_widget($widget, $id)
 98     {
 99         global $core;
100 
101         if (isset($widget['file']))
102         {
103             $file = $widget['file'];
104 
105             if (substr($file, -4, 4) == '.php')
106             {
107                 ob_start();
108 
109                 require $file;
110 
111                 return ob_get_clean();
112             }
113             else if (substr($file, -5, 5) == '.html')
114             {
115                 $patron = new \Patron\Engine;
116 
117                 return $patron(file_get_contents($file), null, array('file' => $file));
118             }
119             else
120             {
121                 throw new Exception('Unable to process file %file, unsupported type', array('%file' => $file));
122             }
123         }
124         else if (isset($widget['module']) && isset($widget['block']))
125         {
126             return $core->modules[$widget['module']]->getBlock($widget['block']);
127         }
128         else
129         {
130             throw new Exception('Unable to render widget %widget, its description is invalid.', array('%widget' => $id));
131         }
132     }
133 }
Autodoc API documentation generated by ApiGen 2.8.0