Clean PHP code.

This commit is contained in:
Lars Jung 2015-05-12 01:00:45 +02:00
parent 34f86997cb
commit 788f4f047c
9 changed files with 22 additions and 55 deletions

View file

@ -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;

View file

@ -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 = [];

View file

@ -4,7 +4,7 @@ class Theme {
private static $extensions = ['svg', 'png', 'jpg'];
function __construct($app) {
public function __construct($app) {
$this->app = $app;
}

View file

@ -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) {

View file

@ -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)) {

View file

@ -4,7 +4,7 @@ class Custom {
private static $extensions = ['html', 'md'];
function __construct($app) {
public function __construct($app) {
$this->app = $app;
}

View file

@ -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);

View file

@ -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')) {

View file

@ -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;