if ( $src_extension ) {
$result .= '.'.$src_extension;
}
return $result;
}
/**
* @param string $load_filename
* @param string $save_filename
*/
protected function run_animated_gif( $load_filename, $save_filename, $editor ) {
$current_size = $editor->get_size();
$src_w = $current_size['width'];
$src_h = $current_size['height'];
$w = $this->w;
$h = $this->h;
if ( !class_exists('Imagick') ) {
Helper::error_log( 'Can not resize GIF, Imagick is not installed' );
}
$image = new \Imagick($load_filename);
$image = $image->coalesceImages();
$crop = self::get_target_sizes($editor);
foreach ( $image as $frame ) {
$frame->cropImage($crop['src_w'], $crop['src_h'], $crop['x'], $crop['y']);
$frame->thumbnailImage($w, $h);
$frame->setImagePage($w, $h, 0, 0);
}
$image = $image->deconstructImages();
return $image->writeImages($save_filename, true);
}
/**
* @param WP_Image_Editor $image
*/
protected function get_target_sizes( \WP_Image_Editor $image ) {
$w = $this->w;
$h = $this->h;
$crop = $this->crop;
$current_size = $image->get_size();
/**
* Performs the actual image manipulation,
* including saving the target file.
*
* @param string $load_filename filepath (not URL) to source file
* (ex: /src/var/www/wp-content/uploads/my-pic.jpg)
* @param string $save_filename filepath (not URL) where result file should be saved
* (ex: /src/var/www/wp-content/uploads/my-pic-300x200-c-default.jpg)
* @return boolean|null true if everything went fine, false otherwise
*/
public function run( $load_filename, $save_filename ) {
$image = wp_get_image_editor($load_filename);
if ( !is_wp_error($image) ) {
//should be resized by gif resizer
if ( ImageHelper::is_animated_gif($load_filename) ) {
//attempt to resize
//return if successful
//proceed if not
$gif = self::run_animated_gif($load_filename, $save_filename, $image);
if ( $gif ) {
return true;
}
}
$crop = self::get_target_sizes($image);
$image->crop( $crop['x'],
$crop['y'],
$crop['src_w'],
$crop['src_h'],
$crop['target_w'],
$crop['target_h']
);
$result = $image->save($save_filename);
if ( is_wp_error($result) ) {
// @codeCoverageIgnoreStart
Helper::error_log('Error resizing image');
Helper::error_log($result);
return false;
// @codeCoverageIgnoreEnd
$source_path = self::_get_file_path(
$au['base'],
$au['subdir'],
$au['basename']
);
$new_url = apply_filters('timber/image/new_url', $new_url);
$destination_path = apply_filters('timber/image/new_path', $destination_path);
// if already exists...
if ( file_exists($destination_path) ) {
if ( $force || filemtime($source_path) > filemtime($destination_path) ) {
// Force operation - warning: will regenerate the image on every pageload, use for testing purposes only!
unlink($destination_path);
} else {
// return existing file (caching)
return $new_url;
}
}
// otherwise generate result file
if ( $op->run($source_path, $destination_path) ) {
if ( get_class($op) === 'Timber\Image\Operation\Resize' && $external ) {
$new_url = strtolower($new_url);
}
return $new_url;
} else {
// in case of error, we return source file itself
return $src;
}
}
// -- the below methods are just used for unit testing the URL generation code
//
public static function get_letterbox_file_url( $url, $w, $h, $color ) {
$au = self::analyze_url($url);
$op = new Image\Operation\Letterbox($w, $h, $color);
$new_url = self::_get_file_url(
$au['base'],
$au['subdir'],
$op->filename($au['filename'], $au['extension']),
* @example
* ```twig
* <img src="{{ image.src | resize(300, 200, 'top') }}" />
* ```
* ```html
* <img src="http://example.org/wp-content/uploads/pic-300x200-c-top.jpg" />
* ```
* @return string (ex: )
*/
public static function resize( $src, $w, $h = 0, $crop = 'default', $force = false ) {
if ( !is_numeric($w) && is_string($w) ) {
if ( $sizes = self::find_wp_dimensions($w) ) {
$w = $sizes['w'];
$h = $sizes['h'];
} else {
return $src;
}
}
$op = new Image\Operation\Resize($w, $h, $crop);
return self::_operate($src, $op, $force);
}
/**
* Find the sizes of an image based on a defined image size
* @param string $size the image size to search for
* can be WordPress-defined ("medium")
* or user-defined ("my-awesome-size")
* @return false|array {
* @type int w
* @type int h
* }
*/
private static function find_wp_dimensions( $size ) {
global $_wp_additional_image_sizes;
if ( isset($_wp_additional_image_sizes[$size]) ) {
$w = $_wp_additional_image_sizes[$size]['width'];
$h = $_wp_additional_image_sizes[$size]['height'];
} else if ( in_array($size, array('thumbnail', 'medium', 'large')) ) {
$w = get_option($size.'_size_w');
$h = get_option($size.'_size_h');
echo " ";
if ((((($this->getAttribute($this->getAttribute(($context["gantry"] ?? null), "config", array()), "get", array(0 => (("content." . ($context["scope"] ?? null)) . ".meta-date.enabled"), 1 => "1"), "method") || $this->getAttribute($this->getAttribute(($context["gantry"] ?? null), "config", array()), "get", array(0 => (("content." . ($context["scope"] ?? null)) . ".meta-author.enabled"), 1 => "1"), "method")) || $this->getAttribute($this->getAttribute(($context["gantry"] ?? null), "config", array()), "get", array(0 => (("content." . ($context["scope"] ?? null)) . ".meta-comments.enabled"), 1 => "1"), "method")) || $this->getAttribute($this->getAttribute(($context["gantry"] ?? null), "config", array()), "get", array(0 => (("content." . ($context["scope"] ?? null)) . ".meta-categories.enabled"), 1 => "1"), "method")) || $this->getAttribute($this->getAttribute(($context["gantry"] ?? null), "config", array()), "get", array(0 => (("content." . ($context["scope"] ?? null)) . ".meta-tags.enabled"), 1 => "0"), "method"))) {
// line 24
echo " ";
$this->loadTemplate(array(0 => (("partials/meta-" . ($context["scope"] ?? null)) . ".html.twig"), 1 => "partials/meta.html.twig"), "partials/content.html.twig", 24)->display($context);
// line 25
echo " ";
}
// line 26
echo " ";
// line 27
echo " </div>
<div class=\"g-block size-90 post__image__block__img\">
<a href=\"";
// line 29
echo $this->getAttribute(($context["post"] ?? null), "link", array());
echo "\" class=\"post-thumbnail\" aria-hidden=\"true\">
<img src=\"";
// line 30
echo Timber\ImageHelper::resize($this->getAttribute($this->getAttribute(($context["post"] ?? null), "thumbnail", array()), "src", array()), $this->getAttribute($this->getAttribute(($context["gantry"] ?? null), "config", array()), "get", array(0 => (("content." . ($context["scope"] ?? null)) . ".featured-image.width"), 1 => "1200"), "method"), $this->getAttribute($this->getAttribute(($context["gantry"] ?? null), "config", array()), "get", array(0 => (("content." . ($context["scope"] ?? null)) . ".featured-image.height"), 1 => "350"), "method"));
echo "\"
class=\"featured-image tease-featured-image ";
// line 31
echo ($context["position"] ?? null);
echo "\" alt=\"";
echo $this->getAttribute(($context["post"] ?? null), "title", array());
echo "\"/>
</a>
</div>
</div>
";
}
// line 36
echo " ";
// line 37
echo " <div class=\"post__content__block\">
";
// line 39
echo " ";
if ($this->getAttribute($this->getAttribute(($context["gantry"] ?? null), "config", array()), "get", array(0 => (("content." . ($context["scope"] ?? null)) . ".title.enabled"), 1 => "1"), "method")) {
if ($useBlocks && isset($blocks[$name])) {
$template = $blocks[$name][0];
$block = $blocks[$name][1];
} elseif (isset($this->blocks[$name])) {
$template = $this->blocks[$name][0];
$block = $this->blocks[$name][1];
} else {
$template = null;
$block = null;
}
// avoid RCEs when sandbox is enabled
if (null !== $template && !$template instanceof self) {
throw new LogicException('A block must be a method on a Twig_Template instance.');
}
if (null !== $template) {
try {
$template->$block($context, $blocks);
} catch (Twig_Error $e) {
if (!$e->getSourceContext()) {
$e->setSourceContext($template->getSourceContext());
}
// this is mostly useful for Twig_Error_Loader exceptions
// see Twig_Error_Loader
if (false === $e->getTemplateLine()) {
$e->setTemplateLine(-1);
$e->guess();
}
throw $e;
} catch (Exception $e) {
throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $template->getSourceContext(), $e);
}
} elseif (false !== $parent = $this->getParent($context)) {
$parent->displayBlock($name, $context, array_merge($this->blocks, $blocks), false);
} else {
@trigger_error(sprintf('Silent display of undefined block "%s" in template "%s" is deprecated since version 1.29 and will throw an exception in 2.0. Use the "block(\'%s\') is defined" expression to test for block existence.', $name, $this->getTemplateName(), $name), E_USER_DEPRECATED);
$this->blocks = array(
'content' => array($this, 'block_content'),
);
}
protected function doDisplay(array $context, array $blocks = array())
{
// line 1
echo "<article class=\"tease tease-";
echo $this->getAttribute(($context["post"] ?? null), "post_type", array());
echo " ";
echo $this->getAttribute(($context["post"] ?? null), "class", array());
echo " clearfix\" id=\"tease-";
echo $this->getAttribute(($context["post"] ?? null), "ID", array());
echo "\">
";
// line 3
$this->displayBlock('content', $context, $blocks);
// line 96
echo "
</article>
";
}
// line 3
public function block_content($context, array $blocks = array())
{
// line 4
echo "
";
// line 6
echo " <section class=\"entry-header\">
</section>
";
// line 10
echo "
";
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
} catch (Throwable $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
}
return ob_get_clean();
}
protected function displayWithErrorHandling(array $context, array $blocks = array())
{
try {
$this->doDisplay($context, $blocks);
} catch (Twig_Error $e) {
if (!$e->getSourceContext()) {
$e->setSourceContext($this->getSourceContext());
}
// this is mostly useful for Twig_Error_Loader exceptions
// see Twig_Error_Loader
if (false === $e->getTemplateLine()) {
$e->setTemplateLine(-1);
$e->guess();
}
throw $e;
} catch (Exception $e) {
throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $this->getSourceContext(), $e);
}
}
/**
* Auto-generated method to display the template with the given context.
}
/**
* Returns all blocks.
*
* This method is for internal use only and should never be called
* directly.
*
* @return array An array of blocks
*
* @internal
*/
public function getBlocks()
{
return $this->blocks;
}
public function display(array $context, array $blocks = array())
{
$this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks));
}
public function render(array $context)
{
$level = ob_get_level();
ob_start();
try {
$this->display($context);
} catch (Exception $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
} catch (Throwable $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
// line 28
$context['_parent'] = $context;
$context['_seq'] = twig_ensure_traversable(($context["posts"] ?? null));
$context['loop'] = array(
'parent' => $context['_parent'],
'index0' => 0,
'index' => 1,
'first' => true,
);
if (is_array($context['_seq']) || (is_object($context['_seq']) && $context['_seq'] instanceof Countable)) {
$length = count($context['_seq']);
$context['loop']['revindex0'] = $length - 1;
$context['loop']['revindex'] = $length;
$context['loop']['length'] = $length;
$context['loop']['last'] = 1 === $length;
}
foreach ($context['_seq'] as $context["_key"] => $context["post"]) {
// line 29
echo " ";
$this->loadTemplate(array(0 => (("partials/content-" . ($context["scope"] ?? null)) . ".html.twig"), 1 => (($this->getAttribute($context["post"], "format", array())) ? ((("partials/content-" . $this->getAttribute($context["post"], "format", array())) . ".html.twig")) : ("")), 2 => "partials/content.html.twig"), "archive.html.twig", 29)->display($context);
// line 30
echo " ";
++$context['loop']['index0'];
++$context['loop']['index'];
$context['loop']['first'] = false;
if (isset($context['loop']['length'])) {
--$context['loop']['revindex0'];
--$context['loop']['revindex'];
$context['loop']['last'] = 0 === $context['loop']['revindex0'];
}
}
$_parent = $context['_parent'];
unset($context['_seq'], $context['_iterated'], $context['_key'], $context['post'], $context['_parent'], $context['loop']);
$context = array_intersect_key($context, $_parent) + $_parent;
// line 31
echo " </section>
";
// line 33
echo "
";
if ($useBlocks && isset($blocks[$name])) {
$template = $blocks[$name][0];
$block = $blocks[$name][1];
} elseif (isset($this->blocks[$name])) {
$template = $this->blocks[$name][0];
$block = $this->blocks[$name][1];
} else {
$template = null;
$block = null;
}
// avoid RCEs when sandbox is enabled
if (null !== $template && !$template instanceof self) {
throw new LogicException('A block must be a method on a Twig_Template instance.');
}
if (null !== $template) {
try {
$template->$block($context, $blocks);
} catch (Twig_Error $e) {
if (!$e->getSourceContext()) {
$e->setSourceContext($template->getSourceContext());
}
// this is mostly useful for Twig_Error_Loader exceptions
// see Twig_Error_Loader
if (false === $e->getTemplateLine()) {
$e->setTemplateLine(-1);
$e->guess();
}
throw $e;
} catch (Exception $e) {
throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $template->getSourceContext(), $e);
}
} elseif (false !== $parent = $this->getParent($context)) {
$parent->displayBlock($name, $context, array_merge($this->blocks, $blocks), false);
} else {
@trigger_error(sprintf('Silent display of undefined block "%s" in template "%s" is deprecated since version 1.29 and will throw an exception in 2.0. Use the "block(\'%s\') is defined" expression to test for block existence.', $name, $this->getTemplateName(), $name), E_USER_DEPRECATED);
}
protected function doDisplay(array $context, array $blocks = array())
{
// line 1
$this->getAttribute($this->getAttribute(($context["gantry"] ?? null), "debugger", array()), "startTimer", array(0 => "render", 1 => "Rendering page"), "method");
// line 2
$this->getAttribute($this->getAttribute(($context["gantry"] ?? null), "theme", array()), "setLayout", array(), "method");
// line 3
$this->getAttribute($this->getAttribute(($context["gantry"] ?? null), "theme", array()), "loadAtoms", array(), "method");
// line 4
$context["segments"] = $this->getAttribute($this->getAttribute(($context["gantry"] ?? null), "theme", array()), "segments", array(), "method");
// line 6
ob_start();
// line 7
echo " ";
if ($this->getAttribute($this->getAttribute(($context["gantry"] ?? null), "theme", array()), "hasContent", array(), "method")) {
// line 8
echo " ";
$this->displayBlock('content', $context, $blocks);
// line 10
echo " ";
}
$context["content"] = ('' === $tmp = ob_get_clean()) ? '' : new Twig_Markup($tmp, $this->env->getCharset());
// line 13
$context["offcanvas"] = null;
// line 14
$context['_parent'] = $context;
$context['_seq'] = twig_ensure_traversable(($context["segments"] ?? null));
foreach ($context['_seq'] as $context["_key"] => $context["segment"]) {
if (($this->getAttribute($context["segment"], "type", array()) == "offcanvas")) {
// line 15
$context["offcanvas"] = $context["segment"];
}
}
$_parent = $context['_parent'];
unset($context['_seq'], $context['_iterated'], $context['_key'], $context['segment'], $context['_parent'], $context['loop']);
$context = array_intersect_key($context, $_parent) + $_parent;
// line 18
ob_start();
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
} catch (Throwable $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
}
return ob_get_clean();
}
protected function displayWithErrorHandling(array $context, array $blocks = array())
{
try {
$this->doDisplay($context, $blocks);
} catch (Twig_Error $e) {
if (!$e->getSourceContext()) {
$e->setSourceContext($this->getSourceContext());
}
// this is mostly useful for Twig_Error_Loader exceptions
// see Twig_Error_Loader
if (false === $e->getTemplateLine()) {
$e->setTemplateLine(-1);
$e->guess();
}
throw $e;
} catch (Exception $e) {
throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $this->getSourceContext(), $e);
}
}
/**
* Auto-generated method to display the template with the given context.
}
/**
* Returns all blocks.
*
* This method is for internal use only and should never be called
* directly.
*
* @return array An array of blocks
*
* @internal
*/
public function getBlocks()
{
return $this->blocks;
}
public function display(array $context, array $blocks = array())
{
$this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks));
}
public function render(array $context)
{
$level = ob_get_level();
ob_start();
try {
$this->display($context);
} catch (Exception $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
} catch (Throwable $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
public function __construct(Twig_Environment $env)
{
parent::__construct($env);
// line 1
$this->parent = $this->loadTemplate("@nucleus/page.html.twig", "partials/page.html.twig", 1);
$this->blocks = array(
'page_head' => array($this, 'block_page_head'),
'page_footer' => array($this, 'block_page_footer'),
);
}
protected function doGetParent(array $context)
{
return "@nucleus/page.html.twig";
}
protected function doDisplay(array $context, array $blocks = array())
{
$this->parent->display($context, array_merge($this->blocks, $blocks));
}
// line 3
public function block_page_head($context, array $blocks = array())
{
// line 4
if (($context["page_head"] ?? null)) {
// line 5
echo " ";
echo ($context["page_head"] ?? null);
echo "
";
} else {
// line 7
echo " ";
$this->displayParentBlock("page_head", $context, $blocks);
echo "
";
}
}
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
} catch (Throwable $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
}
return ob_get_clean();
}
protected function displayWithErrorHandling(array $context, array $blocks = array())
{
try {
$this->doDisplay($context, $blocks);
} catch (Twig_Error $e) {
if (!$e->getSourceContext()) {
$e->setSourceContext($this->getSourceContext());
}
// this is mostly useful for Twig_Error_Loader exceptions
// see Twig_Error_Loader
if (false === $e->getTemplateLine()) {
$e->setTemplateLine(-1);
$e->guess();
}
throw $e;
} catch (Exception $e) {
throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $this->getSourceContext(), $e);
}
}
/**
* Auto-generated method to display the template with the given context.
}
/**
* Returns all blocks.
*
* This method is for internal use only and should never be called
* directly.
*
* @return array An array of blocks
*
* @internal
*/
public function getBlocks()
{
return $this->blocks;
}
public function display(array $context, array $blocks = array())
{
$this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks));
}
public function render(array $context)
{
$level = ob_get_level();
ob_start();
try {
$this->display($context);
} catch (Exception $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
} catch (Throwable $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
// line 1
$this->parent = $this->loadTemplate("partials/page.html.twig", "archive.html.twig", 1);
$this->blocks = array(
'content' => array($this, 'block_content'),
);
}
protected function doGetParent(array $context)
{
return "partials/page.html.twig";
}
protected function doDisplay(array $context, array $blocks = array())
{
// line 2
$context["twigTemplate"] = "archive.html.twig";
// line 3
$context["scope"] = "archive";
// line 1
$this->parent->display($context, array_merge($this->blocks, $blocks));
}
// line 5
public function block_content($context, array $blocks = array())
{
// line 6
echo "
<div class=\"platform-content\">
<div class=\"archive\">
";
// line 11
echo " ";
if ($this->getAttribute($this->getAttribute(($context["gantry"] ?? null), "config", array()), "get", array(0 => (("content." . ($context["scope"] ?? null)) . ".heading.enabled"), 1 => "0"), "method")) {
// line 12
echo " <header class=\"page-header\">
<h1>
";
// line 14
if ( !twig_test_empty($this->getAttribute($this->getAttribute(($context["gantry"] ?? null), "config", array()), "get", array(0 => (("content." . ($context["scope"] ?? null)) . ".heading.text")), "method"))) {
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
} catch (Throwable $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
}
return ob_get_clean();
}
protected function displayWithErrorHandling(array $context, array $blocks = array())
{
try {
$this->doDisplay($context, $blocks);
} catch (Twig_Error $e) {
if (!$e->getSourceContext()) {
$e->setSourceContext($this->getSourceContext());
}
// this is mostly useful for Twig_Error_Loader exceptions
// see Twig_Error_Loader
if (false === $e->getTemplateLine()) {
$e->setTemplateLine(-1);
$e->guess();
}
throw $e;
} catch (Exception $e) {
throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $this->getSourceContext(), $e);
}
}
/**
* Auto-generated method to display the template with the given context.
}
/**
* Returns all blocks.
*
* This method is for internal use only and should never be called
* directly.
*
* @return array An array of blocks
*
* @internal
*/
public function getBlocks()
{
return $this->blocks;
}
public function display(array $context, array $blocks = array())
{
$this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks));
}
public function render(array $context)
{
$level = ob_get_level();
ob_start();
try {
$this->display($context);
} catch (Exception $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
} catch (Throwable $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
* @return array An array of blocks
*
* @internal
*/
public function getBlocks()
{
return $this->blocks;
}
public function display(array $context, array $blocks = array())
{
$this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks));
}
public function render(array $context)
{
$level = ob_get_level();
ob_start();
try {
$this->display($context);
} catch (Exception $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
} catch (Throwable $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
}
return ob_get_clean();
}
protected function displayWithErrorHandling(array $context, array $blocks = array())
{
try {
@trigger_error(sprintf('The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED);
return $this->templateClassPrefix;
}
/**
* Renders a template.
*
* @param string $name The template name
* @param array $context An array of parameters to pass to the template
*
* @return string The rendered template
*
* @throws Twig_Error_Loader When the template cannot be found
* @throws Twig_Error_Syntax When an error occurred during compilation
* @throws Twig_Error_Runtime When an error occurred during rendering
*/
public function render($name, array $context = array())
{
return $this->loadTemplate($name)->render($context);
}
/**
* Displays a template.
*
* @param string $name The template name
* @param array $context An array of parameters to pass to the template
*
* @throws Twig_Error_Loader When the template cannot be found
* @throws Twig_Error_Syntax When an error occurred during compilation
* @throws Twig_Error_Runtime When an error occurred during rendering
*/
public function display($name, array $context = array())
{
$this->loadTemplate($name)->display($context);
}
/**
* Loads a template.
*
}
$key = null;
$output = false;
if ( false !== $expires ) {
ksort($data);
$key = md5($file.json_encode($data));
$output = $this->get_cache($key, self::CACHEGROUP, $cache_mode);
}
if ( false === $output || null === $output ) {
$twig = $this->get_twig();
if ( strlen($file) ) {
$loader = $this->get_loader();
$result = $loader->getCacheKey($file);
do_action('timber_loader_render_file', $result);
}
$data = apply_filters('timber_loader_render_data', $data);
$data = apply_filters('timber/loader/render_data', $data, $file);
$output = $twig->render($file, $data);
}
if ( false !== $output && false !== $expires && null !== $key ) {
$this->delete_cache();
$this->set_cache($key, $output, self::CACHEGROUP, $expires, $cache_mode);
}
$output = apply_filters('timber_output', $output);
return apply_filters('timber/output', $output, $data, $file);
}
protected function delete_cache() {
Cleaner::delete_transients();
}
/**
* @param array $filenames
* @return bool
*/
public function choose_template( $filenames ) {
if ( is_array($filenames) ) {
self::init();
}
$caller = LocationManager::get_calling_script_dir(1);
$loader = new Loader($caller);
$file = $loader->choose_template($filenames);
$caller_file = LocationManager::get_calling_script_file(1);
apply_filters('timber/calling_php_file', $caller_file);
$output = '';
if ( is_null($data) ) {
$data = array();
}
if ( strlen($file) ) {
if ( $via_render ) {
$file = apply_filters('timber_render_file', $file);
$data = apply_filters('timber_render_data', $data);
} else {
$file = apply_filters('timber_compile_file', $file);
$data = apply_filters('timber_compile_data', $data);
}
$output = $loader->render($file, $data, $expires, $cache_mode);
}
do_action('timber_compile_done');
return $output;
}
/**
* Compile string.
* @api
* @param string $string a string with twig variables.
* @param array $data an array with data in it.
* @return bool|string
*/
public static function compile_string( $string, $data = array() ) {
$dummy_loader = new Loader();
$twig = $dummy_loader->get_twig();
$template = $twig->createTemplate($string);
return $template->render($data);
}
/**
* @return bool|string
*/
public static function compile_string( $string, $data = array() ) {
$dummy_loader = new Loader();
$twig = $dummy_loader->get_twig();
$template = $twig->createTemplate($string);
return $template->render($data);
}
/**
* Fetch function.
* @api
* @param array $filenames
* @param array $data
* @param bool $expires
* @param string $cache_mode
* @return bool|string
*/
public static function fetch( $filenames, $data = array(), $expires = false, $cache_mode = Loader::CACHE_USE_DEFAULT ) {
$output = self::compile($filenames, $data, $expires, $cache_mode, true);
$output = apply_filters('timber_compile_result', $output);
return $output;
}
/**
* Render function.
* @api
* @param array $filenames
* @param array $data
* @param boolean|integer $expires
* @param string $cache_mode
* @return boolean|string
*/
public static function render( $filenames, $data = array(), $expires = false, $cache_mode = Loader::CACHE_USE_DEFAULT ) {
$output = self::fetch($filenames, $data, $expires, $cache_mode);
echo $output;
return $output;
}
/**
* @param string $cache_mode
* @return bool|string
*/
public static function fetch( $filenames, $data = array(), $expires = false, $cache_mode = Loader::CACHE_USE_DEFAULT ) {
$output = self::compile($filenames, $data, $expires, $cache_mode, true);
$output = apply_filters('timber_compile_result', $output);
return $output;
}
/**
* Render function.
* @api
* @param array $filenames
* @param array $data
* @param boolean|integer $expires
* @param string $cache_mode
* @return boolean|string
*/
public static function render( $filenames, $data = array(), $expires = false, $cache_mode = Loader::CACHE_USE_DEFAULT ) {
$output = self::fetch($filenames, $data, $expires, $cache_mode);
echo $output;
return $output;
}
/**
* Render string.
* @api
* @param string $string a string with twig variables.
* @param array $data an array with data in it.
* @return bool|string
*/
public static function render_string( $string, $data = array() ) {
$compiled = self::compile_string($string, $data);
echo $compiled;
return $compiled;
}
/* Sidebar
================================ */
$context['title'] = __('Archive', 'g5_hydrogen');
if (is_day()) {
$context['title'] = __('Archive:', 'g5_hydrogen') . ' ' . get_the_date('j F Y');
} else if (is_month()) {
$context['title'] = __('Archive:', 'g5_hydrogen') . ' ' . get_the_date('F Y');
} else if (is_year()) {
$context['title'] = __('Archive:', 'g5_hydrogen') . ' ' . get_the_date('Y');
} else if (is_tag()) {
$context['title'] = single_tag_title('', false);
} else if (is_category()) {
$context['title'] = single_cat_title('', false);
array_unshift($templates, 'archive-' . get_query_var('cat') . '.html.twig');
} else if (is_post_type_archive()) {
$context['title'] = post_type_archive_title('', false);
array_unshift($templates, 'archive-' . get_post_type() . '.html.twig');
}
$context['posts'] = Timber::get_posts();
Timber::render($templates, $context);
elseif ( is_single() && $template = get_single_template() ) :
elseif ( is_page() && $template = get_page_template() ) :
elseif ( is_singular() && $template = get_singular_template() ) :
elseif ( is_category() && $template = get_category_template() ) :
elseif ( is_tag() && $template = get_tag_template() ) :
elseif ( is_author() && $template = get_author_template() ) :
elseif ( is_date() && $template = get_date_template() ) :
elseif ( is_archive() && $template = get_archive_template() ) :
else :
$template = get_index_template();
endif;
/**
* Filters the path of the current template before including it.
*
* @since 3.0.0
*
* @param string $template The path of the template to include.
*/
if ( $template = apply_filters( 'template_include', $template ) ) {
include( $template );
} elseif ( current_user_can( 'switch_themes' ) ) {
$theme = wp_get_theme();
if ( $theme->errors() ) {
wp_die( $theme->errors() );
}
}
return;
endif;
<?php
/**
* Loads the WordPress environment and template.
*
* @package WordPress
*/
if ( !isset($wp_did_header) ) {
$wp_did_header = true;
// Load the WordPress library.
require_once( dirname(__FILE__) . '/wp-load.php' );
// Set up the WordPress query.
wp();
// Load the theme template.
require_once( ABSPATH . WPINC . '/template-loader.php' );
}
<?php
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/
/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/
define('WP_USE_THEMES', true);
/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp-blog-header.php' );