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.
View Plaincopy to Clipboardprint?
- function createhtml ($file)
- {
-   &NB Sp; //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& N. $strlen; nbsp.
- }
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?
- 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 '];
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?
- Function Show ($contentid, $page = 0, $catid = 0, $time = 0, $prefix = ')
- {
- Global $PHPCMS;
- if ($catid = = 0 | | $time = 0 | | $prefix = = ")
- {
- $r = $this->db->get_one ("SELECT * from".) Db_pre. " Content ' WHERE ' contentid ' = ' $contentid ');
- if ($r [' Isupgrade '] &&!emptyempty ($r [' url '])
- {
- if ($page >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->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->db->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->db->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->db->get_one ("SELECT * from".) Db_pre. " Category ' WHERE catid = $rootidtemp LIMIT 1 ');
- $rootcatename = $rootcatetemp [' catname '];
- }else
- {
- $rootcatename = $catdirname;
- }
- $fileext = $this->phpcms[' Fileext '];
- $year = Date (' Y ', $time);
- $month = Date (' m ', $time);
- $day = Date (' d ', $time);
- $modelid = $C [' ModelID '];
- $urlruleid = $this->model[$modelid] [' Show_urlruleid '];
- $urlrules = Explode (' | ', $this->urlrule[$urlruleid]);
- $urlrule = $page < 2? $urlrules [0]: $urlrules [1];
- if ($this->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;
- }
Function Show ($contentid, $page = 0, $catid = 0, $time = 0, $prefix = ') {global $PHPCMS; if ($catid = = 0 | | $time = = 0 | | | $prefix = = ") {$r = $this->db->get_one (" SELECT * from ". Db_pre. "
Content ' WHERE ' contentid ' = ' $contentid '); if ($r [' Isupgrade '] &&!empty ($r [' url ']) {if ($page >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->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->db->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->db->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->db->get_one ("SELECT * from"". Db_pre. "
Category ' WHERE catid = $rootidtemp LIMIT 1 ');
$rootcatename = $rootcatetemp [' catname '];
}else {$rootcatename = $catdirname;
$fileext = $this->phpcms[' Fileext '];
$year = Date (' Y ', $time);
$month = Date (' m ', $time);
$day = Date (' d ', $time);
$modelid = $C [' ModelID '];
$urlruleid = $this->model[$modelid] [' Show_urlruleid '];
$urlrules = Explode (' | ', $this->urlrule[$urlruleid]); $urlrule = $page < 2?
$urlrules [0]: $urlrules [1];
if ($this->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?
- //scofield 2010-3-16 add
- $catdirname =& nbsp. $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;
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?
- function category ($catid, $page = 0, $isurls = 0, $type = 3)
- {
- if (!isset ($this->category[$catid]) return false;
- $C = Cache_read (' Category_ '. $catid. php ', ', 1);
- if ($C [' type '] = = 0)
- {
- $modelid = $C [' ModelID '];
- $urlruleid = $this->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 ']) && (Substr_count ($C [' url '], '/') <4))
- {
- $url _a[0] = $C [' Parentdir ']. $C [' Catdir ']. ' /index. '. $this->phpcms[' Fileext '];
- $url _a[1] = $C [' url '];
- Return $type <3? $url _a[$type]: $url _a;
- }
- Else
- {
- $count = count ($arrparentids)-1;
- for ($i = $count; $i >=0; $i-)
- {
- if (Preg_match ('/:///', $this->category[$arrparentids [$i]][' url ']) && substr_count ($this->category[ $arrparentids [$i]][' url '], '/') <4)
- {
- $domain _dir = $this->category[$arrparentids [$i]][' Parentdir ']. $this->category[$arrparentids [$i]][' Catdir '] .' /';
- $domain _url = $this->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->db->get_one ("SELECT * from".) Db_pre. " Category ' WHERE catid = $parentidtemp LIMIT 1 ');
- $parentcatename = $catetemp [' CatName ']. /'. $catdirname;
- $fileext = $this->phpcms[' Fileext '];
- $urlrules = Explode (' | ', $this->urlrule[$urlruleid]);
- $urlrule = $page = = 0? $urlrules [0]: $urlrules [1];
- Eval ("$url =" $urlrule ";");
- if ($C [' type ']==0 && $this->model[$modelid] [' ishtml '] && $domain _dir)
- {
- if (Strpos ($url, $domain _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 <3? $url _a[$type]: $url _a;
- }
function category ($catid, $page = 0, $isurls = 0, $type = 3) {if (!isset ($this->category[$catid)) return false; $C = Cache_read (' Category_ '. $catid.
php ', ', 1);
if ($C [' type '] = = 0) {$modelid = $C [' ModelID '];
$urlruleid = $this->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 ']) && (Substr_count ($C [' url '], '/') <4)} {$url _a[0] = $C [' Parentdir ' ]. $C [' Catdir ']. ' /index. '.
$this->phpcms[' Fileext '];
$url _a[1] = $C [' url ']; Return $type <3?
$url _a[$type]: $url _a;
else {$count = count ($arrparentids)-1; for ($i = $count; $i >=0; $i-) {if (preg_mAtch ('/:///', $this->category[$arrparentids [$i]][' url ']) && substr_count ($this->category[$ arrparentids[$i]][' url '], '/') <4) {$domain _dir = $this->category[$arrparentids [$i]][' P Arentdir ']. $this->category[$arrparentids [$i]][' Catdir ']. '
/';
$domain _url = $this->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->db->get_one ("SELECT * from".) Db_pre. "
Category ' WHERE catid = $parentidtemp LIMIT 1 '); $parentcatename = $catetemp [' CatName '].
/'. $catdirname;
$fileext = $this->phpcms[' Fileext '];
$urlrules = Explode (' | ', $this->urlrule[$urlruleid]); $urlrule = $page = = 0?
$urlrules [0]: $urlrules [1]; EvaL ("$url = $urlrule"; "); if ($C [' type ']==0 && $this->model[$modelid] [' ishtml '] && $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 <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.
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 |
Phpcms |
Category |
√ |
{$catdir}/index. {$fileext}| {$catdir}/{$page}. {$fileext} |
News/2_1.html |
Modify | Delete |
Phpcms |
Category |
√ |
{$parentcatename}/index. {$fileext}| {$parentcatename}/{$page}. {$fileext} |
News/2_1.html |
Modify | Delete |
Phpcms |
Show |
√ |
{$year}/{$month} {$day}/{$contentid}.} {$fileext}| {$year}/{$month} {$day}/{$contentid}_{$page}. {$fileext} |
2006/1010/1_2.html |
Modify | Delete |
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.