Мой е кода а curl e "web browser" за линукс и php. Бас държа че ти туко що научи какво е curl.
Като не е мой намери откъде съм го копирал! Бас държа че няма да намериш такъв код.
Информация с curl се взима както е в кода и това не е някаква философия а нещо елементарно! Мога да ти кажа че много отдавна, още преди няколко години съм писал такъв скрипт за баща ми който взема продукти от онлайн магазин като дори се логва с име и парола (дилърски акаунт) и пълни Mysql-а на друг онлайн магазин с Opencart ->
. Ако не вярваш ето публикувам кода и всъщност това доказва че горния код е мой /!\ (виждат се доста неща които съвпадат в двата кода като единствено се различава това че преди писах "{" на същия ред а сега ми харесва повече на нов):
Код за потвърждение: Избери целия код
#!/usr/bin/php
<?php
require_once( 'conf.php' );
require_once( 'mmc_functions.php' );
require_once( 'logging.php' );
$nl = "\n";
$start = microtime( true );
//foreach( array() as $v ) mmc_backup_table( DB_USR, DB_PWD, DB_NAME, $v, '/home/mmc/backups/'. $v .'_'. date( 'dmY-His' ) .'.sql' );
( $link = mysql_connect( 'localhost', DB_USR, DB_PWD ) ) or die( '1msqlerr: ' . mysql_error( $link ) );
mysql_select_db ( DB_NAME, $link ) or die( '2msqlerr: ' . mysql_error( $link ) );
mysql_query ( 'SET NAMES UTF8', $link );
/*_*/
// debug configuration
//
$start_from = 0;
//error_reporting( E_ERROR | E_PARSE | E_NOTICE );
error_reporting( E_ALL );
ini_set( 'display_errors', '1' );
mb_internal_encoding( 'UTF-8' );
libxml_use_internal_errors( true );
$log = new Logging( 'bot_dbp_log.txt' );
$log->lwrite('');
$log->lwrite('----------');
$log->lwrite('');
$log->lwrite('script started..');
$log->lwrite('');
/*_*/
/*
mysql_query( 'TRUNCATE TABLE `oc_product`', $link ) or die( 'msqlerr: ' . mysql_error( $link ) );
mysql_query( 'TRUNCATE TABLE `oc_product_description`', $link ) or die( 'msqlerr: ' . mysql_error( $link ) );
mysql_query( 'TRUNCATE TABLE `oc_product_to_category`', $link ) or die( 'msqlerr: ' . mysql_error( $link ) );
mysql_query( 'TRUNCATE TABLE `oc_product_to_store`', $link ) or die( 'msqlerr: ' . mysql_error( $link ) );
mysql_query( 'TRUNCATE TABLE `oc_product_image`', $link ) or die( 'msqlerr: ' . mysql_error( $link ) );
mysql_query( 'TRUNCATE TABLE `oc_product_attribute`', $link ) or die( 'msqlerr: ' . mysql_error( $link ) );
mysql_query( 'TRUNCATE TABLE `oc_product_special`', $link ) or die( 'msqlerr: ' . mysql_error( $link ) );
*/
/*
mysql_query( 'TRUNCATE TABLE `oc_attribute`' );
mysql_query( 'TRUNCATE TABLE `oc_attribute_group`' );
mysql_query( 'TRUNCATE TABLE `oc_attribute_description`' );
mysql_query( 'TRUNCATE TABLE `oc_attribute_group_description`' );
mysql_query( 'INSERT INTO `oc_attribute_group` VALUES( 1, 0 );', $link ) or die( 'msqlerr: ' . mysql_error( $link ) );
$attr_gr_name = rawurldecode( '%D0%A5%D0%B0%D1%80%D0%B0%D0%BA%D1%82%D0%B5%D1%80%D0%B8%D1%81%D1%82%D0%B8%D0%BA%D0%B8' );
mysql_query( 'INSERT INTO `oc_attribute_group_description` VALUES( 1, 1, \''. $attr_gr_name .'\' );', $link ) or die( 'msqlerr: ' . mysql_error( $link ) );
mysql_query( 'INSERT INTO `oc_attribute_group_description` VALUES( 1, 2, \''. $attr_gr_name .'\' );', $link ) or die( 'msqlerr: ' . mysql_error( $link ) );
*/
$prod_i = 0;
$larr = array('-', '\\', '|', '/');
$li = 0;
$manfs = array();
$subs = array();
$cids = array();
$last_pid = 0;
$prods = array();
$db_attrs = array();
$prod_attrs = array();
$prod_spec = array();
$rr = mysql_query( 'SELECT manufacturer_id, name FROM `oc_manufacturer`', $link ) or die( '3msqlerr: ' . mysql_error( $link ) );
while( $row = mysql_fetch_assoc( $rr ) ) $manfs[ $row[ 'name' ] ] = $row[ 'manufacturer_id' ];
$rr = mysql_query( 'SELECT c.parent_id, cd.category_id, cd.name FROM oc_category c, oc_category_description cd WHERE c.category_id = cd.category_id AND c.parent_id <> 0 AND cd.language_id = 2', $link ) or die( '4msqlerr: ' . mysql_error( $link ) );
while( $row = mysql_fetch_assoc( $rr ) ) { $subs[ $row[ 'category_id' ] ] = $row[ 'name' ]; $cids[ $row[ 'category_id' ] ] = $row[ 'parent_id' ]; }
//$rr = mysql_query( 'SELECT p.product_id, p.model FROM oc_product p', $link ) or die( 'msqlerr: ' . mysql_error( $link ) );
//while( $row = mysql_fetch_assoc( $rr ) ) { $prods[ $row[ 'model' ] ] = $row[ 'product_id' ]; }
$rr = mysql_query( 'SELECT p.product_id, p.model FROM oc_product p', $link ) or die( '5msqlerr: ' . mysql_error( $link ) );
while( $row = mysql_fetch_assoc( $rr ) ) { $prods[ $row[ 'model' ] ] = $row[ 'product_id' ]; $prod_attrs[ $row[ 'product_id' ] ] = array(); if( $row[ 'product_id' ] > $last_pid ) $last_pid = $row[ 'product_id' ]; }
$rr = mysql_query( 'SELECT `attribute_id`, `name` FROM `oc_attribute_description` WHERE language_id = 2 ;', $link ) or die( '6msqlerr: ' . mysql_error( $link ) );
while( $row = mysql_fetch_row( $rr ) ) $db_attrs[ $row[0] ] = $row[1];
$rr = mysql_query( 'SELECT a.product_id, a.attribute_id, a.text FROM oc_product_attribute a WHERE a.language_id = 2', $link ) or die( '7msqlerr: ' . mysql_error( $link ) );
while( $row = mysql_fetch_assoc( $rr ) ) $prod_attrs[ $row[ 'product_id' ] ][ $row[ 'attribute_id' ] ] = $row[ 'text' ];
$rr = mysql_query( 'SELECT product_special_id, product_id FROM `oc_product_special` WHERE customer_group_id = 1', $link ) or die( '8msqlerr: ' . mysql_error( $link ) );
while( $row = mysql_fetch_assoc( $rr ) ) $prod_spec[ $row[ 'product_id' ] ] = $row[ 'product_special_id' ];
$rr = mysql_query( 'SELECT product_special_id, product_id FROM `oc_product_special` WHERE customer_group_id = 2', $link ) or die( '9msqlerr: ' . mysql_error( $link ) );
while( $row = mysql_fetch_assoc( $rr ) ) $prod_spec_2[ $row[ 'product_id' ] ] = $row[ 'product_special_id' ];
$rr = mysql_query( 'SELECT product_special_id, product_id FROM `oc_product_special` WHERE customer_group_id = 3', $link ) or die( '10msqlerr: ' . mysql_error( $link ) );
while( $row = mysql_fetch_assoc( $rr ) ) $prod_spec_3[ $row[ 'product_id' ] ] = $row[ 'product_special_id' ];
/*_*/
$currFixing = array();
$rr = mysql_query( 'SELECT * FROM oc_currency', $link ) or die( '11msqlerr: ' . mysql_error( $link ) );
while( $row = mysql_fetch_assoc( $rr ) ) $currFixing[ $row[ 'code' ] ] = $row[ 'value' ];
$currFixing[ 'BGL' ] = $currFixing[ 'BGN' ];
/*
$currFixing = array( 'BGL' => 1, 'BGN' => 1 );
$currFixing[ 'EUR' ] = getCurrencyFixing( 'EUR' );
$currFixing[ 'USD' ] = getCurrencyFixing( 'USD' );
*/
echo "EUR FIXING: ". $currFixing[ 'EUR' ] ."\nUSD FIXING: ". $currFixing[ 'USD' ] ."\n\n";
/*_*/
$c = curl_init( 'http://polycomp.bg/poly/login' );
curl_setopt( $c, CURLOPT_HTTPHEADER, array( 'Host: polycomp.bg' ) );
curl_setopt( $c, CURLOPT_REFERER, 'http://polycomp.bg/poly/products' );
curl_setopt( $c, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13' );
curl_setopt( $c, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $c, CURLOPT_FOLLOWLOCATION, 1 );
//curl_setopt( $c, CURLOPT_POST, 1 );
curl_setopt( $c, CURLOPT_CUSTOMREQUEST, 'POST' );
curl_setopt( $c, CURLOPT_POSTFIELDS, 'username='. POLY_NAME .'&password='. POLY_PASS );
curl_setopt( $c, CURLOPT_COOKIEJAR, 'cookie.txt' );
// login and getting the shit && the status code
( $html = curl_exec( $c ) ) or die( 'curl error '. curl_error( $c ) ."\n" );
echo '[ curl status '. curl_getinfo( $c, CURLINFO_HTTP_CODE ) ." ]\n\n";
//$status = curl_getinfo( $c, CURLINFO_HTTP_CODE );
curl_setopt( $c, CURLOPT_FOLLOWLOCATION, 0 );
curl_setopt( $c, CURLOPT_HTTPGET, true );
/*_*/
foreach( $subs as $sub_id => $sub_name ) {
//echo $sub_name . "\n";
if( $sub_id < $start_from ) continue;
echo "\t-> loading file $sub_id..\n\n";
$doc = new DOMDocument();
if( !file_exists( 'dwnld/products_'. $sub_id .'.xls' ) ) {
echo "\nold category found -> $sub_id\n\n";
//error_log( date( '[ Y-m-d ]' ) ." old category found -> $sub_id\n", 1, 'mmc' );
//error_log( date( '[ Y-m-d ]' ) ." old category found -> $sub_id\n", 3, 'log_old_cats.txt' );
$log->lwrite( 'old category found -> '. $sub_id );
continue;
}
$doc->loadHTMLFile( 'dwnld/products_'. $sub_id .'.xls' );
$tablee = @$doc->getElementsByTagName( 'table' )->item(0)->childNodes;
//$tablee = @$doc->getElementsByTagName( 'table' )->item(1)->childNodes;
//echo 'table length: '. @$tablee->length ."\n\n";
$thead_tds = $tablee->item( 3 )->childNodes;
//echo 'thead length: '. @$thead_tds->length ."\n\n";
$p = array();
$pis = array();
/*foreach( $thead_tds as $ki => $thtd )
if( $thtd->nodeValue == 'Валута' )
$p[ 'Валута на '. $thead_tds->item( $ki - 1 )->nodeValue ] = $ki;
else
$p[ $thtd->nodeValue ] = $ki;*/
foreach( $thead_tds as $ki => $thtd )
$p[ $thtd->nodeValue ] = $ki;
$pis = $p;
for( $i=4; $i < @$tablee->length; $i++ ) {
$tr_tds = $tablee->item( $i )->childNodes;
if( $tr_tds->length != 14 and $tr_tds->length != 15 and $tr_tds->length != 16 ) break;
foreach( $pis as $ph => $pi )
if( is_numeric( $tr_tds->item( $pi )->nodeValue ) ) $p[$ph] = $tr_tds->item( $pi )->nodeValue;
elseif( $ph == 'Характеристики' )
$p[$ph] = $doc->saveXml( $tr_tds->item( $pi )->childNodes->item(0) );
else $p[$ph] = mysql_real_escape_string( $tr_tds->item( $pi )->nodeValue );
//
// custom index 4
$catNo = $p['Кат.номер'];
//$log->lwrite( 'catNo -> '. $catNo );
//
if(!isset( $prods[ $catNo ] )) {
if( rawurlencode( $p['Наличност'] ) == '%D1%81%20%D0%BF%D0%BE%D1%80%D1%8A%D1%87%D0%BA%D0%B0' ) continue;
$prod_notfound = true;
$pid = $last_pid + 1;
$prod_attrs[ $pid ] = array();
} else {
$pid = $prods[ $catNo ];
$prod_notfound = false;
}
//if( $pid != 11565 ) continue;
$prod_doc = new DOMDocument();
/*$fullName_exploded = explode ( ' + ', $fullName );
$catNo_exploded = explode ( '_', $catNo );
if( isset( $fullName_exploded[1] ) and isset( $catNo_exploded[1] ) ) {
echo "\nima podarycii: {$fullName_exploded[0]} [ {$catNo_exploded[0]} ] => {$fullName_exploded[1]} [ {$catNo_exploded[1]} ]\n";
}*/
$polyId = getProdPolyIdByCatNum( $c, $catNo );
if($polyId === false) {
$log->lwrite('losh produkt '. $catNo);
continue;
}
//if($polyId[1] != $catNo) $log->lwrite( 'symnitelen produkt ! -> '. $catNo );
if($polyId[1] != $catNo)
{
$log->lwrite( 'propuskane na produkt -> '. $catNo );
continue;
}
$polyId = $polyId[0];
//if($catNo == 'BE4582B001AA') echo "[ $polyId ] ";
//if( !in_array( $tr_tds->item(11)->nodeValue, $statuses ) ) $statuses[] = $tr_tds->item(11)->nodeValue;
curl_setopt( $c, CURLOPT_URL, 'http://polycomp.bg/poly/product-details/' . $polyId );
//mysql_query( "INSERT INTO `oc_product_to_poly` VALUES( '{$row[1]}', '$polyId' )" );
( $html = curl_exec( $c ) ) or die( curl_error( $c ) );
$kgs = 2;
//$p['Наименование'];
//$fullName = str_replace( '\'', '', substr( $html, strpos( $html, 'itemprop="description"' ) + 23, strpos( $html, '</p>', strpos( $html, 'itemprop="description"' ) )-strpos( $html, 'itemprop="description"' )-23 ) );
$fullName = mysql_real_escape_string( substr( $html, strpos( $html, 'itemprop="description"' ) + 23, strpos( $html, '</p>', strpos( $html, 'itemprop="description"' ) )-strpos( $html, 'itemprop="description"' )-23 ) );
//echo $fullName = substr( $name, , strpos( $name, '</p>' )-2 );
//echo "\n";
$prod_doc->loadHTML( '<?xml encoding="UTF-8">' . substr( $html, strpos( $html, 'class="margin_products"' ) ) );
$tables = $prod_doc->getElementsByTagName( 'table' );
/*
$i_priceTbl = false;
for( $t = 0; $t < $tables->length; $t++ ) {
// table mapping
//echo substr( $tables->item($t)->childNodes->item(0)->childNodes->item(0)->childNodes->item(2)->nodeValue, 0, 4 );
if( isset( $tables->item($t)->childNodes->item(0)->childNodes->item(0)->childNodes->item(2)->nodeValue )and( rawurlencode( substr( $tables->item($t)->childNodes->item(0)->childNodes->item(0)->childNodes->item(2)->nodeValue, 0, 8 ) ) == '%D0%A6%D0%B5%D0%BD%D0%B0' ) )
$i_priceTbl = $t;
//else if( isset( $tables->item($t)->childNodes->item(0)->childNodes->item(0)->childNodes->item(0)->nodeValue )and( $tables->item($t)->getAttribute( 'class' ) != 'hide' ) )
// $i_charsTbl = $t;
}
*/
/*$prod_doc->loadHTML( '<?xml encoding="UTF-8">' . substr( $html, strpos( $html, 'id="product_text"' ) ) );*/
$prod_doc->loadHTML( '<?xml encoding="UTF-8">' . substr( $html, strpos( $html, '<h1 class="parameters_title">' ) ) );
if( method_exists( $tables, 'item' ) and isset( $tables->item( 0 )->childNodes ) ) {
foreach( $tables->item( 0 )->childNodes as $k => $tr_tdsr ) {
$attr = mysql_real_escape_string( $tr_tdsr->childNodes->item(0)->nodeValue );
$attr_val = mysql_real_escape_string( $tr_tdsr->childNodes->item(2)->nodeValue );
if ( rawurlencode( $attr ) == '%D0%A2%D0%B5%D0%B3%D0%BB%D0%BE%2C%20kg' ) {
$test = explode( ' ', $attr_val, 3 );
if( isset( $test[1] ) and ( $test[1] == 'kg' ) ) $kgs = ( float )$test[0];
}
if ( ( $attr_id = array_search( $attr, $db_attrs, true ) ) === false ) {
mysql_query( 'INSERT IGNORE `oc_attribute` VALUES( DEFAULT, 1, '. $k .' );', $link ) or die( '12msqlerr: ' . mysql_error( $link ) );
$attr_id = mysql_insert_id( $link );
mysql_query( 'INSERT IGNORE `oc_attribute_description` VALUES( '. $attr_id .', 1, \''. $attr .'\' );', $link ) or die( '13msqlerr: ' . mysql_error( $link ) );
mysql_query( 'INSERT IGNORE `oc_attribute_description` VALUES( '. $attr_id .', 2, \''. $attr .'\' );', $link ) or die( '14msqlerr: ' . mysql_error( $link ) );
$db_attrs[ $attr_id ] = $attr;
echo date( '[ H:i:s Y-m-d ]' ) .' inserted new attribute with id [ '. $attr_id .' ]'. $nl;
}
if ( !isset( $prod_attrs[ $pid ][ $attr_id ] ) ) {
mysql_query( 'INSERT IGNORE `oc_product_attribute` VALUES ( \''. $pid .'\', \''. $attr_id .'\', \'1\', \''. $attr_val .'\' );', $link ) or die( '15msqlerr: ' . mysql_error( $link ) );
mysql_query( 'INSERT IGNORE `oc_product_attribute` VALUES ( \''. $pid .'\', \''. $attr_id .'\', \'2\', \''. $attr_val .'\' );', $link ) or die( '16msqlerr: ' . mysql_error( $link ) );
} else if ( $prod_attrs[ $pid ][ $attr_id ] != $attr_val )
mysql_query( "UPDATE `oc_product_attribute` SET text = '$attr_val' WHERE product_id = $pid AND attribute_id = $attr_id", $link ) or die( '17msqlerr: ' . mysql_error( $link ) );
// last part depends on predicted pid
}
}
$prod_doc->loadHTML( '<?xml encoding="UTF-8">' . substr( $html, strpos( $html, 'class="margin_products"' ) ) );
// stock_status
switch ( rawurlencode( $p['Наличност'] ) ) {
case '%D0%BD%D0%B0%20%D1%81%D0%BA%D0%BB%D0%B0%D0%B4': $status = 7; $quantity = 54; $prod_status = 1; break;
case '%D0%BD%D0%B0%20%D0%BF%D1%8A%D1%82': $status = 6; $quantity = 0; $prod_status = 1; break;
case '%D1%81%20%D0%BF%D0%BE%D1%80%D1%8A%D1%87%D0%BA%D0%B0': $status = 8; $quantity = 0; $prod_status = 1; break;
case '%D0%BE%D0%B3%D1%80%D0%B0%D0%BD%D0%B8%D1%87%D0%B5%D0%BD%D0%BE%20%D0%BA%D0%BE%D0%BB%D0%B8%D1%87%D0%B5%D1%81%D1%82%D0%B2%D0%BE': $status = 9; $quantity = 5; $prod_status = 1; break;
case '%D1%81%D0%BF%D1%80%D1%8F%D0%BD': $status = 5; $quantity = 0; $prod_status = 0; break;
default: $status = 5; $quantity = 0; $prod_status = 0;
}
//
// some shits
$img = 'prod/' . $pid . '_0.jpg'; // depends on predicted pid
// kgs are set !
$price = ( (float)$p['Цена към дилъри без отстъпка'] ) / $currFixing[ $p['Валута'] ];
$price_dealer = ( (float)$p['Цена към дилъри'] ) / $currFixing[ $p['Валута'] ];
//
// $$ fine tuning
$price *= 1.03;
$price_client_spec = $price_dealer * 1.088;
//$price_firmi_spec = $price_dealer * 1.05;
$price_firmi_spec = ( (float)$p['Цена към дилъри без отстъпка'] ) / $currFixing[ $p['Валута'] ];
/*
//$price = 0;
//$price_dealer = 0;
//if( ( $i_priceTbl !== false ) and method_exists( $tables, 'item' ) and method_exists( $tables->item( $i_priceTbl )->childNodes, 'item' ) and method_exists( $tables->item( $i_priceTbl )->childNodes->item(1)->childNodes, 'item' ) ) {
//if( isset( $tables->item( $i_priceTbl )->childNodes->item(1)->childNodes->item(1)->childNodes ) and isset( $tables->item( $i_priceTbl )->childNodes->item(1)->childNodes->item(0)->childNodes ) ) {
// if( method_exists( $tables->item( $i_priceTbl )->childNodes->item(1)->childNodes->item(1)->childNodes, 'item' ) )
// $price = ( float )str_replace( ',', '.', preg_replace( '/\s+/u', '', $tables->item( $i_priceTbl )->childNodes->item(1)->childNodes->item(1)->childNodes->item(4)->nodeValue ) );
// if( method_exists( $tables->item( $i_priceTbl )->childNodes->item(1)->childNodes->item(0)->childNodes, 'item' ) and ( ( $price_dealer = ( float )str_replace( ',', '.', preg_replace( '/\s+/u', '', $tables->item( $i_priceTbl )->childNodes->item(1)->childNodes->item(0)->childNodes->item(4)->nodeValue ) ) ) != 0 ) ) {
*/
if( $price != $price_dealer ) {
if( ( $price - $price_dealer ) < 3 )
$price = $price_dealer + 4;
/*if( $price_dealer >= 250 and $p['Промоция'] != 'NON' ) {
if( isset( $prod_spec[ $pid ] ) )
mysql_query( "UPDATE `oc_product_special` SET price='$price_client_spec', date_start = NOW() WHERE product_special_id = ". $prod_spec[ $pid ], $link ) or die( '18msqlerr: ' . mysql_error( $link ) );
else
mysql_query( "INSERT INTO `oc_product_special` VALUES ( NULL, '$pid', '1', '1', '$price_client_spec', NOW(), '5454-12-12' )", $link ) or die( '19msqlerr: ' . mysql_error( $link ) );
}*/
if( isset( $prod_spec_2[ $pid ] ) )
mysql_query( "UPDATE `oc_product_special` SET price='$price_firmi_spec' WHERE product_special_id = ". $prod_spec_2[ $pid ], $link ) or die( '20msqlerr: ' . mysql_error( $link ) );
else
mysql_query( "INSERT INTO `oc_product_special` VALUES ( NULL, '$pid', '2', '1', '$price_firmi_spec', NOW(), '5454-12-12' )", $link ) or die( '21msqlerr: ' . mysql_error( $link ) );
if( isset( $prod_spec_3[ $pid ] ) )
mysql_query( "UPDATE `oc_product_special` SET price='$price_dealer' WHERE product_special_id = ". $prod_spec_3[ $pid ], $link ) or die( '22msqlerr: ' . mysql_error( $link ) );
else
mysql_query( "INSERT INTO `oc_product_special` VALUES ( NULL, '$pid', '3', '1', '$price_dealer', NOW(), '5454-12-12' )", $link ) or die( '23msqlerr: ' . mysql_error( $link ) );
}
// }
//}
if( $price == 0 or $price_dealer == 0 ) { $quantity = 0; $prod_status = 0; }
$tax_class_id = 10;
//
// oc_product_description
// fullname
$html = mysql_real_escape_string( $p['Характеристики'] );
//$html = '';
$meta_desc = '';
$meta_keys = '';
$tag = '';
//
/*_*/
if( !isset( $manfs[ $manname = mb_substr( $fullName, mb_strpos( $fullName, ',' ) + 2, mb_strpos( $fullName, ' ', mb_strpos( $fullName, ',' )+2 )-mb_strpos( $fullName, ',' )-2 ) ] ) ) {
mysql_query( 'INSERT INTO `oc_manufacturer` VALUES ( DEFAULT, \''. $manname .'\', NULL, 0 )', $link ) or die( '24msqlerr: ' . mysql_error( $link ) );
$manid = mysql_insert_id( $link );
mysql_query( 'INSERT INTO `oc_manufacturer_to_store` VALUES ( \''. $manid .'\', 0 )', $link ) or die( '25msqlerr: ' . mysql_error( $link ) );
$manfs[ $manname ] = $manid;
}
/*_*/
if( $prod_notfound ) {
mysql_query( $q_product = "INSERT INTO `oc_product` VALUES ( DEFAULT, '$catNo', '', '', '', '', '', '', '', '9999', '$status', '$img', '". $manfs[ $manname ] ."', '1', '$price', '0', '$tax_class_id', '0000-00-00 00:00:00', '$kgs', 1, 0, 0, 0, 0, '0', '1', '0', '1', NOW(), NOW(), 0 ) ;", $link ) or die( '26msqlerr: ' . mysql_error( $link ) );
$pid = mysql_insert_id( $link );
if( $pid != ( $last_pid + 1 ) ) echo date( '[ H:i:s Y-m-d ]' ) .' PRODUCT ID MISHMASH -> predicted[ '. $last_pid+1 .' ], inserted [ '. $pid .' ]'. $nl;
$last_pid = $pid;
$q_product_description = "INSERT INTO `oc_product_description` VALUES ( '$pid', '1', '$fullName', '$html', '$meta_desc', '$meta_keys', '$tag', NULL, NULL, NULL );";
$q_product_description2 = "INSERT INTO `oc_product_description` VALUES ( '$pid', '2', '$fullName', '$html', '$meta_desc', '$meta_keys', '$tag', NULL, NULL, NULL );";
$q_product_to_category = "INSERT INTO `oc_product_to_category` VALUES ( '$pid', '$sub_id' );";
mysql_query( "INSERT INTO `oc_product_to_category` VALUES ( '$pid', '{$cids[$sub_id]}' );", $link ) or die( '27msqlerr: '. mysql_error( $link ) );
$q_product_to_store = "INSERT INTO `oc_product_to_store` VALUES ( '$pid', '0' );";
//echo $q_product_description . "\n";
mysql_query( $q_product_description, $link ) or die( '28msqlerr: ' . mysql_error( $link ) );
mysql_query( $q_product_description2, $link ) or die( '29msqlerr: ' . mysql_error( $link ) );
//echo $q_product_to_category . "\n";
mysql_query( $q_product_to_category, $link ) or die( '30msqlerr: ' . mysql_error( $link ) );
mysql_query( $q_product_to_store, $link ) or die( '31msqlerr: ' . mysql_error( $link ) );
$imgNo = 0;
foreach( $prod_doc->getElementsByTagName( 'img' ) as $img )
if( ( $img->getAttribute( 'width' ) == '160px' ) && ( $img->getAttribute( 'height' ) == '141px' ) && ( substr( $imgSrc = $img->getAttribute( 'src' ), 0, strlen( 'http://polycomp.bg/poly/image/' ) ) == 'http://polycomp.bg/poly/image/' ) ) {
dwnldImg( $imgSrc .'&scale=false', '../../image/prod/'. $pid .'_'. $imgNo .'.jpg' );
//if( $imgNo > 0 )
mysql_query( 'INSERT INTO `oc_product_image` VALUES ( DEFAULT, \''. $pid .'\', \'prod/'. $pid .'_'. $imgNo .'.jpg\', 0 );', $link ) or die( '32msqlerr: ' . mysql_error( $link ) );
$imgNo++;
}
echo date( '[ H:i:s Y-m-d ]' ) .' inserted new product [ '. $catNo .' ] => prod_id [ '. $pid .' ]'. $nl;
} else {
$q_product = "UPDATE `oc_product` SET quantity='$quantity', stock_status_id = '$status', manufacturer_id = '". $manfs[ $manname ] ."', price = '$price', weight = '$kgs', status='$prod_status', date_modified = NOW() WHERE product_id = '$pid' ;";
$q_product_description = "UPDATE `oc_product_description` SET name = '$fullName', description = '$html', meta_description = '$meta_desc', meta_keyword = '$meta_keys', tag = '$tag' WHERE product_id = '$pid' ;";
$q_product_to_category = "UPDATE `oc_product_to_category` SET category_id = '$sub_id' WHERE product_id = '$pid' AND category_id = '$sub_id' ;";
//mysql_query( "INSERT INTO `oc_product_to_category` VALUES ( '$pid', '{$cids[$sub_id]}' );", $link ) or die( 'msqlerr: '. mysql_error( $link ) );
mysql_query( $q_product, $link ) or die( '33msqlerr: ' . mysql_error( $link ) );
mysql_query( $q_product_description, $link ) or die( '34msqlerr: ' . mysql_error( $link ) );
mysql_query( $q_product_to_category, $link ) or die( '35msqlerr: ' . mysql_error( $link ) );
/*
foreach( $prod_doc->getElementsByTagName( 'img' ) as $img )
if( ( $img->getAttribute( 'width' ) == '160px' ) && ( $img->getAttribute( 'height' ) == '141px' ) && ( substr( $imgSrc = $img->getAttribute( 'src' ), 0, strlen( 'http://polycomp.bg/poly/image/' ) ) == 'http://polycomp.bg/poly/image/' ) ) {
mysql_query( 'INSERT INTO `oc_product_image` VALUES ( DEFAULT, \''. $pid .'\', \'prod/'. $pid .'_0.jpg\', 0 );', $link ) or die( 'msqlerr: ' . mysql_error( $link ) );
break;
}
*/
echo date( '[ H:i:s Y-m-d ]' ) .' updated product [ '. $catNo .' ] => prod_id [ '. $pid .' ]'. $nl;
}
echo "{$larr[ $li ]}\r"; if( $li == 3 ) $li = 0; else $li++;
$prod_i++;
}
}
if( $prod_i > 1000 ) {
mysql_query ( 'UPDATE oc_product SET stock_status_id=8, quantity=0, status=0 WHERE date_modified NOT LIKE "'. date( 'Y-m-d' ) .'%"', $link );
$log->lwrite( 'disabling olds..' );
error_log( date( '[ Y-m-d ]' ) ." script-a prikluchi sled $prod_i produkta i uspq da premahne starite !\nwij loga tuk -> http://www.mmcenter.bg/admin/anexAlex/bot_dbp_log.txt\n", 1, 'mmc' );
} else {
error_log( date( '[ Y-m-d ]' ) ." script-a prikluchi sled $prod_i produkta bez da uspee da premahne starite !\nwij loga tuk -> http://www.mmcenter.bg/admin/anexAlex/bot_dbp_log.txt\n", 1, 'mmc' );
}
//mysql_query ( 'UPDATE oc_product SET stock_status_id=7, quantity=54, status=1 WHERE 1', $link );
$time_taken = microtime(true) - $start;
$log->lwrite('');
$log->lwrite('script done.');
$log->lwrite('');
$log->lwrite('script summary:');
$log->lwrite( 'prods: '. $prod_i );
$log->lwrite('');
$log->lwrite( $time_taken );
$log->lclose();
curl_close( $c );
mysql_close( $link );
echo $time_taken . "\n";
?>
"Това е неграмотно написан код, пълен с грешки и абсурди, които не можеш да си представиш. Не препоръчвам да го ползвате"
За да кажеш такова нещо трябва да се аргументираш като кажеш какво по-точно му има. Мога да кажа че на кода му няма абсолютно нищо и работи перфектно!
Трябва само да го променя защото се сетих че при всяко пускане ще банва хората на които им е изтекъл бана наново.