public function Translate($Code, $Default = False) { $this->EventArguments['Code'] = $Code; $this->FireEvent('BeforeTranslate'); $Result = parent::Translate($Code, $Default); return $Result; }
/** * * * @param $info */ protected function calculateLocaleInfo(&$info) { $canonicalLocale = Gdn_Locale::canonicalize($info['Locale']); if ($canonicalLocale !== $info['Locale']) { $info['LocaleRaw'] = $info['Locale']; $info['Locale'] = $canonicalLocale; } }
public function Translate($Code, $Default = FALSE) { // Figure out where the translation was called. // $Trace = debug_backtrace(); // $LastIndex = NULL; // foreach ($Trace as $Index => $Item) { // if (in_array(strtolower($Item['function']), array('t', 'translate'))) { // $LastIndex = $Index; // continue; // } else { // break; // } // } // if (isset($Trace[$LastIndex])) { // $TraceItem = $Trace[$LastIndex]; // } $Result = parent::Translate($Code, $Default); if ($Code) { $this->_CapturedDefinitions[$Code] = $Result; } return $Result; }
public function Translate($Code, $Default = FALSE) { $Result = parent::Translate($Code, $Default); if (!$Code || substr($Code, 0, 1) == '@') { return $Result; } $Prefix = self::GuessPrefix(); if (!$Prefix) { return $Result; } if ($Prefix == 'unknown') { decho($Code); decho(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)); die; } if (Gdn_Theme::InSection('Dashboard')) { $Prefix = 'dash_' . $Prefix; } else { $Prefix = 'site_' . $Prefix; } $this->_CapturedDefinitions[$Prefix][$Code] = $Result; return $Result; }
} $Construct->table('Log')->primaryKey('LogID')->column('Operation', array('Delete', 'Edit', 'Spam', 'Moderate', 'Pending', 'Ban', 'Error'), false, 'index')->column('RecordType', array('Discussion', 'Comment', 'User', 'Registration', 'Activity', 'ActivityComment', 'Configuration', 'Group'), false, 'index')->column('TransactionLogID', 'int', null)->column('RecordID', 'int', null, 'index')->column('RecordUserID', 'int', null, 'index')->column('RecordDate', 'datetime')->column('RecordIPAddress', 'varchar(15)', null, 'index')->column('InsertUserID', 'int')->column('DateInserted', 'datetime', false, 'index')->column('InsertIPAddress', 'varchar(15)', null)->column('OtherUserIDs', 'varchar(255)', null)->column('DateUpdated', 'datetime', null)->column('ParentRecordID', 'int', null, 'index')->column('CategoryID', 'int', null, 'key')->column('Data', 'mediumtext', null)->column('CountGroup', 'int', null)->engine('InnoDB')->set($Explicit, $Drop); $Construct->table('Regarding')->primaryKey('RegardingID')->column('Type', 'varchar(100)', false, 'key')->column('InsertUserID', 'int', false)->column('DateInserted', 'datetime', false)->column('ForeignType', 'varchar(32)', false)->column('ForeignID', 'int(11)', false)->column('OriginalContent', 'text', true)->column('ParentType', 'varchar(32)', true)->column('ParentID', 'int(11)', true)->column('ForeignURL', 'varchar(255)', true)->column('Comment', 'text', false)->column('Reports', 'int(11)', true)->engine('InnoDB')->set($Explicit, $Drop); $Construct->table('Ban')->primaryKey('BanID')->column('BanType', array('IPAddress', 'Name', 'Email'), false, 'unique')->column('BanValue', 'varchar(50)', false, 'unique')->column('Notes', 'varchar(255)', null)->column('CountUsers', 'uint', 0)->column('CountBlockedRegistrations', 'uint', 0)->column('InsertUserID', 'int')->column('DateInserted', 'datetime')->column('InsertIPAddress', 'varchar(15)', true)->column('UpdateUserID', 'int', true)->column('DateUpdated', 'datetime', true)->column('UpdateIPAddress', 'varchar(15)', true)->engine('InnoDB')->set($Explicit, $Drop); $Construct->table('Spammer')->column('UserID', 'int', false, 'primary')->column('CountSpam', 'usmallint', 0)->column('CountDeletedSpam', 'usmallint', 0)->set($Explicit, $Drop); $Construct->table('Media')->primaryKey('MediaID')->column('Name', 'varchar(255)')->column('Path', 'varchar(255)')->column('Type', 'varchar(128)')->column('Size', 'int(11)')->column('InsertUserID', 'int(11)')->column('DateInserted', 'datetime')->column('ForeignID', 'int(11)', true, 'index.Foreign')->column('ForeignTable', 'varchar(24)', true, 'index.Foreign')->column('ImageWidth', 'usmallint', null)->column('ImageHeight', 'usmallint', null)->column('ThumbWidth', 'usmallint', null)->column('ThumbHeight', 'usmallint', null)->column('ThumbPath', 'varchar(255)', null)->set(false, false); // Merge backup. $Construct->table('UserMerge')->primaryKey('MergeID')->column('OldUserID', 'int', false, 'key')->column('NewUserID', 'int', false, 'key')->column('DateInserted', 'datetime')->column('InsertUserID', 'int')->column('DateUpdated', 'datetime', true)->column('UpdateUserID', 'int', true)->column('Attributes', 'text', true)->set(); $Construct->table('UserMergeItem')->column('MergeID', 'int', false, 'key')->column('Table', 'varchar(30)')->column('Column', 'varchar(30)')->column('RecordID', 'int')->column('OldUserID', 'int')->column('NewUserID', 'int')->set(); $Construct->table('Attachment')->primaryKey('AttachmentID')->column('Type', 'varchar(64)')->column('ForeignID', 'varchar(50)', false, 'index')->column('ForeignUserID', 'int', false, 'key')->column('Source', 'varchar(64)')->column('SourceID', 'varchar(32)')->column('SourceURL', 'varchar(255)')->column('Attributes', 'text', true)->column('DateInserted', 'datetime')->column('InsertUserID', 'int', false, 'key')->column('InsertIPAddress', 'varchar(64)')->column('DateUpdated', 'datetime', true)->column('UpdateUserID', 'int', true)->column('UpdateIPAddress', 'varchar(15)', true)->set($Explicit, $Drop); // Save the current input formatter to the user's config. // This will allow us to change the default later and grandfather existing forums in. saveToConfig('Garden.InputFormatter', c('Garden.InputFormatter')); // Make sure the default locale is in its canonical form. $currentLocale = c('Garden.Locale'); $canonicalLocale = Gdn_Locale::canonicalize($currentLocale); if ($currentLocale !== $canonicalLocale) { saveToConfig('Garden.Locale', $canonicalLocale); } // We need to undo cleditor's bad behavior for our reformed users. // If you still need to manipulate this, do it in memory instead (SAVE = false). if (!c('Garden.Html.SafeStyles')) { removeFromConfig('Garden.Html.SafeStyles'); } // Make sure the smarty folders exist. if (!file_exists(PATH_CACHE . '/Smarty')) { @mkdir(PATH_CACHE . '/Smarty'); } if (!file_exists(PATH_CACHE . '/Smarty/cache')) { @mkdir(PATH_CACHE . '/Smarty/cache'); }
/** * Manage list of locales. * * @since 2.0.0 * @access public * @param string $Op 'enable' or 'disable' * @param string $LocaleKey Unique ID of locale to be modified. * @param string $TransientKey Security token. */ public function locales($Op = null, $LocaleKey = null, $TransientKey = null) { $this->permission('Garden.Settings.Manage'); $this->title(t('Locales')); $this->addSideMenu('dashboard/settings/locales'); $this->addJsFile('addons.js'); $LocaleModel = new LocaleModel(); // Get the available locale packs. $AvailableLocales = $LocaleModel->availableLocalePacks(); // Get the enabled locale packs. $EnabledLocales = $LocaleModel->enabledLocalePacks(); // Check to enable/disable a locale. if ($TransientKey && Gdn::session()->validateTransientKey($TransientKey) || $this->Form->authenticatedPostBack()) { if ($Op) { $Refresh = false; switch (strtolower($Op)) { case 'enable': $Locale = val($LocaleKey, $AvailableLocales); if (!is_array($Locale)) { $this->Form->addError('@' . sprintf(t('The %s locale pack does not exist.'), htmlspecialchars($LocaleKey)), 'LocaleKey'); } elseif (!isset($Locale['Locale'])) { $this->Form->addError('ValidateRequired', 'Locale'); } else { saveToConfig("EnabledLocales.{$LocaleKey}", $Locale['Locale']); $EnabledLocales[$LocaleKey] = $Locale['Locale']; $Refresh = true; } break; case 'disable': RemoveFromConfig("EnabledLocales.{$LocaleKey}"); unset($EnabledLocales[$LocaleKey]); $Refresh = true; break; } // Set default locale field if just doing enable/disable $this->Form->setValue('Locale', Gdn_Locale::canonicalize(c('Garden.Locale', 'en'))); } elseif ($this->Form->authenticatedPostBack()) { // Save the default locale. saveToConfig('Garden.Locale', $this->Form->getFormValue('Locale')); $Refresh = true; $this->informMessage(t("Your changes have been saved.")); } if ($Refresh) { Gdn::locale()->refresh(); redirect('/settings/locales'); } } elseif (!$this->Form->isPostBack()) { $this->Form->setValue('Locale', Gdn_Locale::canonicalize(c('Garden.Locale', 'en'))); } // Check for the default locale warning. $DefaultLocale = Gdn_Locale::canonicalize(c('Garden.Locale')); if ($DefaultLocale !== 'en') { $LocaleFound = false; $MatchingLocales = array(); foreach ($AvailableLocales as $Key => $LocaleInfo) { $Locale = val('Locale', $LocaleInfo); if ($Locale == $DefaultLocale) { $MatchingLocales[] = val('Name', $LocaleInfo, $Key); } if (val($Key, $EnabledLocales) == $DefaultLocale) { $LocaleFound = true; } } $this->setData('DefaultLocale', $DefaultLocale); $this->setData('DefaultLocaleWarning', !$LocaleFound); $this->setData('MatchingLocalePacks', htmlspecialchars(implode(', ', $MatchingLocales))); } $this->setData('AvailableLocales', $AvailableLocales); $this->setData('EnabledLocales', $EnabledLocales); $this->setData('Locales', $LocaleModel->availableLocales()); $this->render(); }
/** * Confirm selected locale is valid and available. * * @param string $Locale Locale code. * @return string Returns the canonical version of the locale on success or an empty string otherwise. */ protected function ValidateLocale($Locale) { $canonicalLocale = Gdn_Locale::Canonicalize($Locale); $locales = static::EnabledLocales(); $result = isset($locales[$canonicalLocale]) ? $canonicalLocale : ''; return $result; }
/** * Manage list of locales. * * @since 2.0.0 * @access public * @param string $Op 'enable' or 'disable' * @param string $LocaleKey Unique ID of locale to be modified. * @param string $TransientKey Security token. */ public function locales($Op = null, $LocaleKey = null) { $this->permission('Garden.Settings.Manage'); $this->title(t('Locales')); $this->setHighlightRoute('dashboard/settings/locales'); $this->addJsFile('addons.js'); $LocaleModel = new LocaleModel(); // Get the available locale packs. $AvailableLocales = $LocaleModel->availableLocalePacks(); // Get the enabled locale packs. $EnabledLocales = $LocaleModel->enabledLocalePacks(); // Check to enable/disable a locale. if ($this->Form->authenticatedPostBack() && !$Op) { // Save the default locale. saveToConfig('Garden.Locale', $this->Form->getFormValue('Locale')); $this->informMessage(t("Your changes have been saved.")); Gdn::locale()->refresh(); redirect('/settings/locales'); } else { $this->Form->setValue('Locale', Gdn_Locale::canonicalize(c('Garden.Locale', 'en'))); } if ($Op) { switch (strtolower($Op)) { case 'enable': $this->enableLocale($LocaleKey, val($LocaleKey, $AvailableLocales), $EnabledLocales); break; case 'disable': $this->disableLocale($LocaleKey, val($LocaleKey, $AvailableLocales), $EnabledLocales); } } // Check for the default locale warning. $DefaultLocale = Gdn_Locale::canonicalize(c('Garden.Locale')); if ($DefaultLocale !== 'en') { $LocaleFound = false; $MatchingLocales = array(); foreach ($AvailableLocales as $Key => $LocaleInfo) { $Locale = val('Locale', $LocaleInfo); if ($Locale == $DefaultLocale) { $MatchingLocales[] = val('Name', $LocaleInfo, $Key); } if (val($Key, $EnabledLocales) == $DefaultLocale) { $LocaleFound = true; } } $this->setData('DefaultLocale', $DefaultLocale); $this->setData('DefaultLocaleWarning', !$LocaleFound); $this->setData('MatchingLocalePacks', htmlspecialchars(implode(', ', $MatchingLocales))); } // Remove all hidden locales, unless they are enabled. $AvailableLocales = array_filter($AvailableLocales, function ($locale) use($EnabledLocales) { return !val('Hidden', $locale) || isset($EnabledLocales[val('Index', $locale)]); }); $this->setData('AvailableLocales', $AvailableLocales); $this->setData('EnabledLocales', $EnabledLocales); $this->setData('Locales', $LocaleModel->availableLocales()); $this->render(); }