]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #4865 from annando/dfrn-reshare
authorTobias Diekershoff <tobias.diekershoff@gmx.net>
Thu, 19 Apr 2018 06:43:18 +0000 (08:43 +0200)
committerGitHub <noreply@github.com>
Thu, 19 Apr 2018 06:43:18 +0000 (08:43 +0200)
Diaspora: Improved reshared coding

composer.json
composer.lock
include/conversation.php
include/security.php
include/text.php
src/Core/Cache/MemcachedCacheDriver.php
src/Core/Session/CacheSessionHandler.php
src/Database/DBStructure.php
src/Model/Term.php

index 52b4f2c8678c1a6fbb34e1169c17da8ef684d754..5cb33e67d604ebca8c87bcc3f621b246309ddab7 100644 (file)
@@ -30,6 +30,7 @@
                "bower-asset/base64": "^1.0",
                "bower-asset/Chart-js": "^2.7",
                "bower-asset/perfect-scrollbar": "^0.6",
+               "bower-asset/vue": "^2.5",
                "npm-asset/jquery": "^2.0",
                "npm-asset/jquery-colorbox": "^1.6",
                "npm-asset/jquery-datetimepicker": "^2.4.0",
index 28199f4f5139d364e49b28c9ace7dbfc2ed7dc9e..34362cb1bbca845108dbbfb7b81598015db600ef 100644 (file)
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
         "This file is @generated automatically"
     ],
-    "content-hash": "12b8df66213734281765cb6e2c5a786e",
+    "content-hash": "96062c2020a40f14b52e5e91c79995a7",
     "packages": [
         {
             "name": "asika/simple-console",
             "description": "Minimalistic but perfect custom scrollbar plugin",
             "time": "2017-01-10T01:04:09+00:00"
         },
+        {
+            "name": "bower-asset/vue",
+            "version": "v2.5.16",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/vuejs/vue.git",
+                "reference": "25342194016dc3bcc81cb3e8e229b0fb7ba1d1d6"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/vuejs/vue/zipball/25342194016dc3bcc81cb3e8e229b0fb7ba1d1d6",
+                "reference": "25342194016dc3bcc81cb3e8e229b0fb7ba1d1d6",
+                "shasum": ""
+            },
+            "type": "bower-asset-library"
+        },
         {
             "name": "divineomega/password_exposed",
             "version": "v2.5.1",
index 8a2887d6b742f6f9d9aed74677469e69446ea102..41f10959b2c9524974046f907b6e969c50f501c3 100644 (file)
@@ -668,33 +668,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order =
                                        $profile_name = $item['author-link'];
                                }
 
-                               $tags = [];
-                               $hashtags = [];
-                               $mentions = [];
-
-                               $searchpath = System::baseUrl()."/search?tag=";
-
-                               $taglist = dba::select('term', ['type', 'term', 'url'],
-                                                       ["`otype` = ? AND `oid` = ? AND `type` IN (?, ?)", TERM_OBJ_POST, $item['id'], TERM_HASHTAG, TERM_MENTION],
-                                                       ['order' => ['tid']]);
-
-                               while ($tag = dba::fetch($taglist)) {
-                                       if ($tag["url"] == "") {
-                                               $tag["url"] = $searchpath . strtolower($tag["term"]);
-                                       }
-
-                                       $tag["url"] = best_link_url($item, $sp, $tag["url"]);
-
-                                       if ($tag["type"] == TERM_HASHTAG) {
-                                               $hashtags[] = "#<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
-                                               $prefix = "#";
-                                       } elseif ($tag["type"] == TERM_MENTION) {
-                                               $mentions[] = "@<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
-                                               $prefix = "@";
-                                       }
-                                       $tags[] = $prefix."<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
-                               }
-                               dba::close($taglist);
+                               $tags = \Friendica\Model\Term::populateTagsFromItem($item);
 
                                $sp = false;
                                $profile_link = best_link_url($item, $sp);
@@ -764,9 +738,9 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order =
                                }
 
                                $body_e = $body;
-                               $tags_e = $tags;
-                               $hashtags_e = $hashtags;
-                               $mentions_e = $mentions;
+                               $tags_e = $tags['tags'];
+                               $hashtags_e = $tags['hashtags'];
+                               $mentions_e = $tags['mentions'];
                                $location_e = $location;
                                $owner_name_e = $owner_name;
 
index af424df26c65c6122ff76a2070c936b426cdc46d..b13a507cf483c124e5e1de3ed3817b205784d3aa 100644 (file)
@@ -405,12 +405,21 @@ function get_form_security_token($typename = '')
 
 function check_form_security_token($typename = '', $formname = 'form_security_token')
 {
-       if (!x($_REQUEST, $formname)) {
-               return false;
+       $hash = null;
+
+       if (!empty($_REQUEST[$formname])) {
+               /// @TODO Careful, not secured!
+               $hash = $_REQUEST[$formname];
+       }
+
+       if (!empty($_SERVER['HTTP_X_CSRF_TOKEN'])) {
+               /// @TODO Careful, not secured!
+               $hash = $_SERVER['HTTP_X_CSRF_TOKEN'];
        }
 
-       /// @TODO Careful, not secured!
-       $hash = $_REQUEST[$formname];
+       if (empty($hash)) {
+               return false;
+       }
 
        $max_livetime = 10800; // 3 hours
 
index ee8a213ff659bfa3aa238e740ac51138346d25b3..2ec017caffa9bb613348d153f8cae2c47cc92a01 100644 (file)
@@ -1234,12 +1234,6 @@ function prepare_body(array &$item, $attach = false, $is_preview = false)
        $a = get_app();
        Addon::callHooks('prepare_body_init', $item);
 
-       $searchpath = System::baseUrl() . "/search?tag=";
-
-       $tags = [];
-       $hashtags = [];
-       $mentions = [];
-
        // In order to provide theme developers more possibilities, event items
        // are treated differently.
        if ($item['object-type'] === ACTIVITY_OBJ_EVENT && isset($item['event-id'])) {
@@ -1247,37 +1241,11 @@ function prepare_body(array &$item, $attach = false, $is_preview = false)
                return $ev;
        }
 
-       $taglist = dba::p("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = ? AND `oid` = ? AND `type` IN (?, ?) ORDER BY `tid`",
-                       intval(TERM_OBJ_POST), intval($item['id']), intval(TERM_HASHTAG), intval(TERM_MENTION));
-
-       while ($tag = dba::fetch($taglist)) {
-               if ($tag["url"] == "") {
-                       $tag["url"] = $searchpath . strtolower($tag["term"]);
-               }
-
-               $orig_tag = $tag["url"];
-
-               $tag["url"] = best_link_url($item, $sp, $tag["url"]);
-
-               if ($tag["type"] == TERM_HASHTAG) {
-                       if ($orig_tag != $tag["url"]) {
-                               $item['body'] = str_replace($orig_tag, $tag["url"], $item['body']);
-                       }
-
-                       $hashtags[] = "#<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
-                       $prefix = "#";
-               } elseif ($tag["type"] == TERM_MENTION) {
-                       $mentions[] = "@<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
-                       $prefix = "@";
-               }
-
-               $tags[] = $prefix . "<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
-       }
-       dba::close($taglist);
+       $tags = \Friendica\Model\Term::populateTagsFromItem($item);
 
-       $item['tags'] = $tags;
-       $item['hashtags'] = $hashtags;
-       $item['mentions'] = $mentions;
+       $item['tags'] = $tags['tags'];
+       $item['hashtags'] = $tags['hashtags'];
+       $item['mentions'] = $tags['mentions'];
 
        // Compile eventual content filter reasons
        $filter_reasons = [];
index d6b8d4ad5808146d00d9b8110c30770eaf019834..78a4a6bdfe28c8fd477afd5f8ac37ad23be61337 100644 (file)
@@ -50,7 +50,7 @@ class MemcachedCacheDriver extends BaseObject implements ICacheDriver
        {
                // We store with the hostname as key to avoid problems with other applications
                return $this->memcached->set(
-                       self::getApp()->get_hostname() . ":" . $key,
+                       self::getApp()->get_hostname() . ':' . $key,
                        $value,
                        time() + $duration
                );
@@ -58,7 +58,9 @@ class MemcachedCacheDriver extends BaseObject implements ICacheDriver
 
        public function delete($key)
        {
-               return $this->memcached->delete($key);
+               $return = $this->memcached->delete(self::getApp()->get_hostname() . ':' . $key);
+
+               return $return;
        }
 
        public function clear()
index 463fd33d3eff0d40de528b1446d64a892f9bef7d..507735c4fc41a11391c9b70deefb416ab337d653 100644 (file)
@@ -24,7 +24,7 @@ class CacheSessionHandler extends BaseObject implements SessionHandlerInterface
 
        public function read($session_id)
        {
-               if (!x($session_id)) {
+               if (empty($session_id)) {
                        return '';
                }
 
@@ -58,9 +58,9 @@ class CacheSessionHandler extends BaseObject implements SessionHandlerInterface
                        return true;
                }
 
-               Cache::set('session:' . $session_id, $session_data, Session::$expire);
+               $return = Cache::set('session:' . $session_id, $session_data, Session::$expire);
 
-               return true;
+               return $return;
        }
 
        public function close()
@@ -70,8 +70,9 @@ class CacheSessionHandler extends BaseObject implements SessionHandlerInterface
 
        public function destroy($id)
        {
-               Cache::delete('session:' . $id);
-               return true;
+               $return = Cache::delete('session:' . $id);
+
+               return $return;
        }
 
        public function gc($maxlifetime)
index 67c8d7b8a646a49bbb0cf44f49747cd72088ba32..bccd703720af4fb590eb46eda9cb9d44935745ba 100644 (file)
@@ -1803,6 +1803,8 @@ class DBStructure
                                                ]
                                ];
 
+               \Friendica\Core\Addon::callHooks('dbstructure_definition', $database);
+
                return $database;
        }
 }
index d950d1d5fbff9cd7693b0b0acffc701745336cff..03f19197a361705910867c8400e6c6d24f119713 100644 (file)
@@ -9,6 +9,7 @@ use Friendica\Database\DBM;
 use dba;
 
 require_once 'boot.php';
+require_once 'include/conversation.php';
 require_once 'include/dba.php';
 
 class Term
@@ -168,4 +169,56 @@ class Term
                        }
                }
        }
+
+       /**
+        * Sorts an item's tags into mentions, hashtags and other tags. Generate personalized URLs by user and modify the
+        * provided item's body with them.
+        *
+        * @param array $item
+        * @return array
+        */
+       public static function populateTagsFromItem(&$item)
+       {
+               $return = [
+                       'tags' => [],
+                       'hashtags' => [],
+                       'mentions' => [],
+               ];
+
+               $searchpath = System::baseUrl() . "/search?tag=";
+
+               $taglist = dba::select(
+                       'term',
+                       ['type', 'term', 'url'],
+                       ["`otype` = ? AND `oid` = ? AND `type` IN (?, ?)", TERM_OBJ_POST, $item['id'], TERM_HASHTAG, TERM_MENTION],
+                       ['order' => ['tid']]
+               );
+
+               while ($tag = dba::fetch($taglist)) {
+                       if ($tag["url"] == "") {
+                               $tag["url"] = $searchpath . strtolower($tag["term"]);
+                       }
+
+                       $orig_tag = $tag["url"];
+
+                       $tag["url"] = best_link_url($item, $sp, $tag["url"]);
+
+                       if ($tag["type"] == TERM_HASHTAG) {
+                               if ($orig_tag != $tag["url"]) {
+                                       $item['body'] = str_replace($orig_tag, $tag["url"], $item['body']);
+                               }
+
+                               $return['hashtags'][] = "#<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
+                               $prefix = "#";
+                       } elseif ($tag["type"] == TERM_MENTION) {
+                               $return['mentions'][] = "@<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
+                               $prefix = "@";
+                       }
+
+                       $return['tags'][] = $prefix . "<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
+               }
+               dba::close($taglist);
+
+               return $return;
+       }
 }