diff options
-rw-r--r-- | app/class/Media.php | 47 | ||||
-rw-r--r-- | app/class/Medialist.php | 2 | ||||
-rw-r--r-- | app/fn/fn.php | 29 | ||||
-rw-r--r-- | app/view/templates/media.php | 12 |
4 files changed, 66 insertions, 24 deletions
diff --git a/app/class/Media.php b/app/class/Media.php index f29d2c9..9213c31 100644 --- a/app/class/Media.php +++ b/app/class/Media.php @@ -17,6 +17,8 @@ class Media extends Item Protected $width; Protected $height; Protected $length; + Protected $uid; + Protected $permissions; const IMAGE = array('jpg', 'jpeg', 'gif', 'png'); const SOUND = array('mp3', 'flac', 'wav', 'ogg'); @@ -40,14 +42,20 @@ class Media extends Item $filepath = $this->path . $this->id . '.' . $this->extension; - $this->size = filesize($filepath); - if ($this->type == 'image') { list($width, $height, $type, $attr) = getimagesize($filepath); $this->width = $width; $this->height = $height; } + $stat = stat($filepath); + + $permissions = decoct(fileperms($filepath) & 0777); + + $this->setpermissions($permissions); + + $this->hydrate($stat); + } @@ -168,7 +176,7 @@ class Media extends Item public function size($display = 'binary') { if($display == 'hr') { - return readablesize($this->size); + return readablesize($this->size) . 'o'; } else { return $this->size; } @@ -194,6 +202,27 @@ class Media extends Item return $this->length; } + public function surface() + { + $surface = $this->width * $this->height; + return readablesize($surface, 1000) . 'px'; + } + + public function uid($option = 'id') + { + if($option === 'name') { + $userinfo = posix_getpwuid($this->uid); + return $userinfo['name']; + } else { + return $this->uid; + } + } + + public function permissions() + { + return $this->permissions; + } + // ___________________________________________________ S E T __________________________________________________ public function setid($id) @@ -228,8 +257,8 @@ class Media extends Item public function setsize($size) { - if (40 and is_int($size)) { - $this->size = strip_tags(strtolower($size)); + if (is_int($size)) { + $this->size = $size; } } @@ -260,7 +289,15 @@ class Media extends Item } } + public function setuid($uid) + { + $this->uid = $uid; + } + public function setpermissions($permissions) + { + $this->permissions = $permissions; + } diff --git a/app/class/Medialist.php b/app/class/Medialist.php index ca42f4b..3395b58 100644 --- a/app/class/Medialist.php +++ b/app/class/Medialist.php @@ -74,7 +74,7 @@ class Medialist extends Item $div .= '<audio id="' . $media->id() . '" controls src="' . $media->getincludepath() . '" </audio>'; } elseif ($media->type() == 'video') { $div .= '<video controls><source src="' . $media->getincludepath() . '" type="video/' . $media->extension() . '"></video>'; - } elseif ($media->type() == 'other') { + } else { $div .= '<a href="' . $media->getincludepath() . '" target="_blank" class="media" >' . $media->id() . '.' . $media->extension() . '</a>'; } $div .= '</div>' . PHP_EOL; diff --git a/app/fn/fn.php b/app/fn/fn.php index 60e4722..3ca31c9 100644 --- a/app/fn/fn.php +++ b/app/fn/fn.php @@ -4,24 +4,29 @@ use Wcms\Medialist; use function Clue\StreamFilter\fun; -function readablesize($bytes) +function readablesize($bytes, $base = 2 ** 10) { $format = ' %d %s'; + if ($base === 2 ** 10) { + $i = 'i'; + } else { + $i = ''; + } + $unit = ''; - if ($bytes < 2 ** 10) { + if ($bytes < $base) { $num = $bytes; - $unit = 'o'; - } elseif ($bytes < 2 ** 20) { - $num = round($bytes / 2 ** 10, 1); - $unit = 'Kio'; - } elseif ($bytes < 2 ** 30) { - $num = round($bytes / 2 ** 20, 1); - $unit = 'Mio'; - } elseif ($bytes < 2 ** 40) { - $num = round($bytes / 2 ** 30, 1); - $unit = 'Gio'; + } elseif ($bytes < $base ** 2) { + $num = round($bytes / $base, 1); + $unit = 'K' . $i; + } elseif ($bytes < $base ** 3) { + $num = round($bytes / $base ** 2, 1); + $unit = 'M' . $i; + } elseif ($bytes < $base ** 4) { + $num = round($bytes / $base ** 3, 1); + $unit = 'G' . $i; } return sprintf($format, $num, $unit); diff --git a/app/view/templates/media.php b/app/view/templates/media.php index 50fc0d6..9f56116 100644 --- a/app/view/templates/media.php +++ b/app/view/templates/media.php @@ -80,9 +80,9 @@ $this->layout('layout', ['title' => 'media', 'stylesheets' => [$css . 'home.css' <th><a href="<?= $mediaopt->getsortbyadress('type') ?>">type</a></th> <th><a href="<?= $mediaopt->getsortbyadress('size') ?>">size</a></th> <th><a href="<?= $mediaopt->getsortbyadress('date') ?>">date</a></th> - <th>width</th> - <th>height</th> - <th>lengh</th> + <th>user</th> + <th>perms</th> + <th>surface</th> <th>code</th> </tr> @@ -96,9 +96,9 @@ $this->layout('layout', ['title' => 'media', 'stylesheets' => [$css . 'home.css' <td class="nowrap"><a href="<?= $media->getfullpath() ?>" target="_blank"><?= $media->type() == 'image' ? '<span class="thumbnail">' . $media->getsymbol() . '<img src="' . $media->getfullpath() . '"></span>' : $media->getsymbol() ?></a></td> <td class="nowrap"><?= $media->size('hr') ?></td> <td class="nowrap" title="<?= $media->date('dmy') ?> <?= $media->date('ptime') ?>"><?= $media->date('hrdi') ?></td> - <td><?= $media->width() ?></td> - <td><?= $media->height() ?></td> - <td><?= $media->length() ?></td> + <td><?= $media->uid('name') ?></td> + <td><code><?= $media->permissions() ?></code></td> + <td><?= $media->surface() ?></td> <td class="code"><code><?= $media->getcode() ?></code></td> </tr> <?php |