* @version 1.0.1 (July 09, 2004) * @package AutoIndex */ class TemplateFiles extends TemplateInfo { /** * @var Item The file or folder we're currently processing */ private $temp_item; /** * @var bool Is the current user an admin */ private $is_admin; /** * @var bool Is the current user a moderator */ private $is_mod; /** * @var int The number of the file we're currently processing */ private $i; /** * @var int The total number of files to process */ private $length; /** * @param array $m The array given by preg_replace_callback() * @return string Property is gotten from temp_item */ private function callback_file($m) { global $words, $subdir; switch (strtolower($m[1])) { case 'tr_class': { return (($this -> i % 2) ? 'dark_row' : 'light_row'); } case 'filename': { return Url::html_output($this -> temp_item -> __get('filename')); } case 'file_ext': { return $this -> temp_item -> file_ext(); } case 'size': { return $this -> temp_item -> __get('size') -> formatted(); } case 'bytes': { return $this -> temp_item -> __get('size') -> __get('bytes'); } case 'date': case 'time': case 'm_time': { return $this -> temp_item -> format_m_time(); } case 'a_time': { return $this -> temp_item -> format_a_time(); } case 'thumbnail': { return $this -> temp_item -> __get('thumb_link'); } case 'num_subfiles': { return (($this -> temp_item instanceof DirItem && !$this -> temp_item -> __get('is_parent_dir')) ? $this -> temp_item -> num_subfiles() : ''); } case 'delete_link': { return (($this -> is_admin && !$this -> temp_item -> __get('is_parent_dir')) ? ' [' . $words -> __get('delete') . ']' : ''); } case 'rename_link': { return (($this -> is_admin && !$this -> temp_item -> __get('is_parent_dir')) ? ' [' . $words -> __get('rename') . ']' : ''); } case 'edit_description_link': { $slash = (($this -> temp_item instanceof DirItem) ? '/' : ''); return (($this -> is_mod && DESCRIPTION_FILE && !$this -> temp_item -> __get('is_parent_dir')) ? ' [' . $words -> __get('edit description') . ']' : ''); } case 'ftp_upload_link': { if (!$this -> is_mod || !$this -> temp_item instanceof FileItem || !isset($_SESSION['ftp'])) { return ''; } return ' [' . $words->__get('upload to ftp') . ']'; } default: { return $this -> temp_item -> __get($m[1]); } } } /** * Either the HTML text is returned, or an empty string is returned, * depending on if the if-statement passed. * * @param array $m The array given by preg_replace_callback() * @return string The result to insert into the HTML */ private function callback_type($m) { switch (strtolower($m[1])) { case 'is_file': //file { return (($this -> temp_item instanceof FileItem) ? $m[2] : ''); } case 'is_dir': //folder or link to parent directory { return (($this -> temp_item instanceof DirItem) ? $m[2] : ''); } case 'is_real_dir': //folder { return (($this -> temp_item instanceof DirItem && !$this -> temp_item -> __get('is_parent_dir')) ? $m[2] : ''); } case 'is_parent_dir': //link to parent directory { return (($this -> temp_item instanceof DirItem && $this -> temp_item -> __get('is_parent_dir')) ? $m[2] : ''); } default: { throw new ExceptionDisplay('Invalid file:if statement in ' . Url::html_output(EACH_FILE) . ''); } } } /** * Either the HTML text is returned or an empty string is returned, * depending on if temp_item is the ith file parsed. * * @param array $m The array given by preg_replace_callback() * @return string The result to insert into the HTML output */ private function callback_do_every($m) { $num = $this -> i + 1; return (($num % (int)$m[1] === 0 && $this -> length !== $num) ? $m[2] : ''); } /** * Parses info for each file in the directory. Order of elements to * replace is: * - file:if * - do_every * - file * * @param string $filename The name of the file to parse * @param DirectoryListDetailed $list */ public function __construct($filename, DirectoryListDetailed $list) { parent::__construct($filename, $list); global $you; $this -> is_admin = ($you -> level >= ADMIN); $this -> is_mod = ($you -> level >= MODERATOR); $final_file_line = ''; $this -> length = (int)$list -> __get('list_count'); foreach ($list as $i => $item) { $this -> i = (int)$i; $this -> temp_item = $item; $temp_line = preg_replace_callback('/\{\s*file\s*:\s*if\s*:\s*(\w+)\s*\}(.*)\{\s*end\s*if\s*\}/Uis', array($this, 'callback_type'), $this -> out); $temp_line = preg_replace_callback('/\{\s*do_every\s*:\s*(\d+)\s*\}(.*)\{\s*end\s*do_every\s*\}/Uis', array($this, 'callback_do_every'), $temp_line); $final_file_line .= preg_replace_callback('/\{\s*file\s*:\s*(\w+)\s*\}/Ui', array($this, 'callback_file'), $temp_line); } $this -> out = $final_file_line; } } ?>