コード例 #1
0
ファイル: tasks.file.php プロジェクト: jalmelb/24hl2015
	private function getServerFiles($config, $destination)
	{
		$path = Path::assemble(BASE_PATH, $destination);

		$finder = new Finder();

		// Set folder location
		$finder->in($path);

		// Limit by depth
		$finder->depth('<' . array_get($config, 'depth', '1'));

		// Limit by file extension
		foreach (array_get($config, array('allowed', 'types'), array()) as $ext) {
			$finder->name("/\.{$ext}/i");
		}

		// Fetch matches
		$matches = $finder->files()->followLinks();

		// Build array
		$files = array();
		foreach ($matches as $file) {
			$filename = Path::trimSubdirectory(Path::toAsset($file->getPathname(), false));
			$display_name = ltrim(str_replace($path, '', $file->getPathname()), '/');

			$value = (Config::get('prepend_site_root_to_uploads', false)) 
			         ? '{{ _site_root }}' . ltrim($filename, '/')
			         : $filename;

			$files[] = compact('value', 'display_name');
		}

		return $files;
	}
コード例 #2
0
ファイル: ft.file.php プロジェクト: zane-insight/WhiteLaceInn
 private function makeFileSelect($selected_file = null)
 {
     $html = "<span class='btn btn-file-browse'><span class='ss-icon'>openfolder</span></span>";
     $html .= "<p><select name='{$this->fieldname}' style='display:none'>";
     $html .= "<option value=''>Select a file...</option>";
     $path = Path::assemble(BASE_PATH, array_get($this->field_config, 'destination'));
     $finder = new Finder();
     // Set folder location
     $finder->in($path);
     // Limit by depth
     $finder->depth = array_get($this->field_config, 'depth', '<1');
     // Limit by file extension
     foreach (array_get($this->field_config, array('allowed', 'types'), array()) as $ext) {
         $finder->name("*.{$ext}");
     }
     // Fetch matches
     $matches = $finder->files()->followLinks();
     // Build HTML options
     foreach ($matches as $file) {
         $filename = Path::toAsset($file->getPathname(), false);
         $display_name = ltrim(str_replace($path, '', $file->getPathname()), '/');
         $selected = $selected_file === $filename ? 'selected' : '';
         $html .= "<option value='{$filename}' {$selected}>" . $display_name . "</option>";
     }
     $html .= '</select></p>';
     return $html;
 }
コード例 #3
0
 public function index($value, $parameters = array())
 {
     $dimensions_str = '';
     if (!empty($parameters)) {
         $dimensions = explode(',', $parameters[0]);
         $width = $dimensions[0];
         $dimensions_str .= " width=\"{$width}\"";
         if (isset($dimensions[1])) {
             $height = $dimensions[1];
             $dimensions_str .= " height=\"{$height}\"";
         }
     }
     return '<img src="' . Path::toAsset($value) . '"' . $dimensions_str . ' />';
 }
 public function redactor__fetch_files()
 {
     $this->authCheck();
     $dir = Path::tidy(ltrim(Request::get('path'), '/') . '/');
     $file_list = glob($dir . "*.*", GLOB_BRACE);
     $files = array();
     if (count($file_list) > 0) {
         foreach ($file_list as $file) {
             $pi = pathinfo($file);
             $files[] = array('link' => Path::toAsset($file), 'title' => $pi['filename'], 'name' => $pi['basename'], 'size' => File::getHumanSize(File::getSize(Path::assemble(BASE_PATH, $file))));
         }
     }
     echo json_encode($files);
 }
コード例 #5
0
 public function file__render_thumbnail()
 {
     if (!($path = Request::get('path'))) {
         exit('No path specified');
     }
     $url = Path::toAsset($this->getTransformedImage($path));
     $url = Config::getSiteRoot() !== '/' ? str_replace(Config::getSiteRoot(), '', $url) : $url;
     $file = Path::assemble(BASE_PATH, $url);
     header('Content-type: image/jpeg');
     header('Content-length: ' . filesize($file));
     if ($file = fopen($file, 'rb')) {
         fpassthru($file);
     }
     exit;
 }
コード例 #6
0
 public function markitup__upload()
 {
     if (!Auth::getCurrentMember()) {
         exit("Invalid Request");
     }
     $path = Request::get('path');
     $is_image = Request::get('is_image');
     if (isset($path)) {
         // build directory
         $dir = Path::tidy(ltrim($path, '/') . '/');
         $file_type = strtolower($_FILES['file']['type']);
         $file_info = pathinfo($_FILES['file']['name']);
         // pull out the filename bits
         $filename = $file_info['filename'];
         $ext = $file_info['extension'];
         // build filename
         $file = $dir . $filename . '.' . $ext;
         // check for dupes
         if (File::exists($file)) {
             $file = BASE_PATH . '/' . $dir . $filename . '-' . date('YmdHis') . '.' . $ext;
         }
         if (!Folder::isWritable($dir)) {
             $this->log->error('Upload failed. Directory "' . $dir . '" is not writable.');
             die('Upload directory not writable');
         }
         if ($is_image && ($_FILES['file']['type'] == 'image/png' || $_FILES['file']['type'] == 'image/jpg' || $_FILES['file']['type'] == 'image/gif' || $_FILES['file']['type'] == 'image/jpeg')) {
             if (Request::get('resize', false)) {
                 $image = Image::make($_FILES['file']['tmp_name']);
                 $width = Request::get('width', null);
                 $height = Request::get('height', null);
                 $ratio = Request::get('ratio', true);
                 $upsize = Request::get('upsize', false);
                 $quality = Request::get('quality', '75');
                 $image->resize($width, $height, $ratio, $upsize)->save($file, $quality);
             } else {
                 move_uploaded_file($_FILES['file']['tmp_name'], $file);
             }
         } else {
             move_uploaded_file($_FILES['file']['tmp_name'], $file);
         }
         $return = array('filelink' => Path::toAsset($file));
         die(stripslashes(json_encode($return)));
     } else {
         die('Upload directory not set.');
     }
 }
コード例 #7
0
ファイル: ft.file.php プロジェクト: jeffreyDcreative/gkp
 public function render()
 {
     $html = "<div class='file-field-container'>";
     if ($this->field_data) {
         $html .= "<div class='file-exists'>";
         if (File::isImage(Path::fromAsset($this->field_data, true))) {
             $html .= "<img src='" . Path::toAsset($this->field_data) . "' height='58'>";
         }
         $html .= "<p>" . basename($this->field_data) . "</p>";
         $html .= "<a class='btn btn-small btn-remove-file' href='#'>" . Localization::fetch('remove') . "</a>";
         $html .= "<input type='hidden' name='{$this->fieldname}' value='{$this->field_data}' />";
         $html .= "</div>";
     } else {
         $html .= "<div class='upload-file'>";
         $html .= "<p><input type='file' name='{$this->fieldname}' tabindex='{$this->tabindex}' value='' /></p>";
         $html .= "</div>";
     }
     $html .= "</div>";
     return $html;
 }
コード例 #8
0
ファイル: file.php プロジェクト: zane-insight/WhiteLaceInn
 /**
  * Upload a file.
  *
  * @param string  $file  Name of file
  * @param string  $target  target of file
  * @param string  $filename  Name of new file
  * @return bool
  **/
 public static function upload($file, $destination, $add_root_variable = false, $renamed_file = false)
 {
     Folder::make($destination);
     $info = pathinfo($file['name']);
     $extension = $info['extension'];
     $filename = $renamed_file ?: $info['filename'];
     // build filename
     $new_filename = Path::assemble(BASE_PATH, $destination, $filename . '.' . $extension);
     // check for dupes
     if (File::exists($new_filename)) {
         $new_filename = Path::assemble(BASE_PATH, $destination, $filename . '-' . date('YmdHis') . '.' . $extension);
     }
     // Check if destination is writable
     if (!Folder::isWritable($destination)) {
         Log::error('Upload failed. Directory "' . $destination . '" is not writable.', 'core');
         return null;
     }
     // write file
     move_uploaded_file($file['tmp_name'], $new_filename);
     return Path::toAsset($new_filename, $add_root_variable);
 }
コード例 #9
0
 public function index()
 {
     /*
     |--------------------------------------------------------------------------
     | Check for image
     |--------------------------------------------------------------------------
     |
     | Transform just needs the path to an image to get started. If it exists,
     | the fun begins.
     |
     */
     $image_src = $this->fetchParam('src', null, false, false, false);
     // Set full system path
     $image_path = Path::standardize(Path::fromAsset($image_src));
     // Check if image exists before doing anything.
     if (!File::isImage($image_path)) {
         Log::error("Could not find requested image to transform: " . $image_path, "core", "Transform");
         return;
     }
     /*
     |--------------------------------------------------------------------------
     | Resizing and cropping options
     |--------------------------------------------------------------------------
     |
     | The first transformations we want to run is for size to reduce the
     | memory usage for future effects.
     |
     */
     $width = $this->fetchParam('width', null, 'is_numeric');
     $height = $this->fetchParam('height', null, 'is_numeric');
     // resize specific
     $ratio = $this->fetchParam('ratio', true, false, true);
     $upsize = $this->fetchParam('upsize', true, false, true);
     // crop specific
     $pos_x = $this->fetchParam('pos_x', 0, 'is_numeric');
     $pos_y = $this->fetchParam('pos_y', 0, 'is_numeric');
     $quality = $this->fetchParam('quality', '75', 'is_numeric');
     /*
     |--------------------------------------------------------------------------
     | Action
     |--------------------------------------------------------------------------
     |
     | Available actions: resize, crop, and guess.
     |
     | "Guess" will find the best fitting aspect ratio of your given width and
     | height on the current image automatically, cut it out and resize it to
     | the given dimension.
     |
     */
     $action = $this->fetchParam('action', 'resize');
     /*
     |--------------------------------------------------------------------------
     | Extra bits
     |--------------------------------------------------------------------------
     |
     | Delicious and probably rarely used options.
     |
     */
     $angle = $this->fetchParam('rotate', false);
     $flip_side = $this->fetchParam('flip', false);
     $blur = $this->fetchParam('blur', false, 'is_numeric');
     $pixelate = $this->fetchParam('pixelate', false, 'is_numeric');
     $greyscale = $this->fetchParam(array('greyscale', 'grayscale'), false, false, true);
     /*
     |--------------------------------------------------------------------------
     | Assemble filename and check for duplicate
     |--------------------------------------------------------------------------
     |
     | We need to make sure we don't already have this image created, so we
     | defer any action until we've processed the parameters, which create
     | a unique filename.
     |
     */
     // Late modified time of original image
     $last_modified = File::getLastModified($image_path);
     // Find .jpg, .png, etc
     $extension = File::getExtension($image_path);
     // Filename with the extension removed so we can append our unique filename flags
     $stripped_image_path = str_replace('.' . $extension, '', $image_path);
     // The possible filename flags
     $parameter_flags = array('width' => $width, 'height' => $height, 'quality' => $quality, 'rotate' => $angle, 'flip' => $flip_side, 'pos_x' => $pos_x, 'pos_y' => $pos_y, 'blur' => $blur, 'pixelate' => $pixelate, 'greyscale' => $greyscale, 'modified' => $last_modified);
     // Start with a 1 character action flag
     $file_breadcrumbs = '-' . $action[0];
     foreach ($parameter_flags as $param => $value) {
         if ($value) {
             $flag = is_bool($value) ? '' : $value;
             // don't show boolean flags
             $file_breadcrumbs .= '-' . $param[0] . $flag;
         }
     }
     // Allow converting filetypes (jpg, png, gif)
     $extension = $this->fetchParam('type', $extension);
     // Allow saving in a different directory
     $destination = $this->fetchParam('destination', Config::get('transform_destination', false), false, false, false);
     if ($destination) {
         $destination = Path::tidy(BASE_PATH . '/' . $destination);
         // Method checks to see if folder exists before creating it
         Folder::make($destination);
         $stripped_image_path = Path::tidy($destination . '/' . basename($stripped_image_path));
     }
     // Reassembled filename with all flags filtered and delimited
     $new_image_path = $stripped_image_path . $file_breadcrumbs . '.' . $extension;
     // Check if we've already built this image before
     if (File::exists($new_image_path)) {
         return Path::toAsset($new_image_path);
     }
     /*
     |--------------------------------------------------------------------------
     | Create Image
     |--------------------------------------------------------------------------
     |
     | Transform just needs the path to an image to get started. The image is
     | created in memory so we can start manipulating it.
     |
     */
     $image = Image::make($image_path);
     /*
     |--------------------------------------------------------------------------
     | Perform Actions
     |--------------------------------------------------------------------------
     |
     | This is fresh transformation. Time to work the magic!
     |
     */
     if ($action === 'resize' && ($width || $height)) {
         $image->resize($width, $height, $ratio, $upsize);
     }
     if ($action === 'crop' && $width && $height) {
         $image->crop($width, $height, $pos_x, $pos_y);
     }
     if ($action === 'smart') {
         $image->grab($width, $height);
     }
     $resize = $this->fetchParam('resize', null);
     if ($resize) {
         $resize_options = Helper::explodeOptions($resize, true);
         $image->resize(array_get($resize_options, 'width'), array_get($resize_options, 'height'), array_get($resize_options, 'ratio', true), array_get($resize_options, 'upsize', true));
     }
     $crop = $this->fetchParam('crop', null);
     if ($crop) {
         $crop_options = Helper::explodeOptions($crop, true);
         $image->crop(array_get($crop_options, 'width'), array_get($crop_options, 'height'), array_get($crop_options, 'x'), array_get($crop_options, 'y'));
     }
     if ($angle) {
         $image->rotate($angle);
     }
     if ($flip_side === 'h' || $flip_side === 'v') {
         $image->flip($flip_side);
     }
     if ($greyscale) {
         $image->greyscale();
     }
     if ($blur) {
         $image->blur($blur);
     }
     if ($pixelate) {
         $image->pixelate($pixelate);
     }
     /*
     |--------------------------------------------------------------------------
     | Save
     |--------------------------------------------------------------------------
     |
     | Get out of dodge!
     |
     */
     try {
         $image->save($new_image_path, $quality);
     } catch (Exception $e) {
         Log::fatal('Could not write new images. Try checking your file permissions.', 'core', 'Transform');
         throw new Exception('Could not write new images. Try checking your file permissions.');
     }
     return File::cleanURL($new_image_path);
 }
コード例 #10
0
ファイル: _upload.php プロジェクト: jalmelb/24hl2015
    /**
     * Upload file(s)
     * 
     * @param  string $destination  Where the file is going
     * @param  string $id           The field took look at in the files array
     * @return array
     */
    public static function uploadBatch($destination = null, $id = null)
    {
        $destination = $destination ?: Request::get('destination');
        $id          = $id ?: Request::get('id');
        $files       = self::standardizeFileUploads($_FILES);
        $results     = array();
  
        // Resizing configuration
        if ($resize = Request::get('resize')) {
            $width   = Request::get('width', null);
            $height  = Request::get('height', null);
            $ratio   = Request::get('ratio', true);
            $upsize  = Request::get('upsize', false);
            $quality = Request::get('quality', '75'); 
        }
  
        // If $files[$id][0] exists, it means there's an array of images.
        // If there's not, there's just one. We want to change this to an array.
        if ( ! isset($files[$id][0])) {
            $tmp = $files[$id];
            unset($files[$id]);
            $files[$id][] = $tmp;
        }
  
        // Process each image
        foreach ($files[$id] as $file) {
  
            // Image data
            $path = File::upload($file, $destination);
            $name = basename($path);
    
            // Resize
            if ($resize) {
                $image = \Intervention\Image\Image::make(Path::assemble(BASE_PATH, $path));
                $resize_folder = Path::assemble($image->dirname, 'resized');
                if ( ! Folder::exists($resize_folder)) {
                    Folder::make($resize_folder);
                }
                $resize_path = Path::assemble($resize_folder, $image->basename);
                $path = Path::toAsset($resize_path);
                $name = basename($path);
                $image->resize($width, $height, $ratio, $upsize)->save($resize_path, $quality);
            }
  
            $results[] = compact('path', 'name');
        }

        return $results;
    }
コード例 #11
0
ファイル: Parser.php プロジェクト: nob/joi
 /**
  * Takes a dot-notated key and finds the value for it in the given
  * array or object.
  *
  * @param  string       $key     Dot-notated key to find
  * @param  array|object $data    Array or object to search
  * @param  mixed        $default Default value to use if not found
  * @return mixed
  */
 protected function getVariable($key, $data, $default = null)
 {
     $modifiers = null;
     if (strpos($key, "|") === false) {
     } else {
         $parts = explode("|", $key);
         $key = $parts[0];
         $modifiers = array_splice($parts, 1);
     }
     if (strpos($key, $this->scopeGlue) === false) {
         $parts = explode('.', $key);
     } else {
         $parts = explode($this->scopeGlue, $key);
     }
     foreach ($parts as $key_part) {
         if (is_array($data)) {
             if (!array_key_exists($key_part, $data)) {
                 return $default;
             }
             $data = $data[$key_part];
         } elseif (is_object($data)) {
             if (!isset($data->{$key_part})) {
                 return $default;
             }
             $data = $data->{$key_part};
         } else {
             return $default;
         }
     }
     if ($modifiers) {
         foreach ($modifiers as $mod) {
             if (strpos($mod, ":") === false) {
                 $modifier_name = $mod;
                 $modifier_params = array();
             } else {
                 $parts = explode(":", $mod);
                 $modifier_name = $parts[0];
                 $modifier_params = array_splice($parts, 1);
             }
             if ($modifier_name == 'trim') {
                 $data = trim($data);
             } elseif ($modifier_name == 'img') {
                 $data = '<img src="' . \Path::toAsset($data) . '" />';
             } elseif ($modifier_name == 'link') {
                 if (filter_var($data, FILTER_VALIDATE_EMAIL)) {
                     // email address
                     $data = '<a href="mailto:' . $data . '" />' . $data . '</a>';
                 } else {
                     $data = '<a href="' . $data . '" />' . $data . '</a>';
                 }
             } elseif ($modifier_name == 'upper') {
                 $data = strtoupper($data);
             } else {
                 if ($modifier_name == 'lower') {
                     $data = strtolower($data);
                 } else {
                     if ($modifier_name == 'slugify') {
                         $data = \Slug::make($data);
                     } else {
                         if ($modifier_name == 'deslugify') {
                             $data = trim(preg_replace('~[-_]~', ' ', $data), " ");
                         } else {
                             if ($modifier_name == 'title') {
                                 $data = ucwords($data);
                             } else {
                                 if ($modifier_name == 'format') {
                                     $data = date($modifier_params[0], $data);
                                 } else {
                                     if ($modifier_name == 'format_number') {
                                         $decimals = isset($modifier_params[0]) ? $modifier_params[0] : 0;
                                         $data = number_format($data, $decimals);
                                     } else {
                                         if ($modifier_name == 'in_future') {
                                             $data = \Date::resolve($data) > time() ? "true" : "";
                                         } else {
                                             if ($modifier_name == 'in_past') {
                                                 $data = \Date::resolve($data) < time() ? "true" : "";
                                             } else {
                                                 if ($modifier_name == 'markdown') {
                                                     $data = Markdown($data);
                                                 } else {
                                                     if ($modifier_name == 'textile') {
                                                         $textile = new \Textile();
                                                         $data = $textile->TextileThis($data);
                                                     } else {
                                                         if ($modifier_name == 'length') {
                                                             if (is_array($data)) {
                                                                 $data = count($data);
                                                             } else {
                                                                 $data = strlen($data);
                                                             }
                                                         } else {
                                                             if ($modifier_name == 'scramble') {
                                                                 $data = str_shuffle($data);
                                                             } else {
                                                                 if ($modifier_name == 'word_count') {
                                                                     $data = str_word_count($data);
                                                                 } else {
                                                                     if ($modifier_name == 'obfuscate') {
                                                                         $data = \HTML::obfuscateEmail($data);
                                                                     } else {
                                                                         if ($modifier_name == 'rot13') {
                                                                             $data = str_rot13($data);
                                                                         } else {
                                                                             if ($modifier_name == 'urlencode') {
                                                                                 $data = urlencode($data);
                                                                             } else {
                                                                                 if ($modifier_name == 'urldecode') {
                                                                                     $data = urldecode($data);
                                                                                 } else {
                                                                                     if ($modifier_name == 'striptags') {
                                                                                         $data = strip_tags($data);
                                                                                     } else {
                                                                                         if ($modifier_name == '%') {
                                                                                             $divisor = isset($modifier_params[0]) ? $modifier_params[0] : 1;
                                                                                             $data = $data % $divisor;
                                                                                         } else {
                                                                                             if ($modifier_name == 'empty') {
                                                                                                 $data = \Helper::isEmptyArray($data) ? "true" : "";
                                                                                             } else {
                                                                                                 if ($modifier_name == 'not_empty') {
                                                                                                     $data = !\Helper::isEmptyArray($data) ? "true" : "";
                                                                                                 } else {
                                                                                                     if ($modifier_name == 'numeric') {
                                                                                                         $data = is_numeric($data) ? "true" : "";
                                                                                                     } else {
                                                                                                         if ($modifier_name == 'repeat') {
                                                                                                             $multiplier = isset($modifier_params[0]) ? $modifier_params[0] : 1;
                                                                                                             $data = str_repeat($data, $multiplier);
                                                                                                         } else {
                                                                                                             if ($modifier_name == 'reverse') {
                                                                                                                 $data = strrev($data);
                                                                                                             } else {
                                                                                                                 if ($modifier_name == 'round') {
                                                                                                                     $precision = isset($modifier_params[0]) ? (int) $modifier_params[0] : 0;
                                                                                                                     $data = round((double) $data, $precision);
                                                                                                                 } else {
                                                                                                                     if ($modifier_name == 'floor') {
                                                                                                                         $data = floor((double) $data);
                                                                                                                     } else {
                                                                                                                         if ($modifier_name == 'ceil') {
                                                                                                                             $data = ceil((double) $data);
                                                                                                                         } else {
                                                                                                                             if ($modifier_name == '+') {
                                                                                                                                 if (isset($modifier_params[0])) {
                                                                                                                                     $number = $modifier_params[0];
                                                                                                                                     $data = $data + $number;
                                                                                                                                 }
                                                                                                                             } else {
                                                                                                                                 if ($modifier_name == '-') {
                                                                                                                                     if (isset($modifier_params[0])) {
                                                                                                                                         $number = $modifier_params[0];
                                                                                                                                         $data = $data - $number;
                                                                                                                                     }
                                                                                                                                 } else {
                                                                                                                                     if ($modifier_name == '*') {
                                                                                                                                         if (isset($modifier_params[0])) {
                                                                                                                                             $number = $modifier_params[0];
                                                                                                                                             $data = $data * $number;
                                                                                                                                         }
                                                                                                                                     } else {
                                                                                                                                         if ($modifier_name == '/') {
                                                                                                                                             if (isset($modifier_params[0])) {
                                                                                                                                                 $number = $modifier_params[0];
                                                                                                                                                 $data = $data / $number;
                                                                                                                                             }
                                                                                                                                         } else {
                                                                                                                                             if ($modifier_name == '^') {
                                                                                                                                                 if (isset($modifier_params[0])) {
                                                                                                                                                     $exp = $modifier_params[0];
                                                                                                                                                     $data = pow($data, $exp);
                                                                                                                                                 }
                                                                                                                                             } else {
                                                                                                                                                 if ($modifier_name == 'sqrt') {
                                                                                                                                                     $data = sqrt($data);
                                                                                                                                                 } else {
                                                                                                                                                     if ($modifier_name == 'abs') {
                                                                                                                                                         $data = abs($data);
                                                                                                                                                     } else {
                                                                                                                                                         if ($modifier_name == 'log') {
                                                                                                                                                             $base = isset($modifier_params[0]) ? (int) $modifier_params[0] : M_E;
                                                                                                                                                             $data = log($data, $base);
                                                                                                                                                         } else {
                                                                                                                                                             if ($modifier_name == 'log10') {
                                                                                                                                                                 $data = log10($data);
                                                                                                                                                             } else {
                                                                                                                                                                 if ($modifier_name == 'deg2rad') {
                                                                                                                                                                     $data = deg2rad($data);
                                                                                                                                                                 } else {
                                                                                                                                                                     if ($modifier_name == 'rad2deg') {
                                                                                                                                                                         $data = rad2deg($data);
                                                                                                                                                                     } else {
                                                                                                                                                                         if ($modifier_name == 'sin') {
                                                                                                                                                                             $data = sin($data);
                                                                                                                                                                         } else {
                                                                                                                                                                             if ($modifier_name == 'asin') {
                                                                                                                                                                                 $data = asin($data);
                                                                                                                                                                             } else {
                                                                                                                                                                                 if ($modifier_name == 'cos') {
                                                                                                                                                                                     $data = cos($data);
                                                                                                                                                                                 } else {
                                                                                                                                                                                     if ($modifier_name == 'acos') {
                                                                                                                                                                                         $data = acos($data);
                                                                                                                                                                                     } else {
                                                                                                                                                                                         if ($modifier_name == 'tan') {
                                                                                                                                                                                             $data = tan($data);
                                                                                                                                                                                         } else {
                                                                                                                                                                                             if ($modifier_name == 'atan') {
                                                                                                                                                                                                 $data = atan($data);
                                                                                                                                                                                             } else {
                                                                                                                                                                                                 if ($modifier_name == 'decbin') {
                                                                                                                                                                                                     $data = decbin($data);
                                                                                                                                                                                                 } else {
                                                                                                                                                                                                     if ($modifier_name == 'dechex') {
                                                                                                                                                                                                         $data = dechex($data);
                                                                                                                                                                                                     } else {
                                                                                                                                                                                                         if ($modifier_name == 'decoct') {
                                                                                                                                                                                                             $data = decoct($data);
                                                                                                                                                                                                         } else {
                                                                                                                                                                                                             if ($modifier_name == 'hexdec') {
                                                                                                                                                                                                                 $data = hexdec($data);
                                                                                                                                                                                                             } else {
                                                                                                                                                                                                                 if ($modifier_name == 'octdec') {
                                                                                                                                                                                                                     $data = octdec($data);
                                                                                                                                                                                                                 } else {
                                                                                                                                                                                                                     if ($modifier_name == 'bindec') {
                                                                                                                                                                                                                         $data = bindec((string) $data);
                                                                                                                                                                                                                     } else {
                                                                                                                                                                                                                         if ($modifier_name == 'distance_in_mi_from') {
                                                                                                                                                                                                                             if (!isset($modifier_params[0])) {
                                                                                                                                                                                                                                 return 'Unknown';
                                                                                                                                                                                                                             }
                                                                                                                                                                                                                             if (!preg_match(\Pattern::COORDINATES, $data, $point_1_matches)) {
                                                                                                                                                                                                                                 return 'Unknown';
                                                                                                                                                                                                                             }
                                                                                                                                                                                                                             if (!preg_match(\Pattern::COORDINATES, $modifier_params[0], $point_2_matches)) {
                                                                                                                                                                                                                                 return 'Unknown';
                                                                                                                                                                                                                             }
                                                                                                                                                                                                                             $point_1 = array($point_1_matches[1], $point_1_matches[2]);
                                                                                                                                                                                                                             $point_2 = array($point_2_matches[1], $point_2_matches[2]);
                                                                                                                                                                                                                             $distance = \Math::getDistanceInKilometers($point_1, $point_2);
                                                                                                                                                                                                                             $data = \Math::convertKilometersToMiles($distance);
                                                                                                                                                                                                                         } else {
                                                                                                                                                                                                                             if ($modifier_name == 'distance_in_km_from') {
                                                                                                                                                                                                                                 if (!isset($modifier_params[0])) {
                                                                                                                                                                                                                                     return 'Unknown';
                                                                                                                                                                                                                                 }
                                                                                                                                                                                                                                 if (!preg_match(\Pattern::COORDINATES, $data, $point_1_matches)) {
                                                                                                                                                                                                                                     return 'Unknown';
                                                                                                                                                                                                                                 }
                                                                                                                                                                                                                                 if (!preg_match(\Pattern::COORDINATES, $modifier_params[0], $point_2_matches)) {
                                                                                                                                                                                                                                     return 'Unknown';
                                                                                                                                                                                                                                 }
                                                                                                                                                                                                                                 $point_1 = array($point_1_matches[1], $point_1_matches[2]);
                                                                                                                                                                                                                                 $point_2 = array($point_2_matches[1], $point_2_matches[2]);
                                                                                                                                                                                                                                 $data = \Math::getDistanceInKilometers($point_1, $point_2);
                                                                                                                                                                                                                             } else {
                                                                                                                                                                                                                                 if ($modifier_name == 'smartypants') {
                                                                                                                                                                                                                                     $data = SmartyPants($data, 2);
                                                                                                                                                                                                                                 } else {
                                                                                                                                                                                                                                     if ($modifier_name == 'widont') {
                                                                                                                                                                                                                                         // thanks to Shaun Inman for inspriation here
                                                                                                                                                                                                                                         // http://www.shauninman.com/archive/2008/08/25/widont_2_1_1
                                                                                                                                                                                                                                         // if there are content tags
                                                                                                                                                                                                                                         if (preg_match("/<\\/(?:p|li|h1|h2|h3|h4|h5|h6|figcaption)>/ism", $data)) {
                                                                                                                                                                                                                                             $data = preg_replace("/(?<!<[p|li|h1|h2|h3|h4|h5|h6|div|figcaption])([^\\s])[ \t]+([^\\s]+(?:<\\/(?:p|li|h1|h2|h3|h4|h5|h6|div|figcaption)>))\$/im", "\$1&nbsp;\$2", rtrim($data));
                                                                                                                                                                                                                                             // otherwise
                                                                                                                                                                                                                                         } else {
                                                                                                                                                                                                                                             $data = preg_replace("/([^\\s])\\s+([^\\s]+)\\s*\$/im", "\$1&nbsp;\$2", rtrim($data));
                                                                                                                                                                                                                                         }
                                                                                                                                                                                                                                     } elseif ($modifier_name == 'backspace') {
                                                                                                                                                                                                                                         if (!is_array($data) && isset($modifier_params[0]) && $modifier_params[0] > 0) {
                                                                                                                                                                                                                                             $data = substr($data, 0, -$modifier_params[0]);
                                                                                                                                                                                                                                         }
                                                                                                                                                                                                                                     } else {
                                                                                                                                                                                                                                         if ($modifier_name == 'truncate') {
                                                                                                                                                                                                                                             $length = 30;
                                                                                                                                                                                                                                             $hellip = "&hellip;";
                                                                                                                                                                                                                                             if (sizeof($modifier_params) > 0) {
                                                                                                                                                                                                                                                 $length = (int) $modifier_params[0];
                                                                                                                                                                                                                                             } else {
                                                                                                                                                                                                                                                 if (isset($modifier_params[1])) {
                                                                                                                                                                                                                                                     $hellip = (int) $modifier_params[1];
                                                                                                                                                                                                                                                 }
                                                                                                                                                                                                                                             }
                                                                                                                                                                                                                                             if (strlen($data) > $length) {
                                                                                                                                                                                                                                                 $data = substr($data, 0, $length) . $hellip;
                                                                                                                                                                                                                                             }
                                                                                                                                                                                                                                         }
                                                                                                                                                                                                                                     }
                                                                                                                                                                                                                                 }
                                                                                                                                                                                                                             }
                                                                                                                                                                                                                         }
                                                                                                                                                                                                                     }
                                                                                                                                                                                                                 }
                                                                                                                                                                                                             }
                                                                                                                                                                                                         }
                                                                                                                                                                                                     }
                                                                                                                                                                                                 }
                                                                                                                                                                                             }
                                                                                                                                                                                         }
                                                                                                                                                                                     }
                                                                                                                                                                                 }
                                                                                                                                                                             }
                                                                                                                                                                         }
                                                                                                                                                                     }
                                                                                                                                                                 }
                                                                                                                                                             }
                                                                                                                                                         }
                                                                                                                                                     }
                                                                                                                                                 }
                                                                                                                                             }
                                                                                                                                         }
                                                                                                                                     }
                                                                                                                                 }
                                                                                                                             }
                                                                                                                         }
                                                                                                                     }
                                                                                                                 }
                                                                                                             }
                                                                                                         }
                                                                                                     }
                                                                                                 }
                                                                                             }
                                                                                         }
                                                                                     }
                                                                                 }
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $data;
 }
 public function index()
 {
     /*
     |--------------------------------------------------------------------------
     | Paramers
     |--------------------------------------------------------------------------
     |
     | Match overrides Extension. Exclusion applies in both cases.
     |
     */
     $match = $this->fetchParam('match', false);
     $exclude = $this->fetchParam('exclude', false);
     $extension = $this->fetchParam(array('extension', 'type'), false);
     $in = $this->fetchParam(array('in', 'folder', 'from'), false);
     $not_in = $this->fetchParam('not_in', false);
     $file_size = $this->fetchParam('file_size', false);
     $file_date = $this->fetchParam('file_date', false);
     $depth = $this->fetchParam('depth', false);
     $sort_by = $this->fetchParam(array('sort_by', 'order_by'), false);
     $sort_dir = $this->fetchParam(array('sort_dir', 'sort_direction'), 'asc');
     $limit = $this->fetchParam('limit', false);
     if ($in) {
         $in = Helper::explodeOptions($in);
     }
     if ($not_in) {
         $not_in = Helper::explodeOptions($not_in);
     }
     if ($file_size) {
         $file_size = Helper::explodeOptions($file_size);
     }
     if ($extension) {
         $extension = Helper::explodeOptions($extension);
     }
     /*
     |--------------------------------------------------------------------------
     | Finder
     |--------------------------------------------------------------------------
     |
     | Get_Files implements most of the Symfony Finder component as a clean
     | tag wrapper mapped to matched filenames.
     |
     */
     $finder = new Finder();
     if ($in) {
         foreach ($in as $location) {
             $finder->in(Path::fromAsset($location));
         }
     }
     /*
     |--------------------------------------------------------------------------
     | Name
     |--------------------------------------------------------------------------
     |
     | Match is the "native" Finder name() method, which is supposed to
     | implement string, glob, and regex. The glob support is only partial,
     | so "extension" is a looped *single* glob rule iterator.
     |
     */
     if ($match) {
         $finder->name($match);
     } elseif ($extension) {
         foreach ($extension as $ext) {
             $finder->name("*.{$ext}");
         }
     }
     /*
     |--------------------------------------------------------------------------
     | Exclude
     |--------------------------------------------------------------------------
     |
     | Exclude directories from matching. Remapped to "not in" to allow more
     | intuitive differentiation between filename and directory matching.
     |
     */
     if ($not_in) {
         foreach ($not_in as $location) {
             $finder->exclude($location);
         }
     }
     /*
     |--------------------------------------------------------------------------
     | Not Name
     |--------------------------------------------------------------------------
     |
     | Exclude files matching a given pattern: string, regex, or glob.
     | By default we don't allow looking for PHP files. Be smart.
     |
     */
     if ($this->fetchParam('allow_php', false) !== TRUE) {
         $finder->notName("*.php");
     }
     if ($exclude) {
         $finder->notName($exclude);
     }
     /*
     |--------------------------------------------------------------------------
     | File Size
     |--------------------------------------------------------------------------
     |
     | Restrict files by size. Can be chained and allows comparison operators.
     |
     */
     if ($file_size) {
         foreach ($file_size as $size) {
             $finder->size($size);
         }
     }
     /*
     |--------------------------------------------------------------------------
     | File Date
     |--------------------------------------------------------------------------
     |
     | Restrict files by last modified date. Can use comparison operators, and
     | since/after is aliased to >, and until/before to <.
     |
     */
     if ($file_date) {
         $finder->date($file_date);
     }
     /*
     |--------------------------------------------------------------------------
     | Depth
     |--------------------------------------------------------------------------
     |
     | Recursively traverse directories, starting at 0.
     |
     */
     if ($depth) {
         $finder->depth($depth);
     }
     /*
     |--------------------------------------------------------------------------
     | Sort By
     |--------------------------------------------------------------------------
     |
     | Sort by name, file, or type
     |
     */
     if ($sort_by) {
         if ($sort_by === 'file' || $sort_by === 'name') {
             $finder->sortByName();
         } elseif ($sort_by === 'type') {
             $finder->sortByType();
         }
     }
     /*
     |--------------------------------------------------------------------------
     | Assemble File Array
     |--------------------------------------------------------------------------
     |
     | Select the important bits of data on the list of files.
     |
     */
     $matches = $finder->files()->followLinks();
     $files = array();
     foreach ($matches as $file) {
         $files[] = array('extension' => $file->getExtension(), 'filename' => $file->getFilename(), 'file' => Path::toAsset($file->getPathname()), 'name' => Path::toAsset($file->getPathname()), 'size' => File::getHumanSize($file->getSize()), 'size_bytes' => $file->getSize(), 'size_kilobytes' => number_format($file->getSize() / 1024, 2), 'size_megabytes' => number_format($file->getSize() / 1048576, 2), 'size_gigabytes' => number_format($file->getSize() / 1073741824, 2), 'is_image' => File::isImage($file->getPathname()));
     }
     /*
     |--------------------------------------------------------------------------
     | Sort Direction
     |--------------------------------------------------------------------------
     |
     | Set the sort direction, defaulting to "asc" (ascending)
     |
     */
     if ($sort_dir === 'desc') {
         $files = array_reverse($files);
     }
     /*
     |--------------------------------------------------------------------------
     | Randomizing
     |--------------------------------------------------------------------------
     |
     | You can't sort randomly using Symfony finder, so we'll do it manually.
     |
     */
     if ($sort_by === 'random') {
         shuffle($files);
     }
     /*
     |--------------------------------------------------------------------------
     | Limit Files
     |--------------------------------------------------------------------------
     |
     | Limit the number of files returned. Needs to be run after sort_dir to 
     | ensure consistency.
     |
     */
     if ($limit) {
         $files = array_slice($files, 0, $limit);
     }
     return Parse::tagLoop($this->content, $files, true, $this->context);
 }
コード例 #13
0
 public function index()
 {
     $src = $this->fetchParam('src', '', NULL, FALSE, FALSE);
     return Path::toAsset($src);
 }
コード例 #14
0
ファイル: mod.img.php プロジェクト: zane-insight/WhiteLaceInn
 public function index($value, $parameters = array())
 {
     return '<img src="' . Path::toAsset($value) . '">';
 }