zen cart 函数:zen_href_link

  1.    function  zen_href_link( $page  =  ''$parameters  =  ''$connection  =  'NONSSL'$add_session_id  = true,  $search_engine_safe  = true,  $static  = false,  $use_dir_ws_catalog  = true) {  
  2.     global   $request_type$session_started$http_domain$https_domain ;  
  3.     if  (!zen_not_null( $page )) {  
  4.       die ( '</td></tr></table></td></tr></table><br /><br /><b class="note">Error!<br /><br />Unable to determine the page link!</b><br /><br /><!--'  .  $page  .  '<br />'  .  $parameters  .  ' -->' );  
  5.     }  
  6.     if  ( $connection  ==  'NONSSL' ) {  
  7.       $link  = HTTP_SERVER;  
  8.     } elseif  ( $connection  ==  'SSL' ) {  
  9.       if  (ENABLE_SSL ==  'true' ) {  
  10.         $link  = HTTPS_SERVER ;  
  11.       } else  {  
  12.         $link  = HTTP_SERVER;  
  13.       }  
  14.     } else  {  
  15.       die ( '</td></tr></table></td></tr></table><br /><br /><b class="note">Error!<br /><br />Unable to determine connection method on a link!<br /><br />Known methods: NONSSL SSL</b><br /><br />' );  
  16.     }  
  17.     if  ( $use_dir_ws_catalog ) {  
  18.       if  ( $connection  ==  'SSL'  && ENABLE_SSL ==  'true' ) {  
  19.         $link  .= DIR_WS_HTTPS_CATALOG;  
  20.       } else  {  
  21.         $link  .= DIR_WS_CATALOG;  
  22.       }  
  23.     }  
  24.     if  (! $static ) {  
  25.       if  (zen_not_null( $parameters )) {  
  26.         $link  .=  'index.php?main_page='$page  .  "&"  . zen_output_string( $parameters );  
  27.       } else  {  
  28.         $link  .=  'index.php?main_page='  .  $page ;  
  29.       }  
  30.     } else  {  
  31.       if  (zen_not_null( $parameters )) {  
  32.         $link  .=  $page  .  "?"  . zen_output_string( $parameters );  
  33.       } else  {  
  34.         $link  .=  $page ;  
  35.       }  
  36.     }  
  37.     $separator  =  '&' ;  
  38.     while  ( ( substr ( $link , -1) ==  '&' ) || ( substr ( $link , -1) ==  '?' ) )  $link  =  substr ( $link , 0, -1);  
  39. // Add the session ID when moving from different HTTP and HTTPS servers, or when SID is defined   
  40.     if  ( ( $add_session_id  == true) && ( $session_started  == true) && (SESSION_FORCE_COOKIE_USE ==  'False' ) ) {  
  41.       if  (defined( 'SID' ) && zen_not_null(SID)) {  
  42.         $sid  = SID;  
  43. //      } elseif ( ( ($request_type == 'NONSSL') && ($connection == 'SSL') && (ENABLE_SSL_ADMIN == 'true') ) || ( ($request_type == 'SSL') && ($connection == 'NONSSL') ) ) {   
  44.       } elseif  ( ( ( $request_type  ==  'NONSSL' ) && ( $connection  ==  'SSL' ) && (ENABLE_SSL ==  'true' ) ) || ( ( $request_type  ==  'SSL' ) && ( $connection  ==  'NONSSL' ) ) ) {  
  45.         if  ( $http_domain  !=  $https_domain ) {  
  46.           $sid  = zen_session_name() .  '='  . zen_session_id();  
  47.         }  
  48.       }  
  49.     }  
  50. // clean up the link before processing   
  51.     while  ( strstr ( $link'&&' ))  $link  =  str_replace ( '&&''&'$link );  
  52.     while  ( strstr ( $link'&&' ))  $link  =  str_replace ( '&&''&'$link );  
  53.     if  ( (SEARCH_ENGINE_FRIENDLY_URLS ==  'true' ) && ( $search_engine_safe  == true) ) {  
  54.       while  ( strstr ( $link'&&' ))  $link  =  str_replace ( '&&''&'$link );  
  55.       $link  =  str_replace ( '&''/'$link );  
  56.       $link  =  str_replace ( '?''/'$link );  
  57.       $link  =  str_replace ( '&''/'$link );  
  58.       $link  =  str_replace ( '=''/'$link );  
  59.       $separator  =  '?' ;  
  60.     }  
  61.     if  (isset( $sid )) {  
  62.       $link  .=  $separator  . zen_output_string( $sid );  
  63.     }  
  64. // clean up the link after processing   
  65.     while  ( strstr ( $link'&&' ))  $link  =  str_replace ( '&&''&'$link );  
  66.     $link  = preg_replace( '/&/''&'$link );  
  67.     return   $link ;  
  68.   }  

zen_href_link 函数位于 /includes/functions/html_output.php 文件中,主要用于输出超级链接。它的参数如下表所示:

$page 这个变量通常由 /includes/filename.php 文件中的常量取得
   
$parameters  
   
$connection  
   
$add_session_id  
   
$search_engine_safe  
   
$static  
   
$use_dir_ws_catalog  

第一行代码,定义了 global 变量:$request_type,$session_started,$http_domain 和 $https_domain。(global 的作用是定义全局变量,但是这个全局变量不是应用于整个网站,而是应用于当前页面,包括 include 或 require 的所有文件。在函数体内定义的 global 变量,函数体外可以使用,在函数体外定义的 global 变量不能在函数体内使用。)

接下来的代码,

 

  1. if  (!zen_not_null( $page ))  

判断传递过来的 $page 变量是否为空。zen_not_null 函数,看名字猜,应该是判断它的参数不为空。前面加了一个逻辑非符号 !,这个条件语句的结果应该是,如果 $page 为空,则执行以下代码:

 

  1. die ( '</td></tr></table></td></tr></table><br /><br /><b class="note">Error!<br /><br />Unable to determine the page link!</b><br /><br /><!--'  .  $page  .  '<br />'  .  $parameters  .  ' -->' );  

输出 die 后面括号的内容,然后中止程序执行。输出内容的后半部分容易理解,就是发出一条无法判断页面链接的警告。前半部分,只有关闭的 html 标签,table 的前面部分标签,还不知道是在哪里,有待研究。

然后,根据 $connection 参数,来决定是 http:// 链接,还是 https:// 链接。HTTP_SERVER 这个常量可以在 /includes/configure.php 文件中找到,实际就是网站的根目录。然后把 HTTP_SERVER 这个常量值赋值给 $link 这个变量。

如果 $connection 传递过来的,既不是 NONSSL,也不是 SSL,则会输出错误信息,然后中止执行程序。

判断参数 $use_dir_ws_catalog 是否为真,如果不是,则不执行任何代码,如果为真,执行以下代码:

 

  1. if  ( $connection  ==  'SSL'  && ENABLE_SSL ==  'true' ) {  
  2.         $link  .= DIR_WS_HTTPS_CATALOG;  
  3.       } else  {  
  4.         $link  .= DIR_WS_CATALOG;  
  5.       }  

由于 $use_dir_ws_catalog 默认为真,所以将执行以上代码。这个是一个条件语句,如果 $connection 的值为 SSL,并且 ENABLE_SSL 这个常量为真,则把 DIR_WS_HTTPS_CATALOG 这个常量赋值给 $link;否则将把 DIR_WS_CATALOG 这个常量赋值给 $link。ENABLE_SSL,DIR_WS_HTTPS_CATALOG 和 DIR_WS_CATALOG 这三个常量都可以 /includes/configure.php 文件中找到。

下面看一个实例:

 

  1. zen_href_link(FILENAME_LOGIN,  '''SSL' );  

以上代码,将产生以下的超级链接:

 

  1. http: //zencart/index.php?main_page=login&zenid=5n4b36fqt06jj9pciqtd1v3fs0   

FILENAME_LOGIN 这个常量在 /includes/filenames.php 文件中被定义。

 

  1. define( 'FILENAME_LOGIN''login' );  

接下来将判断 $static 这个变量的真假,如果不为真,则执行以下代码:

 

  1. if  (! $static ) {  
  2.   if  (zen_not_null( $parameters )) {  
  3.     $link  .=  'index.php?main_page='$page  .  "&"  . zen_output_string( $parameters );  
  4.   } else  {  
  5.     $link  .=  'index.php?main_page='  .  $page ;  
  6.   }  
  7. else  {  
  8.   if  (zen_not_null( $parameters )) {  
  9.     $link  .=  $page  .  "?"  . zen_output_string( $parameters );  
  10.   } else  {  
  11.     $link  .=  $page ;  
  12.   }  
  13. }  

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值