本文整理汇总了PHP中Bolt\Library::safeFilename方法的典型用法代码示例。如果您正苦于以下问题:PHP Library::safeFilename方法的具体用法?PHP Library::safeFilename怎么用?PHP Library::safeFilename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bolt\Library
的用法示例。
在下文中一共展示了Library::safeFilename方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSafeFilename
public function testSafeFilename()
{
$abs = '/etc/passwd';
$this->assertEquals('etc/passwd', Library::safeFilename($abs));
// Test urlparams get encoded
$urlparams = '%2F..%2F..%2Fsecretfile.txt';
$this->assertEquals('%252F..%252F..%252Fsecretfile.txt', Library::safeFilename($urlparams));
}
示例2: image
/**
* Helper function to make a path to an image.
*
* @param string $filename Target filename
* @param string|integer $width Target width
* @param string|integer $height Target height
* @param string $crop String identifier for cropped images
*
* @return string Image path
*/
public function image($filename, $width = '', $height = '', $crop = '')
{
if ($width != '' || $height != '') {
// You don't want the image, you just want a thumbnail.
return $this->thumbnail($filename, $width, $height, $crop);
}
// After v1.5.1 we store image data as an array
if (is_array($filename)) {
$filename = isset($filename['filename']) ? $filename['filename'] : $filename['file'];
}
$image = sprintf('%sfiles/%s', $this->app['paths']['root'], Lib::safeFilename($filename));
return $image;
}
示例3: image
/**
* Helper function to make a path to an image.
*
* @param string $filename Target filename
* @param string|integer $width Target width
* @param string|integer $height Target height
* @param string $crop String identifier for cropped images
*
* @return string Image path
*/
public function image($filename, $width = null, $height = null, $crop = null)
{
if ($width || $height) {
// You don't want the image, you just want a thumbnail.
return $this->thumbnail($filename, $width, $height, $crop);
}
// After v1.5.1 we store image data as an array
if (is_array($filename)) {
$filename = isset($filename['filename']) ? $filename['filename'] : $filename['file'];
}
$image = sprintf('%s%s', $this->app['resources']->getUrl('files'), Lib::safeFilename($filename));
return $image;
}
示例4: getLocalUrl
public function getLocalUrl($path)
{
$prefix = $this->app['resources']->getUrl($this->namespace);
return $prefix . Lib::safeFilename($path);
}
示例5: htmlRespImg
public function htmlRespImg($html, $name, array $options = array())
{
$dom = $this->createDOMDocument($html);
$elements = $dom->getElementsByTagName('img');
if (count($elements) === 0) {
return $html;
}
// Get Extension boltresponsiveimages
$extensionName = 'boltresponsiveimages';
if (!$this->app['extensions']->isEnabled($extensionName)) {
return $html;
}
$extension = $this->app['extensions.' . $extensionName];
if ($extension == null) {
return $html;
}
// Get Twig Function respImg
$twigFunction = $this->twig->getFunction('respImg');
if (!$twigFunction) {
return $html;
}
$respImg = $twigFunction->getCallable();
// Not override sizes, if defined
if (!$options['sizes']) {
$options['sizes'] = $extension->getSizesAttrib($name);
}
foreach ($elements as $element) {
if (!$element->hasAttribute('src')) {
continue;
}
$file = $element->getAttribute('src');
$filename = Lib::safeFilename($file);
// Set options for specific image
$optionsImg = $options;
// Add width fallback to sizes because layout reasons
// Example: An editor choose a specific width
if ($element->hasAttribute('width')) {
$width = $element->getAttribute('width');
$optionsImg['sizes'][] = $width . 'px';
}
if ($element->hasAttribute('class')) {
$attrClass = $element->getAttribute('class');
$optionsImg['class'][] = $attrClass;
}
$htmlImg = (string) $respImg($filename, $name, $optionsImg);
$domImg = $this->createDOMDocument($htmlImg);
// Load the $domImg document fragment node into the current document
$newnode = $dom->importNode($domImg->documentElement, true);
// Replace current img node
$element->parentNode->replaceChild($newnode, $element);
}
$result = $dom->saveHTML();
return new \Twig_Markup($result, 'UTF-8');
}