1
0
mirror of https://github.com/typemill/typemill.git synced 2025-07-30 19:00:32 +02:00

Version 1.2.9: Add videos and frontend forms

This commit is contained in:
Sebastian
2019-01-03 21:15:07 +01:00
parent 28b6f93a9c
commit 08ece40117
52 changed files with 1003 additions and 452 deletions

View File

@@ -856,7 +856,7 @@ class ContentApiController extends ContentController
$imageProcessor = new ProcessImage();
if($imageProcessor->createImage($this->params['image'], $this->settings['images'], $name = false))
if($imageProcessor->createImage($this->params['image'], $this->settings['images']))
{
return $response->withJson(array('errors' => false));
}
@@ -867,7 +867,7 @@ class ContentApiController extends ContentController
public function publishImage(Request $request, Response $response, $args)
{
$params = $request->getParsedBody();
$imageProcessor = new ProcessImage();
$imageUrl = $imageProcessor->publishImage($this->settings['images'], $name = false);
@@ -882,4 +882,72 @@ class ContentApiController extends ContentController
return $response->withJson(array('errors' => 'could not store image to temporary folder'));
}
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();
$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'] = '![' . $class . '-video](' . $imageUrl . ' "click to load video"){#' . $videoID. ' .' . $class . '}';
$request = $request->withParsedBody($this->params);
return $this->updateBlock($request, $response, $args);
}
return $response->withJson(array('errors' => 'could not store the preview image'));
}
}

View File

@@ -0,0 +1,106 @@
<?php
namespace Typemill\Controllers;
use Typemill\Models\Validation;
use Typemill\Models\WriteYaml;
class FormController extends Controller
{
/*************************************
** SAVE THEME- AND PLUGIN-SETTINGS **
*************************************/
public function savePublicForm($request, $response, $args)
{
if($request->isPost())
{
$params = $request->getParams();
reset($params);
$pluginName = key($params);
$referer = $request->getHeader('HTTP_REFERER');
# simple bot check with honeypot
if(isset($params[$pluginName]['personal-mail']))
{
if($params[$pluginName]['personal-mail'] != '')
{
$this->c->flash->addMessage('publicform', 'bot');
return $response->withRedirect($referer[0]);
}
unset($params[$pluginName]['personal-mail']);
}
if(isset($params[$pluginName]))
{
# validate the user-input
$this->validateInput('plugins', $pluginName, $params[$pluginName]);
}
# check for errors and redirect to path, if errors found
if(isset($_SESSION['errors']))
{
$this->c->flash->addMessage('error', 'Please correct the errors');
return $response->withRedirect($referer[0]);
}
# clean up and make sure that only validated data are stored
$data = [ $pluginName => $params[$pluginName]];
# create write object
$writeYaml = new WriteYaml();
# write the form data into yaml file
$writeYaml->updateYaml('settings', 'formdata.yaml', $data);
# add message and return to original site
$this->c->flash->addMessage('formdata', $pluginName);
return $response->withRedirect($referer[0]);
}
}
private function validateInput($objectType, $objectName, $userInput)
{
# get settings and start validation
$originalSettings = \Typemill\Settings::getObjectSettings($objectType, $objectName);
$userSettings = \Typemill\Settings::getUserSettings();
$validate = new Validation();
if(isset($originalSettings['public']['fields']))
{
/* flaten the multi-dimensional array with fieldsets to a one-dimensional array */
$originalFields = array();
foreach($originalSettings['public']['fields'] as $fieldName => $fieldValue)
{
if(isset($fieldValue['fields']))
{
foreach($fieldValue['fields'] as $subFieldName => $subFieldValue)
{
$originalFields[$subFieldName] = $subFieldValue;
}
}
else
{
$originalFields[$fieldName] = $fieldValue;
}
}
/* take the user input data and iterate over all fields and values */
foreach($userInput as $fieldName => $fieldValue)
{
/* get the corresponding field definition from original plugin settings */
$fieldDefinition = isset($originalFields[$fieldName]) ? $originalFields[$fieldName] : false;
if($fieldDefinition)
{
/* validate user input for this field */
$validate->objectField($fieldName, $fieldValue, $objectName, $fieldDefinition);
}
if(!$fieldDefinition && $fieldName != 'active')
{
$_SESSION['errors'][$objectName][$fieldName] = array('This field is not defined!');
}
}
}
}
}

View File

@@ -137,8 +137,10 @@ class PageController extends Controller
/* get the first image from content array */
$firstImage = $this->getFirstImage($contentArray);
$itemUrl = isset($item->urlRel) ? $item->urlRel : false;
/* parse markdown-content-array to content-string */
$contentHTML = $parsedown->markup($contentArray, $item->urlRel);
$contentHTML = $parsedown->markup($contentArray, $itemUrl);
$contentHTML = $this->c->dispatcher->dispatch('onHtmlLoaded', new OnHtmlLoaded($contentHTML))->getData();
/* extract the h1 headline*/

View File

@@ -121,7 +121,7 @@ class SettingsController extends Controller
$user = new User();
$users = $user->getUsers();
$route = $request->getAttribute('route');
$this->render($response, 'settings/themes.twig', array('settings' => $userSettings, 'themes' => $themedata, 'users' => $users, 'route' => $route->getName() ));
}
@@ -241,7 +241,7 @@ class SettingsController extends Controller
$pluginSettings = array();
$userInput = $request->getParams();
$validate = new Validation();
/* use the stored user settings and iterate over all original plugin settings, so we do not forget any... */
foreach($userSettings['plugins'] as $pluginName => $pluginUserSettings)
{
@@ -323,7 +323,7 @@ class SettingsController extends Controller
if(!$fieldDefinition && $fieldName != 'active')
{
$_SESSION['errors'][$objectName][$fieldName] = array('This field is not defined!');
}
}
}
}
}