* @version 1.0.1 (July 10, 2004) * @package AutoIndex */ class FileItem extends Item { /** * @param string $fn The filename * @return string Everything after the list dot in the filename, not including the dot */ public static function ext($fn, $ext = true) { $fn = Item::get_basename($fn); switch($ext) { case false: return (strpos($fn, '.') ? substr($fn, 0, strrpos($fn, '.')) : $fn); break; default: return (strpos($fn, '.') ? strtolower(substr(strrchr($fn, '.'), 1)) : ''); break; } } /** * @return string Returns the name of the filename * @see FileItem::ext() */ public function file_name() { return self::ext($this->filename, false); } /** * @return string Returns the extension of the filename * @see FileItem::ext() */ public function file_ext() { return self::ext($this->filename); } /** * @param string $parent_dir * @param string $filename */ public function __construct($parent_dir, $filename) { parent::__construct($parent_dir, $filename); if (!is_file($this->parent_dir . $filename)) { throw new ExceptionDisplay('File ' . Url::html_output($this->parent_dir . $filename) . ' does not exist.'); } global $config, $words, $downloads, $request; $version_compare = explode(".", phpversion(), 3); if ($version_compare[0] == '' || $version_compare[1] == '') { $phpversion = '5.4'; } else { $phpversion = $version_compare[0] . '.' . $version_compare[1]; } $this->filename = $filename; $this->size = new Size(filesize($this->parent_dir . $filename)); if (ICON_PATH) { $file_icon = new Icon($filename); $this->icon = $file_icon->__toString(); } $this->downloads = (DOWNLOAD_COUNT && $downloads->is_set($parent_dir . $filename) ? (int)($downloads->__get($parent_dir . $filename)) : 0); $this->link = Url::html_output($request->server('PHP_SELF')) . '?dir=' . Url::translate_uri(substr($this->parent_dir, strlen($config->__get('base_dir')))) . '&file=' . Url::translate_uri($filename); if (THUMBNAIL_HEIGHT && in_array(self::ext($filename), array('png', 'jpg', 'jpeg', 'jfif', 'gif', 'bmp'))) { $this->thumb_link = ' ' . $words->__get('thumbnail of') . ' ' . $filename . ''; $this->thumb_link .= ' ' . $words->__get('view') . ' ' . $words->__get('file') . ''; } if (in_array(self::ext($filename), array('svg', 'SVG'))) { $svgcontent = false; $svgcontent = file_get_contents(Url::translate_uri($this->parent_dir . $filename)); $width = $height = '32'; // $contentsvg = explode(' $content = explode('=', $contentsvg[1]); //[0] => xmlns [1] => "http://www.w3.org/2000/svg" width [2] => "32" height [3] => "32" viewBox [4] => "0 0 32 32"> if(preg_match('/]*width=\"(.*)\"\/>/isU', '")) { //die("you're on ".$phpversion." or bellow".phpversion().' &'.print_R($version_compare, true)); $svgcontent = ($width > '400') ? str_replace($width, $width / 1.1, $svgcontent) : $svgcontent; $svgcontent = ($width < '24') ? str_replace($width, $width * 1.5 * 2, $svgcontent) : $svgcontent; } else { //die("you're on ".$phpversion." or above: ".phpversion().' &'.print_R($version_compare, true)); $svgcontent = ($width > '400') ? str_replace($width, '200', $svgcontent) : $svgcontent; $svgcontent = ($width < '24') ? str_replace($width, '24', $svgcontent) : $svgcontent; } $svgcontent = ('edit.svg' === basename($filename)) ? str_replace($width, '200', $svgcontent) : $svgcontent; if(preg_match_all('/]*height=\"(.*)\"\/>/isU', '")) { //die("you're on ".$phpversion." or bellow".phpversion().' &'.print_R($version_compare, true)); $svgcontent = ($width > '400') ? str_replace($width, $width / 1.1, $svgcontent) : $svgcontent; $svgcontent = ($width < '24') ? str_replace($width, $width * 1.5 * 2, $svgcontent) : $svgcontent; } else { //die("you're on ".$phpversion." or above: ".phpversion().' &'.print_R($version_compare, true)); $svgcontent = ($width > '400') ? str_replace($width, '200', $svgcontent) : $svgcontent; $svgcontent = ($width < '24') ? str_replace($width, '24', $svgcontent) : $svgcontent; } $svgcontent = ('' === basename($filename)) ? str_replace($height, '200', $svgcontent) : $svgcontent; if(preg_match_all('/]*viewBox=\"(.*)\"\/>/isU', 'thumb_link = ''.$svgcontent.''; } if (THUMBNAIL_HEIGHT && in_array(self::ext($filename), array('thm', 'thm'))) { $this->thumb_link = ' ' . $words->__get('thumbnail of') . ' ' . $filename . ''; $this->thumb_link .= ' ' . $words->__get('view') . ' ' . $words->__get('file') . ''; } if (THUMBNAIL_HEIGHT && in_array(self::ext($filename), array('avi', 'divx', 'xvid', 'mkv', 'asf', 'mov', 'wmv', '3gp', 'mp3', 'mp4', 'mpv', 'ogg', 'ogv','mpg', 'mpeg', 'flv', 'FLV', 'flvjs'))) { $mime = new MimeType($filename); $finfo = finfo_open(FILEINFO_MIME_TYPE); //Display correct headers for media file $mimetype = finfo_file($finfo, $this->parent_dir . $filename); $file_size = function_exists('getvideosize') ? getvideosize($this->parent_dir . $filename) : array(); $file_mime = function_exists('getvideosize') ? $file_size['mime'] : $mime->__toString(); $this->thumb_link = ''; if (function_exists('imagecreatefromavi') && in_array(self::ext($filename), array('avi', 'divx', 'xvid'))) { $this->thumb_link .= ' '; $this->thumb_link .= '
' . $words->__get('thumbnail of') . ' ' . $filename . ''; } elseif (in_array(self::ext($filename), array('avi', 'divx', 'xvid', 'mkv', 'asf', 'mov', 'wmv', '3gp', 'mp4', 'mpv', 'ogv', 'mpg', 'mpeg'))) { $video_href = Url::html_output($request->server('PHP_SELF')) . '?thm='. Url::translate_uri($this->parent_dir . $filename); $thumbnail = Url::html_output($request->server('PHP_SELF')) . '?thumbnail='. Url::translate_uri($this->parent_dir . $filename); $this->thumb_link .= ' '; // if (in_array(self::ext($filename), array('avi', 'divx', 'mp4', 'mpg'))) { $this->thumb_link .=' '; //} $this->thumb_link .= '
' . $words->__get('thumbnail of') . ' ' . $filename . ''; $this->thumb_link .= ' ' . $words->__get('view') . ' ' . $words->__get('file') . ''; } elseif (in_array(self::ext($filename), array('flv', 'FLV', 'flvjs'))) { $video_href = Url::html_output($request->server('PHP_SELF')) . '?thm='. Url::translate_uri($this->parent_dir . $filename); $thumbnail = Url::html_output($request->server('PHP_SELF')) . '?thumbnail='. Url::translate_uri($this->parent_dir . $filename); $this->thumb_link .= ''; $this->thumb_link .=''; $this->thumb_link .= ' ' . $words->__get('view') . ' ' . $words->__get('file') . ''; } elseif (in_array(self::ext($filename), array('MP3', 'mp3', 'ogg'))) { // $this->thumb_link .= ' '; // } else { $this->thumb_link .= ' '; $this->thumb_link .= ' ' . $words->__get('view') . ' ' . $words->__get('file') . ''; } } $size = $this->size->__get('bytes'); /* */ if (($size < 1048576000) && in_array(self::ext($filename), array('pdf', 'PDF'))) { $icon_pdf = ICON_PATH ? Url::translate_uri($config->__get('icon_path') . 'pdf.png') : Url::translate_uri($this->parent_dir . $filename); $heightwidth = in_array(self::ext($filename), array('pdf', 'PDF')) ? ' height="' . '150' . '" width="' . '150' . '" ' : ' '; $this->thumb_link .= ' ' . $words->__get('thumbnail of') . ' ' . $filename . ''; $date = array(); $stringedPDF = $contentpdf = $creationdate = $str_time = $creation_time = $time = false; $pfdcontent = file_get_contents(Url::html_output($this->parent_dir . $filename)); if (preg_match('/CreationDate\\s*\\(D:([0-9]{14})/', $pfdcontent, $date)) { $creation_time = $date[1]; //echo(' date: ' . $creation_time); //date format: YYYYMMDDHHMMSS 2025 03 30 - 09 44 53 $split = date_parse_from_format('Ymdhis', $creation_time); //echo(date ("F d Y H:i:s.", filemtime(Url::translate_uri($this->parent_dir . $filename)))); //echo(' ' . $split['year'] .' '. $split['month'] .' '. $split['day'] .' '. $split['hour'] .' '. $split['minute'] .' '. $split['second']); $str_time = $split['year']."-".$split['month']."-".$split['day']." ".$split['hour'].":".$split['minute'].":".$split['second']; $time = strtotime($split['year']."-".$split['month']."-".$split['day']." ".$split['hour'].":".$split['minute'].":".$split['second']); if ($request->is_request('restorecdate', TYPE_NO_TAGS) && touch(Url::translate_uri($this->parent_dir . $filename), $time)) { $creationdate = date("Y-m-d H:i:s", filemtime(Url::translate_uri($this->parent_dir . $filename))); } else { $creationdate = date("Y-m-d H:i:s", $time); } } else if (preg_match('/ModDate\\s*\\(D:([0-9]{14})/', $pfdcontent, $date)) { $creation_time = $date[1]; $split = date_parse_from_format('Ymdhis', $creation_time); $str_time = $split['year']."-".$split['month']."-".$split['day']." ".$split['hour'].":".$split['minute'].":".$split['second']; $time = strtotime($split['year']."-".$split['month']."-".$split['day']." ".$split['hour'].":".$split['minute'].":".$split['second']); if ($request->is_request('restorecdate', TYPE_NO_TAGS) && touch(Url::translate_uri($this->parent_dir . $filename), $time)) { $creationdate = date("Y-m-d H:i:s", filemtime(Url::translate_uri($this->parent_dir . $filename))); } else { $creationdate = date("Y-m-d H:i:s", $time); } //echo(' creation date: '.$creationdate); } else if (preg_match('/M\\s*\\(D:([0-9]{14})/', $pfdcontent, $date)) { $creation_time = $date[1]; $split = date_parse_from_format('Ymdhis', $creation_time); $str_time = $split['year']."-".$split['month']."-".$split['day']." ".$split['hour'].":".$split['minute'].":".$split['second']; $time = strtotime($split['year']."-".$split['month']."-".$split['day']." ".$split['hour'].":".$split['minute'].":".$split['second']); if ($request->is_request('restorecdate', TYPE_NO_TAGS) && touch(Url::translate_uri($this->parent_dir . $filename), $time)) { $creationdate = date("Y-m-d H:i:s", filemtime(Url::translate_uri($this->parent_dir . $filename))); } else { $creationdate = date("Y-m-d H:i:s", $time); } //echo(' creation date: '.$creationdate); } } /* */ if (MD5_SHOW && $size > 0 && $size / 1048576 <= $config->__get('md5_show')) { $this->md5_link = '[' . $words->__get('calculate md5sum') . ']'; } } /** * @param string $var The key to look for * @return mixed The data stored at the key */ public function __get($var = '') { if (isset($this->$var)) { return $this->$var; } throw new ExceptionDisplay('Variable ' . Url::html_output($var) . ' not set in FileItem class.'); } } ?>