protected function render_inner_html() { global $core; $rc = parent::render_inner_html(); $constructor = $this[self::T_CONSTRUCTOR]; $value = $this['value'] ?: $this[self::DEFAULT_VALUE]; $record = null; if ($value) { $model = $core->models[$constructor]; try { $record = is_numeric($value) ? $model[$value] : $this->getEntry($model, $value); } catch (\Exception $e) { \ICanBoogie\log_error('Missing record %nid', ['%nid' => $value]); } } if (!$record) { $this->add_class('placeholder'); $value = null; } $rc .= new Element('input', ['type' => 'hidden', 'name' => $this['name'], 'value' => $value]); $placeholder = $this['placeholder']; if ($placeholder) { $rc .= '<em class="spinner-placeholder">' . \ICanBoogie\escape($placeholder) . '</em>'; } $rc .= '<span class="spinner-content">' . $this->getPreview($record) . '</span>'; return $rc; }
public function render() { global $core; $document = $core->document; $document->js->add('available-sites.js'); $document->page_title = 'Select a website'; $ws_title = \ICanBoogie\escape($core->site->admin_title ? $core->site->admin_title : $core->site->title . ':' . $core->site->language); $site_model = $core->models['sites']; $available = $site_model->where('siteid IN(' . implode(',', $core->user->restricted_sites_ids) . ')')->order('admin_title, title')->all; $uri = substr($_SERVER['REQUEST_URI'], strlen($core->site->path)); $options = []; foreach ($available as $site) { $title = $site->title . ':' . $site->language; if ($site->admin_title) { $title .= ' (' . $site->admin_title . ')'; } $options[$site->url . $uri] = $title; } $form = new Form([Form::ACTIONS => new Button('Change', ['class' => 'btn-primary', 'type' => 'submit']), Form::RENDERER => 'Simple', Element::CHILDREN => [new Element('select', [Element::DESCRIPTION => "Select one of the website available to your profile.", Element::OPTIONS => $options])], 'name' => 'change-working-site', 'class' => 'form-primary']); return <<<EOT <div id="block--site-access-denied" class="block-alert"> <h2>Access denied</h2> <p>You don't have permission to access the administration interface for the website <q>{$ws_title}</q>, please select another website to work with:</p> {$form} </div> EOT; }
protected function render_body() { global $core; $rendered_columns_cells = $this->render_columns_cells($this->columns); $rows = $this->columns_to_rows($rendered_columns_cells); $html = ''; foreach ($rows as $i => $row) { $record = $this->records[$i]; $title = $record->title; $label = new Element('a', array(Element::INNER_HTML => \ICanBoogie\escape($title), 'class' => 'goto-edit', 'title' => I18n\t('Edit this item'), 'href' => \ICanBoogie\Routing\contextualize("/admin/{$record->constructor}/{$record->nid}/edit"))); $img = $record->thumbnail('$gallery')->to_element(array('title' => $title, 'alt' => $title)); $html .= <<<EOT <div class="thumbnailer-wrapper" data-key="{$record->nid}" style="width: 128px;"> \t<a href="{$record->path}" rel="lightbox[]">{$img}</a> \t{$label} </div> EOT; } $colspan = count($this->columns) + 1; return <<<EOT <tr id="gallery"> \t<td colspan="{$colspan}" class="gallery-inner"> \t\t<div class="gallery-contents">{$html}</div> \t</td> </tr> EOT; }
public static function matches(array $args, \Patron\Engine $patron, $template) { $_GET += array('q' => null, 'start' => 0); $search = $_GET['q']; $start = $_GET['start']; if (!$search) { return; } $response = self::search($search, $start); $count = count($response->results); $total = isset($response->cursor->estimatedResultCount) ? $response->cursor->estimatedResultCount : 0; $page = 0; $pageIndex = 0; $pager = null; if ($total && count($response->cursor->pages) > 1) { $pageIndex = $response->cursor->currentPageIndex; $pages = array(); foreach ($response->cursor->pages as $i => $page) { $pages[] = $pageIndex == $i ? '<strong>' . $page->label . '</strong>' : '<a href="?start=' . $page->start . '&q=' . \ICanBoogie\escape(urlencode($search)) . '">' . $page->label . '</a>'; } $pager = '<div class="pager">' . implode('<span class="separator">, </span>', $pages) . '</div>'; } $patron->context['self']['q'] = $search; $patron->context['self']['response'] = $response; $patron->context['self']['pager'] = $pager; $patron->context['self']['range'] = array('lower' => $start + 1, 'upper' => $start + $count, 'start' => $start, 'page' => $pageIndex, 'count' => $total); return $patron($template, $response->results); }
/** * Initializes the `Location` header. * * @param string $url URL to redirect to. * @param int $status Status code (default to {@link Status::FOUND}). * @param array $headers Additional headers. * * @throws \InvalidArgumentException if the provided status code is not a redirect. */ public function __construct($url, $status = Status::FOUND, array $headers = []) { parent::__construct(function (Response $response) { $location = $response->location; $title = \ICanBoogie\escape($location); echo <<<EOT <!DOCTYPE html> <html> <head> \t<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> \t<meta http-equiv="refresh" content="1;url={$location}" /> \t<title>Redirecting to {$title}</title> </head> <body> \tRedirecting to <a href="{$location}">{$title}</a>. </body> </html> EOT; // @codeCoverageIgnore }, $status, ['Location' => $url] + $headers); if (!$this->status->is_redirect) { throw new StatusCodeNotValid($this->status->code, "The HTTP status code is not a redirect: {$status}."); } }
public function __invoke(Engine $engine, $context) { $rc = $this->render($this->expression); if ($this->escape) { $rc = \ICanBoogie\escape($rc); } return $rc; }
/** * Returns an `IMG` element. * * @return string */ public function __toString() { $path = \ICanBoogie\escape($this->path); $alt = \ICanBoogie\escape($this->alt); return <<<EOT <img src="{$path}" alt="{$alt}" width="{$this->width}" height="{$this->height}" data-nid="{$this->nid}" /> EOT; }
protected function render_inner_html() { global $core; $slug = $this->slug_el['value']; $tease = '<strong>Slug :</strong> '; $tease .= '<a href="#slug-edit" title="' . I18n\t('edit', [], ['scope' => 'titleslugcombo.element']) . '">' . ($slug ? \ICanBoogie\escape(\ICanBoogie\shorten($slug)) : $this->dataset['auto-label']) . '</a>'; $tease .= ' <span>– <a href="slug-delete" class="warn">' . I18n\t('reset', [], ['scope' => 'titleslugcombo.element']) . '</a></span>'; $this->slug_tease->inner_html = $tease; $rc = parent::render_inner_html(); $nid = $this[self::T_NODEID]; if ($nid) { $node = $core->models['nodes'][$nid]; if ($node && $node->url && $node->url[0] != '#') { $url = $node->url; $url_label = \ICanBoogie\shorten($url, 64); $rc .= '<p class="small light">'; $rc .= '<strong>URL :</strong> ' . $url_label; } } return $rc; }
/** * Replaces managed images with width or height attributes by thumbnails, and transform markup * when the original image can be displayed in a lightbox. * * @see Icybee\Modules\Editor.Editor::render() */ public function render($content) { return preg_replace_callback('#<img\\s+[^>]+>#', function ($match) { global $core; preg_match_all('#([\\w\\-]+)\\s*=\\s*\\"([^"]+)#', $match[0], $attributes); $attributes = array_combine($attributes[1], $attributes[2]); $attributes = array_map(function ($v) { return html_entity_decode($v, ENT_COMPAT, \ICanBoogie\CHARSET); }, $attributes); $attributes += array('width' => null, 'height' => null, 'data-nid' => null); $w = $attributes['width']; $h = $attributes['height']; $nid = $attributes['data-nid']; if ($w && $h && $nid) { $attributes['src'] = Operation::encode('images/' . $nid . '/' . $w . 'x' . $h); } else { if (($w || $h) && preg_match('#^/repository/files/image/(\\d+)#', $attributes['src'], $matches)) { $nid = $matches[1]; $options = $attributes; unset($options['src']); $thumbnail = new Thumbnail($core->models['images'][$nid], $options); $attributes['src'] = $thumbnail->url; } } $path = null; if (isset($attributes['data-lightbox']) && $nid) { $attributes['src'] = preg_replace('#\\&lightbox=true#', '', $attributes['src']); $path = $core->models['images']->select('path')->filter_by_nid($nid)->rc; } unset($attributes['data-nid']); unset($attributes['data-lightbox']); $rc = (string) new Element('img', $attributes); if ($path) { $rc = '<a href="' . \ICanBoogie\escape($path) . '" rel="lightbox[]">' . $rc . '</a>'; } return $rc; }, $content); }
protected function render_preview(\ICanBoogie\ActiveRecord $record) { return \ICanBoogie\escape($record->contents); }
function _do_php_symbol($matches) { return $this->hashPart('<span class="symbol">' . \ICanBoogie\escape($matches[0]) . '</span>'); }
protected function render_subcategories(array $categories, $selected_category, $selected_subcategory) { $html = ''; foreach ($categories as $category => $subcategories) { $html .= '<ul' . ($category == $selected_category ? ' class="active selected"' : '') . '>'; foreach ($subcategories as $subcategory => $views) { $html .= '<li' . ($subcategory == $selected_subcategory ? ' class="active selected"' : '') . '><a href="#select">' . \ICanBoogie\escape($subcategory) . '</a></li>'; } $html .= '</ul>'; } return $html; }
public static function markup_page_title(array $args, $engine, $template) { global $core; $page = $core->request->context->page; $title = $page->title; $html = \ICanBoogie\escape($title); new Page\RenderTitleEvent($page, array('title' => $title, 'html' => &$html)); return $template ? $engine($template, $html) : $html; }
public static function create_attachment($entry, $hard_bond = false) { global $core; $hiddens = null; $links = array(); $i = uniqid(); $size = \ICanBoogie\I18n\format_size($entry->size); $preview = null; if ($entry instanceof Uploaded) { $title = $entry->name; $extension = $entry->extension; $hiddens .= '<input type="hidden" class="file" name="nodes_attachments[' . $i . '][file]" value="' . \ICanBoogie\escape(basename($entry->location)) . '" />' . PHP_EOL; $hiddens .= '<input type="hidden" name="nodes_attachments[' . $i . '][mime]" value="' . \ICanBoogie\escape($entry->mime) . '" />' . PHP_EOL; $links = array('<a href="#remove" class="btn btn-warning">' . I18n\t('label.remove') . '</a>'); } else { $fid = $entry->nid; $title = $entry->title; $extension = substr($entry->path, strrpos($entry->path, '.')); $hiddens .= '<input type="hidden" name="nodes_attachments[' . $i . '][fileid]" value="' . $fid . '" />'; $links = array('<a href="' . \ICanBoogie\Routing\contextualize('/admin/files/' . $fid . '/edit') . '" class="btn"><i class="icon-pencil"></i> ' . I18n\t('label.edit') . '</a>', '<a href="' . Operation::encode('files/' . $fid . '/download') . '" class="btn"><i class="icon-download-alt"></i> ' . I18n\t('label.download') . '</a>', $hard_bond ? '<a href="#delete" class="btn btn-danger"><i class="icon-remove icon-white"></i> ' . I18n\t('Delete file') . '</a>' : '<a href="#remove" class="btn btn-warning"><i class="icon-remove"></i> ' . t('Break link') . '</a>'); $node = $core->models['nodes'][$entry->nid]; if ($node instanceof \Icybee\Modules\Images\Image) { $preview = $node->thumbnail('$icon')->to_element(array('data-popover-image' => $node->thumbnail('$popup')->url)); } } $title = \ICanBoogie\escape($title); $links = empty($links) ? '' : ' – ' . implode(' ', $links); if ($extension) { $extension = '<span class="lighter">(' . $extension . ')</span>'; } return <<<EOT <li> \t<span class="handle">↕</span>{$preview}<input type="text" name="nodes_attachments[{$i}][title]" value="{$title}" /> \t<span class="small"> \t\t<span class="info light">{$size} {$extension}</span> {$links} \t</span> \t{$hiddens} </li> EOT; }
private static function make_link(\Icybee\Modules\Files\File $file, $label = null) { if (!$label) { $label = $file->label; } return '<a href="' . \ICanBoogie\escape($file->url('download')) . '">' . \ICanBoogie\escape($label) . '</a> <span class="metas">(' . $file->extension . ' – ' . \ICanBoogie\I18n\format_size($file->size) . ')</span>'; }
function make_set($constructor, $entries, $count, $search, $has_pager = false) { global $core; $flat_id = 'module.' . strtr($constructor, '.', '_'); $rc = '<div class="set">'; if (empty($_GET['constructor'])) { $title = $constructor == 'google' ? 'Google' : $core->modules->descriptors[$constructor][Module::T_TITLE]; $title = I18n\t(strtr($constructor, '.', '_'), array(), array('scope' => 'module_title', 'default' => $title)); $rc .= '<h2>' . $title . '</h2>'; } $rc .= '<p class="count">'; $rc .= I18n\t('found', array(':count' => $count, '%search' => $search), array('scope' => array($flat_id, 'search'))); $rc .= '</p>'; if ($entries) { $rc .= '<ol>'; foreach ($entries as $entry) { $rc .= '<li>'; $rc .= '<h3><a href="' . $entry->url . '">' . \ICanBoogie\escape(\ICanBoogie\shorten($entry->title, 80)) . '</a></h3>'; $rc .= '<cite>' . \ICanBoogie\shorten($entry->url, 64) . '</cite>'; $excerpt = search_excerpt($search, html_entity_decode($entry->body, ENT_COMPAT, 'utf-8')); $rc .= '<p class="excerpt">' . $excerpt . '</p>'; $rc .= '</li>'; } $rc .= '</ol>'; if ($count > count($entries)) { if ($has_pager) { $rc .= new Pager('div', array(Pager::T_COUNT => $count, Pager::T_LIMIT => $core->site->metas->get('search.limits.list', 10), Pager::T_POSITION => isset($_GET['page']) ? (int) $_GET['page'] : 0, Pager::T_WITH => 'q,constructor', 'class' => 'pagination')); } else { $more_url = '?' . http_build_query(array('q' => $search, 'constructor' => $constructor)); $rc .= '<p class="more"><a href="' . $more_url . '">'; $rc .= I18n\t('more', array(':count' => $count, '%search' => $search), array('scope' => array($flat_id, 'search'))); $rc .= '</a></p>'; } } } $rc .= '</div>'; return $rc; }
public static function dashboard_last() { global $core; if (empty($core->modules['comments'])) { return; } $document = $core->document; $document->css->add('../public/admin.css'); $model = $core->models['comments']; $entries = $model->where('(SELECT 1 FROM {prefix}nodes WHERE nid = comment.nid AND (siteid = 0 OR siteid = ?)) IS NOT NULL', $core->site_id)->order('created DESC')->limit(5)->all; if (!$entries) { return '<p class="nothing">' . I18n\t('No record yet') . '</p>'; } $model->including_node($entries); $rc = ''; $context = $core->site->path; foreach ($entries as $entry) { $url = $entry->url; $author = \ICanBoogie\escape($entry->author); if ($entry->author_url) { $author = '<a class="author" href="' . \ICanBoogie\escape($entry->author_url) . '">' . $author . '</a>'; } else { $author = '<strong class="author">' . $author . '</strong>'; } $excerpt = \ICanBoogie\shorten(strip_tags((string) html_entity_decode($entry, ENT_COMPAT, \ICanBoogie\CHARSET)), 140); $target_url = $entry->node->url; $target_title = \ICanBoogie\escape(\ICanBoogie\shorten($entry->node->title)); $image = \ICanBoogie\escape($entry->author_icon); $entry_class = $entry->status == 'spam' ? 'spam' : ''; $url_edit = "{$context}/admin/comments/{$entry->commentid}/edit"; $url_delete = "{$context}/admin/comments/{$entry->commentid}/delete"; $date = \ICanBoogie\I18n\format_date($entry->created, 'dd MMM'); $txt_delete = I18n\t('Delete'); $txt_edit = I18n\t('Edit'); $txt_display_associated_node = I18n\t('Display associated node'); $rc .= <<<EOT <div class="record {$entry_class}"> \t<div class="options"> \t\t<img src="{$image}&s=48" alt="" /> \t</div> \t<div class="contents"> \t\t<div class="head"> \t\t{$author} \t\t<span class="date light">{$date}</span> \t\t</div> \t\t<div class="body"><a href="{$url}">{$excerpt}</a></div> \t\t<div class="actions light"> \t\t\t<a href="{$url_edit}">{$txt_edit}</a>, <a href="{$url_delete}" class="danger">{$txt_delete}</a> − <a href="{$target_url}" class="target" title="{$txt_display_associated_node}">{$target_title}</a> \t\t</div> \t</div> </div> EOT; } $count = $model->joins(':nodes')->where('siteid = 0 OR siteid = ?', $core->site_id)->count; $txt_all_comments = I18n\t('comments.count', array(':count' => $count)); $rc .= <<<EOT <div class="panel-footer"><a href="{$context}/admin/comments">{$txt_all_comments}</a></div> EOT; return $rc; }
public static function dashboard_user_modified() { global $core, $document; $document->css->add(DIR . 'public/dashboard.css'); $model = $core->models['nodes']; $entries = $model->where('uid = ? AND (siteid = 0 OR siteid = ?)', [$core->user_id, $core->site_id])->order('updated_at desc')->limit(10)->all; if (!$entries) { return '<p class="nothing">' . I18n\t('No record yet') . '</p>'; } $last_date = null; $context = $core->site->path; $rc = '<table>'; foreach ($entries as $record) { $date = \ICanBoogie\I18n\date_period($record->updated_at); if ($date === $last_date) { $date = '—'; } else { $last_date = $date; } $title = \ICanBoogie\shorten($record->title, 48); $title = \ICanBoogie\escape($title); $rc .= <<<EOT \t<tr> \t<td class="date light">{$date}</td> \t<td class="title"><a href="{$context}/admin/{$record->constructor}/{$record->nid}/edit">{$title}</a></td> \t</tr> EOT; } $rc .= '</table>'; return $rc; }
/** * The component is shortened if it's longer than 52 characters, in which case the title of * the element is modified to include the original component. */ public function render() { $element = parent::render(); $component = $this->component; $html = $component ? \ICanBoogie\escape(\ICanBoogie\shorten($component, 52, 0.75, $shortened)) : I18n\t('<em>no title</em>'); if (!$shortened) { return $element; } $element[Element::INNER_HTML] = str_replace('…', '<span class="light">…</span>', $html); $element['title'] = I18n\t('manage.edit_named', [':title' => $component ? $component : 'unnamed']); return $element; }
public function render_cell($record) { $property = $this->id; $node = $record->node; $rc = ''; if ($node) { $title = $node->title; $label = \ICanBoogie\escape(\ICanBoogie\shorten($title, 48, 0.75, $shortened)); $rc .= new A("", $node->url, array('title' => $title, 'class' => 'icon-external-link')) . ' '; } else { $label = '<em class="warn">unknown-node-' . $record->{$property} . '</em>'; } return $rc . new FilterDecorator($record, $property, $this->is_filtering, $label); }
continue; } $class = ''; if ($branch->children) { $class .= 'has-children'; } $record = $branch->record; if (!empty($record->is_active)) { if ($class) { $class .= ' '; } $class .= 'active'; } $class .= ' nid-' . $record->nid; $rc .= $class ? '<li class="' . trim($class) . '">' : '<li>'; $rc .= '<a href="' . $record->url . '">' . \ICanBoogie\escape($record->label) . '</a>'; if (($depth === false || $level < $depth) && $branch->children) { $rc .= $builder($branch->children, $depth, $min_child, $level + 1); } $rc .= '</li>'; } if (!$rc) { return; } return '<ol class="lv' . $level . '">' . $rc . '</ol>'; }; $model = $core->models['pages']; $blueprint = $model->blueprint($core->site_id); $subset = $blueprint->subset(null, null, function ($branch) { return $branch->pattern || !$branch->is_online; });
public function __construct() { $this->title = t('requirement.user_config.title'); $this->description = t('requirement.user_config.description', array('action' => new TellMeMore('user_config'), 'data' => '<textarea class="span8" readonly="readonly">' . \ICanBoogie\escape($this->get_data()) . '</textarea>')); }
/** * Formats a stack trace into an HTML element. * * @param array $trace * * @return string */ public static function format_trace(array $trace) { $root = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']); $count = count($trace); $count_max = strlen((string) $count); $rc = "<strong>Stack trace:</strong>\n"; foreach ($trace as $i => $node) { $trace_file = null; $trace_line = 0; $trace_class = null; $trace_type = null; $trace_args = null; $trace_function = null; extract($node, EXTR_PREFIX_ALL, 'trace'); if ($trace_file) { $trace_file = str_replace('\\', '/', $trace_file); $trace_file = str_replace($root, '', $trace_file); } $params = []; if ($trace_args) { foreach ($trace_args as $arg) { switch (gettype($arg)) { case 'array': $arg = 'Array'; break; case 'object': $arg = get_class($arg); break; case 'resource': $arg = 'Resource of type ' . get_resource_type($arg); break; case 'null': $arg = 'null'; break; default: if (strlen($arg) > self::MAX_STRING_LEN) { $arg = substr($arg, 0, self::MAX_STRING_LEN) . '...'; } $arg = '\'' . $arg . '\''; break; } $params[] = $arg; } } $rc .= sprintf("\n%{$count_max}d. <em>%s%s</em>%s%s%s(%s)", $count - $i, $trace_file, $trace_file ? ":{$trace_line} " : "", $trace_class, $trace_type, $trace_function, \ICanBoogie\escape(implode(', ', $params))); } return $rc; }
public function render($content) { global $core; $page = $core->request->context->page; $site = $page->site; $options = $content; $constructor = $options['constructor']; $limit = $options['limit']; $with_author = false; if (isset($options['settings'])) { $options['settings']['is_with_author']; } $gmt_offset = $core->timezone; $fdate = $core->locale->calendar->date_formatter; $time_pattern = "y-MM-dd'T'HH:mm:ss"; $host = preg_replace('#^www\\.#', '', $_SERVER['SERVER_NAME']); $page_created_at = $fdate($page->created_at, 'y-MM-dd'); $entries = $core->models[$constructor]->filter_by_constructor($constructor)->visible->order('date DESC')->limit($limit)->all; ob_start(); ?> <id>tag:<?php echo $host; ?> ,<?php echo $page_created_at; ?> :<?php echo $page->slug; ?> </id> <title><?php echo $page->title; ?> </title> <link href="<?php echo $page->absolute_url; ?> " rel="self" /> <link href="<?php echo $page->home->absolute_url; ?> " /> <author> <name><?php $user = $page->user; echo $user->firstname && $user->lastname ? $user->firstname . ' ' . $user->lastname : $user->name; ?> </name> </author> <updated><?php $updated = ''; foreach ($entries as $entry) { if (strcmp($updated, $entry->updated_at) < 0) { $updated = $entry->updated_at; } } echo $fdate($updated, $time_pattern) . $gmt_offset; ?> </updated> <?php foreach ($entries as $entry) { ?> <entry> <title><?php echo \ICanBoogie\escape($entry->title); ?> </title> <link href="<?php echo $entry->absolute_url; ?> " /> <id>tag:<?php echo $host; ?> ,<?php echo $fdate($entry->created_at, 'y-MM-dd'); ?> :<?php echo $entry->slug; ?> </id> <updated><?php echo $fdate($entry->updated_at, $time_pattern) . $gmt_offset; ?> </updated> <published><?php echo $fdate($entry->date, $time_pattern) . $gmt_offset; ?> </published> <?php if ($with_author) { ?> <author> <name><?php $user = $entry->user; echo $user->firstname && $user->lastname ? $user->firstname . ' ' . $user->lastname : $entry->user->name; ?> </name> </author> <?php } ?> <?php /* <category term="<?php echo $entry->category ?>" /> */ ?> <content type="html" xml:lang="<?php echo $entry->language ? $entry->language : $site->language; ?> "><![CDATA[<?php echo $entry; ?> ]]></content> </entry> <?php } $rc = ob_get_clean(); $rc = preg_replace('#(href|src)="/#', '$1="http://' . $host . '/', $rc); header('Content-Type: application/atom+xml;charset=utf-8'); //header('Content-Type: text/plain'); echo '<?xml version="1.0" encoding="utf-8"?> <feed xmlns="http://www.w3.org/2005/Atom">' . $rc . '</feed>'; exit; }