123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841 |
- <?php
- namespace Typemill\Controllers;
- use Slim\Http\Request;
- use Slim\Http\Response;
- use Typemill\Models\Folder;
- use Typemill\Models\Write;
- use Typemill\Models\WriteYaml;
- use Typemill\Models\ProcessImage;
- use Typemill\Models\ProcessFile;
- use Typemill\Extensions\ParsedownExtension;
- use \URLify;
- class BlockApiController extends ContentController
- {
- public function addBlock(Request $request, Response $response, $args)
- {
- /* get params from call */
- $this->params = $request->getParams();
- $this->uri = $request->getUri();
- /* validate input */
- if(!$this->validateBlockInput()){ return $response->withJson($this->errors,422); }
-
- # set structure
- if(!$this->setStructure($draft = true)){ return $response->withJson(array('data' => false, 'errors' => $this->errors), 404); }
-
- /* set item */
- if(!$this->setItem()){ return $response->withJson($this->errors, 404); }
- # set the status for published and drafted
- $this->setPublishStatus();
- # set path
- $this->setItemPath($this->item->fileType);
- # read content from file
- if(!$this->setContent()){ return $response->withJson(array('data' => false, 'errors' => $this->errors), 404); }
- # make it more clear which content we have
- $pageMarkdown = $this->content;
- $blockMarkdown = $this->params['markdown'];
- # standardize line breaks
- $blockMarkdown = str_replace(array("\r\n", "\r"), "\n", $blockMarkdown);
- # remove surrounding line breaks
- $blockMarkdown = trim($blockMarkdown, "\n");
-
- if($pageMarkdown == '')
- {
- $pageMarkdown = [];
- }
- # initialize parsedown extension
- $parsedown = new ParsedownExtension();
- # if content is not an array, then transform it
- if(!is_array($pageMarkdown))
- {
- # turn markdown into an array of markdown-blocks
- $pageMarkdown = $parsedown->markdownToArrayBlocks($pageMarkdown);
- }
- # if it is a new content-block
- if($this->params['block_id'] == 99999)
- {
- # set the id of the markdown-block (it will be one more than the actual array, so count is perfect)
- $id = count($pageMarkdown);
- # add the new markdown block to the page content
- $pageMarkdown[] = $blockMarkdown;
- }
- elseif(($this->params['block_id'] == 0) OR !isset($pageMarkdown[$this->params['block_id']]))
- {
- # if the block does not exists, return an error
- return $response->withJson(array('data' => false, 'errors' => 'The ID of the content-block is wrong.'), 404);
- }
- else
- {
- # insert new markdown block
- array_splice( $pageMarkdown, $this->params['block_id'], 0, $blockMarkdown );
- $id = $this->params['block_id'];
- }
-
- # encode the content into json
- $pageJson = json_encode($pageMarkdown);
- # set path for the file (or folder)
- $this->setItemPath('txt');
-
- /* update the file */
- if($this->write->writeFile($this->settings['contentFolder'], $this->path, $pageJson))
- {
- # update the internal structure
- $this->setStructure($draft = true, $cache = false);
- $this->content = $pageMarkdown;
- }
- else
- {
- return $response->withJson(['errors' => ['message' => 'Could not write to file. Please check if the file is writable']], 404);
- }
-
- /* set safe mode to escape javascript and html in markdown */
- $parsedown->setSafeMode(true);
- /* parse markdown-file to content-array */
- $blockArray = $parsedown->text($blockMarkdown);
-
- # we assume that toc is not relevant
- $toc = false;
- # needed for ToC links
- $relurl = '/tm/content/' . $this->settings['editor'] . '/' . $this->item->urlRel;
-
- if($blockMarkdown == '[TOC]')
- {
- # if block is table of content itself, then generate the table of content
- $tableofcontent = $this->generateToc();
- # and only use the html-markup
- $blockHTML = $tableofcontent['html'];
- }
- else
- {
- # parse markdown-content-array to content-string
- $blockHTML = $parsedown->markup($blockArray, $relurl);
-
- # if it is a headline
- if($blockMarkdown[0] == '#')
- {
- # then the TOC holds either false (if no toc used in the page) or it holds an object with the id and toc-markup
- $toc = $this->generateToc();
- }
- }
- return $response->withJson(array('content' => [ 'id' => $id, 'html' => $blockHTML ] , 'markdown' => $blockMarkdown, 'id' => $id, 'toc' => $toc, 'errors' => false));
- }
- protected function generateToc()
- {
- # we assume that page has no table of content
- $toc = false;
- # make sure $this->content is updated
- $content = $this->content;
- if($content == '')
- {
- $content = [];
- }
-
- # 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);
- }
-
- # needed for ToC links
- $relurl = '/tm/content/' . $this->settings['editor'] . '/' . $this->item->urlRel;
-
- # loop through mardkown-array and create html-blocks
- foreach($content as $key => $block)
- {
- # parse markdown-file to content-array
- $contentArray = $parsedown->text($block);
-
- if($block == '[TOC]')
- {
- # toc is true and holds the key of the table of content now
- $toc = $key;
- }
- # parse markdown-content-array to content-string
- $content[$key] = ['id' => $key, 'html' => $parsedown->markup($contentArray, $relurl)];
- }
- # if page has a table of content
- if($toc)
- {
- # generate the toc markup
- $tocMarkup = $parsedown->buildTOC($parsedown->headlines);
- # toc holds the id of the table of content and the html-markup now
- $toc = ['id' => $toc, 'html' => $tocMarkup];
- }
- return $toc;
- }
- public function updateBlock(Request $request, Response $response, $args)
- {
- /* get params from call */
- $this->params = $request->getParams();
- $this->uri = $request->getUri();
- /* validate input */
- if(!$this->validateBlockInput()){ return $response->withJson($this->errors,422); }
-
- # set structure
- if(!$this->setStructure($draft = true)){ return $response->withJson(array('data' => false, 'errors' => $this->errors), 404); }
-
- /* set item */
- if(!$this->setItem()){ return $response->withJson($this->errors, 404); }
- # set the status for published and drafted
- $this->setPublishStatus();
- # set path
- $this->setItemPath($this->item->fileType);
- # read content from file
- if(!$this->setContent()){ return $response->withJson(array('data' => false, 'errors' => $this->errors), 404); }
- # make it more clear which content we have
- $pageMarkdown = $this->content;
- $blockMarkdown = $this->params['markdown'];
- # standardize line breaks
- $blockMarkdown = str_replace(array("\r\n", "\r"), "\n", $blockMarkdown);
- # remove surrounding line breaks
- $blockMarkdown = trim($blockMarkdown, "\n");
- if($pageMarkdown == '')
- {
- $pageMarkdown = [];
- }
- # initialize parsedown extension
- $parsedown = new ParsedownExtension();
- $parsedown->setVisualMode();
- # if content is not an array, then transform it
- if(!is_array($pageMarkdown))
- {
- # turn markdown into an array of markdown-blocks
- $pageMarkdown = $parsedown->markdownToArrayBlocks($pageMarkdown);
- }
- if(!isset($pageMarkdown[$this->params['block_id']]))
- {
- # if the block does not exists, return an error
- return $response->withJson(array('data' => false, 'errors' => 'The ID of the content-block is wrong.'), 404);
- }
- elseif($this->params['block_id'] == 0)
- {
- # if it is the title, then delete the "# " if it exists
- $blockMarkdown = trim($blockMarkdown, "# ");
-
- # store the markdown-headline in a separate variable
- $blockMarkdownTitle = '# ' . $blockMarkdown;
-
- # add the markdown-headline to the page-markdown
- $pageMarkdown[0] = $blockMarkdownTitle;
- $id = 0;
- }
- else
- {
- # update the markdown block in the page content
- $pageMarkdown[$this->params['block_id']] = $blockMarkdown;
- $id = $this->params['block_id'];
- }
- # encode the content into json
- $pageJson = json_encode($pageMarkdown);
- # set path for the file (or folder)
- $this->setItemPath('txt');
-
- /* update the file */
- if($this->write->writeFile($this->settings['contentFolder'], $this->path, $pageJson))
- {
- # update the internal structure
- $this->setStructure($draft = true, $cache = false);
- # updated the content variable
- $this->content = $pageMarkdown;
- }
- else
- {
- return $response->withJson(['errors' => ['message' => 'Could not write to file. Please check if the file is writable']], 404);
- }
-
- /* parse markdown-file to content-array, if title parse title. */
- if($this->params['block_id'] == 0)
- {
- $blockArray = $parsedown->text($blockMarkdownTitle);
- }
- else
- {
- /* set safe mode to escape javascript and html in markdown */
- $parsedown->setSafeMode(true);
- $blockArray = $parsedown->text($blockMarkdown);
- }
-
- # we assume that toc is not relevant
- $toc = false;
- # needed for ToC links
- $relurl = '/tm/content/' . $this->settings['editor'] . '/' . $this->item->urlRel;
-
- if($blockMarkdown == '[TOC]')
- {
- # if block is table of content itself, then generate the table of content
- $tableofcontent = $this->generateToc();
- # and only use the html-markup
- $blockHTML = $tableofcontent['html'];
- }
- else
- {
- # parse markdown-content-array to content-string
- $blockHTML = $parsedown->markup($blockArray, $relurl);
-
- # if it is a headline
- if($blockMarkdown[0] == '#')
- {
- # then the TOC holds either false (if no toc used in the page) or it holds an object with the id and toc-markup
- $toc = $this->generateToc();
- }
- }
- return $response->withJson(array('content' => [ 'id' => $id, 'html' => $blockHTML ] , 'markdown' => $blockMarkdown, 'id' => $id, 'toc' => $toc, 'errors' => false));
- }
-
- public function moveBlock(Request $request, Response $response, $args)
- {
- # get params from call
- $this->params = $request->getParams();
- $this->uri = $request->getUri();
- # validate input
- # if(!$this->validateBlockInput()){ return $response->withJson($this->errors,422); }
-
- # set structure
- if(!$this->setStructure($draft = true)){ return $response->withJson(array('data' => false, 'errors' => $this->errors), 404); }
-
- # set item
- if(!$this->setItem()){ return $response->withJson($this->errors, 404); }
- # set the status for published and drafted
- $this->setPublishStatus();
- # set path
- $this->setItemPath($this->item->fileType);
- # read content from file
- if(!$this->setContent()){ return $response->withJson(array('data' => false, 'errors' => $this->errors), 404); }
- # make it more clear which content we have
- $pageMarkdown = $this->content;
-
- if($pageMarkdown == '')
- {
- $pageMarkdown = [];
- }
- # initialize parsedown extension
- $parsedown = new ParsedownExtension();
- # if content is not an array, then transform it
- if(!is_array($pageMarkdown))
- {
- # turn markdown into an array of markdown-blocks
- $pageMarkdown = $parsedown->markdownToArrayBlocks($pageMarkdown);
- }
- $oldIndex = ($this->params['old_index'] + 1);
- $newIndex = ($this->params['new_index'] + 1);
-
- if(!isset($pageMarkdown[$oldIndex]))
- {
- # if the block does not exists, return an error
- return $response->withJson(array('data' => false, 'errors' => 'The ID of the content-block is wrong.'), 404);
- }
- $extract = array_splice($pageMarkdown, $oldIndex, 1);
- array_splice($pageMarkdown, $newIndex, 0, $extract);
-
- # encode the content into json
- $pageJson = json_encode($pageMarkdown);
- # set path for the file (or folder)
- $this->setItemPath('txt');
-
- /* update the file */
- if($this->write->writeFile($this->settings['contentFolder'], $this->path, $pageJson))
- {
- # update the internal structure
- $this->setStructure($draft = true, $cache = false);
- # update this content
- $this->content = $pageMarkdown;
- }
- else
- {
- return $response->withJson(['errors' => ['message' => 'Could not write to file. Please check if the file is writable']], 404);
- }
- # we assume that toc is not relevant
- $toc = false;
- # needed for ToC links
- $relurl = '/tm/content/' . $this->settings['editor'] . '/' . $this->item->urlRel;
- # if the moved item is a headline
- if($extract[0][0] == '#')
- {
- $toc = $this->generateToc();
- }
- # if it is the title, then delete the "# " if it exists
- $pageMarkdown[0] = trim($pageMarkdown[0], "# ");
- return $response->withJson(array('markdown' => $pageMarkdown, 'toc' => $toc, 'errors' => false));
- }
- public function deleteBlock(Request $request, Response $response, $args)
- {
- /* 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); }
-
- # set item
- if(!$this->setItem()){ return $response->withJson($this->errors, 404); }
- # set the status for published and drafted
- $this->setPublishStatus();
- # set path
- $this->setItemPath($this->item->fileType);
- # read content from file
- if(!$this->setContent()){ return $response->withJson(array('data' => false, 'errors' => $this->errors), 404); }
- # get content
- $this->content;
- if($this->content == '')
- {
- $this->content = [];
- }
- # initialize parsedown extension
- $parsedown = new ParsedownExtension();
- # if content is not an array, then transform it
- if(!is_array($this->content))
- {
- # turn markdown into an array of markdown-blocks
- $this->content = $parsedown->markdownToArrayBlocks($this->content);
- }
- # 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); }
- $contentBlock = $this->content[$this->params['block_id']];
- # delete the block
- unset($this->content[$this->params['block_id']]);
- $this->content = array_values($this->content);
- $pageMarkdown = $this->content;
-
- # delete markdown from title
- if(isset($pageMarkdown[0]))
- {
- $pageMarkdown[0] = trim($pageMarkdown[0], "# ");
- }
-
- # encode the content into json
- $pageJson = json_encode($this->content);
- # set path for the file (or folder)
- $this->setItemPath('txt');
-
- /* update the file */
- if($this->write->writeFile($this->settings['contentFolder'], $this->path, $pageJson))
- {
- # update the internal structure
- $this->setStructure($draft = true, $cache = false);
- }
- else
- {
- return $response->withJson(['errors' => ['message' => 'Could not write to file. Please check if the file is writable']], 404);
- }
-
- $toc = false;
- if($contentBlock[0] == '#')
- {
- $toc = $this->generateToc();
- }
- return $response->withJson(array('markdown' => $pageMarkdown, 'toc' => $toc, 'errors' => $errors));
- }
- public function getMediaLibImages(Request $request, Response $response, $args)
- {
- # get params from call
- $this->params = $request->getParams();
- $this->uri = $request->getUri();
- $imageProcessor = new ProcessImage($this->settings['images']);
- if(!$imageProcessor->checkFolders('images'))
- {
- return $response->withJson(['errors' => ['message' => 'Please check if your media-folder exists and all folders inside are writable.']], 500);
- }
- $imagelist = $imageProcessor->scanMediaFlat();
- return $response->withJson(array('images' => $imagelist));
- }
- public function getMediaLibFiles(Request $request, Response $response, $args)
- {
- # get params from call
- $this->params = $request->getParams();
- $this->uri = $request->getUri();
- $fileProcessor = new ProcessFile();
- if(!$fileProcessor->checkFolders())
- {
- return $response->withJson(['errors' => ['message' => 'Please check if your media-folder exists and all folders inside are writable.']], 500);
- }
- $filelist = $fileProcessor->scanFilesFlat();
- return $response->withJson(array('files' => $filelist));
- }
- public function getImage(Request $request, Response $response, $args)
- {
- # get params from call
- $this->params = $request->getParams();
- $this->uri = $request->getUri();
- $this->setStructure($draft = true, $cache = false);
- $imageProcessor = new ProcessImage($this->settings['images']);
- if(!$imageProcessor->checkFolders('images'))
- {
- return $response->withJson(['errors' => ['message' => 'Please check if your media-folder exists and all folders inside are writable.']], 500);
- }
- $imageDetails = $imageProcessor->getImageDetails($this->params['name'], $this->structure);
- if($imageDetails)
- {
- return $response->withJson(array('image' => $imageDetails));
- }
-
- # return $response->withJson(array('image' => false, 'errors' => 'image name invalid or not found'));
- return $response->withJson(['errors' => ['message' => 'Image name invalid or not found.']], 404);
- }
- public function getFile(Request $request, Response $response, $args)
- {
- # get params from call
- $this->params = $request->getParams();
- $this->uri = $request->getUri();
- $this->setStructure($draft = true, $cache = false);
- $fileProcessor = new ProcessFile();
- if(!$fileProcessor->checkFolders())
- {
- return $response->withJson(['errors' => ['message' => 'Please check if your media-folder exists and all folders inside are writable.']], 500);
- }
- $fileDetails = $fileProcessor->getFileDetails($this->params['name'], $this->structure);
- if($fileDetails)
- {
- return $response->withJson(['file' => $fileDetails]);
- }
- return $response->withJson(['errors' => ['message' => 'file name invalid or not found']],404);
- }
- public function createImage(Request $request, Response $response, $args)
- {
- # get params from call
- $this->params = $request->getParams();
- $this->uri = $request->getUri();
-
- # do this shit in the model ...
- $imagename = explode('.', $this->params['name']);
- array_pop($imagename);
- $imagename = implode('-', $imagename);
- $name = URLify::filter(iconv(mb_detect_encoding($imagename, mb_detect_order(), true), "UTF-8", $imagename));
- $imageProcessor = new ProcessImage($this->settings['images']);
- if(!$imageProcessor->checkFolders('images'))
- {
- return $response->withJson(['errors' => ['message' => 'Please check if your media-folder exists and all folders inside are writable.']], 500);
- }
-
- if($imageProcessor->createImage($this->params['image'], $name, $this->settings['images']))
- {
- return $response->withJson(array('errors' => false));
- }
- return $response->withJson(array('errors' => 'could not store image to temporary folder'));
- }
- public function createFile(Request $request, Response $response, $args)
- {
- # get params from call
- $this->params = $request->getParams();
- $this->uri = $request->getUri();
- $finfo = finfo_open( FILEINFO_MIME_TYPE );
- $mtype = finfo_file( $finfo, $this->params['file'] );
- finfo_close( $finfo );
- $allowedMimes = $this->getAllowedMtypes();
- if(!in_array($mtype, $allowedMimes))
- {
- return $response->withJson(array('errors' => 'File-type is not allowed'));
- }
- # sanitize file name
- $filename = basename($this->params['name']);
- $filename = explode('.', $this->params['name']);
- array_pop($filename);
- $filename = implode('-', $filename);
- $name = URLify::filter(iconv(mb_detect_encoding($filename, mb_detect_order(), true), "UTF-8", $filename));
- $fileProcessor = new ProcessFile();
- if(!$fileProcessor->checkFolders())
- {
- return $response->withJson(['errors' => ['message' => 'Please check if your media-folder exists and all folders inside are writable.']], 500);
- }
-
- if($fileProcessor->createFile($this->params['file'], $name))
- {
- return $response->withJson(array('errors' => false, 'name' => $name));
- }
- return $response->withJson(array('errors' => 'could not store file to temporary folder'));
- }
-
- public function publishImage(Request $request, Response $response, $args)
- {
- $params = $request->getParsedBody();
- $imageProcessor = new ProcessImage($this->settings['images']);
- if(!$imageProcessor->checkFolders())
- {
- return $response->withJson(['errors' => ['message' => 'Please check if your media-folder exists and all folders inside are writable.']], 500);
- }
-
- $imageUrl = $imageProcessor->publishImage();
- if($imageUrl)
- {
- # replace the image placeholder in markdown with the image url
- $params['markdown'] = str_replace('imgplchldr', $imageUrl, $params['markdown']);
-
- $request = $request->withParsedBody($params);
-
- if($params['new'])
- {
- return $this->addBlock($request, $response, $args);
- }
- return $this->updateBlock($request, $response, $args);
- }
- return $response->withJson(array('errors' => 'could not store image to media folder'));
- }
- public function deleteImage(Request $request, Response $response, $args)
- {
- # get params from call
- $this->params = $request->getParams();
- $this->uri = $request->getUri();
- if(!isset($this->params['name']))
- {
- return $response->withJson(array('errors' => 'image name is missing'));
- }
- $imageProcessor = new ProcessImage($this->settings['images']);
- if(!$imageProcessor->checkFolders())
- {
- return $response->withJson(['errors' => ['message' => 'Please check if your media-folder exists and all folders inside are writable.']], 500);
- }
- $errors = $imageProcessor->deleteImage($this->params['name']);
- return $response->withJson(array('errors' => $errors));
- }
- public function deleteFile(Request $request, Response $response, $args)
- {
- # get params from call
- $this->params = $request->getParams();
- $this->uri = $request->getUri();
- if(!isset($this->params['name']))
- {
- return $response->withJson(array('errors' => 'file name is missing'));
- }
- $fileProcessor = new ProcessFile();
- $errors = false;
- if($fileProcessor->deleteFile($this->params['name']))
- {
- return $response->withJson(array('errors' => false));
- }
- return $response->withJson(array('errors' => 'could not delete the file'));
- }
- public function saveVideoImage(Request $request, Response $response, $args)
- {
- /* get params from call */
- $this->params = $request->getParams();
- $this->uri = $request->getUri();
- $class = false;
- $imageUrl = $this->params['markdown'];
-
- if(strpos($imageUrl, 'https://www.youtube.com/watch?v=') !== false)
- {
- $videoID = str_replace('https://www.youtube.com/watch?v=', '', $imageUrl);
- $videoID = strpos($videoID, '&') ? substr($videoID, 0, strpos($videoID, '&')) : $videoID;
- $class = 'youtube';
- }
- if(strpos($imageUrl, 'https://youtu.be/') !== false)
- {
- $videoID = str_replace('https://youtu.be/', '', $imageUrl);
- $videoID = strpos($videoID, '?') ? substr($videoID, 0, strpos($videoID, '?')) : $videoID;
- $class = 'youtube';
- }
-
- if($class == 'youtube')
- {
- $videoURLmaxres = 'https://i1.ytimg.com/vi/' . $videoID . '/maxresdefault.jpg';
- $videoURL0 = 'https://i1.ytimg.com/vi/' . $videoID . '/0.jpg';
- }
- $ctx = stream_context_create(array(
- 'https' => array(
- 'timeout' => 1
- )
- )
- );
-
- $imageData = @file_get_contents($videoURLmaxres, 0, $ctx);
- if($imageData === false)
- {
- $imageData = @file_get_contents($videoURL0, 0, $ctx);
- if($imageData === false)
- {
- return $response->withJson(array('errors' => 'could not get the video image'));
- }
- }
-
- $imageData64 = 'data:image/jpeg;base64,' . base64_encode($imageData);
- $desiredSizes = ['live' => ['width' => 560, 'height' => 315]];
- $imageProcessor = new ProcessImage($this->settings['images']);
- if(!$imageProcessor->checkFolders())
- {
- return $response->withJson(['errors' => ['message' => 'Please check if your media-folder exists and all folders inside are writable.']], 500);
- }
- $tmpImage = $imageProcessor->createImage($imageData64, $desiredSizes);
-
- if(!$tmpImage)
- {
- return $response->withJson(array('errors' => 'could not create temporary image'));
- }
-
- $imageUrl = $imageProcessor->publishImage($desiredSizes, $videoID);
- if($imageUrl)
- {
- $this->params['markdown'] = '{#' . $videoID. ' .' . $class . '}';
- $request = $request->withParsedBody($this->params);
-
- if($this->params['new'])
- {
- return $this->addBlock($request, $response, $args);
- }
- return $this->updateBlock($request, $response, $args);
- }
-
- return $response->withJson(array('errors' => 'could not store the preview image'));
- }
- private function getAllowedMtypes()
- {
- return array(
- 'application/zip',
- 'application/gzip',
- 'application/vnd.rar',
- 'application/vnd.visio',
- 'application/vnd.ms-excel',
- 'application/vnd.ms-powerpoint',
- 'application/vnd.ms-word.document.macroEnabled.12',
- 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
- 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
- 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
- 'application/vnd.apple.keynote',
- 'application/vnd.apple.mpegurl',
- 'application/vnd.apple.numbers',
- 'application/vnd.apple.pages',
- 'application/vnd.amazon.mobi8-ebook',
- 'application/epub+zip',
- 'application/pdf',
- 'image/png',
- 'image/jpeg',
- 'image/gif',
- 'image/svg+xml',
- 'font/*',
- 'audio/mpeg',
- 'audio/mp4',
- 'audio/ogg',
- 'video/mpeg',
- 'video/mp4',
- 'video/ogg',
- );
- }
- }
|