示例#1
0
 protected function doSearch(TBGRequest $request)
 {
     $i18n = TBGContext::getI18n();
     if ($this->searchterm) {
         preg_replace_callback(TBGTextParser::getIssueRegex(), array($this, 'extractIssues'), $this->searchterm);
         if (!count($this->foundissues)) {
             $issue = TBGIssue::getIssueFromLink($this->searchterm);
             if ($issue instanceof TBGIssue) {
                 $this->foundissues = array($issue);
                 $this->resultcount = 1;
             }
         }
     }
     if (count($this->foundissues) == 0) {
         $this->foundissues = $this->search_object->getIssues();
         $this->resultcount = $this->search_object->getTotalNumberOfIssues();
     } elseif (count($this->foundissues) == 1 && !$request['quicksearch']) {
         $issue = array_shift($this->foundissues);
         $this->forward(TBGContext::getRouting()->generate('viewissue', array('project_key' => $issue->getProject()->getKey(), 'issue_no' => $issue->getFormattedIssueNo())));
     } else {
         $this->resultcount = count($this->foundissues);
         if ($this->templatename == 'results_userpain_singlepainthreshold') {
             usort($this->foundissues, array('searchActions', 'userPainSort'));
         }
     }
 }
 /**
  * Return an array of the registered regexes to be parsed
  *
  * @return array
  */
 protected static function getRegexes()
 {
     if (self::$additional_regexes === null) {
         self::$additional_regexes = array();
     }
     return self::$additional_regexes;
 }
 public function _addNotifications()
 {
     $parser = new TBGTextParser($this->_log);
     $parser->setOption('plain', true);
     $parser->doParse();
     foreach ($parser->getMentions() as $user) {
         if (!$this->getAuthor() || $user->getID() == $this->getAuthor()) {
             continue;
         }
         $notification = new TBGNotification();
         $notification->setTarget($this);
         $notification->setTriggeredByUser($this->getAuthor());
         $notification->setUser($user);
         $notification->setNotificationType(TBGVCSIntegration::NOTIFICATION_COMMIT_MENTIONED);
         $notification->setModuleName('vcs_integration');
         $notification->save();
     }
 }
示例#4
0
 protected function _install($scope)
 {
     TBGContext::setPermission('article_management', 0, 'publish', 0, 1, 0, true, $scope);
     TBGContext::setPermission('publish_postonglobalbillboard', 0, 'publish', 0, 1, 0, true, $scope);
     TBGContext::setPermission('publish_postonteambillboard', 0, 'publish', 0, 1, 0, true, $scope);
     TBGContext::setPermission('manage_billboard', 0, 'publish', 0, 1, 0, true, $scope);
     $this->saveSetting('allow_camelcase_links', 1);
     $this->saveSetting('require_change_reason', 1);
     TBGContext::getRouting()->addRoute('publish_article', '/wiki/:article_name', 'publish', 'showArticle');
     TBGTextParser::addRegex('/(?<![\\!|\\"|\\[|\\>|\\/\\:])\\b[A-Z]+[a-z]+[A-Z][A-Za-z]*\\b/', array($this, 'getArticleLinkTag'));
     TBGTextParser::addRegex('/(?<!")\\![A-Z]+[a-z]+[A-Z][A-Za-z]*\\b/', array($this, 'stripExclamationMark'));
 }
 protected function _retrieveLinksAndCategoriesFromContent($options = array())
 {
     $parser = new TBGTextParser(html_entity_decode($this->_content));
     $options['no_code_highlighting'] = true;
     $parser->doParse($options);
     return array($parser->getInternalLinks(), $parser->getCategories());
 }
示例#6
0
function tbg_parse_text($text, $toc = false, $article_id = null, $options = array())
{
    // Perform wiki parsing
    $wiki_parser = new TBGTextParser($text, $toc, 'article_' . $article_id);
    foreach ($options as $option => $value) {
        $wiki_parser->setOption($option, $value);
    }
    $text = $wiki_parser->getParsedText();
    return $text;
}
 public function getArticleLinkTag($matches)
 {
     $article_name = $matches[0];
     if (TBGTextParser::getCurrentParser() instanceof TBGTextParser) {
         TBGTextParser::getCurrentParser()->addInternalLinkOccurrence($article_name);
     }
     $article_name = $this->getSpacedName($matches[0]);
     if (!TBGContext::isCLI()) {
         TBGContext::loadLibrary('ui');
         return link_tag(make_url('publish_article', array('article_name' => $matches[0])), $article_name);
     } else {
         return $matches[0];
     }
 }
 protected function _parseText($options = array())
 {
     TBGContext::loadLibrary('common');
     self::$current_parser = $this;
     $this->list_level_types = array();
     $this->list_level = 0;
     $this->deflist = false;
     $this->ignore_newline = false;
     $output = "";
     $text = $this->text;
     $text = preg_replace_callback('/<nowiki>(.+?)<\\/nowiki>(?!<\\/nowiki>)/ism', array($this, "_parse_save_nowiki"), $text);
     $text = preg_replace_callback('/<source((?:\\s+[^\\s]+=".*")*)>\\s*?(.+)\\s*?<\\/source>/ismU', array($this, "_parse_save_code"), $text);
     // Thanks to Mike Smith (scgtrp) for the above regexp
     $text = tbg_decodeUTF8($text, true);
     $text = preg_replace('/&lt;((\\/)?u|(\\/)?strike|br|code)&gt;/ism', '<\\1>', $text);
     $lines = explode("\n", $text);
     foreach ($lines as $line) {
         if (substr($line, -1) == "\r") {
             $line = substr($line, 0, -1);
         }
         $output .= $this->_parse_line($line, $options);
     }
     $this->nowikis = array_reverse($this->nowikis);
     $this->codeblocks = array_reverse($this->codeblocks);
     $this->elinks = array_reverse($this->elinks);
     if (!array_key_exists('ignore_toc', $options)) {
         $output = preg_replace_callback('/\\{\\{TOC\\}\\}/', array($this, "_parse_add_toc"), $output);
     }
     $output = preg_replace_callback('/\\|\\|\\|NOWIKI\\|\\|\\|/i', array($this, "_parse_restore_nowiki"), $output);
     if (!isset($options['no_code_highlighting'])) {
         $output = preg_replace_callback('/\\|\\|\\|CODE\\|\\|\\|/Ui', array($this, "_parse_restore_code"), $output);
     }
     $output = preg_replace_callback('/~~~ILINK~~~/i', array($this, "_parse_restore_ilink"), $output);
     $output = preg_replace_callback('/~~~ELINK~~~/i', array($this, "_parse_restore_elink"), $output);
     self::$current_parser = null;
     return $output;
 }
 protected function doSearch(TBGRequest $request)
 {
     $i18n = TBGContext::getI18n();
     if ($this->searchterm) {
         preg_replace_callback(TBGTextParser::getIssueRegex(), array($this, 'extractIssues'), $this->searchterm);
         if (!count($this->foundissues)) {
             $issue = TBGIssue::getIssueFromLink($this->searchterm);
             if ($issue instanceof TBGIssue) {
                 $this->foundissues = array($issue);
                 $this->resultcount = 1;
             }
         }
     }
     if (count($this->foundissues) == 0) {
         if ($request->hasParameter('predefined_search')) {
             switch ((int) $request->getParameter('predefined_search')) {
                 case TBGContext::PREDEFINED_SEARCH_PROJECT_OPEN_ISSUES:
                     $this->filters['state'] = array('operator' => '=', 'value' => TBGIssue::STATE_OPEN);
                     $this->groupby = 'issuetype';
                     break;
                 case TBGContext::PREDEFINED_SEARCH_PROJECT_CLOSED_ISSUES:
                     $this->filters['state'] = array('operator' => '=', 'value' => TBGIssue::STATE_CLOSED);
                     $this->groupby = 'issuetype';
                     break;
                 case TBGContext::PREDEFINED_SEARCH_PROJECT_MILESTONE_TODO:
                     $this->groupby = 'milestone';
                     break;
                 case TBGContext::PREDEFINED_SEARCH_PROJECT_MOST_VOTED:
                     $this->filters['state'] = array('operator' => '=', 'value' => TBGIssue::STATE_OPEN);
                     $this->groupby = 'votes';
                     $this->grouporder = 'desc';
                     break;
                 case TBGContext::PREDEFINED_SEARCH_MY_REPORTED_ISSUES:
                     $this->filters['posted_by'] = array('operator' => '=', 'value' => TBGContext::getUser()->getID());
                     $this->groupby = 'issuetype';
                     break;
                 case TBGContext::PREDEFINED_SEARCH_MY_ASSIGNED_OPEN_ISSUES:
                     $this->filters['state'] = array('operator' => '=', 'value' => TBGIssue::STATE_OPEN);
                     $this->filters['assigned_type'] = array('operator' => '=', 'value' => TBGIdentifiableClass::TYPE_USER);
                     $this->filters['assigned_to'] = array('operator' => '=', 'value' => TBGContext::getUser()->getID());
                     $this->groupby = 'issuetype';
                     break;
                 case TBGContext::PREDEFINED_SEARCH_TEAM_ASSIGNED_OPEN_ISSUES:
                     $this->filters['state'] = array('operator' => '=', 'value' => TBGIssue::STATE_OPEN);
                     $this->filters['assigned_type'] = array('operator' => '=', 'value' => TBGIdentifiableClass::TYPE_TEAM);
                     foreach (TBGContext::getUser()->getTeams() as $team_id => $team) {
                         $this->filters['assigned_to'][] = array('operator' => '=', 'value' => $team_id);
                     }
                     $this->groupby = 'issuetype';
                     break;
             }
         } elseif (in_array($this->templatename, array('results_userpain_singlepainthreshold', 'results_userpain_totalpainthreshold'))) {
             $this->searchtitle = $i18n->__('Showing "bug report" issues sorted by user pain, threshold set at %threshold%', array('%threshold%' => $this->template_parameter));
             $this->ipp = 0;
             $this->groupby = 'user_pain';
             $this->grouporder = 'desc';
             $ids = TBGIssueTypesTable::getTable()->getBugReportTypeIDs();
             $this->filters['issuetype'] = array();
             foreach ($ids as $id) {
                 $this->filters['issuetype'][] = array('operator' => '=', 'value' => $id);
             }
         } elseif ($this->templatename == 'results_votes') {
             $this->searchtitle = $i18n->__('Showing issues ordered by number of votes');
             $this->ipp = $request->getParameter('issues_per_page', 100);
             $this->groupby = 'votes';
             $this->grouporder = 'desc';
         }
         list($this->foundissues, $this->resultcount) = TBGIssue::findIssues($this->filters, $this->ipp, $this->offset, $this->groupby, $this->grouporder);
     } elseif (count($this->foundissues) == 1 && !$request->getParameter('quicksearch')) {
         $issue = array_shift($this->foundissues);
         $this->forward(TBGContext::getRouting()->generate('viewissue', array('project_key' => $issue->getProject()->getKey(), 'issue_no' => $issue->getFormattedIssueNo())));
     } elseif ($request->hasParameter('sortby')) {
     } else {
         $this->resultcount = count($this->foundissues);
         if ($this->templatename == 'results_userpain_singlepainthreshold') {
             usort($this->foundissues, array('searchActions', 'userPainSort'));
         }
     }
     if ($request->hasParameter('predefined_search')) {
         switch ((int) $request->getParameter('predefined_search')) {
             case TBGContext::PREDEFINED_SEARCH_PROJECT_OPEN_ISSUES:
                 $this->searchtitle = TBGContext::isProjectContext() ? $i18n->__('Open issues for %project_name%', array('%project_name%' => TBGContext::getCurrentProject()->getName())) : $i18n->__('All open issues');
                 break;
             case TBGContext::PREDEFINED_SEARCH_PROJECT_CLOSED_ISSUES:
                 $this->searchtitle = TBGContext::isProjectContext() ? $i18n->__('Closed issues for %project_name%', array('%project_name%' => TBGContext::getCurrentProject()->getName())) : $i18n->__('All closed issues');
                 break;
             case TBGContext::PREDEFINED_SEARCH_PROJECT_MILESTONE_TODO:
                 $this->searchtitle = $i18n->__('Milestone todo-list for %project_name%', array('%project_name%' => TBGContext::getCurrentProject()->getName()));
                 $this->templatename = 'results_todo';
                 break;
             case TBGContext::PREDEFINED_SEARCH_PROJECT_MOST_VOTED:
                 $this->searchtitle = TBGContext::isProjectContext() ? $i18n->__('Most voted issues for %project_name%', array('%project_name%' => TBGContext::getCurrentProject()->getName())) : $i18n->__('Most voted issues');
                 $this->templatename = 'results_votes';
                 break;
             case TBGContext::PREDEFINED_SEARCH_MY_ASSIGNED_OPEN_ISSUES:
                 $this->searchtitle = $i18n->__('Open issues assigned to me');
                 break;
             case TBGContext::PREDEFINED_SEARCH_TEAM_ASSIGNED_OPEN_ISSUES:
                 $this->searchtitle = $i18n->__('Open issues assigned to my teams');
                 break;
             case TBGContext::PREDEFINED_SEARCH_MY_REPORTED_ISSUES:
                 $this->searchtitle = $i18n->__('Issues reported by me');
                 break;
         }
     }
 }
示例#10
0
function tbg_parse_text($text, $toc = false, $article_id = null, $options = array(), $syntax = TBGSettings::SYNTAX_MW)
{
    switch ($syntax) {
        case TBGSettings::SYNTAX_PT:
            $options = array('plain' => true);
        case TBGSettings::SYNTAX_MW:
            $wiki_parser = new TBGTextParser($text, $toc, 'article_' . $article_id);
            foreach ($options as $option => $value) {
                $wiki_parser->setOption($option, $value);
            }
            $text = $wiki_parser->getParsedText();
            break;
        case TBGSettings::SYNTAX_MD:
            $parser = new TBGTextParserMarkdown();
            $text = $parser->transform($text);
            break;
    }
    return $text;
}
示例#11
0
 protected function _parseContent($options = array())
 {
     switch ($this->_syntax) {
         case TBGSettings::SYNTAX_PT:
             $options = array('plain' => true);
         case TBGSettings::SYNTAX_MW:
             $parser = new TBGTextParser($this->_content);
             foreach ($options as $option => $value) {
                 $parser->setOption($option, $value);
             }
             $text = $parser->getParsedText();
             break;
         case TBGSettings::SYNTAX_MD:
             $parser = new TBGTextParserMarkdown();
             $text = $parser->transform($this->_content);
             break;
     }
     if (isset($parser)) {
         $this->_parser = $parser;
     }
     return $text;
 }
示例#12
0
 protected function _getParsedText($text, $syntax, $options = array())
 {
     switch ($syntax) {
         case TBGSettings::SYNTAX_PT:
             $options = array('plain' => true);
         case TBGSettings::SYNTAX_MW:
             $wiki_parser = new TBGTextParser($text);
             foreach ($options as $option => $value) {
                 $wiki_parser->setOption($option, $value);
             }
             $text = $wiki_parser->getParsedText();
             break;
         case TBGSettings::SYNTAX_MD:
             $parser = new TBGTextParserMarkdown();
             $text = $parser->transform($text);
             break;
     }
     return $text;
 }
 protected function _parse_issuelink($matches)
 {
     return TBGTextParser::parseIssuelink($matches);
 }