diff options
Diffstat (limited to 'mod')
| -rw-r--r-- | mod/landing/languages/en.php | 18 | ||||
| -rw-r--r-- | mod/landing/manifest.xml | 29 | ||||
| -rw-r--r-- | mod/landing/start.php | 78 | ||||
| -rw-r--r-- | mod/landing/test/landing_test.php | 117 | ||||
| -rw-r--r-- | mod/landing/views/default/landing/css.php | 1 | ||||
| -rw-r--r-- | mod/landing/views/default/usersettings/landing/edit.php | 27 | 
6 files changed, 270 insertions, 0 deletions
| diff --git a/mod/landing/languages/en.php b/mod/landing/languages/en.php new file mode 100644 index 000000000..c2f17f6bb --- /dev/null +++ b/mod/landing/languages/en.php @@ -0,0 +1,18 @@ +<?php +/** + * English  + */ + +$english = array( +				 // Plugin user settings options +				 'landing:mode:opt:custom'     => '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/mod/landing/manifest.xml b/mod/landing/manifest.xml new file mode 100644 index 000000000..4d96a2e98 --- /dev/null +++ b/mod/landing/manifest.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> +<plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8"> +<name>Landing</name> +<author>Lorea Faeries (federation@lorea.org)</author> +<version>0.1</version> +<blurb>Allow users to choose where to go after login</blurb> +<category>Lorea</category> +<category>Usability</category> +<description> +  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. +</description> +<website>https://lorea.org/plugins/elgg-landing</website> +<copyright>2012 Lorea Faeries (federation@lorea.org)</copyright> +<license>GNU Affero General Public License version 3 or later</license> +<requires> +<type>elgg_version</type> +<version>2011123101</version> +<comparison>gt</comparison> +</requires> +</plugin_manifest> diff --git a/mod/landing/start.php b/mod/landing/start.php new file mode 100644 index 000000000..05ccac9fb --- /dev/null +++ b/mod/landing/start.php @@ -0,0 +1,78 @@ +<?php +/** + * Landing Page Plugin for Elgg 1.8 + * + * @author: hellekin <hellekin@lorea.org> + * @copyright: 2012 Lorea Faeries <federation@lorea.org> + * @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/mod/landing/test/landing_test.php b/mod/landing/test/landing_test.php new file mode 100644 index 000000000..24264e938 --- /dev/null +++ b/mod/landing/test/landing_test.php @@ -0,0 +1,117 @@ +<?php +/** + * Elgg Landing Test + * + * @package ElggLanding + * @subpackage Test + */ +class ElggLandingTest extends ElggCoreUnitTest { + +	/** +	 * Called before each test object. +	 */ +	public function __construct() { +		parent::__construct(); +		 +		// all __construct() code should come after here +		$user = new ElggUser(); +		$user->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/mod/landing/views/default/landing/css.php b/mod/landing/views/default/landing/css.php new file mode 100644 index 000000000..711794fc2 --- /dev/null +++ b/mod/landing/views/default/landing/css.php @@ -0,0 +1 @@ +input[type=text].landing-page-url { width: auto; } diff --git a/mod/landing/views/default/usersettings/landing/edit.php b/mod/landing/views/default/usersettings/landing/edit.php new file mode 100644 index 000000000..f302ce846 --- /dev/null +++ b/mod/landing/views/default/usersettings/landing/edit.php @@ -0,0 +1,27 @@ +<?php +/** + * Page Landing User Settings + */ + +// Get existing usersettings +$custom_url = get_plugin_usersetting('landing_url', 0, 'landing'); +$mode       = get_plugin_usersetting('landing_mode', 0, 'landing'); + +// Prepare dropdown options +$mode_options   = array(); +$mode_options['default'] = elgg_echo('landing:mode:opt:default'); +$mode_options['profile'] = elgg_echo('landing:mode:opt:profile'); +if (elgg_is_active_plugin('dashboard')) { +    $mode_options['dashboard'] = elgg_echo('landing:mode:opt:dashboard'); +} +$mode_options['custom'] = elgg_echo('landing:mode:opt:custom'); + +echo '<p>', elgg_echo('landing:settings:select_url'); +// Add the dropdown menu +echo '<br/>', elgg_echo('landing:settings:choose_option'); +echo elgg_view('input/dropdown', array('name' => 'params[landing_mode]', 'value' => $mode, 'options_values' => $mode_options)); +echo '</p>'; +// Add a text field for custom value or to show existing value +echo '<p><span class="tip">', elgg_echo('landing:settings:custom_url_tip'), '</span>'; +echo '<br/><strong>', chop(elgg_get_site_url(), '/'), '</strong>', elgg_view('input/text', array( 'name' => 'params[landing_url]', 'value' => $custom_url, 'class' => 'landing-page-url')); +echo '</p>';
\ No newline at end of file | 
