Skip to content

Commit

Permalink
EE 2.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
George Ornbo committed Nov 17, 2009
1 parent 9d98a71 commit 7c07f73
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 53 deletions.
6 changes: 4 additions & 2 deletions README.markdown
Expand Up @@ -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
Expand All @@ -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

Expand Down
130 changes: 79 additions & 51 deletions pi.file_oracle.php → ...hird_party/file_oracle/pi.file_oracle.php
Expand Up @@ -11,7 +11,7 @@
*
* @category Plugins
* @package File Oracle
* @version 1.0.0
* @version 2.0.0
* @since 0.1.0
* @author George Ornbo <george@shapeshed.com>
* @see {@link http://github.com/shapeshed/file_oracle.ee_addon/}
Expand All @@ -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',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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);
}
}

Expand Down

0 comments on commit 7c07f73

Please sign in to comment.