Phpcms Chinese URL Path resolution method

Source: Internet
Author: User
Tags chmod eval explode php tutorial strlen
How does the PHP tutorial CMS support Chinese path? Phpcms Chinese URL How to set it?
I'm going to come down here.
First, in the phpcms include directory, there are global.func.php files.
The function createhtml ($file) is found.
Description, this function is used to generate HTML static files.
We just need to modify this function.
Modified as follows:
View Plaincopy to Clipboardprint?
    1. function createhtml ($file)   
    2. {  
    3.   &NB Sp; //scofield 2010-3-16   
    4.     //for create file  as chinses name   
    5.      $file  = iconv (' UTF-8 ',   ' GBK ',  $file);   
    6.   
    7.      $data  = ob_get_contents ();    
    8.     ob_clean ();   
    9.     dir_create ( DirName ($file));   
    10.      $strlen  = file_put_contents ($file,  $data);    
    11.      @chmod ($file, 0777);   
    12.     return& N. $strlen; nbsp.   
    13. }  
function createhtml ($file)
{
	//scofield 2010-3-16
	//for create file as chinses name
	$file = Iconv (' UTF-8 ', ' GBK ', $file);

	$data = Ob_get_contents ();
	Ob_clean ();
	Dir_create (DirName ($file));
	$strlen = File_put_contents ($file, $data);
	@chmod ($file, 0777);
	return $strlen;
}
$file = Iconv (' utf-8′, ' GBK ', $file); This sentence was mainly added. This sentence implements the code conversion. The resulting HTML file or path can be in Chinese.
Second, there are include/url.class.php this file in the Include directory.
When you open it, find the function show ($contentid, $page = 0, $catid = 0, $time = 0, $prefix = ").
Add the following statement
View Plaincopy to Clipboardprint?
  1. Scofield 2010-3-16
  2. Get root category Name
  3. $catetemp = $this->db->get_one ("SELECT * from".) Db_pre. " Category ' WHERE catid = $catid LIMIT 1 ');
  4. $arrparentidarr = Explode (', ', $catetemp [' Arrparentid ']);
  5. $rootidtemp = $arrparentidarr [Count ($arrparentidarr)-1];
  6. $rootcatetemp = $this->db->get_one ("SELECT * from".) Db_pre. " Category ' WHERE catid = $rootidtemp LIMIT 1 ');
  7. $rootcatename = $rootcatetemp [' catname '];
  8. For URL roles add content title and category name
  9. $showtitle = Strip_tags ($r [' title ']);
  10. $catdirname = $C [' catname '];
Scofield 2010-3-16
//get root category name
$catetemp = $this->db->get_one ("SELECT * from". Db_pre. " Category ' WHERE  catid = $catid  LIMIT 1 ');
$arrparentidarr = Explode (', ', $catetemp [' Arrparentid ']);
$rootidtemp = $arrparentidarr [Count ($arrparentidarr)-1];
$rootcatetemp = $this->db->get_one ("SELECT * from".) Db_pre. " Category ' WHERE  catid = $rootidtemp LIMIT 1 ');
$rootcatename = $rootcatetemp [' catname '];
For URL roles add content title and category name
$showtitle = strip_tags ($r [' title ']);
$catdirname = $C [' catname '];
The complete function is as follows:
View Plaincopy to Clipboardprint?
  1. Function Show ($contentid, $page = 0, $catid = 0, $time = 0, $prefix = ')
  2. {
  3. Global $PHPCMS;
  4. if ($catid = = 0 | | $time = 0 | | $prefix = = ")
  5. {
  6. $r = $this->db->get_one ("SELECT * from".) Db_pre. " Content ' WHERE ' contentid ' = ' $contentid ');
  7. if ($r [' Isupgrade '] &&!emptyempty ($r [' url '])
  8. {
  9. if ($page >1)
  10. {
  11. $base _name = basename ($r [' url ']);
  12. $fileext = Fileext ($base _name);
  13. $url _a[0] = $url _a[1] = preg_replace ('/. '). $fileext. ' $/', ' _ '. $page. '. $fileext, $r [' url ']);
  14. return $url _a;
  15. }
  16. Else
  17. {
  18. $url _a[0] = $url _a[1] = $r [' url '];
  19. return $url _a;
  20. }
  21. }
  22. $catid = $r [' catid '];
  23. $time = $r [' Inputtime '];
  24. if (! $prefix) $prefix = $r [' prefix '];
  25. }
  26. if (!isset ($this->category[$catid]) return false;
  27. $C = Cache_read (' Category_ '. $catid. php ', ', 1);
  28. $tag = 0;
  29. if (Preg_match ('/:///', $C [' url ']))
  30. {
  31. $tag = 1;
  32. $arr _url = preg_split ('///', $C [' url ']);
  33. $domain = ' http://'. $arr _url[2];
  34. $domain 1 = ' http://'. $arr _url[2]. ' /';
  35. $info = $this->db->get_one ("SELECT * from".) Db_pre. " Category ' WHERE ' url ' in (' $domain ', ' $domain 1 ') LIMIT 1 ");
  36. $crootdir = $info [' Parentdir ']. $info [' Catdir ']. ' /';
  37. }
  38. $categorydir = $C [' Parentdir ']. $C [' Catdir '];
  39. $catdir = $C [' Catdir '];
  40. Scofield 2010-3-16
  41. For URL roles add content title and category name
  42. $showtitle = Strip_tags ($r [' title ']);
  43. $catdirname = $C [' catname '];
  44. Scofield 2010-3-16
  45. Get root category Name
  46. $catetemp = $this->db->get_one ("SELECT * from".) Db_pre. " Category ' WHERE catid = $catid LIMIT 1 ');
  47. $arrparentidarr = Explode (', ', $catetemp [' Arrparentid ']);
  48. $rootidtemp = $arrparentidarr [Count ($arrparentidarr)-1];
  49. if ($rootidtemp)
  50. {
  51. $rootcatetemp = $this->db->get_one ("SELECT * from".) Db_pre. " Category ' WHERE catid = $rootidtemp LIMIT 1 ');
  52. $rootcatename = $rootcatetemp [' catname '];
  53. }else
  54. {
  55. $rootcatename = $catdirname;
  56. }
  57. $fileext = $this->phpcms[' Fileext '];
  58. $year = Date (' Y ', $time);
  59. $month = Date (' m ', $time);
  60. $day = Date (' d ', $time);
  61. $modelid = $C [' ModelID '];
  62. $urlruleid = $this->model[$modelid] [' Show_urlruleid '];
  63. $urlrules = Explode (' | ', $this->urlrule[$urlruleid]);
  64. $urlrule = $page < 2? $urlrules [0]: $urlrules [1];
  65. if ($this->model[$modelid] [' ishtml '])
  66. {
  67. if ($prefix)
  68. {
  69. $contentid = $prefix;
  70. }
  71. ElseIf ($PHPCMS [' Enable_urlencode '])
  72. {
  73. $contentid = hash_string ($contentid);
  74. }
  75. }
  76. Eval ("$url =" $urlrule ";");
  77. if ($tag)
  78. {
  79. if (!) ( Strpos ($url, $crootdir) ===0))
  80. {
  81. $url = $crootdir. $url;
  82. }
  83. $url _a[0] = $url;
  84. $url _a[1] = $domain 1.str_replace ($crootdir, ', $url);
  85. }
  86. Else
  87. {
  88. $url _a[0] = $url _a[1] = $url;
  89. }
  90. return $url _a;
  91. }
Function Show ($contentid, $page = 0, $catid = 0, $time = 0, $prefix = ') {global $PHPCMS; if ($catid = = 0 | | $time = = 0 | | | $prefix = = ") {$r = $this-&gt;db-&gt;get_one (" SELECT * from ". Db_pre. "
        Content ' WHERE ' contentid ' = ' $contentid '); if ($r [' Isupgrade '] &amp;&amp;!empty ($r [' url ']) {if ($page &gt;1) {$base _
                Name = basename ($r [' url ']);
                $fileext = Fileext ($base _name); $url _a[0] = $url _a[1] = preg_replace ('/. '). $fileext. ' $/', ' _ '. $page. '.
                $fileext, $r [' url ']);
            return $url _a;
                else {$url _a[0] = $url _a[1] = $r [' url '];
            return $url _a;
        }} $catid = $r [' catid '];
        $time = $r [' Inputtime '];
    if (! $prefix) $prefix = $r [' prefix '];
    if (!isset ($this-&gt;category[$catid]) return false; $C = Cache_read (' Category_ '. $catid.
    php ', ', 1);
    $tag = 0; IF (Preg_match ('/:///', $C [' url ']) {$tag = 1;
        $arr _url = preg_split ('///', $C [' url ']);
        $domain = ' http://'. $arr _url[2]; $domain 1 = ' http://'. $arr _url[2]. '
        /'; $info = $this-&gt;db-&gt;get_one ("SELECT * from".) Db_pre. "
        Category ' WHERE ' url ' in (' $domain ', ' $domain 1 ') LIMIT 1 "); $crootdir = $info [' Parentdir ']. $info [' Catdir ']. '
    /';
    $categorydir = $C [' Parentdir ']. $C [' Catdir '];

    $catdir = $C [' Catdir '];
    Scofield 2010-3-16//for URL roles add content title and category name $showtitle = strip_tags ($r [' title ']);

    $catdirname = $C [' catname ']; Scofield 2010-3-16//get root category name $catetemp = $this-&gt;db-&gt;get_one ("SELECT * from". Db_pre. "
    Category ' WHERE catid = $catid LIMIT 1 ');
    $arrparentidarr = Explode (', ', $catetemp [' Arrparentid ']);
    $rootidtemp = $arrparentidarr [Count ($arrparentidarr)-1]; if ($rootidtemp) {$rootcatetemp = $this-&gt;db-&gt;get_one ("SELECT * from"". Db_pre. "
        Category ' WHERE catid = $rootidtemp LIMIT 1 ');
    $rootcatename = $rootcatetemp [' catname '];
    }else {$rootcatename = $catdirname;
    $fileext = $this-&gt;phpcms[' Fileext '];
    $year = Date (' Y ', $time);
    $month = Date (' m ', $time);
    $day = Date (' d ', $time);
    $modelid = $C [' ModelID '];
    $urlruleid = $this-&gt;model[$modelid] [' Show_urlruleid '];
    $urlrules = Explode (' | ', $this-&gt;urlrule[$urlruleid]); $urlrule = $page &lt; 2?
    $urlrules [0]: $urlrules [1];
        if ($this-&gt;model[$modelid] [' ishtml ']) {if ($prefix) {$contentid = $prefix;
        } elseif ($PHPCMS [' Enable_urlencode ']) {$contentid = hash_string ($contentid);
    } eval ("$url = $urlrule;"); if ($tag) {if (!) (
        Strpos ($url, $crootdir) ===0)) {$url = $crootdir. $url;
        } $url _a[0] = $url;
   $url _a[1] = $domain 1.str_replace ($crootdir, ', $url); else {$url _a[0] = $url _a[1] = $url;
return $url _a; }
Description, this function is the function to use to generate the content page for the article.
Similarly, there is a function category ($catid, $page = 0, $isurls = 0, $type = 3) in this file.
Also need to be modified. Add the following code
View plaincopy to Clipboardprint?
  1. //scofield 2010-3-16 add   
  2. $catdirname  =& nbsp. $C [' catname '];   
  3.   
  4. //scofield 2010-3-16   
  5. //get root  Category name   
  6. $parentidtemp  =  $C [' ParentID '];   
  7. $catetemp  =  $this->db->get_one ("select * from "). Db_pre. " Category '  WHERE  catid =  $parentidtemp   limit 1 ');   
  8. $parentcatename  =  $catetemp [' catname ']. /'. $catdirname;   
Scofield 2010-3-16 Add
$catdirname = $C [' catname '];

Scofield 2010-3-16
//get root category name
$parentidtemp = $C [' ParentID '];
$catetemp = $this->db->get_one ("SELECT * from".) Db_pre. " Category ' WHERE  catid = $parentidtemp  LIMIT 1 ');
$parentcatename = $catetemp [' CatName ']. /'. $catdirname;
The complete function code is as follows:
View Plaincopy to Clipboardprint?
  1. function category ($catid, $page = 0, $isurls = 0, $type = 3)
  2. {
  3. if (!isset ($this->category[$catid]) return false;
  4. $C = Cache_read (' Category_ '. $catid. php ', ', 1);
  5. if ($C [' type '] = = 0)
  6. {
  7. $modelid = $C [' ModelID '];
  8. $urlruleid = $this->model[$modelid] [' Category_urlruleid '];
  9. }
  10. ElseIf ($C [' type '] = = 1)
  11. {
  12. $urlruleid = $C [' Category_urlruleid '];
  13. }
  14. ElseIf ($C [' type '] = = 2)
  15. {
  16. return $C [' url '];
  17. }
  18. if (Is_numeric ($page)) $page = Intval ($page);
  19. $arrparentids = Explode (', ', $C [' Arrparentid ']);
  20. $domain _dir = $domain _url = ';
  21. if (Preg_match ('/:///', $C [' url ']) && (Substr_count ($C [' url '], '/') <4))
  22. {
  23. $url _a[0] = $C [' Parentdir ']. $C [' Catdir ']. ' /index. '. $this->phpcms[' Fileext '];
  24. $url _a[1] = $C [' url '];
  25. Return $type <3? $url _a[$type]: $url _a;
  26. }
  27. Else
  28. {
  29. $count = count ($arrparentids)-1;
  30. for ($i = $count; $i >=0; $i-)
  31. {
  32. if (Preg_match ('/:///', $this->category[$arrparentids [$i]][' url ']) && substr_count ($this->category[ $arrparentids [$i]][' url '], '/') <4)
  33. {
  34. $domain _dir = $this->category[$arrparentids [$i]][' Parentdir ']. $this->category[$arrparentids [$i]][' Catdir '] .' /';
  35. $domain _url = $this->category[$arrparentids [$i]][' url '];
  36. Break
  37. }
  38. }
  39. }
  40. $categorydir = $C [' Parentdir ']. $C [' Catdir '];
  41. $catdir = $C [' Catdir '];
  42. Scofield 2010-3-16 Add
  43. $catdirname = $C [' catname '];
  44. Scofield 2010-3-16
  45. Get root category Name
  46. $parentidtemp = $C [' ParentID '];
  47. $catetemp = $this->db->get_one ("SELECT * from".) Db_pre. " Category ' WHERE catid = $parentidtemp LIMIT 1 ');
  48. $parentcatename = $catetemp [' CatName ']. /'. $catdirname;
  49. $fileext = $this->phpcms[' Fileext '];
  50. $urlrules = Explode (' | ', $this->urlrule[$urlruleid]);
  51. $urlrule = $page = = 0? $urlrules [0]: $urlrules [1];
  52. Eval ("$url =" $urlrule ";");
  53. if ($C [' type ']==0 && $this->model[$modelid] [' ishtml '] && $domain _dir)
  54. {
  55. if (Strpos ($url, $domain _dir) ===false)
  56. {
  57. $url _a[0] = $domain _dir. $url;
  58. }
  59. Else
  60. {
  61. $url _a[0] = $url;
  62. }
  63. $url _a[1] = str_replace ($domain _dir, $domain _url. /', $url _a[0]);
  64. }
  65. Else
  66. {
  67. $url _a[0] = $url _a[1] = $url;
  68. }
  69. Return $type <3? $url _a[$type]: $url _a;
  70. }
function category ($catid, $page = 0, $isurls = 0, $type = 3) {if (!isset ($this-&gt;category[$catid)) return false; $C = Cache_read (' Category_ '. $catid.
    php ', ', 1);
        if ($C [' type '] = = 0) {$modelid = $C [' ModelID '];
    $urlruleid = $this-&gt;model[$modelid] [' Category_urlruleid '];
    } elseif ($C [' type '] = = 1) {$urlruleid = $C [' Category_urlruleid '];
    } elseif ($C [' type '] = = 2) {return $C [' url '];
    if (Is_numeric ($page)) $page = Intval ($page);
    $arrparentids = Explode (', ', $C [' Arrparentid ']);
    $domain _dir = $domain _url = '; if (Preg_match ('/:///', $C [' url ']) &amp;&amp; (Substr_count ($C [' url '], '/') &lt;4)} {$url _a[0] = $C [' Parentdir ' ]. $C [' Catdir ']. ' /index. '.
        $this-&gt;phpcms[' Fileext '];
        $url _a[1] = $C [' url ']; Return $type &lt;3?
    $url _a[$type]: $url _a;
        else {$count = count ($arrparentids)-1; for ($i = $count; $i &gt;=0; $i-) {if (preg_mAtch ('/:///', $this-&gt;category[$arrparentids [$i]][' url ']) &amp;&amp; substr_count ($this-&gt;category[$ arrparentids[$i]][' url '], '/') &lt;4) {$domain _dir = $this-&gt;category[$arrparentids [$i]][' P Arentdir ']. $this-&gt;category[$arrparentids [$i]][' Catdir ']. '
                /';
                $domain _url = $this-&gt;category[$arrparentids [$i]][' url '];
            Break
    $categorydir = $C [' Parentdir ']. $C [' Catdir '];

    $catdir = $C [' Catdir '];

    Scofield 2010-3-16 Add $catdirname = $C [' catname '];
    Scofield 2010-3-16//get root category name $parentidtemp = $C [' ParentID ']; $catetemp = $this-&gt;db-&gt;get_one ("SELECT * from".) Db_pre. "
    Category ' WHERE catid = $parentidtemp LIMIT 1 '); $parentcatename = $catetemp [' CatName '].

    /'. $catdirname;
    $fileext = $this-&gt;phpcms[' Fileext '];
    $urlrules = Explode (' | ', $this-&gt;urlrule[$urlruleid]); $urlrule = $page = = 0?
    $urlrules [0]: $urlrules [1]; EvaL ("$url = $urlrule"; "); if ($C [' type ']==0 &amp;&amp; $this-&gt;model[$modelid] [' ishtml '] &amp;&amp; $domain _dir) {if Strpos ($url, $dom
        Ain_dir) ===false) {$url _a[0] = $domain _dir. $url;
        else {$url _a[0] = $url; } $url _a[1] = str_replace ($domain _dir, $domain _url. '
    /', $url _a[0]);
    else {$url _a[0] = $url _a[1] = $url; Return $type &lt;3?
$url _a[$type]: $url _a; }
Note that in the Show method, there are more $showtitle, $catdirname, $rootcatename these three variables. The first is the title of the content, the second is the name of the current category, and the third is the name of the parent category of the category.
This allows you to generate a path similar to the http://www.aa.com/Category 1/Heading _1.html.
Of course, we also need to change the URL rule in the phpcms background to enable PHPCMS to support the Chinese path. Let's talk about this below.
Let's look at the category method again. There are a few more variables to use. $catdirname, $parentcatename The first is the name of the current category and the second is the name of the parent category of the category.
For these variables, we need to change the Phpcms URL rules.
In PHPCMS background-> system administration-> Other settings->url rule Management-> Admin URL rules.
We found
Phpcms Category {$categorydir}/index. {$fileext}| {$categorydir}/{$page}. {$fileext} It/product/2.html Modify | Delete
This line, the revision changed to
Phpcms Category {$parentcatename}/index. {$fileext}| {$parentcatename}/{$page}. {$fileext} It/product/2.html Modify | Delete
And then the
Phpcms Category {$catdir}/index. {$fileext}| {$catdir}/{$page}. {$fileext} News/2_1.html Modify | Delete
Amended to
Phpcms Category {$parentcatename}/index. {$fileext}| {$parentcatename}/{$page}. {$fileext} News/2_1.html Modify | Delete
And then the
Phpcms Show {$year}/{$month} {$day}/{$contentid}.} {$fileext}| {$year}/{$month} {$day}/{$contentid}_{$page}. {$fileext} 2006/1010/1_2.html Modify | Delete
Amended to
Phpcms Show {$rootcatename}/{$showtitle}_{$contentid}. {$fileext}| {$rootcatename}/{$showtitle}_{$contentid}_{$page}. {$fileext} Product/1_2.html Modify | Delete
The modified URL rule will support the Chinese path.
After the above setup and modification, we enable PHPCMS to support the Chinese path and support the Chinese URL.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.