%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /www/varak.net/video.varak.net/app/
Upload File :
Create Path :
Current File : /www/varak.net/video.varak.net/app/ItemsRenderer.php

<?php
/**
 * Created by PhpStorm.
 * User: Turbo
 * Date: 14.12.2015
 * Time: 15:44
 */

namespace Menu;

use App\BaseRenderer;
use Utils\Strings;

class ItemsRenderer extends BaseRenderer
{
	public $dirs = [];
	public $files = [];

	public $iterator = 1;
	private $sub = "";

	/** @var resource|null  */
	public $openDirectory = NULL;

	/***/
	public function __construct($path = NULL, $subDir = NULL)
	{
		parent::__construct($path, $subDir);
		$this->loadItems();
		$this->sub = $subDir;
	}

	public function render()
    {
        echo '<ol class="breadcrumb">';
            $this->renderNav();
        echo '</ol>';

        echo '<div class="row">';
            $this->renderDirs();
            $this->renderFiles();
        echo '</div>';
        $this->clean();
    }

	public function renderNav()
	{
		$dirs = explode('/', $this->subDir);
		$title = $name = 'Home';
		if (count($dirs) <= 1)	{
			$active = TRUE;
		}
		include ('templates/navItem.php');
		foreach ($dirs as $key => $dir)
		{
			$active = FALSE;
			if ($dir != "") {
				$prePath = "";
				$i = 0;
				while ($i < $key)
				{
					$prePath.= "$dirs[$i]"."/";
					$i++;
				}
				$menuItem = $this->basePath.$prePath.$dir;
				if (is_dir($menuItem))
				{
					$name = Strings::truncate($dir, 30);
					$title = $dir;
					$link = urlencode($prePath.$dir);
					if ($key == count($dirs) - 1){
						$active = TRUE;
					}
					include ('templates/navItem.php');
				}
			}
		}

		echo "<li style=\"float: right;\"><a href=\"playlist.php?dir=" . urlencode($this->sub) . "\">Playlist</a></li>";
	}



	public function renderDirs($dirs = NULL)
	{
		if ($dirs === NULL) {
			$dirs = $this->dirs;
		}
		if ($dirs) {
			sort($dirs);
			foreach ($dirs as $dir) {
				$stat = scandir("$this->path/$dir");
				$stat = $stat ? count($stat)-2 : 0;
				include('templates/itemDir.php');
				$this->iterator++;
			}
		}
	}

	public function renderFiles($files = NULL)
	{
		if ($files === NULL) {
			$files = $this->files;
		}
		if ($files) {
			sort($files);
			foreach ($files as $file) {
				if (strtoupper(pathinfo("$this->path/$file", PATHINFO_EXTENSION)) == "WEBM" || strtoupper(pathinfo("$this->path/$file",
						PATHINFO_EXTENSION)) == "MP4" || strtoupper(pathinfo("$this->path/$file",
                        PATHINFO_EXTENSION)) == "MOV"
				) {
					$stat = stat("$this->path/$file");
					include('templates/itemFile.php');
					$this->iterator++;
				}
			}
		}
	}
	
	public function getFiles($files = NULL)
	{
		if ($files === NULL) 
		{
                        $files = $this->files;
                }
                if ($files) 
		{
			sort($files);
			$retVal = array();
                        foreach ($files as $file) {
                                if (strtoupper(pathinfo("$this->path/$file", PATHINFO_EXTENSION)) == "WEBM" || strtoupper(pathinfo("$this->path/$file",
                                                PATHINFO_EXTENSION)) == "MP4" || strtoupper(pathinfo("$this->path/$file",
                        PATHINFO_EXTENSION)) == "MOV"
                                ) {
					$retVal[] = $file;
                                }
                        }
			return $retVal;
		}
	}

	public function clean()
	{
		if ($this->openDirectory) {
			closedir($this->openDirectory);
		}
	}

	protected function loadItems()
	{
		$this->openDirectory = opendir($this->path);
		$addr = "https://video.varak.net/player.php?file=";
		while (($file = readdir($this->openDirectory)) !== FALSE) {
			if ($file != "." && $file != "..") {
				if (!is_dir($this->path . "/" . $file)) {
					/*$stat = stat("$path/$file");
					$size = fsize($stat['size']);
					$date = date("Y-m-d H:i:s", $stat['mtime']);
					//echo "$i. <a href=\"http://expert.isibrno.cz:56/waritko/down/$sub/$file\">$file</a> &nbsp;&nbsp;($size) <br />";
					echo "<tr><td>$i</td><td><a href=\"$sub/$file\">$file</a><!-- INODE: ".$stat['ino']." --></td><td>$size</td><td>$date</td></tr>\n";*/
					$this->files[] = $file;
				} else {
					//echo "$i. <a href='?dir=$sub/$file'>$file</a><br />";
					$this->dirs[] = $file;
				}
				//$i++;
			}
		}
	}

	protected function fileSize($size)
	{
		$jedn = array("bytes", "Kbytes", "Mbytes", "Gbytes", "Tbytes", "Pbytes");
		//$size = filesize($name);
		$i = 0;
		while ($size > 1023) {
			$size /= 1024;
			$i++;
		}

		return sprintf("%0.2f %s", $size, $jedn[$i]);
	}
}

Zerion Mini Shell 1.0