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
|
|
|
*/
|
2018-01-16 19:51:12 -05:00
|
|
|
use Friendica\Core\Addon;
|
2018-01-22 14:03:11 -05:00
|
|
|
use Friendica\Core\L10n;
|
2017-11-06 18:55:24 -05:00
|
|
|
use Friendica\Core\PConfig;
|
2012-05-22 21:05:39 -04:00
|
|
|
|
|
|
|
function startpage_install() {
|
2018-01-16 19:51:12 -05:00
|
|
|
Addon::registerHook('home_init', 'addon/startpage/startpage.php', 'startpage_home_init');
|
2018-01-20 08:57:41 -05:00
|
|
|
Addon::registerHook('addon_settings', 'addon/startpage/startpage.php', 'startpage_settings');
|
|
|
|
Addon::registerHook('addon_settings_post', 'addon/startpage/startpage.php', 'startpage_settings_post');
|
2012-05-22 21:05:39 -04:00
|
|
|
}
|
|
|
|
|
2018-08-08 02:24:47 -04:00
|
|
|
function startpage_uninstall()
|
|
|
|
{
|
2018-01-16 19:51:12 -05:00
|
|
|
Addon::unregisterHook('home_init', 'addon/startpage/startpage.php', 'startpage_home_init');
|
2018-01-20 08:57:41 -05:00
|
|
|
Addon::unregisterHook('addon_settings', 'addon/startpage/startpage.php', 'startpage_settings');
|
|
|
|
Addon::unregisterHook('addon_settings_post', 'addon/startpage/startpage.php', 'startpage_settings_post');
|
2012-05-22 21:05:39 -04:00
|
|
|
}
|
|
|
|
|
2018-08-08 02:24:47 -04:00
|
|
|
function startpage_home_init($a, $b)
|
|
|
|
{
|
|
|
|
if (!local_user()) {
|
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
|
|
|
|
2018-08-08 02:24:47 -04:00
|
|
|
$page = PConfig::get(local_user(), 'startpage', 'startpage');
|
|
|
|
if (strlen($page)) {
|
2017-12-31 21:04:02 -05:00
|
|
|
goaway($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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-08-08 02:24:47 -04:00
|
|
|
function startpage_settings_post($a, $post)
|
|
|
|
{
|
|
|
|
if (!local_user()) {
|
2012-05-22 21:05:39 -04:00
|
|
|
return;
|
2018-08-08 02:24:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($_POST['startpage-submit'])) {
|
|
|
|
PConfig::set(local_user(), 'startpage', 'startpage', strip_tags(trim($_POST['startpage'])));
|
|
|
|
}
|
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.
|
|
|
|
*
|
|
|
|
*/
|
2018-08-08 02:24:47 -04:00
|
|
|
function startpage_settings(&$a, &$s)
|
|
|
|
{
|
|
|
|
if (!local_user()) {
|
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
|
|
|
|
|
|
|
/* Add our stylesheet to the page so we can make our settings look nice */
|
|
|
|
|
2018-10-09 14:13:22 -04:00
|
|
|
$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->getBaseURL() . '/addon/startpage/startpage.css' . '" media="all" />' . "\r\n";
|
2012-05-22 21:05:39 -04:00
|
|
|
|
|
|
|
/* Get the current state of our config variable */
|
|
|
|
|
2018-08-08 02:24:47 -04:00
|
|
|
$page = PConfig::get(local_user(), 'startpage', 'startpage');
|
2012-05-22 21:05:39 -04:00
|
|
|
|
|
|
|
/* Add some HTML to the existing form */
|
|
|
|
|
2014-03-16 15:50:36 -04:00
|
|
|
$s .= '<span id="settings_startpage_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_startpage_expanded\'); openClose(\'settings_startpage_inflated\');">';
|
2018-01-22 14:03:11 -05:00
|
|
|
$s .= '<h3>' . L10n::t('Startpage') . '</h3>';
|
2014-03-16 15:50:36 -04:00
|
|
|
$s .= '</span>';
|
|
|
|
$s .= '<div id="settings_startpage_expanded" class="settings-block" style="display: none;">';
|
|
|
|
$s .= '<span class="fakelink" onclick="openClose(\'settings_startpage_expanded\'); openClose(\'settings_startpage_inflated\');">';
|
2018-01-22 14:03:11 -05:00
|
|
|
$s .= '<h3>' . L10n::t('Startpage') . '</h3>';
|
2014-03-16 15:50:36 -04:00
|
|
|
$s .= '</span>';
|
2012-05-22 21:05:39 -04:00
|
|
|
$s .= '<div id="startpage-page-wrapper">';
|
2018-01-22 14:03:11 -05:00
|
|
|
$s .= '<label id="startpage-page-label" for="startpage-page">' . L10n::t('Home page to load after login - leave blank for profile wall') . '</label>';
|
2012-05-22 21:05:39 -04:00
|
|
|
$s .= '<input id="startpage-page" type="text" name="startpage" value="' . $page . '" />';
|
|
|
|
$s .= '</div><div class="clear"></div>';
|
2018-01-22 14:03:11 -05:00
|
|
|
$s .= '<div id="startpage-desc">' . L10n::t('Examples: "network" or "notifications/system"') . '</div>';
|
2012-05-22 21:05:39 -04:00
|
|
|
|
|
|
|
/* provide a submit button */
|
|
|
|
|
2018-01-22 14:03:11 -05:00
|
|
|
$s .= '<div class="settings-submit-wrapper" ><input type="submit" name="startpage-submit" class="settings-submit" value="' . L10n::t('Save Settings') . '" /></div></div>';
|
2012-05-22 21:05:39 -04:00
|
|
|
}
|