add(domainsearch): files
This commit is contained in:
parent
03530d4489
commit
3e196c17b1
44
domainsearch/domainsearch.php
Normal file
44
domainsearch/domainsearch.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Plugin Domain Search.
|
||||
*
|
||||
* Add an icon in the link list for searching links from the same domain.
|
||||
*/
|
||||
|
||||
use Shaarli\Plugin\PluginManager;
|
||||
|
||||
/**
|
||||
* Add domain search icon to link_plugin when rendering linklist.
|
||||
*
|
||||
* @param mixed $data - linklist data.
|
||||
*
|
||||
* @return mixed - linklist data with domain search plugin.
|
||||
*/
|
||||
function hook_domainsearch_render_linklist($data)
|
||||
{
|
||||
$domainsearch_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/domainsearch/domainsearch.html');
|
||||
$path = ($data['_ROOT_PATH_'] ?? '') . '/' . PluginManager::$PLUGINS_PATH;
|
||||
|
||||
foreach ($data['links'] as &$value) {
|
||||
$isNote = startsWith($value['real_url'], '/shaare/');
|
||||
if ($value['private'] && $isNote) {
|
||||
continue;
|
||||
}
|
||||
$url = $isNote ? rtrim(index_url($_SERVER), '/') . $value['real_url'] : $value['real_url'];
|
||||
$domain = parse_url($url, PHP_URL_SCHEME) . '://' . parse_url($url, PHP_URL_HOST);
|
||||
$domainsearch = sprintf($domainsearch_html, urlencode($domain), $path, t('Search links from this domain'));
|
||||
$value['link_plugin'][] = $domainsearch;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is never called, but contains translation calls for GNU gettext extraction.
|
||||
*/
|
||||
function domainsearch_dummy_translation()
|
||||
{
|
||||
// meta
|
||||
t('For each link, add a Domain Search icon to search for links from the same domain.');
|
||||
}
|
Loading…
Reference in New Issue
Block a user