当前位置: 首页>>代码示例>>PHP>>正文


PHP f::extension方法代码示例

本文整理汇总了PHP中f::extension方法的典型用法代码示例。如果您正苦于以下问题:PHP f::extension方法的具体用法?PHP f::extension怎么用?PHP f::extension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在f的用法示例。


在下文中一共展示了f::extension方法的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;
 }
开发者ID:narrenfrei,项目名称:kirbycms,代码行数:28,代码来源:uri.php

示例2: write

 public static function write($file, $data, $type = null)
 {
     // type autodetection
     if (is_null($type)) {
         $type = f::extension($file);
     }
     return f::write($file, data::encode($data, $type));
 }
开发者ID:robinandersen,项目名称:robin,代码行数:8,代码来源:data.php

示例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));
 }
开发者ID:chrishiam,项目名称:LVSL,代码行数:9,代码来源:upload.php

示例4: 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;
 }
开发者ID:kristianhalte,项目名称:super_organic,代码行数:9,代码来源:content.php

示例5: sublime

 function sublime($params)
 {
     global $site;
     $page = $this->obj;
     $id = @$params['sublime'];
     $class = @$params['class'];
     $videos = array();
     $poster = false;
     // gather all video files which match the given id/name
     foreach ($page->videos() as $v) {
         if (preg_match('!^' . preg_quote($id) . '!i', $v->name())) {
             $extension = f::extension($v->name());
             $mobile = $extension == 'mobile' ? $v->mobile = true : ($v->mobile = false);
             $hd = $extension == 'hd' ? $v->hd = true : ($v->hd = false);
             $videos[] = $v;
         }
     }
     if (empty($videos)) {
         return false;
     }
     // find the poster for this video
     foreach ($page->images() as $i) {
         if (preg_match('!^' . preg_quote($id) . '!i', $i->name())) {
             $poster = $i;
             break;
         }
     }
     $defaults = array('uid' => $id, 'name' => $id);
     $options = array_merge($defaults, $params);
     $width = html($options['width']);
     $height = html($options['height']);
     $uid = html($options['uid']);
     $name = html($options['name']);
     if (!$width) {
         $width = c::get('kirbytext.video.width');
     }
     if (!$height) {
         $height = c::get('kirbytext.video.height');
     }
     // create an additional css class if specified
     if (!empty($class)) {
         $class = ' ' . html($class);
     }
     // check for a poster
     $poster = $poster ? ' poster="' . $poster->url() . '"' : false;
     $html = '<video class="sublime' . $class . '"' . $poster . ' width="' . $width . '" height="' . $height . '" data-uid="' . $uid . '" data-name="' . $name . '" preload="none">';
     foreach ($videos as $video) {
         // check for hd quality
         $hd = $video->hd() ? ' data-quality="hd"' : '';
         // generate the source tag for each video
         $html .= '<source src="' . $video->url() . '"' . $hd . ' />';
     }
     $html .= '</video>';
     return $html;
 }
开发者ID:nilshendriks,项目名称:kirbycms-extensions,代码行数:55,代码来源:sublimevideo.php

示例6: __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);
     }
 }
开发者ID:aoimedia,项目名称:kosmonautensofa,代码行数:12,代码来源:users.php

示例7: plugins

 static function plugins()
 {
     $root = c::get('root.plugins');
     $files = dir::read($root);
     if (!is_array($files)) {
         return false;
     }
     foreach ($files as $file) {
         if (f::extension($file) != 'php') {
             continue;
         }
         self::file($root . '/' . $file);
     }
 }
开发者ID:04x10,项目名称:04x10.com,代码行数:14,代码来源:load.php

示例8: 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));
 }
开发者ID:irenehilber,项目名称:kirby-base,代码行数:15,代码来源:upload.php

示例9: 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, f::extension($name));
     // 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));
 }
开发者ID:codecuts,项目名称:lanningsmith-website,代码行数:46,代码来源:upload.php

示例10: plugins

 static function plugins($folder = false)
 {
     $root = c::get('root.plugins');
     $folder = $folder ? $folder : $root;
     $files = dir::read($folder);
     if (!is_array($files)) {
         return false;
     }
     foreach ($files as $file) {
         if (is_dir($folder . '/' . $file) && $folder == $root) {
             self::plugins($folder . '/' . $file);
             continue;
         }
         if (f::extension($file) != 'php') {
             continue;
         }
         self::file($folder . '/' . $file);
     }
 }
开发者ID:nilshendriks,项目名称:kirbycms,代码行数:19,代码来源:load.php

示例11: photo

 public function photo()
 {
     if (!is_null($this->photo)) {
         return $this->photo;
     }
     $extension = f::extension($this->data['photo']);
     $filename = rtrim(sha1($this->url) . '.' . $extension, '.');
     $path = c::get('webmentions.images', 'assets/images/mentions');
     $root = kirby()->roots()->index() . DS . str_replace('/', DS, $path) . DS . $filename;
     $url = kirby()->urls()->index() . '/' . $path . '/' . $filename;
     $photo = new Media($root, $url);
     if (!$photo->exists()) {
         $image = remote::get($this->data['photo']);
         $allowed = array('image/jpeg', 'image/png', 'image/gif');
         f::write($root, $image->content());
         if (!in_array($photo->mime(), $allowed) or $photo->size() == 0) {
             $photo->delete();
         }
     }
     if (!$photo->exists() or !$photo->type() == 'image') {
         $photo = new Obj(array('url' => $this->data['photo'], 'exists' => false));
     }
     return $this->photo = $photo;
 }
开发者ID:aizlewood,项目名称:2016,代码行数:24,代码来源:author.php

示例12: 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);
}
开发者ID:o-github-o,项目名称:jQuery-Ajax-Upload,代码行数:93,代码来源:secure_upload.php

示例13: foreach

    foreach ($page->images() as $i) {
        if (preg_match('!^' . preg_quote($id) . '!i', $i->name())) {
            $poster = $i;
            break;
        }
    }
    $width = $tag->attr('width', c::get('kirbytext.video.width'));
    $height = $tag->attr('height', c::get('kirbytext.video.height'));
    $uid = $tag->attr('uid', $id);
    $name = $tag->attr('name', $id);
    $html = new Brick('video');
    $html->attr('width', $width);
    $html->attr('height', $height);
    $html->attr('data-uid', $uid);
    $html->attr('data-name', $name);
    $html->attr('preload', 'none');
    $html->attr('class', trim('video sublime' . $class));
    if ($poster) {
        $html->attr('poster', $poster->url());
    }
    foreach ($videos as $video) {
        $source = new Brick('source');
        $source->attr('src', $video->url());
        $source->attr('type', $video->mime());
        if (f::extension($video->name()) == 'hd') {
            $source->attr('data-quality', 'hd');
        }
        $html->append($source);
    }
    return $html;
});
开发者ID:cfreitag,项目名称:plugins,代码行数:31,代码来源:sublimevideo.php

示例14: 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;
 }
开发者ID:getkirby,项目名称:cli,代码行数:14,代码来源:Blueprint.php

示例15: 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();
 }
开发者ID:nilshendriks,项目名称:kirbycms,代码行数:51,代码来源:files.php


注:本文中的f::extension方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。