Jump to content
dmkionut

evomag.ro - ceva interesant

Recommended Posts

Posted

cat /var/www/www.evomag.ro/admin/login/cron/feed_emag.php

<?php

function IsCustomSoft() {
if ($_SERVER['REMOTE_ADDR'] == '77.36.13.24' || $_SERVER['REMOTE_ADDR'] == '109.99.141.133') {
return true;
} else {
return false;
}
}

set_time_limit(0);
ini_set("memory_limit", "512M");

require_once("/var/www/www.evomag.ro/__config_with_connection.php");

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://apps.madball.ro/analizator-preturi/feed/?tree=1&auth=uuyb65vcvdpo1n6");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);

$test = curl_exec($ch);

curl_close($ch);

$fis = 'xml/emag.xml';
$fp = fopen($fis, 'w');
fwrite($fp, $test);
fclose($fp);

$handler = new XMLHandler();
$import = $handler->parseFeed($fis);

unlink($fis);

$IdMagazin=4; //eMAG.ro
$i = 0;
$cnt = 0;
$nr_produse=0;
$nuedatacorecta = 0;

while (isset($import["Magazin"]["Produs"]["$i"]["DataPret"]["value"])) {
$inreg = $import["Magazin"]["Produs"]["$i"];
$cod = $inreg["Cod"]["value"];
$preturi[$cod] = $inreg["Pret"]["value"];
$linkuri[$cod] = $inreg["URL"]["value"];
if (date('Y-m-d') != $inreg["DataPret"]["value"]){
$nuedatacorecta = 1;
}
$i++;
}

if ($nuedatacorecta == 1) {
echo "Preturile nu sunt de astazi pentru acest magazin! Va trebui rulat script-ul manual!";
} else {
mysql_query("DELETE FROM
IstoricPret
WHERE Moment=DATE(NOW()) and IdMagazin='".$IdMagazin."'");

foreach ($preturi as $cod => $pret){
$cnt++;
$query="(SELECT
id as IdProdus
FROM
produse
WHERE
cod_produs='" . $cod . "')
Union
(SELECT IdProdus
FROM
produse_echivalente
WHERE
CodProdus='" . $cod . "')";
$produs_query=mysql_query($query);
if (mysql_num_rows($produs_query)>0){

$produs=mysql_fetch_array($produs_query);
$query2="INSERT
IstoricPret (IdProdus, Moment, Pret, IdMagazin)
VALUES ('".$produs['IdProdus']."', DATE(NOW()), '".$pret."', '".$IdMagazin."')";
$rezquery=mysql_query($query2);
$eroaremysql=mysql_error();
if ($eroaremysql=='') {
$nr_produse++;
}

$query2="INSERT
IstoricPretAdrese (IdProdus, IdMagazin, Link)
VALUES ('".$produs['IdProdus']."', '".$IdMagazin."', '".$linkuri[$cod]."')
ON DUPLICATE KEY UPDATE Link = '".$linkuri[$cod]."';";
$rezquery=mysql_query($query2);
}
}


echo 'Au fost introduse in IstoricPret ' . $nr_produse .' inregistrari din produse eMAG ('.$cnt.' produse la magazin)!';
}

class XMLHandler {
function XMLHandler() {

}

function parseFeed($url) {
if (empty($url)) {
return array();
}

$feed = implode('', file($url));

return $this->XML2Array($feed);
}

function XML2Array($contents, $get_attributes=1) {
if(!$contents) return array();

if(!function_exists('xml_parser_create')) {
//PHP standard xml parser not found
return array();
}
//Get the XML parser of PHP - PHP must have this module for the parser to work
$parser = xml_parser_create();
xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, 0 );
xml_parser_set_option( $parser, XML_OPTION_SKIP_WHITE, 1 );
xml_parse_into_struct( $parser, $contents, $xml_values );
xml_parser_free( $parser );

if(!$xml_values) return;//Hmm...

//Initializations
$xml_array = array();
$parents = array();
$opened_tags = array();
$arr = array();

$current = &$xml_array;

//Go through the tags.
foreach($xml_values as $data) {
unset($attributes,$value);
extract($data);

$result = '';
if($get_attributes) {
$result = array();
if(isset($value)) $result['value'] = $value;

//Set the attributes too.
if(isset($attributes)) {
foreach($attributes as $attr => $val) {
if($get_attributes == 1) $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr'
}
}
} elseif(isset($value)) {
$result = $value;
}

if($type == "open") {
$parent[$level-1] = &$current;

if(!is_array($current) or (!in_array($tag, array_keys($current)))) { //Insert New tag
$current[$tag] = $result;
$current = &$current[$tag];

} else { //There was another element with the same tag name
if(isset($current[$tag][0])) {
array_push($current[$tag], $result);
} else {
$current[$tag] = array($current[$tag],$result);
}
$last = count($current[$tag]) - 1;
$current = &$current[$tag][$last];
}

} elseif($type == "complete") {
//See if the key is already taken.
if(!isset($current[$tag])) {
$current[$tag] = $result;

} else {
if((is_array($current[$tag]) and $get_attributes == 0)
or (isset($current[$tag][0]) and is_array($current[$tag][0]) and $get_attributes == 1)) {
array_push($current[$tag],$result);
} else {
$current[$tag] = array($current[$tag],$result);
}
}

} elseif($type == 'close') {
$current = &$parent[$level-1];
}
}

return($xml_array);
}

}
?>

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...