Exemple #1
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);
     }
 }
Exemple #2
0
 public static function getPage_Invitations($contents, $containers)
 {
     $repositoryID = self::validateID(self::getDataGET('project'), true);
     $repositoryData = Database::getRepositoryData($repositoryID);
     if (empty($repositoryData)) {
         self::addBreadcrumbItem(URL::toProject($repositoryID), 'Project not found');
         self::setTitle('Project not found');
         $contents[] = new UI_Heading('Project not found', true);
         $contents[] = new UI_Paragraph('We\'re sorry, but we could not find the project that you requested.');
         $contents[] = new UI_Paragraph('Please check if you have made any typing errors.');
     } else {
         if (Authentication::getUserID() <= 0) {
             self::setTitle($repositoryData['name']);
             $contents[] = new UI_Heading(htmlspecialchars($repositoryData['name']), true);
             $contents[] = self::getLoginForm();
         } elseif (!Repository::hasUserPermissions(Authentication::getUserID(), $repositoryID, $repositoryData, Repository::ROLE_ADMINISTRATOR)) {
             self::setTitle($repositoryData['name']);
             $contents[] = new UI_Heading(htmlspecialchars($repositoryData['name']), true);
             $contents[] = new UI_Paragraph('Only administrators of this project are allowed to review invitation requests.');
         } else {
             $currentPageURL = URL::toInvitations($repositoryID);
             self::addBreadcrumbItem($currentPageURL, 'Invitations');
             self::setTitle('Invitations');
             $contents[] = new UI_Heading('Invitations', true);
             $invitationData = Database::getInvitationByRepository($repositoryID);
             if (empty($invitationData)) {
                 // no invitations available for review (anymore)
                 UI::redirectToURL(URL::toDashboard());
             } else {
                 // edits available to review
                 Time::init();
                 $form = new UI_Form(htmlspecialchars($currentPageURL), false);
                 $table = new UI_Table(array('', ''));
                 $table->setColumnPriorities(6, 6);
                 $buttonAccept = new UI_Form_Button('Accept', UI_Link::TYPE_SUCCESS, UI_Form_Button::ACTION_SUBMIT, 'invitations[accept]', Repository::INVITATION_ACCEPTED);
                 $buttonDecline = new UI_Form_Button('Decline', UI_Link::TYPE_WARNING, UI_Form_Button::ACTION_SUBMIT, 'invitations[accept]', Repository::INVITATION_DECLINED);
                 $actionButtons = new UI_Form_ButtonGroup(array($buttonAccept, $buttonDecline), true);
                 $invitationRoleSelect = new UI_Form_Select('', 'invitations[role]', '', false, '', '', '', true);
                 $invitationRoleSelect->addOption(Repository::getRoleName(Repository::ROLE_CONTRIBUTOR), Repository::ROLE_CONTRIBUTOR);
                 $invitationRoleSelect->addOption(Repository::getRoleName(Repository::ROLE_MODERATOR), Repository::ROLE_MODERATOR);
                 $invitationRoleSelect->addOption(Repository::getRoleName(Repository::ROLE_DEVELOPER), Repository::ROLE_DEVELOPER);
                 $invitationRoleSelect->addOption(Repository::getRoleName(Repository::ROLE_ADMINISTRATOR), Repository::ROLE_ADMINISTRATOR);
                 $table->addRow(array('<strong>Assigned role</strong>', $invitationRoleSelect->getHTML()));
                 $table->addRow(array('<strong>Username</strong>', htmlspecialchars($invitationData[0]['username'])));
                 $table->addRow(array('<strong>Real name</strong>', empty($invitationData[0]['real_name']) ? '&mdash;' : htmlspecialchars($invitationData[0]['real_name'])));
                 $table->addRow(array('<strong>Country</strong>', empty($invitationData[0]['localeCountry']) ? '&mdash;' : Time::getCountryName($invitationData[0]['localeCountry'], '&mdash;')));
                 $table->addRow(array('<strong>Request date</strong>', date('d.m.Y H:i', $invitationData[0]['request_time'])));
                 $table->addRow(array('<strong>Sign-up date</strong>', date('d.m.Y H:i', $invitationData[0]['join_date'])));
                 $table->addRow(array('<strong>Last sign-in</strong>', date('d.m.Y H:i', $invitationData[0]['last_login'])));
                 $form->addContent(new UI_Form_Hidden('invitations[userID]', URL::encodeID($invitationData[0]['userID'])));
                 $form->addContent($actionButtons);
                 $form->addContent($table);
                 $form->addContent($actionButtons);
                 $contents[] = $form;
             }
         }
     }
     $cell = new UI_Cell($contents);
     $row = new UI_Row(array($cell));
     $containers[] = new UI_Container(array($row));
     return new UI_Group($containers);
 }