diff --git a/controllers/bookmark.php b/controllers/bookmark.php index b54fa33..f36456e 100644 --- a/controllers/bookmark.php +++ b/controllers/bookmark.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'); diff --git a/controllers/common.php b/controllers/common.php index f77db2e..8af9551 100644 --- a/controllers/common.php +++ b/controllers/common.php @@ -1,7 +1,7 @@ '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; }); diff --git a/controllers/config.php b/controllers/config.php index e6ce984..b48cd57 100644 --- a/controllers/config.php +++ b/controllers/config.php @@ -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.')); } diff --git a/controllers/console.php b/controllers/console.php index 74bbe25..ea362b0 100644 --- a/controllers/console.php +++ b/controllers/console.php @@ -1,13 +1,13 @@ @file_get_contents(DEBUG_FILENAME), 'nb_unread_items' => Model\Item\count_by_status('unread'), diff --git a/controllers/feed.php b/controllers/feed.php index 1bfcf62..7e80278 100644 --- a/controllers/feed.php +++ b/controllers/feed.php @@ -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.')); diff --git a/controllers/history.php b/controllers/history.php index c7a14d3..79a250a 100644 --- a/controllers/history.php +++ b/controllers/history.php @@ -1,7 +1,7 @@ 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'); } } diff --git a/lib/Request.php b/lib/Request.php index 13a8cad..af67d42 100644 --- a/lib/Request.php +++ b/lib/Request.php @@ -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; } diff --git a/lib/Response.php b/lib/Response.php index 43d5a85..b74db76 100644 --- a/lib/Response.php +++ b/lib/Response.php @@ -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; } diff --git a/lib/Router.php b/lib/Router.php index 812205f..090e1bc 100644 --- a/lib/Router.php +++ b/lib/Router.php @@ -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; } diff --git a/lib/Session.php b/lib/Session.php index 43a9ae9..1e77e75 100644 --- a/lib/Session.php +++ b/lib/Session.php @@ -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( diff --git a/lib/Template.php b/lib/Template.php index 262e213..a73d523 100644 --- a/lib/Template.php +++ b/lib/Template.php @@ -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'); } diff --git a/lib/Translator.php b/lib/Translator.php index ff0b46b..3024856 100644 --- a/lib/Translator.php +++ b/lib/Translator.php @@ -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()); } } diff --git a/lib/helpers.php b/lib/helpers.php index 0d77045..839826b 100644 --- a/lib/helpers.php +++ b/lib/helpers.php @@ -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 .= '