$v)
{
if (is_array($v))
{
strip_slashes_from_user_data($array[$k]);
continue;
}
$array[$k] = stripslashes($v);
}
}
strip_slashes_from_user_data($_GET);
strip_slashes_from_user_data($_POST);
strip_slashes_from_user_data($_COOKIE);
}
class wishList
{
private $is_allowed = false;
private $wishlist = array();
private $wishlis_file = false;
const STATUS_ALREADY_HAVE = 1;
const STATUS_NEED = 10;
const STATUS_NEED_MORE = 20;
public function __construct()
{
$host = gethostbyaddr($_SERVER['REMOTE_ADDR']);
if (preg_match('!'.ALLOW_HOST.'!', $host))
$this->is_allowed = true;
$this->wishlist_file = dirname(__FILE__) . '/wishlist.datas';
if (file_exists($this->wishlist_file))
{
require $this->wishlist_file;
}
}
public function save()
{
$out = 'wishlist = array(';
function escape($str)
{
$str = str_replace("\n", "\\n", $str);
return str_replace("\"", "\\\"", $str);
}
foreach ($this->wishlist as $id=>$item)
{
$out .= '
"' . $id . '" => array(
"title" => "'.escape($item['title']).'",
"url" => "'.escape($item['url']).'",
"desc" => "'.escape($item['desc']).'",
"author" => "'.escape($item['author']).'",
"price" => "'.escape($item['price']).'",
"image_url" => "'.escape($item['image_url']).'",
"status" => '.(int)$item['status'].',
"date" => "'.(int)$item['date'].'",
),';
}
$out .= ");\n?>";
file_put_contents($this->wishlist_file, $out);
}
public function import($orig_url)
{
if (!$this->is_allowed)
throw new Exception("Not allowed to add item");
if (!preg_match('!^(http://www.amazon.fr/[^/]+/dp/([A-Z0-9]+)/).*!i', $orig_url, $match))
throw new Exception("Invalid URL");
$url = $match[1];
$id = $match[2];
if (!empty($this->wishlist[$id]))
throw new Exception("Item already in list");
$title = false;
$image_url = false;
$price = false;
$desc = false;
$author = false;
$in_desc = false;
$context = stream_context_create(array(
'http' => array(
'method' => 'GET',
'headers' => "User-Agent: Opera/9.25 (X11; Linux i686; U; fr)\r\n",
'timeout' => 5,
),
)
);
$fp = fopen($orig_url, 'r', false, $context);
while (!feof($fp))
{
$line = trim(fgets($fp, 4096));
if (preg_match('!([^<]+)!i', $line, $match))
$title = $match[1];
if (!$author && preg_match('!([~]|de)\s+(([^<]+)!', $match[1], $match2, PREG_SET_ORDER);
foreach ($match2 as $m)
{
if ($author) $author .= ', ';
$author .= $m[1];
}
}
elseif (preg_match('!]+src="([^"]+)"\s+id="prodImage"!i', $line, $match))
$image_url = $match[1];
elseif (preg_match('!EUR ([^<]+)!i', $line, $match))
$price = $match[1];
elseif (preg_match('!