本文整理汇总了PHP中f::name方法的典型用法代码示例。如果您正苦于以下问题:PHP f::name方法的具体用法?PHP f::name怎么用?PHP f::name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类f
的用法示例。
在下文中一共展示了f::name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: crawl
function crawl()
{
$path = url::strip_query($this->raw);
$path = (array) str::split($path, '/');
if (a::first($path) == 'index.php') {
array_shift($path);
}
// parse params
foreach ($path as $p) {
if (str::contains($p, ':')) {
$parts = explode(':', $p);
if (count($parts) < 2) {
continue;
}
$this->params->{$parts}[0] = $parts[1];
} else {
$this->path->_[] = $p;
}
}
// get the extension from the last part of the path
$this->extension = f::extension($this->path->last());
if ($this->extension != false) {
// remove the last part of the path
$last = array_pop($this->path->_);
$this->path->_[] = f::name($last);
}
return $this->path;
}
示例2: language
public function language()
{
if (!is_null($this->language)) {
return $this->language;
}
$codes = $this->page->site()->languages()->codes();
$code = f::extension(f::name($this->root));
return $this->language = in_array($code, $codes) ? $this->page->site()->languages()->find($code) : false;
}
示例3: to
public function to()
{
$source = $this->source();
$name = f::name($source['name']);
$extension = f::extension($source['name']);
$safeName = f::safeName($name);
$safeExtension = str_replace('jpeg', 'jpg', str::lower($extension));
return str::template($this->options['to'], array('name' => $name, 'filename' => $source['name'], 'safeName' => $safeName, 'safeFilename' => $safeName . '.' . $safeExtension, 'extension' => $extension, 'safeExtension' => $safeExtension));
}
示例4: __construct
public function __construct()
{
$root = kirby::instance()->roots()->accounts();
foreach (dir::read($root) as $file) {
// skip invalid account files
if (f::extension($file) != 'php') {
continue;
}
$user = new User(f::name($file));
$this->append($user->username(), $user);
}
}
示例5: all
public static function all()
{
$files = dir::read(static::$root);
$result = array();
$home = site()->homePage()->uid();
$error = site()->errorPage()->uid();
foreach ($files as $file) {
$name = f::name($file);
if ($name != 'site' and $name != $home and $name != $error) {
$result[] = $name;
}
}
return $result;
}
示例6: all
public static function all()
{
$files = dir::read(static::$root);
$result = array();
$home = kirby()->option('home', 'home');
$error = kirby()->option('error', 'error');
foreach ($files as $file) {
$name = f::name($file);
if ($name != 'site' and $name != $home and $name != $error) {
$result[] = $name;
}
}
return $result;
}
示例7: to
public function to()
{
if (!is_null($this->to)) {
return $this->to;
}
$source = $this->source();
$name = f::name($source['name']);
$extension = f::extension($source['name']);
$safeName = f::safeName($name);
$safeExtension = str_replace('jpeg', 'jpg', str::lower($extension));
if (empty($safeExtension)) {
$safeExtension = f::mimeToExtension(f::mime($source['tmp_name']));
}
return $this->to = str::template($this->options['to'], array('name' => $name, 'filename' => $source['name'], 'safeName' => $safeName, 'safeFilename' => $safeName . r(!empty($safeExtension), '.' . $safeExtension), 'extension' => $extension, 'safeExtension' => $safeExtension));
}
示例8: file
function file($field, $destination, $params = array())
{
$allowed = a::get($params, 'allowed', c::get('upload.allowed', array('image/jpeg', 'image/png', 'image/gif')));
$maxsize = a::get($params, 'maxsize', c::get('upload.maxsize', self::max_size()));
$overwrite = a::get($params, 'overwrite', c::get('upload.overwrite', true));
$sanitize = a::get($params, 'sanitize', true);
$file = a::get($_FILES, $field);
if (empty($file)) {
return array('status' => 'error', 'msg' => l::get('upload.errors.missing-file', 'The file has not been found'));
}
$name = a::get($file, 'name');
$type = a::get($file, 'type');
$tmp_name = a::get($file, 'tmp_name');
$error = a::get($file, 'error');
$size = a::get($file, 'size');
$msg = false;
$extension = self::mime_to_extension($type, 'jpg');
// convert the filename to a save name
$fname = $sanitize ? f::safe_name(f::name($name)) : f::name($name);
// setup the destination
$destination = str_replace('{name}', $fname, $destination);
$destination = str_replace('{extension}', $extension, $destination);
if (file_exists($destination) && $overwrite == false) {
return array('status' => 'error', 'msg' => l::get('upload.errors.file-exists', 'The file exists and cannot be overwritten'));
}
if (empty($tmp_name)) {
return array('status' => 'error', 'msg' => l::get('upload.errors.missing-file', 'The file has not been found'));
}
if ($error != 0) {
return array('status' => 'error', 'msg' => l::get('upload.errors.invalid-upload', 'The upload failed'));
}
if ($size > $maxsize) {
return array('status' => 'error', 'msg' => l::get('upload.errors.too-big', 'The file is too big'));
}
if (!in_array($type, $allowed)) {
return array('status' => 'error', 'msg' => l::get('upload.errors.invalid-file', 'The file type is not allowed') . ': ' . $type);
}
// try to change the permissions for the destination
@chmod(dirname($destination), 0777);
if (!@copy($tmp_name, $destination)) {
return array('status' => 'error', 'msg' => l::get('upload.errors.move-error', 'The file could not be moved to the server'));
}
// try to change the permissions for the final file
@chmod($destination, 0777);
return array('status' => 'success', 'msg' => l::get('upload.success', 'The file has been uploaded'), 'type' => $type, 'extension' => $extension, 'file' => $destination, 'size' => $size, 'name' => f::filename($destination));
}
示例9: templates
protected function templates()
{
$templates = ['all'];
foreach (dir::read($this->dir() . '/site/blueprints') as $file) {
if (!in_array(f::extension($file), ['php', 'yml', 'yaml'])) {
continue;
}
$name = f::name($file);
if (!in_array($name, ['error', 'site', 'home'])) {
$templates[] = $name;
}
}
return $templates;
}
示例10: init
function init($page)
{
foreach ($page->rawfiles as $key => $file) {
// skip invisible files
if (preg_match('!^\\.!', $file)) {
continue;
}
$info = array('name' => f::name($file), 'filename' => $file, 'extension' => f::extension($file), 'root' => $page->root . '/' . $file, 'uri' => $page->diruri . '/' . $file, 'parent' => $this, 'modified' => @filectime($page->root . '/' . $file));
switch ($info['extension']) {
case 'jpg':
case 'jpeg':
case 'gif':
case 'png':
$info['type'] = 'image';
$class = 'image';
break;
case 'pdf':
case 'doc':
case 'xls':
case 'ppt':
$info['type'] = 'document';
$class = 'file';
break;
case 'mov':
case 'avi':
case 'ogg':
case 'ogv':
case 'webm':
case 'flv':
case 'swf':
case 'mp4':
$info['type'] = 'video';
$class = 'video';
break;
case 'mp3':
$info['type'] = 'sound';
$class = 'file';
break;
case c::get('content.file.extension', 'txt'):
$info['type'] = 'content';
$class = 'variables';
break;
default:
$info['type'] = 'other';
$class = 'file';
}
$this->{$file} = new $class($info);
}
$this->dispatchImages();
$this->dispatchContent();
}
示例11: stillHasDefaultAccount
static function stillHasDefaultAccount()
{
$file = c::get('root.site') . '/' . c::get('panel.folder') . '/accounts/admin.php';
if (file_exists($file)) {
return true;
}
$dir = c::get('root.site') . '/' . c::get('panel.folder') . '/accounts';
$files = dir::read($dir);
$default = array('username' => 'admin', 'password' => 'adminpassword', 'language' => 'en');
foreach ($files as $file) {
$username = f::name($file);
$user = user::load($username);
$diff = array_diff($user, $default);
if (empty($diff)) {
return true;
}
}
return false;
}
示例12: plugins
/**
* Loads all available plugins for the site
*
* @return array
*/
public function plugins()
{
// check for a cached plugins array
if (!is_null($this->plugins)) {
return $this->plugins;
}
// get the plugins root
$root = $this->roots->plugins();
// start the plugin registry
$this->plugins = array();
// check for an existing plugins dir
if (!is_dir($root)) {
return $this->plugins;
}
foreach (array_diff(scandir($root), array('.', '..')) as $file) {
if (is_dir($root . DS . $file)) {
$this->plugin($file, 'dir');
} else {
if (f::extension($file) == 'php') {
$this->plugin(f::name($file), 'file');
}
}
}
return $this->plugins;
}
示例13: findTemplates
static function findTemplates()
{
global $settings, $pages, $page, $site;
$templates = array();
if (@$settings->pages['template'] && !$site->isHome) {
$templates[] = $settings->pages['template'];
} else {
$files = dir::read(c::get('root.site') . '/templates');
foreach ($files as $file) {
$name = f::name($file);
// check if it is valid or already there.
if (empty($name) || in_array($name, $templates)) {
continue;
}
// add it to the list of templates
$templates[] = $name;
}
}
return $templates;
}
示例14: createNewFilename
/**
* Generates a new filename for a given name
* and makes sure to handle badly given extensions correctly
*
* @param string $name
* @return string
*/
public function createNewFilename($name, $safeName = true)
{
$name = basename($safeName ? f::safeName($name) : $name);
$ext = f::extension($name);
// remove possible extensions
if (in_array($ext, f::extensions())) {
$name = f::name($name);
}
return trim($name . '.' . $this->extension(), '.');
}
示例15: secure_upload
/**
* Upload image
*
* Requirement: Kirby
*
* @param string $name Name POSTNAME
* @return array
* @version 1.0 - 2011-01-12
*/
function secure_upload($options)
{
/*
$options['field'] // (required) source string
$options['path'] // (required) source string
*/
$options['image'] = isset($options['image']) ? $options['image'] : true;
// default true
$options['max_size'] = isset($options['max_size']) ? min($options['max_size'], server_maxupload()) : server_maxupload();
// default server max upload in bytes
if (empty($options['field']) || empty($options['path'])) {
return array('error' => 'Option field and path is required');
}
if (!isset($_FILES[$options['field']])) {
return array('error' => 'No file was selected');
}
// validate path
$upload_path = $options['path'];
$upload_path = rtrim($upload_path, '/') . '/';
if (@realpath($upload_path) !== false) {
$upload_path = str_replace("\\", "/", realpath($upload_path));
}
if (!file_exists($upload_path)) {
if (!@mkdir($upload_path, 0777)) {
return array('error' => 'Directory isnt writable');
}
chmod($upload_path, 0777);
}
if (!@is_dir($upload_path) || !is_writable($upload_path)) {
return array('error' => 'Directory isnt writable');
}
$upload_path = preg_replace("/(.+?)\\/*\$/", "\\1/", $upload_path);
// ?
// Remapping for loop
if (!is_array($_FILES[$options['field']]['tmp_name'])) {
$_FILES[$options['field']] = array_map(function ($item) {
return array($item);
}, $_FILES[$options['field']]);
}
$success = array();
foreach ($_FILES[$options['field']]['tmp_name'] as $key => $value) {
// Get upload info
$error = $_FILES[$options['field']]['error'][$key];
$name = $_FILES[$options['field']]['name'][$key];
$tmp_name = $_FILES[$options['field']]['tmp_name'][$key];
$size = $_FILES[$options['field']]['size'][$key];
$type = $_FILES[$options['field']]['type'][$key];
if (!is_uploaded_file($tmp_name) || $error != UPLOAD_ERR_OK) {
continue;
}
$type = preg_replace("/^(.+?);.*\$/", "\\1", $type);
// ?
$type = strtolower(trim(stripslashes($type), '"'));
$ext = f::extension($name);
$name = f::safe_name(f::name($name));
$name = substr($name, 0, 100);
// Check allowed file type
$image_types = array('gif', 'jpg', 'jpeg', 'png', 'jpe');
if ($options['image']) {
if (!in_array($ext, $image_types) || !is_image($type) || getimagesize($tmp_name) === false) {
continue;
}
}
// Check file size
if ($options['max_size'] < $size) {
continue;
}
// Unique filename
if (file_exists($upload_path . $name . "." . $ext)) {
$number = 1;
while (file_exists($upload_path . $name . $number . "." . $ext)) {
$number++;
}
$name = $name . $number;
}
// save
if (!@move_uploaded_file($tmp_name, $upload_path . $name . "." . $ext)) {
continue;
}
// TODO xss clean
$success[] = array('extension' => $ext, 'filename' => $name . "." . $ext, 'original_filename' => $_FILES[$options['field']]['name'][$key], 'name' => $name, 'size' => $size, 'nice_size' => f::nice_size($size), 'md5' => md5(file_get_contents($upload_path . $name . "." . $ext)));
}
return array('failed' => count($_FILES[$options['field']]['tmp_name']) - count($success), 'success' => $success);
}