1<?php 2/** 3 * PhotoWidget Plugin: Generate feed photowidget format XML output 4 * 5 * @author Jonathan Tsai <tryweb@ichiayi.com> 6 * @date 10:57 2012/9/11 7 * 2012/4/13 8 * 1. Release first version 9 * 2012/9/11 10 * 1. Bug Fix for Debian, Thanks for Andre 11 * 12 */ 13 14 extract($_GET, EXTR_PREFIX_ALL, 'p'); 15 extract($_POST, EXTR_PREFIX_ALL, 'p'); 16 $w_feed = str_replace("_andand_", "&", urldecode($p_feed)); 17 18 if (substr($w_feed, 0, 28) == 'https://picasaweb.google.com') { 19 # Picasa - https://picasaweb.google.com/data/feed/base/user/105702831509661581714/albumid/5730701044821175185?alt=rss&kind=photo&hl=zh_TW 20 $arr_image = parsing_picasa_rss($w_feed); 21 } 22 else if (substr($w_feed, 0, 21) == 'http://api.flickr.com') { 23 # Filckr - http://api.flickr.com/services/feeds/photoset.gne?set=72157607663864583&nsid=76823408@N00&lang=zh-hk 24 $arr_image = parsing_filckr_rss($w_feed); 25 } 26 else { 27 # Gallery3 - http://photos.ichiayi.com/gallery3/index.php/rss/feed/gallery/album/588 28 $arr_image = parsing_gallery3_rss($w_feed); 29 } 30 31 $xmlhead = '<?xml version="1.0" encoding="utf-8"?>'; 32 $xmldata = ''; 33 foreach ($arr_image as $w_url => $w_img) { 34 $xmldata .= '<image href="'.$w_url.'">'.$w_img.'</image>'."\n"; 35 } 36 echo $xmlhead."\n<images>".$xmldata."</images>"; 37 38 // 14:25 2012/4/13 39 function parsing_picasa_rss($p_feed) { 40 $p = xml_parser_create(); 41 xml_parse_into_struct($p, file_get_contents($p_feed), $vals, $index); 42 xml_parser_free($p); 43 44 for($i=0;$i<count($vals);$i++){ 45 if ($vals[$i]['tag']=='DESCRIPTION' && $vals[$i]['level']==4) { 46 $p = xml_parser_create(); 47 xml_parse_into_struct($p, $vals[$i]['value'], $imgvals); 48 xml_parser_free($p); 49 for($j=0;$j<count($imgvals);$j++){ 50 if ($imgvals[$j]['tag']=='A' && $imgvals[$j]['type']=='open') { 51 $url = $imgvals[$j]['attributes']['HREF']; 52 } 53 if ($imgvals[$j]['tag']=='IMG') { 54 $img = $imgvals[$j]['attributes']['SRC']; 55 } 56 } 57 #echo "[$url]=>$img\n"; 58 $arr_result[$url] = $img; 59 } 60 } 61 62 return($arr_result); 63 } 64 65 // 20:13 2012/4/13 66 function parsing_filckr_rss($p_feed) { 67 $p = xml_parser_create(); 68 xml_parse_into_struct($p, file_get_contents($p_feed), $vals, $index); 69 xml_parser_free($p); 70 71 for($i=0;$i<count($vals);$i++){ 72 if ($vals[$i]['tag']=='CONTENT') { 73 $str = $vals[$i]['value']; 74 $str = _str_cut($str, '</p>', 'left'); 75 $str = _str_cut($str, '<p><a href="', 'left'); 76 $url = _str_cut($str, '"', 'right'); 77 $str = _str_cut($str, '<img src="', 'left'); 78 $img = _str_cut($str, '"', 'right'); 79 #echo "[$url]=>$img\n"; 80 $arr_result[$url] = $img; 81 } 82 } 83 84 return($arr_result); 85 } 86 87 // 20:39 2012/4/13 88 function parsing_gallery3_rss($p_feed) { 89 $p = xml_parser_create(); 90 xml_parse_into_struct($p, file_get_contents($p_feed), $vals, $index); 91 xml_parser_free($p); 92 93 for($i=0;$i<count($vals);$i++){ 94 if ($vals[$i]['tag']=='LINK' && $vals[$i]['level']==4) { 95 #echo "[$i]--LINK Level4\n"; 96 $url = $vals[$i]['value']; 97 } 98 if ($vals[$i]['tag']=='MEDIA:THUMBNAIL') { 99 $img = $vals[$i]['attributes']['URL']; 100 #echo "[$url]=>$img\n"; 101 $arr_result[$url] = $img; 102 $url = ''; 103 } 104 } 105 106 return($arr_result); 107 } 108 109 /* 00:04 2012/4/9 Jonathan Tsai 110 Add for CardioTrainer 111 */ 112 function _str_cut($src, $keyword, $mode) 113 { 114 $keyword_pos = strpos($src, $keyword); 115 if ($mode == 'right') { 116 $result = substr($src, 0, $keyword_pos); 117 } 118 else { 119 $result = substr($src, $keyword_pos+strlen($keyword)); 120 } 121 return $result; 122 } 123 124?>