public function dtgLanguage_Bind()
 {
     if ($this->txtSearch->Text != '') {
         $objSearchCondition = QQ::Like(QQN::NarroLanguage()->LanguageName, sprintf('%%%s%%', $this->txtSearch->Text));
     } else {
         $objSearchCondition = QQ::All();
     }
     switch ($this->lstFilter->SelectedValue) {
         /**
          * Only active
          */
         case 1:
             $objFilterCondition = QQ::AndCondition($objSearchCondition, QQ::Equal(QQN::NarroLanguage()->Active, 1));
             break;
             /**
              * 0 - show all
              */
         /**
          * 0 - show all
          */
         default:
             $objFilterCondition = $objSearchCondition;
     }
     // Because we want to enable pagination AND sorting, we need to setup the $objClauses array to send to LoadAll()
     // Remember!  We need to first set the TotalItemCount, which will affect the calcuation of LimitClause below
     $this->dtgLanguage->TotalItemCount = NarroLanguage::QueryCount($objFilterCondition);
     // Setup the $objClauses Array
     $objClauses = array(QQ::Expand(QQ::Virtual('last_translation', QQ::SubSql('SELECT MAX(created) FROM narro_suggestion WHERE language_id={1}', QQN::NarroLanguage()->LanguageId))), QQ::Count(QQN::NarroLanguage()->NarroSuggestionAsLanguage->SuggestionId, 'translations_count'), QQ::GroupBy(QQN::NarroLanguage()->LanguageId));
     // If a column is selected to be sorted, and if that column has a OrderByClause set on it, then let's add
     // the OrderByClause to the $objClauses array
     if ($objClause = $this->dtgLanguage->OrderByClause) {
         array_push($objClauses, $objClause);
     }
     // Add the LimitClause information, as well
     if ($objClause = $this->dtgLanguage->LimitClause) {
         array_push($objClauses, $objClause);
     }
     // Set the DataSource to be the array of all NarroLanguage objects, given the clauses above
     $this->dtgLanguage->DataSource = NarroLanguage::QueryArray($objFilterCondition, $objClauses);
     QApplication::ExecuteJavaScript('highlight_datagrid();');
 }
 private function CreateNarroTemplate($intProjectId)
 {
     $strPoFile = __DOCROOT__ . __SUBDIRECTORY__ . '/locale/' . $this->objSourceLanguage->LanguageCode . '/narro.po';
     NarroLogger::LogInfo(sprintf('Building a narro gettext template in %s.', $strPoFile));
     $arrPermissions = NarroPermission::QueryArray(QQ::All(), QQ::Clause(QQ::OrderBy(QQN::NarroPermission()->PermissionName)));
     NarroLogger::LogInfo(sprintf('Found %d permission names to localize.', count($arrPermissions)));
     $arrRoles = NarroRole::QueryArray(QQ::All(), QQ::Clause(QQ::OrderBy(QQN::NarroRole()->RoleName)));
     NarroLogger::LogInfo(sprintf('Found %d role names to localize.', count($arrRoles)));
     $allFiles = NarroUtils::ListDirectory(realpath(dirname(__FILE__) . '/../../..'), null, '/.*\\/drafts\\/.*|.*\\/data\\/.*|.*\\/examples\\/.*|.*\\/qcubed_generated\\/.*/');
     NarroLogger::LogInfo(sprintf('Found %d php files to search for localizable messages.', count($allFiles)));
     foreach ($allFiles as $strFileName) {
         if (pathinfo($strFileName, PATHINFO_EXTENSION) != 'php') {
             continue;
         }
         $strFile = file_get_contents($strFileName);
         $strShortPath = str_ireplace(realpath(__DOCROOT__ . __SUBDIRECTORY__) . '/', '', $strFileName);
         if (strpos($strShortPath, 'data') === 0) {
             continue;
         }
         if (strpos($strShortPath, 'includes/qcubed_generated') === 0) {
             continue;
         }
         $strFile = str_replace("\\'", "&&&escapedsimplequote&&&", $strFile);
         $strFile = str_replace('\\"', "&&&escapeddoublequote&&&", $strFile);
         if ($strFile) {
             preg_match_all('/([^a-zA-Z]t|NarroApp::Translate|QApplication::Translate|__t)\\s*\\(\\s*[\']([^\']{2,})[\']\\s*\\)/', $strFile, $arrMatches);
             if (isset($arrMatches[2])) {
                 foreach ($arrMatches[2] as $intMatchNo => $strText) {
                     if (trim($strText) != '') {
                         $strText = str_replace(array("&&&escapedsimplequote&&&", "&&&escapeddoublequote&&&"), array("'", '\\"'), $strText);
                         $arrMessages[md5($strText)]['text'] = $strText;
                         $arrMessages[md5($strText)]['files'][$strShortPath] = $strShortPath;
                         $strSearchText = str_replace(array("&&&escapedsimplequote&&&", "&&&escapeddoublequote&&&"), array("'", '\\"'), $arrMatches[0][$intMatchNo]);
                         preg_match_all('/^.*' . preg_quote($strSearchText, '/') . '.*$/m', $strFile, $arrFullMatches);
                         $arrMessages[md5($strText)]['context'] = '#. ';
                         foreach ($arrFullMatches[0] as $strFullMatch) {
                             if (trim($strFullMatch)) {
                                 $arrMessages[md5($strText)]['context'] .= trim($strFullMatch) . "\n";
                             }
                         }
                     }
                 }
             }
             preg_match_all('/([^a-zA-Z]t|NarroApp::Translate|QApplication::Translate|__t)\\s*\\(\\s*[\\"]([^\\"]{2,})[\\"]\\s*\\)/', $strFile, $arrMatches);
             if (isset($arrMatches[2])) {
                 foreach ($arrMatches[2] as $intMatchNo => $strText) {
                     if (trim($strText) != '') {
                         $strText = str_replace(array("&&&escapedsimplequote&&&", "&&&escapeddoublequote&&&"), array("'", '\\"'), $strText);
                         $arrMessages[md5($strText)]['text'] = $strText;
                         $arrMessages[md5($strText)]['files'][$strShortPath] = $strShortPath;
                         $strSearchText = str_replace(array("&&&escapedsimplequote&&&", "&&&escapeddoublequote&&&"), array("'", '\\"'), $arrMatches[0][$intMatchNo]);
                         preg_match_all('/^.*' . preg_quote($strSearchText, '/') . '.*$/m', $strFile, $arrFullMatches);
                         $arrMessages[md5($strText)]['context'] = '#. ';
                         foreach ($arrFullMatches[0] as $strFullMatch) {
                             if (trim($strFullMatch)) {
                                 $arrMessages[md5($strText)]['context'] .= trim($strFullMatch) . "\n";
                             }
                         }
                     }
                 }
             }
             preg_match_all('/([^a-zA-Z]t|NarroApp::Translate|QApplication::Translate|__t)\\s*\\(\\s*[\']([^\']{2,})[\']\\s*,\\s*[\']([^\']{2,})[\']\\s*,\\s*([^\\)]+)\\s*\\)/', $strFile, $arrMatches);
             if (isset($arrMatches[2])) {
                 foreach ($arrMatches[2] as $intMatchNo => $strText) {
                     if (trim($strText) != '') {
                         $strText = str_replace(array("&&&escapedsimplequote&&&", "&&&escapeddoublequote&&&"), array("'", '\\"'), $strText);
                         $arrMessages[md5($strText)]['text'] = $strText;
                         $arrMessages[md5($strText)]['files'][$strShortPath] = $strShortPath;
                         $arrMessages[md5($strText)]['plural'] = $arrMatches[3][$intMatchNo];
                         $strSearchText = str_replace(array("&&&escapedsimplequote&&&", "&&&escapeddoublequote&&&"), array("'", '\\"'), $arrMatches[0][$intMatchNo]);
                         preg_match_all('/^.*' . preg_quote($strSearchText, '/') . '.*$/m', $strFile, $arrFullMatches);
                         $arrMessages[md5($strText)]['context'] = '#. ';
                         foreach ($arrFullMatches[0] as $strFullMatch) {
                             if (trim($strFullMatch)) {
                                 $arrMessages[md5($strText)]['context'] .= trim($strFullMatch) . "\n";
                             }
                         }
                     }
                 }
             }
             preg_match_all('/([^a-zA-Z]t|NarroApp::Translate|QApplication::Translate|__t)\\s*\\(\\s*[\\"]([^\\"]{2,})[\\"]\\s*,\\s*[\\"]([^\\"]{2,})[\\"]\\s*,\\s*([^\\)]+)\\s*\\)/', $strFile, $arrMatches);
             if (isset($arrMatches[2])) {
                 foreach ($arrMatches[2] as $intMatchNo => $strText) {
                     if (trim($strText) != '') {
                         $strText = str_replace(array("&&&escapedsimplequote&&&", "&&&escapeddoublequote&&&"), array("'", '\\"'), $strText);
                         $arrMessages[md5($strText)]['text'] = $strText;
                         $arrMessages[md5($strText)]['files'][$strShortPath] = $strShortPath;
                         $arrMessages[md5($strText)]['plural'] = $arrMatches[3][$intMatchNo];
                         $strSearchText = str_replace(array("&&&escapedsimplequote&&&", "&&&escapeddoublequote&&&"), array("'", '\\"'), $arrMatches[0][$intMatchNo]);
                         preg_match_all('/^.*' . preg_quote($strSearchText, '/') . '.*$/m', $strFile, $arrFullMatches);
                         $arrMessages[md5($strText)]['context'] = '#. ';
                         foreach ($arrFullMatches[0] as $strFullMatch) {
                             if (trim($strFullMatch)) {
                                 $arrMessages[md5($strText)]['context'] .= trim($strFullMatch) . "\n";
                             }
                         }
                     }
                 }
             }
             preg_match_all('/NarroApp::RegisterPreference\\(\\s*\'([^\']+)\'\\s*,\\s*\'[^\']+\'\\s*,\\s*\'([^\']+)\'\\s*,\\s*/', $strFile, $arrMatches);
             if (isset($arrMatches[1])) {
                 foreach ($arrMatches[1] as $intMatchNo => $strText) {
                     if (trim($strText) != '') {
                         $strText = str_replace(array("&&&escapedsimplequote&&&", "&&&escapeddoublequote&&&"), array("'", '\\"'), $strText);
                         $arrMessages[md5($strText)]['text'] = $strText;
                         $arrMessages[md5($strText)]['files'][$strShortPath] = $strShortPath;
                         $strSearchText = $arrMatches[0][$intMatchNo];
                         preg_match_all('/^.*' . preg_quote($strSearchText, '/') . '.*$/m', $strFile, $arrFullMatches);
                         $arrMessages[md5($strText)]['context'] = "#. Preference name\n";
                         foreach ($arrFullMatches[0] as $strLine) {
                             if (isset($strLine) && trim($strLine)) {
                                 $arrMessages[md5($strText)]['context'] .= trim($strLine) . "\n";
                             }
                         }
                     }
                 }
                 foreach ($arrMatches[2] as $intMatchNo => $strText) {
                     if (trim($strText) != '') {
                         $strText = str_replace(array("&&&escapedsimplequote&&&", "&&&escapeddoublequote&&&"), array("'", '\\"'), $strText);
                         $arrMessages[md5($strText)]['text'] = $strText;
                         $arrMessages[md5($strText)]['files'][$strShortPath] = $strShortPath;
                         $strSearchText = $arrMatches[0][$intMatchNo];
                         preg_match_all('/^.*' . preg_quote($strSearchText, '/') . '.*$/m', $strFile, $arrFullMatches);
                         $arrMessages[md5($strText)]['context'] = "#. Preference description\n";
                         foreach ($arrFullMatches[0] as $strLine) {
                             if (isset($strLine) && trim($strLine)) {
                                 $arrMessages[md5($strText)]['context'] .= trim($strLine) . "\n";
                             }
                         }
                     }
                 }
             }
             if (preg_match_all('/t\\(\\$[a-zA-Z]+\\-\\>LanguageName/', $strFile, $arrMatches)) {
                 if (!isset($arrLanguages)) {
                     $arrLanguages = NarroLanguage::QueryArray(QQ::All(), QQ::Clause(QQ::OrderBy(QQN::NarroLanguage()->LanguageName)));
                 }
                 $strLangContext = '#. ';
                 foreach ($arrMatches as $intMatchNo => $arrVal) {
                     $strSearchText = $arrMatches[0][$intMatchNo];
                     preg_match_all('/^.*' . preg_quote($strSearchText, '/') . '.*$/m', $strFile, $arrFullMatches);
                     foreach ($arrFullMatches[0] as $strLine) {
                         if (isset($strLine) && trim($strLine)) {
                             $strLangContext .= trim($strLine) . "\n";
                         }
                     }
                 }
                 if (is_array($arrLanguages)) {
                     foreach ($arrLanguages as $objLanguage) {
                         $arrMessages[md5($objLanguage->LanguageName)]['text'] = $objLanguage->LanguageName;
                         $arrMessages[md5($objLanguage->LanguageName)]['files'][$strShortPath] = $strShortPath;
                         $arrMessages[md5($objLanguage->LanguageName)]['context'] = $strLangContext;
                     }
                 }
             }
             if (preg_match_all('/t\\(\\$[a-zA-Z]+\\-\\>RoleName/', $strFile, $arrMatches)) {
                 $strLangContext = '#. ';
                 foreach ($arrMatches as $intMatchNo => $arrVal) {
                     $strSearchText = $arrMatches[0][$intMatchNo];
                     preg_match_all('/^.*' . preg_quote($strSearchText, '/') . '.*$/m', $strFile, $arrFullMatches);
                     foreach ($arrFullMatches[0] as $strLine) {
                         if (isset($strLine) && trim($strLine)) {
                             $strLangContext .= trim($strLine) . "\n";
                         }
                     }
                 }
                 if (is_array($arrRoles)) {
                     foreach ($arrRoles as $objRole) {
                         $arrMessages[md5($objRole->RoleName)]['text'] = $objRole->RoleName;
                         $arrMessages[md5($objRole->RoleName)]['files'][$strShortPath] = $strShortPath;
                         $arrMessages[md5($objRole->RoleName)]['context'] = $strLangContext;
                     }
                 }
             }
             if (preg_match_all('/t\\(\\$[a-zA-Z]+\\-\\>PermissionName/', $strFile, $arrMatches)) {
                 $strLangContext = '#. ';
                 foreach ($arrMatches as $intMatchNo => $arrVal) {
                     $strSearchText = $arrMatches[0][$intMatchNo];
                     preg_match_all('/^.*' . preg_quote($strSearchText, '/') . '.*$/m', $strFile, $arrFullMatches);
                     foreach ($arrFullMatches[0] as $strLine) {
                         if (isset($strLine) && trim($strLine)) {
                             $strLangContext .= trim($strLine) . "\n";
                         }
                     }
                 }
                 if (is_array($arrPermissions)) {
                     foreach ($arrPermissions as $objPermission) {
                         $arrMessages[md5($objPermission->PermissionName)]['text'] = $objPermission->PermissionName;
                         $arrMessages[md5($objPermission->PermissionName)]['files'][$strShortPath] = $strShortPath;
                         $arrMessages[md5($objPermission->PermissionName)]['context'] = $strLangContext;
                     }
                 }
             }
         }
     }
     $strPoHeader = '#, fuzzy' . "\n" . 'msgid ""' . "\n" . 'msgstr ""' . "\n" . '"Project-Id-Version: Narro ' . NARRO_VERSION . "\n" . '"Report-Msgid-Bugs-To: alexxed@gmail.com\\n"' . "\n" . '"POT-Creation-Date: ' . date('Y-d-m H:iO') . '\\n"' . "\n" . '"PO-Revision-Date: ' . date('Y-d-m H:iO') . '\\n"' . "\n" . '"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"' . "\n" . '"Language-Team: LANGUAGE <*****@*****.**>\\n"' . "\n" . '"MIME-Version: 1.0\\n"' . "\n" . '"Content-Type: text/plain; charset=UTF-8\\n"' . "\n" . '"Content-Transfer-Encoding: 8bit\\n"' . "\n" . '"Plural-Forms: nplurals=2; plural=n != 1;\\n"' . "\n" . '"X-Generator: Narro\\n"' . "\n";
     $hndFile = fopen($strPoFile, 'w');
     if (!$hndFile) {
         NarroLogger::LogError(sprintf('Error while opening the po file "%s" for writing.', $strPoFile));
     }
     fputs($hndFile, $strPoHeader);
     // Obtain a list of columns
     foreach ($arrMessages as $key => $row) {
         $texts[$key] = $row['text'];
     }
     //array_multisort($texts, SORT_ASC, SORT_STRING, $arrMessages);
     foreach ($arrMessages as $intKey => $arrMsgData) {
         if (isset($arrMsgData['plural'])) {
             fputs($hndFile, sprintf("#: %s\nmsgid \"%s\"\nmsgid_plural \"%s\"\nmsgstr[0] \"\"\nmsgstr[1] \"\"\n\n", join(' ', array_values($arrMsgData['files'])), str_replace(array('"', "\n"), array('\\"', '\\n'), $arrMsgData['text']), str_replace(array('"', "\n"), array('\\"', '\\n'), $arrMsgData['plural'])));
         } else {
             if (!isset($arrMsgData['files'])) {
                 print_r($arrMsgData);
             } else {
                 fputs($hndFile, sprintf("%s\n#: %s\nmsgid \"%s\"\nmsgstr \"\"\n\n", isset($arrMsgData['context']) ? str_replace("\n", "\n#. ", trim($arrMsgData['context'])) . '' : '', join(' ', array_values($arrMsgData['files'])), str_replace(array('"', "\n"), array('\\"', '\\n'), $arrMsgData['text'])));
             }
         }
     }
     fclose($hndFile);
     NarroUtils::Chmod($strPoFile, 0666);
     NarroLogger::LogInfo('Wrote a new Narro template file in ' . $strPoFile);
 }
Example #3
0
 /**
  * Load all NarroLanguages
  * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  * @return NarroLanguage[]
  */
 public static function LoadAll($objOptionalClauses = null)
 {
     if (func_num_args() > 1) {
         throw new QCallerException("LoadAll must be called with an array of optional clauses as a single argument");
     }
     // Call NarroLanguage::QueryArray to perform the LoadAll query
     try {
         return NarroLanguage::QueryArray(QQ::All(), $objOptionalClauses);
     } catch (QCallerException $objExc) {
         $objExc->IncrementOffset();
         throw $objExc;
     }
 }
 /**
  * Default / simple DataBinder for this Meta DataGrid.  This can easily be overridden
  * by calling SetDataBinder() on this DataGrid with another DataBinder of your choice.
  *
  * If a paginator is set on this DataBinder, it will use it.  If not, then no pagination will be used.
  * It will also perform any sorting (if applicable).
  */
 public function MetaDataBinder()
 {
     $objConditions = $this->Conditions;
     if (null !== $this->conAdditionalConditions) {
         $objConditions = QQ::AndCondition($this->conAdditionalConditions, $objConditions);
     }
     // Setup the $objClauses Array
     $objClauses = array();
     if (null !== $this->clsAdditionalClauses) {
         $objClauses = $this->clsAdditionalClauses;
     }
     // Remember!  We need to first set the TotalItemCount, which will affect the calcuation of LimitClause below
     if ($this->Paginator) {
         $this->TotalItemCount = NarroLanguage::QueryCount($objConditions);
     }
     // If a column is selected to be sorted, and if that column has a OrderByClause set on it, then let's add
     // the OrderByClause to the $objClauses array
     if ($objClause = $this->OrderByClause) {
         array_push($objClauses, $objClause);
     }
     // Add the LimitClause information, as well
     if ($objClause = $this->LimitClause) {
         array_push($objClauses, $objClause);
     }
     // Set the DataSource to be a Query result from NarroLanguage, given the clauses above
     $this->DataSource = NarroLanguage::QueryArray($objConditions, $objClauses);
 }
Example #5
0
 protected function GetControlHtml()
 {
     $strOutput = $this->lblMessage->Render(false) . '<br /><table style="border: 1px solid #DDDDDD" cellpadding="4" cellspacing="0" width="100%">';
     foreach (NarroUser::$AvailablePreferences as $strName => $arrPref) {
         switch ($arrPref['type']) {
             case 'number':
                 $txtNumber = new QIntegerTextBox($this);
                 $txtNumber->Name = $strName;
                 $txtNumber->Minimum = 5;
                 $txtNumber->Maximum = 100;
                 $txtNumber->MaxLength = 3;
                 $txtNumber->Width = 50;
                 $txtNumber->Text = $this->objUser->GetPreferenceValueByName($strName);
                 $strOutput .= sprintf('<tr class="datagrid_row datagrid_even" style="height:40px"><td>%s:</td><td>%s</td><td style="font-size:-1">%s</td></tr>', t($strName), $txtNumber->RenderWithError(false), t($arrPref['description']));
                 $this->arrControls[$strName] = $txtNumber;
                 break;
             case 'text':
                 $txtTextPref = new QTextBox($this);
                 $txtTextPref->Name = $strName;
                 $txtTextPref->Text = $this->objUser->GetPreferenceValueByName($strName);
                 if ($strName == 'Special characters') {
                     $strSelect = sprintf('<select onchange="document.getElementById(\'%s\').value+=this.options[this.selectedIndex].value;">', $txtTextPref->ControlId);
                     foreach (NarroDiacriticsPanel::$arrEntities as $strEntityName => $strEntityChar) {
                         $strSelect .= sprintf('<option value=" %s">%s (%s)', $strEntityName, $strEntityChar, $strEntityName);
                     }
                     $strSelect .= '</select>';
                     $arrPref['description'] = t($arrPref['description']) . $strSelect;
                     $txtTextPref->Width = 400;
                 } elseif ($strName == 'Other languages') {
                     $strSelect = sprintf('<select onchange="document.getElementById(\'%s\').value+= \' \' + this.options[this.selectedIndex].value;">', $txtTextPref->ControlId);
                     foreach (NarroLanguage::QueryArray(QQ::All(), QQ::Clause(QQ::OrderBy(QQN::NarroLanguage()->LanguageName))) as $objLanguage) {
                         $strSelect .= sprintf('<option value="%s">%s (%s)', $objLanguage->LanguageCode, t($objLanguage->LanguageName), $objLanguage->LanguageCode);
                     }
                     $strSelect .= '</select>';
                     $arrPref['description'] = t($arrPref['description']) . $strSelect;
                     $txtTextPref->Width = 400;
                 }
                 $strOutput .= sprintf('<tr class="datagrid_row datagrid_even" style="height:40px"><td>%s:</td><td>%s</td><td style="font-size:-1">%s</td></tr>', t($strName), $txtTextPref->RenderWithError(false), $arrPref['description']);
                 $this->arrControls[$strName] = $txtTextPref;
                 break;
             case 'option':
                 $lstOption = new QListBox($this);
                 $lstOption->Name = $strName;
                 if ($strName == 'Language') {
                     $arrLanguages = NarroLanguage::LoadAllActive(QQ::Clause(QQ::OrderBy(QQN::NarroLanguage()->LanguageName)));
                     foreach ($arrLanguages as $objLanguage) {
                         $lstOption->AddItem(t($objLanguage->LanguageName), $objLanguage->LanguageCode, $objLanguage->LanguageCode == $this->objUser->GetPreferenceValueByName($strName));
                     }
                 } elseif ($strName == 'Application language') {
                     $arrLanguages = NarroLanguage::QueryArray(QQ::All(), QQ::Clause(QQ::OrderBy(QQN::NarroLanguage()->LanguageName)));
                     foreach ($arrLanguages as $objLanguage) {
                         $lstOption->AddItem(t($objLanguage->LanguageName), $objLanguage->LanguageCode, $objLanguage->LanguageCode == $this->objUser->GetPreferenceValueByName($strName));
                     }
                 } else {
                     foreach ($arrPref['values'] as $strValue) {
                         $lstOption->AddItem(t($strValue), $strValue, $strValue == $this->objUser->GetPreferenceValueByName($strName));
                     }
                 }
                 $strOutput .= sprintf('<tr class="datagrid_row datagrid_even" style="height:40px"><td>%s:</td><td>%s</td><td style="font-size:-1">%s</td></tr>', t($strName), $lstOption->RenderWithError(false), t($arrPref['description']));
                 $this->arrControls[$strName] = $lstOption;
                 break;
         }
     }
     $strOutput .= '</table><br />';
     $strOutput .= $this->btnCancel->Render(false) . ' ' . $this->btnSave->Render(false);
     if ($this->txtPreviousUrl) {
         $strOutput .= ' ' . sprintf(t('Click <a href="%s">here</a> to return to the page you were.'), $this->txtPreviousUrl);
     }
     $this->strText = $strOutput;
     return parent::GetControlHtml();
 }