Example #1
0
 private function onAdd()
 {
     $form = $this->formAdd();
     if (false !== ($error = $form->validate($this->module))) {
         return $error . $this->templateAdd();
     }
     $file = $form->getVar('file');
     $tmp = $file['tmp_name'];
     $postid = $this->post->getID();
     $userid = GWF_Session::getUserID();
     $options = 0;
     $options |= isset($_POST['guest_view']) ? GWF_ForumAttachment::GUEST_VISIBLE : 0;
     $options |= isset($_POST['guest_down']) ? GWF_ForumAttachment::GUEST_DOWNLOAD : 0;
     # Put in db
     $attach = new GWF_ForumAttachment(array('fatt_aid' => 0, 'fatt_uid' => $userid, 'fatt_pid' => $postid, 'fatt_mime' => GWF_Upload::getMimeType($tmp), 'fatt_size' => filesize($tmp), 'fatt_downloads' => 0, 'fatt_filename' => $file['name'], 'fatt_options' => $options, 'fatt_date' => GWF_Time::getDate(GWF_Date::LEN_SECOND)));
     if (false === $attach->insert()) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     $aid = $attach->getID();
     # Copy file
     $path = $attach->dbimgPath();
     if (false === GWF_Upload::moveTo($file, $path)) {
         @unlink($tmp);
         return GWF_HTML::err('ERR_WRITE_FILE', $path);
     }
     @unlink($tmp);
     $this->post->increase('post_attachments', 1);
     return $this->module->message('msg_attach_added', array($this->post->getShowHREF()));
 }
Example #2
0
 private function sanitize()
 {
     $this->quoted = Common::getGet('quote') !== false;
     if (false === ($pid = Common::getGet('pid'))) {
         if (false === ($this->thread = $this->module->getCurrentThread())) {
             return $this->module->error('err_post');
         }
         if (false === ($this->post = $this->thread->getLastPost())) {
             //				return $this->module->error('err_post');
         }
         $this->replyThread = true;
     } elseif (false === ($this->post = $this->module->getCurrentPost())) {
         return $this->module->error('err_post');
     } else {
         if (false === ($this->thread = $this->post->getThread())) {
             return $this->module->error('err_post');
         }
     }
     # Check Permission
     $user = GWF_Session::getUser();
     if (!$this->thread->hasReplyPermission($user, $this->module)) {
         $a = GWF_HTML::display($this->post->getShowHREF());
         return $this->module->error('err_reply_perm', array($a));
     }
     if (false !== ($last_post = $this->thread->getLastPost())) {
         if ($last_post->getPosterID() === GWF_Session::getUserID()) {
             if (!$this->module->cfgDoublePost()) {
                 $a = GWF_HTML::display($this->post->getShowHREF());
                 return $this->module->error('err_better_edit', array($a));
             }
         }
     }
     return false;
 }
Example #3
0
 private function onEdit()
 {
     $form = $this->formEdit();
     if (false !== ($error = $form->validate($this->module))) {
         return $error;
     }
     $prepend = '';
     # Re-Upload
     if (false !== ($file = $form->getVar('file')) & $file['size'] !== 0) {
         if (false !== ($error = $this->unReUpload($file, $this->attach))) {
             return $error;
         }
         $prepend = $this->module->message('msg_reupload');
     }
     # Save option
     $this->attach->saveOption(GWF_ForumAttachment::GUEST_VISIBLE, isset($_POST['guest_view']));
     $this->attach->saveOption(GWF_ForumAttachment::GUEST_DOWNLOAD, isset($_POST['guest_down']));
     return $prepend . $this->module->message('msg_attach_edited', array($this->post->getShowHREF()));
 }