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