Define dirs and files global (#122)

This commit is contained in:
Tobias Reich 2014-04-13 14:08:18 +02:00
parent 4761f178d4
commit d382b62f57
6 changed files with 39 additions and 26 deletions

View File

@ -15,16 +15,18 @@
if (!empty($_POST['function'])||!empty($_GET['function'])) {
session_start();
define('LYCHEE', true);
date_default_timezone_set('UTC');
# Define globals
require(__DIR__ . '/define.php');
# Load autoload
require(__DIR__ . '/autoload.php');
# Load modules
require(__DIR__ . '/modules/misc.php');
if (file_exists(__DIR__ . '/../data/config.php')) require(__DIR__ . '/../data/config.php');
if (file_exists(LYCHEE_CONFIG_FILE)) require(LYCHEE_CONFIG_FILE);
else {
/**

21
php/define.php Normal file
View File

@ -0,0 +1,21 @@
<?php
###
# @name Define
# @author Tobias Reich
# @copyright 2014 by Tobias Reich
###
# Define root
define('LYCHEE', substr(__DIR__, 0, -3));
# Define dirs
define('LYCHEE_DATA', LYCHEE . 'data/');
define('LYCHEE_UPLOADS_BIG', LYCHEE . 'uploads/big/');
define('LYCHEE_UPLOADS_THUMB', LYCHEE . 'uploads/thumb/');
define('LYCHEE_UPLOADS_IMPORT', LYCHEE . 'uploads/import/');
# Define files
define('LYCHEE_CONFIG_FILE', LYCHEE_DATA . 'config.php');
?>

View File

@ -247,7 +247,7 @@ class Album extends Module {
# Set title
$album = $this->database->query("SELECT title FROM lychee_albums WHERE id = '$this->albumIDs' LIMIT 1;");
if ($this->albumIDs!=0&&is_numeric($this->albumIDs)) $zipTitle = $album->fetch_object()->title;
$filename = __DIR__ . "/../../data/$zipTitle.zip";
$filename = LYCHEE_DATA . $zipTitle . '.zip';
# Create zip
$zip = new ZipArchive();
@ -264,7 +264,7 @@ class Album extends Module {
while ($photo = $photos->fetch_object()) {
# Parse url
$photo->url = __DIR__ . '/../../uploads/big/' . $photo->url;
$photo->url = LYCHEE_UPLOADS_BIG . $photo->url;
# Parse title
$badChars = array_merge(

View File

@ -89,7 +89,7 @@ if(!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
?>";
# Save file
if (file_put_contents(__DIR__ . '/../../data/config.php', $config)===false) return 'Warning: Could not create file!';
if (file_put_contents(LYCHEE_CONFIG_FILE, $config)===false) return 'Warning: Could not create file!';
return true;

View File

@ -34,16 +34,13 @@ class Import extends Module {
$urls = str_replace(' ', '%20', $urls);
$urls = explode(',', $urls);
# Set path
$path = __DIR__ . '/../../data/';
foreach ($urls as &$url) {
if (@getimagesize($url)) {
$pathinfo = pathinfo($url);
$filename = $pathinfo['filename'] . '.' . $pathinfo['extension'];
$tmp_name = $path . $filename;
$tmp_name = LYCHEE_DATA . $filename;
if (!@copy($url, $tmp_name)) return false;
@ -51,13 +48,13 @@ class Import extends Module {
}
return Import::server($albumID, $path);
return Import::server($albumID, LYCHEE_DATA);
}
static function server($albumID = 0, $path) {
if (!isset($path)) $path = __DIR__ . '/../../uploads/import/';
if (!isset($path)) $path = LYCHEE_UPLOADS_IMPORT;
global $database, $plugins, $settings;

View File

@ -14,9 +14,6 @@ class Photo extends Module {
private $settings = null;
private $photoIDs = null;
private $uploadsBig = null;
private $uploadsThumb = null;
public function __construct($database, $plugins, $settings, $photoIDs) {
# Init vars
@ -25,10 +22,6 @@ class Photo extends Module {
$this->settings = $settings;
$this->photoIDs = $photoIDs;
# Set upload dirs
$this->uploadsBig = __DIR__ . '/../../uploads/big/';
$this->uploadsThumb = __DIR__ . '/../../uploads/thumb/';
return true;
}
@ -77,7 +70,7 @@ class Photo extends Module {
$extension = array_reverse(explode('.', $file['name']));
$extension = $extension[0];
$photo_name = md5($id) . ".$extension";
$path = $this->uploadsBig . $photo_name;
$path = LYCHEE_UPLOADS_BIG . $photo_name;
# Import if not uploaded via web
if (!is_uploaded_file($tmp_name)) {
@ -152,8 +145,8 @@ class Photo extends Module {
$info = getimagesize($url);
$photoName = explode(".", $filename);
$newUrl = $this->uploadsThumb . $photoName[0] . '.jpeg';
$newUrl2x = $this->uploadsThumb . $photoName[0] . '@2x.jpeg';
$newUrl = LYCHEE_UPLOADS_THUMB . $photoName[0] . '.jpeg';
$newUrl2x = LYCHEE_UPLOADS_THUMB . $photoName[0] . '@2x.jpeg';
# create thumbnails with Imagick
if(extension_loaded('imagick')) {
@ -479,10 +472,10 @@ class Photo extends Module {
# Set headers
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"$photo->title.$extension[0]\"");
header("Content-Length: " . filesize($this->uploadsBig . $photo->url));
header("Content-Length: " . filesize(LYCHEE_UPLOADS_BIG . $photo->url));
# Send file
readfile($this->uploadsBig . $photo->url);
readfile(LYCHEE_UPLOADS_BIG . $photo->url);
# Call plugins
$this->plugins(__METHOD__, 1, func_get_args());
@ -678,9 +671,9 @@ class Photo extends Module {
$thumbUrl2x = $thumbUrl2x[0] . '@2x.' . $thumbUrl2x[1];
# Delete files
if (file_exists($this->uploadsBig . $photo->url)&&!unlink($this->uploadsBig . $photo->url)) return false;
if (file_exists($this->uploadsThumb . $photo->thumbUrl)&&!unlink($this->uploadsThumb . $photo->thumbUrl)) return false;
if (file_exists($this->uploadsThumb . $thumbUrl2x)&&!unlink($this->uploadsThumb . $thumbUrl2x)) return false;
if (file_exists(LYCHEE_UPLOADS_BIG . $photo->url)&&!unlink(LYCHEE_UPLOADS_BIG . $photo->url)) return false;
if (file_exists(LYCHEE_UPLOADS_THUMB . $photo->thumbUrl)&&!unlink(LYCHEE_UPLOADS_THUMB . $photo->thumbUrl)) return false;
if (file_exists(LYCHEE_UPLOADS_THUMB . $thumbUrl2x)&&!unlink(LYCHEE_UPLOADS_THUMB . $thumbUrl2x)) return false;
# Delete db entry
$delete = $this->database->query("DELETE FROM lychee_photos WHERE id = '$photo->id';");