コード例 #1
0
 public function processRequest()
 {
     $request = $this->getRequest();
     $macro_table = new PhabricatorFileImageMacro();
     if ($request->getStr('name') !== null) {
         $macros = $macro_table->loadAllWhere('name LIKE %~', $request->getStr('name'));
     } else {
         $pager = new AphrontPagerView();
         $pager->setOffset($request->getInt('page'));
         $macros = $macro_table->loadAllWhere('1 = 1 ORDER BY id DESC LIMIT %d, %d', $pager->getOffset(), $pager->getPageSize());
         // Get an exact count since the size here is reasonably going to be a few
         // thousand at most in any reasonable case.
         $count = queryfx_one($macro_table->establishConnection('r'), 'SELECT COUNT(*) N FROM %T', $macro_table->getTableName());
         $count = $count['N'];
         $pager->setCount($count);
         $pager->setURI($request->getRequestURI(), 'page');
     }
     $file_phids = mpull($macros, 'getFilePHID');
     $files = array();
     if ($file_phids) {
         $files = id(new PhabricatorFile())->loadAllWhere("phid IN (%Ls)", $file_phids);
         $author_phids = mpull($files, 'getAuthorPHID', 'getPHID');
         $handles = id(new PhabricatorObjectHandleData($author_phids))->loadHandles();
     }
     $files_map = mpull($files, null, 'getPHID');
     $rows = array();
     foreach ($macros as $macro) {
         $file_phid = $macro->getFilePHID();
         $file = idx($files_map, $file_phid);
         $author_link = isset($author_phids[$file_phid]) ? $handles[$author_phids[$file_phid]]->renderLink() : null;
         $rows[] = array(phutil_render_tag('a', array('href' => '/file/macro/edit/' . $macro->getID() . '/'), phutil_escape_html($macro->getName())), $author_link, phutil_render_tag('a', array('href' => $file ? $file->getBestURI() : null, 'target' => '_blank'), phutil_render_tag('img', array('src' => $file ? $file->getBestURI() : null))), javelin_render_tag('a', array('href' => '/file/macro/delete/' . $macro->getID() . '/', 'sigil' => 'workflow', 'class' => 'grey small button'), 'Delete'));
     }
     $table = new AphrontTableView($rows);
     $table->setHeaders(array('Name', 'Author', 'Image', ''));
     $table->setColumnClasses(array('pri', '', 'wide thumb', 'action'));
     $filter_form = id(new AphrontFormView())->setMethod('GET')->setAction('/file/macro/')->setUser($request->getUser())->appendChild(id(new AphrontFormTextControl())->setName('name')->setLabel('Name')->setValue($request->getStr('name')))->appendChild(id(new AphrontFormSubmitControl())->setValue('Filter Image Macros'));
     $filter_view = new AphrontListFilterView();
     $filter_view->appendChild($filter_form);
     $filter_view->addButton(phutil_render_tag('a', array('href' => '/file/macro/edit/', 'class' => 'green button'), 'New Image Macro'));
     $panel = new AphrontPanelView();
     $panel->appendChild($table);
     $panel->setHeader('Image Macros');
     if ($request->getStr('name') === null) {
         $panel->appendChild($pager);
     }
     $side_nav = new PhabricatorFileSideNavView();
     $side_nav->setSelectedFilter('all_macros');
     $side_nav->appendChild($filter_view);
     $side_nav->appendChild($panel);
     return $this->buildStandardPageResponse($side_nav, array('title' => 'Image Macros'));
 }
コード例 #2
0
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     switch ($this->getFilter()) {
         case 'upload':
         default:
             $this->setShowUploader(true);
             $this->setUseBasicUploader($request->getExists('basic_uploader'));
             $see_all = phutil_render_tag('a', array('href' => '/file/filter/all'), 'See all Files');
             $this->setListHeader("Recently Uploaded Files · {$see_all}");
             $this->setShowListPager(false);
             $this->setPagerOffset(0);
             $this->setPagerPageSize(10);
             break;
         case 'my':
             $this->setShowUploader(false);
             $this->setListHeader('Files You Uploaded');
             $this->setListAuthor($user);
             $this->setPagerOffset($request->getInt('page', 0));
             break;
         case 'all':
             $this->setShowUploader(false);
             $this->setListHeader('All Files');
             $this->setPagerOffset($request->getInt('page', 0));
             break;
     }
     $this->loadListData();
     $side_nav = new PhabricatorFileSideNavView();
     $side_nav->setSelectedFilter($this->getFilter());
     if ($this->showUploader()) {
         $side_nav->appendChild($this->renderUploadPanel());
     }
     $side_nav->appendChild($this->renderList());
     return $this->buildStandardPageResponse($side_nav, array('title' => 'Files', 'tab' => 'files'));
 }
コード例 #3
0
 public function processRequest()
 {
     if ($this->id) {
         $macro = id(new PhabricatorFileImageMacro())->load($this->id);
         if (!$macro) {
             return new Aphront404Response();
         }
     } else {
         $macro = new PhabricatorFileImageMacro();
     }
     $errors = array();
     $e_name = true;
     $request = $this->getRequest();
     $user = $request->getUser();
     if ($request->isFormPost()) {
         $macro->setName($request->getStr('name'));
         if (!strlen($macro->getName())) {
             $errors[] = 'Macro name is required.';
             $e_name = 'Required';
         } else {
             if (!preg_match('/^[a-z0-9_-]{3,}$/', $macro->getName())) {
                 $errors[] = 'Macro must be at least three characters long and contain ' . 'only lowercase letters, digits, hyphen and underscore.';
                 $e_name = 'Invalid';
             } else {
                 $e_name = null;
             }
         }
         if (!$errors) {
             $file = PhabricatorFile::newFromPHPUpload(idx($_FILES, 'file'), array('name' => $request->getStr('name'), 'authorPHID' => $user->getPHID()));
             $macro->setFilePHID($file->getPHID());
             try {
                 $macro->save();
                 return id(new AphrontRedirectResponse())->setURI('/file/macro/');
             } catch (AphrontQueryDuplicateKeyException $ex) {
                 $errors[] = 'Macro name is not unique!';
                 $e_name = 'Duplicate';
             }
         }
     }
     if ($errors) {
         $error_view = new AphrontErrorView();
         $error_view->setTitle('Form Errors');
         $error_view->setErrors($errors);
     } else {
         $error_view = null;
     }
     $form = new AphrontFormView();
     $form->setAction('/file/macro/edit/');
     $form->setUser($request->getUser());
     $form->setEncType('multipart/form-data')->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($macro->getName())->setCaption('This word or phrase will be replaced with the image.')->setError($e_name))->appendChild(id(new AphrontFormFileControl())->setLabel('File')->setName('file')->setError(true))->appendChild(id(new AphrontFormSubmitControl())->setValue('Save Image Macro')->addCancelButton('/file/macro/'));
     $panel = new AphrontPanelView();
     if ($macro->getID()) {
         $title = 'Edit Image Macro';
     } else {
         $title = 'Create Image Macro';
     }
     $panel->setHeader($title);
     $panel->appendChild($form);
     $panel->setWidth(AphrontPanelView::WIDTH_FULL);
     $side_nav = new PhabricatorFileSideNavView();
     $side_nav->setSelectedFilter('create_macro');
     $side_nav->appendChild($error_view);
     $side_nav->appendChild($panel);
     return $this->buildStandardPageResponse($side_nav, array('title' => $title));
 }