1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Modules\Editor;
13
14 15 16
17 class FeedEditor implements Editor
18 {
19 20 21 22 23
24 public function serialize($content)
25 {
26 return json_encode($content);
27 }
28
29 30 31 32 33
34 public function unserialize($serialized_content)
35 {
36 return json_decode($serialized_content, true);
37 }
38 39 40 41 42
43 public function from(array $attributes)
44 {
45 return new FeedEditorElement($attributes);
46 }
47
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
70
71
72
73 public function render($content)
74 {
75 global $core;
76
77 $page = $core->request->context->page;
78 $site = $page->site;
79 $options = $content;
80
81 $constructor = $options['constructor'];
82 $limit = $options['limit'];
83 $with_author = false;
84
85 if (isset($options['settings']))
86 {
87 $options['settings']['is_with_author'];
88 }
89
90 $gmt_offset = $core->timezone;
91
92 $fdate = $core->locale->calendar->date_formatter;
93 $time_pattern = "y-MM-dd'T'HH:mm:ss";
94
95 $host = preg_replace('#^www\.#', '', $_SERVER['SERVER_NAME']);
96 $page_created_at = $fdate($page->created_at, 'y-MM-dd');
97
98 $entries = $core->models[$constructor]->filter_by_constructor($constructor)->visible->order('date DESC')->limit($limit)->all;
99
100 ob_start();
101
102 ?>
103
104 <id>tag:<?= $host ?>,<?= $page_created_at ?>:<?= $page->slug ?></id>
105 <title><?= $page->title ?></title>
106 <link href="<?php echo $page->absolute_url ?>" rel="self" />
107 <link href="<?php echo $page->home->absolute_url ?>" />
108
109 <author>
110 <name><?php $user = $page->user; echo ($user->firstname && $user->lastname) ? $user->firstname . ' ' . $user->lastname : $user->name ?></name>
111 </author>
112
113 <updated><?php
114
115 $updated = '';
116
117 foreach ($entries as $entry)
118 {
119 if (strcmp($updated, $entry->updated_at) < 0)
120 {
121 $updated = $entry->updated_at;
122 }
123 }
124
125 echo $fdate($updated, $time_pattern) . $gmt_offset ?></updated>
126
127 <?php
128
129 foreach ($entries as $entry)
130 {
131 ?>
132 <entry>
133 <title><?= \ICanBoogie\escape($entry->title) ?></title>
134 <link href="<?php echo $entry->absolute_url ?>" />
135 <id>tag:<?= $host ?>,<?php echo $fdate($entry->created_at, 'y-MM-dd') ?>:<?= $entry->slug ?></id>
136 <updated><?= $fdate($entry->updated_at, $time_pattern) . $gmt_offset ?></updated>
137 <published><?= $fdate($entry->date, $time_pattern) . $gmt_offset ?></published>
138 <?php if ($with_author): ?>
139 <author>
140 <name><?php
141
142 $user = $entry->user;
143
144 echo ($user->firstname && $user->lastname) ? $user->firstname . ' ' . $user->lastname : $entry->user->name ?></name>
145 </author>
146 <?php endif; ?>
147 <?php 148 ?>
149 <content type="html" xml:lang="<?php echo $entry->language ? $entry->language : $site->language ?>"><![CDATA[<?php echo $entry ?>]]></content>
150 </entry>
151 <?php
152 }
153
154 $rc = ob_get_clean();
155 $rc = preg_replace('#(href|src)="/#', '$1="http://' . $host .'/', $rc);
156
157 header('Content-Type: application/atom+xml;charset=utf-8');
158
159
160 echo '<?xml version="1.0" encoding="utf-8"?>
161 <feed xmlns="http://www.w3.org/2005/Atom">' . $rc . '</feed>';
162
163 exit;
164 }
165 }
166