/** * Import feed from opml file (as exported by google reader, * tiny tiny rss, rss lounge... using */ 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::$pb->assign('class', 'text-success'); FeedPage::$pb->assign('message', sprintf(Intl::msg('File %s (%s) was successfully processed: %d links imported'), htmlspecialchars($filename), MyTool::humanBytes($filesize), $importCount)); FeedPage::$pb->assign('button', Intl::msg('Continue')); FeedPage::$pb->assign('referer', MyTool::getUrl()); FeedPage::$pb->renderPage('message', false); $kfData['feeds'] = $feeds; $kfData['folders'] = $folders; return $kfData; } else { FeedPage::$pb->assign('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))); FeedPage::$pb->renderPage('message'); } }
$pb->assign('message', sprintf(Intl::msg('The file you are trying to upload is probably bigger than what this webserver can accept (%s). Please upload in smaller chunks.'), MyTool::humanBytes(MyTool::getMaxFileSize()))); $pb->assign('referer', $rurl); $pb->renderPage('message'); } $kf->loadData(); $kf->setData(Opml::importOpml($kf->getData())); $kf->sortFeeds(); $kf->writeData(); exit; } else { if (isset($_POST['cancel'])) { MyTool::redirect(); } else { $pb->assign('pagetitle', Intl::msg('Import') . ' - ' . strip_tags($kfc->title)); $pb->assign('maxsize', MyTool::getMaxFileSize()); $pb->assign('humanmaxsize', MyTool::humanBytes(MyTool::getMaxFileSize())); $pb->assign('token', Session::getToken()); $pb->renderPage('import'); } } } elseif (isset($_GET['export']) && $kfc->isLogged()) { // Export $kf->loadData(); Opml::exportOpml($kf->getFeeds(), $kf->getFolders()); } elseif (isset($_GET['add']) && $kfc->isLogged()) { // Add feed $kf->loadData(); if (isset($_POST['newfeed']) && !empty($_POST['newfeed'])) { $addc = $kf->addChannel($_POST['newfeed']); if (empty($addc['error'])) { // Add success