Commit 72b30127 authored by Benjamin Bellamy's avatar Benjamin Bellamy 💬
Browse files

feat: add lock podcast according to the Podcastindex podcast-namespace to...

feat: add lock podcast according to the Podcastindex podcast-namespace to prevent unauthozized import
parent e49b2239
Loading
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -156,6 +156,7 @@ class Podcast extends BaseController
            'copyright' => $this->request->getPost('copyright'),
            'block' => $this->request->getPost('block') === 'yes',
            'complete' => $this->request->getPost('complete') === 'yes',
            'lock' => $this->request->getPost('lock') === 'yes',
            'created_by' => user(),
            'updated_by' => user(),
        ]);
@@ -244,10 +245,19 @@ class Podcast extends BaseController
                    ' ⎋</a>',
                ]);
        }

        $nsItunes = $feed->channel[0]->children(
            'http://www.itunes.com/dtds/podcast-1.0.dtd'
        );
        $nsPodcast = $feed->channel[0]->children(
            'https://github.com/Podcastindex-org/podcast-namespace/blob/main/docs/1.0.md'
        );

        if ((string) $nsPodcast->locked === 'yes') {
            return redirect()
                ->back()
                ->withInput()
                ->with('errors', [lang('PodcastImport.lock_import')]);
        }

        $podcast = new \App\Entities\Podcast([
            'name' => $this->request->getPost('name'),
@@ -453,6 +463,7 @@ class Podcast extends BaseController
        $this->podcast->block = $this->request->getPost('block') === 'yes';
        $this->podcast->complete =
            $this->request->getPost('complete') === 'yes';
        $this->podcast->lock = $this->request->getPost('lock') === 'yes';
        $this->updated_by = user();

        $db = \Config\Database::connect();
+20 −13
Original line number Diff line number Diff line
@@ -79,6 +79,10 @@ class AddPodcasts extends Migration
                'constraint' => 1024,
                'null' => true,
            ],
            'episode_description_footer' => [
                'type' => 'TEXT',
                'null' => true,
            ],
            'block' => [
                'type' => 'TINYINT',
                'constraint' => 1,
@@ -89,19 +93,12 @@ class AddPodcasts extends Migration
                'constraint' => 1,
                'default' => 0,
            ],
            'episode_description_footer' => [
                'type' => 'TEXT',
                'null' => true,
            ],
            'created_by' => [
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
            ],
            'updated_by' => [
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
            'lock' => [
                'type' => 'TINYINT',
                'constraint' => 1,
                'comment' =>
                    'This tells other podcast platforms whether they are allowed to import this feed.',
                'default' => 1,
            ],
            'imported_feed_url' => [
                'type' => 'VARCHAR',
@@ -117,6 +114,16 @@ class AddPodcasts extends Migration
                    'The RSS new feed URL if this podcast is moving out, NULL otherwise.',
                'null' => true,
            ],
            'created_by' => [
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
            ],
            'updated_by' => [
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
            ],
            'created_at' => [
                'type' => 'TIMESTAMP',
            ],
+4 −3
Original line number Diff line number Diff line
@@ -76,13 +76,14 @@ class Podcast extends Entity
        'owner_email' => '?string',
        'type' => 'string',
        'copyright' => '?string',
        'episode_description_footer' => '?string',
        'block' => 'boolean',
        'complete' => 'boolean',
        'episode_description_footer' => '?string',
        'created_by' => 'integer',
        'updated_by' => 'integer',
        'lock' => 'boolean',
        'imported_feed_url' => '?string',
        'new_feed_url' => '?string',
        'created_by' => 'integer',
        'updated_by' => 'integer',
    ];

    /**
+7 −2
Original line number Diff line number Diff line
@@ -21,8 +21,11 @@ function get_rss_feed($podcast)

    $itunes_namespace = 'http://www.itunes.com/dtds/podcast-1.0.dtd';

    $podcast_namespace =
        'https://github.com/Podcastindex-org/podcast-namespace/blob/main/docs/1.0.md';

    $rss = new SimpleRSSElement(
        "<?xml version='1.0' encoding='utf-8'?><rss version='2.0' xmlns:itunes='$itunes_namespace' xmlns:content='http://purl.org/rss/1.0/modules/content/'></rss>"
        "<?xml version='1.0' encoding='utf-8'?><rss version='2.0' xmlns:itunes='$itunes_namespace' xmlns:podcast='$podcast_namespace' xmlns:content='http://purl.org/rss/1.0/modules/content/'></rss>"
    );

    $channel = $rss->addChild('channel');
@@ -60,7 +63,9 @@ function get_rss_feed($podcast)
    $itunes_image = $channel->addChild('image', null, $itunes_namespace);
    $itunes_image->addAttribute('href', $podcast->image->original_url);
    $channel->addChild('language', $podcast->language);

    $channel
        ->addChild('locked', $podcast->lock ? 'yes' : 'no', $podcast_namespace)
        ->addAttribute('owner', $podcast->owner_email);
    // set main category first, then other categories as apple
    add_category_tag($channel, $podcast->category);
    foreach ($podcast->other_categories as $other_category) {
+3 −0
Original line number Diff line number Diff line
@@ -65,6 +65,9 @@ return [
        'status_section_subtitle' => 'Dead or alive?',
        'block' => 'Podcast should be hidden from all platforms',
        'complete' => 'Podcast will not be having new episodes',
        'lock' => 'Podcast is locked for export',
        'lock_hint' =>
            'The purpose is to tell other podcast platforms whether they are allowed to import this feed. A value of yes means that any attempt to import this feed into a new platform should be rejected.',
        'submit_create' => 'Create podcast',
        'submit_edit' => 'Save podcast',
    ],
Loading