コード例 #1
0
ファイル: pages.php プロジェクト: mined-gatech/hubzero-cms
 /**
  * Scan group page for possible issues
  *
  * @return void
  */
 public function scanTask()
 {
     // make sure we are approvers
     if (!Helpers\Pages::isPageApprover()) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&gid=' . $this->gid, false), Lang::txt('COM_GROUPS_PAGES_MUST_BE_AUTHORIZED'), 'error');
         return;
     }
     // get request vars
     $id = Request::getInt('id', 0);
     // load page
     $page = new Page($id);
     // load current version
     $currentVersion = $page->version();
     // make sure version is unapproved
     if ($currentVersion->get('approved') == 1) {
         //inform user & redirect
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&gid=' . $this->gid, false), Lang::txt('COM_GROUPS_PAGES_ALREADY_APPROVED'), 'warning');
         return;
     }
     // get flags
     $flags = Helpers\Pages::getCodeFlags();
     // get current versions content by lines
     $content = explode("\n", $currentVersion->get('content'));
     // get any issues
     $issues = new stdClass();
     $issues->count = 0;
     foreach ($flags as $lang => $flag) {
         // define level patterns
         $severe = implode('|', $flag['severe']);
         $elevated = implode('|', $flag['elevated']);
         $minor = implode('|', $flag['minor']);
         // do case insensitive search for any flags
         if (!isset($issues->{$lang})) {
             $issues->{$lang} = new stdClass();
         }
         $issues->{$lang}->severe = $severe != '' ? preg_grep("/{$severe}/i", $content) : array();
         $issues->{$lang}->elevated = $elevated != '' ? preg_grep("/{$elevated}/i", $content) : array();
         $issues->{$lang}->minor = $minor != '' ? preg_grep("/{$minor}/i", $content) : array();
         // add to issues count
         $issues->count += count($issues->{$lang}->severe) + count($issues->{$lang}->elevated) + count($issues->{$lang}->minor);
     }
     // handle issues
     if ($issues->count != 0) {
         $this->view->setLayout('scan');
         $this->view->issues = $issues;
         $this->view->page = $page;
         $this->view->option = $this->_option;
         $this->view->controller = $this->_controller;
         $this->view->group = $this->group;
         $this->view->display();
         return;
     }
     // marked as scanned for potential issues!
     $currentVersion->set('scanned', 1);
     // DONT RUN CHECK ON STORE METHOD (pass false as first arg to store() method)
     $currentVersion->store(false, $this->group->isSuperGroup());
     // were all set
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&gid=' . $this->gid, false), Lang::txt('COM_GROUPS_PAGES_NO_XSS'), 'passed');
 }