/**
  * Returns a publish article
  *
  * @param $a_id
  * @param $row
  *
  * @return TBGWikiArticle
  */
 static function articleName($article_name, $row = null)
 {
     if (!isset(self::$_article_names[$article_name])) {
         try {
             $article = TBGWikiArticle::getByName($article_name);
             if ($article instanceof TBGWikiArticle) {
                 self::$_articles[$article->getID()] = $article;
                 self::$_article_names[$article_name] = $article->getID();
             } else {
                 throw new Exception('No such article');
             }
         } catch (Exception $e) {
             throw $e;
         }
     }
     return self::$_articles[self::$_article_names[$article_name]];
 }
 public function componentSettings()
 {
     $articles = array();
     $categories = array();
     $_path_handle = opendir(THEBUGGENIE_MODULES_PATH . 'publish' . DS . 'fixtures' . DS);
     while ($article_name = readdir($_path_handle)) {
         if (mb_strpos($article_name, '.') === false) {
             if (mb_strpos($article_name, '%3A') !== false) {
                 $article_elements = explode('%3A', $article_name);
                 $category = array_shift($article_elements);
                 $categories[mb_strtolower($category)] = $category;
             } else {
                 $category = '';
             }
             $articles[$article_name] = array('exists' => TBGWikiArticle::doesArticleExist(urldecode($article_name)), 'category' => mb_strtolower($category));
         }
     }
     ksort($articles, SORT_STRING);
     $this->articles = $articles;
     $this->categories = $categories;
 }
 public static function createNew($name, $content, $published, $scope = null, $options = array())
 {
     $user_id = TBGContext::getUser() instanceof TBGUser ? TBGContext::getUser()->getID() : 0;
     $article = new TBGWikiArticle();
     $article->setName($name);
     $article->setContent($content);
     $article->setIsPublished($published);
     if (!isset($options['noauthor'])) {
         $article->setAuthor($user_id);
     } else {
         $article->setAuthor(0);
     }
     if ($scope !== null) {
         $article->setScope($scope);
     }
     $article->doSave($options);
     return $article->getID();
 }
 public function listen_quicksearchDropdownFoundItems(TBGEvent $event)
 {
     $searchterm = $event->getSubject();
     list($resultcount, $articles) = TBGWikiArticle::findByArticleNameAndProject($searchterm, TBGContext::getCurrentProject());
     TBGActionComponent::includeTemplate('publish/quicksearch_dropdown_founditems', array('searchterm' => $searchterm, 'articles' => $articles, 'resultcount' => $resultcount));
 }
示例#5
0
 public function runDetachFile(TBGrequest $request)
 {
     try {
         switch ($request['mode']) {
             case 'issue':
                 $issue = TBGContext::factory()->TBGIssue($request['issue_id']);
                 if ($issue->canRemoveAttachments() && (int) $request->getParameter('file_id', 0)) {
                     \b2db\Core::getTable('TBGIssueFilesTable')->removeByIssueIDAndFileID($issue->getID(), (int) $request['file_id']);
                     return $this->renderJSON(array('file_id' => $request['file_id'], 'attachmentcount' => count($issue->getFiles()) + count($issue->getLinks()), 'message' => TBGContext::getI18n()->__('The attachment has been removed')));
                 }
                 $this->getResponse()->setHttpStatus(400);
                 return $this->renderJSON(array('error' => TBGContext::getI18n()->__('You can not remove items from this issue')));
                 break;
             case 'article':
                 $article = TBGWikiArticle::getByName($request['article_name']);
                 if ($article instanceof TBGWikiArticle && $article->canEdit() && (int) $request->getParameter('file_id', 0)) {
                     $article->removeFile(TBGContext::factory()->TBGFile((int) $request['file_id']));
                     return $this->renderJSON(array('file_id' => $request['file_id'], 'attachmentcount' => count($article->getFiles()), 'message' => TBGContext::getI18n()->__('The attachment has been removed')));
                 }
                 $this->getResponse()->setHttpStatus(400);
                 return $this->renderJSON(array('error' => TBGContext::getI18n()->__('You can not remove items from this issue')));
                 break;
         }
     } catch (Exception $e) {
         throw $e;
     }
     $this->getResponse()->setHttpStatus(400);
     return $this->renderJSON(array('error' => TBGContext::getI18n()->__('Invalid mode')));
 }
 public function componentAttachedfile()
 {
     if ($this->mode == 'issue' && !isset($this->issue)) {
         $this->issue = TBGContext::factory()->TBGIssue($this->issue_id);
     } elseif ($this->mode == 'article' && !isset($this->article)) {
         $this->article = TBGWikiArticle::getByName($this->article_name);
     }
     $this->file_id = $this->file->getID();
 }
 public function runFindArticles(TBGRequest $request)
 {
     $this->articlename = $request->getParameter('articlename');
     if ($this->articlename) {
         list($this->resultcount, $this->articles) = TBGWikiArticle::findByArticleNameAndProject($this->articlename, TBGContext::getCurrentProject(), 10);
     }
 }
 protected function _parse_insert_template($matches)
 {
     switch ($matches[1]) {
         case 'CURRENTMONTH':
             return date('m');
         case 'CURRENTMONTHNAMEGEN':
         case 'CURRENTMONTHNAME':
             return date('F');
         case 'CURRENTDAY':
             return date('d');
         case 'CURRENTDAYNAME':
             return date('l');
         case 'CURRENTYEAR':
             return date('Y');
         case 'CURRENTTIME':
             return date('H:i');
         case 'NUMBEROFARTICLES':
             return 0;
         case 'PAGENAME':
             return TBGContext::getResponse()->getPage();
         case 'NAMESPACE':
             return 'None';
         case 'TOC':
             return isset($this->options['included']) ? '' : '{{TOC}}';
         case 'SITENAME':
         case 'SITETAGLINE':
             return TBGSettings::getTBGname();
         default:
             $details = explode('|', $matches[1]);
             $template_name = array_shift($details);
             if (substr($template_name, 0, 1) == ':') {
                 $template_name = substr($template_name, 1);
             }
             $template_name = TBGWikiArticle::doesArticleExist($template_name) ? $template_name : 'Template:' . $template_name;
             $template_article = TBGArticlesTable::getTable()->getArticleByName($template_name);
             $parameters = array();
             if (count($details)) {
                 foreach ($details as $parameter) {
                     $param = explode('=', $parameter);
                     if (count($param) == 2) {
                         $parameters[$param[0]] = $param[1];
                     } else {
                         $parameters[] = $parameter;
                     }
                 }
             }
             if ($template_article instanceof TBGWikiArticle) {
                 return tbg_parse_text($template_article->getContent(), false, null, array('included' => true, 'parameters' => $parameters));
             } else {
                 return $matches[0];
             }
     }
 }
示例#9
0
 public function runFindArticles(TBGRequest $request)
 {
     $this->articlename = $request['articlename'];
     if ($this->articlename) {
         list($this->resultcount, $this->articles) = TBGWikiArticle::findArticlesByContentAndProject($this->articlename, TBGContext::getCurrentProject(), 10);
     }
 }
示例#10
0
 /**
  * Adds "notify once" settings for necessary articles
  * 
  * @param TBGWikiArticle $article
  * @param array|TBGUser $users
  */
 protected function _markArticleSent(TBGWikiArticle $article, $users)
 {
     foreach ($users as $user) {
         if ($user->getNotificationSetting(self::NOTIFY_ITEM_ONCE, false, 'mailing')->isOn()) {
             $user->setNotificationSetting(self::NOTIFY_ITEM_ONCE . '_article_' . $article->getID(), true, 'mailing')->save();
         }
     }
 }