Run php-cs-fixer on the code base

master
Frederic Guillot 6 years ago
parent 427b41f892
commit aaaafb263b
  1. 8
      controllers/bookmark.php
  2. 14
      controllers/common.php
  3. 46
      controllers/config.php
  4. 4
      controllers/console.php
  5. 62
      controllers/feed.php
  6. 6
      controllers/history.php
  7. 31
      controllers/item.php
  8. 6
      controllers/user.php
  9. 55
      fever/index.php
  10. 2
      lib/Request.php
  11. 11
      lib/Response.php
  12. 26
      lib/Router.php
  13. 4
      lib/Session.php
  14. 1
      lib/Template.php
  15. 21
      lib/Translator.php
  16. 42
      lib/helpers.php
  17. 431
      lib/password.php
  18. 51
      models/auto_update.php
  19. 39
      models/config.php
  20. 8
      models/database.php
  21. 14
      models/favicon.php
  22. 7
      models/feed.php
  23. 7
      models/group.php
  24. 36
      models/item.php
  25. 5
      models/proxy.php
  26. 3
      models/remember_me.php
  27. 6
      models/schema.php
  28. 3
      models/service.php
  29. 5
      models/user.php
  30. 13
      tests/integration/keyboardShortcutsTest.php
  31. 102
      tests/integration/minifluxTestCase.php
  32. 12
      tests/integration/pageBookmarksTest.php
  33. 17
      tests/integration/pageFirstFeedTest.php
  34. 14
      tests/integration/pageHistoryTest.php
  35. 5
      tests/integration/pageSubscriptionTest.php
  36. 19
      tests/integration/pageUnreadTest.php

@ -4,7 +4,7 @@ use PicoFeed\Syndication\AtomFeedBuilder;
use PicoFeed\Syndication\AtomItemBuilder;
// Ajax call to add or remove a bookmark
Router\post_action('bookmark', function() {
Router\post_action('bookmark', function () {
$id = Request\param('id');
$value = Request\int_param('value');
@ -16,7 +16,7 @@ Router\post_action('bookmark', function() {
});
// Add new bookmark
Router\get_action('bookmark', function() {
Router\get_action('bookmark', function () {
$id = Request\param('id');
$menu = Request\param('menu', 'unread');
$source = Request\param('source', 'unread');
@ -33,7 +33,7 @@ Router\get_action('bookmark', function() {
});
// Display bookmarks page
Router\get_action('bookmarks', function() {
Router\get_action('bookmarks', function () {
$offset = Request\int_param('offset', 0);
$group_id = Request\int_param('group_id', null);
$feed_ids = array();
@ -70,7 +70,7 @@ Router\get_action('bookmarks', function() {
});
// Display bookmark feeds
Router\get_action('bookmark-feed', function() {
Router\get_action('bookmark-feed', function () {
// Select database if the parameter is set
$database = Request\param('database');

@ -1,7 +1,7 @@
<?php
// Called before each action
Router\before(function($action) {
Router\before(function ($action) {
Session\open(BASE_URL_DIRECTORY, SESSION_SAVE_PATH, 0);
// Select the requested database either from post param database or from the
@ -10,8 +10,7 @@ Router\before(function($action) {
if (! is_null(Request\value('database')) && ! Model\Database\select(Request\value('database'))) {
Model\User\logout();
Response\redirect('?action=login');
}
elseif (! empty($_SESSION['database'])) {
} elseif (! empty($_SESSION['database'])) {
if (! Model\Database\select($_SESSION['database'])) {
Model\User\logout();
Response\redirect('?action=login');
@ -26,8 +25,7 @@ Router\before(function($action) {
Model\User\logout();
Response\redirect('?action=login');
}
}
elseif (Model\RememberMe\has_cookie()) {
} elseif (Model\RememberMe\has_cookie()) {
Model\RememberMe\refresh();
}
@ -56,17 +54,17 @@ Router\before(function($action) {
});
// Show help
Router\get_action('show-help', function() {
Router\get_action('show-help', function () {
Response\html(Template\load('show_help'));
});
// Show the menu for the mobile view
Router\get_action('more', function() {
Router\get_action('more', function () {
Response\html(Template\layout('show_more', array('menu' => 'more')));
});
// Image proxy (avoid SSL mixed content warnings)
Router\get_action('proxy', function() {
Router\get_action('proxy', function () {
Model\Proxy\download(rawurldecode(Request\param('url')));
exit;
});

@ -3,7 +3,7 @@
use PicoDb\Database;
// Display a form to add a new database
Router\get_action('new-db', function() {
Router\get_action('new-db', function () {
if (ENABLE_MULTIPLE_DB) {
Response\html(Template\layout('new_db', array(
'errors' => array(),
@ -20,18 +20,16 @@ Router\get_action('new-db', function() {
});
// Create a new database
Router\post_action('new-db', function() {
Router\post_action('new-db', function () {
if (ENABLE_MULTIPLE_DB) {
$values = Request\values();
Model\Config\check_csrf_values($values);
list($valid, $errors) = Model\Database\validate($values);
if ($valid) {
if (Model\Database\create(strtolower($values['name']).'.sqlite', $values['username'], $values['password'])) {
Session\flash(t('Database created successfully.'));
}
else {
} else {
Session\flash_error(t('Unable to create the new database.'));
}
@ -51,7 +49,7 @@ Router\post_action('new-db', function() {
});
// Confirmation box before auto-update
Router\get_action('confirm-auto-update', function() {
Router\get_action('confirm-auto-update', function () {
Response\html(Template\layout('confirm_auto_update', array(
'nb_unread_items' => Model\Item\count_by_status('unread'),
'menu' => 'config',
@ -60,7 +58,7 @@ Router\get_action('confirm-auto-update', function() {
});
// Auto-update
Router\get_action('auto-update', function() {
Router\get_action('auto-update', function () {
if (ENABLE_AUTO_UPDATE) {
if (Model\AutoUpdate\execute(Model\Config\get('auto_update_url'))) {
Session\flash(t('Miniflux is updated!'));
@ -73,7 +71,7 @@ Router\get_action('auto-update', function() {
});
// Re-generate tokens
Router\get_action('generate-tokens', function() {
Router\get_action('generate-tokens', function () {
if (Model\Config\check_csrf(Request\param('csrf'))) {
Model\Config\new_tokens();
}
@ -82,7 +80,7 @@ Router\get_action('generate-tokens', function() {
});
// Optimize the database manually
Router\get_action('optimize-db', function() {
Router\get_action('optimize-db', function () {
if (Model\Config\check_csrf(Request\param('csrf'))) {
Database::getInstance('db')->getConnection()->exec('VACUUM');
}
@ -91,7 +89,7 @@ Router\get_action('optimize-db', function() {
});
// Download the compressed database
Router\get_action('download-db', function() {
Router\get_action('download-db', function () {
if (Model\Config\check_csrf(Request\param('csrf'))) {
Response\force_download('db.sqlite.gz');
Response\binary(gzencode(file_get_contents(Model\Database\get_path())));
@ -99,7 +97,7 @@ Router\get_action('download-db', function() {
});
// Display preferences page
Router\get_action('config', function() {
Router\get_action('config', function () {
Response\html(Template\layout('config', array(
'errors' => array(),
'values' => Model\Config\get_all() + array('csrf' => Model\Config\generate_csrf()),
@ -120,17 +118,15 @@ Router\get_action('config', function() {
});
// Update preferences
Router\post_action('config', function() {
Router\post_action('config', function () {
$values = Request\values() + array('nocontent' => 0, 'image_proxy' => 0, 'favicons' => 0, 'debug_mode' => 0, 'original_marks_read' => 0);
Model\Config\check_csrf_values($values);
list($valid, $errors) = Model\Config\validate_modification($values);
if ($valid) {
if (Model\Config\save($values)) {
Session\flash(t('Your preferences are updated.'));
}
else {
} else {
Session\flash_error(t('Unable to update your preferences.'));
}
@ -157,14 +153,13 @@ Router\post_action('config', function() {
});
// Get configuration parameters (AJAX request)
Router\post_action('get-config', function() {
Router\post_action('get-config', function () {
$return = array();
$options = Request\values();
if (empty($options)) {
$return = Model\Config\get_all();
}
else {
} else {
foreach ($options as $name) {
$return[$name] = Model\Config\get($name);
}
@ -174,7 +169,7 @@ Router\post_action('get-config', function() {
});
// Display help page
Router\get_action('help', function() {
Router\get_action('help', function () {
Response\html(Template\layout('help', array(
'config' => Model\Config\get_all(),
'nb_unread_items' => Model\Item\count_by_status('unread'),
@ -184,7 +179,7 @@ Router\get_action('help', function() {
});
// Display about page
Router\get_action('about', function() {
Router\get_action('about', function () {
Response\html(Template\layout('about', array(
'csrf' => Model\Config\generate_csrf(),
'config' => Model\Config\get_all(),
@ -196,7 +191,7 @@ Router\get_action('about', function() {
});
// Display database page
Router\get_action('database', function() {
Router\get_action('database', function () {
Response\html(Template\layout('database', array(
'csrf' => Model\Config\generate_csrf(),
'config' => Model\Config\get_all(),
@ -208,7 +203,7 @@ Router\get_action('database', function() {
});
// Display API page
Router\get_action('api', function() {
Router\get_action('api', function () {
Response\html(Template\layout('api', array(
'config' => Model\Config\get_all(),
'nb_unread_items' => Model\Item\count_by_status('unread'),
@ -218,7 +213,7 @@ Router\get_action('api', function() {
});
// Display bookmark services page
Router\get_action('services', function() {
Router\get_action('services', function () {
Response\html(Template\layout('services', array(
'errors' => array(),
'values' => Model\Config\get_all() + array('csrf' => Model\Config\generate_csrf()),
@ -228,14 +223,13 @@ Router\get_action('services', function() {
});
// Update bookmark services
Router\post_action('services', function() {
Router\post_action('services', function () {
$values = Request\values() + array('pinboard_enabled' => 0, 'instapaper_enabled' => 0);
Model\Config\check_csrf_values($values);
if (Model\Config\save($values)) {
Session\flash(t('Your preferences are updated.'));
}
else {
} else {
Session\flash_error(t('Unable to update your preferences.'));
}

@ -1,13 +1,13 @@
<?php
// Flush console messages
Router\get_action('flush-console', function() {
Router\get_action('flush-console', function () {
@unlink(DEBUG_FILENAME);
Response\redirect('?action=console');
});
// Display console
Router\get_action('console', function() {
Router\get_action('console', function () {
Response\html(Template\layout('console', array(
'content' => @file_get_contents(DEBUG_FILENAME),
'nb_unread_items' => Model\Item\count_by_status('unread'),

@ -3,14 +3,14 @@
use PicoFeed\Parser\MalformedXmlException;
// Refresh all feeds, used when Javascript is disabled
Router\get_action('refresh-all', function() {
Router\get_action('refresh-all', function () {
Model\Feed\refresh_all();
Session\flash(t('Your subscriptions are updated'));
Response\redirect('?action=unread');
});
// Edit feed form
Router\get_action('edit-feed', function() {
Router\get_action('edit-feed', function () {
$id = Request\int_param('feed_id');
$values = Model\Feed\get($id);
@ -29,7 +29,7 @@ Router\get_action('edit-feed', function() {
});
// Submit edit feed form
Router\post_action('edit-feed', function() {
Router\post_action('edit-feed', function () {
$values = Request\values();
$values += array(
'enabled' => 0,
@ -46,8 +46,7 @@ Router\post_action('edit-feed', function() {
if (Model\Feed\update($values)) {
Session\flash(t('Your subscription has been updated.'));
Response\redirect('?action=feeds');
}
else {
} else {
Session\flash_error(t('Unable to edit your subscription.'));
}
}
@ -63,7 +62,7 @@ Router\post_action('edit-feed', function() {
});
// Confirmation box to remove a feed
Router\get_action('confirm-remove-feed', function() {
Router\get_action('confirm-remove-feed', function () {
$id = Request\int_param('feed_id');
Response\html(Template\layout('confirm_remove_feed', array(
@ -75,13 +74,12 @@ Router\get_action('confirm-remove-feed', function() {
});
// Remove a feed
Router\get_action('remove-feed', function() {
Router\get_action('remove-feed', function () {
$id = Request\int_param('feed_id');
if ($id && Model\Feed\remove($id)) {
Session\flash(t('This subscription has been removed successfully.'));
}
else {
} else {
Session\flash_error(t('Unable to remove this subscription.'));
}
@ -89,7 +87,7 @@ Router\get_action('remove-feed', function() {
});
// Refresh one feed and redirect to unread items
Router\get_action('refresh-feed', function() {
Router\get_action('refresh-feed', function () {
$feed_id = Request\int_param('feed_id');
$redirect = Request\param('redirect', 'unread');
@ -98,7 +96,7 @@ Router\get_action('refresh-feed', function() {
});
// Ajax call to refresh one feed
Router\post_action('refresh-feed', function() {
Router\post_action('refresh-feed', function () {
$feed_id = Request\int_param('feed_id', 0);
Response\json(array(
@ -109,7 +107,7 @@ Router\post_action('refresh-feed', function() {
});
// Display all feeds
Router\get_action('feeds', function() {
Router\get_action('feeds', function () {
$nothing_to_read = Request\int_param('nothing_to_read');
$nb_unread_items = Model\Item\count_by_status('unread');
@ -130,7 +128,7 @@ Router\get_action('feeds', function() {
});
// Display form to add one feed
Router\get_action('add', function() {
Router\get_action('add', function () {
$values = array(
'download_content' => 0,
'rtl' => 0,
@ -150,7 +148,7 @@ Router\get_action('add', function() {
});
// Add a feed with the form or directly from the url, it can be used by a bookmarklet by example
Router\action('subscribe', function() {
Router\action('subscribe', function () {
if (Request\is_post()) {
$values = Request\values();
Model\Config\check_csrf_values($values);
@ -183,34 +181,25 @@ Router\action('subscribe', function() {
$values['feed_group_ids'],
$values['create_group']
);
}
catch (UnexpectedValueException $e) {
} catch (UnexpectedValueException $e) {
$error_message = t('This subscription already exists.');
}
catch (PicoFeed\Client\InvalidCertificateException $e) {
} catch (PicoFeed\Client\InvalidCertificateException $e) {
$error_message = t('Invalid SSL certificate.');
}
catch (PicoFeed\Client\InvalidUrlException $e) {
} catch (PicoFeed\Client\InvalidUrlException $e) {
// picoFeed uses this exception for multiple reasons, but doesn't
// provide an exception code to distinguish what exactly happend here
$error_message = $e->getMessage();
}
catch (PicoFeed\Client\MaxRedirectException $e) {
} catch (PicoFeed\Client\MaxRedirectException $e) {
$error_message = t('Maximum number of HTTP redirections exceeded.');
}
catch (PicoFeed\Client\MaxSizeException $e) {
} catch (PicoFeed\Client\MaxSizeException $e) {
$error_message = t('The content size exceeds to maximum allowed size.');
}
catch (PicoFeed\Client\TimeoutException $e) {
} catch (PicoFeed\Client\TimeoutException $e) {
$error_message = t('Connection timeout.');
}
catch (PicoFeed\Parser\MalformedXmlException $e) {
} catch (PicoFeed\Parser\MalformedXmlException $e) {
$error_message = t('Feed is malformed.');
}
catch (PicoFeed\Reader\SubscriptionNotFoundException $e) {
} catch (PicoFeed\Reader\SubscriptionNotFoundException $e) {
$error_message = t('Unable to find a subscription.');
}
catch (PicoFeed\Reader\UnsupportedFeedFormatException $e) {
} catch (PicoFeed\Reader\UnsupportedFeedFormatException $e) {
$error_message = t('Unable to detect the feed format.');
}
@ -219,8 +208,7 @@ Router\action('subscribe', function() {
if (isset($feed_id) && $feed_id !== false) {
Session\flash(t('Subscription added successfully.'));
Response\redirect('?action=feed-items&feed_id='.$feed_id);
}
else {
} else {
if (! isset($error_message)) {
$error_message = t('Error occured.');
}
@ -238,13 +226,13 @@ Router\action('subscribe', function() {
});
// OPML export
Router\get_action('export', function() {
Router\get_action('export', function () {
Response\force_download('feeds.opml');
Response\xml(Model\Feed\export_opml());
});
// OPML import form
Router\get_action('import', function() {
Router\get_action('import', function () {
Response\html(Template\layout('import', array(
'errors' => array(),
'nb_unread_items' => Model\Item\count_by_status('unread'),
@ -254,7 +242,7 @@ Router\get_action('import', function() {
});
// OPML importation
Router\post_action('import', function() {
Router\post_action('import', function () {
try {
Model\Feed\import_opml(Request\file_content('file'));
Session\flash(t('Your feeds have been imported.'));

@ -1,7 +1,7 @@
<?php
// Display history page
Router\get_action('history', function() {
Router\get_action('history', function () {
$offset = Request\int_param('offset', 0);
$group_id = Request\int_param('group_id', null);
$feed_ids = array();
@ -42,7 +42,7 @@ Router\get_action('history', function() {
});
// Confirmation box to flush history
Router\get_action('confirm-flush-history', function() {
Router\get_action('confirm-flush-history', function () {
$group_id = Request\int_param('group_id', null);
Response\html(Template\layout('confirm_flush_items', array(
@ -54,7 +54,7 @@ Router\get_action('confirm-flush-history', function() {
});
// Flush history
Router\get_action('flush-history', function() {
Router\get_action('flush-history', function () {
$group_id = Request\int_param('group_id', null);
if (!is_null($group_id)) {

@ -1,7 +1,7 @@
<?php
// Display unread items
Router\get_action('unread', function() {
Router\get_action('unread', function () {
Model\Item\autoflush_read();
Model\Item\autoflush_unread();
@ -52,7 +52,7 @@ Router\get_action('unread', function() {
});
// Show item
Router\get_action('show', function() {
Router\get_action('show', function () {
$id = Request\param('id');
$menu = Request\param('menu');
$item = Model\Item\get($id);
@ -98,7 +98,7 @@ Router\get_action('show', function() {
});
// Display feed items page
Router\get_action('feed-items', function() {
Router\get_action('feed-items', function () {
$feed_id = Request\int_param('feed_id', 0);
$offset = Request\int_param('offset', 0);
$nb_items = Model\Item\count_by_feed($feed_id);
@ -126,7 +126,7 @@ Router\get_action('feed-items', function() {
});
// Ajax call to download an item (fetch the full content from the original website)
Router\post_action('download-item', function() {
Router\post_action('download-item', function () {
$id = Request\param('id');
$item = Model\Item\get($id);
@ -139,31 +139,30 @@ Router\post_action('download-item', function() {
});
// Ajax call to mark item read
Router\post_action('mark-item-read', function() {
Router\post_action('mark-item-read', function () {
Model\Item\set_read(Request\param('id'));
Response\json(array('Ok'));
});
// Ajax call to mark item as removed
Router\post_action('mark-item-removed', function() {
Router\post_action('mark-item-removed', function () {
Model\Item\set_removed(Request\param('id'));
Response\json(array('Ok'));
});
// Ajax call to mark item unread
Router\post_action('mark-item-unread', function() {
Router\post_action('mark-item-unread', function () {
Model\Item\set_unread(Request\param('id'));
Response\json(array('Ok'));
});
// Mark unread items as read
Router\get_action('mark-all-read', function() {
Router\get_action('mark-all-read', function () {
$group_id = Request\int_param('group_id', null);
if (!is_null($group_id)) {
Model\Item\mark_group_as_read($group_id);
}
else {
} else {
Model\Item\mark_all_as_read();
}
@ -171,7 +170,7 @@ Router\get_action('mark-all-read', function() {
});
// Mark all unread items as read for a specific feed
Router\get_action('mark-feed-as-read', function() {
Router\get_action('mark-feed-as-read', function () {
$feed_id = Request\int_param('feed_id');
Model\Item\mark_feed_as_read($feed_id);
@ -182,7 +181,7 @@ Router\get_action('mark-feed-as-read', function() {
// the number of unread items. It's not possible to get the number of items
// that where marked read from the frontend, since the number of unread items
// on page 2+ is unknown.
Router\post_action('mark-feed-as-read', function() {
Router\post_action('mark-feed-as-read', function () {
Model\Item\mark_feed_as_read(Request\int_param('feed_id'));
$nb_items = Model\Item\count_by_status('unread');
@ -190,7 +189,7 @@ Router\post_action('mark-feed-as-read', function() {
});
// Mark item as read and redirect to the listing page
Router\get_action('mark-item-read', function() {
Router\get_action('mark-item-read', function () {
$id = Request\param('id');
$redirect = Request\param('redirect', 'unread');
$offset = Request\int_param('offset', 0);
@ -201,7 +200,7 @@ Router\get_action('mark-item-read', function() {
});
// Mark item as unread and redirect to the listing page
Router\get_action('mark-item-unread', function() {
Router\get_action('mark-item-unread', function () {
$id = Request\param('id');
$redirect = Request\param('redirect', 'history');
$offset = Request\int_param('offset', 0);
@ -212,7 +211,7 @@ Router\get_action('mark-item-unread', function() {
});
// Mark item as removed and redirect to the listing page
Router\get_action('mark-item-removed', function() {
Router\get_action('mark-item-removed', function () {
$id = Request\param('id');
$redirect = Request\param('redirect', 'history');
$offset = Request\int_param('offset', 0);
@ -222,7 +221,7 @@ Router\get_action('mark-item-removed', function() {
Response\redirect('?action='.$redirect.'&offset='.$offset.'&feed_id='.$feed_id);
});
Router\post_action('latest-feeds-items', function() {
Router\post_action('latest-feeds-items', function () {
$items = Model\Item\get_latest_feeds_items();
$nb_unread_items = Model\Item\count_by_status('unread');

@ -1,13 +1,13 @@
<?php
// Logout and destroy session
Router\get_action('logout', function() {
Router\get_action('logout', function () {
Model\User\logout();
Response\redirect('?action=login');
});
// Display form login
Router\get_action('login', function() {
Router\get_action('login', function () {
if (Model\User\is_loggedin()) {
Response\redirect('?action=unread');
}
@ -23,7 +23,7 @@ Router\get_action('login', function() {
});
// Check credentials and redirect to unread items
Router\post_action('login', function() {
Router\post_action('login', function () {
$values = Request\values();
Model\Config\check_csrf_values($values);
list($valid, $errors) = Model\User\validate_login($values);

@ -14,8 +14,7 @@ function route($name, Closure $callback = null)
if ($callback !== null) {
$routes[$name] = $callback;
}
else if (isset($routes[$name])) {
} elseif (isset($routes[$name])) {
$routes[$name]();
}
}
@ -46,7 +45,7 @@ function auth()
$response = array(
'api_version' => 3,
'auth' => (int) (isset($_POST['api_key']) && (strcasecmp($_POST['api_key'], $api_key) === 0 )),
'auth' => (int) (isset($_POST['api_key']) && (strcasecmp($_POST['api_key'], $api_key) === 0)),
'last_refreshed_on_time' => time(),
);
@ -54,12 +53,11 @@ function auth()
}
// Call: ?api&groups
route('groups', function() {
route('groups', function () {
$response = auth();
if ($response['auth']) {
$response['groups'] = Group\get_all();
$response['feeds_groups'] = array();
$group_map = Group\get_map();
@ -76,12 +74,11 @@ route('groups', function() {
});
// Call: ?api&feeds
route('feeds', function() {
route('feeds', function () {
$response = auth();
if ($response['auth']) {
$response['feeds'] = array();
$response['feeds_groups'] = array();
@ -112,12 +109,11 @@ route('feeds', function() {
});
// Call: ?api&favicons
route('favicons', function() {
route('favicons', function () {
$response = auth();
if ($response['auth']) {
$favicons = Database::getInstance('db')
->table('favicons')
->columns(
@ -140,12 +136,11 @@ route('favicons', function() {
});
// Call: ?api&items
route('items', function() {
route('items', function () {
$response = auth();
if ($response['auth']) {
$query = Database::getInstance('db')
->table('items')
->columns(
@ -163,11 +158,9 @@ route('items', function() {
->neq('status', 'removed');
if (isset($_GET['since_id']) && is_numeric($_GET['since_id'])) {
$items = $query->gt('rowid', $_GET['since_id'])
->asc('rowid');
}
else if (! empty($_GET['with_ids'])) {
} elseif (! empty($_GET['with_ids'])) {
$query->in('rowid', explode(',', $_GET['with_ids']));
}
@ -198,7 +191,7 @@ route('items', function() {
});
// Call: ?api&links
route('links', function() {
route('links', function () {
$response = auth();
@ -210,12 +203,11 @@ route('links', function() {
});
// Call: ?api&unread_item_ids
route('unread_item_ids', function() {
route('unread_item_ids', function () {
$response = auth();
if ($response['auth']) {
$item_ids = Database::getInstance('db')
->table('items')
->eq('status', 'unread')
@ -228,12 +220,11 @@ route('unread_item_ids', function() {
});
// Call: ?api&saved_item_ids
route('saved_item_ids', function() {
route('saved_item_ids', function () {
$response = auth();
if ($response['auth']) {
$item_ids = Database::getInstance('db')
->table('items')
->eq('bookmark', 1)
@ -246,12 +237,11 @@ route('saved_item_ids', function() {
});
// handle write items
route('write_items', function() {
route('write_items', function () {
$response = auth();
if ($response['auth']) {
$query = Database::getInstance('db')
->table('items')
->eq('rowid', $_POST['id']);
@ -266,14 +256,11 @@ route('write_items', function() {
->findOneColumn('id');
Service\push($item_id);
}
else if ($_POST['as'] === 'unsaved') {
} elseif ($_POST['as'] === 'unsaved') {
$query->update(array('bookmark' => 0));
}
else if ($_POST['as'] === 'read') {
} elseif ($_POST['as'] === 'read') {
$query->update(array('status' => 'read'));
}
else if ($_POST['as'] === 'unread') {
} elseif ($_POST['as'] === 'unread') {
$query->update(array('status' => 'unread'));
}
}
@ -282,12 +269,11 @@ route('write_items', function() {
});
// handle write feeds
route('write_feeds', function() {
route('write_feeds', function () {
$response = auth();
if ($response['auth']) {
Database::getInstance('db')
->table('items')
->eq('feed_id', $_POST['id'])
@ -299,7 +285,7 @@ route('write_feeds', function() {
});
// handle write groups
route('write_groups', function() {
route('write_groups', function () {
$response = auth();
@ -323,15 +309,12 @@ foreach (array_keys($_GET) as $action) {
}
if (! empty($_POST['mark']) && ! empty($_POST['as'])
&& ! is_null(filter_input(INPUT_POST, 'id', FILTER_VALIDATE_INT, array('options' => array('default' => NULL,'min_range' => -1)))) ){
&& ! is_null(filter_input(INPUT_POST, 'id', FILTER_VALIDATE_INT, array('options' => array('default' => null, 'min_range' => -1))))) {
if ($_POST['mark'] === 'item') {
route('write_items');
}
else if ($_POST['mark'] === 'feed' && ! empty($_POST['before'])) {
} elseif ($_POST['mark'] === 'feed' && ! empty($_POST['before'])) {
route('write_feeds');
}
else if ($_POST['mark'] === 'group' && ! empty($_POST['before'])) {
} elseif ($_POST['mark'] === 'group' && ! empty($_POST['before'])) {
route('write_groups');
}
}

@ -2,7 +2,6 @@
namespace Request;
function param($name, $default_value = null)
{
return isset($_GET[$name]) ? $_GET[$name] : $default_value;
@ -25,7 +24,6 @@ function value($name)
function values()
{
if (! empty($_POST)) {
return $_POST;
}

@ -2,7 +2,6 @@
namespace Response;
function force_download($filename)
{
header('Content-Disposition: attachment; filename="'.$filename.'"');
@ -21,8 +20,7 @@ function status($status_code)
if (strpos($sapi_name, 'apache') !== false || $sapi_name === 'cli-server') {
header('HTTP/1.0 '.$status_code);
}
else {
} else {
header('Status: '.$status_code);
}
}
@ -116,20 +114,15 @@ function csp(array $policies = array())
$values = '';
foreach ($policies as $policy => $hosts) {
if (is_array($hosts)) {
$acl = '';
foreach ($hosts as &$host) {
if ($host === '*' || $host === "'self'" || strpos($host, 'http') === 0) {
$acl .= $host.' ';
}
}
}
else {
} else {
$acl = $hosts;
}

@ -20,8 +20,7 @@ function before($value = null)
if (is_callable($value)) {
$before_callback = $value;
}
else if (is_callable($before_callback)) {
} elseif (is_callable($before_callback)) {
$before_callback($value);
}
}
@ -33,8 +32,7 @@ function before_action($name, $value = null)
if (is_callable($value)) {
$callbacks[$name] = $value;
}
else if (isset($callbacks[$name]) && is_callable($callbacks[$name])) {
} elseif (isset($callbacks[$name]) && is_callable($callbacks[$name])) {
$callbacks[$name]($value);
}
}
@ -103,18 +101,15 @@ function delete($url, \Closure $callback)
function find_route($method, $route, \Closure $callback)
{
if ($_SERVER['REQUEST_METHOD'] === $method) {
if (! empty($_SERVER['QUERY_STRING'])) {
$url = substr($_SERVER['REQUEST_URI'], 0, -(strlen($_SERVER['QUERY_STRING']) + 1));
}
else {
} else {
$url = $_SERVER['REQUEST_URI'];
}
$params = array();
if (url_match($route, $url, $params)) {
before($route);
\call_user_func_array($callback, $params);
exit;
@ -125,8 +120,12 @@ function find_route($method, $route, \Closure $callback)
// Parse url and find matches
function url_match($route_uri, $request_uri, array &$params)
{
if ($request_uri === $route_uri) return true;
if ($route_uri === '/' || $request_uri === '/') return false;
if ($request_uri === $route_uri) {
return true;
}
if ($route_uri === '/' || $request_uri === '/') {
return false;
}
$route_uri = trim($route_uri, '/');
$request_uri = trim($request_uri, '/');
@ -136,15 +135,10 @@ function url_match($route_uri, $request_uri, array &$params)
$nb_route_items = count($route_items);
if ($nb_route_items === count($request_items)) {
for ($i = 0; $i < $nb_route_items; ++$i) {
if ($route_items[$i][0] === ':') {
$params[substr($route_items[$i], 1)] = $request_items[$i];
}
else if ($route_items[$i] !== $request_items[$i]) {
} elseif ($route_items[$i] !== $request_items[$i]) {
$params = array();
return false;
}

@ -7,7 +7,9 @@ const SESSION_LIFETIME = 2678400;
function open($base_path = '/', $save_path = '', $session_lifetime = SESSION_LIFETIME)
{
if ($save_path !== '') session_save_path($save_path);
if ($save_path !== '') {
session_save_path($save_path);
}
// HttpOnly and secure flags for session cookie
session_set_cookie_params(

@ -16,7 +16,6 @@ function load()
}
if (func_num_args() === 2) {
if (! is_array(func_get_arg(1))) {
die('Template variables must be an array');
}

@ -55,14 +55,12 @@ namespace Translator {
$str = '';
if ($position === 'before') {
$str .= $symbol;
}
$str .= number($amount);
if ($position === 'after') {
$str .= ' '.$symbol;
}
@ -89,8 +87,7 @@ namespace Translator {
if (isset($locales[$identifier])) {
if (is_array($locales[$identifier])) {
$translation = plural($identifier, $default, $values);
}
else {
} else {
$translation = $locales[$identifier];
}
}
@ -129,7 +126,6 @@ namespace Translator {
$locales = array();
if (is_dir($path)) {
$dir = new \DirectoryIterator($path);
foreach ($dir as $fileinfo) {
@ -157,23 +153,28 @@ namespace Translator {
namespace {
function tne() {
function tne()
{
return call_user_func_array('\Translator\translate_no_escaping', func_get_args());
}
function t() {
function t()
{
return call_user_func_array('\Translator\translate', func_get_args());
}
function c() {
function c()
{
return call_user_func_array('\Translator\currency', func_get_args());
}
function n() {
function n()
{
return call_user_func_array('\Translator\number', func_get_args());
}
function dt() {
function dt()
{
return call_user_func_array('\Translator\datetime', func_get_args());
}
}

@ -68,7 +68,6 @@ function css()
$theme = \Model\Config\get('theme');
if ($theme !== 'original') {
$css_file = THEME_DIRECTORY.'/'.$theme.'/css/app.css';
if (file_exists($css_file)) {
@ -129,8 +128,7 @@ function summary($value, $min_length = 5, $max_length = 120, $end = '[...]')
$max = $max_length;
}
return substr($value, 0, $max).' '.$end;
}
else if ($length < $min_length) {
} elseif ($length < $min_length) {
return '';
}
@ -150,24 +148,38 @@ function relative_time($timestamp, $fallback_date_format = '%e %B %Y %k:%M')
{
$diff = time() - $timestamp;
if ($diff < 0) return \dt($fallback_date_format, $timestamp);
if ($diff < 0) {
return \dt($fallback_date_format, $timestamp);
}
if ($diff < 60) return \t('%d second ago', $diff);
if ($diff < 60) {
return \t('%d second ago', $diff);
}
$diff = floor($diff / 60);
if ($diff < 60) return \t('%d minute ago', $diff);
if ($diff < 60) {
return \t('%d minute ago', $diff);
}
$diff = floor($diff / 60);
if ($diff < 24) return \t('%d hour ago', $diff);
if ($diff < 24) {
return \t('%d hour ago', $diff);
}
$diff = floor($diff / 24);
if ($diff < 7) return \t('%d day ago', $diff);
if ($diff < 7) {
return \t('%d day ago', $diff);
}
$diff = floor($diff / 7);
if ($diff < 4) return \t('%d week ago', $diff);
if ($diff < 4) {
return \t('%d week ago', $diff);
}
$diff = floor($diff / 4);
if ($diff < 12) return \t('%d month ago', $diff);
if ($diff < 12) {
return \t('%d month ago', $diff);
}
return \dt($fallback_date_format, $timestamp);
}
@ -182,7 +194,6 @@ function error_list(array $errors, $name)
$html = '';
if (isset($errors[$name])) {
$html .= '<ul class="form-errors">';
foreach ($errors[$name] as $error) {
@ -220,11 +231,14 @@ function form_select($name, array $options, $values = array(), array $errors = a
$html = '<select name="'.$name.'" id="form-'.$name.'" class="'.$class.'">';
foreach ($options as $id => $value) {
$html .= '<option value="'.escape($id).'"';
if (isset($values->$name) && $id == $values->$name) $html .= ' selected="selected"';
if (isset($values[$name]) && $id == $values[$name]) $html .= ' selected="selected"';
if (isset($values->$name) && $id == $values->$name) {
$html .= ' selected="selected"';
}
if (isset($values[$name]) && $id == $values[$name]) {
$html .= ' selected="selected"';
}
$html .= '>'.escape($value).'</option>';
}

@ -8,220 +8,219 @@
*/
if (!defined('PASSWORD_BCRYPT')) {
define('PASSWORD_BCRYPT', 1);
define('PASSWORD_DEFAULT', PASSWORD_BCRYPT);
if (version_compare(PHP_VERSION, '5.3.7', '<')) {
define('PASSWORD_PREFIX', '$2a$');
}
else {
define('PASSWORD_PREFIX', '$2y$');
}
/**
* Hash the password using the specified algorithm
*
* @param string $password The password to hash
* @param int $algo The algorithm to use (Defined by PASSWORD_* constants)
* @param array $options The options for the algorithm to use
*
* @return string|false The hashed password, or false on error.
*/
function password_hash($password, $algo, array $options = array()) {
if (!function_exists('crypt')) {
trigger_error("Crypt must be loaded for password_hash to function", E_USER_WARNING);
return null;
}
if (!is_string($password)) {
trigger_error("password_hash(): Password must be a string", E_USER_WARNING);
return null;
}
if (!is_int($algo)) {
trigger_error("password_hash() expects parameter 2 to be long, " . gettype($algo) . " given", E_USER_WARNING);
return null;
}
switch ($algo) {
case PASSWORD_BCRYPT:
// Note that this is a C constant, but not exposed to PHP, so we don't define it here.
$cost = 10;
if (isset($options['cost'])) {
$cost = $options['cost'];
if ($cost < 4 || $cost > 31) {
trigger_error(sprintf("password_hash(): Invalid bcrypt cost parameter specified: %d", $cost), E_USER_WARNING);
return null;
}
}
$required_salt_len = 22;
$hash_format = sprintf("%s%02d$", PASSWORD_PREFIX, $cost);
break;
default:
trigger_error(sprintf("password_hash(): Unknown password hashing algorithm: %s", $algo), E_USER_WARNING);
return null;
}
if (isset($options['salt'])) {
switch (gettype($options['salt'])) {
case 'NULL':
case 'boolean':
case 'integer':
case 'double':
case 'string':
$salt = (string) $options['salt'];
break;
case 'object':
if (method_exists($options['salt'], '__tostring')) {
$salt = (string) $options['salt'];
break;
}
case 'array':
case 'resource':
default:
trigger_error('password_hash(): Non-string salt parameter supplied', E_USER_WARNING);
return null;
}
if (strlen($salt) < $required_salt_len) {
trigger_error(sprintf("password_hash(): Provided salt is too short: %d expecting %d", strlen($salt), $required_salt_len), E_USER_WARNING);
return null;
} elseif (0 == preg_match('#^[a-zA-Z0-9./]+$#D', $salt)) {
$salt = str_replace('+', '.', base64_encode($salt));
}
} else {
$buffer = '';
$raw_length = (int) ($required_salt_len * 3 / 4 + 1);
$buffer_valid = false;
if (function_exists('mcrypt_create_iv') && !defined('PHALANGER')) {
$buffer = mcrypt_create_iv($raw_length, MCRYPT_DEV_URANDOM);
if ($buffer) {
$buffer_valid = true;
}
}
if (!$buffer_valid && function_exists('openssl_random_pseudo_bytes')) {
$buffer = openssl_random_pseudo_bytes($raw_length);
if ($buffer) {
$buffer_valid = true;
}
}
if (!$buffer_valid && is_readable('/dev/urandom')) {
$f = fopen('/dev/urandom', 'r');
$read = strlen($buffer);
while ($read < $raw_length) {
$buffer .= fread($f, $raw_length - $read);
$read = strlen($buffer);
}
fclose($f);
if ($read >= $raw_length) {
$buffer_valid = true;
}
}
if (!$buffer_valid || strlen($buffer) < $raw_length) {
$bl = strlen($buffer);
for ($i = 0; $i < $raw_length; $i++) {
if ($i < $bl) {
$buffer[$i] = $buffer[$i] ^ chr(mt_rand(0, 255));
} else {
$buffer .= chr(mt_rand(0, 255));
}
}
}
$salt = str_replace('+', '.', base64_encode($buffer));
}
$salt = substr($salt, 0, $required_salt_len);
$hash = $hash_format . $salt;
$ret = crypt($password, $hash);
if (!is_string($ret) || strlen($ret) <= 13) {
return false;
}
return $ret;
}
/**
* Get information about the password hash. Returns an array of the information
* that was used to generate the password hash.
*
* array(
* 'algo' => 1,
* 'algoName' => 'bcrypt',
* 'options' => array(
* 'cost' => 10,
* ),
* )
*
* @param string $hash The password hash to extract info from
*
* @return array The array of information about the hash.
*/
function password_get_info($hash) {
$return = array(
'algo' => 0,
'algoName' => 'unknown',
'options' => array(),
);
if (substr($hash, 0, 4) == PASSWORD_PREFIX && strlen($hash) == 60) {
$return['algo'] = PASSWORD_BCRYPT;
$return['algoName'] = 'bcrypt';
list($cost) = sscanf($hash, PASSWORD_PREFIX."%d$");
$return['options']['cost'] = $cost;
}
return $return;
}
/**
* Determine if the password hash needs to be rehashed according to the options provided
*
* If the answer is true, after validating the password using password_verify, rehash it.
*
* @param string $hash The hash to test
* @param int $algo The algorithm used for new password hashes
* @param array $options The options array passed to password_hash
*
* @return boolean True if the password needs to be rehashed.
*/
function password_needs_rehash($hash, $algo, array $options = array()) {
$info = password_get_info($hash);
if ($info['algo'] != $algo) {
return true;
}
switch ($algo) {
case PASSWORD_BCRYPT:
$cost = isset($options['cost']) ? $options['cost'] : 10;
if ($cost != $info['options']['cost']) {
return true;
}
break;
}
return false;
}
/**
* Verify a password against a hash using a timing attack resistant approach
*
* @param string $password The password to verify
* @param string $hash The hash to verify against
*
* @return boolean If the password matches the hash
*/
function password_verify($password, $hash) {
if (!function_exists('crypt')) {
trigger_error("Crypt must be loaded for password_verify to function", E_USER_WARNING);
return false;
}
$ret = crypt($password, $hash);
if (!is_string($ret) || strlen($ret) != strlen($hash) || strlen($ret) <= 13) {
return false;
}
$status = 0;
for ($i = 0; $i < strlen($ret); $i++) {
$status |= (ord($ret[$i]) ^ ord($hash[$i]));
}
return $status === 0;
}
define('PASSWORD_BCRYPT', 1);
define('PASSWORD_DEFAULT', PASSWORD_BCRYPT);
if (version_compare(PHP_VERSION, '5.3.7', '<')) {
define('PASSWORD_PREFIX', '$2a$');
} else {
define('PASSWORD_PREFIX', '$2y$');
}