Commit 5f9710f4 authored by Peter Tönnies's avatar Peter Tönnies Committed by Matthias Larisch

102 pt code style

parent 205ef1f1
Pipeline #11843679 passed with stages
in 5 minutes and 6 seconds
......@@ -20,3 +20,4 @@ tests/_support/_generated/
chat/.npm
api
light
.php_cs.cache
<?php
$finder = PhpCsFixer\Finder::create()
->exclude('docker')
->exclude('lang')
->exclude('fonts')
->exclude('chat')
->exclude('images')
->exclude('light')
->exclude('scripts')
->exclude('js')
->exclude('vendor')
->notPath('lib/fpdi')
->notPath('lib/Html2Text.php')
->notPath('lib/makefont')
->notPath('lib/flourish')
->notPath('lib/phpqrcode')
->notPath('lib/Mobile_Detect.php')
->notPath('lib/fpdf.php')
->notPath('lib/minify')
->notPath('lib/font')
->in(__DIR__)
;
return PhpCsFixer\Config::create()
->setRules([
'@Symfony' => true,
'concat_space' => ['spacing' => 'one'],
'cast_spaces' => ['space' => 'none'],
'phpdoc_align' => ['tags' => []],
'trailing_comma_in_multiline_array' => false
])
->setIndent("\t")
->setFinder($finder)
;
?>
......@@ -179,6 +179,17 @@ To rebuild assets on change, run:
./scripts/watch-assets
```
# Code style
We use php-cs-fixer to format the code style. The aim is to make it use the same style as phpstorm does by default.
It is based on the @Symfony ruleset, with a few changes.
To format all files you can run:
```
vendor/bin/php-cs-fixer fix --show-progress=estimating --verbose
```
# Helper scripts
There are a number of helper scripts available. Most of them obey the `FS_INT` env var. Default is `dev`, you can also set it to `test`.
......
<?php
<?php
require_once 'config.inc.php';
require_once 'lib/func.inc.php';
......@@ -7,44 +8,52 @@ require_once 'lang/DE/de.php';
require_once 'lib/Manual.class.php';
/** Checks the validity of an API token
@param $fs Foodsaver ID
@param $key API token
@return True or False depending on validity
* @param $fs Foodsaver ID
* @param $key API token
*
* @return true or False depending on validity
*/
function check_api_token($fs, $key)
{
global $db;
$res = $db->qOne('SELECT COUNT(foodsaver_id) FROM '.PREFIX.'apitoken WHERE foodsaver_id = '.(int)$fs.' AND token="'.$db->safe($key).'"');
return ($res == 1);
$res = $db->qOne('SELECT COUNT(foodsaver_id) FROM ' . PREFIX . 'apitoken WHERE foodsaver_id = ' . (int)$fs . ' AND token="' . $db->safe($key) . '"');
return $res == 1;
}
function dateToCal($timestamp) {
function dateToCal($timestamp)
{
return gmdate('Ymd\THis\Z', $timestamp);
}
function dateToLocalCal($timestamp) {
function dateToLocalCal($timestamp)
{
return date('Ymd\THis', $timestamp);
}
function escapeString($string) {
$string = str_replace("\r\n", "\\n", $string);
$string = str_replace("\n", "\\n", $string);
return preg_replace('/([\,;])/','\\\$1', $string);
function escapeString($string)
{
$string = str_replace("\r\n", '\\n', $string);
$string = str_replace("\n", '\\n', $string);
return preg_replace('/([\,;])/', '\\\$1', $string);
}
function generate_calendar_event($utc_begin, $utc_end, $utc_change, $uid, $location, $description, $summary, $uri)
{
$out = "BEGIN:VEVENT\r\nDTEND:";
$out .= dateToCal($utc_end)."\r\nUID:";
$out .= $uid."\r\nDTSTAMP:";
$out .= dateToCal($utc_change)."\r\nLOCATION:";
$out .= escapeString($location)."\r\nDESCRIPTION:";
$out .= escapeString($description)."\r\nURL;VALUE=URI:";
$out .= escapeString($uri)."\r\nSUMMARY:";
$out .= escapeString($summary)."\r\nDTSTART:";
$out .= dateToCal($utc_begin)."\r\nEND:VEVENT\r\n";
$out .= dateToCal($utc_end) . "\r\nUID:";
$out .= $uid . "\r\nDTSTAMP:";
$out .= dateToCal($utc_change) . "\r\nLOCATION:";
$out .= escapeString($location) . "\r\nDESCRIPTION:";
$out .= escapeString($description) . "\r\nURL;VALUE=URI:";
$out .= escapeString($uri) . "\r\nSUMMARY:";
$out .= escapeString($summary) . "\r\nDTSTART:";
$out .= dateToCal($utc_begin) . "\r\nEND:VEVENT\r\n";
return $out;
}
function api_generate_calendar($fs, $options)
{
global $db;
......@@ -52,32 +61,27 @@ function api_generate_calendar($fs, $options)
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: attachment; filename=calendar.ics');
echo "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Foodsharing.de//NONSGML v1.0//EN\r\nCALSCALE:GREGORIAN\r\n";
if(strpos($options, 's') !== FALSE)
{
$fetches = $db->q('SELECT b.id, b.name, b.str, b.hsnr, b.plz, b.stadt, a.confirmed, UNIX_TIMESTAMP(a.`date`) AS date_ts FROM '.PREFIX.'abholer a INNER JOIN '.PREFIX.'betrieb b ON a.betrieb_id = b.id WHERE a.foodsaver_id = '.(int)$fs.' AND a.`date` > NOW() - INTERVAL 1 DAY');
if(is_array($fetches))
{
foreach($fetches as $f)
{
if (strpos($options, 's') !== false) {
$fetches = $db->q('SELECT b.id, b.name, b.str, b.hsnr, b.plz, b.stadt, a.confirmed, UNIX_TIMESTAMP(a.`date`) AS date_ts FROM ' . PREFIX . 'abholer a INNER JOIN ' . PREFIX . 'betrieb b ON a.betrieb_id = b.id WHERE a.foodsaver_id = ' . (int)$fs . ' AND a.`date` > NOW() - INTERVAL 1 DAY');
if (is_array($fetches)) {
foreach ($fetches as $f) {
$datestart = $f['date_ts'];
$dateend = $f['date_ts'] + 30 * 60;
$uid = $f['id'].$f['date_ts'].'@fetch.foodsharing.de';
$address = $f['str'].' '.$f['hsnr'].', '.$f['plz'].' '.$f['stadt'];
$summary = $f['name'].' Abholung';
if(!$f['confirmed'])
{
$uid = $f['id'] . $f['date_ts'] . '@fetch.foodsharing.de';
$address = $f['str'] . ' ' . $f['hsnr'] . ', ' . $f['plz'] . ' ' . $f['stadt'];
$summary = $f['name'] . ' Abholung';
if (!$f['confirmed']) {
$summary .= ' (unbestätigt)';
}
$description = 'Foodsharing Abholung bei '.$f['name'];
$uri = BASE_URL.'/?page=fsbetrieb&id='.$f['id'];
$description = 'Foodsharing Abholung bei ' . $f['name'];
$uri = BASE_URL . '/?page=fsbetrieb&id=' . $f['id'];
// 3. Echo out the ics file's contents
echo generate_calendar_event($datestart, $dateend, time(), $uid, $address, $description, $summary, $uri);
}
}
}
if(strpos($options, 'e') !== FALSE)
{
if (strpos($options, 'e') !== false) {
$calendar = $db->q('
SELECT
e.id,
......@@ -87,18 +91,18 @@ function api_generate_calendar($fs, $options)
UNIX_TIMESTAMP(e.`end`) AS end_ts,
e.online,
fe.`status`,
loc.name as loc_name,
loc.name AS loc_name,
loc.street,
loc.zip,
loc.city
FROM
`'.PREFIX.'event` e
`' . PREFIX . 'event` e
INNER JOIN
`'.PREFIX.'foodsaver_has_event` fe
`' . PREFIX . 'foodsaver_has_event` fe
ON
e.id = fe.event_id AND fe.foodsaver_id = '.(int)$fs.'
e.id = fe.event_id AND fe.foodsaver_id = ' . (int)$fs . '
LEFT JOIN
`'.PREFIX.'location` loc
`' . PREFIX . 'location` loc
ON
loc.id = e.location_id
WHERE
......@@ -108,33 +112,28 @@ function api_generate_calendar($fs, $options)
OR
fe.`status` IN(1,2)
)');
if(is_array($calendar))
{
foreach($calendar as $c)
{
if (is_array($calendar)) {
foreach ($calendar as $c) {
$datestart = $c['start_ts'];
$dateend = $c['end_ts'];
$uid = $c['id'].$c['start_ts'].'@event.foodsharing.de';
if($c['online'])
{
$address = "Online, mumble.lebensmittelretten.de";
} else
{
$address = $c['loc_name'].', '.$c['street'].' '.$c['zip'].', '.$c['city'];
$uid = $c['id'] . $c['start_ts'] . '@event.foodsharing.de';
if ($c['online']) {
$address = 'Online, mumble.lebensmittelretten.de';
} else {
$address = $c['loc_name'] . ', ' . $c['street'] . ' ' . $c['zip'] . ', ' . $c['city'];
}
$summary = $c['name'].' Event';
if(!$c['status'] == 1)
{
$summary = '('.$summary.')';
$summary = $c['name'] . ' Event';
if (!$c['status'] == 1) {
$summary = '(' . $summary . ')';
}
$description = 'Foodsharing Event: '.$c['description'];
$uri = BASE_URL.'/?page=event&id='.$c['id'];
$description = 'Foodsharing Event: ' . $c['description'];
$uri = BASE_URL . '/?page=event&id=' . $c['id'];
// 3. Echo out the ics file's contents
echo generate_calendar_event($datestart, $dateend, time(), $uid, $address, $description, $summary, $uri);
}
}
}
echo "END:VCALENDAR\r\n";
}
......@@ -145,16 +144,13 @@ $fs = $_GET['fs'];
$key = $_GET['key'];
$opts = $_GET['opts'];
if(!check_api_token($fs, $key)) {
if (!check_api_token($fs, $key)) {
http_response_code(403);
echo "Invalid access token!";
}
else
{
switch($action)
{
case 'cal':
api_generate_calendar($fs, $opts);
break;
echo 'Invalid access token!';
} else {
switch ($action) {
case 'cal':
api_generate_calendar($fs, $opts);
break;
}
}
<?php
class ActivityControl extends Control
{
{
public function __construct()
{
$this->model = new ActivityModel();
$this->view = new ActivityView();
parent::__construct();
}
public function index()
{
}
}
\ No newline at end of file
}
This diff is collapsed.
<?php
class ActivityView extends View
{
}
\ No newline at end of file
}
<?php
<?php
class ActivityXhr extends Control
{
public function __construct()
{
$this->model = new ActivityModel();
......@@ -9,251 +9,217 @@ class ActivityXhr extends Control
parent::__construct();
}
public function loadmore()
{
$mailbox =loadModel('mailbox');
$mailbox = loadModel('mailbox');
/*
* get ids to not display from options
*/
* get ids to not display from options
*/
$hidden_ids = array(
'bezirk' => array(),
'mailbox' => array(),
'buddywall' => array()
'bezirk' => array(),
'mailbox' => array(),
'buddywall' => array()
);
if($sesOptions = S::option('activity-listings'))
{
foreach ($sesOptions as $o)
{
if(isset($hidden_ids[$o['index']]))
{
if ($sesOptions = S::option('activity-listings')) {
foreach ($sesOptions as $o) {
if (isset($hidden_ids[$o['index']])) {
$hidden_ids[$o['index']][$o['id']] = true;
}
}
}
$xhr = new Xhr();
/*
* get FOrum updates
*/
* get FOrum updates
*/
$updates = array();
if($up = $this->model->loadForumUpdates($_GET['page'],$hidden_ids['bezirk']))
{
if ($up = $this->model->loadForumUpdates($_GET['page'], $hidden_ids['bezirk'])) {
$updates = $up;
}
if($up = $this->model->loadBetriebUpdates($_GET['page']))
{
$updates = array_merge($updates,$up);
if ($up = $this->model->loadBetriebUpdates($_GET['page'])) {
$updates = array_merge($updates, $up);
}
if($up = $this->model->loadMailboxUpdates($_GET['page'],$mailbox,$hidden_ids['mailbox']))
{
$updates = array_merge($updates,$up);
if ($up = $this->model->loadMailboxUpdates($_GET['page'], $mailbox, $hidden_ids['mailbox'])) {
$updates = array_merge($updates, $up);
}
if($up = $this->model->loadFriendWallUpdates($_GET['page'],$hidden_ids['buddywall']))
{
$updates = array_merge($updates,$up);
if ($up = $this->model->loadFriendWallUpdates($_GET['page'], $hidden_ids['buddywall'])) {
$updates = array_merge($updates, $up);
}
if($up = $this->model->loadBasketWallUpdates($_GET['page']))
{
$updates = array_merge($updates,$up);
if ($up = $this->model->loadBasketWallUpdates($_GET['page'])) {
$updates = array_merge($updates, $up);
}
$xhr->addData('updates', $updates);
$xhr->send();
}
public function load()
{
/*
* get Forum updates
*/
$mailbox =loadModel('mailbox');
if(isset($_GET['options']))
{
* get Forum updates
*/
$mailbox = loadModel('mailbox');
if (isset($_GET['options'])) {
$options = array();
foreach ($_GET['options'] as $o)
{
if(isset($o['index']) && isset($o['id']) && (int)$o['id'] > 0)
{
$options[$o['index'].'-'.$o['id']] = array(
foreach ($_GET['options'] as $o) {
if (isset($o['index']) && isset($o['id']) && (int)$o['id'] > 0) {
$options[$o['index'] . '-' . $o['id']] = array(
'index' => $o['index'],
'id' => $o['id']
);
}
}
if(empty($options))
{
if (empty($options)) {
$options = false;
}
S::setOption('activity-listings', $options, $this->model);
}
$page = 0;
$hidden_ids = array(
'bezirk' => array(),
'mailbox' => array(),
'buddywall'=> array()
'buddywall' => array()
);
if($sesOptions = S::option('activity-listings'))
{
foreach ($sesOptions as $o)
{
if(isset($hidden_ids[$o['index']]))
{
if ($sesOptions = S::option('activity-listings')) {
foreach ($sesOptions as $o) {
if (isset($hidden_ids[$o['index']])) {
$hidden_ids[$o['index']][$o['id']] = $o['id'];
}
}
}
$xhr = new Xhr();
$updates = array();
if($up = $this->model->loadForumUpdates($page,$hidden_ids['bezirk']))
{
if ($up = $this->model->loadForumUpdates($page, $hidden_ids['bezirk'])) {
$updates = $up;
}
if($up = $this->model->loadBetriebUpdates())
{
$updates = array_merge($updates,$up);
if ($up = $this->model->loadBetriebUpdates()) {
$updates = array_merge($updates, $up);
}
if($up = $this->model->loadMailboxUpdates($page,$mailbox,$hidden_ids['mailbox']))
{
$updates = array_merge($updates,$up);
if ($up = $this->model->loadMailboxUpdates($page, $mailbox, $hidden_ids['mailbox'])) {
$updates = array_merge($updates, $up);
}
if($up = $this->model->loadFriendWallUpdates($page,$hidden_ids['buddywall']))
{
$updates = array_merge($updates,$up);
if ($up = $this->model->loadFriendWallUpdates($page, $hidden_ids['buddywall'])) {
$updates = array_merge($updates, $up);
}
if($up = $this->model->loadBasketWallUpdates($page))
{
$updates = array_merge($updates,$up);
if ($up = $this->model->loadBasketWallUpdates($page)) {
$updates = array_merge($updates, $up);
}
$xhr->addData('updates', $updates);
$xhr->addData('user', array(
'id' => fsId(),
'name' => S::user('name'),
'avatar' => img(S::user('photo'))
'id' => fsId(),
'name' => S::user('name'),
'avatar' => img(S::user('photo'))
));
if(isset($_GET['listings']))
{
if (isset($_GET['listings'])) {
$listings = array(
'groups' => array(),
'regions' => array(),
'mailboxes' => array(),
'stores' => array(),
'buddywalls' => array()
'groups' => array(),
'regions' => array(),
'mailboxes' => array(),
'stores' => array(),
'buddywalls' => array()
);
$option = array();
if($list = S::option('activity-listings'))
{