Refactor PHP. Switch to explicit string literals where possible.

This commit is contained in:
Lars Jung 2015-05-11 12:14:25 +02:00
parent c18b09c658
commit 429a2b7749
2 changed files with 40 additions and 40 deletions

View file

@ -8,46 +8,46 @@ class Bootstrap {
public function __construct($basepath) {
$this->basepath = $basepath;
$this->classpaths = ["/inc", "/inc/core", "/inc/ext"];
$this->classpaths = ['/inc', '/inc/core', '/inc/ext'];
}
public function run() {
spl_autoload_register([$this, "autoload"]);
putenv("LANG=en_US.UTF-8");
setlocale(LC_CTYPE, "en_US.UTF-8");
spl_autoload_register([$this, 'autoload']);
putenv('LANG=en_US.UTF-8');
setlocale(LC_CTYPE, 'en_US.UTF-8');
date_default_timezone_set(@date_default_timezone_get());
session_start();
$request_method = getenv("REQUEST_METHOD");
$request_uri = getenv("REQUEST_URI");
$script_name = getenv("SCRIPT_NAME");
$server_software = getenv("SERVER_SOFTWARE");
$request_method = getenv('REQUEST_METHOD');
$request_uri = getenv('REQUEST_URI');
$script_name = getenv('SCRIPT_NAME');
$server_software = getenv('SERVER_SOFTWARE');
$this->once("config");
$this->once('config');
$request = new Request($_REQUEST);
$setup = new Setup($request->query_boolean("updateCachedSetup", false), $_ENV);
$setup = new Setup($request->query_boolean('updateCachedSetup', false), $_ENV);
$app = new App($request, $setup);
if (strtolower(getenv("REQUEST_METHOD")) === "post") {
if (strtolower(getenv('REQUEST_METHOD')) === 'post') {
(new Api($app))->apply();
} else {
// (new Page($app))->apply();
// define("PAGE_APP_HREF", $setup->get("APP_HREF"));
// define("PAGE_FALLBACK", (new Fallback($app))->get_html());
define("APP_HREF", $setup->get("APP_HREF"));
define("FALLBACK", (new Fallback($app))->get_html());
$this->once("inc/page");
// define('PAGE_APP_HREF', $setup->get('APP_HREF'));
// define('PAGE_FALLBACK', (new Fallback($app))->get_html());
define('APP_HREF', $setup->get('APP_HREF'));
define('FALLBACK', (new Fallback($app))->get_html());
$this->once('inc/page');
}
}
public function autoload($class_name) {
$filename = "class-" . strtolower($class_name) . ".php";
$filename = 'class-' . strtolower($class_name) . '.php';
foreach ($this->classpaths as $classpath) {
$file = $this->basepath . $classpath . "/" . $filename;
$file = $this->basepath . $classpath . '/' . $filename;
if (file_exists($file)) {
require_once($file);
return true;
@ -57,6 +57,6 @@ class Bootstrap {
private function once($lib) {
require_once($this->basepath . "/" . $lib . ".php");
require_once($this->basepath . '/' . $lib . '.php');
}
}

View file

@ -2,10 +2,10 @@
class Thumb {
private static $FFMPEG_CMDV = ["ffmpeg", "-ss", "0:00:10", "-i", "[SRC]", "-an", "-vframes", "1", "[DEST]"];
private static $AVCONV_CMDV = ["avconv", "-ss", "0:00:10", "-i", "[SRC]", "-an", "-vframes", "1", "[DEST]"];
private static $CONVERT_CMDV = ["convert", "-density", "200", "-quality", "100", "-sharpen", "0x1.0", "-strip", "[SRC][0]", "[DEST]"];
private static $THUMB_CACHE = "thumbs";
private static $FFMPEG_CMDV = ['ffmpeg', '-ss', '0:00:10', '-i', '[SRC]', '-an', '-vframes', '1', '[DEST]'];
private static $AVCONV_CMDV = ['avconv', '-ss', '0:00:10', '-i', '[SRC]', '-an', '-vframes', '1', '[DEST]'];
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;
@ -15,8 +15,8 @@ class Thumb {
$this->setup = $app->get_setup();
$this->app = $app;
$this->thumbs_path = $this->setup->get("CACHE_PATH") . "/" . Thumb::$THUMB_CACHE;
$this->thumbs_href = $this->setup->get("CACHE_HREF") . Thumb::$THUMB_CACHE;
$this->thumbs_path = $this->setup->get('CACHE_PATH') . '/' . Thumb::$THUMB_CACHE;
$this->thumbs_href = $this->setup->get('CACHE_HREF') . Thumb::$THUMB_CACHE;
if (!is_dir($this->thumbs_path)) {
@mkdir($this->thumbs_path, 0755, true);
@ -27,20 +27,20 @@ class Thumb {
public function thumb($type, $source_href, $width, $height) {
$source_path = $this->app->to_path($source_href);
if (!file_exists($source_path) || Util::starts_with($source_path, $this->setup->get("CACHE_PATH"))) {
if (!file_exists($source_path) || Util::starts_with($source_path, $this->setup->get('CACHE_PATH'))) {
return null;
}
$capture_path = $source_path;
if ($type === "img") {
if ($type === 'img') {
$capture_path = $source_path;
} else if ($type === "mov") {
if ($this->setup->get("HAS_CMD_AVCONV")) {
} else if ($type === 'mov') {
if ($this->setup->get('HAS_CMD_AVCONV')) {
$capture_path = $this->capture(Thumb::$AVCONV_CMDV, $source_path);
} else if ($this->setup->get("HAS_CMD_FFMPEG")) {
} else if ($this->setup->get('HAS_CMD_FFMPEG')) {
$capture_path = $this->capture(Thumb::$FFMPEG_CMDV, $source_path);
}
} else if ($type === "doc" && $this->setup->get("HAS_CMD_CONVERT")) {
} else if ($type === 'doc' && $this->setup->get('HAS_CMD_CONVERT')) {
$capture_path = $this->capture(Thumb::$CONVERT_CMDV, $source_path);
}
@ -54,16 +54,16 @@ class Thumb {
return null;
}
$name = "thumb-" . sha1("$source_path") . "-" . $width . "x" . $height . ".jpg";
$thumb_path = $this->thumbs_path . "/" . $name;
$thumb_href = $this->thumbs_href . "/" . $name;
$name = 'thumb-' . sha1($source_path) . '-' . $width . 'x' . $height . '.jpg';
$thumb_path = $this->thumbs_path . '/' . $name;
$thumb_href = $this->thumbs_href . '/' . $name;
if (!file_exists($thumb_path) || filemtime($source_path) >= filemtime($thumb_path)) {
$image = new Image();
$et = false;
if ($this->setup->get("HAS_PHP_EXIF") && $this->app->query_option("thumbnails.exif", false) === true && $height != 0) {
if ($this->setup->get('HAS_PHP_EXIF') && $this->app->query_option('thumbnails.exif', false) === true && $height != 0) {
$et = @exif_thumbnail($source_path);
}
if($et !== false) {
@ -88,13 +88,13 @@ class Thumb {
return null;
}
$capture_path = $this->thumbs_path . "/capture-" . sha1($source_path) . ".jpg";
$capture_path = $this->thumbs_path . '/capture-' . sha1($source_path) . '.jpg';
if (!file_exists($capture_path) || filemtime($source_path) >= filemtime($capture_path)) {
foreach ($cmdv as &$arg) {
$arg = str_replace("[SRC]", $source_path, $arg);
$arg = str_replace("[DEST]", $capture_path, $arg);
$arg = str_replace('[SRC]', $source_path, $arg);
$arg = str_replace('[DEST]', $capture_path, $arg);
}
Util::exec_cmdv($cmdv);
@ -248,7 +248,7 @@ class Image {
public function normalize_exif_orientation($exif_source_file = null) {
if (is_null($this->source) || !function_exists("exif_read_data")) {
if (is_null($this->source) || !function_exists('exif_read_data')) {
return;
}
@ -257,7 +257,7 @@ class Image {
}
$exif = exif_read_data($exif_source_file);
switch(@$exif["Orientation"]) {
switch(@$exif['Orientation']) {
case 3:
$this->rotate(180);
break;