/** * Execute the action * We will build the classname, require the class and call the execute method. */ public function execute() { $this->loadConfig(); // is the requested action possible? If not we throw an exception. // We don't redirect because that could trigger a redirect loop if (!in_array($this->getAction(), $this->config->getPossibleActions())) { throw new Exception('This is an invalid action (' . $this->getAction() . ').'); } // build action-class $actionClass = 'Backend\\Modules\\' . $this->getModule() . '\\Actions\\' . $this->getAction(); if ($this->getModule() == 'Core') { $actionClass = 'Backend\\Core\\Actions\\' . $this->getAction(); } if (!class_exists($actionClass)) { throw new Exception('The class ' . $actionClass . ' could not be found.'); } // get working languages $languages = Language::getWorkingLanguages(); $workingLanguages = array(); // loop languages and build an array that we can assign foreach ($languages as $abbreviation => $label) { $workingLanguages[] = array('abbr' => $abbreviation, 'label' => $label, 'selected' => $abbreviation == Language::getWorkingLanguage()); } // assign the languages $this->tpl->assign('workingLanguages', $workingLanguages); // create action-object /** @var $object BackendBaseAction */ $object = new $actionClass($this->getKernel()); $this->getContainer()->get('logger')->info("Executing backend action '{$object->getAction()}' for module '{$object->getModule()}'."); $object->execute(); return $object->getContent(); }
/** * Execute the action * We will build the classname, require the class and call the execute method. */ public function execute() { $this->loadConfig(); // is the requested action available? If not we redirect to the error page. if (!$this->config->isActionAvailable($this->action)) { // build the url $errorUrl = '/' . NAMED_APPLICATION . '/' . $this->get('request')->getLocale() . '/error?type=action-not-allowed'; // redirect to the error page return $this->redirect($errorUrl, 307); } // build action-class $actionClass = 'Backend\\Modules\\' . $this->getModule() . '\\Actions\\' . $this->getAction(); if ($this->getModule() == 'Core') { $actionClass = 'Backend\\Core\\Actions\\' . $this->getAction(); } if (!class_exists($actionClass)) { throw new Exception('The class ' . $actionClass . ' could not be found.'); } // get working languages $languages = BackendLanguage::getWorkingLanguages(); $workingLanguages = array(); // loop languages and build an array that we can assign foreach ($languages as $abbreviation => $label) { $workingLanguages[] = array('abbr' => $abbreviation, 'label' => $label, 'selected' => $abbreviation == BackendLanguage::getWorkingLanguage()); } // assign the languages $this->tpl->assign('workingLanguages', $workingLanguages); // create action-object /** @var $object BackendBaseAction */ $object = new $actionClass($this->getKernel()); $this->getContainer()->get('logger')->info("Executing backend action '{$object->getAction()}' for module '{$object->getModule()}'."); $object->execute(); return $object->getContent(); }
/** * Execute the action */ public function execute() { parent::execute(); //--Create template object $tpl = new Template(); //--Add list of all mediaitems to template $tpl->assign('mediaItems', BackendMediaHelper::getAllMediaItems()); //--Get html list $html = $tpl->getContent(BACKEND_MODULES_PATH . '/Media/Layout/Templates/Ajax/Link.tpl'); // success output $this->output(self::OK, $html, ''); }
/** * Execute the action */ public function execute() { // add jquery, we will need this in every action, so add it globally $this->header->addJS('jquery/jquery.js', 'Core', false); $this->header->addJS('jquery/jquery.ui.js', 'Core', false); $this->header->addJS('jquery/jquery.ui.dialog.patch.js', 'Core'); $this->header->addJS('jquery/jquery.tools.js', 'Core', false); $this->header->addJS('jquery/jquery.backend.js', 'Core'); // add items that always need to be loaded $this->header->addJS('utils.js', 'Core'); $this->header->addJS('backend.js', 'Core'); // add module js if (is_file($this->getBackendModulePath() . '/Js/' . $this->getModule() . '.js')) { $this->header->addJS($this->getModule() . '.js'); } // add action js if (is_file($this->getBackendModulePath() . '/Js/' . $this->getAction() . '.js')) { $this->header->addJS($this->getAction() . '.js'); } // add core css files $this->header->addCSS('reset.css', 'Core'); $this->header->addCSS('jquery_ui/fork/jquery_ui.css', 'Core', false, false); $this->header->addCSS('screen.css', 'Core'); $this->header->addCSS('debug.css', 'Core'); // add module specific css if (is_file($this->getBackendModulePath() . '/Layout/Css/' . $this->getModule() . '.css')) { $this->header->addCSS($this->getModule() . '.css'); } // store var so we don't have to call this function twice $var = array_map('strip_tags', $this->getParameter('var', 'array', array())); // is there a report to show? if ($this->getParameter('report') !== null) { // show the report $this->tpl->assign('report', true); // camelcase the string $messageName = strip_tags(\SpoonFilter::toCamelCase($this->getParameter('report'), '-')); // if we have data to use it will be passed as the var parameter if (!empty($var)) { $this->tpl->assign('reportMessage', vsprintf(BL::msg($messageName), $var)); } else { $this->tpl->assign('reportMessage', BL::msg($messageName)); } // highlight an element with the given id if needed if ($this->getParameter('highlight')) { $this->tpl->assign('highlight', strip_tags($this->getParameter('highlight'))); } } // is there an error to show? if ($this->getParameter('error') !== null) { // camelcase the string $errorName = strip_tags(\SpoonFilter::toCamelCase($this->getParameter('error'), '-')); // if we have data to use it will be passed as the var parameter if (!empty($var)) { $this->tpl->assign('errorMessage', vsprintf(BL::err($errorName), $var)); } else { $this->tpl->assign('errorMessage', BL::err($errorName)); } } }
/** * Contstructor * */ public function execute() { parent::execute(); //--Set post var to check submit $_POST["form"] = "add_image"; //--Set module $module = (string) \SpoonFilter::getPostValue('mediaModule', null, '', 'string'); //--Set action $action = (string) \SpoonFilter::getPostValue('mediaAction', null, '', 'string'); //--Set the id $id = (int) \SpoonFilter::getPostValue('mediaId', null, '', 'int'); //--Set the type $type = (string) \SpoonFilter::getPostValue('mediaType', null, '', 'string'); //--Create media helper $this->media = new BackendMediaHelper(new BackendForm('add_image', null, 'post', false), $module, $id, $action, $type); //--Validate media -> upload file $this->media->validate(); //--File is image if ($this->media->item['filetype'] == 1) { //Create html $tpl = new Template(); $this->media->item['txtText'] = $this->media->frm->addTextarea("text-" . $this->media->item["id"], $this->media->item['text'])->setAttribute('style', 'resize: none;')->parse(); //--Get file info (ext, filename, path) $path_parts = pathinfo(FRONTEND_FILES_PATH . '/Media/Images/Source/' . $this->media->item['filename']); $this->media->item['name'] = $path_parts['filename']; $folders = BackendModel::getThumbnailFolders(FRONTEND_FILES_PATH . '/Media/Images', true); foreach ($folders as $folder) { $this->media->item['image_' . $folder['dirname']] = $folder['url'] . '/' . $folder['dirname'] . '/' . $this->media->item['filename']; } $tpl->assign('mediaItems', array('images' => array($this->media->item))); $html = $tpl->getContent(BACKEND_MODULES_PATH . '/Media/Layout/Templates/Ajax/Image.tpl'); //--File is file } else { //Create html $tpl = new Template(); $this->media->item['txtText'] = $this->media->frm->addTextarea("text-" . $this->media->item["id"], $this->media->item['text'])->setAttribute('style', 'resize: none;')->parse(); //--Get file info (ext, filename, path) $path_parts = pathinfo(FRONTEND_FILES_PATH . '/Media/Files/' . $this->media->item['filename']); $this->media->item['url'] = FRONTEND_FILES_URL . '/Media/Files/' . $this->media->item['filename']; $this->media->item['name'] = $path_parts['filename']; $tpl->assign('mediaItems', array('files' => array($this->media->item))); $html = $tpl->getContent(BACKEND_MODULES_PATH . '/Media/Layout/Templates/Ajax/File.tpl'); } // output (filetype, html) $this->output(self::OK, array($this->media->item['filetype'], $html), FrontendLanguage::msg('Success')); }
public function execute() { parent::execute(); //--Get the video info //$video_type = \SpoonFilter::getPostValue('video_type', null, '', 'int'); $video_url = \SpoonFilter::getPostValue('video', null, '', 'string'); if (preg_match('%youtube|youtu\\.be%i', $video_url)) { $video_type = 0; $video_id = self::getYoutubeId($video_url); } elseif (preg_match('%vimeo%i', $video_url)) { $video_type = 1; $video_id = self::getVimeoId($video_url); } elseif (preg_match('%vine%i', $video_url)) { $video_type = 2; $video_id = preg_replace('/^.*\\//', '', $video_url); } if (isset($video_id)) { //--Set module $module = (string) \SpoonFilter::getPostValue('mediaModule', null, '', 'string'); //--Set action $action = (string) \SpoonFilter::getPostValue('mediaAction', null, '', 'string'); //--Set the id $id = (int) \SpoonFilter::getPostValue('mediaId', null, '', 'int'); //--Set the type $type = (string) \SpoonFilter::getPostValue('mediaType', null, '', 'string'); //--Create media object $media = new BackendMediaHelper(new BackendForm('add_image', null, 'post', false), $module, $id, $action, $type); //--Validate media -> add video $media->addVideo($video_type, $video_id); $tpl = new Template(); $media->item['txtText'] = $media->frm->addTextarea("text-" . $media->item["id"], $media->item['text'])->setAttribute('style', 'resize: none;')->parse(); switch ($media->item['extension']) { //youtube case 0: $media->item['video_html'] = '<iframe id="ytplayer" type="text/html" width="100%" src="http://www.youtube.com/embed/' . $media->item['filename'] . '?autoplay=0" frameborder="0"></iframe>'; break; //vimeo //vimeo case 1: $media->item['video_html'] = '<iframe src="//player.vimeo.com/video/' . $media->item['filename'] . '" width="100%" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>'; break; //vine //vine case 2: $media->item['video_html'] = '<iframe src="https://vine.co/v/' . $media->item['filename'] . '/embed/postcard" width="100%" frameborder="0"></iframe><script src="https://platform.vine.co/static/scripts/embed.js"></script>'; break; default: $media->item['video_html'] = ""; break; } $tpl->assign('mediaItems', array('videos' => array($media->item))); $html = $tpl->getContent(BACKEND_MODULES_PATH . '/Media/Layout/Templates/Ajax/Video.tpl'); $this->output(self::OK, array($media->item['filetype'], $html), FrontendLanguage::msg('Success')); } else { $this->output(self::OK, null, 'video not added'); } // success output }
/** * Parse the JS-files */ public function parseJS() { $jsFiles = array(); $existingJSFiles = $this->getJSFiles(); // if there aren't any JS-files added we don't need to do something if (!empty($existingJSFiles)) { // some files should be cached, even if we don't want cached (mostly libraries) $ignoreCache = array('/src/Backend/Core/Js/jquery/jquery.js', '/src/Backend/Core/Js/jquery/jquery.ui.js', '/src/Backend/Core/Js/ckeditor/jquery.ui.dialog.patch.js', '/src/Backend/Core/Js/jquery/jquery.tools.js', '/src/Backend/Core/Js/jquery/jquery.backend.js', '/src/Backend/Core/Js/ckeditor/ckeditor.js', '/src/Backend/Core/Js/ckeditor/adapters/jquery.js', '/src/Backend/Core/Js/ckfinder/ckfinder.js'); foreach ($existingJSFiles as $file) { // some files shouldn't be uncachable if (in_array($file['file'], $ignoreCache) || $file['add_timestamp'] === false) { $file = array('file' => $file['file']); } else { if (substr($file['file'], 0, 11) == '/frontend/js') { $file = array('file' => $file['file'] . '&m=' . time()); } else { $modifiedTime = strpos($file['file'], '?') !== false ? '&m=' . LAST_MODIFIED_TIME : '?m=' . LAST_MODIFIED_TIME; $file = array('file' => $file['file'] . $modifiedTime); } } // add $jsFiles[] = $file; } } // assign JS-files $this->tpl->assign('jsFiles', $jsFiles); // fetch preferred interface language if (Authentication::getUser()->isAuthenticated()) { $interfaceLanguage = (string) Authentication::getUser()->getSetting('interface_language'); } else { $interfaceLanguage = Language::getInterfaceLanguage(); } // some default stuff $this->jsData['debug'] = $this->getContainer()->getParameter('kernel.debug'); $this->jsData['site']['domain'] = SITE_DOMAIN; $this->jsData['editor']['language'] = $interfaceLanguage; $this->jsData['interface_language'] = $interfaceLanguage; // is the user object filled? if (Authentication::getUser()->isAuthenticated()) { $this->jsData['editor']['language'] = (string) Authentication::getUser()->getSetting('interface_language'); } // CKeditor has support for simplified Chinese, but the language is called zh-cn instead of zn if ($this->jsData['editor']['language'] == 'zh') { $this->jsData['editor']['language'] = 'zh-cn'; } // theme if ($this->get('fork.settings')->get('Core', 'theme') !== null) { $this->jsData['theme']['theme'] = $this->get('fork.settings')->get('Core', 'theme'); $this->jsData['theme']['path'] = FRONTEND_PATH . '/Themes/' . $this->get('fork.settings')->get('Core', 'theme'); $this->jsData['theme']['has_css'] = is_file(FRONTEND_PATH . '/Themes/' . $this->get('fork.settings')->get('Core', 'theme') . '/Core/Layout/Css/screen.css'); $this->jsData['theme']['has_editor_css'] = is_file(FRONTEND_PATH . '/Themes/' . $this->get('fork.settings')->get('Core', 'theme') . '/Core/Layout/Css/editor_content.css'); } // encode and add $jsData = json_encode($this->jsData); $this->tpl->assign('jsData', 'var jsData = ' . $jsData . ';' . "\n"); }
/** * Validate the form add image * * @return void */ private function validateForm() { //--Check if the add-image form is submitted if ($this->frm->isSubmitted()) { //--Clean up fields in the form (NOT ALLOWED: fields from plupload like name are deleted) //$this->frm->cleanupFields(); //--Get image field $filImage = $this->frm->getField('images'); //--Check if the field is filled in if ($filImage->isFilled()) { //--Image extension and mime type $filImage->isAllowedExtension(array('jpg', 'png', 'gif', 'jpeg'), BL::err('JPGGIFAndPNGOnly')); $filImage->isAllowedMimeType(array('image/jpg', 'image/png', 'image/gif', 'image/jpeg'), BL::err('JPGGIFAndPNGOnly')); //--Check if there are no errors. $strError = $filImage->getErrors(); if ($strError === null) { //--Get the filename $strFilename = BackendGalleryModel::checkFilename(substr($_REQUEST["name"], 0, 0 - (strlen($filImage->getExtension()) + 1)), $filImage->getExtension()); //--Fill in the item $item = array(); $item["album_id"] = (int) $this->id; $item["user_id"] = BackendAuthentication::getUser()->getUserId(); $item["language"] = BL::getWorkingLanguage(); $item["filename"] = $strFilename; $item["description"] = ""; $item["publish_on"] = BackendModel::getUTCDate(); $item["hidden"] = "N"; $item["sequence"] = BackendGalleryModel::getMaximumImageSequence($this->id) + 1; //--the image path $imagePath = FRONTEND_FILES_PATH . '/Gallery/Images'; //--create folders if needed $resolutions = $this->get('fork.settings')->get("Gallery", 'resolutions', false); foreach ($resolutions as $res) { if (!\SpoonDirectory::exists($imagePath . '/' . $res)) { \SpoonDirectory::create($imagePath . '/' . $res); // Create filesystem object $filesystem = new Filesystem(); // Create var dir for ease of use $dir = $imagePath; // Check if dir exists if ($filesystem->exists($dir . '/Source/')) { // Create Finder object for the files $finderFiles = new Finder(); // Get all the files in the source-dir $files = $finderFiles->files()->in($dir . '/Source/'); // Check if $files is not empty if (!empty($files)) { // Explode the dir-name $chunks = explode("x", $res, 2); // Create folder array $folder = array(); $folder['width'] = $chunks[0] != '' ? (int) $chunks[0] : null; $folder['height'] = $chunks[1] != '' ? (int) $chunks[1] : null; // Loop all the files foreach ($files as $file) { set_time_limit(150); // Check if the file exists if (!$filesystem->exists($imagePath . '/' . $res . '/' . $file->getBasename())) { // generate the thumbnail $thumbnail = new \SpoonThumbnail($dir . '/Source/' . $file->getBasename(), $folder['width'], $folder['height']); $thumbnail->setAllowEnlargement(true); // if the width & height are specified we should ignore the aspect ratio if ($folder['width'] !== null && $folder['height'] !== null) { $thumbnail->setForceOriginalAspectRatio(false); } $thumbnail->parseToFile($imagePath . '/' . $res . '/' . $file->getBasename()); } } } } } } if (!\SpoonDirectory::exists($imagePath . '/Source')) { \SpoonDirectory::create($imagePath . '/Source'); } if (!\SpoonDirectory::exists($imagePath . '/128x128')) { \SpoonDirectory::create($imagePath . '/128x128'); } if (!\SpoonDirectory::exists($imagePath . '/800x')) { \SpoonDirectory::create($imagePath . '/800x'); } if (!\SpoonDirectory::exists($imagePath . '/200x')) { \SpoonDirectory::create($imagePath . '/200x'); } if (!\SpoonDirectory::exists($imagePath . '/400x300')) { \SpoonDirectory::create($imagePath . '/400x300'); } //--image provided? if ($filImage->isFilled()) { //--upload the image & generate thumbnails $filImage->generateThumbnails($imagePath, $item["filename"]); } //--Add item to the database $idInsert = BackendGalleryModel::insert($item); $item['id'] = $idInsert; //--Create html for ajax $tpl = new Template(); $txtDescription = $this->frm->addTextarea("description_" . $idInsert, $item['description']); $item['field_description'] = $txtDescription->setAttribute('style', 'resize: none;')->parse(); //--Parse filename to get name $path_parts = pathinfo(FRONTEND_FILES_PATH . '/Gallery/Images/Source/' . $item['filename']); $item['name'] = $path_parts['filename']; $folders = BackendModel::getThumbnailFolders(FRONTEND_FILES_PATH . '/Gallery/Images', true); foreach ($folders as $folder) { $item['image_' . $folder['dirname']] = $folder['url'] . '/' . $folder['dirname'] . '/' . $item['filename']; } $tpl->assign('images', array($item)); $html = $tpl->getContent(BACKEND_MODULES_PATH . '/Gallery/Layout/Templates/Ajax/Image.tpl'); //Send html (ajax response) $this->output(self::OK, $html, BL::msg('Success')); } } } }