From 9590b4684d4ff87a5986742bf00ea0a91e061b0c Mon Sep 17 00:00:00 2001 From: Sem Date: Mon, 9 Jul 2012 02:02:59 +0200 Subject: Fixes #4643. Locks the upgrade process while it is running. --- upgrade.php | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/upgrade.php b/upgrade.php index 60764ba93..38be476a4 100644 --- a/upgrade.php +++ b/upgrade.php @@ -13,6 +13,35 @@ * @subpackage Upgrade */ +function upgrade_lock() { + global $CONFIG, $DB_QUERY_CACHE; + + $is_locked = count(get_data("show tables like '{$CONFIG->dbprefix}locked'")); + + // Invalidate query cache + if ($DB_QUERY_CACHE) { + $DB_QUERY_CACHE->clear(); + elgg_log("Query cache invalidated", 'NOTICE'); + } + + if (!$is_locked) { + // lock it + insert_data("create table {$CONFIG->dbprefix}locked (id INT)"); + error_log('Upgrade continue running'); + return true; + } + + error_log('Upgrade is locked'); + return false; +} + +function upgrade_unlock() { + global $CONFIG; + delete_data("drop table {$CONFIG->dbprefix}locked"); + error_log('Upgrade unlocks itself'); +} + + // we want to know if an error occurs ini_set('display_errors', 1); @@ -20,6 +49,12 @@ define('UPGRADING', 'upgrading'); require_once(dirname(__FILE__) . "/engine/start.php"); if (get_input('upgrade') == 'upgrade') { + + // prevent someone from running the upgrade script in parallel (see #4643) + if (!upgrade_lock()) { + forward(); + } + // disable the system log for upgrades to avoid exceptions when the schema changes. elgg_unregister_event_handler('log', 'systemlog', 'system_log_default_logger'); elgg_unregister_event_handler('all', 'all', 'system_log_listener'); @@ -33,6 +68,10 @@ if (get_input('upgrade') == 'upgrade') { elgg_trigger_event('upgrade', 'system', null); elgg_invalidate_simplecache(); elgg_reset_system_cache(); + + // critical region has past + upgrade_unlock(); + } else { // if upgrading from < 1.8.0, check for the core view 'welcome' and bail if it's found. // see http://trac.elgg.org/ticket/3064 @@ -53,4 +92,4 @@ if (get_input('upgrade') == 'upgrade') { exit; } -forward(); \ No newline at end of file +forward(); -- cgit v1.2.3 From 1d2ce9657a44398646ed1a3980d89a1d2f50fa05 Mon Sep 17 00:00:00 2001 From: Sem Date: Fri, 13 Jul 2012 07:42:36 +0200 Subject: Fixes #1334. Added dropdown to change the parent of a page. --- mod/pages/actions/pages/edit.php | 3 ++ mod/pages/languages/en.php | 3 +- mod/pages/lib/pages.php | 53 +++++++++++++++++++++------- mod/pages/start.php | 1 + mod/pages/views/default/forms/pages/edit.php | 10 +++--- mod/pages/views/default/input/parent.php | 37 +++++++++++++++++++ 6 files changed, 87 insertions(+), 20 deletions(-) create mode 100644 mod/pages/views/default/input/parent.php diff --git a/mod/pages/actions/pages/edit.php b/mod/pages/actions/pages/edit.php index a32e4a4ba..e6387c1a4 100644 --- a/mod/pages/actions/pages/edit.php +++ b/mod/pages/actions/pages/edit.php @@ -59,6 +59,9 @@ if (sizeof($input) > 0) { if (($name == 'access_id' || $name == 'write_access_id') && !$can_change_access) { continue; } + if ($name == 'parent_guid') { + continue; + } $page->$name = $value; } diff --git a/mod/pages/languages/en.php b/mod/pages/languages/en.php index eb9d22708..930676b3e 100644 --- a/mod/pages/languages/en.php +++ b/mod/pages/languages/en.php @@ -61,6 +61,7 @@ View and comment on the new page: 'pages:title' => 'Page title', 'pages:description' => 'Page text', 'pages:tags' => 'Tags', + 'pages:parent_guid' => 'Parent page', 'pages:access_id' => 'Read access', 'pages:write_access_id' => 'Write access', @@ -110,4 +111,4 @@ View and comment on the new page: 'pages:backtoparent' => "Back to '%s'", ); -add_translation("en", $english); \ No newline at end of file +add_translation("en", $english); diff --git a/mod/pages/lib/pages.php b/mod/pages/lib/pages.php index 9a9ba12e9..afe42b68f 100644 --- a/mod/pages/lib/pages.php +++ b/mod/pages/lib/pages.php @@ -65,11 +65,11 @@ function pages_prepare_parent_breadcrumbs($page) { } /** - * Register the navigation menu + * Produce the navigation tree * * @param ElggEntity $container Container entity for the pages */ -function pages_register_navigation_tree($container) { +function pages_get_navigation_tree($container) { if (!$container) { return; } @@ -84,13 +84,18 @@ function pages_register_navigation_tree($container) { if (!$top_pages) { return; } + + $tree = array(); + $depths = array(); foreach ($top_pages as $page) { - elgg_register_menu_item('pages_nav', array( - 'name' => $page->getGUID(), - 'text' => $page->title, - 'href' => $page->getURL(), - )); + $tree[] = array( + 'guid' => $page->getGUID(), + 'title' => $page->title, + 'url' => $page->getURL(), + 'depth' => 0, + ); + $depths[$page->guid] = 0; $stack = array(); array_push($stack, $page); @@ -106,15 +111,37 @@ function pages_register_navigation_tree($container) { if ($children) { foreach ($children as $child) { - elgg_register_menu_item('pages_nav', array( - 'name' => $child->getGUID(), - 'text' => $child->title, - 'href' => $child->getURL(), - 'parent_name' => $parent->getGUID(), - )); + $tree[] = array( + 'guid' => $child->getGUID(), + 'title' => $child->title, + 'url' => $child->getURL(), + 'parent_guid' => $parent->getGUID(), + 'depth' => $depths[$parent->guid] + 1, + ); + $depths[$child->guid] = $depths[$parent->guid] + 1; array_push($stack, $child); } } } } + return $tree; +} + +/** + * Register the navigation menu + * + * @param ElggEntity $container Container entity for the pages + */ +function pages_register_navigation_tree($container) { + $pages = pages_get_navigation_tree($container); + if ($pages) { + foreach ($pages as $page) { + elgg_register_menu_item('pages_nav', array( + 'name' => $page['guid'], + 'text' => $page['title'], + 'href' => $page['url'], + 'parent_name' => $page['parent_guid'], + )); + } + } } diff --git a/mod/pages/start.php b/mod/pages/start.php index 6b0ad38b0..6d974f122 100644 --- a/mod/pages/start.php +++ b/mod/pages/start.php @@ -63,6 +63,7 @@ function pages_init() { 'title' => 'text', 'description' => 'longtext', 'tags' => 'tags', + 'parent_guid' => 'parent', 'access_id' => 'access', 'write_access_id' => 'write_access', )); diff --git a/mod/pages/views/default/forms/pages/edit.php b/mod/pages/views/default/forms/pages/edit.php index 9469f5eb9..119b9ba23 100644 --- a/mod/pages/views/default/forms/pages/edit.php +++ b/mod/pages/views/default/forms/pages/edit.php @@ -18,6 +18,9 @@ foreach ($variables as $name => $type) { if (($type == 'access' || $type == 'write_access') && !$can_change_access) { continue; } + if ($name == 'parent_guid' && empty($vars['parent_guid'])) { + continue; + } ?>
@@ -29,6 +32,7 @@ foreach ($variables as $name => $type) { echo elgg_view("input/$type", array( 'name' => $name, 'value' => $vars[$name], + 'entity' => ($name == 'parent_guid') ? $vars['entity'] : null, )); ?>
@@ -52,12 +56,6 @@ echo elgg_view('input/hidden', array( 'name' => 'container_guid', 'value' => $vars['container_guid'], )); -if ($vars['parent_guid']) { - echo elgg_view('input/hidden', array( - 'name' => 'parent_guid', - 'value' => $vars['parent_guid'], - )); -} echo elgg_view('input/submit', array('value' => elgg_echo('save'))); diff --git a/mod/pages/views/default/input/parent.php b/mod/pages/views/default/input/parent.php new file mode 100644 index 000000000..f354129fe --- /dev/null +++ b/mod/pages/views/default/input/parent.php @@ -0,0 +1,37 @@ +getContainerEntity(); +} + +$pages = pages_get_navigation_tree($container); +$options = array(); + +foreach ($pages as $page) { + $spacing = ""; + for ($i = 0; $i < $page['depth']; $i++) { + $spacing .= "--"; + } + $options[$page['guid']] = "$spacing " . $page['title']; +} + +$defaults = array( + 'class' => 'elgg-input-parent-picker', + 'options_values' => $options, +); + +$vars = array_merge($defaults, $vars); + +echo elgg_view('input/dropdown', $vars); -- cgit v1.2.3 From 3bd71fbe0aa4a64021c4c2d59b0782faba8c22b6 Mon Sep 17 00:00:00 2001 From: Sem Date: Sat, 14 Jul 2012 21:42:20 +0200 Subject: Refs #1334. Prevent cycles in the pages tree. --- mod/pages/actions/pages/edit.php | 22 +++++++++++++++++++++- mod/pages/views/default/forms/pages/edit.php | 3 ++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/mod/pages/actions/pages/edit.php b/mod/pages/actions/pages/edit.php index e6387c1a4..bf54ae87d 100644 --- a/mod/pages/actions/pages/edit.php +++ b/mod/pages/actions/pages/edit.php @@ -70,7 +70,27 @@ if (sizeof($input) > 0) { // need to add check to make sure user can write to container $page->container_guid = $container_guid; -if ($parent_guid) { +if ($parent_guid && $parent_guid != $page_guid) { + // Check if parent isn't below of the page in the tree + if ($page_guid) { + $tree_page = get_entity($parent_guid); + while ($tree_page->parent_guid > 0 && $page_guid != $tree_page->guid) { + $tree_page = get_entity($tree_page->parent_guid); + } + // If is below, bring all child elements forward + if ($page_guid == $tree_page->guid) { + $previous_parent = $page->parent_guid; + $children = elgg_get_entities_from_metadata(array( + 'metadata_name' => 'parent_guid', + 'metadata_value' => $page->getGUID() + )); + if ($children) { + foreach ($children as $child) { + $child->parent_guid = $previous_parent; + } + } + } + } $page->parent_guid = $parent_guid; } diff --git a/mod/pages/views/default/forms/pages/edit.php b/mod/pages/views/default/forms/pages/edit.php index 119b9ba23..583dc414f 100644 --- a/mod/pages/views/default/forms/pages/edit.php +++ b/mod/pages/views/default/forms/pages/edit.php @@ -18,7 +18,8 @@ foreach ($variables as $name => $type) { if (($type == 'access' || $type == 'write_access') && !$can_change_access) { continue; } - if ($name == 'parent_guid' && empty($vars['parent_guid'])) { + // don't show parent picker input for top or new pages. + if ($name == 'parent_guid' && (!$vars['parent_guid'] || !$vars['guid'])) { continue; } ?> -- cgit v1.2.3 From 21eb7616a11906a19260a081070a6b1c51820fa3 Mon Sep 17 00:00:00 2001 From: Sem Date: Sat, 14 Jul 2012 22:24:09 +0200 Subject: Refs #1334. Readded hidden input in edit page form, only on page creation. --- mod/pages/views/default/forms/pages/edit.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mod/pages/views/default/forms/pages/edit.php b/mod/pages/views/default/forms/pages/edit.php index 583dc414f..653a7ee47 100644 --- a/mod/pages/views/default/forms/pages/edit.php +++ b/mod/pages/views/default/forms/pages/edit.php @@ -57,6 +57,12 @@ echo elgg_view('input/hidden', array( 'name' => 'container_guid', 'value' => $vars['container_guid'], )); +if (!$vars['guid']) { + echo elgg_view('input/hidden', array( + 'name' => 'parent_guid', + 'value' => $vars['parent_guid'], + )); +} echo elgg_view('input/submit', array('value' => elgg_echo('save'))); -- cgit v1.2.3 From b134c8c70cc310e8170da44d1e2291f507cb31ff Mon Sep 17 00:00:00 2001 From: Matt Beckett Date: Sun, 15 Jul 2012 01:40:02 -0600 Subject: persist 'selected' state of site menu --- engine/lib/navigation.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/engine/lib/navigation.php b/engine/lib/navigation.php index 4ff009bfb..8845d5164 100644 --- a/engine/lib/navigation.php +++ b/engine/lib/navigation.php @@ -308,6 +308,41 @@ function elgg_site_menu_setup($hook, $type, $return, $params) { $return['more'] = array_splice($return['default'], $max_display_items); } } + + // check if we have anything selected + $selected = false; + foreach ($return as $section_name => $section) { + foreach ($section as $key => $item) { + if ($item->getSelected()) { + $selected = true; + break 2; + } + } + } + + if (!$selected) { + // nothing selected, match by handler + $handler = get_input('handler'); + + foreach ($return as $section_name => $section) { + foreach ($section as $key => $item) { + // determine the 'handler' of this url, if there is one + if (strpos($item->getHref(), elgg_get_site_url()) === 0) { + // this is an internal link, so it has a page handler + $path = array(str_replace(elgg_get_site_url(), '', $item->getHref())); + $separators = array('/', '?', '#'); + foreach ($separators as $separator) { + $path = explode($separator, $path[0]); + } + + if ($path[0] == $handler) { + $return[$section_name][$key]->setSelected(true); + break 2; + } + } + } + } + } return $return; } -- cgit v1.2.3 From dce60b43126dcaa38e6845ae45e09db87aa7e229 Mon Sep 17 00:00:00 2001 From: Sem Date: Tue, 17 Jul 2012 02:46:53 +0200 Subject: Refs #4643. Added unlock upgrade action. --- actions/admin/site/unlock_upgrade.php | 23 ++++++++++++++++++ engine/lib/admin.php | 1 + languages/en.php | 3 +++ upgrade.php | 2 ++ views/default/widgets/control_panel/content.php | 32 ++++++++++++++++++++----- 5 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 actions/admin/site/unlock_upgrade.php diff --git a/actions/admin/site/unlock_upgrade.php b/actions/admin/site/unlock_upgrade.php new file mode 100644 index 000000000..b73cf7033 --- /dev/null +++ b/actions/admin/site/unlock_upgrade.php @@ -0,0 +1,23 @@ +dbprefix}locked'")); + +// Invalidate query cache +if ($DB_QUERY_CACHE) { + $DB_QUERY_CACHE->clear(); + elgg_log("Query cache invalidated", 'NOTICE'); +} + +if ($is_locked) { + // @todo Move to ElggUpgradeManager::unlock() when #4682 fixed. + delete_data("drop table {$CONFIG->dbprefix}locked"); + error_log('Upgrade unlocks itself'); +} +system_message(elgg_echo('upgrade:unlock:success')); +forward(REFERER); \ No newline at end of file diff --git a/engine/lib/admin.php b/engine/lib/admin.php index b65d98c95..4673805f0 100644 --- a/engine/lib/admin.php +++ b/engine/lib/admin.php @@ -233,6 +233,7 @@ function admin_init() { elgg_register_action('admin/site/update_basic', '', 'admin'); elgg_register_action('admin/site/update_advanced', '', 'admin'); elgg_register_action('admin/site/flush_cache', '', 'admin'); + elgg_register_action('admin/site/unlock_upgrade', '', 'admin'); elgg_register_action('admin/menu/save', '', 'admin'); diff --git a/languages/en.php b/languages/en.php index 18d0c88d9..159867e2f 100644 --- a/languages/en.php +++ b/languages/en.php @@ -1047,6 +1047,9 @@ Once you have logged in, we highly recommend that you change your password. 'upgrading' => 'Upgrading...', 'upgrade:db' => 'Your database was upgraded.', 'upgrade:core' => 'Your Elgg installation was upgraded.', + 'upgrade:unlock' => 'Unlock upgrade', + 'upgrade:unlock:confirm' => "Somebody is performing an upgrade. You should cancel and wait until upgrade is done. Are you sure you want to continue?", + 'upgrade:unlock:success' => "Upgrade unlocked suscessfully.", 'upgrade:unable_to_upgrade' => 'Unable to upgrade.', 'upgrade:unable_to_upgrade_info' => 'This installation cannot be upgraded because legacy views diff --git a/upgrade.php b/upgrade.php index 38be476a4..e1f3c6b9e 100644 --- a/upgrade.php +++ b/upgrade.php @@ -13,6 +13,7 @@ * @subpackage Upgrade */ +// @todo Move to ElggUpgradeManager::lock() when #4628 fixed. function upgrade_lock() { global $CONFIG, $DB_QUERY_CACHE; @@ -35,6 +36,7 @@ function upgrade_lock() { return false; } +// @todo Move to ElggUpgradeManager::unlock() when #4682 fixed. function upgrade_unlock() { global $CONFIG; delete_data("drop table {$CONFIG->dbprefix}locked"); diff --git a/views/default/widgets/control_panel/content.php b/views/default/widgets/control_panel/content.php index d2db54bc6..e6763d851 100644 --- a/views/default/widgets/control_panel/content.php +++ b/views/default/widgets/control_panel/content.php @@ -11,12 +11,32 @@ elgg_register_menu_item('admin_control_panel', array( 'link_class' => 'elgg-button elgg-button-action', )); -elgg_register_menu_item('admin_control_panel', array( - 'name' => 'upgrade', - 'text' => elgg_echo('upgrade'), - 'href' => 'upgrade.php', - 'link_class' => 'elgg-button elgg-button-action', -)); +// @todo Move in this in ElggUpgradeManager::isLocked() when #4682 fixed +global $CONFIG, $DB_QUERY_CACHE; +$is_locked = count(get_data("show tables like '{$CONFIG->dbprefix}locked'")); +// Invalidate query cache +if ($DB_QUERY_CACHE) { + $DB_QUERY_CACHE->clear(); + elgg_log("Query cache invalidated", 'NOTICE'); +} + +if (!$is_locked) { + elgg_register_menu_item('admin_control_panel', array( + 'name' => 'upgrade', + 'text' => elgg_echo('upgrade'), + 'href' => 'upgrade.php', + 'link_class' => 'elgg-button elgg-button-action', + )); +} else { + elgg_register_menu_item('admin_control_panel', array( + 'name' => 'unlock_upgrade', + 'text' => elgg_echo('upgrade:unlock'), + 'href' => 'action/admin/site/unlock_upgrade', + 'is_action' => true, + 'link_class' => 'elgg-button elgg-button-delete', + 'confirm' => elgg_echo('upgrade:unlock:confirm'), + )); +} echo elgg_view_menu('admin_control_panel', array( 'class' => 'elgg-menu-hz', -- cgit v1.2.3 From b336f1065259b28113be1bca11dabe3ac167bd1a Mon Sep 17 00:00:00 2001 From: Matt Beckett Date: Tue, 17 Jul 2012 22:39:49 -0600 Subject: switched to matching by link name - same results, simpler code --- engine/lib/navigation.php | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/engine/lib/navigation.php b/engine/lib/navigation.php index 8845d5164..a9d28e22e 100644 --- a/engine/lib/navigation.php +++ b/engine/lib/navigation.php @@ -321,21 +321,12 @@ function elgg_site_menu_setup($hook, $type, $return, $params) { } if (!$selected) { - // nothing selected, match by handler - $handler = get_input('handler'); - + // nothing selected, match name to context foreach ($return as $section_name => $section) { foreach ($section as $key => $item) { - // determine the 'handler' of this url, if there is one + // only highlight internal links if (strpos($item->getHref(), elgg_get_site_url()) === 0) { - // this is an internal link, so it has a page handler - $path = array(str_replace(elgg_get_site_url(), '', $item->getHref())); - $separators = array('/', '?', '#'); - foreach ($separators as $separator) { - $path = explode($separator, $path[0]); - } - - if ($path[0] == $handler) { + if ($item->getName() == elgg_get_context()) { $return[$section_name][$key]->setSelected(true); break 2; } -- cgit v1.2.3 From ef351d0cf8a866cb40285e71fe5ed2b980bd11ed Mon Sep 17 00:00:00 2001 From: Steve Clay Date: Sun, 5 Aug 2012 21:03:35 -0400 Subject: Fixes #4764: Twitter login supports persistent and referrer forwarding --- actions/login.php | 4 +- engine/classes/ElggSession.php | 14 ++++--- mod/twitter_api/lib/twitter_api.php | 44 +++++++++++++++++++--- mod/twitter_api/start.php | 9 +++-- mod/twitter_api/views/default/twitter_api/css.php | 2 +- mod/twitter_api/views/default/twitter_api/js.php | 16 ++++++++ .../views/default/twitter_api/login.php | 2 +- 7 files changed, 72 insertions(+), 19 deletions(-) create mode 100644 mod/twitter_api/views/default/twitter_api/js.php diff --git a/actions/login.php b/actions/login.php index ea7fb3508..1e5e92ede 100644 --- a/actions/login.php +++ b/actions/login.php @@ -7,7 +7,7 @@ */ // set forward url -if (isset($_SESSION['last_forward_from']) && $_SESSION['last_forward_from']) { +if (!empty($_SESSION['last_forward_from'])) { $forward_url = $_SESSION['last_forward_from']; unset($_SESSION['last_forward_from']); } elseif (get_input('returntoreferer')) { @@ -19,7 +19,7 @@ if (isset($_SESSION['last_forward_from']) && $_SESSION['last_forward_from']) { $username = get_input('username'); $password = get_input('password', null, false); -$persistent = get_input("persistent", false); +$persistent = (bool) get_input("persistent"); $result = false; if (empty($username) || empty($password)) { diff --git a/engine/classes/ElggSession.php b/engine/classes/ElggSession.php index 13a33736c..9750f063e 100644 --- a/engine/classes/ElggSession.php +++ b/engine/classes/ElggSession.php @@ -54,7 +54,7 @@ class ElggSession implements ArrayAccess { * * @param mixed $key Name * - * @return void + * @return mixed */ function offsetGet($key) { if (!ElggSession::$__localcache) { @@ -98,7 +98,7 @@ class ElggSession implements ArrayAccess { * * @param int $offset Offset * - * @return int + * @return bool */ function offsetExists($offset) { if (isset(ElggSession::$__localcache[$offset])) { @@ -112,6 +112,8 @@ class ElggSession implements ArrayAccess { if ($this->offsetGet($offset)) { return true; } + + return false; } @@ -132,10 +134,10 @@ class ElggSession implements ArrayAccess { * @param string $key Name * @param mixed $value Value * - * @return mixed + * @return void */ function set($key, $value) { - return $this->offsetSet($key, $value); + $this->offsetSet($key, $value); } /** @@ -143,9 +145,9 @@ class ElggSession implements ArrayAccess { * * @param string $key Name * - * @return bool + * @return void */ function del($key) { - return $this->offsetUnset($key); + $this->offsetUnset($key); } } diff --git a/mod/twitter_api/lib/twitter_api.php b/mod/twitter_api/lib/twitter_api.php index fbce00d34..81c9c6628 100644 --- a/mod/twitter_api/lib/twitter_api.php +++ b/mod/twitter_api/lib/twitter_api.php @@ -29,6 +29,8 @@ function twitter_api_allow_sign_on_with_twitter() { * This includes the login URL as the callback */ function twitter_api_forward() { + global $SESSION; + // sanity check if (!twitter_api_allow_sign_on_with_twitter()) { forward(); @@ -37,6 +39,18 @@ function twitter_api_forward() { $callback = elgg_normalize_url("twitter_api/login"); $request_link = twitter_api_get_authorize_url($callback); + // capture metadata about login to persist through redirects + $login_metadata = array( + 'persistent' => (bool) get_input("persistent"), + ); + // capture referrer if in site, but not the twitter_api + if (!empty($_SERVER['HTTP_REFERER']) + && 0 === strpos($_SERVER['HTTP_REFERER'], elgg_get_site_url()) + && 0 !== strpos($_SERVER['HTTP_REFERER'], elgg_get_site_url() . 'twitter_api/')) { + $login_metadata['forward'] = $_SERVER['HTTP_REFERER']; + } + $SESSION['twitter_api_login_metadata'] = $login_metadata; + forward($request_link, 'twitter_api'); } @@ -55,6 +69,8 @@ function twitter_api_forward() { * the Twitter OAuth data. */ function twitter_api_login() { + /* @var ElggSession $SESSION */ + global $SESSION; // sanity check if (!twitter_api_allow_sign_on_with_twitter()) { @@ -62,6 +78,20 @@ function twitter_api_login() { } $token = twitter_api_get_access_token(get_input('oauth_verifier')); + + $persistent = false; + $forward = ''; + + // fetch login metadata from session + $login_metadata = $SESSION['twitter_api_login_metadata']; + unset($SESSION['twitter_api_login_metadata']); + if (!empty($login_metadata['persistent'])) { + $persistent = true; + } + if (!empty($login_metadata['forward'])) { + $forward = $login_metadata['forward']; + } + if (!isset($token['oauth_token']) or !isset($token['oauth_token_secret'])) { register_error(elgg_echo('twitter_api:login:error')); forward(); @@ -81,13 +111,13 @@ function twitter_api_login() { $users = elgg_get_entities_from_plugin_user_settings($options); if ($users) { - if (count($users) == 1 && login($users[0])) { - system_message(elgg_echo('twitter_api:login:success')); + if (count($users) == 1 && login($users[0], $persistent)) { + system_message(elgg_echo('twitter_api:login:success')); + forward($forward); } else { register_error(elgg_echo('twitter_api:login:error')); + forward(); } - - forward(elgg_get_site_url()); } else { $consumer_key = elgg_get_plugin_setting('consumer_key', 'twitter_api'); $consumer_secret = elgg_get_plugin_setting('consumer_secret', 'twitter_api'); @@ -301,9 +331,11 @@ function twitter_api_get_authorize_url($callback = NULL, $login = true) { /** * Returns the access token to use in twitter calls. * - * @param unknown_type $oauth_verifier + * @param bool $oauth_verifier + * @return array */ function twitter_api_get_access_token($oauth_verifier = FALSE) { + /* @var ElggSession $SESSION */ global $SESSION; $consumer_key = elgg_get_plugin_setting('consumer_key', 'twitter_api'); @@ -312,7 +344,7 @@ function twitter_api_get_access_token($oauth_verifier = FALSE) { // retrieve stored tokens $oauth_token = $SESSION['twitter_api']['oauth_token']; $oauth_token_secret = $SESSION['twitter_api']['oauth_token_secret']; - $SESSION->offsetUnset('twitter_api'); + unset($SESSION['twitter_api']); // fetch an access token $api = new TwitterOAuth($consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret); diff --git a/mod/twitter_api/start.php b/mod/twitter_api/start.php index 08bce5479..e6221de6b 100644 --- a/mod/twitter_api/start.php +++ b/mod/twitter_api/start.php @@ -20,6 +20,7 @@ function twitter_api_init() { //elgg_extend_view('metatags', 'twitter_api/metatags'); elgg_extend_view('css/elgg', 'twitter_api/css'); elgg_extend_view('css/admin', 'twitter_api/css'); + elgg_extend_view('js/elgg', 'twitter_api/js'); // sign on with twitter if (twitter_api_allow_sign_on_with_twitter()) { @@ -60,7 +61,7 @@ function twitter_api_pagehandler_deprecated($page) { * Serves pages for twitter. * * @param array $page - * @return void + * @return bool */ function twitter_api_pagehandler($page) { if (!isset($page[0])) { @@ -131,14 +132,15 @@ function twitter_api_tweet($hook, $type, $returnvalue, $params) { // send tweet $api = new TwitterOAuth($consumer_key, $consumer_secret, $access_key, $access_secret); - $response = $api->post('statuses/update', array('status' => $params['message'])); + $api->post('statuses/update', array('status' => $params['message'])); } /** * Get tweets for a user. * - * @param int $user_id The Elgg user GUID + * @param int $user_guid The Elgg user GUID * @param array $options + * @return array */ function twitter_api_fetch_tweets($user_guid, $options = array()) { // check admin settings @@ -167,6 +169,7 @@ function twitter_api_fetch_tweets($user_guid, $options = array()) { * @param string $type * @param array $return_value * @param array $params + * @return array */ function twitter_api_public_pages($hook, $type, $return_value, $params) { $return_value[] = 'twitter_api/forward'; diff --git a/mod/twitter_api/views/default/twitter_api/css.php b/mod/twitter_api/views/default/twitter_api/css.php index 04bbed668..2d081d361 100644 --- a/mod/twitter_api/views/default/twitter_api/css.php +++ b/mod/twitter_api/views/default/twitter_api/css.php @@ -4,7 +4,7 @@ */ ?> -#login_with_twitter { +.login_with_twitter { padding: 10px 0 0 0; } diff --git a/mod/twitter_api/views/default/twitter_api/js.php b/mod/twitter_api/views/default/twitter_api/js.php new file mode 100644 index 000000000..60839709d --- /dev/null +++ b/mod/twitter_api/views/default/twitter_api/js.php @@ -0,0 +1,16 @@ +