| | 1349 | /** |
|---|
| | 1350 | * AtomCreator10 is a FeedCreator that implements the atom specification, |
|---|
| | 1351 | * as in http://www.atomenabled.org/developers/syndication/atom-format-spec.php |
|---|
| | 1352 | * Please note that just by using AtomCreator10 you won't automatically |
|---|
| | 1353 | * produce valid atom files. For example, you have to specify either an editor |
|---|
| | 1354 | * for the feed or an author for every single feed item. |
|---|
| | 1355 | * |
|---|
| | 1356 | * Some elements have not been implemented yet. These are (incomplete list): |
|---|
| | 1357 | * author URL, item author's email and URL, item contents, alternate links, |
|---|
| | 1358 | * other link content types than text/html. Some of them may be created with |
|---|
| | 1359 | * AtomCreator10::additionalElements. |
|---|
| | 1360 | * |
|---|
| | 1361 | * @see FeedCreator#additionalElements |
|---|
| | 1362 | * @since 1.7.2-mod (modified) |
|---|
| | 1363 | * @author Mohammad Hafiz Ismail (mypapit@gmail.com) |
|---|
| | 1364 | */ |
|---|
| | 1365 | class AtomCreator10 extends FeedCreator { |
|---|
| | 1366 | |
|---|
| | 1367 | function AtomCreator10() { |
|---|
| | 1368 | $this->contentType = "application/atom+xml"; |
|---|
| | 1369 | $this->encoding = "utf-8"; |
|---|
| | 1370 | |
|---|
| | 1371 | } |
|---|
| | 1372 | |
|---|
| | 1373 | function createFeed() { |
|---|
| | 1374 | $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n"; |
|---|
| | 1375 | $feed.= $this->_createGeneratorComment(); |
|---|
| | 1376 | $feed.= $this->_createStylesheetReferences(); |
|---|
| | 1377 | $feed.= "<feed xmlns=\"http://www.w3.org/2005/Atom\""; |
|---|
| | 1378 | if ($this->language!="") { |
|---|
| | 1379 | $feed.= " xml:lang=\"".$this->language."\""; |
|---|
| | 1380 | } |
|---|
| | 1381 | $feed.= ">\n"; |
|---|
| | 1382 | $feed.= " <title>".htmlspecialchars($this->title)."</title>\n"; |
|---|
| | 1383 | $feed.= " <subtitle>".htmlspecialchars($this->description)."</subtitle>\n"; |
|---|
| | 1384 | $feed.= " <link rel=\"alternate\" type=\"text/html\" href=\"".htmlspecialchars($this->link)."\"/>\n"; |
|---|
| | 1385 | $feed.= " <id>".htmlspecialchars($this->link)."</id>\n"; |
|---|
| | 1386 | $now = new FeedDate(); |
|---|
| | 1387 | $feed.= " <updated>".htmlspecialchars($now->iso8601())."</updated>\n"; |
|---|
| | 1388 | if ($this->editor!="") { |
|---|
| | 1389 | $feed.= " <author>\n"; |
|---|
| | 1390 | $feed.= " <name>".$this->editor."</name>\n"; |
|---|
| | 1391 | if ($this->editorEmail!="") { |
|---|
| | 1392 | $feed.= " <email>".$this->editorEmail."</email>\n"; |
|---|
| | 1393 | } |
|---|
| | 1394 | $feed.= " </author>\n"; |
|---|
| | 1395 | } |
|---|
| | 1396 | if ($this->category!="") { |
|---|
| | 1397 | |
|---|
| | 1398 | |
|---|
| | 1399 | $feed.= " <category term=\"" . htmlspecialchars($this->category) . "\" />\n"; |
|---|
| | 1400 | } |
|---|
| | 1401 | if ($this->copyright!="") { |
|---|
| | 1402 | $feed.= " <rights>".FeedCreator::iTrunc(htmlspecialchars($this->copyright),100)."</rights>\n"; |
|---|
| | 1403 | } |
|---|
| | 1404 | $feed.= " <generator>".$this->version()."</generator>\n"; |
|---|
| | 1405 | |
|---|
| | 1406 | |
|---|
| | 1407 | $feed.= " <link rel=\"self\" type=\"application/atom+xml\" href=\"". htmlspecialchars($this->syndicationURL). "\" />\n"; |
|---|
| | 1408 | $feed.= $this->_createAdditionalElements($this->additionalElements, " "); |
|---|
| | 1409 | for ($i=0;$i<count($this->items);$i++) { |
|---|
| | 1410 | $feed.= " <entry>\n"; |
|---|
| | 1411 | $feed.= " <title>".htmlspecialchars(strip_tags($this->items[$i]->title))."</title>\n"; |
|---|
| | 1412 | $feed.= " <link rel=\"alternate\" type=\"text/html\" href=\"".htmlspecialchars($this->items[$i]->link)."\"/>\n"; |
|---|
| | 1413 | if ($this->items[$i]->date=="") { |
|---|
| | 1414 | $this->items[$i]->date = time(); |
|---|
| | 1415 | } |
|---|
| | 1416 | $itemDate = new FeedDate($this->items[$i]->date); |
|---|
| | 1417 | $feed.= " <published>".htmlspecialchars($itemDate->iso8601())."</published>\n"; |
|---|
| | 1418 | $feed.= " <updated>".htmlspecialchars($itemDate->iso8601())."</updated>\n"; |
|---|
| | 1419 | |
|---|
| | 1420 | |
|---|
| | 1421 | $tempguid = $this->items[$i]->link; |
|---|
| | 1422 | if ($this->items[$i]->guid!="") { |
|---|
| | 1423 | $tempguid = $this->items[$i]->guid; |
|---|
| | 1424 | } |
|---|
| | 1425 | |
|---|
| | 1426 | $feed.= " <id>". htmlspecialchars($tempguid)."</id>\n"; |
|---|
| | 1427 | $feed.= $this->_createAdditionalElements($this->items[$i]->additionalElements, " "); |
|---|
| | 1428 | if ($this->items[$i]->author!="") { |
|---|
| | 1429 | $feed.= " <author>\n"; |
|---|
| | 1430 | $feed.= " <name>".htmlspecialchars($this->items[$i]->author)."</name>\n"; |
|---|
| | 1431 | if ($this->items[$i]->authorEmail!="") { |
|---|
| | 1432 | $feed.= " <email>".htmlspecialchars($this->items[$i]->authorEmail)."</email>\n"; |
|---|
| | 1433 | } |
|---|
| | 1434 | |
|---|
| | 1435 | if ($this->items[$i]->authorURL!="") { |
|---|
| | 1436 | $feed.= " <uri>".htmlspecialchars($this->items[$i]->authorURL)."</uri>\n"; |
|---|
| | 1437 | } |
|---|
| | 1438 | |
|---|
| | 1439 | $feed.= " </author>\n"; |
|---|
| | 1440 | } |
|---|
| | 1441 | |
|---|
| | 1442 | if ($this->items[$i]->category!="") { |
|---|
| | 1443 | $feed.= " <category "; |
|---|
| | 1444 | |
|---|
| | 1445 | if ($this->items[$i]->categoryScheme!="") { |
|---|
| | 1446 | $feed.=" scheme=\"".htmlspecialchars($this->items[$i]->categoryScheme)."\" "; |
|---|
| | 1447 | } |
|---|
| | 1448 | |
|---|
| | 1449 | $feed.=" term=\"" . htmlspecialchars($this->items[$i]->category) . "\" />\n"; |
|---|
| | 1450 | } |
|---|
| | 1451 | |
|---|
| | 1452 | if ($this->items[$i]->description!="") { |
|---|
| | 1453 | |
|---|
| | 1454 | |
|---|
| | 1455 | /* |
|---|
| | 1456 | * ATOM should have at least summary tag, however this implementation may be inaccurate |
|---|
| | 1457 | */ |
|---|
| | 1458 | $tempdesc = $this->items[$i]->getDescription(); |
|---|
| | 1459 | $temptype=""; |
|---|
| | 1460 | |
|---|
| | 1461 | |
|---|
| | 1462 | if ($this->items[$i]->descriptionHtmlSyndicated){ |
|---|
| | 1463 | $temptype=" type=\"html\""; |
|---|
| | 1464 | $tempdesc = $this->items[$i]->getDescription(); |
|---|
| | 1465 | |
|---|
| | 1466 | } |
|---|
| | 1467 | |
|---|
| | 1468 | if (empty($this->items[$i]->descriptionTruncSize)) { |
|---|
| | 1469 | $feed.= " <content". $temptype . ">". $tempdesc ."</content>\n"; |
|---|
| | 1470 | } |
|---|
| | 1471 | |
|---|
| | 1472 | |
|---|
| | 1473 | $feed.= " <summary". $temptype . ">". $tempdesc ."</summary>\n"; |
|---|
| | 1474 | } else { |
|---|
| | 1475 | |
|---|
| | 1476 | $feed.= " <summary>no summary</summary>\n"; |
|---|
| | 1477 | |
|---|
| | 1478 | } |
|---|
| | 1479 | |
|---|
| | 1480 | if ($this->items[$i]->enclosure != NULL) { |
|---|
| | 1481 | $feed.=" <link rel=\"enclosure\" href=\"". $this->items[$i]->enclosure->url ."\" type=\"". $this->items[$i]->enclosure->type."\" length=\"". $this->items[$i]->enclosure->length ."\""; |
|---|
| | 1482 | |
|---|
| | 1483 | if ($this->items[$i]->enclosure->language != ""){ |
|---|
| | 1484 | $feed .=" xml:lang=\"". $this->items[$i]->enclosure->language . "\" "; |
|---|
| | 1485 | } |
|---|
| | 1486 | |
|---|
| | 1487 | if ($this->items[$i]->enclosure->title != ""){ |
|---|
| | 1488 | $feed .=" title=\"". $this->items[$i]->enclosure->title . "\" "; |
|---|
| | 1489 | } |
|---|
| | 1490 | |
|---|
| | 1491 | $feed .=" /> \n"; |
|---|
| | 1492 | |
|---|
| | 1493 | |
|---|
| | 1494 | |
|---|
| | 1495 | } |
|---|
| | 1496 | $feed.= " </entry>\n"; |
|---|
| | 1497 | } |
|---|
| | 1498 | $feed.= "</feed>\n"; |
|---|
| | 1499 | return $feed; |
|---|
| | 1500 | } |
|---|
| | 1501 | |
|---|
| | 1502 | |
|---|
| | 1503 | } |
|---|