search_refresh_dt or search_refresh_dt = '0000-00-00 00-00-00'"; $result=MYSQL_QUERY("$SQLstr"); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $search_id = $row['search_id']; $searchcond = $row['search_cond']; $cat= $row['search_cat']; echo "\nDoing Search $search_id"; $searches = ""; $tot = do_search_id_searches($search_id); // $txt .= "\n\n$tot results returned \nSearch id: $search_id using: $searchcond"; } $txt = $msg; } function discover_domains(){ $SQLstr = "select * from h_url_groups WHERE ug_id > 0 "; $result=MYSQL_QUERY("$SQLstr"); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $dir = $row['ug_basedir']; $ugid = $row['ug_id']; $dir = substr($dir,0,strpos($dir,"*")); $dh = opendir($dir); $files1= ""; while (false !== ($filename = readdir($dh))) { $files1[] = $filename; } foreach($files1 as $dr){ $found = false; $pos = strpos($dr,".co.uk"); if ($pos ===false){ }else { $SQLstr = "select * from h_url where lower(url_domain) like '%$dr'"; $result2=MYSQL_QUERY("$SQLstr"); while($row2 = mysql_fetch_array($result2, MYSQL_ASSOC)) { if (strtolower($row2['url_domain'])== strtolower("www.$dr")){ $found = true; } } if (!$found){ $ct++; echo "\n
FOUND $dr not in DB ADDING"; $SQLstr = "insert into h_url (url_name,url_domain,url_ug_id,url_type) values('$dr','www.$dr','$ugid',".DISCOVERED.")"; $result3=MYSQL_QUERY("$SQLstr"); } } } } $SQLstr = "select * from h_url_groups WHERE ug_id = 0 "; $result=MYSQL_QUERY("$SQLstr"); $row = mysql_fetch_array($result); for ($i = 0;$i<25;$i++){ $dir = $row['ug_basedir']; $ugid = $row['ug_id']; $dir = str_replace("***letter***",chr(97+$i)."___",$dir); $dir = substr($dir,0,strpos($dir,"*")); $dh = opendir($dir); $files1= ""; while (false !== ($filename = readdir($dh))) { $files1[] = $filename; } foreach($files1 as $dr){ $found = false; $pos = strpos($dr,".co.uk"); if ($pos ===false){ }else { $SQLstr = "select * from h_url where lower(url_domain) like '%$dr'"; $result2=MYSQL_QUERY("$SQLstr"); while($row2 = mysql_fetch_array($result2, MYSQL_ASSOC)) { if (strtolower($row2['url_domain'])== strtolower("www.$dr")){ $found = true; } } if (!$found){ $ct++; echo "\n
FOUND $dr not in DB ADDING"; $SQLstr = "insert into h_url (url_name,url_domain,url_ug_id,url_type) values('$dr','www.$dr','$ugid',".DISCOVERED.")"; $result3=MYSQL_QUERY("$SQLstr"); } } } } echo "\n

$ct domains added"; } function get_domain_list(){ include "global_url.inc"; include "host.inc"; global $filelist; $SQLstr = "select * from h_url"; echo $SQLstr; // $ret = " '$_SERVER[\'HTTP_HOST\']';" $result=MYSQL_QUERY("$SQLstr"); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { load_url($row); $doms[$url_status][] = $domain; $ret .= "$uid;;;$domain:::"; } //print_r($doms); makepage($basedir,"domainarray.inc",$ret); foreach ($doms as $st => $stat){ $cont =""; foreach($stat as $dom){ $cont .= "
$dom"; } makepage($basedir,"domainlist_$st.htm",$cont); $filelist .= "\ndomainlist_$st.htm"; } } function get_brands(){ $SQLstr = "select * from h_products where prod_brand != '' group by prod_brand "; echo $SQLstr; $result=MYSQL_QUERY("$SQLstr"); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $brand = $row['prod_brand']; // $sid= $row['prod_source_id']; // $cid= $row['prod_cat_id']; $lbrand = strtolower($brand); $SQLstr = "select * from h_advertiser where lower(adv_link_display) = '$lbrand' and adv_type =".BRAND; $result2=MYSQL_QUERY("$SQLstr"); $row2 = mysql_fetch_array($result2); $nm = $row2['adv_link_display']; $nid = $row2['adv_id']; $pos = strpos($brand,"http"); if ($nm == "" && ($pos === false)){ $SQLstr = "select max(adv_id) as mid from h_advertiser "; $result2=MYSQL_QUERY("$SQLstr"); $row2 = mysql_fetch_array($result2); $nid = $row2['mid']+1; $SQLstr = "insert into h_advertiser (adv_id,adv_name, adv_link_display, adv_type, adv_visible)"; $SQLstr .= " values ($nid,'$brand', '$brand','".BRAND."', '1')"; echo "\n
$SQLstr"; $result2=MYSQL_QUERY("$SQLstr"); } // $wgid = get_product_wg($sid,$cid); // if ($wgid > 0) { // add_link($nid,$wgid,"bwc"); // } } } function link_brands(){ } function jumppages (){ include "global_adv.inc"; global $types; global $chmod, $faillist,$fault; $dir = $types[100]['alpha3']; $path="$dir/advertisers"; echo "Path $path"; rm_recurse($path); $SQLstr = "select * from h_advertiser where adv_type != ".BRAND; $result=MYSQL_QUERY("$SQLstr"); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { load_adv($row); if ($adv_visible){ $dir = $types[$adv_link_type]['alpha3']; //echo "\nadv type $adv_link_type; $adv_link;; $adv_program ;;;"; $refresh= treat($types[$adv_link_type]['alpha2']); if ($dir != ""){ $jumplink = cleanout($types[$adv_program]['alpha3']); $pos = strpos($jumplink,"***"); if (!($pos === false)){ $jumplink = cleanout($jumplink); } $content = cleanout($refresh); $content = cleanout($content); $dir .= "/advertisers/"; if (! (file_exists ( $dir ))) { mkdir ( $dir, 0775 ); echo "
Directory created $dir

"; } $dir .= strtolower(substr($adv_nm,0,1)); makepage($dir,$adv_jump_file,$content); $dir = $types[$adv_link_type]['alpha3']; // $content = cleanout($types[$adv_program]['alpha4']); $dir .= "/advertisers"; makepage($dir,$adv_id.".inc",$content); } } } // echo $faillist; } function make_advertiser_lists (){ include "global_adv.inc"; global $types; $dir = $types[100]['alpha3']; $SQLstr = "select * from h_advertiser where adv_visible = 0 and adv_type = ".ADVERTISER; $result=MYSQL_QUERY("$SQLstr"); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { load_adv($row); $content .= " adv_id = '$adv_id' and "; } $content = "not ( $content adv_id = 0 )"; makepage($dir,"invalid_adv.inc",$content); } function make_category_lists(){ global $types; $dir = $types[100]['alpha3']; $SQLstr = "select * from h_word_groups"; $result=MYSQL_QUERY("$SQLstr"); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $wg = $row['wg_id']; $content = get_valid_child_categories($wg); makepage($dir,"catlist_$wg.inc",$content); } } function publishdir ($url_id){ include "global_url.inc"; include "global_template.inc"; include "global_generate.inc"; include "host.inc"; $now =date("Y-m-d"); $SQLstr = "select * from h_url,h_url_groups where url_ug_id = ug_id and url_id = $url_id"; $result=MYSQL_QUERY("$SQLstr"); $row = mysql_fetch_array($result); load_url($row); echo "\nprocessing $domain"; $dom =substr($domain,4); //remove "www." $pubdir = str_replace("***url***",$dom,$row['ug_basedir']); $pubdir = str_replace("***letter***",substr($dom,0,1)."___",$pubdir); // $bkdir="/home/pub_backups/$now"; // if (!is_dir($bkdir)) { // if (!mkdir($bkdir,0775)){ // echo "\nBACKUP DIR NOT CREATED $bkdir"; // } // if (!is_dir($bkdir)) { // echo "\MKDIR BACKUP FAILES 2 $bkdir"; // mkdir($bkdir, 0777, true); // if (!is_dir($bkdir)) // echo "\MKDIR BACKUP FAILED 3 $bkdir"; // } // } // $bkdir = "/home/pub_backups/$now/$dom/"; $fromdir = "$basedir/$domain/"; //echo "\nfrom $fromdir\nto $pubdir\nback $bkdir"; // dircopy($pubdir, $bkdir, TRUE, false); // if ($url_type != 12 && $url_type != 142) { // rm_recurse($pubdir); // } dircopy($fromdir, $pubdir, TRUE, false); } function process_maint($maint_id,$id,$action,$tag){ include "global_url.inc"; include "global_template.inc"; include "global_generate.inc"; include "global_page.inc"; include "global_prod.inc"; include "global_search.inc"; include "global_maint.inc"; include "global_affiliate.inc"; include 'global_adv.inc'; global $types, $templates, $allpages, $allcategories, $pubprodsused, $advid, $fault,$pid; global $faillist,$txt,$noglobal,$thisprogram,$progid; global $filelist; global $disablekeys,$insfile,$delfile,$addfile,$pid,$now,$prefix; global $nm,$link,$price,$img,$desc,$thumb,$pid,$meid,$now,$cat,$brand,$scat,$ibsn,$thisprogram,$merct,$badct,$pubcats,$ct,$pubcatct,$probcats, $chgs,$advid,$fault,$insfail,$addct,$chgct,$disablekeys,$insfile,$delfile,$addfile,$prefix; global $txt,$act,$cnt; include "host.inc"; $pid = getmypid (); $progid = $pid; $now =date("Y-m-d-H-i-s"); $txt .= "Starttime: $now\n"; upd_maint($maint_id,998); upd_maint_item($maint_id,'st_time',$now); echo "\n url $url_id,action$action"; switch ($action){ case "1": // release domain publishdir($id); $txt .= "Action: Release $domain \n"; upd_url_field ($id,"status",RELEASED); rec_release($id,$now); upd_maint($maint_id,COMPLETED); $rec= true; break; case "2": // generate domain gen_web($id); upd_url_field ($id,"status",GENERATED); $txt .= "Action: Generate domain $domain\n"; upd_maint($maint_id,COMPLETED); $rec= true; break; case "3": // generate and release domain gen_web($id); $now =date("Y-m-d-H-i-s"); $txt .= "Midtime: $now\n"; rec_maint($maint_id,$txt); publishdir($id); $txt .= "Action: Generate and Release $domain \n"; upd_url_field ($id,"status",RELEASED); if ($tag >0) { add_maint($id,$tag,"",""); } rec_release($id,$now); upd_maint($maint_id,COMPLETED); $rec= true; break; case "4": // create jumppages $txt .= "Action: Create Jump Pages\n"; jumppages (); $txt .= "Files creation errors: ".$faillist."\n"; upd_maint($maint_id,COMPLETED); $rec= true; $fault = 1; break; case "5": // create domain lists get_domain_list(); $txt .= "Action: Create Domain Lists\n"; $txt .= "Files Created: $filelist\n"; upd_maint($maint_id,COMPLETED); $rec= true; break; case "6": // CHMOD Files $txt .= "Action: CHMOD Files\n"; chmod_files(); upd_maint($maint_id,COMPLETED); $rec= true; break; case "7": // extract brands $txt .= "Action: Extract Brands\n"; get_brands(); upd_maint($maint_id,COMPLETED); $rec= true; break; case "8": // create excluded merchantlist $txt .= "Action: Create Excluded Merchant List\n"; make_advertiser_lists(); upd_maint($maint_id,COMPLETED); $rec= true; break; case "9": // Get Awin Products $txt .= "Action: Get Affiliate Window Products\n"; $mail_title = "Get Affiliate Window Products"; $act = "getmeta"; include "getfeeds2.inc"; get_feed(); $act = "loaddata"; get_feed(); upd_maint($maint_id,COMPLETED); $rec= true; $fault = 1; break; case "10": // Get TD Products $txt .= "Action: Get Trade Doubler Products $tag\n"; $mail_title = "Get Trade Doubler Products"; $batch=true; $act = "gettd"; $cnt = $tag; include "getfeeds2.inc"; get_feed(); $act = "loaddata"; get_feed(); upd_maint($maint_id,COMPLETED); $rec= true; $fault = 1; break; case "11": // generate HUB $txt .= "Action: Generate HUB\n"; make_hub_web($id); $now =date("Y-m-d-H-i-s"); $txt .= "Midtime: $now\n"; rec_maint($maint_id,$txt); publishdir($id); $txt .= "Action: Release HUB $domain \n"; upd_url_field ($id,"status",RELEASED); if ($tag >0) { add_maint($id,$tag,"",""); } rec_release($id,$now); upd_maint($maint_id,COMPLETED); $rec= true; $fault = 1; break; case "12": // generate HUB Category Node $txt .= "Action: Generate HUB Category Node\n"; upd_maint($maint_id,COMPLETED); $rec= true; break; case "13": // Generate Advertiser Pages $txt .= "Action: Generate Advertiser Pages\n"; upd_maint($maint_id,COMPLETED); $rec= true; break; case "14": // Clean Product Database routine $txt .= "Action: Clean Product Database routine\n"; upd_maint($maint_id,COMPLETED); $rec= true; break; case "15": // Discover Domains $txt .= "Action: Discover Domains\n"; discover_domains(); upd_maint($maint_id,COMPLETED); $rec= true; $fault = 1; break; case "16": // Link Brands to Word Categories $txt .= "Action: Link Brands to Word Categories\n"; link_brands(); upd_maint($maint_id,COMPLETED); $rec= true; break; case "17": // Get Buyat Products $txt .= "Action: Get Buyat Products\n"; $mail_title = "Get Buyat Products"; include "getfeeds2.inc"; $act = "getbuyat"; get_feed(); $act = "loaddata"; get_feed(); upd_maint($maint_id,COMPLETED); $rec= true; $fault = 1; break; case "19": // Make Category lists $txt .= "Action: Make Category lists\n"; make_category_lists(); upd_maint($maint_id,COMPLETED); $rec= true; break; case "20": // Generate All Released domains $mail_title = "Generate All Released domains\n"; $fault = 1; if ($id > 0) { $cats = " and (url_word_group_id = $id or url_word_group_id2 = $id) "; } $SQLstr = "select * from h_url where url_type = 11 $cats and url_status = ".RELEASED; $result=MYSQL_QUERY("$SQLstr"); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $id = $row['url_id']; gen_web($id); $now =date("Y-m-d-H-i-s"); $txt .= "Midtime: $now\n"; rec_maint($maint_id,$txt); publishdir($id); $txt .= "Action: Generate and Release $domain ($id)\n"; upd_url_field ($id,"status",RELEASED); if ($tag >0) { add_maint($id,$tag,"",""); } rec_release($id,$now); upd_maint($maint_id,COMPLETED); } $rec= true; break; case "21": // Daily Click Reporting $txt .= "Action: Daily Click Reporting\n"; $mail_title = "Daily Click Reporting"; $txt .= report_sql($maint_tag); upd_maint($maint_id,COMPLETED); $rec= true; $fault = 1; break; case "22": // Do Category Searches $now =date("Y-m-d-H-i-s"); $txt .= "Start time: $now\n"; $txt .= "Action: Get Category Searches\n"; do_cat_searches(); upd_maint($maint_id,COMPLETED); $rec= true; $mail_title = "SEARCH Results"; $fault = 1; add_maint("",23,0,""); break; case "23": // Do Need Gen Domains $txt .= "Action: Generating Domains Needing Doing\n"; $SQLstr = "select url_id from h_url, h_page,h_search ,h_links p, h_links s where url_type = 11 and url_rel_dt < search_refresh_dt and page_id = p.link_primary_id and p.link_secondary_id = search_id and p.link_type = 'pse' and url_id = s.link_primary_id and s.link_secondary_id = page_id and s.link_type = 'upg' and url_status = ".RELEASED. " group by url_id "; $result=MYSQL_QUERY("$SQLstr"); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $id = $row['url_id']; gen_web($id); $now =date("Y-m-d-H-i-s"); $txt .= "Midtime: $now\n"; rec_maint($maint_id,$txt); publishdir($id); $txt .= "Action: Generate and Release $domain \n"; upd_url_field ($id,"status",RELEASED); rec_release($id,$now); upd_maint($maint_id,COMPLETED); } // do_need_gen(); upd_maint($maint_id,COMPLETED); $rec= true; $mail_title = "Domain Gen for new Search Results"; $fault = 1; break; case "24": // Get Awin Merchants $txt .= "Action: Get Affiliate Window Merchants\n"; $mail_title = "Get All Affiliate Window Merchants\n"; $act = "getallmeta"; include "getfeeds2.inc"; get_feed(); upd_maint($maint_id,COMPLETED); $rec= true; $fault = 1; break; case "25": // Get Merchants Feed $txt .= "Action: Get Merchants Feed $id\n"; $act = "getmer"; $mid = $id; include "getfeeds2.inc"; get_feed(); upd_maint($maint_id,COMPLETED); $fault = 1; $rec= true; break; case "26": // Check and Build pages $txt .= "Action: Check and Build Domain Pages\n"; $mail_title = "Check and Build Domain Pages\n"; echo $mail_title; checkbuild_all_pages(); upd_maint($maint_id,COMPLETED); $rec= true; break; case "30": // Do all maintenance activities $txt .= "Action: Do All Maintenance activities\n"; $mail_title = "Check and Build Domain Pages\n"; $txt .= "Action: Create Jump Pages\n"; jumppages (); $txt .= "Files creation errors: ".$faillist."\n"; $txt .= "Action: Create Domain Lists\n"; get_domain_list(); $txt .= "Files Created: $filelist\n"; $txt .= "Action: Create Excluded Merchant List\n"; make_advertiser_lists(); $txt .= "Action: Discover Domains\n"; discover_domains(); $txt .= "Action: Get Affiliate Window Merchants\n"; $act = "getallmeta"; include "getfeeds2.inc"; $txt .= "Action: Check and Build Domain Pages\n"; checkbuild_all_pages(); upd_maint($maint_id,COMPLETED); $rec= true; break; case "31": // do all feeds for the day $txt .= "Action: Daily Feeds\n"; $mail_title = "Daily Feeds"; $batch=true; include "getfeeds3.inc"; $txt .= "Action: Get ALL Feeds Products\n"; get_feed(); upd_maint($maint_id,COMPLETED); $rec= true; $fault = 1; break; case "32": // create all banner images $txt .= "create all banner images for\n"; $mail_title = "create all banner images"; $SQLstr = "select * from h_url "; $result=MYSQL_QUERY("$SQLstr"); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { load_url($row); echo "\n$domain $uid"; $txt= str_replace("www","",$domain); $flnm = str_replace(".","",$txt)."_auto"; $flnm = make_txt_img("",$txt,"","",$flnm); upd_url_banner($uid,$flnm); } $rec= true; break; } if ($rec){ $now =date("Y-m-d-H-i-s"); $txt .= "\nEndtime: $now\n"; rec_maint($maint_id,$txt); upd_maint_item($maint_id,'end_time',$now); } if ($fault ==1){ mail_it("MAINTENANCE Results - $mail_title",$txt); } } ?>