Hallo,
ich habe ein kleines Problem mit einem Script. Ich wollte vor den Kategorie URLs ein /preisvergleich/ stehen haben. Die .htaccess kriege ich noch hin nur die datei welche für die dateienamen der Kategorien zuständig ist macht mich ganz wirre.
Zurzeit sieht ein link folgendermaßen aus:
http://www.link.com/handys~1004.html
So sollte es aussehen:
http://www.link.com/preisvergleich/handys~1004.html
Ich blicke in der Datei einfach nicht durch. Ich hoffe ihr könnt mir helfen. Die Urls werden mit "getCategoryPath" geholt.
Hier der Code:
CODE <?php
//*************************************************************************************************
//
// CATEGORY FUNCTIONS
//
//*************************************************************************************************
function addCategory(&$msg, $parent, $level, $name, $filename='', $isValid='Y', $homepageDisplay='N', $sortOrder=0, $detail='', $pageTitle='', $pageKeywords='', $pageDescription='')
{
$name = handleSingleQuote($name);
$filename = handleSingleQuote($filename);
$detail = handleSingleQuote($detail);
$pageTitle = handleSingleQuote($pageTitle);
$pageKeywords = handleSingleQuote($pageKeywords);
$pageDescription = handleSingleQuote($pageDescription);
if ( !isset($parent) )
{
$msg = "Category`s parent cannot be empty. Please select parent and retry. -addCategory-";
return 0;
}
if ( $name == "" )
{
$msg = "Category name cannot be empty. Please fill the form completely and retry. -addCategory-";
return 0;
}
if ( isCategoryHasProducts($msg, $parent) )
return 0;
if ( validateCategoryName($msg, $name, $filename) == 0 )
return 0;
// Level is empty OR Zero then CALCULATE it
if ( $level == '' )
$level = $parent==0?0:(getColumn("CATEGORY", $parent, "LEVEL", "ID")+1);
$categoryId = getNextId("CATEGORY");
$sql = "INSERT INTO ".PREFIX."CATEGORY (ID, PARENT_ID, LEVEL, TITLE, DETAIL, FILENAME, PAGE_TITLE, PAGE_KEYWORDS, PAGE_DESCRIPTION, SORT_ORDER, ISVALID, HOMEPAGE_DISPLAY) VALUES('".$categoryId."', '".(int)$parent."', '".$level."', '".$name."', '".$detail."', '".$filename."', '".$pageTitle."', '".$pageKeywords."', '".$pageDescription."', '".$sortOrder."', '".$isValid."', '".$homepageDisplay."')";
$res = executeUpdate($sql);
//echo $sql.'<br><br>';
if ( $res > 0 )
{
if ( IS_AUCTION_INSTALLED == 1 )
{
$aucCategoryId = auction_getNextId("CATEGORY");
$aucSql = "INSERT INTO ".AUCTION_PREFIX."CATEGORY (ID, PARENT_ID, LEVEL, TITLE, FILENAME, SORT_ORDER, ISVALID, HOMEPAGE_DISPLAY) VALUES('".$aucCategoryId."', '".(int)$parent."', '".$level."', '".$name."', '".$filename."', '".$sortOrder."', '".$isValid."', '".$homepageDisplay."')";
$aucRes = executeUpdate($aucSql);
}
$msg = "2";
return $categoryId;
}
else
{
$msg = "6";
return 0;
}
}
//*************************************************************************************************
// $isUpdateAll is used to update all columns (except ENUM columns) even if the value is empty.
// It is usually called in the update where TEXT values can be reset.
//
function updateCategory(&$msg, $categoryId, $parent, $level, $name, $filename='', $isValid='', $homepageDisplay='', $sortOrder='', $detail='', $pageTitle='', $pageKeywords='', $pageDescription='', $isUpdateAll=0)
{
$name = handleSingleQuote($name);
$filename = handleSingleQuote($filename);
$detail = handleSingleQuote($detail);
$pageTitle = handleSingleQuote($pageTitle);
$pageKeywords = handleSingleQuote($pageKeywords);
$pageDescription = handleSingleQuote($pageDescription);
if ( $categoryId == "" )
{
$msg = "Empty CategoryID passed. -updateCategory-";
return 0;
}
if ( $isUpdateAll == 1 )
{
if ( $name == "" )
{
$msg = "Category name cannot be empty. -updateCategory-";
return 0;
}
}
$sql = "UPDATE ".PREFIX."CATEGORY SET ";
if ( isset($parent) && $isUpdateAll == 1 )
{
if ( isCategoryHasProducts($msg, $parent) )
return 0;
if ( $parent == $categoryId )
{
$msg = "Cannot add category to itself. Please select another parent category.";
return 0;
}
$sql .= "PARENT_ID = '".$parent."', ";
// Level is empty OR Zero then CALCULATE it
if ( $level == '' )
$level = $parent==0?0:(getColumn("CATEGORY", $parent, "LEVEL", "ID")+1);
$sql .= "LEVEL = '".$level."', ";
$parentFlag = 1;
}
if ( $isUpdateAll == 1 || $name != "" )
$sql .= "TITLE = '".$name."', ";
if ( $isUpdateAll == 1 || $detail != "" )
$sql .= "DETAIL = '".$detail."', ";
if ( $isUpdateAll == 1 || $filename != "" )
{
// Filename is to be changed, validate it
if ( validateCategoryName($msg, $name, $filename, $categoryId) == 0 )
return 0;
$sql .= "FILENAME = '".$filename."', ";
}
if ( $isUpdateAll == 1 || $pageTitle != "" )
$sql .= "PAGE_TITLE = '".$pageTitle."', ";
if ( $isUpdateAll == 1 || $pageKeywords != "" )
$sql .= "PAGE_KEYWORDS = '".$pageKeywords."', ";
if ( $isUpdateAll == 1 || $pageDescription != "" )
$sql .= "PAGE_DESCRIPTION = '".$pageDescription."', ";
if ( $isUpdateAll == 1 || $sortOrder != "" )
$sql .= "SORT_ORDER = '".$sortOrder."', ";
if ( $isValid != "" )
{
$sql .= "ISVALID = '".$isValid."', ";
$validFlag = 1;
}
if ( $homepageDisplay != "" )
$sql .= "HOMEPAGE_DISPLAY = '".$homepageDisplay."', ";
$sql .= "LAST_UPDATED = '".getTimezoneTime()."' WHERE ID = ".$categoryId;
//echo $sql.'['.$parent.']';die;
$res = executeUpdate($sql);
if ( $res > 0 )
{
if ( $parentFlag == 1 )
updateCategoryLevels($categoryId, $level+1);
if ( $validFlag == 1 )
{
$sIds = statusRecursive("CATEGORY", "PARENT_ID", "ID", $categoryId, $isValid);
executeUpdate("UPDATE ".PREFIX."PRODUCT SET ISVALID = '".$isValid."' WHERE CATEGORY_ID IN (".$sIds."0)");
}
$msg = "3";
return 1;
}
else
{
$msg = "6";
return 0;
}
}
//*************************************************************************************************
function deleteCategory(&$msg, $categoryId)
{
if ( $categoryId == "" )
{
$msg = "Empty CategoryID passed. -deleteCategory-";
return 0;
}
// Category Delete May Take Quite Long
@set_time_limit(0);
@ignore_user_abort(true);
$msgEx= '';
$sIds = delRecursive("CATEGORY", "PARENT_ID", "ID", $categoryId, PATH."upload/category/");
if ( IS_AUCTION_INSTALLED == 1 )
{
$msgEx2 = '';
auction_deleteCategory($msgEx2, $categoryId);
}
/*
// ******************************
// InnoDB this is not needed
// ******************************
$res = executeQuery("SELECT ID FROM ".PREFIX."PRODUCT WHERE CATEGORY_ID IN (".$sIds."0)");
while ( $row = getRow($res) )
deleteProduct($msgEx, $row['ID']);
// Delete Dependent Addons
if ( IS_PRODUCTFILTERS_INSTALLED == 1 )
{
executeUpdate("DELETE FROM ".PREFIX."PRODUCT_FEATURE_CATEGORY WHERE CATEGORY_ID IN (".$sIds."0)");
executeUpdate("DELETE FROM ".PREFIX."PRODUCT_FEATURE_VALUE WHERE CATEGORY_ID IN (".$sIds."0)");
executeUpdate("DELETE FROM ".PREFIX."PRODUCT_FEATURE WHERE CATEGORY_ID IN (".$sIds."0)");
}
*/
$msg = "4";
}
//*************************************************************************************************
function uploadCategoryImage(&$msg, $categoryId, $image)
{
if ( $categoryId == "" )
{
$msg = "Empty CategoryID passed. -updateCategory-";
return 0;
}
if ( $image == "" )
{
$msg = "1";
return 0;
}
$filename = PATH."upload/category/".$categoryId.".jpg";
if ( copyFile($image["tmp_name"], $filename) )
{
$arr = getimagesize($filename);
if ( $arr !== false )
{
$msg = "10";
return 1;
}
else
{
@unlink($filename);
$msg = "Incorrect Mime type";
}
}
else
$msg = "6";
return 0;
}
//*************************************************************************************************
function getCategoryThumbnail($cId, $cLink='', $cFilename='', $width='90', $height='90', $border='gray')
{
if ( $cId == '' )
return 'Empty Category ID -getCategoryThumbnail-';
if ( $cLink == '' )
$cLink = getCategoryPath($cId, $cFilename);
$out = "
<table border='0' width='$width' height='$height' bgcolor='$border' cellspacing='1'>
<tr>
<td bgcolor='white' align='center' class='td'>";
$categoryImagePath = 'upload/category/'.$cId.'.jpg';
if ( file_exists(PATH.$categoryImagePath) )
{
$imgInfo = @getimagesize(PATH.$categoryImagePath);
$imgDim = "";
if ( $imgInfo[0] > $imgInfo[1] )
$imgDim = "width='".$width."'";
else
$imgDim = "height='".$height."'";
$out .= "<a href=\"".$cLink."\"><img src=\"".SCRIPT_ROOT."thumbnail.php?f=".urlencode($categoryImagePath)."&amp;w=".$width."&amp;h=".$height."\" border='0' ".$imgDim."></a>";
}
else
{
$out .= "<font class='small'><font color='".$border."'>- no image -</font></font>";
}
$out .= "</td>
</tr>
</table>";
return $out;
}
//*************************************************************************************************
//*************************************************************************************************
//*************************************************************************************************
function isCategoryHasProducts(&$msg, $category)
{
$res = executeQuery("SELECT ID FROM ".PREFIX."PRODUCT WHERE CATEGORY_ID = '".$category."'");
if ( $row = getRow($res) )
{
$msg = "Cannot add categories under this parent as it already has products. -isCategoryHasProducts-";
return 1;
}
else
return 0;
}
//*************************************************************************************************
function updateCategoryLevels($parentId, $level) // update level to $level of all the childs of $id
{
$res = executeQuery("SELECT ID FROM ".PREFIX."CATEGORY WHERE PARENT_ID = ".$parentId);
while ( $row = getRow($res) )
{
executeUpdate("UPDATE ".PREFIX."CATEGORY SET LEVEL = ".$level." WHERE ID = ".$row["ID"]);
updateCategoryLevels($row["ID"], $level+1);
}
}
//*************************************************************************************************
function isCategoryHasChildCategory(&$msg, $category)
{
$res = executeQuery("SELECT ID FROM ".PREFIX."CATEGORY WHERE PARENT_ID = '".$category."'");
if ( $row = getRow($res) )
{
$msg = "Product cannot be added to this category because it has sub-categories.<br>You can only add product at the last level of the category nesting.";
return 1;
}
else
return 0;
}
//*************************************************************************************************
function validateCategoryName(&$msg, $title, &$filename, $categoryId=0)
{
if ( USE_MOD_REWRITE == 'Y' )
{
if ( $filename == "" )
$filename = $title;
$filename = trim($filename);
if ( $filename == "" )
{
$msg = "Category name cannot be empty. -validateCategoryName-";
return 0;
}
$filename = replaceFilenameChars($filename);
return 1;
}
return 1;
}
//*************************************************************************************************
?>
Ich würde mich sehr über eure Hilfe freuen.
Mfg
inox
ich habe ein kleines Problem mit einem Script. Ich wollte vor den Kategorie URLs ein /preisvergleich/ stehen haben. Die .htaccess kriege ich noch hin nur die datei welche für die dateienamen der Kategorien zuständig ist macht mich ganz wirre.
Zurzeit sieht ein link folgendermaßen aus:
http://www.link.com/handys~1004.html
So sollte es aussehen:
http://www.link.com/preisvergleich/handys~1004.html
Ich blicke in der Datei einfach nicht durch. Ich hoffe ihr könnt mir helfen. Die Urls werden mit "getCategoryPath" geholt.
Hier der Code:
CODE <?php
//*************************************************************************************************
//
// CATEGORY FUNCTIONS
//
//*************************************************************************************************
function addCategory(&$msg, $parent, $level, $name, $filename='', $isValid='Y', $homepageDisplay='N', $sortOrder=0, $detail='', $pageTitle='', $pageKeywords='', $pageDescription='')
{
$name = handleSingleQuote($name);
$filename = handleSingleQuote($filename);
$detail = handleSingleQuote($detail);
$pageTitle = handleSingleQuote($pageTitle);
$pageKeywords = handleSingleQuote($pageKeywords);
$pageDescription = handleSingleQuote($pageDescription);
if ( !isset($parent) )
{
$msg = "Category`s parent cannot be empty. Please select parent and retry. -addCategory-";
return 0;
}
if ( $name == "" )
{
$msg = "Category name cannot be empty. Please fill the form completely and retry. -addCategory-";
return 0;
}
if ( isCategoryHasProducts($msg, $parent) )
return 0;
if ( validateCategoryName($msg, $name, $filename) == 0 )
return 0;
// Level is empty OR Zero then CALCULATE it
if ( $level == '' )
$level = $parent==0?0:(getColumn("CATEGORY", $parent, "LEVEL", "ID")+1);
$categoryId = getNextId("CATEGORY");
$sql = "INSERT INTO ".PREFIX."CATEGORY (ID, PARENT_ID, LEVEL, TITLE, DETAIL, FILENAME, PAGE_TITLE, PAGE_KEYWORDS, PAGE_DESCRIPTION, SORT_ORDER, ISVALID, HOMEPAGE_DISPLAY) VALUES('".$categoryId."', '".(int)$parent."', '".$level."', '".$name."', '".$detail."', '".$filename."', '".$pageTitle."', '".$pageKeywords."', '".$pageDescription."', '".$sortOrder."', '".$isValid."', '".$homepageDisplay."')";
$res = executeUpdate($sql);
//echo $sql.'<br><br>';
if ( $res > 0 )
{
if ( IS_AUCTION_INSTALLED == 1 )
{
$aucCategoryId = auction_getNextId("CATEGORY");
$aucSql = "INSERT INTO ".AUCTION_PREFIX."CATEGORY (ID, PARENT_ID, LEVEL, TITLE, FILENAME, SORT_ORDER, ISVALID, HOMEPAGE_DISPLAY) VALUES('".$aucCategoryId."', '".(int)$parent."', '".$level."', '".$name."', '".$filename."', '".$sortOrder."', '".$isValid."', '".$homepageDisplay."')";
$aucRes = executeUpdate($aucSql);
}
$msg = "2";
return $categoryId;
}
else
{
$msg = "6";
return 0;
}
}
//*************************************************************************************************
// $isUpdateAll is used to update all columns (except ENUM columns) even if the value is empty.
// It is usually called in the update where TEXT values can be reset.
//
function updateCategory(&$msg, $categoryId, $parent, $level, $name, $filename='', $isValid='', $homepageDisplay='', $sortOrder='', $detail='', $pageTitle='', $pageKeywords='', $pageDescription='', $isUpdateAll=0)
{
$name = handleSingleQuote($name);
$filename = handleSingleQuote($filename);
$detail = handleSingleQuote($detail);
$pageTitle = handleSingleQuote($pageTitle);
$pageKeywords = handleSingleQuote($pageKeywords);
$pageDescription = handleSingleQuote($pageDescription);
if ( $categoryId == "" )
{
$msg = "Empty CategoryID passed. -updateCategory-";
return 0;
}
if ( $isUpdateAll == 1 )
{
if ( $name == "" )
{
$msg = "Category name cannot be empty. -updateCategory-";
return 0;
}
}
$sql = "UPDATE ".PREFIX."CATEGORY SET ";
if ( isset($parent) && $isUpdateAll == 1 )
{
if ( isCategoryHasProducts($msg, $parent) )
return 0;
if ( $parent == $categoryId )
{
$msg = "Cannot add category to itself. Please select another parent category.";
return 0;
}
$sql .= "PARENT_ID = '".$parent."', ";
// Level is empty OR Zero then CALCULATE it
if ( $level == '' )
$level = $parent==0?0:(getColumn("CATEGORY", $parent, "LEVEL", "ID")+1);
$sql .= "LEVEL = '".$level."', ";
$parentFlag = 1;
}
if ( $isUpdateAll == 1 || $name != "" )
$sql .= "TITLE = '".$name."', ";
if ( $isUpdateAll == 1 || $detail != "" )
$sql .= "DETAIL = '".$detail."', ";
if ( $isUpdateAll == 1 || $filename != "" )
{
// Filename is to be changed, validate it
if ( validateCategoryName($msg, $name, $filename, $categoryId) == 0 )
return 0;
$sql .= "FILENAME = '".$filename."', ";
}
if ( $isUpdateAll == 1 || $pageTitle != "" )
$sql .= "PAGE_TITLE = '".$pageTitle."', ";
if ( $isUpdateAll == 1 || $pageKeywords != "" )
$sql .= "PAGE_KEYWORDS = '".$pageKeywords."', ";
if ( $isUpdateAll == 1 || $pageDescription != "" )
$sql .= "PAGE_DESCRIPTION = '".$pageDescription."', ";
if ( $isUpdateAll == 1 || $sortOrder != "" )
$sql .= "SORT_ORDER = '".$sortOrder."', ";
if ( $isValid != "" )
{
$sql .= "ISVALID = '".$isValid."', ";
$validFlag = 1;
}
if ( $homepageDisplay != "" )
$sql .= "HOMEPAGE_DISPLAY = '".$homepageDisplay."', ";
$sql .= "LAST_UPDATED = '".getTimezoneTime()."' WHERE ID = ".$categoryId;
//echo $sql.'['.$parent.']';die;
$res = executeUpdate($sql);
if ( $res > 0 )
{
if ( $parentFlag == 1 )
updateCategoryLevels($categoryId, $level+1);
if ( $validFlag == 1 )
{
$sIds = statusRecursive("CATEGORY", "PARENT_ID", "ID", $categoryId, $isValid);
executeUpdate("UPDATE ".PREFIX."PRODUCT SET ISVALID = '".$isValid."' WHERE CATEGORY_ID IN (".$sIds."0)");
}
$msg = "3";
return 1;
}
else
{
$msg = "6";
return 0;
}
}
//*************************************************************************************************
function deleteCategory(&$msg, $categoryId)
{
if ( $categoryId == "" )
{
$msg = "Empty CategoryID passed. -deleteCategory-";
return 0;
}
// Category Delete May Take Quite Long
@set_time_limit(0);
@ignore_user_abort(true);
$msgEx= '';
$sIds = delRecursive("CATEGORY", "PARENT_ID", "ID", $categoryId, PATH."upload/category/");
if ( IS_AUCTION_INSTALLED == 1 )
{
$msgEx2 = '';
auction_deleteCategory($msgEx2, $categoryId);
}
/*
// ******************************
// InnoDB this is not needed
// ******************************
$res = executeQuery("SELECT ID FROM ".PREFIX."PRODUCT WHERE CATEGORY_ID IN (".$sIds."0)");
while ( $row = getRow($res) )
deleteProduct($msgEx, $row['ID']);
// Delete Dependent Addons
if ( IS_PRODUCTFILTERS_INSTALLED == 1 )
{
executeUpdate("DELETE FROM ".PREFIX."PRODUCT_FEATURE_CATEGORY WHERE CATEGORY_ID IN (".$sIds."0)");
executeUpdate("DELETE FROM ".PREFIX."PRODUCT_FEATURE_VALUE WHERE CATEGORY_ID IN (".$sIds."0)");
executeUpdate("DELETE FROM ".PREFIX."PRODUCT_FEATURE WHERE CATEGORY_ID IN (".$sIds."0)");
}
*/
$msg = "4";
}
//*************************************************************************************************
function uploadCategoryImage(&$msg, $categoryId, $image)
{
if ( $categoryId == "" )
{
$msg = "Empty CategoryID passed. -updateCategory-";
return 0;
}
if ( $image == "" )
{
$msg = "1";
return 0;
}
$filename = PATH."upload/category/".$categoryId.".jpg";
if ( copyFile($image["tmp_name"], $filename) )
{
$arr = getimagesize($filename);
if ( $arr !== false )
{
$msg = "10";
return 1;
}
else
{
@unlink($filename);
$msg = "Incorrect Mime type";
}
}
else
$msg = "6";
return 0;
}
//*************************************************************************************************
function getCategoryThumbnail($cId, $cLink='', $cFilename='', $width='90', $height='90', $border='gray')
{
if ( $cId == '' )
return 'Empty Category ID -getCategoryThumbnail-';
if ( $cLink == '' )
$cLink = getCategoryPath($cId, $cFilename);
$out = "
<table border='0' width='$width' height='$height' bgcolor='$border' cellspacing='1'>
<tr>
<td bgcolor='white' align='center' class='td'>";
$categoryImagePath = 'upload/category/'.$cId.'.jpg';
if ( file_exists(PATH.$categoryImagePath) )
{
$imgInfo = @getimagesize(PATH.$categoryImagePath);
$imgDim = "";
if ( $imgInfo[0] > $imgInfo[1] )
$imgDim = "width='".$width."'";
else
$imgDim = "height='".$height."'";
$out .= "<a href=\"".$cLink."\"><img src=\"".SCRIPT_ROOT."thumbnail.php?f=".urlencode($categoryImagePath)."&amp;w=".$width."&amp;h=".$height."\" border='0' ".$imgDim."></a>";
}
else
{
$out .= "<font class='small'><font color='".$border."'>- no image -</font></font>";
}
$out .= "</td>
</tr>
</table>";
return $out;
}
//*************************************************************************************************
//*************************************************************************************************
//*************************************************************************************************
function isCategoryHasProducts(&$msg, $category)
{
$res = executeQuery("SELECT ID FROM ".PREFIX."PRODUCT WHERE CATEGORY_ID = '".$category."'");
if ( $row = getRow($res) )
{
$msg = "Cannot add categories under this parent as it already has products. -isCategoryHasProducts-";
return 1;
}
else
return 0;
}
//*************************************************************************************************
function updateCategoryLevels($parentId, $level) // update level to $level of all the childs of $id
{
$res = executeQuery("SELECT ID FROM ".PREFIX."CATEGORY WHERE PARENT_ID = ".$parentId);
while ( $row = getRow($res) )
{
executeUpdate("UPDATE ".PREFIX."CATEGORY SET LEVEL = ".$level." WHERE ID = ".$row["ID"]);
updateCategoryLevels($row["ID"], $level+1);
}
}
//*************************************************************************************************
function isCategoryHasChildCategory(&$msg, $category)
{
$res = executeQuery("SELECT ID FROM ".PREFIX."CATEGORY WHERE PARENT_ID = '".$category."'");
if ( $row = getRow($res) )
{
$msg = "Product cannot be added to this category because it has sub-categories.<br>You can only add product at the last level of the category nesting.";
return 1;
}
else
return 0;
}
//*************************************************************************************************
function validateCategoryName(&$msg, $title, &$filename, $categoryId=0)
{
if ( USE_MOD_REWRITE == 'Y' )
{
if ( $filename == "" )
$filename = $title;
$filename = trim($filename);
if ( $filename == "" )
{
$msg = "Category name cannot be empty. -validateCategoryName-";
return 0;
}
$filename = replaceFilenameChars($filename);
return 1;
}
return 1;
}
//*************************************************************************************************
?>
Ich würde mich sehr über eure Hilfe freuen.
Mfg
inox