public function before() { parent::before(); $this->m_manager = TemplateManager::create(BRAMBLE_TEMPLATES); $this->m_manager->register('subvert', function ($options, $context, $text) { $subvert_options = []; $subvert_options['image_callback'] = function (&$attributes) { // add dimensions to url $width = isset($attributes['width']) ? $attributes['width'] : '0'; $height = isset($attributes['height']) ? $attributes['height'] : '0'; if (ctype_digit($width) && ctype_digit($height) && ($width != 0 || $height != 0)) { $parts = pathinfo($attributes['src']); $attributes['src'] = sprintf('%s/%s-%sx%s.%s', $parts['dirname'], $parts['filename'], $width, $height, $parts['extension']); } }; if ($options) { if (isset($options['code'])) { $subvert_options['code_formatting'] = true; } if (isset($options['root'])) { $subvert_options['root_url'] = BRAMBLE_URL; } if (isset($options['header'])) { $subvert_options['header_level'] = (int) $options['header']; } else { // does it make sense to have this here? $subvert_options['header_level'] = 3; } } return Subvert::Parse($text, $subvert_options); }); $this->m_manager->register('format-date', function ($options, $context, $date) { if (is_string($date)) { $date = strtotime($date); } if ($options) { if (isset($options['atom'])) { $date = date(\DateTime::ATOM, $date); } else { if (count($options) === 1) { $date = date(trim(key($options), "'"), $date); } } } else { $date = date('Y-m-d', $date); } return $date; }); $this->m_manager->register('format-url', function ($options, $context) { if ($options && count($options) === 1) { if (isset($options['post'])) { $time = $context['time']; if (is_string($time)) { $time = strtotime($time); } return self::_format_post_url($time, $context['slug']); } else { if (isset($options['page'])) { return self::_format_page_url($context['slug']); } else { if (isset($options['category'])) { return self::_format_category_url($context['slug']); } else { if (isset($options['archive'])) { $time = $context['month']; if (is_string($time)) { $time = strtotime($time); } return self::_format_archive_url($time); } } } } } return ''; }); }
public function before() { parent::before(); $this->m_response->status(200)->content_type(Response::CONTENT_TYPE_JSON)->cache_control(Response::CACHE_CONTROL_NOCACHE)->expires(Response::HTTP_DATE_ANCIENT); }
private static function create_posts_list(array $rows) { return Controller::map_each($rows, ['time', 'title', 'slug', 'content', 'display' => 'author'], ['categories' => [PageCategories::class, 'load']]); }