1
0
mirror of https://github.com/typemill/typemill.git synced 2025-08-09 23:58:08 +02:00

Version 1.2.5: Create Pages

This commit is contained in:
Sebastian
2018-10-06 23:23:22 +02:00
parent 065a01c2fd
commit 77985ccacb
85 changed files with 624 additions and 163 deletions

View File

@@ -54,6 +54,16 @@ class Validation
if(!$email){ return false; }
return true;
}, 'unknown');
Validator::addRule('noSpecialChars', function($field, $value, array $params, array $fields)
{
$format = '/[!@#$%^&*()_+=\[\]{};\':"\\|,.<>\/?]/';
if ( preg_match($format, $value))
{
return false;
}
return true;
}, 'contains special characters');
Validator::addRule('noHTML', function($field, $value, array $params, array $fields)
{
@@ -241,6 +251,33 @@ class Validation
return $v->errors();
}
}
/**
* validation for new navigation items
*
* @param array $params with form data.
* @return true or $v->errors with array of errors to use in json-response
*/
public function navigationItem(array $params)
{
$v = new Validator($params);
$v->rule('required', ['folder_id', 'item_name', 'type', 'url']);
$v->rule('regex', 'folder_id', '/^[0-9.]+$/i');
$v->rule('noSpecialChars', 'item_name');
$v->rule('lengthBetween', 'item_name', 1, 20);
$v->rule('in', 'type', ['file', 'folder']);
if($v->validate())
{
return true;
}
else
{
return $v->errors();
}
}
/**
* validation for dynamic fields ( settings for themes and plugins)

View File

@@ -15,7 +15,7 @@ class Write
public function checkPath($folder)
{
$folderPath = $this->basePath . $folder;
if(!is_dir($folderPath))
{
if(@mkdir($folderPath, 0774, true))
@@ -55,6 +55,7 @@ class Write
if($this->checkPath($folder))
{
$filePath = $this->basePath . $folder . DIRECTORY_SEPARATOR . $file;
$openFile = @fopen($filePath, "w");
if(!$openFile)
@@ -79,7 +80,7 @@ class Write
}
return false;
}
public function moveElement($item, $folderPath, $index)
{
$filetypes = array('md', 'txt');
@@ -88,7 +89,7 @@ class Write
$newOrder = ($index < 10) ? '0' . $index : $index;
# create new path with foldername or filename but without file-type
$newPath = $this->basePath . 'content' . $folderPath . DIRECTORY_SEPARATOR . $newOrder . '-' . $item->name;
$newPath = $this->basePath . 'content' . $folderPath . DIRECTORY_SEPARATOR . $newOrder . '-' . str_replace(" ", "-", $item->name);
if($item->elementType == 'folder')
{
@@ -125,58 +126,6 @@ class Write
}
}
return $result;
/*
if($item->elementType == 'folder')
{
$newName = $newOrder . '-' . $item->name;
}
else
{
$newName = $newOrder . '-' . $item->name . '.' . $item->fileType;
}
$oldPath = $this->basePath . 'content' . $item->path;
$newPath = $this->basePath . 'content' . $folderPath . DIRECTORY_SEPARATOR . $newName;
if(@rename($oldPath, $newPath))
{
$result = true;
}
foreach($filetypes as $filetype)
{
#check if file exists
if(file_exists($oldPath))
{
}
}
# if it is a txt file, check, if there is a corresponding .md file and move it
if($result && $item->elementType == 'file' && $item->fileType == 'txt')
{
$result = false;
$oldPath = substr($item->path, 0, strpos($item->path, "."));
$oldPath = $this->basePath . 'content' . $oldPath . '.md';
if(file_exists($oldPath))
{
$newName = $newOrder . '-' . $item->name . '.md';
$newPath = $this->basePath . 'content' . $folderPath . DIRECTORY_SEPARATOR . $newName;
if(@rename($oldPath, $newPath))
{
$result = true;
}
}
}
return $result;
*/
return $result;
}
}