Example #1
0
 public function generated_photos()
 {
     // auth
     Auth::isAdminAuthorized($this->signedUser, 'admin.media.image', true, '/media');
     $photos = \Rebond\Util\File::getFiles('www/media');
     $generated = [];
     $pattern = '/-(.*).(.*)/';
     $count = count($photos);
     for ($i = 0; $i < $count; $i++) {
         if (preg_match($pattern, $photos[$i])) {
             $generated[] = $photos[$i];
             unset($photos[$i]);
         }
     }
     $cleanup = Converter::bool('cleanup');
     if ($cleanup) {
         foreach ($generated as $photo) {
             \Rebond\Util\File::deleteAllMedia('', $photo);
         }
         Session::adminSuccess('generatedPhotosDeleted', '/media/generated-photos');
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Template(Template::SITE, ['admin', 'media']);
     $tplMain->set('photos', $photos);
     $tplMain->set('generated', $generated);
     // layout
     $this->tplLayout->set('column1', $tplMain->render('generated-photos'));
     // master
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col'));
     return $this->tplMaster->render('tpl-default');
 }
Example #2
0
 public function deleteMedia()
 {
     if (!$this->hasPrivilege('admin.media.edit')) {
         return $this->noPrivilege('admin.media.edit');
     }
     $json = [];
     $json['result'] = ResultType::ERROR;
     // check
     $id = Converter::int('id', 'post', 0);
     // get media
     $media = \Rebond\Core\Media\Data::loadById($id);
     if (!isset($media)) {
         $json['message'] = Lang::lang('itemNotFound', [$id]);
         return json_encode($json);
     }
     $count = 0;
     // find app modules that use medium
     $moduleMedium = \Rebond\Cms\ModuleMedia\Data::loadAll();
     if ($moduleMedium) {
         foreach ($moduleMedium as $moduleMedia) {
             $module = \Rebond\Cms\Module\Data::loadById($moduleMedia->getModuleId());
             if (isset($module)) {
                 $appData = '\\Rebond\\App\\' . $module->getTitle() . '\\Data';
                 // count
                 $options = [];
                 $options['where'][] = [$moduleMedia->getField() . ' = ?', $id];
                 $options['where'][] = ['content.version NOT IN (?)', [VersionType::DELETED, VersionType::OLD]];
                 $num = $appData::count($options);
                 $count += $num;
             }
         }
     }
     if ($count > 0) {
         $json['message'] = 'media cannot not been deleted because it is used by <a href="/media/in-use?id=' . $id . '">' . $count . ' item(s)</a>.';
         return json_encode($json);
     }
     $r = \Rebond\Core\Media\Data::deleteById($media->getId());
     if ($r == ResultType::ERROR) {
         $json['message'] = 'media could not be deleted';
         return json_encode($json);
     }
     \Rebond\Util\File::deleteAllMedia($media->getPath(), $media->getUpload());
     $json['result'] = ResultType::SUCCESS;
     $json['message'] = 'media deleted';
     return json_encode($json);
 }