Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ $rules = [
'semicolon_after_instruction' => false,
// additional rules
'array_syntax' => ['syntax' => 'short'],
'dir_constant' => true,
'is_null' => ['use_yoda_style' => false],
'modernize_types_casting' => true,
'no_alias_functions' => true,
'ordered_imports' => true,
'phpdoc_add_missing_param_annotation' => ['only_untyped' => false],
'phpdoc_order' => true,
'psr4' => true,
'strict_param' => true,
];

return PhpCsFixer\Config::create()
Expand Down
4 changes: 2 additions & 2 deletions common.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// overwrite config with ENV variables
$env_prefix = $f3->get('env_prefix');
foreach ($f3->get('ENV') as $key => $value) {
if (strncasecmp($key, $env_prefix, strlen($env_prefix)) == 0) {
if (strncasecmp($key, $env_prefix, strlen($env_prefix)) === 0) {
$f3->set(strtolower(substr($key, strlen($env_prefix))), $value);
}
}
Expand Down Expand Up @@ -83,5 +83,5 @@ function(Base $f3) {
);

if (\F3::get('DEBUG') != 0) {
ini_set('display_errors', 0);
ini_set('display_errors', '0');
}
2 changes: 1 addition & 1 deletion controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function needsLoggedIn() {
* @return bool
*/
public function allowedToUpdate() {
return \F3::get('auth')->isLoggedin() == 1
return \F3::get('auth')->isLoggedin() === true
|| $_SERVER['REMOTE_ADDR'] === $_SERVER['SERVER_ADDR']
|| $_SERVER['REMOTE_ADDR'] === '127.0.0.1'
|| \F3::get('allow_public_update_access') == 1;
Expand Down
26 changes: 12 additions & 14 deletions controllers/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace controllers;

use Base;

/**
* Controller for root
*
Expand All @@ -14,21 +16,14 @@ class Index extends BaseController {
* home site
* html
*
* @param Base $f3 fatfree base instance
*
* @return void
*/
public function home() {
// parse params
$options = [];
if (\F3::get('homepage') != '') {
$options = ['type' => \F3::get('homepage')];
}
public function home(Base $f3) {
$options = $_GET;

// use ajax given params?
if (count($_GET) > 0) {
$options = $_GET;
}

if (!isset($options['ajax'])) {
if (!$f3->ajax()) {
// show as full html page
$this->view->publicMode = \F3::get('public') == 1;
$this->view->authEnabled = \F3::get('auth')->enabled() === true;
Expand Down Expand Up @@ -81,7 +76,7 @@ public function home() {
}

// ajax call = only send entries and statistics not full template
if (isset($options['ajax'])) {
if ($f3->ajax()) {
$this->view->jsonSuccess([
'lastUpdate' => \helpers\ViewHelper::date_iso8601($itemsDao->lastUpdate()),
'hasMore' => $items['hasMore'],
Expand Down Expand Up @@ -201,9 +196,12 @@ public function win8Notifications() {
/**
* load items
*
* @param array $options
* @param array $tags
*
* @return string html with items
*/
private function loadItems($options, $tags) {
private function loadItems(array $options, array $tags) {
$itemDao = new \daos\Items();
$itemsHtml = '';

Expand Down
38 changes: 26 additions & 12 deletions controllers/Items.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace controllers;

use Base;

/**
* Controller for item handling
*
Expand All @@ -14,13 +16,16 @@ class Items extends BaseController {
* mark items as read. Allows one id or an array of ids
* json
*
* @param Base $f3 fatfree base instance
* @param array $params query string parameters
*
* @return void
*/
public function mark() {
public function mark(Base $f3, array $params) {
$this->needsLoggedIn();

if (\F3::get('PARAMS["item"]') != null) {
$lastid = \F3::get('PARAMS["item"]');
if (isset($params['item'])) {
$lastid = $params['item'];
} elseif (isset($_POST['ids'])) {
$lastid = $_POST['ids'];
}
Expand All @@ -45,12 +50,15 @@ public function mark() {
* mark item as unread
* json
*
* @param Base $f3 fatfree base instance
* @param array $params query string parameters
*
* @return void
*/
public function unmark() {
public function unmark(Base $f3, array $params) {
$this->needsLoggedIn();

$lastid = \F3::get('PARAMS["item"]');
$lastid = $params['item'];

$itemDao = new \daos\Items();

Expand All @@ -69,12 +77,15 @@ public function unmark() {
* starr item
* json
*
* @param Base $f3 fatfree base instance
* @param array $params query string parameters
*
* @return void
*/
public function starr() {
public function starr(Base $f3, array $params) {
$this->needsLoggedIn();

$id = \F3::get('PARAMS["item"]');
$id = $params['item'];

$itemDao = new \daos\Items();

Expand All @@ -92,12 +103,15 @@ public function starr() {
* unstarr item
* json
*
* @param Base $f3 fatfree base instance
* @param array $params query string parameters
*
* @return void
*/
public function unstarr() {
public function unstarr(Base $f3, array $params) {
$this->needsLoggedIn();

$id = \F3::get('PARAMS["item"]');
$id = $params['item'];

$itemDao = new \daos\Items();

Expand Down Expand Up @@ -197,9 +211,9 @@ public function sync() {

$sinceId = 0;
if (array_key_exists('itemsSinceId', $params)) {
$sinceId = intval($params['itemsSinceId']);
$sinceId = (int) $params['itemsSinceId'];
if ($sinceId >= 0) {
$notBefore = date_create($params['itemsNotBefore']);
$notBefore = new \DateTime($params['itemsNotBefore']);
if ($sinceId < 1 || !$notBefore) {
$sinceId = $itemsDao->lowestIdOfInterest() - 1;
// only send 1 day worth of items
Expand Down Expand Up @@ -255,7 +269,7 @@ public function sync() {

$wantItemsStatuses = array_key_exists('itemsStatuses', $params) && $params['itemsStatuses'] == 'true';
if ($wantItemsStatuses) {
$sync['itemUpdates'] = $itemsDao->statuses($since->format(\DateTime::ATOM));
$sync['itemUpdates'] = $itemsDao->statuses($since);
}
}

Expand Down
36 changes: 22 additions & 14 deletions controllers/Opml.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ public function add() {

try {
$opml = $_FILES['opml'];
if ($opml['error'] == UPLOAD_ERR_NO_FILE) {
if ($opml['error'] === UPLOAD_ERR_NO_FILE) {
throw new \Exception('No file uploaded!');
}
if (!in_array($opml['type'], ['application/xml', 'text/xml', 'text/x-opml+xml', 'text/x-opml'])) {
if (!in_array($opml['type'], ['application/xml', 'text/xml', 'text/x-opml+xml', 'text/x-opml'], true)) {
throw new \Exception('Unsupported file type: ' . $opml['type']);
}

Expand All @@ -90,7 +90,7 @@ public function add() {
$this->show();
} else { // On success bring them back to their subscription list
$amount = count($this->imported);
$this->msg = 'Success! ' . $amount . ' feed' . ($amount != 1 ? 's have' : ' has') . ' been imported.<br>' .
$this->msg = 'Success! ' . $amount . ' feed' . ($amount !== 1 ? 's have' : ' has') . ' been imported.<br>' .
'You might want to <a href="update">update now</a> or <a href="./">view your feeds</a>.';
$this->msgclass = 'success';
$this->show();
Expand All @@ -105,11 +105,14 @@ public function add() {
/**
* Process a group of outlines
*
* - Recursive
* - We use non-rss outline’s text as tags
* - Reads outline elements from both the default and selfoss namespace
*
* @param SimpleXMLElement $xml A SimpleXML object with <outline> children
* @param array $tags An array of tags for the current <outline>
* @note Recursive
* @note We use non-rss outline's text as tags
* @note Reads outline elements from both the default and selfoss namespace
*
* @return string[] titles of feeds that could not be added to subscriptions
*/
private function processGroup(SimpleXMLElement $xml, array $tags = []) {
$errors = [];
Expand All @@ -118,12 +121,12 @@ private function processGroup(SimpleXMLElement $xml, array $tags = []) {

// tags are the words of the outline parent
$title = (string) $xml->attributes(null)->title;
if ($title != null && $title != '/') {
if ($title !== '' && $title !== '/') {
$tags[] = $title;
// for new tags, try to import tag color, otherwise use random color
if (!$this->tagsDao->hasTag($title)) {
$tagColor = (string) $xml->attributes('selfoss', true)->color;
if ($tagColor != null) {
if ($tagColor !== '') {
$this->tagsDao->saveTagColor($title, $tagColor);
} else {
$this->tagsDao->autocolorTag($title);
Expand Down Expand Up @@ -154,7 +157,7 @@ private function processGroup(SimpleXMLElement $xml, array $tags = []) {
* @param SimpleXMLElement $xml xml feed entry for item
* @param array $tags of the entry
*
* @return bool true on success or item title on error
* @return bool|string true on success or item title on error
*/
private function addSubscription(SimpleXMLElement $xml, array $tags) {
// OPML Required attributes: text, xmlUrl, type
Expand All @@ -166,7 +169,7 @@ private function addSubscription(SimpleXMLElement $xml, array $tags) {

// description
$title = (string) $attrs->text;
if ($title == null) {
if ($title === '') {
$title = (string) $attrs->title;
}

Expand All @@ -184,7 +187,7 @@ private function addSubscription(SimpleXMLElement $xml, array $tags) {
}
$spout = (string) $nsattrs->spout;
$data = json_decode(html_entity_decode((string) $nsattrs->params), true);
} elseif (in_array((string) $attrs->type, ['rss', 'atom'])) {
} elseif (in_array((string) $attrs->type, ['rss', 'atom'], true)) {
$spout = 'spouts\rss\feed';
} else {
\F3::get('logger')->warning("OPML import: failed to import '$title'");
Expand Down Expand Up @@ -227,16 +230,19 @@ private function addSubscription(SimpleXMLElement $xml, array $tags) {
/**
* Generate an OPML outline element from a source
*
* @param array $source source
* @note Uses the selfoss namespace to store information about spouts
*
* @param array $source source
*
* @return void
*/
private function writeSource(array $source) {
// retrieve the feed url of the source
$params = json_decode(html_entity_decode($source['params']), true);
$feedUrl = $this->spoutLoader->get($source['spout'])->getXmlUrl($params);

// if the spout doesn't return a feed url, the source isn't an RSS feed
if ($feedUrl !== false) {
if ($feedUrl !== null) {
$this->writer->startElement('outline');
} else {
$this->writer->startElementNS('selfoss', 'outline', null);
Expand All @@ -245,7 +251,7 @@ private function writeSource(array $source) {
$this->writer->writeAttribute('title', $source['title']);
$this->writer->writeAttribute('text', $source['title']);

if ($feedUrl !== false) {
if ($feedUrl !== null) {
$this->writer->writeAttribute('xmlUrl', $feedUrl);
$this->writer->writeAttribute('type', 'rss');
}
Expand All @@ -262,6 +268,8 @@ private function writeSource(array $source) {
* Export user's subscriptions to OPML file
*
* @note Uses the selfoss namespace to store selfoss-specific information
*
* @return void
*/
public function export() {
$this->needsLoggedIn();
Expand Down
24 changes: 14 additions & 10 deletions controllers/Rss.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace controllers;

use Base;
use FeedWriter\RSS2;

/**
Expand All @@ -15,9 +16,12 @@ class Rss extends BaseController {
/**
* rss feed
*
* @param Base $f3 fatfree base instance
* @param array $params query string parameters
*
* @return void
*/
public function rss() {
public function rss(Base $f3, array $params) {
$this->needsLoggedInOrPublicMode();

$feedWriter = new RSS2();
Expand All @@ -38,19 +42,19 @@ public function rss() {
$options = $_GET;
}
$options['items'] = \F3::get('rss_max_items');
if (\F3::get('PARAMS["tag"]') != null) {
$options['tag'] = \F3::get('PARAMS["tag"]');
if (isset($params['tag'])) {
$options['tag'] = $params['tag'];
}
if (\F3::get('PARAMS["type"]') != null) {
$options['type'] = \F3::get('PARAMS["type"]');
if (isset($params['type'])) {
$options['type'] = $params['type'];
}

// get items
$newestEntryDate = false;
$lastid = -1;
$newestEntryDate = null;
$lastid = null;
$itemDao = new \daos\Items();
foreach ($itemDao->get($options) as $item) {
if ($newestEntryDate === false) {
if ($newestEntryDate === null) {
$newestEntryDate = $item['datetime'];
}
$newItem = $feedWriter->createNewItem();
Expand Down Expand Up @@ -84,12 +88,12 @@ public function rss() {
$lastid = $item['id'];

// mark as read
if (\F3::get('rss_mark_as_read') == 1 && $lastid != -1) {
if (\F3::get('rss_mark_as_read') == 1 && $lastid !== null) {
$itemDao->mark($lastid);
}
}

if ($newestEntryDate === false) {
if ($newestEntryDate === null) {
$newestEntryDate = date(\DATE_ATOM, time());
}
$feedWriter->setDate($newestEntryDate);
Expand Down
Loading