2014-06-01 12:39:46 +00:00
< ? php
/***
* Name : New Member Widget
* Description : Adds a widget for new members into the sidebar of the network page . The widget will be displayed for the 1 st 14 days of a account existance and contains a link to the new member page and a free - form text the admin can define .
* Version : 1
* Author : Tobias Diekershoff < https :// f . diekershoff . de / profile / tobias >
***/
2018-02-15 02:43:40 +00:00
use Friendica\Content\Text\BBCode ;
2017-11-06 23:55:24 +00:00
use Friendica\Core\Config ;
2018-12-26 07:28:16 +00:00
use Friendica\Core\Hook ;
2018-10-29 23:40:18 +00:00
use Friendica\Core\Logger ;
2018-10-31 14:55:15 +00:00
use Friendica\Core\Renderer ;
2019-12-30 02:55:10 +00:00
use Friendica\DI ;
2018-11-08 16:45:19 +00:00
use Friendica\Util\Strings ;
2017-11-06 23:55:24 +00:00
2018-07-10 12:30:23 +00:00
function newmemberwidget_install ()
{
2018-12-26 07:28:16 +00:00
Hook :: register ( 'network_mod_init' , 'addon/newmemberwidget/newmemberwidget.php' , 'newmemberwidget_network_mod_init' );
2018-10-29 23:40:18 +00:00
Logger :: log ( 'newmemberwidget installed' );
2014-06-01 12:39:46 +00:00
}
2018-07-10 12:30:23 +00:00
function newmemberwidget_uninstall ()
{
2018-12-26 07:28:16 +00:00
Hook :: unregister ( 'network_mod_init' , 'addon/newmemberwidget/newmemberwidget.php' , 'newmemberwidget_network_mod_init' );
2014-06-01 12:39:46 +00:00
}
2018-07-10 12:30:23 +00:00
function newmemberwidget_network_mod_init ( $a , $b )
{
if ( empty ( $_SESSION [ 'new_member' ])) {
return ;
}
2014-06-01 12:39:46 +00:00
$t = '<div id="newmember_widget" class="widget">' . EOL ;
2020-01-18 19:52:33 +00:00
$t .= '<h3>' . DI :: l10n () -> t ( 'New Member' ) . '</h3>' . EOL ;
$t .= '<a href="newmember" id="newmemberwidget-tips">' . DI :: l10n () -> t ( 'Tips for New Members' ) . '</a><br />' . EOL ;
2018-07-10 12:30:23 +00:00
2020-01-19 20:21:12 +00:00
if ( DI :: config () -> get ( 'newmemberwidget' , 'linkglobalsupport' , false )) {
2020-01-18 19:52:33 +00:00
$t .= '<a href="https://forum.friendi.ca/profile/helpers" target="_new">' . DI :: l10n () -> t ( 'Global Support Forum' ) . '</a><br />' . EOL ;
2018-07-10 12:30:23 +00:00
}
2020-01-19 20:21:12 +00:00
if ( DI :: config () -> get ( 'newmemberwidget' , 'linklocalsupport' , false )) {
$t .= '<a href="' . DI :: baseUrl () -> get () . '/profile/' . DI :: config () -> get ( 'newmemberwidget' , 'localsupport' ) . '" target="_new">' . DI :: l10n () -> t ( 'Local Support Forum' ) . '</a><br />' . EOL ;
2018-07-10 12:30:23 +00:00
}
2020-01-19 20:21:12 +00:00
$ft = DI :: config () -> get ( 'newmemberwidget' , 'freetext' , '' );
2018-07-10 12:30:23 +00:00
if ( ! empty ( $ft )) {
$t .= '<p>' . BBCode :: convert ( trim ( $ft )) . '</p>' ;
}
2014-06-01 12:39:46 +00:00
$t .= '</div><div class="clear"></div>' ;
2019-12-30 20:53:43 +00:00
DI :: page ()[ 'aside' ] = $t . DI :: page ()[ 'aside' ];
2014-06-01 12:39:46 +00:00
}
2018-01-22 19:03:11 +00:00
function newmemberwidget_addon_admin_post ( & $a )
{
2018-11-30 14:11:56 +00:00
$ft = ( ! empty ( $_POST [ 'freetext' ]) ? trim ( $_POST [ 'freetext' ]) : " " );
$lsn = ( ! empty ( $_POST [ 'localsupportname' ]) ? Strings :: escapeTags ( trim ( $_POST [ 'localsupportname' ])) : " " );
2018-01-22 19:03:11 +00:00
$gs = intval ( $_POST [ 'linkglobalsupport' ]);
$ls = intval ( $_POST [ 'linklocalsupport' ]);
Config :: set ( 'newmemberwidget' , 'freetext' , trim ( $ft ));
Config :: set ( 'newmemberwidget' , 'linkglobalsupport' , $gs );
Config :: set ( 'newmemberwidget' , 'linklocalsupport' , $ls );
Config :: set ( 'newmemberwidget' , 'localsupport' , trim ( $lsn ));
2014-06-01 12:39:46 +00:00
}
2018-01-22 19:03:11 +00:00
function newmemberwidget_addon_admin ( & $a , & $o )
{
2018-10-31 14:55:15 +00:00
$t = Renderer :: getMarkupTemplate ( 'admin.tpl' , 'addon/newmemberwidget' );
$o = Renderer :: replaceMacros ( $t , [
2020-01-18 19:52:33 +00:00
'$submit' => DI :: l10n () -> t ( 'Save Settings' ),
2020-01-19 20:21:12 +00:00
'$freetext' => [ " freetext " , DI :: l10n () -> t ( " Message " ), DI :: config () -> get ( " newmemberwidget " , " freetext " ), DI :: l10n () -> t ( " Your message for new members. You can use bbcode here. " )],
'$linkglobalsupport' => [ " linkglobalsupport " , DI :: l10n () -> t ( 'Add a link to global support forum' ), DI :: config () -> get ( 'newmemberwidget' , 'linkglobalsupport' ), DI :: l10n () -> t ( 'Should a link to the global support forum be displayed?' ) . " (<a href='https://forum.friendi.ca/profile/helpers'>@helpers</a>) " ],
'$linklocalsupport' => [ " linklocalsupport " , DI :: l10n () -> t ( 'Add a link to the local support forum' ), DI :: config () -> get ( 'newmemberwidget' , 'linklocalsupport' ), DI :: l10n () -> t ( 'If you have a local support forum and want to have a link displayed in the widget, check this box.' )],
'$localsupportname' => [ " localsupportname " , DI :: l10n () -> t ( 'Name of the local support group' ), DI :: config () -> get ( 'newmemberwidget' , 'localsupport' ), DI :: l10n () -> t ( 'If you checked the above, specify the <em>nickname</em> of the local support group here (i.e. helpers)' )],
2018-01-22 19:03:11 +00:00
]);
2014-06-01 12:39:46 +00:00
}