PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/tag/feed/Atom10.php

http://rhaco.googlecode.com/
PHP | 335 lines | 135 code | 6 blank | 194 comment | 19 complexity | a14d88672c6ae239843181cff7159045 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. Rhaco::import("tag.feed.Atom");
  3. Rhaco::import("tag.feed.model.AtomAuthor");
  4. Rhaco::import("tag.feed.model.AtomLink");
  5. Rhaco::import("tag.feed.model.AtomEntry10");
  6. Rhaco::import("tag.model.SimpleTag");
  7. Rhaco::import("lang.Variable");
  8. /**
  9. * Atom10 Model
  10. *
  11. * @author Kazutaka Tokushima
  12. * @license New BSD License
  13. * @copyright Copyright 2005- rhaco project. All rights reserved.
  14. */
  15. class Atom10 extends Atom{
  16. var $version = "1.0";
  17. var $title = "";
  18. var $subtitle = "";
  19. var $updated = null;
  20. var $id = "";
  21. var $link = array();
  22. var $generator = "";
  23. var $entryList = array();
  24. var $author = null;
  25. function Atom10(){
  26. }
  27. /**
  28. * ?????Atom10??????
  29. *
  30. * @param string $src
  31. */
  32. function set($src){
  33. /***
  34. * unit("tag.feed.Atom10Test");
  35. *
  36. * $src = <<< __XML__
  37. * <feed xmlns="http://www.w3.org/2005/Atom">
  38. * <title>atom10 feed</title>
  39. * <subtitle>atom10 sub title</subtitle>
  40. * <updated>2007-07-18T16:16:31+00:00</updated>
  41. * <generator>tokushima</generator>
  42. * <link href="http://tokushimakazutaka.com" rel="abc" type="xyz" />
  43. *
  44. * <author>
  45. * <url>http://tokushimakazutaka.com</url>
  46. * <name>tokushima</name>
  47. * <email>tokushima@hoge.hoge</email>
  48. * </author>
  49. *
  50. * <entry>
  51. * <title>rhaco</title>
  52. * <summary type="xml" xml:lang="ja">summary test</summary>
  53. * <content type="text/xml" mode="abc" xml:lang="ja" xml:base="base">atom content</content>
  54. * <link href="http://rhaco.org" rel="abc" type="xyz" />
  55. * <link href="http://conveyor.rhaco.org" rel="abc" type="conveyor" />
  56. * <link href="http://lib.rhaco.org" rel="abc" type="lib" />
  57. *
  58. * <updated>2007-07-18T16:16:31+00:00</updated>
  59. * <issued>2007-07-18T16:16:31+00:00</issued>
  60. * <published>2007-07-18T16:16:31+00:00</published>
  61. * <id>rhaco</id>
  62. * <author>
  63. * <url>http://rhaco.org</url>
  64. * <name>rhaco</name>
  65. * <email>rhaco@rhaco.org</email>
  66. * </author>
  67. * </entry>
  68. *
  69. * <entry>
  70. * <title>django</title>
  71. * <summary type="xml" xml:lang="ja">summary test</summary>
  72. * <content type="text/xml" mode="abc" xml:lang="ja" xml:base="base">atom content</content>
  73. * <link href="http://djangoproject.jp" rel="abc" type="xyz" />
  74. *
  75. * <updated>2007-07-18T16:16:31+00:00</updated>
  76. * <issued>2007-07-18T16:16:31+00:00</issued>
  77. * <published>2007-07-18T16:16:31+00:00</published>
  78. * <id>django</id>
  79. * <author>
  80. * <url>http://www.everes.net</url>
  81. * <name>everes</name>
  82. * <email>everes@hoge.hoge</email>
  83. * </author>
  84. * </entry>
  85. *
  86. * </feed>
  87. * __XML__;
  88. *
  89. * $xml = new Atom10();
  90. * assert($xml->set($src));
  91. * eq("atom10 feed",$xml->getTitle());
  92. * eq("atom10 sub title",$xml->getSubTitle());
  93. * eq("http://tokushimakazutaka.com",$xml->getLinkHref());
  94. * eq("2007-07-19T01:16:31Z",$xml->getUpdated());
  95. * eq("tokushima",$xml->getGenerator());
  96. *
  97. * $author = $xml->getAuthor();
  98. * eq("http://tokushimakazutaka.com",$author->getUrl());
  99. * eq("tokushima",$author->getName());
  100. * eq("tokushima@hoge.hoge",$author->getEmail());
  101. *
  102. * eq(2,sizeof($xml->getEntry()));
  103. * foreach($xml->getEntry() as $entry){
  104. * assert(Variable::istype("AtomEntry10",$entry));
  105. * }
  106. */
  107. if(simpleTag::setof($tag,$src,"feed")){
  108. if($tag->getParameter("xmlns") != "http://www.w3.org/2005/Atom") return false;
  109. foreach($tag->getIn("entry") as $intag){
  110. $data = new AtomEntry10();
  111. $data->set($intag->get());
  112. $this->entryList[] = $data;
  113. $src = str_replace($intag->getPlain(),"",$src);
  114. }
  115. $tag->set($src,"feed");
  116. $this->setId($tag->getInValue("id"));
  117. $this->setTitle($tag->getInValue("title"));
  118. $this->setSubtitle($tag->getInValue("subtitle"));
  119. $this->setUpdated($tag->getInValue("updated"));
  120. $this->setGenerator($tag->getInValue("generator"));
  121. foreach($tag->getIn("author") as $intag){
  122. $this->setAuthor($intag->get());
  123. }
  124. foreach($tag->getIn("link",true) as $intag){
  125. $data = new AtomLink();
  126. if($data->set($intag->get())) $this->link[] = $data;
  127. }
  128. return true;
  129. }
  130. return false;
  131. }
  132. /**
  133. * ???????????????
  134. *
  135. * @return string
  136. */
  137. function get(){
  138. /***
  139. * unit("tag.feed.Atom10Test");
  140. *
  141. * $src = <<< __XML__
  142. * <feed xmlns="http://www.w3.org/2005/Atom">
  143. * <title>atom10 feed</title>
  144. * <subtitle>atom10 sub title</subtitle>
  145. * <updated>2007-07-18T16:16:31+00:00</updated>
  146. * <generator>tokushima</generator>
  147. * <link href="http://tokushimakazutaka.com" rel="abc" type="xyz" />
  148. *
  149. * <author>
  150. * <url>http://tokushimakazutaka.com</url>
  151. * <name>tokushima</name>
  152. * <email>tokushima@hoge.hoge</email>
  153. * </author>
  154. *
  155. * <entry>
  156. * <title>rhaco</title>
  157. * <summary type="xml" xml:lang="ja">summary test</summary>
  158. * <content type="text/xml" mode="abc" xml:lang="ja" xml:base="base">atom content</content>
  159. * <link href="http://rhaco.org" rel="abc" type="xyz" />
  160. * <link href="http://conveyor.rhaco.org" rel="abc" type="conveyor" />
  161. * <link href="http://lib.rhaco.org" rel="abc" type="lib" />
  162. *
  163. * <updated>2007-07-18T16:16:31+00:00</updated>
  164. * <issued>2007-07-18T16:16:31+00:00</issued>
  165. * <published>2007-07-18T16:16:31+00:00</published>
  166. * <id>rhaco</id>
  167. * <author>
  168. * <url>http://rhaco.org</url>
  169. * <name>rhaco</name>
  170. * <email>rhaco@rhaco.org</email>
  171. * </author>
  172. * </entry>
  173. *
  174. * <entry>
  175. * <title>django</title>
  176. * <summary type="xml" xml:lang="ja">summary test</summary>
  177. * <content type="text/xml" mode="abc" xml:lang="ja" xml:base="base">atom content</content>
  178. * <link href="http://djangoproject.jp" rel="abc" type="xyz" />
  179. *
  180. * <updated>2007-07-18T16:16:31+00:00</updated>
  181. * <issued>2007-07-18T16:16:31+00:00</issued>
  182. * <published>2007-07-18T16:16:31+00:00</published>
  183. * <id>django</id>
  184. * <author>
  185. * <url>http://www.everes.net</url>
  186. * <name>everes</name>
  187. * <email>everes@hoge.hoge</email>
  188. * </author>
  189. * </entry>
  190. *
  191. * </feed>
  192. * __XML__;
  193. *
  194. *
  195. * $xml = new Atom10();
  196. * assert($xml->set($src));
  197. *
  198. * $result = <<< __XML__
  199. * <feed xmlns="http://www.w3.org/2005/Atom">
  200. * <title>atom10 feed</title>
  201. * <subtitle>atom10 sub title</subtitle>
  202. * <updated>2007-07-19T01:16:31Z</updated>
  203. * <link href="http://tokushimakazutaka.com" rel="abc" type="xyz" />
  204. * <generator>tokushima</generator>
  205. * <author>
  206. * <url>http://tokushimakazutaka.com</url>
  207. * <name>tokushima</name>
  208. * <email>tokushima@hoge.hoge</email>
  209. * </author>
  210. * <entry>
  211. * <title>rhaco</title>
  212. * <summary type="xml" xml:lang="ja">summary test</summary>
  213. * <content type="text/xml" mode="abc" xml:lang="ja" xml:base="base">atom content</content>
  214. * <link href="http://rhaco.org" rel="abc" type="xyz" />
  215. * <link href="http://conveyor.rhaco.org" rel="abc" type="conveyor" />
  216. * <link href="http://lib.rhaco.org" rel="abc" type="lib" />
  217. * <id>rhaco</id>
  218. * <author><url>http://rhaco.org</url><name>rhaco</name><email>rhaco@rhaco.org</email></author>
  219. * <published>2007-07-19T01:16:31Z</published>
  220. * <updated>2007-07-19T01:16:31Z</updated>
  221. * <issued>2007-07-19T01:16:31Z</issued>
  222. * </entry>
  223. * <entry>
  224. * <title>django</title>
  225. * <summary type="xml" xml:lang="ja">summary test</summary>
  226. * <content type="text/xml" mode="abc" xml:lang="ja" xml:base="base">atom content</content>
  227. * <link href="http://djangoproject.jp" rel="abc" type="xyz" />
  228. * <id>django</id>
  229. * <author><url>http://www.everes.net</url><name>everes</name><email>everes@hoge.hoge</email></author>
  230. * <published>2007-07-19T01:16:31Z</published>
  231. * <updated>2007-07-19T01:16:31Z</updated>
  232. * <issued>2007-07-19T01:16:31Z</issued>
  233. * </entry>
  234. * </feed>
  235. * __XML__;
  236. *
  237. * $result = str_replace("\n","",$result);
  238. *
  239. * eq($result,$xml->get());
  240. */
  241. $outTag = new SimpleTag("feed","",array("xmlns"=>"http://www.w3.org/2005/Atom"));
  242. if($this->id != "") $outTag->addValue(new SimpleTag("id",$this->getId()));
  243. if($this->title != "") $outTag->addValue(new SimpleTag("title",$this->getTitle()));
  244. if($this->subtitle != "") $outTag->addValue(new SimpleTag("subtitle",$this->getSubtitle()));
  245. if($this->updated !== null) $outTag->addValue(new SimpleTag("updated",$this->getUpdated()));
  246. foreach($this->getLink() as $data){
  247. if(Variable::istype("AtomLink",$data)){
  248. if(!$data->isEmpty()) $outTag->addValue($data->get());
  249. }
  250. }
  251. if($this->generator != "") $outTag->addValue(new SimpleTag("generator",$this->getGenerator()));
  252. if($this->author !== null){
  253. $data = $this->getAuthor();
  254. $outTag->addValue($data->get());
  255. }
  256. foreach($this->getEntry() as $data){
  257. if(Variable::istype("AtomEntry10",$data)){
  258. $outTag->addValue($data->get());
  259. }
  260. }
  261. return $outTag->get();
  262. }
  263. function setVersion($value){
  264. $this->version = $value;
  265. }
  266. function getVersion(){
  267. return $this->version;
  268. }
  269. function setId($value){
  270. $this->id = $value;
  271. }
  272. function getId(){
  273. return $this->id;
  274. }
  275. function setTitle($value){
  276. $this->title = $value;
  277. }
  278. function getTitle(){
  279. return $this->title;
  280. }
  281. function setSubtitle($value){
  282. $this->subtitle = $value;
  283. }
  284. function getSubtitle(){
  285. return $this->subtitle;
  286. }
  287. function setUpdated($value){
  288. $this->updated = DateUtil::parseString($value);
  289. }
  290. function getUpdated($format=""){
  291. return (empty($format)) ? DateUtil::formatAtom($this->updated) : DateUtil::format($this->updated,$format);
  292. }
  293. function setGenerator($value){
  294. $this->generator = $value;
  295. }
  296. function getGenerator(){
  297. return $this->generator;
  298. }
  299. function setLink($href,$rel="",$type=""){
  300. $this->link[] = new AtomLink($href,$rel,$type);
  301. }
  302. function getLink(){
  303. return $this->link;
  304. }
  305. function getLinkHref(){
  306. foreach($this->link as $link) return $link->getHref();
  307. return "";
  308. }
  309. function getEntry(){
  310. return $this->entryList;
  311. }
  312. function setEntry($title,$summary="",$content=""){
  313. $this->entryList[] = (Variable::istype("AtomEntry10",$title)) ?
  314. $title :
  315. new AtomEntry10($title,$summary,$content);
  316. }
  317. function setAuthor($value){
  318. if(!Variable::istype("AtomAuthor",$value)){
  319. $author = new AtomAuthor();
  320. if(!$author->set($value)) $author->setName($value);
  321. $value = $author;
  322. }
  323. $this->author = $value;
  324. }
  325. function getAuthor(){
  326. return (Variable::istype("AtomAuthor",$this->author)) ? $this->author : new AtomAuthor($this->author);
  327. }
  328. }
  329. ?>