/** * Update channel and return feed information error, lastUpdate * and newItems * * @param string $feedHash Hash corresponding to a feed * * @return empty string */ public function updateFeedsHash($feedsHash, $force, $format = '') { $i = 0; $errorCount = 0; $noUpdateCount = 0; $successCount = 0; $nbItemsAdded = 0; $feedsHash = $this->orderFeedsForUpdate($feedsHash); $nbFeeds = count($feedsHash); ob_end_flush(); if (ob_get_level() == 0) { ob_start(); } if ($format === 'html') { echo '<table class="table table-striped"> <thead> <tr> <th>#</th> <th>' . Intl::msg('Feed') . '</th> <th>' . Intl::msg('New items') . '</th> <th>' . Intl::msg('Time') . '</th> <th>' . Intl::msg('Status') . '</th> </tr> </thead> <tbody>'; } $start = microtime(true); $lastTime = $start; foreach ($feedsHash as $feedHash) { $i++; $feed = $this->getFeed($feedHash); $strBegin = "\n" . '<tr><td>' . str_pad($i . '/' . $nbFeeds, 7, ' ', STR_PAD_LEFT) . '</td><td> <a href="?currentHash=' . $feedHash . '">' . substr(str_pad($feed['title'], 50), 0, 50) . '</a> </td><td>'; if ($format === 'html') { echo str_pad($strBegin, 4096); ob_flush(); flush(); } $strEnd = ''; $time = microtime(true) - $lastTime; $lastTime += $time; if ($force or $this->needUpdate($feed)) { $info = $this->updateChannel($feedHash, $force); $countItems = count($info['newItems']); $strEnd .= '<span class="text-success">' . str_pad($countItems, 3, ' ', STR_PAD_LEFT) . '</span> </td><td>' . str_pad(number_format($time, 1), 6, ' ', STR_PAD_LEFT) . 's </td><td>'; if (empty($info['error'])) { $strEnd .= Intl::msg('Successfully updated') . '</td></tr>'; $successCount++; $nbItemsAdded += $countItems; } else { $strEnd .= '<span class="text-error">' . $info['error'] . '</span></td></tr>'; $errorCount++; } } else { $strEnd .= str_pad('0', 3, ' ', STR_PAD_LEFT) . ' </td><td>' . str_pad(number_format($time, 1), 6, ' ', STR_PAD_LEFT) . 's </td><td><span class="text-warning">' . Intl::msg('Already up-to-date') . '</span></td></tr>'; $noUpdateCount++; } if ($format === 'html') { echo str_pad($strEnd, 4096); ob_flush(); flush(); } else { echo strip_tags($strBegin . $strEnd); } } // summary $strBegin = "\n" . '<tr><td></td><td> ' . Intl::msg('Total:') . ' ' . $nbFeeds . ' ' . ($nbFeeds > 1 ? Intl::msg('items') : Intl::msg('item')) . '</td><td>'; if ($format === 'html') { echo str_pad($strBegin, 4096); ob_flush(); flush(); } $strEnd = str_pad($nbItemsAdded, 3, ' ', STR_PAD_LEFT) . ' </td><td>' . str_pad(number_format(microtime(true) - $start, 1), 6, ' ', STR_PAD_LEFT) . 's </td><td>' . '<span class="text-success">' . $successCount . ' ' . ($successCount > 1 ? Intl::msg('Successes') : Intl::msg('Success')) . ' </span><br />' . '<span class="text-warning">' . $noUpdateCount . ' ' . Intl::msg('Up-to-date') . ' </span><br />' . '<span class="text-error">' . $errorCount . ' ' . ($errorCount > 1 ? Intl::msg('Errors') : Intl::msg('Error')) . ' </span></td></tr>'; if ($format === 'html') { echo str_pad($strEnd, 4096); ob_flush(); flush(); } else { echo strip_tags($strBegin . $strEnd); } if ($format === 'html') { echo '</tbody></table>'; } return ''; }
/** * 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'); } }
/** * Installation of the configuration file */ private function _install() { if (!empty($_POST['setlogin']) && !empty($_POST['setpassword'])) { $this->setSalt(sha1(uniqid('', true) . '_' . mt_rand())); $this->setLogin($_POST['setlogin']); $this->setHash($_POST['setpassword']); $this->write(); FeedPage::$pb->assign('pagetitle', 'KrISS feed installation'); FeedPage::$pb->assign('class', 'text-success'); FeedPage::$pb->assign('message', Intl::msg('Your simple and smart (or stupid) feed reader is now configured.')); FeedPage::$pb->assign('referer', MyTool::getUrl() . '?import'); FeedPage::$pb->assign('button', Intl::msg('Continue')); FeedPage::$pb->renderPage('message'); } else { FeedPage::$pb->assign('pagetitle', Intl::msg('KrISS feed installation')); FeedPage::$pb->assign('token', Session::getToken()); FeedPage::$pb->renderPage('install'); } exit; }
$hashView = 'Folder (' . $kf->getFolderTitle($currentHash) . '): <span id="nb-unread">' . $unread . '</span><span class="hidden-phone"> ' . Intl::msg('unread items') . '</span>'; break; default: $hashView = '<span id="nb-unread">' . $unread . '</span><span class="hidden-phone"> ' . Intl::msg('unread items') . '</span>'; break; } $menu = $kfc->getMenu(); $paging = $kfc->getPaging(); $pb->assign('menu', $menu); $pb->assign('paging', $paging); $pb->assign('currentHashType', $currentHashType); $pb->assign('currentHashView', $hashView); $pb->assign('currentPage', (int) $currentPage); $pb->assign('maxPage', (int) $maxPage); $pb->assign('currentItemHash', $currentItemHash); $pb->assign('nbItems', $nbItems); $pb->assign('items', $listItems); if ($listFeeds == 'show') { $pb->assign('feedsView', $kf->getFeedsView()); } $pb->assign('pagetitle', strip_tags($kfc->title)); $pb->renderPage('index'); } else { $pb->assign('pagetitle', Intl::msg('Sign in') . ' - ' . strip_tags($kfc->title)); if (!empty($_SERVER['QUERY_STRING'])) { $pb->assign('referer', MyTool::getUrl() . '?' . $_SERVER['QUERY_STRING']); } $pb->assign('token', Session::getToken()); $pb->renderPage('login'); } }
/** * Get human readable error * * @param integer $error Number of error occured during a feed update * * @return string String of the corresponding error */ public static function getError($error) { switch ($error) { case self::ERROR_UNKNOWN_CODE: return Intl::msg('Http code not valid'); break; case self::ERROR_LOCATION: return Intl::msg('Location not found'); break; case self::ERROR_TOO_MANY_REDIRECTS: return Intl::msg('Too many redirects'); break; case self::ERROR_NO_CURL: return Intl::msg('Error when loading without curl'); break; default: return $error; break; } }