Completed
Push — dev ( b07a73...6b08a7 )
by Darko
09:08
created

XML_Response::writeRssMusicInfo()   A

Complexity

Conditions 5
Paths 6

Size

Total Lines 31
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 31
ccs 0
cts 15
cp 0
rs 9.3554
c 0
b 0
f 0
cc 5
nc 6
nop 0
crap 30
1
<?php
2
/**
3
 * This program is free software: you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License as published by
5
 * the Free Software Foundation, either version 3 of the License, or
6
 * (at your option) any later version.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 * GNU General Public License for more details.
12
 *
13
 * You should have received a copy of the GNU General Public License
14
 * along with this program (see LICENSE.txt in the base directory.  If
15
 * not, see:
16
 *
17
 * @link      <http://www.gnu.org/licenses/>.
18
 * @author    ruhllatio
19
 * @copyright 2016 nZEDb
20
 */
21
22
namespace Blacklight\http;
23
24
use App\Models\Category;
25
use Illuminate\Support\Carbon;
26
27
/**
28
 * Class XMLReturn.
29
 */
30
class XML_Response
31
{
32
    /**
33
     * @var string The buffered cData before final write
34
     */
35
    protected $cdata;
36
37
    /**
38
     * The RSS namespace used for the output.
39
     *
40
     * @var string
41
     */
42
    protected $namespace;
43
44
    /**
45
     * The trailing URL parameters on the request.
46
     *
47
     * @var mixed
48
     */
49
    protected $parameters;
50
51
    /**
52
     * The release we are adding to the stream.
53
     *
54
     * @var mixed
55
     */
56
    protected $release;
57
58
    /**
59
     * The retrieved releases we are returning from the API call.
60
     *
61
     * @var mixed
62
     */
63
    protected $releases;
64
65
    /**
66
     * The various server variables and active categories.
67
     *
68
     * @var mixed
69
     */
70
    protected $server;
71
72
    /**
73
     * The XML formatting operation we are returning.
74
     *
75
     * @var mixed
76
     */
77
    protected $type;
78
79
    /**
80
     * The XMLWriter Class.
81
     *
82
     * @var \XMLWriter
83
     */
84
    protected $xml;
85
86
    /**
87
     * @var mixed
88
     */
89
    protected $offset;
90
91
    /**
92
     * XMLReturn constructor.
93
     *
94
     * @param array $options
95
     */
96
    public function __construct(array $options = [])
97
    {
98
        $defaults = [
99
            'Parameters' => null,
100
            'Data'       => null,
101
            'Server'     => null,
102
            'Offset'     => null,
103
            'Type'       => null,
104
        ];
105
        $options += $defaults;
106
107
        $this->parameters = $options['Parameters'];
108
        $this->releases = $options['Data'];
109
        $this->server = $options['Server'];
110
        $this->offset = $options['Offset'];
111
        $this->type = $options['Type'];
112
113
        $this->xml = new \XMLWriter();
114
        $this->xml->openMemory();
115
        $this->xml->setIndent(true);
116
    }
117
118
    /**
119
     * @return bool|string
120
     */
121
    public function returnXML()
122
    {
123
        if ($this->xml) {
124
            switch ($this->type) {
125
                case 'caps':
126
                    return $this->returnCaps();
127
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
128
                case 'api':
129
                    $this->namespace = 'newznab';
130
131
                    return $this->returnApiRss();
132
                    break;
133
                case 'rss':
134
                    $this->namespace = 'nntmux';
135
136
                    return $this->returnApiRss();
137
                    break;
138
                case 'reg':
139
                    return $this->returnReg();
140
                    break;
141
            }
142
        }
143
144
        return false;
145
    }
146
147
    /**
148
     * XML writes and returns the API capabilities.
149
     *
150
     * @return string The XML Formatted string data
151
     */
152
    protected function returnCaps(): string
153
    {
154
        $this->xml->startDocument('1.0', 'UTF-8');
155
        $this->xml->startElement('caps');
156
        $this->addNode(['name' => 'server', 'data' => $this->server['server']]);
157
        $this->addNode(['name' => 'limits', 'data' => $this->server['limits']]);
158
        $this->addNode(['name' => 'registration', 'data' => $this->server['registration']]);
159
        $this->addNodes(['name' => 'searching', 'data' => $this->server['searching']]);
160
        $this->writeCategoryListing();
161
        $this->xml->endElement();
162
        $this->xml->endDocument();
163
164
        return $this->xml->outputMemory();
165
    }
166
167
    /**
168
     * XML writes and returns the API data.
169
     *
170
     * @return string The XML Formatted string data
171
     */
172
    protected function returnApiRss(): string
173
    {
174
        $this->xml->startDocument('1.0', 'UTF-8');
175
        $this->includeRssAtom(); // Open RSS
176
        $this->xml->startElement('channel'); // Open channel
177
        $this->includeRssAtomLink();
178
        $this->includeMetaInfo();
179
        $this->includeImage();
180
        $this->includeTotalRows();
181
        $this->includeReleases();
182
        $this->xml->endElement(); // End channel
183
        $this->xml->endElement(); // End RSS
184
        $this->xml->endDocument();
185
186
        return $this->xml->outputMemory();
187
    }
188
189
    /**
190
     * @return string The XML formatted registration information
191
     */
192
    protected function returnReg(): string
193
    {
194
        $this->xml->startDocument('1.0', 'UTF-8');
195
        $this->xml->startElement('register');
196
        $this->xml->writeAttribute('username', $this->parameters['username']);
197
        $this->xml->writeAttribute('password', $this->parameters['password']);
198
        $this->xml->writeAttribute('apikey', $this->parameters['token']);
199
        $this->xml->endElement();
200
        $this->xml->endDocument();
201
202
        return $this->xml->outputMemory();
203
    }
204
205
    /**
206
     * Starts a new element, loops through the attribute data and ends the element.
207
     *
208
     * @param array $element An array with the name of the element and the attribute data
209
     */
210
    protected function addNode($element): void
211
    {
212
        $this->xml->startElement($element['name']);
213
        foreach ($element['data'] as $attr => $val) {
214
            $this->xml->writeAttribute($attr, $val);
215
        }
216
        $this->xml->endElement();
217
    }
218
219
    /**
220
     * Starts a new element, loops through the attribute data and ends the element.
221
     *
222
     * @param array $element An array with the name of the element and the attribute data
223
     */
224
    protected function addNodes($element): void
225
    {
226
        $this->xml->startElement($element['name']);
227
        foreach ($element['data'] as $elem => $value) {
228
            $subelement['name'] = $elem;
229
            $subelement['data'] = $value;
230
            $this->addNode($subelement);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $subelement seems to be defined later in this foreach loop on line 228. Are you sure it is defined here?
Loading history...
231
        }
232
        $this->xml->endElement();
233
    }
234
235
    /**
236
     * Adds the site category listing to the XML feed.
237
     */
238
    protected function writeCategoryListing(): void
239
    {
240
        $this->xml->startElement('categories');
241
        foreach ($this->server['categories'] as $this->parameters) {
242
            $this->xml->startElement('category');
243
            $this->xml->writeAttribute('id', $this->parameters['id']);
244
            $this->xml->writeAttribute('name', html_entity_decode($this->parameters['title']));
245
            if (! empty($this->parameters['description'])) {
246
                $this->xml->writeAttribute('description', html_entity_decode($this->parameters['description']));
247
            }
248
            foreach ($this->parameters['categories'] as $c) {
249
                $this->xml->startElement('subcat');
250
                $this->xml->writeAttribute('id', $c['id']);
251
                $this->xml->writeAttribute('name', html_entity_decode($c['title']));
252
                if (! empty($c['description'])) {
253
                    $this->xml->writeAttribute('description', html_entity_decode($c['description']));
254
                }
255
                $this->xml->endElement();
256
            }
257
            $this->xml->endElement();
258
        }
259
    }
260
261
    /**
262
     * Adds RSS Atom information to the XML.
263
     */
264
    protected function includeRssAtom(): void
265
    {
266
        switch ($this->namespace) {
267
            case 'newznab':
268
                $url = 'http://www.newznab.com/DTD/2010/feeds/attributes/';
269
                break;
270
            case 'nntmux':
271
            default:
272
                $url = $this->server['server']['url'].'/rss-info/';
273
        }
274
275
        $this->xml->startElement('rss');
276
        $this->xml->writeAttribute('version', '2.0');
277
        $this->xml->writeAttribute('xmlns:atom', 'http://www.w3.org/2005/Atom');
278
        $this->xml->writeAttribute("xmlns:{$this->namespace}", $url);
279
        $this->xml->writeAttribute('encoding', 'utf-8');
280
    }
281
282
    protected function includeRssAtomLink(): void
283
    {
284
        $this->xml->startElement('atom:link');
285
        $this->xml->startAttribute('href');
286
        $this->xml->text($this->server['server']['url'].($this->namespace === 'newznab' ? '/api/v1/api' : '/rss'));
287
        $this->xml->endAttribute();
288
        $this->xml->startAttribute('rel');
289
        $this->xml->text('self');
290
        $this->xml->endAttribute();
291
        $this->xml->startAttribute('type');
292
        $this->xml->text('application/rss+xml');
293
        $this->xml->endAttribute();
294
        $this->xml->endElement();
295
    }
296
297
    /**
298
     * Writes the channel information for the feed.
299
     */
300
    protected function includeMetaInfo(): void
301
    {
302
        $server = $this->server['server'];
303
304
        switch ($this->namespace) {
305
            case 'newznab':
306
                $path = '/apihelp/';
307
                $tag = 'API';
308
                break;
309
            case 'nntmux':
310
            default:
311
                $path = '/rss-info/';
312
                $tag = 'RSS';
313
        }
314
315
        $this->xml->writeElement('title', $server['title']);
316
        $this->xml->writeElement('description', $server['title']." {$tag} Details");
317
        $this->xml->writeElement('link', $server['url']);
318
        $this->xml->writeElement('language', 'en-gb');
319
        $this->xml->writeElement('webMaster', $server['email'].' '.$server['title']);
320
        $this->xml->writeElement('category', $server['meta']);
321
        $this->xml->writeElement('generator', 'nntmux');
322
        $this->xml->writeElement('ttl', '10');
323
        $this->xml->writeElement('docs', $this->server['server']['url'].$path);
324
    }
325
326
    /**
327
     * Adds nntmux logo data to the XML.
328
     */
329
    protected function includeImage(): void
330
    {
331
        $this->xml->startElement('image');
332
        $this->xml->writeAttribute('url', $this->server['server']['url'].'/assets/images/tmux_logo.png');
333
        $this->xml->writeAttribute('title', $this->server['server']['title']);
334
        $this->xml->writeAttribute('link', $this->server['server']['url']);
335
        $this->xml->writeAttribute(
336
            'description',
337
            'Visit '.$this->server['server']['title'].' - '.$this->server['server']['strapline']
338
        );
339
        $this->xml->endElement();
340
    }
341
342
    public function includeTotalRows(): void
343
    {
344
        $this->xml->startElement($this->namespace.':response');
345
        $this->xml->writeAttribute('offset', $this->offset);
346
        $this->xml->writeAttribute('total', $this->releases[0]->_totalrows ?? 0);
347
        $this->xml->endElement();
348
    }
349
350
    /**
351
     * Loop through the releases and add their info to the XML stream.
352
     */
353
    public function includeReleases(): void
354
    {
355
        if (isset($this->releases) && ! empty($this->releases->toArray())) {
356
            if (isset($this->releases[0]->_totalrows)) {
357
                if ($this->releases[0]->_totalrows > 1) {
358
                    foreach ($this->releases as $this->release) {
359
                        $this->xml->startElement('item');
360
                        $this->includeReleaseMain();
361
                        $this->setZedAttributes();
362
                        $this->xml->endElement();
363
                    }
364
                }
365
            } elseif (! isset($this->releases[0]->_totalrows) && preg_match('/rss/i', request()->getRequestUri())) {
366
                foreach ($this->releases as $this->release) {
367
                    $this->xml->startElement('item');
368
                    $this->includeReleaseMain();
369
                    $this->setZedAttributes();
370
                    $this->xml->endElement();
371
                }
372
            } else {
373
                $this->release = $this->releases;
374
                $this->xml->startElement('item');
375
                $this->includeReleaseMain();
376
                $this->setZedAttributes();
377
                $this->xml->endElement();
378
            }
379
        }
380
    }
381
382
    /**
383
     * Writes the primary release information.
384
     */
385
    public function includeReleaseMain(): void
386
    {
387
        $this->xml->writeElement('title', $this->release->searchname);
388
        $this->xml->startElement('guid');
389
        $this->xml->writeAttribute('isPermaLink', 'true');
390
        $this->xml->text("{$this->server['server']['url']}/details/{$this->release->guid}");
391
        $this->xml->endElement();
392
        $this->xml->writeElement(
393
            'link',
394
            "{$this->server['server']['url']}/getnzb?id={$this->release->guid}.nzb".
395
            "&r={$this->parameters['token']}".
396
            ((int) $this->parameters['del'] === 1 ? '&del=1' : '')
397
        );
398
        $this->xml->writeElement('comments', "{$this->server['server']['url']}/details/{$this->release->guid}#comments");
399
        $this->xml->writeElement('pubDate', date(DATE_RSS, strtotime($this->release->adddate)));
400
        $this->xml->writeElement('category', $this->release->category_name);
401
        if ($this->namespace === 'newznab') {
402
            $this->xml->writeElement('description', $this->release->searchname);
403
        } else {
404
            $this->writeRssCdata();
405
        }
406
        if (! isset($this->parameters['dl']) || (isset($this->parameters['dl']) && (int) $this->parameters['dl'] === 1)) {
407
            $this->xml->startElement('enclosure');
408
            $this->xml->writeAttribute(
409
                'url',
410
                "{$this->server['server']['url']}/getnzb?id={$this->release->guid}.nzb".
411
                "&r={$this->parameters['token']}".
412
                ((int) $this->parameters['del'] === 1 ? '&del=1' : '')
413
            );
414
            $this->xml->writeAttribute('length', $this->release->size);
415
            $this->xml->writeAttribute('type', 'application/x-nzb');
416
            $this->xml->endElement();
417
        }
418
    }
419
420
    /**
421
     * Writes the Zed (newznab) specific attributes.
422
     */
423
    protected function setZedAttributes(): void
424
    {
425
        $this->writeZedAttr('category', $this->release->categories_id);
426
        $this->writeZedAttr('size', $this->release->size);
427
        if (isset($this->release->coverurl) && ! empty($this->release->coverurl)) {
428
            $this->writeZedAttr(
429
                'coverurl',
430
                $this->server['server']['url']."/covers/{$this->release->coverurl}"
431
            );
432
        }
433
434
        if ((int) $this->parameters['extended'] === 1) {
435
            $this->writeZedAttr('files', $this->release->totalpart);
436
            $this->writeZedAttr('poster', $this->release->fromname);
437
            if (($this->release->videos_id > 0 || $this->release->tv_episodes_id > 0) && $this->namespace === 'newznab') {
438
                $this->setTvAttr();
439
            }
440
441
            if (isset($this->release->imdbid) && $this->release->imdbid > 0) {
442
                $this->writeZedAttr('imdb', $this->release->imdbid);
443
            }
444
            if (isset($this->release->anidbid) && $this->release->anidbid > 0) {
445
                $this->writeZedAttr('anidbid', $this->release->anidbid);
446
            }
447
            if (isset($this->release->predb_id) && $this->release->predb_id > 0) {
448
                $this->writeZedAttr('prematch', 1);
449
            }
450
            if (isset($this->release->nfostatus) && (int) $this->release->nfostatus === 1) {
451
                $this->writeZedAttr(
452
                    'info',
453
                    $this->server['server']['url'].
454
                    "api?t=info&id={$this->release->guid}&r={$this->parameters['token']}"
455
                );
456
            }
457
458
            $this->writeZedAttr('grabs', $this->release->grabs);
459
            $this->writeZedAttr('comments', $this->release->comments);
460
            $this->writeZedAttr('password', $this->release->passwordstatus);
461
            $this->writeZedAttr('usenetdate', Carbon::parse($this->release->postdate)->toRssString());
462
            if (! empty($this->release->group_name)) {
463
                $this->writeZedAttr('group', $this->release->group_name);
464
            }
465
        }
466
    }
467
468
    /**
469
     * Writes the TV Specific attributes.
470
     */
471
    protected function setTvAttr(): void
472
    {
473
        if (! empty($this->release->title)) {
474
            $this->writeZedAttr('title', $this->release->title);
475
        }
476
        if (isset($this->release->series) && $this->release->series > 0) {
477
            $this->writeZedAttr('season', $this->release->series);
478
        }
479
        if (isset($this->release->episode->episode) && $this->release->episode->episode > 0) {
480
            $this->writeZedAttr('episode', $this->release->episode->episode);
481
        }
482
        if (! empty($this->release->firstaired)) {
483
            $this->writeZedAttr('tvairdate', $this->release->firstaired);
484
        }
485
        if (isset($this->release->tvdb) && $this->release->tvdb > 0) {
486
            $this->writeZedAttr('tvdbid', $this->release->tvdb);
487
        }
488
        if (isset($this->release->trakt) && $this->release->trakt > 0) {
489
            $this->writeZedAttr('traktid', $this->release->trakt);
490
        }
491
        if (isset($this->release->tvrage) && $this->release->tvrage > 0) {
492
            $this->writeZedAttr('tvrageid', $this->release->tvrage);
493
            $this->writeZedAttr('rageid', $this->release->tvrage);
494
        }
495
        if (isset($this->release->tvmaze) && $this->release->tvmaze > 0) {
496
            $this->writeZedAttr('tvmazeid', $this->release->tvmaze);
497
        }
498
        if (isset($this->release->imdb) && $this->release->imdb > 0) {
499
            $this->writeZedAttr('imdbid', $this->release->imdb);
500
        }
501
        if (isset($this->release->tmdb) && $this->release->tmdb > 0) {
502
            $this->writeZedAttr('tmdbid', $this->release->tmdb);
503
        }
504
    }
505
506
    /**
507
     * Writes individual zed (newznab) type attributes.
508
     *
509
     * @param string $name  The namespaced attribute name tag
510
     * @param string $value The namespaced attribute value
511
     */
512
    protected function writeZedAttr($name, $value): void
513
    {
514
        $this->xml->startElement($this->namespace.':attr');
515
        $this->xml->writeAttribute('name', $name);
516
        $this->xml->writeAttribute('value', $value);
517
        $this->xml->endElement();
518
    }
519
520
    /**
521
     * Writes the cData (HTML format) for the RSS feed
522
     * Also calls supplementary cData writes depending upon post process.
523
     */
524
    protected function writeRssCdata(): void
525
    {
526
        $this->cdata = "\n\t<div>\n";
527
        switch (1) {
528
            case ! empty($this->release->cover):
529
                $dir = 'movies';
530
                $column = 'imdbid';
531
                break;
532
            case ! empty($this->release->mu_cover):
533
                $dir = 'music';
534
                $column = 'musicinfo_id';
535
                break;
536
            case ! empty($this->release->co_cover):
537
                $dir = 'console';
538
                $column = 'consoleinfo_id';
539
                break;
540
            case ! empty($this->release->bo_cover):
541
                $dir = 'books';
542
                $column = 'bookinfo_id';
543
                break;
544
        }
545
        if (isset($dir, $column)) {
546
            $dcov = ($dir === 'movies' ? '-cover' : '');
547
            $this->cdata .=
548
                "\t<img style=\"margin-left:10px;margin-bottom:10px;float:right;\" ".
549
                "src=\"{$this->server['server']['url']}/covers/{$dir}/{$this->release->$column}{$dcov}.jpg\" ".
550
                "width=\"120\" alt=\"{$this->release->searchname}\" />\n";
551
        }
552
        $size = human_filesize($this->release->size);
553
        $this->cdata .=
554
            "\t<li>ID: <a href=\"{$this->server['server']['url']}/details/{$this->release->guid}\">{$this->release->guid}</a></li>\n".
555
            "\t<li>Name: {$this->release->searchname}</li>\n".
556
            "\t<li>Size: {$size}</li>\n".
557
            "\t<li>Category: <a href=\"{$this->server['server']['url']}/browse/{$this->release->category_name}\">{$this->release->category_name}</a></li>\n".
558
            "\t<li>Group: <a href=\"{$this->server['server']['url']}/browse/group?g={$this->release->group_name}\">{$this->release->group_name}</a></li>\n".
559
            "\t<li>Poster: {$this->release->fromname}</li>\n".
560
            "\t<li>Posted: {$this->release->postdate}</li>\n";
561
562
        switch ($this->release->passwordstatus) {
563
            case 0:
564
                $pstatus = 'None';
565
                break;
566
            case 1:
567
                $pstatus = 'Possibly Passworded';
568
                break;
569
            case 2:
570
                $pstatus = 'Probably not viable';
571
                break;
572
            case 10:
573
                $pstatus = 'Passworded';
574
                break;
575
            default:
576
                $pstatus = 'Unknown';
577
        }
578
        $this->cdata .= "\t<li>Password: {$pstatus}</li>\n";
579
        if ($this->release->nfostatus === 1) {
580
            $this->cdata .=
581
                "\t<li>Nfo: ".
582
                "<a href=\"{$this->server['server']['url']}/api?t=nfo&id={$this->release->guid}&raw=1&i={$this->parameters['uid']}&r={$this->parameters['token']}\">".
583
                "{$this->release->searchname}.nfo</a></li>\n";
584
        }
585
586
        if ($this->release->parentid === Category::MOVIE_ROOT && $this->release->imdbid !== '') {
587
            $this->writeRssMovieInfo();
588
        } elseif ($this->release->parentid === Category::MUSIC_ROOT && $this->release->musicinfo_id > 0) {
589
            $this->writeRssMusicInfo();
590
        } elseif ($this->release->parentid === Category::GAME_ROOT && $this->release->consoleinfo_id > 0) {
591
            $this->writeRssConsoleInfo();
592
        }
593
        $this->xml->startElement('description');
594
        $this->xml->writeCdata($this->cdata."\t</div>");
595
        $this->xml->endElement();
596
    }
597
598
    /**
599
     * Writes the Movie Info for the RSS feed cData.
600
     */
601
    protected function writeRssMovieInfo(): void
602
    {
603
        $movieCol = ['rating', 'plot', 'year', 'genre', 'director', 'actors'];
604
605
        $cData = $this->buildCdata($movieCol);
606
607
        $this->cdata .=
608
            "\t<li>Imdb Info:
609
				\t<ul>
610
					\t<li>IMDB Link: <a href=\"http://www.imdb.com/title/tt{$this->release->imdbid}/\">{$this->release->searchname}</a></li>\n
611
					\t{$cData}
612
				\t</ul>
613
			\t</li>
614
			\n";
615
    }
616
617
    /**
618
     * Writes the Music Info for the RSS feed cData.
619
     */
620
    protected function writeRssMusicInfo(): void
621
    {
622
        $tData = $cDataUrl = '';
623
624
        $musicCol = ['mu_artist', 'mu_genre', 'mu_publisher', 'mu_releasedate', 'mu_review'];
625
626
        $cData = $this->buildCdata($musicCol);
627
628
        if ($this->release->mu_url !== '') {
629
            $cDataUrl = "<li>Amazon: <a href=\"{$this->release->mu_url}\">{$this->release->mu_title}</a></li>";
630
        }
631
632
        $this->cdata .=
633
            "\t<li>Music Info:
634
			<ul>
635
			{$cDataUrl}
636
			{$cData}
637
			</ul>
638
			</li>\n";
639
        if ($this->release->mu_tracks !== '') {
640
            $tracks = explode('|', $this->release->mu_tracks);
641
            if (\count($tracks) > 0) {
642
                foreach ($tracks as $track) {
643
                    $track = trim($track);
644
                    $tData .= "<li>{$track}</li>";
645
                }
646
            }
647
            $this->cdata .= "
648
			<li>Track Listing:
649
				<ol>
650
				{$tData}
651
				</ol>
652
			</li>\n";
653
        }
654
    }
655
656
    /**
657
     * Writes the Console Info for the RSS feed cData.
658
     */
659
    protected function writeRssConsoleInfo(): void
660
    {
661
        $gamesCol = ['co_genre', 'co_publisher', 'year', 'co_review'];
662
663
        $cData = $this->buildCdata($gamesCol);
664
665
        $this->cdata .= "
666
		<li>Console Info:
667
			<ul>
668
				<li>Amazon: <a href=\"{$this->release->co_url}\">{$this->release->co_title}</a></li>\n
669
				{$cData}
670
			</ul>
671
		</li>\n";
672
    }
673
674
    /**
675
     * Accepts an array of values to loop through to build cData from the release info.
676
     *
677
     * @param array $columns The columns in the release we need to insert
678
     *
679
     * @return string The HTML format cData
680
     */
681
    protected function buildCdata($columns): string
682
    {
683
        $cData = '';
684
685
        foreach ($columns as $info) {
686
            if (! empty($this->release->$info)) {
687
                if ($info === 'mu_releasedate') {
688
                    $ucInfo = 'Released';
689
                    $rDate = date('Y-m-d', strtotime($this->release->$info));
690
                    $cData .= "<li>{$ucInfo}: {$rDate}</li>\n";
691
                } else {
692
                    $ucInfo = ucfirst(preg_replace('/^[a-z]{2}_/i', '', $info));
693
                    $cData .= "<li>{$ucInfo}: {$this->release->$info}</li>\n";
694
                }
695
            }
696
        }
697
698
        return $cData;
699
    }
700
}
701