[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/vendor/openpsa/universalfeedcreator/lib/Creator/ -> AtomCreator10.php (source)

   1  <?php
   2  
   3  /**
   4   * AtomCreator10 is a FeedCreator that implements the atom specification,
   5   * as in http://www.atomenabled.org/developers/syndication/atom-format-spec.php
   6   * Please note that just by using AtomCreator10 you won't automatically
   7   * produce valid atom files. For example, you have to specify either an editor
   8   * for the feed or an author for every single feed item.
   9   * Some elements have not been implemented yet. These are (incomplete list):
  10   * author URL, item author's email and URL, item contents, alternate links,
  11   * other link content types than text/html. Some of them may be created with
  12   * AtomCreator10::additionalElements.
  13   *
  14   * @see     FeedCreator#additionalElements
  15   * @since   1.7.2-mod (modified)
  16   * @author  Mohammad Hafiz Ismail (mypapit@gmail.com)
  17   */
  18  class AtomCreator10 extends FeedCreator
  19  {
  20  
  21      /**
  22       * AtomCreator10 constructor.
  23       */
  24      public function __construct()
  25      {
  26          $this->contentType = "application/atom+xml";
  27          $this->encoding = "utf-8";
  28      }
  29  
  30      /** @inheritdoc */
  31      public function createFeed()
  32      {
  33          $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
  34          $feed .= $this->_createGeneratorComment();
  35          $feed .= $this->_createStylesheetReferences();
  36          $feed .= "<feed xmlns=\"http://www.w3.org/2005/Atom\"";
  37          if (!empty($this->items[0]->lat)) {
  38              $feed .= " xmlns:georss=\"http://www.georss.org/georss\"\n";
  39          }
  40          if ($this->language != "") {
  41              $feed .= " xml:lang=\"".$this->language."\"";
  42          }
  43          $feed .= ">\n";
  44          $feed .= "    <title>".htmlspecialchars((string) $this->title)."</title>\n";
  45          $feed .= "    <subtitle>".htmlspecialchars($this->description)."</subtitle>\n";
  46          $feed .= "    <link rel=\"alternate\" type=\"text/html\" href=\"".htmlspecialchars((string) $this->link)."\"/>\n";
  47          $feed .= "    <id>".htmlspecialchars((string) $this->link)."</id>\n";
  48          $now = new FeedDate();
  49          $feed .= "    <updated>".htmlspecialchars($now->iso8601())."</updated>\n";
  50          if ($this->editor != "") {
  51              $feed .= "    <author>\n";
  52              $feed .= "        <name>".$this->editor."</name>\n";
  53              if ($this->editorEmail != "") {
  54                  $feed .= "        <email>".$this->editorEmail."</email>\n";
  55              }
  56              $feed .= "    </author>\n";
  57          }
  58          if ($this->category != "") {
  59  
  60              $feed .= "    <category term=\"".htmlspecialchars($this->category)."\" />\n";
  61          }
  62          if ($this->copyright != "") {
  63              $feed .= "    <rights>".FeedCreator::iTrunc(htmlspecialchars($this->copyright), 100)."</rights>\n";
  64          }
  65          $feed .= "    <generator>".$this->version()."</generator>\n";
  66  
  67          $feed .= "    <link rel=\"self\" type=\"application/atom+xml\" href=\"".htmlspecialchars(
  68                  (string) $this->syndicationURL
  69              )."\" />\n";
  70          $feed .= $this->_createAdditionalElements($this->additionalElements, "    ");
  71          for ($i = 0; $i < count($this->items); $i++) {
  72              $feed .= "    <entry>\n";
  73              $feed .= "        <title>".htmlspecialchars(strip_tags((string) $this->items[$i]->title))."</title>\n";
  74              $feed .= "        <link rel=\"alternate\" type=\"text/html\" href=\"".htmlspecialchars(
  75                      (string) $this->items[$i]->link
  76                  )."\"/>\n";
  77              if ($this->items[$i]->date == "") {
  78                  $this->items[$i]->date = time();
  79              }
  80              $itemDate = new FeedDate($this->items[$i]->date);
  81              $feed .= "        <published>".htmlspecialchars($itemDate->iso8601())."</published>\n";
  82              $feed .= "        <updated>".htmlspecialchars($itemDate->iso8601())."</updated>\n";
  83  
  84              $tempguid = $this->items[$i]->link;
  85              if ($this->items[$i]->guid != "") {
  86                  $tempguid = $this->items[$i]->guid;
  87              }
  88  
  89              $feed .= "        <id>".htmlspecialchars((string) $tempguid)."</id>\n";
  90              $feed .= $this->_createAdditionalElements($this->items[$i]->additionalElements, "        ");
  91              if ($this->items[$i]->author != "") {
  92                  $feed .= "        <author>\n";
  93                  $feed .= "            <name>".htmlspecialchars($this->items[$i]->author)."</name>\n";
  94                  if ($this->items[$i]->authorEmail != "") {
  95                      $feed .= "            <email>".htmlspecialchars($this->items[$i]->authorEmail)."</email>\n";
  96                  }
  97  
  98                  if ($this->items[$i]->authorURL != "") {
  99                      $feed .= "            <uri>".htmlspecialchars($this->items[$i]->authorURL)."</uri>\n";
 100                  }
 101  
 102                  $feed .= "        </author>\n";
 103              }
 104  
 105              if (!empty($this->items[$i]->category)) {
 106                  foreach ((array) $this->items[$i]->category as $category) {
 107                      $feed .= "        <category ";
 108  
 109                      if ($this->items[$i]->categoryScheme != "") {
 110                          $feed .= " scheme=\"".htmlspecialchars($this->items[$i]->categoryScheme)."\" ";
 111                      }
 112  
 113                      $feed .= " term=\"".htmlspecialchars($category)."\" />\n";
 114                  }
 115              }
 116  
 117              if ($this->items[$i]->description != "") {
 118  
 119                  /*
 120                   * ATOM should have at least summary tag, however this implementation may be inaccurate
 121                  */
 122                  $tempdesc = $this->items[$i]->getDescription();
 123                  $temptype = "";
 124  
 125                  if ($this->items[$i]->descriptionHtmlSyndicated) {
 126                      $temptype = " type=\"html\"";
 127                      $tempdesc = $this->items[$i]->getDescription();
 128  
 129                  }
 130  
 131                  if (empty($this->items[$i]->descriptionTruncSize)) {
 132                      $feed .= "        <content".$temptype.">".$tempdesc."</content>\n";
 133                  }
 134  
 135                  $feed .= "        <summary".$temptype.">".$tempdesc."</summary>\n";
 136              } else {
 137  
 138                  $feed .= "     <summary>no summary</summary>\n";
 139  
 140              }
 141  
 142              if ($this->items[$i]->enclosure != null) {
 143                  $feed .= "        <link rel=\"enclosure\" href=\"".$this->items[$i]->enclosure->url."\" type=\"".$this->items[$i]->enclosure->type."\"  length=\"".$this->items[$i]->enclosure->length."\"";
 144  
 145                  if ($this->items[$i]->enclosure->language != "") {
 146                      $feed .= " xml:lang=\"".$this->items[$i]->enclosure->language."\" ";
 147                  }
 148  
 149                  if ($this->items[$i]->enclosure->title != "") {
 150                      $feed .= " title=\"".$this->items[$i]->enclosure->title."\" ";
 151                  }
 152  
 153                  $feed .= " /> \n";
 154              }
 155              if ($this->items[$i]->lat != "") {
 156                  $feed .= "        <georss:point>".$this->items[$i]->lat." ".$this->items[$i]->long."</georss:point>\n";
 157              }
 158              $feed .= "    </entry>\n";
 159          }
 160          $feed .= "</feed>\n";
 161  
 162          return $feed;
 163      }
 164  }