/** * 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, ''); }
/** * Display, this wil output the template to the browser * If no template is specified we build the path form the current module and action * * @param string $template The template to use, if not provided it will be based on the action. */ public function display($template = null) { // parse header $this->header->parse(); /* * If no template is specified, we have to build the path ourself. The default template is * based on the name of the current action */ if ($template === null) { $template = $this->getBackendModulePath() . '/Layout/Templates/' . $this->URL->getAction() . '.tpl'; } $this->content = $this->tpl->getContent($template); }
/** * 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 }
/** * 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')); } } } }