Update of /cvsroot/php-blog/additional_plugins/serendipity_plugin_amazon
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7489
Modified Files:
serendipity_plugin_amazon.php
Log Message:
applied changes suggested by kevin polley for users without gdlib
Index: serendipity_plugin_amazon.php
===================================================================
RCS file: /cvsroot/php-blog/additional_plugins/serendipity_plugin_amazon/serendipity_plugin_amazon.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- serendipity_plugin_amazon.php 13 Nov 2004 02:15:52 -0000 1.2
+++ serendipity_plugin_amazon.php 24 Nov 2004 13:35:13 -0000 1.3
@@ -34,6 +34,9 @@
$propbag->add('name', PLUGIN_AMAZON_TITLE);
$propbag->add('description', PLUGIN_AMAZON_DESC);
$propbag->add('configuration', array('title', 'site', 'amazonid', 'asin', 'articleinfo', 'info_asin'));
+ $propbag->add('author', 'Thomas Nesges');
+ $propbag->add('stackable', true);
+ $propbag->add('version', '1.1');
}
function introspect_config_item($name, &$propbag) {
@@ -44,13 +47,13 @@
$propbag->add('description', PLUGIN_AMAZON_PROP_TITLE_DESC);
$propbag->add('default', PLUGIN_AMAZON_TITLE);
break;
-
+
case 'site':
$propbag->add('type', 'select');
$propbag->add('name', PLUGIN_AMAZON_SITE);
$propbag->add('description', PLUGIN_AMAZON_SITE_DESC);
$propbag->add('select_values', array('de' => 'Amazon.de', 'com' => 'Amazon.com'));
- $propbag->add('default', $serendipity['lang']=="en"?"com":$serendipity['lang']);
+ $propbag->add('default', ($serendipity['lang'] == 'en' ? 'com' : $serendipity['lang']));
break;
case 'amazonid':
@@ -66,13 +69,13 @@
$propbag->add('description', PLUGIN_AMAZON_ASIN_DESC);
$propbag->add('default', '');
break;
-
+
case 'articleinfo':
case 'info_asin':
$propbag->add('type', 'hidden');
$propbag->add('default', '');
break;
-
+
default:
return false;
}
@@ -95,7 +98,7 @@
$articleinfo = array();
$changesmade++;
}
-
+
foreach($config_asins as $asin) {
$asin = preg_replace('/\s+/', '', $asin);
$found = 0;
@@ -110,52 +113,54 @@
$changesmade++;
}
}
-
+
if($changesmade) {
$this->set_config('info_asin', $config_asin);
$this->set_config('articleinfo', serialize($articleinfo));
}
$show = rand(0, sizeof($articleinfo)-1);
- echo "<div align='center'><a href='".$articleinfo[$show][url]."/".$amazonid."' target='_SELF'><img src='".$articleinfo[$show][imgpath]."' alt='".$articleinfo[$show][desc]."' border='0'></a></div>";
+ echo "<div align='center'><a href='" . $articleinfo[$show]['url'] . "/" . $amazonid . "'><img src='" . $articleinfo[$show]['imgpath'] . "' alt='" . $articleinfo[$show]['desc'] . "' style='border: 0px'></a></div>";
}
-
+
function amazon_fetch($asin, $site="de") {
- $local_path = "uploads/amazon/$asin.jpg";
+ $local_path = "uploads/amazon/$asin";
$amazon_url = "http://www.amazon.".$site."/exec/obidos/ASIN/$asin";
$ret = array();
-
- if(! file_exists($local_path)) {
+
+ if(!file_exists($local_path . '.jpg') && !file_exists($local_path . '.gif') && !file_exists($local_path . '.png')) {
echo "<div style='font-size:xx-small'>";
- echo "getting $asin<br>";
+ echo "getting $asin<br />";
$content = join('', file($amazon_url));
- if(! $content) {
- echo "no content for $asin<br>";
+ if(!$content) {
+ echo "no content for $asin<br />";
}
-
+
if(preg_match('@<\s*meta\s+name\s*=\s*([\'"])description\1\s+content\s*=\s*([\'"])(.*?)\2@i', $content, $matches)) {
$description = $matches[3];
if(preg_match('/^([^,]*?), ([^,]*)$/', $description, $matches)) {
$description = $matches[2].": ".$matches[1];
}
if($description) {
- echo "description: <i>$description</i><br>";
+ echo "description: <i>$description</i><br />";
}
}
if(preg_match('@<\s*img.*?src=\s*([\'"])(http://images-eu\.amazon\.com/images/.+/'.$asin.'.+?\.(jpg|gif))\1\s+@i', $content, $matches)) {
$image_url = $matches[2];
$file_type = strtolower($matches[3]);
}
-
+
if($image_url) {
- echo "getting image<br>";
- @mkdir("uploads", 0755);
- @mkdir("uploads/amazon", 0755);
+ echo "getting image<br />";
+ @mkdir("uploads", 0755);
+ @mkdir("uploads/amazon", 0755);
switch($file_type) {
- case "jpg":
- $file = fopen($image_url, "rb");
+ case 'png':
+ case 'gif':
+ case 'jpg':
+ $file = @fopen($image_url, "rb");
if($file) {
- $save = fopen($local_path, "wb");
+ $save = @fopen($local_path . '.' . $file_type, "wb");
if($save) {
while($line = fread($file, 1024)) {
fwrite($save, $line);
@@ -164,24 +169,17 @@
}
break;
- case "gif":
- $img = imagecreatefromgif($image_url);
- imagejpeg($img, $local_path);
- break;
-
- case "png":
- $img = imagecreatefrompng($image_url);
- imagejpeg($img, $local_path);
- break;
+ default:
+ echo "unknown file type: '$file_type'<br />";
}
}
- echo "ready. next!<br><br>";
-
+ echo "ready. next!<br /><br />";
+
$ret['desc'] = $description;
}
-
+
$ret['asin'] = $asin;
- $ret['imgpath'] = $local_path;
+ $ret['imgpath'] = $local_path . '.' . $file_type;
$ret['url'] = $amazon_url;
return $ret;
}
|