Example #1
0
 public static function setUpBeforeClass()
 {
     /* Setup virtual file system. */
     vfsStream::setup('root/');
     /* Modify root path to point to the virtual file system. */
     Core\Config()->modifyPath('root', vfsStream::url('root/'));
 }
Example #2
0
 protected function setUp()
 {
     $this->imagePath = Core\Config()->paths('root') . 'image.png';
     $this->width = 640;
     $this->height = 480;
     $this->size = array("{$this->width}x{$this->height}", "{$this->height}x{$this->width}");
     $imagine = new Imagine();
     $this->image = $imagine->create(new Box($this->width * 2, $this->width * 2))->save($this->imagePath);
 }
/**
 * Paginate layout printing function.
 *
 * @param array                    $params   Specified params.
 * @param Smarty_Internal_Template $template Instance of Smarty template class.
 *
 * @uses   Core\Config()
 *
 * @return string Rendered pagination template.
 */
function smarty_function_pagination(array $params, Smarty_Internal_Template $template)
{
    $viewsPaths = Core\Config()->paths('views');
    $params['range'] = isset($params['range']) ? abs($params['range']) : 2;
    $_path_to_templates = $viewsPaths['templates'] . '_shared' . DIRECTORY_SEPARATOR;
    $_template = isset($params['template']) ? $_path_to_templates . $params['template'] . '.html.tpl' : null;
    $params['template'] = file_exists($_template) ? $_template : $_path_to_templates . 'pagination' . DIRECTORY_SEPARATOR . 'default.html.tpl';
    $paginator = $params['paginator'];
    $pages_range = $paginator->range($params['range']);
    $range = array();
    $range['start'] = isset($pages_range['first']->pageNumber) ? $pages_range['first']->pageNumber : 0;
    $range['end'] = isset($pages_range['last']->pageNumber) ? $pages_range['last']->pageNumber : 0;
    $template->assign('pagination', array('current' => $paginator->current(), 'first' => $paginator->first(), 'last' => $paginator->last(), 'prev' => $paginator->prev(), 'next' => $paginator->next(), 'boundaries' => isset($params['boundaries']) ? !!$params['boundaries'] : false, 'range' => $params['range'], 'pages' => range($range['start'], $range['end'])));
    return $template->fetch($params['template']);
}
/**
 * URL helper to use in templates
 *
 * @param array                    $options  Provided options.
 * @param Smarty_Internal_Template $template Smarty template object.
 *
 * @uses   Core\Router()
 * @uses   Core\Config()
 *
 * @return string
 */
function smarty_function_link_to(array $options, Smarty_Internal_Template $template)
{
    return \Core\Config()->urls('relative') . \Core\Router()->toUrl($options);
}
Example #5
0
/**
 * Include and manage Assets into templates.
 *
 * Supported styles:
 *  - CSS
 *  - LESS via /vendor/leafo/LessphpFilter
 *  - SCSS via /vendor/leafo/ScssphpFilter
 *
 * Supported scripts:
 *  - JavaScript
 *  - Coffee Script via Assetic\Filter\CoffeeScriptFilter
 *
 * @param array                    $options  Assets source options.
 * @param Smarty_Internal_Template $template Smarty Template object.
 *
 * @uses   Core\Config
 * @uses   Core\Utils
 * @see    Assetic
 *
 * @return string
 */
function smarty_function_assets(array $options, Smarty_Internal_Template $template)
{
    $result = array();
    if (isset($options['source'])) {
        $assetsPath = Core\Config()->paths('assets');
        $optimization_enabled = Core\Config()->ASSETS['optimize'];
        $combination_enabled = Core\Config()->ASSETS['combine'];
        $caching_enabled = Core\Config()->ASSETS['cache'];
        $dist_path = $assetsPath['distribution'];
        $source_path = $assetsPath['source'];
        $dist_url = Core\Config()->urls('assets');
        $media = isset($options['media']) ? $options['media'] : 'all';
        $rel = isset($options['rel']) ? $options['rel'] : 'stylesheet';
        $mimetype = isset($options['type']) ? $options['type'] : 'text/css';
        $assets = is_array($options['source']) ? $options['source'] : array($options['source']);
        $assets_id = md5(implode(Core\Utils::arrayFlatten($assets)));
        $assets_to_process = array();
        /* Format assets if needed */
        if (!Core\Utils::arrayIsAssoc($options['source'])) {
            $formatted_assets = array();
            foreach ($options['source'] as $file) {
                $file_extension = pathinfo($file, PATHINFO_EXTENSION);
                $formatted_assets[$file_extension][] = $file;
                $formatted_assets[$file_extension] = array_unique($formatted_assets[$file_extension]);
            }
            $assets = $formatted_assets;
        }
        if ($caching_enabled) {
            if ($combination_enabled) {
                if (array_intersect(array('css', 'less', 'scass'), array_keys($assets))) {
                    $cached_asset = 'css' . DIRECTORY_SEPARATOR . $assets_id . '.css';
                    if (file_exists($dist_path . $cached_asset)) {
                        $target = str_replace(DIRECTORY_SEPARATOR, '/', $cached_asset);
                        $result[] = sprintf('<link href="%s" rel="%s" type="%s" media="%s" />', $dist_url . $target, $rel, $mimetype, $media);
                    } else {
                        $assets_to_process = $assets;
                    }
                } elseif (array_intersect(array('js'), array_keys($assets))) {
                    $cached_asset = 'js' . DIRECTORY_SEPARATOR . $assets_id . '.js';
                    if (file_exists($dist_path . $cached_asset)) {
                        $target = str_replace(DIRECTORY_SEPARATOR, '/', $cached_asset);
                        $result[] = sprintf('<script src="%s"></script>', $dist_url . $target);
                    } else {
                        $assets_to_process = $assets;
                    }
                }
            } else {
                foreach ($assets as $type => $files) {
                    switch ($type) {
                        case 'css':
                        case 'less':
                        case 'scass':
                            foreach ($files as $file) {
                                $filename = basename($file, '.css');
                                $filename = basename($filename, '.less');
                                $filename = basename($filename, '.scss');
                                $cached_asset = 'css' . DIRECTORY_SEPARATOR . $filename . '.css';
                                if (file_exists($dist_path . $cached_asset)) {
                                    $target = str_replace(DIRECTORY_SEPARATOR, '/', $cached_asset);
                                    $result[] = sprintf('<link href="%s" rel="%s" type="%s" media="%s" />', $dist_url . $target, $rel, $mimetype, $media);
                                } else {
                                    $assets_to_process[$type][] = $file;
                                }
                            }
                            break;
                        case 'js':
                        case 'coffee':
                            foreach ($files as $file) {
                                $filename = basename($file, '.js');
                                $filename = basename($filename, '.coffee');
                                $cached_asset = 'js' . DIRECTORY_SEPARATOR . $filename . '.js';
                                if (file_exists($dist_path . $cached_asset)) {
                                    $target = str_replace(DIRECTORY_SEPARATOR, '/', $cached_asset);
                                    $result[] = sprintf('<script src="%s"></script>', $dist_url . $target);
                                } else {
                                    $assets_to_process[$type][] = $file;
                                }
                            }
                            break;
                    }
                }
            }
        }
        if (!$caching_enabled || $assets_to_process) {
            $assets = $assets_to_process ? $assets_to_process : $assets;
            $writer = new AssetWriter($dist_path);
            $styles = new AssetCollection(array(), $optimization_enabled ? array(new CssMinFilter()) : array());
            $scripts = new AssetCollection(array(), $optimization_enabled ? array(new JsMinFilter()) : array());
            foreach ($assets as $type => $files) {
                switch ($type) {
                    case 'js':
                        foreach ($files as $file) {
                            $scripts->add(new FileAsset($source_path . $file));
                        }
                        break;
                    case 'css':
                        foreach ($files as $file) {
                            $styles->add(new FileAsset($source_path . $file));
                        }
                        break;
                    case 'less':
                        foreach ($files as $file) {
                            $styles->add(new FileAsset($source_path . $file, array(new LessphpFilter())));
                        }
                        break;
                    case 'scss':
                        foreach ($files as $file) {
                            $styles->add(new FileAsset($source_path . $file, array(new ScssphpFilter())));
                        }
                        break;
                    case 'coffee':
                        foreach ($files as $file) {
                            $scripts->add(new FileAsset($source_path . $file), array(new CoffeeScriptFilter()));
                        }
                        break;
                }
            }
            if ($combination_enabled) {
                if ($styles->all()) {
                    $am = new AssetManager($dist_path);
                    $styles->setTargetPath('css' . DIRECTORY_SEPARATOR . $assets_id . '.css');
                    $am->set('styles', $styles);
                    $writer->writeManagerAssets($am);
                    $target = str_replace(DIRECTORY_SEPARATOR, '/', $styles->getTargetPath());
                    $result[] = sprintf('<link href="%s" rel="%s" type="%s" media="%s" />', $dist_url . $target, $rel, $mimetype, $media);
                }
                if ($scripts->all()) {
                    $am = new AssetManager($dist_path);
                    $scripts->setTargetPath('js' . DIRECTORY_SEPARATOR . $assets_id . '.js');
                    $am->set('scripts', $scripts);
                    $writer->writeManagerAssets($am);
                    $target = str_replace(DIRECTORY_SEPARATOR, '/', $scripts->getTargetPath());
                    $result[] = sprintf('<script src="%s"></script>', $dist_url . $target);
                }
            } else {
                foreach ($styles->all() as $style) {
                    $filename = basename($style->getSourcePath(), '.css');
                    $filename = basename($filename, '.less');
                    $filename = basename($filename, '.scss');
                    $style->setTargetPath('css' . DIRECTORY_SEPARATOR . $filename . '.css');
                    $writer->writeAsset($style);
                    $target = str_replace(DIRECTORY_SEPARATOR, '/', $style->getTargetPath());
                    $result[] = sprintf('<link href="%s" rel="%s" type="%s" media="%s" />', $dist_url . $target, $rel, $mimetype, $media);
                }
                foreach ($scripts->all() as $script) {
                    $filename = basename($script->getSourcePath(), '.js');
                    $filename = basename($filename, '.coffee');
                    $script->setTargetPath('js' . DIRECTORY_SEPARATOR . $filename . '.js');
                    $writer->writeAsset($script);
                    $target = str_replace(DIRECTORY_SEPARATOR, '/', $script->getTargetPath());
                    $result[] = sprintf('<script src="%s"></script>', $dist_url . $target);
                }
            }
        }
    }
    return $result ? implode("\n\t", $result) : '';
}
/**
 * Checks whether a template exists.
 *
 * @param string $template Text representation of the template name.
 *
 * @uses   Core\Config()
 * @return boolean
 */
function smarty_modifier_template_exists($template)
{
    $viewsPaths = Core\Config()->paths('views');
    return is_file($viewsPaths['templates'] . $template);
}
Example #7
0
 /**
  * Logs debug data to a log file.
  *
  * @param mixed $what Input data.
  *
  * @uses   Core\Config()
  * @see    file_put_contents()
  *
  * @return void
  */
 function var_log($what)
 {
     if (!is_scalar($what)) {
         $what = print_r($what, true);
     }
     file_put_contents(Core\Config()->paths('tmp') . 'debug.log', gmdate('[Y-m-d H:i:s e] ') . $what . "\n", FILE_APPEND);
 }
Example #8
0
 /**
  * @covers Core\Helpers\Directory::create
  * @expectedException DomainException
  */
 public function testCreatingExistingDirectory()
 {
     Directory::create(Core\Config()->paths('root'));
 }
Example #9
0
 /**
  * @covers Core\Modules\DB\DbCache::__construct()
  */
 public function testInitialisingDbCacheWithCaching()
 {
     Core\Config()->CACHE['db_schema'] = true;
     $this->dbCache = new DbCache();
 }
Example #10
0
 /**
  * @covers Core\Helpers\File::getContentsCurl
  * @todo Test with credentials.
  */
 public function testGettingContentsCurl()
 {
     $url = 'https://raw.githubusercontent.com/WeAreAthlon/silla.io/master/VERSION';
     $this->assertStringEqualsFile(Core\Config()->paths('root') . $this->baseName, File::getContentsCurl($url));
 }