public static function create(array $data) { $feed = $data['feed']; // Feed must be http/https if (strpos($feed, "http://") !== 0 && strpos($feed, "https://") !== 0) { AmpError::add('feed', T_('Wrong feed url')); } $catalog_id = intval($data['catalog']); if ($catalog_id <= 0) { AmpError::add('catalog', T_('Target catalog required')); } else { $catalog = Catalog::create_from_id($catalog_id); if ($catalog->gather_types !== "podcast") { AmpError::add('catalog', T_('Wrong target catalog type')); } } if (AmpError::occurred()) { return false; } $title = T_('Unknown'); $website = null; $description = null; $language = null; $copyright = null; $generator = null; $lastbuilddate = 0; $episodes = array(); $arturl = ''; $xmlstr = file_get_contents($feed); if ($xmlstr === false) { AmpError::add('feed', T_('Cannot access the feed.')); } else { $xml = simplexml_load_string($xmlstr); if ($xml === false) { AmpError::add('feed', T_('Cannot read the feed.')); } else { $title = html_entity_decode($xml->channel->title); $website = $xml->channel->link; $description = html_entity_decode($xml->channel->description); $language = $xml->channel->language; $copyright = html_entity_decode($xml->channel->copyright); $generator = html_entity_decode($xml->channel->generator); $lastbuilddatestr = $xml->channel->lastBuildDate; if ($lastbuilddatestr) { $lastbuilddate = strtotime($lastbuilddatestr); } if ($xml->channel->image) { $arturl = $xml->channel->image->url; } $episodes = $xml->channel->item; } } if (AmpError::occurred()) { return false; } $sql = "INSERT INTO `podcast` (`feed`, `catalog`, `title`, `website`, `description`, `language`, `copyright`, `generator`, `lastbuilddate`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"; $db_results = Dba::write($sql, array($feed, $catalog_id, $title, $website, $description, $language, $copyright, $generator, $lastbuilddate)); if ($db_results) { $id = Dba::insert_id(); $podcast = new Podcast($id); $dirpath = $podcast->get_root_path(); if (!is_dir($dirpath)) { if (mkdir($dirpath) === false) { debug_event('podcast', 'Cannot create directory ' . $dirpath, 1); } } if (!empty($arturl)) { $art = new Art($id, 'podcast'); $art->insert_url($arturl); } if (count($episodes) > 0) { $podcast->add_episodes($episodes); } } return $db_results; }