Skip to content

Commit

Permalink
Automated CS fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jtojnar committed Feb 27, 2017
1 parent d07b960 commit 6ed01c5
Show file tree
Hide file tree
Showing 75 changed files with 3,299 additions and 3,306 deletions.
87 changes: 44 additions & 43 deletions _docs/website/feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,34 @@
// github tags feed generator by samrayner:
// https://github.com/samrayner/GitHub-Tags-Feed

$username = "ssilence";
$repo_name = "selfoss";
$username = 'ssilence';
$repo_name = 'selfoss';

// use cache?
$cacheFile = "rss.cache";
if(!file_exists($cacheFile))
$cacheFile = 'rss.cache';
if (!file_exists($cacheFile)) {
touch($cacheFile);
}
$maxTimestampValidity = 5400; // 1.5 hours
$cacheFileContent = file_get_contents($cacheFile);
if(strlen($cacheFileContent)>0) {
if (strlen($cacheFileContent) > 0) {
$cacheFileContent = json_decode($cacheFileContent, true);
if($cacheFileContent['timestamp'] + $maxTimestampValidity < time()) {
if ($cacheFileContent['timestamp'] + $maxTimestampValidity < time()) {
unlink($cacheFile);
} else {
header("Content-Type: application/xml;");
header('Content-Type: application/xml;');
die($cacheFileContent['feed']);
}
}

function status_ok($curl) {
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
return ($status >= 200 && $status < 300);

return $status >= 200 && $status < 300;
}

$repo_url = "https://api.github.com/repos/$username/$repo_name";
$list_url = $repo_url."/git/refs/tags/";
$list_url = $repo_url . '/git/refs/tags/';

$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
Expand All @@ -36,8 +38,8 @@ function status_ok($curl) {
curl_setopt($curl, CURLOPT_URL, $repo_url);
$response = curl_exec($curl);

if(!status_ok($curl)) {
header("HTTP/1.1 404 Not Found");
if (!status_ok($curl)) {
header('HTTP/1.1 404 Not Found');
exit("Repository doesn't exist or is private." . $response);
}

Expand All @@ -46,18 +48,18 @@ function status_ok($curl) {
curl_setopt($curl, CURLOPT_URL, $list_url);
$response = curl_exec($curl);

if(!status_ok($curl)) {
header("HTTP/1.1 404 Not Found");
exit("No tags for this repository yet.");
if (!status_ok($curl)) {
header('HTTP/1.1 404 Not Found');
exit('No tags for this repository yet.');
}

$tag_refs = array_reverse(json_decode($response, true));

$tags = array();
foreach($tag_refs as $tag) {
$tags = [];
foreach ($tag_refs as $tag) {
//only match version tags
//if(preg_match('~/v\d+(\.\d+)*$~', $tag["ref"])) {
curl_setopt($curl, CURLOPT_URL, $tag["object"]["url"]);
curl_setopt($curl, CURLOPT_URL, $tag['object']['url']);
$tags[] = json_decode(curl_exec($curl), true);
//}
}
Expand All @@ -68,54 +70,53 @@ function escape(&$var) {
$var = htmlspecialchars($var, ENT_NOQUOTES | 16); //ENT_XML1 = 16
}

escape($repo["name"]);
escape($repo["description"]);
escape($repo['name']);
escape($repo['description']);
escape($username);


header("Content-Type: application/xml;");
header('Content-Type: application/xml;');
ob_start();
echo '<?xml version="1.0" encoding="utf-8"?>'; ?>
<rss version="2.0">
<channel>
<title>Changelog for <?php echo $repo["name"] ?></title>
<link><?php echo $repo["html_url"] ?></link>
<description><?php echo $repo["description"] ?></description>
<title>Changelog for <?= $repo['name'] ?></title>
<link><?= $repo['html_url'] ?></link>
<description><?= $repo['description'] ?></description>
<language>en</language>
<copyright>Copyright <?php echo date("Y") ?>, <?php echo $username ?></copyright>
<copyright>Copyright <?= date('Y') ?>, <?= $username ?></copyright>
<docs>https://cyber.harvard.edu/rss/rss.html</docs>
<pubDate><?php echo date("r", strtotime($repo["pushed_at"])) ?></pubDate>
<lastBuildDate><?php echo date("r", strtotime($repo["updated_at"])) ?></lastBuildDate>
<pubDate><?= date('r', strtotime($repo['pushed_at'])) ?></pubDate>
<lastBuildDate><?= date('r', strtotime($repo['updated_at'])) ?></lastBuildDate>

<?php foreach($tags as $tag): ?>
<?php foreach ($tags as $tag): ?>
<item>

<?php
escape($tag["tag"]);
escape($tag["tagger"]["email"]);
escape($tag["message"]);
escape($tag['tag']);
escape($tag['tagger']['email']);
escape($tag['message']);
?>

<title><?php echo $tag["tag"] ?></title>
<link><?php echo "https://github.com/$username/$repo_name/zipball/".$tag["tag"] ?></link>
<pubDate><?php echo date("r", strtotime($tag["tagger"]["date"])) ?></pubDate>
<guid><?php echo "https://github.com/$username/$repo_name/commit/".$tag["sha"] ?></guid>
<author><?php echo $tag["tagger"]["email"] ?></author>
<description><?php echo $tag["message"] ?></description>
<title><?= $tag['tag'] ?></title>
<link><?= "https://github.com/$username/$repo_name/zipball/" . $tag['tag'] ?></link>
<pubDate><?= date('r', strtotime($tag['tagger']['date'])) ?></pubDate>
<guid><?= "https://github.com/$username/$repo_name/commit/" . $tag['sha'] ?></guid>
<author><?= $tag['tagger']['email'] ?></author>
<description><?= $tag['message'] ?></description>

</item>
<?php endforeach ?>

</channel>
</rss>
<?PHP
<?php
$content = ob_get_contents();
ob_end_clean();
header("Content-Type: text/xml");
$cacheFileContent = json_encode(array(
"timestamp" => time(),
"feed" => $content
));
header('Content-Type: text/xml');
$cacheFileContent = json_encode([
'timestamp' => time(),
'feed' => $content
]);
file_put_contents($cacheFile, $cacheFileContent);
echo $content;
?>
6 changes: 2 additions & 4 deletions cliupdate.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?php

chdir(__DIR__);
require(__DIR__.'/common.php');
require __DIR__ . '/common.php';

$f3->set('FTRSS_DATA_DIR', __DIR__.'/data/fulltextrss');
$f3->set('FTRSS_DATA_DIR', __DIR__ . '/data/fulltextrss');

$loader = new \helpers\ContentLoader();
$loader->update();

?>
28 changes: 15 additions & 13 deletions common.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,26 @@

$f3 = $f3 = Base::instance();

$f3->set('DEBUG',0);
$f3->set('version','2.17-SNAPSHOT');
$f3->set('DEBUG', 0);
$f3->set('version', '2.17-SNAPSHOT');
$f3->set('AUTOLOAD', false);
$f3->set('cache',__DIR__.'/data/cache');
$f3->set('BASEDIR',__DIR__);
$f3->set('LOCALES',__DIR__.'/public/lang/');
$f3->set('cache', __DIR__ . '/data/cache');
$f3->set('BASEDIR', __DIR__);
$f3->set('LOCALES', __DIR__ . '/public/lang/');

// read defaults
$f3->config('defaults.ini');

// read config, if it exists
if(file_exists('config.ini'))
if (file_exists('config.ini')) {
$f3->config('config.ini');
}

// 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) {
$f3->set(strtolower(substr($key,strlen($env_prefix))),$value);
foreach ($f3->get('ENV') as $key => $value) {
if (strncasecmp($key, $env_prefix, strlen($env_prefix)) == 0) {
$f3->set(strtolower(substr($key, strlen($env_prefix))), $value);
}
}

Expand All @@ -47,13 +48,13 @@ function($f3) {
$exception = $f3->get('EXCEPTION');

if ($exception) {
\F3::get('logger')->error($exception->getMessage(), array('exception' => $exception));
\F3::get('logger')->error($exception->getMessage(), ['exception' => $exception]);
} else {
\F3::get('logger')->error($f3->get('ERROR.text'));
}

if (\F3::get('DEBUG') != 0) {
echo $f3->get('lang_error') . ": ";
echo $f3->get('lang_error') . ': ';
echo $f3->get('ERROR.text') . "\n";
echo $trace;
} else {
Expand All @@ -62,5 +63,6 @@ function($f3) {
}
);

if (\F3::get('DEBUG')!=0)
ini_set('display_errors',0);
if (\F3::get('DEBUG') != 0) {
ini_set('display_errors', 0);
}
13 changes: 5 additions & 8 deletions controllers/BaseController.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
<?PHP
<?php

namespace controllers;

/**
* Parent Controller
*
* @package controllers
* @copyright Copyright (c) Tobias Zeising (http://www.aditu.de)
* @license GPLv3 (https://www.gnu.org/licenses/gpl-3.0.html)
* @author Tobias Zeising <tobias.zeising@aditu.de>
*/
class BaseController {

/** @var \helpers\View view helper */
protected $view;


/**
* initialize controller
*
Expand All @@ -29,9 +26,9 @@ public function __construct() {
* send 403 if not logged in and not public mode
*
* @return void
*/
*/
public function needsLoggedInOrPublicMode() {
if(\F3::get('auth')->isLoggedin()!==true && \F3::get('public')!=1) {
if (\F3::get('auth')->isLoggedin() !== true && \F3::get('public') != 1) {
\F3::error(403);
}
}
Expand All @@ -40,9 +37,9 @@ public function needsLoggedInOrPublicMode() {
* send 403 if not logged in
*
* @return void
*/
*/
public function needsLoggedIn() {
if(\F3::get('auth')->isLoggedin()!==true) {
if (\F3::get('auth')->isLoggedin() !== true) {
\F3::error(403);
}
}
Expand Down
Loading

0 comments on commit 6ed01c5

Please sign in to comment.