Created
August 12, 2020 14:37
-
-
Save philipp-r/af0341593589d8c0237b131d9754a4b8 to your computer and use it in GitHub Desktop.
Import RSS feed / podcast feed / xml file in dokuwiki
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
<?php | |
$xml = simplexml_load_file("https://example.com/feed.xml"); | |
foreach($xml->channel->item as $podcastItem){ | |
// data: | |
$podcast_title = $podcastItem->title->__toString(); | |
$podcast_id = $podcastItem->guid->__toString(); | |
$podcast_link = $podcastItem->link->__toString(); | |
// datum umwandeln: | |
date_default_timezone_set("Europe/Berlin"); | |
$podcast_date_original = $podcastItem->pubDate->__toString(); | |
$podcast_date = date("d.m.Y H:i", strtotime($podcast_date_original)); | |
$podcast_date_short = date("d.m.Y", strtotime($podcast_date_original)); | |
// iTunes data: (https://www.sitepoint.com/simplexml-and-namespaces/) | |
$podcastItemiTunes = $podcastItem->children('http://www.itunes.com/dtds/podcast-1.0.dtd'); | |
$podcast_subtitle = $podcastItemiTunes->subtitle->__toString(); | |
$podcast_summary = $podcastItemiTunes->summary->__toString(); | |
$podcast_episode = $podcastItemiTunes->episode->__toString(); | |
$podcast_title2 = $podcastItemiTunes->title->__toString(); | |
$podcast_duration = $podcastItemiTunes->duration->__toString(); | |
// .mp3 attribute (https://www.php.net/manual/en/simplexmlelement.attributes.php) | |
$podcastItemMp3 = $podcastItem->enclosure->attributes(); | |
$podcast_mp3 = $podcastItemMp3->__toString(); | |
// build post data | |
$putpageInhalt = <<<EOF | |
<?xml version="1.0"?> | |
<methodCall> | |
<methodName>wiki.putPage</methodName> | |
<params> | |
<param> | |
<value> | |
<string>$podcast_episode</string> | |
</value> | |
</param> | |
<param> | |
<value> | |
<string><![CDATA[====== Folge $podcast_episode: $podcast_title2 ====== | |
$podcast_summary | |
Dauer: $podcast_duration | |
[[$podcast_link|Link zur Folge]] | |
[[$podcast_mp3|.mp3 Datei]] ]]></string> | |
</value> | |
</param> | |
<param> | |
<value> | |
<struct> | |
<member> | |
<name>sum</name> | |
<value><string>Folge $podcast_episode angelegt</string></value> | |
</member> | |
<member> | |
<name>minor</name> | |
<value><boolean>False</boolean></value> | |
</member> | |
</struct> | |
</value> | |
</param> | |
</params> | |
</methodCall> | |
EOF; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL,"https://example.com/lib/exe/xmlrpc.php"); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $putpageInhalt); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_USERPWD, "username:password" ); | |
$server_output = curl_exec($ch); | |
curl_close ($ch); | |
print_r($server_output); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment