kesoh
Registered Member
- Jun 2, 2008
- 55
- 21
I am trying to install CB Profit feeds Gen.. all installed ok but when I try to Synchronize Categories I get this.......... Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/blah/public_html/newfolder/newadmin/sync_cat.php on line 89 ...can someone help me out... here is the code for sync_cat.php
Thanks For Any Help ..........(Sorry for the long post thought it would be better at least I hope)
Thanks For Any Help ..........(Sorry for the long post thought it would be better at least I hope)
<?
include("include/htmlparser.inc.php");
include("header1.php");
include("include/connect.inc.php");
/*
include("connect.inc.php");
include("htmlparser.inc.php");
*/
set_time_limit(36000);
// TODO:
$mainPage = "http://clickbank.com/marketplace/?r=xxxxx&s=1&i=10&t=ClickBank_Marketplace";
//$mainPage = "E:\\Ihab\\Projects\\LaserTargetedAds\\Documents\\Clickbank\\Source\\Clickbank Catalog.html";
class Category {
var $code;
var $url;
var $description;
var $SubCategories;
function Category($code, $url, $description) {
$this->code = $code;
$this->url = $url;
$this->description = $description;
}
function set_SubCategories($subCategories) {
$this->subCategories = $subCategories;
}
}
function getCategories($page) {
$parser = HtmlParser_ForUrl($page);
$foundCategory = false;
$categoryReady = false;
$categoriesTable = false;
$categories = NULL;
$code = NULL;
$url = NULL;
$description = NULL;
while ($parser->parse()) {
if ($parser->iNodeType == NODE_TYPE_ELEMENT && strcasecmp($parser->iNodeName, "a") == 0) {
$attrValues = $parser->iNodeAttributes;
if (stristr($attrValues["href"], "http://www.clickbank.com/marketplace/?r=xxxxx&c=")) {
$foundCategory = true;
$categoriesTable = true;
$url = $attrValues["href"];
//Added on 6may ..Praj
$code = substr($attrValues["href"], 48, strpos(substr($attrValues["href"], 48), "&"));
// echo "<br>Code : ".$code;
}
}
elseif ($foundCategory && $parser->iNodeType == NODE_TYPE_TEXT) {
$foundCategory = false;
$categoryReady = true;
$description = $parser->iNodeValue;
}
elseif ($categoriesTable && $parser->iNodeType == NODE_TYPE_ENDELEMENT && $parser->iNodeName == "table") {
break;
}
if ($categoryReady) {
$categories[$code] = new Category($code, $url, $description);
$categoryReady = false;
$code = NULL;
$url = NULL;
$description = NULL;
}
}
//echo "<br>Cat: ";
//print_r($categories);
return $categories;
}
$categories = getCategories($mainPage);
$count = count($categories);
$codes = array_keys($categories);
//$subPage = "E:\\Ihab\\Projects\\LaserTargetedAds\\Documents\\Clickbank\\Source\\Clickbank Catalog B2B.html";
for ($i = 0; $i < $count; $i++) {
//$categories[$codes[$i]]->set_SubCategories(getCategories($subPage));
// TODO:
$categories[$codes[$i]]->set_SubCategories(getCategories($categories[$codes[$i]]->url));
}
//include("include/connect.inc.php");
$deletedCategories = "";
$addedCategories = "";
$query = "SELECT CategoryId, Code, Description FROM ".$prefix."sys_cb_category WHERE CategoryId = ParentCategoryId";
//echo "<br>".$query;
$result_new = mysql_query($query)
or die("Query Failed query klkglkl");
while ($row = mysql_fetch_row($result_new)) {
// If the category still exist
if (in_array($row[1], $codes)) {
// Check its subcategories
$query = "SELECT CategoryId, Code, Description FROM ".$prefix."sys_cb_category WHERE ParentCategoryId = $row[0] AND CategoryId <> ParentCategoryId";
// echo "<br>".$query;
$resultDetail = mysql_query($query)
or die("Query Failed $query");
//Added on 5may ..Praj
if($categories[$row[1]]->subCategories!='' or count($categories[$row[1]]->subCategories)!=0) {
$codesDetail = array_keys($categories[$row[1]]->subCategories);
}
$deleteCount = 0;
while ($rowDetail = mysql_fetch_row($resultDetail)) {
// If the subcategory still exist
if (in_array($rowDetail[1], $codesDetail)) {
// Set sub-category to null so we don't add it later
$categories[$row[1]]->subCategories[$rowDetail[1]] = NULL;
}
else {
// Delete sub category details
mysql_query("DELETE FROM ".$prefix."sys_cb_category_detail WHERE CategoryId = $rowDetail[0]")
or die("Query Failed del");
// Delete sub category
mysql_query("DELETE FROM ".$prefix."sys_cb_category WHERE CategoryId = $rowDetail[0]")
or die("Query Failed del");
if ($deleteCount == 0) {
$deletedCategories .= "<li class=\"transText\">$row[2]</li><ul>";
}
$deletedCategories .= "<li class=\"text\">$rowDetail[2]</li>";
$deleteCount++;
}
}
if ($deleteCount > 0) {
$deleteCategories .= "</ul>";
}
mysql_free_result($resultDetail);
// Add new subcategories
$subCount = count($categories[$row[1]]->subCategories);
for ($i = 0; $i < $subCount; $i++) {
if ($categories[$row[1]]->subCategories[$codesDetail[$i]] != NULL) {
//Added By Arvind --- For checking "Next" value in array..DO NOT EDIT OR CHANGE THIS ....
if(strcmp($categories[$row[1]]->subCategories[$codesDetail[$i]]->description,"Next")!=0)
{
mysql_query("
INSERT INTO ".$prefix."sys_cb_category
(Description, ParentCategoryId, Code)
VALUES
('" . str_replace("'", "\'", $categories[$row[1]]->subCategories[$codesDetail[$i]]->description) . "', $row[0], '$codesDetail[$i]')")
or die("Query Failed ins");
}
if ($i == 0) {
$addedCategories .= "<li class=\"transText\">$row[2]</li><ul>";
}
//Added By Arvind --- For checking "Next" value in array..DO NOT EDIT OR CHANGE THIS ....
if(strcmp($categories[$row[1]]->subCategories[$codesDetail[$i]]->description,"Next")!=0)
{
$addedCategories .= "<li class=\"text\">" . $categories[$row[1]]->subCategories[$codesDetail[$i]]->description . "</li>";
}
if ($i == $subCount - 1) {
$addedCategories .= "</ul>";
}
}
}
// Set category to null so we don't add it later
$categories[$row[1]] = NULL;
}
else {
// Get the ids of the category to be deleted and all of its subcategories
/* $resultDetail = mysql_query("
SELECT DISTINCT ".$prefix."sys_cb_category.CategoryId
FROM sys_cb_category_detail INNER JOIN sys_cb_category ON sys_cb_category_detail.CategoryId = sys_cb_category.CategoryId
WHERE sys_cb_category.categoryId = $row[0] OR ParentCategoryId = $row[0]")
or die("Query Failed dist");
*/
/////////CHANGE DONE 5april
$resultDetail = mysql_query("
SELECT DISTINCT ".$prefix."sys_cb_category.CategoryId
FROM ".$prefix."sys_cb_category_detail INNER JOIN ".$prefix."sys_cb_category ON ".$prefix."sys_cb_category_detail.CategoryId = ".$prefix."sys_cb_category.CategoryId
WHERE ".$prefix."sys_cb_category.categoryId = $row[0] OR ParentCategoryId = $row[0]")
or die("Query Failed dist");
if (mysql_num_rows($resultDetail) > 0) {
$ids = "";
while ($rowDetail = mysql_fetch_row($resultDetail)) {
if ($ids != "") {
$ids .= ",";
}
$ids .= $rowDetail[0];
}
// Delete category details for this category and all its subcategories
mysql_query("DELETE FROM ".$prefix."sys_cb_category_detail WHERE CategoryId IN ($ids)")
or die("Query Failed dele");
}
mysql_free_result($resultDetail);
// Delete category and all its subcategories
mysql_query("DELETE FROM ".$prefix."sys_cb_category WHERE CategoryId = $row[0] OR ParentCategoryId = $row[0]")
or die("Query Failed DEL");
$deletedCategories .= "<li class=\"text\">$row[2]</li>";
}
}
mysql_free_result($result_new);
// Delete all unlinked items
$query= "SELECT ".$prefix."sys_cb_item.ItemId FROM ".$prefix."sys_cb_item LEFT JOIN ".$prefix."sys_cb_category_detail ON ".$prefix."sys_cb_item.ItemId = ".$prefix."sys_cb_category_detail.ItemId WHERE ".$prefix."sys_cb_category_detail.CategoryId IS NULL";
// echo "<br><br>QRY : ".$query;
$result = mysql_query($query)
or die("Query Failed SEL");
if (mysql_num_rows($result) > 0) {
$ids = "";
while ($row = mysql_fetch_row($result)) {
if ($ids != "") {
$ids .= ",";
}
$ids .= $row[0];
}
$result = mysql_query("DELETE FROM ".$prefix."sys_cb_item WHERE ItemId IN ($ids)")
or die("Query Failed");
}
mysql_free_result($result);
// Add new categories and sub-categories
for ($i = 0; $i < $count; $i++) {
if ($categories[$codes[$i]] != NULL) {
// Add main category
//Added By Arvind --- For checking "Next" value in array..DO NOT EDIT OR CHANGE THIS ....
if(strcmp($categories[$codes[$i]]->description,"Next")!=0)
{
mysql_query("
INSERT INTO ".$prefix."sys_cb_category
(Description, ParentCategoryId, Code)
VALUES
('" . str_replace("'", "\'", $categories[$codes[$i]]->description) . "', NULL, '$codes[$i]')")
or die("Query Failed");
}
$categoryId = mysql_insert_id($conn);
mysql_query("UPDATE ".$prefix."sys_cb_category SET ParentCategoryId = CategoryId WHERE CategoryId = $categoryId")
or die("Query Failed");
//Added By Arvind --- For checking "Next" value in array..DO NOT EDIT OR CHANGE THIS ....
if(strcmp($categories[$codes[$i]]->description,"Next")!=0)
{
$addedCategories .= "<li>";
$addedCategories .= $categories[$codes[$i]]->description;
}
// Add sub-categories
$codesDetail = array_keys($categories[$codes[$i]]->subCategories);
$subCount = count($codesDetail);
for ($j = 0; $j < $subCount; $j++) {
if ($categories[$codes[$i]]->subCategories[$codesDetail[$j]] != NULL) {
// Add sub category
//Added By Arvind --- For checking "Next" value in array..DO NOT EDIT OR CHANGE THIS ....
if(strcmp($categories[$codes[$i]]->subCategories[$codesDetail[$j]]->description,"Next")!=0)
{
mysql_query("
INSERT INTO ".$prefix."sys_cb_category
(Description, ParentCategoryId, Code)
VALUES
('" . str_replace("'", "\'", $categories[$codes[$i]]->subCategories[$codesDetail[$j]]->description) . "', $categoryId, '$codesDetail[$j]')")
or die("Query Failed");
}
if ($j == 0) {
$addedCategories .= "<ul>";
}
//Added By Arvind --- For checking "Next" value in array..DO NOT EDIT OR CHANGE THIS ....
if(strcmp($categories[$codes[$i]]->subCategories[$codesDetail[$j]]->description,"Next")!=0)
{
$addedCategories .= "<li class=\"text\">" . $categories[$codes[$i]]->subCategories[$codesDetail[$j]]->description . "</li>";
}
if ($j == $subCount - 1) {
$addedCategories .= "</ul>";
}
//$addedCategories .= $categories[$codes[$i]]->description . " > " . $categories[$codes[$i]]->subCategories[$codesDetail[$j]]->description . "<br>";
}
}
$addedCategories .= "</li>";
}
}
//include("include/dbdisconnect.inc");
//include("header.php");
?>
<link href="css/style.css" rel="stylesheet" type="text/css">
<tr>
<td><table width="681" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><img src="images/cor1.gif" width="13" height="34"></td>
<td width="655" background="images/topbg1.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center"><span class="title"><span class="text_white1">Categories Synchronization Summary</span></span></div></td>
</tr>
</table> </td>
<td><img src="images/cor2.gif" width="13" height="34"></td>
</tr>
<tr>
<td colspan="3"><table width="100%" border="0" cellspacing="0" cellpadding="0" class="bluebrder">
<tr>
<td><table width="95%" border="0" align="center" cellpadding="2" cellspacing="3">
<tr>
<td height="42" class="text">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="60%" class="border" align="center">
<tr>
<td class="menu1">Â </td>
</tr>
<tr>
<td class="title">Deleted Categories</td>
</tr>
<tr>
<td class="text_blk">
          Â
<?php
if ($deletedCategories) {
print("<ul><font class='text1'>$deletedCategories</font></ul>");
}
else {
print("<font class='text1'>No categories were deleted</font>");
}
?>
</td>
</tr>
<tr>
<td class="header">Â </td>
</tr>
<tr>
<td class="title" >Added Categories</td>
</tr>
<tr>
<td class="text_blk">Â Â Â Â Â Â Â Â Â Â Â
<?php
if ($addedCategories) {
print("<ul><font class='text1'>$addedCategories</font></ul>");
}
else {
print("<font class='text1'>No categories were added</font>");
}
?>
</td>
</tr>
<tr>
<td align="right">Â </td>
</tr>
<tr><td align="right">
<!-- <a href="JavaScript: parent.window.close();"><img border="0" src="../images/btn_close.gif"></a> -->
<div align="center">
<input type="button" onclick="JavaScript: parent.window.close();" name="close" value=" Close " class="newbutton">
</div></td>
</tr>
<tr>
<td align="right">Â </td>
</tr>
</table>
</td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="3">Â </td>
</tr>
</table></td>
</tr>
<tr>
<td>Â </td>
</tr>
</table></td>
</tr>
<? //include("footer.php"); ?>