public static function addFile($objFile)
 {
     $checksum = md5(preg_replace('/ +/', ' ', strip_tags($objFile->copyright)));
     $objModel = FileCreditModel::findByUuid($objFile->uuid);
     // do not index again if copyright did not change, but add the current page
     if ($objModel !== null && $checksum == $objModel->checksum) {
         static::addCurrentPage($objModel);
         return false;
     }
     $arrSet = array('tstamp' => time(), 'uuid' => $objFile->uuid, 'checksum' => $checksum, 'published' => 1, 'start' => '', 'stop' => '');
     if ($objModel !== null) {
         // delete: remove credit if copyright is empty
         if ($objFile->copyright == '') {
             // remove all pages for the credit before
             FileCreditPageModel::deleteByPid($objModel->id);
             $objModel->delete();
             return false;
         }
         // update: otherwise update existing filecredit
         $objModel->setRow($arrSet);
         $objModel->save();
         static::addCurrentPage($objModel);
         return true;
     }
     // create: add new credit
     if ($objFile->copyright != '') {
         $objModel = new FileCreditModel();
         $objModel->setRow($arrSet);
         $objModel->save();
         static::addCurrentPage($objModel);
         return true;
     }
     return false;
 }
 public static function parseCredit(FileCreditModel $objModel, array $arrPids = array(), $objModule)
 {
     global $objPage;
     $objTemplate = new \FrontendTemplate(!$objModule->creditsGroupBy ? 'filecredit_default' : 'filecredit_grouped');
     // skip if no files model exists
     if (($objFilesModel = $objModel->getRelated('uuid')) === null) {
         return null;
     }
     // cleanup: remove credits where copyright was deleted
     if ($objFilesModel->copyright == '') {
         FileCreditPageModel::deleteByPid($objModel->id);
         $objModel->delete();
         return null;
     }
     // skip if credit occurs on no page
     if (($objCreditPages = FileCreditPageModel::findPublishedByPids(array($objModel->id))) === null) {
         return null;
     }
     while ($objCreditPages->next()) {
         $arrCredit = $objCreditPages->row();
         // not a child of current root page
         if (!empty($arrPids) && !in_array($arrCredit['page'], $arrPids)) {
             continue;
         }
         if ($arrCredit['url'] == '' && ($objTarget = \PageModel::findByPk($arrCredit['page'])) !== null) {
             $arrCredit['url'] = \Controller::generateFrontendUrl($objTarget->row());
         }
         $arrPages[] = $arrCredit;
     }
     if ($arrPages === null) {
         return null;
     }
     $objTemplate->setData($objModel->row());
     $objTemplate->fileData = $objFilesModel->row();
     static::addCopyrightToTemplate($objTemplate, $objFilesModel, $objModule);
     $objTemplate->link = $GLOBALS['TL_LANG']['MSC']['creditLinkText'];
     $objTemplate->pagesLabel = $GLOBALS['TL_LANG']['MSC']['creditPagesLabel'];
     $objTemplate->path = $objFilesModel->path;
     $objTemplate->pages = $arrPages;
     $objTemplate->pageCount = count($arrPages);
     // colorbox support
     if ($objPage->outputFormat == 'xhtml') {
         $strLightboxId = 'lightbox';
     } else {
         $strLightboxId = 'lightbox[' . substr(md5($objTemplate->getName() . '_' . $objFilesModel->id), 0, 6) . ']';
     }
     $objTemplate->attribute = $strLightboxId ? ($objPage->outputFormat == 'html5' ? ' data-gallery="#gallery-' . $objModule->id . '" data-lightbox="' : ' rel="') . $strLightboxId . '"' : '';
     $objTemplate->addImage = false;
     // Add an image
     if (!is_file(TL_ROOT . '/' . $objModel->path)) {
         $arrData = array('singleSRC' => $objFilesModel->path, 'doNotIndex' => true);
         $size = deserialize($objModule->imgSize);
         if ($size[0] > 0 || $size[1] > 0 || is_numeric($size[2])) {
             $arrData['size'] = $objModule->imgSize;
         }
         \Controller::addImageToTemplate($objTemplate, $arrData);
     }
     return array('pages' => $arrPages, 'order' => static::getSortValue($objModule->creditsSortBy, $objTemplate), 'group' => static::getGroupValue($objModule->creditsGroupBy, $objTemplate), 'output' => $objTemplate->parse());
 }
 protected function compile()
 {
     FileCredit::indexStop();
     $arrPids = array();
     if ($this->defineRoot && $this->rootPage > 0) {
         if (($objRoot = $this->objModel->getRelated('rootPage')) !== null) {
             $arrPids = \Database::getInstance()->getChildRecords(array($objRoot->id), 'tl_page');
         }
     }
     $objCredits = FileCreditModel::findByPublished();
     if ($objCredits === null) {
         $this->Template->empty = $GLOBALS['TL_LANG']['MSC']['emptyCreditList'];
         return;
     }
     $this->Template->cssClass = 'sortby_' . $this->creditsSortBy;
     $this->Template->cssClass .= $this->creditsGroupBy ? ' groupby_' . $this->creditsGroupBy : '';
     $this->Template->group = $this->creditsGroupBy;
     $this->Template->credits = FileCredit::parseCredits($objCredits, $arrPids, $this);
     FileCredit::indexContinue();
 }
Exemplo n.º 4
0
 protected function getFileCredits()
 {
     $arrAllowedTypes = trimsplit(',', strtolower($GLOBALS['TL_CONFIG']['validImageTypes']));
     $objSingleSRCCredits = FileCreditModel::findMultiplePublishedSingleSRCContentElementsByExtensions($this->arrPids, $arrAllowedTypes);
     $objMultiSRCCredits = FileCreditModel::findMultiplePublishedMultiSRCContentElements($this->arrPids, $arrAllowedTypes);
     $objMultiSelectedCredits = FileCreditModel::findMultiplePublishedBySelectedCredits(deserialize($this->selectedCredits));
     if ($objSingleSRCCredits === null) {
         $objSingleSRCCredits = array();
     }
     if ($objMultiSRCCredits === null) {
         $objMultiSRCCredits = array();
     }
     if ($objMultiSelectedCredits === null) {
         $objMultiSelectedCredits = array();
     }
     $arrAll = array_merge($objSingleSRCCredits, $objMultiSRCCredits, $objMultiSelectedCredits);
     if ($arrAll === null) {
         return null;
     }
     uasort($arrAll, 'HeimrichHannot\\FileCredit\\FileCredit::sortByParent');
     return $arrAll;
 }