]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #5022 from Rudloff/feature/test_api
authorHypolite Petovan <mrpetovan@gmail.com>
Wed, 16 May 2018 12:25:11 +0000 (08:25 -0400)
committerGitHub <noreply@github.com>
Wed, 16 May 2018 12:25:11 +0000 (08:25 -0400)
 Add API tests

30 files changed:
.gitattributes
.gitignore
.htaccess
bin/daemon.php
boot.php
doc/de/Settings.md
doc/htconfig.md
include/api.php
include/conversation.php
include/items.php
include/security.php
include/text.php
mod/admin.php
mod/events.php
mod/photos.php
mod/poco.php
mod/share.php
mod/subthread.php
mod/tagger.php
mods/readme.txt [deleted file]
mods/redme.txt [new file with mode: 0644]
src/Core/Cache.php
src/Core/Cache/RedisCacheDriver.php [new file with mode: 0644]
src/Core/PConfig.php
src/Core/Worker.php
src/Model/Event.php
src/Model/Item.php
src/Protocol/DFRN.php
src/Protocol/OStatus.php
src/Protocol/PortableContact.php

index 4be1c918527cb1766cac23f98c6f14867a8c589c..18ba9e0758c7b4ebe701e521b1258f3ef8ff6706 100644 (file)
@@ -1,2 +1,2 @@
-# Disable LF normalization for all files\r
-* -text
\ No newline at end of file
+# Disable LF normalization for all files
+* -text
index 9e6504184c03c4347f630441b34c0fc8e133c13c..9de700d148d8960ee1b9a52f5f00ba4dc8b31300 100644 (file)
@@ -1,61 +1,64 @@
-favicon.*\r
-.htconfig.php\r
-.htpreconfig.php\r
-\#*\r
-include/jquery-1.4.2.min.js\r
-*.log\r
-*.out\r
-*.version*\r
-favicon.*\r
-home.html\r
-addon\r
-*.orig\r
-*~\r
-robots.txt\r
-\r
-#ignore documentation, it should be newly built\r
-doc/html\r
-\r
-#ignore reports, should be generted with every build\r
-report/\r
-\r
-#ignore config files from eclipse, we don't want IDE files in our repository\r
-.project\r
-.buildpath\r
-.externalToolBuilders\r
-.settings\r
-#ignore OSX .DS_Store files\r
-.DS_Store\r
-\r
-/nbproject/private/\r
-\r
-#ignore smarty cache\r
-/view/smarty3/compiled/\r
-\r
-#ignore cache folders\r
-/privacy_image_cache/\r
-/photo/\r
-/proxy/\r
-nbproject\r
-\r
-#ignore vagrant dir\r
-.vagrant/\r
-\r
-#ignore local folder\r
-/local/\r
-\r
-#ignore config files from Visual Studio\r
-/.vs/\r
-/php_friendica.phpproj\r
-/php_friendica.sln\r
-/php_friendica.phpproj.user\r
-\r
-#ignore things from transifex-client\r
-venv/\r
-\r
-#ignore Composer dependencies\r
-/vendor\r
-/view/asset\r
-\r
-#ignore config files from JetBrains\r
-/.idea\r
+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/
index 2348cdc38b36ca4eed776ae762eee7d2c8edf660..a671cc680aff06f63aa301add63c8cc59c34ad33 100644 (file)
--- a/.htaccess
+++ b/.htaccess
@@ -4,7 +4,7 @@ AddType audio/ogg .oga
 #AddHandler php53-cgi .php
 
 <FilesMatch "\.(out|log)$">
-  <IfModule authz_host_module> 
+  <IfModule authz_host_module>
     #Apache 2.4
     Require all denied
   </IfModule>
@@ -38,4 +38,3 @@ AddType audio/ogg .oga
   RewriteRule ^(.*)$ index.php?pagename=$1 [E=REMOTE_USER:%{HTTP:Authorization},L,QSA]
 
 </IfModule>
-
index 6b0e377a3a1bfa0126c8a4bfe9b5d25efebd603c..b51dd392ef7fdd1e7c831871ab15a55f38df4575 100755 (executable)
@@ -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".
index ae2f4b1a06306d484f96ea4d723c8db48f0ec837..69450260129f4692f8b06c054ca223f2e8e0dd72 100644 (file)
--- 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()
index 8a654e32c8518f8311c5f37dd45ed7a6e20614f6..b7b696ea652eddfb3ef92fa64818453738b08ce2 100644 (file)
@@ -344,6 +344,14 @@ Mit den folgenden Einstellungen kannst du die Zugriffsdaten für den Datenbank S
     $db_pass = 'db_password';
     $db_data = 'database_name';
 
+Sollten alle der folgenden Environment-Variablen gesetzt sein, wird Friendica diese anstatt der vorher konfigurierten Werte nutzen.
+
+    MYSQL_HOST
+    MYSQL_PORT
+    MYSQL_USERNAME
+    MYSQL_PASSWORD
+    MYSQL_DATABASE
+
 ## Administratoren
 
 Du kannst einen, oder mehrere Accounts, zu Administratoren machen.
index 6598fa142affa227a95a1b4fa3859de18520401d..4743da444cb95aaabc705c7ed8f3eb0f6a667af3 100644 (file)
@@ -124,3 +124,11 @@ The configuration variables db_host, db_user, db_pass and db_data are holding yo
 If you need to specify a port to access the database, you can do so by appending ":portnumber" to the db_host variable.
 
     $db_host = 'your.mysqlhost.com:123456';
+
+If all of the following environment variables are set, Friendica will use them instead of the previously configured variables for the db:
+
+    MYSQL_HOST
+    MYSQL_PORT
+    MYSQL_USERNAME
+    MYSQL_PASSWORD
+    MYSQL_DATABASE
index ebf48c9b78957b68f3a97a8621207961e8786eae..cc31a94e65185b22f7e2dad566ae64bcc8676251 100644 (file)
@@ -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;
 }
 
 /**
index ae12cf4827de6b8c0c6e3b3222f108ebd39698d0..43f0a445da68dea3ce15bca2c83935d2d9a152d8 100644 (file)
@@ -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 = '<a href="'. $url . '"'. $sparkle .'>' . htmlentities($item['author-name']) . '</a>';
 
-                       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] = [];
index af13898b2496d3f48d440314626a9f7b4fb37b2f..1cfad356c24088e96ed358a79fe6e5e0e6eabfb3 100644 (file)
@@ -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",
index b13a507cf483c124e5e1de3ed3817b205784d3aa..bcfddf8872cab6c909f0e8999dfc3800a25543d0 100644 (file)
@@ -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(
index 4c9a8864d595d6dca9d10c9f221d5a9e4627542b..3f66d379c9666e2f5162fccf60ca21ef070199fa 100644 (file)
@@ -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 <music><video> or [music][video]
-function file_tag_list_to_file($list,$type = 'file') {
+function file_tag_list_to_file($list, $type = 'file') {
        $tag_list = '';
        if (strlen($list)) {
                $list_array = explode(",",$list);
@@ -1803,7 +1805,7 @@ function file_tag_list_to_file($list,$type = 'file') {
 }
 
 // ex. given <music><video>[friends], return music,video or friends
-function file_tag_file_to_list($file,$type = 'file') {
+function file_tag_file_to_list($file, $type = 'file') {
        $matches = false;
        $list = '';
        if ($type == 'file') {
@@ -1829,8 +1831,7 @@ function file_tag_update_pconfig($uid, $file_old, $file_new, $type = 'file') {
 
        if (!intval($uid)) {
                return false;
-       }
-       if ($file_old == $file_new) {
+       } elseif ($file_old == $file_new) {
                return true;
        }
 
@@ -1853,8 +1854,9 @@ function file_tag_update_pconfig($uid, $file_old, $file_new, $type = 'file') {
                $check_new_tags = explode(",",file_tag_file_to_list($file_new,$type));
 
                foreach ($check_new_tags as $tag) {
-                       if (! stristr($saved,$lbracket . file_tag_encode($tag) . $rbracket))
+                       if (! stristr($saved,$lbracket . file_tag_encode($tag) . $rbracket)) {
                                $new_tags[] = $tag;
+                       }
                }
 
                $filetags_updated .= file_tag_list_to_file(implode(",",$new_tags),$type);
@@ -1864,8 +1866,9 @@ function file_tag_update_pconfig($uid, $file_old, $file_new, $type = 'file') {
                $check_deleted_tags = explode(",",file_tag_file_to_list($file_old,$type));
 
                foreach ($check_deleted_tags as $tag) {
-                       if (! stristr($file_new,$lbracket . file_tag_encode($tag) . $rbracket))
+                       if (! stristr($file_new,$lbracket . file_tag_encode($tag) . $rbracket)) {
                                $deleted_tags[] = $tag;
+                       }
                }
 
                foreach ($deleted_tags as $key => $tag) {
@@ -1975,17 +1978,22 @@ function protect_sprintf($s) {
        return str_replace('%', '%%', $s);
 }
 
-
+/// @TODO Rewrite this
 function is_a_date_arg($s) {
        $i = intval($s);
+
        if ($i > 1900) {
                $y = date('Y');
+
                if ($i <= $y + 1 && strpos($s, '-') == 4) {
-                       $m = intval(substr($s,5));
-                       if ($m > 0 && $m <= 12)
+                       $m = intval(substr($s, 5));
+
+                       if ($m > 0 && $m <= 12) {
                                return true;
+                       }
                }
        }
+
        return false;
 }
 
@@ -2003,6 +2011,7 @@ function deindent($text, $chr = "[\t ]", $count = NULL) {
                preg_match("|^" . $chr . "*|", $lines[$k], $m);
                $count = strlen($m[0]);
        }
+
        for ($k = 0; $k < count($lines); $k++) {
                $lines[$k] = preg_replace("|^" . $chr . "{" . $count . "}|", "", $lines[$k]);
        }
index 1447dbaf185dc8313b8f60d005933429736b736f..1d6f1395a0eac6da6c3b7b41decf2de17d6aff99 100644 (file)
@@ -64,7 +64,7 @@ function admin_post(App $a)
                        case 'addons':
                                if ($a->argc > 2 &&
                                        is_file("addon/" . $a->argv[2] . "/" . $a->argv[2] . ".php")) {
-                                       @include_once("addon/" . $a->argv[2] . "/" . $a->argv[2] . ".php");
+                                       include_once "addon/" . $a->argv[2] . "/" . $a->argv[2] . ".php";
                                        if (function_exists($a->argv[2] . '_addon_admin_post')) {
                                                $func = $a->argv[2] . '_addon_admin_post';
                                                $func($a);
@@ -917,6 +917,7 @@ function admin_page_site_post(App $a)
                        $upds = implode(", ", $upd);
 
                        $r = q("UPDATE %s SET %s;", $table_name, $upds);
+
                        if (!DBM::is_result($r)) {
                                notice("Failed updating '$table_name': " . dba::errorMessage());
                                goaway('admin/site');
@@ -1298,15 +1299,18 @@ function admin_page_site(App $a)
        $user_names = [];
        $user_names['---'] = L10n::t('Multi user instance');
        $users = q("SELECT `username`, `nickname` FROM `user`");
+
        foreach ($users as $user) {
                $user_names[$user['nickname']] = $user['username'];
        }
 
        /* Banner */
        $banner = Config::get('system', 'banner');
+
        if ($banner == false) {
                $banner = '<a href="https://friendi.ca"><img id="logo-img" src="images/friendica-32.png" alt="logo" /></a><span id="logo-text"><a href="https://friendi.ca">Friendica</a></span>';
        }
+
        $banner = htmlspecialchars($banner);
        $info = Config::get('config', 'info');
        $info = htmlspecialchars($info);
@@ -1506,9 +1510,12 @@ function admin_page_dbsync(App $a)
 
        if ($a->argc > 2 && intval($a->argv[2])) {
                require_once 'update.php';
+
                $func = 'update_' . intval($a->argv[2]);
+
                if (function_exists($func)) {
                        $retval = $func();
+
                        if ($retval === UPDATE_FAILED) {
                                $o .= L10n::t("Executing %s failed with error: %s", $func, $retval);
                        } elseif ($retval === UPDATE_SUCCESS) {
@@ -1521,11 +1528,13 @@ function admin_page_dbsync(App $a)
                        $o .= L10n::t('There was no additional update function %s that needed to be called.', $func) . "<br />";
                        Config::set('database', $func, 'success');
                }
+
                return $o;
        }
 
        $failed = [];
        $r = q("SELECT `k`, `v` FROM `config` WHERE `cat` = 'database' ");
+
        if (DBM::is_result($r)) {
                foreach ($r as $rr) {
                        $upd = intval(substr($rr['k'], 7));
@@ -1535,6 +1544,7 @@ function admin_page_dbsync(App $a)
                        $failed[] = $upd;
                }
        }
+
        if (!count($failed)) {
                $o = replace_macros(get_markup_template('structure_check.tpl'), [
                        '$base' => System::baseUrl(true),
@@ -1769,8 +1779,8 @@ function admin_page_users(App $a)
                $e['page-flags-raw'] = $e['page-flags'];
                $e['page-flags'] = $page_types[$e['page-flags']];
 
-               $e['account-type-raw'] = ($e['page_flags_raw']==0) ? $e['account-type'] : -1;
-               $e['account-type'] = ($e['page_flags_raw']==0) ? $account_types[$e['account-type']] : "";
+               $e['account-type-raw'] = ($e['page_flags_raw'] == 0) ? $e['account-type'] : -1;
+               $e['account-type'] = ($e['page_flags_raw'] == 0) ? $account_types[$e['account-type']] : "";
 
                $e['register_date'] = Temporal::getRelativeDate($e['register_date']);
                $e['login_date'] = Temporal::getRelativeDate($e['login_date']);
@@ -1921,7 +1931,7 @@ function admin_page_addons(App $a)
 
                $admin_form = "";
                if (in_array($addon, $a->addons_admin)) {
-                       @require_once("addon/$addon/$addon.php");
+                       require_once "addon/$addon/$addon.php";
                        $func = $addon . '_addon_admin';
                        $func($a, $admin_form);
                }
@@ -2162,6 +2172,7 @@ function admin_page_themes(App $a)
                }
 
                $readme = null;
+
                if (is_file("view/theme/$theme/README.md")) {
                        $readme = Markdown::convert(file_get_contents("view/theme/$theme/README.md"), false);
                } elseif (is_file("view/theme/$theme/README")) {
index cad440f164c542feb6915868b0d49d18e997f277..bbd6337c3792c32a3b4b0f71df2568e5d1484793 100644 (file)
@@ -433,6 +433,7 @@ function events_content(App $a) {
                if (x($_REQUEST, 'location'))    {$orig_event['location']    = $_REQUEST['location'];}
                if (x($_REQUEST, 'start'))       {$orig_event['start']       = $_REQUEST['start'];}
                if (x($_REQUEST, 'finish'))      {$orig_event['finish']      = $_REQUEST['finish'];}
+               if (x($_REQUEST,'finish')) $orig_event['finish'] = $_REQUEST['finish'];
 
                $n_checked = ((x($orig_event) && $orig_event['nofinish']) ? ' checked="checked" ' : '');
                $a_checked = ((x($orig_event) && $orig_event['adjust'])   ? ' checked="checked" ' : '');
index c8dad750d1528b95f9231b7eb0d69706b76c9ffa..235acdfc47bdfd0b354003b5e8f80e0e315a4f03 100644 (file)
@@ -1243,9 +1243,11 @@ function photos_content(App $a)
                $prevlink = '';
                $nextlink = '';
 
-               /// @todo This query is totally bad, the whole functionality has to be changed
-               // The query leads to a really intense used index.
-               // By now we hide it if someone wants to.
+               /*
+                * @todo This query is totally bad, the whole functionality has to be changed
+                * The query leads to a really intense used index.
+                * By now we hide it if someone wants to.
+                */
                if (!Config::get('system', 'no_count', false)) {
                        $order_field = defaults($_GET, 'order', '');
                        if ($order_field === 'posted') {
@@ -1280,8 +1282,10 @@ function photos_content(App $a)
                        }
                }
 
-               if (count($ph) == 1)
+               if (count($ph) == 1) {
                        $hires = $lores = $ph[0];
+               }
+
                if (count($ph) > 1) {
                        if ($ph[1]['scale'] == 2) {
                                // original is 640 or less, we can display it directly
@@ -1293,6 +1297,7 @@ function photos_content(App $a)
                }
 
                $album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
+
                $tools = null;
                $lock = null;
 
@@ -1319,8 +1324,9 @@ function photos_content(App $a)
                        ]);
                }
 
-               if ($prevlink)
+               if ($prevlink) {
                        $prevlink = [$prevlink, '<div class="icon prev"></div>'] ;
+               }
 
                $photo = [
                        'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
@@ -1681,8 +1687,9 @@ function photos_content(App $a)
                $twist = false;
                foreach ($r as $rr) {
                        //hide profile photos to others
-                       if (!$is_owner && !remote_user() && ($rr['album'] == L10n::t('Profile Photos')))
+                       if (!$is_owner && !remote_user() && ($rr['album'] == L10n::t('Profile Photos'))) {
                                continue;
+                       }
 
                        $twist = !$twist;
 
index 0728020eccab3292e6cc7428b616bc5b80bed149..671551f832589e89ab4c839e1c48ada353a79cb7 100644 (file)
@@ -43,6 +43,7 @@ function poco_init(App $a) {
                echo json_encode($ret);
                killme();
        }
+
        if ($a->argc > 1 && $a->argv[1] === '@global') {
                // List of all profiles that this server recently had data from
                $global = true;
index f67dd3d200c96aa74c37602e2a360cc439db4638..555273443c6fc668b4bca76a7ddecf0b6ff26998 100644 (file)
@@ -5,6 +5,7 @@ use Friendica\Database\DBM;
 
 function share_init(App $a) {
        $post_id = (($a->argc > 1) ? intval($a->argv[1]) : 0);
+
        if (!$post_id || !local_user()) {
                killme();
        }
@@ -14,37 +15,44 @@ function share_init(App $a) {
                WHERE `item`.`id` = %d LIMIT 1",
                intval($post_id)
        );
+
        if (!DBM::is_result($r) || ($r[0]['private'] == 1)) {
                killme();
        }
+
        if (strpos($r[0]['body'], "[/share]") !== false) {
                $pos = strpos($r[0]['body'], "[share");
                $o = substr($r[0]['body'], $pos);
        } else {
                $o = share_header($r[0]['author-name'], $r[0]['author-link'], $r[0]['author-avatar'], $r[0]['guid'], $r[0]['created'], $r[0]['plink']);
 
-               if ($r[0]['title'])
+               if ($r[0]['title']) {
                        $o .= '[b]'.$r[0]['title'].'[/b]'."\n";
+               }
+
                $o .= $r[0]['body'];
-               $o.= "[/share]";
+               $o .= "[/share]";
        }
 
        echo $o;
        killme();
 }
 
+/// @TODO Rewrite to handle over whole record array
 function share_header($author, $profile, $avatar, $guid, $posted, $link) {
-       $header = "[share author='".str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $author).
-               "' profile='".str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $profile).
-               "' avatar='".str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $avatar);
+       $header = "[share author='" . str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $author).
+               "' profile='" . str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $profile).
+               "' avatar='" . str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $avatar);
 
        if ($guid) {
-               $header .= "' guid='".str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $guid);
+               $header .= "' guid='" . str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $guid);
        }
+
        if ($posted) {
-               $header .= "' posted='".str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $posted);
+               $header .= "' posted='" . str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $posted);
        }
-       $header .= "' link='".str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $link)."']";
+
+       $header .= "' link='" . str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $link)."']";
 
        return $header;
 }
index c858f2d1fa3a3c847ea132b823605d33b31496ce..df44df6efa893331ba525d29de6ee2573a80ea95 100644 (file)
@@ -63,17 +63,19 @@ function subthread_content(App $a) {
                WHERE `contact`.`self` = 1 AND `contact`.`uid` = %d LIMIT 1",
                intval($owner_uid)
        );
-       if (DBM::is_result($r))
+
+       if (DBM::is_result($r)) {
                $owner = $r[0];
+       }
 
        if (! $owner) {
                logger('like: no owner');
                return;
        }
 
-       if (! $remote_owner)
+       if (! $remote_owner) {
                $remote_owner = $owner;
-
+       }
 
        $contact = null;
        // This represents the person posting
@@ -85,8 +87,10 @@ function subthread_content(App $a) {
                        intval($_SESSION['visitor_id']),
                        intval($owner_uid)
                );
-               if (DBM::is_result($r))
+
+               if (DBM::is_result($r)) {
                        $contact = $r[0];
+               }
        }
        if (! $contact) {
                return;
index 16195cc339d2f02f4c04eb719f7e7b04484e1e98..211e2ffa1fe6c94bb63eac0c84ebc7447ade683a 100644 (file)
@@ -159,11 +159,13 @@ EOT;
        }
 
        $term_objtype = ($item['resource-id'] ? TERM_OBJ_PHOTO : TERM_OBJ_POST);
-        $t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'",
-                intval($item['id']),
-                dbesc($term)
-        );
-       if((! $blocktags) && $t[0]['tcount']==0 ) {
+
+       $t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'",
+               intval($item['id']),
+               dbesc($term)
+       );
+
+       if ((!$blocktags) && $t[0]['tcount'] == 0 ) {
                q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)",
                   intval($item['id']),
                   $term_objtype,
@@ -176,26 +178,28 @@ EOT;
 
        // if the original post is on this site, update it.
 
-       $r = q("select `tag`,`id`,`uid` from item where `origin` = 1 AND `uri` = '%s' LIMIT 1",
+       $r = q("SELECT `tag`,`id`,`uid` FROM `item` WHERE `origin`=1 AND `uri`='%s' LIMIT 1",
                dbesc($item['uri'])
        );
+
        if (DBM::is_result($r)) {
-               $x = q("SELECT `blocktags` FROM `user` WHERE `uid` = %d limit 1",
+               $x = q("SELECT `blocktags` FROM `user` WHERE `uid`=%d LIMIT 1",
                        intval($r[0]['uid'])
                );
-               $t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'",
+               $t = q("SELECT COUNT(`tid`) AS `tcount` FROM `term` WHERE `oid`=%d AND `term`='%s'",
                        intval($r[0]['id']),
                        dbesc($term)
                );
-               if(count($x) && !$x[0]['blocktags'] && $t[0]['tcount']==0){
-                       q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)",
-                          intval($r[0]['id']),
-                          $term_objtype,
-                          TERM_HASHTAG,
-                          dbesc($term),
-                          dbesc(System::baseUrl() . '/search?tag=' . $term),
-                          intval($owner_uid)
-                       );
+
+               if (DBM::is_result($x) && !$x[0]['blocktags'] && $t[0]['tcount'] == 0){
+                       q("INSERT INTO term (`oid`, `otype`, `type`, `term`, `url`, `uid`) VALUE (%d, %d, %d, '%s', '%s', %d)",
+                               intval($r[0]['id']),
+                               $term_objtype,
+                               TERM_HASHTAG,
+                               dbesc($term),
+                               dbesc(System::baseUrl() . '/search?tag=' . $term),
+                               intval($owner_uid)
+                       );
                }
        }
 
diff --git a/mods/readme.txt b/mods/readme.txt
deleted file mode 100644 (file)
index 8fc1c48..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-sample-Lighttpd.config
-sample-nginx.config
-
-               Sample configuration files to use Friendica with Lighttpd
-               or Nginx. Pleas check software documentation to know how modify
-               these examples to make them work on your server.
-
-
-sample-systemd.timer
-sample-systemd.service
-
-               Sample systemd unit files to start worker.php periodically.
-               
-               Please place them in the correct location for your system,
-               typically this is /etc/systemd/system/friendicaworker.timer 
-               and /etc/systemd/system/friendicaworker.service.
-               Please report problems and improvements to 
-               !helpers@forum.friendi.ca and @utzer@social.yl.ms or open an 
-               issue in Github (https://github.com/friendica/friendica/issues).
-               This is for usage of systemd instead of cron to start the worker.php
-               periodically, the solution is work-in-progress and can surely be improved.
-
-home.css
-home.html
-
-               Example files to customize the landing page of your Friendica node.
-               The home.html file contains the text of the page, the home.css file
-               the style information. The login box will be added according to the
-               other system settings.
-               Both files have to be placed in the base directory of your Friendica
-               installation to be used for the landing page.
diff --git a/mods/redme.txt b/mods/redme.txt
new file mode 100644 (file)
index 0000000..8fc1c48
--- /dev/null
@@ -0,0 +1,31 @@
+sample-Lighttpd.config
+sample-nginx.config
+
+               Sample configuration files to use Friendica with Lighttpd
+               or Nginx. Pleas check software documentation to know how modify
+               these examples to make them work on your server.
+
+
+sample-systemd.timer
+sample-systemd.service
+
+               Sample systemd unit files to start worker.php periodically.
+               
+               Please place them in the correct location for your system,
+               typically this is /etc/systemd/system/friendicaworker.timer 
+               and /etc/systemd/system/friendicaworker.service.
+               Please report problems and improvements to 
+               !helpers@forum.friendi.ca and @utzer@social.yl.ms or open an 
+               issue in Github (https://github.com/friendica/friendica/issues).
+               This is for usage of systemd instead of cron to start the worker.php
+               periodically, the solution is work-in-progress and can surely be improved.
+
+home.css
+home.html
+
+               Example files to customize the landing page of your Friendica node.
+               The home.html file contains the text of the page, the home.css file
+               the style information. The login box will be added according to the
+               other system settings.
+               Both files have to be placed in the base directory of your Friendica
+               installation to be used for the landing page.
index f1d1e11a542a26835b0700e25221fd36493ef044..4202db325c411c38b7852321af769bfb0f09d33c 100644 (file)
@@ -40,6 +40,12 @@ class Cache extends \Friendica\BaseObject
 
                                self::$driver = new Cache\MemcachedCacheDriver($memcached_hosts);
                                break;
+                       case 'redis':
+                               $redis_host = Config::get('system', 'redis_host', '127.0.0.1');
+                               $redis_port = Config::get('system', 'redis_port', 6379);
+
+                               self::$driver = new Cache\RedisCacheDriver($redis_host, $redis_port);
+                               break;
                        default:
                                self::$driver = new Cache\DatabaseCacheDriver();
                }
diff --git a/src/Core/Cache/RedisCacheDriver.php b/src/Core/Cache/RedisCacheDriver.php
new file mode 100644 (file)
index 0000000..fa98842
--- /dev/null
@@ -0,0 +1,77 @@
+<?php
+
+namespace Friendica\Core\Cache;
+
+use Friendica\BaseObject;
+use Friendica\Core\Cache;
+
+/**
+ * Redis Cache Driver. This driver is based on Memcache driver
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ * @author Roland Haeder <roland@mxchange.org>
+ */
+class RedisCacheDriver extends BaseObject implements ICacheDriver
+{
+       /**
+        * @var Redis
+        */
+       private $redis;
+
+       public function __construct($redis_host, $redis_port)
+       {
+               if (!class_exists('Redis', false)) {
+                       throw new \Exception('Redis class isn\'t available');
+               }
+
+               $this->redis = new \Redis();
+
+               if (!$this->redis->connect($redis_host, $redis_port)) {
+                       throw new \Exception('Expected Redis server at ' . $redis_host . ':' . $redis_port . ' isn\'t available');
+               }
+       }
+
+       public function get($key)
+       {
+               $return = null;
+
+               // We fetch with the hostname as key to avoid problems with other applications
+               $cached = $this->redis->get(self::getApp()->get_hostname() . ':' . $key);
+
+               // @see http://php.net/manual/en/redis.get.php#84275
+               if (is_bool($cached) || is_double($cached) || is_long($cached)) {
+                       return $return;
+               }
+
+               $value = @unserialize($cached);
+
+               // Only return a value if the serialized value is valid.
+               // We also check if the db entry is a serialized
+               // boolean 'false' value (which we want to return).
+               if ($cached === serialize(false) || $value !== false) {
+                       $return = $value;
+               }
+
+               return $return;
+       }
+
+       public function set($key, $value, $duration = Cache::MONTH)
+       {
+               // We store with the hostname as key to avoid problems with other applications
+               return $this->redis->set(
+                       self::getApp()->get_hostname() . ":" . $key,
+                       serialize($value),
+                       time() + $duration
+               );
+       }
+
+       public function delete($key)
+       {
+               return $this->redis->delete($key);
+       }
+
+       public function clear()
+       {
+               return true;
+       }
+}
index bfa52f5a36ebd7e480d97d2c638ccf8a77b2958e..274122deda4513dd63acaeded4414989b0d7fd21 100644 (file)
@@ -29,9 +29,7 @@ class PConfig extends BaseObject
 
        public static function init($uid)
        {
-               $a = self::getApp();
-
-               if (isset($a->config['system']['config_adapter']) && $a->config['system']['config_adapter'] == 'preload') {
+               if (Config::get('system', 'config_adapter') == 'preload') {
                        self::$adapter = new Config\PreloadPConfigAdapter($uid);
                } else {
                        self::$adapter = new Config\JITPConfigAdapter($uid);
index e3d8df45e40625eb2ce42b31d7328f6639f549f9..8c8e2733186b3530fc0074346bf798f219790e14 100644 (file)
@@ -688,7 +688,7 @@ class Worker
                        logger("Load: ".$load."/".$maxsysload." - processes: ".$active."/".$entries.$processlist." - maximum: ".$queues."/".$maxqueues, LOGGER_DEBUG);
 
                        // Are there fewer workers running as possible? Then fork a new one.
-                       if (!Config::get("system", "worker_dont_fork") && ($queues > ($active + 1)) && ($entries > 1)) {
+                       if (!Config::get("system", "worker_dont_fork", false) && ($queues > ($active + 1)) && ($entries > 1)) {
                                logger("Active workers: ".$active."/".$queues." Fork a new worker.", LOGGER_DEBUG);
                                self::spawnWorker();
                        }
@@ -1039,7 +1039,7 @@ class Worker
                }
 
                $priority = PRIORITY_MEDIUM;
-               $dont_fork = Config::get("system", "worker_dont_fork");
+               $dont_fork = Config::get("system", "worker_dont_fork", false);
                $created = DateTimeFormat::utcNow();
 
                $run_parameter = array_shift($args);
index e65e61ee58367a4e3e6005217a36a5a29af1b860..db9e2b93034127cc85e1036571a8a3caea20899a 100644 (file)
@@ -803,10 +803,10 @@ class Event extends BaseObject
        /**
         * @brief Format an item array with event data to HTML.
         *
-        * @param arr $item Array with item and event data.
+        * @param array $item Array with item and event data.
         * @return string HTML output.
         */
-       public static function getItemHTML($item) {
+       public static function getItemHTML(array $item) {
                $same_date = false;
                $finish    = false;
 
index 425f71822ae1ab6b717777a1568c03f02db1c35c..bf1193d7096996a6b0c92e52043c884edbfc431d 100644 (file)
@@ -1032,8 +1032,9 @@ class Item extends BaseObject
                }
 
                // Is this a shadow entry?
-               if ($item['uid'] == 0)
+               if ($item['uid'] == 0) {
                        return;
+               }
 
                // Is there a shadow parent?
                if (!dba::exists('item', ['uri' => $item['parent-uri'], 'uid' => 0])) {
@@ -1073,10 +1074,8 @@ class Item extends BaseObject
 
                // If this was a comment to a Diaspora post we don't get our comment back.
                // This means that we have to distribute the comment by ourselves.
-               if ($origin) {
-                       if (dba::exists('item', ['id' => $parent, 'network' => NETWORK_DIASPORA])) {
-                               self::distribute($public_shadow);
-                       }
+               if ($origin && dba::exists('item', ['id' => $parent, 'network' => NETWORK_DIASPORA])) {
+                       self::distribute($public_shadow);
                }
        }
 
@@ -1087,14 +1086,14 @@ class Item extends BaseObject
         */
        private static function addLanguageInPostopts(&$item)
        {
+               $postopts = "";
+
                if (!empty($item['postopts'])) {
                        if (strstr($item['postopts'], 'lang=')) {
                                // do not override
                                return;
                        }
                        $postopts = $item['postopts'];
-               } else {
-                       $postopts = "";
                }
 
                $naked_body = Text\BBCode::toPlaintext($item['body'], false);
index b66e1d5bfa9f954eff6a285246df368fa542838c..d738adecb8b2d95f245f8371abbcdaf2e7aa96a8 100644 (file)
@@ -63,7 +63,7 @@ class DFRN
         * @param array $owner Owner record
         *
         * @return string DFRN entries
-        * @todo Add type-hints
+        * @todo Find proper type-hints
         */
        public static function entries($items, $owner)
        {
@@ -81,7 +81,7 @@ class DFRN
                        $root->appendChild($entry);
                }
 
-               return(trim($doc->saveXML()));
+               return trim($doc->saveXML());
        }
 
        /**
@@ -120,8 +120,6 @@ class DFRN
                        }
                }
 
-
-
                // default permissions - anonymous user
 
                $sql_extra = " AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = '' ";
@@ -134,6 +132,7 @@ class DFRN
                );
 
                if (! DBM::is_result($r)) {
+                       logger(sprintf('No contact found for nickname=%d', $owner_nick), LOGGER_WARNING);
                        killme();
                }
 
@@ -169,6 +168,7 @@ class DFRN
                        );
 
                        if (! DBM::is_result($r)) {
+                               logger(sprintf('No contact found for uid=%d', $owner_id), LOGGER_WARNING);
                                killme();
                        }
 
@@ -177,8 +177,10 @@ class DFRN
                        $groups = Group::getIdsByContactId($contact['id']);
 
                        if (count($groups)) {
-                               for ($x = 0; $x < count($groups); $x ++)
+                               for ($x = 0; $x < count($groups); $x ++) {
                                        $groups[$x] = '<' . intval($groups[$x]) . '>' ;
+                               }
+
                                $gs = implode('|', $groups);
                        } else {
                                $gs = '<<>>' ; // Impossible to match
@@ -219,10 +221,8 @@ class DFRN
                        //$sql_extra .= file_tag_file_query('item',$category,'category');
                }
 
-               if ($public_feed) {
-                       if (! $converse) {
-                               $sql_extra .= " AND `contact`.`self` = 1 ";
-                       }
+               if ($public_feed && ! $converse) {
+                       $sql_extra .= " AND `contact`.`self` = 1 ";
                }
 
                $check_date = DateTimeFormat::utc($last_update);
@@ -397,7 +397,7 @@ class DFRN
         * @param array $owner Owner record
         *
         * @return string DFRN mail
-        * @todo Add type-hints
+        * @todo Find proper type-hints
         */
        public static function mail($item, $owner)
        {
@@ -423,7 +423,7 @@ class DFRN
 
                $root->appendChild($mail);
 
-               return(trim($doc->saveXML()));
+               return trim($doc->saveXML());
        }
 
        /**
@@ -433,7 +433,7 @@ class DFRN
         * @param array $owner Owner record
         *
         * @return string DFRN suggestions
-        * @todo Add type-hints
+        * @todo Find proper type-hints
         */
        public static function fsuggest($item, $owner)
        {
@@ -452,7 +452,7 @@ class DFRN
 
                $root->appendChild($suggest);
 
-               return(trim($doc->saveXML()));
+               return trim($doc->saveXML());
        }
 
        /**
@@ -462,7 +462,7 @@ class DFRN
         * @param int   $uid   User ID
         *
         * @return string DFRN relocations
-        * @todo Add type-hints
+        * @todo Find proper type-hints
         */
        public static function relocate($owner, $uid)
        {
@@ -487,7 +487,6 @@ class DFRN
                        $photos[$p['scale']] = System::baseUrl().'/photo/'.$p['resource-id'].'-'.$p['scale'].'.'.$ext[$p['type']];
                }
 
-               unset($rp, $ext);
 
                $doc = new DOMDocument('1.0', 'utf-8');
                $doc->formatOutput = true;
@@ -511,7 +510,7 @@ class DFRN
 
                $root->appendChild($relocate);
 
-               return(trim($doc->saveXML()));
+               return trim($doc->saveXML());
        }
 
        /**
@@ -524,7 +523,7 @@ class DFRN
         * @param bool   $public        Is it a header for public posts?
         *
         * @return object XML root object
-        * @todo Add type-hints
+        * @todo Find proper type-hints
         */
        private static function addHeader($doc, $owner, $authorelement, $alternatelink = "", $public = false)
        {
@@ -600,7 +599,7 @@ class DFRN
         * @param boolean $public        boolean
         *
         * @return object XML author object
-        * @todo Add type-hints
+        * @todo Find proper type-hints
         */
        private static function addAuthor($doc, $owner, $authorelement, $public)
        {
@@ -744,7 +743,7 @@ class DFRN
         * @param array  $item        Item elements
         *
         * @return object XML author object
-        * @todo Add type-hints
+        * @todo Find proper type-hints
         */
        private static function addEntryAuthor($doc, $element, $contact_url, $item)
        {
@@ -785,7 +784,7 @@ class DFRN
         * @param string $activity activity value
         *
         * @return object XML activity object
-        * @todo Add type-hints
+        * @todo Find proper type-hints
         */
        private static function createActivity($doc, $element, $activity)
        {
@@ -796,12 +795,15 @@ class DFRN
                        if (!$r) {
                                return false;
                        }
+
                        if ($r->type) {
                                XML::addElement($doc, $entry, "activity:object-type", $r->type);
                        }
+
                        if ($r->id) {
                                XML::addElement($doc, $entry, "id", $r->id);
                        }
+
                        if ($r->title) {
                                XML::addElement($doc, $entry, "title", $r->title);
                        }
@@ -848,7 +850,7 @@ class DFRN
         * @param array  $item Item element
         *
         * @return object XML attachment object
-        * @todo Add type-hints
+        * @todo Find proper type-hints
         */
        private static function getAttachment($doc, $root, $item)
        {
@@ -888,9 +890,9 @@ class DFRN
         * @param bool   $single  If set, the entry is created as an XML document with a single "entry" element
         *
         * @return object XML entry object
-        * @todo Add type-hints
+        * @todo Find proper type-hints
         */
-       private static function entry($doc, $type, $item, $owner, $comment = false, $cid = 0, $single = false)
+       private static function entry($doc, $type, array $item, array $owner, $comment = false, $cid = 0, $single = false)
        {
                $mentioned = [];
 
@@ -934,7 +936,7 @@ class DFRN
                        $htmlbody = $body;
 
                        if ($item['title'] != "") {
-                               $htmlbody = "[b]".$item['title']."[/b]\n\n".$htmlbody;
+                               $htmlbody = "[b]" . $item['title'] . "[/b]\n\n" . $htmlbody;
                        }
 
                        $htmlbody = BBCode::convert($htmlbody, false, 7);
@@ -1061,6 +1063,7 @@ class DFRN
 
                $tags = Item::getFeedTags($item);
 
+               /// @TODO Combine this with similar below if() block?
                if (count($tags)) {
                        foreach ($tags as $t) {
                                if (($type != 'html') || ($t[0] != "@")) {
@@ -1289,7 +1292,6 @@ class DFRN
                        $postvars['dissolve'] = '1';
                }
 
-
                if ((($contact['rel']) && ($contact['rel'] != CONTACT_IS_SHARING) && (! $contact['blocked'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
                        $postvars['data'] = $atom;
                        $postvars['perm'] = 'rw';
@@ -1571,12 +1573,12 @@ class DFRN
                // Until now we aren't serving different sizes - but maybe later
                $avatarlist = [];
                /// @todo check if "avatar" or "photo" would be the best field in the specification
-               $avatars = $xpath->query($element."/atom:link[@rel='avatar']", $context);
+               $avatars = $xpath->query($element . "/atom:link[@rel='avatar']", $context);
                foreach ($avatars as $avatar) {
                        $href = "";
                        $width = 0;
                        foreach ($avatar->attributes as $attributes) {
-                               /// @TODO Rewrite these similar if () to one switch
+                               /// @TODO Rewrite these similar if() to one switch
                                if ($attributes->name == "href") {
                                        $href = $attributes->textContent;
                                }
@@ -1591,6 +1593,7 @@ class DFRN
                                $avatarlist[$width] = $href;
                        }
                }
+
                if (count($avatarlist) > 0) {
                        krsort($avatarlist);
                        $author["avatar"] = current($avatarlist);
@@ -2093,6 +2096,9 @@ class DFRN
                $condition = ["(`id` = ?) OR (`nurl` = ?)", $importer["id"], normalise_link($old["url"])];
                dba::update('contact', $fields, $condition);
 
+               // @TODO No dba:update here?
+               dba::update('contact', $fields, $condition);
+
                Contact::updateAvatar($relocate["avatar"], $importer["importer_uid"], $importer["id"], true);
 
                logger('Contacts are updated.');
@@ -2703,7 +2709,7 @@ class DFRN
                        if (self::updateContent($current, $item, $importer, $entrytype)) {
                                logger("Item ".$item["uri"]." was updated.", LOGGER_DEBUG);
                        } else {
-                               logger("Item ".$item["uri"]." already existed.", LOGGER_DEBUG);
+                               logger("Item " . $item["uri"] . " already existed.", LOGGER_DEBUG);
                        }
                        return;
                }
@@ -2796,6 +2802,7 @@ class DFRN
        {
                logger("Processing deletions");
                $uri = null;
+
                foreach ($deletion->attributes as $attributes) {
                        if ($attributes->name == "ref") {
                                $uri = $attributes->textContent;
index 8b6939214496aa61ff92b5598cc120ed397f4e0c..8dac2b456ce858c9c427319bb1e7d7f4967c59b7 100644 (file)
@@ -1948,7 +1948,7 @@ class OStatus
         * @param bool   $complete default true
         * @return void
         */
-       private static function entryFooter($doc, $entry, $item, $owner, $complete = true)
+       private static function entryFooter($doc, $entry, array $item, array $owner, $complete = true)
        {
                $mentioned = [];
 
@@ -1988,6 +1988,7 @@ class OStatus
 
                        if (isset($parent_item)) {
                                $r = dba::fetch_first("SELECT `conversation-uri`, `conversation-href` FROM `conversation` WHERE `item-uri` = ?", $parent_item);
+
                                if (DBM::is_result($r)) {
                                        if ($r['conversation-uri'] != '') {
                                                $conversation_uri = $r['conversation-uri'];
@@ -2048,9 +2049,11 @@ class OStatus
                }
 
                if ($owner['account-type'] == ACCOUNT_TYPE_COMMUNITY) {
-                       XML::addElement($doc, $entry, "link", "", ["rel" => "mentioned",
-                                                                       "ostatus:object-type" => "http://activitystrea.ms/schema/1.0/group",
-                                                                       "href" => $owner['url']]);
+                       XML::addElement($doc, $entry, "link", "", [
+                               "rel" => "mentioned",
+                               "ostatus:object-type" => "http://activitystrea.ms/schema/1.0/group",
+                               "href" => $owner['url']
+                       ]);
                }
 
                if (!$item["private"]) {
index 672956ffb952fe492b23262b9031fe55e3f8e6ee..50b903fb02c4e1469c664dd747a3f05ad0a98d98 100644 (file)
@@ -1316,20 +1316,8 @@ class PortableContact
                                        $version = $data->version;
                                        $site_name = $data->site_name;
                                        $info = $data->info;
-                                       $register_policy_str = $data->register_policy;
+                                       $register_policy = constant($data->register_policy);
                                        $platform = $data->platform;
-
-                                       switch ($register_policy_str) {
-                                               case "REGISTER_CLOSED":
-                                                       $register_policy = REGISTER_CLOSED;
-                                                       break;
-                                               case "REGISTER_APPROVE":
-                                                       $register_policy = REGISTER_APPROVE;
-                                                       break;
-                                               case "REGISTER_OPEN":
-                                                       $register_policy = REGISTER_OPEN;
-                                                       break;
-                                       }
                                }
                        }
                }