Browse Source

Implemented feed item categories (#746)

Eugene Molotov 5 years ago
parent
commit
049ee52fb5
4 changed files with 40 additions and 1 deletions
  1. 11 0
      formats/AtomFormat.php
  2. 15 0
      formats/HtmlFormat.php
  3. 11 0
      formats/MrssFormat.php
  4. 3 1
      static/HtmlFormat.css

+ 11 - 0
formats/AtomFormat.php

@@ -40,6 +40,16 @@ class AtomFormat extends FormatAbstract{
 				}
 			}
 
+			$entryCategories = '';
+			if(isset($item['categories'])) {
+				foreach($item['categories'] as $category) {
+					$entryCategories .= '<category term="'
+					. $this->xml_encode($category)
+					. '"/>'
+					. PHP_EOL;
+				}
+			}
+
 			$entries .= <<<EOD
 
 	<entry>
@@ -52,6 +62,7 @@ class AtomFormat extends FormatAbstract{
 		<updated>{$entryTimestamp}</updated>
 		<content type="html">{$entryContent}</content>
 		{$entryEnclosures}
+		{$entryCategories}
 	</entry>
 
 EOD;

+ 15 - 0
formats/HtmlFormat.php

@@ -47,6 +47,20 @@ class HtmlFormat extends FormatAbstract {
 				$entryEnclosures .= '</div>';
 			}
 
+			$entryCategories = '';
+			if(isset($item['categories'])) {
+				$entryCategories = '<div class="categories"><p>Categories:</p>';
+
+				foreach($item['categories'] as $category) {
+
+					$entryCategories .= '<li class="category">'
+					. $this->sanitizeHtml($category)
+					. '</li>';
+				}
+
+				$entryCategories .= '</div>';
+			}
+
 			$entries .= <<<EOD
 
 <section class="feeditem">
@@ -55,6 +69,7 @@ class HtmlFormat extends FormatAbstract {
 	{$entryAuthor}
 	{$entryContent}
 	{$entryEnclosures}
+	{$entryCategories}
 </section>
 
 EOD;

+ 11 - 0
formats/MrssFormat.php

@@ -51,6 +51,16 @@ Some media files might not be shown to you. Consider using the ATOM format inste
 				}
 			}
 
+			$entryCategories = '';
+			if(isset($item['categories'])) {
+
+				foreach($item['categories'] as $category) {
+					$entryCategories .= '<category>'
+					. $category  . '</category>'
+					. PHP_EOL;
+				}
+			}
+
 			$items .= <<<EOD
 
 	<item>
@@ -61,6 +71,7 @@ Some media files might not be shown to you. Consider using the ATOM format inste
 		<description>{$itemContent}{$entryEnclosuresWarning}</description>
 		<author>{$itemAuthor}</author>
 		{$entryEnclosures}
+		{$entryCategories}
 	</item>
 
 EOD;

+ 3 - 1
static/HtmlFormat.css

@@ -69,12 +69,14 @@ a.backlink, a.backlink:link, a.backlink:visited, a.itemtitle, a.itemtitle:link,
 
 }
 
+section > div.content, section > div.categories,
 section > div.content, section > div.attachments {
 
 	padding: 10px;
 
 }
 
+section > div.categories > li.category,
 section > div.attachments > li.enclosure {
 
 	list-style-type: circle;
@@ -114,4 +116,4 @@ img {
 
   max-width: 100%;
 
-}
+}