From 7c07f735d5015bb484833cb2543cc5d4d8c58e07 Mon Sep 17 00:00:00 2001 From: George Ornbo Date: Tue, 17 Nov 2009 17:10:37 +0000 Subject: [PATCH] EE 2.0 release --- README.markdown | 6 +- .../file_oracle/pi.file_oracle.php | 130 +++++++++++------- 2 files changed, 83 insertions(+), 53 deletions(-) rename pi.file_oracle.php => system/expressionengine/third_party/file_oracle/pi.file_oracle.php (53%) diff --git a/README.markdown b/README.markdown index 3f1e951..0c2f77a 100755 --- a/README.markdown +++ b/README.markdown @@ -5,7 +5,7 @@ ## Compatibility -* ExpressionEngine Version 1.6.x +* ExpressionEngine Version 1.6.x (1.x.x releases), ExpressionEngine Version 2.0.x (2.x.x releases) * PHP 5.x ## License @@ -18,7 +18,9 @@ File Oracle is licensed under a [Open Source Initiative - BSD License][] license ## Installation -This file pi.file_oracle_.php must be placed in the /system/plugins/ folder in your [ExpressionEngine][] installation. +For EE 1.6.x the file pi.file\_oracle.php must be placed in the /system/plugins/ folder in your [ExpressionEngine][] installation. + +For EE 2.0.0 the file\_oracle folder must be placed in the /system/expressionengine/third_party/ folder in your [ExpressionEngine][] installation. ## Name diff --git a/pi.file_oracle.php b/system/expressionengine/third_party/file_oracle/pi.file_oracle.php similarity index 53% rename from pi.file_oracle.php rename to system/expressionengine/third_party/file_oracle/pi.file_oracle.php index 9a8a374..2bd268a 100644 --- a/pi.file_oracle.php +++ b/system/expressionengine/third_party/file_oracle/pi.file_oracle.php @@ -11,7 +11,7 @@ * * @category Plugins * @package File Oracle - * @version 1.0.0 + * @version 2.0.0 * @since 0.1.0 * @author George Ornbo * @see {@link http://github.com/shapeshed/file_oracle.ee_addon/} @@ -24,7 +24,7 @@ */ $plugin_info = array( 'pi_name' => 'File Oracle', - 'pi_version' => '1.0.0', + 'pi_version' => '2.0.0', 'pi_author' => 'George Ornbo', 'pi_author_url' => 'http://shapeshed.com/', 'pi_description' => 'Provides information on a file', @@ -57,7 +57,7 @@ class File_oracle{ * The error message used if no file is found * @var string */ - private $error_message = "The file was not found - please check your settings"; + public $error_message = "The file was not found - please check your settings"; /** * Holds the response from the pathinfo() on the file @@ -94,23 +94,26 @@ public function File_oracle() */ public function __construct() { - global $TMPL; - - $this->tagdata = $TMPL->tagdata; + $this->EE =& get_instance(); + + $this->tagdata = $this->EE->TMPL->tagdata; + - $this->file = str_replace(SLASH, '/', $TMPL->fetch_param('file')); - $this->file = trim(strip_tags($this->file)); + $this->file = str_replace(SLASH, '/', $this->EE->TMPL->fetch_param('file')); + + echo $this->file; + $this->file = trim(strip_tags($this->file)); - if (stristr($this->file, $_SERVER['DOCUMENT_ROOT'])) - { - $this->file = $this->file; - } - else - { - $this->file = $_SERVER['DOCUMENT_ROOT'] . $this->file; - } + if (stristr($this->file, $_SERVER['DOCUMENT_ROOT'])) + { + $this->file = $this->file; + } + else + { + $this->file = $_SERVER['DOCUMENT_ROOT'] . $this->file; + } - $this->return_data = file_exists($this->file) ? $this->get_file_data($this->file, $this->tagdata) : $this->error_message; + $this->return_data = file_exists($this->file) ? $this->get_file_data($this->file, $this->tagdata) : $this->error_message; } /** @@ -120,72 +123,97 @@ public function __construct() */ protected function get_file_data($file, $tagdata) { - global $TMPL, $LOC; - clearstatcache(); + clearstatcache(); - $this->pathinfo = pathinfo($file); - $this->stat = stat($file); + $this->EE =& get_instance(); + + $this->file = str_replace(SLASH, '/', $this->EE->TMPL->fetch_param('file')); + $this->file = trim(strip_tags($this->file)); + + if (stristr($this->file, $_SERVER['DOCUMENT_ROOT'])) + { + $this->file = $this->file; + } + else + { + $this->file = $_SERVER['DOCUMENT_ROOT'] . $this->file; + } + + if (!file_exists($this->file)) + { + $this->return_data = $this->error_message; + return; + } + + $this->pathinfo = pathinfo($this->file); + $this->stat = stat($this->file); - $this->data['human_size'] = $this->human_size($this->stat['size']); - $this->data['file_perms'] = substr(decoct(fileperms($file)),2); - $this->data['mime_type'] = $this->get_mime_type($file); - $this->data['md5'] = md5_file($file); - $this->data['sha1'] = sha1_file($file); + $this->data['human_size'] = $this->human_size($this->stat['size']); + $this->data['file_perms'] = substr(decoct(fileperms($this->file)),2); + $this->data['mime_type'] = $this->get_mime_type($this->file); + $this->data['md5'] = md5_file($this->file); + $this->data['sha1'] = sha1_file($this->file); - $date_vars = array('atime', 'mtime', 'ctime'); + $date_vars = array('atime', 'mtime', 'ctime'); - foreach ($date_vars as $val) - { - if (preg_match_all("/".LD.$val."\s+format=[\"'](.*?)[\"']".RD."/s", $tagdata, $matches)) + foreach ($date_vars as $val) { - for ($j = 0; $j < count($matches['0']); $j++) + if (preg_match_all("/".LD.$val."\s+format=[\"'](.*?)[\"']".RD."/s", $this->EE->TMPL->tagdata, $matches)) { - $matches['0'][$j] = str_replace(array(LD,RD), '', $matches['0'][$j]); + + if (strpos($this->EE->TMPL->tagdata, LD.$val) === FALSE) continue; - switch ($val) + if (preg_match_all("/".LD.$val."\s+format=([\"'])([^\\1]*?)\\1".RD."/s", $this->EE->TMPL->tagdata, $matches)) { - case 'mtime' : $mtime[$matches['0'][$j]] = $LOC->fetch_date_params($matches['1'][$j]); - break; - case 'atime' : $atime[$matches['0'][$j]] = $LOC->fetch_date_params($matches['1'][$j]); - break; - case 'ctime' : $ctime[$matches['0'][$j]] = $LOC->fetch_date_params($matches['1'][$j]); - break; + for ($j = 0; $j < count($matches[0]); $j++) + { + $matches[0][$j] = str_replace(array(LD,RD), '', $matches[0][$j]); + + switch ($val) + { + case 'mtime' : $mtime[$matches[0][$j]] = $this->EE->localize->fetch_date_params($matches[2][$j]); + break; + case 'atime' : $atime[$matches[0][$j]] = $this->EE->localize->fetch_date_params($matches[2][$j]); + break; + case 'ctime' : $ctime[$matches[0][$j]] = $this->EE->localize->fetch_date_params($matches[2][$j]); + break; + } + } } } } - } - - foreach ($TMPL->var_single as $key => $val) + foreach ($this->EE->TMPL->var_single as $key => $val) { if (isset($this->stat[$val])) { - $tagdata = $TMPL->swap_var_single($val, $this->stat[$val], $tagdata); + $tagdata = $this->EE->TMPL->swap_var_single($key, $this->stat[$val], $tagdata); } if (isset($this->pathinfo[$val])) { - $tagdata = $TMPL->swap_var_single($val, $this->pathinfo[$val], $tagdata); + $tagdata = $this->EE->TMPL->swap_var_single($key, $this->pathinfo[$val], $tagdata); } if (isset($this->data[$val])) { - $tagdata = $TMPL->swap_var_single($val, $this->data[$val], $tagdata); + $tagdata = $this->EE->TMPL->swap_var_single($key, $this->data[$val], $tagdata); } if (isset($mtime[$key])) { foreach ($mtime[$key] as $dvar) - $val = str_replace($dvar, $LOC->convert_timestamp($dvar, $this->stat['mtime'], TRUE), $val); - $tagdata = $TMPL->swap_var_single($key, $val, $tagdata); + $val = str_replace($dvar, $this->EE->localize->convert_timestamp($dvar, $this->stat['mtime'], TRUE), $val); + $tagdata = $this->EE->TMPL->swap_var_single($key, $val, $tagdata); } if (isset($atime[$key])) { foreach ($atime[$key] as $dvar) - $val = str_replace($dvar, $LOC->convert_timestamp($dvar, $this->stat['atime'], TRUE), $val); - $tagdata = $TMPL->swap_var_single($key, $val, $tagdata); + $val = str_replace($dvar, $this->EE->localize->convert_timestamp($dvar, $this->stat['atime'], TRUE), $val); + $tagdata = $this->EE->TMPL->swap_var_single($key, $val, $tagdata); } if (isset($ctime[$key])) { foreach ($ctime[$key] as $dvar) - $val = str_replace($dvar, $LOC->convert_timestamp($dvar, $this->stat['ctime'], TRUE), $val); - $tagdata = $TMPL->swap_var_single($key, $val, $tagdata); + + $val = str_replace($dvar, $this->EE->localize->convert_timestamp($dvar, $this->stat['ctime'], TRUE), $val); + $tagdata = $this->EE->TMPL->swap_var_single($key, $val, $tagdata); } }