diff --git a/.gitattributes b/.gitattributes index 4be1c91852..18ba9e0758 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,2 @@ -# Disable LF normalization for all files -* -text \ No newline at end of file +# Disable LF normalization for all files +* -text diff --git a/.gitignore b/.gitignore index 9e6504184c..12dd3b49ea 100644 --- a/.gitignore +++ b/.gitignore @@ -1,61 +1,67 @@ -favicon.* -.htconfig.php -.htpreconfig.php -\#* -include/jquery-1.4.2.min.js -*.log -*.out -*.version* -favicon.* -home.html -addon -*.orig -*~ -robots.txt - -#ignore documentation, it should be newly built -doc/html - -#ignore reports, should be generted with every build -report/ - -#ignore config files from eclipse, we don't want IDE files in our repository -.project -.buildpath -.externalToolBuilders -.settings -#ignore OSX .DS_Store files -.DS_Store - -/nbproject/private/ - -#ignore smarty cache -/view/smarty3/compiled/ - -#ignore cache folders -/privacy_image_cache/ -/photo/ -/proxy/ -nbproject - -#ignore vagrant dir -.vagrant/ - -#ignore local folder -/local/ - -#ignore config files from Visual Studio -/.vs/ -/php_friendica.phpproj -/php_friendica.sln -/php_friendica.phpproj.user - -#ignore things from transifex-client -venv/ - -#ignore Composer dependencies -/vendor -/view/asset - -#ignore config files from JetBrains -/.idea +favicon.* +.htconfig.php +.htpreconfig.php +\#* +include/jquery-1.4.2.min.js +*.log +*.out +*.version* +favicon.* +home.html +addon +*~ +robots.txt + +#ignore documentation, it should be newly built +doc/html + +#ignore reports, should be generted with every build +report/ + +#ignore config files from eclipse, we don't want IDE files in our repository +.project +.buildpath +.externalToolBuilders +.settings + +#ignore OSX .DS_Store files +.DS_Store + +#ignore NetBeans IDE's private files (at least) +/nbproject/private/ + +#ignore smarty cache +/view/smarty3/compiled/ + +#ignore cache folders +/privacy_image_cache/ +/photo/ +/proxy/ +nbproject + +#ignore vagrant dir +.vagrant/ + +#ignore local folder +/local/ + +#ignore config files from Visual Studio +/.vs/ +/php_friendica.phpproj +/php_friendica.sln +/php_friendica.phpproj.user + +#ignore things from transifex-client +venv/ + +#ignore all in 'vendor' as `utils/composer.phar install` will bring it back +vendor/* + +#ignore config files from JetBrains +/.idea + +#ignore addons/ directory +addons/ + +#Ignore .htaccess as it may contain local changes +.htaccess diff --git a/.htaccess b/.htaccess-dist similarity index 96% rename from .htaccess rename to .htaccess-dist index 2348cdc38b..a671cc680a 100644 --- a/.htaccess +++ b/.htaccess-dist @@ -4,7 +4,7 @@ AddType audio/ogg .oga #AddHandler php53-cgi .php - + #Apache 2.4 Require all denied @@ -38,4 +38,3 @@ AddType audio/ogg .oga RewriteRule ^(.*)$ index.php?pagename=$1 [E=REMOTE_USER:%{HTTP:Authorization},L,QSA] - diff --git a/bin/daemon.php b/bin/daemon.php index 6b0e377a3a..b51dd392ef 100755 --- a/bin/daemon.php +++ b/bin/daemon.php @@ -38,7 +38,7 @@ if (substr($directory, 0, 1) != "/") { } $directory = realpath($directory."/.."); -@include($directory."/.htconfig.php"); +include $directory."/.htconfig.php"; if (!isset($pidfile)) { die('Please specify a pid file in the variable $pidfile in the .htconfig.php. For example:'."\n". diff --git a/boot.php b/boot.php index ae2f4b1a06..6945026012 100644 --- a/boot.php +++ b/boot.php @@ -1076,6 +1076,7 @@ function is_site_admin() $adminlist = explode(",", str_replace(" ", "", $a->config['admin_email'])); //if(local_user() && x($a->user,'email') && x($a->config,'admin_email') && ($a->user['email'] === $a->config['admin_email'])) + /// @TODO This if() + 2 returns can be shrinked into one return if (local_user() && x($a->user, 'email') && x($a->config, 'admin_email') && in_array($a->user['email'], $adminlist)) { return true; } @@ -1173,7 +1174,7 @@ function random_digits($digits) { $rn = ''; for ($i = 0; $i < $digits; $i++) { - /// @TODO rand() is different to mt_rand() and maybe lesser "random" + /// @TODO Avoid rand/mt_rand, when it comes to cryptography, they are generating predictable (seedable) numbers. $rn .= rand(0, 9); } return $rn; @@ -1187,7 +1188,7 @@ function get_server() $server = "https://dir.friendica.social"; } - return($server); + return $server; } function get_temppath() @@ -1236,7 +1237,7 @@ function get_cachefile($file, $writemode = true) $cache = get_itemcachepath(); if ((!$cache) || (!is_dir($cache))) { - return(""); + return ""; } $subfolder = $cache . "/" . substr($file, 0, 2); @@ -1250,7 +1251,6 @@ function get_cachefile($file, $writemode = true) } } - /// @TODO no need to put braces here return $cachepath; } @@ -1357,7 +1357,6 @@ function get_spoolpath() return ""; } - if (!function_exists('exif_imagetype')) { function exif_imagetype($file) { @@ -1395,7 +1394,7 @@ function validate_include(&$file) } // Simply return flag - return ($valid); + return $valid; } function current_load() diff --git a/mods/readme.txt b/doc/server-config/readme.txt similarity index 100% rename from mods/readme.txt rename to doc/server-config/readme.txt diff --git a/mods/sample-Lighttpd.config b/doc/server-config/sample-Lighttpd.config similarity index 100% rename from mods/sample-Lighttpd.config rename to doc/server-config/sample-Lighttpd.config diff --git a/mods/sample-nginx-reverse-proxy.config b/doc/server-config/sample-nginx-reverse-proxy.config similarity index 100% rename from mods/sample-nginx-reverse-proxy.config rename to doc/server-config/sample-nginx-reverse-proxy.config diff --git a/mods/sample-nginx.config b/doc/server-config/sample-nginx.config similarity index 100% rename from mods/sample-nginx.config rename to doc/server-config/sample-nginx.config diff --git a/include/api.php b/include/api.php index 72997dd3a0..ae2f06406e 100644 --- a/include/api.php +++ b/include/api.php @@ -935,7 +935,7 @@ function api_reformat_xml(&$item, &$key) * * @return string The XML data */ -function api_create_xml($data, $root_element) +function api_create_xml(array $data, $root_element) { $childname = key($data); $data2 = array_pop($data); @@ -960,7 +960,7 @@ function api_create_xml($data, $root_element) $i = 1; foreach ($data2 as $item) { - $data4[$i++.":".$childname] = $item; + $data4[$i++ . ":" . $childname] = $item; } $data2 = $data4; @@ -4379,7 +4379,6 @@ function api_fr_photo_create_update($type) throw new InternalServerErrorException("unknown error - this error on uploading or updating a photo should never happen"); } - /** * @brief delete a single photo from the database through api * @@ -4518,6 +4517,7 @@ function api_account_update_profile_image($type) } else { throw new InternalServerErrorException('Unsupported filetype'); } + // change specified profile or all profiles to the new resource-id if ($is_default_profile) { $condition = ["`profile` AND `resource-id` != ? AND `uid` = ?", $data['photo']['id'], api_user()]; @@ -4531,7 +4531,6 @@ function api_account_update_profile_image($type) Contact::updateSelfFromUserID(api_user(), true); // Update global directory in background - //$user = api_get_user(get_app()); $url = System::baseUrl() . '/profile/' . get_app()->user['nickname']; if ($url && strlen(Config::get('system', 'directory'))) { Worker::add(PRIORITY_LOW, "Directory", $url); @@ -5273,27 +5272,27 @@ function api_in_reply_to($item) /** * - * @param string $Text + * @param string $text * * @return string */ -function api_clean_plain_items($Text) +function api_clean_plain_items($text) { $include_entities = strtolower(x($_REQUEST, 'include_entities') ? $_REQUEST['include_entities'] : "false"); - $Text = BBCode::cleanPictureLinks($Text); + $text = BBCode::cleanPictureLinks($text); $URLSearchString = "^\[\]"; - $Text = preg_replace("/([!#@])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$1$3', $Text); + $text = preg_replace("/([!#@])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$1$3', $text); if ($include_entities == "true") { - $Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '[url=$1]$1[/url]', $Text); + $text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '[url=$1]$1[/url]', $text); } // Simplify "attachment" element - $Text = api_clean_attachments($Text); + $text = api_clean_attachments($text); - return($Text); + return $text; } /** diff --git a/include/conversation.php b/include/conversation.php index ae12cf4827..43f0a445da 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -116,7 +116,7 @@ function localize_item(&$item) { $item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']); } - /// @Separted ??? + /// @TODO Separted ??? $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">"; if (activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE) @@ -162,22 +162,19 @@ function localize_item(&$item) { if (activity_match($item['verb'], ACTIVITY_LIKE)) { $bodyverb = L10n::t('%1$s likes %2$s\'s %3$s'); - } - elseif (activity_match($item['verb'], ACTIVITY_DISLIKE)) { + } elseif (activity_match($item['verb'], ACTIVITY_DISLIKE)) { $bodyverb = L10n::t('%1$s doesn\'t like %2$s\'s %3$s'); - } - elseif (activity_match($item['verb'], ACTIVITY_ATTEND)) { + } elseif (activity_match($item['verb'], ACTIVITY_ATTEND)) { $bodyverb = L10n::t('%1$s attends %2$s\'s %3$s'); - } - elseif (activity_match($item['verb'], ACTIVITY_ATTENDNO)) { + } elseif (activity_match($item['verb'], ACTIVITY_ATTENDNO)) { $bodyverb = L10n::t('%1$s doesn\'t attend %2$s\'s %3$s'); - } - elseif (activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) { + } elseif (activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) { $bodyverb = L10n::t('%1$s attends maybe %2$s\'s %3$s'); } - $item['body'] = sprintf($bodyverb, $author, $objauthor, $plink); + $item['body'] = sprintf($bodyverb, $author, $objauthor, $plink); } + if (activity_match($item['verb'], ACTIVITY_FRIEND)) { if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return; @@ -304,8 +301,8 @@ function localize_item(&$item) { $item['body'] = L10n::t('%1$s tagged %2$s\'s %3$s with %4$s', $author, $objauthor, $plink, $tag ); } - if (activity_match($item['verb'], ACTIVITY_FAVORITE)) { + if (activity_match($item['verb'], ACTIVITY_FAVORITE)) { if ($item['object-type'] == "") { return; } @@ -394,10 +391,9 @@ function visible_activity($item) { } } - if (activity_match($item['verb'], ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE) { - if (!($item['self'] && ($item['uid'] == local_user()))) { - return false; - } + // @TODO below if() block can be rewritten to a single line: $isVisible = allConditionsHere; + if (activity_match($item['verb'], ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE && empty($item['self']) && $item['uid'] == local_user()) { + return false; } return true; @@ -1123,7 +1119,7 @@ function builtin_activity_puller($item, &$conv_responses) { $url = '' . htmlentities($item['author-name']) . ''; - if (!$item['thr-parent']) { + if (!x($item, 'thr-parent')) { $item['thr-parent'] = $item['parent-uri']; } @@ -1611,19 +1607,17 @@ function sort_thr_commented(array $a, array $b) return strcmp($b['commented'], $a['commented']); } -/// @TODO Add type-hint -function render_location_dummy($item) { - if ($item['location'] != "") { +function render_location_dummy(array $item) { + if (x($item, 'location') && !empty($item['location'])) { return $item['location']; } - if ($item['coord'] != "") { + if (x($item, 'coord') && !empty($item['coord'])) { return $item['coord']; } } -/// @TODO Add type-hint -function get_responses($conv_responses, $response_verbs, $ob, $item) { +function get_responses(array $conv_responses, array $response_verbs, $ob, array $item) { $ret = []; foreach ($response_verbs as $v) { $ret[$v] = []; diff --git a/include/items.php b/include/items.php index af13898b24..1cfad356c2 100644 --- a/include/items.php +++ b/include/items.php @@ -274,6 +274,7 @@ function consume_feed($xml, $importer, $contact, &$hub, $datedir = 0, $pass = 0) function subscribe_to_hub($url, $importer, $contact, $hubmode = 'subscribe') { $a = get_app(); + $r = null; if (is_array($importer)) { $r = q("SELECT `nickname` FROM `user` WHERE `uid` = %d LIMIT 1", diff --git a/include/security.php b/include/security.php index b13a507cf4..bcfddf8872 100644 --- a/include/security.php +++ b/include/security.php @@ -254,6 +254,7 @@ function can_write_wall($owner) return false; } +/// @TODO $groups should be array function permissions_sql($owner_id, $remote_verified = false, $groups = null) { $local_user = local_user(); @@ -275,6 +276,13 @@ function permissions_sql($owner_id, $remote_verified = false, $groups = null) */ if ($local_user && $local_user == $owner_id) { $sql = ''; + /** + * Authenticated visitor. Unless pre-verified, + * check that the contact belongs to this $owner_id + * and load the groups the visitor belongs to. + * If pre-verified, the caller is expected to have already + * done this and passed the groups into this function. + */ } elseif ($remote_user) { /* * Authenticated visitor. Unless pre-verified, @@ -298,9 +306,10 @@ function permissions_sql($owner_id, $remote_verified = false, $groups = null) if ($remote_verified) { $gs = '<<>>'; // should be impossible to match - if (is_array($groups) && count($groups)) { - foreach ($groups as $g) + if (is_array($groups)) { + foreach ($groups as $g) { $gs .= '|<' . intval($g) . '>'; + } } $sql = sprintf( diff --git a/include/text.php b/include/text.php index 4c9a8864d5..3f66d379c9 100644 --- a/include/text.php +++ b/include/text.php @@ -182,6 +182,7 @@ function autoname($len) { break; } } + if (substr($word, -1) == 'q') { $word = substr($word, 0, -1); } @@ -452,7 +453,7 @@ function perms2str($p) { if (is_array($p)) { $tmp = $p; } else { - $tmp = explode(',',$p); + $tmp = explode(',', $p); } if (is_array($tmp)) { @@ -1660,10 +1661,11 @@ function bb_translate_video($s) { $r = preg_match_all("/\[video\](.*?)\[\/video\]/ism",$s,$matches,PREG_SET_ORDER); if ($r) { foreach ($matches as $mtch) { - if ((stristr($mtch[1],'youtube')) || (stristr($mtch[1],'youtu.be'))) - $s = str_replace($mtch[0],'[youtube]' . $mtch[1] . '[/youtube]',$s); - elseif (stristr($mtch[1],'vimeo')) - $s = str_replace($mtch[0],'[vimeo]' . $mtch[1] . '[/vimeo]',$s); + if ((stristr($mtch[1], 'youtube')) || (stristr($mtch[1], 'youtu.be'))) { + $s = str_replace($mtch[0], '[youtube]' . $mtch[1] . '[/youtube]', $s); + } elseif (stristr($mtch[1], 'vimeo')) { + $s = str_replace($mtch[0], '[vimeo]' . $mtch[1] . '[/vimeo]', $s); + } } } return $s; @@ -1781,7 +1783,7 @@ function file_tag_file_query($table,$s,$type = 'file') { } // ex. given music,video return