From da4f97feee4a79644d93217de287809df68038bf Mon Sep 17 00:00:00 2001 From: Ismayil Khayredinov Date: Tue, 17 Apr 2018 18:28:38 +0200 Subject: [PATCH] fix(dev): use service facade --- actions/admin/scraper/clear.php | 2 +- actions/admin/scraper/edit.php | 2 +- actions/admin/scraper/refetch.php | 2 +- actions/admin/scraper/timestamp_images.php | 2 +- actions/upgrade/scraper/move_to_db.php | 2 +- classes/hypeJunction/Scraper/ScraperService.php | 11 +++++++++++ classes/hypeJunction/Scraper/WebLocation.php | 2 +- lib/functions.php | 8 ++++++-- views/default/admin/scraper/cache.php | 2 +- views/default/admin/upgrades/scraper/move_to_db.php | 2 +- views/default/embed/safe/player.php | 2 +- 11 files changed, 26 insertions(+), 11 deletions(-) diff --git a/actions/admin/scraper/clear.php b/actions/admin/scraper/clear.php index d48941e..9d3e5f4 100644 --- a/actions/admin/scraper/clear.php +++ b/actions/admin/scraper/clear.php @@ -5,7 +5,7 @@ return elgg_ok_response(); } -$svc = elgg()->scraper; +$svc = \hypeJunction\Scraper\ScraperService::instance(); $urls = $svc->find($domain); foreach ($urls as $url) { diff --git a/actions/admin/scraper/edit.php b/actions/admin/scraper/edit.php index a37f9de..adeefa7 100644 --- a/actions/admin/scraper/edit.php +++ b/actions/admin/scraper/edit.php @@ -2,7 +2,7 @@ $href = get_input('href'); -$svc = elgg()->scraper; +$svc = \hypeJunction\Scraper\ScraperService::instance(); $data = $svc->get($href); $data['thumbnail_url'] = get_input('thumbnail_url', $data['thumbnail_url']); $data['title'] = get_input('title', $data['title'], false); diff --git a/actions/admin/scraper/refetch.php b/actions/admin/scraper/refetch.php index d1889c8..182ca54 100644 --- a/actions/admin/scraper/refetch.php +++ b/actions/admin/scraper/refetch.php @@ -2,7 +2,7 @@ $href = get_input('href'); -$svc = elgg()->scraper; +$svc = \hypeJunction\Scraper\ScraperService::instance(); if ($data = $svc->parse($href, true)) { return elgg_ok_response($data, elgg_echo('scraper:refetch:success')); diff --git a/actions/admin/scraper/timestamp_images.php b/actions/admin/scraper/timestamp_images.php index 26c4187..a06991b 100644 --- a/actions/admin/scraper/timestamp_images.php +++ b/actions/admin/scraper/timestamp_images.php @@ -16,7 +16,7 @@ return elgg()->db->getData($query); }; -$svc = elgg()->scraper; +$svc = \hypeJunction\Scraper\ScraperService::instance(); $batch = new ElggBatch($getter, [ 'limit' => 0, diff --git a/actions/upgrade/scraper/move_to_db.php b/actions/upgrade/scraper/move_to_db.php index dba15a9..c2c4708 100644 --- a/actions/upgrade/scraper/move_to_db.php +++ b/actions/upgrade/scraper/move_to_db.php @@ -11,7 +11,7 @@ return true; } -$svc = elgg()->scraper; +$svc = \hypeJunction\Scraper\ScraperService::instance(); $site = elgg_get_site_entity(); $dataroot = elgg_get_config('dataroot'); diff --git a/classes/hypeJunction/Scraper/ScraperService.php b/classes/hypeJunction/Scraper/ScraperService.php index c44863c..c6fad7c 100644 --- a/classes/hypeJunction/Scraper/ScraperService.php +++ b/classes/hypeJunction/Scraper/ScraperService.php @@ -8,6 +8,7 @@ use Elgg\Database\Delete; use Elgg\Database\Insert; use Elgg\Database\Select; +use Elgg\Di\ServiceFacade; use ElggFile; use hypeJunction\Parser; use InvalidParameterException; @@ -15,6 +16,8 @@ class ScraperService { + use ServiceFacade; + /** * @var Parser */ @@ -456,4 +459,12 @@ public function hasMemoryToResize($source) { return $mem_avail > $requiredMemory; } + + /** + * Returns registered service name + * @return string + */ + public static function name() { + return 'scraper'; + } } diff --git a/classes/hypeJunction/Scraper/WebLocation.php b/classes/hypeJunction/Scraper/WebLocation.php index 644540b..d273932 100644 --- a/classes/hypeJunction/Scraper/WebLocation.php +++ b/classes/hypeJunction/Scraper/WebLocation.php @@ -31,7 +31,7 @@ public function getURL() { * @return WebResource */ public function getData() { - $scraper = elgg()->scraper; + $scraper = \hypeJunction\Scraper\ScraperService::instance(); /* @var $scraper ScraperService */ $data = $scraper->scrape($this->url) ? : [ 'url' => $this->url, diff --git a/lib/functions.php b/lib/functions.php index d7e502c..315dcb4 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -9,7 +9,7 @@ * @return array|false */ function hypeapps_scrape($url, $cache_only = false, $flush = false) { - return elgg()->scraper->scrape($url, $cache_only, $flush); + return \hypeJunction\Scraper\ScraperService::instance()->scrape($url, $cache_only, $flush); } /** @@ -27,21 +27,25 @@ function hypeapps_extract_tokens($text) { * * @param string $text Source text * @param array $options Flags indicating which tokens to parse - * @return array + * @return string */ function hypeapps_linkify_tokens($text, array $options = []) { if (elgg_extract('parse_hashtags', $options, true)) { $text = \hypeJunction\Scraper\Linkify::hashtags($text); } + if (elgg_extract('parse_urls', $options, true)) { $text = \hypeJunction\Scraper\Linkify::urls($text); } + if (elgg_extract('parse_usernames', $options, true)) { $text = \hypeJunction\Scraper\Linkify::usernames($text); } + if (elgg_extract('parse_emails', $options, true)) { $text = \hypeJunction\Scraper\Linkify::emails($text); } + return $text; } diff --git a/views/default/admin/scraper/cache.php b/views/default/admin/scraper/cache.php index ddbf8b0..06bfa5f 100644 --- a/views/default/admin/scraper/cache.php +++ b/views/default/admin/scraper/cache.php @@ -14,7 +14,7 @@ return; } -$svc = elgg()->scraper; +$svc = \hypeJunction\Scraper\ScraperService::instance(); $urls = $svc->find($domain); if (empty($urls)) { echo elgg_format_element('p', [ diff --git a/views/default/admin/upgrades/scraper/move_to_db.php b/views/default/admin/upgrades/scraper/move_to_db.php index 32adccd..12c4eef 100644 --- a/views/default/admin/upgrades/scraper/move_to_db.php +++ b/views/default/admin/upgrades/scraper/move_to_db.php @@ -1,6 +1,6 @@ scraper; +$svc = \hypeJunction\Scraper\ScraperService::instance(); $site = elgg_get_site_entity(); $dataroot = elgg_get_config('dataroot'); diff --git a/views/default/embed/safe/player.php b/views/default/embed/safe/player.php index aca7481..afd0cea 100644 --- a/views/default/embed/safe/player.php +++ b/views/default/embed/safe/player.php @@ -7,7 +7,7 @@ $svc = elgg()->shortcodes; /* @var $svc \hypeJunction\Shortcodes\ShortcodesService */ -$scraper = elgg()->scraper; +$scraper = \hypeJunction\Scraper\ScraperService::instance(); /* @var $scraper \hypeJunction\Scraper\ScraperService */ $url = elgg_extract('url', $vars);