本文整理汇总了PHP中eZURLAliasML::create方法的典型用法代码示例。如果您正苦于以下问题:PHP eZURLAliasML::create方法的具体用法?PHP eZURLAliasML::create怎么用?PHP eZURLAliasML::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZURLAliasML
的用法示例。
在下文中一共展示了eZURLAliasML::create方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testChoosePrioritizedRow
public function testChoosePrioritizedRow()
{
// Make sure we can see all languages
ezpINIHelper::setINISetting('site.ini', 'RegionalSettings', 'ShowUntranslatedObjects', 'enabled');
$action = "eznode:" . mt_rand();
$name = __FUNCTION__ . mt_rand();
$engGB = eZContentLanguage::fetchByLocale('eng-GB');
$norNO = eZContentLanguage::fetchByLocale('nor-NO');
// Create an english entry
$url1 = eZURLAliasML::create($name . " en", $action, 0, $engGB->attribute('id'));
$url1->store();
// Create a norwegian entry
$url2 = eZURLAliasML::create($name . " no", $action, 0, $norNO->attribute('id'));
$url2->store();
// Fetch the created entries. choosePrioritizedRow() wants rows from the
// database so our eZURLAliasML objects wont work.
$db = eZDB::instance();
$rows = $db->arrayQuery("SELECT * FROM ezurlalias_ml where action = '{$action}'");
// -------------------------------------------------------------------
// TEST PART 1 - NORMAL PRIORITIZATION -------------------------------
// The order of the language array also determines the prioritization.
// In this case 'eng-GB' should be prioritized before 'nor-NO'.
$languageList = array("eng-GB", "nor-NO");
ezpINIHelper::setINISetting('site.ini', 'RegionalSettings', 'SiteLanguageList', $languageList);
eZContentLanguage::clearPrioritizedLanguages();
$row = eZURLAliasML::choosePrioritizedRow($rows);
// The prioritzed language should be 'eng-GB'
self::assertEquals($engGB->attribute('id'), $row["lang_mask"]);
// -------------------------------------------------------------------
// TEST PART 2 - REVERSED PRIORITIZATION -----------------------------
// Reverse the order of the specified languages, this will also
// reverse the priority.
$languageList = array_reverse($languageList);
ezpINIHelper::setINISetting('site.ini', 'RegionalSettings', 'SiteLanguageList', $languageList);
eZContentLanguage::clearPrioritizedLanguages();
$row = eZURLAliasML::choosePrioritizedRow($rows);
// The prioritzed language should be 'nor-NO'
self::assertEquals($norNO->attribute('id'), $row["lang_mask"]);
// -------------------------------------------------------------------
// TEST TEAR DOWN ----------------------------------------------------
ezpINIHelper::restoreINISettings();
// -------------------------------------------------------------------
}
示例2: storePath
static function storePath($path, $action, $languageName = false, $linkID = false, $alwaysAvailable = false, $rootID = false, $cleanupElements = true, $autoAdjustName = false, $reportErrors = true, $aliasRedirects = true)
{
$path = eZURLAliasML::cleanURL($path);
if ($languageName === false) {
$languageName = eZContentLanguage::topPriorityLanguage();
}
if (is_object($languageName)) {
$languageObj = $languageName;
$languageID = (int) $languageName->attribute('id');
$languageName = $languageName->attribute('locale');
} else {
$languageObj = eZContentLanguage::fetchByLocale($languageName);
$languageID = (int) $languageObj->attribute('id');
}
$languageMask = $languageID;
if ($alwaysAvailable) {
$languageMask |= 1;
}
$path = eZURLAliasML::cleanURL($path);
$elements = explode('/', $path);
$db = eZDB::instance();
$parentID = 0;
// If the root ID is specified we will start the parent search from that
if ($rootID !== false) {
$parentID = $rootID;
}
$i = 0;
// Top element is handled separately.
$topElement = array_pop($elements);
// Find correct parent, and create missing ones if necessary
$createdPath = array();
foreach ($elements as $element) {
$actionStr = $db->escapeString($action);
if ($cleanupElements) {
$element = eZURLAliasML::convertToAlias($element, 'noname' . (count($createdPath) + 1));
}
$elementStr = $db->escapeString(eZURLAliasML::strtolower($element));
$query = "SELECT * FROM ezurlalias_ml WHERE text_md5 = " . eZURLAliasML::md5($db, $elementStr, false) . " AND parent = {$parentID}";
$rows = $db->arrayQuery($query);
if (count($rows) == 0) {
// Create a fake element to ensure we have a parent
$elementObj = eZURLAliasML::create($element, "nop:", $parentID, 1);
$elementObj->store();
$parentID = (int) $elementObj->attribute('id');
} else {
$parentID = (int) $rows[0]['link'];
}
$createdPath[] = $element;
++$i;
}
if ($parentID != 0) {
$sql = "SELECT text, parent FROM ezurlalias_ml WHERE id = {$parentID}";
$rows = $db->arrayQuery($sql);
if (count($rows) > 0) {
// A special case. If the special entry with empty text is used as parent
// the parent must be adjust to 0 (ie. real top level).
if (strlen($rows[0]['text']) == 0 && $rows[0]['parent'] == 0) {
$createdPath = array();
$parentID = 0;
}
}
}
if (!preg_match("#^(.+):(.+)\$#", $action, $matches)) {
return array('status' => self::ACTION_INVALID, 'error_message' => "The action value " . var_export($action, true) . " is invalid", 'error_number' => self::ACTION_INVALID, 'path' => null, 'element' => null);
}
$actionName = $matches[1];
$actionValue = $matches[2];
$existingElementID = null;
$alwaysMask = $alwaysAvailable ? 1 : 0;
$actionStr = $db->escapeString($action);
$actionTypeStr = $db->escapeString($actionName);
$createdElement = null;
if ($linkID === false) {
if ($cleanupElements) {
$topElement = eZURLAliasML::convertToAlias($topElement, 'noname' . (count($createdPath) + 1));
}
$adjustName = false;
$curElementID = null;
$newElementID = null;
$newText = $topElement;
$uniqueCounter = 0;
// Loop until we a valid entry point, which means:
// 1. The entry does not exist yet, so create a new one
// 2. The entry exists but is re-usable (e.g. nop or same action)
// 3. The entry exists and cannot be re-used, instead the name is adjusted to be unique.
while (true) {
$newText = $topElement;
if ($uniqueCounter > 0) {
$newText .= $uniqueCounter + 1;
}
$textMD5 = eZURLAliasML::md5($db, $newText);
$query = "SELECT * FROM ezurlalias_ml WHERE parent = {$parentID} AND text_md5 = {$textMD5}";
$rows = $db->arrayQuery($query);
if (count($rows) == 0) {
// No such entry, create a new one
break;
}
$row = $rows[0];
$curID = (int) $row['id'];
$curAction = $row['action'];
//.........这里部分代码省略.........
示例3: testChoosePrioritizedRow
public function testChoosePrioritizedRow()
{
// TEST SETUP --------------------------------------------------------
$ini = eZINI::instance();
// Make sure to preserve ini settings in case other tests depend on them
$orgShowUntranslatedObjects = $ini->variable('RegionalSettings', 'ShowUntranslatedObjects');
$orgSiteLanguageList = $ini->variable('RegionalSettings', 'SiteLanguageList');
// Make sure we can see all languages
$ini->setVariable('RegionalSettings', 'ShowUntranslatedObjects', 'enabled');
$action = "eznode:" . mt_rand();
$name = __FUNCTION__ . mt_rand();
// Create an english entry
$url1 = eZURLAliasML::create($name . " en", $action, 0, 2);
$url1->store();
// Create a norwegian entry
$url2 = eZURLAliasML::create($name . " no", $action, 0, 4);
$url2->store();
// Fetch the created entries. choosePrioritizedRow() wants rows from the
// database so our eZURLAliasML objects wont work.
$db = eZDB::instance();
$rows = $db->arrayQuery("SELECT * FROM ezurlalias_ml where action = '{$action}'");
// -------------------------------------------------------------------
// TEST PART 1 - NORMAL PRIORITIZATION -------------------------------
// The order of the language array also determines the prioritization.
// In this case 'eng-GB' should be prioritized before 'nor-NO'.
$languageList = array("eng-GB", "nor-NO");
$ini->setVariable('RegionalSettings', 'SiteLanguageList', $languageList);
eZContentLanguage::clearPrioritizedLanguages();
$row = eZURLAliasML::choosePrioritizedRow($rows);
// The prioritzed language should be 'eng-GB' (lang_mask = 2)
self::assertEquals(2, $row["lang_mask"]);
// -------------------------------------------------------------------
// TEST PART 2 - REVERSED PRIORITIZATION -----------------------------
// Reverse the order of the specified languages, this will also
// reverse the priority.
$languageList = array_reverse($languageList);
$ini->setVariable('RegionalSettings', 'SiteLanguageList', $languageList);
eZContentLanguage::clearPrioritizedLanguages();
$row = eZURLAliasML::choosePrioritizedRow($rows);
// The prioritzed language should be 'nor-NO' (lang_mask = 4)
self::assertEquals(4, $row["lang_mask"]);
// -------------------------------------------------------------------
// TEST TEAR DOWN ----------------------------------------------------
$ini->setVariable('RegionalSettings', 'ShowUntranslatedObjects', $orgShowUntranslatedObjects);
$ini->setVariable('RegionalSettings', 'SiteLanguageList', $orgSiteLanguageList);
// -------------------------------------------------------------------
}