1
0
mirror of https://github.com/typemill/typemill.git synced 2025-08-06 14:16:46 +02:00

Version 1.2.8 Image Management

This commit is contained in:
Sebastian
2018-12-03 10:39:55 +01:00
parent d87fe9d0d9
commit 979ebebe1b
41 changed files with 1060 additions and 341 deletions

View File

@@ -6,6 +6,7 @@ use Slim\Http\Request;
use Slim\Http\Response;
use Typemill\Models\Folder;
use Typemill\Models\Write;
use Typemill\Models\ProcessImage;
use Typemill\Extensions\ParsedownExtension;
class ContentApiController extends ContentController
@@ -755,6 +756,7 @@ class ContentApiController extends ContentController
/* get params from call */
$this->params = $request->getParams();
$this->uri = $request->getUri();
$errors = false;
# set structure
if(!$this->setStructure($draft = true)){ return $response->withJson(array('data' => false, 'errors' => $this->errors), 404); }
@@ -792,6 +794,25 @@ class ContentApiController extends ContentController
# check if id exists
if(!isset($this->content[$this->params['block_id']])){ return $response->withJson(array('data' => false, 'errors' => 'The ID of the content-block is wrong.'), 404); }
# check if block is image
$contentBlock = $this->content[$this->params['block_id']];
$contentBlockStart = substr($contentBlock, 0, 2);
if($contentBlockStart == '[!' OR $contentBlockStart == '![')
{
# extract image path
preg_match("/\((.*?)\)/",$contentBlock,$matches);
if(isset($matches[1]))
{
$imageBaseName = explode('-', $matches[1]);
$imageBaseName = str_replace('media/live/', '', $imageBaseName[0]);
$processImage = new ProcessImage();
if(!$processImage->deleteImage($imageBaseName))
{
$errors = 'Could not delete some of the images, please check manually';
}
}
}
# delete the block
unset($this->content[$this->params['block_id']]);
$this->content = array_values($this->content);
@@ -821,6 +842,41 @@ class ContentApiController extends ContentController
return $response->withJson(['errors' => ['message' => 'Could not write to file. Please check if the file is writable']], 404);
}
return $response->withJson(array('markdown' => $pageMarkdown, 'errors' => false));
return $response->withJson(array('markdown' => $pageMarkdown, 'errors' => $errors));
}
public function createImage(Request $request, Response $response, $args)
{
/* get params from call */
$this->params = $request->getParams();
$this->uri = $request->getUri();
$imageProcessor = new ProcessImage();
if($imageProcessor->createImage($this->params['image'], $this->settings['images'], $name = false))
{
return $response->withJson(array('errors' => false));
}
return $response->withJson(array('errors' => 'could not store image to temporary folder'));
}
public function publishImage(Request $request, Response $response, $args)
{
$params = $request->getParsedBody();
$imageProcessor = new ProcessImage();
$imageUrl = $imageProcessor->publishImage($this->settings['images'], $name = false);
if($imageUrl)
{
$params['markdown'] = str_replace('imgplchldr', $imageUrl, $params['markdown']);
$request = $request->withParsedBody($params);
return $this->updateBlock($request, $response, $args);
}
return $response->withJson(array('errors' => 'could not store image to temporary folder'));
}
}

View File

@@ -23,7 +23,7 @@ class ContentBackendController extends ContentController
# get params from call
$this->uri = $request->getUri();
$this->params = isset($args['params']) ? ['url' => $this->uri->getBasePath() . '/' . $args['params']] : ['url' => $this->uri->getBasePath()];
# set structure
if(!$this->setStructure($draft = true)){ return $this->renderIntern404($response, array( 'navigation' => true, 'content' => $this->errors )); }
@@ -71,7 +71,7 @@ class ContentBackendController extends ContentController
$content = trim($contentParts[1]);
}
}
return $this->render($response, 'editor/editor-raw.twig', array('navigation' => $this->structure, 'title' => $title, 'content' => $content, 'item' => $this->item, 'settings' => $this->settings ));
}
@@ -85,6 +85,7 @@ class ContentBackendController extends ContentController
public function showBlox(Request $request, Response $response, $args)
{
# get params from call
$this->uri = $request->getUri();
$this->params = isset($args['params']) ? ['url' => $this->uri->getBasePath() . '/' . $args['params']] : ['url' => $this->uri->getBasePath()];
@@ -100,7 +101,7 @@ class ContentBackendController extends ContentController
# set the status for published and drafted
$this->setPublishStatus();
# set path
$this->setItemPath($this->item->fileType);
@@ -133,12 +134,16 @@ class ContentBackendController extends ContentController
$contentArray = $parsedown->text($block);
/* parse markdown-content-array to content-string */
$content[$key] = $parsedown->markup($contentArray);
$content[$key] = $parsedown->markup($contentArray);
}
# extract title and delete from content array, array will start at 1 after that.
$title = $content[0];
unset($content[0]);
$title = '# add title';
if(isset($content[0]))
{
$title = $content[0];
unset($content[0]);
}
return $this->render($response, 'editor/editor-blox.twig', array('navigation' => $this->structure, 'title' => $title, 'content' => $content, 'item' => $this->item, 'settings' => $this->settings ));
}

View File

@@ -95,7 +95,7 @@ class SettingsController extends Controller
/* store them as default theme data with author, year, default settings and field-definitions */
$themedata[$themeName] = $themeSettings;
}
if(isset($themeSettings['forms']['fields']))
{
$fields = $this->getFields($userSettings, 'themes', $themeName, $themeSettings);
@@ -271,6 +271,12 @@ class SettingsController extends Controller
$themeName = isset($params['theme']) ? $params['theme'] : false;
$userInput = isset($params[$themeName]) ? $params[$themeName] : false;
$validate = new Validation();
$themeSettings = \Typemill\Settings::getObjectSettings('themes', $themeName);
if(isset($themeSettings['settings']['images']))
{
$userSettings = ['images' => $themeSettings['settings']['images']];
}
/* set theme name and delete theme settings from user settings for the case, that the new theme has no settings */
$userSettings['theme'] = $themeName;