本文整理汇总了PHP中eZContentLanguage::addLanguage方法的典型用法代码示例。如果您正苦于以下问题:PHP eZContentLanguage::addLanguage方法的具体用法?PHP eZContentLanguage::addLanguage怎么用?PHP eZContentLanguage::addLanguage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZContentLanguage
的用法示例。
在下文中一共展示了eZContentLanguage::addLanguage方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testIssue19174
/**
* Regression test for issue {@see #19174 http://issues.ez.no/19174}
*/
public function testIssue19174()
{
$bkpLanguages = eZContentLanguage::prioritizedLanguageCodes();
// add a secondary language
$locale = eZLocale::instance('fre-FR');
$translation = eZContentLanguage::addLanguage($locale->localeCode(), $locale->internationalLanguageName());
// create related objects
$relatedObjectsIds = array($this->createObjectForRelation(), $this->createObjectForRelation(), $this->createObjectForRelation(), $this->createObjectForRelation());
$xmlTextEn = "<embed href=\"ezobject://{$relatedObjectsIds[0]}\" /><link href=\"ezobject://{$relatedObjectsIds[1]}\">link</link>";
$xmlTextFr = "<embed href=\"ezobject://{$relatedObjectsIds[2]}\" /><link href=\"ezobject://{$relatedObjectsIds[3]}\">link</link>";
// Create an article in eng-GB, and embed related object one in the intro
$article = new ezpObject('article', 2, 14, 1, 'eng-GB');
$article->title = __METHOD__ . ' eng-GB';
$article->intro = $xmlTextEn;
$articleId = $article->publish();
// Workaround as setting folder->name directly doesn't produce the expected result
$article->addTranslation('fre-FR', array('title' => __METHOD__ . ' fre-FR', 'intro' => $xmlTextFr));
$relatedObjects = eZContentObject::fetch($articleId)->relatedObjects(false, false, 0, false, array('AllRelations' => eZContentObject::RELATION_LINK | eZContentObject::RELATION_EMBED));
self::assertEquals(4, count($relatedObjects));
$expectedRelations = array_flip($relatedObjectsIds);
foreach ($relatedObjects as $relatedObject) {
if (isset($expectedRelations[$relatedObject->ID])) {
unset($expectedRelations[$relatedObject->ID]);
}
}
self::assertEquals(0, count($expectedRelations));
$article->remove();
$translation->removeThis();
eZContentLanguage::setPrioritizedLanguages($bkpLanguages);
}
示例2: testMapLanguage
/**
* Test that fetching the language listing, works after languages
* have been altered in database, and then later refetched.
*
* @link http://issues.ez.no/15484
*/
public function testMapLanguage()
{
$db = eZDB::instance();
eZContentLanguage::addLanguage('nno-NO', 'Nynorsk');
$localeToChangeInto = 'dan-DK';
$languageNameToChangeInto = 'Danish';
$langObject = eZContentLanguage::fetchByLocale('nno-NO');
$langId = (int) $langObject->attribute('id');
$updateSql = <<<END
UPDATE ezcontent_language
SET
locale='{$localeToChangeInto}',
name='{$languageNameToChangeInto}'
WHERE
id={$langId}
END;
$db->query($updateSql);
eZContentLanguage::expireCache();
$newLangObject = eZContentLanguage::fetchByLocale($localeToChangeInto);
if (!$newLangObject instanceof eZContentLanguage) {
self::fail("Language object not returned. Old version provided by cache?");
}
$newLangId = (int) $newLangObject->attribute('id');
self::assertEquals($langId, $newLangId, "New language not mapped to existing language");
}
示例3: setUp
public function setUp()
{
parent::setUp();
$this->xxx = eZContentLanguage::addLanguage('xxx-XX', 'XXXX');
ezpINIHelper::setINISetting('site.ini', 'RegionalSettings', 'SiteLanguageList', array('xxx-XX', 'eng-GB'));
eZContentLanguage::clearPrioritizedLanguages();
}
示例4: testIssue13497
/**
* Test for regression #13497:
* attribute operator throws a PHP fatal error on a node without parent in a displayable language
*
* Situation:
* - siteaccess with one language (fre-FR) and ShowUntranslatedObjects disabled
* - parent content node in another language (eng-GB) with always available disabled
* - content node in the siteaccess' language (fre-FR)
* - fetch this fre-FR node from anywhere, and call attribute() on it
*
* Result:
* - Fatal error: Call to a member function attribute() on a non-object in
* kernel/classes/ezcontentobjecttreenode.php on line 4225
*
* Explanation: the error actually comes from the can_remove_location attribute
**/
public function testIssue13497()
{
// Create a folder in english only
$folder = new ezpObject("folder", 2, 14, 1, 'eng-GB');
$folder->setAlwaysAvailableLanguageID(false);
$folder->name = "Parent for " . __FUNCTION__;
$folder->publish();
$locale = eZLocale::instance('fre-FR');
$translation = eZContentLanguage::addLanguage($locale->localeCode(), $locale->internationalLanguageName());
// Create an article in french only, as a subitem of the previously created folder
$article = new ezpObject("article", $folder->attribute('main_node_id'), 14, 1, 'fre-FR');
$article->title = "Object for " . __FUNCTION__;
$article->short_description = "Description of test for " . __FUNCTION__;
$article->publish();
$articleNodeID = $article->attribute('main_node_id');
// INi changes: set language to french only, untranslatedobjects disabled
ezpINIHelper::setINISetting('site.ini', 'RegionalSettings', 'ContentObjectLocale', 'fre-FR');
ezpINIHelper::setINISetting('site.ini', 'RegionalSettings', 'SiteLanguageList', array('fre-FR'));
ezpINIHelper::setINISetting('site.ini', 'RegionalSettings', 'ShowUntranslatedObjects', 'disabled');
eZContentLanguage::expireCache();
// This should crash
eZContentObjectTreeNode::fetch($articleNodeID)->attribute('can_remove_location');
ezpINIHelper::restoreINISettings();
// re-expire cache for further tests
eZContentLanguage::expireCache();
}
示例5: setUp
public function setUp()
{
parent::setUp();
$this->language = eZContentLanguage::addLanguage("nor-NO", "Norsk");
// Make sure all tests are done using utf-8 as charset
$this->charset = $GLOBALS['eZTextCodecInternalCharsetReal'];
$GLOBALS['eZTextCodecInternalCharsetReal'] = 'utf-8';
}
示例6: testIssue17632
/**
* Regression test for issue {@see #17632 http://issues.ez.no/17632}
*
* In a multi language environment, a node fetched with a language other than the prioritized one(s) will return the
* URL alias in the prioritized language
*/
public function testIssue17632()
{
$bkpLanguages = eZContentLanguage::prioritizedLanguageCodes();
$strNameEngGB = __FUNCTION__ . " eng-GB";
$strNameFreFR = __FUNCTION__ . " fre-FR";
// add a secondary language
$locale = eZLocale::instance( 'fre-FR' );
$translation = eZContentLanguage::addLanguage( $locale->localeCode(), $locale->internationalLanguageName() );
// set the prioritize language list to contain english
// ezpINIHelper::setINISetting( 'site.ini', 'RegionalSettings', 'SiteLanguageList', array( 'fre-FR' ) );
eZContentLanguage::setPrioritizedLanguages( array( 'fre-FR' ) );
// Create an object with data in fre-FR and eng-GB
$folder = new ezpObject( 'folder', 2, 14, 1, 'eng-GB' );
$folder->publish();
// Workaround as setting folder->name directly doesn't produce the expected result
$folder->addTranslation( 'eng-GB', array( 'name' => $strNameEngGB ) );
$folder->addTranslation( 'fre-FR', array( 'name' => $strNameFreFR ) );
$nodeId = $folder->main_node_id;
// fetch the node with no default parameters. Should return the french URL Alias
$node = eZContentObjectTreeNode::fetch( $nodeId );
self::assertEquals( 'testIssue17632-fre-FR' , $node->attribute( 'url_alias' ) );
// fetch the node in english. Should return the english URL Alias
$node = eZContentObjectTreeNode::fetch( $nodeId, 'eng-GB' );
self::assertEquals( 'testIssue17632-eng-GB' , $node->attribute( 'url_alias' ) );
ezpINIHelper::restoreINISettings();
eZContentLanguage::setPrioritizedLanguages( $bkpLanguages );
}
示例7: initializePackage
//.........这里部分代码省略.........
// Add a policy to permit editors using OE
eZPolicy::createNew(3, array('ModuleName' => 'ezoe', 'FunctionName' => '*'));
// Install site package and it's required packages
$sitePackageName = $this->chosenSitePackage();
$sitePackage = eZPackage::fetch($sitePackageName);
if (!is_object($sitePackage)) {
$resultArray['errors'][] = array('code' => 'EZSW-041', 'text' => " Could not fetch site package: '{$sitePackageName}'");
return false;
}
$dependecies = $sitePackage->attribute('dependencies');
$requires = $dependecies['requires'];
$requiredPackages = array();
// Include setting files
$settingsFiles = $sitePackage->attribute('settings-files');
foreach ($settingsFiles as $settingsFileName) {
if (file_exists($sitePackage->path() . '/settings/' . $settingsFileName)) {
include_once $sitePackage->path() . '/settings/' . $settingsFileName;
}
}
// Call user function for additional setup tasks.
if (function_exists('eZSitePreInstall')) {
eZSitePreInstall($siteType);
}
// Make sure objects use the selected main language instead of eng-GB
if ($primaryLanguageLocaleCode != 'eng-GB') {
$engLanguageObj = eZContentLanguage::fetchByLocale('eng-GB');
$engLanguageID = (int) $engLanguageObj->attribute('id');
$updateSql = "UPDATE ezcontent_language\nSET\nlocale='{$primaryLanguageLocaleCode}',\nname='{$primaryLanguageName}'\nWHERE\nid={$engLanguageID}";
$db->query($updateSql);
eZContentLanguage::expireCache();
$primaryLanguageObj = eZContentLanguage::fetchByLocale($primaryLanguageLocaleCode);
// Add it if it is missing (most likely)
if (!$primaryLanguageObj) {
$primaryLanguageObj = eZContentLanguage::addLanguage($primaryLanguageLocaleCode, $primaryLanguageName);
}
$primaryLanguageID = (int) $primaryLanguageObj->attribute('id');
// Find objects which are always available
if ($db->databaseName() == 'oracle') {
$sql = "SELECT id\nFROM\nezcontentobject\nWHERE\nbitand( language_mask, 1 ) = 1";
} else {
$sql = "SELECT id\nFROM\nezcontentobject\nWHERE\nlanguage_mask & 1 = 1";
}
$objectList = array();
$list = $db->arrayQuery($sql);
foreach ($list as $row) {
$objectList[] = (int) $row['id'];
}
$inSql = 'IN ( ' . implode(', ', $objectList) . ')';
// Updates databases that have eng-GB data to the new locale.
$updateSql = "UPDATE ezcontentobject_name\nSET\ncontent_translation='{$primaryLanguageLocaleCode}',\nreal_translation='{$primaryLanguageLocaleCode}',\nlanguage_id={$primaryLanguageID}\nWHERE\ncontent_translation='eng-GB' OR\nreal_translation='eng-GB'";
$db->query($updateSql);
// Fix always available
$updateSql = "UPDATE ezcontentobject_name\nSET\nlanguage_id=language_id+1\nWHERE\ncontentobject_id {$inSql}";
$db->query($updateSql);
// attributes
$updateSql = "UPDATE ezcontentobject_attribute\nSET\nlanguage_code='{$primaryLanguageLocaleCode}',\nlanguage_id={$primaryLanguageID}\nWHERE\nlanguage_code='eng-GB'";
$db->query($updateSql);
// Fix always available
$updateSql = "UPDATE ezcontentobject_attribute\nSET\nlanguage_id=language_id+1\nWHERE\ncontentobject_id {$inSql}";
$db->query($updateSql);
// version
$updateSql = "UPDATE ezcontentobject_version\nSET\ninitial_language_id={$primaryLanguageID},\nlanguage_mask={$primaryLanguageID}\nWHERE\ninitial_language_id={$engLanguageID}";
$db->query($updateSql);
// Fix always available
$updateSql = "UPDATE ezcontentobject_version\nSET\nlanguage_mask=language_mask+1\nWHERE\ncontentobject_id {$inSql}";
$db->query($updateSql);
示例8: setUp
public function setUp()
{
parent::setUp();
$this->language = eZContentLanguage::addLanguage("nor-NO", "Norsk");
}
示例9: fetchByLocale
/**
* Fetches the language identified by locale code.
*
* \param locale Locale of the language to fetch, e. g. 'slk-SK'.
* \return eZContentLanguage object identified by locale code $locale.
*/
static function fetchByLocale($locale, $createIfNotExist = false)
{
$languages = eZContentLanguage::fetchList();
foreach ($languages as $language) {
if ($language->attribute('locale') == $locale) {
return $language;
}
}
$language = false;
if ($createIfNotExist) {
$language = eZContentLanguage::addLanguage($locale);
}
return $language;
}
示例10: unserialize
/**
* Unserialize xml structure. Creates an object from xml input.
*
* Transaction unsafe. If you call several transaction unsafe methods you must enclose
* the calls within a db transaction; thus within db->begin and db->commit.
*
* @param mixed $package
* @param DOMElement $domNode
* @param array $options
* @param int|bool $ownerID Override owner ID, null to use XML owner id (optional)
* @param string $handlerType
* @return array|bool|eZContentObject|null created object, false if could not create object/xml invalid
*/
static function unserialize( $package, $domNode, &$options, $ownerID = false, $handlerType = 'ezcontentobject' )
{
if ( $domNode->localName != 'object' )
{
$retValue = false;
return $retValue;
}
$initialLanguage = eZContentObject::mapLanguage( $domNode->getAttribute( 'initial_language' ), $options );
if( $initialLanguage === 'skip' )
{
$retValue = true;
return $retValue;
}
$sectionID = $domNode->getAttributeNS( 'http://ez.no/ezobject', 'section_id' );
if ( $ownerID === false )
{
$ownerID = $domNode->getAttributeNS( 'http://ez.no/ezobject', 'owner_id' );
}
$remoteID = $domNode->getAttribute( 'remote_id' );
$name = $domNode->getAttribute( 'name' );
$classRemoteID = $domNode->getAttribute( 'class_remote_id' );
$classIdentifier = $domNode->getAttributeNS( 'http://ez.no/ezobject', 'class_identifier' );
$alwaysAvailable = ( $domNode->getAttributeNS( 'http://ez.no/ezobject', 'always_available' ) == '1' );
$contentClass = eZContentClass::fetchByRemoteID( $classRemoteID );
if ( !$contentClass )
{
$contentClass = eZContentClass::fetchByIdentifier( $classIdentifier );
}
if ( !$contentClass )
{
$options['error'] = array( 'error_code' => self::PACKAGE_ERROR_NO_CLASS,
'element_id' => $remoteID,
'description' => "Can't install object '$name': Unable to fetch class with remoteID: $classRemoteID." );
$retValue = false;
return $retValue;
}
/** @var DOMElement $versionListNode */
$versionListNode = $domNode->getElementsByTagName( 'version-list' )->item( 0 );
$importedLanguages = array();
foreach( $versionListNode->getElementsByTagName( 'version' ) as $versionDOMNode )
{
/** @var DOMElement $versionDOMNode */
foreach ( $versionDOMNode->getElementsByTagName( 'object-translation' ) as $versionDOMNodeChild )
{
/** @var DOMElement $versionDOMNodeChild */
$importedLanguage = eZContentObject::mapLanguage( $versionDOMNodeChild->getAttribute( 'language' ), $options );
$language = eZContentLanguage::fetchByLocale( $importedLanguage );
// Check if the language is allowed in this setup.
if ( $language )
{
$hasTranslation = true;
}
else
{
if ( $importedLanguage == 'skip' )
continue;
// if there is no needed translation in system then add it
$locale = eZLocale::instance( $importedLanguage );
$translationName = $locale->internationalLanguageName();
$translationLocale = $locale->localeCode();
if ( $locale->isValid() )
{
eZContentLanguage::addLanguage( $locale->localeCode(), $locale->internationalLanguageName() );
$hasTranslation = true;
}
else
$hasTranslation = false;
}
if ( $hasTranslation )
{
$importedLanguages[] = $importedLanguage;
$importedLanguages = array_unique( $importedLanguages );
}
}
}
// If object exists we return a error.
// Minimum install element is an object now.
//.........这里部分代码省略.........
示例11: array
// Make sure the locale string is valid, if not we try to extract a valid part of it
if (!preg_match("/^" . eZLocale::localeRegexp(false, false) . "\$/", $translationLocale)) {
if (preg_match("/(" . eZLocale::localeRegexp(false, false) . ")/", $translationLocale, $matches)) {
$translationLocale = $matches[1];
} else {
// The locale cannot be used so we show the edit page again.
$tpl->setVariable('is_edit', $Module->isCurrentAction('Edit'));
$Result['content'] = $tpl->fetch('design:content/translationnew.tpl');
$Result['path'] = array(array('text' => ezpI18n::tr('kernel/content', 'Translation'), 'url' => false), array('text' => 'New', 'url' => false));
return;
}
}
if (!eZContentLanguage::fetchByLocale($translationLocale)) {
$locale = eZLocale::instance($translationLocale);
if ($locale->isValid()) {
$translation = eZContentLanguage::addLanguage($locale->localeCode(), $translationName);
ezpEvent::getInstance()->notify('content/translations/cache', array($translation->attribute('id')));
} else {
// The locale cannot be used so we show the edit page again.
$tpl->setVariable('is_edit', $Module->isCurrentAction('Edit'));
$Result['content'] = $tpl->fetch('design:content/translationnew.tpl');
$Result['path'] = array(array('text' => ezpI18n::tr('kernel/content', 'Translation'), 'url' => false), array('text' => 'New', 'url' => false));
return;
}
}
}
if ($Module->isCurrentAction('Remove')) {
$seletedIDList = $Module->actionParameter('SelectedTranslationList');
$db = eZDB::instance();
$db->begin();
foreach ($seletedIDList as $translationID) {
示例12: unserialize
static function unserialize( $domNode, $contentObject, $ownerID, $sectionID, $activeVersion, $firstVersion, &$nodeList, &$options, $package, $handlerType = 'ezcontentobject' )
{
$oldVersion = $domNode->getAttributeNS( 'http://ez.no/ezobject', 'version' );
$status = $domNode->getAttributeNS( 'http://ez.no/ezobject', 'status' );
$languageNodeArray = $domNode->getElementsByTagName( 'object-translation' );
$initialLanguage = false;
$importedLanguages = $options['language_array'];
$currentLanguages = array();
foreach( $languageNodeArray as $languageNode )
{
$language = eZContentObjectVersion::mapLanguage( $languageNode->getAttribute( 'language' ), $options );
if ( in_array( $language, $importedLanguages ) )
{
$currentLanguages[] = $language;
}
}
foreach ( eZContentLanguage::prioritizedLanguages() as $language )
{
if ( in_array( $language->attribute( 'locale' ), $currentLanguages ) )
{
$initialLanguage = $language->attribute( 'locale' );
break;
}
}
if ( !$initialLanguage )
{
$initialLanguage = $currentLanguages[0];
}
if ( $firstVersion )
{
$contentObjectVersion = $contentObject->version( 1 );
}
else
{
// Create new version in specific language but with empty data.
$contentObjectVersion = $contentObject->createNewVersionIn( $initialLanguage );
}
$created = eZDateUtils::textToDate( $domNode->getAttributeNS( 'http://ez.no/ezobject', 'created' ) );
$modified = eZDateUtils::textToDate( $domNode->getAttributeNS( 'http://ez.no/ezobject', 'modified' ) );
$contentObjectVersion->setAttribute( 'created', $created );
$contentObjectVersion->setAttribute( 'modified', $modified );
$contentObjectVersion->setAttribute( 'status', eZContentObjectVersion::STATUS_DRAFT );
$contentObjectVersion->store();
$db = eZDB::instance();
$db->begin();
foreach( $languageNodeArray as $languageNode )
{
$language = eZContentObjectVersion::mapLanguage( $languageNode->getAttribute( 'language' ), $options );
// Only import allowed languages.
if ( !in_array( $language, $importedLanguages ) )
{
continue;
}
$attributeArray = $contentObjectVersion->contentObjectAttributes( $language );
if ( count( $attributeArray ) == 0)
{
$hasTranslation = eZContentLanguage::fetchByLocale( $language );
if ( !$hasTranslation )
{
// if there is no needed translation in system then add it
$locale = eZLocale::instance( $language );
if ( $locale->isValid() )
{
eZContentLanguage::addLanguage( $locale->localeCode(), $locale->internationalLanguageName() );
$hasTranslation = true;
}
else
$hasTranslation = false;
}
if ( $hasTranslation )
{
// Add translated attributes for the translation
$originalContentAttributes = $contentObjectVersion->contentObjectAttributes( $initialLanguage );
foreach ( $originalContentAttributes as $originalContentAttribute )
{
$contentAttribute = $originalContentAttribute->translateTo( $language );
$contentAttribute->sync();
$attributeArray[] = $contentAttribute;
}
}
// unserialize object name in current version-translation
$objectName = $languageNode->getAttribute( 'object_name' );
if ( $objectName )
$contentObject->setName( $objectName, $contentObjectVersion->attribute( 'version' ), $language );
}
$xpath = new DOMXPath( $domNode->ownerDocument );
$xpath->registerNamespace( 'ezobject', 'http://ez.no/object/' );
$xpath->registerNamespace( 'ezremote', 'http://ez.no/ezobject' );
//.........这里部分代码省略.........
示例13: testIssue23753
/**
* Regression test for issue {@see #23753 http://issues.ez.no/23753}
*
* In a multi language environment, an untranslated node fetched with default language will return the
* full URL alias in the language of the node.
*/
public function testIssue23753()
{
$bkpLanguages = eZContentLanguage::prioritizedLanguageCodes();
$strNameEngGB = __FUNCTION__ . " eng-GB";
$strNameFreFR = __FUNCTION__ . " fre-FR";
// add a secondary language
$locale = eZLocale::instance('fre-FR');
$translation = eZContentLanguage::addLanguage($locale->localeCode(), $locale->internationalLanguageName());
// set the prioritize language list to contain english
eZContentLanguage::setPrioritizedLanguages(array('fre-FR', 'eng-GB'));
// Create an object with data in fre-FR and eng-GB
$folder = new ezpObject('folder', 2, 14, 1, 'eng-GB');
$folder->publish();
// Workaround as setting folder->name directly doesn't produce the expected result
$folder->addTranslation('eng-GB', array('name' => $strNameEngGB));
$folder->addTranslation('fre-FR', array('name' => $strNameFreFR));
$article = new ezpObject('article', $folder->main_node_id, 14, 1, 'eng-GB');
$article->publish();
// Workaround as setting article->name directly doesn't produce the expected result
$article->addTranslation('eng-GB', array('title' => $strNameEngGB));
$nodeId = $article->main_node_id;
// fetch the node with no default parameters. Should return the french URL Alias when applicable
$node = eZContentObjectTreeNode::fetch($nodeId);
self::assertEquals('testIssue23753-fre-FR/testIssue23753-eng-GB', $node->attribute('url_alias'));
// fetch the node in english. Should return the full english URL Alias
$node = eZContentObjectTreeNode::fetch($nodeId, 'eng-GB');
self::assertEquals('testIssue23753-eng-GB/testIssue23753-eng-GB', $node->attribute('url_alias'));
// Test that PathPrefix is correctly removed from UrlAlias
ezpINIHelper::setINISetting('site.ini', 'SiteAccessSettings', 'PathPrefix', 'testIssue23753-fre-FR');
$node = eZContentObjectTreeNode::fetch($nodeId);
self::assertEquals('testIssue23753-eng-GB', $node->attribute('url_alias'));
$folder->remove();
$translation->removeThis();
ezpINIHelper::restoreINISettings();
eZContentLanguage::setPrioritizedLanguages($bkpLanguages);
}