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); }
public function __toString() { try { return (string) $this->render(); } catch (\Exception $e) { return \ICanBoogie\Debug::format_alert($e); } }
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; }
/** * 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); }); }
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), [])]; }
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; }
public function __toString() { try { return (string) $this->render(); } catch (\Exception $e) { Debug::report($e); return Debug::format_alert($e); } }
/** * 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; }
/** * 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; }