2014-06-01 08:39:46 -04: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-01-22 14:03:11 -05:00
require_once 'include/bbcode.php' ;
2014-06-01 08:39:46 -04:00
2018-02-14 21:43:40 -05:00
use Friendica\Content\Text\BBCode ;
2018-01-16 19:51:12 -05:00
use Friendica\Core\Addon ;
2017-11-06 18:55:24 -05:00
use Friendica\Core\Config ;
2018-01-22 14:03:11 -05:00
use Friendica\Core\L10n ;
2017-11-06 18:55:24 -05:00
2014-06-01 08:39:46 -04:00
function newmemberwidget_install () {
2018-01-16 19:51:12 -05:00
Addon :: registerHook ( 'network_mod_init' , 'addon/newmemberwidget/newmemberwidget.php' , 'newmemberwidget_network_mod_init' );
2014-06-01 08:39:46 -04:00
logger ( 'newmemberwidget installed' );
}
function newmemberwidget_uninstall () {
2018-01-16 19:51:12 -05:00
Addon :: unregisterHook ( 'network_mod_init' , 'addon/newmemberwidget/newmemberwidget.php' , 'newmemberwidget_network_mod_init' );
2014-06-01 08:39:46 -04:00
}
function newmemberwidget_network_mod_init ( $a , $b ) {
if ( x ( $_SESSION [ 'new_member' ])) {
$t = '<div id="newmember_widget" class="widget">' . EOL ;
2018-01-22 14:03:11 -05:00
$t .= '<h3>' . L10n :: t ( 'New Member' ) . '</h3>' . EOL ;
$t .= '<a href="newmember" id="newmemberwidget-tips">' . L10n :: t ( 'Tips for New Members' ) . '</a><br />' . EOL ;
2017-11-06 18:55:24 -05:00
if ( Config :: get ( 'newmemberwidget' , 'linkglobalsupport' ) == 1 )
2018-01-22 14:03:11 -05:00
$t .= '<a href="https://forum.friendi.ca/profile/helpers" target="_new">' . L10n :: t ( 'Global Support Forum' ) . '</a><br />' . EOL ;
2017-11-06 18:55:24 -05:00
if ( Config :: get ( 'newmemberwidget' , 'linklocalsupport' ) == 1 )
2018-01-22 14:03:11 -05:00
$t .= '<a href="' . $a -> get_baseurl () . '/profile/' . Config :: get ( 'newmemberwidget' , 'localsupport' ) . '" target="_new">' . L10n :: t ( 'Local Support Forum' ) . '</a><br />' . EOL ;
2017-11-06 18:55:24 -05:00
$ft = Config :: get ( 'newmemberwidget' , 'freetext' );
2014-06-01 08:39:46 -04:00
if ( ! trim ( $ft ) == " " )
2018-02-14 21:43:40 -05:00
$t .= '<p>' . BBCode :: convert ( trim ( $ft )) . '</p>' ;
2014-06-01 08:39:46 -04:00
$t .= '</div><div class="clear"></div>' ;
$a -> page [ 'aside' ] = $t . $a -> page [ 'aside' ];
}
}
2018-01-22 14:03:11 -05:00
function newmemberwidget_addon_admin_post ( & $a )
{
$ft = (( x ( $_POST , 'freetext' )) ? trim ( $_POST [ 'freetext' ]) : " " );
$lsn = (( x ( $_POST , 'localsupportname' )) ? notags ( trim ( $_POST [ 'localsupportname' ])) : " " );
$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 08:39:46 -04:00
}
2018-01-22 14:03:11 -05:00
function newmemberwidget_addon_admin ( & $a , & $o )
{
$t = get_markup_template ( 'admin.tpl' , 'addon/newmemberwidget' );
$o = replace_macros ( $t , [
'$submit' => L10n :: t ( 'Save Settings' ),
'$freetext' => [ " freetext " , L10n :: t ( " Message " ), Config :: get ( " newmemberwidget " , " freetext " ), L10n :: t ( " Your message for new members. You can use bbcode here. " )],
'$linkglobalsupport' => [ " linkglobalsupport " , L10n :: t ( 'Add a link to global support forum' ), Config :: get ( 'newmemberwidget' , 'linkglobalsupport' ), L10n :: t ( 'Should a link to the global support forum be displayed?' ) . " (<a href='https://forum.friendi.ca/profile/helpers'>@helpers</a>) " ],
'$linklocalsupport' => [ " linklocalsupport " , L10n :: t ( 'Add a link to the local support forum' ), Config :: get ( 'newmemberwidget' , 'linklocalsupport' ), L10n :: t ( 'If you have a local support forum and want to have a link displayed in the widget, check this box.' )],
'$localsupportname' => [ " localsupportname " , L10n :: t ( 'Name of the local support group' ), Config :: get ( 'newmemberwidget' , 'localsupport' ), L10n :: t ( 'If you checked the above, specify the <em>nickname</em> of the local support group here (i.e. helpers)' )],
]);
2014-06-01 08:39:46 -04:00
}