2012-05-22 21:05:39 -04:00
< ? php
/**
* Name : Start Page
* Description : Set a preferred page to load on login from home page
* Version : 1.0
* Author : Mike Macgirvin < http :// macgirvin . com / profile / mike >
2017-12-31 21:04:02 -05:00
*
2012-05-22 21:05:39 -04:00
*/
2021-11-20 04:56:55 -05:00
use Friendica\App ;
2018-12-26 02:28:16 -05:00
use Friendica\Core\Hook ;
2021-11-20 04:56:55 -05:00
use Friendica\Core\Renderer ;
2022-10-18 16:42:46 -04:00
use Friendica\Core\Session ;
2019-12-29 21:55:10 -05:00
use Friendica\DI ;
2012-05-22 21:05:39 -04:00
function startpage_install () {
2018-12-26 02:28:16 -05:00
Hook :: register ( 'home_init' , 'addon/startpage/startpage.php' , 'startpage_home_init' );
Hook :: register ( 'addon_settings' , 'addon/startpage/startpage.php' , 'startpage_settings' );
Hook :: register ( 'addon_settings_post' , 'addon/startpage/startpage.php' , 'startpage_settings_post' );
2012-05-22 21:05:39 -04:00
}
2022-06-23 01:16:22 -04:00
function startpage_home_init ( App $a , $b )
2018-08-08 02:24:47 -04:00
{
2022-10-18 16:42:46 -04:00
if ( ! Session :: getLocalUser ()) {
2012-05-22 21:05:39 -04:00
return ;
2018-08-08 02:24:47 -04:00
}
2012-05-22 21:05:39 -04:00
2022-10-18 16:42:46 -04:00
$page = DI :: pConfig () -> get ( Session :: getLocalUser (), 'startpage' , 'startpage' );
2018-08-08 02:24:47 -04:00
if ( strlen ( $page )) {
2019-12-29 21:55:10 -05:00
DI :: baseUrl () -> redirect ( $page );
2012-05-22 21:05:39 -04:00
}
return ;
}
/**
*
* Callback from the settings post function .
* $post contains the $_POST array .
* We will make sure we ' ve got a valid user account
* and if so set our configuration setting for this person .
*
*/
2022-06-23 01:16:22 -04:00
function startpage_settings_post ( App $a , $post )
2018-08-08 02:24:47 -04:00
{
2022-10-18 16:42:46 -04:00
if ( ! Session :: getLocalUser ()) {
2012-05-22 21:05:39 -04:00
return ;
2018-08-08 02:24:47 -04:00
}
if ( ! empty ( $_POST [ 'startpage-submit' ])) {
2022-10-18 16:42:46 -04:00
DI :: pConfig () -> set ( Session :: getLocalUser (), 'startpage' , 'startpage' , strip_tags ( trim ( $_POST [ 'startpage' ])));
2018-08-08 02:24:47 -04:00
}
2012-05-22 21:05:39 -04:00
}
/**
*
2018-01-20 08:57:41 -05:00
* Called from the Addon Setting form .
2012-05-22 21:05:39 -04:00
* Add our own settings info to the page .
*
*/
2021-11-20 04:56:55 -05:00
function startpage_settings ( App & $a , array & $data )
2018-08-08 02:24:47 -04:00
{
2022-10-18 16:42:46 -04:00
if ( ! Session :: getLocalUser ()) {
2012-05-22 21:05:39 -04:00
return ;
2018-08-08 02:24:47 -04:00
}
2012-05-22 21:05:39 -04:00
2022-10-18 16:42:46 -04:00
$startpage = DI :: pConfig () -> get ( Session :: getLocalUser (), 'startpage' , 'startpage' );
2012-05-22 21:05:39 -04:00
2021-11-20 04:56:55 -05:00
$t = Renderer :: getMarkupTemplate ( 'settings.tpl' , 'addon/startpage/' );
$html = Renderer :: replaceMacros ( $t , [
'$startpage' => [ 'startpage' , DI :: l10n () -> t ( 'Home page to load after login - leave blank for profile wall' ), $startpage , DI :: l10n () -> t ( 'Examples: "network" or "notifications/system"' )],
]);
2012-05-22 21:05:39 -04:00
2021-11-20 04:56:55 -05:00
$data = [
'addon' => 'startpage' ,
'title' => DI :: l10n () -> t ( 'Startpage' ),
'html' => $html ,
];
2012-05-22 21:05:39 -04:00
}