コード例 #1
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());
         }
     }
 }
コード例 #2
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));
     }
 }
コード例 #3
0
 public function runUpgrade(TBGRequest $request)
 {
     $version_info = explode(',', file_get_contents(THEBUGGENIE_PATH . 'installed'));
     $this->current_version = $version_info[0];
     $this->upgrade_available = $this->current_version != '3.1';
     if ($this->upgrade_available) {
         $scope = new TBGScope();
         $scope->setID(1);
         $scope->setEnabled();
         TBGContext::setScope($scope);
     }
     $this->upgrade_complete = false;
     if ($this->upgrade_available && $request->isMethod(TBGRequest::POST)) {
         $this->upgrade_complete = false;
         switch ($this->current_version) {
             case '3.0':
                 $this->_upgradeFrom3dot0();
                 break;
         }
         if ($this->upgrade_complete) {
             $existing_installed_content = file_get_contents(THEBUGGENIE_PATH . 'installed');
             file_put_contents(THEBUGGENIE_PATH . 'installed', TBGSettings::getVersion(false, false) . ', upgraded ' . date('d.m.Y H:i') . "\n" . $existing_installed_content);
             unlink(THEBUGGENIE_PATH . 'upgrade');
             $this->current_version = '3.1';
             $this->upgrade_available = false;
         }
     } elseif ($this->current_version != '3.1') {
         $this->permissions_ok = false;
         if (is_writable(THEBUGGENIE_PATH . 'installed') && is_writable(THEBUGGENIE_PATH . 'upgrade')) {
             $this->permissions_ok = true;
         }
     } else {
         $this->forward(TBGContext::getRouting()->generate('home'));
     }
 }
コード例 #4
0
 /**
  * Find users and show selection links
  * 
  * @param TBGRequest $request The request object
  */
 public function runFindIdentifiable(TBGRequest $request)
 {
     $this->forward403unless($request->isMethod(TBGRequest::POST));
     $this->users = array();
     if ($find_identifiable_by = $request->getParameter('find_identifiable_by')) {
         $this->users = TBGUser::findUsers($find_identifiable_by, 10);
         if ($request->getParameter('include_teams')) {
             $this->teams = TBGTeam::findTeams($find_identifiable_by);
         } else {
             $this->teams = array();
         }
     }
     $teamup_callback = $request->getParameter('teamup_callback');
     return $this->renderComponent('identifiableselectorresults', array('users' => $this->users, 'teams' => $this->teams, 'callback' => $request->getParameter('callback'), 'teamup_callback' => $teamup_callback));
 }