Ejemplo n.º 1
0
 protected function Form_Create()
 {
     parent::Form_Create();
     if (QApplication::GetUserId() == NarroUser::ANONYMOUS_USER_ID) {
         $strPassHash = QApplication::QueryString('h');
         $strUsername = QApplication::QueryString('u');
         if ($strPassHash && $strUsername) {
             $objUser = NarroUser::LoadByUsernameAndPassword($strUsername, $strPassHash);
             if ($objUser instanceof NarroUser) {
                 QApplication::$User = $objUser;
             } else {
                 QApplication::Redirect('login.php');
             }
         } else {
             QApplication::Redirect('login.php');
         }
     }
     $this->lblMessage = new QLabel($this);
     $this->lblMessage->HtmlEntities = false;
     $this->txtPassword = new QTextBox($this);
     $this->txtPassword->TextMode = QTextMode::Password;
     $this->btnChangePassword = new QButton($this);
     $this->btnChangePassword->PrimaryButton = true;
     $this->btnChangePassword->Text = t('Change password');
     $this->btnChangePassword->AddAction(new QClickEvent(), new QServerAction('btnChangePassword_Click'));
 }
Ejemplo n.º 2
0
 protected function Form_Create()
 {
     parent::Form_Create();
     if (QApplication::GetUserId() == NarroUser::ANONYMOUS_USER_ID) {
         QApplication::Redirect(NarroLink::ProjectList());
         exit;
     }
     if (QApplication::GetUserId() != QApplication::QueryString('u') && QApplication::HasPermissionForThisLang('Can manage users', null)) {
         $this->objUser = NarroUser::Load(QApplication::QueryString('u'));
     }
     if (!$this->objUser instanceof NarroUser) {
         $this->objUser = QApplication::$User;
     }
     $this->pnlBreadcrumb->setElements(NarroLink::ProjectList(t('Projects')), NarroLink::UserList('', t('Users')), $this->objUser->RealName);
     $this->pnlTab = new QTabs($this);
     new QPanel($this->pnlTab);
     $arrHeaders[] = NarroLink::UserProfile($this->objUser->UserId, t('Profile'));
     if (QApplication::GetUserId() == $this->objUser->UserId || QApplication::HasPermissionForThisLang('Can manage users', null)) {
         new QPanel($this->pnlTab);
         $arrHeaders[] = NarroLink::UserPreferences($this->objUser->UserId, t('Preferences'));
     }
     new QPanel($this->pnlTab);
     $arrHeaders[] = NarroLink::UserRole($this->objUser->UserId, t('Roles'));
     if (QApplication::GetUserId() == $this->objUser->UserId || QApplication::HasPermissionForThisLang('Can manage users', null)) {
         $this->pnlUser = new NarroUserEditPanel($this->objUser, $this->pnlTab);
         $arrHeaders[] = NarroLink::UserEdit($this->objUser->UserId, t('Edit'));
         $this->pnlTab->Selected = count($arrHeaders) - 1;
     }
     $this->pnlTab->Headers = $arrHeaders;
 }
Ejemplo n.º 3
0
 protected function GetWorkingDirectory($strCheckoutCommand = null)
 {
     $this->strWorkingDirectory = sprintf('%s/upload-u_%d-l_%s-p_%d', __TMP_PATH__, QApplication::GetUserId(), $this->objLanguage->LanguageCode, $this->objProject->ProjectId);
     $this->CleanWorkingDirectory();
     if (!$this instanceof NarroMercurialSourcePanel) {
         mkdir($this->strWorkingDirectory);
     }
     $strCommand = sprintf($strCheckoutCommand, escapeshellarg($this->txtRepository->Text), escapeshellarg($this->strWorkingDirectory));
     NarroLogger::LogInfo(sprintf('Running "%s"', $strCommand));
     $strProcLogFile = __TMP_PATH__ . '/' . $this->objProject->ProjectId . '-' . $this->objLanguage->LanguageCode . '-vcs.log';
     if (file_exists($strProcLogFile) && is_writable($strProcLogFile)) {
         unlink($strProcLogFile);
     }
     chdir(__TMP_PATH__);
     $mixProcess = proc_open("{$strCommand}", array(1 => array("file", $strProcLogFile, 'a'), 2 => array("file", $strProcLogFile, 'a')), $foo);
     $status = proc_get_status($mixProcess);
     while ($status['running']) {
         $status = proc_get_status($mixProcess);
     }
     proc_close($mixProcess);
     if (!file_exists($this->strWorkingDirectory)) {
         throw new Exception(sprintf('The working directory "%s" does not exist, probably the checkout command failed', $this->strWorkingDirectory));
     }
     chmod($this->strWorkingDirectory, 0777);
     if (file_exists($strProcLogFile)) {
         NarroLogger::LogInfo(file_get_contents($strProcLogFile));
     }
     NarroUtils::RecursiveDelete($this->strWorkingDirectory . '/.hg');
     foreach (NarroUtils::SearchDirectoryByName($this->strWorkingDirectory, '.svn') as $strSvnDir) {
         NarroUtils::RecursiveDelete($strSvnDir);
     }
     $arrSearchResult = NarroUtils::SearchDirectoryByName($this->strWorkingDirectory, $this->objLanguage->LanguageCode);
     if ($arrSearchResult == false) {
         $arrSearchResult = NarroUtils::SearchDirectoryByName($this->strWorkingDirectory, $this->objLanguage->LanguageCode . '-' . $this->objLanguage->CountryCode);
     }
     if ($arrSearchResult == false) {
         $arrSearchResult = NarroUtils::SearchDirectoryByName($this->strWorkingDirectory, $this->objLanguage->LanguageCode . '_' . $this->objLanguage->CountryCode);
     }
     NarroUtils::RecursiveChmod($this->strWorkingDirectory);
     if (is_array($arrSearchResult) && count($arrSearchResult) == 1) {
         NarroLogger::LogWarn(sprintf('Path changed from "%s" to "%s" because a directory named "%s" was found deeper in the given path.', $this->strWorkingDirectory, $arrSearchResult[0], $this->objLanguage->LanguageCode));
         $this->strWorkingDirectory = $arrSearchResult[0];
     }
     if ($this->chkCopyFilesToDefaultDirectory->Checked) {
         if (file_exists(__IMPORT_PATH__ . '/' . $this->objProject->ProjectId . '/' . $this->objLanguage->LanguageCode)) {
             NarroUtils::RecursiveDelete(__IMPORT_PATH__ . '/' . $this->objProject->ProjectId . '/' . $this->objLanguage->LanguageCode . '/*');
         } else {
             mkdir(__IMPORT_PATH__ . '/' . $this->objProject->ProjectId . '/' . $this->objLanguage->LanguageCode, 0777, true);
         }
         NarroUtils::RecursiveCopy($this->strWorkingDirectory, __IMPORT_PATH__ . '/' . $this->objProject->ProjectId . '/' . $this->objLanguage->LanguageCode);
         NarroUtils::RecursiveChmod(__IMPORT_PATH__ . '/' . $this->objProject->ProjectId . '/' . $this->objLanguage->LanguageCode);
     }
     return $this->strWorkingDirectory;
 }
Ejemplo n.º 4
0
 public function btnSave_Click()
 {
     if (trim($this->txtComment->Text)) {
         $objComment = new NarroTextComment();
         $objComment->UserId = QApplication::GetUserId();
         $objComment->LanguageId = QApplication::GetLanguageId();
         $objComment->TextId = $this->intTextId;
         $objComment->Created = QDateTime::Now();
         $objComment->CommentText = $this->txtComment->Text;
         $objComment->CommentTextMd5 = md5($objComment->CommentText);
         $objComment->Save();
         $this->dtgComments->Refresh();
     }
 }
 public function __construct(NarroUser $objUser, $objParentObject, $strControlId = null)
 {
     // Call the Parent
     try {
         parent::__construct($objParentObject, $strControlId);
     } catch (QCallerException $objExc) {
         $objExc->IncrementOffset();
         throw $objExc;
     }
     $this->strTemplate = dirname(__FILE__) . '/' . __CLASS__ . '.tpl.php';
     $this->objUser = $objUser;
     $this->pnlTranslatedPerProjectPie = new QDatabasePieChart($this);
     $this->pnlTranslatedPerProjectPie->Query = sprintf('
                         SELECT
                             narro_project.project_name AS label, COUNT(narro_suggestion.suggestion_id) AS cnt
                         FROM
                             narro_suggestion, narro_context, narro_project
                         WHERE
                             narro_context.text_id = narro_suggestion.text_id AND
                             narro_project.project_id = narro_context.project_id AND
                             narro_suggestion.language_id=%d AND
                             narro_suggestion.user_id=%d
                         GROUP BY narro_context.project_id', QApplication::GetLanguageId(), $this->objUser->UserId);
     $intSuggestionCount = NarroSuggestion::CountByUserId($this->objUser->UserId);
     $this->pnlTranslatedPerProjectPie->Total = $intSuggestionCount;
     $this->pnlTranslatedPerProjectPie->MinimumDataValue = 0;
     $this->pnlApprovedPie = new QPieChart($this);
     $this->pnlApprovedPie->Total = $this->pnlTranslatedPerProjectPie->Total;
     $this->pnlApprovedPie->MinimumDataValue = 0;
     $objDatabase = NarroContextInfo::GetDatabase();
     $strQuery = sprintf("\n                            SELECT\n                                DISTINCT narro_context_info.valid_suggestion_id\n                            FROM\n                                narro_context_info, narro_suggestion\n                            WHERE\n                                narro_context_info.valid_suggestion_id=narro_suggestion.suggestion_id AND\n                                narro_suggestion.user_id=%d", $this->objUser->UserId);
     $objDbResult = $objDatabase->Query($strQuery);
     $intValidSuggestionCount = $objDbResult->CountRows();
     $this->pnlApprovedPie->Data = array(t('Approved') => $intValidSuggestionCount, t('Not approved') => $intSuggestionCount - $intValidSuggestionCount);
     $this->tabActivity = new QTabs($this);
     $this->dtgSuggestions_Create();
     $arrHeaders[] = t('Translations');
     $this->dtgReviews_Create();
     $arrHeaders[] = t('Reviews');
     $this->dtgComments_Create();
     $arrHeaders[] = t('Comments');
     $this->dtgVotes_Create();
     $arrHeaders[] = t('Votes');
     if (QApplication::HasPermissionForThisLang('Administrator') || QApplication::GetUserId() == $this->objUser->UserId) {
         $this->dtgLog_Create();
         $arrHeaders[] = t('Logged messages');
     }
     $this->tabActivity->Headers = $arrHeaders;
 }
Ejemplo n.º 6
0
 public function btnVote_Click($strFormId, $strControlId, $strParameter)
 {
     if (!QApplication::HasPermissionForThisLang('Can vote', $this->objContextInfo->Context->ProjectId)) {
         return false;
     }
     $objNarroSuggestionVote = NarroSuggestionVote::QuerySingle(QQ::AndCondition(QQ::Equal(QQN::NarroSuggestionVote()->ContextId, $this->objContextInfo->ContextId), QQ::Equal(QQN::NarroSuggestionVote()->SuggestionId, $strParameter), QQ::Equal(QQN::NarroSuggestionVote()->UserId, QApplication::GetUserId())));
     if (!$objNarroSuggestionVote) {
         $objNarroSuggestionVote = new NarroSuggestionVote();
         $objNarroSuggestionVote->SuggestionId = $strParameter;
         $objNarroSuggestionVote->ContextId = $this->objContextInfo->ContextId;
         $objNarroSuggestionVote->UserId = QApplication::GetUserId();
         $objNarroSuggestionVote->Created = QDateTime::Now();
     }
     if (strpos($strControlId, 'votdn') === 0) {
         $objNarroSuggestionVote->VoteValue = -1;
     } else {
         $objNarroSuggestionVote->VoteValue = 1;
     }
     $objNarroSuggestionVote->Modified = QDateTime::Now();
     $objNarroSuggestionVote->Save();
     $this->objContextInfo->Modified = QDateTime::Now();
     $this->objContextInfo->Save();
     if ($this->ParentControl->ParentControl->chkRefresh->Checked && $strControlId != $this->btnKeepUntranslated->ControlId) {
         $this->ParentControl->ParentControl->btnSearch_Click();
     }
     $this->lblText->Warning = t('Thank you for your vote. You can change it anytime by voting another suggestion.');
 }
Ejemplo n.º 7
0
 protected function GetWorkingDirectory()
 {
     if (!file_exists($this->fileSource->File)) {
         throw new Exception('You have to upload a file');
     }
     $this->strWorkingDirectory = sprintf('%s/upload-u_%d-l_%s-p_%d', __TMP_PATH__, QApplication::GetUserId(), $this->objLanguage->LanguageCode, $this->objProject->ProjectId);
     $this->CleanWorkingDirectory();
     mkdir($this->strWorkingDirectory);
     chmod($this->strWorkingDirectory, 0777);
     switch (strtolower(pathinfo($this->fileSource->File, PATHINFO_EXTENSION))) {
         case 'zip':
         case 'xpi':
             NarroLogger::LogInfo(sprintf('Trying to uncompress %s', $this->fileSource->FileName));
             $objZipFile = new ZipArchive();
             $intErrCode = $objZipFile->open($this->fileSource->File);
             if ($intErrCode === TRUE) {
                 $objZipFile->extractTo($this->strWorkingDirectory);
                 $objZipFile->close();
                 NarroLogger::LogInfo(sprintf('Sucessfully uncompressed %s.', $this->fileSource->FileName));
             } else {
                 switch ($intErrCode) {
                     case ZIPARCHIVE::ER_NOZIP:
                         $strError = 'Not a zip archive';
                         break;
                     default:
                         $strError = 'Error code: ' . $intErrCode;
                 }
                 $this->fileSource->File = '';
                 throw new Exception(sprintf('Failed to uncompress %s: %s', $this->fileSource->File, $strError));
             }
             break;
         case 'dtd':
         case 'properties':
         case 'ini':
         case 'inc':
         case 'po':
         case 'sdf':
         case 'svg':
         case 'dpo':
         case 'srt':
         case 'php':
             copy($this->fileSource->File, $this->strWorkingDirectory . '/' . $this->fileSource->FileName);
             chmod($this->strWorkingDirectory . '/' . $this->fileSource->FileName, 0666);
             NarroLogger::LogInfo(sprintf('Single file uploaded, copied %s to %s', $this->fileSource->FileName, $this->strWorkingDirectory));
             break;
         default:
             throw new Exception(sprintf('Unsupported file type uploaded'));
     }
     if (file_exists($this->fileSource->File)) {
         unlink($this->fileSource->File);
     }
     $this->fileSource->btnDelete_Click();
     $arrSearchResult = NarroUtils::SearchDirectoryByName($this->strWorkingDirectory, $this->objLanguage->LanguageCode);
     if ($arrSearchResult == false) {
         $arrSearchResult = NarroUtils::SearchDirectoryByName($this->strWorkingDirectory, $this->objLanguage->LanguageCode . '-' . $this->objLanguage->CountryCode);
     }
     if ($arrSearchResult == false) {
         $arrSearchResult = NarroUtils::SearchDirectoryByName($this->strWorkingDirectory, $this->objLanguage->LanguageCode . '_' . $this->objLanguage->CountryCode);
     }
     NarroUtils::RecursiveChmod($this->strWorkingDirectory);
     if (is_array($arrSearchResult) && count($arrSearchResult) == 1) {
         NarroLogger::LogWarn(sprintf('Path changed from "%s" to "%s" because a directory named "%s" was found deeper in the given path.', $this->strWorkingDirectory, $arrSearchResult[0], $this->objLanguage->LanguageCode));
         $this->strWorkingDirectory = $arrSearchResult[0];
     }
     if ($this->chkCopyFilesToDefaultDirectory->Checked) {
         if (file_exists(__IMPORT_PATH__ . '/' . $this->objProject->ProjectId . '/' . $this->objLanguage->LanguageCode)) {
             NarroUtils::RecursiveDelete(__IMPORT_PATH__ . '/' . $this->objProject->ProjectId . '/' . $this->objLanguage->LanguageCode . '/*');
         } else {
             mkdir(__IMPORT_PATH__ . '/' . $this->objProject->ProjectId . '/' . $this->objLanguage->LanguageCode, 0777);
         }
         NarroUtils::RecursiveCopy($this->strWorkingDirectory, __IMPORT_PATH__ . '/' . $this->objProject->ProjectId . '/' . $this->objLanguage->LanguageCode);
         NarroUtils::RecursiveChmod(__IMPORT_PATH__ . '/' . $this->objProject->ProjectId . '/' . $this->objLanguage->LanguageCode);
     }
     return $this->strWorkingDirectory;
 }
Ejemplo n.º 8
0
 public function btnReplace_Click()
 {
     if (!QApplication::HasPermissionForThisLang('Can approve')) {
         return false;
     }
     if ($this->txtReplace->Display == false) {
         $this->txtReplace->Display = true;
     } else {
         if ($this->txtSearch->Text == '') {
             return false;
         }
         if ($this->txtReplace->Text == '') {
             return false;
         }
         $strQuery = NarroContextInfo::GetQueryForConditions($objQueryBuilder, QQ::AndCondition($this->arrConditions), $this->arrClauses);
         $objDbResult = NarroContextInfo::GetDatabase()->Query($strQuery);
         if ($objDbResult) {
             $intReplaceCnt = 0;
             $intApproved = 0;
             $intTranslations = 0;
             $arrProcessed = array();
             while ($objDbRow = $objDbResult->GetNextRow()) {
                 $objContextInfo = NarroContextInfo::InstantiateDbRow($objDbRow, null, null, null, $objQueryBuilder->ColumnAliasArray);
                 if (in_array($objContextInfo->ContextInfoId, $arrProcessed)) {
                     continue;
                 } else {
                     $arrProcessed[] = $objContextInfo->ContextInfoId;
                 }
                 $objReplaceSuggestion = null;
                 if (preg_match("/^'.*'\$/", $this->txtSearch->Text)) {
                     $strToReplace = substr($this->txtSearch->Text, 1, -1);
                 } else {
                     $strToReplace = $this->txtSearch->Text;
                 }
                 if ($strToReplace == $objContextInfo->Context->Text->TextValue) {
                     $objReplaceSuggestion = NarroSuggestion::LoadByTextIdLanguageIdSuggestionValueMd5($objContextInfo->Context->TextId, QApplication::GetLanguageId(), md5($this->txtReplace->Text));
                     if (!$objReplaceSuggestion) {
                         $objSuggestion = new NarroSuggestion();
                         $objSuggestion->UserId = QApplication::GetUserId();
                         $objSuggestion->TextId = $objContextInfo->Context->TextId;
                         $objSuggestion->LanguageId = QApplication::GetLanguageId();
                         $objSuggestion->SuggestionValue = $this->txtReplace->Text;
                         $objSuggestion->HasComments = 0;
                         $objSuggestion->IsImported = 0;
                         $objSuggestion->Created = QDateTime::Now();
                         $objSuggestion->Modified = null;
                         $objSuggestion->Save();
                         $intTranslations++;
                         $objReplaceSuggestion = $objSuggestion;
                     }
                 }
                 if ($objReplaceSuggestion instanceof NarroSuggestion) {
                     $intReplaceCnt++;
                     if ($objContextInfo->ValidSuggestionId != $objReplaceSuggestion->SuggestionId || $this->chkApprove->Checked) {
                         if ($objContextInfo->ValidSuggestionId == null) {
                             $intApproved++;
                         }
                         $objContextInfo->ValidSuggestionId = $objReplaceSuggestion->SuggestionId;
                         $objContextInfo->ValidatorUserId = QApplication::GetUserId();
                         $objContextInfo->Modified = QDateTime::Now();
                         $objContextInfo->Save();
                     }
                 }
             }
             $this->dtrText->RemoveChildControls(true);
             $this->btnReplace->Refresh();
             QApplication::ExecuteJavaScript(sprintf('jQuery(\'#%s\').after(\'&nbsp;<small style="padding: 2px;" class="ui-state-highlight ui-corner-all"><span style="width:16px; height: 16px; display:inline-block" class="ui-icon ui-icon-info"></span>&nbsp;%s.</small>\')', $this->btnReplace->ControlId, sprintf(t('%d occurences of "%s" translated with "%s", out of which %d were already approved, %d translations added.'), $intReplaceCnt, $strToReplace, $this->txtReplace->Text, $intApproved, $intTranslations)));
         }
     }
 }
Ejemplo n.º 9
0
 /**
  * Returns a suggestion based on intExportedSuggestion value
  * @param NarroContextInfo $objContextInfo
  * @return string or false
  */
 public function GetExportedSuggestion(NarroContextInfo $objContextInfo)
 {
     switch ($this->intExportedSuggestion) {
         case 1:
             if ($objContextInfo->ValidSuggestionId) {
                 return $objContextInfo->ValidSuggestion->SuggestionValue;
             } else {
                 return false;
             }
             /**
              * If there is no approved suggestion, export the most voted one (minimum 1 vote required)
              */
         /**
          * If there is no approved suggestion, export the most voted one (minimum 1 vote required)
          */
         case 2:
             $objSuggestion = $this->GetMostVotedSuggestion($objContextInfo->ContextId, $objContextInfo->Context->TextId, $this->objUser->UserId);
             if ($objSuggestion instanceof NarroSuggestion) {
                 // NarroLogger::LogDebug(sprintf('Exporting most voted suggestion "%s" for "%s"', $objSuggestion->SuggestionValue, $objContextInfo->Context->Text->TextValue));
                 return $objSuggestion->SuggestionValue;
             } else {
                 return false;
             }
             /**
              * If there is no approved suggestion, export the most recent one added
              */
         /**
          * If there is no approved suggestion, export the most recent one added
          */
         case 3:
             $objSuggestion = $this->GetMostRecentSuggestion($objContextInfo->ContextId, $objContextInfo->Context->TextId, $this->objUser->UserId);
             if ($objSuggestion instanceof NarroSuggestion) {
                 // NarroLogger::LogDebug(sprintf('Exporting most recent suggestion "%s" for "%s"', $objSuggestion->SuggestionValue, $objContextInfo->Context->Text->TextValue));
                 return $objSuggestion->SuggestionValue;
             } else {
                 return false;
             }
             /**
              * If there is no approved suggestion, export the most voted one (minimum 1 vote required)
              * If there is no voted suggestion, export the most recent one
              */
         /**
          * If there is no approved suggestion, export the most voted one (minimum 1 vote required)
          * If there is no voted suggestion, export the most recent one
          */
         case 4:
             $objSuggestion = $this->GetMostVotedSuggestion($objContextInfo->ContextId, $objContextInfo->Context->TextId, $this->objUser->UserId);
             if ($objSuggestion instanceof NarroSuggestion) {
                 // NarroLogger::LogDebug(sprintf('Exporting most voted suggestion "%s" for "%s"', $objSuggestion->SuggestionValue, $objContextInfo->Context->Text->TextValue));
                 return $objSuggestion->SuggestionValue;
             } else {
                 $objSuggestion = $this->GetMostRecentSuggestion($objContextInfo->ContextId, $objContextInfo->Context->TextId, $this->objUser->UserId);
                 if ($objSuggestion instanceof NarroSuggestion) {
                     // NarroLogger::LogDebug(sprintf('Exporting most recent suggestion "%s" for "%s"', $objSuggestion->SuggestionValue, $objContextInfo->Context->Text->TextValue));
                     return $objSuggestion->SuggestionValue;
                 } else {
                     // NarroLogger::LogDebug(sprintf('No suggestion found for "%s"', $objContextInfo->Context->Text->TextValue));
                     return false;
                 }
             }
         case 5:
             $objSuggestion = $this->GetUserSuggestion($objContextInfo->ContextId, $objContextInfo->Context->TextId, QApplication::GetUserId());
             if ($objSuggestion instanceof NarroSuggestion) {
                 // NarroLogger::LogDebug(sprintf('Exporting %s\'s suggestion "%s" for "%s"', QApplication::$User->RealName, $objSuggestion->SuggestionValue, $objContextInfo->Context->Text->TextValue));
                 return $objSuggestion->SuggestionValue;
             } else {
                 return false;
             }
         case 6:
             $objSuggestion = $this->GetUserListSuggestion($objContextInfo->ContextId, $objContextInfo->Context->TextId, QApplication::GetUserId());
             if ($objSuggestion instanceof NarroSuggestion) {
                 // NarroLogger::LogDebug(sprintf('Exporting %s\'s suggestion "%s" for "%s"', QApplication::$User->RealName, $objSuggestion->SuggestionValue, $objContextInfo->Context->Text->TextValue));
                 return $objSuggestion->SuggestionValue;
             } else {
                 return false;
             }
         default:
             return false;
     }
 }
Ejemplo n.º 10
0
 public function ExportProject()
 {
     if ($this->objProject->ProjectName == 'Narro') {
         $this->strTemplatePath = __DOCROOT__ . __SUBDIRECTORY__ . '/locale/en-US';
         $this->strTranslationPath = __DOCROOT__ . __SUBDIRECTORY__ . '/locale/' . $this->objTargetLanguage->LanguageCode;
         if (!file_exists($this->strTranslationPath)) {
             mkdir($this->strTranslationPath, 0777);
         }
     }
     NarroLogger::LogInfo(sprintf(t('Starting export for the project %s using as template %s'), $this->objProject->ProjectName, $this->strTemplatePath));
     NarroLogger::LogInfo(sprintf('Active plugins: %s', join(',', QApplication::$PluginHandler->ActivePlugins)));
     NarroLogger::LogInfo(sprintf('Running export under user %s', $this->objUser->Username));
     $this->startTimer();
     QApplication::$PluginHandler->BeforeExportProject($this->objProject);
     if (file_exists($this->strTemplatePath) && is_dir($this->strTemplatePath)) {
         if ($this->ExportFromDirectory()) {
             $this->stopTimer();
             NarroLogger::LogInfo(sprintf('Export finished successfully in %d seconds.', NarroImportStatistics::$arrStatistics['End time'] - NarroImportStatistics::$arrStatistics['Start time']));
         } else {
             NarroLogger::LogError('Export failed.');
         }
     } else {
         throw new Exception(sprintf('Template path "%s" does not exist or it is not a directory', $this->strTemplatePath));
     }
     if (function_exists('popen') && function_exists('escapeshellarg') && function_exists('escapeshellcmd') && file_exists($this->strTemplatePath . '/../export.sh')) {
         NarroLogger::LogInfo('Found an after export script, trying to run it.');
         $fp = popen(sprintf('/bin/sh %s %s %d %s %d %d 2>&1', escapeshellarg(realpath($this->strTemplatePath . '/..') . '/export.sh'), escapeshellarg($this->objTargetLanguage->LanguageCode), $this->objTargetLanguage->LanguageId, escapeshellarg($this->objProject->ProjectName), $this->objProject->ProjectId, QApplication::GetUserId()), 'r');
         $strOutput = '';
         while (!feof($fp)) {
             $strOutput .= fread($fp, 1024);
         }
         if (pclose($fp)) {
             NarroLogger::LogError("After export script failed:\n" . $strOutput);
         } else {
             NarroLogger::LogInfo("After export script finished successfully:\n" . $strOutput);
         }
     }
     if ($this->objProject->ProjectName == 'Narro') {
         NarroUtils::Exec(sprintf('msgfmt -cv %s -o %s 2>&1', escapeshellarg($this->strTranslationPath . '/narro.po'), escapeshellarg($this->strTranslationPath . '/narro.mo')), $arrOutput, $arrError, $intRetVal);
         if ($intRetVal != 0) {
             NarroLogger::LogError("Exporting Narro's translation failed:\n" . $strOutput);
         } else {
             NarroLogger::LogInfo("Exported Narro's translation succesfully. Press Ctrl+F5 to reload and see it.");
         }
         if (file_exists($this->strTranslationPath . '/narro.mo')) {
             chmod($this->strTranslationPath . '/narro.mo', 0666);
         }
     }
     NarroProgress::ClearProgressFileName($this->objProject->ProjectId, 'export');
     QApplication::$PluginHandler->AfterExportProject($this->objProject);
     foreach (NarroImportStatistics::$arrStatistics as $strName => $strValue) {
         if ($strValue != 0) {
             NarroLogger::LogInfo(stripslashes($strName) . ': ' . $strValue);
         }
     }
     if (SERVER_INSTANCE == 'dev') {
         $strQueryData = '';
         $intTimeSpentOnQueries = 0;
         if (isset($GLOBALS['arrQueries']) && is_array($GLOBALS['arrQueries'])) {
             foreach ($GLOBALS['arrQueries'] as $arrQueryData) {
                 $strQueryData .= '"' . join('";"', $arrQueryData) . '"';
                 $intTimeSpentOnQueries += $arrQueryData[1];
             }
         }
         file_put_contents(__TMP_PATH__ . '/queries.csv', $strQueryData);
         chmod(__TMP_PATH__ . '/queries.csv', 0666);
         $strCacheData = '';
         if (isset($GLOBALS['arrCacheQueries']) && is_array($GLOBALS['arrCacheQueries'])) {
             foreach ($GLOBALS['arrCacheQueries'] as $arrCacheData) {
                 $strCacheData .= '"' . join('";"', $arrCacheData) . '"';
             }
         }
         file_put_contents(__TMP_PATH__ . '/cache.csv', $strCacheData);
         chmod(__TMP_PATH__ . '/cache.csv', 0666);
         NarroLogger::LogInfo(sprintf('%d queries in total, %d seconds spent on them', count(@$GLOBALS['arrQueries']), $intTimeSpentOnQueries));
         NarroLogger::LogInfo(sprintf('%d cache queries in total, %s seconds spent on them', count(@$GLOBALS['arrCacheQueries']), intval(@$GLOBALS['arrCacheQueriesSpent'])));
     }
 }
Ejemplo n.º 11
0
<?php

/**
 * Narro is an application that allows online software translation and maintenance.
 * Copyright (C) 2008-2011 Alexandru Szasz <*****@*****.**>
 * http://code.google.com/p/narro/
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any
 * later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
$this->objDefaultWaitIcon->Render();
if (QApplication::GetUserId() == NarroUser::ANONYMOUS_USER_ID) {
    echo sprintf(t('Translating in %s'), $_CONTROL->lstLanguage->ItemCount > 1 ? $_CONTROL->lstLanguage->Render(false) : $_CONTROL->lstLanguage->GetItem(0)->Name) . sprintf(', <a href="%s">' . t('sign in') . '</a>', 'login.php?l=' . QApplication::$TargetLanguage->LanguageCode);
} else {
    echo sprintf(t('Translating in %s as %s'), $_CONTROL->lstLanguage->ItemCount > 1 ? $_CONTROL->lstLanguage->Render(false) : $_CONTROL->lstLanguage->GetItem(0)->Name, sprintf(' <a title="%s" href="%s"><b>%s</b></a> ', t('Profile'), NarroLink::UserProfile(QApplication::$User->UserId), QApplication::$User->RealName ? QApplication::$User->RealName : QApplication::$User->RealName) . sprintf('<a title="%s" href="%s" style="vertical-align:middle"><img src="%s/settings.png" /></a>', t('Preferences'), NarroLink::UserPreferences(QApplication::GetUserId()), __NARRO_IMAGE_ASSETS__) . ' ' . $_CONTROL->btnLogout->Render(false));
}