From 279e74d06be7e2fc98c3df3cd867d1ecfd3e6de4 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sat, 15 Mar 2014 14:49:36 -0300 Subject: Squashed 'mod/landing/' content from commit d1ea0d2 git-subtree-dir: mod/landing git-subtree-split: d1ea0d2593cbf55a3804224fd587dbde00672a8c --- languages/en.php | 18 +++++ manifest.xml | 29 +++++++ start.php | 78 +++++++++++++++++++ test/landing_test.php | 117 ++++++++++++++++++++++++++++ views/default/landing/css.php | 1 + views/default/usersettings/landing/edit.php | 27 +++++++ 6 files changed, 270 insertions(+) create mode 100644 languages/en.php create mode 100644 manifest.xml create mode 100644 start.php create mode 100644 test/landing_test.php create mode 100644 views/default/landing/css.php create mode 100644 views/default/usersettings/landing/edit.php diff --git a/languages/en.php b/languages/en.php new file mode 100644 index 000000000..c2f17f6bb --- /dev/null +++ b/languages/en.php @@ -0,0 +1,18 @@ + 'A Custom Page', + 'landing:mode:opt:dashboard' => 'Your Dashboard', + 'landing:mode:opt:default' => 'Site Default', + 'landing:mode:opt:profile' => 'Your Profile', + // Plugin user settings labels + 'landing:settings:choose_option' => 'Choose landing destination', + 'landing:settings:custom_url_tip' => 'If you chose "A Custom Page", enter the path to the page, e.g.: "/g/lorea"', + 'landing:settings:select_url' => 'Choose the default page where you want to go after you log in from the front page:', +); + +add_translation('en', $english); \ No newline at end of file diff --git a/manifest.xml b/manifest.xml new file mode 100644 index 000000000..4d96a2e98 --- /dev/null +++ b/manifest.xml @@ -0,0 +1,29 @@ + + +Landing +Lorea Faeries (federation@lorea.org) +0.1 +Allow users to choose where to go after login +Lorea +Usability + + Choose where you go after you logged in from the front page. + You can choose between 'Site Default', 'Your Profile', 'Your + Dashboard', or 'A Custom Page'. + A custom page can be any existing URL in the site (e.g., your + favorite group, your blog, your friends' activity, or a wiki page.) + + The Dashboard plugin needs to be activated to use the 'Dashboard' + landing. + The Profiles plugin should be activated for the 'Profile' landing to + be useful. + +https://lorea.org/plugins/elgg-landing +2012 Lorea Faeries (federation@lorea.org) +GNU Affero General Public License version 3 or later + +elgg_version +2011123101 +gt + + diff --git a/start.php b/start.php new file mode 100644 index 000000000..05ccac9fb --- /dev/null +++ b/start.php @@ -0,0 +1,78 @@ + + * @copyright: 2012 Lorea Faeries + * @license: GNU Affero General Public License version 3 or later + * @package: ElggLanding + */ + +elgg_register_event_handler('init', 'system', 'landing_init'); + +function landing_init() { + // Register Tests + elgg_register_plugin_hook_handler('unit_test', 'system', 'landing_test'); + + // Register CSS + elgg_extend_view('css', 'landing/css'); + + // Register Login Event Handler + elgg_register_event_handler('login', 'user', 'landing_login_handler'); + +} + +/** + * Test the plugin + */ +function landing_test($hook, $type, $value, $params) { + $value[] = 'landing/test/landing_test.php'; + return $value; +} + +/** + * Redirect user to chosen landing page upon login + */ +function landing_login_handler($event, $type, $user) { + global $forward_url; + + if (empty($forward_url)) { + $forward_url = landing_page_url(); + } + + return NULL; +} + +function landing_page_url() { + + $user = elgg_get_logged_in_user_entity(); + if (!($user instanceof ElggUser)) { + return ''; + } + + $mode = get_plugin_usersetting('landing_mode', $user->guid, 'landing'); + + switch($mode) { + case 'profile': + if (elgg_is_active_plugin('profile')) { + $forward_url = "/profile/{$user->username}"; + } else { + $forward_url = "/view/{$user->guid}"; + } + break; + case 'custom': + $forward_url = get_plugin_usersetting('landing_url', $user->guid, 'landing'); + break; + case 'dashboard': + if (elgg_is_active_plugin('dashboard')) { + $forward_url = '/dashboard'; + break; + } + case 'default': + default: + $forward_url = ''; + break; + } + + return $forward_url; +} diff --git a/test/landing_test.php b/test/landing_test.php new file mode 100644 index 000000000..24264e938 --- /dev/null +++ b/test/landing_test.php @@ -0,0 +1,117 @@ +username = 'test_astronaut'; + $user->email = 'astronaut@example.net'; + $user->name = 'Astronaut Landing'; + $user->access_id = ACCESS_PUBLIC; + $user->salt = generate_random_cleartext_password(); + $user->password = generate_user_password($user, 'foo.bar.baz'); + $user->owner_guid = 0; + $user->container_guid = 0; + $user->save(); + + $this->user = $user; + } + + /** + * Called before each test method. + */ + public function setUp() { + $this->user->landing_mode = NULL; + $this->user->landing_url = NULL; + $this->user->save(); + } + + /** + * Called after each test method. + */ + public function tearDown() { + // do not allow SimpleTest to interpret Elgg notices as exceptions + $this->swallowErrors(); + logout($this->user); + } + + /** + * Called after each test object. + */ + public function __destruct() { + $this->user->delete(); + // all __destruct() code should go above here + parent::__destruct(); + } + + /** + * User must be able to login + */ + public function testUserCanLogin() { + $this->assertTrue(login($this->user->username, 'foo.bar.baz')); + } + + /** + * The landing plugin requires that $forward_url is declared + * global in actions/login.php + */ + public function testGlobalForwardURL() { + // require elgg_get_config('path') . 'actions/login.php'; + login($this->user->username, 'foo.bar.baz'); + $this->assertTrue(in_array('forward_url', array_keys($GLOBALS), TRUE)); + } + + public function testLandingToDefault() { + set_plugin_usersetting('landing_mode', 'default', $this->user->guid, 'landing'); + $this->assertEqual('default', $this->user->landing_mode); + login($this->user->username, 'foo.bar.baz'); + $this->assertEqual('', $forward_url); + } + + public function testLandingToProfile() { + set_plugin_usersetting('landing_mode', 'profile', $this->user->guid, 'landing'); + $this->assertEqual('profile', $this->user->landing_mode); + login($this->user->username, 'foo.bar.baz'); + if (elgg_is_active_plugin('profile')) { + $this->assertEqual("/profile/{$this->user->username}", $forward_url); + } else { + $this->assertEqual("/view/{$this->user->guid}", $forward_url); + } + } + + public function testLandingToDashboard() { + if (elgg_is_active_plugin('dashboard')) { + set_plugin_usersetting('landing_mode', 'dashboard', $this->user->guid, 'landing'); + $this->assertEqual('dashboard', $this->user->landing_mode); + login($this->user->username, 'foo.bar.baz'); + $this->assertEqual('/dashboard', $forward_url); + } + } + + public function testLandingToCustomPage() { + set_plugin_usersetting('landing_mode', 'custom', $this->user->guid, 'landing'); + set_plugin_usersetting('landing_url', '/some/existing/page', $this->user->guid, 'landing'); + $this->assertEqual('custom', $this->user->landing_mode); + login($this->user->username, 'foo.bar.baz'); + $this->assertEqual('/some/existing/page', $forward_url); + } + + public function testLandingToNonExistentCustomPage() { + set_plugin_usersetting('landing_mode', 'custom', $this->user->guid, 'landing'); + $this->assertEqual('custom', $this->user->landing_mode); + login($this->user->username, 'foo.bar.baz'); + $this->assertEqual(-1, $forward_url); // -1 means REFERRER + } + +} diff --git a/views/default/landing/css.php b/views/default/landing/css.php new file mode 100644 index 000000000..711794fc2 --- /dev/null +++ b/views/default/landing/css.php @@ -0,0 +1 @@ +input[type=text].landing-page-url { width: auto; } diff --git a/views/default/usersettings/landing/edit.php b/views/default/usersettings/landing/edit.php new file mode 100644 index 000000000..f302ce846 --- /dev/null +++ b/views/default/usersettings/landing/edit.php @@ -0,0 +1,27 @@ +', elgg_echo('landing:settings:select_url'); +// Add the dropdown menu +echo '
', elgg_echo('landing:settings:choose_option'); +echo elgg_view('input/dropdown', array('name' => 'params[landing_mode]', 'value' => $mode, 'options_values' => $mode_options)); +echo '

'; +// Add a text field for custom value or to show existing value +echo '

', elgg_echo('landing:settings:custom_url_tip'), ''; +echo '
', chop(elgg_get_site_url(), '/'), '', elgg_view('input/text', array( 'name' => 'params[landing_url]', 'value' => $custom_url, 'class' => 'landing-page-url')); +echo '

'; \ No newline at end of file -- cgit v1.2.3