'); // Suffix to encapsulate data in php code. define('MIN_TIME_UPDATE', 5); // Minimum accepted time for update define('ERROR_NO_ERROR', 0); define('ERROR_NO_XML', 1); define('ERROR_ITEMS_MISSED', 2); define('ERROR_LAST_UPDATE', 3); define('ERROR_UNKNOWN', 4); // fix some warning date_default_timezone_set('Europe/Paris'); if (!is_dir(DATA_DIR)) { if (!@mkdir(DATA_DIR, 0755)) { echo ' '; exit(); } @chmod(DATA_DIR, 0755); if (!is_file(DATA_DIR.'/.htaccess')) { if (!@file_put_contents( DATA_DIR.'/.htaccess', "Allow from none\nDeny from all\n" )) { echo ' '; exit(); } } } class FeedConf { private $_file = ''; public $login = ''; public $hash = ''; public $disableSessionProtection = false; public $salt = ''; public $title = "Kriss feed"; public $redirector = ''; public $locale = 'en_GB'; public $shaarli = ''; public $maxItems = 100; public $maxUpdate = 60; public $order = 'newerFirst'; public $autoreadItem = false; public $autoreadPage = false; public $autoUpdate = false; public $autohide = false; public $autofocus = true; public $addFavicon = false; public $blank = false; public $visibility = 'private'; public $version; public $view = 'list'; public $tpl = 'std'; public $filter = 'unread'; public $listFeeds = 'show'; public $byPage = 10; public $currentHash = 'all'; public $currentPage = 1; public $menuView = 1; public $menuListFeeds = 2; public $menuFilter = 3; public $menuOrder = 4; public $menuUpdate = 5; public $menuRead = 6; public $menuUnread = 7; public $menuEdit = 8; public $menuAdd = 9; public $menuHelp = 10; public $menuStars = 11; public $pagingItem = 1; public $pagingPage = 2; public $pagingByPage = 3; public $pagingMarkAs = 4; public function __construct($configFile, $version) { $this->_file = $configFile; $this->version = $version; // Loading user config if (file_exists($this->_file)) { include_once $this->_file; } else { $this->_install(); } Session::$disableSessionProtection = $this->disableSessionProtection; if ($this->addFavicon) { /* favicon dir */ if (!is_dir(INC_DIR)) { if (!@mkdir(INC_DIR, 0755)) { die("Can not create inc dir: ".INC_DIR); } } if (!is_dir(FAVICON_DIR)) { if (!@mkdir(FAVICON_DIR, 0755)) { die("Can not create inc dir: ".FAVICON_DIR); } } } if ($this->isLogged()) { unset($_SESSION['view']); unset($_SESSION['tpl']); unset($_SESSION['listFeeds']); unset($_SESSION['filter']); unset($_SESSION['order']); unset($_SESSION['byPage']); } $view = $this->getView(); $tpl = $this->getTpl(); $listFeeds = $this->getListFeeds(); $filter = $this->getFilter(); $order = $this->getOrder(); $byPage = $this->getByPage(); if ($this->view != $view || $this->tpl != $tpl || $this->listFeeds != $listFeeds || $this->filter != $filter || $this->order != $order || $this->byPage != $byPage ) { $this->view = $view; $this->tpl = $tpl; $this->listFeeds = $listFeeds; $this->filter = $filter; $this->order = $order; $this->byPage = $byPage; $this->write(); } if (!$this->isLogged()) { $_SESSION['view'] = $view; $_SESSION['tpl'] = $tpl; $_SESSION['listFeeds'] = $listFeeds; $_SESSION['filter'] = $filter; $_SESSION['order'] = $order; $_SESSION['byPage'] = $byPage; } } 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(); echo ' '; exit(); } else { FeedPage::init( array( 'version' => $this->version, 'pagetitle' => 'KrISS feed installation' ) ); FeedPage::installTpl(); } exit(); } public function hydrate(array $data) { foreach ($data as $key => $value) { // get setter $method = 'set'.ucfirst($key); // if setter exists just call it // (php is not case-sensitive with functions) if (method_exists($this, $method)) { $this->$method($value); } } $this->write(); } public function getView() { $view = $this->view; if (isset($_GET['view'])) { if ($_GET['view'] == 'expanded') { $view = 'expanded'; } if ($_GET['view'] == 'list') { $view = 'list'; } } else if (isset($_SESSION['view'])) { $view = $_SESSION['view']; } return $view; } public function getTpl() { $tpl = $this->tpl; if (isset($_GET['tpl'])) { if ($_GET['tpl'] == 'std') { $tpl = 'std'; } if ($_GET['tpl'] == 'alt') { $tpl = 'alt'; } } else if (isset($_SESSION['tpl'])) { $tpl = $_SESSION['tpl']; } return $tpl; } public function getFilter() { $filter = $this->filter; if (isset($_GET['filter'])) { if ($_GET['filter'] == 'unread') { $filter = 'unread'; } if ($_GET['filter'] == 'all') { $filter = 'all'; } } else if (isset($_SESSION['filter'])) { $filter = $_SESSION['filter']; } return $filter; } public function getListFeeds() { $listFeeds = $this->listFeeds; if (isset($_GET['listFeeds'])) { if ($_GET['listFeeds'] == 'show') { $listFeeds = 'show'; } if ($_GET['listFeeds'] == 'hide') { $listFeeds = 'hide'; } } else if (isset($_SESSION['listFeeds'])) { $listFeeds = $_SESSION['listFeeds']; } return $listFeeds; } public function getByPage() { $byPage = $this->byPage; if (isset($_GET['byPage']) && is_numeric($_GET['byPage']) && $_GET['byPage'] > 0) { $byPage = $_GET['byPage']; } else if (isset($_SESSION['byPage'])) { $byPage = $_SESSION['byPage']; } return $byPage; } public function getOrder() { $order = $this->order; if (isset($_GET['order'])) { if ($_GET['order'] === 'newerFirst') { $order = 'newerFirst'; } if ($_GET['order'] === 'olderFirst') { $order = 'olderFirst'; } } else if (isset($_SESSION['order'])) { $order = $_SESSION['order']; } return $order; } public function getCurrentHash() { $currentHash = $this->currentHash; if (isset($_GET['currentHash'])) { $currentHash = preg_replace('/[^a-zA-Z0-9-_@]/', '', substr(trim($_GET['currentHash'], '/'), 0, 6)); } if (empty($currentHash)) { $currentHash = 'all'; } return $currentHash; } public function getCurrentPage() { $currentPage = $this->currentPage; if (isset($_GET['page']) && !empty($_GET['page'])) { $currentPage = (int)$_GET['page']; } else if (isset($_GET['previousPage']) && !empty($_GET['previousPage'])) { $currentPage = (int)$_GET['previousPage'] - 1; if ($currentPage < 1) { $currentPage = 1; } } else if (isset($_GET['nextPage']) && !empty($_GET['nextPage'])) { $currentPage = (int)$_GET['nextPage'] + 1; } return $currentPage; } public function setDisableSessionProtection($disableSessionProtection) { $this->disableSessionProtection = $disableSessionProtection; } public function setLogin($login) { $this->login = $login; } public function setVisibility($visibility) { $this->visibility = $visibility; } public function setHash($pass) { $this->hash = sha1($pass.$this->login.$this->salt); } public function setSalt($salt) { $this->salt = $salt; } public function setTitle($title) { $this->title = $title; } public function setLocale($locale) { $this->locale = $locale; } public function setRedirector($redirector) { $this->redirector = $redirector; } public function setAutoreadPage($autoreadPage) { $this->autoreadPage = $autoreadPage; } public function setAutoUpdate($autoUpdate) { $this->autoUpdate = $autoUpdate; } public function setAutoreadItem($autoreadItem) { $this->autoreadItem = $autoreadItem; } public function setAutohide($autohide) { $this->autohide = $autohide; } public function setAutofocus($autofocus) { $this->autofocus = $autofocus; } public function setAddFavicon($addFavicon) { $this->addFavicon = $addFavicon; } public function setShaarli($url) { $this->shaarli = $url; } public function setMaxUpdate($max) { $this->maxUpdate = $max; } public function setMaxItems($max) { $this->maxItems = $max; } public function setOrder($order) { $this->order = $order; } public function setBlank($blank) { $this->blank = $blank; } public function getMenu() { $menu = array(); if ($this->menuView != 0) { $menu['menuView'] = $this->menuView; } if ($this->menuListFeeds != 0) { $menu['menuListFeeds'] = $this->menuListFeeds; } if ($this->menuFilter != 0) { $menu['menuFilter'] = $this->menuFilter; } if ($this->menuOrder != 0) { $menu['menuOrder'] = $this->menuOrder; } if ($this->menuUpdate != 0) { $menu['menuUpdate'] = $this->menuUpdate; } if ($this->menuRead != 0) { $menu['menuRead'] = $this->menuRead; } if ($this->menuUnread != 0) { $menu['menuUnread'] = $this->menuUnread; } if ($this->menuEdit != 0) { $menu['menuEdit'] = $this->menuEdit; } if ($this->menuAdd != 0) { $menu['menuAdd'] = $this->menuAdd; } if ($this->menuHelp != 0) { $menu['menuHelp'] = $this->menuHelp; } if ($this->menuStars != 0) { $menu['menuStars'] = $this->menuStars; } asort($menu); return $menu; } public function getPaging() { $paging = array(); if ($this->pagingItem != 0) { $paging['pagingItem'] = $this->pagingItem; } if ($this->pagingPage != 0) { $paging['pagingPage'] = $this->pagingPage; } if ($this->pagingByPage != 0) { $paging['pagingByPage'] = $this->pagingByPage; } if ($this->pagingMarkAs != 0) { $paging['pagingMarkAs'] = $this->pagingMarkAs; } asort($paging); return $paging; } public function setMenuView($menuView) { $this->menuView = $menuView; } public function setMenuListFeeds($menuListFeeds) { $this->menuListFeeds = $menuListFeeds; } public function setMenuFilter($menuFilter) { $this->menuFilter = $menuFilter; } public function setMenuOrder($menuOrder) { $this->menuOrder = $menuOrder; } public function setMenuUpdate($menuUpdate) { $this->menuUpdate = $menuUpdate; } public function setMenuRead($menuRead) { $this->menuRead = $menuRead; } public function setMenuUnread($menuUnread) { $this->menuUnread = $menuUnread; } public function setMenuEdit($menuEdit) { $this->menuEdit = $menuEdit; } public function setMenuAdd($menuAdd) { $this->menuAdd = $menuAdd; } public function setMenuHelp($menuHelp) { $this->menuHelp = $menuHelp; } public function setMenuStars($menuStars) { $this->menuStars = $menuStars; } public function setPagingItem($pagingItem) { $this->pagingItem = $pagingItem; } public function setPagingPage($pagingPage) { $this->pagingPage = $pagingPage; } public function setPagingByPage($pagingByPage) { $this->pagingByPage = $pagingByPage; } public function setPagingMarkAs($pagingMarkAs) { $this->pagingMarkAs = $pagingMarkAs; } public function isLogged() { global $argv; if (Session::isLogged() || $this->visibility === 'public' || (isset($_GET['cron']) && $_GET['cron'] === sha1($this->salt.$this->hash)) || (isset($argv) && count($argv) >= 3 && $argv[1] == 'update' && $argv[2] == sha1($this->salt.$this->hash))) { return true; } return false; } public function write() { if ($this->isLogged() || !is_file($this->_file)) { $data = array('login', 'hash', 'salt', 'title', 'redirector', 'shaarli', 'byPage', 'order', 'visibility', 'filter', 'view','tpl','locale', 'maxItems', 'autoreadItem', 'autoreadPage', 'maxUpdate', 'autohide', 'autofocus', 'listFeeds', 'autoUpdate', 'menuView', 'menuListFeeds', 'menuFilter', 'menuOrder', 'menuUpdate', 'menuRead', 'menuUnread', 'menuEdit', 'menuAdd', 'menuHelp', 'menuStars', 'pagingItem', 'pagingPage', 'pagingByPage', 'addFavicon', 'pagingMarkAs', 'disableSessionProtection', 'blank'); $out = ''.$key.' = '.var_export($this->$key, true).";\n"; } $out .= '?>'; if (!@file_put_contents($this->_file, $out)) { die("Can't write to ".CONFIG_FILE." check permissions"); } } } } class altFeedPage { public static $var = array(); private static $_instance; public static function init($var) { altFeedPage::$var = $var; } public static function includesTpl() { extract(altFeedPage::$var); ?>
$1', '/\[code\](.+?)\[\/code\]/is' => '
$1
',
'/\[([^[]+)\|([^[]+)\]/is'
=> '$1'
);
$text = preg_replace(
array_keys($replace),
array_values($replace),
$text
);
return $text;
}
public static function formatText($text)
{
$text = preg_replace_callback(
'/