diff --git a/bl-kernel/boot/init.php b/bl-kernel/boot/init.php index 12489adb..df1d3ea4 100644 --- a/bl-kernel/boot/init.php +++ b/bl-kernel/boot/init.php @@ -9,7 +9,7 @@ define('BLUDIT_BUILD', '20190228'); // Debug mode // Change to FALSE, for prevent warning or errors on browser define('DEBUG_MODE', TRUE); -define('DEBUG_TYPE', 'TRACE'); // INFO, TRACE +define('DEBUG_TYPE', 'INFO'); // INFO, TRACE error_reporting(0); // Turn off all error reporting if (DEBUG_MODE) { // Turn on all error reporting diff --git a/bl-kernel/boot/variables.php b/bl-kernel/boot/variables.php index e1786835..6de0f009 100644 --- a/bl-kernel/boot/variables.php +++ b/bl-kernel/boot/variables.php @@ -95,6 +95,9 @@ define('SESSION_COOKIE_LIFE_TIME', 0); // Tags, type of pages included in the tag database define('DB_TAGS_TYPES', array('published','static','sticky')); +// Allowed image extensions +define('ALLOWED_IMG_EXTENSION', array('gif', 'png', 'jpg', 'jpeg', 'svg')); + // Alert notification dissappear in X seconds $GLOBALS['ALERT_DISSAPEAR_IN'] = 3; // Seconds diff --git a/bl-kernel/functions.php b/bl-kernel/functions.php index 45405b71..b8a50f6e 100644 --- a/bl-kernel/functions.php +++ b/bl-kernel/functions.php @@ -804,4 +804,37 @@ function ajaxResponse($status=0, $message="", $data=array()) { $default = array('status'=>$status, 'message'=>$message); $output = array_merge($default, $data); exit (json_encode($output)); +} + +function uploadImage($file, $imageDir, $thumbnailDir) { + global $site; + + // Check image extension + $fileExtension = Filesystem::extension($file); + $fileExtension = Text::lowercase($fileExtension); + if (!in_array($fileExtension, ALLOWED_IMG_EXTENSION) ) { + return false; + } + + // Generate a filename to not overwrite current image if exists + $filename = Filesystem::filename($file); + $nextFilename = Filesystem::nextFilename($imageDir, $filename); + + // Move the image to a proper place and name + $image = $imageDir.$nextFilename; + Filesystem::mv($file, $image); + chmod($image, 0644); + + // Generate Thumbnail + if (!empty($thumbnailDir)) { + if ($fileExtension == 'svg') { + symlink($image, $thumbnailDir.$nextFilename); + } else { + $Image = new Image(); + $Image->setImage($image, $site->thumbnailWidth(), $site->thumbnailHeight(), 'crop'); + $Image->saveImage($thumbnailDir.$nextFilename, $site->thumbnailQuality(), true); + } + } + + return $image; } \ No newline at end of file diff --git a/bl-kernel/helpers/filesystem.class.php b/bl-kernel/helpers/filesystem.class.php index 139c18be..3af90466 100644 --- a/bl-kernel/helpers/filesystem.class.php +++ b/bl-kernel/helpers/filesystem.class.php @@ -203,7 +203,14 @@ class Filesystem { return $zip->close(); } - // Returns the next filename if the filename already exist + /* + | Returns the next filename if the filename already exist otherwise returns the original filename + | + | @path string Path + | @filename string Filename + | + | @return string + */ public static function nextFilename($path=PATH_UPLOADS, $filename) { // Clean filename and get extension $fileExtension = pathinfo($filename, PATHINFO_EXTENSION); @@ -224,4 +231,32 @@ class Filesystem { } return $tmpName; } + + /* + | Returns the filename + | Example: + | @file /home/diego/dog.jpg + | @return dog.jpg + | + | @file string Full path of the file + | + | @return string + */ + public static function filename($file) { + return basename($file); + } + + /* + | Returns the file extension + | Example: + | @file /home/diego/dog.jpg + | @return jpg + | + | @file string Full path of the file + | + | @return string + */ + public static function extension($file) { + return pathinfo($file, PATHINFO_EXTENSION); + } } diff --git a/bl-plugins/api/plugin.php b/bl-plugins/api/plugin.php index 0a736573..25a81bb8 100644 --- a/bl-plugins/api/plugin.php +++ b/bl-plugins/api/plugin.php @@ -30,7 +30,7 @@ class pluginAPI extends Plugin { $html .= '
'.DOMAIN.'/api/{endpoint}
'; + $html .= ''.DOMAIN_BASE.'api/{endpoint}
'; $html .= '