Ejemplo n.º 1
0
 /**
  * Returns the path to the preview-thumbnail of an album
  * @param $intAlbumId
  * @return array
  */
 public function getAlbumPreviewThumb($intAlbumId)
 {
     $thumbSRC = $this->defaultThumb;
     // Check for an alternate thumbnail
     if (\Config::get('gc_error404_thumb') !== '') {
         $objFile = \FilesModel::findByUuid(\Config::get('gc_error404_thumb'));
         if ($objFile !== null) {
             if (\Validator::isUuid(\Config::get('gc_error404_thumb'))) {
                 if (is_file(TL_ROOT . '/' . $objFile->path)) {
                     $thumbSRC = $objFile->path;
                 }
             }
         }
     }
     // Predefine thumb
     $arrThumb = array('name' => basename($thumbSRC), 'path' => $thumbSRC);
     $objAlb = \GalleryCreatorAlbumsModel::findByPk($intAlbumId);
     if ($objAlb->thumb !== null) {
         $objPreviewThumb = \GalleryCreatorPicturesModel::findByPk($objAlb->thumb);
     } else {
         $objPreviewThumb = \GalleryCreatorPicturesModel::findOneByPid($intAlbumId);
     }
     if ($objPreviewThumb !== null) {
         $oFile = \FilesModel::findByUuid($objPreviewThumb->uuid);
         if ($oFile !== null) {
             if (is_file(TL_ROOT . '/' . $oFile->path)) {
                 $arrThumb = array('name' => basename($oFile->path), 'path' => $oFile->path);
             }
         }
     }
     return $arrThumb;
 }
Ejemplo n.º 2
0
 /**
  * insert a new entry in tl_gallery_creator_pictures
  *
  * @param integer
  * @param string
  * $intAlbumId - albumId
  * $strFilepath - filepath -> files/gallery_creator_albums/albumalias/filename.jpg
  * @return bool
  */
 public static function createNewImage($intAlbumId, $strFilepath)
 {
     //get the file-object
     $objFile = new \File($strFilepath);
     if (!$objFile->isGdImage) {
         return false;
     }
     //get the album-object
     $objAlbum = \MCupic\GalleryCreatorAlbumsModel::findById($intAlbumId);
     // get the assigned album directory
     $objFolder = \FilesModel::findByUuid($objAlbum->assignedDir);
     $assignedDir = null;
     if ($objFolder !== null) {
         if (is_dir(TL_ROOT . '/' . $objFolder->path)) {
             $assignedDir = $objFolder->path;
         }
     }
     if ($assignedDir == null) {
         die('Aborted Script, because there is no upload directory assigned to the Album with ID ' . $intAlbumId);
     }
     //check if the file ist stored in the album-directory or if it is stored in an external directory
     $blnExternalFile = false;
     if (\Input::get('importFromFilesystem')) {
         $blnExternalFile = strstr($objFile->dirname, $assignedDir) ? false : true;
     }
     //get the album object and the alias
     $strAlbumAlias = $objAlbum->alias;
     //db insert
     $objImg = new \GalleryCreatorPicturesModel();
     $objImg->tstamp = time();
     $objImg->pid = $objAlbum->id;
     $objImg->externalFile = $blnExternalFile ? "1" : "";
     $objImg->save();
     if ($objImg->id) {
         $insertId = $objImg->id;
         // Get the next sorting index
         $objImg_2 = \Database::getInstance()->prepare('SELECT MAX(sorting)+10 AS maximum FROM tl_gallery_creator_pictures WHERE pid=?')->execute($objAlbum->id);
         $sorting = $objImg_2->maximum;
         // If filename should be generated
         if (!$objAlbum->preserve_filename && $blnExternalFile === false) {
             $newFilepath = sprintf('%s/alb%s_img%s.%s', $assignedDir, $objAlbum->id, $insertId, $objFile->extension);
             $objFile->renameTo($newFilepath);
         }
         // GalleryCreatorImagePostInsert - HOOK
         // übergibt die id des neu erstellten db-Eintrages ($lastInsertId)
         if (isset($GLOBALS['TL_HOOKS']['galleryCreatorImagePostInsert']) && is_array($GLOBALS['TL_HOOKS']['galleryCreatorImagePostInsert'])) {
             foreach ($GLOBALS['TL_HOOKS']['galleryCreatorImagePostInsert'] as $callback) {
                 $objClass = self::importStatic($callback[0]);
                 $objClass->{$callback}[1]($insertId);
             }
         }
         if (is_file(TL_ROOT . '/' . $objFile->path)) {
             //get the userId
             $userId = '0';
             if (TL_MODE == 'BE') {
                 $userId = \BackendUser::getInstance()->id;
             }
             // the album-owner is automaticaly the image owner, if the image was uploaded by a by a frontend user
             if (TL_MODE == 'FE') {
                 $userId = $objAlbum->owner;
             }
             // Get the FilesModel
             $objFileModel = \FilesModel::findByPath($objFile->path);
             //finally save the new image in tl_gallery_creator_pictures
             $objPicture = \GalleryCreatorPicturesModel::findByPk($insertId);
             $objPicture->uuid = $objFileModel->uuid;
             $objPicture->owner = $userId;
             $objPicture->date = $objAlbum->date;
             $objPicture->sorting = $sorting;
             $objPicture->save();
             \System::log('A new version of tl_gallery_creator_pictures ID ' . $insertId . ' has been created', __METHOD__, TL_GENERAL);
             //check for a valid preview-thumb for the album
             $objAlbum = \MCupic\GalleryCreatorAlbumsModel::findByAlias($strAlbumAlias);
             if ($objAlbum !== null) {
                 if ($objAlbum->thumb == "") {
                     $objAlbum->thumb = $insertId;
                     $objAlbum->save();
                 }
             }
             return true;
         } else {
             if ($blnExternalFile === true) {
                 $_SESSION['TL_ERROR'][] = sprintf($GLOBALS['TL_LANG']['ERR']['link_to_not_existing_file'], $strFilepath);
             } else {
                 $_SESSION['TL_ERROR'][] = sprintf($GLOBALS['TL_LANG']['ERR']['uploadError'], $strFilepath);
             }
             \System::log('Unable to create the new image in: ' . $strFilepath . '!', __METHOD__, TL_ERROR);
         }
     }
     return false;
 }
 /**
  * toggle visibility of a certain image
  *
  * @param integer
  * @param boolean
  */
 public function toggleVisibility($intId, $blnVisible)
 {
     $objPicture = GalleryCreatorPicturesModel::findByPk($intId);
     // Check permissions to publish
     if (!$this->User->isAdmin && $objPicture->owner != $this->User->id && !$GLOBALS['TL_CONFIG']['gc_disable_backend_edit_protection']) {
         $this->log('Not enough permissions to publish/unpublish tl_gallery_creator_albums ID "' . $intId . '"', __METHOD__, TL_ERROR);
         $this->redirect('contao/main.php?act=error');
     }
     $objVersions = new Versions('tl_gallery_creator_pictures', $intId);
     $objVersions->initialize();
     // Trigger the save_callback
     if (is_array($GLOBALS['TL_DCA']['tl_gallery_creator_pictures']['fields']['published']['save_callback'])) {
         foreach ($GLOBALS['TL_DCA']['tl_gallery_creator_pictures']['fields']['published']['save_callback'] as $callback) {
             if (is_array($callback)) {
                 $this->import($callback[0]);
                 $blnVisible = $this->{$callback}[0]->{$callback}[1]($blnVisible, $this);
             } elseif (is_callable($callback)) {
                 $blnVisible = $callback($blnVisible, $this);
             }
         }
     }
     // Update the database
     $this->Database->prepare("UPDATE tl_gallery_creator_pictures SET tstamp=" . time() . ", published='" . ($blnVisible ? 1 : '') . "' WHERE id=?")->execute($intId);
     $objVersions->create();
     $this->log('A new version of record "tl_gallery_creator_pictures.id=' . $intId . '" has been created.', __METHOD__, TL_GENERAL);
 }
 /**
  * sortBy  - save_callback
  * @param $varValue
  * @param \Contao\DataContainer $dc
  * @return string
  */
 public function saveCbSortAlbum($varValue, \Contao\DataContainer $dc)
 {
     if ($varValue == 'custom') {
         return $varValue;
     }
     $objPictures = GalleryCreatorPicturesModel::findByPid($dc->id);
     if ($objPictures === null) {
         return 'custom';
     }
     $files = array();
     $auxDate = array();
     while ($objPictures->next()) {
         $oFile = FilesModel::findByUuid($objPictures->uuid);
         $objFile = new \File($oFile->path, true);
         $files[$oFile->path] = array('id' => $objPictures->id);
         $auxDate[] = $objFile->mtime;
     }
     switch ($varValue) {
         case 'custom':
             break;
         case 'name_asc':
             uksort($files, 'basename_natcasecmp');
             break;
         case 'name_desc':
             uksort($files, 'basename_natcasercmp');
             break;
         case 'date_asc':
             array_multisort($files, SORT_NUMERIC, $auxDate, SORT_ASC);
             break;
         case 'date_desc':
             array_multisort($files, SORT_NUMERIC, $auxDate, SORT_DESC);
             break;
     }
     $sorting = 0;
     foreach ($files as $arrFile) {
         $sorting += 10;
         $objPicture = GalleryCreatorPicturesModel::findByPk($arrFile['id']);
         $objPicture->sorting = $sorting;
         $objPicture->save();
     }
     // return default value
     return 'custom';
 }
Ejemplo n.º 5
0
 /**
  * Returns the information-array about an album
  *
  * @param null $intPictureId
  * @param $objContentElement
  * @return array|null
  */
 public static function getPictureInformationArray($intPictureId = null, $objContentElement)
 {
     if ($intPictureId < 1) {
         return null;
     }
     global $objPage;
     $hasCustomThumb = false;
     $defaultThumbSRC = $objContentElement->defaultThumb;
     if (\Config::get('gc_error404_thumb') !== '') {
         $objFile = \FilesModel::findByUuid(\Config::get('gc_error404_thumb'));
         if ($objFile !== null) {
             if (\Validator::isUuid(\Config::get('gc_error404_thumb'))) {
                 if (is_file(TL_ROOT . '/' . $objFile->path)) {
                     $defaultThumbSRC = $objFile->path;
                 }
             }
         }
     }
     // Get the page model
     $objPageModel = \PageModel::findByPk($objPage->id);
     $objPicture = \Database::getInstance()->prepare('SELECT * FROM tl_gallery_creator_pictures WHERE id=?')->execute($intPictureId);
     //Alle Informationen zum Album in ein array packen
     $objAlbum = \Database::getInstance()->prepare('SELECT * FROM tl_gallery_creator_albums WHERE id=?')->execute($objPicture->pid);
     $arrAlbumInfo = $objAlbum->fetchAssoc();
     //Bild-Besitzer
     $objOwner = \Database::getInstance()->prepare('SELECT name FROM tl_user WHERE id=?')->execute($objPicture->owner);
     $arrMeta = array();
     $objFileModel = \FilesModel::findByUuid($objPicture->uuid);
     if ($objFileModel == null) {
         $strImageSrc = $defaultThumbSRC;
     } else {
         $strImageSrc = $objFileModel->path;
         if (!is_file(TL_ROOT . '/' . $strImageSrc)) {
             // Fallback to the default thumb
             $strImageSrc = $defaultThumbSRC;
         }
         //meta
         $arrMeta = $objContentElement->getMetaData($objFileModel->meta, $objPage->language);
         // Use the file name as title if none is given
         if ($arrMeta['title'] == '') {
             $arrMeta['title'] = specialchars($objFileModel->name);
         }
     }
     // get thumb dimensions
     $arrSize = unserialize($objContentElement->gc_size_detailview);
     //Generate the thumbnails and the picture element
     try {
         $thumbSrc = \Image::create($strImageSrc, $arrSize)->executeResize()->getResizedPath();
         // overwrite $thumbSrc if there is a valid custom thumb
         if ($objPicture->addCustomThumb && !empty($objPicture->customThumb)) {
             $customThumbModel = \FilesModel::findByUuid($objPicture->customThumb);
             if ($customThumbModel !== null) {
                 if (is_file(TL_ROOT . '/' . $customThumbModel->path)) {
                     $objFileCustomThumb = new \File($customThumbModel->path, true);
                     if ($objFileCustomThumb->isGdImage) {
                         $thumbSrc = \Image::create($objFileCustomThumb->path, $arrSize)->executeResize()->getResizedPath();
                         $hasCustomThumb = true;
                     }
                 }
             }
         }
         $thumbPath = $hasCustomThumb ? $objFileCustomThumb->path : $strImageSrc;
         $picture = \Picture::create($thumbPath, $arrSize)->getTemplateData();
     } catch (\Exception $e) {
         \System::log('Image "' . $strImageSrc . '" could not be processed: ' . $e->getMessage(), __METHOD__, TL_ERROR);
         $thumbSrc = '';
         $picture = array('img' => array('src' => '', 'srcset' => ''), 'sources' => array());
     }
     $picture['alt'] = $objPicture->title != '' ? specialchars($objPicture->title) : specialchars($arrMeta['title']);
     $picture['title'] = $objPicture->comment != '' ? $objPage->outputFormat == 'xhtml' ? specialchars(\StringUtil::toXhtml($objPicture->comment)) : specialchars(\StringUtil::toHtml5($objPicture->comment)) : specialchars($arrMeta['caption']);
     $objFileThumb = new \File(rawurldecode($thumbSrc));
     $arrSize[0] = $objFileThumb->width;
     $arrSize[1] = $objFileThumb->height;
     $arrFile["thumb_width"] = $objFileThumb->width;
     $arrFile["thumb_height"] = $objFileThumb->height;
     // get some image params
     if (is_file(TL_ROOT . '/' . $strImageSrc)) {
         $objFileImage = new \File($strImageSrc);
         if (!$objFileImage->isGdImage) {
             return null;
         }
         $arrFile["path"] = $objFileImage->path;
         $arrFile["basename"] = $objFileImage->basename;
         // filename without extension
         $arrFile["filename"] = $objFileImage->filename;
         $arrFile["extension"] = $objFileImage->extension;
         $arrFile["dirname"] = $objFileImage->dirname;
         $arrFile["image_width"] = $objFileImage->width;
         $arrFile["image_height"] = $objFileImage->height;
     } else {
         return null;
     }
     //exif
     if ($GLOBALS['TL_CONFIG']['gc_read_exif']) {
         try {
             $exif = is_callable('exif_read_data') && TL_MODE == 'FE' ? exif_read_data($strImageSrc) : array('info' => "The function 'exif_read_data()' is not available on this server.");
         } catch (Exception $e) {
             $exif = array('info' => "The function 'exif_read_data()' is not available on this server.");
         }
     } else {
         $exif = array('info' => "The function 'exif_read_data()' has not been activated in the Contao backend settings.");
     }
     //video-integration
     $strMediaSrc = trim($objPicture->socialMediaSRC) != "" ? trim($objPicture->socialMediaSRC) : "";
     if (\Validator::isUuid($objPicture->localMediaSRC)) {
         //get path of a local Media
         $objMovieFile = \FilesModel::findById($objPicture->localMediaSRC);
         $strMediaSrc = $objMovieFile !== null ? $objMovieFile->path : $strMediaSrc;
     }
     $href = null;
     if (TL_MODE == 'FE' && $objContentElement->gc_fullsize) {
         $href = $strMediaSrc != "" ? $strMediaSrc : \System::urlEncode($strImageSrc);
     }
     //cssID
     $cssID = deserialize($objPicture->cssID, true);
     // build the array
     $arrPicture = array('id' => $objPicture->id, 'pid' => $objPicture->pid, 'date' => $objPicture->date, 'owner' => $objPicture->owner, 'owners_name' => $objOwner->name, 'album_id' => $objPicture->pid, 'name' => specialchars($arrFile["basename"]), 'filename' => $arrFile["filename"], 'uuid' => $objPicture->uuid, 'path' => $arrFile["path"], 'basename' => $arrFile["basename"], 'dirname' => $arrFile["dirname"], 'extension' => $arrFile["extension"], 'alt' => $objPicture->title != '' ? specialchars($objPicture->title) : specialchars($arrMeta['title']), 'title' => $objPicture->title != '' ? specialchars($objPicture->title) : specialchars($arrMeta['title']), 'comment' => $objPicture->comment != '' ? $objPage->outputFormat == 'xhtml' ? specialchars(\StringUtil::toXhtml($objPicture->comment)) : specialchars(\StringUtil::toHtml5($objPicture->comment)) : specialchars($arrMeta['caption']), 'caption' => $objPicture->comment != '' ? $objPage->outputFormat == 'xhtml' ? specialchars(\StringUtil::toXhtml($objPicture->comment)) : specialchars(\StringUtil::toHtml5($objPicture->comment)) : specialchars($arrMeta['caption']), 'href' => TL_FILES_URL . $href, 'single_image_url' => $objPageModel->getFrontendUrl(($GLOBALS['TL_CONFIG']['useAutoItem'] ? '/' : '/items/') . \Input::get('items') . '/img/' . $arrFile["filename"], $objPage->language), 'image_src' => $arrFile["path"], 'media_src' => $strMediaSrc, 'socialMediaSRC' => $objPicture->socialMediaSRC, 'localMediaSRC' => $objPicture->localMediaSRC, 'addCustomThumb' => $objPicture->addCustomThumb, 'thumb_src' => isset($thumbSrc) ? TL_FILES_URL . $thumbSrc : '', 'size' => $arrSize, 'thumb_width' => $arrFile["thumb_width"], 'thumb_height' => $arrFile["thumb_height"], 'image_width' => $arrFile["image_width"], 'image_height' => $arrFile["image_height"], 'lightbox' => $objPage->outputFormat == 'xhtml' ? 'rel="lightbox[lb' . $objPicture->pid . ']"' : 'data-lightbox="lb' . $objPicture->pid . '"', 'tstamp' => $objPicture->tstamp, 'sorting' => $objPicture->sorting, 'published' => $objPicture->published, 'exif' => $exif, 'albuminfo' => $arrAlbumInfo, 'metaData' => $arrMeta, 'cssID' => $cssID[0] != '' ? $cssID[0] : '', 'cssClass' => $cssID[1] != '' ? $cssID[1] : '', 'externalFile' => $objPicture->externalFile, 'picture' => $picture);
     //Fuegt dem Array weitere Eintraege hinzu, falls tl_gallery_creator_pictures erweitert wurde
     $objPicture = \GalleryCreatorPicturesModel::findByPk($intPictureId);
     if ($objPicture !== null) {
         $arrPicture = array_merge($objPicture->row(), $arrPicture);
     }
     return $arrPicture;
 }