2
0
Fork 0
ussr-hubzilla-addons/link/link.php

47 lines
2.1 KiB
PHP

<?php
/**
* Name: Link
* Description: Using short links on whole hub
* Version: 0.05
* Author: ivan zlax <@zlax@ussr.win>
* Maintainer: ivan zlax <@zlax@ussr.win>
*/
use Zotlabs\Lib\Apps;
use Zotlabs\Extend\Hook;
use Zotlabs\Extend\Route;
function link_load() {
Route::register('addon/link/Mod_Link.php','link');
if (get_config('link','linkonhub'))
register_hook('page_end', 'addon/link/link.php', 'link_active');
}
function link_unload() {
Route::unregister('addon/link/Mod_Link.php','link');
unregister_hook('page_end', 'addon/link/link.php', 'link_active');
}
function link_plugin_admin(&$a,&$o) {
$t = get_markup_template( "admin.tpl", "addon/link/" );
$o = replace_macros($t, array(
'$submit' => t('Submit'),
'$linkonhub' => array('linkonhub', t('Show "Link on Hub" button'), get_config('link', 'linkonhub'), t('Currently used temporarily javascript code for the integrating with wall-item-menu (will be fixed later)')),
));
}
function link_plugin_admin_post(&$a) {
set_config('link','linkonhub',trim($_POST['linkonhub']));
info( t('Settings updated.') . EOL);
if (get_config('link','linkonhub'))
register_hook('page_end', 'addon/link/link.php', 'link_active');
else
unregister_hook('page_end', 'addon/link/link.php', 'link_active');
}
function link_active(&$a,&$b) {
// Javascript code for "Link on Hub" button insert - it is not good, it is temporarily, works not good
$b .= "\n<script>window.buttonsnotedited = true; setInterval(addButtons, 1000); function addButtons() { if (window.buttonsnotedited == true) { if (loadingPage == false) { let visibleitems = document.querySelectorAll('.btn-group [aria-labelledby]'); for (currentitem of visibleitems) { if (currentitem.getAttribute('aria-labelledby').substr(0,15) == 'wall-item-menu-') currentitem.querySelector('[title=\"Link to Source\"]').outerHTML += '<a class=\"dropdown-item\" href=\"/link/' + currentitem.getAttribute('aria-labelledby').substr(15) + '\" title=\"Link on Hub\"><i class=\"generic-icons-nav fa fa-fw fa-external-link\"></i>Link on Hub</a>';} window.buttonsnotedited = false; } } }</script>\n";
}