Example #1
0
 public function handleGalleryDeleteItem($imageId = 0)
 {
     if ($this->mainManager instanceof MagicManager && $this->mainManager->isGallery()) {
         $image = $this->mainManager->getGalleryImage($imageId);
         if ($image) {
             // delete image from database
             $this->mainManager->removeGalleryImage($imageId);
             $this->imageStorage->setNamespace($image->namespace);
             $this->imageStorage->deleteFile($image->filename);
             if ($this->isAjax()) {
                 $this->payload->datalistRemoveLine = TRUE;
                 $this->sendPayload();
             }
         } else {
             $this->flashMessage('Image not found', 'error');
             if ($this->isAjax()) {
                 $this->redrawControl('flashes');
             }
         }
         if (!$this->isAjax()) {
             $this->redirect('multifile');
         }
     } else {
         $this->error();
     }
 }
Example #2
0
 /**
  * @param Form $form
  * @throws ForbiddenRequestException
  */
 public function articleFormSucceeded(Form $form)
 {
     $v = $form->getValues();
     if (!$this->user->isAllowed('Article', 'add') || !$this->user->isAllowed('Article', 'edit')) {
         throw new ForbiddenRequestException();
     }
     $tags = [];
     if ($v->tags !== '') {
         $articleTags = explode(',', $v->tags);
         $tags = $this->articleManager->createTagsAndReturnIds($articleTags);
     }
     // type
     if ($v->type != 'default') {
         $type = $this->articleManager->addTag($v->type, 'type');
     } else {
         $type = NULL;
     }
     if ($v->draft) {
         $draft = TRUE;
     } else {
         $draft = FALSE;
     }
     if (empty($this->article)) {
         $article = $this->articleManager->addArticle($v->title, $v->content, $draft, $v->language, $tags, $type, $this->getUser()->getId());
         $this->versionManager->addVersionToArticle($v->version, $article->id);
         $this->flashMessage('Article was added');
         $this->redirect('Detail:default', $article->id, $article->slug);
     } else {
         // file upload
         if ($v->file->isOk()) {
             /** @var \Nette\Http\FileUpload $file */
             $file = $v->file;
             // TODO : refactor
             $this->imageStorage->setNamespace("knowledgebase");
             $filename = uniqid() . '.' . (pathinfo($file->name, PATHINFO_EXTENSION) ?: 'png');
             $image = $this->imageStorage->save($file->getContents(), $filename);
             $returnPath = pathinfo($image->file, PATHINFO_BASENAME);
             $note = '';
             if ($v->fileNote) {
                 $note = $v->fileNote;
             }
             $status = $this->articleManager->assignImageToArticle($this->article->id, $returnPath, "knowledgebase", $note);
             if ($status) {
                 $this->flashMessage('Image was uploaded');
             }
         }
         $this->article = $this->articleManager->editArticle($this->article->id, $v->title, $v->content, $draft, $v->language, $tags, $type, $this->getUser()->getId());
         // .. Update version
         $this->versionManager->updateVersion($v->version, $this->article->id);
         $this->flashMessage('Article was updated');
         if (isset($form['sendAndView']) && $form['sendAndView']->isSubmittedBy()) {
             $this->redirect('Detail:default', $this->article->id, $this->article->slug);
         } else {
             $this->redirect('Edit:edit', $this->article->id);
         }
     }
 }
 /**
  * TODO: refactor use Aprila/Brick/ImageManager
  */
 public function handleSaveImage()
 {
     $this->imageStorage->setNamespace("texy");
     $onlinePath = 'texy/';
     $response = array();
     /** @var \Nette\Http\FileUpload $file */
     if ($file = $this->httpRequest->getFile('file')) {
         $filename = uniqid() . '.' . (pathinfo($file->name, PATHINFO_EXTENSION) ?: 'png');
         $image = $this->imageStorage->save($file->getContents(), $filename);
         $returnPath = pathinfo($image->file, PATHINFO_BASENAME);
         if (FALSE) {
             // $this->someManager->assignImageToObject($this->object->id, $returnPath, "texy");
         }
         $response['filename'] = $onlinePath . pathinfo($image->file, PATHINFO_BASENAME);
     } else {
         $response['error'] = 'Error while uploading file';
     }
     $this->sendJson($response);
 }
 public function handleGalleryDeleteItem($imageId = 0)
 {
     $image = $this->database->table('image')->get($imageId);
     if ($image) {
         $this->imageStorage->setNamespace($image->namespace);
         $this->imageStorage->deleteFile($image->filename);
         $this->database->table('image')->wherePrimary($image->id)->delete();
         if ($this->isAjax()) {
             $this->payload->datalistRemoveLine = TRUE;
             $this->sendPayload();
         }
     } else {
         $this->flashMessage('Image not found', 'error');
         if ($this->isAjax()) {
             $this->sendPayload();
         }
     }
     if (!$this->isAjax()) {
         $this->redirect('multifile');
     }
 }