예제 #1
0
 /**
  * Send a test email
  *
  * @param TBGRequest $request
  */
 public function runTestEmail(TBGRequest $request)
 {
     if ($email_to = $request->getParameter('test_email_to')) {
         try {
             if (TBGMailing::getModule()->sendTestEmail($email_to)) {
                 TBGContext::setMessage('module_message', TBGContext::getI18n()->__('The email was successfully accepted for delivery'));
             } else {
                 TBGContext::setMessage('module_error', TBGContext::getI18n()->__('The email was not sent'));
                 TBGContext::setMessage('module_error_details', TBGLogging::getMessagesForCategory('mailing', TBGLogging::LEVEL_NOTICE));
             }
         } catch (Exception $e) {
             TBGContext::setMessage('module_error', TBGContext::getI18n()->__('The email was not sent'));
             TBGContext::setMessage('module_error_details', $e->getMessage());
         }
     } else {
         TBGContext::setMessage('module_error', TBGContext::getI18n()->__('Please specify an email address'));
     }
     $this->forward(TBGContext::getRouting()->generate('configure_module', array('config_module' => 'mailing')));
 }
예제 #2
0
 /**
  * Forward the user with HTTP status code 403 and an (optional) message
  * based on a boolean check
  * 
  * @param boolean $condition
  * @param string $message[optional] The message
  */
 public function forward403unless($condition, $message = null)
 {
     if (!$condition) {
         $message = $message === null ? TBGContext::getI18n()->__("You are not allowed to access to this page") : $message;
         TBGContext::setMessage('forward', $message);
         $this->forward(TBGContext::getRouting()->generate('login_redirect'), 403);
     }
 }
예제 #3
0
 public function runScope(TBGRequest $request)
 {
     $this->scope = new TBGScope($request->getParameter('id'));
     $modules = TBGModulesTable::getTable()->getModulesForScope($this->scope->getID());
     $this->modules = $modules;
     $this->scope_save_error = TBGContext::getMessageAndClear('scope_save_error');
     $this->scope_saved = TBGContext::getMessageAndClear('scope_saved');
     if ($request->isMethod(TBGRequest::POST)) {
         try {
             if ($request->getParameter('scope_action') == 'delete') {
                 if (!$this->scope->isDefault()) {
                     $this->scope->delete();
                     TBGContext::setMessage('scope_deleted', true);
                     $this->forward(make_url('configure_scopes'));
                 } else {
                     $this->scope_save_error = TBGContext::getI18n()->__('You cannot delete the default scope');
                 }
             } else {
                 if (!$request->getParameter('name')) {
                     throw new Exception(TBGContext::getI18n()->__('Please specify a scope name'));
                 }
                 $this->scope->setName($request->getParameter('name'));
                 $this->scope->setDescription($request->getParameter('description'));
                 $this->scope->setCustomWorkflowsEnabled((bool) $request->getParameter('custom_workflows_enabled'));
                 $this->scope->setMaxWorkflowsLimit((int) $request->getParameter('workflow_limit'));
                 $this->scope->setUploadsEnabled((bool) $request->getParameter('file_uploads_enabled'));
                 $this->scope->setMaxUploadLimit((int) $request->getParameter('upload_limit'));
                 $this->scope->setMaxProjects((int) $request->getParameter('project_limit'));
                 $this->scope->setMaxUsers((int) $request->getParameter('user_limit'));
                 $this->scope->setMaxTeams((int) $request->getParameter('team_limit'));
                 $this->scope->save();
                 $enabled_modules = $request->getParameter('module_enabled');
                 $prev_scope = TBGContext::getScope();
                 foreach ($enabled_modules as $module => $enabled) {
                     if (!TBGContext::getModule($module)->isCore() && !$enabled && array_key_exists($module, $modules)) {
                         $module = TBGModulesTable::getTable()->getModuleForScope($module, $this->scope->getID());
                         $module->uninstall($this->scope->getID());
                     } elseif (!TBGContext::getModule($module)->isCore() && $enabled && !array_key_exists($module, $modules)) {
                         TBGContext::setScope($this->scope);
                         TBGModule::installModule($module);
                         TBGContext::setScope($prev_scope);
                     }
                 }
                 TBGContext::setMessage('scope_saved', true);
                 $this->forward(make_url('configure_scope', array('id' => $this->scope->getID())));
             }
         } catch (Exception $e) {
             TBGContext::setMessage('scope_save_error', $e->getMessage());
         }
     }
 }
예제 #4
0
 public function runEditSavedSearch(TBGRequest $request)
 {
     if ($request->isPost()) {
         if ($request['delete_saved_search']) {
             try {
                 if (!$this->search_object instanceof TBGSavedSearch || !$this->search_object->getB2DBID()) {
                     throw new Exception('not a saved search');
                 }
                 if ($this->search_object->getUserID() == TBGContext::getUser()->getID() || $this->search_object->isPublic() && TBGContext::getUser()->canCreatePublicSearches()) {
                     $search->delete();
                     return $this->renderJSON(array('failed' => false, 'message' => TBGContext::getI18n()->__('The saved search was deleted successfully')));
                 }
             } catch (Exception $e) {
                 return $this->renderJSON(array('failed' => true, 'message' => TBGContext::getI18n()->__('Cannot delete this saved search')));
             }
         } elseif ($request['saved_search_name'] != '') {
             //					$project_id = (TBGContext::isProjectContext()) ? TBGContext::getCurrentProject()->getID() : 0;
             //					TBGSavedSearchesTable::getTable()->saveSearch($request['saved_search_name'], $request['saved_search_description'], $request['saved_search_public'], $this->filters, $this->groupby, $this->grouporder, $this->ipp, $this->templatename, $this->template_parameter, $project_id, $request['saved_search_id']);
             if (!$search instanceof TBGSavedSearch) {
                 $search = new TBGSavedSearch();
             }
             $search->setName($request['saved_search_name']);
             $search->setDescription($request['saved_search_description']);
             $search->setIsPublic((bool) $request['saved_search_public']);
             $search->save();
             if ($request['saved_search_id']) {
                 TBGContext::setMessage('search_message', TBGContext::getI18n()->__('The saved search was updated'));
             } else {
                 TBGContext::setMessage('search_message', TBGContext::getI18n()->__('The saved search has been created'));
             }
             $params = array();
         } else {
             TBGContext::setMessage('search_error', TBGContext::getI18n()->__('You have to specify a name for the saved search'));
             $params = array('fs' => $this->filters, 'groupby' => $this->groupby, 'grouporder' => $this->grouporder, 'templatename' => $this->templatename, 'saved_search' => $request['saved_search_id'], 'issues_per_page' => $this->ipp);
         }
         if (TBGContext::isProjectContext()) {
             $route = 'project_issues';
             $params['project_key'] = TBGContext::getCurrentProject()->getKey();
         } else {
             $route = 'search';
         }
         $this->forward(TBGContext::getRouting()->generate($route, $params));
     }
 }
예제 #5
0
 /**
  * Add a build (AJAX call)
  *
  * @param TBGRequest $request The request object
  */
 public function runProjectBuild(TBGRequest $request)
 {
     $i18n = TBGContext::getI18n();
     if ($this->getUser()->canManageProjectReleases($this->selected_project)) {
         try {
             if (TBGContext::getUser()->canManageProjectReleases($this->selected_project)) {
                 if (($b_name = $request['build_name']) && trim($b_name) != '') {
                     $build = new TBGBuild($request['build_id']);
                     $build->setName($b_name);
                     $build->setVersion($request->getParameter('ver_mj', 0), $request->getParameter('ver_mn', 0), $request->getParameter('ver_rev', 0));
                     $build->setReleased((bool) $request['isreleased']);
                     $build->setLocked((bool) $request['locked']);
                     if ($request['milestone'] && ($milestone = TBGContext::factory()->TBGMilestone($request['milestone']))) {
                         $build->setMilestone($milestone);
                     } else {
                         $build->clearMilestone();
                     }
                     if ($request['edition'] && ($edition = TBGContext::factory()->TBGEdition($request['edition']))) {
                         $build->setEdition($edition);
                     } else {
                         $build->clearEdition();
                     }
                     $release_date = null;
                     if ($request['has_release_date']) {
                         $release_date = mktime($request['release_hour'], $request['release_minute'], 1, $request['release_month'], $request['release_day'], $request['release_year']);
                     }
                     $build->setReleaseDate($release_date);
                     switch ($request->getParameter('download', 'leave_file')) {
                         case '0':
                             $build->clearFile();
                             $build->setFileURL('');
                             break;
                         case 'upload_file':
                             if ($build->hasFile()) {
                                 $build->getFile()->delete();
                                 $build->clearFile();
                             }
                             $file = TBGContext::getRequest()->handleUpload('upload_file');
                             $build->setFile($file);
                             $build->setFileURL('');
                             break;
                         case 'url':
                             $build->clearFile();
                             $build->setFileURL($request['file_url']);
                             break;
                     }
                     if ($request['edition_id']) {
                         $build->setEdition($edition);
                     }
                     if (!$build->getID()) {
                         $build->setProject($this->selected_project);
                     }
                     $build->save();
                 } else {
                     throw new Exception($i18n->__('You need to specify a name for the release'));
                 }
             } else {
                 throw new Exception($i18n->__('You do not have access to this project'));
             }
         } catch (Exception $e) {
             TBGContext::setMessage('build_error', $e->getMessage());
         }
         $this->forward(TBGContext::getRouting()->generate('project_release_center', array('project_key' => $this->selected_project->getKey())));
     }
     return $this->forward403($i18n->__("You don't have access to add releases"));
 }
예제 #6
0
 public function postConfigSettings(TBGRequest $request)
 {
     if ($request->hasParameter('import_articles')) {
         $cc = 0;
         foreach ($request->getParameter('import_article') as $article_name => $import) {
             $cc++;
             TBGArticlesTable::getTable()->deleteArticleByName(urldecode($article_name));
             $content = file_get_contents(THEBUGGENIE_MODULES_PATH . 'publish' . DS . 'fixtures' . DS . $article_name);
             TBGWikiArticle::createNew(urldecode($article_name), $content, true, null, array('overwrite' => true, 'noauthor' => true));
         }
         TBGContext::setMessage('module_message', TBGContext::getI18n()->__('%number_of_articles% articles imported successfully', array('%number_of_articles%' => $cc)));
     } else {
         $settings = array('allow_camelcase_links', 'menu_title', 'hide_wiki_links', 'free_edit');
         foreach ($settings as $setting) {
             if ($request->hasParameter($setting)) {
                 $this->saveSetting($setting, $request->getParameter($setting));
             }
         }
     }
 }
예제 #7
0
 /**
  * Performs the "find issues" action
  *
  * @param TBGRequest $request
  */
 public function runFindIssues(TBGRequest $request)
 {
     $this->_getSearchDetailsFromRequest($request);
     if ($request->isMethod(TBGRequest::POST) && !$request->getParameter('quicksearch')) {
         if ($request->getParameter('delete_saved_search')) {
             try {
                 $search = TBGSavedSearchesTable::getTable()->getByID($request->getParameter('saved_search_id'));
                 if ($search->get(TBGSavedSearchesTable::UID) == TBGContext::getUser()->getID() || $search->get(TBGSavedSearchesTable::IS_PUBLIC) && TBGContext::getUser()->canCreatePublicSearches()) {
                     TBGSavedSearchesTable::getTable()->doDeleteById($request->getParameter('saved_search_id'));
                     return $this->renderJSON(array('failed' => false, 'message' => TBGContext::getI18n()->__('The saved search was deleted successfully')));
                 }
             } catch (Exception $e) {
                 return $this->renderJSON(array('failed' => true, 'message' => TBGContext::getI18n()->__('Cannot delete this saved search')));
             }
         } elseif ($request->getParameter('saved_search_name') != '') {
             $project_id = TBGContext::isProjectContext() ? TBGContext::getCurrentProject()->getID() : 0;
             TBGSavedSearchesTable::getTable()->saveSearch($request->getParameter('saved_search_name'), $request->getParameter('saved_search_description'), $request->getParameter('saved_search_public'), $this->filters, $this->groupby, $this->grouporder, $this->ipp, $this->templatename, $this->template_parameter, $project_id, $request->getParameter('saved_search_id'));
             if ($request->getParameter('saved_search_id')) {
                 TBGContext::setMessage('search_message', TBGContext::getI18n()->__('The saved search was updated'));
             } else {
                 TBGContext::setMessage('search_message', TBGContext::getI18n()->__('The saved search has been created'));
             }
             $params = array();
         } else {
             TBGContext::setMessage('search_error', TBGContext::getI18n()->__('You have to specify a name for the saved search'));
             $params = array('filters' => $this->filters, 'groupby' => $this->groupby, 'grouporder' => $this->grouporder, 'templatename' => $this->templatename, 'saved_search' => $request->getParameter('saved_search_id'), 'issues_per_page' => $this->ipp);
         }
         if (TBGContext::isProjectContext()) {
             $route = 'project_issues';
             $params['project_key'] = TBGContext::getCurrentProject()->getKey();
         } else {
             $route = 'search';
         }
         $this->forward(TBGContext::getRouting()->generate($route, $params));
     } else {
         $this->doSearch($request);
         $this->issues = $this->foundissues;
         if ($request->getParameter('quicksearch') == true) {
             $this->redirect('quicksearch');
         }
     }
     $this->search_error = TBGContext::getMessageAndClear('search_error');
     $this->search_message = TBGContext::getMessageAndClear('search_message');
     $this->appliedfilters = $this->filters;
     $this->templates = $this->getTemplates();
     $this->savedsearches = B2DB::getTable('TBGSavedSearchesTable')->getAllSavedSearchesByUserIDAndPossiblyProjectID(TBGContext::getUser()->getID(), TBGContext::isProjectContext() ? TBGContext::getCurrentProject()->getID() : 0);
 }
예제 #8
0
 public function runTransitionIssue(TBGRequest $request)
 {
     try {
         $transition = TBGContext::factory()->TBGWorkflowTransition($request->getParameter('transition_id'));
         $issue = TBGContext::factory()->TBGIssue($request->getParameter('issue_id'));
         if (!$issue->isWorkflowTransitionsAvailable()) {
             throw new Exception(TBGContext::getI18n()->__('You are not allowed to perform any workflow transitions on this issue'));
         }
         if ($transition->validateFromRequest($request)) {
             $transition->transitionIssueToOutgoingStepFromRequest($issue);
         } else {
             TBGContext::setMessage('issue_error', 'transition_error');
             TBGContext::setMessage('issue_workflow_errors', $transition->getValidationErrors());
         }
         $this->forward(TBGContext::getRouting()->generate('viewissue', array('project_key' => $issue->getProject()->getKey(), 'issue_no' => $issue->getFormattedIssueNo())));
     } catch (Exception $e) {
         throw $e;
         return $this->return404();
     }
 }
예제 #9
0
 public function runAccountPickUsername(TBGRequest $request)
 {
     if (TBGUser::isUsernameAvailable($request['selected_username'])) {
         $user = $this->getUser();
         $user->setUsername($request['selected_username']);
         $user->setOpenIdLocked(false);
         $user->setPassword(TBGUser::createPassword());
         $user->save();
         $this->getResponse()->setCookie('tbg3_username', $user->getUsername());
         $this->getResponse()->setCookie('tbg3_password', $user->getPassword());
         TBGContext::setMessage('username_chosen', true);
         $this->forward($this->getRouting()->generate('account'));
     }
     TBGContext::setMessage('error', $this->getI18n()->__('Could not pick the username "%username"', array('%username' => $request['selected_username'])));
     $this->forward($this->getRouting()->generate('account'));
 }
예제 #10
0
 /**
  * Import all valid users
  * 
  * @param TBGRequest $request
  */
 public function runImportUsers(TBGRequest $request)
 {
     $validgroups = TBGContext::getModule('auth_ldap')->getSetting('groups');
     $base_dn = TBGContext::getModule('auth_ldap')->getSetting('b_dn');
     $dn_attr = TBGContext::getModule('auth_ldap')->getSetting('dn_attr');
     $username_attr = TBGContext::getModule('auth_ldap')->getSetting('u_attr');
     $fullname_attr = TBGContext::getModule('auth_ldap')->getSetting('f_attr');
     $buddyname_attr = TBGContext::getModule('auth_ldap')->getSetting('b_attr');
     $email_attr = TBGContext::getModule('auth_ldap')->getSetting('e_attr');
     $groups_members_attr = TBGContext::getModule('auth_ldap')->getSetting('g_attr');
     $user_class = TBGContext::getModule('auth_ldap')->getSetting('u_type');
     $group_class = TBGContext::getModule('auth_ldap')->getSetting('g_type');
     $users = array();
     $importcount = 0;
     $updatecount = 0;
     try {
         /*
          * Connect and bind to the control user
          */
         $connection = TBGContext::getModule('auth_ldap')->connect();
         TBGContext::getModule('auth_ldap')->bind($connection, TBGContext::getModule('auth_ldap')->getSetting('control_user'), TBGContext::getModule('auth_ldap')->getSetting('control_pass'));
         /*
          * Get a list of all users of a certain objectClass
          */
         $fields = array($fullname_attr, $buddyname_attr, $username_attr, $email_attr, 'cn', $dn_attr);
         $filter = '(objectClass=' . TBGLDAPAuthentication::getModule()->escape($user_class) . ')';
         $results = ldap_search($connection, $base_dn, $filter, $fields);
         if (!$results) {
             TBGLogging::log('failed to search for users: ' . ldap_error($connection), 'ldap', TBGLogging::LEVEL_FATAL);
             throw new Exception(TBGContext::geti18n()->__('Search failed: ') . ldap_error($connection));
         }
         $data = ldap_get_entries($connection, $results);
         /*
          * For every user that exists, process it.
          */
         for ($i = 0; $i != $data['count']; $i++) {
             $user_dn = $data[$i][strtolower($dn_attr)][0];
             /*
              * If groups are specified, perform group restriction tests
              */
             if ($validgroups != '') {
                 /*
                  * We will repeat this for every group, but groups are supplied as a comma-separated list
                  */
                 if (strstr($validgroups, ',')) {
                     $groups = explode(',', $validgroups);
                 } else {
                     $groups = array();
                     $groups[] = $validgroups;
                 }
                 // Assumed we are initially banned
                 $allowed = false;
                 foreach ($groups as $group) {
                     // No need to carry on looking if we have access
                     if ($allowed == true) {
                         continue;
                     }
                     /*
                      * Find the group we are looking for, we search the entire directory
                      * We want to find 1 group, if we don't get 1, silently ignore this group.
                      */
                     $fields2 = array($groups_members_attr);
                     $filter2 = '(&(cn=' . TBGLDAPAuthentication::getModule()->escape($group) . ')(objectClass=' . TBGLDAPAuthentication::getModule()->escape($group_class) . '))';
                     $results2 = ldap_search($connection, $base_dn, $filter2, $fields2);
                     if (!$results2) {
                         TBGLogging::log('failed to search for user: '******'ldap', TBGLogging::LEVEL_FATAL);
                         throw new Exception(TBGContext::geti18n()->__('Search failed: ') . ldap_error($connection));
                     }
                     $data2 = ldap_get_entries($connection, $results2);
                     if ($data2['count'] != 1) {
                         continue;
                     }
                     /*
                      * Look through the group's member list. If we are found, grant access.
                      */
                     foreach ($data2[0][strtolower($groups_members_attr)] as $member) {
                         $member = preg_replace('/(?<=,) +(?=[a-zA-Z])/', '', $member);
                         $user_dn = preg_replace('/(?<=,) +(?=[a-zA-Z])/', '', $user_dn);
                         if (!is_numeric($member) && strtolower($member) == strtolower($user_dn)) {
                             $allowed = true;
                         }
                     }
                 }
                 if ($allowed == false) {
                     continue;
                 }
             }
             $users[$i] = array();
             /*
              * Set user's properties.
              * Realname is obtained from directory, if not found we set it to the username
              * Email is obtained from directory, if not found we set it to blank
              */
             if (!array_key_exists(strtolower($fullname_attr), $data[$i])) {
                 $users[$i]['realname'] = $data[$i]['cn'][0];
             } else {
                 $users[$i]['realname'] = $data[$i][strtolower($fullname_attr)][0];
             }
             if (!array_key_exists(strtolower($buddyname_attr), $data[$i])) {
                 $users[$i]['buddyname'] = $data[$i]['cn'][0];
             } else {
                 $users[$i]['buddyname'] = $data[$i][strtolower($buddyname_attr)][0];
             }
             if (!array_key_exists(strtolower($email_attr), $data[$i])) {
                 $users[$i]['email'] = '';
             } else {
                 $users[$i]['email'] = $data[$i][strtolower($email_attr)][0];
             }
             $users[$i]['username'] = $data[$i][strtolower($username_attr)][0];
         }
     } catch (Exception $e) {
         TBGContext::setMessage('module_error', TBGContext::getI18n()->__('Import failed'));
         TBGContext::setMessage('module_error_details', $e->getMessage());
         $this->forward(TBGContext::getRouting()->generate('configure_module', array('config_module' => 'auth_ldap')));
     }
     /*
      * For every user that was found, either create a new user object, or update
      * the existing one. This will update the created and updated counts as appropriate.
      */
     foreach ($users as $ldapuser) {
         $username = $ldapuser['username'];
         $email = $ldapuser['email'];
         $realname = $ldapuser['realname'];
         $buddyname = $ldapuser['buddyname'];
         try {
             $user = TBGUser::getByUsername($username);
             if ($user instanceof TBGUser) {
                 $user->setRealname($realname);
                 $user->setEmail($email);
                 // update email address
                 $user->save();
                 $updatecount++;
             } else {
                 // create user
                 $user = new TBGUser();
                 $user->setUsername($username);
                 $user->setRealname($realname);
                 $user->setBuddyname($buddyname);
                 $user->setEmail($email);
                 $user->setEnabled();
                 $user->setActivated();
                 $user->setPassword($user->getJoinedDate() . $username);
                 $user->setJoined();
                 $user->save();
                 $importcount++;
             }
         } catch (Exception $e) {
             ldap_unbind($connection);
             TBGContext::setMessage('module_error', TBGContext::getI18n()->__('Import failed'));
             TBGContext::setMessage('module_error_details', $e->getMessage());
             $this->forward(TBGContext::getRouting()->generate('configure_module', array('config_module' => 'auth_ldap')));
         }
     }
     ldap_unbind($connection);
     TBGContext::setMessage('module_message', TBGContext::getI18n()->__('Import successful! %imp users imported, %upd users updated from LDAP', array('%imp' => $importcount, '%upd' => $updatecount)));
     $this->forward(TBGContext::getRouting()->generate('configure_module', array('config_module' => 'auth_ldap')));
 }
예제 #11
0
 /**
  * Show an article
  *
  * @param TBGRequest $request
  */
 public function runEditArticle(TBGRequest $request)
 {
     $article_name = $this->article instanceof TBGWikiArticle ? $this->article->getName() : $request->getParameter('article_name');
     if (!TBGContext::getModule('publish')->canUserEditArticle($article_name)) {
         TBGContext::setMessage('publish_article_error', TBGContext::getI18n()->__('You do not have permission to edit this article'));
         $this->forward(TBGContext::getRouting()->generate('publish_article', array('article_name' => $article_name)));
     }
     if ($request->isMethod(TBGRequest::POST)) {
         if ($request->hasParameter('new_article_name') && $request->getParameter('new_article_name') != '') {
             if ($request->hasParameter('change_reason') && trim($request->getParameter('change_reason')) != '') {
                 try {
                     if ($request->getParameter('article_id')) {
                         if (($article = PublishFactory::article($request->getParameter('article_id'))) && $article instanceof TBGWikiArticle) {
                             if ($article->getLastUpdatedDate() != $request->getParameter('last_modified')) {
                                 $this->error = TBGContext::getI18n()->__('The file has been modified since you last opened it');
                             } else {
                                 try {
                                     $article->setName($request->getParameter('new_article_name'));
                                     $article->setContent($request->getRawParameter('new_article_content'));
                                     if ($request->getParameter('preview')) {
                                         $this->article = $article;
                                     } else {
                                         $article->doSave(array(), $request->getParameter('change_reason'));
                                         TBGContext::setMessage('publish_article_message', TBGContext::getI18n()->__('The article was saved'));
                                         $this->forward(TBGContext::getRouting()->generate('publish_article', array('article_name' => $article->getName())));
                                     }
                                 } catch (Exception $e) {
                                     $this->error = $e->getMessage();
                                 }
                             }
                         }
                     }
                 } catch (Exception $e) {
                 }
                 if (($article = TBGWikiArticle::getByName($request->getParameter('new_article_name'))) && $article instanceof TBGWikiArticle && $article->getID() != $request->getParameter('article_id')) {
                     $this->error = TBGContext::getI18n()->__('An article with that name already exists. Please choose a different article name');
                 } elseif (!$article instanceof TBGWikiArticle) {
                     if ($request->getParameter('preview')) {
                         $article = new TBGWikiArticle();
                         $article->setContent($request->getRawParameter('new_article_content'));
                         $article->setName($request->getParameter('new_article_name'));
                         $this->article = $article;
                     } else {
                         $article_id = TBGWikiArticle::createNew($request->getParameter('new_article_name'), $request->getRawParameter('new_article_content', ''), true);
                         $this->forward(TBGContext::getRouting()->generate('publish_article', array('article_name' => $request->getParameter('new_article_name'))));
                     }
                 }
             } else {
                 $this->error = TBGContext::getI18n()->__('You have to provide a reason for the changes');
             }
         } else {
             $this->error = TBGContext::getI18n()->__('You need to specify the article name');
         }
     }
     $this->preview = (bool) $request->getParameter('preview');
     $this->article_title = null;
     $this->article_content = null;
     $this->article_intro = null;
     $this->change_reason = null;
     if ($this->article instanceof TBGWikiArticle) {
         $this->article_title = $this->article->getTitle();
         $this->article_content = $this->article->getContent();
         if ($request->isMethod(TBGRequest::POST)) {
             if ($request->hasParameter('new_article_name')) {
                 $this->article_title = $request->getParameter('new_article_name');
             }
             if ($request->hasParameter('new_article_content')) {
                 $this->article_content = $request->getRawParameter('new_article_content');
             }
             if ($request->hasParameter('change_reason')) {
                 $this->change_reason = $request->getParameter('change_reason');
             }
         }
     } else {
         if ($request->hasParameter('new_article_content')) {
             $this->article_content = $request->getRawParameter('new_article_content');
         }
         TBGContext::loadLibrary('publish');
         $this->article_title = str_replace(array(':', '_'), array(' ', ' '), get_spaced_name($this->article_name));
     }
 }
예제 #12
0
 /**
  * Launches the MVC framework
  */
 public static function go()
 {
     TBGLogging::log('Dispatching');
     try {
         if (($route = self::getRouting()->getRouteFromUrl(self::getRequest()->getParameter('url', null, false))) || self::isInstallmode()) {
             if (self::isUpgrademode()) {
                 $route = array('module' => 'installation', 'action' => 'upgrade');
             } elseif (self::isInstallmode()) {
                 $route = array('module' => 'installation', 'action' => 'installIntro');
             }
             if (is_dir(THEBUGGENIE_MODULES_PATH . $route['module'])) {
                 if (!file_exists(THEBUGGENIE_MODULES_PATH . $route['module'] . DS . 'classes' . DS . 'actions.class.php')) {
                     throw new TBGActionNotFoundException('The ' . $route['module'] . ' module is missing the classes/actions.class.php file, containing all the module actions');
                 }
                 if (!class_exists($route['module'] . 'Actions') && !class_exists($route['module'] . 'ActionComponents')) {
                     self::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . $route['module'] . DS . 'classes' . DS);
                 }
             } else {
                 throw new Exception('Cannot load the ' . $route['module'] . ' module');
             }
             // Set up the action object
             // Construct the action class and method name, including any pre- action(s)
             $actionClassName = $route['module'] . 'Actions';
             $actionObject = new $actionClassName();
             $moduleName = $route['module'];
             $moduleMethod = $route['action'];
         } else {
             //					self::setupI18n();
             require THEBUGGENIE_MODULES_PATH . 'main' . DS . 'classes' . DS . 'actions.class.php';
             $actionObject = new mainActions();
             $moduleName = 'main';
             $moduleMethod = 'notFound';
             //					self::performAction($actionObject, 'main', 'notFound');
             //					if (self::isDebugMode()) self::generateDebugInfo();
         }
         self::$_action = $actionObject;
         if (!self::isInstallmode()) {
             self::initializeUser();
         }
         self::setupI18n();
         if (self::$_redirect_login == 'login') {
             TBGLogging::log('An error occurred setting up the user object, redirecting to login', 'main', TBGLogging::LEVEL_NOTICE);
             if (self::getRouting()->getCurrentRouteName() != 'login') {
                 TBGContext::setMessage('login_message_err', TBGContext::geti18n()->__('Please log in'));
             }
             self::getResponse()->headerRedirect(self::getRouting()->generate('login_page'), 403);
         }
         if (self::$_redirect_login == 'elevated_login') {
             TBGLogging::log('Elevated permissions required', 'main', TBGLogging::LEVEL_NOTICE);
             if (self::getRouting()->getCurrentRouteName() != 'elevated_login') {
                 TBGContext::setMessage('elevated_login_message_err', TBGContext::geti18n()->__('Please re-enter your password to continue'));
             }
             if (!class_exists('mainActions')) {
                 require THEBUGGENIE_MODULES_PATH . 'main' . DS . 'classes' . DS . 'actions.class.php';
             }
             $actionObject = new mainActions();
             $moduleName = 'main';
             $moduleMethod = 'elevatedLogin';
         }
         if (self::performAction($actionObject, $moduleName, $moduleMethod)) {
             if (self::isDebugMode()) {
                 self::generateDebugInfo();
             }
             if (\b2db\Core::isInitialized()) {
                 \b2db\Core::closeDBLink();
             }
             return true;
         }
     } catch (TBGTemplateNotFoundException $e) {
         \b2db\Core::closeDBLink();
         //header("HTTP/1.0 404 Not Found", true, 404);
         throw $e;
     } catch (TBGActionNotFoundException $e) {
         \b2db\Core::closeDBLink();
         header("HTTP/1.0 404 Not Found", true, 404);
         throw $e;
     } catch (TBGCSRFFailureException $e) {
         \b2db\Core::closeDBLink();
         if (self::isDebugMode()) {
             self::generateDebugInfo();
         }
         self::getResponse()->setHttpStatus(301);
         $message = $e->getMessage();
         if (self::getRequest()->getRequestedFormat() == 'json') {
             self::getResponse()->setContentType('application/json');
             $message = json_encode(array('message' => $message));
         }
         self::getResponse()->renderHeaders();
         echo $message;
     } catch (Exception $e) {
         \b2db\Core::closeDBLink();
         //header("HTTP/1.0 404 Not Found", true, 404);
         throw $e;
     }
 }
예제 #13
0
 /**
  * Show an article
  *
  * @param TBGRequest $request
  */
 public function runEditArticle(TBGRequest $request)
 {
     if (!$this->article->canEdit()) {
         TBGContext::setMessage('publish_article_error', TBGContext::getI18n()->__('You do not have permission to edit this article'));
         $this->forward(TBGContext::getRouting()->generate('publish_article', array('article_name' => $this->article_name)));
     }
     $this->article_route = $this->article->getID() ? 'publish_article_edit' : 'publish_article_new';
     $this->article_route_params = $this->article->getID() ? array('article_name' => $this->article_name) : array();
     if ($request->isPost()) {
         $this->preview = (bool) $request['preview'];
         $this->change_reason = $request['change_reason'];
         try {
             $this->article->setArticleType($request['article_type']);
             $this->article->setName($request['new_article_name']);
             $this->article->setParentArticle(TBGArticlesTable::getTable()->getArticleByName($request['parent_article_name']));
             $this->article->setManualName($request['manual_name']);
             if ($this->article->getArticleType() == TBGWikiArticle::TYPE_MANUAL && !$this->article->getName()) {
                 $article_name_prefix = $this->article->getParentArticle() instanceof TBGWikiArticle ? $this->article->getParentArticle()->getName() . ':' : $request['parent_article_name'];
                 $this->article->setName(str_replace(' ', '', $article_name_prefix . $this->article->getManualName()));
             }
             $this->article->setContentSyntax($request['article_content_syntax']);
             $this->article->setContent($request->getRawParameter('article_content'));
             if (!$this->article->getName() || trim($this->article->getName()) == '' || !preg_match('/[\\w:]+/i', $this->article->getName())) {
                 throw new Exception(TBGContext::getI18n()->__('You need to specify a valid article name'));
             }
             if ($request['article_type'] == TBGWikiArticle::TYPE_MANUAL && (!$this->article->getManualName() || trim($this->article->getManualName()) == '' || !preg_match('/[\\w:]+/i', $this->article->getManualName()))) {
                 throw new Exception(TBGContext::getI18n()->__('You need to specify a valid article name'));
             }
             if (TBGPublish::getModule()->getSetting('require_change_reason') == 1 && (!$this->change_reason || trim($this->change_reason) == '')) {
                 throw new Exception(TBGContext::getI18n()->__('You have to provide a reason for the changes'));
             }
             if ($this->article->getLastUpdatedDate() != $request['last_modified']) {
                 throw new Exception(TBGContext::getI18n()->__('The file has been modified since you last opened it'));
             }
             if (($article = TBGWikiArticle::getByName($request['new_new_article_name'])) && $article instanceof TBGWikiArticle && $article->getID() != $request['article_id']) {
                 throw new Exception(TBGContext::getI18n()->__('An article with that name already exists. Please choose a different article name'));
             }
             if (!$this->preview) {
                 $this->article->doSave(array(), $request['change_reason']);
                 TBGContext::setMessage('publish_article_message', TBGContext::getI18n()->__('The article was saved'));
                 $this->forward(TBGContext::getRouting()->generate('publish_article', array('article_name' => $this->article->getName())));
             }
         } catch (Exception $e) {
             $this->error = $e->getMessage();
         }
     }
 }
예제 #14
0
 public function runAddComment(TBGRequest $request)
 {
     $i18n = TBGContext::getI18n();
     $comment = null;
     $comment_applies_type = $request->getParameter('comment_applies_type');
     try {
         if (!TBGContext::getUser()->canPostComments()) {
             throw new Exception($i18n->__('You are not allowed to do this'));
         } else {
             if ($request->getParameter('comment_body') == '') {
                 throw new Exception($i18n->__('The comment must have some content'));
             }
             if ($comment_applies_type == TBGComment::TYPE_ISSUE && !$request->isAjaxCall()) {
                 $this->comment_lines = array();
                 $this->comment = '';
                 TBGEvent::listen('core', 'TBGIssue::save', array($this, 'listenIssueSaveAddComment'));
                 $issue = TBGContext::factory()->TBGIssue($request->getParameter('comment_applies_id'));
                 $issue->save(false);
             }
             if (empty($this->comment) == false) {
                 // prevent empty lines when only user comment
                 $comment_body = $this->comment . "\n\n" . $request->getParameter('comment_body', null, false);
             } else {
                 $comment_body = $request->getParameter('comment_body', null, false);
             }
             $comment = new TBGComment();
             $comment->setTitle($i18n->__('Untitled comment'));
             $comment->setContent($comment_body);
             $comment->setPostedBy(TBGContext::getUser()->getID());
             $comment->setTargetID($request->getParameter('comment_applies_id'));
             $comment->setTargetType($request->getParameter('comment_applies_type'));
             $comment->setModuleName($request->getParameter('comment_module'));
             $comment->setIsPublic((bool) $request->getParameter('comment_visibility'));
             $comment->save();
             switch ($comment_applies_type) {
                 case TBGComment::TYPE_ISSUE:
                     $comment_html = $this->getTemplateHTML('main/comment', array('comment' => $comment, 'issue' => TBGContext::factory()->TBGIssue($request->getParameter('comment_applies_id'))));
                     break;
                 case TBGComment::TYPE_ARTICLE:
                     $comment_html = $this->getTemplateHTML('main/comment', array('comment' => $comment));
                     break;
                 default:
                     $comment_html = 'OH NO!';
             }
             if ($comment_applies_type == TBGComment::TYPE_ISSUE) {
                 $issue = TBGContext::factory()->TBGIssue($request->getParameter('comment_applies_id'));
                 TBGEvent::createNew('core', 'TBGComment::createNew', $issue, array('comment' => $comment))->trigger();
                 $issue->save();
             }
         }
     } catch (Exception $e) {
         if ($request->isAjaxCall()) {
             return $this->renderJSON(array('failed' => true, 'error' => $e->getMessage()));
         } else {
             TBGContext::setMessage('comment_error', $e->getMessage());
             TBGContext::setMessage('comment_error_body', $request->getParameter('comment_body'));
             TBGContext::setMessage('comment_error_title', $request->getParameter('comment_title'));
             TBGContext::setMessage('comment_error_visibility', $request->getParameter('comment_visibility'));
         }
     }
     if ($request->isAjaxCall()) {
         return $this->renderJSON(array('title' => $i18n->__('Comment added!'), 'comment_data' => $comment_html, 'continue_url' => $request->getParameter('forward_url'), 'commentcount' => TBGComment::countComments($request->getParameter('comment_applies_id'), $request->getParameter('comment_applies_type'))));
     }
     if ($comment instanceof TBGComment) {
         $this->forward($request->getParameter('forward_url') . "#comment_{$request->getParameter('comment_applies_type')}_{$request->getParameter('comment_applies_id')}_{$comment->getID()}");
     } else {
         $this->forward($request->getParameter('forward_url'));
     }
 }
예제 #15
0
 /**
  * Forward the user with HTTP status code 403 and an (optional) message
  * based on a boolean check
  * 
  * @param boolean $condition
  * @param string $message[optional] The message
  */
 public function forward403unless($condition, $message = null)
 {
     if (!$condition) {
         $message = $message === null ? TBGContext::getI18n()->__("You are not allowed to access this page") : htmlentities($message);
         if (TBGContext::getUser()->isGuest()) {
             TBGContext::setMessage('login_message_err', $message);
             TBGContext::setMessage('login_force_redirect', true);
             TBGContext::setMessage('login_referer', TBGContext::getRouting()->generate(TBGContext::getRouting()->getCurrentRouteName(), TBGContext::getRequest()->getParameters()));
             $this->forward(TBGContext::getRouting()->generate('login_page'), 403);
         } else {
             $this->getResponse()->setHttpStatus(403);
             $this->getResponse()->setTemplate('main/forbidden', array('message' => $message));
         }
     }
 }