From 4d39164c1ee6de2b1a09c2a1a8a4c89531d47ee5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 31 Jul 2018 04:06:22 +0200 Subject: [PATCH] [WIP] Rewrite to Proxy class: (#5507) * Rewrite to Proxy class: - introduced new Friendica\Network\Proxy class for in exchange of proxy_*() functions - moved also all PROXY_* constants there as Proxy::* - removed now no longer needed mod/proxy.php loading as composer's auto-load will do this for us - renamed those proxy_*() functions to better names: + proxy_init() -> Proxy::init() (public) + proxy_url() -> Proxy::proxifyUrl() (public) + proxy_parse_html() -> Proxy::proxifyHtml() (public) + proxy_is_local_image() -> Proxy::isLocalImage() (private) + proxy_parse_query() -> Proxy::parseQuery() (private) + proxy_img_cb() -> Proxy::replaceUrl() (private) * Ops, need to set $a here ... * CR request: - moved Proxy class to Friendica\Module - extended BaseModule * Ops, no need for own instance of $a when self::getApp() is around. * Proxy-rewrite: - proxy_url() and proxy_parse_html() are both non-module functions (now methods) - so they must be splitted into a seperate class - also the SIZE_* and DEFAULT_TIME constants are both not relevant to module * No instances from utility classes * Fixed error: - proxify*() is now located in `Friendica\Util\ProxyUtils` * Moved back to original place, ops? How did they move here? Well, it was not intended by me. * Removed duplicate (left-over from split) constants and static array. Thank to MrPetovan finding it. * Renamed ProxyUtils -> Proxy and aliased it back to ProxyUtils. --- include/api.php | 6 +- include/conversation.php | 13 +- include/dba.php | 1 + include/text.php | 4 +- mod/acl.php | 8 +- mod/allfriends.php | 3 +- mod/common.php | 3 +- mod/contacts.php | 5 +- mod/directory.php | 5 +- mod/dirfind.php | 3 +- mod/follow.php | 3 +- mod/hovercard.php | 3 +- mod/match.php | 4 +- mod/message.php | 5 +- mod/network.php | 3 +- mod/ping.php | 6 +- mod/proxy.php | 375 ------------------------------ mod/suggest.php | 10 +- mod/viewcontacts.php | 5 +- src/Content/ForumManager.php | 3 +- src/Content/OEmbed.php | 9 +- src/Content/Text/BBCode.php | 7 +- src/Core/NotificationsManager.php | 23 +- src/Model/Profile.php | 4 +- src/Module/Proxy.php | 268 +++++++++++++++++++++ src/Object/Post.php | 8 +- src/Protocol/OStatus.php | 4 +- src/Util/Proxy.php | 221 ++++++++++++++++++ src/Worker/CronJobs.php | 7 +- view/theme/vier/theme.php | 7 +- 30 files changed, 578 insertions(+), 448 deletions(-) delete mode 100644 mod/proxy.php create mode 100644 src/Module/Proxy.php create mode 100644 src/Util/Proxy.php diff --git a/include/api.php b/include/api.php index c00578cdf0..4fbbc37779 100644 --- a/include/api.php +++ b/include/api.php @@ -40,6 +40,7 @@ use Friendica\Object\Image; use Friendica\Protocol\Diaspora; use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; +use Friendica\Util\Proxy as ProxyUtils; use Friendica\Util\XML; require_once 'include/conversation.php'; @@ -47,7 +48,6 @@ require_once 'mod/share.php'; require_once 'mod/item.php'; require_once 'include/security.php'; require_once 'mod/wall_upload.php'; -require_once 'mod/proxy.php'; define('API_METHOD_ANY', '*'); define('API_METHOD_GET', 'GET'); @@ -2518,7 +2518,7 @@ function api_get_entitities(&$text, $bbcode) preg_match_all("/\[img](.*?)\[\/img\]/ism", $bbcode, $images); foreach ($images[1] as $image) { - $replace = proxy_url($image); + $replace = ProxyUtils::proxifyUrl($image); $text = str_replace($image, $replace, $text); } return []; @@ -2627,7 +2627,7 @@ function api_get_entitities(&$text, $bbcode) // If image cache is activated, then use the following sizes: // thumb (150), small (340), medium (600) and large (1024) if (!Config::get("system", "proxy_disabled")) { - $media_url = proxy_url($url); + $media_url = ProxyUtils::proxifyUrl($url); $sizes = []; $scale = Image::getScalingDimensions($image[0], $image[1], 150); diff --git a/include/conversation.php b/include/conversation.php index 89bc4b5478..5addb610c7 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -20,6 +20,7 @@ use Friendica\Model\Term; use Friendica\Object\Post; use Friendica\Object\Thread; use Friendica\Util\DateTimeFormat; +use Friendica\Util\Proxy as ProxyUtils; use Friendica\Util\Temporal; use Friendica\Util\XML; @@ -407,7 +408,6 @@ function visible_activity($item) { * */ function conversation(App $a, array $items, $mode, $update, $preview = false, $order = 'commented', $uid = 0) { - require_once 'mod/proxy.php'; $ssl_state = ((local_user()) ? true : false); @@ -418,8 +418,10 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o if (local_user()) { $str_blocked = PConfig::get(local_user(), 'system', 'blocked'); + if ($str_blocked) { $arr_blocked = explode(',', $str_blocked); + for ($x = 0; $x < count($arr_blocked); $x ++) { $arr_blocked[$x] = trim($arr_blocked[$x]); } @@ -477,6 +479,7 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o } } elseif ($mode === 'notes') { $profile_owner = local_user(); + if (!$update) { $live_update_div = '
' . "\r\n" . "