00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 class FeedWriterTitle {
00026 public $title = '';
00027 public $description = '';
00028 public $link = '';
00029
00030 public $last_updated = 0;
00031
00032 public $copyright = '';
00033 public $editor = '';
00034
00035 public $imageurl = '';
00036 public $image_width = '';
00037 public $image_height = '';
00038
00039 public $generator = '';
00040 public $language = "en";
00041 public $selfurl = '';
00042
00043 public function __construct() {
00044 $this->title = Config::get_value(Config::TITLE);
00045 $this->link = Config::get_url(Config::URL_BASEURL);
00046 $this->language = GyroLocale::get_language();
00047 $this->selfurl = Url::current()->build();
00048 }
00049 }
00050
00051
00052
00053
00054
00055
00056
00057 class FeedWriterItem {
00058 public $description = '';
00059 public $title = '';
00060 public $link = '';
00061 public $pubdate = 0;
00062 public $last_update = 0;
00063 public $guid = '';
00064 public $author_name = '';
00065 public $author_email = '';
00066 public $content = '';
00067 public $categories = array();
00068 public $enclosures = array();
00069
00070 public $baseurl = '';
00071 }
00072
00073
00074
00075
00076
00077
00078
00079 class FeedWriterCategory {
00080 public $domain = '';
00081 public $title = '';
00082
00083 public function __construct($title = '', $domain = '') {
00084 $this->domain = $domain;
00085 $this->title = $title;
00086 }
00087 }
00088
00089
00090
00091
00092
00093
00094
00095 class FeedWriterEnclosures {
00096 public $url = '';
00097 public $length = 0;
00098 public $type = '';
00099 }
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 class FeedWriter implements IRenderer {
00110 protected $items;
00111
00112
00113
00114 protected $title;
00115
00116
00117
00118
00119
00120
00121
00122 public function __construct(FeedWriterTitle $title, $items) {
00123 $this->items = $items;
00124 $this->title = $title;
00125 }
00126
00127
00128
00129
00130
00131
00132 public function get_mime_type() {
00133 return 'application/xml';
00134 }
00135
00136
00137
00138
00139
00140
00141
00142 public function render($policy = self::NONE) {
00143 $items = '';
00144 foreach($this->items as $item) {
00145 $items .= $this->render_item($item);
00146 }
00147
00148
00149
00150 $title = $this->render_title($this->title);
00151
00152 $ret = $this->render_end($title, $items);
00153 return $ret;
00154 }
00155
00156
00157
00158
00159 protected function escape($obj) {
00160 return String::escape($obj, String::XML);
00161 }
00162
00163
00164
00165
00166
00167
00168
00169 protected function render_item(FeedWriterItem $item) {
00170 return '';
00171 }
00172
00173
00174
00175
00176
00177
00178
00179 protected function render_title(FeedWriterTitle $title) {
00180 return '';
00181 }
00182
00183
00184
00185
00186
00187
00188
00189
00190 protected function render_end($title, $items) {
00191 return '';
00192 }
00193
00194
00195
00196
00197 protected function strip_html($text) {
00198 return String::clear_html(String::unescape(str_replace(" ", '', $text)));
00199 }
00200
00201
00202
00203
00204
00205
00206
00207 protected function relative_to_absolute($text, $base) {
00208 if (empty($base)) {
00209 return $text;
00210 }
00211
00212 if (substr($base, -1, 1) != "/") { $base .= "/"; }
00213 $domain = Url::create($base)->clear_query()->set_path('')->build(Url::ABSOLUTE);
00214
00215
00216 $pattern = '|<a(.*?) href="/(.*?)"|';
00217 $replace = '<a$1 href="' . $domain . '$2"';
00218 $text = preg_replace($pattern, $replace, $text);
00219
00220
00221 $pattern = '|<a(.*?) href="(?!\w+://)(.*?)"|';
00222 $replace = '<a$1 href="' . $base . '$2"';
00223 $text = preg_replace($pattern, $replace, $text);
00224
00225
00226 $pattern = '|<img(.*?) src="/(.*?)"|';
00227 $replace = '<img$1 src="' . $domain . '$2"';
00228 $text = preg_replace($pattern, $replace, $text);
00229
00230
00231 $pattern = '|<img(.*?) src="(?!\w+://)(.*?)"|';
00232 $replace = '<img$1 src="' . $base . '$2"';
00233 $text = preg_replace($pattern, $replace, $text);
00234
00235 return $text;
00236 }
00237 }