本文整理汇总了PHP中Translatable::enable_locale_filter方法的典型用法代码示例。如果您正苦于以下问题:PHP Translatable::enable_locale_filter方法的具体用法?PHP Translatable::enable_locale_filter怎么用?PHP Translatable::enable_locale_filter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Translatable
的用法示例。
在下文中一共展示了Translatable::enable_locale_filter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sitemap
/**
* We need to disable Translatable before retreiving the DataObjects or
* Pages for the sitemap, because otherwise only pages in the default
* language are found.
*
* Next we need to add the alternatives for each Translatable Object
* included in the sitemap: basically these are the Translations plus
* the current object itself
*
* @return Array
*/
public function sitemap()
{
Translatable::disable_locale_filter();
$sitemap = parent::sitemap();
Translatable::enable_locale_filter();
$updatedItems = new ArrayList();
foreach ($sitemap as $items) {
foreach ($items as $item) {
if ($item->hasExtension('Translatable')) {
$translations = $item->getTranslations();
if ($translations) {
$alternatives = new ArrayList();
foreach ($translations as $translation) {
$translation->GoogleLocale = $this->getGoogleLocale($translation->Locale);
$alternatives->push($translation);
}
$item->GoogleLocale = $this->getGoogleLocale($item->Locale);
$alternatives->push($item);
$item->Alternatives = $alternatives;
}
$updatedItems->push($item);
}
}
}
if (!empty($updatedItems)) {
return array('Items' => $updatedItems);
} else {
return $sitemap;
}
}
开发者ID:helpfulrobot,项目名称:martimiz-silverstripe-translatablegooglesitemaps,代码行数:41,代码来源:TranslatableGoogleSitemapController.php
示例2: setUp
public function setUp()
{
parent::setUp();
Translatable::disable_locale_filter();
//Publish all english pages
$pages = Page::get()->filter('Locale', 'en_US');
foreach ($pages as $page) {
$page->publish('Stage', 'Live');
}
//Rewrite the french translation groups and publish french pages
$pagesFR = Page::get()->filter('Locale', 'fr_FR');
foreach ($pagesFR as $index => $page) {
$page->addTranslationGroup($pages->offsetGet($index)->ID, true);
$page->publish('Stage', 'Live');
}
Translatable::enable_locale_filter();
$this->origLocaleRoutingEnabled = Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL');
Config::inst()->update('MultilingualRootURLController', 'UseLocaleURL', false);
$this->origDashLocaleEnabled = Config::inst()->get('MultilingualRootURLController', 'UseDashLocale');
Config::inst()->update('MultilingualRootURLController', 'UseDashLocale', false);
$this->origAcceptLanguage = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en-US,en;q=0.5';
$this->origCookieLocale = Cookie::get('language');
Cookie::force_expiry('language');
Cookie::set('language', 'en');
$this->origCurrentLocale = Translatable::get_current_locale();
Translatable::set_current_locale('en_US');
$this->origLocale = Translatable::default_locale();
Translatable::set_default_locale('en_US');
$this->origi18nLocale = i18n::get_locale();
i18n::set_locale('en_US');
$this->origAllowedLocales = Translatable::get_allowed_locales();
Translatable::set_allowed_locales(array('en_US', 'fr_FR'));
MultilingualRootURLController::reset();
}
开发者ID:helpfulrobot,项目名称:webbuilders-group-silverstripe-translatablerouting,代码行数:35,代码来源:MultilingualModelAsControllerTest.php
示例3: setUp
public function setUp()
{
parent::setUp();
//Remap translation group for home pages
Translatable::disable_locale_filter();
$default = $this->objFromFixture('Page', 'home');
$defaultFR = $this->objFromFixture('Page', 'home_fr');
$defaultFR->addTranslationGroup($default->ID, true);
Translatable::enable_locale_filter();
$this->origLocaleRoutingEnabled = Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL');
Config::inst()->update('MultilingualRootURLController', 'UseLocaleURL', false);
$this->origDashLocaleEnabled = Config::inst()->get('MultilingualRootURLController', 'UseDashLocale');
Config::inst()->update('MultilingualRootURLController', 'UseDashLocale', false);
$this->origAcceptLanguage = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en-US,en;q=0.5';
$this->origCookieLocale = Cookie::get('language');
Cookie::force_expiry('language');
$this->origCurrentLocale = Translatable::get_current_locale();
Translatable::set_current_locale('en_US');
$this->origLocale = Translatable::default_locale();
Translatable::set_default_locale('en_US');
$this->origi18nLocale = i18n::get_locale();
i18n::set_locale('en_US');
$this->origAllowedLocales = Translatable::get_allowed_locales();
Translatable::set_allowed_locales(array('en_US', 'fr_FR'));
MultilingualRootURLController::reset();
}
开发者ID:helpfulrobot,项目名称:webbuilders-group-silverstripe-translatablerouting,代码行数:27,代码来源:MultilingualRootURLControllerTest.php
示例4: getExtendedResults
public function getExtendedResults($pageLength = null, $sort = 'Relevance DESC', $filter = '', $data = null)
{
// legacy usage: $data was defaulting to $_REQUEST, parameter not passed in doc.silverstripe.org tutorials
if (!isset($data) || !is_array($data)) {
$data = $_REQUEST;
}
// set language (if present)
if (class_exists('Translatable')) {
if (singleton('SiteTree')->hasExtension('Translatable') && isset($data['searchlocale'])) {
if ($data['searchlocale'] == "ALL") {
Translatable::disable_locale_filter();
} else {
$origLocale = Translatable::get_current_locale();
Translatable::set_current_locale($data['searchlocale']);
}
}
}
$keywords = $data['Search'];
$andProcessor = create_function('$matches', '
return " +" . $matches[2] . " +" . $matches[4] . " ";
');
$notProcessor = create_function('$matches', '
return " -" . $matches[3];
');
$keywords = preg_replace_callback('/()("[^()"]+")( and )("[^"()]+")()/i', $andProcessor, $keywords);
$keywords = preg_replace_callback('/(^| )([^() ]+)( and )([^ ()]+)( |$)/i', $andProcessor, $keywords);
$keywords = preg_replace_callback('/(^| )(not )("[^"()]+")/i', $notProcessor, $keywords);
$keywords = preg_replace_callback('/(^| )(not )([^() ]+)( |$)/i', $notProcessor, $keywords);
$keywords = $this->addStarsToKeywords($keywords);
if (!$pageLength) {
$pageLength = $this->owner->pageLength;
}
$start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
if (strpos($keywords, '"') !== false || strpos($keywords, '+') !== false || strpos($keywords, '-') !== false || strpos($keywords, '*') !== false) {
$results = DB::getConn()->searchEngine($this->owner->classesToSearch, $keywords, $start, $pageLength, $sort, $filter, true);
} else {
$results = DB::getConn()->searchEngine($this->owner->classesToSearch, $keywords, $start, $pageLength);
}
// filter by permission
if ($results) {
foreach ($results as $result) {
if (!$result->canView()) {
$results->remove($result);
}
}
}
// reset locale
if (class_exists('Translatable')) {
if (singleton('SiteTree')->hasExtension('Translatable') && isset($data['searchlocale'])) {
if ($data['searchlocale'] == "ALL") {
Translatable::enable_locale_filter();
} else {
Translatable::set_current_locale($origLocale);
}
}
}
return $results;
}
开发者ID:helpfulrobot,项目名称:nglasl-silverstripe-extensible-search,代码行数:58,代码来源:SearchFormResultsExtension.php
示例5: handleAction
function handleAction($request)
{
// This method can't be called without ajax.
if (!$request->isAjax()) {
$this->parentController->redirectBack();
return;
}
// Protect against CSRF on destructive action
if (!SecurityToken::inst()->checkRequest($request)) {
return $this->httpError(400);
}
$actions = $this->batchActions();
$actionClass = $actions[$request->param('BatchAction')]['class'];
$actionHandler = new $actionClass();
// Sanitise ID list and query the database for apges
$ids = preg_split('/ *, */', trim($request->requestVar('csvIDs')));
foreach ($ids as $k => $v) {
if (!is_numeric($v)) {
unset($ids[$k]);
}
}
if ($ids) {
if (class_exists('Translatable') && Object::has_extension('SiteTree', 'Translatable')) {
Translatable::disable_locale_filter();
}
$pages = DataObject::get($this->recordClass, sprintf('"%s"."ID" IN (%s)', ClassInfo::baseDataClass($this->recordClass), implode(", ", $ids)));
if (class_exists('Translatable') && Object::has_extension('SiteTree', 'Translatable')) {
Translatable::enable_locale_filter();
}
if (Object::has_extension($this->recordClass, 'Versioned')) {
// If we didn't query all the pages, then find the rest on the live site
if (!$pages || $pages->Count() < sizeof($ids)) {
foreach ($ids as $id) {
$idsFromLive[$id] = true;
}
if ($pages) {
foreach ($pages as $page) {
unset($idsFromLive[$page->ID]);
}
}
$idsFromLive = array_keys($idsFromLive);
$sql = sprintf('"%s"."ID" IN (%s)', $this->recordClass, implode(", ", $idsFromLive));
$livePages = Versioned::get_by_stage($this->recordClass, 'Live', $sql);
if ($pages) {
// Can't merge into a DataList, need to condense into an actual list first
// (which will retrieve all records as objects, so its an expensive operation)
$pages = new ArrayList($pages->toArray());
$pages->merge($livePages);
} else {
$pages = $livePages;
}
}
}
} else {
$pages = new ArrayList();
}
return $actionHandler->run($pages);
}
示例6: done
/**
* @param array $compatibility
*/
public static function done(array $compatibility)
{
if (class_exists("Subsite")) {
Subsite::$disable_subsite_filter = $compatibility[self::SUBSITES];
}
if (class_exists("Translatable")) {
Translatable::enable_locale_filter($compatibility[self::TRANSLATABLE]);
}
}
示例7: sitemap
/**
* Specific controller action for displaying a particular list of links
* for a class
*
* @return mixed
*/
public function sitemap()
{
if ($this->request->param('ID') == 'SiteTree') {
//Disable the locale filter
Translatable::disable_locale_filter();
$items = parent::sitemap();
//Re-enable the locale filter
Translatable::enable_locale_filter();
return $items;
} else {
return parent::sitemap();
}
}
开发者ID:helpfulrobot,项目名称:webbuilders-group-silverstripe-translatablerouting,代码行数:19,代码来源:MultilingualGoogleSitemap.php
示例8: handleAction
function handleAction($request)
{
// This method can't be called without ajax.
if (!$this->parentController->isAjax()) {
$this->parentController->redirectBack();
return;
}
$actions = $this->batchActions();
$actionClass = $actions[$request->param('BatchAction')]['class'];
$actionHandler = new $actionClass();
// Sanitise ID list and query the database for apges
$ids = split(' *, *', trim($request->requestVar('csvIDs')));
foreach ($ids as $k => $v) {
if (!is_numeric($v)) {
unset($ids[$k]);
}
}
if ($ids) {
if (Object::has_extension('SiteTree', 'Translatable')) {
Translatable::disable_locale_filter();
}
$pages = DataObject::get($this->recordClass, sprintf('"%s"."ID" IN (%s)', ClassInfo::baseDataClass($this->recordClass), implode(", ", $ids)));
if (Object::has_extension('SiteTree', 'Translatable')) {
Translatable::enable_locale_filter();
}
if (Object::has_extension($this->recordClass, 'Versioned')) {
// If we didn't query all the pages, then find the rest on the live site
if (!$pages || $pages->Count() < sizeof($ids)) {
foreach ($ids as $id) {
$idsFromLive[$id] = true;
}
if ($pages) {
foreach ($pages as $page) {
unset($idsFromLive[$page->ID]);
}
}
$idsFromLive = array_keys($idsFromLive);
$sql = sprintf('"%s"."ID" IN (%s)', $this->recordClass, implode(", ", $idsFromLive));
$livePages = Versioned::get_by_stage($this->recordClass, 'Live', $sql);
if ($pages) {
$pages->merge($livePages);
} else {
$pages = $livePages;
}
}
}
} else {
$pages = new DataObjectSet();
}
return $actionHandler->run($pages);
}
示例9: getNestedController
/**
* @return ContentController
*/
public function getNestedController()
{
$request = $this->request;
if (!($URLSegment = $request->param('URLSegment'))) {
throw new Exception('ModelAsController->getNestedController(): was not passed a URLSegment value.');
}
// Find page by link, regardless of current locale settings
Translatable::disable_locale_filter();
$sitetree = DataObject::get_one('SiteTree', sprintf('"URLSegment" = \'%s\' %s', Convert::raw2sql($URLSegment), SiteTree::nested_urls() ? 'AND "ParentID" = 0' : null));
Translatable::enable_locale_filter();
if (!$sitetree) {
// If a root page has been renamed, redirect to the new location.
// See ContentController->handleRequest() for similiar logic.
$redirect = self::find_old_page($URLSegment);
if ($redirect = self::find_old_page($URLSegment)) {
$params = $request->getVars();
if (isset($params['url'])) {
unset($params['url']);
}
$this->response = new SS_HTTPResponse();
$this->response->redirect(Controller::join_links($redirect->Link(Controller::join_links($request->param('Action'), $request->param('ID'), $request->param('OtherID'))), $params ? '?' . http_build_query($params) : null), 301);
return $this->response;
}
$ctrl = new Paste_Controller();
$ctrl->request = $request;
$paste = $ctrl->getCurrentPaste();
if ($paste) {
if (is_string($paste) || is_object($paste) && is_a($paste, 'SS_HTTPResponse')) {
return $paste;
}
$ctrl->init($paste);
$response = $ctrl->handleRequest($request);
return $response;
}
if ($response = ErrorPage::response_for(404)) {
return $response;
} else {
$this->httpError(404, 'The requested page could not be found.');
}
}
// Enforce current locale setting to the loaded SiteTree object
if ($sitetree->Locale) {
Translatable::set_current_locale($sitetree->Locale);
}
if (isset($_REQUEST['debug'])) {
Debug::message("Using record #{$sitetree->ID} of type {$sitetree->class} with link {$sitetree->Link()}");
}
return self::controller_for($sitetree, $this->request->param('Action'));
}
示例10: Fetch
public static function Fetch($echo = false)
{
$since_id = (int) SocialMediaSettings::getValue('TwitterIndex');
if ($since_id == 0) {
$since_id = 1;
}
//Twitter gives an error message if since_id is zero. This happens when tweets are fetched the first time.
$tweets = self::Connection()->get('statuses/user_timeline', array('since_id' => $since_id, 'count' => 200, 'include_rts' => true, 'exclude_replies' => true, 'screen_name' => self::config()->username));
if (self::Error()) {
user_error("Twitter error: " . self::ErrorMessage($tweets));
return false;
}
$updates = array();
$max_id = (int) SocialMediaSettings::getValue('TwitterIndex');
$skipped = 0;
$translatable_locale_filter = Translatable::disable_locale_filter();
//ID filtering does not work well if locale filtering is on.
foreach ($tweets as $tweet) {
if (!DataObject::get('BlogPost')->filter('TwitterID', $tweet->id)->exists()) {
//Do not supply the tweet if a DataObject with the same Twitter ID already exists.
//However, $max_id can still be updated with the already existing ID number. This will
//Ensure we do not have to loop over this tweet again.
$updates[] = self::tweet_to_array($tweet);
} else {
$skipped++;
}
$max_id = max($max_id, (int) $tweet->id);
}
Translatable::enable_locale_filter($translatable_locale_filter);
if ($echo and $skipped > 0) {
echo "Twitter: Skipped {$skipped} existing records. This is normal if its only a few records occasionally, but if it happens every time and the number is constant or raises, then the Twitter's 'since_id' parameter is not working correctly. If the count reaches 200, it might be that you won't get any new records at all, because Twitter's maximum count for returned records per query is 200 at the moment when writing this (January 2016). Also constant skipping might affect performance.<br />";
}
if ($echo) {
echo "Twitter: since_id was {$since_id} and is now {$max_id}.<br />";
}
SocialMediaSettings::setValue('TwitterIndex', $max_id);
//Keep track of where we left, so we don't get the same tweets next time.
return $updates;
}
示例11: getPages
/**
* Safely query and return all pages queried
*
* @param array $ids
* @return SS_List
*/
protected function getPages($ids)
{
// Check empty set
if (empty($ids)) {
return new ArrayList();
}
$recordClass = $this->recordClass;
// Bypass translatable filter
if (class_exists('Translatable') && $recordClass::has_extension('Translatable')) {
Translatable::disable_locale_filter();
}
// Bypass versioned filter
if ($recordClass::has_extension('Versioned')) {
// Workaround for get_including_deleted not supporting byIDs filter very well
// Ensure we select both stage / live records
$pages = Versioned::get_including_deleted($recordClass, array('"RecordID" IN (' . DB::placeholders($ids) . ')' => $ids));
} else {
$pages = DataObject::get($recordClass)->byIDs($ids);
}
if (class_exists('Translatable') && $recordClass::has_extension('Translatable')) {
Translatable::enable_locale_filter();
}
return $pages;
}
示例12: populateSiteConfigDefaults
/**
* When the SiteConfig object is automatically instantiated, we should ensure that
* 1. All SiteConfig objects belong to the same group
* 2. Defaults are correctly initiated from the base object
* 3. The creation mechanism uses the createTranslation function in order to be consistent
* This function ensures that any already created "vanilla" SiteConfig object is populated
* correctly with translated values.
* This function DOES populate the ID field with the newly created object ID
* @see SiteConfig
*/
protected function populateSiteConfigDefaults()
{
// Work-around for population of defaults during database initialisation.
// When the database is being setup singleton('SiteConfig') is called.
if (!DB::getConn()->hasTable($this->owner->class)) {
return;
}
if (!DB::getConn()->hasField($this->owner->class, 'Locale')) {
return;
}
if (DB::getConn()->isSchemaUpdating()) {
return;
}
// Find the best base translation for SiteConfig
$enabled = Translatable::locale_filter_enabled();
Translatable::disable_locale_filter();
$existingConfig = SiteConfig::get()->filter(array('Locale' => Translatable::default_locale()))->first();
if (!$existingConfig) {
$existingConfig = SiteConfig::get()->first();
}
if ($enabled) {
Translatable::enable_locale_filter();
}
// Stage this SiteConfig and copy into the current object
if ($existingConfig && !$existingConfig->getTranslation(Translatable::get_current_locale()) && $existingConfig->canTranslate(null, Translatable::get_current_locale())) {
// Create an unsaved "staging" translated object using the correct createTranslation mechanism
$stagingConfig = $existingConfig->createTranslation(Translatable::get_current_locale(), false);
$this->owner->update($stagingConfig->toMap());
}
// Maintain single translation group for SiteConfig
if ($existingConfig) {
$this->owner->_TranslationGroupID = $existingConfig->getTranslationGroup();
}
$this->owner->Locale = Translatable::get_current_locale();
}
示例13: testLocaleFilteringEnabledAndDisabled
function testLocaleFilteringEnabledAndDisabled()
{
$this->assertTrue(Translatable::locale_filter_enabled());
// get our base page to use for testing
$origPage = $this->objFromFixture('Page', 'testpage_en');
$origPage->MenuTitle = 'unique-key-used-in-my-query';
$origPage->write();
$origPage->publish('Stage', 'Live');
// create a translation of it so that we can see if translations are filtered
$translatedPage = $origPage->createTranslation('de_DE');
$translatedPage->MenuTitle = $origPage->MenuTitle;
$translatedPage->write();
$translatedPage->publish('Stage', 'Live');
$where = sprintf("\"MenuTitle\" = '%s'", Convert::raw2sql($origPage->MenuTitle));
// make sure that our query was filtered
$this->assertEquals(1, Page::get()->where($where)->count());
// test no filtering with disabled locale filter
Translatable::disable_locale_filter();
$this->assertEquals(2, Page::get()->where($where)->count());
Translatable::enable_locale_filter();
// make sure that our query was filtered after re-enabling the filter
$this->assertEquals(1, Page::get()->where($where)->count());
// test effectiveness of disabling locale filter with 3.x delayed querying
// see https://github.com/silverstripe/silverstripe-translatable/issues/113
Translatable::disable_locale_filter();
// create the DataList while the locale filter is disabled
$dataList = Page::get()->where($where);
Translatable::enable_locale_filter();
// but don't use it until later - after the filter is re-enabled
$this->assertEquals(2, $dataList->count());
}
示例14: onBeforeWrite
/**
* The holder-page ID should be set if translatable, otherwise, we just select the first available one.
* The NewsHolderPage should NEVER be doubled.
*/
public function onBeforeWrite()
{
parent::onBeforeWrite();
/** Check if we have translatable and a NewsHolderPage. If no HolderPage available, skip (Create an orphan) */
if (!$this->NewsHolderPages()->count()) {
if (!class_exists('Translatable') && ($page = NewsHolderPage::get()->first())) {
$this->NewsHolderPages()->add($page);
} elseif (class_exists('Translatable')) {
Translatable::disable_locale_filter();
$page = NewsHolderPage::get()->first();
$this->NewsHolderPages()->add($page);
Translatable::enable_locale_filter();
}
}
if (!$this->Type || $this->Type === '') {
$this->Type = 'news';
}
/** Set PublishFrom to today to prevent errors with sorting. New since 2.0, backward compatible. */
if (!$this->PublishFrom) {
$this->PublishFrom = SS_Datetime::now()->Rfc2822();
}
/**
* Make sure the link is valid.
*/
if (substr($this->External, 0, 4) !== 'http' && $this->External != '') {
$this->External = 'http://' . $this->External;
}
$this->setURLValue();
$this->setAuthorData();
}
示例15: Buyable
/**
*
* @param Boolean $current - is this a current one, or an older VERSION ?
* @return DataObject (Any type of Data Object that is buyable)
**/
function Buyable($current = false)
{
$tempBuyableStoreType = $current ? "current" : "version";
if (!isset($this->tempBuyableStore[$tempBuyableStoreType])) {
if (!$this->BuyableID) {
user_error("There was an error retrieving the product", E_USER_NOTICE);
return null;
}
//start hack
if (!$this->BuyableClassName) {
$this->BuyableClassName = str_replace("_OrderItem", "", $this->ClassName);
}
$turnTranslatableBackOn = false;
$className = $this->BuyableClassName;
if ($className::has_extension($this->class, 'Translatable')) {
Translatable::disable_locale_filter();
$turnTranslatableBackOn = true;
}
//end hack!
$obj = null;
if ($current) {
$obj = $className::get()->byID($this->BuyableID);
}
//run if current not available or current = false
if (!$obj || !$current) {
if ((!$obj || !$obj->exists()) && $this->Version) {
/* @TODO: check if the version exists?? - see sample below
$versionTable = $this->BuyableClassName."_versions";
$dbConnection = DB::getConn();
if($dbConnection && $dbConnection instanceOf MySQLDatabase && $dbConnection->hasTable($versionTable)) {
$result = DB::query("
SELECT COUNT(\"ID\")
FROM \"$versionTable\"
WHERE
\"RecordID\" = ".intval($this->BuyableID)."
AND \"Version\" = ".intval($this->Version)."
");
if($result->value()) {
*/
$obj = OrderItem::get_version($this->BuyableClassName, $this->BuyableID, $this->Version);
}
//our second to last resort
if (!$obj || !$obj->exists()) {
$obj = Versioned::get_latest_version($this->BuyableClassName, $this->BuyableID);
}
}
//our final backup
if (!$obj || !$obj->exists()) {
$obj = $className::get()->byID($this->BuyableID);
}
if ($turnTranslatableBackOn) {
Translatable::enable_locale_filter();
}
$this->tempBuyableStore[$tempBuyableStoreType] = $obj;
}
return $this->tempBuyableStore[$tempBuyableStoreType];
}