示例#1
0
 protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addForeignKeyColumn(self::UID, \thebuggenie\core\entities\tables\Users::getTable(), \thebuggenie\core\entities\tables\Users::ID);
     parent::_addForeignKeyColumn(self::ARTICLE_ID, Articles::getTable(), Articles::ID);
     parent::_addForeignKeyColumn(self::FILE_ID, \thebuggenie\core\entities\tables\Files::getTable(), \thebuggenie\core\entities\tables\Files::ID);
     parent::_addInteger(self::ATTACHED_AT, 10);
 }
示例#2
0
 public function doSave($options = array(), $reason = null)
 {
     if (tables\Articles::getTable()->doesNameConflictExist($this->_name, $this->_id, framework\Context::getScope()->getID())) {
         if (!array_key_exists('overwrite', $options) || !$options['overwrite']) {
             throw new \Exception(framework\Context::getI18n()->__('Another article with this name already exists'));
         }
     }
     $user_id = framework\Context::getUser() instanceof User ? framework\Context::getUser()->getID() : 0;
     if (!isset($options['revert']) || !$options['revert']) {
         $revision = tables\ArticleHistory::getTable()->addArticleHistory($this->_name, $this->_old_content, $this->_content, $user_id, $reason);
     } else {
         $revision = null;
     }
     tables\ArticleLinks::getTable()->deleteLinksByArticle($this->_name);
     ArticleCategories::getTable()->deleteCategoriesByArticle($this->_name);
     if ($this->getArticleType() == self::TYPE_MANUAL && isset($options['article_prev_name']) && $this->_name != $options['article_prev_name']) {
         $manual_articles = Articles::getTable()->getManualSidebarArticles(framework\Context::getCurrentProject(), $options['article_prev_name']);
         foreach ($manual_articles as $manual_article) {
             $manual_article->setName(str_replace($options['article_prev_name'], $this->_name, $manual_article->getName()));
             $manual_article->doSave();
         }
     }
     $this->save();
     $this->_old_content = $this->_content;
     if (mb_substr($this->getContent(), 0, 10) == "#REDIRECT ") {
         $content = explode("\n", $this->getContent());
         preg_match('/(\\[\\[([^\\]]*?)\\]\\])$/im', mb_substr(array_shift($content), 10), $matches);
         if (count($matches) == 3) {
             return;
         }
     }
     list($links, $categories) = $this->_retrieveLinksAndCategoriesFromContent($options);
     foreach ($links as $link => $occurrences) {
         tables\ArticleLinks::getTable()->addArticleLink($this->_name, $link);
     }
     foreach ($categories as $category => $occurrences) {
         ArticleCategories::getTable()->addArticleCategory($this->_name, $category, $this->isCategory());
     }
     $this->_history = null;
     \thebuggenie\core\framework\Event::createNew('core', 'thebuggenie\\modules\\publish\\entities\\Article::doSave', $this, compact('reason', 'revision', 'user_id'))->trigger();
     return true;
 }
 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 framework\Context::getResponse()->getPage();
         case 'NAMESPACE':
             return 'None';
         case 'TOC':
             return isset($this->options['included']) ? '' : '{{TOC}}';
         case 'SITENAME':
         case 'SITETAGLINE':
             return \thebuggenie\core\framework\Settings::getSiteHeaderName();
         default:
             $details = explode('|', $matches[1]);
             $template_name = array_shift($details);
             if (substr($template_name, 0, 1) == ':') {
                 $template_name = substr($template_name, 1);
             }
             $template_name = Article::doesArticleExist($template_name) ? $template_name : 'Template:' . $template_name;
             $template_article = Articles::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 Article) {
                 return tbg_parse_text($template_article->getContent(), false, null, array('included' => true, 'parameters' => $parameters));
             } else {
                 return $matches[0];
             }
     }
 }
示例#4
0
 /**
  * Toggle favourite article (starring)
  *
  * @param \thebuggenie\core\framework\Request $request
  */
 public function runToggleFavouriteArticle(framework\Request $request)
 {
     if ($article_id = $request['article_id']) {
         try {
             $article = Articles::getTable()->selectById($article_id);
             $user = \thebuggenie\core\entities\User::getB2DBTable()->selectById($request['user_id']);
         } catch (\Exception $e) {
             return $this->renderText('fail');
         }
     } else {
         return $this->renderText('no article');
     }
     if ($user->isArticleStarred($article_id)) {
         $retval = !$user->removeStarredArticle($article_id);
     } else {
         $retval = $user->addStarredArticle($article_id);
         if ($user->getID() != $this->getUser()->getID()) {
             framework\Event::createNew('core', 'article_subscribe_user', $article, compact('user'))->trigger();
         }
     }
     return $this->renderText(json_encode(array('starred' => $retval, 'subscriber' => $this->getComponentHTML('publish/articlesubscriber', array('user' => $user, 'article' => $article)))));
 }
示例#5
0
 /**
  * Returns the object which the notification is for
  *
  * @return \thebuggenie\core\entities\common\IdentifiableScoped
  */
 public function getTarget()
 {
     if ($this->_target === null) {
         if ($this->_module_name == 'core') {
             switch ($this->_notification_type) {
                 case self::TYPE_ARTICLE_COMMENTED:
                 case self::TYPE_ISSUE_COMMENTED:
                 case self::TYPE_COMMENT_MENTIONED:
                     $this->_target = tables\Comments::getTable()->selectById((int) $this->_target_id);
                     break;
                 case self::TYPE_ISSUE_UPDATED:
                 case self::TYPE_ISSUE_CREATED:
                 case self::TYPE_ISSUE_MENTIONED:
                     $this->_target = \thebuggenie\core\entities\Issue::getB2DBTable()->selectById((int) $this->_target_id);
                     break;
                 case self::TYPE_ARTICLE_CREATED:
                 case self::TYPE_ARTICLE_UPDATED:
                 case self::TYPE_ARTICLE_MENTIONED:
                     $this->_target = Articles::getTable()->selectById((int) $this->_target_id);
                     break;
             }
         } else {
             $event = new \thebuggenie\core\framework\Event('core', 'thebuggenie\\core\\entities\\Notification::getTarget', $this);
             $event->triggerUntilProcessed();
             $this->_target = $event->getReturnValue();
         }
     }
     return $this->_target;
 }
示例#6
0
 public function componentReportIssue()
 {
     $introarticle = \thebuggenie\modules\publish\entities\tables\Articles::getTable()->getArticleByName(ucfirst(framework\Context::getCurrentProject()->getKey()) . ':ReportIssueIntro');
     $this->introarticle = $introarticle instanceof \thebuggenie\modules\publish\entities\Article ? $introarticle : \thebuggenie\modules\publish\entities\tables\Articles::getTable()->getArticleByName('ReportIssueIntro');
     $reporthelparticle = \thebuggenie\modules\publish\entities\tables\Articles::getTable()->getArticleByName(ucfirst(framework\Context::getCurrentProject()->getKey()) . ':ReportIssueHelp');
     $this->reporthelparticle = $reporthelparticle instanceof \thebuggenie\modules\publish\entities\Article ? $reporthelparticle : \thebuggenie\modules\publish\entities\tables\Articles::getTable()->getArticleByName('ReportIssueHelp');
     $this->uniqid = framework\Context::getRequest()->getParameter('uniqid', uniqid());
     $this->_setupReportIssueProperties();
     $dummyissue = new entities\Issue();
     $dummyissue->setProject(framework\Context::getCurrentProject());
     $this->canupload = framework\Settings::isUploadsEnabled() && $dummyissue->canAttachFiles();
 }
示例#7
0
 public function componentSpecialWhatLinksHere()
 {
     $this->linked_article_name = framework\Context::getRequest()->getParameter('linked_article_name');
     $this->articles = Articles::getTable()->getAllByLinksToArticleName($this->linked_article_name);
 }
示例#8
0
 /**
  * Adds an article to the list of articles "starred" by this user
  *
  * @return boolean
  */
 public function User__addStarredArticle(framework\Event $event)
 {
     $user = $event->getSubject();
     $arguments = $event->getParameters();
     $article_id = $arguments[0];
     if ($user->isLoggedIn() && !$user->isGuest()) {
         if (UserArticles::getTable()->hasStarredArticle($user->getID(), $article_id)) {
             $event->setProcessed();
             $event->setReturnValue(true);
             return;
         }
         UserArticles::getTable()->addStarredArticle($user->getID(), $article_id);
         if ($user->_isset('publish', 'starredarticles')) {
             $article = Articles::getTable()->selectById($article_id);
             $articles = $user->_retrieve('publish', 'starredarticles');
             $articles[$article->getID()] = $article;
             $user->_store('publish', 'starredarticles', $articles);
         }
         $event->setProcessed();
         $event->setReturnValue(true);
         return;
     }
     $event->setProcessed();
     $event->setReturnValue(false);
     return;
 }
示例#9
0
 public function getTarget()
 {
     if ($this->_target === null) {
         switch ($this->getTargetType()) {
             case self::TYPE_ISSUE:
                 $this->_target = \thebuggenie\core\entities\Issue::getB2DBTable()->selectById($this->_target_id);
                 break;
             case self::TYPE_ARTICLE:
                 $this->_target = publish\entities\tables\Articles::getTable()->selectById($this->_target_id);
                 break;
             default:
                 $event = \thebuggenie\core\framework\Event::createNew('core', 'Comment::getTarget', $this);
                 $event->trigger();
                 $this->_target = $event->getReturnValue();
         }
     }
     return $this->_target;
 }
示例#10
0
 public function runAddComment(framework\Request $request)
 {
     $i18n = framework\Context::getI18n();
     $comment_applies_type = $request['comment_applies_type'];
     try {
         if (!$this->getUser()->canPostComments()) {
             throw new \Exception($i18n->__('You are not allowed to do this'));
         }
         if (!trim($request['comment_body'])) {
             throw new \Exception($i18n->__('The comment must have some content'));
         }
         $comment = new entities\Comment();
         $comment->setContent($request->getParameter('comment_body', null, false));
         $comment->setPostedBy($this->getUser()->getID());
         $comment->setTargetID($request['comment_applies_id']);
         $comment->setTargetType($request['comment_applies_type']);
         $comment->setReplyToComment($request['reply_to_comment_id']);
         $comment->setModuleName($request['comment_module']);
         $comment->setIsPublic((bool) $request['comment_visibility']);
         $comment->setSyntax($request['comment_body_syntax']);
         $comment->save();
         if ($comment_applies_type == entities\Comment::TYPE_ISSUE) {
             $issue = entities\Issue::getB2DBTable()->selectById((int) $request['comment_applies_id']);
             if (!$request->isAjaxCall() || $request['comment_save_changes']) {
                 $issue->setSaveComment($comment);
                 $issue->save();
             } else {
                 \thebuggenie\core\framework\Event::createNew('core', 'thebuggenie\\core\\entities\\Comment::createNew', $comment, compact('issue'))->trigger();
             }
         } elseif ($comment_applies_type == entities\Comment::TYPE_ARTICLE) {
             $article = \thebuggenie\modules\publish\entities\tables\Articles::getTable()->selectById((int) $request['comment_applies_id']);
             \thebuggenie\core\framework\Event::createNew('core', 'thebuggenie\\core\\entities\\Comment::createNew', $comment, compact('article'))->trigger();
         }
         switch ($comment_applies_type) {
             case entities\Comment::TYPE_ISSUE:
                 $issue = entities\Issue::getB2DBTable()->selectById($request['comment_applies_id']);
                 framework\Context::setCurrentProject($issue->getProject());
                 $comment_html = $this->getComponentHTML('main/comment', array('comment' => $comment, 'issue' => $issue, 'mentionable_target_type' => 'issue', 'comment_count_div' => 'viewissue_comment_count'));
                 break;
             case entities\Comment::TYPE_ARTICLE:
                 $comment_html = $this->getComponentHTML('main/comment', array('comment' => $comment, 'mentionable_target_type' => 'article', 'comment_count_div' => 'article_comment_count'));
                 break;
             default:
                 $comment_html = 'OH NO!';
         }
     } catch (\Exception $e) {
         if ($request->isAjaxCall()) {
             $this->getResponse()->setHttpStatus(400);
             return $this->renderJSON(array('error' => $e->getMessage()));
         } else {
             framework\Context::setMessage('comment_error', $e->getMessage());
             framework\Context::setMessage('comment_error_body', $request['comment_body']);
             framework\Context::setMessage('comment_error_visibility', $request['comment_visibility']);
         }
     }
     if ($request->isAjaxCall()) {
         return $this->renderJSON(array('title' => $i18n->__('Comment added!'), 'comment_data' => $comment_html, 'continue_url' => $request['forward_url'], 'commentcount' => entities\Comment::countComments($request['comment_applies_id'], $request['comment_applies_type'])));
     }
     if (isset($comment) && $comment instanceof entities\Comment) {
         $this->forward($request['forward_url'] . "#comment_{$request['comment_applies_type']}_{$request['comment_applies_id']}_{$comment->getID()}");
     } else {
         $this->forward($request['forward_url']);
     }
 }
示例#11
0
 /**
  * Configuration import page
  *
  * @param framework\Request $request
  */
 public function runIndex(framework\Request $request)
 {
     if ($request->isPost()) {
         if ($request['import_sample_data']) {
             $transaction = \b2db\Core::startTransaction();
             $users = array();
             $user1 = new entities\User();
             $user1->setUsername('john');
             $user1->setPassword('john');
             $user1->setBuddyname('John');
             $user1->setRealname('John');
             $user1->setActivated();
             $user1->setEnabled();
             $user1->save();
             $users[] = $user1;
             $user2 = new entities\User();
             $user2->setUsername('jane');
             $user2->setPassword('jane');
             $user2->setBuddyname('Jane');
             $user2->setRealname('Jane');
             $user2->setActivated();
             $user2->setEnabled();
             $user2->save();
             $users[] = $user2;
             $user3 = new entities\User();
             $user3->setUsername('jackdaniels');
             $user3->setPassword('jackdaniels');
             $user3->setBuddyname('Jack');
             $user3->setRealname('Jack Daniels');
             $user3->setActivated();
             $user3->setEnabled();
             $user3->save();
             $users[] = $user3;
             $project1 = new entities\Project();
             $project1->setName('Sample project 1');
             $project1->setOwner($users[rand(0, 2)]);
             $project1->setLeader($users[rand(0, 2)]);
             $project1->setQaResponsible($users[rand(0, 2)]);
             $project1->setDescription('This is a sample project that is awesome. Try it out!');
             $project1->setHomepage('http://www.google.com');
             $project1->save();
             $project2 = new entities\Project();
             $project2->setName('Sample project 2');
             $project2->setOwner($users[rand(0, 2)]);
             $project2->setLeader($users[rand(0, 2)]);
             $project2->setQaResponsible($users[rand(0, 2)]);
             $project2->setDescription('This is the second sample project. Not as awesome as the first one, but still worth a try!');
             $project2->setHomepage('http://www.bing.com');
             $project2->save();
             foreach (array($project1, $project2) as $project) {
                 for ($cc = 1; $cc <= 5; $cc++) {
                     $milestone = new entities\Milestone();
                     $milestone->setName("Milestone {$cc}");
                     $milestone->setProject($project);
                     $milestone->setType(entities\Milestone::TYPE_REGULAR);
                     if ((bool) rand(0, 1)) {
                         $milestone->setScheduledDate(NOW + 100000 * (20 * $cc));
                     }
                     $milestone->save();
                 }
             }
             $p1_milestones = $project1->getMilestones();
             $p2_milestones = $project2->getMilestones();
             $issues = array();
             $priorities = entities\Priority::getAll();
             $categories = entities\Category::getAll();
             $severities = entities\Severity::getAll();
             $statuses = entities\Status::getAll();
             $reproducabilities = entities\Reproducability::getAll();
             $lorem_ipsum = \thebuggenie\modules\publish\entities\tables\Articles::getTable()->getArticleByName('LoremIpsum');
             $lorem_words = explode(' ', $lorem_ipsum->getContent());
             foreach (array('bugreport', 'featurerequest', 'enhancement', 'idea') as $issuetype) {
                 $issuetype = entities\Issuetype::getByKeyish($issuetype);
                 for ($cc = 1; $cc <= 10; $cc++) {
                     $issue1 = new entities\Issue();
                     $issue1->setProject($project1);
                     $issue1->setPostedBy($users[rand(0, 2)]);
                     $issue1->setPosted(NOW - 86400 * rand(1, 30));
                     $title_string = '';
                     $description_string = '';
                     $rand_length = rand(4, 15);
                     $ucnext = true;
                     for ($ll = 1; $ll <= $rand_length; $ll++) {
                         $word = str_replace(array(',', '.', "\r", "\n"), array('', '', '', ''), $lorem_words[array_rand($lorem_words)]);
                         $word = $ucnext || rand(1, 40) == 19 ? ucfirst($word) : mb_strtolower($word);
                         $title_string .= $word;
                         $ucnext = false;
                         if ($ll == $rand_length || rand(1, 15) == 5) {
                             $title_string .= '.';
                             $ucnext = true;
                         }
                         $title_string .= ' ';
                     }
                     $rand_length = rand(40, 500);
                     $ucnext = true;
                     for ($ll = 1; $ll <= $rand_length; $ll++) {
                         $word = str_replace(array(',', '.', "\r", "\n"), array('', '', '', ''), $lorem_words[array_rand($lorem_words)]);
                         $word = $ucnext || rand(1, 40) == 19 ? ucfirst($word) : mb_strtolower($word);
                         $description_string .= $word;
                         $ucnext = false;
                         if ($ll == $rand_length || rand(1, 15) == 5) {
                             $description_string .= '.';
                             $ucnext = true;
                             $description_string .= $ll != $rand_length && rand(1, 15) == 8 ? "\n\n" : ' ';
                         } else {
                             $description_string .= ' ';
                         }
                     }
                     $issue1->setTitle(ucfirst($title_string));
                     $issue1->setDescription($description_string);
                     $issue1->setIssuetype($issuetype);
                     $issue1->setMilestone($p1_milestones[array_rand($p1_milestones)]);
                     $issue1->setPriority($priorities[array_rand($priorities)]);
                     $issue1->setCategory($categories[array_rand($categories)]);
                     $issue1->setSeverity($severities[array_rand($severities)]);
                     $issue1->setReproducability($reproducabilities[array_rand($reproducabilities)]);
                     $issue1->setPercentCompleted(rand(0, 100));
                     $issue1->save();
                     $issue1->setStatus($statuses[array_rand($statuses)]);
                     if (rand(0, 1)) {
                         $issue1->setAssignee($users[array_rand($users)]);
                     }
                     $issue1->save();
                     $issues[] = $issue1;
                     $issue2 = new entities\Issue();
                     $issue2->setProject($project2);
                     $issue2->setPostedBy($users[rand(0, 2)]);
                     $issue2->setPosted(NOW - 86400 * rand(1, 30));
                     $title_string = '';
                     $description_string = '';
                     $rand_length = rand(4, 15);
                     $ucnext = true;
                     for ($ll = 1; $ll <= $rand_length; $ll++) {
                         $word = str_replace(array(',', '.', "\r", "\n"), array('', '', '', ''), $lorem_words[array_rand($lorem_words)]);
                         $word = $ucnext || rand(1, 40) == 19 ? ucfirst($word) : mb_strtolower($word);
                         $title_string .= $word;
                         $ucnext = false;
                         if ($ll == $rand_length || rand(1, 15) == 5) {
                             $title_string .= '.';
                             $ucnext = true;
                         }
                         $title_string .= ' ';
                     }
                     $rand_length = rand(40, 500);
                     $ucnext = true;
                     for ($ll = 1; $ll <= $rand_length; $ll++) {
                         $word = str_replace(array(',', '.', "\r", "\n"), array('', '', '', ''), $lorem_words[array_rand($lorem_words)]);
                         $word = $ucnext || rand(1, 40) == 19 ? ucfirst($word) : mb_strtolower($word);
                         $description_string .= $word;
                         $ucnext = false;
                         if ($ll == $rand_length || rand(1, 15) == 5) {
                             $description_string .= '.';
                             $ucnext = true;
                             $description_string .= $ll != $rand_length && rand(1, 15) == 8 ? "\n\n" : ' ';
                         } else {
                             $description_string .= ' ';
                         }
                     }
                     $issue2->setTitle(ucfirst($title_string));
                     $issue2->setDescription($description_string);
                     $issue2->setIssuetype($issuetype);
                     $issue2->setMilestone($p2_milestones[array_rand($p2_milestones)]);
                     $issue2->setPriority($priorities[array_rand($priorities)]);
                     $issue2->setCategory($categories[array_rand($categories)]);
                     $issue2->setSeverity($severities[array_rand($severities)]);
                     $issue2->setReproducability($reproducabilities[array_rand($reproducabilities)]);
                     $issue2->setPercentCompleted(rand(0, 100));
                     if (rand(0, 1)) {
                         $issue1->setAssignee($users[array_rand($users)]);
                     }
                     $issue2->save();
                     $issue2->setStatus($statuses[array_rand($statuses)]);
                     $issue2->save();
                     $issues[] = $issue2;
                 }
             }
             $rand_issues_to_close = rand(8, 40);
             $resolutions = entities\Resolution::getAll();
             for ($cc = 1; $cc <= $rand_issues_to_close; $cc++) {
                 $issue = array_slice($issues, array_rand($issues), 1);
                 $issue = $issue[0];
                 $issue->setResolution($resolutions[array_rand($resolutions)]);
                 $issue->close();
                 $issue->save();
             }
             $this->imported_data = true;
             $roles = entities\Role::getAll();
             foreach (array($project1, $project2) as $project) {
                 foreach ($users as $user) {
                     $project->addAssignee($user, $roles[array_rand($roles)]);
                 }
             }
             $transaction->commitAndEnd();
         }
     }
     $project1 = entities\Project::getByKey('sampleproject1');
     $project2 = entities\Project::getByKey('sampleproject2');
     $this->canimport = !$project1 instanceof entities\Project && !$project2 instanceof entities\Project;
 }
示例#12
0
 public function componentForgotPasswordPane()
 {
     $this->forgottenintro = \thebuggenie\modules\publish\entities\tables\Articles::getTable()->getArticleByName('ForgottenPasswordIntro');
 }