%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/File.php

<?php
/**
 * Created by PhpStorm.
 * User: Turbo
 * Date: 14.12.2015
 * Time: 18:21
 */

namespace App;

use Utils\Strings;

class File
{
	public $name;

	public $fileLink;

	public $dirPath;

	public $directory;

	public $dirName;

	public $subtitles;

	/** @var File[] */
	protected $siblings = [];

	/***/
	public function __construct($name, $path)
	{
		list($this->name, $this->directory, $this->dirName) = $this->formNameAndDir($name);
		$this->fileLink = $this->directory . '/' . $this->name;
		$this->dirPath = $path . $this->directory;
		if(substr($name, -3) == "mp4")
			$this->subtitles = substr($name, 0, strlen($name) - 4).".srt";
		else
			$this->subtitles = substr($name, 0, strlen($name) - 5).".srt";
	}

	protected function formNameAndDir($file)
	{
		$name = basename($file);
		$directory = dirname($file);
		$dirName = basename($directory);

		return [$name, $directory, $dirName];
	}

	public function loadDirectoryFiles()
	{
		$dir = opendir($this->dirPath);
		$files = [];
		if ($dir) {
			while (($file = readdir($dir)) !== FALSE) {
				if ($file != "." && $file != ".." && !Strings::endsWith($file, '.srt')) {
					if (!is_dir($this->dirPath . "/" . $file)) {
						$files[] = $file;
					}
				}
			}
			if (count($files) > 0) {
				sort($files);
				foreach ($files as $file) {
					$this->siblings[] = new File($this->directory . "/" . $file, $this->dirPath);
				}
			}
			closedir($dir);
		}
	}

	/***/
	public function renderDirectoryFiles()
	{
		$this->loadDirectoryFiles();
		foreach ($this->siblings as $sibling) {
			include('templates/playerSiblings.php');
		}
	}

	public function getSiblings()
	{
		if (count($this->siblings) == 0) {
			$this->loadDirectoryFiles();
		}
		return $this->siblings;
	}
}

Zerion Mini Shell 1.0