コード例 #1
0
ファイル: module.php プロジェクト: icybee/core
 public function getBlock($name)
 {
     global $core;
     $args = func_get_args();
     $class_name = $this->resolve_block_class($name);
     if ($class_name) {
         array_shift($args);
         I18n::push_scope($this->flat_id);
         I18n::push_scope($this->flat_id . '.' . $name);
         try {
             $block = new $class_name($this, array(), $args);
             // 				$rendered_block = $block->render();
         } catch (\ICanBoogie\SecurityException $e) {
             I18n::pop_scope();
             I18n::pop_scope();
             throw $e;
         } catch (\Exception $e) {
             $block = \ICanBoogie\Debug::format_alert($e);
         }
         I18n::pop_scope();
         I18n::pop_scope();
         return $block;
     }
     // 		\ICanBoogie\log_info("Block class not found for <q>$name</q> falling to callbacks.");
     return call_user_func_array(PHP_MAJOR_VERSION > 5 || PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 2 ? 'parent::' . __FUNCTION__ : array($this, 'parent::' . __FUNCTION__), $args);
 }
コード例 #2
0
ファイル: content.php プロジェクト: icybee/module-pages
 public function __toString()
 {
     try {
         return (string) $this->render();
     } catch (\Exception $e) {
         return \ICanBoogie\Debug::format_alert($e);
     }
 }
コード例 #3
0
ファイル: Engine.php プロジェクト: icybee/patron
 public function __invoke($template, $bind = null, array $options = [])
 {
     if (!$template) {
         return null;
     }
     if ($bind !== null) {
         $this->context['this'] = $bind;
     }
     $file = null;
     foreach ($options as $option => $value) {
         switch ((string) $option) {
             case 'variables':
                 foreach ($value as $k => $v) {
                     $this->context[$k] = $v;
                 }
                 break;
             case 'file':
                 $file = $value;
                 break;
             default:
                 trigger_error(\ICanBoogie\format('Suspicious option: %option :value', ['%option' => $option, ':value' => $value]));
                 break;
         }
     }
     if (!$template instanceof Template) {
         if (is_array($template) && isset($template['file'])) {
             $file = $template['file'];
             unset($template['file']);
         }
         if (!is_array($template)) {
             $template = $this->get_compiled($template);
         }
         $template = new Template($template, ['file' => $file]);
     }
     if ($template->file) {
         $this->trace_enter(['file', $template->file]);
     }
     $rc = '';
     foreach ($template as $node) {
         if (!$node instanceof Node) {
             continue;
         }
         try {
             $rc .= $node($this, $this->context);
         } catch (\Exception $e) {
             if (class_exists('ICanBoogie\\Debug')) {
                 $rc .= Debug::format_alert($e);
             } else {
                 $rc .= $e;
             }
         }
         $rc .= $this->fetchErrors();
     }
     $rc .= $this->fetchErrors();
     #
     #
     #
     if ($file) {
         array_shift($this->trace);
     }
     return $rc;
 }
コード例 #4
0
ファイル: Core.php プロジェクト: icanboogie/icanboogie
 /**
  * Configures the application.
  *
  * The `configure` event of class {@link Core\ConfigureEvent} is fired after the application
  * is configured. Event hooks may use this event to further configure the application.
  */
 protected function configure()
 {
     $this->change_status(self::STATUS_CONFIGURING, function () {
         Debug::configure($this->configs['debug']);
         Prototype::configure($this->configs['prototype']);
         $this->events;
         new Core\ConfigureEvent($this);
     });
 }
コード例 #5
0
ファイル: Hooks.php プロジェクト: EhteshamMehmood/BlogMVC
 public static function before_view_render(View\BeforeRender $event, View $target)
 {
     $target['user'] = $target->controller->user;
     $target['in_admin'] = strpos($target->controller->route->id, 'admin:') === 0;
     $target['alerts'] = ['success' => new Alert(Debug::fetch_messages(\ICanBoogie\LogLevel::SUCCESS), [Alert::CONTEXT => Alert::CONTEXT_SUCCESS]), 'info' => new Alert(Debug::fetch_messages(\ICanBoogie\LogLevel::INFO), [Alert::CONTEXT => Alert::CONTEXT_INFO]), 'error' => new Alert(Debug::fetch_messages(\ICanBoogie\LogLevel::ERROR), [Alert::CONTEXT => 'danger']), 'debug' => new Alert(Debug::fetch_messages(\ICanBoogie\LogLevel::DEBUG), [])];
 }
コード例 #6
0
ファイル: site.php プロジェクト: icybee/module-sites
 protected function get_partial_templates()
 {
     $templates = array();
     $root = \ICanBoogie\DOCUMENT_ROOT;
     $models = array('default', 'all');
     foreach ($models as $model) {
         $path = self::BASE . $model . '/templates/partials';
         if (!is_dir($root . $path)) {
             continue;
         }
         $dh = opendir($root . $path);
         if (!$dh) {
             Debug::trigger('Unable to open directory %path', array('%path' => $path));
             continue;
         }
         while (($file = readdir($dh)) !== false) {
             if ($file[0] == '.') {
                 continue;
             }
             $pos = strrpos($file, '.');
             if (!$pos) {
                 continue;
             }
             $id = preg_replace('#\\.(php|html)$#', '', $file);
             $templates[$id] = $root . $path . '/' . $file;
         }
         closedir($dh);
     }
     return $templates;
 }
コード例 #7
0
ファイル: form.php プロジェクト: icybee/module-forms
 public function __toString()
 {
     try {
         return (string) $this->render();
     } catch (\Exception $e) {
         Debug::report($e);
         return Debug::format_alert($e);
     }
 }
コード例 #8
0
ファイル: View.php プロジェクト: icybee/module-views
    /**
     * Returns the HTML representation of the view element and its content.
     *
     * @return string
     */
    protected function render_outer_html()
    {
        $class = '';
        $type = \ICanBoogie\normalize($this->type);
        $m = $this->module;
        while ($m) {
            $normalized_id = \ICanBoogie\normalize($m->id);
            $class = "view--{$normalized_id}--{$type} {$class}";
            $m = $m->parent;
        }
        $this->element = new Element('div', ['id' => 'view-' . \ICanBoogie\normalize($this->id), 'class' => trim("view view--{$type} {$class}"), 'data-constructor' => $this->module->id]);
        $this->element = $this->alter_element($this->element);
        #
        $html = $o_html = $this->render_inner_html($this->engine->context);
        new RenderEvent($this, $html);
        #
        if (Debug::is_dev()) {
            $possible_templates = implode(PHP_EOL, $this->template_tries);
            $html = <<<EOT

<!-- Possible templates for view "{$this->id}":

{$possible_templates}

-->
{$html}
EOT;
        }
        $this->element[Element::INNER_HTML] = $html;
        $this->element['data-template-path'] = $this->template_pathname;
        return (string) $this->element;
    }
コード例 #9
0
ファイル: content.php プロジェクト: icybee/module-contents
 /**
  * Renders the body of the activerecord into a string.
  *
  * The body is rendered using the editor that was used to edit the content.
  *
  * A cache maybe used to store et retrieve the rendered content.
  *
  * @return string The rendered body.
  */
 public function __toString()
 {
     global $core;
     $rendered_body = $this->rendered_body;
     if ($rendered_body) {
         return $rendered_body;
     }
     $rendered_body = $body = $this->body;
     try {
         $cache = self::obtain_cache();
         if ($cache) {
             $nid = $this->nid;
             $updated_at = $this->updated_at;
             $cached = $cache->select('body')->filter_by_nid_and_updated_at($nid, $updated_at)->rc;
             if ($cached) {
                 return $cached;
             }
             if ($this->editor) {
                 $rendered_body = $this->render_body();
             }
             if ($rendered_body && $rendered_body != $body) {
                 $cache->save(['nid' => $nid, 'updated_at' => $updated_at, 'body' => $rendered_body], null, ['on duplicate' => true]);
             }
         } else {
             if ($this->editor) {
                 $rendered_body = $this->render_body();
             }
         }
     } catch (\Exception $e) {
         $rendered_body = \ICanBoogie\Debug::format_alert($e);
     }
     $this->rendered_body = $rendered_body;
     return $rendered_body;
 }