示例#1
0
文件: PictureModel.php 项目: acp3/cms
 /**
  * @inheritdoc
  */
 public function save(array $data, $entryId = null)
 {
     $settings = $this->config->getSettings(Schema::MODULE_NAME);
     $data = array_merge($data, ['comments' => $settings['comments'] == 1 ? isset($data['comments']) && $data['comments'] == 1 ? 1 : 0 : $settings['comments']]);
     if ($entryId === null) {
         $picNum = $this->repository->getLastPictureByGalleryId($entryId);
         $data['pic'] = !is_null($picNum) ? $picNum + 1 : 1;
     }
     return parent::save($data, $entryId);
 }
示例#2
0
 protected function fetchSitemapUrls()
 {
     $this->addUrl('gallery/index/index');
     foreach ($this->galleryRepository->getAll($this->date->getCurrentDateTime()) as $result) {
         $this->addUrl(sprintf(Helpers::URL_KEY_PATTERN_GALLERY, $result['id']), $this->date->format($result['updated_at'], 'Y-m-d'));
         foreach ($this->pictureRepository->getPicturesByGalleryId($result['id']) as $picture) {
             $this->addUrl(sprintf(Helpers::URL_KEY_PATTERN_PICTURE, $picture['id']), $this->date->format($result['updated_at'], 'Y-m-d'));
         }
     }
 }
示例#3
0
文件: Image.php 项目: acp3/cms
 /**
  * @param int    $id
  * @param string $action
  *
  * @return \Symfony\Component\HttpFoundation\Response
  * @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
  */
 public function execute($id, $action = '')
 {
     set_time_limit(20);
     $picture = $this->pictureRepository->getFileById($id);
     $action = $action === 'thumb' ? 'thumb' : '';
     /** @var Core\Picture $image */
     $image = $this->get('core.image');
     $image->setEnableCache($this->config->getSettings(Schema::MODULE_NAME)['cache_images'] == 1)->setCachePrefix('gallery_' . $action)->setCacheDir($this->appPath->getUploadsDir() . 'gallery/cache/')->setMaxWidth($this->settings[$action . 'width'])->setMaxHeight($this->settings[$action . 'height'])->setFile($this->appPath->getUploadsDir() . 'gallery/' . $picture)->setPreferHeight($action === 'thumb');
     if ($image->process()) {
         return $image->sendResponse();
     }
     throw new Core\Controller\Exception\ResultNotExistsException();
 }
 /**
  * @param ModelSaveEvent $event
  */
 public function generatePictureAliases(ModelSaveEvent $event)
 {
     if ($this->aliases && $this->metaStatements && $this->uriAliasManager) {
         $galleryId = $event->getEntryId();
         $pictures = $this->pictureRepository->getPicturesByGalleryId($galleryId);
         $alias = $this->aliases->getUriAlias(sprintf(Gallery\Helpers::URL_KEY_PATTERN_GALLERY, $galleryId), true);
         $seoKeywords = $this->metaStatements->getKeywords(sprintf(Gallery\Helpers::URL_KEY_PATTERN_GALLERY, $galleryId));
         $seoDescription = $this->metaStatements->getDescription(sprintf(Gallery\Helpers::URL_KEY_PATTERN_GALLERY, $galleryId));
         foreach ($pictures as $picture) {
             $this->uriAliasManager->insertUriAlias(sprintf(Gallery\Helpers::URL_KEY_PATTERN_PICTURE, $picture['id']), !empty($alias) ? $alias . '/img-' . $picture['id'] : '', $seoKeywords, $seoDescription);
         }
     }
 }
示例#5
0
文件: Order.php 项目: acp3/cms
 /**
  * @param int    $id
  * @param string $action
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  * @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
  */
 public function execute($id, $action)
 {
     if (($action === 'up' || $action === 'down') && $this->pictureRepository->pictureExists($id) === true) {
         if ($action === 'up') {
             $this->sortHelper->up(Gallery\Model\Repository\PictureRepository::TABLE_NAME, 'id', 'pic', $id, 'gallery_id');
         } else {
             $this->sortHelper->down(Gallery\Model\Repository\PictureRepository::TABLE_NAME, 'id', 'pic', $id, 'gallery_id');
         }
         $galleryId = $this->pictureRepository->getGalleryIdFromPictureId($id);
         $this->galleryCache->saveCache($galleryId);
         Core\Cache\Purge::doPurge($this->appPath->getCacheDir() . 'http');
         return $this->redirect()->temporary('acp/gallery/index/edit/id_' . $galleryId);
     }
     throw new Core\Controller\Exception\ResultNotExistsException();
 }
示例#6
0
文件: Edit.php 项目: acp3/cms
 /**
  * @param int $id
  *
  * @return array
  */
 protected function executeListPictures($id)
 {
     $pictures = $this->pictureRepository->getPicturesByGalleryId($id);
     /** @var Core\Helpers\DataGrid $dataGrid */
     $dataGrid = $this->get('core.helpers.data_grid');
     $dataGrid->setResults($pictures)->setRecordsPerPage($this->resultsPerPage->getResultsPerPage(Schema::MODULE_NAME))->setIdentifier('#acp-table')->setResourcePathDelete('admin/gallery/pictures/delete/id_' . $id)->setResourcePathEdit('admin/gallery/pictures/edit');
     $this->addDataGridColumns($dataGrid);
     return ['grid' => $dataGrid->render(), 'show_mass_delete_button' => $dataGrid->countDbResults() > 0];
 }
示例#7
0
文件: Delete.php 项目: acp3/cms
 /**
  * @param int $id
  * @param string $action
  *
  * @return mixed
  * @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
  */
 public function execute($id, $action = '')
 {
     return $this->actionHelper->handleDeleteAction($action, function (array $items) {
         $bool = false;
         foreach ($items as $item) {
             if (!empty($item) && $this->pictureRepository->pictureExists($item) === true) {
                 $picture = $this->pictureRepository->getOneById($item);
                 $this->pictureRepository->updatePicturesNumbers($picture['pic'], $picture['gallery_id']);
                 $this->galleryHelpers->removePicture($picture['file']);
                 $bool = $this->pictureRepository->delete($item);
                 if ($this->uriAliasManager) {
                     $this->uriAliasManager->deleteUriAlias(sprintf(Gallery\Helpers::URL_KEY_PATTERN_PICTURE, $item));
                 }
                 $this->galleryCache->saveCache($picture['gallery_id']);
             }
         }
         Core\Cache\Purge::doPurge($this->appPath->getCacheDir() . 'http');
         return $bool;
     }, 'acp/gallery/pictures/delete/id_' . $id, 'acp/gallery/index/edit/id_' . $id);
 }
示例#8
0
文件: Cache.php 项目: acp3/cms
 /**
  * Erstellt den Galerie-Cache anhand der angegebenen ID
  *
  * @param integer $galleryId
  *
  * @return boolean
  */
 public function saveCache($galleryId)
 {
     $pictures = $this->pictureRepository->getPicturesByGalleryId($galleryId);
     $cPictures = count($pictures);
     $settings = $this->config->getSettings(Schema::MODULE_NAME);
     for ($i = 0; $i < $cPictures; ++$i) {
         $pictures[$i]['width'] = $settings['thumbwidth'];
         $pictures[$i]['height'] = $settings['thumbheight'];
         $picInfos = @getimagesize($this->appPath->getModulesDir() . 'gallery/' . $pictures[$i]['file']);
         if ($picInfos !== false) {
             if ($picInfos[0] > $settings['thumbwidth'] || $picInfos[1] > $settings['thumbheight']) {
                 $newHeight = $settings['thumbheight'];
                 $newWidth = intval($picInfos[0] * $newHeight / $picInfos[1]);
             }
             $pictures[$i]['width'] = isset($newWidth) ? $newWidth : $picInfos[0];
             $pictures[$i]['height'] = isset($newHeight) ? $newHeight : $picInfos[1];
         }
     }
     return $this->cache->save(self::CACHE_ID . $galleryId, $pictures);
 }
示例#9
0
文件: Delete.php 项目: acp3/cms
 /**
  * @param integer $galleryId
  *
  * @return boolean
  */
 protected function deletePictureAliases($galleryId)
 {
     if ($this->uriAliasManager) {
         $pictures = $this->pictureRepository->getPicturesByGalleryId($galleryId);
         $cPictures = count($pictures);
         for ($i = 0; $i < $cPictures; ++$i) {
             $this->uriAliasManager->deleteUriAlias(sprintf(Gallery\Helpers::URL_KEY_PATTERN_PICTURE, $pictures[$i]['id']));
         }
     }
     return true;
 }
示例#10
0
文件: Details.php 项目: acp3/cms
 /**
  * @param int $id
  *
  * @return array
  * @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
  */
 public function execute($id)
 {
     if ($this->pictureRepository->pictureExists($id, $this->date->getCurrentDateTime()) === true) {
         $this->setCacheResponseCacheable($this->config->getSettings(Schema::MODULE_NAME)['cache_lifetime']);
         $picture = $this->pictureRepository->getOneById($id);
         $this->breadcrumb->append($this->translator->t('gallery', 'gallery'), 'gallery')->append($picture['title'], 'gallery/index/pics/id_' . $picture['gallery_id'])->append($this->translator->t('gallery', 'details'));
         $this->title->setPageTitlePrefix($picture['title'])->setPageTitlePostfix($this->translator->t('gallery', 'picture_x', ['%picture%' => $picture['pic']]));
         $picture = $this->calculatePictureDimensions($picture);
         $previousPicture = $this->pictureRepository->getPreviousPictureId($picture['pic'], $picture['gallery_id']);
         if (!empty($previousPicture)) {
             $this->setPreviousPage((int) $previousPicture);
         }
         $nextPicture = $this->pictureRepository->getNextPictureId($picture['pic'], $picture['gallery_id']);
         if (!empty($nextPicture)) {
             $this->setNextPage((int) $nextPicture);
         }
         return ['picture' => $picture, 'picture_next' => $nextPicture, 'picture_previous' => $previousPicture, 'comments_allowed' => $this->isCommentsAllowed($picture)];
     }
     throw new Core\Controller\Exception\ResultNotExistsException();
 }
示例#11
0
文件: Create.php 项目: acp3/cms
 /**
  * Setzt einen einzelnen Alias für ein Bild einer Fotogalerie
  *
  * @param integer $pictureId
  *
  * @return boolean
  */
 protected function generatePictureAlias($pictureId)
 {
     if ($this->aliases && $this->metaStatements && $this->uriAliasManager) {
         $galleryId = $this->pictureRepository->getGalleryIdFromPictureId($pictureId);
         $alias = $this->aliases->getUriAlias(sprintf(Gallery\Helpers::URL_KEY_PATTERN_GALLERY, $galleryId), true);
         if (!empty($alias)) {
             $alias .= '/img-' . $pictureId;
         }
         $seoKeywords = $this->metaStatements->getKeywords(sprintf(Gallery\Helpers::URL_KEY_PATTERN_GALLERY, $galleryId));
         $seoDescription = $this->metaStatements->getDescription(sprintf(Gallery\Helpers::URL_KEY_PATTERN_GALLERY, $galleryId));
         return $this->uriAliasManager->insertUriAlias(sprintf(Gallery\Helpers::URL_KEY_PATTERN_PICTURE, $pictureId), $alias, $seoKeywords, $seoDescription);
     }
     return true;
 }