public function editAction()
 {
     $comment_id = (int) $this->getParam('id');
     $form_config = $this->current_module_config->forms->upload_comment;
     $form = new \FA\Form($form_config);
     $form->populate($_POST);
     if ($_POST && $form->isValid($_POST) && $this->csrf->verify($form->getValue('csrf'), '_upload_comments')) {
         // TODO: Check comment edit rate limit here!
         $comment = UploadComment::find($comment_id);
         if (!$comment instanceof UploadComment) {
             throw new \FA\Exception('Comment not found!');
         }
         if (!$comment->canEdit($this->user)) {
             throw new \FA\Exception('Unable to edit comment!');
         }
         $upload = $comment->upload;
         // Prevent posting if comments are locked
         if ($upload->comments_locked) {
             throw new \FA\Exception('Comments are locked on this Upload!');
         }
         // Verify the user can even progress further
         self::_userCheck($upload);
         // Update the comment's text
         $comment->message = $form->getValue('JSMessage');
         $comment->save();
         // Redirect to the Upload page to our comment!
         // TODO: Add a way to auto-lock on to the comment. Maybe a perma-link style approach?
         return $this->redirectToName('upload_view', array('id' => $upload->id));
     }
 }
示例#2
0
 public function indexAction()
 {
     // TODO: Use variable for this setting.
     $per_page = 48;
     $form_config = $this->current_module_config->forms->browse->toArray();
     if (!$this->fa->canSeeArt('mature')) {
         unset($form_config['elements']['rating'][1]['options'][Upload::RATING_MATURE]);
         unset($form_config['elements']['rating'][1]['options'][Upload::RATING_ADULT]);
     } elseif (!$this->fa->canSeeArt('adult')) {
         unset($form_config['elements']['rating'][1]['options'][Upload::RATING_ADULT]);
     }
     $form = new \FA\Form($form_config);
     if ($this->request->isPost() && $form->isValid($_POST)) {
         $filters = $form->getValues();
     } else {
         $filters = $form->getDefaults();
     }
     // Force form to default to page 1, so that if filters change, the page will reset.
     $form->populate(array('page' => 1));
     $this->view->form = $form;
     // Create query builder.
     $qb = $this->em->createQueryBuilder();
     $qb->select('up')->from('Entity\\Upload up');
     if (!empty($filters['category']) && $filters['category'] != 1) {
         $qb->andWhere('up.category = :category')->setParameter('category', $filters['category']);
     }
     if (!empty($filters['theme']) && $filters['theme'] != 1) {
         $qb->andWhere('up.theme = :theme')->setParameter('theme', $filters['theme']);
     }
     if (!empty($filters['species']) && $filters['species'] != 1) {
         $qb->andWhere('up.species = :species')->setParameter('species', $filters['species']);
     }
     if (!empty($filters['gender']) && $filters['gender'] != 0) {
         $qb->andWhere('up.gender = :gender')->setParameter('gender', $filters['gender']);
     }
     if (isset($filters['rating'])) {
         $qb->andWhere('up.rating IN (:ratings)')->setParameter('ratings', (array) $filters['rating']);
         if (in_array(Upload::RATING_MATURE, $filters['rating']) || in_array(Upload::RATING_ADULT, $filters['rating'])) {
             $this->fa->setPageHasMatureContent(true);
         }
     }
     $query = $qb->orderBy('up.created_at', 'DESC')->getQuery();
     $pager = new \FA\Paginator\Doctrine($query, $filters['page'], $per_page);
     $this->view->page_current = $filters['page'];
     $this->view->page_count = $pager->getPageCount();
     $this->view->pager = $pager;
     $this->view->thumbnail_size = $this->user->getVariable('thumbnail_size');
 }
示例#3
0
 public function editAction()
 {
     $this->fa->readOnly();
     $form_config = $this->current_module_config->forms->journal->toArray();
     $form = new \FA\Form($form_config);
     $record = null;
     $edit_mode = false;
     $id = (int) $this->getParam('id');
     if ($id != 0) {
         $record = Journal::getRepository()->findOneBy(array('id' => $id, 'user_id' => $this->user->id));
         if (!$record instanceof Journal) {
             throw new \FA\Exception('Journal entry not found!');
         }
         $record_info = $record->toArray(FALSE, TRUE);
         if ($this->user->getVariable('featured_journal_id') == $id) {
             $record_info['is_featured'] = 1;
         }
         $form->populate($record_info);
         $edit_mode = true;
     }
     if ($this->request->isPost() && $form->isValid($_POST)) {
         if (!$record instanceof Journal) {
             $record = new Journal();
             $record->user = $this->user;
         }
         $data = $form->getValues();
         if ($data['is_featured']) {
             $this->user->setVariable('featured_journal_id', $id);
         } elseif ($this->user->getVariable('featured_journal_id') == $id) {
             $this->user->deleteVariable('featured_journal_id');
         }
         $record->fromArray($data);
         $record->save();
         if ($edit_mode) {
             $this->alert('<b>Journal edited!</b>', 'green');
         } else {
             $this->alerT('<b>New journal posted!</b>', 'green');
         }
         return $this->redirectFromHere(array('action' => 'index', 'id' => NULL));
     }
     $this->view->edit_mode = $edit_mode;
     $this->view->form = $form;
 }
示例#4
0
 public function indexAction()
 {
     $form_config = $this->current_module_config->forms->search->toArray();
     $form_config['elements']['perpage']['default'] = $this->user->getVariable('perpage');
     if (!$this->fa->canSeeArt('mature')) {
         unset($form_config['elements']['rating'][1]['options'][Upload::RATING_MATURE]);
         unset($form_config['elements']['rating'][1]['options'][Upload::RATING_ADULT]);
     } elseif (!$this->fa->canSeeArt('adult')) {
         unset($form_config['elements']['rating'][1]['options'][Upload::RATING_ADULT]);
     }
     $form = new \FA\Form($form_config);
     $data = $form->getDefaults();
     if ($this->request->isPost() && $form->isValid($_POST)) {
         // Leave all values default if not specified by the user.
         $data = array_merge($data, array_filter($form->getValues()));
     }
     // Force form to default to page 1, so that if filters change, the page will reset.
     $form->populate(array('page' => 1));
     $this->view->form = $form;
     $pager = NULL;
     // Run the search query if the terms were provided
     if (!empty($data['q'])) {
         // TODO: Add user search back into this.
         // Create the sphinx request hash
         $sphinx_request['q'] = preg_replace('/[\\x00-\\x1F]/', ' ', $data['q']);
         $sphinx_request['page'] = $data['page'];
         $sphinx_request['perpage'] = $data['perpage'];
         $sphinx_request['use_index'] = 'submissions_delta submissions';
         $sphinx_request['match_mode'] = $this->_sphinx_match_mode($data['mode']);
         $sphinx_request['field_weights'] = array('title' => 3, 'keywords' => 4, 'message' => 2, 'filename' => 1, 'lower' => 1);
         $sphinx_request['order_by'] = $data['order_by'];
         $sphinx_request['order_direction'] = $data['order_direction'];
         // Filters
         $sphinx_request['filters'] = array();
         if (isset($data['rating'])) {
             $sphinx_request['filters']['adultsubmission'] = (array) $data['rating'];
             if (in_array(Upload::RATING_MATURE, $data['rating']) || in_array(Upload::RATING_ADULT, $data['rating'])) {
                 $this->fa->setPageHasMatureContent(true);
             }
         }
         if (!empty($data['type'])) {
             $sphinx_request['filters']['type'] = $data['type'];
         }
         if ($data['range'] != 0) {
             $sphinx_request['filters']['date'] = array(time() - $data['range'], time());
         }
         // Make the request
         $sphinx_error = NULL;
         $sphinx_warning = NULL;
         $sphinx_result = $this->_sphinx_make_request($sphinx_request, $sphinx_error, $sphinx_warning);
         if (!$sphinx_result) {
             throw new \FA\Exception($sphinx_error);
         }
         if ($sphinx_result['total_found'] && isset($sphinx_result['matches']) && is_array($sphinx_result['matches'])) {
             $found_docs = array();
             $doc_info = array();
             foreach ($sphinx_result['matches'] as $match) {
                 $found_docs[] = $match['id'];
                 $doc_info[$match['id']] = $match;
             }
             $result = $this->em->createQuery('SELECT up, us, field(up.id, :ids) AS HIDDEN field FROM Entity\\Upload up JOIN up.user us WHERE up.id IN (:ids) ORDER BY field')->setParameter('ids', $found_docs)->execute();
             $pager = new \FA\Paginator\Sphinx($result, $sphinx_result['total_found'], $data['page'], $data['perpage']);
         }
     }
     if (!$pager) {
         $pager = new \FA\Paginator\Sphinx(array(), 0, $data['page'], $data['perpage']);
     }
     $this->view->page_current = $data['page'];
     $this->view->page_count = $pager->getPageCount();
     $this->view->pager = $pager;
     $this->view->thumbnail_size = $this->user->getVariable('thumbnail_size');
 }
示例#5
0
 public function editgroupAction()
 {
     $this->fa->readOnly();
     $form_config = $this->current_module_config->forms->foldergroup->toArray();
     $form = new \FA\Form($form_config);
     $id = (int) $this->getParam('id');
     if ($id) {
         $record = FolderGroup::getRepository()->findOneBy(array('id' => $id, 'user_id' => $this->user->id));
         if (!$record instanceof FolderGroup) {
             throw new \FA\Exception('Folder ID not found!');
         }
         $form->populate($record->toArray());
     }
     if ($this->request->isPost() && $form->isValid($_POST)) {
         $data = $form->getValues();
         if (!$record instanceof FolderGroup) {
             // TODO: Enforce folder count limit.
             $record = new FolderGroup();
             $record->user = $this->user;
             $record->sort_order = 100;
         }
         $record->fromArray($data);
         $record->save();
         $this->_reSort();
         $this->alert('<b>Group updated!</b>', 'green');
         return $this->redirectFromHere(array('action' => 'index', 'id' => NULL));
     }
     $this->view->form = $form;
 }