2020-03-21 18:30:30 +00:00
< ? php
/**
* Name : Link
* Description : Using short links on whole hub
2020-04-02 12:40:23 +00:00
* Version : 0.05
2020-03-21 18:30:30 +00:00
* Author : ivan zlax <@ zlax @ ussr . win >
* Maintainer : ivan zlax <@ zlax @ ussr . win >
*/
2020-03-31 20:21:35 +00:00
use Zotlabs\Lib\Apps ;
use Zotlabs\Extend\Hook ;
use Zotlabs\Extend\Route ;
2020-03-21 18:30:30 +00:00
2020-03-31 20:21:35 +00:00
function link_load () {
Route :: register ( 'addon/link/Mod_Link.php' , 'link' );
2020-04-02 11:38:07 +00:00
if ( get_config ( 'link' , 'linkonhub' ))
register_hook ( 'page_end' , 'addon/link/link.php' , 'link_active' );
2020-03-31 20:21:35 +00:00
}
2020-03-21 18:30:30 +00:00
2020-03-31 20:21:35 +00:00
function link_unload () {
Route :: unregister ( 'addon/link/Mod_Link.php' , 'link' );
2020-04-02 11:38:07 +00:00
unregister_hook ( 'page_end' , 'addon/link/link.php' , 'link_active' );
}
function link_plugin_admin ( & $a , & $o ) {
$linkonhub = get_config ( 'link' , 'linkonhub' );
$t = get_markup_template ( " admin.tpl " , " addon/link/ " );
$o = replace_macros ( $t , array (
'$submit' => t ( 'Submit' ),
2020-04-02 12:40:23 +00:00
'$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)' )),
2020-04-02 11:38:07 +00:00
));
}
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' );
2020-03-31 17:45:31 +00:00
}
2020-03-31 20:21:35 +00:00
function link_active ( & $a , & $b ) {
2020-04-02 11:38:07 +00:00
// Javascript code for "Link on Hub" button insert - it is not good, it is temporarily, works not good
2020-03-31 21:08:20 +00:00
$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 " ;
2020-03-31 20:21:35 +00:00
}