Source for file class.modrewriteinstaller.php
Documentation is available at class.modrewriteinstaller.php
* Installer for Advanced Mod Rewrite Plugin, used by plugin setup.
* Some features are taken over from initial functions.mod_rewrite_setup.php file beeing created by
* @author Murat Purc <murat@purc.de>
* @copyright © ww.purc.de
throw
new Exception('ModRewriteInstaller: Base class "PluginSetupAbstract" doesn\'t exists, classfile must be included before.');
* Installer for Advanced Mod Rewrite Plugin, used by plugin setup.
* Some features are taken over from initial functions.mod_rewrite_setup.php file beeing created by
* Stefan Seifarth (aka stese).
* @author Murat Purc <murat@purc.de>
* @copyright © ww.purc.de
* Constructor, initializes parent.
* Installs the plugin, interface function implementation.
* Handle upgrading of mod rewrite needed database table columns
// check the existance of art_lang.urlname
$sql =
"SELECT * FROM " .
$this->_cfg['tab']['art_lang'] .
" LIMIT 0,1";
if (!$this->_db->next_record() ||
!$this->_db->f('urlname')) {
// add field 'urlname' to table
$sql =
"ALTER TABLE " .
$this->_cfg['tab']['art_lang'] .
" ADD urlname VARCHAR( 128 ) AFTER title";
// check the existance of cat_lang.urlpath
$sql =
"SELECT * FROM " .
$this->_cfg['tab']['cat_lang'] .
" LIMIT 0,1";
if (!$this->_db->next_record() ||
!$this->_db->f('urlpath')) {
// add field 'urlpath' to table
$sql =
"ALTER TABLE " .
$this->_cfg['tab']['cat_lang'] .
" ADD urlpath VARCHAR( 255 ) AFTER urlname";
// check for empty article fields
$sql =
"SELECT idlang, title, idart FROM " .
$this->_cfg['tab']['art_lang'] .
" WHERE urlname IS NULL OR urlname = ''";
while ($this->_db->next_record()) {
// check for empty category urlname
$sql =
"SELECT name, idcat, idlang FROM " .
$this->_cfg['tab']['cat_lang'] .
" WHERE urlname IS NULL OR urlname = ''";
while ($this->_db->next_record()) {
// check for empty category urlpath
$sql =
"SELECT name, idcat, idlang FROM " .
$this->_cfg['tab']['cat_lang'] .
" WHERE urlpath IS NULL OR urlpath = ''";
while ($this->_db->next_record()) {
* Upgrade plugin, interface function implementation.
* Handle upgrading of mod rewrite needed database table columns
* Delete plugin, interface function implementation.
* Handle deleteting of mod rewrite needed database table columns
// remove field 'urlpath' from 'cat_lang' table
$sql =
"ALTER TABLE " .
$this->_cfg['tab']['cat_lang'] .
" DROP urlpath";
* Set websafe name in article list
* insert new websafe name in article list
* @param string original name (will be converted)
* @param integer current article id
* @param integer current language id
* @return boolean true if insert was successfully
private function _setArticle($sName=
"", $iArtId=
0, $iLangId=
0, $iCatId=
0) {
$db =
new DB_Contenido();
$sNewName =
capiStrCleanURLCharacters($sName);
// check if websafe name already exists
if ($this->_inArticles($sNewName, $iArtId, $iLangId, $iCatId)) {
// create new websafe name if exists
$sNewName =
capiStrCleanURLCharacters($sName) .
'_' .
$iArtId;
// check again - and set name
if (!$this->_inArticles($sNewName, $iArtId, $iLangId, $iCatId)) {
// insert websafe name in article list
$sql =
"UPDATE " .
$this->_cfg['tab']['art_lang'] .
" SET urlname = '" .
$sNewName .
"' WHERE idart = '" .
$iArtId .
"' AND idlang = '" .
$iLangId .
"'";
* Set websafe name in category list
* insert new websafe name in category list
* @param string original name (will be converted)
* @param integer current article id
* @param integer current language id
* @return boolean true if insert was successfully
private function _setCategory($sName=
'', $iCatId=
0, $iLangId=
0) {
$db =
new DB_Contenido();
$sNewName =
capiStrCleanURLCharacters($sName);
// check if websafe name already exists
if ($this->_inCategory($sNewName, $iCatId, $iLangId)) {
// create new websafe name if exists
$sNewName =
capiStrCleanURLCharacters($sName) .
'_' .
$iCatId;
// check again - and set name
if (!$this->_inCategory($sNewName, $iCatId, $iLangId)) {
// insert websafe name in article list
$sql =
"UPDATE " .
$this->_cfg['tab']['cat_lang'] .
" SET urlname = '$sNewName' WHERE idcat = '$iCatId' AND idlang = '$iLangId'";
* Build and set recursiv path for mod_rewrite rule like server directories
* @param int $iCatId Latest category id
* @param int $iLangId Language id
* @param int $iLastId Last category id
* @return string linkpath with correct uri
$db =
new DB_Contenido();
while ($bFinish ==
false) {
$sql =
"SELECT cl.urlname, c.parentid FROM " .
$this->_cfg['tab']['cat_lang'] .
" cl "
.
"LEFT JOIN " .
$this->_cfg['tab']['cat'] .
" c ON cl.idcat = c.idcat "
.
"WHERE cl.idcat = '$iTmpCatId' AND cl.idlang = '$iLangId'";
if ($db->next_record()) {
$aDirs[] =
$db->f('urlname');
$iTmpCatId =
$db->f('parentid');
if ($db->f('parentid') ==
0 ||
$db->f('parentid') ==
$iLastId) {
// reverse array entries and create directory string
// insert urlpath for category
$sql =
"UPDATE " .
$this->_cfg['tab']['cat_lang'] .
" SET urlpath = '$sPath' WHERE idcat = '$iCatId' AND idlang = '$iLangId'";
* Check articles on websafe name
* Check all articles in the current category on existing same websafe name
* @param string Websafe name to check
* @param integer current article id
* @param integer current language id
* @param integer current category id
* @return boolean true if websafename already exists, false if not
private function _inArticles($sName=
'', $iArtId=
0, $iLangId=
0, $iCatId=
0) {
$db =
new DB_Contenido();
// get category id if not set
$sql =
"SELECT idcat FROM " .
$this->_cfg['tab']['cat_art'] .
" WHERE idart = '$iArtId'";
$iCatId =
($db->f('idcat') >
0) ?
$db->f('idcat') :
'0';
$sWhere =
" ca.idcat = '$iCatId' AND al.idlang = '" .
$iLangId .
"' AND"
.
" al.urlname = '" .
$sName .
"' AND al.idart <> '$iArtId'";
// check if websafe name is in this category
$sql =
"SELECT count(al.idart) as numcats FROM " .
$this->_cfg['tab']['art_lang'] .
" al LEFT JOIN " .
$this->_cfg['tab']['cat_art'] .
" ca ON al.idart = ca.idart WHERE " .
$sWhere;
return ($db->f('numcats') >
0) ?
true :
false;
* Check categories on websafe name
* Check all categories in the main parent category on existing same websafe name
* @param string Websafe name to check
* @param integer current category id
* @param integer current language id
* @return boolean true if websafename already exists, false if not
private function _inCategory($sName=
'', $iCatId=
0, $iLangId=
0) {
$db =
new DB_Contenido();
$sql =
"SELECT parentid FROM " .
$this->_cfg['tab']['cat'] .
" WHERE idcat = '$iCatId'";
$iParentId =
($db->f('parentid') >
0) ?
$db->f('parentid') :
'0';
$sWhere =
" c.parentid = '$iParentId' AND cl.idlang = '" .
$iLangId .
"' AND"
.
" cl.urlname = '" .
$sName .
"' AND cl.idcat <> '$iCatId'";
// check if websafe name is in this category
$sql =
"SELECT count(cl.idcat) as numcats FROM " .
$this->_cfg['tab']['cat_lang'] .
" cl LEFT JOIN " .
$this->_cfg['tab']['cat'] .
" c ON cl.idcat = c.idcat WHERE " .
$sWhere;
return ($db->f('numcats') >
0) ?
true :
false;
Documentation generated on Tue, 25 Nov 2008 22:07:27 +0100 by phpDocumentor 1.4.1