fix: page upload symlink
This commit is contained in:
parent
e770d6a972
commit
4bfa4a74a9
5 changed files with 274 additions and 257 deletions
|
@ -93,5 +93,3 @@ foreach ($_FILES['images']['name'] as $uuid=>$filename) {
|
||||||
ajaxResponse(0, 'Images uploaded.', array(
|
ajaxResponse(0, 'Images uploaded.', array(
|
||||||
'images' => $images
|
'images' => $images
|
||||||
));
|
));
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ define('BLUDIT_RELEASE_DATE', '2023-07-15');
|
||||||
define('BLUDIT_BUILD', '20230715');
|
define('BLUDIT_BUILD', '20230715');
|
||||||
|
|
||||||
// Change to TRUE for debugging
|
// Change to TRUE for debugging
|
||||||
define('DEBUG_MODE', FALSE);
|
define('DEBUG_MODE', TRUE);
|
||||||
define('DEBUG_TYPE', 'INFO'); // INFO, TRACE
|
define('DEBUG_TYPE', 'INFO'); // INFO, TRACE
|
||||||
|
|
||||||
// This determines whether errors should be printed to the screen as part of the output or if they should be hidden from the user.
|
// This determines whether errors should be printed to the screen as part of the output or if they should be hidden from the user.
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||||
|
|
||||||
class Filesystem {
|
class Filesystem
|
||||||
|
{
|
||||||
|
|
||||||
// Returns an array with the absolutes directories.
|
// Returns an array with the absolutes directories.
|
||||||
public static function listDirectories($path, $regex = '*', $sortByDate = false)
|
public static function listDirectories($path, $regex = '*', $sortByDate = false)
|
||||||
|
@ -12,7 +13,8 @@ class Filesystem {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($sortByDate) {
|
if ($sortByDate) {
|
||||||
usort($directories,
|
usort(
|
||||||
|
$directories,
|
||||||
function ($a, $b) {
|
function ($a, $b) {
|
||||||
return filemtime($b) - filemtime($a);
|
return filemtime($b) - filemtime($a);
|
||||||
}
|
}
|
||||||
|
@ -35,7 +37,8 @@ class Filesystem {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($sortByDate) {
|
if ($sortByDate) {
|
||||||
usort($files,
|
usort(
|
||||||
|
$files,
|
||||||
function ($a, $b) {
|
function ($a, $b) {
|
||||||
return filemtime($b) - filemtime($a);
|
return filemtime($b) - filemtime($a);
|
||||||
}
|
}
|
||||||
|
@ -53,6 +56,7 @@ class Filesystem {
|
||||||
|
|
||||||
public static function mkdir($pathname, $recursive = false)
|
public static function mkdir($pathname, $recursive = false)
|
||||||
{
|
{
|
||||||
|
Log::set('mkdir ' . $pathname . ' recursive = ' . $recursive, LOG_TYPE_INFO);
|
||||||
return mkdir($pathname, DIR_PERMISSIONS, $recursive);
|
return mkdir($pathname, DIR_PERMISSIONS, $recursive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +112,8 @@ class Filesystem {
|
||||||
|
|
||||||
foreach ($iterator = new RecursiveIteratorIterator(
|
foreach ($iterator = new RecursiveIteratorIterator(
|
||||||
new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS),
|
new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS),
|
||||||
RecursiveIteratorIterator::SELF_FIRST) as $item) {
|
RecursiveIteratorIterator::SELF_FIRST
|
||||||
|
) as $item) {
|
||||||
|
|
||||||
$currentDirectory = dirname($item->getPathName());
|
$currentDirectory = dirname($item->getPathName());
|
||||||
if ($skipDirectory !== $currentDirectory) {
|
if ($skipDirectory !== $currentDirectory) {
|
||||||
|
@ -135,7 +140,8 @@ class Filesystem {
|
||||||
|
|
||||||
foreach (new RecursiveIteratorIterator(
|
foreach (new RecursiveIteratorIterator(
|
||||||
new RecursiveDirectoryIterator($source, FilesystemIterator::SKIP_DOTS),
|
new RecursiveDirectoryIterator($source, FilesystemIterator::SKIP_DOTS),
|
||||||
RecursiveIteratorIterator::CHILD_FIRST) as $item) {
|
RecursiveIteratorIterator::CHILD_FIRST
|
||||||
|
) as $item) {
|
||||||
if ($item->isFile() || $item->isLink()) {
|
if ($item->isFile() || $item->isLink()) {
|
||||||
unlink($item);
|
unlink($item);
|
||||||
} else {
|
} else {
|
||||||
|
@ -217,7 +223,8 @@ class Filesystem {
|
||||||
|
|
|
|
||||||
| @return string
|
| @return string
|
||||||
*/
|
*/
|
||||||
public static function nextFilename($filename, $path=PATH_UPLOADS) {
|
public static function nextFilename($filename, $path = PATH_UPLOADS)
|
||||||
|
{
|
||||||
// Clean filename and get extension
|
// Clean filename and get extension
|
||||||
$fileExtension = pathinfo($filename, PATHINFO_EXTENSION);
|
$fileExtension = pathinfo($filename, PATHINFO_EXTENSION);
|
||||||
$fileExtension = Text::lowercase($fileExtension);
|
$fileExtension = Text::lowercase($fileExtension);
|
||||||
|
@ -248,7 +255,8 @@ class Filesystem {
|
||||||
|
|
|
|
||||||
| @return string
|
| @return string
|
||||||
*/
|
*/
|
||||||
public static function filename($file) {
|
public static function filename($file)
|
||||||
|
{
|
||||||
return basename($file);
|
return basename($file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,7 +270,8 @@ class Filesystem {
|
||||||
|
|
|
|
||||||
| @return string
|
| @return string
|
||||||
*/
|
*/
|
||||||
public static function extension($file) {
|
public static function extension($file)
|
||||||
|
{
|
||||||
return pathinfo($file, PATHINFO_EXTENSION);
|
return pathinfo($file, PATHINFO_EXTENSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,7 +280,8 @@ class Filesystem {
|
||||||
* @param [string] $fileOrDirectory
|
* @param [string] $fileOrDirectory
|
||||||
* @return [int|bool] [bytes or false on error]
|
* @return [int|bool] [bytes or false on error]
|
||||||
*/
|
*/
|
||||||
public static function getSize($fileOrDirectory) {
|
public static function getSize($fileOrDirectory)
|
||||||
|
{
|
||||||
// Files
|
// Files
|
||||||
if (is_file($fileOrDirectory)) {
|
if (is_file($fileOrDirectory)) {
|
||||||
return filesize($fileOrDirectory);
|
return filesize($fileOrDirectory);
|
||||||
|
@ -291,7 +301,8 @@ class Filesystem {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function bytesToHumanFileSize($bytes, $decimals = 2) {
|
public static function bytesToHumanFileSize($bytes, $decimals = 2)
|
||||||
|
{
|
||||||
$size = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
|
$size = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
|
||||||
$factor = floor((strlen($bytes) - 1) / 3);
|
$factor = floor((strlen($bytes) - 1) / 3);
|
||||||
return sprintf("%.{$decimals}f ", $bytes / pow(1024, $factor)) . @$size[$factor];
|
return sprintf("%.{$decimals}f ", $bytes / pow(1024, $factor)) . @$size[$factor];
|
||||||
|
@ -307,7 +318,8 @@ class Filesystem {
|
||||||
|
|
|
|
||||||
| @return [string|bool] Mime type as string or FALSE if not possible to get the mime type
|
| @return [string|bool] Mime type as string or FALSE if not possible to get the mime type
|
||||||
*/
|
*/
|
||||||
public static function mimeType($file) {
|
public static function mimeType($file)
|
||||||
|
{
|
||||||
if (function_exists('mime_content_type')) {
|
if (function_exists('mime_content_type')) {
|
||||||
return mime_content_type($file);
|
return mime_content_type($file);
|
||||||
}
|
}
|
||||||
|
@ -322,12 +334,13 @@ class Filesystem {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function symlink($from, $to) {
|
public static function symlink($from, $to)
|
||||||
|
{
|
||||||
if (function_exists('symlink')) {
|
if (function_exists('symlink')) {
|
||||||
|
Log::set('symlink from = ' . $from . ' to = ' . $to, LOG_TYPE_INFO);
|
||||||
return symlink($from, $to);
|
return symlink($from, $to);
|
||||||
} else {
|
} else {
|
||||||
return copy($from, $to);
|
return copy($from, $to);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||||
|
|
||||||
class Pages extends dbJSON {
|
class Pages extends dbJSON
|
||||||
|
{
|
||||||
|
|
||||||
protected $parentKeyList = array();
|
protected $parentKeyList = array();
|
||||||
protected $dbFields = array(
|
protected $dbFields = array(
|
||||||
|
@ -156,10 +157,12 @@ class Pages extends dbJSON {
|
||||||
// Save database
|
// Save database
|
||||||
$this->save();
|
$this->save();
|
||||||
|
|
||||||
// Create symlink for images directory
|
// Create upload page directory for images
|
||||||
if (Filesystem::mkdir(PATH_UPLOADS_PAGES.$row['uuid'])) {
|
if (!Filesystem::directoryExists(PATH_UPLOADS_PAGES . $row['uuid'])) {
|
||||||
Filesystem::symlink(PATH_UPLOADS_PAGES.$row['uuid'], PATH_UPLOADS_PAGES.$key);
|
Filesystem::mkdir(PATH_UPLOADS_PAGES . $row['uuid']);
|
||||||
}
|
}
|
||||||
|
// Create a symlink to the upload page directory for images for better SEO
|
||||||
|
Filesystem::symlink(PATH_UPLOADS_PAGES . $row['uuid'], PATH_UPLOADS_PAGES . $key);
|
||||||
|
|
||||||
return $key;
|
return $key;
|
||||||
}
|
}
|
||||||
|
@ -289,7 +292,8 @@ class Pages extends dbJSON {
|
||||||
|
|
||||||
// This function reindex the orphan children with the new parent key
|
// This function reindex the orphan children with the new parent key
|
||||||
// If a page has subpages and the page change his key is necesarry check the children key
|
// If a page has subpages and the page change his key is necesarry check the children key
|
||||||
public function reindexChildren($oldParentKey, $newParentKey) {
|
public function reindexChildren($oldParentKey, $newParentKey)
|
||||||
|
{
|
||||||
if ($oldParentKey == $newParentKey) {
|
if ($oldParentKey == $newParentKey) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -655,7 +659,8 @@ class Pages extends dbJSON {
|
||||||
return $a['date'] < $b['date'];
|
return $a['date'] < $b['date'];
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateUUID() {
|
function generateUUID()
|
||||||
|
{
|
||||||
return md5(uniqid() . time());
|
return md5(uniqid() . time());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -704,8 +709,7 @@ class Pages extends dbJSON {
|
||||||
$this->db[$pageKey]['type'] = 'published';
|
$this->db[$pageKey]['type'] = 'published';
|
||||||
$saveDatabase = true;
|
$saveDatabase = true;
|
||||||
}
|
}
|
||||||
}
|
} elseif (($fields['type'] == 'published') && (ORDER_BY == 'date')) {
|
||||||
elseif( ($fields['type']=='published') && (ORDER_BY=='date') ) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -820,6 +824,4 @@ class Pages extends dbJSON {
|
||||||
|
|
||||||
return $this->save();
|
return $this->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||||
|
|
||||||
class Page {
|
class Page
|
||||||
|
{
|
||||||
|
|
||||||
protected $vars;
|
protected $vars;
|
||||||
|
|
||||||
|
@ -519,7 +520,8 @@ class Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the amount of minutes takes to read the page
|
// Returns the amount of minutes takes to read the page
|
||||||
public function readingTime() {
|
public function readingTime()
|
||||||
|
{
|
||||||
global $L;
|
global $L;
|
||||||
|
|
||||||
$words = $this->content(true);
|
$words = $this->content(true);
|
||||||
|
@ -540,7 +542,8 @@ class Page {
|
||||||
// Modified for Bludit
|
// Modified for Bludit
|
||||||
// $complete = false : short version
|
// $complete = false : short version
|
||||||
// $complete = true : full version
|
// $complete = true : full version
|
||||||
public function relativeTime($complete = false) {
|
public function relativeTime($complete = false)
|
||||||
|
{
|
||||||
$current = new DateTime;
|
$current = new DateTime;
|
||||||
$past = new DateTime($this->getValue('dateRaw'));
|
$past = new DateTime($this->getValue('dateRaw'));
|
||||||
$elapsed = $current->diff($past);
|
$elapsed = $current->diff($past);
|
||||||
|
@ -588,7 +591,8 @@ class Page {
|
||||||
|
|
||||||
// Returns an array with all pages key related to the page
|
// Returns an array with all pages key related to the page
|
||||||
// The relation is based on the tags
|
// The relation is based on the tags
|
||||||
public function related() {
|
public function related()
|
||||||
|
{
|
||||||
global $tags;
|
global $tags;
|
||||||
$pageTags = $this->tags(true);
|
$pageTags = $this->tags(true);
|
||||||
$list = array();
|
$list = array();
|
||||||
|
|
Loading…
Add table
Reference in a new issue