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/your-article-title-here.html
Important: backup all files before modifying them!
- Open admin/article_edit.php
FindReplace withif ($action == 'N') { $data['DATE_ADDED'] = gmdate ('Y-m-d H:i:s'); }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
FindReplace with$data['META_KEYWORDS'] = (!empty ($data['META_KEYWORDS']) ? clean_meta_keywords($data['META_KEYWORDS']) : '');
$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
FindReplace with$tables['article'] = array ( 'name' => TABLE_PREFIX.'ARTICLE' , 'fields' => array ( 'ID' => 'I KEY AUTO' , 'TITLE' => 'C(255) NOTNULL' ,
Find$tables['article'] = array ( 'name' => TABLE_PREFIX.'ARTICLE' , 'fields' => array ( 'ID' => 'I KEY AUTO' , 'TITLE' => 'C(255) NOTNULL' , 'TITLE_REWRITE' => 'C(255) NOTNULL' ,
Replace with$tables['article_review'] = array ( 'name' => TABLE_PREFIX.'ARTICLE_REVIEW' , 'fields' => array ( 'ID' => 'I KEY AUTO' , 'TITLE' => 'C(255) NOTNULL' ,
$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
FindReplace with//Article search $search_preferences = array (); $search_preferences['Select_Options'] = array ( '`ID`' , '`TITLE`' ,
//Article search $search_preferences = array (); $search_preferences['Select_Options'] = array ( '`ID`' , '`TITLE`' , '`TITLE_REWRITE`' ,
- Open search.php
FindReplace with//Add search query $search_preferences['search'] = $searchPrefs['query']; $search_preferences['Select_Options'] = array ( '`ID`' , '`TITLE`' ,
//Add search query $search_preferences['search'] = $searchPrefs['query']; $search_preferences['Select_Options'] = array ( '`ID`' , '`TITLE`' , '`TITLE_REWRITE`' ,
- Open .htaccess
FindReplace withRewriteRule (.*)articles/article-(.*)\.htm[l]?$ article.php [QSA,NC]
RewriteRule (.*)articles/(.*)\.htm[l]?$ article.php [QSA,NC]
- Open article.php
Find (around line 158)Replace withelseif (ENABLE_REWRITE == 1) { preg_match ('#(.*)article(_|-)(\d+)\.htm[l]?$#i', request_uri(), $matches); $id = (!empty ($matches[3]) ? intval ($matches[3]) : 0); }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}.htmlwitharticles/{$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
- templates/Professional/rss2.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`)








