/**
  * Repository history
  *
  * @return void
  * @author Chris Conover
  **/
 function history()
 {
     $page = intval(array_var($_GET, 'page')) > 0 ? array_var($_GET, 'page') : 1;
     $branch_tag = strval(array_var($_GET, 'branch_tag')) != '' ? array_var($_GET, 'branch_tag') : 'master';
     js_assign('commit_filepath_url', assemble_url('github_commit_filepaths', array('project_id' => $this->active_project->getId(), 'github_repository_id' => $this->active_repository->getID())));
     $commits = $this->active_repository->getBranchTagCommits($branch_tag, $page);
     // Group commits by days
     $grouped_commits = array();
     $date_format = 'F j. Y';
     foreach ($commits as $commit) {
         $commit->short_id = substr($commit->id, 0, 9) . '...' . substr($commit->id, -9);
         $commit->message = $this->analyzeCommitMessage($commit->message);
         $commit_formatted_date = date($date_format, strtotime($commit->committed_date));
         if (count($grouped_commits) == 0 || !isset($grouped_commits[$commit_formatted_date])) {
             $grouped_commits[$commit_formatted_date] = array($commit);
         } else {
             array_push($grouped_commits[$commit_formatted_date], $commit);
         }
     }
     $this->smarty->assign(array('path_info' => strval(array_var($_GET, 'path_info')), 'page' => $page, 'next_page' => $page + 1, 'prev_page' => $page > 1 ? $page - 1 : null, 'branches' => $this->active_repository->getBranches(), 'tags' => $this->active_repository->getTags(), 'commits' => $grouped_commits, 'user' => $this->active_repository->getUserName(), 'repo' => $this->active_repository->getRepoName(), 'branch_tag' => $branch_tag));
 }
예제 #2
0
 /**
  * Exports the given repository and creates a ZIP file containing XML output files
  *
  * @param Repository $repository the Repository instance to export
  * @param string $filename the output file name inside each language folder
  * @param int $groupID the group to get the output for (or Phrase::GROUP_ALL)
  * @param int $format the format (constant) to use for this export
  * @param int $minCompletion the minimum percentage of completion for languages to be eligible for exporting
  * @param bool $ignoreIfSameAsDefault ignore phrases which are the same as the default language
  * @throws Exception if the repository could not be exported
  */
 public static function exportRepository($repository, $filename, $groupID, $format, $minCompletion = 0, $ignoreIfSameAsDefault = false)
 {
     if (self::isFilenameValid($filename)) {
         if ($repository instanceof Repository) {
             $exportSuccess = true;
             $randomDir = mt_rand(1000000, 9999999);
             $savePath = URL::getTempPath(false) . URL::encodeID($repository->getID());
             self::deleteDirectoryRecursively($savePath);
             // delete all old output files from output directory first
             $savePath .= '/' . $randomDir;
             // navigate to random directory inside output folder
             if (mkdir($savePath, 0755, true)) {
                 // if output folder could be created
                 $languages = Language::getList();
                 $defaultLanguageObject = $repository->getLanguage($repository->getDefaultLanguage());
                 foreach ($languages as $language) {
                     $languageObject = $repository->getLanguage($language);
                     $languageKeys = $languageObject->getKeys();
                     $ignorePhrasesSameAsDefault = $ignoreIfSameAsDefault && $repository->getDefaultLanguage() != $language;
                     if ($format == self::FORMAT_ANDROID_XML_ESCAPED_HTML) {
                         $languageOutput = $languageObject->outputAndroidXMLEscapedHTML($groupID, $ignorePhrasesSameAsDefault, $defaultLanguageObject);
                         $fileExtension = '.xml';
                     } elseif ($format == self::FORMAT_JSON) {
                         $languageOutput = $languageObject->outputJSON($groupID, $ignorePhrasesSameAsDefault, $defaultLanguageObject);
                         $fileExtension = '.json';
                     } elseif ($format == self::FORMAT_PLAINTEXT) {
                         $languageOutput = $languageObject->outputPlaintext($groupID, $ignorePhrasesSameAsDefault, $defaultLanguageObject);
                         $fileExtension = '.txt';
                     } else {
                         $languageOutput = $languageObject->outputAndroidXML($groupID, $ignorePhrasesSameAsDefault, $defaultLanguageObject);
                         $fileExtension = '.xml';
                     }
                     if ($languageOutput->getCompleteness() >= $minCompletion) {
                         foreach ($languageKeys as $languageKey) {
                             if (mkdir($savePath . '/' . $languageKey . '/', 0755, true)) {
                                 if (file_put_contents($savePath . '/' . $languageKey . '/' . $filename . $fileExtension, $languageOutput->getContent()) !== false) {
                                     $exportSuccess = true;
                                 } else {
                                     // output file could not be written
                                     $exportSuccess = false;
                                 }
                             } else {
                                 // sub-directory for language could not be created
                                 $exportSuccess = false;
                             }
                         }
                     }
                 }
             } else {
                 // output folder could not be created
                 $exportSuccess = false;
             }
             if ($exportSuccess) {
                 $outputPath = URL::getTempPath(true) . URL::encodeID($repository->getID()) . '/' . $randomDir;
                 if (self::zipFolder($savePath, $savePath . '/Export.zip')) {
                     UI::redirectToURL($outputPath . '/Export.zip');
                 }
             }
         } else {
             throw new Exception('The repository must be an instance of class Repository');
         }
     } else {
         throw new Exception('Invalid filename: ' . $filename);
     }
 }