Esempio n. 1
0
 public function do_execute()
 {
     /* Prepare variables */
     try {
         $project_id = $this->getProvidedArgument('projectid');
         $project_row = \thebuggenie\core\entities\tables\Projects::getTable()->getById($project_id, false);
         \thebuggenie\core\framework\Context::setScope(new \thebuggenie\core\entities\Scope($project_row[\thebuggenie\core\entities\tables\Projects::SCOPE]));
         $project = new \thebuggenie\core\entities\Project($project_id, $project_row);
     } catch (\Exception $e) {
         $this->cliEcho("The project with the ID " . $this->getProvidedArgument('projectid') . " does not exist\n", 'red', 'bold');
         exit;
     }
     $author = $this->getProvidedArgument('author');
     $new_rev = $this->getProvidedArgument('revno');
     $commit_msg = $this->getProvidedArgument('log');
     $changed = $this->getProvidedArgument('changed');
     $old_rev = $this->getProvidedArgument('oldrev', null);
     $date = $this->getProvidedArgument('date', null);
     $branch = $this->getProvidedArgument('branch', null);
     if (\thebuggenie\core\framework\Settings::get('access_method_' . $project->getKey()) == Vcs_integration::ACCESS_HTTP) {
         $this->cliEcho("This project uses the HTTP access method, and so access via the CLI has been disabled\n", 'red', 'bold');
         exit;
     }
     if ($old_rev === null && !ctype_digit($new_rev)) {
         $this->cliEcho("Error: if only the new revision is specified, it must be a number so that old revision can be calculated from it (by substracting 1 from new revision number).");
     } else {
         if ($old_rev === null) {
             $old_rev = $new_rev - 1;
         }
     }
     $output = Vcs_integration::processCommit($project, $commit_msg, $old_rev, $new_rev, $date, $changed, $author, $branch);
     $this->cliEcho($output);
 }
Esempio n. 2
0
 public static function loadFixtures(\thebuggenie\core\entities\Scope $scope)
 {
     $scope_id = $scope->getID();
     $admin_group = new \thebuggenie\core\entities\Group();
     $admin_group->setName('Administrators');
     $admin_group->setScope($scope);
     $admin_group->save();
     \thebuggenie\core\framework\Settings::saveSetting('admingroup', $admin_group->getID(), 'core', $scope_id);
     $user_group = new \thebuggenie\core\entities\Group();
     $user_group->setName('Regular users');
     $user_group->setScope($scope);
     $user_group->save();
     \thebuggenie\core\framework\Settings::saveSetting('defaultgroup', $user_group->getID(), 'core', $scope_id);
     $guest_group = new \thebuggenie\core\entities\Group();
     $guest_group->setName('Guests');
     $guest_group->setScope($scope);
     $guest_group->save();
     // Set up initial users, and their permissions
     if ($scope->isDefault()) {
         list($guestuser_id, $adminuser_id) = \thebuggenie\core\entities\User::loadFixtures($scope, $admin_group, $user_group, $guest_group);
         tables\UserScopes::getTable()->addUserToScope($guestuser_id, $scope->getID(), $guest_group->getID(), true);
         tables\UserScopes::getTable()->addUserToScope($adminuser_id, $scope->getID(), $admin_group->getID(), true);
     } else {
         $default_scope_id = \thebuggenie\core\framework\Settings::getDefaultScopeID();
         $default_user_id = (int) \thebuggenie\core\framework\Settings::get(\thebuggenie\core\framework\Settings::SETTING_DEFAULT_USER_ID, 'core', $default_scope_id);
         tables\UserScopes::getTable()->addUserToScope($default_user_id, $scope->getID(), $user_group->getID(), true);
         tables\UserScopes::getTable()->addUserToScope(1, $scope->getID(), $admin_group->getID());
         \thebuggenie\core\framework\Settings::saveSetting(\thebuggenie\core\framework\Settings::SETTING_DEFAULT_USER_ID, $default_user_id, 'core', $scope->getID());
     }
     tables\Permissions::getTable()->loadFixtures($scope, $admin_group->getID(), $guest_group->getID());
 }
Esempio n. 3
0
 public function addUserToScope($user_id, $scope_id, $group_id = null, $confirmed = false)
 {
     $group_id = $group_id === null ? \thebuggenie\core\framework\Settings::get(\thebuggenie\core\framework\Settings::SETTING_USER_GROUP, 'core', $scope_id) : $group_id;
     $crit = $this->getCriteria();
     $crit->addInsert(self::USER_ID, $user_id);
     $crit->addInsert(self::SCOPE, $scope_id);
     $crit->addInsert(self::GROUP_ID, $group_id);
     $crit->addInsert(self::CONFIRMED, $confirmed);
     $this->doInsert($crit);
 }
Esempio n. 4
0
 public function do_execute()
 {
     $hostname = $this->getProvidedArgument('hostname');
     $this->cliEcho('Checking scope availability ...');
     if (tables\ScopeHostnames::getTable()->getScopeIDForHostname($hostname) === null) {
         $this->cliEcho("available!\n");
         $this->cliEcho("Creating scope ...");
         $scope = new entities\Scope();
         $scope->addHostname($hostname);
         $scope->setName($this->getProvidedArgument('shortname'));
         $uploads_enabled = $this->getProvidedArgument('enable_uploads', 'yes') == 'yes';
         $scope->setUploadsEnabled((bool) $uploads_enabled);
         $scope->setMaxUploadLimit($this->getProvidedArgument('upload_limit', 0));
         $scope->setMaxProjects($this->getProvidedArgument('projects', 0));
         $scope->setMaxUsers($this->getProvidedArgument('users', 0));
         $scope->setMaxTeams($this->getProvidedArgument('teams', 0));
         $scope->setMaxWorkflowsLimit($this->getProvidedArgument('workflows', 0));
         $scope->setEnabled();
         $this->cliEcho(".");
         $scope->save();
         $this->cliEcho(".done!\n");
         $admin_user = $this->getProvidedArgument('scope_admin');
         if ($admin_user) {
             $user = entities\User::getByUsername($admin_user);
             if ($user instanceof entities\User) {
                 $this->cliEcho("Adding user {$admin_user} to scope\n");
                 $admin_group_id = (int) framework\Settings::get(framework\Settings::SETTING_ADMIN_GROUP, 'core', $scope->getID());
                 tables\UserScopes::getTable()->addUserToScope($user->getID(), $scope->getID(), $admin_group_id, true);
             } else {
                 $this->cliEcho("Could not add user {$admin_user} to scope (username not found)\n");
             }
         }
         if ($this->getProvidedArgument('remove_admin', 'no') == 'yes') {
             $this->cliEcho("Removing administrator user from scope\n");
             tables\UserScopes::getTable()->removeUserFromScope(1, $scope->getID());
         }
         foreach (framework\Context::getModules() as $module) {
             $module_name = $module->getName();
             if ($module_name == 'publish') {
                 continue;
             }
             if ($this->getProvidedArgument("install_module_{$module_name}", "no") == 'yes') {
                 $this->cliEcho("Installing module {$module_name}\n");
                 entities\Module::installModule($module_name, $scope);
             }
         }
     } else {
         $this->cliEcho("not available\n", 'red');
     }
     $this->cliEcho("\n");
 }
Esempio n. 5
0
        <td><label for="highlight_default_interval"><?php 
echo __('Default line highlight interval');
?>
</label></td>
        <td>
            <input type="text" name="<?php 
echo \thebuggenie\core\framework\Settings::SETTING_SYNTAX_HIGHLIGHT_DEFAULT_INTERVAL;
?>
" style="width: 50px;"<?php 
if ($access_level != \thebuggenie\core\framework\Settings::ACCESS_FULL) {
    ?>
 disabled<?php 
}
?>
 id="highlight_default_interval" value="<?php 
echo \thebuggenie\core\framework\Settings::get('highlight_default_interval');
?>
" />
            <?php 
echo config_explanation(__('When using fancy numbering, you can have a line highlighted at a regular interval. Set the default interval to use here, if not otherwise specified'));
?>
        </td>
    </tr>
    <tr>
        <td><label for="notification_poll_interval"><?php 
echo __('Notification poll interval');
?>
</label></td>
        <td>
            <input type="text" name="<?php 
echo \thebuggenie\core\framework\Settings::SETTING_NOTIFICATION_POLL_INTERVAL;
Esempio n. 6
0
?>
            </ul>
        </div>
        <div id="account_tabs_panes">
            <div id="tab_profile_pane" style="<?php 
if ($selected_tab != 'profile') {
    ?>
 display: none;<?php 
}
?>
">
                <?php 
if (\thebuggenie\core\framework\Settings::isUsingExternalAuthenticationBackend()) {
    ?>
                    <?php 
    echo tbg_parse_text(\thebuggenie\core\framework\Settings::get('changedetails_message'), false, null, array('embedded' => true));
    ?>
                <?php 
} else {
    ?>
                    <form accept-charset="<?php 
    echo \thebuggenie\core\framework\Context::getI18n()->getCharset();
    ?>
" action="<?php 
    echo make_url('account_save_information');
    ?>
" onsubmit="TBG.Main.Profile.updateInformation('<?php 
    echo make_url('account_save_information');
    ?>
'); return false;" method="post" id="profile_information_form">
                        <h3><?php 
Esempio n. 7
0
 /**
  * Reinitialize the i18n object, used only when changing the language in the middle of something
  *
  * @param string $language The language code to change to
  */
 public static function reinitializeI18n($language = null)
 {
     if (!$language) {
         self::$_i18n = new I18n(Settings::get('language'));
     } else {
         Logging::log('Changing language to ' . $language);
         self::$_i18n = new I18n($language);
         self::$_i18n->initialize();
     }
 }
Esempio n. 8
0
 public function runAddCommitGitorious(framework\Request $request)
 {
     framework\Context::getResponse()->setContentType('text/plain');
     framework\Context::getResponse()->renderHeaders();
     $passkey = framework\Context::getRequest()->getParameter('passkey');
     $project_id = framework\Context::getRequest()->getParameter('project_id');
     $project = Project::getB2DBTable()->selectByID($project_id);
     // Validate access
     if (!$project) {
         echo 'Error: The project with the ID ' . $project_id . ' does not exist';
         exit;
     }
     if (framework\Settings::get('access_method_' . $project->getID(), 'vcs_integration') == Vcs_integration::ACCESS_DIRECT) {
         echo 'Error: This project uses the CLI access method, and so access via HTTP has been disabled';
         exit;
     }
     if (framework\Settings::get('access_passkey_' . $project->getID(), 'vcs_integration') != $passkey) {
         echo 'Error: The passkey specified does not match the passkey specified for this project';
         exit;
     }
     // Validate data
     $data = html_entity_decode(framework\Context::getRequest()->getParameter('payload', null, false));
     if (empty($data) || $data == null) {
         die('Error: No payload was provided');
     }
     $entries = json_decode($data);
     if ($entries == null) {
         die('Error: The payload could not be decoded');
     }
     $entries = json_decode($data);
     $previous = $entries->before;
     // Branch is stored in the ref
     $ref = $entries->ref;
     $parts = explode('/', $ref);
     if (count($parts) == 3) {
         $branch = $parts[2];
     } else {
         $branch = null;
     }
     // Parse each commit individually
     foreach (array_reverse($entries->commits) as $commit) {
         $email = $commit->author->email;
         $author = $commit->author->name;
         $new_rev = $commit->id;
         $old_rev = $previous;
         $commit_msg = $commit->message;
         $time = strtotime($commit->timestamp);
         // Add commit
         echo Vcs_integration::processCommit($project, $commit_msg, $old_rev, $previous, $time, "", $author, $branch);
         $previous = $new_rev;
         exit;
     }
 }
</label></td>
                        <td style="width: 580px; position: relative;">
                            <input type="text" name="blob_url" style="width: 100%" id="blob_url" value="<?php 
    echo \thebuggenie\core\framework\Settings::get('blob_url_' . $project->getID(), 'vcs_integration');
    ?>
" style="width: 100;">
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 200px;"><label for="diff_url"><?php 
    echo __('Diff page');
    ?>
</label></td>
                        <td style="width: 580px; position: relative;">
                            <input type="text" name="diff_url" style="width: 100%" id="diff_url" value="<?php 
    echo \thebuggenie\core\framework\Settings::get('diff_url_' . $project->getID(), 'vcs_integration');
    ?>
" style="width: 100;">
                        </td>
                    </tr>
                </table>
            </div>
            <table style="clear: both; width: 780px;" class="padded_table" cellpadding=0 cellspacing=0>
                <tr>
                    <td colspan="2" style="padding: 10px 0 10px 10px; text-align: right;">
                        <div style="float: left; font-size: 13px; padding-top: 2px; font-style: italic;" class="config_explanation"><?php 
    echo __('When you are done, click "%save" to save your changes on all tabs', array('%save' => __('Save')));
    ?>
</div>
                        <div id="vcs_button" style="float: right; font-size: 14px; font-weight: bold;">
                            <input type="submit" class="button button-green" value="<?php 
Esempio n. 10
0
} else {
    ?>
    <?php 
    if ($article->getArticleType() == \thebuggenie\modules\publish\entities\Article::TYPE_MANUAL) {
        echo get_spaced_name($article->getManualName());
    } else {
        $namespaces = explode(':', $article_name);
        if (count($namespaces) > 1 && $namespaces[0] == 'Category') {
            array_shift($namespaces);
            echo '<span class="faded_out blue">Category:</span>';
        }
        if (\thebuggenie\core\framework\Context::isProjectContext() && count($namespaces) > 1 && mb_strtolower($namespaces[0]) == \thebuggenie\core\framework\Context::getCurrentProject()->getKey()) {
            array_shift($namespaces);
            echo '<span>', \thebuggenie\core\framework\Context::getCurrentProject()->getName(), ':</span>';
        }
        echo \thebuggenie\core\framework\Settings::get('allow_camelcase_links', 'publish', \thebuggenie\core\framework\Context::getScope()->getID(), 0) ? get_spaced_name(implode(':', $namespaces)) : implode(':', $namespaces);
    }
    ?>
    <?php 
}
?>
    <?php 
if ($article->getID() && $mode) {
    switch ($mode) {
        /* case 'edit':
           ?><span class="faded_out"><?php echo __('%article_name ~ Edit', array('%article_name' => '')); ?></span><?php
           break; */
        case 'history':
            ?>
<span class="faded_out"><?php 
            echo __('%article_name ~ History', array('%article_name' => ''));
Esempio n. 11
0
 protected function _geshify($matches)
 {
     if (!(is_array($matches) && count($matches) > 1)) {
         return '';
     }
     $codeblock = $matches[2];
     if (strlen(trim($codeblock))) {
         $params = $matches[1];
         $language = preg_match('/(?<=lang=")(.+?)(?=")/', $params, $matches);
         if ($language !== 0) {
             $language = $matches[0];
         } else {
             $language = \thebuggenie\core\framework\Settings::get('highlight_default_lang');
         }
         $numbering_startfrom = preg_match('/(?<=line start=")(.+?)(?=")/', $params, $matches);
         if ($numbering_startfrom !== 0) {
             $numbering_startfrom = (int) $matches[0];
         } else {
             $numbering_startfrom = 1;
         }
         $geshi = new \GeSHi($codeblock, $language);
         $highlighting = preg_match('/(?<=line=")(.+?)(?=")/', $params, $matches);
         if ($highlighting !== 0) {
             $highlighting = $matches[0];
         } else {
             $highlighting = false;
         }
         $interval = preg_match('/(?<=highlight=")(.+?)(?=")/', $params, $matches);
         if ($interval !== 0) {
             $interval = $matches[0];
         } else {
             $interval = \thebuggenie\core\framework\Settings::get('highlight_default_interval');
         }
         if ($highlighting === false) {
             switch (\thebuggenie\core\framework\Settings::get('highlight_default_numbering')) {
                 case 1:
                     // Line numbering with a highloght every n rows
                     $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, $interval);
                     $geshi->start_line_numbers_at($numbering_startfrom);
                     break;
                 case 2:
                     // Normal line numbering
                     $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS, 10);
                     $geshi->start_line_numbers_at($numbering_startfrom);
                     break;
                 case 3:
                     break;
                     // No numbering
             }
         } else {
             switch ($highlighting) {
                 case 'highlighted':
                 case 'GESHI_FANCY_LINE_NUMBERS':
                     // Line numbering with a highloght every n rows
                     $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, $interval);
                     $geshi->start_line_numbers_at($numbering_startfrom);
                     break;
                 case 'normal':
                 case 'GESHI_NORMAL_LINE_NUMBERS':
                     // Normal line numbering
                     $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS, 10);
                     $geshi->start_line_numbers_at($numbering_startfrom);
                     break;
                 case 3:
                     break;
                     // No numbering
             }
         }
         $codeblock = $geshi->parse_code();
         unset($geshi);
     }
     return '<code>' . $codeblock . '</code>';
 }
Esempio n. 12
0
 public static function processCommit(\thebuggenie\core\entities\Project $project, $commit_msg, $old_rev, $new_rev, $date = null, $changed, $author, $branch = null, \Closure $callback = null)
 {
     $output = '';
     framework\Context::setCurrentProject($project);
     if ($project->isArchived()) {
         return;
     }
     if (Commits::getTable()->isProjectCommitProcessed($new_rev, $project->getID())) {
         return;
     }
     try {
         framework\Context::getI18n();
     } catch (\Exception $e) {
         framework\Context::reinitializeI18n(null);
     }
     // Is VCS Integration enabled?
     if (framework\Settings::get('vcs_mode_' . $project->getID(), 'vcs_integration') == self::MODE_DISABLED) {
         $output .= '[VCS ' . $project->getKey() . '] This project does not use VCS Integration' . "\n";
         return $output;
     }
     // Parse the commit message, and obtain the issues and transitions for issues.
     $parsed_commit = \thebuggenie\core\entities\Issue::getIssuesFromTextByRegex($commit_msg);
     $issues = $parsed_commit["issues"];
     $transitions = $parsed_commit["transitions"];
     // Build list of affected files
     $file_lines = preg_split('/[\\n\\r]+/', $changed);
     $files = array();
     foreach ($file_lines as $aline) {
         $action = mb_substr($aline, 0, 1);
         if ($action == "A" || $action == "U" || $action == "D" || $action == "M") {
             $theline = trim(mb_substr($aline, 1));
             $files[] = array($action, $theline);
         }
     }
     // Find author of commit, fallback is guest
     /*
      * Some VCSes use a different format of storing the committer's name. Systems like bzr, git and hg use the format
      * Joe Bloggs <*****@*****.**>, instead of a classic username. Therefore a user will be found via 4 queries:
      * a) First we extract the email if there is one, and find a user with that email
      * b) If one is not found - or if no email was specified, then instead test against the real name (using the name part if there was an email)
      * c) the username or full name is checked against the friendly name field
      * d) and if we still havent found one, then we check against the username
      * e) and if we STILL havent found one, we use the guest user
      */
     // a)
     $user = \thebuggenie\core\entities\tables\Users::getTable()->getByEmail($author);
     if (!$user instanceof \thebuggenie\core\entities\User && preg_match("/(?<=<)(.*)(?=>)/", $author, $matches)) {
         $email = $matches[0];
         // a2)
         $user = \thebuggenie\core\entities\tables\Users::getTable()->getByEmail($email);
         if (!$user instanceof \thebuggenie\core\entities\User) {
             // Not found by email
             preg_match("/(?<=^)(.*)(?= <)/", $author, $matches);
             $author = $matches[0];
         }
     }
     // b)
     if (!$user instanceof \thebuggenie\core\entities\User) {
         $user = \thebuggenie\core\entities\tables\Users::getTable()->getByRealname($author);
     }
     // c)
     if (!$user instanceof \thebuggenie\core\entities\User) {
         $user = \thebuggenie\core\entities\tables\Users::getTable()->getByBuddyname($author);
     }
     // d)
     if (!$user instanceof \thebuggenie\core\entities\User) {
         $user = \thebuggenie\core\entities\tables\Users::getTable()->getByUsername($author);
     }
     // e)
     if (!$user instanceof \thebuggenie\core\entities\User) {
         $user = framework\Settings::getDefaultUser();
     }
     framework\Context::setUser($user);
     framework\Settings::forceSettingsReload();
     framework\Context::cacheAllPermissions();
     $output .= '[VCS ' . $project->getKey() . '] Commit to be logged by user ' . $user->getName() . "\n";
     if ($date == null) {
         $date = NOW;
     }
     // Create the commit data
     $commit = new Commit();
     $commit->setAuthor($user);
     $commit->setDate($date);
     $commit->setLog($commit_msg);
     $commit->setPreviousRevision($old_rev);
     $commit->setRevision($new_rev);
     $commit->setProject($project);
     if ($branch !== null) {
         $data = 'branch:' . $branch;
         $commit->setMiscData($data);
     }
     if ($callback !== null) {
         $commit = $callback($commit);
     }
     $commit->save();
     $output .= '[VCS ' . $project->getKey() . '] Commit logged with revision ' . $commit->getRevision() . "\n";
     // Iterate over affected issues and update them.
     foreach ($issues as $issue) {
         $inst = new IssueLink();
         $inst->setIssue($issue);
         $inst->setCommit($commit);
         $inst->save();
         // Process all commit-message transitions for an issue.
         foreach ($transitions[$issue->getFormattedIssueNo()] as $transition) {
             if (framework\Settings::get('vcs_workflow_' . $project->getID(), 'vcs_integration') == self::WORKFLOW_ENABLED) {
                 framework\Context::setUser($user);
                 framework\Settings::forceSettingsReload();
                 framework\Context::cacheAllPermissions();
                 if ($issue->isWorkflowTransitionsAvailable()) {
                     // Go through the list of possible transitions for an issue. Only
                     // process transitions that are applicable to issue's workflow.
                     foreach ($issue->getAvailableWorkflowTransitions() as $possible_transition) {
                         if (mb_strtolower($possible_transition->getName()) == mb_strtolower($transition[0])) {
                             $output .= '[VCS ' . $project->getKey() . '] Running transition ' . $transition[0] . ' on issue ' . $issue->getFormattedIssueNo() . "\n";
                             // String representation of parameters. Used for log message.
                             $parameters_string = "";
                             // Iterate over the list of this transition's parameters, and
                             // set them.
                             foreach ($transition[1] as $parameter => $value) {
                                 $parameters_string .= "{$parameter}={$value} ";
                                 switch ($parameter) {
                                     case 'resolution':
                                         if (($resolution = \thebuggenie\core\entities\Resolution::getByKeyish($value)) instanceof \thebuggenie\core\entities\Resolution) {
                                             framework\Context::getRequest()->setParameter('resolution_id', $resolution->getID());
                                         }
                                         break;
                                     case 'status':
                                         if (($status = \thebuggenie\core\entities\Status::getByKeyish($value)) instanceof \thebuggenie\core\entities\Status) {
                                             framework\Context::getRequest()->setParameter('status_id', $status->getID());
                                         }
                                         break;
                                 }
                             }
                             // Run the transition.
                             $possible_transition->transitionIssueToOutgoingStepWithoutRequest($issue);
                             // Log an informative message about the transition.
                             $output .= '[VCS ' . $project->getKey() . '] Ran transition ' . $possible_transition->getName() . ' with parameters \'' . $parameters_string . '\' on issue ' . $issue->getFormattedIssueNo() . "\n";
                         }
                     }
                 }
             }
         }
         $issue->addSystemComment(framework\Context::getI18n()->__('This issue has been updated with the latest changes from the code repository.<source>%commit_msg</source>', array('%commit_msg' => $commit_msg)), $user->getID());
         $output .= '[VCS ' . $project->getKey() . '] Updated issue ' . $issue->getFormattedIssueNo() . "\n";
     }
     // Create file links
     foreach ($files as $afile) {
         // index 0 is action, index 1 is file
         $inst = new File();
         $inst->setAction($afile[0]);
         $inst->setFile($afile[1]);
         $inst->setCommit($commit);
         $inst->save();
         $output .= '[VCS ' . $project->getKey() . '] Added with action ' . $afile[0] . ' file ' . $afile[1] . "\n";
     }
     framework\Event::createNew('vcs_integration', 'new_commit')->trigger(array('commit' => $commit));
     return $output;
 }
Esempio n. 13
0
 /**
  * @param \thebuggenie\core\entities\User $user
  * @return array
  */
 public function getPlanningColumns(\thebuggenie\core\entities\User $user)
 {
     $columns = framework\Settings::get('planning_columns_' . $this->getID(), 'project', framework\Context::getScope()->getID(), $user->getID());
     $columns = explode(',', $columns);
     if (empty($columns) || isset($columns[0]) && empty($columns[0])) {
         // Default values
         $columns = array('priority', 'estimated_time', 'spent_time');
     }
     // Set array keys to equal array values
     $columns = array_combine($columns, $columns);
     return $columns;
 }
Esempio n. 14
0
 /**
  * Registration logic
  *
  * @Route(name="register", url="/do/register")
  * @AnonymousRoute
  *
  * @param \thebuggenie\core\framework\Request $request
  */
 public function runRegister(framework\Request $request)
 {
     framework\Context::loadLibrary('common');
     $i18n = framework\Context::getI18n();
     $fields = array();
     try {
         $username = mb_strtolower(trim($request['fieldusername']));
         $buddyname = $request['buddyname'];
         $email = mb_strtolower(trim($request['email_address']));
         $confirmemail = mb_strtolower(trim($request['email_confirm']));
         $security = $request['verification_no'];
         $realname = $request['realname'];
         $available = tables\Users::getTable()->isUsernameAvailable($username);
         if (!$available) {
             throw new \Exception($i18n->__('This username is in use'));
         }
         if (!empty($buddyname) && !empty($email) && !empty($confirmemail) && !empty($security)) {
             if ($email != $confirmemail) {
                 array_push($fields, 'email_address', 'email_confirm');
                 throw new \Exception($i18n->__('The email address must be valid, and must be typed twice.'));
             }
             if ($security != $_SESSION['activation_number']) {
                 array_push($fields, 'verification_no');
                 throw new \Exception($i18n->__('To prevent automatic sign-ups, enter the verification number shown below.'));
             }
             $email_ok = false;
             if (tbg_check_syntax($email, "EMAIL")) {
                 $email_ok = true;
             }
             if ($email_ok && framework\Settings::get('limit_registration') != '') {
                 $allowed_domains = preg_replace('/[[:space:]]*,[[:space:]]*/', '|', framework\Settings::get('limit_registration'));
                 if (preg_match('/@(' . $allowed_domains . ')$/i', $email) == false) {
                     array_push($fields, 'email_address', 'email_confirm');
                     throw new \Exception($i18n->__('Email adresses from this domain can not be used.'));
                 }
             }
             if ($email_ok == false) {
                 array_push($fields, 'email_address', 'email_confirm');
                 throw new \Exception($i18n->__('The email address must be valid, and must be typed twice.'));
             }
             if ($security != $_SESSION['activation_number']) {
                 array_push($fields, 'verification_no');
                 throw new \Exception($i18n->__('To prevent automatic sign-ups, enter the verification number shown below.'));
             }
             $password = entities\User::createPassword();
             $user = new entities\User();
             $user->setUsername($username);
             $user->setRealname($realname);
             $user->setBuddyname($buddyname);
             $user->setGroup(framework\Settings::getDefaultGroup());
             $user->setEnabled();
             $user->setPassword($password);
             $user->setEmail($email);
             $user->setJoined();
             $user->save();
             $_SESSION['activation_number'] = tbg_printRandomNumber();
             if ($user->isActivated()) {
                 framework\Context::setMessage('auto_password', $password);
                 return $this->renderJSON(array('loginmessage' => $i18n->__('After pressing %continue, you need to set your password.', array('%continue' => $i18n->__('Continue'))), 'one_time_password' => $password, 'activated' => true));
             }
             return $this->renderJSON(array('loginmessage' => $i18n->__('The account has now been registered - check your email inbox for the activation email. Please be patient - this email can take up to two hours to arrive.'), 'activated' => false));
         } else {
             array_push($fields, 'email_address', 'email_confirm', 'buddyname', 'verification_no');
             throw new \Exception($i18n->__('You need to fill out all fields correctly.'));
         }
     } catch (\Exception $e) {
         $this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array('error' => $i18n->__($e->getMessage()), 'fields' => $fields));
     }
 }
Esempio n. 15
0
 /**
  * @Listener(module='core', identifier='get_backdrop_partial')
  * @param \thebuggenie\core\framework\Event $event
  */
 public function listen_get_backdrop_partial(framework\Event $event)
 {
     $request = framework\Context::getRequest();
     $options = array();
     switch ($event->getSubject()) {
         case 'agileboard':
             $template_name = 'agile/editagileboard';
             $board = $request['board_id'] ? entities\tables\AgileBoards::getTable()->selectById($request['board_id']) : new entities\AgileBoard();
             if (!$board->getID()) {
                 $board->setAutogeneratedSearch(\thebuggenie\core\entities\SavedSearch::PREDEFINED_SEARCH_PROJECT_OPEN_ISSUES);
                 $board->setTaskIssuetype(framework\Settings::get('issuetype_task'));
                 $board->setEpicIssuetype(framework\Settings::get('issuetype_epic'));
                 $board->setIsPrivate($request->getParameter('is_private', true));
                 $board->setProject($request['project_id']);
             }
             $options['board'] = $board;
             break;
         case 'milestone_finish':
             $template_name = 'agile/milestonefinish';
             $options['project'] = \thebuggenie\core\entities\tables\Projects::getTable()->selectById($request['project_id']);
             $options['board'] = entities\tables\AgileBoards::getTable()->selectById($request['board_id']);
             $options['milestone'] = \thebuggenie\core\entities\tables\Milestones::getTable()->selectById($request['milestone_id']);
             if (!$options['milestone']->hasReachedDate()) {
                 $options['milestone']->setReachedDate(time());
             }
             break;
         case 'agilemilestone':
             $template_name = 'agile/milestone';
             $options['project'] = \thebuggenie\core\entities\tables\Projects::getTable()->selectById($request['project_id']);
             $options['board'] = entities\tables\AgileBoards::getTable()->selectById($request['board_id']);
             if ($request->hasParameter('milestone_id')) {
                 $options['milestone'] = \thebuggenie\core\entities\tables\Milestones::getTable()->selectById($request['milestone_id']);
             }
             break;
         default:
             return;
     }
     foreach ($options as $key => $value) {
         $event->addToReturnList($value, $key);
     }
     $event->setReturnValue($template_name);
     $event->setProcessed();
 }
Esempio n. 16
0
 /**
  * Shortcut for the global settings function
  *
  * @param string  $setting the name of the setting
  * @param integer $uid     the uid for the user to check
  *
  * @return mixed
  */
 public function getSetting($setting, $uid = 0)
 {
     return framework\Settings::get($setting, $this->getName(), framework\Context::getScope()->getID(), $uid);
 }
Esempio n. 17
0
 public function getCharset()
 {
     if (Context::isInstallmode()) {
         return $this->_charset;
     }
     return Settings::get('charset') != '' ? Settings::get('charset') : $this->_charset;
 }
Esempio n. 18
0
 public function isKeyboardNavigationEnabled()
 {
     $val = framework\Settings::get(framework\Settings::SETTING_USER_KEYBOARD_NAVIGATION, 'core', framework\Context::getScope(), $this->getID());
     return $val !== null ? $val : true;
 }
Esempio n. 19
0
 public function runAddUser(framework\Request $request)
 {
     try {
         if (!framework\Context::getScope()->hasUsersAvailable()) {
             throw new \Exception($this->getI18n()->__('This instance of The Bug Genie cannot add more users'));
         }
         if ($username = trim($request['username'])) {
             if (!entities\User::isUsernameAvailable($username)) {
                 if ($request->getParameter('mode') == 'import') {
                     $user = entities\User::getByUsername($username);
                     $user->addScope(framework\Context::getScope());
                     return $this->renderJSON(array('imported' => true, 'message' => $this->getI18n()->__('The user was successfully added to this scope (pending user confirmation)')));
                 } elseif (framework\Context::getScope()->isDefault()) {
                     throw new \Exception($this->getI18n()->__('This username already exists'));
                 } else {
                     $this->getResponse()->setHttpStatus(400);
                     return $this->renderJSON(array('allow_import' => true));
                 }
             }
             $user = new entities\User();
             $user->setUsername($username);
             $user->setRealname($request->getParameter('realname', $username));
             $user->setBuddyname($request->getParameter('buddyname', $username));
             $user->setEmail($request->getParameter('email'));
             $group_id = $request->getParameter('group_id') ? $request->getParameter('group_id') : framework\Settings::get(framework\Settings::SETTING_USER_GROUP);
             $user->setGroup($group_id);
             if ($request->hasParameter('password') && !(empty($request['password']) && empty($request['password_repeat']))) {
                 if (empty($request['password']) || $request['password'] != $request['password_repeat']) {
                     throw new \Exception($this->getI18n()->__('Please enter the same password twice'));
                 }
                 $password = $request['password'];
                 $user->setPassword($password);
             } else {
                 $password = entities\User::createPassword();
                 $user->setPassword($password);
             }
             $user->save();
             foreach ((array) $request['teams'] as $team_id) {
                 $user->addToTeam(entities\Team::getB2DBTable()->selectById((int) $team_id));
             }
             framework\Event::createNew('core', 'config.createuser.save', $user, array('password' => $password))->trigger();
         } else {
             throw new \Exception($this->getI18n()->__('Please enter a username'));
         }
         $this->getResponse()->setTemplate('configuration/findusers');
         $this->too_short = false;
         $this->created_user = true;
         $this->users = array($user);
         $this->total_results = 1;
         $this->title = $this->getI18n()->__('User %username created', array('%username' => $username));
         $this->total_count = entities\User::getUsersCount();
         $this->more_available = framework\Context::getScope()->hasUsersAvailable();
     } catch (\Exception $e) {
         $this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array('error' => $e->getMessage()));
     }
 }
Esempio n. 20
0
            </li>
        <?php 
}
?>
        <li><a href="javascript:void(0);" onclick="TBG.Main.Helpers.Backdrop.show('<?php 
echo make_url('get_partial_for_backdrop', array('key' => 'usercard', 'user_id' => $user->getID()));
?>
');$('bud_<?php 
echo $user->getUsername() . "_12";
?>
').hide();"><?php 
echo __('Show user details');
?>
</a></li>
        <?php 
if (!in_array($user->getID(), array(1, (int) \thebuggenie\core\framework\Settings::get(\thebuggenie\core\framework\Settings::SETTING_DEFAULT_USER_ID)))) {
    ?>
            <?php 
    if (\thebuggenie\core\framework\Context::getScope()->isDefault()) {
        ?>
                <li><?php 
        echo javascript_link_tag(__('Delete this user'), array('onclick' => "TBG.Main.Helpers.Dialog.show('" . __e('Permanently delete this user?') . "', '" . __e('Are you sure you want to remove this user? This will remove the users login data, as well as memberships in (and data in) any scopes the user is a member of.') . "', {yes: {click: function() {TBG.Config.User.remove('" . make_url('configure_users_delete_user', array('user_id' => $user->getID())) . "', " . $user->getID() . "); TBG.Main.Helpers.Dialog.dismiss(); } }, no: {click: TBG.Main.Helpers.Dialog.dismiss}});"));
        ?>
</li>
            <?php 
    } elseif ($user->isScopeConfirmed()) {
        ?>
                <li><?php 
        echo javascript_link_tag(__('Remove user from this scope'), array('onclick' => "TBG.Main.Helpers.Dialog.show('" . __e('Remove this user?') . "', '" . __e('Are you sure you want to remove this user from the current scope? The users login is kept, and you can re-add the user later.') . "', {yes: {click: function() {TBG.Config.User.remove('" . make_url('configure_users_delete_user', array('user_id' => $user->getID())) . "', " . $user->getID() . "); TBG.Main.Helpers.Dialog.dismiss(); } }, no: {click: TBG.Main.Helpers.Dialog.dismiss}});"));
        ?>
</li>
</div>
    <div class="content">
        <?php 
if (count($latest_articles)) {
    ?>
            <ul class="article_list">
                <?php 
    foreach ($latest_articles as $article) {
        ?>
                    <li>
                        <div>
                            <?php 
        echo image_tag('news_item_medium.png', array('style' => 'float: left;'), false, 'publish');
        ?>
                            <?php 
        echo link_tag(make_url('publish_article', array('article_name' => $article->getName())), \thebuggenie\core\framework\Settings::get('allow_camelcase_links', 'publish', \thebuggenie\core\framework\Context::getScope()->getID(), 0) ? get_spaced_name($article->getTitle()) : $article->getTitle());
        ?>
                            <br>
                            <span><?php 
        echo __('%time, by %user', array('%time' => tbg_formatTime($article->getPostedDate(), 3), '%user' => '<b>' . ($article->getAuthor() instanceof \thebuggenie\core\entities\common\Identifiable ? '<a href="javascript:void(0);" onclick="TBG.Main.Helpers.Backdrop.show(\'' . make_url('get_partial_for_backdrop', array('key' => 'usercard', 'user_id' => $article->getAuthor()->getID())) . '\');">' . $article->getAuthor()->getName() . '</a>' : __('System')) . '</b>'));
        ?>
</span>
                        </div>
                    </li>
                <?php 
    }
    ?>
            </ul>
        <?php 
} else {
    ?>
Esempio n. 22
0
 public function isDesktopNotificationsNewTabEnabled()
 {
     $val = framework\Settings::get(framework\Settings::SETTING_USER_DESKTOP_NOTIFICATIONS_NEW_TAB, 'core', framework\Context::getScope(), $this->getID());
     return $val !== null ? $val : false;
 }
?>
</label></td>
                        <td>
                            <?php 
include_component('main/textarea', array('area_name' => 'changepw_message', 'area_id' => 'changepw_message', 'height' => '75px', 'width' => '100%', 'value' => \thebuggenie\core\framework\Settings::get('changepw_message'), 'hide_hint' => true));
?>
                        </td>
                    </tr>
                    <tr>
                        <td style="vertical-align: top"><label for="changedetails_message"><?php 
echo __('Change account details message');
?>
</label></td>
                        <td>
                            <?php 
include_component('main/textarea', array('area_name' => 'changedetails_message', 'area_id' => 'changedetails_message', 'height' => '75px', 'width' => '100%', 'value' => \thebuggenie\core\framework\Settings::get('changedetails_message'), 'hide_hint' => true));
?>
                        </td>
                    </tr>
                </table>
                <?php 
if ($access_level == \thebuggenie\core\framework\Settings::ACCESS_FULL) {
    ?>
                        <div class="greybox" style="margin: 5px 0px 5px 0px; height: 23px; padding: 5px 10px 5px 10px;">
                            <div style="float: left; font-size: 13px; padding-top: 2px;"><?php 
    echo __('Click "%save" to save your changes in all categories', array('%save' => __('Save')));
    ?>
</div>
                            <input type="submit" id="config_auth_button" style="float: right; padding: 0 10px 0 10px; font-size: 14px; font-weight: bold;" value="<?php 
    echo __('Save');
    ?>
Esempio n. 24
0
 protected function _initializeColumns()
 {
     if (!is_array($this->_columns)) {
         if (!strlen($this->_columns)) {
             if ($columns = \thebuggenie\core\framework\Settings::get('search_scs_' . $this->getTemplateName())) {
                 $this->_columns = explode(',', $columns);
             } else {
                 $this->_columns = self::getDefaultVisibleColumns();
             }
         } else {
             $this->_columns = explode(',', $this->_columns);
         }
     }
 }
</label></td>
                <td style="width: 580px;">
                    <input type="email" name="mailing_from_address" style="width: 300px;" id="mailing_from_address" value="<?php 
echo \thebuggenie\core\framework\Settings::get('project_from_address_' . $project->getID(), 'mailing');
?>
">
                </td>
            </tr>
            <tr>
                <td style="width: 200px;"><label for="mailing_from_name"><?php 
echo __('Project from-name');
?>
</label></td>
                <td style="width: 580px;">
                    <input type="text" name="mailing_from_name" style="width: 300px;" id="mailing_from_name" value="<?php 
echo \thebuggenie\core\framework\Settings::get('project_from_name_' . $project->getID(), 'mailing');
?>
">
                </td>
            </tr>
            <tr>
                <td class="config_explanation" colspan="2"><?php 
echo __('By specifying an email address here, users can hit the "Reply" button on email notifications, and replies will be sent to the specified address instead of the usual generic no-reply address.');
?>
</td>
            </tr>
        </table>
    </form>
</div>
<div id="tab_mailing_other_pane"<?php 
if ($selected_tab != 'mailing_other') {