/**
  * Get the parent album trail as an array
  * @param $AlbumId
  * @return array
  */
 public static function getParentAlbums($AlbumId)
 {
     $arrParentAlbums = array();
     $objAlb = \GalleryCreatorAlbumsModel::findByPk($AlbumId);
     if ($objAlb !== null) {
         $pid = $objAlb->pid;
         while ($pid > 0) {
             $parentAlb = \GalleryCreatorAlbumsModel::findByPk($pid);
             if ($parentAlb !== null) {
                 $arrParentAlbums[] = $parentAlb->id;
                 $pid = $parentAlb->pid;
             }
         }
     }
     return $arrParentAlbums;
 }
 /**
  * Generate module
  */
 protected function compile()
 {
     // use a private template
     if (TL_MODE == 'FE' && $this->gc_template != '') {
         $this->Template->style = count($this->arrStyle) ? implode(' ', $this->arrStyle) : '';
         $this->Template->cssID = strlen($this->cssID[0]) ? ' id="' . $this->cssID[0] . '"' : '';
         $this->Template->class = trim('mod_' . $this->type . ' ' . $this->cssID[1]);
     }
     // check for excluded albums in the module settings
     $arrExcludedAlbums = deserialize($this->gc_excludedAlbums);
     $strExcludedAlbums = is_array($arrExcludedAlbums) && !empty($arrExcludedAlbums) ? implode(',', $arrExcludedAlbums) : '0';
     // redirect to the detailview if there is only 1 album
     if (!\Input::get('items') && $this->gc_redirectSingleAlb) {
         $objAlbum = $this->Database->prepare('SELECT * FROM tl_gallery_creator_albums WHERE published=? AND id NOT IN (' . $strExcludedAlbums . ')')->execute('1');
         if ($objAlbum->numRows === 1) {
             \Input::setGet('items', $objAlbum->alias);
         }
     }
     if (\Input::get('items')) {
         $this->strAlbumalias = \Input::get('items');
         // authenticate user if album is protected
         $this->authenticate($this->strAlbumalias);
         // get the album id from the album alias
         $objAlbum = $this->Database->prepare('SELECT id FROM tl_gallery_creator_albums WHERE alias=?')->execute($this->strAlbumalias);
         $this->intAlbumId = $objAlbum->id;
     }
     $switch = strlen(\Input::get('items')) ? 'detailview' : 'albumlisting';
     $switch = strlen(\Input::get('jw_imagerotator')) ? 'jw_imagerotator' : $switch;
     switch ($switch) {
         case 'albumlisting':
             // get all published albums
             $arrAllowedAlbums = array();
             if ($this->gc_hierarchicalOutput) {
                 $objAlbum = $this->Database->prepare('SELECT * FROM tl_gallery_creator_albums WHERE published=? AND pid=? AND id NOT IN (' . $strExcludedAlbums . ')')->execute('1', '0');
             } else {
                 $objAlbum = $this->Database->prepare('SELECT * FROM tl_gallery_creator_albums WHERE published=? AND id NOT IN (' . $strExcludedAlbums . ')')->execute('1');
             }
             while ($objAlbum->next()) {
                 if (TL_MODE == 'FE' && $objAlbum->protected == true) {
                     $this->import('FrontendUser', 'User');
                     // check if the frontend user is allowed
                     if (FE_USER_LOGGED_IN && is_array(unserialize($this->User->allGroups))) {
                         if (array_intersect(unserialize($this->User->allGroups), unserialize($objAlbum->groups))) {
                             // user is allowed
                             $arrAllowedAlbums[] = $objAlbum->id;
                         }
                     }
                     continue;
                 }
                 // album is not protected
                 $arrAllowedAlbums[] = $objAlbum->id;
             }
             // pagination settings
             $limit = $this->gc_AlbumsPerPage;
             if ($limit > 0) {
                 $page = \Input::get('page') ? \Input::get('page') : 1;
                 $offset = ($page - 1) * $limit;
                 $itemsTotal = count($arrAllowedAlbums);
                 // add pagination menu
                 $numberOfLinks = $this->gc_PaginationNumberOfLinks < 1 ? 7 : $this->gc_PaginationNumberOfLinks;
                 $objPagination = new \Pagination($itemsTotal, $limit, $numberOfLinks);
                 $this->Template->pagination = $objPagination->generate("\n ");
             }
             // get all published albums
             $objAlbum = $this->Database->prepare('SELECT * FROM tl_gallery_creator_albums WHERE id IN(' . implode(",", $arrAllowedAlbums) . ') ORDER BY sorting ASC');
             if ($limit > 0) {
                 $objAlbum->limit($limit, $offset);
             }
             $objAlbum = $objAlbum->execute('1', '0');
             // album array
             $arrAlbums = array();
             while ($objAlbum->next()) {
                 $arrAlbums[$objAlbum->id] = GcHelpers::getAlbumInformationArray($objAlbum->id, $this);
             }
             $this->Template->imagemargin = $this->generateMargin(unserialize($this->gc_imagemargin_albumlisting));
             $this->Template->arrAlbums = $arrAlbums;
             $this->getAlbumTemplateVars($objAlbum->id);
             // Call gcGenerateFrontendTemplateHook
             $this->Template = $this->callGcGenerateFrontendTemplateHook($this);
             break;
         case 'detailview':
             $objAlbum = \GalleryCreatorAlbumsModel::findByPk($this->intAlbumId);
             $published = $objAlbum->published ? true : false;
             if ($published) {
                 $published = in_array($this->intAlbumId, explode(',', $strExcludedAlbums)) ? false : true;
             }
             // for security reasons...
             if (!$published) {
                 die("Gallery with alias " . \Input::get('items') . " is either not published or not available!!!");
             }
             // generate the subalbum array
             if ($this->gc_hierarchicalOutput) {
                 $arrSubalbums = GcHelpers::getSubalbumsInformationArray($this->intAlbumId, $this);
                 $this->Template->subalbums = count($arrSubalbums) ? $arrSubalbums : null;
             }
             // pagination settings
             $limit = $this->gc_ThumbsPerPage;
             if ($limit > 0) {
                 $page = \Input::get('page') ? \Input::get('page') : 1;
                 $offset = ($page - 1) * $limit;
                 // count albums
                 $objTotal = $this->Database->prepare('SELECT COUNT(id) as itemsTotal FROM tl_gallery_creator_pictures WHERE published=? AND pid=?')->execute('1', $this->intAlbumId);
                 $itemsTotal = $objTotal->itemsTotal;
                 // add pagination menu
                 $numberOfLinks = $this->gc_PaginationNumberOfLinks < 1 ? 7 : $this->gc_PaginationNumberOfLinks;
                 $objPagination = new \Pagination($itemsTotal, $limit, $numberOfLinks);
                 $this->Template->pagination = $objPagination->generate("\n ");
             }
             $objPictures = $this->Database->prepare('SELECT * FROM tl_gallery_creator_pictures WHERE published=?  AND pid=? ORDER BY sorting');
             if ($limit > 0) {
                 $objPictures->limit($limit, $offset);
             }
             $objPictures = $objPictures->execute('1', $this->intAlbumId);
             $arrPictures = array();
             while ($objPictures->next()) {
                 // picture array
                 $arrPictures[$objPictures->id] = GcHelpers::getPictureInformationArray($objPictures->id, $this);
             }
             // add picture array to the template
             $this->Template->arrPictures = $arrPictures;
             // add some other useful template vars
             $this->getAlbumTemplateVars($this->intAlbumId);
             // init the counter
             $this->initCounter($this->intAlbumId);
             // Call gcGenerateFrontendTemplateHook
             $this->Template = $this->callGcGenerateFrontendTemplateHook($this);
             break;
         case 'jw_imagerotator':
             header("content-type:text/xml;charset=utf-8");
             echo $this->getJwImagerotatorXml($this->strAlbumalias);
             exit;
             break;
     }
     //end switch
 }
 /**
  * Hilfsmethode
  * generiert den back-Link
  *
  * @param string
  * @param int
  * @return string
  */
 public function generateBackLink($intAlbumId)
 {
     global $objPage;
     if (TL_MODE == 'BE') {
         return false;
     }
     if ($this->moduleType == 'cte') {
         //Nur, wenn nicht automatisch zu overview weitergeleitet wurde, wird der back Link angezeigt
         if ($this->doRedirectOnSingleAlbum()) {
             return null;
         }
     }
     // Get the page model
     $objPageModel = \PageModel::findByPk($objPage->id);
     //generiert den Link zum Parent-Album
     if ($this->gc_hierarchicalOutput && \GalleryCreatorAlbumsModel::getParentAlbum($intAlbumId)) {
         $arrParentAlbum = \GalleryCreatorAlbumsModel::getParentAlbum($intAlbumId);
         return $objPageModel->getFrontendUrl(($GLOBALS['TL_CONFIG']['useAutoItem'] ? '/' : '/items/') . $arrParentAlbum["alias"]);
     }
     //generiert den Link zur Startuebersicht unter Beruecksichtigung der pagination
     $url = $objPageModel->getFrontendUrl();
     $url .= isset($_SESSION['gallery_creator']['PAGINATION']) ? '?page=' . $_SESSION['gallery_creator']['PAGINATION'] : '';
     return $url;
 }
 /**
  * Generate module
  */
 protected function compile()
 {
     global $objPage;
     // process request variables
     $this->getUrlParams();
     if (!is_array(deserialize($this->gc_publish_albums)) && !$this->gc_publish_all_albums) {
         return;
     }
     if ($this->gc_publish_all_albums) {
         // if all albums should be shown
         $arrSelectedAlb = $this->listAllAlbums();
     } else {
         // if only selected albums should be shown
         $arrSelectedAlb = deserialize($this->gc_publish_albums);
     }
     // clean array from unpublished or empty or protected albums
     foreach ($arrSelectedAlb as $key => $albumId) {
         $objAlbum = $this->Database->prepare('SELECT * FROM tl_gallery_creator_albums WHERE id=? AND published=?')->execute($albumId, '1');
         $objPics = $this->Database->prepare('SELECT id FROM tl_gallery_creator_pictures WHERE pid = ? AND published=?')->execute($albumId, '1');
         // if the album doesn't exist
         if (!$objAlbum->numRows) {
             unset($arrSelectedAlb[$key]);
             continue;
         }
         // if the album doesn't contain any pictures
         if (!$objPics->numRows) {
             unset($arrSelectedAlb[$key]);
             continue;
         }
         // remove id from $arrSelectedAlb if user is not allowed
         if (TL_MODE == 'FE' && $objAlbum->protected == true) {
             $blnAllowed = null;
             $this->import('FrontendUser', 'User');
             // remove id from $arrSelectedAlb if user is not allowed
             if (FE_USER_LOGGED_IN && is_array(unserialize($this->User->allGroups))) {
                 // check for accordance
                 if (array_intersect(unserialize($this->User->allGroups), unserialize($objAlbum->groups))) {
                     $blnAllowed = true;
                 }
             }
             if (!$blnAllowed) {
                 unset($arrSelectedAlb[$key]);
                 continue;
             }
         }
     }
     // build up the new array
     $arrAllowedAlbums = array_values($arrSelectedAlb);
     $switch = strlen(\Input::get('items')) ? 'detailview' : 'albumlisting';
     $switch = strlen(\Input::get('jw_imagerotator')) ? 'jw_imagerotator' : $switch;
     $switch = strlen(\Input::get('img')) ? 'single_image' : $switch;
     switch ($switch) {
         case 'albumlisting':
             // abort if no album is selected
             if (count($arrAllowedAlbums) < 1) {
                 return;
             }
             // pagination settings
             $limit = $this->gc_AlbumsPerPage;
             if ($limit > 0) {
                 $page = \Input::get('page') ? \Input::get('page') : 1;
                 $offset = ($page - 1) * $limit;
                 // count albums
                 $itemsTotal = count($arrAllowedAlbums);
                 // create pagination menu
                 $numberOfLinks = $this->gc_PaginationNumberOfLinks < 1 ? 7 : $this->gc_PaginationNumberOfLinks;
                 $objPagination = new \Pagination($itemsTotal, $limit, $numberOfLinks);
                 $this->Template->pagination = $objPagination->generate("\n ");
             }
             if ($limit == '0') {
                 $limit = count($arrAllowedAlbums);
                 $offset = 0;
             }
             $arrAlbums = array();
             for ($i = $offset; $i < $offset + $limit; $i++) {
                 if (!$arrAllowedAlbums[$i]) {
                     continue;
                 }
                 $currAlbumId = $arrAllowedAlbums[$i];
                 $objAlbum = $this->Database->prepare('SELECT id, alias FROM tl_gallery_creator_albums WHERE id=?')->execute($currAlbumId);
                 if (false === $this->authenticate($objAlbum->alias)) {
                     continue;
                 }
                 $arrAlbums[$objAlbum->id] = GcHelpers::getAlbumInformationArray($objAlbum->id, $this);
             }
             $this->Template->imagemargin = $this->generateMargin(unserialize($this->gc_imagemargin_albumlisting));
             $this->Template->arrAlbums = $arrAlbums;
             $this->getAlbumTemplateVars($objAlbum->id);
             // Call gcGenerateFrontendTemplateHook
             $this->Template = $this->callGcGenerateFrontendTemplateHook($this);
             break;
         case 'detailview':
             $objAlbum = \GalleryCreatorAlbumsModel::findByAlias($this->strAlbumalias);
             $published = $objAlbum->published ? true : false;
             // for security reasons...
             if (!$published || !$this->gc_publish_all_albums && !in_array($this->intAlbumId, $arrAllowedAlbums)) {
                 die("Gallery with alias " . $this->strAlbumalias . " is either not published or not available or you haven't got enough permission to watch it!!!");
             }
             // pagination settings
             $limit = $this->gc_ThumbsPerPage;
             if ($limit > 0) {
                 $page = \Input::get('page') ? \Input::get('page') : 1;
                 $offset = ($page - 1) * $limit;
                 // count albums
                 $objTotal = $this->Database->prepare('SELECT COUNT(id) as itemsTotal FROM tl_gallery_creator_pictures WHERE published=? AND pid=? GROUP BY ?')->execute('1', $this->intAlbumId, 'id');
                 $itemsTotal = $objTotal->itemsTotal;
                 // create the pagination menu
                 $numberOfLinks = $this->gc_PaginationNumberOfLinks < 1 ? 7 : $this->gc_PaginationNumberOfLinks;
                 $objPagination = new \Pagination($itemsTotal, $limit, $numberOfLinks);
                 $this->Template->pagination = $objPagination->generate("\n ");
             }
             // picture sorting
             $str_sorting = $this->gc_picture_sorting == '' || $this->gc_picture_sorting_direction == '' ? 'sorting ASC' : $this->gc_picture_sorting . ' ' . $this->gc_picture_sorting_direction;
             // sort by name is done below
             $str_sorting = str_replace('name', 'id', $str_sorting);
             $objPictures = $this->Database->prepare('SELECT * FROM tl_gallery_creator_pictures WHERE published=? AND pid=? ORDER BY ' . $str_sorting);
             if ($limit > 0) {
                 $objPictures->limit($limit, $offset);
             }
             $objPictures = $objPictures->execute('1', $this->intAlbumId);
             // build up $arrPictures
             $arrPictures = array();
             $auxBasename = array();
             while ($objPictures->next()) {
                 $objFilesModel = \FilesModel::findByUuid($objPictures->uuid);
                 $basename = 'undefined';
                 if ($objFilesModel !== null) {
                     $basename = $objFilesModel->name;
                 }
                 $auxBasename[] = $basename;
                 $arrPictures[$objPictures->id] = GcHelpers::getPictureInformationArray($objPictures->id, $this);
             }
             // sort by basename
             if ($this->gc_picture_sorting == 'name') {
                 if ($this->gc_picture_sorting_direction == 'ASC') {
                     array_multisort($arrPictures, SORT_STRING, $auxBasename, SORT_ASC);
                 } else {
                     array_multisort($arrPictures, SORT_STRING, $auxBasename, SORT_DESC);
                 }
             }
             $arrPictures = array_values($arrPictures);
             // store $arrPictures in the template variable
             $this->Template->arrPictures = $arrPictures;
             // generate other template variables
             $this->getAlbumTemplateVars($this->intAlbumId);
             // init the counter
             $this->initCounter($this->intAlbumId);
             // Call gcGenerateFrontendTemplateHook
             $this->Template = $this->callGcGenerateFrontendTemplateHook($this, $objAlbum);
             break;
         case 'single_image':
             $objAlbum = \GalleryCreatorAlbumsModel::findByAlias(\Input::get('items'));
             if ($objAlbum === null) {
                 die('Invalid album alias: ' . \Input::get('items'));
             }
             $objPic = \Database::getInstance()->prepare("SELECT * FROM tl_gallery_creator_pictures WHERE pid=? AND name LIKE '" . \Input::get('img') . ".%'")->execute($objAlbum->id);
             if (!$objPic->numRows) {
                 die(sprintf('File with filename "%s" does not exist in album with alias "%s".', \Input::get('img'), \Input::get('items')));
             }
             $picId = $objPic->id;
             $published = $objPic->published ? true : false;
             $published = $objAlbum->published ? $published : false;
             // for security reasons...
             if (!$published || !$this->gc_publish_all_albums && !in_array($this->intAlbumId, $arrAllowedAlbums)) {
                 die("Picture with id " . $picId . " is either not published or not available or you haven't got enough permission to watch it!!!");
             }
             // picture sorting
             $str_sorting = $this->gc_picture_sorting == '' || $this->gc_picture_sorting_direction == '' ? 'sorting ASC' : $this->gc_picture_sorting . ' ' . $this->gc_picture_sorting_direction;
             $objPictures = $this->Database->prepare('SELECT id FROM tl_gallery_creator_pictures WHERE published=? AND pid=? ORDER BY ' . $str_sorting);
             $objPictures = $objPictures->execute('1', $this->intAlbumId);
             // build up $arrPictures
             $arrIDS = array();
             $i = 0;
             $currentIndex = null;
             while ($objPictures->next()) {
                 if ($picId == $objPictures->id) {
                     $currentIndex = $i;
                 }
                 $arrIDS[] = $objPictures->id;
                 $i++;
             }
             $arrPictures = array();
             if (count($arrIDS)) {
                 // store $arrPictures in the template variable
                 $arrPictures['prev'] = GcHelpers::getPictureInformationArray($arrIDS[$currentIndex - 1], $this);
                 $arrPictures['current'] = GcHelpers::getPictureInformationArray($arrIDS[$currentIndex], $this);
                 $arrPictures['next'] = GcHelpers::getPictureInformationArray($arrIDS[$currentIndex + 1], $this);
                 // add navigation href's to the template
                 $this->Template->prevHref = $arrPictures['prev']['single_image_url'];
                 $this->Template->nextHref = $arrPictures['next']['single_image_url'];
                 if ($currentIndex == 0) {
                     $arrPictures['prev'] = null;
                     $this->Template->prevHref = null;
                 }
                 if ($currentIndex == count($arrIDS) - 1) {
                     $arrPictures['next'] = null;
                     $this->Template->nextHref = null;
                 }
                 if (count($arrIDS) == 1) {
                     $arrPictures['next'] = null;
                     $arrPictures['prev'] = null;
                     $this->Template->nextHref = null;
                     $this->Template->prevItem = null;
                 }
             }
             // Get the page model
             $objPageModel = \PageModel::findByPk($objPage->id);
             $this->Template->returnHref = $objPageModel->getFrontendUrl(($GLOBALS['TL_CONFIG']['useAutoItem'] ? '/' : '/items/') . \Input::get('items'), $objPage->language);
             $this->Template->arrPictures = $arrPictures;
             // generate other template variables
             $this->getAlbumTemplateVars($this->intAlbumId);
             // init the counter
             $this->initCounter($this->intAlbumId);
             // Call gcGenerateFrontendTemplateHook
             $this->Template = $this->callGcGenerateFrontendTemplateHook($this, $objAlbum);
             break;
         case 'jw_imagerotator':
             header("content-type:text/xml;charset=utf-8");
             echo $this->getJwImagerotatorXml($this->strAlbumalias);
             exit;
             break;
     }
     // end switch
 }
Beispiel #5
0
 /**
  * gibt ein Array mit allen Angaben des Parent-Albums zurueck
  * @deprecated Use \GalleryCreatorAlbumsModel::getParentAlbum($AlbumId) instead
  * @param integer
  * @return array
  */
 public static function getParentAlbum($AlbumId)
 {
     return \GalleryCreatorAlbumsModel::getParentAlbum($AlbumId);
 }
 /**
  * Generate module
  */
 protected function compile()
 {
     // Get the album object
     $objAlbum = \GalleryCreatorAlbumsModel::findByPk($this->intAlbumId);
     // Init the counter
     ContentGalleryCreator::initCounter($this->intAlbumId);
     // Pagination settings
     $limit = $this->gc_ThumbsPerPage;
     if ($limit > 0) {
         $page = \Input::get('page') ? \Input::get('page') : 1;
         $offset = ($page - 1) * $limit;
         // Count pictures
         $objPictures = $this->Database->prepare('SELECT * FROM tl_gallery_creator_pictures WHERE published=? AND pid=?')->execute('1', $this->intAlbumId);
         $itemsTotal = $objPictures->numRows;
         // Create the pagination menu
         $numberOfLinks = $this->gc_PaginationNumberOfLinks < 1 ? 7 : $this->gc_PaginationNumberOfLinks;
         $objPagination = new \Pagination($itemsTotal, $limit, $numberOfLinks);
         $this->Template->pagination = $objPagination->generate("\n ");
     }
     // Picture sorting
     $str_sorting = $this->gc_picture_sorting == '' || $this->gc_picture_sorting_direction == '' ? 'sorting ASC' : $this->gc_picture_sorting . ' ' . $this->gc_picture_sorting_direction;
     // Sort by name is done below
     $str_sorting = str_replace('name', 'id', $str_sorting);
     $objPictures = $this->Database->prepare('SELECT * FROM tl_gallery_creator_pictures WHERE published=? AND pid=? ORDER BY ' . $str_sorting);
     if ($limit > 0) {
         $objPictures->limit($limit, $offset);
     }
     $objPictures = $objPictures->execute('1', $this->intAlbumId);
     // Build up $arrPictures
     $arrPictures = array();
     $auxBasename = array();
     while ($objPictures->next()) {
         $objFilesModel = \FilesModel::findByUuid($objPictures->uuid);
         $basename = 'undefined';
         if ($objFilesModel !== null) {
             $basename = $objFilesModel->name;
         }
         $auxBasename[] = $basename;
         $arrPictures[$objPictures->id] = GcHelpers::getPictureInformationArray($objPictures->id, $this);
     }
     // Sort by basename
     if ($this->gc_picture_sorting == 'name') {
         if ($this->gc_picture_sorting_direction == 'ASC') {
             array_multisort($arrPictures, SORT_STRING, $auxBasename, SORT_ASC);
         } else {
             array_multisort($arrPictures, SORT_STRING, $auxBasename, SORT_DESC);
         }
     }
     $arrPictures = array_values($arrPictures);
     // Store $arrPictures in the template variable
     $this->Template->arrPictures = $arrPictures;
     // Generate other template variables
     $this->getAlbumTemplateVars($this->intAlbumId);
     // HOOK: modify the page or template object
     if (isset($GLOBALS['TL_HOOKS']['gc_generateFrontendTemplate']) && is_array($GLOBALS['TL_HOOKS']['gc_generateFrontendTemplate'])) {
         foreach ($GLOBALS['TL_HOOKS']['gc_generateFrontendTemplate'] as $callback) {
             $this->import($callback[0]);
             $this->Template = $this->{$callback}[0]->{$callback}[1]($this, $objAlbum);
         }
     }
 }
 /**
  * generate an albumalias based on the albumname and create a directory of the same name
  * and register the directory in tl files
  * @param $strAlias
  * @param \Contao\DataContainer $dc
  * @return mixed|string
  */
 public function saveCbGenerateAlias($strAlias, \Contao\DataContainer $dc)
 {
     $blnDoNotCreateDir = false;
     // get current row
     $objAlbum = GalleryCreatorAlbumsModel::findByPk($dc->id);
     if ($objAlbum === null) {
         return;
     }
     // Save assigned Dir if it was defined.
     if ($this->Input->post('FORM_SUBMIT') && strlen($this->Input->post('assignedDir'))) {
         $objAlbum->assignedDir = $this->Input->post('assignedDir');
         $objAlbum->save();
         $blnDoNotCreateDir = true;
     }
     $strAlias = standardize($strAlias);
     // if there isn't an existing albumalias generate one from the albumname
     if (!strlen($strAlias)) {
         $strAlias = standardize($dc->activeRecord->name);
     }
     // limit alias to 50 characters
     $strAlias = substr($strAlias, 0, 43);
     // remove invalid characters
     $strAlias = preg_replace("/[^a-z0-9\\_\\-]/", "", $strAlias);
     // if alias already exists add the album-id to the alias
     $objAlb = $this->Database->prepare('SELECT * FROM tl_gallery_creator_albums WHERE id!=? AND alias=?')->execute($dc->activeRecord->id, $strAlias);
     if ($objAlb->numRows) {
         $strAlias = 'id-' . $dc->id . '-' . $strAlias;
     }
     // Create default upload folder
     if ($blnDoNotCreateDir === false) {
         // create the new folder and register it in tl_files
         $objFolder = new Folder($this->uploadPath . '/' . $strAlias);
         $oFolder = Dbafs::addResource($objFolder->path, true);
         $objAlbum->assignedDir = $oFolder->uuid;
         $objAlbum->save();
         // Important
         Input::setPost('assignedDir', String::binToUuid($objAlbum->assignedDir));
     }
     return $strAlias;
 }
 /**
  * initCounter
  *
  * @param integer
  * @return string
  */
 public static function initCounter($intAlbumId)
 {
     if (preg_match('/bot|sp[iy]der|crawler|lib(?:cur|www)|search|archive/i', $_SERVER['HTTP_USER_AGENT'])) {
         // do not count spiders/bots
         return;
     }
     if (TL_MODE == 'FE') {
         $objAlbum = \GalleryCreatorAlbumsModel::findByPk($intAlbumId);
         if (strpos($objAlbum->visitors_details, $_SERVER['REMOTE_ADDR'])) {
             // return if the visitor is allready registered
             return;
         }
         $arrVisitors = deserialize($objAlbum->visitors_details, true);
         // keep visiors data in the db unless 50 other users have visited the album
         if (count($arrVisitors) == 50) {
             // slice the last position
             $arrVisitors = array_slice($arrVisitors, 0, count($arrVisitors) - 1);
         }
         //build up the array
         $newVisitor = array($_SERVER['REMOTE_ADDR'] => array('ip' => $_SERVER['REMOTE_ADDR'], 'pid' => $intAlbumId, 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'tstamp' => time(), 'url' => \Environment::get('request')));
         if (!empty($arrVisitors)) {
             // insert the element to the beginning of the array
             array_unshift($arrVisitors, $newVisitor);
         } else {
             $arrVisitors[] = array($_SERVER['REMOTE_ADDR'] => $newVisitor);
         }
         // update database
         $objAlbum->visitors = $objAlbum->visitors += 1;
         $objAlbum->visitors_details = serialize($arrVisitors);
         $objAlbum->save();
     }
 }
 /**
  * ondelete-callback
  * prevents deleting images by unauthorised users
  */
 public function ondeleteCb(\Contao\DC_Table $dc)
 {
     $objImg = GalleryCreatorPicturesModel::findByPk($dc->id);
     $pid = $objImg->pid;
     if ($objImg->owner == $this->User->id || $this->User->isAdmin || $GLOBALS['TL_CONFIG']['gc_disable_backend_edit_protection']) {
         // Datensatz löschen
         $uuid = $objImg->uuid;
         $objImg->delete();
         //Nur Bilder innerhalb des gallery_creator_albums und wenn sie nicht in einem anderen Datensatz noch Verwendung finden, werden vom Server geloescht
         // Prüfen, ob das Bild noch mit einem anderen Datensatz verknüpft ist
         $objPictureModel = GalleryCreatorPicturesModel::findByUuid($uuid);
         if ($objPictureModel === null) {
             // Wenn nein darf gelöscht werden...
             $oFile = FilesModel::findByUuid($uuid);
             $objAlbum = GalleryCreatorAlbumsModel::findByPk($pid);
             $oFolder = FilesModel::findByUuid($objAlbum->assignedDir);
             // Bild nur löschen, wenn es im Verzeichnis liegt, das dem Album zugewiesen ist
             if ($oFile !== null && strstr($oFile->path, $oFolder->path)) {
                 // delete file from filesystem
                 $file = new File($oFile->path, true);
                 $file->delete();
             }
         }
     } elseif (!$this->User->isAdmin && $objImg->owner != $this->User->id) {
         $this->log('Datensatz mit ID ' . $dc->id . ' wurde vom  Benutzer mit ID ' . $this->User->id . ' versucht aus tl_gallery_creator_pictures zu loeschen.', __METHOD__, TL_ERROR);
         Message::addError('No permission to delete picture with ID ' . $dc->id . '.');
         $this->redirect('contao/main.php?do=error');
     }
 }
 /**
  * return the level of an album or subalbum (level_0, level_1, level_2,...)
  * @param integer
  * @return integer
  */
 public static function getAlbumLevel($pid)
 {
     $level = 0;
     if ($pid == '0') {
         return $level;
     }
     $hasParent = true;
     while ($hasParent) {
         $level++;
         $objAlbum = \GalleryCreatorAlbumsModel::findByPk($pid);
         if ($objAlbum->pid < 1) {
             $hasParent = false;
         }
         $pid = $objAlbum->pid;
     }
     return $level;
 }