Use short form array syntax everywhere

pull/487/head
Hypolite Petovan 2018-01-15 08:15:33 -05:00
parent 4ee41c64a3
commit 27b60e003f
68 changed files with 869 additions and 869 deletions

View File

@ -36,10 +36,10 @@
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@ -95,14 +95,14 @@ function blackout_plugin_admin(&$a, &$o) {
$myurl = Config::get('blackout','url');
if (! is_string($myurl)) { $myurl = "http://www.example.com"; }
$t = get_markup_template( "admin.tpl", "addon/blackout/" );
$o = replace_macros($t, array(
'$submit' => t('Save Settings'),
'$rurl' => array("rurl", "Redirect URL", $myurl, "all your visitors from the web will be redirected to this URL"),
'$startdate' => array("startdate", "Begin of the Blackout<br />(YYYY-MM-DD hh:mm)", $mystart, "format is <em>YYYY</em> year, <em>MM</em> month, <em>DD</em> day, <em>hh</em> hour and <em>mm</em> minute"),
'$enddate' => array("enddate", "End of the Blackout<br />(YYYY-MM-DD hh:mm)", $myend, ""),
));
$o = replace_macros($t, [
'$submit' => t('Save Settings'),
'$rurl' => ["rurl", "Redirect URL", $myurl, "all your visitors from the web will be redirected to this URL"],
'$startdate' => ["startdate", "Begin of the Blackout<br />(YYYY-MM-DD hh:mm)", $mystart, "format is <em>YYYY</em> year, <em>MM</em> month, <em>DD</em> day, <em>hh</em> hour and <em>mm</em> minute"],
'$enddate' => ["enddate", "End of the Blackout<br />(YYYY-MM-DD hh:mm)", $myend, ""],
]);
$date1 = DateTime::createFromFormat('Y-m-d G:i', $mystart);
$date2 = DateTime::createFromFormat('Y-m-d G:i', $myend);
if ($date2 < $date1) {

View File

@ -6,7 +6,7 @@
* Description: block people
* Version: 1.0
* Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
*
*
*/
use Friendica\Core\PConfig;
@ -141,7 +141,7 @@ function blockem_prepare_body(&$a,&$b) {
}
if($found) {
$rnd = random_string(8);
$b['html'] = '<div id="blockem-wrap-' . $rnd . '" class="fakelink" onclick=openClose(\'blockem-' . $rnd . '\'); >' . sprintf( t('Blocked %s - Click to open/close'),$word ) . '</div><div id="blockem-' . $rnd . '" style="display: none; " >' . $b['html'] . '</div>';
$b['html'] = '<div id="blockem-wrap-' . $rnd . '" class="fakelink" onclick=openClose(\'blockem-' . $rnd . '\'); >' . sprintf( t('Blocked %s - Click to open/close'),$word ) . '</div><div id="blockem-' . $rnd . '" style="display: none; " >' . $b['html'] . '</div>';
}
}
@ -218,7 +218,7 @@ function blockem_init(&$a) {
}
if(array_key_exists('unblock',$_GET) && $_GET['unblock']) {
$arr = explode(',',$words);
$newarr = array();
$newarr = [];
if(count($arr)) {
foreach($arr as $x) {

View File

@ -57,12 +57,12 @@ function buffer_content(&$a) {
function buffer_plugin_admin(&$a, &$o){
$t = get_markup_template( "admin.tpl", "addon/buffer/" );
$o = replace_macros($t, array(
$o = replace_macros($t, [
'$submit' => t('Save Settings'),
// name, label, value, help, [extra values]
'$client_id' => array('client_id', t('Client ID'), Config::get('buffer', 'client_id' ), ''),
'$client_secret' => array('client_secret', t('Client Secret'), Config::get('buffer', 'client_secret' ), ''),
));
'$client_id' => ['client_id', t('Client ID'), Config::get('buffer', 'client_id' ), ''],
'$client_secret' => ['client_secret', t('Client Secret'), Config::get('buffer', 'client_secret' ), ''],
]);
}
function buffer_plugin_admin_post(&$a){
$client_id = ((x($_POST,'client_id')) ? notags(trim($_POST['client_id'])) : '');
@ -369,7 +369,7 @@ function buffer_send(App $a, &$b)
elseif ($profile->service == "google")
$post["text"] .= html_entity_decode("&#x00A0;", ENT_QUOTES, 'UTF-8'); // Send a special blank to identify the post through the "fromgplus" addon
$message = array();
$message = [];
$message["text"] = $post["text"];
$message["profile_ids[]"] = $profile->id;
$message["shorten"] = false;

View File

@ -12,7 +12,7 @@
public $ok = false;
private $endpoints = array(
private $endpoints = [
'/user' => 'get',
'/profiles' => 'get',
@ -37,9 +37,9 @@
'/info/configuration' => 'get',
);
];
public $errors = array(
public $errors = [
'invalid-endpoint' => 'The endpoint you supplied does not appear to be valid.',
'403' => 'Permission denied.',
@ -77,7 +77,7 @@
'1042' => 'User did not save successfully.',
'1050' => 'Client could not be found.',
'1051' => 'No authorization to access client.',
);
];
function __construct($client_id = '', $client_secret = '', $callback_url = '', $access_token = '') {
if ($client_id) $this->set_client_id($client_id);
@ -110,7 +110,7 @@
if (!$ok) return $this->error('invalid-endpoint');
}
if (!$data || !is_array($data)) $data = array();
if (!$data || !is_array($data)) $data = [];
$data['access_token'] = $this->access_token;
$method = $this->endpoints[$done_endpoint]; //get() or post()
@ -130,17 +130,17 @@
}
function error($error) {
return (object) array('error' => $this->errors[$error]);
return (object) ['error' => $this->errors[$error]];
}
function create_access_token_url() {
$data = array(
$data = [
'code' => $this->code,
'grant_type' => 'authorization_code',
'client_id' => $this->client_id,
'client_secret' => $this->client_secret,
'redirect_uri' => $this->callback_url,
);
];
$obj = $this->post($this->access_token_url, $data);
$this->access_token = $obj->access_token;
@ -150,15 +150,15 @@
function req($url = '', $data = '', $post = true) {
if (!$url) return false;
if (!$data || !is_array($data)) $data = array();
if (!$data || !is_array($data)) $data = [];
$options = array(CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false);
$options = [CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false];
if ($post) {
$options += array(
$options += [
CURLOPT_POST => $post,
CURLOPT_POSTFIELDS => $data
);
];
} else {
$url .= '?' . http_build_query($data);
}

View File

@ -62,27 +62,27 @@ function communityhome_home(&$a, &$o){
$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="'.$a->get_baseurl().'/addon/communityhome/communityhome.css" media="all" />';
if (!Config::get('communityhome','hidelogin')){
$aside = array(
$aside = [
'$tab_1' => t('Login'),
'$tab_2' => t('OpenID'),
'$noOid' => Config::get('system','no_openid'),
);
];
// login form
$aside['$login_title'] = t('Login');
$aside['$login_form'] = Login::form($a->query_string, $a->config['register_policy'] == REGISTER_CLOSED ? false : true);
} else {
$aside = array(
$aside = [
//'$tab_1' => t('Login'),
//'$tab_2' => t('OpenID'),
//'$noOid' => Config::get('system','no_openid'),
);
];
}
// last 12 users
if (Config::get('communityhome','showlastusers')){
$aside['$lastusers_title'] = t('Latest users');
$aside['$lastusers_items'] = array();
$aside['$lastusers_items'] = [];
$sql_extra = "";
$publish = (Config::get('system','publish_all') ? '' : " AND `publish` = 1 " );
$order = " ORDER BY `register_date` DESC ";
@ -99,12 +99,12 @@ function communityhome_home(&$a, &$o){
$photo = 'thumb';
foreach($r as $rr) {
$profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
$entry = replace_macros($tpl,array(
$entry = replace_macros($tpl,[
'$id' => $rr['id'],
'$profile_link' => $profile_link,
'$photo' => $a->get_cached_avatar_image($rr[$photo]),
'$alt_text' => $rr['name'],
));
]);
$aside['$lastusers_items'][] = $entry;
}
}
@ -127,17 +127,17 @@ function communityhome_home(&$a, &$o){
LIMIT 0,10");
if($r && count($r)) {
$aside['$activeusers_title'] = t('Most active users');
$aside['$activeusers_items'] = array();
$aside['$activeusers_items'] = [];
$photo = 'thumb';
foreach($r as $rr) {
$profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
$entry = replace_macros($tpl,array(
$entry = replace_macros($tpl,[
'$id' => $rr['id'],
'$profile_link' => $profile_link,
'$photo' => $rr[$photo],
'$photo_user' => sprintf("%s (%s posts, %s contacts)",$rr['name'], ($rr['items']?$rr['items']:'0'), ($rr['contacts']?$rr['contacts']:'0'))
));
]);
$aside['$activeusers_items'][] = $entry;
}
}
@ -145,7 +145,7 @@ function communityhome_home(&$a, &$o){
// last 12 photos
if (Config::get('communityhome','showlastphotos')){
$aside['$photos_title'] = t('Latest photos');
$aside['$photos_items'] = array();
$aside['$photos_items'] = [];
$r = q("SELECT `photo`.`id`, `photo`.`resource-id`, `photo`.`scale`, `photo`.`desc`, `user`.`nickname`, `user`.`username` FROM
(SELECT `resource-id`, MAX(`scale`) as maxscale FROM `photo`
WHERE `profile`=0 AND `contact-id`=0 AND `album` NOT IN ('Contact Photos', '%s', 'Profile Photos', '%s')
@ -169,13 +169,13 @@ function communityhome_home(&$a, &$o){
$photo_page = $a->get_baseurl() . '/photos/' . $rr['nickname'] . '/image/' . $rr['resource-id'];
$photo_url = $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] .'.jpg';
$entry = replace_macros($tpl,array(
$entry = replace_macros($tpl,[
'$id' => $rr['id'],
'$profile_link' => $photo_page,
'$photo' => $photo_url,
'$photo_user' => $rr['username'],
'$photo_title' => $rr['desc']
));
]);
$aside['$photos_items'][] = $entry;
}
@ -185,7 +185,7 @@ function communityhome_home(&$a, &$o){
// last 10 liked items
if (Config::get('communityhome','showlastlike')){
$aside['$like_title'] = t('Latest likes');
$aside['$like_items'] = array();
$aside['$like_items'] = [];
$r = q("SELECT `T1`.`created`, `T1`.`liker`, `T1`.`liker-link`, `item`.* FROM
(SELECT `parent-uri`, `created`, `author-name` AS `liker`,`author-link` AS `liker-link`
FROM `item` WHERE `verb`='http://activitystrea.ms/schema/1.0/like' GROUP BY `parent-uri` ORDER BY `created` DESC) AS T1
@ -215,7 +215,7 @@ function communityhome_home(&$a, &$o){
default:
if ($rr['resource-id']){
$post_type = t('photo');
$m=array(); preg_match("/\[url=([^]]*)\]/", $rr['body'], $m);
$m=[]; preg_match("/\[url=([^]]*)\]/", $rr['body'], $m);
$rr['plink'] = $m[1];
} else {
$post_type = t('status');

View File

@ -15,7 +15,7 @@ function convert_uninstall() {
}
function convert_app_menu($a,&$b) {
$b['app_menu'][] = '<div class="app-title"><a href="convert">Units Conversion</a></div>';
$b['app_menu'][] = '<div class="app-title"><a href="convert">Units Conversion</a></div>';
}
@ -30,7 +30,7 @@ function convert_module() {}
function convert_content($app) {
include("UnitConvertor.php");
class TP_Converter extends UnitConvertor {
function TP_Converter($lang = "en")
{
@ -39,7 +39,7 @@ include("UnitConvertor.php");
} else {
$dec_point = '.'; $thousand_sep = ",";
}
$this->UnitConvertor($dec_point , $thousand_sep );
} // end func UnitConvertor
@ -47,24 +47,24 @@ include("UnitConvertor.php");
function find_base_unit($from,$to) {
while (list($skey,$sval) = each($this->bases)) {
if ($skey == $from || $to == $skey || in_array($to,$sval) || in_array($from,$sval)) {
return $skey;
return $skey;
}
}
return false;
return false;
}
function getTable($value, $from_unit, $to_unit, $precision) {
if ($base_unit = $this->find_base_unit($from_unit,$to_unit)) {
// A baseunit was found now lets convert from -> $base_unit
$cell ['value'] = $this->convert($value, $from_unit, $base_unit, $precision)." ".$base_unit;
// A baseunit was found now lets convert from -> $base_unit
$cell ['value'] = $this->convert($value, $from_unit, $base_unit, $precision)." ".$base_unit;
$cell ['class'] = ($base_unit == $from_unit || $base_unit == $to_unit) ? "framedred": "";
$cells[] = $cell;
// We now have the base unit and value now lets produce the table;
while (list($key,$val) = each($this->bases[$base_unit])) {
$cell ['value'] = $this->convert($value, $from_unit, $val, $precision)." ".$val;
$cell ['value'] = $this->convert($value, $from_unit, $val, $precision)." ".$val;
$cell ['class'] = ($val == $from_unit || $val == $to_unit) ? "framedred": "";
$cells[] = $cell;
}
@ -83,8 +83,8 @@ include("UnitConvertor.php");
}
$string .= "</tr></table>";
return $string;
}
}
}
}
@ -92,16 +92,16 @@ include("UnitConvertor.php");
$conv = new TP_Converter('en');
$conversions = array(
'Temperature'=>array('base' =>'Celsius',
'conv'=>array(
'Fahrenheit'=>array('ratio'=>1.8, 'offset'=>32),
'Kelvin'=>array('ratio'=>1, 'offset'=>273),
$conversions = [
'Temperature'=>['base' =>'Celsius',
'conv'=>[
'Fahrenheit'=>['ratio'=>1.8, 'offset'=>32],
'Kelvin'=>['ratio'=>1, 'offset'=>273],
'Reaumur'=>0.8
)
),
'Weight' => array('base' =>'kg',
'conv'=>array(
]
],
'Weight' => ['base' =>'kg',
'conv'=>[
'g'=>1000,
'mg'=>1000000,
't'=>0.001,
@ -109,13 +109,13 @@ $conversions = array(
'oz'=>35.274,
'lb'=>2.2046,
'cwt(UK)' => 0.019684,
'cwt(US)' => 0.022046,
'cwt(US)' => 0.022046,
'ton (US)' => 0.0011023,
'ton (UK)' => 0.0009842
)
),
'Distance' => array('base' =>'km',
'conv'=>array(
]
],
'Distance' => ['base' =>'km',
'conv'=>[
'm'=>1000,
'dm'=>10000,
'cm'=>100000,
@ -127,25 +127,25 @@ $conversions = array(
'yd'=>1093.6,
'furlong'=>4.970969537898672,
'fathom'=>546.8066491688539
)
),
'Area' => array('base' =>'km 2',
'conv'=>array(
]
],
'Area' => ['base' =>'km 2',
'conv'=>[
'ha'=>100,
'acre'=>247.105,
'm 2'=>pow(1000,2),
'dm 2'=>pow(10000,2),
'cm 2'=>pow(100000,2),
'mm 2'=>pow(1000000,2),
'mm 2'=>pow(1000000,2),
'mile 2'=>pow(0.62137,2),
'naut.miles 2'=>pow(0.53996,2),
'in 2'=>pow(39370,2),
'ft 2'=>pow(3280.8,2),
'yd 2'=>pow(1093.6,2),
)
),
'Volume' => array('base' =>'m 3',
'conv'=>array(
]
],
'Volume' => ['base' =>'m 3',
'conv'=>[
'in 3'=>61023.6,
'ft 3'=>35.315,
'cm 3'=>pow(10,6),
@ -161,22 +161,22 @@ $conversions = array(
'fl oz' => 33814.02,
'tablespoon' => 67628.04,
'teaspoon' => 202884.1,
'pt (UK)'=>1000/0.56826,
'pt (UK)'=>1000/0.56826,
'barrel petroleum'=>1000/158.99,
'Register Tons'=>2.832,
'Register Tons'=>2.832,
'Ocean Tons'=>1.1327
)
),
'Speed' =>array('base' =>'kmph',
'conv'=>array(
]
],
'Speed' =>['base' =>'kmph',
'conv'=>[
'mps'=>0.0001726031,
'milesph'=>0.62137,
'knots'=>0.53996,
'mach STP'=>0.0008380431,
'c (warp)'=>9.265669e-10
)
)
);
]
]
];
while (list($key,$val) = each($conversions)) {
@ -223,6 +223,6 @@ while (list($key,$val) = each($conversions)) {
$o .= '</select>';
$o .= '<input type="submit" name="Submit" value="Submit" /></form>';
return $o;
}

View File

@ -1,6 +1,6 @@
<?php
/**
* Name: Current Weather
* Name: Current Weather
* Description: Shows current weather conditions for user's location on their network page.
* Version: 1.1
* Author: Tony Baldwin <http://friendica.tonybaldwin.info/u/t0ny>
@ -47,7 +47,7 @@ function getWeather( $loc, $units='metric', $lang='en', $appid='', $cachetime=0)
} else {
$desc = (string)$res->weather['value'].', '.(string)$res->clouds['name'];
}
$r = array(
$r = [
'city'=> (string) $res->city['name'][0],
'country' => (string) $res->city->country[0],
'lat' => (string) $res->city->coord['lat'],
@ -59,7 +59,7 @@ function getWeather( $loc, $units='metric', $lang='en', $appid='', $cachetime=0)
'wind' => (string)$res->wind->speed['name'].' ('.(string)$res->wind->speed['value'].$wunit.')',
'update' => (string)$res->lastupdate['value'],
'icon' => (string)$res->weather['icon']
);
];
PConfig::set(local_user(), 'curweather', 'last', $now->getTimestamp());
Cache::set('curweather'.md5($url), serialize($r), CACHE_HOUR);
return $r;
@ -111,7 +111,7 @@ function curweather_network_mod_init(&$fk_app,&$b) {
if ($ok) {
$t = get_markup_template("widget.tpl", "addon/curweather/" );
$curweather = replace_macros ($t, array(
$curweather = replace_macros ($t, [
'$title' => t("Current Weather"),
'$icon' => proxy_url('http://openweathermap.org/img/w/'.$res['icon'].'.png'),
'$city' => $res['city'],
@ -119,20 +119,20 @@ function curweather_network_mod_init(&$fk_app,&$b) {
'$lat' => $res['lat'],
'$description' => $res['descripion'],
'$temp' => $res['temperature'],
'$relhumidity' => array('caption'=>t('Relative Humidity'), 'val'=>$res['humidity']),
'$pressure' => array('caption'=>t('Pressure'), 'val'=>$res['pressure']),
'$wind' => array('caption'=>t('Wind'), 'val'=> $res['wind']),
'$relhumidity' => ['caption'=>t('Relative Humidity'), 'val'=>$res['humidity']],
'$pressure' => ['caption'=>t('Pressure'), 'val'=>$res['pressure']],
'$wind' => ['caption'=>t('Wind'), 'val'=> $res['wind']],
'$lastupdate' => t('Last Updated').': '.$res['update'].'UTC',
'$databy' => t('Data by'),
'$showonmap' => t('Show on map')
));
]);
} else {
$t = get_markup_template('widget-error.tpl', 'addon/curweather/');
$curweather = replace_macros( $t, array(
$curweather = replace_macros( $t, [
'$problem' => t('There was a problem accessing the weather data. But have a look'),
'$rpt' => $rpt,
'$atOWM' => t('at OpenWeatherMap')
));
]);
}
$fk_app->page['aside'] = $curweather.$fk_app->page['aside'];
@ -161,25 +161,25 @@ function curweather_plugin_settings(&$a,&$s) {
$curweather_loc = PConfig::get(local_user(), 'curweather', 'curweather_loc');
$curweather_units = PConfig::get(local_user(), 'curweather', 'curweather_units');
$appid = Config::get('curweather','appid');
if ($appid=="") {
if ($appid=="") {
$noappidtext = t('No APPID found, please contact your admin to obtain one.');
} else {
$noappidtext = '';
}
$enable = intval(PConfig::get(local_user(),'curweather','curweather_enable'));
$enable_checked = (($enable) ? ' checked="checked" ' : '');
// load template and replace the macros
$t = get_markup_template("settings.tpl", "addon/curweather/" );
$s = replace_macros ($t, array(
'$submit' => t('Save Settings'),
$s = replace_macros ($t, [
'$submit' => t('Save Settings'),
'$header' => t('Current Weather').' '.t('Settings'),
'$noappidtext' => $noappidtext,
'$info' => t('Enter either the name of your location or the zip code.'),
'$curweather_loc' => array( 'curweather_loc', t('Your Location'), $curweather_loc, t('Identifier of your location (name or zip code), e.g. <em>Berlin,DE</em> or <em>14476,DE</em>.') ),
'$curweather_units' => array( 'curweather_units', t('Units'), $curweather_units, t('select if the temperature should be displayed in &deg;C or &deg;F'), array('metric'=>'°C', 'imperial'=>'°F')),
'$enabled' => array( 'curweather_enable', t('Show weather data'), $enable, '')
));
'$curweather_loc' => [ 'curweather_loc', t('Your Location'), $curweather_loc, t('Identifier of your location (name or zip code), e.g. <em>Berlin,DE</em> or <em>14476,DE</em>.') ],
'$curweather_units' => [ 'curweather_units', t('Units'), $curweather_units, t('select if the temperature should be displayed in &deg;C or &deg;F'), ['metric'=>'°C', 'imperial'=>'°F']],
'$enabled' => [ 'curweather_enable', t('Show weather data'), $enable, '']
]);
return;
}
@ -200,9 +200,9 @@ function curweather_plugin_admin (&$a, &$o) {
$appid = Config::get('curweather','appid');
$cachetime = Config::get('curweather','cachetime');
$t = get_markup_template("admin.tpl", "addon/curweather/" );
$o = replace_macros ($t, array(
$o = replace_macros ($t, [
'$submit' => t('Save Settings'),
'$cachetime' => array('cachetime', t('Caching Interval'), $cachetime, t('For how long should the weather data be cached? Choose according your OpenWeatherMap account type.'), array('0'=>t('no cache'), '300'=>'5 '.t('minutes'), '900'=>'15 '.t('minutes'), '1800'=>'30 '.t('minutes'), '3600'=>'60 '.t('minutes'))),
'$appid' => array('appid', t('Your APPID'), $appid, t('Your API key provided by OpenWeatherMap'))
));
'$cachetime' => ['cachetime', t('Caching Interval'), $cachetime, t('For how long should the weather data be cached? Choose according your OpenWeatherMap account type.'), ['0'=>t('no cache'), '300'=>'5 '.t('minutes'), '900'=>'15 '.t('minutes'), '1800'=>'30 '.t('minutes'), '3600'=>'60 '.t('minutes')]],
'$appid' => ['appid', t('Your APPID'), $appid, t('Your API key provided by OpenWeatherMap')]
]);
}

View File

@ -16,13 +16,13 @@ define("CALDAV_NAMESPACE_PRIVATE", 1);
define("CALDAV_FRIENDICA_MINE", "friendica-mine");
define("CALDAV_FRIENDICA_CONTACTS", "friendica-contacts");
$GLOBALS["CALDAV_PRIVATE_SYSTEM_CALENDARS"] = array(CALDAV_FRIENDICA_MINE, CALDAV_FRIENDICA_CONTACTS);
$GLOBALS["CALDAV_PRIVATE_SYSTEM_BACKENDS"] = array("Sabre_CalDAV_Backend_Friendica");
$GLOBALS["CALDAV_PRIVATE_SYSTEM_CALENDARS"] = [CALDAV_FRIENDICA_MINE, CALDAV_FRIENDICA_CONTACTS];
$GLOBALS["CALDAV_PRIVATE_SYSTEM_BACKENDS"] = ["Sabre_CalDAV_Backend_Friendica"];
define("CARDDAV_NAMESPACE_PRIVATE", 1);
define("CARDDAV_FRIENDICA_CONTACT", "friendica");
$GLOBALS["CARDDAV_PRIVATE_SYSTEM_ADDRESSBOOKS"] = array(CARDDAV_FRIENDICA_CONTACT);
$GLOBALS["CARDDAV_PRIVATE_SYSTEM_BACKENDS"] = array("Sabre_CardDAV_Backend_Friendica");
$GLOBALS["CARDDAV_PRIVATE_SYSTEM_ADDRESSBOOKS"] = [CARDDAV_FRIENDICA_CONTACT];
$GLOBALS["CARDDAV_PRIVATE_SYSTEM_BACKENDS"] = ["Sabre_CardDAV_Backend_Friendica"];
$GLOBALS["CALDAV_ACL_PLUGIN_CLASS"] = "Sabre_DAVACL_Plugin_Friendica";
@ -106,7 +106,7 @@ function dav_compat_principal2namespace($principalUri = "")
if (strpos($principalUri, "principals/users/") !== 0) return null;
$username = substr($principalUri, strlen("principals/users/"));
return array("namespace" => CALDAV_NAMESPACE_PRIVATE, "namespace_id" => dav_compat_username2id($username));
return ["namespace" => CALDAV_NAMESPACE_PRIVATE, "namespace_id" => dav_compat_username2id($username)];
}
@ -200,13 +200,13 @@ function wdcal_calendar_factory_by_id($calendar_id)
*/
function wdcal_create_std_calendars_get_statements($user_id, $withcheck = true)
{
$stms = array();
$stms = [];
$a = get_app();
$uris = array(
$uris = [
'private' => t("Private Calendar"),
CALDAV_FRIENDICA_MINE => t("Friendica Events: Mine"),
CALDAV_FRIENDICA_CONTACTS => t("Friendica Events: Contacts"),
);
];
foreach ($uris as $uri => $name) {
$cals = q("SELECT * FROM %s%scalendars WHERE `namespace` = %d AND `namespace_id` = %d AND `uri` = '%s'",
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, CALDAV_NAMESPACE_PRIVATE, IntVal($user_id), dbesc($uri));
@ -242,12 +242,12 @@ function wdcal_create_std_calendars()
*/
function wdcal_create_std_addressbooks_get_statements($user_id, $withcheck = true)
{
$stms = array();
$stms = [];
$a = get_app();
$uris = array(
$uris = [
'private' => t("Private Addresses"),
CARDDAV_FRIENDICA_CONTACT => t("Friendica Contacts"),
);
];
foreach ($uris as $uri => $name) {
$cals = q("SELECT * FROM %s%saddressbooks WHERE `namespace` = %d AND `namespace_id` = %d AND `uri` = '%s'",
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, CALDAV_NAMESPACE_PRIVATE, IntVal($user_id), dbesc($uri));

View File

@ -7,7 +7,7 @@
*/
function dav_get_update_statements($from_version)
{
$stms = array();
$stms = [];
if ($from_version == 1) {
$stms[] = "ALTER TABLE `dav_calendarobjects`
@ -30,7 +30,7 @@ function dav_get_update_statements($from_version)
`dav_locks` ,
`dav_notifications` ;";
$stms = array_merge($stms, dav_get_create_statements(array("dav_calendarobjects")));
$stms = array_merge($stms, dav_get_create_statements(["dav_calendarobjects"]));
$user_ids = q("SELECT DISTINCT `uid` FROM %s%scalendars", CALDAV_SQL_DB, CALDAV_SQL_PREFIX);
foreach ($user_ids as $user) $stms = array_merge($stms, wdcal_create_std_calendars_get_statements($user["uid"], false));
@ -43,7 +43,7 @@ function dav_get_update_statements($from_version)
}
if (in_array($from_version, array(1, 2))) {
if (in_array($from_version, [1, 2])) {
$stms[] = "CREATE TABLE IF NOT EXISTS `dav_addressbooks` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`namespace` mediumint(9) NOT NULL,
@ -80,9 +80,9 @@ function dav_get_update_statements($from_version)
* @param array $except
* @return array
*/
function dav_get_create_statements($except = array())
function dav_get_create_statements($except = [])
{
$arr = array();
$arr = [];
if (!in_array("dav_caldav_log", $except)) $arr[] = "CREATE TABLE IF NOT EXISTS `dav_caldav_log` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
@ -240,7 +240,7 @@ function dav_check_tables()
function dav_create_tables()
{
$stms = dav_get_create_statements();
$errors = array();
$errors = [];
foreach ($stms as $st) { // @TODO Friendica-dependent
dba::e($st);
@ -258,10 +258,10 @@ function dav_create_tables()
function dav_upgrade_tables()
{
$ver = dav_check_tables();
if (!in_array($ver, array(1, 2))) return array("Unknown error");
if (!in_array($ver, [1, 2])) return ["Unknown error"];
$stms = dav_get_update_statements($ver);
$errors = array();
$errors = [];
foreach ($stms as $st) { // @TODO Friendica-dependent
dba::e($st);

View File

@ -124,7 +124,7 @@ class Sabre_CalDAV_Backend_Friendica extends Sabre_CalDAV_Backend_Virtual
$summary = (($row["summary"]) ? $row["summary"] : substr(preg_replace("/\[[^\]]*\]/", "", $row["desc"]), 0, 100));
return array(
return [
"jq_id" => $row["id"],
"ev_id" => $row["id"],
"summary" => escape_tags($summary),
@ -142,7 +142,7 @@ class Sabre_CalDAV_Backend_Friendica extends Sabre_CalDAV_Backend_Virtual
"url_detail" => $base_path . "/events/event/" . $row["id"],
"url_edit" => "",
"special_type" => ($row["type"] == "birthday" ? "birthday" : ""),
);
];
}
@ -179,7 +179,7 @@ class Sabre_CalDAV_Backend_Friendica extends Sabre_CalDAV_Backend_Virtual
if (is_numeric($date_to)) $sql_where .= " AND `start` <= '" . date("Y-m-d H:i:s", $date_to) . "'";
else $sql_where .= " AND `start` <= '" . dbesc($date_to) . "'";
}
$ret = array();
$ret = [];
$r = q("SELECT * FROM `event` WHERE `uid` = %d " . $sql_where . " ORDER BY `start`", IntVal($calendar["namespace_id"]));
@ -214,21 +214,21 @@ class Sabre_CalDAV_Backend_Friendica extends Sabre_CalDAV_Backend_Virtual
public function getCalendarsForUser($principalUri)
{
$n = dav_compat_principal2namespace($principalUri);
if ($n["namespace"] != $this->getNamespace()) return array();
if ($n["namespace"] != $this->getNamespace()) return [];
$cals = q("SELECT * FROM %s%scalendars WHERE `namespace` = %d AND `namespace_id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $this->getNamespace(), IntVal($n["namespace_id"]));
$ret = array();
$ret = [];
foreach ($cals as $cal) {
if (!in_array($cal["uri"], $GLOBALS["CALDAV_PRIVATE_SYSTEM_CALENDARS"])) continue;
$dat = array(
$dat = [
"id" => $cal["id"],
"uri" => $cal["uri"],
"principaluri" => $principalUri,
'{' . Sabre_CalDAV_Plugin::NS_CALENDARSERVER . '}getctag' => $cal['ctag'] ? $cal['ctag'] : '0',
'{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}supported-calendar-component-set' => new Sabre_CalDAV_Property_SupportedCalendarComponentSet(array("VEVENT")),
'{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}supported-calendar-component-set' => new Sabre_CalDAV_Property_SupportedCalendarComponentSet(["VEVENT"]),
"calendar_class" => "Sabre_CalDAV_Calendar_Virtual",
);
];
foreach ($this->propertyMap as $key=> $field) $dat[$key] = $cal[$field];
$ret[] = $dat;

View File

@ -46,13 +46,13 @@ class Sabre_CardDAV_Backend_Friendica extends Sabre_CardDAV_Backend_Virtual
{
$uid = dav_compat_principal2uid($principalUri);
$addressBooks = array();
$addressBooks = [];
$books = q("SELECT id, ctag FROM %s%saddressbooks WHERE `namespace` = %d AND `namespace_id` = %d AND `uri` = '%s'",
CALDAV_SQL_DB, CALDAV_SQL_PREFIX, CARDDAV_NAMESPACE_PRIVATE, IntVal($uid), dbesc(CARDDAV_FRIENDICA_CONTACT));
$ctag = $books[0]["ctag"];
$addressBooks[] = array(
$addressBooks[] = [
'id' => $books[0]["id"],
'uri' => "friendica",
'principaluri' => $principalUri,
@ -61,7 +61,7 @@ class Sabre_CardDAV_Backend_Friendica extends Sabre_CardDAV_Backend_Virtual
'{http://calendarserver.org/ns/}getctag' => $ctag,
'{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}supported-address-data' =>
new Sabre_CardDAV_Property_SupportedAddressData(),
);
];
return $addressBooks;
@ -76,7 +76,7 @@ class Sabre_CardDAV_Backend_Friendica extends Sabre_CardDAV_Backend_Virtual
{
$name = explode(" ", $contact["name"]);
$first_name = $last_name = "";
$middle_name = array();
$middle_name = [];
$num = count($name);
for ($i = 0; $i < $num && $first_name == ""; $i++) if ($name[$i] != "") {
$first_name = $name[$i];
@ -114,14 +114,14 @@ class Sabre_CardDAV_Backend_Friendica extends Sabre_CardDAV_Backend_Virtual
}
$vcard = vcard_source_compile($vcarddata);
return array(
return [
"id" => $contact["id"],
"carddata" => $vcard,
"uri" => $contact["id"] . ".vcf",
"lastmodified" => wdcal_mySql2PhpTime($vcarddata->last_update),
"etag" => md5($vcard),
"size" => strlen($vcard),
);
];
}

View File

@ -26,7 +26,7 @@ class Sabre_DAV_Auth_Backend_Std extends Sabre_DAV_Auth_Backend_AbstractBasic
*/
public function getUsers()
{
return array($this->currentUser);
return [$this->currentUser];
}
/**

View File

@ -61,16 +61,16 @@ class Sabre_DAVACL_PrincipalBackend_Std implements Sabre_DAVACL_IPrincipalBacken
{
// This backend only support principals in one collection
if ($prefixPath !== $this->prefix) return array();
if ($prefixPath !== $this->prefix) return [];
$users = array();
$users = [];
$r = q("SELECT `nickname` FROM `user` WHERE `nickname` = '%s'", escape_tags($this->authBackend->getCurrentUser()) );
foreach ($r as $t) {
$users[] = array(
$users[] = [
'uri' => $this->prefix . '/' . strtolower($t['nickname']),
'{DAV:}displayname' => $t['nickname'],
);
];
}
return $users;
@ -94,24 +94,24 @@ class Sabre_DAVACL_PrincipalBackend_Std implements Sabre_DAVACL_IPrincipalBacken
if ($prefixPath !== $this->prefix) return null;
$r = q("SELECT `nickname` FROM `user` WHERE `nickname` = '%s'", escape_tags($userName) );
if (count($r) == 0) return array();
if (count($r) == 0) return [];
return array(
return [
'uri' => $this->prefix . '/' . strtolower($r[0]['nickname']),
'{DAV:}displayname' => $r[0]['nickname'],
);
];
}
function getGroupMemberSet($principal)
{
return array();
return [];
}
function getGroupMembership($principal)
{
return array();
return [];
}

View File

@ -91,7 +91,7 @@ function wdcal_import_user_ics($calendar_id) {
/** @var Sabre\VObject\Component\VCalendar $vObject */
$vObject = Sabre\VObject\Reader::read($text);
$comp = $vObject->getComponents();
$imported = array();
$imported = [];
foreach ($comp as $c) try {
/** @var Sabre\VObject\Component\VEvent $c */
$uid = $c->__get("UID")->value;
@ -171,18 +171,18 @@ function wdcal_import_user_ics($calendar_id) {
* @param bool $show_nav
* @return string
*/
function wdcal_printCalendar($calendars, $calendars_selected, $data_feed_url, $view = "week", $theme = 0, $height_diff = 175, $readonly = false, $curr_day = "", $add_params = array(), $show_nav = true)
function wdcal_printCalendar($calendars, $calendars_selected, $data_feed_url, $view = "week", $theme = 0, $height_diff = 175, $readonly = false, $curr_day = "", $add_params = [], $show_nav = true)
{
$a = get_app();
$localization = wdcal_local::getInstanceByUser($a->user["uid"]);
if (count($calendars_selected) == 0) foreach ($calendars as $c) {
$prop = $c->getProperties(array("id"));
$prop = $c->getProperties(["id"]);
$calendars_selected[] = $prop["id"];
}
$opts = array(
$opts = [
"view" => $view,
"theme" => $theme,
"readonly" => $readonly,
@ -194,7 +194,7 @@ function wdcal_printCalendar($calendars, $calendars_selected, $data_feed_url, $v
"date_format_dm3" => $localization->dateformat_js_dm3(),
"date_format_full" => $localization->dateformat_datepicker_js(),
"baseurl" => $a->get_baseurl() . "/dav/wdcal/",
);
];
$x = '
<script>
@ -207,7 +207,7 @@ function wdcal_printCalendar($calendars, $calendars_selected, $data_feed_url, $v
<div class="calselect"><strong>Available Calendars:</strong>';
foreach ($calendars as $cal) {
$cal_id = $cal->getProperties(array("id", DAV_DISPLAYNAME));
$cal_id = $cal->getProperties(["id", DAV_DISPLAYNAME]);
$x .= '<label style="margin-left: 10px; margin-right: 10px;"><input type="checkbox" name="cals[]" value="' . $cal_id["id"] . '"';
$found = false;
foreach ($calendars_selected as $pre) if ($pre["id"] == $cal_id["id"]) $found = true;

View File

@ -198,7 +198,7 @@ function dav_content()
} else {
$server = dav_create_server(true, true, false);
$cals = dav_get_current_user_calendars($server, DAV_ACL_READ);
$x = wdcal_printCalendar($cals, array(), $a->get_baseurl() . "/dav/wdcal/feed/", "week", 0, 200);
$x = wdcal_printCalendar($cals, [], $a->get_baseurl() . "/dav/wdcal/feed/", "week", 0, 200);
}
}
} catch (DAVVersionMismatchException $e) {
@ -238,12 +238,12 @@ function dav_event_updated_hook(&$a, &$b)
*/
function dav_profile_tabs_hook(&$a, &$b)
{
$b["tabs"][] = array(
$b["tabs"][] = [
"label" => t('Calendar'),
"url" => $a->get_baseurl() . "/dav/wdcal/",
"sel" => "",
"title" => t('Extended calendar with CalDAV-support'),
);
];
}
@ -261,7 +261,7 @@ function dav_cron(&$a, &$b)
q("UPDATE %s%snotifications SET `notified` = 1 WHERE `id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $not["id"]);
$event = q("SELECT * FROM %s%sjqcalendar WHERE `calendarobject_id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $not["calendarobject_id"]);
$calendar = q("SELECT * FROM %s%scalendars WHERE `id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $not["calendar_id"]);
$users = array();
$users = [];
if (count($calendar) != 1 || count($event) == 0) continue;
switch ($calendar[0]["namespace"]) {
case CALDAV_NAMESPACE_PRIVATE:
@ -274,11 +274,11 @@ function dav_cron(&$a, &$b)
case "email":
case "display": // @TODO implement "Display"
foreach ($users as $user) {
$find = array("%to%", "%event%", "%url%");
$repl = array($user["username"], $event[0]["Summary"], $a->get_baseurl() . "/dav/wdcal/" . $calendar[0]["id"] . "/" . $not["calendarobject_id"] . "/");
$find = ["%to%", "%event%", "%url%"];
$repl = [$user["username"], $event[0]["Summary"], $a->get_baseurl() . "/dav/wdcal/" . $calendar[0]["id"] . "/" . $not["calendarobject_id"] . "/"];
$text_text = str_replace($find, $repl, "Hi %to%!\n\nThe event \"%event%\" is about to begin:\n%url%");
$text_html = str_replace($find, $repl, "Hi %to%!<br>\n<br>\nThe event \"%event%\" is about to begin:<br>\n<a href='" . "%url%" . "'>%url%</a>");
$params = array(
$params = [
'fromName' => FRIENDICA_PLATFORM,
'fromEmail' => t('noreply') . '@' . $a->get_hostname(),
'replyTo' => t('noreply') . '@' . $a->get_hostname(),
@ -287,7 +287,7 @@ function dav_cron(&$a, &$b)
'htmlVersion' => $text_html,
'textVersion' => $text_text,
'additionalMailHeader' => "",
);
];
Emailer::send($params);
}
break;

View File

@ -69,7 +69,7 @@ class Diaspora_Connection {
return ($this->tls) ? 'https' : 'http';
}
private function doHttpRequest($url, $data = array(), $headers = array()) {
private function doHttpRequest($url, $data = [], $headers = []) {
if (0 === strpos($url, '/')) {
$url = $this->getScheme() . '://' . $this->host . $url;
}
@ -122,14 +122,14 @@ class Diaspora_Connection {
return $this->last_http_result;
}
private function doHttpDelete($url, $data = array(), $headers = array()) {
private function doHttpDelete($url, $data = [], $headers = []) {
$this->http_method = 'DELETE';
$this->doHttpRequest($url, $data, $headers);
$this->http_method = null; // reset for next request
}
private function parseAuthenticityToken($str) {
$m = array();
$m = [];
preg_match('/<meta (?:name="csrf-token" content="(.*?)"|content="(.*?)" name="csrf-token")/', $str, $m);
if (empty($m[1]) && !empty($m[2])) {
$token = $m[2];
@ -151,11 +151,11 @@ class Diaspora_Connection {
public function logIn() {
$this->doHttpRequest('/users/sign_in');
$params = array(
$params = [
'user[username]' => $this->user,
'user[password]' => $this->password,
'authenticity_token' => $this->csrf_token
);
];
$this->doHttpRequest('/users/sign_in', $params);
$this->doHttpRequest('/stream');
return (200 === $this->last_http_result->info['http_code']) ? true : false;
@ -163,14 +163,14 @@ class Diaspora_Connection {
public function getAspects() {
$this->doHttpRequest('/bookmarklet');
$m = array();
$m = [];
preg_match('/"aspects"\:(\[.+?\])/', $this->last_http_result->response, $m);
return (!empty($m[1])) ? json_decode($m[1]) : false;
}
public function getServices() {
$this->doHttpRequest('/bookmarklet');
$m = array();
$m = [];
preg_match('/"configured_services"\:(\[.+?\])/', $this->last_http_result->response, $m);
return (!empty($m[1])) ? json_decode($m[1]) : false;
}
@ -196,24 +196,24 @@ class Diaspora_Connection {
return $this->readJsonResponse($this->last_http_result->response);
}
public function postStatusMessage($msg, $aspect_ids = 'all_aspects', $additional_data = array()) {
$data = array(
public function postStatusMessage($msg, $aspect_ids = 'all_aspects', $additional_data = []) {
$data = [
'aspect_ids' => $aspect_ids,
'status_message' => array(
'status_message' => [
'text' => $msg,
'provider_display_name' => $this->provider
)
);
]
];
if (!empty($additional_data)) {
$data += $additional_data;
}
$headers = array(
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'X-CSRF-Token: ' . $this->csrf_token
);
];
$this->http_method = 'POST';
$this->doHttpRequest('/status_messages', json_encode($data), $headers);
@ -228,18 +228,18 @@ class Diaspora_Connection {
}
public function postPhoto($file) {
$params = array(
$params = [
'photo[pending]' => 'true',
'qqfile' => basename($file)
);
];
$query_string = '?' . http_build_query($params);
$headers = array(
$headers = [
'Accept: application/json',
'X-Requested-With: XMLHttpRequest',
'X-CSRF-Token: ' . $this->csrf_token,
'X-File-Name: ' . basename($file),
'Content-Type: application/octet-stream',
);
];
if ($size = @filesize($file)) {
$headers[] = "Content-Length: $size";
}
@ -249,14 +249,14 @@ class Diaspora_Connection {
}
public function deletePost($id) {
$headers = array('X-CSRF-Token: ' . $this->csrf_token);
$this->doHttpDelete("/posts/$id", array(), $headers);
$headers = ['X-CSRF-Token: ' . $this->csrf_token];
$this->doHttpDelete("/posts/$id", [], $headers);
return (204 === $this->last_http_result->info['http_code']) ? true : false;
}
public function deleteComment($id) {
$headers = array('X-CSRF-Token: ' . $this->csrf_token);
$this->doHttpDelete("/comments/$id", array(), $headers);
$headers = ['X-CSRF-Token: ' . $this->csrf_token];
$this->doHttpDelete("/comments/$id", [], $headers);
return (204 === $this->last_http_result->info['http_code']) ? true : false;
}

View File

@ -305,7 +305,7 @@ function diaspora_send(&$a,&$b) {
logger('diaspora_send: all values seem to be okay', LOGGER_DEBUG);
require_once('include/bb2diaspora.php');
$tag_arr = array();
$tag_arr = [];
$tags = '';
$x = preg_match_all('/\#\[(.*?)\](.*?)\[/',$b['tag'],$matches,PREG_SET_ORDER);
@ -364,7 +364,7 @@ function diaspora_send(&$a,&$b) {
if (count($r))
$a->contact = $r[0]["id"];
$s = serialize(array('url' => $url, 'item' => $b['id'], 'post' => $body));
$s = serialize(['url' => $url, 'item' => $b['id'], 'post' => $body]);
require_once('include/queue_fn.php');
add_to_queue($a->contact,NETWORK_DIASPORA2,$s);
notice(t('Diaspora post failed. Queued for retry.').EOL);

View File

@ -158,7 +158,7 @@ function dwpost_send(&$a,&$b) {
if($b['parent'] != $b['id'])
return;
// dreamwidth post in the LJ user's timezone.
// dreamwidth post in the LJ user's timezone.
// Hopefully the person's Friendica account
// will be set to the same thing.
@ -168,7 +168,7 @@ function dwpost_send(&$a,&$b) {
intval($b['uid'])
);
if($x && strlen($x[0]['timezone']))
$tz = $x[0]['timezone'];
$tz = $x[0]['timezone'];
$dw_username = PConfig::get($b['uid'],'dwpost','dw_username');
$dw_password = PConfig::get($b['uid'],'dwpost','dw_password');
@ -221,7 +221,7 @@ EOT;
logger('dwpost: data: ' . $xml, LOGGER_DATA);
if($dw_blog !== 'test')
$x = post_url($dw_blog,$xml,array("Content-Type: text/xml"));
$x = post_url($dw_blog,$xml,["Content-Type: text/xml"]);
logger('posted to dreamwidth: ' . ($x) ? $x : '', LOGGER_DEBUG);
}