当前位置: 首页>>代码示例>>PHP>>正文


PHP eZURLAliasML::reverseTranslate方法代码示例

本文整理汇总了PHP中eZURLAliasML::reverseTranslate方法的典型用法代码示例。如果您正苦于以下问题:PHP eZURLAliasML::reverseTranslate方法的具体用法?PHP eZURLAliasML::reverseTranslate怎么用?PHP eZURLAliasML::reverseTranslate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在eZURLAliasML的用法示例。


在下文中一共展示了eZURLAliasML::reverseTranslate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: translate

 public static function translate(&$uri, $reverse = false)
 {
     if ($uri instanceof eZURI) {
         $uriString = $uri->elements();
     } else {
         $uriString = $uri;
     }
     $uriString = eZURLAliasML::cleanURL($uriString);
     $internalURIString = $uriString;
     $originalURIString = $uriString;
     $ini = eZINI::instance();
     $prefixAdded = false;
     $prefix = $ini->hasVariable('SiteAccessSettings', 'PathPrefix') && $ini->variable('SiteAccessSettings', 'PathPrefix') != '' ? eZURLAliasML::cleanURL($ini->variable('SiteAccessSettings', 'PathPrefix')) : false;
     if ($prefix) {
         $escapedPrefix = preg_quote($prefix, '#');
         // Only prepend the path prefix if it's not already the first element of the url.
         if (!preg_match("#^{$escapedPrefix}(/.*)?\$#i", $uriString)) {
             $exclude = $ini->hasVariable('SiteAccessSettings', 'PathPrefixExclude') ? $ini->variable('SiteAccessSettings', 'PathPrefixExclude') : false;
             $breakInternalURI = false;
             foreach ($exclude as $item) {
                 $escapedItem = preg_quote($item, '#');
                 if (preg_match("#^{$escapedItem}(/.*)?\$#i", $uriString)) {
                     $breakInternalURI = true;
                     break;
                 }
             }
             if (!$breakInternalURI) {
                 $internalURIString = $prefix . '/' . $uriString;
                 $prefixAdded = true;
             }
         }
     }
     $db = eZDB::instance();
     $elements = explode('/', $internalURIString);
     $len = count($elements);
     if ($reverse) {
         return eZURLAliasML::reverseTranslate($uri, $uriString, $internalURIString);
     }
     $i = 0;
     $selects = array();
     $tables = array();
     $conds = array();
     foreach ($elements as $element) {
         $table = "e" . $i;
         $selectString = "{$table}.id AS {$table}_id, ";
         $selectString .= "{$table}.link AS {$table}_link, ";
         $selectString .= "{$table}.text AS {$table}_text, ";
         $selectString .= "{$table}.text_md5 AS {$table}_text_md5, ";
         $selectString .= "{$table}.is_alias AS {$table}_is_alias, ";
         if ($i == $len - 1) {
             $selectString .= "{$table}.action AS {$table}_action, ";
         }
         $selectString .= "{$table}.alias_redirects AS {$table}_alias_redirects";
         $selects[] = $selectString;
         $tables[] = "ezurlalias_ml " . $table;
         $langMask = trim(eZContentLanguage::languagesSQLFilter($table, 'lang_mask'));
         if ($i == 0) {
             $conds[] = "{$table}.parent = 0 AND ({$langMask}) AND {$table}.text_md5 = " . eZURLAliasML::md5($db, $element);
         } else {
             $conds[] = "{$table}.parent = {$prevTable}.link AND ({$langMask}) AND {$table}.text_md5 = " . eZURLAliasML::md5($db, $element);
         }
         $prevTable = $table;
         ++$i;
     }
     $query = "SELECT " . join(", ", $selects) . " FROM " . join(", ", $tables) . " WHERE " . join(" AND ", $conds);
     $return = false;
     $urlAliasArray = $db->arrayQuery($query, array('limit' => 1));
     if (count($urlAliasArray) > 0) {
         $pathRow = $urlAliasArray[0];
         $l = count($pathRow);
         $redirectLink = false;
         $redirectAction = false;
         $lastID = false;
         $action = false;
         $verifiedPath = array();
         $doRedirect = false;
         for ($i = 0; $i < $len; ++$i) {
             $table = "e" . $i;
             $id = $pathRow[$table . "_id"];
             $link = $pathRow[$table . "_link"];
             $text = $pathRow[$table . "_text"];
             $isAlias = $pathRow[$table . '_is_alias'];
             $aliasRedirects = $pathRow[$table . '_alias_redirects'];
             $verifiedPath[] = $text;
             if ($i == $len - 1) {
                 $action = $pathRow[$table . "_action"];
             }
             if ($link != $id) {
                 $doRedirect = true;
             } else {
                 if ($isAlias && $action !== false) {
                     if ($aliasRedirects) {
                         // If the entry is an alias and we have an action we redirect to the original
                         // url of that action.
                         $redirectAction = $action;
                         $doRedirect = true;
                     }
                 }
             }
             $lastID = $link;
//.........这里部分代码省略.........
开发者ID:patrickallaert,项目名称:ezpublish-legacy-php7,代码行数:101,代码来源:ezurlaliasml.php


注:本文中的eZURLAliasML::reverseTranslate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。