82 lines
2.2 KiB
PHP
82 lines
2.2 KiB
PHP
<?php
|
||
|
||
require_once 'core/sort.php';
|
||
|
||
//Становиться похоже на работу файлов через SPL возможно стоит реализовать на базе его
|
||
class FileRecord
|
||
{
|
||
public $file;
|
||
protected $src;
|
||
protected $parent;
|
||
|
||
function __construct(array $file, $src, $parent = false)
|
||
{
|
||
$this->file = $file;
|
||
$this->filename = $src;
|
||
$this->parent = $parent;
|
||
}
|
||
|
||
function get($name) {
|
||
return isset($this->file[$name]) ? $this->file[$name] : null;
|
||
}
|
||
|
||
function fileStat()
|
||
{
|
||
$type = is_dir($this->filename);
|
||
return array(
|
||
'name' => ($this->parent) ? ".." : $this->getName(),
|
||
'type' => $type,
|
||
'extension' => ($type) ? 'folder' : pathinfo($this->filename, PATHINFO_EXTENSION),
|
||
'date' => date("d.m.Y H:i", $this->getTime()),
|
||
'access' => 0,
|
||
'size' => ($type) ? "" : $this->getSizeString(),
|
||
'state' => isset($this->file['state']) ? $this->file['state'] : 'unknown',
|
||
'title' => $this->getTitle(),
|
||
/*'author' => $this->file['author'],
|
||
'description' => $this->file['description'],
|
||
'keywords' => $this->file['keywords'],*/
|
||
);
|
||
}
|
||
|
||
function isExpected()
|
||
{
|
||
if (isset($this->file['state'])) {
|
||
return ($this->file['state'] == 'expected');
|
||
}
|
||
return false;
|
||
}
|
||
|
||
function getSizeString()
|
||
{
|
||
$size = $this->getSize();
|
||
foreach (array('б ', 'Kб', 'Mб') as $suffix) {
|
||
if (($size / 1024) <= 1) {
|
||
return round($size, 0) . ' ' . $suffix;
|
||
}
|
||
$size /= 1024;
|
||
}
|
||
return round($size, 0) . ' GB';
|
||
}
|
||
|
||
function getSize()
|
||
{
|
||
return ($this->isExpected()) ? 0 : filesize($this->filename);
|
||
}
|
||
|
||
function getTime()
|
||
{
|
||
return ($this->isExpected()) ? 0 : filemtime($this->filename);
|
||
}
|
||
|
||
function getName()
|
||
{
|
||
return pathinfo($this->filename, PATHINFO_BASENAME);
|
||
}
|
||
|
||
function getTitle()
|
||
{
|
||
return isset($this->file['title']) ? $this->file['title'] : $this->getName();
|
||
}
|
||
}
|
||
|
||
?>
|