PageRenderTime 43ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/startpage/startpage.php

https://github.com/chiefdome/friendica-addons
PHP | 94 lines | 43 code | 26 blank | 25 comment | 6 complexity | 3a5afe5009ad3b720a234fe6541770fb MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-3.0, GPL-2.0
  1. <?php
  2. /**
  3. * Name: Start Page
  4. * Description: Set a preferred page to load on login from home page
  5. * Version: 1.0
  6. * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
  7. *
  8. */
  9. function startpage_install() {
  10. register_hook('home_init', 'addon/startpage/startpage.php', 'startpage_home_init');
  11. register_hook('plugin_settings', 'addon/startpage/startpage.php', 'startpage_settings');
  12. register_hook('plugin_settings_post', 'addon/startpage/startpage.php', 'startpage_settings_post');
  13. }
  14. function startpage_uninstall() {
  15. unregister_hook('home_init', 'addon/startpage/startpage.php', 'startpage_home_init');
  16. unregister_hook('plugin_settings', 'addon/startpage/startpage.php', 'startpage_settings');
  17. unregister_hook('plugin_settings_post', 'addon/startpage/startpage.php', 'startpage_settings_post');
  18. }
  19. function startpage_home_init($a, $b) {
  20. if(! local_user())
  21. return;
  22. $page = get_pconfig(local_user(),'startpage','startpage');
  23. if(strlen($page)) {
  24. $slash = ((strpos($page,'/') === 0) ? true : false);
  25. if(stristr($page,'://'))
  26. goaway($page);
  27. goaway($a->get_baseurl() . (($slash) ? '' : '/') . $page);
  28. }
  29. return;
  30. }
  31. /**
  32. *
  33. * Callback from the settings post function.
  34. * $post contains the $_POST array.
  35. * We will make sure we've got a valid user account
  36. * and if so set our configuration setting for this person.
  37. *
  38. */
  39. function startpage_settings_post($a,$post) {
  40. if(! local_user())
  41. return;
  42. if($_POST['startpage-submit'])
  43. set_pconfig(local_user(),'startpage','startpage',strip_tags(trim($_POST['startpage'])));
  44. }
  45. /**
  46. *
  47. * Called from the Plugin Setting form.
  48. * Add our own settings info to the page.
  49. *
  50. */
  51. function startpage_settings(&$a,&$s) {
  52. if(! local_user())
  53. return;
  54. /* Add our stylesheet to the page so we can make our settings look nice */
  55. $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/startpage/startpage.css' . '" media="all" />' . "\r\n";
  56. /* Get the current state of our config variable */
  57. $page = get_pconfig(local_user(),'startpage','startpage');
  58. /* Add some HTML to the existing form */
  59. $s .= '<div class="settings-block">';
  60. $s .= '<h3>' . t('Startpage Settings') . '</h3>';
  61. $s .= '<div id="startpage-page-wrapper">';
  62. $s .= '<label id="startpage-page-label" for="startpage-page">' . t('Home page to load after login - leave blank for profile wall') . '</label>';
  63. $s .= '<input id="startpage-page" type="text" name="startpage" value="' . $page . '" />';
  64. $s .= '</div><div class="clear"></div>';
  65. $s .= '<div id="startpage-desc">' . t('Examples: &quot;network&quot; or &quot;notifications/system&quot;') . '</div>';
  66. /* provide a submit button */
  67. $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="startpage-submit" class="settings-submit" value="' . t('Submit') . '" /></div></div>';
  68. }