This repository has been archived by the owner on Aug 30, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): align with latest core changes
- Loading branch information
1 parent
ab24023
commit 9acff29
Showing
20 changed files
with
484 additions
and
445 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
classes/hypeJunction/Scraper/AddBookmarkProfilePreview.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace hypeJunction\Scraper; | ||
|
||
class AddBookmarkProfilePreview { | ||
|
||
/** | ||
* Display a preview of a bookmark | ||
* | ||
* @param string $hook 'view_vars' | ||
* @param string $type "object/elements/full" | ||
* @param array $return View vars | ||
* @param array $params Hook params | ||
* | ||
* @return array | ||
*/ | ||
public function __invoke($hook, $type, $return, $params) { | ||
|
||
if (!elgg_get_plugin_setting('bookmarks', 'hypeScraper')) { | ||
return; | ||
} | ||
|
||
$entity = elgg_extract('entity', $return); | ||
if (!elgg_instanceof($entity, 'object', 'bookmarks')) { | ||
return; | ||
} | ||
|
||
$return['body'] .= elgg_view('output/player', [ | ||
'href' => $entity->address, | ||
]); | ||
|
||
return $return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace hypeJunction\Scraper; | ||
|
||
class AddBookmarkRiverPreview { | ||
|
||
/** | ||
* Display a preview of a bookmark | ||
* | ||
* @param string $hook 'view_vars' | ||
* @param string $type "river/elements/layout" | ||
* @param array $return View vars | ||
* @param array $params Hook params | ||
* | ||
* @return array | ||
*/ | ||
public function __invoke($hook, $type, $return, $params) { | ||
|
||
if (!elgg_get_plugin_setting('bookmarks', 'hypeScraper')) { | ||
return; | ||
} | ||
|
||
$item = elgg_extract('item', $return); | ||
if (!$item instanceof ElggRiverItem) { | ||
return; | ||
} | ||
|
||
if ($item->view != 'river/object/bookmarks/create') { | ||
return; | ||
} | ||
|
||
$object = $item->getObjectEntity(); | ||
if (!elgg_instanceof($object, 'object', 'bookmarks')) { | ||
return; | ||
} | ||
|
||
$preview_type = elgg_get_plugin_setting('preview_type', 'hypeScraper', 'card'); | ||
if ($preview_type != 'card') { | ||
$return['attachments'] = elgg_view('output/player', [ | ||
'href' => $object->address, | ||
'fallback' => true, | ||
]); | ||
} else { | ||
$return['attachments'] = elgg_view('output/card', [ | ||
'href' => $object->address, | ||
]); | ||
} | ||
|
||
return $return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
|
||
namespace hypeJunction\Scraper; | ||
|
||
use Elgg\Includer; | ||
use Elgg\PluginBootstrap; | ||
|
||
class Bootstrap extends PluginBootstrap { | ||
|
||
/** | ||
* Get plugin root | ||
* @return string | ||
*/ | ||
protected function getRoot() { | ||
return dirname(dirname(dirname(dirname(__FILE__)))); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function load() { | ||
Includer::requireFileOnce($this->getRoot() . '/autoloader.php'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function boot() { | ||
|
||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function init() { | ||
|
||
elgg_extend_view('elgg.css', 'framework/scraper/stylesheet.css'); | ||
elgg_extend_view('admin.css', 'framework/scraper/stylesheet.css'); | ||
elgg_extend_view('elgg.js', 'framework/scraper/player.js'); | ||
|
||
elgg_register_ajax_view('output/card'); | ||
|
||
elgg_register_plugin_hook_handler('format:src', 'embed', PrepareEmbedCard::class); | ||
elgg_register_plugin_hook_handler('extract:meta', 'all', ScrapeUrlMetadata::class); | ||
elgg_register_plugin_hook_handler('extract:qualifiers', 'all', ExtractTokensFromText::class); | ||
elgg_register_plugin_hook_handler('prepare', 'html', PrepareHtmlOutput::class, 100); | ||
|
||
elgg_register_plugin_hook_handler('fields', 'object', AddFormField::class); | ||
|
||
// Bookmark previews | ||
if (elgg_is_active_plugin('bookmarks')) { | ||
elgg_register_plugin_hook_handler('view_vars', 'river/elements/layout', AddBookmarkRiverPreview::class); | ||
elgg_register_plugin_hook_handler('view_vars', 'object/elements/full', AddBookmarkProfilePreview::class); | ||
} | ||
|
||
// Basic XSS protection | ||
elgg_register_plugin_hook_handler('parse', 'framework:scraper', FilteroEmbedHtml::class); | ||
|
||
// Menus | ||
elgg_register_plugin_hook_handler('register', 'menu:scraper:card', CardMenu::class); | ||
elgg_register_plugin_hook_handler('register', 'menu:page', PageMenu::class); | ||
|
||
if (elgg()->has('shortcodes')) { | ||
elgg()->shortcodes->register('player'); | ||
|
||
elgg_register_action('embed/player', \hypeJunction\Scraper\EmbedAction::class); | ||
|
||
elgg_register_plugin_hook_handler('register', 'menu:embed', EmbedMenu::class); | ||
elgg_register_plugin_hook_handler('view_vars', 'river/elements/layout', EmbedRiverAttachment::class, 999); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function ready() { | ||
|
||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function shutdown() { | ||
|
||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function activate() { | ||
|
||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function deactivate() { | ||
|
||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function upgrade() { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace hypeJunction\Scraper; | ||
|
||
use Elgg\Hook; | ||
|
||
class ExtractTokensFromText { | ||
|
||
/** | ||
* Extract qualifiers such as hashtags, usernames, urls, and emails | ||
* | ||
* @elgg_plugin_hook extract:qualifiers scraper | ||
* | ||
* @param Hook $hook Hook | ||
* | ||
* @return array | ||
*/ | ||
public static function extractTokens(Hook $hook) { | ||
$text = $hook->getParam('source'); | ||
|
||
return Extractor::all($text); | ||
} | ||
} |
Oops, something went wrong.