mirror of
https://github.com/typemill/typemill.git
synced 2025-07-30 19:00:32 +02:00
Version 1.3.5 Consolidation
This commit is contained in:
@@ -98,7 +98,7 @@ class ProcessAssets
|
||||
return (count(scandir($dir)) == 2);
|
||||
}
|
||||
|
||||
public function setFileName($originalname, $type, $overwrite = null)
|
||||
public function setFileName($originalname, $type, $overwrite = NULL)
|
||||
{
|
||||
$pathinfo = pathinfo($originalname);
|
||||
|
||||
@@ -135,6 +135,11 @@ class ProcessAssets
|
||||
return $this->filename;
|
||||
}
|
||||
|
||||
public function setExtension($extension)
|
||||
{
|
||||
$this->extension = $extension;
|
||||
}
|
||||
|
||||
public function getExtension()
|
||||
{
|
||||
return $this->extension;
|
||||
|
@@ -5,7 +5,7 @@ use Typemill\Models\Helpers;
|
||||
|
||||
class ProcessImage extends ProcessAssets
|
||||
{
|
||||
public function createImage(string $image, string $name, array $desiredSizes)
|
||||
public function createImage(string $image, string $name, array $desiredSizes, $overwrite = NULL)
|
||||
{
|
||||
# fix error from jpeg-library
|
||||
ini_set ('gd.jpeg_ignore_warning', 1);
|
||||
@@ -15,13 +15,15 @@ class ProcessImage extends ProcessAssets
|
||||
$this->clearTempFolder();
|
||||
|
||||
# set the name of the image
|
||||
$this->setFileName($name, 'image');
|
||||
$this->setFileName($name, 'image', $overwrite);
|
||||
|
||||
# decode the image from base64-string
|
||||
$imageDecoded = $this->decodeImage($image);
|
||||
$imageData = $imageDecoded["image"];
|
||||
$imageType = $imageDecoded["type"];
|
||||
|
||||
$this->setExtension($imageType);
|
||||
|
||||
# transform image-stream into image
|
||||
$image = imagecreatefromstring($imageData);
|
||||
|
||||
@@ -38,7 +40,7 @@ class ProcessImage extends ProcessAssets
|
||||
$tmpname = fopen($this->tmpFolder . $this->getName() . '.' . $imageType . ".txt", "w");
|
||||
|
||||
$this->saveOriginal($this->tmpFolder, $imageData, $name = 'original', $imageType);
|
||||
|
||||
|
||||
# temporary store resized images
|
||||
foreach($resizedImages as $key => $resizedImage)
|
||||
{
|
||||
@@ -71,8 +73,8 @@ class ProcessImage extends ProcessAssets
|
||||
{
|
||||
$tmpname = str_replace('.txt', '', basename($imagename));
|
||||
|
||||
# set extension and sanitize name
|
||||
$this->setFileName($tmpname, 'image');
|
||||
# set extension and sanitize name. Overwrite because this has been checked before
|
||||
$this->setFileName($tmpname, 'image', $overwrite = true);
|
||||
|
||||
unlink($imagename);
|
||||
}
|
||||
@@ -80,7 +82,7 @@ class ProcessImage extends ProcessAssets
|
||||
$name = uniqid();
|
||||
|
||||
if($this->filename && $this->extension)
|
||||
{
|
||||
{
|
||||
$name = $this->filename;
|
||||
}
|
||||
|
||||
@@ -110,7 +112,7 @@ class ProcessImage extends ProcessAssets
|
||||
|
||||
if($success)
|
||||
{
|
||||
return true;
|
||||
# return true;
|
||||
return 'media/live/' . $name . '.' . $tmpfilename[1];
|
||||
}
|
||||
|
||||
@@ -201,7 +203,9 @@ class ProcessImage extends ProcessAssets
|
||||
|
||||
# save resized images in temporary folder
|
||||
public function saveImage($folder, $image, $name, $type)
|
||||
{
|
||||
{
|
||||
$type = strtolower($type);
|
||||
|
||||
if($type == "png")
|
||||
{
|
||||
$result = imagepng( $image, $folder . $name . '.png' );
|
||||
@@ -210,10 +214,14 @@ class ProcessImage extends ProcessAssets
|
||||
{
|
||||
$result = imagegif( $image, $folder . $name . '.gif' );
|
||||
}
|
||||
elseif($type == "jpg" OR $type == "jpeg")
|
||||
{
|
||||
$result = imagejpeg( $image, $folder . $name . '.' . $type );
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = imagejpeg( $image, $folder . $name . '.jpeg' );
|
||||
$type = 'jpeg';
|
||||
# image type not supported
|
||||
return false;
|
||||
}
|
||||
|
||||
imagedestroy($image);
|
||||
@@ -339,12 +347,13 @@ class ProcessImage extends ProcessAssets
|
||||
{
|
||||
$this->setFileName($filename, 'image', $overwrite = true);
|
||||
|
||||
if($this->extension == 'jpeg') $this->extension = 'jpg';
|
||||
# if($this->extension == 'jpg') $this->extension = 'jpeg';
|
||||
|
||||
switch($this->extension)
|
||||
{
|
||||
case 'gif': $image = imagecreatefromgif($this->liveFolder . $filename); break;
|
||||
case 'jpg': $image = imagecreatefromjpeg($this->liveFolder . $filename); break;
|
||||
case 'jpg' :
|
||||
case 'jpeg': $image = imagecreatefromjpeg($this->liveFolder . $filename); break;
|
||||
case 'png': $image = imagecreatefrompng($this->liveFolder . $filename); break;
|
||||
default: return 'image type not supported';
|
||||
}
|
||||
@@ -367,12 +376,13 @@ class ProcessImage extends ProcessAssets
|
||||
{
|
||||
$this->setFileName($filename, 'image');
|
||||
|
||||
if($this->extension == 'jpeg') $this->extension = 'jpg';
|
||||
if($this->extension == 'jpg') $this->extension = 'jpeg';
|
||||
|
||||
switch($this->extension)
|
||||
{
|
||||
case 'gif': $image = imagecreatefromgif($image); break;
|
||||
case 'jpg': $image = imagecreatefromjpeg($image); break;
|
||||
case 'jpg' :
|
||||
case 'jpeg': $image = imagecreatefromjpeg($image); break;
|
||||
case 'png': $image = imagecreatefrompng($image); break;
|
||||
default: return 'image type not supported';
|
||||
}
|
||||
@@ -383,5 +393,4 @@ class ProcessImage extends ProcessAssets
|
||||
|
||||
return $resizedImages;
|
||||
}
|
||||
|
||||
}
|
348
system/Models/WriteMeta.php
Normal file
348
system/Models/WriteMeta.php
Normal file
@@ -0,0 +1,348 @@
|
||||
<?php
|
||||
|
||||
namespace Typemill\Models;
|
||||
|
||||
use Typemill\Extensions\ParsedownExtension;
|
||||
|
||||
class WriteMeta extends WriteYaml
|
||||
{
|
||||
# used by contentApiController (backend) and pageController (frontend) and TwigMetaExtension (list pages)
|
||||
public function getPageMeta($settings, $item)
|
||||
{
|
||||
$meta = $this->getYaml($settings['contentFolder'], $item->pathWithoutType . '.yaml');
|
||||
|
||||
if(!$meta)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
# compare with meta that are in use right now (e.g. changed theme, disabled plugin)
|
||||
$metascheme = $this->getYaml('cache', 'metatabs.yaml');
|
||||
|
||||
if($metascheme)
|
||||
{
|
||||
$meta = $this->whitelistMeta($meta,$metascheme);
|
||||
}
|
||||
|
||||
$meta = $this->addFileTimeToMeta($meta, $item, $settings);
|
||||
|
||||
return $meta;
|
||||
}
|
||||
|
||||
# cases are rare: updates from old version prior 1.3.4 or if content-files are added manually, e.g. by ftp
|
||||
public function getPageMetaDefaults($content, $settings, $item)
|
||||
{
|
||||
# initialize parsedown extension
|
||||
$parsedown = new ParsedownExtension();
|
||||
|
||||
# if content is not an array, then transform it
|
||||
if(!is_array($content))
|
||||
{
|
||||
# turn markdown into an array of markdown-blocks
|
||||
$content = $parsedown->markdownToArrayBlocks($content);
|
||||
}
|
||||
|
||||
$title = false;
|
||||
|
||||
# delete markdown from title
|
||||
if(isset($content[0]))
|
||||
{
|
||||
$title = trim($content[0], "# ");
|
||||
}
|
||||
|
||||
$description = $this->generateDescription($content, $parsedown, $item);
|
||||
|
||||
$author = $settings['author'];
|
||||
|
||||
if(isset($_SESSION))
|
||||
{
|
||||
if(isset($_SESSION['firstname']) && $_SESSION['firstname'] !='' && isset($_SESSION['lastname']) && $_SESSION['lastname'] != '')
|
||||
{
|
||||
$author = $_SESSION['firstname'] . ' ' . $_SESSION['lastname'];
|
||||
}
|
||||
elseif(isset($_SESSION['user']))
|
||||
{
|
||||
$author = $_SESSION['user'];
|
||||
}
|
||||
}
|
||||
|
||||
# create new meta-file
|
||||
$meta = [
|
||||
'meta' => [
|
||||
'title' => $title,
|
||||
'description' => $description,
|
||||
'author' => $author,
|
||||
'created' => date("Y-m-d"),
|
||||
'time' => date("H-i-s"),
|
||||
'navtitle' => $item->name,
|
||||
]
|
||||
];
|
||||
|
||||
$meta = $this->addFileTimeToMeta($meta, $item, $settings);
|
||||
|
||||
$this->updateYaml($settings['contentFolder'], $item->pathWithoutType . '.yaml', $meta);
|
||||
|
||||
return $meta;
|
||||
}
|
||||
|
||||
# used by MetaApiController. Do not set title or description in defaults if page is not published yet
|
||||
public function getPageMetaBlank($content, $settings, $item)
|
||||
{
|
||||
$author = $settings['author'];
|
||||
|
||||
if(isset($_SESSION))
|
||||
{
|
||||
if(isset($_SESSION['firstname']) && $_SESSION['firstname'] !='' && isset($_SESSION['lastname']) && $_SESSION['lastname'] != '')
|
||||
{
|
||||
$author = $_SESSION['firstname'] . ' ' . $_SESSION['lastname'];
|
||||
}
|
||||
elseif(isset($_SESSION['user']))
|
||||
{
|
||||
$author = $_SESSION['user'];
|
||||
}
|
||||
}
|
||||
|
||||
# create new meta-file
|
||||
$meta = [
|
||||
'meta' => [
|
||||
'title' => '',
|
||||
'description' => '',
|
||||
'author' => $author,
|
||||
'created' => date("Y-m-d"),
|
||||
'time' => date("H-i-s"),
|
||||
'navtitle' => $item->name
|
||||
]
|
||||
];
|
||||
|
||||
$meta = $this->addFileTimeToMeta($meta, $item, $settings);
|
||||
|
||||
$this->updateYaml($settings['contentFolder'], $item->pathWithoutType . '.yaml', $meta);
|
||||
|
||||
return $meta;
|
||||
}
|
||||
|
||||
public function getNavtitle($url)
|
||||
{
|
||||
# get the extended structure where the navigation title is stored
|
||||
$extended = $this->getYaml('cache', 'structure-extended.yaml');
|
||||
|
||||
if(isset($extended[$url]['navtitle']))
|
||||
{
|
||||
return $extended[$url]['navtitle'];
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
# used by articleApiController and pageController to add title and description if an article is published
|
||||
public function completePageMeta($content, $settings, $item)
|
||||
{
|
||||
$meta = $this->getPageMeta($settings, $item);
|
||||
|
||||
if(!$meta)
|
||||
{
|
||||
return $this->getPageMetaDefaults($content, $settings, $item);
|
||||
}
|
||||
|
||||
$title = (isset($meta['meta']['title']) AND $meta['meta']['title'] !== '') ? true : false;
|
||||
$description = (isset($meta['meta']['description']) AND $meta['meta']['description'] !== '') ? true : false;
|
||||
|
||||
if($title && $description)
|
||||
{
|
||||
return $meta;
|
||||
}
|
||||
|
||||
# initialize parsedown extension
|
||||
$parsedown = new ParsedownExtension();
|
||||
|
||||
# if content is not an array, then transform it
|
||||
if(!is_array($content))
|
||||
{
|
||||
# turn markdown into an array of markdown-blocks
|
||||
$content = $parsedown->markdownToArrayBlocks($content);
|
||||
}
|
||||
|
||||
# delete markdown from title
|
||||
if(!$title && isset($content[0]))
|
||||
{
|
||||
$meta['meta']['title'] = trim($content[0], "# ");
|
||||
}
|
||||
|
||||
if(!$description && isset($content[1]))
|
||||
{
|
||||
$meta['meta']['description'] = $this->generateDescription($content, $parsedown, $item);
|
||||
}
|
||||
|
||||
$this->updateYaml($settings['contentFolder'], $item->pathWithoutType . '.yaml', $meta);
|
||||
|
||||
return $meta;
|
||||
}
|
||||
|
||||
private function whitelistMeta($meta, $metascheme)
|
||||
{
|
||||
# we have only 2 dimensions, so no recursive needed
|
||||
foreach($meta as $tab => $values)
|
||||
{
|
||||
if(!isset($metascheme[$tab]))
|
||||
{
|
||||
unset($meta[$tab]);
|
||||
}
|
||||
foreach($values as $key => $value)
|
||||
{
|
||||
if(!isset($metascheme[$tab][$key]))
|
||||
{
|
||||
unset($meta[$tab][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $meta;
|
||||
}
|
||||
|
||||
private function addFileTimeToMeta($meta, $item, $settings)
|
||||
{
|
||||
$filePath = $settings['contentFolder'] . $item->path;
|
||||
$fileType = isset($item->fileType) ? $item->fileType : 'md';
|
||||
|
||||
# check if url is a folder.
|
||||
if($item->elementType == 'folder')
|
||||
{
|
||||
$filePath = $settings['contentFolder'] . $item->path . DIRECTORY_SEPARATOR . 'index.'. $fileType;
|
||||
}
|
||||
|
||||
# add the modified date for the file
|
||||
$meta['meta']['modified'] = file_exists($filePath) ? date("Y-m-d",filemtime($filePath)) : date("Y-m-d");
|
||||
|
||||
return $meta;
|
||||
}
|
||||
|
||||
public function generateDescription($content, $parsedown, $item)
|
||||
{
|
||||
$description = isset($content[1]) ? $content[1] : '';
|
||||
|
||||
# create description or abstract from content
|
||||
if($description !== '')
|
||||
{
|
||||
$firstLineArray = $parsedown->text($description);
|
||||
$description = strip_tags($parsedown->markup($firstLineArray, $item->urlAbs));
|
||||
|
||||
# if description is very short
|
||||
if(strlen($description) < 100 && isset($content[2]))
|
||||
{
|
||||
$secondLineArray = $parsedown->text($content[2]);
|
||||
$description .= ' ' . strip_tags($parsedown->markup($secondLineArray, $item->urlAbs));
|
||||
}
|
||||
|
||||
# if description is too long
|
||||
if(strlen($description) > 300)
|
||||
{
|
||||
$description = substr($description, 0, 300);
|
||||
$lastSpace = strrpos($description, ' ');
|
||||
$description = substr($description, 0, $lastSpace);
|
||||
}
|
||||
}
|
||||
return $description;
|
||||
}
|
||||
|
||||
public function transformPagesToPosts($folder){
|
||||
|
||||
$filetypes = array('md', 'txt', 'yaml');
|
||||
|
||||
foreach($folder->folderContent as $page)
|
||||
{
|
||||
# create old filename without filetype
|
||||
$oldFile = $this->basePath . 'content' . $page->pathWithoutType;
|
||||
|
||||
# set default date
|
||||
$date = date('Y-m-d', time());
|
||||
$time = date('H-i', time());
|
||||
|
||||
$meta = $this->getYaml('content', $page->pathWithoutType . '.yaml');
|
||||
|
||||
if($meta)
|
||||
{
|
||||
# get dates from meta
|
||||
if(isset($meta['meta']['manualdate'])){ $date = $meta['meta']['manualdate']; }
|
||||
elseif(isset($meta['meta']['created'])){ $date = $meta['meta']['created']; }
|
||||
elseif(isset($meta['meta']['modified'])){ $date = $meta['meta']['modified']; }
|
||||
|
||||
# set time
|
||||
if(isset($meta['meta']['time']))
|
||||
{
|
||||
$time = $meta['meta']['time'];
|
||||
}
|
||||
}
|
||||
|
||||
$datetime = $date . '-' . $time;
|
||||
$datetime = implode(explode('-', $datetime));
|
||||
$datetime = substr($datetime,0,12);
|
||||
|
||||
# create new file-name without filetype
|
||||
$newFile = $this->basePath . 'content' . $folder->path . DIRECTORY_SEPARATOR . $datetime . '-' . $page->slug;
|
||||
|
||||
$result = true;
|
||||
|
||||
foreach($filetypes as $filetype)
|
||||
{
|
||||
$oldFilePath = $oldFile . '.' . $filetype;
|
||||
$newFilePath = $newFile . '.' . $filetype;
|
||||
|
||||
#check if file with filetype exists and rename
|
||||
if($oldFilePath != $newFilePath && file_exists($oldFilePath))
|
||||
{
|
||||
if(@rename($oldFilePath, $newFilePath))
|
||||
{
|
||||
$result = $result;
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function transformPostsToPages($folder){
|
||||
|
||||
$filetypes = array('md', 'txt', 'yaml');
|
||||
$index = 0;
|
||||
|
||||
foreach($folder->folderContent as $page)
|
||||
{
|
||||
# create old filename without filetype
|
||||
$oldFile = $this->basePath . 'content' . $page->pathWithoutType;
|
||||
|
||||
$order = $index;
|
||||
|
||||
if($index < 10)
|
||||
{
|
||||
$order = '0' . $index;
|
||||
}
|
||||
|
||||
# create new file-name without filetype
|
||||
$newFile = $this->basePath . 'content' . $folder->path . DIRECTORY_SEPARATOR . $order . '-' . $page->slug;
|
||||
|
||||
$result = true;
|
||||
|
||||
foreach($filetypes as $filetype)
|
||||
{
|
||||
$oldFilePath = $oldFile . '.' . $filetype;
|
||||
$newFilePath = $newFile . '.' . $filetype;
|
||||
|
||||
#check if file with filetype exists and rename
|
||||
if($oldFilePath != $newFilePath && file_exists($oldFilePath))
|
||||
{
|
||||
if(@rename($oldFilePath, $newFilePath))
|
||||
{
|
||||
$result = $result;
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$index++;
|
||||
}
|
||||
}
|
||||
}
|
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace Typemill\Models;
|
||||
|
||||
use Typemill\Extensions\ParsedownExtension;
|
||||
|
||||
class WriteYaml extends Write
|
||||
{
|
||||
/**
|
||||
@@ -37,235 +35,4 @@ class WriteYaml extends Write
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
# used by contentApiController (backend) and pageController (frontend)
|
||||
public function getPageMeta($settings, $item)
|
||||
{
|
||||
$meta = $this->getYaml($settings['contentFolder'], $item->pathWithoutType . '.yaml');
|
||||
|
||||
if(!$meta)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
# compare with meta that are in use right now (e.g. changed theme, disabled plugin)
|
||||
$metascheme = $this->getYaml('cache', 'metatabs.yaml');
|
||||
|
||||
if($metascheme)
|
||||
{
|
||||
$meta = $this->whitelistMeta($meta,$metascheme);
|
||||
}
|
||||
|
||||
$meta = $this->addFileTimeToMeta($meta, $item, $settings);
|
||||
|
||||
return $meta;
|
||||
}
|
||||
|
||||
# used by contentApiController (backend) and pageController (frontend)
|
||||
public function getPageMetaDefaults($content, $settings, $item)
|
||||
{
|
||||
# initialize parsedown extension
|
||||
$parsedown = new ParsedownExtension();
|
||||
|
||||
# if content is not an array, then transform it
|
||||
if(!is_array($content))
|
||||
{
|
||||
# turn markdown into an array of markdown-blocks
|
||||
$content = $parsedown->markdownToArrayBlocks($content);
|
||||
}
|
||||
|
||||
$title = false;
|
||||
|
||||
# delete markdown from title
|
||||
if(isset($content[0]))
|
||||
{
|
||||
$title = trim($content[0], "# ");
|
||||
}
|
||||
|
||||
$description = false;
|
||||
|
||||
# delete markdown from title
|
||||
if(isset($content[1]))
|
||||
{
|
||||
$firstLineArray = $parsedown->text($content[1]);
|
||||
$description = strip_tags($parsedown->markup($firstLineArray, $item->urlAbs));
|
||||
$description = substr($description, 0, 300);
|
||||
$lastSpace = strrpos($description, ' ');
|
||||
$description = substr($description, 0, $lastSpace);
|
||||
}
|
||||
|
||||
$author = $settings['author'];
|
||||
|
||||
if(isset($_SESSION))
|
||||
{
|
||||
if(isset($_SESSION['firstname']) && $_SESSION['firstname'] !='' && isset($_SESSION['lastname']) && $_SESSION['lastname'] != '')
|
||||
{
|
||||
$author = $_SESSION['firstname'] . ' ' . $_SESSION['lastname'];
|
||||
}
|
||||
elseif(isset($_SESSION['user']))
|
||||
{
|
||||
$author = $_SESSION['user'];
|
||||
}
|
||||
}
|
||||
|
||||
# create new meta-file
|
||||
$meta = [
|
||||
'meta' => [
|
||||
'title' => $title,
|
||||
'description' => $description,
|
||||
'author' => $author,
|
||||
'created' => date("Y-m-d"),
|
||||
'time' => date("H-i-s"),
|
||||
]
|
||||
];
|
||||
|
||||
$this->updateYaml($settings['contentFolder'], $item->pathWithoutType . '.yaml', $meta);
|
||||
|
||||
$meta = $this->addFileTimeToMeta($meta, $item, $settings);
|
||||
|
||||
return $meta;
|
||||
}
|
||||
|
||||
|
||||
private function whitelistMeta($meta, $metascheme)
|
||||
{
|
||||
# we have only 2 dimensions, so no recursive needed
|
||||
foreach($meta as $tab => $values)
|
||||
{
|
||||
if(!isset($metascheme[$tab]))
|
||||
{
|
||||
unset($meta[$tab]);
|
||||
}
|
||||
foreach($values as $key => $value)
|
||||
{
|
||||
if(!isset($metascheme[$tab][$key]))
|
||||
{
|
||||
unset($meta[$tab][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $meta;
|
||||
}
|
||||
|
||||
private function addFileTimeToMeta($meta, $item, $settings)
|
||||
{
|
||||
$filePath = $settings['contentFolder'] . $item->path;
|
||||
$fileType = isset($item->fileType) ? $item->fileType : 'md';
|
||||
|
||||
# check if url is a folder.
|
||||
if($item->elementType == 'folder')
|
||||
{
|
||||
$filePath = $settings['contentFolder'] . $item->path . DIRECTORY_SEPARATOR . 'index.'. $fileType;
|
||||
}
|
||||
|
||||
# add the modified date for the file
|
||||
$meta['meta']['modified'] = file_exists($filePath) ? date("Y-m-d",filemtime($filePath)) : false;
|
||||
|
||||
return $meta;
|
||||
}
|
||||
|
||||
|
||||
public function transformPagesToPosts($folder){
|
||||
|
||||
$filetypes = array('md', 'txt', 'yaml');
|
||||
|
||||
foreach($folder->folderContent as $page)
|
||||
{
|
||||
# create old filename without filetype
|
||||
$oldFile = $this->basePath . 'content' . $page->pathWithoutType;
|
||||
|
||||
# set default date
|
||||
$date = date('Y-m-d', time());
|
||||
$time = date('H-i', time());
|
||||
|
||||
$meta = $this->getYaml('content', $page->pathWithoutType . '.yaml');
|
||||
|
||||
if($meta)
|
||||
{
|
||||
# get dates from meta
|
||||
if(isset($meta['meta']['manualdate'])){ $date = $meta['meta']['manualdate']; }
|
||||
elseif(isset($meta['meta']['created'])){ $date = $meta['meta']['created']; }
|
||||
elseif(isset($meta['meta']['modified'])){ $date = $meta['meta']['modified']; }
|
||||
|
||||
# set time
|
||||
if(isset($meta['meta']['time']))
|
||||
{
|
||||
$time = $meta['meta']['time'];
|
||||
}
|
||||
}
|
||||
|
||||
$datetime = $date . '-' . $time;
|
||||
$datetime = implode(explode('-', $datetime));
|
||||
$datetime = substr($datetime,0,12);
|
||||
|
||||
# create new file-name without filetype
|
||||
$newFile = $this->basePath . 'content' . $folder->path . DIRECTORY_SEPARATOR . $datetime . '-' . $page->slug;
|
||||
|
||||
$result = true;
|
||||
|
||||
foreach($filetypes as $filetype)
|
||||
{
|
||||
$oldFilePath = $oldFile . '.' . $filetype;
|
||||
$newFilePath = $newFile . '.' . $filetype;
|
||||
|
||||
#check if file with filetype exists and rename
|
||||
if($oldFilePath != $newFilePath && file_exists($oldFilePath))
|
||||
{
|
||||
if(@rename($oldFilePath, $newFilePath))
|
||||
{
|
||||
$result = $result;
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function transformPostsToPages($folder){
|
||||
|
||||
$filetypes = array('md', 'txt', 'yaml');
|
||||
$index = 0;
|
||||
|
||||
foreach($folder->folderContent as $page)
|
||||
{
|
||||
# create old filename without filetype
|
||||
$oldFile = $this->basePath . 'content' . $page->pathWithoutType;
|
||||
|
||||
$order = $index;
|
||||
|
||||
if($index < 10)
|
||||
{
|
||||
$order = '0' . $index;
|
||||
}
|
||||
|
||||
# create new file-name without filetype
|
||||
$newFile = $this->basePath . 'content' . $folder->path . DIRECTORY_SEPARATOR . $order . '-' . $page->slug;
|
||||
|
||||
$result = true;
|
||||
|
||||
foreach($filetypes as $filetype)
|
||||
{
|
||||
$oldFilePath = $oldFile . '.' . $filetype;
|
||||
$newFilePath = $newFile . '.' . $filetype;
|
||||
|
||||
#check if file with filetype exists and rename
|
||||
if($oldFilePath != $newFilePath && file_exists($oldFilePath))
|
||||
{
|
||||
if(@rename($oldFilePath, $newFilePath))
|
||||
{
|
||||
$result = $result;
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$index++;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user