Skip to content
This repository has been archived by the owner on Aug 30, 2019. It is now read-only.

Commit

Permalink
fix(dev): use service facade
Browse files Browse the repository at this point in the history
  • Loading branch information
hypeJunction committed Apr 17, 2018
1 parent d510ace commit da4f97f
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion actions/admin/scraper/clear.php
Expand Up @@ -5,7 +5,7 @@
return elgg_ok_response();
}

$svc = elgg()->scraper;
$svc = \hypeJunction\Scraper\ScraperService::instance();
$urls = $svc->find($domain);

foreach ($urls as $url) {
Expand Down
2 changes: 1 addition & 1 deletion actions/admin/scraper/edit.php
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion actions/admin/scraper/refetch.php
Expand Up @@ -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'));
Expand Down
2 changes: 1 addition & 1 deletion actions/admin/scraper/timestamp_images.php
Expand Up @@ -16,7 +16,7 @@
return elgg()->db->getData($query);
};

$svc = elgg()->scraper;
$svc = \hypeJunction\Scraper\ScraperService::instance();

$batch = new ElggBatch($getter, [
'limit' => 0,
Expand Down
2 changes: 1 addition & 1 deletion actions/upgrade/scraper/move_to_db.php
Expand Up @@ -11,7 +11,7 @@
return true;
}

$svc = elgg()->scraper;
$svc = \hypeJunction\Scraper\ScraperService::instance();

$site = elgg_get_site_entity();
$dataroot = elgg_get_config('dataroot');
Expand Down
11 changes: 11 additions & 0 deletions classes/hypeJunction/Scraper/ScraperService.php
Expand Up @@ -8,13 +8,16 @@
use Elgg\Database\Delete;
use Elgg\Database\Insert;
use Elgg\Database\Select;
use Elgg\Di\ServiceFacade;
use ElggFile;
use hypeJunction\Parser;
use InvalidParameterException;
use IOException;

class ScraperService {

use ServiceFacade;

/**
* @var Parser
*/
Expand Down Expand Up @@ -456,4 +459,12 @@ public function hasMemoryToResize($source) {

return $mem_avail > $requiredMemory;
}

/**
* Returns registered service name
* @return string
*/
public static function name() {
return 'scraper';
}
}
2 changes: 1 addition & 1 deletion classes/hypeJunction/Scraper/WebLocation.php
Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions lib/functions.php
Expand Up @@ -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);
}

/**
Expand All @@ -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;
}
2 changes: 1 addition & 1 deletion views/default/admin/scraper/cache.php
Expand Up @@ -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', [
Expand Down
2 changes: 1 addition & 1 deletion views/default/admin/upgrades/scraper/move_to_db.php
@@ -1,6 +1,6 @@
<?php

$svc = elgg()->scraper;
$svc = \hypeJunction\Scraper\ScraperService::instance();

$site = elgg_get_site_entity();
$dataroot = elgg_get_config('dataroot');
Expand Down
2 changes: 1 addition & 1 deletion views/default/embed/safe/player.php
Expand Up @@ -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);
Expand Down

0 comments on commit da4f97f

Please sign in to comment.