网络营销电子商务研究中心

网络营销电子商务研究中心 (https://www.0058.net/index.php)
-   Web Directory (https://www.0058.net/forumdisplay.php?f=60)
-   -   Full Article Rewrite [phpld 3.3] (https://www.0058.net/showthread.php?t=3212)

car 2008-04-23 08:22 PM

Full Article Rewrite [phpld 3.3]
 
Mod Title: Full Article Rewrite

Last Updated: 19 Jan. 2008

Supported by Mod Developer: Yes

This mod upgrades the simplistic article rewrite from phpLD 3.3. After installing this mod your article URLs will turn from http://www.mydirectory.com/articles/article-239.html to http://www.mydirectory.com/articles/...itle-here.html
Important: backup all files before modifying them!

Open admin/article_edit.php
Find
if ($action == 'N')
{
$data['DATE_ADDED'] = gmdate ('Y-m-d H:i:s');
}
Replace with
if ($action == 'N')
{
$data['DATE_ADDED'] = gmdate ('Y-m-d H:i:s');
$data['TITLE_REWRITE'] = preg_replace ('`[^\w_-]+`', '-', $data['TITLE']);
}
Open submit_article.php
Find
$data['META_KEYWORDS'] = (!empty ($data['META_KEYWORDS']) ? clean_meta_keywords($data['META_KEYWORDS']) : '');
Replace with
$data['META_KEYWORDS'] = (!empty ($data['META_KEYWORDS']) ? clean_meta_keywords($data['META_KEYWORDS']) : '');
$data['TITLE_REWRITE'] = preg_replace ('`[^\w_-]+`', '-', $data['TITLE']);
Open include/tables.php
Find
$tables['article'] = array (
'name' => TABLE_PREFIX.'ARTICLE' ,
'fields' => array (
'ID' => 'I KEY AUTO' ,
'TITLE' => 'C(255) NOTNULL' ,
Replace with
$tables['article'] = array (
'name' => TABLE_PREFIX.'ARTICLE' ,
'fields' => array (
'ID' => 'I KEY AUTO' ,
'TITLE' => 'C(255) NOTNULL' ,
'TITLE_REWRITE' => 'C(255) NOTNULL' ,
Find
$tables['article_review'] = array (
'name' => TABLE_PREFIX.'ARTICLE_REVIEW' ,
'fields' => array (
'ID' => 'I KEY AUTO' ,
'TITLE' => 'C(255) NOTNULL' ,
Replace with
$tables['article_review'] = array (
'name' => TABLE_PREFIX.'ARTICLE_REVIEW' ,
'fields' => array (
'ID' => 'I KEY AUTO' ,
'TITLE' => 'C(255) NOTNULL' ,
'TITLE_REWRITE' => 'C(255) NOTNULL' ,
Open index.php
Find
//Article search
$search_preferences = array ();
$search_preferences['Select_Options'] = array ( '`ID`' ,
'`TITLE`' ,
Replace with
//Article search
$search_preferences = array ();
$search_preferences['Select_Options'] = array ( '`ID`' ,
'`TITLE`' ,
'`TITLE_REWRITE`' ,
Open .htaccess
Find
RewriteRule (.*)articles/article-(.*)\.htm[l]?$ article.php [QSA,NC]
Replace with
RewriteRule (.*)articles/(.*)\.htm[l]?$ article.php [QSA,NC]
Open article.php
Find (around line 158)
elseif (ENABLE_REWRITE == 1)
{
preg_match ('#(.*)article(_|-)(\d+)\.htm[l]?$#i', request_uri(), $matches);
$id = (!empty ($matches[3]) ? intval ($matches[3]) : 0);
}
Replace with
elseif (ENABLE_REWRITE == 1)
{
preg_match ('`articles/([\w_-]+)\.htm[l]?$`', request_uri(), $matches);
$rdata = $db->GetRow("SELECT `ID` FROM `{$tables['article']['name']}` WHERE `TITLE_REWRITE` = '$matches[1]'");
if (!$rdata)
{
$tpl->assign('error', "Invalid article title - not found in database");
$id = 0;
}
else
{
$id = $rdata['ID'];
}
}
Now you have to edit the template files that reference articles. The general rule is to replace anything that references
articles/article-{$article.ID}.html
with
articles/{$article.TITLE_REWRITE}.html
NOTE: $article is just a random name. It could appear as $val, $latest_search[i] etc depending on your template. You have to replace it keeping the same variable name (i.e. $val.TITLE_REWRITE, $latest_search[i].TITLE_REWRITE)

For example, for the Professional template (the default that comes with 3.3) you have to make the replacements in
templates/Professional/articlelink.tpl
templates/Professional/article_search.tpl
templates/Professional/rightside.tpl
Run these SQL queries from the phpLD admin System->Database page or from phpMyAdmin

ALTER TABLE `PLD_ARTICLE` ADD `TITLE_REWRITE` VARCHAR( 255 ) NOT NULL AFTER `TITLE`
ALTER TABLE `PLD_ARTICLE_REVIEW` ADD `TITLE_REWRITE` VARCHAR( 255 ) NOT NULL AFTER `TITLE`
UPDATE `PLD_ARTICLE` SET `TITLE_REWRITE`=CONCAT('article-', `ID`)
UPDATE `PLD_ARTICLE_REVIEW` SET `TITLE_REWRITE`=CONCAT('article-', `ID`)


All times are GMT +8. The time now is 09:17 PM.

Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.