@ 2015-11-13T19:09:26Z <?php
use Symfony\Component\Finder\Finder;
class BonesSingleton {
public static $instance;
public static function getInstance() {
if (null === static::$instance) {
static::$instance = new static();
}
return static::$instance;
}
protected function __construct() {
}
private function __clone() {
}
private function __wakeup() {
}
}
class TwigSingleton extends BonesSingleton {
public $twig = false;
public $templates = array();
protected function __construct() {
$this->getTemplates();
$loader = new Twig_Loader_Array($this->templates);
$twigEnv = new Twig_Environment($loader, array('debug' => true));
$imageFunc = new Twig_SimpleFunction('imagesrc', 'show_image', array('is_safe' => array('html')));
$doShortcodeFunc = new Twig_SimpleFunction('do_shortcode', function ($content, $ignore_html = false) {
return do_shortcode($content, $ignore_html);
}, array('is_safe' => array('html')));
$doBlockFunc = new Twig_SimpleFunction('localize_url', function ($url, $ignore_html = false) {
return localize_url($url);
}, array('is_safe' => array('html')));
$addEncoFunc = new Twig_SimpleFunction('add_enc',function($redirect_page){
return '<input type="hidden" name="uenc" value="'. Mage::helper('core')->urlEncode(Mage::helper('cms/page')->getPageUrl($redirect_page)).'"/>';
}, array('is_safe' => array('html')));
$twigEnv->addExtension(new Twig_Extension_Debug());
$twigEnv->addFunction($imageFunc);
$twigEnv->addFunction($doShortcodeFunc);
$twigEnv->addFunction($doBlockFunc);
$twigEnv->addFunction($addEncoFunc);
$this->twig = $twigEnv;
}
public function getTwig() {
return $this->twig;
}
public function getTemplates() {
//execute all the pattern portfolio parts
$this->get_templates_for('04-pages', 'pages');
$this->get_templates_for('03-templates', 'templates');
$this->get_templates_for('02-organisms', 'organisms');
$this->get_templates_for('01-molecules', 'molecules');
$this->get_templates_for('00-atoms', 'atoms');
}
private function get_templates_for($folder, $prefix) {
$pages = new Finder();
$pages->files()->in(PATTERNS_TEMPLATES . '/' . $folder)->name('*.twig');
foreach ($pages as $file) {
$this->templates[$this->prepare_name($file, $prefix . '-')] = $file->getContents();
}
}
private function prepare_name($file, $prefix = '') {
return $prefix . preg_replace('/^[_0-9\-]*/', '', $file->getBasename('.twig'));
}
}
define('PATTERNS_TEMPLATES', dirname(ABSPATH) . '/skin/frontend/sophiehulme/uk/styleguide/source/_patterns');
function create_sh_link($link) {
return $link;
}
function show_image($img, $size, $title = false, $classes = '', $animTarget = false, $lazyload) {
$imgHtml = '<img class="block image auto-height js-anim-image ' . $classes . '" width="' . $img['width'] . '" height="' . $img['height'] . '" alt="' . $img['name'] . '" srcset="' . get_image_group_srcset($img, $size) . '"' . ($animTarget ? ' data-anim-target="' . $animTarget . '"' : '') . ' sizes="'. get_image_group_size($size).'">';
if ($title && is_string($title)) {
return "<figure class='figure'>
$imgHtml
<figcaption class='figcaption t-header-small psy1'>$title</figcaption>
</figure>";
} else {
echo $imgHtml;
}
}
function date_to_unix($date) {
$dateTime = DateTime::createFromFormat('d/m/Y', $date);
return $dateTime->getTimestamp();
}
function should_be_visible($from, $to) {
$currentTime = strtotime('now');
return (date_to_unix($from) < $currentTime && $currentTime < date_to_unix($to));
}
//small singleton (Yeah I know)
//lazy person loader
function twig_render($name, $data, $debug) {
return TwigSingleton::getInstance()->getTwig()->render($name, $data);
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.1.0 - 8.1.28 , 8.2.0 - 8.2.19 , 8.3.0 - 8.3.7 Warning: The magic method BonesSingleton::__wakeup() must have public visibility in /in/4Ocuo on line 25
Deprecated: Optional parameter $title declared before required parameter $lazyload is implicitly treated as a required parameter in /in/4Ocuo on line 98
Deprecated: Optional parameter $classes declared before required parameter $lazyload is implicitly treated as a required parameter in /in/4Ocuo on line 98
Deprecated: Optional parameter $animTarget declared before required parameter $lazyload is implicitly treated as a required parameter in /in/4Ocuo on line 98
Fatal error: Uncaught Error: Undefined constant "ABSPATH" in /in/4Ocuo:92
Stack trace:
#0 {main}
thrown in /in/4Ocuo on line 92
Process exited with code 255 . Output for 8.0.0 - 8.0.30 Warning: The magic method BonesSingleton::__wakeup() must have public visibility in /in/4Ocuo on line 25
Deprecated: Required parameter $lazyload follows optional parameter $title in /in/4Ocuo on line 98
Fatal error: Uncaught Error: Undefined constant "ABSPATH" in /in/4Ocuo:92
Stack trace:
#0 {main}
thrown in /in/4Ocuo on line 92
Process exited with code 255 . Output for 7.2.0 - 7.2.34 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 Warning: Use of undefined constant ABSPATH - assumed 'ABSPATH' (this will throw an Error in a future version of PHP) in /in/4Ocuo on line 92
Output for 5.5.0 - 5.5.38 , 5.6.0 - 5.6.40 , 7.0.0 - 7.0.33 , 7.1.0 - 7.1.33 preferences:dark mode live preview
208.51 ms | 402 KiB | 341 Q