From 788f4f047cf597b4829423e61dc031447bf36a7e Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Tue, 12 May 2015 01:00:45 +0200 Subject: [PATCH] Clean PHP code. --- .../server/php/inc/core/class-fallback.php | 2 +- src/_h5ai/server/php/inc/core/class-item.php | 14 +++++----- src/_h5ai/server/php/inc/core/class-theme.php | 2 +- src/_h5ai/server/php/inc/core/class-util.php | 14 ---------- .../server/php/inc/ext/class-archive.php | 9 ------- src/_h5ai/server/php/inc/ext/class-custom.php | 2 +- src/_h5ai/server/php/inc/ext/class-search.php | 6 ++--- src/_h5ai/server/php/inc/ext/class-thumb.php | 26 +++++++------------ src/_h5ai/server/php/index.php | 2 +- 9 files changed, 22 insertions(+), 55 deletions(-) diff --git a/src/_h5ai/server/php/inc/core/class-fallback.php b/src/_h5ai/server/php/inc/core/class-fallback.php index d8e93ddb..86f5e42b 100644 --- a/src/_h5ai/server/php/inc/core/class-fallback.php +++ b/src/_h5ai/server/php/inc/core/class-fallback.php @@ -5,7 +5,7 @@ class Fallback { private $setup; private $app; - function __construct($app) { + public function __construct($app) { $this->setup = $app->get_setup(); $this->app = $app; diff --git a/src/_h5ai/server/php/inc/core/class-item.php b/src/_h5ai/server/php/inc/core/class-item.php index 25eca2f8..8aecf705 100644 --- a/src/_h5ai/server/php/inc/core/class-item.php +++ b/src/_h5ai/server/php/inc/core/class-item.php @@ -14,7 +14,6 @@ class Item { return strcasecmp($item1->path, $item2->path); } - public static function get($app, $path, &$cache) { if (!Util::starts_with($path, $app->get_setup()->get('ROOT_PATH'))) { @@ -33,11 +32,13 @@ class Item { return $item; } - public $app; - public $path, $href, $date, $size; - public $is_folder, $is_content_fetched; - + public $path; + public $href; + public $date; + public $size; + public $is_folder; + public $is_content_fetched; private function __construct($app, $path) { @@ -51,7 +52,6 @@ class Item { $this->is_content_fetched = false; } - public function to_json_object() { $obj = [ @@ -68,7 +68,6 @@ class Item { return $obj; } - public function get_parent(&$cache) { $parent_path = Util::normalize_path(dirname($this->path), false); @@ -78,7 +77,6 @@ class Item { return null; } - public function get_content(&$cache) { $items = []; diff --git a/src/_h5ai/server/php/inc/core/class-theme.php b/src/_h5ai/server/php/inc/core/class-theme.php index a1a766a0..a453c3ca 100644 --- a/src/_h5ai/server/php/inc/core/class-theme.php +++ b/src/_h5ai/server/php/inc/core/class-theme.php @@ -4,7 +4,7 @@ class Theme { private static $extensions = ['svg', 'png', 'jpg']; - function __construct($app) { + public function __construct($app) { $this->app = $app; } diff --git a/src/_h5ai/server/php/inc/core/class-util.php b/src/_h5ai/server/php/inc/core/class-util.php index 11620a3a..f237c183 100644 --- a/src/_h5ai/server/php/inc/core/class-util.php +++ b/src/_h5ai/server/php/inc/core/class-util.php @@ -2,7 +2,6 @@ class Util { - const ERR_MISSING_PARAM = 'ERR_MISSING_PARAM'; const ERR_ILLIGAL_PARAM = 'ERR_ILLIGAL_PARAM'; const ERR_FAILED = 'ERR_FAILED'; @@ -11,14 +10,12 @@ class Util { const NO_DEFAULT = 'NO_*@+#?!_DEFAULT'; const RE_DELIMITER = '@'; - public static function normalize_path($path, $trailing_slash = false) { $path = preg_replace('#[\\\\/]+#', '/', $path); return preg_match('#^(\w:)?/$#', $path) ? $path : (rtrim($path, '/') . ($trailing_slash ? '/' : '')); } - public static function json_exit($obj = []) { header('Content-type: application/json;charset=utf-8'); @@ -26,7 +23,6 @@ class Util { exit; } - public static function json_fail($err, $msg = '', $cond = true) { if ($cond) { @@ -34,7 +30,6 @@ class Util { } } - public static function array_query($array, $keypath = '', $default = Util::NO_DEFAULT) { $value = $array; @@ -50,25 +45,21 @@ class Util { return $value; } - public static function starts_with($sequence, $head) { return substr($sequence, 0, strlen($head)) === $head; } - public static function ends_with($sequence, $tail) { return substr($sequence, -strlen($tail)) === $tail; } - public static function wrap_pattern($pattern) { return Util::RE_DELIMITER . str_replace(Util::RE_DELIMITER, '\\' . Util::RE_DELIMITER, $pattern) . Util::RE_DELIMITER; } - public static function load_commented_json($path) { if (!file_exists($path)) { @@ -83,14 +74,12 @@ class Util { return json_decode($content, true); } - public static function save_json($path, $obj) { $json = json_encode($obj); return file_put_contents($path, $json) !== false; } - public static function passthru_cmd($cmd) { $rc = null; @@ -98,7 +87,6 @@ class Util { return $rc; } - public static function exec_cmdv($cmdv) { if (!is_array($cmdv)) { @@ -112,7 +100,6 @@ class Util { return implode("\n", $lines); } - public static function exec_0($cmd) { $lines = []; @@ -124,7 +111,6 @@ class Util { return false; } - private static $size_cache = []; public static function filesize($app, $path) { diff --git a/src/_h5ai/server/php/inc/ext/class-archive.php b/src/_h5ai/server/php/inc/ext/class-archive.php index 1a98b6fb..7e2b9f02 100644 --- a/src/_h5ai/server/php/inc/ext/class-archive.php +++ b/src/_h5ai/server/php/inc/ext/class-archive.php @@ -8,13 +8,11 @@ class Archive { private $app, $base_path, $dirs, $files; - public function __construct($app) { $this->app = $app; } - public function output($type, $base_href, $hrefs) { $this->base_path = $this->app->to_path($base_href); @@ -50,7 +48,6 @@ class Archive { return false; } - private function shell_cmd($cmd) { $cmd = str_replace('[ROOTDIR]', escapeshellarg($this->base_path), $cmd); @@ -64,7 +61,6 @@ class Archive { return true; } - private function php_tar($dirs, $files) { $filesizes = []; @@ -101,7 +97,6 @@ class Archive { return true; } - private function php_tar_header($filename, $size, $mtime, $type) { $name = substr(basename($filename), -99); @@ -135,7 +130,6 @@ class Archive { return $header; } - private function print_file($file) { // Send file content in segments to not hit PHP's memory limit (default: 128M) @@ -149,7 +143,6 @@ class Archive { } } - private function add_hrefs($hrefs) { foreach ($hrefs as $href) { @@ -175,7 +168,6 @@ class Archive { } } - private function add_file($real_file, $archived_file) { if (is_readable($real_file)) { @@ -183,7 +175,6 @@ class Archive { } } - private function add_dir($real_dir, $archived_dir) { if ($this->app->is_managed_path($real_dir)) { diff --git a/src/_h5ai/server/php/inc/ext/class-custom.php b/src/_h5ai/server/php/inc/ext/class-custom.php index 55f64235..679968c2 100644 --- a/src/_h5ai/server/php/inc/ext/class-custom.php +++ b/src/_h5ai/server/php/inc/ext/class-custom.php @@ -4,7 +4,7 @@ class Custom { private static $extensions = ['html', 'md']; - function __construct($app) { + public function __construct($app) { $this->app = $app; } diff --git a/src/_h5ai/server/php/inc/ext/class-search.php b/src/_h5ai/server/php/inc/ext/class-search.php index 597f356d..46e80045 100644 --- a/src/_h5ai/server/php/inc/ext/class-search.php +++ b/src/_h5ai/server/php/inc/ext/class-search.php @@ -2,12 +2,12 @@ class Search { - function __construct($app) { + public function __construct($app) { $this->app = $app; } - function get_paths($root, $pattern = null) { + public function get_paths($root, $pattern = null) { $paths = []; if ($pattern && $this->app->is_managed_path($root)) { @@ -26,7 +26,7 @@ class Search { return $paths; } - function get_items($href, $pattern = null) { + public function get_items($href, $pattern = null) { $cache = []; $root = $this->app->to_path($href); diff --git a/src/_h5ai/server/php/inc/ext/class-thumb.php b/src/_h5ai/server/php/inc/ext/class-thumb.php index bf5235c1..a9f5a37a 100644 --- a/src/_h5ai/server/php/inc/ext/class-thumb.php +++ b/src/_h5ai/server/php/inc/ext/class-thumb.php @@ -7,9 +7,9 @@ class Thumb { private static $CONVERT_CMDV = ['convert', '-density', '200', '-quality', '100', '-sharpen', '0x1.0', '-strip', '[SRC][0]', '[DEST]']; private static $THUMB_CACHE = 'thumbs'; - - private $app, $thumbs_path, $thumbs_href; - + private $app; + private $thumbs_path; + private $thumbs_href; public function __construct($app) { @@ -23,7 +23,6 @@ class Thumb { } } - public function thumb($type, $source_href, $width, $height) { $source_path = $this->app->to_path($source_href); @@ -47,7 +46,6 @@ class Thumb { return $this->thumb_href($capture_path, $width, $height); } - private function thumb_href($source_path, $width, $height) { if (!file_exists($source_path)) { @@ -81,7 +79,6 @@ class Thumb { return file_exists($thumb_path) ? $thumb_href : null; } - private function capture($cmdv, $source_path) { if (!file_exists($source_path)) { @@ -104,11 +101,14 @@ class Thumb { } } - class Image { - private $source_file, $source, $width, $height, $type, $dest; - + private $source_file; + private $source; + private $width; + private $height; + private $type; + private $dest; public function __construct($filename = null) { @@ -123,14 +123,12 @@ class Image { $this->set_source($filename); } - public function __destruct() { $this->release_source(); $this->release_dest(); } - public function set_source($filename) { $this->release_source(); @@ -155,7 +153,6 @@ class Image { $this->source = imagecreatefromstring(file_get_contents($this->source_file)); } - public function save_dest_jpeg($filename, $quality = 80) { if (!is_null($this->dest)) { @@ -164,7 +161,6 @@ class Image { } } - public function release_dest() { if (!is_null($this->dest)) { @@ -173,7 +169,6 @@ class Image { } } - public function release_source() { if (!is_null($this->source)) { @@ -186,7 +181,6 @@ class Image { } } - public function thumb($width, $height) { if (is_null($this->source)) { @@ -232,7 +226,6 @@ class Image { imagecopyresampled($this->dest, $this->source, 0, 0, $src_x, 0, $width, $height, $src_w, $src_h); } - public function rotate($angle) { if (is_null($this->source) || ($angle !== 90 && $angle !== 180 && $angle !== 270)) { @@ -245,7 +238,6 @@ class Image { } } - public function normalize_exif_orientation($exif_source_file = null) { if (is_null($this->source) || !function_exists('exif_read_data')) { diff --git a/src/_h5ai/server/php/index.php b/src/_h5ai/server/php/index.php index 01d4a1e6..5cdb9013 100644 --- a/src/_h5ai/server/php/index.php +++ b/src/_h5ai/server/php/index.php @@ -2,7 +2,7 @@ define('MIN_PHP_VERSION', '5.4.0'); -if (version_compare(PHP_VERSION, MIN_PHP_VERSION) < 0) { +if (version_compare(PHP_VERSION, MIN_PHP_VERSION, '<')) { header('Content-type: application/json;charset=utf-8'); echo '{"err":"ERR_PHP","msg":"PHP ' . MIN_PHP_VERSION . '+ required","ver":"' . PHP_VERSION . '"}'; exit;