'+filename+'<\/div>'+
'
'+
- 'p('Insert') ?><\/button>'+
+ 'p('Insert') ?><\/button>'+
'p('Set as cover image') ?><\/button>'+
'p('Delete') ?><\/button>'+
'<\/div>'+
@@ -108,25 +119,28 @@ function displayFiles(files) {
// Get the list of files via AJAX, filter by the page number
function getFiles(pageNumber) {
- $.post("ajax/list-files",
+ $.post(HTML_PATH_ADMIN_ROOT+"ajax/list-images",
{ tokenCSRF: tokenCSRF,
pageNumber: pageNumber,
- path: "thumbnails" // the path are defined in the list-files
+ uuid: "",
+ path: "thumbnails" // the paths are defined in the list-images.php
},
function(data) {
displayFiles(data.files);
- });
+ }
+ );
}
// Delete the file and the thumbnail if exist
function deleteMedia(filename) {
- $.post("ajax/delete-file",
+ $.post(HTML_PATH_ADMIN_ROOT+"ajax/delete-file",
{ tokenCSRF: tokenCSRF,
filename: filename
},
function(data) {
getFiles(1);
- });
+ }
+ );
}
function setCoverImage(filename) {
@@ -144,10 +158,18 @@ $(document).ready(function() {
// Check file size ?
// Check file type/extension ?
+ $("#jsbluditProgressBar").width("1%");
+
+ // Data to send via AJAX
+ var uuid = $("#jsuuid").val();
+ var formData = new FormData($("#jsbluditFormUpload")[0]);
+ formData.append('uuid', uuid);
+ formData.append('tokenCSRF', tokenCSRF);
+
$.ajax({
- url: "ajax/upload-files",
+ url: HTML_PATH_ADMIN_ROOT+"ajax/upload-images",
type: "POST",
- data: new FormData($("#jsbluditFormUpload")[0]),
+ data: formData,
cache: false,
contentType: false,
processData: false,
diff --git a/bl-kernel/admin/views/new-content.php b/bl-kernel/admin/views/new-content.php
index 736093a5..19dea7b3 100644
--- a/bl-kernel/admin/views/new-content.php
+++ b/bl-kernel/admin/views/new-content.php
@@ -33,7 +33,7 @@
// UUID
echo Bootstrap::formInputHidden(array(
'name'=>'uuid',
- 'value'=>$pages->generateUUID()
+ 'value'=>$uuid
));
// Status = published, draft, sticky, static
diff --git a/bl-kernel/ajax/generate-slug.php b/bl-kernel/ajax/generate-slug.php
index d6063926..b61f65dc 100644
--- a/bl-kernel/ajax/generate-slug.php
+++ b/bl-kernel/ajax/generate-slug.php
@@ -2,7 +2,7 @@
header('Content-Type: application/json');
$text = isset($_POST['text']) ? $_POST['text'] : '';
-$parent = isset($_POST['parentKey']) ? $_POST['parentKey'] : PARENT;
+$parent = isset($_POST['parentKey']) ? $_POST['parentKey'] : '';
$oldKey = isset($_POST['currentKey']) ? $_POST['currentKey'] : '';
$slug = $pages->generateKey($text, $parent, $returnSlug=true, $oldKey);
diff --git a/bl-kernel/ajax/list-files.php b/bl-kernel/ajax/list-images.php
similarity index 63%
rename from bl-kernel/ajax/list-files.php
rename to bl-kernel/ajax/list-images.php
index bc5ef1b3..93b9996f 100644
--- a/bl-kernel/ajax/list-files.php
+++ b/bl-kernel/ajax/list-images.php
@@ -4,14 +4,23 @@ header('Content-Type: application/json');
// $_POST
// ----------------------------------------------------------------------------
// (integer) $_POST['pageNumber'] > 0
-$pageNumber = !empty($_POST['pageNumber']) ? (int)$_POST['pageNumber'] : 1;
+$pageNumber = empty($_POST['pageNumber']) ? 1 : (int)$_POST['pageNumber'];
$pageNumber = $pageNumber - 1;
// (string) $_POST['path']
-$path = isset($_POST['path']) ? $_POST['path'] : false;
+$path = empty($_POST['path']) ? false : $_POST['path'];
+
+// (string) $_POST['uuid']
+$uuid = empty($_POST['uuid']) ? false : $_POST['uuid'];
// ----------------------------------------------------------------------------
+
+// Set the path to get the file list
if ($path=='thumbnails') {
- $path = PATH_UPLOADS_THUMBNAILS;
+ if ($uuid && IMAGE_RESTRICT) {
+ $path = PATH_UPLOADS_PAGES.$uuid.DS.'thumbnails'.DS;
+ } else {
+ $path = PATH_UPLOADS_THUMBNAILS;
+ }
} else {
exit (json_encode(array(
'status'=>1,
@@ -20,15 +29,17 @@ if ($path=='thumbnails') {
}
// Get all files from the directory $path, also split the array by numberOfItems
-$listOfFilesByPage = Filesystem::listFiles($path, '*', '*', $GLOBALS['BLUDIT_MEDIA_MANAGER_SORT_BY_DATE'], $GLOBALS['BLUDIT_MEDIA_MANAGER_AMOUNT_OF_FILES']);
+// The function listFiles split in chunks
+$listOfFilesByPage = Filesystem::listFiles($path, '*', '*', $GLOBALS['MEDIA_MANAGER_SORT_BY_DATE'], $GLOBALS['MEDIA_MANAGER_NUMBER_OF_FILES']);
// Check if the page number exists in the chunks
if (isset($listOfFilesByPage[$pageNumber])) {
// Get only the filename from the chunk
- $tmp = array();
+ $files = array();
foreach ($listOfFilesByPage[$pageNumber] as $file) {
- array_push($tmp, basename($file));
+ $filename = basename($file);
+ array_push($files, $filename);
}
// Returns the number of chunks for the paginator
@@ -36,7 +47,7 @@ if (isset($listOfFilesByPage[$pageNumber])) {
exit (json_encode(array(
'status'=>0,
'numberOfPages'=>count($listOfFilesByPage),
- 'files'=>$tmp
+ 'files'=>$files
)));
}
diff --git a/bl-kernel/ajax/upload-files.php b/bl-kernel/ajax/upload-files.php
deleted file mode 100644
index 3f31df97..00000000
--- a/bl-kernel/ajax/upload-files.php
+++ /dev/null
@@ -1,50 +0,0 @@
-$filename) {
-
- if ($_FILES['bluditInputFiles']['error'][$key] != 0) {
- $message = 'Error occurred uploading the image, max file size allowed: '.ini_get('upload_max_filesize');
- Log::set($message, LOG_TYPE_ERROR);
- exit (json_encode(array(
- 'status'=>1,
- 'message'=>$message
- )));
- }
-
- // Get the next filename if already exist the file to not overwrite the original file
- $nextFilename = Filesystem::nextFilename(PATH_UPLOADS, $filename);
-
- // File extension
- $fileExtension = pathinfo($nextFilename, PATHINFO_EXTENSION);
-
- // Move from temporary directory to uploads folder
- rename($_FILES['bluditInputFiles']['tmp_name'][$key], PATH_UPLOADS.$nextFilename);
- chmod(PATH_UPLOADS.$nextFilename, 0644);
-
- // Generate Thumbnail
-
- // Exclude generate thumbnail for SVG format and generate a symlink to the svg
- if ($fileExtension == 'svg') {
- symlink(PATH_UPLOADS.$nextFilename, PATH_UPLOADS_THUMBNAILS.$nextFilename);
- } else {
- $Image = new Image();
- $Image->setImage(PATH_UPLOADS.$nextFilename, $GLOBALS['THUMBNAILS_WIDTH'], $GLOBALS['THUMBNAILS_HEIGHT'], 'crop');
- $Image->saveImage(PATH_UPLOADS_THUMBNAILS.$nextFilename, $GLOBALS['THUMBNAILS_QUALITY'], true);
- }
-}
-
-$absoluteURL = DOMAIN_UPLOADS.$nextFilename;
-$absoluteURLThumbnail = DOMAIN_UPLOADS_THUMBNAILS.$nextFilename;
-$absolutePath = PATH_UPLOADS.$nextFilename;
-
-exit (json_encode(array(
- 'status'=>0,
- 'message'=>'Image uploaded success.',
- 'filename'=>$nextFilename,
- 'absoluteURL'=>$absoluteURL,
- 'absoluteURLThumbnail'=>$absoluteURLThumbnail,
- 'absolutePath'=>$absolutePath
-)));
-
-?>
\ No newline at end of file
diff --git a/bl-kernel/ajax/upload-images.php b/bl-kernel/ajax/upload-images.php
new file mode 100644
index 00000000..cebc0d50
--- /dev/null
+++ b/bl-kernel/ajax/upload-images.php
@@ -0,0 +1,80 @@
+$filename) {
+
+ // Check for errors
+ if ($_FILES['bluditInputFiles']['error'][$key] != 0) {
+ $message = 'Error occurred uploading the image, max file size allowed: '.ini_get('upload_max_filesize');
+ Log::set($message, LOG_TYPE_ERROR);
+ exit (json_encode(array(
+ 'status'=>1,
+ 'message'=>$message
+ )));
+ }
+
+ // Check file extension
+ $fileExtension = pathinfo($filename, PATHINFO_EXTENSION);
+ if (!in_array($fileExtension, $allowedExtensions) ) {
+ $message = 'Extension file not supported.';
+ Log::set($message, LOG_TYPE_ERROR);
+ exit (json_encode(array(
+ 'status'=>1,
+ 'message'=>$message
+ )));
+ }
+
+ // Get the next filename to not overwrite the original file
+ $nextFilename = Filesystem::nextFilename($uploadDirectory, $filename);
+
+ // Move from temporary directory to uploads folder
+ rename($_FILES['bluditInputFiles']['tmp_name'][$key], $uploadDirectory.$nextFilename);
+ chmod($uploadDirectory.$nextFilename, 0644);
+
+ // Generate Thumbnail
+ // Exclude generate thumbnail for SVG format and generate a symlink to the svg
+ if ($fileExtension == 'svg') {
+ symlink($uploadDirectory.$nextFilename, $thumbnailDirectory.$nextFilename);
+ } else {
+ $Image = new Image();
+ $Image->setImage($uploadDirectory.$nextFilename, $GLOBALS['THUMBNAILS_WIDTH'], $GLOBALS['THUMBNAILS_HEIGHT'], 'crop');
+ $Image->saveImage($thumbnailDirectory.$nextFilename, $GLOBALS['THUMBNAILS_QUALITY'], true);
+ }
+}
+
+exit (json_encode(array(
+ 'status'=>0,
+ 'message'=>'Image uploaded success.',
+ 'filename'=>$nextFilename
+)));
+
+?>
\ No newline at end of file
diff --git a/bl-kernel/boot/init.php b/bl-kernel/boot/init.php
index 3b098490..8d603ad1 100644
--- a/bl-kernel/boot/init.php
+++ b/bl-kernel/boot/init.php
@@ -40,6 +40,7 @@ define('PATH_TMP', PATH_CONTENT.'tmp'.DS);
define('PATH_UPLOADS', PATH_CONTENT.'uploads'.DS);
define('PATH_WORKSPACES', PATH_CONTENT.'workspaces'.DS);
+define('PATH_UPLOADS_PAGES', PATH_UPLOADS.'pages'.DS);
define('PATH_UPLOADS_PROFILES', PATH_UPLOADS.'profiles'.DS);
define('PATH_UPLOADS_THUMBNAILS', PATH_UPLOADS.'thumbnails'.DS);
@@ -171,6 +172,7 @@ define('HTML_PATH_CORE_JS', HTML_PATH_ROOT.'bl-kernel/js/');
define('HTML_PATH_CORE_CSS', HTML_PATH_ROOT.'bl-kernel/css/');
define('HTML_PATH_CONTENT', HTML_PATH_ROOT.'bl-content/');
define('HTML_PATH_UPLOADS', HTML_PATH_ROOT.'bl-content/uploads/');
+define('HTML_PATH_UPLOADS_PAGES', HTML_PATH_UPLOADS.'pages/');
define('HTML_PATH_UPLOADS_PROFILES', HTML_PATH_UPLOADS.'profiles/');
define('HTML_PATH_UPLOADS_THUMBNAILS', HTML_PATH_UPLOADS.'thumbnails/');
define('HTML_PATH_PLUGINS', HTML_PATH_ROOT.'bl-plugins/');
@@ -199,6 +201,12 @@ define('EXTREME_FRIENDLY_URL', $site->extremeFriendly());
// Minutes to execute the autosave function
define('AUTOSAVE_INTERVAL', $site->autosaveInterval());
+// TRUE for upload images restric to a pages, FALSE to upload images in common
+define('IMAGE_RESTRICT', $site->imageRestrict());
+
+// TRUE to convert relatives images to absoultes, FALSE No changes apply
+define('IMAGE_RELATIVE_TO_ABSOLUTE', $site->imageRelativeToAbsolute());
+
// --- PHP paths with dependency ---
// This paths are absolutes for the OS
define('THEME_DIR', PATH_ROOT.'bl-themes'.DS.$site->theme().DS);
@@ -222,6 +230,7 @@ define('DOMAIN_ADMIN_THEME', DOMAIN.HTML_PATH_ADMIN_THEME);
define('DOMAIN_ADMIN_THEME_CSS', DOMAIN.HTML_PATH_ADMIN_THEME_CSS);
define('DOMAIN_ADMIN_THEME_JS', DOMAIN.HTML_PATH_ADMIN_THEME_JS);
define('DOMAIN_UPLOADS', DOMAIN.HTML_PATH_UPLOADS);
+define('DOMAIN_UPLOADS_PAGES', DOMAIN.HTML_PATH_UPLOADS_PAGES);
define('DOMAIN_UPLOADS_PROFILES', DOMAIN.HTML_PATH_UPLOADS_PROFILES);
define('DOMAIN_UPLOADS_THUMBNAILS', DOMAIN.HTML_PATH_UPLOADS_THUMBNAILS);
define('DOMAIN_PLUGINS', DOMAIN.HTML_PATH_PLUGINS);
diff --git a/bl-kernel/boot/variables.php b/bl-kernel/boot/variables.php
index a1d72aad..916efaa7 100644
--- a/bl-kernel/boot/variables.php
+++ b/bl-kernel/boot/variables.php
@@ -20,19 +20,14 @@ define('ALERT_STATUS_OK', 0);
// Alert status fail
define('ALERT_STATUS_FAIL', 1);
-// Amount of thumbnails shown on Bludit Quick images
-define('THUMBNAILS_AMOUNT', 6);
-
-// Thubmnails size
-define('THUMBNAILS_WIDTH', 400);
-define('THUMBNAILS_HEIGHT', 400);
-define('THUMBNAILS_QUALITY', 100); // 100%
-
// Profile image size
define('PROFILE_IMG_WIDTH', 400);
define('PROFILE_IMG_HEIGHT', 400);
define('PROFILE_IMG_QUALITY', 100); // 100%
+// Items per page for admin area
+define('ITEMS_PER_PAGE_ADMIN', 20);
+
// Password length
define('PASSWORD_LENGTH', 6);
@@ -42,18 +37,6 @@ define('SALT_LENGTH', 8);
// Page brake string
define('PAGE_BREAK', '');
-// Parent key for the array $pagesByParents
-define('PARENT', 'BLUDIT3849abb4cb7abd24c2d8dac17b216f17');
-
-// Items per page for admin area
-define('ITEMS_PER_PAGE_ADMIN', 20);
-
-// Cli mode, status for new pages
-define('CLI_STATUS', 'published');
-
-// Cli mode, username for new pages
-define('CLI_USERNAME', 'admin');
-
// Remember me
define('REMEMBER_COOKIE_USERNAME', 'BLUDITREMEMBERUSERNAME');
define('REMEMBER_COOKIE_TOKEN', 'BLUDITREMEMBERTOKEN');
@@ -109,15 +92,17 @@ define('SESSION_GC_MAXLIFETIME', 3600);
// The value 0 means until the browser is closed
define('SESSION_COOKIE_LIFE_TIME', 0);
-// New Global Variables
-$GLOBALS['BLUDIT_MEDIA_MANAGER_AMOUNT_OF_FILES'] = 5;
-$GLOBALS['BLUDIT_MEDIA_MANAGER_SORT_BY_DATE'] = true;
+// Alert notification dissappear in X seconds
+$GLOBALS['ALERT_DISSAPEAR_IN'] = 3; // Seconds
+
+// Number of images to show in the media manager per page
+$GLOBALS['MEDIA_MANAGER_NUMBER_OF_FILES'] = 5;
+
+// Sort the image by date
+$GLOBALS['MEDIA_MANAGER_SORT_BY_DATE'] = true;
// Thubmnails size
$GLOBALS['THUMBNAILS_WIDTH'] = 400;
$GLOBALS['THUMBNAILS_HEIGHT'] = 400;
$GLOBALS['THUMBNAILS_QUALITY'] = 100;
-// Alert
-$GLOBALS['ALERT_DISSAPEAR_IN'] = 3; // Seconds
-
diff --git a/bl-kernel/helpers/filesystem.class.php b/bl-kernel/helpers/filesystem.class.php
index 041c7722..7841dfb7 100644
--- a/bl-kernel/helpers/filesystem.class.php
+++ b/bl-kernel/helpers/filesystem.class.php
@@ -52,8 +52,7 @@ class Filesystem {
public static function mkdir($pathname, $recursive=false)
{
- // DEBUG: Ver permisos si son correctos
- return mkdir($pathname, 0755, $recursive);
+ return mkdir($pathname, DIR_PERMISSIONS, $recursive);
}
public static function rmdir($pathname)
@@ -98,7 +97,7 @@ class Filesystem {
// Check $destionation directory if exists
if (!self::directoryExists($destination)) {
// Create the $destination directory
- if (!mkdir($destination, 0755, true)) {
+ if (!mkdir($destination, DIR_PERMISSIONS, true)) {
return false;
}
}
diff --git a/bl-kernel/js/variables.php b/bl-kernel/js/variables.php
index 8d29dde2..5f8cacdd 100644
--- a/bl-kernel/js/variables.php
+++ b/bl-kernel/js/variables.php
@@ -6,7 +6,6 @@ echo 'var HTML_PATH_ADMIN_THEME = "'.HTML_PATH_ADMIN_THEME.'";'.PHP_EOL;
echo 'var HTML_PATH_ADMIN_THEME_IMG = "'.HTML_PATH_ADMIN_THEME_IMG.'";'.PHP_EOL;
echo 'var HTML_PATH_UPLOADS = "'.HTML_PATH_UPLOADS.'";'.PHP_EOL;
echo 'var HTML_PATH_UPLOADS_THUMBNAILS = "'.HTML_PATH_UPLOADS_THUMBNAILS.'";'.PHP_EOL;
-echo 'var PARENT = "'.PARENT.'";'.PHP_EOL;
echo 'var BLUDIT_VERSION = "'.BLUDIT_VERSION.'";'.PHP_EOL;
echo 'var BLUDIT_BUILD = "'.BLUDIT_BUILD.'";'.PHP_EOL;
echo 'var DOMAIN_UPLOADS = "'.DOMAIN_UPLOADS.'";'.PHP_EOL;
diff --git a/bl-kernel/pagex.class.php b/bl-kernel/pagex.class.php
index db285613..108a1584 100644
--- a/bl-kernel/pagex.class.php
+++ b/bl-kernel/pagex.class.php
@@ -83,7 +83,10 @@ class Page {
$content = $parsedown->text($content);
// Parse img src relative to absolute (with domain)
- $content = Text::imgRel2Abs($content, DOMAIN_UPLOADS);
+ if (IMAGE_RELATIVE_TO_ABSOLUTE) {
+ $domain = IMAGE_RESTRICT?DOMAIN_UPLOADS_PAGES.$this->uuid().'/':DOMAIN_UPLOADS;
+ $content = Text::imgRel2Abs($content, $domain);
+ }
if ($sanitize) {
return Sanitize::html($content);
diff --git a/bl-kernel/site.class.php b/bl-kernel/site.class.php
index e3408faf..20fcf293 100644
--- a/bl-kernel/site.class.php
+++ b/bl-kernel/site.class.php
@@ -38,7 +38,9 @@ class Site extends dbJSON {
'titleFormatHomepage'=> '{{site-slogan}} | {{site-title}}',
'titleFormatPages'=> '{{page-title}} | {{site-title}}',
'titleFormatCategory'=> '{{category-name}} | {{site-title}}',
- 'titleFormatTag'=> '{{tag-name}} | {{site-title}}'
+ 'titleFormatTag'=> '{{tag-name}} | {{site-title}}',
+ 'imageRestrict'=> true,
+ 'imageRelativeToAbsolute'=> false
);
function __construct()
@@ -168,6 +170,16 @@ class Site extends dbJSON {
return $this->getField('orderBy');
}
+ public function imageRestrict()
+ {
+ return $this->getField('imageRestrict');
+ }
+
+ public function imageRelativeToAbsolute()
+ {
+ return $this->getField('imageRelativeToAbsolute');
+ }
+
// Returns the site title
public function title()
{
diff --git a/bl-plugins/remote-content/plugin.php b/bl-plugins/remote-content/plugin.php
index 7d2c5b07..309d0a5d 100644
--- a/bl-plugins/remote-content/plugin.php
+++ b/bl-plugins/remote-content/plugin.php
@@ -94,10 +94,10 @@ class pluginRemoteContent extends Plugin {
Filesystem::deleteRecursive(PATH_PAGES);
Filesystem::deleteRecursive(PATH_UPLOADS);
- mkdir(PATH_PAGES, 0755, true);
- mkdir(PATH_UPLOADS, 0755, true);
- mkdir(PATH_UPLOADS_PROFILES, 0755, true);
- mkdir(PATH_UPLOADS_THUMBNAILS, 0755, true);
+ mkdir(PATH_PAGES, DIR_PERMISSIONS, true);
+ mkdir(PATH_UPLOADS, DIR_PERMISSIONS, true);
+ mkdir(PATH_UPLOADS_PROFILES, DIR_PERMISSIONS, true);
+ mkdir(PATH_UPLOADS_THUMBNAILS, DIR_PERMISSIONS, true);
return true;
}
@@ -106,7 +106,7 @@ class pluginRemoteContent extends Plugin {
{
$workspace = $this->workspace();
Filesystem::deleteRecursive($workspace.DS);
- mkdir($workspace, 0755, true);
+ mkdir($workspace, DIR_PERMISSIONS, true);
return true;
}
diff --git a/bl-plugins/tinymce/plugin.php b/bl-plugins/tinymce/plugin.php
index 7bd2c51a..cdaaab07 100644
--- a/bl-plugins/tinymce/plugin.php
+++ b/bl-plugins/tinymce/plugin.php
@@ -120,7 +120,6 @@ tinymce.init({
paste_as_text: true,
relative_urls: true,
remove_script_host: false,
- document_base_url: DOMAIN_UPLOADS,
plugins: ["$plugins"],
toolbar1: "$toolbar1",
toolbar2: "$toolbar2",
@@ -130,6 +129,8 @@ tinymce.init({
EOF;
+// document_base_url: DOMAIN_UPLOADS,
+
return $script;
}
diff --git a/install.php b/install.php
index 61cf61ab..f95978dd 100644
--- a/install.php
+++ b/install.php
@@ -305,6 +305,11 @@ function install($adminPassword, $timezone)
error_log('[ERROR] '.$errorText, 0);
}
+ if (!mkdir(PATH_UPLOADS_PAGES, DIR_PERMISSIONS, true)) {
+ $errorText = 'Error when trying to created the directory=>'.PATH_UPLOADS_PAGES;
+ error_log('[ERROR] '.$errorText, 0);
+ }
+
// ============================================================================
// Create files
// ============================================================================
@@ -391,7 +396,9 @@ function install($adminPassword, $timezone)
'titleFormatHomepage'=>'{{site-slogan}} | {{site-title}}',
'titleFormatPages'=>'{{page-title}} | {{site-title}}',
'titleFormatCategory'=>'{{category-name}} | {{site-title}}',
- 'titleFormatTag'=>'{{tag-name}} | {{site-title}}'
+ 'titleFormatTag'=>'{{tag-name}} | {{site-title}}',
+ 'imageRestrict'=>true,
+ 'imageRelativeToAbsolute'=>false
);
file_put_contents(PATH_DATABASES.'site.php', $dataHead.json_encode($data, JSON_PRETTY_PRINT), LOCK_EX);