public function testNormalizePath() { $this->assertEquals('/fake/file/path', File::normalizePath('/fake\\file/path\\//', '/')); $this->assertEquals('/fake/file/path/', File::normalizePath('/fake\\file/path\\//', '/', false)); $this->assertEquals('C:\\fake\\file\\path', File::normalizePath('C:\\fake\\file/path\\//', '\\')); $this->assertEquals('C:\\fake\\file\\path\\', File::normalizePath('C:/fake\\file/path\\//', '\\', false)); $this->assertEquals('http://host/fake/path', File::normalizePath('http://host/fake\\path\\')); $this->assertEquals('http://*****:*****@host:80/fake/path', File::normalizePath('http://user@host:80/fake\\path\\')); $this->assertEquals('http://*****:*****@host:80/fake/path', File::normalizePath('http://*****:*****@host:80/fake\\path\\')); $this->assertEquals(realpath($this->folderPath), File::normalizePath($this->folderPath)); }
/** * Generate a layout thumbnail according to the configuration. * * @access public * * @param Layout $layout The layout to treate * @param BBApplication $app The current instance of BBApplication * * @return mixed FALSE if something wrong, the ressource path of the thumbnail elsewhere */ public function generateThumbnail(Layout $layout, BBApplication $app) { // Is the layout valid ? if (!$layout->isValid()) { return false; } // Is some layout configuration existing ? if (null === $app->getConfig()->getSection('layout')) { return false; } $layoutconfig = $app->getConfig()->getSection('layout'); // Is some thumbnail configuration existing ? if (!isset($layoutconfig['thumbnail'])) { return false; } $thumbnailconfig = $layoutconfig['thumbnail']; // Is gd available ? if (!function_exists('gd_info')) { return false; } $gd_info = gd_info(); // Is the selected format supported by gd ? if (!isset($thumbnailconfig['format'])) { return false; } if (true !== $gd_info[strtoupper($thumbnailconfig['format']) . ' Support']) { return false; } // Is the template file existing ? if (!isset($thumbnailconfig['template'])) { return false; } $templatefile = $thumbnailconfig['template']; $thumbnaildir = dirname($templatefile); File::resolveFilepath($templatefile, null, array('include_path' => $app->getResourceDir())); if (false === file_exists($templatefile) || false === is_readable($templatefile)) { return false; } try { $gd_function = 'imagecreatefrom' . strtolower($thumbnailconfig['format']); $thumbnail = $gd_function($templatefile); $thumbnailfile = $thumbnaildir . '/' . $layout->getUid() . '.' . strtolower($thumbnailconfig['format']); // Is a background color existing ? if (!isset($thumbnailconfig['background']) || !is_array($thumbnailconfig['background']) || 3 != count($thumbnailconfig['background'])) { return false; } $background = imagecolorallocate($thumbnail, $thumbnailconfig['background'][0], $thumbnailconfig['background'][1], $thumbnailconfig['background'][2]); // Is a clipping zone existing ? if (!isset($thumbnailconfig['clip']) || !is_array($thumbnailconfig['clip']) || 4 != count($thumbnailconfig['clip'])) { return false; } $gridcolumn = 12; if (null !== ($lessconfig = $app->getConfig()->getSection('less'))) { if (isset($lessconfig['gridcolumn'])) { $gridcolumn = $lessconfig['gridcolumn']; } } $domlayout = $layout->getDomDocument(); if (!$domlayout->hasChildNodes() || !$domlayout->firstChild->hasChildNodes()) { $this->drawRect($thumbnail, $thumbnailconfig['clip'], $background); } else { $this->drawThumbnailZone($thumbnail, $domlayout->firstChild, $thumbnailconfig['clip'], $background, $gridcolumn); } imagesavealpha($thumbnail, true); $thumbnaildir = dirname(File::normalizePath($app->getCurrentResourceDir() . '/' . $thumbnailfile)); if (false === is_dir($thumbnaildir)) { mkdir($thumbnaildir, 0755, true); } imagepng($thumbnail, File::normalizePath($app->getCurrentResourceDir() . '/' . $thumbnailfile)); } catch (\Exception $e) { return false; } $layout->setPicPath($thumbnailfile); return $layout->getPicPath(); }
public function testNormalizePath() { $this->assertEquals(realpath($this->folderPath), File::normalizePath($this->folderPath)); }
/** * Tries to match a URL with a set of routes. * * @param string $pathinfo The path info to be parsed (raw format, i.e. not urldecoded) * * @return array An array of parameters * * @throws ResourceNotFoundException If the resource could not be found * @throws MethodNotAllowedException If the resource was found but the request method is not allowed */ public function match($pathinfo) { $pathinfo = File::normalizePath($pathinfo, '/', false); return parent::match($pathinfo); }