]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #4429 from MrPetovan/bug/4426-handle-auth-exceptions
authorMichael Vogel <icarus@dabo.de>
Fri, 9 Feb 2018 18:03:52 +0000 (19:03 +0100)
committerGitHub <noreply@github.com>
Fri, 9 Feb 2018 18:03:52 +0000 (19:03 +0100)
Handle authentication exceptions in Login module

40 files changed:
boot.php
composer.json
include/security.php
mod/manage.php
src/BaseModule.php
src/Content/Text/Markdown.php
src/Content/Widget/TagCloud.php
src/Core/Session.php
src/Core/Session/DatabaseSessionHandler.php
src/Core/Session/MemcacheSessionHandler.php
src/Core/Theme.php
src/Database/DBStructure.php
src/Database/PostUpdate.php
src/Module/Feed.php
src/Module/Logout.php
src/Module/Oembed.php
src/Network/HTTPException.php
src/Network/HTTPException/BadGatewayException.php
src/Network/HTTPException/BadRequestException.php
src/Network/HTTPException/ConflictException.php
src/Network/HTTPException/ExpectationFailedException.php
src/Network/HTTPException/ForbiddenException.php
src/Network/HTTPException/GatewayTimeoutException.php
src/Network/HTTPException/GoneException.php
src/Network/HTTPException/ImATeapotException.php
src/Network/HTTPException/InternalServerErrorException.php
src/Network/HTTPException/LenghtRequiredException.php
src/Network/HTTPException/MethodNotAllowedException.php
src/Network/HTTPException/NonAcceptableException.php
src/Network/HTTPException/NotFoundException.php
src/Network/HTTPException/NotImplementedException.php
src/Network/HTTPException/PreconditionFailedException.php
src/Network/HTTPException/ServiceUnavaiableException.php
src/Network/HTTPException/TooManyRequestsException.php
src/Network/HTTPException/UnauthorizedException.php
src/Network/HTTPException/UnprocessableEntityException.php
src/Network/HTTPException/UnsupportedMediaTypeException.php
src/Protocol/DFRN.php
src/Render/FriendicaSmarty.php
src/Render/ITemplateEngine.php

index feca5039978d67ee0c481c627ac057626454e104..6816915417b1fb694afc0dca23e1aa2833b9cd78 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -39,7 +39,7 @@ define('FRIENDICA_PLATFORM',     'Friendica');
 define('FRIENDICA_CODENAME',     'Asparagus');
 define('FRIENDICA_VERSION',      '3.6-dev');
 define('DFRN_PROTOCOL_VERSION',  '2.23');
-define('DB_UPDATE_VERSION',      1251);
+define('DB_UPDATE_VERSION',      1252);
 define('NEW_UPDATE_ROUTINE_VERSION', 1170);
 
 /**
index 1cf58db55491f66869a1ed9cd820a63dd857fe68..7bdba4cf0e36ac5082e7a768ec737baf5710c491 100644 (file)
@@ -1,67 +1,67 @@
-{\r
-       "name": "friendica/friendica",\r
-       "description": "A decentralized social network part of The Federation",\r
-       "type": "project",\r
-       "keywords": [\r
-               "social network",\r
-               "dfrn",\r
-               "ostatus",\r
-               "diaspora"\r
-       ],\r
-       "license": "AGPL-3.0+",\r
-       "support": {\r
-               "issues": "https://github.com/friendica/friendica/issues"\r
-       },\r
-       "require": {\r
-               "php": ">5.6",\r
-               "ext-xml": "*",\r
-               "ezyang/htmlpurifier": "~4.7.0",\r
-               "league/html-to-markdown": "~4.4.1",\r
-               "lightopenid/lightopenid": "dev-master",\r
-               "michelf/php-markdown": "^1.7",\r
-               "mobiledetect/mobiledetectlib": "2.8.*",\r
-               "paragonie/random_compat": "^2.0",\r
-               "pear/Text_LanguageDetect": "1.*",\r
-               "pear/Text_Highlighter": "dev-master",\r
-               "smarty/smarty": "^3.1",\r
-               "fxp/composer-asset-plugin": "~1.3",\r
-               "bower-asset/base64": "^1.0",\r
-               "bower-asset/Chart-js": "^2.7",\r
-               "bower-asset/perfect-scrollbar": "^0.6",\r
-               "npm-asset/jquery": "^2.0",\r
-               "npm-asset/jquery-colorbox": "^1.6",\r
-               "npm-asset/jquery-datetimepicker": "^2.4.0",\r
-               "npm-asset/jgrowl": "^1.4",\r
-               "npm-asset/fullcalendar": "^3.0.1"\r
-       },\r
-       "repositories": [\r
-        {\r
-            "type": "vcs",\r
-            "url": "https://github.com/pear/Text_Highlighter"\r
-        }\r
-    ],\r
-       "autoload": {\r
-               "psr-4": {\r
-                       "Friendica\\": "src/"\r
-               },\r
-               "psr-0": {\r
-                       "": "library/"\r
-               }\r
-       },\r
-       "config": {\r
-               "autoloader-suffix": "Friendica",\r
-               "optimize-autoloader": true,\r
-               "preferred-install": "dist",\r
-               "fxp-asset": {\r
-            "installer-paths": {\r
-                "npm-asset-library": "vendor/asset",\r
-                "bower-asset-library": "vendor/asset"\r
-            }\r
-        }\r
-       },\r
-       "archive": {\r
-               "exclude": [\r
-                       "log", "cache", "/photo", "/proxy"\r
-               ]\r
-       }\r
-}\r
+{
+       "name": "friendica/friendica",
+       "description": "A decentralized social network part of The Federation",
+       "type": "project",
+       "keywords": [
+               "social network",
+               "dfrn",
+               "ostatus",
+               "diaspora"
+       ],
+       "license": "AGPL-3.0+",
+       "support": {
+               "issues": "https://github.com/friendica/friendica/issues"
+       },
+       "require": {
+               "php": ">5.6",
+               "ext-xml": "*",
+               "ezyang/htmlpurifier": "~4.7.0",
+               "league/html-to-markdown": "~4.4.1",
+               "lightopenid/lightopenid": "dev-master",
+               "michelf/php-markdown": "^1.7",
+               "mobiledetect/mobiledetectlib": "2.8.*",
+               "paragonie/random_compat": "^2.0",
+               "pear/Text_LanguageDetect": "1.*",
+               "pear/Text_Highlighter": "dev-master",
+               "smarty/smarty": "^3.1",
+               "fxp/composer-asset-plugin": "~1.3",
+               "bower-asset/base64": "^1.0",
+               "bower-asset/Chart-js": "^2.7",
+               "bower-asset/perfect-scrollbar": "^0.6",
+               "npm-asset/jquery": "^2.0",
+               "npm-asset/jquery-colorbox": "^1.6",
+               "npm-asset/jquery-datetimepicker": "^2.4.0",
+               "npm-asset/jgrowl": "^1.4",
+               "npm-asset/fullcalendar": "^3.0.1"
+       },
+       "repositories": [
+        {
+            "type": "vcs",
+            "url": "https://github.com/pear/Text_Highlighter"
+        }
+    ],
+       "autoload": {
+               "psr-4": {
+                       "Friendica\\": "src/"
+               },
+               "psr-0": {
+                       "": "library/"
+               }
+       },
+       "config": {
+               "autoloader-suffix": "Friendica",
+               "optimize-autoloader": true,
+               "preferred-install": "dist",
+               "fxp-asset": {
+            "installer-paths": {
+                "npm-asset-library": "vendor/asset",
+                "bower-asset-library": "vendor/asset"
+            }
+        }
+       },
+       "archive": {
+               "exclude": [
+                       "log", "cache", "/photo", "/proxy"
+               ]
+       }
+}
index 45f8d86b10f4808238059e97515cd5fc3eeffb1f..af424df26c65c6122ff76a2070c936b426cdc46d 100644 (file)
@@ -107,12 +107,35 @@ function authenticate_success($user_record, $login_initial = false, $interactive
                }
        }
 
-       $r = dba::select('user', ['uid', 'username', 'nickname'],
-               ['password' => $master_record['password'], 'email' => $master_record['email'], 'account_removed' => false]);
-       if (DBM::is_result($r)) {
-               $a->identities = dba::inArray($r);
+       if ($master_record['parent-uid'] == 0) {
+               // First add our own entry
+               $a->identities = [['uid' => $master_record['uid'],
+                               'username' => $master_record['username'],
+                               'nickname' => $master_record['nickname']]];
+
+               // Then add all the children
+               $r = dba::select('user', ['uid', 'username', 'nickname'],
+                       ['parent-uid' => $master_record['uid'], 'account_removed' => false]);
+               if (DBM::is_result($r)) {
+                       $a->identities = array_merge($a->identities, dba::inArray($r));
+               }
        } else {
+               // Just ensure that the array is always defined
                $a->identities = [];
+
+               // First entry is our parent
+               $r = dba::select('user', ['uid', 'username', 'nickname'],
+                       ['uid' => $master_record['parent-uid'], 'account_removed' => false]);
+               if (DBM::is_result($r)) {
+                       $a->identities = dba::inArray($r);
+               }
+
+               // Then add all siblings
+               $r = dba::select('user', ['uid', 'username', 'nickname'],
+                       ['parent-uid' => $master_record['parent-uid'], 'account_removed' => false]);
+               if (DBM::is_result($r)) {
+                       $a->identities = array_merge($a->identities, dba::inArray($r));
+               }
        }
 
        $r = dba::p("SELECT `user`.`uid`, `user`.`username`, `user`.`nickname`
@@ -146,7 +169,7 @@ function authenticate_success($user_record, $login_initial = false, $interactive
 
                // Set the login date for all identities of the user
                dba::update('user', ['login_date' => DateTimeFormat::utcNow()],
-                       ['password' => $master_record['password'], 'email' => $master_record['email'], 'account_removed' => false]);
+                       ['parent-uid' => $master_record['uid'], 'account_removed' => false]);
        }
 
        if ($login_initial) {
index a454d414739e0bf2bc7681ec70ab7828cedcebfd..0f60e704e4d299e5566dc044e9ce92646a4d48d9 100644 (file)
@@ -35,8 +35,8 @@ function manage_post(App $a) {
 
        $submanage = $r;
 
-       $identity = ((x($_POST['identity'])) ? intval($_POST['identity']) : 0);
-       if (! $identity) {
+       $identity = (x($_POST['identity']) ? intval($_POST['identity']) : 0);
+       if (!$identity) {
                return;
        }
 
@@ -57,14 +57,36 @@ function manage_post(App $a) {
                        intval($limited_id)
                );
        } else {
-               $r = q("SELECT * FROM `user` WHERE `uid` = %d AND `email` = '%s' AND `password` = '%s' LIMIT 1",
+               // Check if the target user is one of our children
+               $r = q("SELECT * FROM `user` WHERE `uid` = %d AND `parent-uid` = %d LIMIT 1",
                        intval($identity),
-                       dbesc($orig_record['email']),
-                       dbesc($orig_record['password'])
+                       dbesc($orig_record['uid'])
                );
+
+               // Check if the target user is one of our siblings
+               if (!DBM::is_result($r) && ($orig_record['parent-uid'] != 0)) {
+                       $r = q("SELECT * FROM `user` WHERE `uid` = %d AND `parent-uid` = %d LIMIT 1",
+                               intval($identity),
+                               dbesc($orig_record['parent-uid'])
+                       );
+               }
+
+               // Check if it's our parent
+               if (!DBM::is_result($r) && ($orig_record['parent-uid'] != 0) && ($orig_record['parent-uid'] == $identity)) {
+                       $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
+                               intval($identity)
+                       );
+               }
+
+               // Finally check if it's out own user
+               if (!DBM::is_result($r) && ($orig_record['uid'] != 0) && ($orig_record['uid'] == $identity)) {
+                       $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
+                               intval($identity)
+                       );
+               }
        }
 
-       if (! DBM::is_result($r)) {
+       if (!DBM::is_result($r)) {
                return;
        }
 
index 08f77555459b43485a5b0ef9498c6cc5aedffff1..aad4e6fb01dd8df56c91fdf068415937f8f23984 100644 (file)
@@ -1,60 +1,60 @@
-<?php\r
-\r
-namespace Friendica;\r
-\r
-/**\r
- * All modules in Friendica should extend BaseModule, although not all modules\r
- * need to extend all the methods described here\r
- *\r
- * @author Hypolite Petovan mrpetovan@gmail.com\r
- */\r
-abstract class BaseModule extends BaseObject\r
-{\r
-       /**\r
-        * @brief Initialization method common to both content() and post()\r
-        *\r
-        * Extend this method if you need to do any shared processing before both\r
-        * content() or post()\r
-        */\r
-       public static function init()\r
-       {\r
-\r
-       }\r
-\r
-       /**\r
-        * @brief Module GET method to display any content\r
-        *\r
-        * Extend this method if the module is supposed to return any display\r
-        * through a GET request. It can be an HTML page through templating or a\r
-        * XML feed or a JSON output.\r
-        *\r
-        * @return string\r
-        */\r
-       public static function content()\r
-       {\r
-               $o = '';\r
-\r
-               return $o;\r
-       }\r
-\r
-       /**\r
-        * @brief Module POST method to process submitted data\r
-        *\r
-        * Extend this method if the module is supposed to process POST requests.\r
-        * Doesn't display any content\r
-        */\r
-       public static function post()\r
-       {\r
-               // goaway('module');\r
-       }\r
-\r
-       /**\r
-        * @brief Called after post()\r
-        *\r
-        * Unknown purpose\r
-        */\r
-       public static function afterpost()\r
-       {\r
-\r
-       }\r
-}\r
+<?php
+
+namespace Friendica;
+
+/**
+ * All modules in Friendica should extend BaseModule, although not all modules
+ * need to extend all the methods described here
+ *
+ * @author Hypolite Petovan mrpetovan@gmail.com
+ */
+abstract class BaseModule extends BaseObject
+{
+       /**
+        * @brief Initialization method common to both content() and post()
+        *
+        * Extend this method if you need to do any shared processing before both
+        * content() or post()
+        */
+       public static function init()
+       {
+
+       }
+
+       /**
+        * @brief Module GET method to display any content
+        *
+        * Extend this method if the module is supposed to return any display
+        * through a GET request. It can be an HTML page through templating or a
+        * XML feed or a JSON output.
+        *
+        * @return string
+        */
+       public static function content()
+       {
+               $o = '';
+
+               return $o;
+       }
+
+       /**
+        * @brief Module POST method to process submitted data
+        *
+        * Extend this method if the module is supposed to process POST requests.
+        * Doesn't display any content
+        */
+       public static function post()
+       {
+               // goaway('module');
+       }
+
+       /**
+        * @brief Called after post()
+        *
+        * Unknown purpose
+        */
+       public static function afterpost()
+       {
+
+       }
+}
index 2615aa411f91e4dc18f2c52f48729a52a57a1265..1d2f68bc7c4ef2bbc0c930c4c15acdaa01bdcd0d 100644 (file)
@@ -1,39 +1,39 @@
-<?php\r
-\r
-/**\r
- * @file src/Content/Text/Markdown.php\r
- */\r
-\r
-namespace Friendica\Content\Text;\r
-\r
-use Friendica\BaseObject;\r
-use Michelf\MarkdownExtra;\r
-\r
-/**\r
- * Friendica-specific usage of Markdown\r
- *\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-class Markdown extends BaseObject\r
-{\r
-       /**\r
-        * Converts a Markdown string into HTML. The hardwrap parameter maximizes\r
-        * compatibility with Diaspora in spite of the Markdown standard.\r
-        *\r
-        * @brief Converts a Markdown string into HTML\r
-        * @param string $text\r
-        * @param bool   $hardwrap\r
-        * @return string\r
-        */\r
-       public static function convert($text, $hardwrap = true) {\r
-               $stamp1 = microtime(true);\r
-\r
-               $MarkdownParser = new MarkdownExtra();\r
-               $MarkdownParser->hard_wrap = $hardwrap;\r
-               $html = $MarkdownParser->transform($text);\r
-\r
-               self::getApp()->save_timestamp($stamp1, "parser");\r
-\r
-               return $html;\r
-       }\r
-}\r
+<?php
+
+/**
+ * @file src/Content/Text/Markdown.php
+ */
+
+namespace Friendica\Content\Text;
+
+use Friendica\BaseObject;
+use Michelf\MarkdownExtra;
+
+/**
+ * Friendica-specific usage of Markdown
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class Markdown extends BaseObject
+{
+       /**
+        * Converts a Markdown string into HTML. The hardwrap parameter maximizes
+        * compatibility with Diaspora in spite of the Markdown standard.
+        *
+        * @brief Converts a Markdown string into HTML
+        * @param string $text
+        * @param bool   $hardwrap
+        * @return string
+        */
+       public static function convert($text, $hardwrap = true) {
+               $stamp1 = microtime(true);
+
+               $MarkdownParser = new MarkdownExtra();
+               $MarkdownParser->hard_wrap = $hardwrap;
+               $html = $MarkdownParser->transform($text);
+
+               self::getApp()->save_timestamp($stamp1, "parser");
+
+               return $html;
+       }
+}
index 6d53ca9951dcd9c0e596006781201cb48027c50d..19ea3eea0485eed8e3f445bda7b3fe94bdc3f0a9 100644 (file)
-<?php\r
-\r
-/*\r
- * @file src/Content/Widget/TagCloud.php\r
- */\r
-\r
-namespace Friendica\Content\Widget;\r
-\r
-use dba;\r
-use Friendica\Core\L10n;\r
-use Friendica\Core\System;\r
-use Friendica\Database\DBM;\r
-\r
-require_once 'include/dba.php';\r
-require_once 'include/security.php';\r
-\r
-/**\r
- * TagCloud widget\r
- *\r
- * @author Rabuzarus\r
- */\r
-class TagCloud\r
-{\r
-       /**\r
-        * Construct a tag/term cloud block for an user.\r
-        *\r
-        * @brief Construct a tag/term cloud block for an user.\r
-        * @param int $uid      The user ID.\r
-        * @param int $count    Max number of displayed tags/terms.\r
-        * @param int $owner_id The contact ID of the owner of the tagged items.\r
-        * @param string $flags Special item flags.\r
-        * @param int $type     The tag/term type.\r
-        *\r
-        * @return string       HTML formatted output.\r
-        */\r
-       public static function getHTML($uid, $count = 0, $owner_id = 0, $flags = '', $type = TERM_HASHTAG)\r
-       {\r
-               $o = '';\r
-               $r = self::tagadelic($uid, $count, $owner_id, $flags, $type);\r
-               if (count($r)) {\r
-                       $contact = dba::selectFirst('contact', ['url'], ['uid' => $uid, 'self' => true]);\r
-                       $url = System::removedBaseUrl($contact['url']);\r
-\r
-                       foreach ($r as $rr) {\r
-                               $tag['level'] = $rr[2];\r
-                               $tag['url'] = $url . '?tag=' . urlencode($rr[0]);\r
-                               $tag['name'] = $rr[0];\r
-\r
-                               $tags[] = $tag;\r
-                       }\r
-\r
-                       $tpl = get_markup_template('tagblock_widget.tpl');\r
-                       $o = replace_macros($tpl, [\r
-                               '$title' => L10n::t('Tags'),\r
-                               '$tags' => $tags\r
-                       ]);\r
-               }\r
-               return $o;\r
-       }\r
-\r
-       /**\r
-        * Get alphabetical sorted array of used tags/terms of an user including\r
-        * a weighting by frequency of use.\r
-        *\r
-        * @brief Get alphabetical sorted array of used tags/terms of an user including\r
-        * a weighting by frequency of use.\r
-        * @param int $uid      The user ID.\r
-        * @param int $count    Max number of displayed tags/terms.\r
-        * @param int $owner_id The contact id of the owner of the tagged items.\r
-        * @param string $flags Special item flags.\r
-        * @param int $type     The tag/term type.\r
-        *\r
-        * @return arr          Alphabetical sorted array of used tags of an user.\r
-        */\r
-       private static function tagadelic($uid, $count = 0, $owner_id = 0, $flags = '', $type = TERM_HASHTAG)\r
-       {\r
-               $item_condition = item_condition();\r
-               $sql_options = item_permissions_sql($uid);\r
-               $limit = $count ? sprintf('LIMIT %d', intval($count)) : '';\r
-\r
-               if ($flags) {\r
-                       if ($flags === 'wall') {\r
-                               $sql_options .= ' AND `item`.`wall` ';\r
-                       }\r
-               }\r
-\r
-               if ($owner_id) {\r
-                       $sql_options .= ' AND `item`.`owner-id` = ' . intval($owner_id) . ' ';\r
-               }\r
-\r
-               // Fetch tags\r
-               $r = dba::p("SELECT `term`, COUNT(`term`) AS `total` FROM `term`\r
-                       LEFT JOIN `item` ON `term`.`oid` = `item`.`id`\r
-                       WHERE `term`.`uid` = ? AND `term`.`type` = ?\r
-                       AND `term`.`otype` = ?\r
-                       AND $item_condition $sql_options\r
-                       GROUP BY `term` ORDER BY `total` DESC $limit",\r
-                       $uid,\r
-                       $type,\r
-                       TERM_OBJ_POST\r
-               );\r
-               if (!DBM::is_result($r)) {\r
-                       return [];\r
-               }\r
-\r
-               return self::tagCalc($r);\r
-       }\r
-\r
-       /**\r
-        * Calculate weighting of tags according to the frequency of use.\r
-        *\r
-        * @brief Calculate weighting of tags according to the frequency of use.\r
-        * @param array $arr Array of tags/terms with tag/term name and total count of use.\r
-        * @return array     Alphabetical sorted array of used tags/terms of an user.\r
-        */\r
-       private static function tagCalc($arr)\r
-       {\r
-               $tags = [];\r
-               $min = 1e9;\r
-               $max = -1e9;\r
-               $x = 0;\r
-\r
-               if (!$arr) {\r
-                       return [];\r
-               }\r
-\r
-               foreach ($arr as $rr) {\r
-                       $tags[$x][0] = $rr['term'];\r
-                       $tags[$x][1] = log($rr['total']);\r
-                       $tags[$x][2] = 0;\r
-                       $min = min($min, $tags[$x][1]);\r
-                       $max = max($max, $tags[$x][1]);\r
-                       $x ++;\r
-               }\r
-\r
-               usort($tags, 'self::tagsSort');\r
-               $range = max(.01, $max - $min) * 1.0001;\r
-\r
-               for ($x = 0; $x < count($tags); $x ++) {\r
-                       $tags[$x][2] = 1 + floor(9 * ($tags[$x][1] - $min) / $range);\r
-               }\r
-\r
-               return $tags;\r
-       }\r
-\r
-       /**\r
-        * Compare function to sort tags/terms alphabetically.\r
-        *\r
-        * @brief Compare function to sort tags/terms alphabetically.\r
-        * @param type $a\r
-        * @param type $b\r
-        *\r
-        * @return int\r
-        */\r
-       private static function tagsSort($a, $b)\r
-       {\r
-               if (strtolower($a[0]) == strtolower($b[0])) {\r
-                       return 0;\r
-               }\r
-               return ((strtolower($a[0]) < strtolower($b[0])) ? -1 : 1);\r
-       }\r
-}\r
+<?php
+
+/*
+ * @file src/Content/Widget/TagCloud.php
+ */
+
+namespace Friendica\Content\Widget;
+
+use dba;
+use Friendica\Core\L10n;
+use Friendica\Core\System;
+use Friendica\Database\DBM;
+
+require_once 'include/dba.php';
+require_once 'include/security.php';
+
+/**
+ * TagCloud widget
+ *
+ * @author Rabuzarus
+ */
+class TagCloud
+{
+       /**
+        * Construct a tag/term cloud block for an user.
+        *
+        * @brief Construct a tag/term cloud block for an user.
+        * @param int $uid      The user ID.
+        * @param int $count    Max number of displayed tags/terms.
+        * @param int $owner_id The contact ID of the owner of the tagged items.
+        * @param string $flags Special item flags.
+        * @param int $type     The tag/term type.
+        *
+        * @return string       HTML formatted output.
+        */
+       public static function getHTML($uid, $count = 0, $owner_id = 0, $flags = '', $type = TERM_HASHTAG)
+       {
+               $o = '';
+               $r = self::tagadelic($uid, $count, $owner_id, $flags, $type);
+               if (count($r)) {
+                       $contact = dba::selectFirst('contact', ['url'], ['uid' => $uid, 'self' => true]);
+                       $url = System::removedBaseUrl($contact['url']);
+
+                       foreach ($r as $rr) {
+                               $tag['level'] = $rr[2];
+                               $tag['url'] = $url . '?tag=' . urlencode($rr[0]);
+                               $tag['name'] = $rr[0];
+
+                               $tags[] = $tag;
+                       }
+
+                       $tpl = get_markup_template('tagblock_widget.tpl');
+                       $o = replace_macros($tpl, [
+                               '$title' => L10n::t('Tags'),
+                               '$tags' => $tags
+                       ]);
+               }
+               return $o;
+       }
+
+       /**
+        * Get alphabetical sorted array of used tags/terms of an user including
+        * a weighting by frequency of use.
+        *
+        * @brief Get alphabetical sorted array of used tags/terms of an user including
+        * a weighting by frequency of use.
+        * @param int $uid      The user ID.
+        * @param int $count    Max number of displayed tags/terms.
+        * @param int $owner_id The contact id of the owner of the tagged items.
+        * @param string $flags Special item flags.
+        * @param int $type     The tag/term type.
+        *
+        * @return arr          Alphabetical sorted array of used tags of an user.
+        */
+       private static function tagadelic($uid, $count = 0, $owner_id = 0, $flags = '', $type = TERM_HASHTAG)
+       {
+               $item_condition = item_condition();
+               $sql_options = item_permissions_sql($uid);
+               $limit = $count ? sprintf('LIMIT %d', intval($count)) : '';
+
+               if ($flags) {
+                       if ($flags === 'wall') {
+                               $sql_options .= ' AND `item`.`wall` ';
+                       }
+               }
+
+               if ($owner_id) {
+                       $sql_options .= ' AND `item`.`owner-id` = ' . intval($owner_id) . ' ';
+               }
+
+               // Fetch tags
+               $r = dba::p("SELECT `term`, COUNT(`term`) AS `total` FROM `term`
+                       LEFT JOIN `item` ON `term`.`oid` = `item`.`id`
+                       WHERE `term`.`uid` = ? AND `term`.`type` = ?
+                       AND `term`.`otype` = ?
+                       AND $item_condition $sql_options
+                       GROUP BY `term` ORDER BY `total` DESC $limit",
+                       $uid,
+                       $type,
+                       TERM_OBJ_POST
+               );
+               if (!DBM::is_result($r)) {
+                       return [];
+               }
+
+               return self::tagCalc($r);
+       }
+
+       /**
+        * Calculate weighting of tags according to the frequency of use.
+        *
+        * @brief Calculate weighting of tags according to the frequency of use.
+        * @param array $arr Array of tags/terms with tag/term name and total count of use.
+        * @return array     Alphabetical sorted array of used tags/terms of an user.
+        */
+       private static function tagCalc($arr)
+       {
+               $tags = [];
+               $min = 1e9;
+               $max = -1e9;
+               $x = 0;
+
+               if (!$arr) {
+                       return [];
+               }
+
+               foreach ($arr as $rr) {
+                       $tags[$x][0] = $rr['term'];
+                       $tags[$x][1] = log($rr['total']);
+                       $tags[$x][2] = 0;
+                       $min = min($min, $tags[$x][1]);
+                       $max = max($max, $tags[$x][1]);
+                       $x ++;
+               }
+
+               usort($tags, 'self::tagsSort');
+               $range = max(.01, $max - $min) * 1.0001;
+
+               for ($x = 0; $x < count($tags); $x ++) {
+                       $tags[$x][2] = 1 + floor(9 * ($tags[$x][1] - $min) / $range);
+               }
+
+               return $tags;
+       }
+
+       /**
+        * Compare function to sort tags/terms alphabetically.
+        *
+        * @brief Compare function to sort tags/terms alphabetically.
+        * @param type $a
+        * @param type $b
+        *
+        * @return int
+        */
+       private static function tagsSort($a, $b)
+       {
+               if (strtolower($a[0]) == strtolower($b[0])) {
+                       return 0;
+               }
+               return ((strtolower($a[0]) < strtolower($b[0])) ? -1 : 1);
+       }
+}
index b5c09f745b27a549f637f9793ce849deac64f8e4..20d1e9ef7b521e6aac48cce6e357a2633078eadb 100644 (file)
@@ -1,57 +1,57 @@
-<?php\r
-\r
-/**\r
- * @file src/Core/Session.php\r
- */\r
-namespace Friendica\Core;\r
-\r
-use Friendica\Core\Session\DatabaseSessionHandler;\r
-use Friendica\Core\Session\MemcacheSessionHandler;\r
-\r
-/**\r
- * High-level Session service class\r
- *\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-class Session\r
-{\r
-       public static $exists = false;\r
-       public static $expire = 180000;\r
-\r
-       public static function init()\r
-       {\r
-               ini_set('session.gc_probability', 50);\r
-               ini_set('session.use_only_cookies', 1);\r
-               ini_set('session.cookie_httponly', 1);\r
-\r
-               if (Config::get('system', 'ssl_policy') == SSL_POLICY_FULL) {\r
-                       ini_set('session.cookie_secure', 1);\r
-               }\r
-\r
-               if (!Config::get('system', 'disable_database_session')) {\r
-                       $memcache = Cache::memcache();\r
-                       if (is_object($memcache)) {\r
-                               $SessionHandler = new MemcacheSessionHandler($memcache);\r
-                       } else {\r
-                               $SessionHandler = new DatabaseSessionHandler();\r
-                       }\r
-\r
-                       session_set_save_handler($SessionHandler);\r
-               }\r
-       }\r
-\r
-       public static function exists($name)\r
-       {\r
-               return isset($_SESSION[$name]);\r
-       }\r
-\r
-       public static function get($name)\r
-       {\r
-               return defaults($_SESSION, $name, null);\r
-       }\r
-\r
-       public static function set($name, $value)\r
-       {\r
-               $_SESSION[$name] = $value;\r
-       }\r
-}\r
+<?php
+
+/**
+ * @file src/Core/Session.php
+ */
+namespace Friendica\Core;
+
+use Friendica\Core\Session\DatabaseSessionHandler;
+use Friendica\Core\Session\MemcacheSessionHandler;
+
+/**
+ * High-level Session service class
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class Session
+{
+       public static $exists = false;
+       public static $expire = 180000;
+
+       public static function init()
+       {
+               ini_set('session.gc_probability', 50);
+               ini_set('session.use_only_cookies', 1);
+               ini_set('session.cookie_httponly', 1);
+
+               if (Config::get('system', 'ssl_policy') == SSL_POLICY_FULL) {
+                       ini_set('session.cookie_secure', 1);
+               }
+
+               if (!Config::get('system', 'disable_database_session')) {
+                       $memcache = Cache::memcache();
+                       if (is_object($memcache)) {
+                               $SessionHandler = new MemcacheSessionHandler($memcache);
+                       } else {
+                               $SessionHandler = new DatabaseSessionHandler();
+                       }
+
+                       session_set_save_handler($SessionHandler);
+               }
+       }
+
+       public static function exists($name)
+       {
+               return isset($_SESSION[$name]);
+       }
+
+       public static function get($name)
+       {
+               return defaults($_SESSION, $name, null);
+       }
+
+       public static function set($name, $value)
+       {
+               $_SESSION[$name] = $value;
+       }
+}
index d017e2edd23968157caa1e67550b27b591b2e8b5..f69531a8882ebb954f0e3324ae331b1dc70e7f49 100644 (file)
@@ -1,95 +1,95 @@
-<?php\r
-\r
-namespace Friendica\Core\Session;\r
-\r
-use Friendica\BaseObject;\r
-use Friendica\Core\Session;\r
-use Friendica\Database\DBM;\r
-use SessionHandlerInterface;\r
-use dba;\r
-\r
-require_once 'boot.php';\r
-require_once 'include/dba.php';\r
-require_once 'include/text.php';\r
-\r
-/**\r
- * SessionHandler using database\r
- *\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-class DatabaseSessionHandler extends BaseObject implements SessionHandlerInterface\r
-{\r
-       public function open($save_path, $session_name)\r
-       {\r
-               return true;\r
-       }\r
-\r
-       public function read($session_id)\r
-       {\r
-               if (!x($session_id)) {\r
-                       return '';\r
-               }\r
-\r
-               $session = dba::selectFirst('session', ['data'], ['sid' => $session_id]);\r
-               if (DBM::is_result($session)) {\r
-                       Session::$exists = true;\r
-                       return $session['data'];\r
-               }\r
-               logger("no data for session $session_id", LOGGER_TRACE);\r
-\r
-               return '';\r
-       }\r
-\r
-       /**\r
-        * @brief Standard PHP session write callback\r
-        *\r
-        * This callback updates the DB-stored session data and/or the expiration depending\r
-        * on the case. Uses the Session::expire global for existing session, 5 minutes\r
-        * for newly created session.\r
-        *\r
-        * @param  string $session_id   Session ID with format: [a-z0-9]{26}\r
-        * @param  string $session_data Serialized session data\r
-        * @return boolean Returns false if parameters are missing, true otherwise\r
-        */\r
-       public function write($session_id, $session_data)\r
-       {\r
-               if (!$session_id) {\r
-                       return false;\r
-               }\r
-\r
-               if (!$session_data) {\r
-                       return true;\r
-               }\r
-\r
-               $expire = time() + Session::$expire;\r
-               $default_expire = time() + 300;\r
-\r
-               if (Session::$exists) {\r
-                       $fields = ['data' => $session_data, 'expire' => $expire];\r
-                       $condition = ["`sid` = ? AND (`data` != ? OR `expire` != ?)", $session_id, $session_data, $expire];\r
-                       dba::update('session', $fields, $condition);\r
-               } else {\r
-                       $fields = ['sid' => $session_id, 'expire' => $default_expire, 'data' => $session_data];\r
-                       dba::insert('session', $fields);\r
-               }\r
-\r
-               return true;\r
-       }\r
-\r
-       public function close()\r
-       {\r
-               return true;\r
-       }\r
-\r
-       public function destroy($id)\r
-       {\r
-               dba::delete('session', ['sid' => $id]);\r
-               return true;\r
-       }\r
-\r
-       public function gc($maxlifetime)\r
-       {\r
-               dba::delete('session', ["`expire` < ?", time()]);\r
-               return true;\r
-       }\r
-}\r
+<?php
+
+namespace Friendica\Core\Session;
+
+use Friendica\BaseObject;
+use Friendica\Core\Session;
+use Friendica\Database\DBM;
+use SessionHandlerInterface;
+use dba;
+
+require_once 'boot.php';
+require_once 'include/dba.php';
+require_once 'include/text.php';
+
+/**
+ * SessionHandler using database
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class DatabaseSessionHandler extends BaseObject implements SessionHandlerInterface
+{
+       public function open($save_path, $session_name)
+       {
+               return true;
+       }
+
+       public function read($session_id)
+       {
+               if (!x($session_id)) {
+                       return '';
+               }
+
+               $session = dba::selectFirst('session', ['data'], ['sid' => $session_id]);
+               if (DBM::is_result($session)) {
+                       Session::$exists = true;
+                       return $session['data'];
+               }
+               logger("no data for session $session_id", LOGGER_TRACE);
+
+               return '';
+       }
+
+       /**
+        * @brief Standard PHP session write callback
+        *
+        * This callback updates the DB-stored session data and/or the expiration depending
+        * on the case. Uses the Session::expire global for existing session, 5 minutes
+        * for newly created session.
+        *
+        * @param  string $session_id   Session ID with format: [a-z0-9]{26}
+        * @param  string $session_data Serialized session data
+        * @return boolean Returns false if parameters are missing, true otherwise
+        */
+       public function write($session_id, $session_data)
+       {
+               if (!$session_id) {
+                       return false;
+               }
+
+               if (!$session_data) {
+                       return true;
+               }
+
+               $expire = time() + Session::$expire;
+               $default_expire = time() + 300;
+
+               if (Session::$exists) {
+                       $fields = ['data' => $session_data, 'expire' => $expire];
+                       $condition = ["`sid` = ? AND (`data` != ? OR `expire` != ?)", $session_id, $session_data, $expire];
+                       dba::update('session', $fields, $condition);
+               } else {
+                       $fields = ['sid' => $session_id, 'expire' => $default_expire, 'data' => $session_data];
+                       dba::insert('session', $fields);
+               }
+
+               return true;
+       }
+
+       public function close()
+       {
+               return true;
+       }
+
+       public function destroy($id)
+       {
+               dba::delete('session', ['sid' => $id]);
+               return true;
+       }
+
+       public function gc($maxlifetime)
+       {
+               dba::delete('session', ["`expire` < ?", time()]);
+               return true;
+       }
+}
index dce206e64cbaa5efb00ddb2641a9b67935b46093..0bc5e8bfe924ea8d95bd7fb2252924734986b5db 100644 (file)
-<?php\r
-\r
-namespace Friendica\Core\Session;\r
-\r
-use Friendica\BaseObject;\r
-use Friendica\Core\Session;\r
-use SessionHandlerInterface;\r
-use Memcache;\r
-\r
-require_once 'boot.php';\r
-require_once 'include/text.php';\r
-\r
-/**\r
- * SessionHandler using Memcache\r
- *\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-class MemcacheSessionHandler extends BaseObject implements SessionHandlerInterface\r
-{\r
-       /**\r
-        * @var Memcache\r
-        */\r
-       private $memcache = null;\r
-\r
-       /**\r
-        *\r
-        * @param Memcache $memcache\r
-        */\r
-       public function __construct(Memcache $memcache)\r
-       {\r
-               $this->memcache = $memcache;\r
-       }\r
-\r
-       public function open($save_path, $session_name)\r
-       {\r
-               return true;\r
-       }\r
-\r
-       public function read($session_id)\r
-       {\r
-               if (!x($session_id)) {\r
-                       return '';\r
-               }\r
-\r
-               $data = $this->memcache->get(self::getApp()->get_hostname() . ":session:" . $session_id);\r
-               if (!is_bool($data)) {\r
-                       Session::$exists = true;\r
-                       return $data;\r
-               }\r
-               logger("no data for session $session_id", LOGGER_TRACE);\r
-               return '';\r
-       }\r
-\r
-       /**\r
-        * @brief Standard PHP session write callback\r
-        *\r
-        * This callback updates the stored session data and/or the expiration depending\r
-        * on the case. Uses the Session::expire for existing session, 5 minutes\r
-        * for newly created session.\r
-        *\r
-        * @param  string $session_id   Session ID with format: [a-z0-9]{26}\r
-        * @param  string $session_data Serialized session data\r
-        * @return boolean Returns false if parameters are missing, true otherwise\r
-        */\r
-       public function write($session_id, $session_data)\r
-       {\r
-               if (!$session_id) {\r
-                       return false;\r
-               }\r
-\r
-               if (!$session_data) {\r
-                       return true;\r
-               }\r
-\r
-               $expire = time() + Session::$expire;\r
-\r
-               $this->memcache->set(\r
-                       self::getApp()->get_hostname() . ":session:" . $session_id,\r
-                       $session_data,\r
-                       MEMCACHE_COMPRESSED,\r
-                       $expire\r
-               );\r
-\r
-               return true;\r
-       }\r
-\r
-       public function close()\r
-       {\r
-               return true;\r
-       }\r
-\r
-       public function destroy($id)\r
-       {\r
-               $this->memcache->delete(self::getApp()->get_hostname() . ":session:" . $id);\r
-               return true;\r
-       }\r
-\r
-       public function gc($maxlifetime)\r
-       {\r
-               return true;\r
-       }\r
-}\r
+<?php
+
+namespace Friendica\Core\Session;
+
+use Friendica\BaseObject;
+use Friendica\Core\Session;
+use SessionHandlerInterface;
+use Memcache;
+
+require_once 'boot.php';
+require_once 'include/text.php';
+
+/**
+ * SessionHandler using Memcache
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class MemcacheSessionHandler extends BaseObject implements SessionHandlerInterface
+{
+       /**
+        * @var Memcache
+        */
+       private $memcache = null;
+
+       /**
+        *
+        * @param Memcache $memcache
+        */
+       public function __construct(Memcache $memcache)
+       {
+               $this->memcache = $memcache;
+       }
+
+       public function open($save_path, $session_name)
+       {
+               return true;
+       }
+
+       public function read($session_id)
+       {
+               if (!x($session_id)) {
+                       return '';
+               }
+
+               $data = $this->memcache->get(self::getApp()->get_hostname() . ":session:" . $session_id);
+               if (!is_bool($data)) {
+                       Session::$exists = true;
+                       return $data;
+               }
+               logger("no data for session $session_id", LOGGER_TRACE);
+               return '';
+       }
+
+       /**
+        * @brief Standard PHP session write callback
+        *
+        * This callback updates the stored session data and/or the expiration depending
+        * on the case. Uses the Session::expire for existing session, 5 minutes
+        * for newly created session.
+        *
+        * @param  string $session_id   Session ID with format: [a-z0-9]{26}
+        * @param  string $session_data Serialized session data
+        * @return boolean Returns false if parameters are missing, true otherwise
+        */
+       public function write($session_id, $session_data)
+       {
+               if (!$session_id) {
+                       return false;
+               }
+
+               if (!$session_data) {
+                       return true;
+               }
+
+               $expire = time() + Session::$expire;
+
+               $this->memcache->set(
+                       self::getApp()->get_hostname() . ":session:" . $session_id,
+                       $session_data,
+                       MEMCACHE_COMPRESSED,
+                       $expire
+               );
+
+               return true;
+       }
+
+       public function close()
+       {
+               return true;
+       }
+
+       public function destroy($id)
+       {
+               $this->memcache->delete(self::getApp()->get_hostname() . ":session:" . $id);
+               return true;
+       }
+
+       public function gc($maxlifetime)
+       {
+               return true;
+       }
+}
index 9e7c6329822d70e8da7908edc368c46da20371c1..9133eae187a4d5505e54e1b439ecf4d981fd118c 100644 (file)
-<?php\r
-/**\r
- * @file src/Core/Theme.php\r
- */\r
-namespace Friendica\Core;\r
-\r
-use Friendica\Core\System;\r
-\r
-require_once 'boot.php';\r
-\r
-/**\r
- * Some functions to handle themes\r
- */\r
-class Theme\r
-{\r
-    /**\r
-     * @brief Parse theme comment in search of theme infos.\r
-     *\r
-     * like\r
-     * \code\r
-     * ..* Name: My Theme\r
-     *   * Description: My Cool Theme\r
-     * . * Version: 1.2.3\r
-     *   * Author: John <profile url>\r
-     *   * Maintainer: Jane <profile url>\r
-     *   *\r
-     * \endcode\r
-     * @param string $theme the name of the theme\r
-     * @return array\r
-     */\r
-\r
-    public static function getInfo($theme)\r
-    {\r
-        $info=[\r
-            'name' => $theme,\r
-            'description' => "",\r
-            'author' => [],\r
-            'maintainer' => [],\r
-            'version' => "",\r
-            'credits' => "",\r
-            'experimental' => false,\r
-            'unsupported' => false\r
-        ];\r
-\r
-        if (file_exists("view/theme/$theme/experimental"))\r
-            $info['experimental'] = true;\r
-        if (file_exists("view/theme/$theme/unsupported"))\r
-            $info['unsupported'] = true;\r
-\r
-        if (!is_file("view/theme/$theme/theme.php")) return $info;\r
-\r
-        $a = get_app();\r
-        $stamp1 = microtime(true);\r
-        $f = file_get_contents("view/theme/$theme/theme.php");\r
-        $a->save_timestamp($stamp1, "file");\r
-\r
-        $r = preg_match("|/\*.*\*/|msU", $f, $m);\r
-\r
-        if ($r) {\r
-            $ll = explode("\n", $m[0]);\r
-            foreach ( $ll as $l ) {\r
-                $l = trim($l,"\t\n\r */");\r
-                if ($l != "") {\r
-                    list($k, $v) = array_map("trim", explode(":", $l, 2));\r
-                    $k= strtolower($k);\r
-                    if ($k == "author") {\r
-\r
-                        $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);\r
-                        if ($r) {\r
-                            $info['author'][] = ['name'=>$m[1], 'link'=>$m[2]];\r
-                        } else {\r
-                            $info['author'][] = ['name'=>$v];\r
-                        }\r
-                    } elseif ($k == "maintainer") {\r
-                        $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);\r
-                        if ($r) {\r
-                            $info['maintainer'][] = ['name'=>$m[1], 'link'=>$m[2]];\r
-                        } else {\r
-                            $info['maintainer'][] = ['name'=>$v];\r
-                        }\r
-                    } else {\r
-                        if (array_key_exists($k, $info)) {\r
-                            $info[$k] = $v;\r
-                        }\r
-                    }\r
-                }\r
-            }\r
-        }\r
-        return $info;\r
-    }\r
-\r
-    /**\r
-     * @brief Returns the theme's screenshot.\r
-     *\r
-     * The screenshot is expected as view/theme/$theme/screenshot.[png|jpg].\r
-     *\r
-     * @param sring $theme The name of the theme\r
-     * @return string\r
-     */\r
-    public static function getScreenshot($theme)\r
-    {\r
-        $exts = ['.png','.jpg'];\r
-        foreach ($exts as $ext) {\r
-            if (file_exists('view/theme/' . $theme . '/screenshot' . $ext)) {\r
-                return(System::baseUrl() . '/view/theme/' . $theme . '/screenshot' . $ext);\r
-            }\r
-        }\r
-        return(System::baseUrl() . '/images/blank.png');\r
-    }\r
-\r
-    // install and uninstall theme\r
-    public static function uninstall($theme)\r
-    {\r
-        logger("Addons: uninstalling theme " . $theme);\r
-\r
-        include_once("view/theme/$theme/theme.php");\r
-        if (function_exists("{$theme}_uninstall")) {\r
-            $func = "{$theme}_uninstall";\r
-            $func();\r
-        }\r
-    }\r
-\r
-    public static function install($theme)\r
-    {\r
-        // silently fail if theme was removed\r
-\r
-        if (! file_exists("view/theme/$theme/theme.php")) {\r
-            return false;\r
-        }\r
-\r
-        logger("Addons: installing theme $theme");\r
-\r
-        include_once("view/theme/$theme/theme.php");\r
-\r
-        if (function_exists("{$theme}_install")) {\r
-            $func = "{$theme}_install";\r
-            $func();\r
-            return true;\r
-        } else {\r
-            logger("Addons: FAILED installing theme $theme");\r
-            return false;\r
-        }\r
-\r
-    }\r
-\r
-    /**\r
-     * @brief Get the full path to relevant theme files by filename\r
-     *\r
-     * This function search in the theme directory (and if not present in global theme directory)\r
-     * if there is a directory with the file extension and  for a file with the given\r
-     * filename.\r
-     *\r
-     * @param string $file Filename\r
-     * @param string $root Full root path\r
-     * @return string Path to the file or empty string if the file isn't found\r
-     */\r
-    public static function getPathForFile($file, $root = '')\r
-    {\r
-        $file = basename($file);\r
-\r
-        // Make sure $root ends with a slash / if it's not blank\r
-        if ($root !== '' && $root[strlen($root)-1] !== '/') {\r
-            $root = $root . '/';\r
-        }\r
-        $theme_info = get_app()->theme_info;\r
-        if (is_array($theme_info) && array_key_exists('extends',$theme_info)) {\r
-            $parent = $theme_info['extends'];\r
-        } else {\r
-            $parent = 'NOPATH';\r
-        }\r
-        $theme = current_theme();\r
-        $thname = $theme;\r
-        $ext = substr($file,strrpos($file,'.')+1);\r
-        $paths = [\r
-            "{$root}view/theme/$thname/$ext/$file",\r
-            "{$root}view/theme/$parent/$ext/$file",\r
-            "{$root}view/$ext/$file",\r
-        ];\r
-        foreach ($paths as $p) {\r
-            // strpos() is faster than strstr when checking if one string is in another (http://php.net/manual/en/function.strstr.php)\r
-            if (strpos($p,'NOPATH') !== false) {\r
-                continue;\r
-            } elseif (file_exists($p)) {\r
-                return $p;\r
-            }\r
-        }\r
-        return '';\r
-    }\r
-}\r
+<?php
+/**
+ * @file src/Core/Theme.php
+ */
+namespace Friendica\Core;
+
+use Friendica\Core\System;
+
+require_once 'boot.php';
+
+/**
+ * Some functions to handle themes
+ */
+class Theme
+{
+    /**
+     * @brief Parse theme comment in search of theme infos.
+     *
+     * like
+     * \code
+     * ..* Name: My Theme
+     *   * Description: My Cool Theme
+     * . * Version: 1.2.3
+     *   * Author: John <profile url>
+     *   * Maintainer: Jane <profile url>
+     *   *
+     * \endcode
+     * @param string $theme the name of the theme
+     * @return array
+     */
+
+    public static function getInfo($theme)
+    {
+        $info=[
+            'name' => $theme,
+            'description' => "",
+            'author' => [],
+            'maintainer' => [],
+            'version' => "",
+            'credits' => "",
+            'experimental' => false,
+            'unsupported' => false
+        ];
+
+        if (file_exists("view/theme/$theme/experimental"))
+            $info['experimental'] = true;
+        if (file_exists("view/theme/$theme/unsupported"))
+            $info['unsupported'] = true;
+
+        if (!is_file("view/theme/$theme/theme.php")) return $info;
+
+        $a = get_app();
+        $stamp1 = microtime(true);
+        $f = file_get_contents("view/theme/$theme/theme.php");
+        $a->save_timestamp($stamp1, "file");
+
+        $r = preg_match("|/\*.*\*/|msU", $f, $m);
+
+        if ($r) {
+            $ll = explode("\n", $m[0]);
+            foreach ( $ll as $l ) {
+                $l = trim($l,"\t\n\r */");
+                if ($l != "") {
+                    list($k, $v) = array_map("trim", explode(":", $l, 2));
+                    $k= strtolower($k);
+                    if ($k == "author") {
+
+                        $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
+                        if ($r) {
+                            $info['author'][] = ['name'=>$m[1], 'link'=>$m[2]];
+                        } else {
+                            $info['author'][] = ['name'=>$v];
+                        }
+                    } elseif ($k == "maintainer") {
+                        $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
+                        if ($r) {
+                            $info['maintainer'][] = ['name'=>$m[1], 'link'=>$m[2]];
+                        } else {
+                            $info['maintainer'][] = ['name'=>$v];
+                        }
+                    } else {
+                        if (array_key_exists($k, $info)) {
+                            $info[$k] = $v;
+                        }
+                    }
+                }
+            }
+        }
+        return $info;
+    }
+
+    /**
+     * @brief Returns the theme's screenshot.
+     *
+     * The screenshot is expected as view/theme/$theme/screenshot.[png|jpg].
+     *
+     * @param sring $theme The name of the theme
+     * @return string
+     */
+    public static function getScreenshot($theme)
+    {
+        $exts = ['.png','.jpg'];
+        foreach ($exts as $ext) {
+            if (file_exists('view/theme/' . $theme . '/screenshot' . $ext)) {
+                return(System::baseUrl() . '/view/theme/' . $theme . '/screenshot' . $ext);
+            }
+        }
+        return(System::baseUrl() . '/images/blank.png');
+    }
+
+    // install and uninstall theme
+    public static function uninstall($theme)
+    {
+        logger("Addons: uninstalling theme " . $theme);
+
+        include_once("view/theme/$theme/theme.php");
+        if (function_exists("{$theme}_uninstall")) {
+            $func = "{$theme}_uninstall";
+            $func();
+        }
+    }
+
+    public static function install($theme)
+    {
+        // silently fail if theme was removed
+
+        if (! file_exists("view/theme/$theme/theme.php")) {
+            return false;
+        }
+
+        logger("Addons: installing theme $theme");
+
+        include_once("view/theme/$theme/theme.php");
+
+        if (function_exists("{$theme}_install")) {
+            $func = "{$theme}_install";
+            $func();
+            return true;
+        } else {
+            logger("Addons: FAILED installing theme $theme");
+            return false;
+        }
+
+    }
+
+    /**
+     * @brief Get the full path to relevant theme files by filename
+     *
+     * This function search in the theme directory (and if not present in global theme directory)
+     * if there is a directory with the file extension and  for a file with the given
+     * filename.
+     *
+     * @param string $file Filename
+     * @param string $root Full root path
+     * @return string Path to the file or empty string if the file isn't found
+     */
+    public static function getPathForFile($file, $root = '')
+    {
+        $file = basename($file);
+
+        // Make sure $root ends with a slash / if it's not blank
+        if ($root !== '' && $root[strlen($root)-1] !== '/') {
+            $root = $root . '/';
+        }
+        $theme_info = get_app()->theme_info;
+        if (is_array($theme_info) && array_key_exists('extends',$theme_info)) {
+            $parent = $theme_info['extends'];
+        } else {
+            $parent = 'NOPATH';
+        }
+        $theme = current_theme();
+        $thname = $theme;
+        $ext = substr($file,strrpos($file,'.')+1);
+        $paths = [
+            "{$root}view/theme/$thname/$ext/$file",
+            "{$root}view/theme/$parent/$ext/$file",
+            "{$root}view/$ext/$file",
+        ];
+        foreach ($paths as $p) {
+            // strpos() is faster than strstr when checking if one string is in another (http://php.net/manual/en/function.strstr.php)
+            if (strpos($p,'NOPATH') !== false) {
+                continue;
+            } elseif (file_exists($p)) {
+                return $p;
+            }
+        }
+        return '';
+    }
+}
index 9ab866de9dc0eb18701f9ffcd27fa080a2175a79..9c3c0d82a3c259f00a54992a9de27a5df9e08718 100644 (file)
@@ -1707,6 +1707,7 @@ class DBStructure
                                "comment" => "The local users",
                                "fields" => [
                                                "uid" => ["type" => "mediumint", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => ""],
+                                               "parent-uid" => ["type" => "mediumint", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "The parent user that has full control about this user"],
                                                "guid" => ["type" => "varchar(64)", "not null" => "1", "default" => "", "comment" => ""],
                                                "username" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
                                                "password" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
index dba2b321286a8de9db7b84c840509ad96af244c3..0b9321b3405777df5ca3f9861d244a9a65b327c0 100644 (file)
-<?php\r
-/**\r
- * @file src/Database/PostUpdate.php\r
- */\r
-namespace Friendica\Database;\r
-\r
-use Friendica\Core\Config;\r
-use Friendica\Database\DBM;\r
-use Friendica\Model\Contact;\r
-use Friendica\Model\GContact;\r
-use dba;\r
-\r
-require_once 'include/dba.php';\r
-\r
-/**\r
- * Post update functions\r
- */\r
-class PostUpdate\r
-{\r
-    /**\r
-     * @brief Calls the post update functions\r
-     */\r
-    public static function update()\r
-    {\r
-        if (!self::update1192()) {\r
-            return;\r
-        }\r
-        if (!self::update1194()) {\r
-            return;\r
-        }\r
-        if (!self::update1198()) {\r
-            return;\r
-        }\r
-        if (!self::update1206()) {\r
-            return;\r
-        }\r
-    }\r
-\r
-    /**\r
-     * @brief set the gcontact-id in all item entries\r
-     *\r
-     * This job has to be started multiple times until all entries are set.\r
-     * It isn't started in the update function since it would consume too much time and can be done in the background.\r
-     *\r
-     * @return bool "true" when the job is done\r
-     */\r
-    private static function update1192()\r
-    {\r
-        // Was the script completed?\r
-        if (Config::get("system", "post_update_version") >= 1192) {\r
-            return true;\r
-        }\r
-\r
-        // Check if the first step is done (Setting "gcontact-id" in the item table)\r
-        $r = dba::select('item', ['author-link', 'author-name', 'author-avatar', 'uid', 'network'], ['gcontact-id' => 0], ['limit' => 1000]);\r
-        if (!$r) {\r
-            // Are there unfinished entries in the thread table?\r
-            $r = q("SELECT COUNT(*) AS `total` FROM `thread`\r
-                INNER JOIN `item` ON `item`.`id` =`thread`.`iid`\r
-                WHERE `thread`.`gcontact-id` = 0 AND\r
-                    (`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");\r
-\r
-            if ($r && ($r[0]["total"] == 0)) {\r
-                Config::set("system", "post_update_version", 1192);\r
-                return true;\r
-            }\r
-\r
-            // Update the thread table from the item table\r
-            q("UPDATE `thread` INNER JOIN `item` ON `item`.`id`=`thread`.`iid`\r
-                    SET `thread`.`gcontact-id` = `item`.`gcontact-id`\r
-                WHERE `thread`.`gcontact-id` = 0 AND\r
-                    (`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");\r
-\r
-            return false;\r
-        }\r
-\r
-        $item_arr = [];\r
-        foreach ($r as $item) {\r
-            $index = $item["author-link"]."-".$item["uid"];\r
-            $item_arr[$index] = ["author-link" => $item["author-link"],\r
-                            "uid" => $item["uid"],\r
-                            "network" => $item["network"]];\r
-        }\r
-\r
-        // Set the "gcontact-id" in the item table and add a new gcontact entry if needed\r
-        foreach ($item_arr as $item) {\r
-            $gcontact_id = GContact::getId(["url" => $item['author-link'], "network" => $item['network'],\r
-                            "photo" => $item['author-avatar'], "name" => $item['author-name']]);\r
-            dba::update('item', ['gcontact-id' => $gcontact_id], ['uid' => $item['uid'], 'author-link' => $item['author-link'], 'gcontact-id' => 0]);\r
-        }\r
-        return false;\r
-    }\r
-\r
-    /**\r
-     * @brief Updates the "global" field in the item table\r
-     *\r
-     * @return bool "true" when the job is done\r
-     */\r
-    private static function update1194()\r
-    {\r
-        // Was the script completed?\r
-        if (Config::get("system", "post_update_version") >= 1194) {\r
-            return true;\r
-        }\r
-\r
-        logger("Start", LOGGER_DEBUG);\r
-\r
-        $end_id = Config::get("system", "post_update_1194_end");\r
-        if (!$end_id) {\r
-            $r = q("SELECT `id` FROM `item` WHERE `uid` != 0 ORDER BY `id` DESC LIMIT 1");\r
-            if ($r) {\r
-                Config::set("system", "post_update_1194_end", $r[0]["id"]);\r
-                $end_id = Config::get("system", "post_update_1194_end");\r
-            }\r
-        }\r
-\r
-        logger("End ID: ".$end_id, LOGGER_DEBUG);\r
-\r
-        $start_id = Config::get("system", "post_update_1194_start");\r
-\r
-        $query1 = "SELECT `item`.`id` FROM `item` ";\r
-\r
-        $query2 = "INNER JOIN `item` AS `shadow` ON `item`.`uri` = `shadow`.`uri` AND `shadow`.`uid` = 0 ";\r
-\r
-        $query3 = "WHERE `item`.`uid` != 0 AND `item`.`id` >= %d AND `item`.`id` <= %d\r
-                AND `item`.`visible` AND NOT `item`.`private`\r
-                AND NOT `item`.`deleted` AND NOT `item`.`moderated`\r
-                AND `item`.`network` IN ('%s', '%s', '%s', '')\r
-                AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''\r
-                AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''\r
-                AND NOT `item`.`global`";\r
-\r
-        $r = q($query1.$query2.$query3."  ORDER BY `item`.`id` LIMIT 1",\r
-            intval($start_id), intval($end_id),\r
-            dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS));\r
-        if (!$r) {\r
-            Config::set("system", "post_update_version", 1194);\r
-            logger("Update is done", LOGGER_DEBUG);\r
-            return true;\r
-        } else {\r
-            Config::set("system", "post_update_1194_start", $r[0]["id"]);\r
-            $start_id = Config::get("system", "post_update_1194_start");\r
-        }\r
-\r
-        logger("Start ID: ".$start_id, LOGGER_DEBUG);\r
-\r
-        $r = q($query1.$query2.$query3."  ORDER BY `item`.`id` LIMIT 1000,1",\r
-            intval($start_id), intval($end_id),\r
-            dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS));\r
-        if ($r)\r
-            $pos_id = $r[0]["id"];\r
-        else\r
-            $pos_id = $end_id;\r
-\r
-        logger("Progress: Start: ".$start_id." position: ".$pos_id." end: ".$end_id, LOGGER_DEBUG);\r
-\r
-        q("UPDATE `item` ".$query2." SET `item`.`global` = 1 ".$query3,\r
-            intval($start_id), intval($pos_id),\r
-            dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS));\r
-\r
-        logger("Done", LOGGER_DEBUG);\r
-    }\r
-\r
-    /**\r
-     * @brief set the author-id and owner-id in all item entries\r
-     *\r
-     * This job has to be started multiple times until all entries are set.\r
-     * It isn't started in the update function since it would consume too much time and can be done in the background.\r
-     *\r
-     * @return bool "true" when the job is done\r
-     */\r
-    private static function update1198()\r
-    {\r
-        // Was the script completed?\r
-        if (Config::get("system", "post_update_version") >= 1198) {\r
-            return true;\r
-        }\r
-\r
-        logger("Start", LOGGER_DEBUG);\r
-\r
-        // Check if the first step is done (Setting "author-id" and "owner-id" in the item table)\r
-        $r = dba::select('item', ['author-link', 'owner-link', 'uid'], ['author-id' => 0, 'owner-id' => 0], ['limit' => 1000]);\r
-        if (!$r) {\r
-            // Are there unfinished entries in the thread table?\r
-            $r = q("SELECT COUNT(*) AS `total` FROM `thread`\r
-                INNER JOIN `item` ON `item`.`id` =`thread`.`iid`\r
-                WHERE `thread`.`author-id` = 0 AND `thread`.`owner-id` = 0 AND\r
-                    (`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");\r
-\r
-            if ($r && ($r[0]["total"] == 0)) {\r
-                Config::set("system", "post_update_version", 1198);\r
-                logger("Done", LOGGER_DEBUG);\r
-                return true;\r
-            }\r
-\r
-            // Update the thread table from the item table\r
-            $r = q("UPDATE `thread` INNER JOIN `item` ON `item`.`id`=`thread`.`iid`\r
-                    SET `thread`.`author-id` = `item`.`author-id`,\r
-                    `thread`.`owner-id` = `item`.`owner-id`\r
-                WHERE `thread`.`author-id` = 0 AND `thread`.`owner-id` = 0 AND\r
-                    (`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");\r
-\r
-            logger("Updated threads", LOGGER_DEBUG);\r
-            if (DBM::is_result($r)) {\r
-                Config::set("system", "post_update_version", 1198);\r
-                logger("Done", LOGGER_DEBUG);\r
-                return true;\r
-            }\r
-            return false;\r
-        }\r
-\r
-        logger("Query done", LOGGER_DEBUG);\r
-\r
-        $item_arr = [];\r
-        foreach ($r as $item) {\r
-            $index = $item["author-link"]."-".$item["owner-link"]."-".$item["uid"];\r
-            $item_arr[$index] = ["author-link" => $item["author-link"],\r
-                            "owner-link" => $item["owner-link"],\r
-                            "uid" => $item["uid"]];\r
-        }\r
-\r
-        // Set the "gcontact-id" in the item table and add a new gcontact entry if needed\r
-        foreach ($item_arr as $item) {\r
-            $author_id = Contact::getIdForURL($item["author-link"], 0);\r
-            $owner_id = Contact::getIdForURL($item["owner-link"], 0);\r
-\r
-            if ($author_id == 0)\r
-                $author_id = -1;\r
-\r
-            if ($owner_id == 0)\r
-                $owner_id = -1;\r
-\r
-            dba::update('item', ['author-id' => $author_id, 'owner-id' => $owner_id], ['uid' => $item['uid'], 'author-link' => $item['author-link'], 'owner-link' => $item['owner-link'], 'author-id' => 0, 'owner-id' => 0]);\r
-        }\r
-\r
-        logger("Updated items", LOGGER_DEBUG);\r
-        return false;\r
-    }\r
-\r
-    /**\r
-     * @brief update the "last-item" field in the "self" contact\r
-     *\r
-     * This field avoids cost intensive calls in the admin panel and in "nodeinfo"\r
-     *\r
-     * @return bool "true" when the job is done\r
-     */\r
-    private static function update1206()\r
-    {\r
-        // Was the script completed?\r
-        if (Config::get("system", "post_update_version") >= 1206) {\r
-            return true;\r
-        }\r
-\r
-        logger("Start", LOGGER_DEBUG);\r
-        $r = q("SELECT `contact`.`id`, `contact`.`last-item`,\r
-            (SELECT MAX(`changed`) FROM `item` USE INDEX (`uid_wall_changed`) WHERE `wall` AND `uid` = `user`.`uid`) AS `lastitem_date`\r
-            FROM `user`\r
-            INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`");\r
-\r
-        if (!DBM::is_result($r)) {\r
-            return false;\r
-        }\r
-        foreach ($r as $user) {\r
-            if (!empty($user["lastitem_date"]) && ($user["lastitem_date"] > $user["last-item"])) {\r
-                dba::update('contact', ['last-item' => $user['lastitem_date']], ['id' => $user['id']]);\r
-            }\r
-        }\r
-\r
-        Config::set("system", "post_update_version", 1206);\r
-        logger("Done", LOGGER_DEBUG);\r
-        return true;\r
-    }\r
-}\r
+<?php
+/**
+ * @file src/Database/PostUpdate.php
+ */
+namespace Friendica\Database;
+
+use Friendica\Core\Config;
+use Friendica\Database\DBM;
+use Friendica\Model\Contact;
+use Friendica\Model\GContact;
+use dba;
+
+require_once 'include/dba.php';
+
+/**
+ * Post update functions
+ */
+class PostUpdate
+{
+    /**
+     * @brief Calls the post update functions
+     */
+    public static function update()
+    {
+        if (!self::update1192()) {
+            return;
+        }
+        if (!self::update1194()) {
+            return;
+        }
+        if (!self::update1198()) {
+            return;
+        }
+        if (!self::update1206()) {
+            return;
+        }
+    }
+
+    /**
+     * @brief set the gcontact-id in all item entries
+     *
+     * This job has to be started multiple times until all entries are set.
+     * It isn't started in the update function since it would consume too much time and can be done in the background.
+     *
+     * @return bool "true" when the job is done
+     */
+    private static function update1192()
+    {
+        // Was the script completed?
+        if (Config::get("system", "post_update_version") >= 1192) {
+            return true;
+        }
+
+        // Check if the first step is done (Setting "gcontact-id" in the item table)
+        $r = dba::select('item', ['author-link', 'author-name', 'author-avatar', 'uid', 'network'], ['gcontact-id' => 0], ['limit' => 1000]);
+        if (!$r) {
+            // Are there unfinished entries in the thread table?
+            $r = q("SELECT COUNT(*) AS `total` FROM `thread`
+                INNER JOIN `item` ON `item`.`id` =`thread`.`iid`
+                WHERE `thread`.`gcontact-id` = 0 AND
+                    (`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");
+
+            if ($r && ($r[0]["total"] == 0)) {
+                Config::set("system", "post_update_version", 1192);
+                return true;
+            }
+
+            // Update the thread table from the item table
+            q("UPDATE `thread` INNER JOIN `item` ON `item`.`id`=`thread`.`iid`
+                    SET `thread`.`gcontact-id` = `item`.`gcontact-id`
+                WHERE `thread`.`gcontact-id` = 0 AND
+                    (`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");
+
+            return false;
+        }
+
+        $item_arr = [];
+        foreach ($r as $item) {
+            $index = $item["author-link"]."-".$item["uid"];
+            $item_arr[$index] = ["author-link" => $item["author-link"],
+                            "uid" => $item["uid"],
+                            "network" => $item["network"]];
+        }
+
+        // Set the "gcontact-id" in the item table and add a new gcontact entry if needed
+        foreach ($item_arr as $item) {
+            $gcontact_id = GContact::getId(["url" => $item['author-link'], "network" => $item['network'],
+                            "photo" => $item['author-avatar'], "name" => $item['author-name']]);
+            dba::update('item', ['gcontact-id' => $gcontact_id], ['uid' => $item['uid'], 'author-link' => $item['author-link'], 'gcontact-id' => 0]);
+        }
+        return false;
+    }
+
+    /**
+     * @brief Updates the "global" field in the item table
+     *
+     * @return bool "true" when the job is done
+     */
+    private static function update1194()
+    {
+        // Was the script completed?
+        if (Config::get("system", "post_update_version") >= 1194) {
+            return true;
+        }
+
+        logger("Start", LOGGER_DEBUG);
+
+        $end_id = Config::get("system", "post_update_1194_end");
+        if (!$end_id) {
+            $r = q("SELECT `id` FROM `item` WHERE `uid` != 0 ORDER BY `id` DESC LIMIT 1");
+            if ($r) {
+                Config::set("system", "post_update_1194_end", $r[0]["id"]);
+                $end_id = Config::get("system", "post_update_1194_end");
+            }
+        }
+
+        logger("End ID: ".$end_id, LOGGER_DEBUG);
+
+        $start_id = Config::get("system", "post_update_1194_start");
+
+        $query1 = "SELECT `item`.`id` FROM `item` ";
+
+        $query2 = "INNER JOIN `item` AS `shadow` ON `item`.`uri` = `shadow`.`uri` AND `shadow`.`uid` = 0 ";
+
+        $query3 = "WHERE `item`.`uid` != 0 AND `item`.`id` >= %d AND `item`.`id` <= %d
+                AND `item`.`visible` AND NOT `item`.`private`
+                AND NOT `item`.`deleted` AND NOT `item`.`moderated`
+                AND `item`.`network` IN ('%s', '%s', '%s', '')
+                AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
+                AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
+                AND NOT `item`.`global`";
+
+        $r = q($query1.$query2.$query3."  ORDER BY `item`.`id` LIMIT 1",
+            intval($start_id), intval($end_id),
+            dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS));
+        if (!$r) {
+            Config::set("system", "post_update_version", 1194);
+            logger("Update is done", LOGGER_DEBUG);
+            return true;
+        } else {
+            Config::set("system", "post_update_1194_start", $r[0]["id"]);
+            $start_id = Config::get("system", "post_update_1194_start");
+        }
+
+        logger("Start ID: ".$start_id, LOGGER_DEBUG);
+
+        $r = q($query1.$query2.$query3."  ORDER BY `item`.`id` LIMIT 1000,1",
+            intval($start_id), intval($end_id),
+            dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS));
+        if ($r)
+            $pos_id = $r[0]["id"];
+        else
+            $pos_id = $end_id;
+
+        logger("Progress: Start: ".$start_id." position: ".$pos_id." end: ".$end_id, LOGGER_DEBUG);
+
+        q("UPDATE `item` ".$query2." SET `item`.`global` = 1 ".$query3,
+            intval($start_id), intval($pos_id),
+            dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS));
+
+        logger("Done", LOGGER_DEBUG);
+    }
+
+    /**
+     * @brief set the author-id and owner-id in all item entries
+     *
+     * This job has to be started multiple times until all entries are set.
+     * It isn't started in the update function since it would consume too much time and can be done in the background.
+     *
+     * @return bool "true" when the job is done
+     */
+    private static function update1198()
+    {
+        // Was the script completed?
+        if (Config::get("system", "post_update_version") >= 1198) {
+            return true;
+        }
+
+        logger("Start", LOGGER_DEBUG);
+
+        // Check if the first step is done (Setting "author-id" and "owner-id" in the item table)
+        $r = dba::select('item', ['author-link', 'owner-link', 'uid'], ['author-id' => 0, 'owner-id' => 0], ['limit' => 1000]);
+        if (!$r) {
+            // Are there unfinished entries in the thread table?
+            $r = q("SELECT COUNT(*) AS `total` FROM `thread`
+                INNER JOIN `item` ON `item`.`id` =`thread`.`iid`
+                WHERE `thread`.`author-id` = 0 AND `thread`.`owner-id` = 0 AND
+                    (`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");
+
+            if ($r && ($r[0]["total"] == 0)) {
+                Config::set("system", "post_update_version", 1198);
+                logger("Done", LOGGER_DEBUG);
+                return true;
+            }
+
+            // Update the thread table from the item table
+            $r = q("UPDATE `thread` INNER JOIN `item` ON `item`.`id`=`thread`.`iid`
+                    SET `thread`.`author-id` = `item`.`author-id`,
+                    `thread`.`owner-id` = `item`.`owner-id`
+                WHERE `thread`.`author-id` = 0 AND `thread`.`owner-id` = 0 AND
+                    (`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");
+
+            logger("Updated threads", LOGGER_DEBUG);
+            if (DBM::is_result($r)) {
+                Config::set("system", "post_update_version", 1198);
+                logger("Done", LOGGER_DEBUG);
+                return true;
+            }
+            return false;
+        }
+
+        logger("Query done", LOGGER_DEBUG);
+
+        $item_arr = [];
+        foreach ($r as $item) {
+            $index = $item["author-link"]."-".$item["owner-link"]."-".$item["uid"];
+            $item_arr[$index] = ["author-link" => $item["author-link"],
+                            "owner-link" => $item["owner-link"],
+                            "uid" => $item["uid"]];
+        }
+
+        // Set the "gcontact-id" in the item table and add a new gcontact entry if needed
+        foreach ($item_arr as $item) {
+            $author_id = Contact::getIdForURL($item["author-link"], 0);
+            $owner_id = Contact::getIdForURL($item["owner-link"], 0);
+
+            if ($author_id == 0)
+                $author_id = -1;
+
+            if ($owner_id == 0)
+                $owner_id = -1;
+
+            dba::update('item', ['author-id' => $author_id, 'owner-id' => $owner_id], ['uid' => $item['uid'], 'author-link' => $item['author-link'], 'owner-link' => $item['owner-link'], 'author-id' => 0, 'owner-id' => 0]);
+        }
+
+        logger("Updated items", LOGGER_DEBUG);
+        return false;
+    }
+
+    /**
+     * @brief update the "last-item" field in the "self" contact
+     *
+     * This field avoids cost intensive calls in the admin panel and in "nodeinfo"
+     *
+     * @return bool "true" when the job is done
+     */
+    private static function update1206()
+    {
+        // Was the script completed?
+        if (Config::get("system", "post_update_version") >= 1206) {
+            return true;
+        }
+
+        logger("Start", LOGGER_DEBUG);
+        $r = q("SELECT `contact`.`id`, `contact`.`last-item`,
+            (SELECT MAX(`changed`) FROM `item` USE INDEX (`uid_wall_changed`) WHERE `wall` AND `uid` = `user`.`uid`) AS `lastitem_date`
+            FROM `user`
+            INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`");
+
+        if (!DBM::is_result($r)) {
+            return false;
+        }
+        foreach ($r as $user) {
+            if (!empty($user["lastitem_date"]) && ($user["lastitem_date"] > $user["last-item"])) {
+                dba::update('contact', ['last-item' => $user['lastitem_date']], ['id' => $user['id']]);
+            }
+        }
+
+        Config::set("system", "post_update_version", 1206);
+        logger("Done", LOGGER_DEBUG);
+        return true;
+    }
+}
index 485d070e30dd37dcc68e9e37db79b0c489169703..2be12f13e48ce8204c79e187c09e630f8ea9d189 100644 (file)
@@ -1,60 +1,60 @@
-<?php\r
-\r
-namespace Friendica\Module;\r
-\r
-use Friendica\BaseModule;\r
-use Friendica\Core\System;\r
-use Friendica\Protocol\OStatus;\r
-\r
-/**\r
- * Provides public Atom feeds\r
- *\r
- * Currently supported:\r
- * - /feed/[nickname]/ => posts\r
- * - /feed/[nickname]/posts => posts\r
- * - /feed/[nickname]/comments => comments\r
- * - /feed/[nickname]/replies => comments\r
- * - /feed/[nickname]/activity => activity\r
- *\r
- * The nocache GET parameter is provided mainly for debug purposes, requires auth\r
- *\r
- * @brief Provides public Atom feeds\r
- *\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-class Feed extends BaseModule\r
-{\r
-       public static function content()\r
-       {\r
-               $a = self::getApp();\r
-\r
-               $last_update = x($_GET, 'last_update') ? $_GET['last_update'] : '';\r
-               $nocache     = x($_GET, 'nocache') && local_user();\r
-\r
-               if ($a->argc < 2) {\r
-                       System::httpExit(400);\r
-               }\r
-\r
-               $type = null;\r
-               if ($a->argc > 2) {\r
-                       $type = $a->argv[2];\r
-               }\r
-\r
-               switch ($type) {\r
-                       case 'posts':\r
-                       case 'comments':\r
-                       case 'activity':\r
-                               break;\r
-                       case 'replies':\r
-                               $type = 'comments';\r
-                               break;\r
-                       default:\r
-                               $type = 'posts';\r
-               }\r
-\r
-               $nickname = $a->argv[1];\r
-               header("Content-type: application/atom+xml");\r
-               echo OStatus::feed($nickname, $last_update, 10, $type, $nocache);\r
-               killme();\r
-       }\r
-}\r
+<?php
+
+namespace Friendica\Module;
+
+use Friendica\BaseModule;
+use Friendica\Core\System;
+use Friendica\Protocol\OStatus;
+
+/**
+ * Provides public Atom feeds
+ *
+ * Currently supported:
+ * - /feed/[nickname]/ => posts
+ * - /feed/[nickname]/posts => posts
+ * - /feed/[nickname]/comments => comments
+ * - /feed/[nickname]/replies => comments
+ * - /feed/[nickname]/activity => activity
+ *
+ * The nocache GET parameter is provided mainly for debug purposes, requires auth
+ *
+ * @brief Provides public Atom feeds
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class Feed extends BaseModule
+{
+       public static function content()
+       {
+               $a = self::getApp();
+
+               $last_update = x($_GET, 'last_update') ? $_GET['last_update'] : '';
+               $nocache     = x($_GET, 'nocache') && local_user();
+
+               if ($a->argc < 2) {
+                       System::httpExit(400);
+               }
+
+               $type = null;
+               if ($a->argc > 2) {
+                       $type = $a->argv[2];
+               }
+
+               switch ($type) {
+                       case 'posts':
+                       case 'comments':
+                       case 'activity':
+                               break;
+                       case 'replies':
+                               $type = 'comments';
+                               break;
+                       default:
+                               $type = 'posts';
+               }
+
+               $nickname = $a->argv[1];
+               header("Content-type: application/atom+xml");
+               echo OStatus::feed($nickname, $last_update, 10, $type, $nocache);
+               killme();
+       }
+}
index a03ef05c2e192d114e00b364bca241b7596a8f97..7c5391a6ba9bd7df9869a33abfb2b8a7e8c5ad06 100644 (file)
@@ -1,31 +1,31 @@
-<?php\r
-/**\r
- * @file src/Module/Logout.php\r
- */\r
-namespace Friendica\Module;\r
-\r
-use Friendica\BaseModule;\r
-use Friendica\Core\Addon;\r
-use Friendica\Core\L10n;\r
-\r
-require_once 'boot.php';\r
-require_once 'include/security.php';\r
-\r
-/**\r
- * Logout module\r
- *\r
- * @author Hypolite Petovan mrpetovan@gmail.com\r
- */\r
-class Logout extends BaseModule\r
-{\r
-       /**\r
-        * @brief Process logout requests\r
-        */\r
-       public static function init()\r
-       {\r
-               Addon::callHooks("logging_out");\r
-               nuke_session();\r
-               info(L10n::t('Logged out.') . EOL);\r
-               goaway(self::getApp()->get_baseurl());\r
-       }\r
-}\r
+<?php
+/**
+ * @file src/Module/Logout.php
+ */
+namespace Friendica\Module;
+
+use Friendica\BaseModule;
+use Friendica\Core\Addon;
+use Friendica\Core\L10n;
+
+require_once 'boot.php';
+require_once 'include/security.php';
+
+/**
+ * Logout module
+ *
+ * @author Hypolite Petovan mrpetovan@gmail.com
+ */
+class Logout extends BaseModule
+{
+       /**
+        * @brief Process logout requests
+        */
+       public static function init()
+       {
+               Addon::callHooks("logging_out");
+               nuke_session();
+               info(L10n::t('Logged out.') . EOL);
+               goaway(self::getApp()->get_baseurl());
+       }
+}
index e5f3941bb5525e0bcbcd873aff8a82a4e00ea19d..570e2812412da7a34997f8772b2210f5370598f3 100644 (file)
@@ -1,53 +1,53 @@
-<?php\r
-\r
-namespace Friendica\Module;\r
-\r
-use Friendica\BaseModule;\r
-use Friendica\Content;\r
-\r
-/**\r
- * Oembed module\r
- *\r
- * Displays stored embed content based on a base64 hash of a remote URL\r
- *\r
- * Example: /oembed/aHR0cHM6Ly9...\r
- *\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-class Oembed extends BaseModule\r
-{\r
-       public static function content()\r
-       {\r
-               $a = self::getApp();\r
-\r
-               // Unused form: /oembed/b2h?url=...\r
-               if ($a->argv[1] == 'b2h') {\r
-                       $url = ["", trim(hex2bin($_REQUEST['url']))];\r
-                       echo Content\OEmbed::replaceCallback($url);\r
-                       killme();\r
-               }\r
-\r
-               // Unused form: /oembed/h2b?text=...\r
-               if ($a->argv[1] == 'h2b') {\r
-                       $text = trim(hex2bin($_REQUEST['text']));\r
-                       echo Content\OEmbed::HTML2BBCode($text);\r
-                       killme();\r
-               }\r
-\r
-               if ($a->argc == 2) {\r
-                       echo '<html><body>';\r
-                       $url = base64url_decode($a->argv[1]);\r
-                       $j = Content\OEmbed::fetchURL($url);\r
-\r
-                       // workaround for media.ccc.de (and any other endpoint that return size 0)\r
-                       if (substr($j->html, 0, 7) == "<iframe" && strstr($j->html, 'width="0"')) {\r
-                               $j->html = '<style>html,body{margin:0;padding:0;} iframe{width:100%;height:100%;}</style>' . $j->html;\r
-                               $j->html = str_replace('width="0"', '', $j->html);\r
-                               $j->html = str_replace('height="0"', '', $j->html);\r
-                       }\r
-                       echo $j->html;\r
-                       echo '</body></html>';\r
-               }\r
-               killme();\r
-       }\r
-}\r
+<?php
+
+namespace Friendica\Module;
+
+use Friendica\BaseModule;
+use Friendica\Content;
+
+/**
+ * Oembed module
+ *
+ * Displays stored embed content based on a base64 hash of a remote URL
+ *
+ * Example: /oembed/aHR0cHM6Ly9...
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class Oembed extends BaseModule
+{
+       public static function content()
+       {
+               $a = self::getApp();
+
+               // Unused form: /oembed/b2h?url=...
+               if ($a->argv[1] == 'b2h') {
+                       $url = ["", trim(hex2bin($_REQUEST['url']))];
+                       echo Content\OEmbed::replaceCallback($url);
+                       killme();
+               }
+
+               // Unused form: /oembed/h2b?text=...
+               if ($a->argv[1] == 'h2b') {
+                       $text = trim(hex2bin($_REQUEST['text']));
+                       echo Content\OEmbed::HTML2BBCode($text);
+                       killme();
+               }
+
+               if ($a->argc == 2) {
+                       echo '<html><body>';
+                       $url = base64url_decode($a->argv[1]);
+                       $j = Content\OEmbed::fetchURL($url);
+
+                       // workaround for media.ccc.de (and any other endpoint that return size 0)
+                       if (substr($j->html, 0, 7) == "<iframe" && strstr($j->html, 'width="0"')) {
+                               $j->html = '<style>html,body{margin:0;padding:0;} iframe{width:100%;height:100%;}</style>' . $j->html;
+                               $j->html = str_replace('width="0"', '', $j->html);
+                               $j->html = str_replace('height="0"', '', $j->html);
+                       }
+                       echo $j->html;
+                       echo '</body></html>';
+               }
+               killme();
+       }
+}
index 7602290c2b873c3a7e8eddea441260e8b7feed4c..b9bad457da13b0dbd17b45b7145abc1c12597197 100644 (file)
@@ -1,27 +1,27 @@
-<?php\r
-\r
-/**\r
- * Throwable exceptions to return HTTP status code\r
- *\r
- * This list of Exception has be extracted from\r
- * here http://racksburg.com/choosing-an-http-status-code/\r
- */\r
-\r
-namespace Friendica\Network;\r
-\r
-use Exception;\r
-\r
-class HTTPException extends Exception\r
-{\r
-       var $httpcode = 200;\r
-       var $httpdesc = "";\r
-\r
-       public function __construct($message = '', $code = 0, Exception $previous = null)\r
-       {\r
-               if ($this->httpdesc == '') {\r
-                       $classname = str_replace('Exception', '', str_replace('Friendica\Network\HTTPException\\', '', get_class($this)));\r
-                       $this->httpdesc = preg_replace("|([a-z])([A-Z])|",'$1 $2', $classname);\r
-               }\r
-               parent::__construct($message, $code, $previous);\r
-       }\r
-}\r
+<?php
+
+/**
+ * Throwable exceptions to return HTTP status code
+ *
+ * This list of Exception has be extracted from
+ * here http://racksburg.com/choosing-an-http-status-code/
+ */
+
+namespace Friendica\Network;
+
+use Exception;
+
+class HTTPException extends Exception
+{
+       var $httpcode = 200;
+       var $httpdesc = "";
+
+       public function __construct($message = '', $code = 0, Exception $previous = null)
+       {
+               if ($this->httpdesc == '') {
+                       $classname = str_replace('Exception', '', str_replace('Friendica\Network\HTTPException\\', '', get_class($this)));
+                       $this->httpdesc = preg_replace("|([a-z])([A-Z])|",'$1 $2', $classname);
+               }
+               parent::__construct($message, $code, $previous);
+       }
+}
index 1bb8b29e98411c00c03e5f260d7bdeba5f33e989..6fc80c909115ba09e19c09e6406c6fbdebff6239 100644 (file)
@@ -1,10 +1,10 @@
-<?php\r
-\r
-namespace Friendica\Network\HTTPException;\r
-\r
-use Friendica\Network\HTTPException;\r
-\r
-class BadGatewayException extends HTTPException\r
-{\r
-       var $httpcode = 502;\r
-}\r
+<?php
+
+namespace Friendica\Network\HTTPException;
+
+use Friendica\Network\HTTPException;
+
+class BadGatewayException extends HTTPException
+{
+       var $httpcode = 502;
+}
index 23e59b3ca24189a1c4fc559463cabb1e3c6c14f8..dd1dc191b81f99d0bd3a770d0b55d9fd34085051 100644 (file)
@@ -1,10 +1,10 @@
-<?php\r
-\r
-namespace Friendica\Network\HTTPException;\r
-\r
-use Friendica\Network\HTTPException;\r
-\r
-class BadRequestException extends HTTPException\r
-{\r
-       var $httpcode = 400;\r
-}\r
+<?php
+
+namespace Friendica\Network\HTTPException;
+
+use Friendica\Network\HTTPException;
+
+class BadRequestException extends HTTPException
+{
+       var $httpcode = 400;
+}
index b1aef72d7e56ddb40d400c03fcdfaf34aa7bb8a5..1d5053c4b7e9dbcb2ebf5373de19fa016ae3aca4 100644 (file)
@@ -1,10 +1,10 @@
-<?php\r
-\r
-namespace Friendica\Network\HTTPException;\r
-\r
-use Friendica\Network\HTTPException;\r
-\r
-class ConflictException extends HTTPException\r
-{\r
-       var $httpcode = 409;\r
-}\r
+<?php
+
+namespace Friendica\Network\HTTPException;
+
+use Friendica\Network\HTTPException;
+
+class ConflictException extends HTTPException
+{
+       var $httpcode = 409;
+}
index 2b7b1febb78edd1aed055198e83d1e0c8133fe5d..fe932a9f0a4861fe467c34c3456227c17df44f28 100644 (file)
@@ -1,10 +1,10 @@
-<?php\r
-\r
-namespace Friendica\Network\HTTPException;\r
-\r
-use Friendica\Network\HTTPException;\r
-\r
-class ExpectationFailedException extends HTTPException\r
-{\r
-       var $httpcode = 417;\r
-}\r
+<?php
+
+namespace Friendica\Network\HTTPException;
+
+use Friendica\Network\HTTPException;
+
+class ExpectationFailedException extends HTTPException
+{
+       var $httpcode = 417;
+}
index 75622c4c86302687c2800a680db87af22034b047..66a063e137a47778099abdd1bd98e9e6b99300ce 100644 (file)
@@ -1,10 +1,10 @@
-<?php\r
-\r
-namespace Friendica\Network\HTTPException;\r
-\r
-use Friendica\Network\HTTPException;\r
-\r
-class ForbiddenException extends HTTPException\r
-{\r
-       var $httpcode = 403;\r
+<?php
+
+namespace Friendica\Network\HTTPException;
+
+use Friendica\Network\HTTPException;
+
+class ForbiddenException extends HTTPException
+{
+       var $httpcode = 403;
 }
\ No newline at end of file
index 306fbd41124707b3049e4cd12089efd54ba2dbf2..bcd98080eda8e82113e007058f0a45985c38de87 100644 (file)
@@ -1,10 +1,10 @@
-<?php\r
-\r
-namespace Friendica\Network\HTTPException;\r
-\r
-use Friendica\Network\HTTPException;\r
-\r
-class GatewayTimeoutException extends HTTPException\r
-{\r
-       var $httpcode = 504;\r
-}\r
+<?php
+
+namespace Friendica\Network\HTTPException;
+
+use Friendica\Network\HTTPException;
+
+class GatewayTimeoutException extends HTTPException
+{
+       var $httpcode = 504;
+}
index ea844b087b59bbe4af8888b4ad09908a7e693dd3..42e19e89da6e50933f2ce8832e8b50c603047a52 100644 (file)
@@ -1,10 +1,10 @@
-<?php\r
-\r
-namespace Friendica\Network\HTTPException;\r
-\r
-use Friendica\Network\HTTPException;\r
-\r
-class GoneException extends HTTPException\r
-{\r
-       var $httpcode = 410;\r
-}\r
+<?php
+
+namespace Friendica\Network\HTTPException;
+
+use Friendica\Network\HTTPException;
+
+class GoneException extends HTTPException
+{
+       var $httpcode = 410;
+}
index fccf632be609ecfeb725791ba4fa1330954b74c9..f4eea4077c7b710fa9e34f3e46c0d945bd417d85 100644 (file)
@@ -1,11 +1,11 @@
-<?php\r
-\r
-namespace Friendica\Network\HTTPException;\r
-\r
-use Friendica\Network\HTTPException;\r
-\r
-class ImATeapotException extends HTTPException\r
-{\r
-       var $httpcode = 418;\r
-       var $httpdesc = "I'm A Teapot";\r
-}\r
+<?php
+
+namespace Friendica\Network\HTTPException;
+
+use Friendica\Network\HTTPException;
+
+class ImATeapotException extends HTTPException
+{
+       var $httpcode = 418;
+       var $httpdesc = "I'm A Teapot";
+}
index 09c969419d22f8dcb24af91e6fef16780a257a34..c049ef25bacbfbf40b484acd946bdc35ed051e2d 100644 (file)
@@ -1,10 +1,10 @@
-<?php\r
-\r
-namespace Friendica\Network\HTTPException;\r
-\r
-use Friendica\Network\HTTPException;\r
-\r
-class InternalServerErrorException extends HTTPException\r
-{\r
-       var $httpcode = 500;\r
-}\r
+<?php
+
+namespace Friendica\Network\HTTPException;
+
+use Friendica\Network\HTTPException;
+
+class InternalServerErrorException extends HTTPException
+{
+       var $httpcode = 500;
+}
index dd952b06461b37b552a94e43e1db4e5ce737ecd8..1f2f0f16bcb748eaef98f33a096d6bfca7fbd206 100644 (file)
@@ -1,10 +1,10 @@
-<?php\r
-\r
-namespace Friendica\Network\HTTPException;\r
-\r
-use Friendica\Network\HTTPException;\r
-\r
-class LenghtRequiredException extends HTTPException\r
-{\r
-       var $httpcode = 411;\r
-}\r
+<?php
+
+namespace Friendica\Network\HTTPException;
+
+use Friendica\Network\HTTPException;
+
+class LenghtRequiredException extends HTTPException
+{
+       var $httpcode = 411;
+}
index 8dce41432dace007edba235f8c982b19c0063db3..82fd3e786bd1f1695efa561c33de823be3355a92 100644 (file)
@@ -1,10 +1,10 @@
-<?php\r
-\r
-namespace Friendica\Network\HTTPException;\r
-\r
-use Friendica\Network\HTTPException;\r
-\r
-class MethodNotAllowedException extends HTTPException\r
-{\r
-       var $httpcode = 405;\r
-}\r
+<?php
+
+namespace Friendica\Network\HTTPException;
+
+use Friendica\Network\HTTPException;
+
+class MethodNotAllowedException extends HTTPException
+{
+       var $httpcode = 405;
+}
index 8705a13e0ce258485a572ce711e3f5ed9329a633..356bc0c545a157ab50d36ca624c9d02d31f1c335 100644 (file)
@@ -1,10 +1,10 @@
-<?php\r
-\r
-namespace Friendica\Network\HTTPException;\r
-\r
-use Friendica\Network\HTTPException;\r
-\r
-class NonAcceptableException extends HTTPException\r
-{\r
-       var $httpcode = 406;\r
-}\r
+<?php
+
+namespace Friendica\Network\HTTPException;
+
+use Friendica\Network\HTTPException;
+
+class NonAcceptableException extends HTTPException
+{
+       var $httpcode = 406;
+}
index bd4f6151b488be947ec967e628179bc04be22058..2d24ccef044736e724c4f158555674dcf6c03bec 100644 (file)
@@ -1,9 +1,9 @@
-<?php\r
-\r
-namespace Friendica\Network\HTTPException;\r
-\r
-use Friendica\Network\HTTPException;\r
-\r
-class NotFoundException extends HTTPException {\r
-       var $httpcode = 404;\r
-}\r
+<?php
+
+namespace Friendica\Network\HTTPException;
+
+use Friendica\Network\HTTPException;
+
+class NotFoundException extends HTTPException {
+       var $httpcode = 404;
+}
index 74bc8adf566aafdc102c11ac487010acfaee13b3..c0dc21c15860404a02e9cbdfbd724cbf6578b122 100644 (file)
@@ -1,10 +1,10 @@
-<?php\r
-\r
-namespace Friendica\Network\HTTPException;\r
-\r
-use Friendica\Network\HTTPException;\r
-\r
-class NotImplementedException extends HTTPException\r
-{\r
-       var $httpcode = 501;\r
-}\r
+<?php
+
+namespace Friendica\Network\HTTPException;
+
+use Friendica\Network\HTTPException;
+
+class NotImplementedException extends HTTPException
+{
+       var $httpcode = 501;
+}
index b0f4e71cafbf36a6b2e6fdb8bb82bd961b61eece..fd5fdbc995a072aeecd841a0f9b4095f40eed29b 100644 (file)
@@ -1,10 +1,10 @@
-<?php\r
-\r
-namespace Friendica\Network\HTTPException;\r
-\r
-use Friendica\Network\HTTPException;\r
-\r
-class PreconditionFailedException extends HTTPException\r
-{\r
-       var $httpcode = 412;\r
-}\r
+<?php
+
+namespace Friendica\Network\HTTPException;
+
+use Friendica\Network\HTTPException;
+
+class PreconditionFailedException extends HTTPException
+{
+       var $httpcode = 412;
+}
index 0dd21259cfdc4e003b1d6861aa1a282daaa62258..9270bc4505b6dbee4d7ec08e291107b974465772 100644 (file)
@@ -1,10 +1,10 @@
-<?php\r
-\r
-namespace Friendica\Network\HTTPException;\r
-\r
-use Friendica\Network\HTTPException;\r
-\r
-class ServiceUnavaiableException extends HTTPException\r
-{\r
-       var $httpcode = 503;\r
-}\r
+<?php
+
+namespace Friendica\Network\HTTPException;
+
+use Friendica\Network\HTTPException;
+
+class ServiceUnavaiableException extends HTTPException
+{
+       var $httpcode = 503;
+}
index c21b22325a453c622e7307d9834c06a55e3de610..093911f932917aefe9dfd9923ac5850c149ad1f3 100644 (file)
@@ -1,10 +1,10 @@
-<?php\r
-\r
-namespace Friendica\Network\HTTPException;\r
-\r
-use Friendica\Network\HTTPException;\r
-\r
-class TooManyRequestsException extends HTTPException\r
-{\r
-       var $httpcode = 429;\r
-}\r
+<?php
+
+namespace Friendica\Network\HTTPException;
+
+use Friendica\Network\HTTPException;
+
+class TooManyRequestsException extends HTTPException
+{
+       var $httpcode = 429;
+}
index 79e6114a9299f769815c24db0c1d60979214b0dc..a3015d412da0648e32dccdcf5bd905288582914d 100644 (file)
@@ -1,10 +1,10 @@
-<?php\r
-\r
-namespace Friendica\Network\HTTPException;\r
-\r
-use Friendica\Network\HTTPException;\r
-\r
-class UnauthorizedException extends HTTPException\r
-{\r
-       var $httpcode = 401;\r
-}\r
+<?php
+
+namespace Friendica\Network\HTTPException;
+
+use Friendica\Network\HTTPException;
+
+class UnauthorizedException extends HTTPException
+{
+       var $httpcode = 401;
+}
index 9d92778328769b212b8c33e1bdb204fa995358dc..02852e2f929e4e821a8a5a769c74c59a7b12be6d 100644 (file)
@@ -1,10 +1,10 @@
-<?php\r
-\r
-namespace Friendica\Network\HTTPException;\r
-\r
-use Friendica\Network\HTTPException;\r
-\r
-class UnprocessableEntityException extends HTTPException\r
-{\r
-       var $httpcode = 422;\r
-}\r
+<?php
+
+namespace Friendica\Network\HTTPException;
+
+use Friendica\Network\HTTPException;
+
+class UnprocessableEntityException extends HTTPException
+{
+       var $httpcode = 422;
+}
index e73049333e9472344502eb23f286e351e9ba4999..b0399017392cf00e1d43bc7e3392d1e726eea64e 100644 (file)
@@ -1,10 +1,10 @@
-<?php\r
-\r
-namespace Friendica\Network\HTTPException;\r
-\r
-use Friendica\Network\HTTPException;\r
-\r
-class UnsupportedMediaTypeException extends HTTPException\r
-{\r
-       var $httpcode = 415;\r
-}\r
+<?php
+
+namespace Friendica\Network\HTTPException;
+
+use Friendica\Network\HTTPException;
+
+class UnsupportedMediaTypeException extends HTTPException
+{
+       var $httpcode = 415;
+}
index 9f690847a7bb9d543777c6ce9f57df3c006c40e0..ca881484611302634828fb397b3fce0625e260ff 100644 (file)
@@ -2411,10 +2411,8 @@ class DFRN
                );
 
                // Is there an existing item?
-               if (DBM::is_result($current) && self::isEditedTimestampNewer($current[0], $item)
-                       && (DateTimeFormat::utc($item["edited"]) < $current[0]["edited"])
-               ) {
-                       logger("Item ".$item["uri"]." already existed.", LOGGER_DEBUG);
+               if (DBM::is_result($current) && !self::isEditedTimestampNewer($current[0], $item)) {
+                       logger("Item ".$item["uri"]." already existed in this version.", LOGGER_DEBUG);
                        return;
                }
 
index 278fe1f9388cfdcde84a8440c18aa01d89e2d66b..ab19993081a293e972e95769861281a7e11a345d 100644 (file)
@@ -1,56 +1,56 @@
-<?php\r
-/**\r
- * @file src/Render/FriendicaSmarty.php\r
- */\r
-namespace Friendica\Render;\r
-\r
-use Smarty;\r
-\r
-/**\r
- * Friendica extension of the Smarty3 template engine\r
- *\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-class FriendicaSmarty extends Smarty\r
-{\r
-       const SMARTY3_TEMPLATE_FOLDER = 'templates';\r
-\r
-       public $filename;\r
-\r
-       function __construct()\r
-       {\r
-               parent::__construct();\r
-\r
-               $a = get_app();\r
-               $theme = current_theme();\r
-\r
-               // setTemplateDir can be set to an array, which Smarty will parse in order.\r
-               // The order is thus very important here\r
-               $template_dirs = ['theme' => "view/theme/$theme/" . self::SMARTY3_TEMPLATE_FOLDER . "/"];\r
-               if (x($a->theme_info, "extends")) {\r
-                       $template_dirs = $template_dirs + ['extends' => "view/theme/" . $a->theme_info["extends"] . "/" . self::SMARTY3_TEMPLATE_FOLDER . "/"];\r
-               }\r
-\r
-               $template_dirs = $template_dirs + ['base' => "view/" . self::SMARTY3_TEMPLATE_FOLDER . "/"];\r
-               $this->setTemplateDir($template_dirs);\r
-\r
-               $this->setCompileDir('view/smarty3/compiled/');\r
-               $this->setConfigDir('view/smarty3/config/');\r
-               $this->setCacheDir('view/smarty3/cache/');\r
-\r
-               $this->left_delimiter = $a->get_template_ldelim('smarty3');\r
-               $this->right_delimiter = $a->get_template_rdelim('smarty3');\r
-\r
-               // Don't report errors so verbosely\r
-               $this->error_reporting = E_ALL & ~E_NOTICE;\r
-       }\r
-\r
-       function parsed($template = '')\r
-       {\r
-               if ($template) {\r
-                       return $this->fetch('string:' . $template);\r
-               }\r
-               return $this->fetch('file:' . $this->filename);\r
-       }\r
-\r
+<?php
+/**
+ * @file src/Render/FriendicaSmarty.php
+ */
+namespace Friendica\Render;
+
+use Smarty;
+
+/**
+ * Friendica extension of the Smarty3 template engine
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class FriendicaSmarty extends Smarty
+{
+       const SMARTY3_TEMPLATE_FOLDER = 'templates';
+
+       public $filename;
+
+       function __construct()
+       {
+               parent::__construct();
+
+               $a = get_app();
+               $theme = current_theme();
+
+               // setTemplateDir can be set to an array, which Smarty will parse in order.
+               // The order is thus very important here
+               $template_dirs = ['theme' => "view/theme/$theme/" . self::SMARTY3_TEMPLATE_FOLDER . "/"];
+               if (x($a->theme_info, "extends")) {
+                       $template_dirs = $template_dirs + ['extends' => "view/theme/" . $a->theme_info["extends"] . "/" . self::SMARTY3_TEMPLATE_FOLDER . "/"];
+               }
+
+               $template_dirs = $template_dirs + ['base' => "view/" . self::SMARTY3_TEMPLATE_FOLDER . "/"];
+               $this->setTemplateDir($template_dirs);
+
+               $this->setCompileDir('view/smarty3/compiled/');
+               $this->setConfigDir('view/smarty3/config/');
+               $this->setCacheDir('view/smarty3/cache/');
+
+               $this->left_delimiter = $a->get_template_ldelim('smarty3');
+               $this->right_delimiter = $a->get_template_rdelim('smarty3');
+
+               // Don't report errors so verbosely
+               $this->error_reporting = E_ALL & ~E_NOTICE;
+       }
+
+       function parsed($template = '')
+       {
+               if ($template) {
+                       return $this->fetch('string:' . $template);
+               }
+               return $this->fetch('file:' . $this->filename);
+       }
+
 }
\ No newline at end of file
index d592481192707ab6afc1ae4b077851ee86f97474..cf19e2065a285effe6628251a83badece5078bdc 100644 (file)
@@ -1,15 +1,15 @@
-<?php\r
-/**\r
- * @file src/Render/ITemplateEngine.php\r
- */\r
-\r
-namespace Friendica\Render;\r
-\r
-/**\r
- * Interface for template engines\r
- */\r
-interface ITemplateEngine\r
-{\r
-       public function replaceMacros($s, $v);\r
-       public function getTemplateFile($file, $root = '');\r
-}\r
+<?php
+/**
+ * @file src/Render/ITemplateEngine.php
+ */
+
+namespace Friendica\Render;
+
+/**
+ * Interface for template engines
+ */
+interface ITemplateEngine
+{
+       public function replaceMacros($s, $v);
+       public function getTemplateFile($file, $root = '');
+}