-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/wizard' into develop
- Loading branch information
Showing
21 changed files
with
588 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
title: Podcaster Wizard | ||
tabs: | ||
wizard: | ||
label: Wizard | ||
icon: wand | ||
columns: | ||
- width: 1/3 | ||
sections: | ||
wizardInfo: | ||
type: fields | ||
fields: | ||
wizardHead: | ||
type: headline | ||
label: Import Wizard | ||
wizardInfo: | ||
type: info | ||
label: Hello there!️️ | ||
theme: positive | ||
text: This wizard helps you transfering your existing podcast to Kirby. It uses your RSS-Feed for that. All information will be imported from this feed. | ||
wizardStep1: | ||
type: info | ||
label: Needed information | ||
text: Please enter the URL of your current podcast feed. Then select the page which will function as your target. All episodes and the feed will be created as children of this page. Hit save, then start the import. | ||
wizardStep2: | ||
type: info | ||
label: Be aware | ||
theme: negative | ||
text: This feature is experimental. It'll create new pages and add information. Please backup your data before you do this. Also make sure the target page has no other pages in it. Otherwise the import may fail! | ||
- width: 2/3 | ||
sections: | ||
wizardSteps: | ||
type: fields | ||
fields: | ||
wizardInfos: | ||
type: headline | ||
label: Start your import | ||
podcasterWizardSrcFeed: | ||
type: url | ||
label: Your source RSS-Feed | ||
required: true | ||
podcasterWizardDestination: | ||
type: pages | ||
label: Parent Page | ||
width: 1/3 | ||
required: true | ||
podcasterWizardTemplate: | ||
type: text | ||
label: Template Name | ||
help: Without file extension, if your content files look like 'article.txt' then your template name is 'article' | ||
width: 1/3 | ||
required: true | ||
podcasterWizardPageStatus: | ||
type: toggle | ||
label: Page Status | ||
default: no | ||
text: | ||
Draft | ||
Unlisted | ||
help: Pages created by this wizard will be drafts. If you want, they can also be unlisted. | ||
width: 1/3 | ||
podstatsFeed: | ||
type: podcasterWizard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
<?php | ||
|
||
namespace Plugin\Podcaster; | ||
|
||
use Xml; | ||
use File; | ||
|
||
return [ | ||
'routes' => [ | ||
[ | ||
'pattern' => 'podcaster/stats/(:any)/year/(:num)/month/(:num)', | ||
'action' => function ($podcast, $year, $month) { | ||
if (option('mauricerenck.podcaster.statsInternal') === false || option('mauricerenck.podcaster.statsType') === 'file') { | ||
$errorMessage = ['error' => 'cannot use stats on file method, use mysql version instead']; | ||
echo new Response(json_encode($errorMessage), 'application/json', 501); | ||
} | ||
|
||
$podcasterStats = new PodcasterStats(); | ||
$stats = $podcasterStats->getEpisodeStatsOfMonth($podcast, $year, $month); | ||
return [ | ||
'stats' => $stats | ||
]; | ||
} | ||
], | ||
[ | ||
'pattern' => 'podcaster/stats/(:any)/(:any)/yearly-downloads/(:any)', | ||
'action' => function ($podcast, $type, $year) { | ||
if (option('mauricerenck.podcaster.statsInternal') === false || option('mauricerenck.podcaster.statsType') === 'file') { | ||
$errorMessage = ['error' => 'cannot use stats on file method, use mysql version instead']; | ||
echo new Response(json_encode($errorMessage), 'application/json', 501); | ||
} | ||
|
||
$podcasterStats = new PodcasterStats(); | ||
$stats = $podcasterStats->getDownloadsOfYear($podcast, $year, $type); | ||
return [ | ||
'stats' => $stats | ||
]; | ||
} | ||
], | ||
[ | ||
'pattern' => 'podcaster/stats/(:any)/top/(:num)', | ||
'action' => function ($podcast, $limit) { | ||
if (option('mauricerenck.podcaster.statsInternal') === false || option('mauricerenck.podcaster.statsType') === 'file') { | ||
$errorMessage = ['error' => 'cannot use stats on file method, use mysql version instead']; | ||
echo new Response(json_encode($errorMessage), 'application/json', 501); | ||
} | ||
|
||
$podcasterStats = new PodcasterStats(); | ||
$stats = $podcasterStats->getTopDownloads($podcast, $limit); | ||
return [ | ||
'stats' => $stats | ||
]; | ||
} | ||
], | ||
[ | ||
'pattern' => 'podcaster/wizard/checkfeed', | ||
'action' => function () { | ||
try { | ||
$feedUrl = $_SERVER['HTTP_X_FEED_URI']; | ||
} catch (Exeption $e) { | ||
echo 'Could not read feed'; | ||
} | ||
|
||
$feed = implode(file($feedUrl)); | ||
return Xml::parse($feed); | ||
} | ||
], | ||
[ | ||
'pattern' => 'podcaster/wizard/createFeed', | ||
'action' => function () { | ||
$headerTarget = $_SERVER['HTTP_X_TARGET_PAGE']; | ||
|
||
$targetPage = kirby()->page($headerTarget); | ||
$pageData = json_decode(file_get_contents('php://input')); | ||
|
||
$wizardHelper = new PodcasterWizard(); | ||
|
||
$newPageData = [ | ||
'slug' => 'feed', | ||
'template' => 'podcasterfeed', | ||
'draft' => false, | ||
'content' => [ | ||
'podcasterSource' => $targetPage->slug(), | ||
'title' => $wizardHelper->getField($pageData, 'title'), | ||
'podcasterTitle' => $wizardHelper->getField($pageData, 'title'), | ||
'podcasterDescription' => $wizardHelper->getField($pageData, 'description'), | ||
'podcasterSubtitle' => $wizardHelper->getField($pageData, 'itunessubtitle'), | ||
'podcasterKeywords' => $wizardHelper->getField($pageData, 'ituneskeywords'), | ||
'podcasterCopyright' => $wizardHelper->getField($pageData, 'copyright'), | ||
'podcasterLink' => $wizardHelper->getField($pageData, 'link'), | ||
'podcasterLanguage' => $wizardHelper->getField($pageData, 'language'), | ||
'podcasterType' => $wizardHelper->getField($pageData, 'itunestype'), | ||
'podcasterExplicit' => $wizardHelper->getField($pageData, 'itunesexplicit'), | ||
'podcasterBlock' => $wizardHelper->getField($pageData, 'itunesblock') | ||
] | ||
]; | ||
|
||
$feed = $targetPage->createChild($newPageData); | ||
|
||
return json_encode(['title' => $pageData->title, 'slug' => $feed->id()]); | ||
}, | ||
'method' => 'POST' | ||
], | ||
[ | ||
'pattern' => 'podcaster/wizard/createEpisode', | ||
'action' => function () { | ||
$headerTarget = $_SERVER['HTTP_X_TARGET_PAGE']; | ||
$headerTemplate = $_SERVER['HTTP_X_PAGE_TEMPLATE']; | ||
$pageStatus = ($_SERVER['HTTP_X_PAGE_STATUS'] === 'false'); | ||
|
||
$targetPage = kirby()->page($headerTarget); | ||
$pageData = json_decode(file_get_contents('php://input')); | ||
|
||
$wizardHelper = new PodcasterWizard(); | ||
$slug = $wizardHelper->getPageSlug($wizardHelper->getField($pageData, 'link'), $wizardHelper->getField($pageData, 'title')); | ||
|
||
$newPageData = [ | ||
'slug' => $slug, | ||
'template' => $headerTemplate, | ||
'draft' => $pageStatus, | ||
'content' => [ | ||
'title' => $wizardHelper->getField($pageData, 'title'), | ||
'date' => $wizardHelper->getField($pageData, 'pubDate'), | ||
'podcasterSeason' => $wizardHelper->getField($pageData, 'itunesseason'), | ||
'podcasterEpisode' => $wizardHelper->getField($pageData, 'itunesepisode'), | ||
'podcasterEpisodeType' => $wizardHelper->getField($pageData, 'itunesepisodetype'), | ||
'podcasterExplizit' => $wizardHelper->getField($pageData, 'itunesexplicit'), | ||
'podcasterBlock' => $wizardHelper->getField($pageData, 'itunesblock'), | ||
'podcasterTitle' => $wizardHelper->getField($pageData, 'title'), | ||
'podcasterSubtitle' => $wizardHelper->getField($pageData, 'itunessubtitle'), | ||
'podcasterDescription' => $wizardHelper->getField($pageData, 'description'), | ||
] | ||
]; | ||
|
||
$episode = $targetPage->createChild($newPageData); | ||
$mp3FileName = $slug . '.mp3'; | ||
|
||
return json_encode(['title' => $pageData->title, 'slug' => $episode->id(), 'file' => $wizardHelper->getField($pageData, 'file')]); | ||
}, | ||
'method' => 'POST' | ||
], | ||
[ | ||
'pattern' => 'podcaster/wizard/createFile', | ||
'action' => function () { | ||
$headerTarget = $_SERVER['HTTP_X_TARGET_PAGE']; | ||
|
||
$episode = kirby()->page($headerTarget); | ||
$pageData = json_decode(file_get_contents('php://input')); | ||
|
||
$wizardHelper = new PodcasterWizard(); | ||
$slug = $episode->slug(); | ||
|
||
$mp3FileName = $slug . '.mp3'; | ||
$mp3 = $wizardHelper->downloadMp3($wizardHelper->getField($pageData, 'file'), $mp3FileName); | ||
|
||
$file = File::create([ | ||
'source' => kirby()->root('plugins') . '/kirby-podcaster/tmp/' . $mp3FileName, | ||
'parent' => $episode, | ||
'filename' => $mp3FileName, | ||
'template' => 'podcaster-episode', | ||
'content' => [ | ||
'duration' => $wizardHelper->getField($pageData, 'itunesduration'), | ||
'episodeTitle' => $wizardHelper->getField($pageData, 'itunestitle') | ||
] | ||
]); | ||
|
||
unlink(kirby()->root('plugins') . '/kirby-podcaster/tmp/' . $mp3FileName); | ||
|
||
return json_encode(['created' => $mp3FileName]); | ||
}, | ||
'method' => 'POST' | ||
] | ||
] | ||
]; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.