Commit 6ecdaad9 authored by Benjamin Bellamy's avatar Benjamin Bellamy 💬
Browse files

feat(custom-rss): add custom xml tag injection in rss feed for ❬channel❭ and ❬item❭

parent ea538364
Loading
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -141,6 +141,7 @@ class Episode extends BaseController
                : null,
            'type' => $this->request->getPost('type'),
            'is_blocked' => $this->request->getPost('block') == 'yes',
            'custom_rss_string' => $this->request->getPost('custom_rss'),
            'created_by' => user(),
            'updated_by' => user(),
            'published_at' => $publicationDate
@@ -236,6 +237,9 @@ class Episode extends BaseController
            : null;
        $this->episode->type = $this->request->getPost('type');
        $this->episode->is_blocked = $this->request->getPost('block') == 'yes';
        $this->episode->custom_rss_string = $this->request->getPost(
            'custom_rss'
        );

        $publicationDate = $this->request->getPost('publication_date');
        $this->episode->published_at = $publicationDate
+4 −0
Original line number Diff line number Diff line
@@ -163,6 +163,7 @@ class Podcast extends BaseController
            'copyright' => $this->request->getPost('copyright'),
            'location' => $this->request->getPost('location_name'),
            'payment_pointer' => $this->request->getPost('payment_pointer'),
            'custom_rss_string' => $this->request->getPost('custom_rss'),
            'is_blocked' => $this->request->getPost('block') === 'yes',
            'is_completed' => $this->request->getPost('complete') === 'yes',
            'is_locked' => $this->request->getPost('lock') === 'yes',
@@ -259,6 +260,9 @@ class Podcast extends BaseController
        $this->podcast->payment_pointer = $this->request->getPost(
            'payment_pointer'
        );
        $this->podcast->custom_rss_string = $this->request->getPost(
            'custom_rss'
        );
        $this->podcast->is_blocked = $this->request->getPost('block') === 'yes';
        $this->podcast->is_completed =
            $this->request->getPost('complete') === 'yes';
+4 −0
Original line number Diff line number Diff line
@@ -138,6 +138,10 @@ class AddPodcasts extends Migration
                'constraint' => 12,
                'null' => true,
            ],
            'custom_rss' => [
                'type' => 'JSON',
                'null' => true,
            ],
            'created_by' => [
                'type' => 'INT',
                'unsigned' => true,
+4 −0
Original line number Diff line number Diff line
@@ -124,6 +124,10 @@ class AddEpisodes extends Migration
                'constraint' => 12,
                'null' => true,
            ],
            'custom_rss' => [
                'type' => 'JSON',
                'null' => true,
            ],
            'created_by' => [
                'type' => 'INT',
                'unsigned' => true,
+60 −0
Original line number Diff line number Diff line
@@ -106,6 +106,13 @@ class Episode extends Entity
     */
    protected $publication_status;

    /**
     * Return custom rss as string
     *
     * @var string
     */
    protected $custom_rss_string;

    protected $dates = [
        'published_at',
        'created_at',
@@ -136,6 +143,7 @@ class Episode extends Entity
        'location_name' => '?string',
        'location_geo' => '?string',
        'location_osmid' => '?string',
        'custom_rss' => '?json-array',
        'created_by' => 'integer',
        'updated_by' => 'integer',
    ];
@@ -564,4 +572,56 @@ class Episode extends Entity
        }
        return $this;
    }

    /**
     * Get custom rss tag as XML String
     *
     * @return string
     *
     */
    function getCustomRssString()
    {
        helper('rss');
        if (empty($this->attributes['custom_rss'])) {
            return '';
        } else {
            $xmlNode = (new \App\Libraries\SimpleRSSElement(
                '<?xml version="1.0" encoding="utf-8"?><rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:podcast="https://github.com/Podcastindex-org/podcast-namespace/blob/main/docs/1.0.md" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0"/>'
            ))
                ->addChild('channel')
                ->addChild('item');
            array_to_rss(
                [
                    'elements' => $this->custom_rss,
                ],
                $xmlNode
            );
            return str_replace(['<item>', '</item>'], '', $xmlNode->asXML());
        }
    }

    /**
     * Saves custom rss tag into json
     *
     * @param string $customRssString
     *
     */
    function setCustomRssString($customRssString)
    {
        helper('rss');
        $customRssArray = rss_to_array(
            simplexml_load_string(
                '<?xml version="1.0" encoding="utf-8"?><rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:podcast="https://github.com/Podcastindex-org/podcast-namespace/blob/main/docs/1.0.md" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0"><channel><item>' .
                    $customRssString .
                    '</item></channel></rss>'
            )
        )['elements'][0]['elements'][0];
        if (array_key_exists('elements', $customRssArray)) {
            $this->attributes['custom_rss'] = json_encode(
                $customRssArray['elements']
            );
        } else {
            $this->attributes['custom_rss'] = null;
        }
    }
}
Loading