Esempio n. 1
0
 /**
  * Build content data to model properties
  * @param $records
  * @throws ForbiddenException
  * @throws NotFoundException
  */
 private function buildContent($records)
 {
     $nullItems = 0;
     foreach ($records as $row) {
         /** @var Content $row */
         // check title length on current language locale
         $localeTitle = $row->getLocaled('title');
         if (Str::likeEmpty($localeTitle)) {
             ++$nullItems;
             continue;
         }
         // get snippet from full text for current locale
         $text = Text::snippet($row->getLocaled('text'));
         $itemPath = $this->categories[$row->category_id]->path;
         if (!Str::likeEmpty($itemPath)) {
             $itemPath .= '/';
         }
         $itemPath .= $row->path;
         // prepare tags data
         $tags = $row->getLocaled('meta_keywords');
         if (!Str::likeEmpty($tags)) {
             $tags = explode(',', $tags);
         } else {
             $tags = null;
         }
         $owner = App::$User->identity($row->author_id);
         // make a fake if user is not exist over id
         if ($owner === null) {
             $owner = new User();
         }
         // check if current user can rate item
         $ignoredRate = App::$Session->get('content.rate.ignore');
         $canRate = true;
         if (Obj::isArray($ignoredRate) && Arr::in((string) $row->id, $ignoredRate)) {
             $canRate = false;
         }
         if (!App::$User->isAuth()) {
             $canRate = false;
         } elseif ($owner->getId() === App::$User->identity()->getId()) {
             // own item
             $canRate = false;
         }
         // build result array
         $this->items[] = ['id' => $row->id, 'title' => $localeTitle, 'text' => $text, 'date' => Date::humanize($row->created_at), 'updated' => $row->updated_at, 'author' => $owner, 'poster' => $row->getPosterUri(), 'thumb' => $row->getPosterThumbUri(), 'thumbSize' => File::size($row->getPosterThumbUri()), 'views' => (int) $row->views, 'rating' => (int) $row->rating, 'canRate' => $canRate, 'category' => $this->categories[$row->category_id], 'uri' => '/content/read/' . $itemPath, 'tags' => $tags];
     }
     if ($nullItems === $this->_contentCount) {
         throw new NotFoundException(__('Content is not founded'));
     }
 }
Esempio n. 2
0
 /**
  * Show gallery images from upload directory
  * @param int $id
  * @return string
  * @throws NotFoundException
  * @throws NativeException
  */
 public function actionGallerylist($id)
 {
     // check if id is passed
     if (Str::likeEmpty($id)) {
         throw new NativeException('Wrong input data');
     }
     // check if user have permission to access there
     if (!App::$User->isAuth() || !App::$User->identity()->getRole()->can('global/file')) {
         throw new NativeException('Permission denied');
     }
     $thumbDir = Normalize::diskFullPath('/upload/gallery/' . $id . '/orig/');
     if (!Directory::exist($thumbDir)) {
         throw new NotFoundException('Nothing found');
     }
     $files = Directory::scan($thumbDir, null, true);
     if ($files === false || !Obj::isArray($files) || count($files) < 1) {
         throw new NotFoundException('Nothing found');
     }
     $output = [];
     foreach ($files as $file) {
         $fileExt = Str::lastIn($file, '.');
         $fileName = Str::sub($file, 0, -Str::length($fileExt));
         $output[] = ['thumbnailUrl' => '/upload/gallery/' . $id . '/thumb/' . $fileName . '.jpg', 'url' => '/upload/gallery/' . $id . '/orig/' . $file, 'name' => $file, 'size' => File::size('/upload/gallery/' . $id . '/orig/' . $file)];
     }
     $this->setJsonHeader();
     return json_encode(['status' => 1, 'files' => $output]);
 }