public static function importOpml($kfData) { $feeds = $kfData['feeds']; $folders = $kfData['folders']; $filename = $_FILES['filetoupload']['name']; $filesize = $_FILES['filetoupload']['size']; $data = file_get_contents($_FILES['filetoupload']['tmp_name']); $overwrite = isset($_POST['overwrite']); $opml = new DOMDocument('1.0', 'UTF-8'); $importCount = 0; if ($opml->loadXML($data)) { $body = $opml->getElementsByTagName('body'); $xmlArray = Opml::getArrayFromXml($body->item(0)); $array = Opml::convertOpmlArray($xmlArray['outline']); foreach ($array as $hashUrl => $arrayInfo) { $title = ''; if (isset($arrayInfo['title'])) { $title = $arrayInfo['title']; } else { if (isset($arrayInfo['text'])) { $title = $arrayInfo['text']; } } $foldersHash = array(); if (isset($arrayInfo['folders'])) { foreach ($arrayInfo['folders'] as $folder) { $folderTitle = html_entity_decode($folder, ENT_QUOTES, 'UTF-8'); $folderHash = MyTool::smallHash($folderTitle); if (!isset($folders[$folderHash])) { $folders[$folderHash] = array('title' => $folderTitle, 'isOpen' => true); } $foldersHash[] = $folderHash; } } $timeUpdate = 'auto'; $lastUpdate = 0; $xmlUrl = ''; if (isset($arrayInfo['xmlUrl'])) { $xmlUrl = $arrayInfo['xmlUrl']; } $htmlUrl = ''; if (isset($arrayInfo['htmlUrl'])) { $htmlUrl = $arrayInfo['htmlUrl']; } $description = ''; if (isset($arrayInfo['description'])) { $description = $arrayInfo['description']; } // create new feed if (!empty($xmlUrl)) { $oldFeed = array('nbUnread' => 0, 'nbAll' => 0); if (isset($feeds[$hashUrl])) { $oldFeed['nbUnread'] = $feeds[$hashUrl]['nbUnread']; $oldFeed['nbAll'] = $feeds[$hashUrl]['nbAll']; } $currentFeed = array('title' => html_entity_decode($title, ENT_QUOTES, 'UTF-8'), 'description' => html_entity_decode($description, ENT_QUOTES, 'UTF-8'), 'htmlUrl' => html_entity_decode($htmlUrl, ENT_QUOTES, 'UTF-8'), 'xmlUrl' => html_entity_decode($xmlUrl, ENT_QUOTES, 'UTF-8'), 'nbUnread' => $oldFeed['nbUnread'], 'nbAll' => $oldFeed['nbAll'], 'foldersHash' => $foldersHash, 'timeUpdate' => $timeUpdate, 'lastUpdate' => $lastUpdate); if ($overwrite || !isset($feeds[$hashUrl])) { $feeds[$hashUrl] = $currentFeed; $importCount++; } } } FeedPage::init(array('base' => MyTool::getUrl(), 'message' => sprintf(Intl::msg('File %s (%s) was successfully processed: %d links imported'), htmlspecialchars($filename), MyTool::humanBytes($filesize), $importCount), 'button' => Intl::msg('Continue'), 'referer' => MyTool::getUrl(), 'version' => FEED_VERSION, 'pagetitle' => 'KrISS feed installation')); FeedPage::messageTpl(); $kfData['feeds'] = $feeds; $kfData['folders'] = $folders; return $kfData; } else { FeedPage::init(array('base' => MyTool::getUrl(), 'class' => 'text-success', 'message' => sprintf(Intl::msg('File %s (%s) has an unknown file format. Check encoding, try to remove accents and try again. Nothing was imported.'), htmlspecialchars($filename), MyTool::humanBytes($filesize)), 'referer' => MyTool::getUrl() . '?import', 'version' => FEED_VERSION, 'pagetitle' => 'KrISS feed installation')); FeedPage::messageTpl(); exit; } }