예제 #1
0
 /**
  * Generates new UI module
  * 
  * @param  string                                      $id   Module ID
  * @param  array                                       $args Module arguments
  * @return Ponticlaro\Bebop\UI\Patterns\ModuleAbstract       Module instance
  */
 public static function __callStatic($id, array $args)
 {
     if (ModuleFactory::canManufacture($id)) {
         $args = isset($args[0]) && is_array($args[0]) ? $args[0] : [];
         return call_user_func_array(array('Ponticlaro\\Bebop\\UI\\Helpers\\ModuleFactory', 'create'), [$id, $args]);
     }
 }
예제 #2
0
 /**
  * Calls to undefined functions
  * 
  * @param  string $name Function name
  * @param  array  $args Function arguments
  * @return object       This class instance
  */
 public function __call($name, array $args = [])
 {
     // Quick method to add sections
     if (ModuleFactory::canManufacture($name)) {
         $args = isset($args[0]) && is_array($args[0]) ? $args[0] : [];
         $section = ModuleFactory::create($name, $args);
         $this->sections->push($section);
     }
     return $this;
 }
예제 #3
0
 /**
  * Build item views from sections
  * 
  * @return void
  */
 protected function buildItemViewsFromSections()
 {
     $view_sections = $this->views_sections->getAll();
     foreach ($view_sections as $view => $sections) {
         // Add Gallery Mode sections
         if ($this->isMode('gallery')) {
             array_unshift($sections, ModuleFactory::create('rawHtml', ['ui' => 'rawHtml', 'html' => '</div>']));
             $file_upload_config = array_merge(['before' => '<div class="bebop-ui-mod bebop-ui-mod-fileupload">'], $this->getConfig('file_upload') ?: []);
             array_unshift($sections, ModuleFactory::create('fileupload', $file_upload_config));
             array_unshift($sections, ModuleFactory::create('rawHtml', ['ui' => 'rawHtml', 'html' => '<div bebop-ui-mod-list--item-with-media-source-visual><div bebop-ui-mod-list--media-source-embed>']));
             // Add default reorder view for gallery mode
             if ($view == 'reorder' && count($sections) == 1) {
                 $sections[] = ModuleFactory::create('rawHtml', ['html' => '<span class="bebop-list--media-title">{{image.title}}</span>']);
             }
             // Making sure old style gallery mode with template files still works
             if ($this->getItemView($view)) {
                 $sections[] = ModuleFactory::create('rawHtml', ['html' => $this->getHtml($this->getItemView($view))]);
             }
             $sections[] = ModuleFactory::create('rawHtml', ['ui' => 'rawHtml', 'html' => '</div>']);
         }
         // Handle manually added sections
         if ($sections && is_array($sections)) {
             ob_start();
             foreach ($sections as $section) {
                 $data = [];
                 if ($section->getVar('name')) {
                     $data[$section->getVar('name')] = '{{' . $section->getVar('name') . '}}';
                 }
                 // Handle checked/selected
                 $el = $section->getEl();
                 if ($el) {
                     if (is_a($el, 'Ponticlaro\\Bebop\\Html\\Elements\\Select')) {
                         $section->preRendering();
                         if ($section->configIsValid()) {
                             $section->renderBeforeMainTemplate();
                             echo $el->getOpeningTag();
                             if (is_a($section, 'Ponticlaro\\Bebop\\UI\\Modules\\PostSearch')) {
                                 $name = $el->getName();
                                 echo "{{#{$name}}}<option selected value='{{.}}'>{{.}}</option>{{/{$name}}}";
                             } else {
                                 $opt_elements = $el->getOptionsAsElements();
                                 if ($opt_elements) {
                                     foreach ($opt_elements as $opt_el) {
                                         $name = $opt_el->getName();
                                         $value = $opt_el->getValue();
                                         $opt_el->removeAttr('selected');
                                         // Set 'selected' attribute for Mustache
                                         if ($el->allowsMultipleValues()) {
                                             $opt_el->setAttr("{{#{$name}_has_{$value}}}selected{{/{$name}_has_{$value}}}");
                                         } else {
                                             $opt_el->setAttr("{{#{$name}_is_{$value}}}selected{{/{$name}_is_{$value}}}");
                                         }
                                         $opt_el->render();
                                     }
                                 }
                             }
                             echo $el->getClosingTag();
                             $section->renderAfterMainTemplate();
                         }
                     } elseif (is_a($el, 'Ponticlaro\\Bebop\\Html\\Elements\\Checkbox') || is_a($el, 'Ponticlaro\\Bebop\\Html\\Elements\\Radio')) {
                         $section->preRendering();
                         if ($section->configIsValid()) {
                             $section->renderBeforeMainTemplate();
                             $elements = $el->getOptionsAsElements();
                             if ($elements) {
                                 foreach ($elements as $opt_el) {
                                     $name = $opt_el->getName();
                                     $value = $opt_el->getValue();
                                     $opt_el->removeAttr('checked');
                                     // Set 'checked' attribute for Mustache
                                     if ($opt_el->allowsMultipleValues()) {
                                         $opt_el->setAttr("{{#{$name}_has_{$value}}}checked{{/{$name}_has_{$value}}}");
                                     } else {
                                         $opt_el->setAttr("{{#{$name}_is_{$value}}}checked{{/{$name}_is_{$value}}}");
                                     }
                                     $opt_el->render();
                                 }
                             }
                             $section->renderAfterMainTemplate();
                         }
                     } elseif (is_a($el, 'Ponticlaro\\Bebop\\UI\\Plugins\\ContentList\\ContentList')) {
                         $section->preRendering();
                         if ($section->configIsValid()) {
                             $el->setConfig('data', '{{' . $el->getFieldName() . '}}');
                             $el->setConfig('childList', true);
                             $section->renderBeforeMainTemplate();
                             $section->renderMainTemplate();
                             $section->renderAfterMainTemplate();
                         }
                     } elseif (is_a($el, 'Ponticlaro\\Bebop\\UI\\Plugins\\Media\\Media')) {
                         $section->preRendering();
                         if ($section->configIsValid()) {
                             $el->setConfig('data', '{{' . $el->getName() . '}}');
                             $section->renderBeforeMainTemplate();
                             $section->renderMainTemplate();
                             $section->renderAfterMainTemplate();
                         }
                     } elseif (is_a($el, 'Ponticlaro\\Bebop\\Html\\ControlElement')) {
                         $el->setValue('{{' . $section->getVar('name') . '}}');
                         $section->setEl($el)->render($data);
                     }
                 } else {
                     $section->render($data);
                 }
             }
             $html = ob_get_contents();
             ob_end_clean();
             $this->setItemView($view, $html);
         }
     }
 }