From 02840336736e2b827c1c073246785bde260222f6 Mon Sep 17 00:00:00 2001
From: Franz Liedke
Date: Mon, 20 Jun 2011 15:24:53 +0200
Subject: Add setHref() method to ElggMenuItem class. Fixes #3486.
---
engine/classes/ElggMenuItem.php | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
(limited to 'engine/classes')
diff --git a/engine/classes/ElggMenuItem.php b/engine/classes/ElggMenuItem.php
index 157ed9ceb..d76518be2 100644
--- a/engine/classes/ElggMenuItem.php
+++ b/engine/classes/ElggMenuItem.php
@@ -132,7 +132,7 @@ class ElggMenuItem {
$item->setItemClass($options['item_class']);
unset($options['item_class']);
}
-
+
foreach ($options as $key => $value) {
$item->$key = $value;
}
@@ -163,6 +163,15 @@ class ElggMenuItem {
return $this->text;
}
+ /**
+ * Set the URL of the menu item
+ *
+ * @return void
+ */
+ public function setHref($href) {
+ $this->href = $href;
+ }
+
/**
* Get the URL of the menu item
*
@@ -465,7 +474,7 @@ class ElggMenuItem {
* @params array $vars Options to pass to output/url if a link
*
* @return string
- *
+ *
* @todo View code in a model. How do we feel about that?
*/
public function getContent(array $vars = array()) {
@@ -475,7 +484,7 @@ class ElggMenuItem {
}
$vars['text'] = $this->text;
-
+
if ($this->href) {
$vars['href'] = $this->href;
}
@@ -483,15 +492,15 @@ class ElggMenuItem {
if ($this->linkClass) {
$vars['class'] = $this->getLinkClass();
}
-
+
if ($this->rel) {
$vars['rel'] = $this->rel;
}
-
+
if ($this->title) {
$vars['title'] = $this->title;
}
-
+
if ($this->is_action) {
$vars['is_action'] = $this->is_action;
}
--
cgit v1.2.3
From c26b3f7cc82f935f0fb5c1e12e63fc2719886397 Mon Sep 17 00:00:00 2001
From: Franz Liedke
Date: Mon, 20 Jun 2011 22:03:50 +0200
Subject: Add setText() method to ElggMenuItem class. Fixes #3546.
---
engine/classes/ElggMenuItem.php | 9 +++++++++
1 file changed, 9 insertions(+)
(limited to 'engine/classes')
diff --git a/engine/classes/ElggMenuItem.php b/engine/classes/ElggMenuItem.php
index 157ed9ceb..caab2223d 100644
--- a/engine/classes/ElggMenuItem.php
+++ b/engine/classes/ElggMenuItem.php
@@ -153,6 +153,15 @@ class ElggMenuItem {
public function getName() {
return $this->name;
}
+
+ /**
+ * Set the display text of the menu
+ *
+ * @return string
+ */
+ public function setText($text) {
+ $this->text = $text;
+ }
/**
* Get the display text of the menu
--
cgit v1.2.3
From 7f1df879c1e083575baa890edd07f7f2f1469f67 Mon Sep 17 00:00:00 2001
From: Franz Liedke
Date: Tue, 21 Jun 2011 01:00:49 -0700
Subject: Fix dumb typos from last commit.
---
engine/classes/ElggMenuItem.php | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'engine/classes')
diff --git a/engine/classes/ElggMenuItem.php b/engine/classes/ElggMenuItem.php
index caab2223d..10146899e 100644
--- a/engine/classes/ElggMenuItem.php
+++ b/engine/classes/ElggMenuItem.php
@@ -155,16 +155,16 @@ class ElggMenuItem {
}
/**
- * Set the display text of the menu
+ * Set the display text of the menu item
*
- * @return string
+ * @return void
*/
public function setText($text) {
$this->text = $text;
}
/**
- * Get the display text of the menu
+ * Get the display text of the menu item
*
* @return string
*/
--
cgit v1.2.3
From a76b2261206e097f091bf75ff679f2f33c55232b Mon Sep 17 00:00:00 2001
From: Franz Liedke
Date: Tue, 21 Jun 2011 11:36:05 -0700
Subject: Add param description to PHPDoc comments of setText() function.
---
engine/classes/ElggMenuItem.php | 2 ++
1 file changed, 2 insertions(+)
(limited to 'engine/classes')
diff --git a/engine/classes/ElggMenuItem.php b/engine/classes/ElggMenuItem.php
index 10146899e..47d1e8374 100644
--- a/engine/classes/ElggMenuItem.php
+++ b/engine/classes/ElggMenuItem.php
@@ -157,6 +157,8 @@ class ElggMenuItem {
/**
* Set the display text of the menu item
*
+ * @param string $text The display text
+ *
* @return void
*/
public function setText($text) {
--
cgit v1.2.3
From dbf3edd887ee26b85d609481ea9ee247f3d46ac3 Mon Sep 17 00:00:00 2001
From: cash
Date: Sat, 25 Jun 2011 11:37:16 -0400
Subject: Fixes #3609 removed use of deprecated trigger_plugin_hook()
---
engine/classes/ElggEntity.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'engine/classes')
diff --git a/engine/classes/ElggEntity.php b/engine/classes/ElggEntity.php
index 8fc1e46cb..5b78f5db5 100644
--- a/engine/classes/ElggEntity.php
+++ b/engine/classes/ElggEntity.php
@@ -851,7 +851,7 @@ abstract class ElggEntity extends ElggData implements
*/
function countComments() {
$params = array('entity' => $this);
- $num = trigger_plugin_hook('comments:count', $this->getType(), $params);
+ $num = elgg_trigger_plugin_hook('comments:count', $this->getType(), $params);
if (is_int($num)) {
return $num;
--
cgit v1.2.3
From b0b197ee2e73974a8b0c080086945383a863410e Mon Sep 17 00:00:00 2001
From: Cash Costello
Date: Sun, 26 Jun 2011 06:41:39 -0400
Subject: Fixes #3614 updated use of elgg_view_entity() throughout core
---
engine/classes/ElggEntity.php | 2 +-
mod/blog/lib/blog.php | 2 +-
mod/bookmarks/pages/bookmarks/view.php | 2 +-
mod/file/pages/file/view.php | 2 +-
mod/groups/lib/discussion.php | 2 +-
mod/groups/views/default/groups/sidebar/featured.php | 2 +-
mod/messages/pages/messages/read.php | 2 +-
mod/pages/pages/pages/view.php | 2 +-
mod/search/views/default/search/entity.php | 2 +-
pages/entities/index.php | 2 +-
views/default/page/elements/owner_block.php | 2 +-
views/json/entities/entity_list.php | 4 ++--
12 files changed, 13 insertions(+), 13 deletions(-)
(limited to 'engine/classes')
diff --git a/engine/classes/ElggEntity.php b/engine/classes/ElggEntity.php
index 5b78f5db5..6edc99dd4 100644
--- a/engine/classes/ElggEntity.php
+++ b/engine/classes/ElggEntity.php
@@ -1628,7 +1628,7 @@ abstract class ElggEntity extends ElggData implements
*/
elgg_set_viewtype('default');
- $view = elgg_view_entity($this, true);
+ $view = elgg_view_entity($this, array('full_view' => true));
elgg_set_viewtype();
$tmp[] = new ODDMetaData($uuid . "volatile/renderedentity/", $uuid,
diff --git a/mod/blog/lib/blog.php b/mod/blog/lib/blog.php
index 8964d5b53..6bdbc8b1f 100644
--- a/mod/blog/lib/blog.php
+++ b/mod/blog/lib/blog.php
@@ -38,7 +38,7 @@ function blog_get_page_content_read($guid = NULL) {
}
elgg_push_breadcrumb($blog->title);
- $return['content'] = elgg_view_entity($blog, TRUE);
+ $return['content'] = elgg_view_entity($blog, array('full_view' => true));
//check to see if comment are on
if ($blog->comments_on != 'Off') {
$return['content'] .= elgg_view_comments($blog);
diff --git a/mod/bookmarks/pages/bookmarks/view.php b/mod/bookmarks/pages/bookmarks/view.php
index d0a9c630a..8e097b090 100644
--- a/mod/bookmarks/pages/bookmarks/view.php
+++ b/mod/bookmarks/pages/bookmarks/view.php
@@ -21,7 +21,7 @@ $title = $bookmark->title;
elgg_push_breadcrumb($title);
-$content = elgg_view_entity($bookmark, true);
+$content = elgg_view_entity($bookmark, array('full_view' => true));
$content .= elgg_view_comments($bookmark);
$body = elgg_view_layout('content', array(
diff --git a/mod/file/pages/file/view.php b/mod/file/pages/file/view.php
index 45e112d4d..4b395d20d 100644
--- a/mod/file/pages/file/view.php
+++ b/mod/file/pages/file/view.php
@@ -22,7 +22,7 @@ $title = $file->title;
elgg_push_breadcrumb($title);
-$content = elgg_view_entity($file, true);
+$content = elgg_view_entity($file, array('full_view' => true));
$content .= elgg_view_comments($file);
$download = elgg_view('output/url', array(
diff --git a/mod/groups/lib/discussion.php b/mod/groups/lib/discussion.php
index 94d212ef6..342115c81 100644
--- a/mod/groups/lib/discussion.php
+++ b/mod/groups/lib/discussion.php
@@ -167,7 +167,7 @@ function discussion_handle_view_page($guid) {
elgg_push_breadcrumb($group->name, "discussion/owner/$group->guid");
elgg_push_breadcrumb($topic->title);
- $content = elgg_view_entity($topic, true);
+ $content = elgg_view_entity($topic, array('full_view' => true));
if ($topic->status == 'closed') {
$content .= elgg_view('discussion/replies', array(
'entity' => $topic,
diff --git a/mod/groups/views/default/groups/sidebar/featured.php b/mod/groups/views/default/groups/sidebar/featured.php
index 695782783..8bd51ab5c 100644
--- a/mod/groups/views/default/groups/sidebar/featured.php
+++ b/mod/groups/views/default/groups/sidebar/featured.php
@@ -17,7 +17,7 @@ if ($featured_groups) {
elgg_push_context('widgets');
$body = '';
foreach ($featured_groups as $group) {
- $body .= elgg_view_entity($group, false);
+ $body .= elgg_view_entity($group, array('full_view' => false));
}
elgg_pop_context();
diff --git a/mod/messages/pages/messages/read.php b/mod/messages/pages/messages/read.php
index 5397d33e5..9bedbd08a 100644
--- a/mod/messages/pages/messages/read.php
+++ b/mod/messages/pages/messages/read.php
@@ -27,7 +27,7 @@ if ($page_owner->getGUID() == $message->toId) {
elgg_push_breadcrumb($title);
$buttons = '';
-$content = elgg_view_entity($message, true);
+$content = elgg_view_entity($message, array('full_view' => true));
if ($inbox) {
$form_params = array(
'id' => 'messages-reply-form',
diff --git a/mod/pages/pages/pages/view.php b/mod/pages/pages/pages/view.php
index b73bc985c..06064d993 100644
--- a/mod/pages/pages/pages/view.php
+++ b/mod/pages/pages/pages/view.php
@@ -29,7 +29,7 @@ if (elgg_instanceof($container, 'group')) {
pages_prepare_parent_breadcrumbs($page);
elgg_push_breadcrumb($title);
-$content = elgg_view_entity($page, true);
+$content = elgg_view_entity($page, array('full_view' => true));
$content .= elgg_view_comments($page);
$buttons = '';
diff --git a/mod/search/views/default/search/entity.php b/mod/search/views/default/search/entity.php
index 2193a70d8..e04d08836 100644
--- a/mod/search/views/default/search/entity.php
+++ b/mod/search/views/default/search/entity.php
@@ -27,7 +27,7 @@ if (!$icon) {
} else {
// display a generic icon if no owner, though there will probably be
// other problems if the owner can't be found.
- $icon = elgg_view_entity($entity, 'tiny');
+ $icon = elgg_view_entity_icon($entity, 'tiny');
}
}
diff --git a/pages/entities/index.php b/pages/entities/index.php
index 13aea9e5a..d3b935dc4 100644
--- a/pages/entities/index.php
+++ b/pages/entities/index.php
@@ -36,7 +36,7 @@ if ($entity = get_entity($guid)) {
} else if ($entity instanceof ElggEntity) {
$title = $entity->name;
}
- $area1 = elgg_view_entity($entity, true);
+ $area1 = elgg_view_entity($entity, array('full_view' => true));
if ($shell) {
$body = elgg_view_layout('one_column', array('content' => $area1));
} else {
diff --git a/views/default/page/elements/owner_block.php b/views/default/page/elements/owner_block.php
index c525a38aa..fc7f0f6d2 100644
--- a/views/default/page/elements/owner_block.php
+++ b/views/default/page/elements/owner_block.php
@@ -15,7 +15,7 @@ $owner = elgg_get_page_owner_entity();
if ($owner instanceof ElggGroup ||
($owner instanceof ElggUser && $owner->getGUID() != elgg_get_logged_in_user_guid())) {
- $header = elgg_view_entity($owner, false);
+ $header = elgg_view_entity($owner, array('full_view' => false));
$body = elgg_view_menu('owner_block', array('entity' => $owner));
diff --git a/views/json/entities/entity_list.php b/views/json/entities/entity_list.php
index b583588c3..d5b134a71 100644
--- a/views/json/entities/entity_list.php
+++ b/views/json/entities/entity_list.php
@@ -4,7 +4,7 @@ $entities = $vars['entities'];
$full_view = $vars['full_view'];
if (is_array($entities) && sizeof($entities) > 0) {
- foreach($entities as $entity) {
- echo elgg_view_entity($entity, $full_view);
+ foreach ($entities as $entity) {
+ echo elgg_view_entity($entity, array('full_view' => $full_view));
}
}
--
cgit v1.2.3
From 32387e6db0c56935e93314217b52eab4d9dca016 Mon Sep 17 00:00:00 2001
From: Cash Costello
Date: Sun, 26 Jun 2011 08:16:19 -0400
Subject: Fixes #3470 using rel=toggle now
---
engine/classes/ElggMenuItem.php | 4 ++++
engine/lib/navigation.php | 2 +-
js/lib/ui.js | 6 +++---
mod/groups/start.php | 4 ++--
mod/logbrowser/views/default/logbrowser/form.php | 8 ++++----
mod/profile/views/default/profile/owner_block.php | 2 +-
mod/reportedcontent/views/default/object/reported_content.php | 2 +-
views/default/object/plugin/advanced.php | 2 +-
views/default/object/plugin/invalid.php | 2 +-
views/default/object/widget/elements/controls.php | 6 ++++--
views/default/page/layouts/widgets/add_button.php | 11 ++++++++---
11 files changed, 30 insertions(+), 19 deletions(-)
(limited to 'engine/classes')
diff --git a/engine/classes/ElggMenuItem.php b/engine/classes/ElggMenuItem.php
index cd6267ad6..1181583f2 100644
--- a/engine/classes/ElggMenuItem.php
+++ b/engine/classes/ElggMenuItem.php
@@ -504,6 +504,10 @@ class ElggMenuItem {
$vars['class'] = $this->getLinkClass();
}
+ if ($this->link_rel) {
+ $vars['rel'] = $this->link_rel;
+ }
+
if ($this->rel) {
$vars['rel'] = $this->rel;
}
diff --git a/engine/lib/navigation.php b/engine/lib/navigation.php
index b51c63b49..4b2c998a2 100644
--- a/engine/lib/navigation.php
+++ b/engine/lib/navigation.php
@@ -276,7 +276,7 @@ function elgg_river_menu_setup($hook, $type, $return, $params) {
'href' => "#comments-add-$object->guid",
'text' => elgg_view_icon('speech-bubble'),
'title' => elgg_echo('comment:this'),
- 'link_class' => "elgg-toggler",
+ 'link_rel' => 'toggle',
'priority' => 50,
);
$return[] = ElggMenuItem::factory($options);
diff --git a/js/lib/ui.js b/js/lib/ui.js
index 89a996122..fd20acbd1 100644
--- a/js/lib/ui.js
+++ b/js/lib/ui.js
@@ -11,7 +11,7 @@ elgg.ui.init = function () {
$('.elgg-system-messages li').animate({opacity: 0.9}, 6000);
$('.elgg-system-messages li').fadeOut('slow');
- $('.elgg-toggler').live('click', elgg.ui.toggles);
+ $('[rel=toggle]').live('click', elgg.ui.toggles);
$('[rel=popup]').live('click', elgg.ui.popsUp);
@@ -27,8 +27,8 @@ elgg.ui.init = function () {
/**
* Toggles an element based on clicking a separate element
*
- * Use .elgg-toggler on the toggler element
- * Set the href to target the item you want to toggle ()
+ * Use rel="toggle" on the toggler element
+ * Set the href to target the item you want to toggle ()
*
* @param {Object} event
* @return void
diff --git a/mod/groups/start.php b/mod/groups/start.php
index f35c058b6..57c40af5d 100644
--- a/mod/groups/start.php
+++ b/mod/groups/start.php
@@ -764,7 +764,7 @@ function discussion_owner_block_menu($hook, $type, $return, $params) {
* Add the reply button for the river
*/
function discussion_add_to_river_menu($hook, $type, $return, $params) {
- if (elgg_is_logged_in() && !elgg_get_context('widgets')) {
+ if (elgg_is_logged_in() && !elgg_in_context('widgets')) {
$item = $params['item'];
$object = $item->getObjectEntity();
if (elgg_instanceof($object, 'object', 'groupforumtopic')) {
@@ -776,7 +776,7 @@ function discussion_add_to_river_menu($hook, $type, $return, $params) {
'href' => "#groups-reply-$object->guid",
'text' => elgg_view_icon('speech-bubble'),
'title' => elgg_echo('reply:this'),
- 'link_class' => "elgg-toggler",
+ 'link_rel' => 'toggle',
'priority' => 50,
);
$return[] = ElggMenuItem::factory($options);
diff --git a/mod/logbrowser/views/default/logbrowser/form.php b/mod/logbrowser/views/default/logbrowser/form.php
index d2476afac..d5cf9f6b8 100644
--- a/mod/logbrowser/views/default/logbrowser/form.php
+++ b/mod/logbrowser/views/default/logbrowser/form.php
@@ -59,9 +59,12 @@
$toggle_link = elgg_view('output/url', array(
'href' => '#log-browser-search-form',
'text' => elgg_echo('logbrowser:search'),
- 'class' => 'elgg-toggler',
+ 'rel' => 'toggle',
));
?>
+
+
+
-
-
-
\ No newline at end of file
diff --git a/mod/profile/views/default/profile/owner_block.php b/mod/profile/views/default/profile/owner_block.php
index 48d7ff24f..5a65a3a26 100644
--- a/mod/profile/views/default/profile/owner_block.php
+++ b/mod/profile/views/default/profile/owner_block.php
@@ -35,7 +35,7 @@ if (elgg_is_admin_logged_in() && elgg_get_logged_in_user_guid() != elgg_get_page
$text = elgg_echo('admin:options');
$admin_links = '
diff --git a/views/default/object/plugin/advanced.php b/views/default/object/plugin/advanced.php
index 51fb69d17..84fc0439b 100644
--- a/views/default/object/plugin/advanced.php
+++ b/views/default/object/plugin/advanced.php
@@ -242,7 +242,7 @@ if (elgg_view_exists($settings_view_old) || elgg_view_exists($settings_view_new)
echo elgg_view('output/url', array(
'href' => "#elgg-plugin-manifest-{$plugin->getID()}",
'text' => elgg_echo("admin:plugins:label:moreinfo"),
- 'class' => 'elgg-toggler',
+ 'rel' => 'toggle',
));
?>
diff --git a/views/default/object/plugin/invalid.php b/views/default/object/plugin/invalid.php
index 9e239b7ca..f29ee8d12 100644
--- a/views/default/object/plugin/invalid.php
+++ b/views/default/object/plugin/invalid.php
@@ -29,7 +29,7 @@ $error = $plugin->getError();
echo elgg_view('output/url', array(
'href' => "#elgg-plugin-manifest-{$plugin->getID()}",
'text' => elgg_echo("admin:plugins:label:moreinfo"),
- 'class' => 'elgg-toggler',
+ 'rel' => 'toggle',
));
?>
diff --git a/views/default/object/widget/elements/controls.php b/views/default/object/widget/elements/controls.php
index 83a2f5767..abf2154fc 100644
--- a/views/default/object/widget/elements/controls.php
+++ b/views/default/object/widget/elements/controls.php
@@ -12,7 +12,8 @@ $show_edit = elgg_extract('show_edit', $vars, true);
$params = array(
'text' => ' ',
'href' => "#elgg-widget-content-$widget->guid",
- 'class' => 'elgg-widget-collapse-button elgg-toggler',
+ 'class' => 'elgg-widget-collapse-button',
+ 'rel' => 'toggle',
);
$collapse_link = elgg_view('output/url', $params);
@@ -33,7 +34,8 @@ if ($widget->canEdit()) {
'text' => elgg_view_icon('settings-alt'),
'title' => elgg_echo('widget:edit'),
'href' => "#widget-edit-$widget->guid",
- 'class' => "elgg-toggler elgg-widget-edit-button",
+ 'class' => "elgg-widget-edit-button",
+ 'rel' => 'toggle',
);
$edit_link = elgg_view('output/url', $params);
}
diff --git a/views/default/page/layouts/widgets/add_button.php b/views/default/page/layouts/widgets/add_button.php
index a8670146b..89e83b096 100644
--- a/views/default/page/layouts/widgets/add_button.php
+++ b/views/default/page/layouts/widgets/add_button.php
@@ -4,7 +4,12 @@
*/
?>
--
cgit v1.2.3
From e43d4443e6e9718433496b739f0af6630aad9e95 Mon Sep 17 00:00:00 2001
From: cash
Date: Sun, 26 Jun 2011 14:02:36 -0400
Subject: added a data array to ElggMenuItem. Now by default options end up
being passed to output/url.
---
engine/classes/ElggMenuItem.php | 273 ++++++++++++++++++++++------------------
engine/lib/navigation.php | 2 +-
mod/groups/start.php | 2 +-
3 files changed, 152 insertions(+), 125 deletions(-)
(limited to 'engine/classes')
diff --git a/engine/classes/ElggMenuItem.php b/engine/classes/ElggMenuItem.php
index 1181583f2..36c21b8b4 100644
--- a/engine/classes/ElggMenuItem.php
+++ b/engine/classes/ElggMenuItem.php
@@ -10,75 +10,62 @@
* @since 1.8.0
*/
class ElggMenuItem {
- /**
- * @var string Identifier of the menu
- */
- protected $name;
/**
- * @var string The menu display string
+ * @var array Non-rendered data about the menu item
*/
- protected $text;
+ protected $data = array(
+ // string Identifier of the menu
+ 'name' => '',
- /**
- * @var string The menu url
- */
- protected $href = null;
+ // array Page contexts this menu item should appear on
+ 'contexts' => array('all'),
- /**
- * @var string The string to display if link is clicked
- */
- protected $confirm = '';
+ // string Menu section identifier
+ 'section' => 'default',
- /**
- * @var array Classes to apply to the anchor tag.
- */
- protected $linkClass = array();
+ // int Smaller priorities float to the top
+ 'priority' => 100,
- /**
- * @var array Classes to apply to the li tag.
- */
- protected $itemClass = array();
+ // bool Is this the currently selected menu item
+ 'selected' => false,
- /**
- * @var array Page context array
- */
- protected $contexts = array('all');
+ // string Identifier of this item's parent
+ 'parent_name' => '',
- /**
- * @var string Menu section identifier
- */
- protected $section = 'default';
+ // ElggMenuItem The parent object or null
+ 'parent' => null,
- /**
- * @var string Tooltip
- */
- protected $title = '';
+ // array Array of children objects or empty array
+ 'children' => array(),
- /**
- * @var int Menu priority - smaller prioritys float to the top
- */
- protected $priority = 100;
+ // array Classes to apply to the li tag
+ 'itemClass' => array(),
+
+ // array Classes to apply to the anchor tag
+ 'linkClass' => array(),
+ );
/**
- * @var bool Is this the currently selected menu item
+ * @var string The menu display string
*/
- protected $selected = false;
+ protected $text;
/**
- * @var string Identifier of this item's parent
+ * @var string The menu url
*/
- protected $parent_name = '';
+ protected $href = null;
/**
- * @var ElggMenuItem The parent object or null
+ * @var string Tooltip
*/
- protected $parent = null;
+ protected $title = '';
/**
- * @var array Array of children objects or empty array
+ * @var string The string to display if link is clicked
*/
- protected $children = array();
+ protected $confirm = '';
+
/**
* ElggMenuItem constructor
@@ -88,13 +75,15 @@ class ElggMenuItem {
* @param string $href URL of the menu item (false if not a link)
*/
public function __construct($name, $text, $href) {
- $this->name = $name;
+ //$this->name = $name;
$this->text = $text;
if ($href) {
$this->href = elgg_normalize_url($href);
} else {
$this->href = $href;
}
+
+ $this->data['name'] = $name;
}
/**
@@ -122,6 +111,12 @@ class ElggMenuItem {
$options['contexts'] = $options['context'];
unset($options['context']);
}
+
+ // make sure contexts is set correctly
+ if (isset($options['contexts'])) {
+ $item->setContext($options['contexts']);
+ unset($options['contexts']);
+ }
if (isset($options['link_class'])) {
$item->setLinkClass($options['link_class']);
@@ -133,16 +128,62 @@ class ElggMenuItem {
unset($options['item_class']);
}
+ if (isset($options['data']) && is_array($options['data'])) {
+ $item->setData($options['data']);
+ unset($options['data']);
+ }
+
foreach ($options as $key => $value) {
- $item->$key = $value;
+ if (isset($item->data[$key])) {
+ $item->data[$key] = $value;
+ } else {
+ $item->$key = $value;
+ }
}
- // make sure contexts is set correctly
- if (isset($options['contexts'])) {
- $item->setContext($options['contexts']);
+ return $item;
+ }
+
+ /**
+ * Set a data key/value pair or a set of key/value pairs
+ *
+ * This method allows storage of arbitrary data with this menu item. The
+ * data can be used for sorting, custom rendering, or any other use.
+ *
+ * @param mixed $key String key or an associative array of key/value pairs
+ * @param mixed $value The value if $key is a string
+ * @return void
+ */
+ public function setData($key, $value = null) {
+ if (is_array($key)) {
+ $this->data += $key;
+ } else {
+ $this->data[$key] = $value;
}
+ }
- return $item;
+ /**
+ * Get stored data
+ *
+ * @param string $key The key for the requested key/value pair
+ * @return mixed
+ */
+ public function getData($key) {
+ if (isset($this->data[$key])) {
+ return $this->data[$key];
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Set the identifier of the menu item
+ *
+ * @param string Unique identifier
+ * @return void
+ */
+ public function setName($name) {
+ $this->data['name'] = $name;
}
/**
@@ -151,14 +192,13 @@ class ElggMenuItem {
* @return string
*/
public function getName() {
- return $this->name;
+ return $this->data['name'];
}
-
+
/**
* Set the display text of the menu item
*
* @param string $text The display text
- *
* @return void
*/
public function setText($text) {
@@ -177,6 +217,7 @@ class ElggMenuItem {
/**
* Set the URL of the menu item
*
+ * @param string $href URL or false if not a link
* @return void
*/
public function setHref($href) {
@@ -196,14 +237,13 @@ class ElggMenuItem {
* Set the contexts that this menu item is available for
*
* @param array $contexts An array of context strings
- *
* @return void
*/
public function setContext($contexts) {
if (is_string($contexts)) {
$contexts = array($contexts);
}
- $this->contexts = $contexts;
+ $this->data['contexts'] = $contexts;
}
/**
@@ -212,27 +252,26 @@ class ElggMenuItem {
* @return array
*/
public function getContext() {
- return $this->contexts;
+ return $this->data['contexts'];
}
/**
* Should this menu item be used given the current context
*
* @param string $context A context string (default is empty string for
- * current context stack.
- *
+ * current context stack).
* @return bool
*/
public function inContext($context = '') {
if ($context) {
- return in_array($context, $this->contexts);
+ return in_array($context, $this->data['contexts']);
}
- if (in_array('all', $this->contexts)) {
+ if (in_array('all', $this->data['contexts'])) {
return true;
}
- foreach ($this->contexts as $context) {
+ foreach ($this->data['contexts'] as $context) {
if (elgg_in_context($context)) {
return true;
}
@@ -244,11 +283,10 @@ class ElggMenuItem {
* Set the selected flag
*
* @param bool $state Selected state (default is true)
- *
* @return void
*/
public function setSelected($state = true) {
- $this->selected = $state;
+ $this->data['selected'] = $state;
}
/**
@@ -257,14 +295,13 @@ class ElggMenuItem {
* @return bool
*/
public function getSelected() {
- return $this->selected;
+ return $this->data['selected'];
}
/**
* Set the tool tip text
*
* @param string $text The text of the tool tip
- *
* @return void
*/
public function setTooltip($text) {
@@ -284,7 +321,6 @@ class ElggMenuItem {
* Set the confirm text shown when link is clicked
*
* @param string $text The text to show
- *
* @return void
*/
public function setConfirmText($text) {
@@ -304,14 +340,13 @@ class ElggMenuItem {
* Set the anchor class
*
* @param mixed $class An array of class names, or a single string class name.
- *
* @return void
*/
public function setLinkClass($class) {
if (!is_array($class)) {
- $this->linkClass[] = $class;
+ $this->data['linkClass'] = array($class);
} else {
- $this->linkClass = $class;
+ $this->data['linkClass'] = $class;
}
}
@@ -321,21 +356,34 @@ class ElggMenuItem {
* @return string
*/
public function getLinkClass() {
- return implode(' ', $this->linkClass);
+ return implode(' ', $this->data['linkClass']);
}
/**
- * Set the li classes
+ * Add a link class
*
* @param mixed $class An array of class names, or a single string class name.
+ * @return void
+ */
+ public function addLinkClass($class) {
+ if (!is_array($class)) {
+ $this->data['linkClass'][] = $class;
+ } else {
+ $this->data['linkClass'] += $class;
+ }
+ }
+
+ /**
+ * Set the li classes
*
+ * @param mixed $class An array of class names, or a single string class name.
* @return void
*/
public function setItemClass($class) {
if (!is_array($class)) {
- $this->itemClass[] = $class;
+ $this->data['itemClass'] = array($class);
} else {
- $this->itemClass = $class;
+ $this->data['itemClass'] = $class;
}
}
@@ -345,11 +393,11 @@ class ElggMenuItem {
* @return string
*/
public function getItemClass() {
- //allow people to specify name with underscores and colons
+ // allow people to specify name with underscores and colons
$name = str_replace('_', '-', $this->getName());
$name = str_replace(':', '-', $name);
- $class = implode(' ', $this->itemClass);
+ $class = implode(' ', $this->data['itemClass']);
if ($class) {
return "elgg-menu-item-$name $class";
} else {
@@ -361,11 +409,10 @@ class ElggMenuItem {
* Set the priority of the menu item
*
* @param int $priority The smaller numbers mean higher priority (1 before 100)
- *
* @return void
*/
public function setWeight($priority) {
- $this->priority = $priority;
+ $this->data['priority'] = $priority;
}
/**
@@ -374,18 +421,17 @@ class ElggMenuItem {
* @return int
*/
public function getWeight() {
- return $this->priority;
+ return $this->data['priority'];
}
/**
* Set the section identifier
*
* @param string $section The identifier of the section
- *
* @return void
*/
public function setSection($section) {
- $this->section = $section;
+ $this->data['section'] = $section;
}
/**
@@ -394,18 +440,17 @@ class ElggMenuItem {
* @return string
*/
public function getSection() {
- return $this->section;
+ return $this->data['section'];
}
/**
* Set the parent identifier
*
- * @param string $parent_name The identifier of the parent ElggMenuItem
- *
+ * @param string $name The identifier of the parent ElggMenuItem
* @return void
*/
- public function setParentName($parent_name) {
- $this->parent_name = $parent_name;
+ public function setParentName($name) {
+ $this->data['parent_name'] = $name;
}
/**
@@ -414,18 +459,17 @@ class ElggMenuItem {
* @return string
*/
public function getParentName() {
- return $this->parent_name;
+ return $this->data['parent_name'];
}
/**
* Set the parent menu item
*
* @param ElggMenuItem $parent
- *
* @return void
*/
public function setParent($parent) {
- $this->parent = $parent;
+ $this->data['parent'] = $parent;
}
/**
@@ -434,29 +478,27 @@ class ElggMenuItem {
* @return ElggMenuItem or null
*/
public function getParent() {
- return $this->parent;
+ return $this->data['parent'];
}
/**
* Add a child menu item
*
* @param ElggMenuItem $item
- *
* @return void
*/
public function addChild($item) {
- $this->children[] = $item;
+ $this->data['children'][] = $item;
}
/**
* Set the menu item's children
*
* @param array $children Array of ElggMenuItems
- *
* @return void
*/
public function setChildren($children) {
- $this->children = $children;
+ $this->data['children'] = $children;
}
/**
@@ -465,25 +507,23 @@ class ElggMenuItem {
* @return array
*/
public function getChildren() {
- return $this->children;
+ return $this->data['children'];
}
/**
* Sort the children
*
- * @param string $sort_function
- *
+ * @param string $sortFunction A function that is passed to usort()
* @return void
*/
- public function sortChildren($sort_function) {
- usort($this->children, $sort_function);
+ public function sortChildren($sortFunction) {
+ usort($this->data['children'], $sortFunction);
}
/**
* Get the menu item content (usually a link)
*
* @params array $vars Options to pass to output/url if a link
- *
* @return string
*
* @todo View code in a model. How do we feel about that?
@@ -494,30 +534,17 @@ class ElggMenuItem {
return $this->text;
}
- $vars['text'] = $this->text;
+ $defaults = get_object_vars($this);
+ unset($defaults['data']);
- if ($this->href) {
- $vars['href'] = $this->href;
- }
+ $vars += $defaults;
- if ($this->linkClass) {
- $vars['class'] = $this->getLinkClass();
- }
-
- if ($this->link_rel) {
- $vars['rel'] = $this->link_rel;
- }
-
- if ($this->rel) {
- $vars['rel'] = $this->rel;
- }
-
- if ($this->title) {
- $vars['title'] = $this->title;
- }
-
- if ($this->is_action) {
- $vars['is_action'] = $this->is_action;
+ if ($this->data['linkClass']) {
+ if (isset($vars['class'])) {
+ $vars['class'] += $this->getLinkClass();
+ } else {
+ $vars['class'] = $this->getLinkClass();
+ }
}
if ($this->confirm) {
diff --git a/engine/lib/navigation.php b/engine/lib/navigation.php
index 4b2c998a2..48a3659f6 100644
--- a/engine/lib/navigation.php
+++ b/engine/lib/navigation.php
@@ -276,7 +276,7 @@ function elgg_river_menu_setup($hook, $type, $return, $params) {
'href' => "#comments-add-$object->guid",
'text' => elgg_view_icon('speech-bubble'),
'title' => elgg_echo('comment:this'),
- 'link_rel' => 'toggle',
+ 'rel' => 'toggle',
'priority' => 50,
);
$return[] = ElggMenuItem::factory($options);
diff --git a/mod/groups/start.php b/mod/groups/start.php
index 57c40af5d..83353bae5 100644
--- a/mod/groups/start.php
+++ b/mod/groups/start.php
@@ -776,7 +776,7 @@ function discussion_add_to_river_menu($hook, $type, $return, $params) {
'href' => "#groups-reply-$object->guid",
'text' => elgg_view_icon('speech-bubble'),
'title' => elgg_echo('reply:this'),
- 'link_rel' => 'toggle',
+ 'rel' => 'toggle',
'priority' => 50,
);
$return[] = ElggMenuItem::factory($options);
--
cgit v1.2.3
From 8526e7d2d081dc516710864c79561abf974d8feb Mon Sep 17 00:00:00 2001
From: cash
Date: Wed, 29 Jun 2011 20:38:11 -0400
Subject: handling spaces and uppercase characters when creating menu item
classes
---
engine/classes/ElggMenuItem.php | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
(limited to 'engine/classes')
diff --git a/engine/classes/ElggMenuItem.php b/engine/classes/ElggMenuItem.php
index 36c21b8b4..cfdc2f5fa 100644
--- a/engine/classes/ElggMenuItem.php
+++ b/engine/classes/ElggMenuItem.php
@@ -394,8 +394,10 @@ class ElggMenuItem {
*/
public function getItemClass() {
// allow people to specify name with underscores and colons
- $name = str_replace('_', '-', $this->getName());
+ $name = strtolower($this->getName());
+ $name = str_replace('_', '-', $name);
$name = str_replace(':', '-', $name);
+ $name = str_replace(' ', '-', $name);
$class = implode(' ', $this->data['itemClass']);
if ($class) {
--
cgit v1.2.3
From c4a53af23533d44383a87b5180b15e1a01a0e18a Mon Sep 17 00:00:00 2001
From: cash
Date: Sat, 2 Jul 2011 12:07:27 -0400
Subject: added logging to the web page footer
---
engine/classes/ElggPlugin.php | 10 ++---
mod/developers/actions/developers/settings.php | 3 ++
mod/developers/classes/ElggLogCache.php | 43 ++++++++++++++++++++++
mod/developers/languages/en.php | 5 +++
mod/developers/start.php | 8 ++++
.../views/default/admin/developers/settings.php | 7 ++++
mod/developers/views/default/developers/css.php | 6 +++
mod/developers/views/default/developers/log.php | 16 ++++++++
8 files changed, 93 insertions(+), 5 deletions(-)
create mode 100644 mod/developers/classes/ElggLogCache.php
create mode 100644 mod/developers/views/default/developers/log.php
(limited to 'engine/classes')
diff --git a/engine/classes/ElggPlugin.php b/engine/classes/ElggPlugin.php
index 95a7362e2..e46ac4273 100644
--- a/engine/classes/ElggPlugin.php
+++ b/engine/classes/ElggPlugin.php
@@ -700,6 +700,11 @@ class ElggPlugin extends ElggObject {
// return false;
// }
+ // include classes
+ if ($flags & ELGG_PLUGIN_REGISTER_CLASSES) {
+ $this->registerClasses();
+ }
+
// include start file
if ($flags & ELGG_PLUGIN_INCLUDE_START) {
$this->includeFile('start.php');
@@ -715,11 +720,6 @@ class ElggPlugin extends ElggObject {
$this->registerLanguages();
}
- // include classes
- if ($flags & ELGG_PLUGIN_REGISTER_CLASSES) {
- $this->registerClasses();
- }
-
return true;
}
diff --git a/mod/developers/actions/developers/settings.php b/mod/developers/actions/developers/settings.php
index d8be34866..9fa96fa91 100644
--- a/mod/developers/actions/developers/settings.php
+++ b/mod/developers/actions/developers/settings.php
@@ -18,6 +18,7 @@ if (get_input('view_path_cache')) {
}
elgg_set_plugin_setting('display_errors', get_input('display_errors'), 'developers');
+elgg_set_plugin_setting('screen_log', get_input('screen_log'), 'developers');
$debug = get_input('debug_level');
if ($debug) {
@@ -26,4 +27,6 @@ if ($debug) {
unset_config('debug', $site->getGUID());
}
+system_message(elgg_echo('developers:settings:success'));
+
forward(REFERER);
diff --git a/mod/developers/classes/ElggLogCache.php b/mod/developers/classes/ElggLogCache.php
new file mode 100644
index 000000000..19df598d7
--- /dev/null
+++ b/mod/developers/classes/ElggLogCache.php
@@ -0,0 +1,43 @@
+cache = array();
+ }
+
+ /**
+ * Insert into cache
+ *
+ * @param mixed $data The log data to cache
+ */
+ public function insert($data) {
+ $this->cache[] = $data;
+ }
+
+ /**
+ * Insert into cache from plugin hook
+ *
+ * @param string $hook
+ * @param string $type
+ * @param bool $result
+ * @param array $params Must have the data at $params['msg']
+ */
+ public function insertDump($hook, $type, $result, $params) {
+ $this->insert($params['msg']);
+ }
+
+ /**
+ * Get the cache
+ *
+ * @return array
+ */
+ public function get() {
+ return $this->cache;
+ }
+}
diff --git a/mod/developers/languages/en.php b/mod/developers/languages/en.php
index dc763765c..053eed04f 100644
--- a/mod/developers/languages/en.php
+++ b/mod/developers/languages/en.php
@@ -21,6 +21,8 @@ $english = array(
'developers:help:debug_level' => "This controls the amount of information logged. See elgg_log() for more information.",
'developers:label:display_errors' => 'Display fatal PHP errors',
'developers:help:display_errors' => "By default, Elgg's .htaccess file supresses the display of fatal errors.",
+ 'developers:label:screen_log' => "Log to the screen",
+ 'developers:help:screen_log' => "This displays elgg_log() and elgg_dump() output on the web page.",
'developers:debug:off' => 'Off',
'developers:debug:error' => 'Error',
@@ -41,6 +43,9 @@ $english = array(
'theme_preview:modules' => 'Modules',
'theme_preview:navigation' => 'Navigation',
'theme_preview:typography' => 'Typography',
+
+ // status messages
+ 'developers:settings:success' => 'Settings saved',
);
add_translation('en', $english);
diff --git a/mod/developers/start.php b/mod/developers/start.php
index a53b7eec4..23b82d9db 100644
--- a/mod/developers/start.php
+++ b/mod/developers/start.php
@@ -12,6 +12,7 @@ function developers_init() {
elgg_register_event_handler('pagesetup', 'system', 'developers_setup_menu');
elgg_extend_view('css/admin', 'developers/css');
+ elgg_extend_view('css/elgg', 'developers/css');
elgg_register_page_handler('theme_preview', 'developers_theme_preview_controller');
@@ -32,6 +33,13 @@ function developers_process_settings() {
} else {
ini_set('display_errors', 0);
}
+
+ if (elgg_get_plugin_setting('screen_log', 'developers') == 1) {
+ $cache = new ElggLogCache();
+ elgg_set_config('log_cache', $cache);
+ elgg_register_plugin_hook_handler('debug', 'log', array($cache, 'insertDump'));
+ elgg_extend_view('page/elements/foot', 'developers/log');
+ }
}
function developers_setup_menu() {
diff --git a/mod/developers/views/default/admin/developers/settings.php b/mod/developers/views/default/admin/developers/settings.php
index 705ad00c6..3843c2c30 100644
--- a/mod/developers/views/default/admin/developers/settings.php
+++ b/mod/developers/views/default/admin/developers/settings.php
@@ -8,6 +8,7 @@ $sections = array(
'view_path_cache' => 'checkbox',
'display_errors' => 'checkbox',
'debug_level' => 'pulldown',
+ 'screen_log' => 'checkbox',
);
$data = array(
@@ -39,6 +40,12 @@ $data = array(
'NOTICE' => elgg_echo('developers:debug:notice'),
),
),
+
+ 'screen_log' => array(
+ 'type' => 'checkbox',
+ 'value' => 1,
+ 'checked' => elgg_get_plugin_setting('screen_log', 'developers') == 1,
+ ),
);
$form_vars = array('id' => 'developer-settings-form');
diff --git a/mod/developers/views/default/developers/css.php b/mod/developers/views/default/developers/css.php
index 3aa226d0a..4690945a9 100644
--- a/mod/developers/views/default/developers/css.php
+++ b/mod/developers/views/default/developers/css.php
@@ -15,3 +15,9 @@
.elgg-page .jstree-default.jstree-focused {
background-color: transparent;
}
+.developers-log {
+ background-color: #EBF5FF;
+ border: 1px solid #999;
+ color: #666;
+ padding: 20px;
+}
diff --git a/mod/developers/views/default/developers/log.php b/mod/developers/views/default/developers/log.php
new file mode 100644
index 000000000..eca2b4b67
--- /dev/null
+++ b/mod/developers/views/default/developers/log.php
@@ -0,0 +1,16 @@
+get();
+
+echo '';
+foreach ($items as $item) {
+ echo '
';
+ print_r($item);
+ echo '
';
+}
+
+echo '
';
\ No newline at end of file
--
cgit v1.2.3
From d2c9e39308cfd64ca8a6487aac8e0d44a4e406c9 Mon Sep 17 00:00:00 2001
From: Cash Costello
Date: Sun, 3 Jul 2011 07:45:06 -0400
Subject: Fixes #3656 updates the AccessArray interface methods for ElggCache
---
engine/classes/ElggCache.php | 37 +++++++++++++++++++------------------
1 file changed, 19 insertions(+), 18 deletions(-)
(limited to 'engine/classes')
diff --git a/engine/classes/ElggCache.php b/engine/classes/ElggCache.php
index 2e697e0bb..5c2cafcb7 100644
--- a/engine/classes/ElggCache.php
+++ b/engine/classes/ElggCache.php
@@ -6,9 +6,7 @@
* @package Elgg.Core
* @subpackage Cache
*/
-abstract class ElggCache implements
- // Override for array access
- ArrayAccess {
+abstract class ElggCache implements ArrayAccess {
/**
* Variables for the cache object.
*
@@ -141,6 +139,9 @@ abstract class ElggCache implements
/**
* Load data from the cache using a given key.
*
+ * @todo $offset is a horrible variable name because it creates confusion
+ * with the ArrayAccess methods
+ *
* @param string $key Name
* @param int $offset Offset
* @param int $limit Limit
@@ -186,12 +187,12 @@ abstract class ElggCache implements
// ARRAY ACCESS INTERFACE //////////////////////////////////////////////////////////
/**
- * Set offset
+ * Assigns a value for the specified key
*
* @see ArrayAccess::offsetSet()
*
- * @param mixed $key Name
- * @param mixed $value Value
+ * @param mixed $key The key (offset) to assign the value to.
+ * @param mixed $value The value to set.
*
* @return void
*/
@@ -200,43 +201,43 @@ abstract class ElggCache implements
}
/**
- * Get offset
+ * Get the value for specified key
*
* @see ArrayAccess::offsetGet()
*
- * @param mixed $key Name
+ * @param mixed $offset The key (offset) to retrieve.
*
- * @return void
+ * @return mixed
*/
function offsetGet($key) {
return $this->load($key);
}
/**
- * Unsets offset
+ * Unsets a key.
*
* @see ArrayAccess::offsetUnset()
*
- * @param mixed $key Name
+ * @param mixed $key The key (offset) to unset.
*
* @return void
*/
function offsetUnset($key) {
- if (isset($this->key)) {
- unset($this->key);
+ if (isset($this->$key)) {
+ unset($this->$key);
}
}
/**
- * Does offset exist
+ * Does key exist
*
* @see ArrayAccess::offsetExists()
*
- * @param mixed $offset Offset
+ * @param mixed $key A key (offset) to check for.
*
- * @return void
+ * @return bool
*/
- function offsetExists($offset) {
- return isset($this->$offset);
+ function offsetExists($key) {
+ return isset($this->$key);
}
}
--
cgit v1.2.3
From 79e1f34a9ab3bc501f2c68c6bec64d270830ad42 Mon Sep 17 00:00:00 2001
From: cash
Date: Sun, 3 Jul 2011 09:24:07 -0400
Subject: Fixes #3650 deprecated ElggUser::getCollections()
---
engine/classes/ElggUser.php | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'engine/classes')
diff --git a/engine/classes/ElggUser.php b/engine/classes/ElggUser.php
index 1af4cdc3a..75ac008f6 100644
--- a/engine/classes/ElggUser.php
+++ b/engine/classes/ElggUser.php
@@ -484,7 +484,8 @@ class ElggUser extends ElggEntity
* @return array|false
*/
public function getCollections($subtype = "", $limit = 10, $offset = 0) {
- return get_user_collections($this->getGUID(), $subtype, $limit, $offset);
+ elgg_deprecated_notice("ElggUser::getCollections() has been deprecated", 1.8);
+ return false;
}
/**
--
cgit v1.2.3
From b4f9682d2dae28db4ee183909be3ae439be2a858 Mon Sep 17 00:00:00 2001
From: Cash Costello
Date: Wed, 6 Jul 2011 07:51:51 -0400
Subject: Fixes #2204 standardized the hooks/overrides for plugin settings and
usersettings
---
actions/plugins/settings/save.php | 4 ++--
actions/plugins/usersettings/save.php | 4 ++--
engine/classes/ElggPlugin.php | 13 +++++++------
3 files changed, 11 insertions(+), 10 deletions(-)
(limited to 'engine/classes')
diff --git a/actions/plugins/settings/save.php b/actions/plugins/settings/save.php
index 3b5694039..e94127f7c 100644
--- a/actions/plugins/settings/save.php
+++ b/actions/plugins/settings/save.php
@@ -26,8 +26,8 @@ $plugin_name = $plugin->getManifest()->getName();
$result = false;
// allow a plugin to override the save action for their settings
-if (elgg_action_exists("settings/$plugin_id/save")) {
- action("settings/$plugin_id/save");
+if (elgg_action_exists("$plugin_id/settings/save")) {
+ action("$plugin_id/settings/save");
} else {
foreach ($params as $k => $v) {
$result = $plugin->setSetting($k, $v);
diff --git a/actions/plugins/usersettings/save.php b/actions/plugins/usersettings/save.php
index c6214f68d..71ad2ad7b 100644
--- a/actions/plugins/usersettings/save.php
+++ b/actions/plugins/usersettings/save.php
@@ -39,8 +39,8 @@ if (!$user->canEdit()) {
$result = false;
-if (elgg_action_exists("usersettings/$plugin_id/save")) {
- action("usersettings/$plugin_id/save");
+if (elgg_action_exists("$plugin_id/usersettings/save")) {
+ action("$plugin_id/usersettings/save");
} else {
foreach ($params as $k => $v) {
// Save
diff --git a/engine/classes/ElggPlugin.php b/engine/classes/ElggPlugin.php
index e46ac4273..d837431fc 100644
--- a/engine/classes/ElggPlugin.php
+++ b/engine/classes/ElggPlugin.php
@@ -315,9 +315,9 @@ class ElggPlugin extends ElggObject {
return false;
}
// Hook to validate setting
- $value = elgg_trigger_plugin_hook('plugin:setting', 'plugin', array(
- 'plugin' => $this->pluginID,
- 'plugin_object' => $this,
+ $value = elgg_trigger_plugin_hook('setting', 'plugin', array(
+ 'plugin_id' => $this->pluginID,
+ 'plugin' => $this,
'name' => $name,
'value' => $value
), $value);
@@ -454,10 +454,11 @@ class ElggPlugin extends ElggObject {
}
// Hook to validate setting
- // note this doesn't pass the namespaced name!
- $value = elgg_trigger_plugin_hook('plugin:usersetting', 'user', array(
+ // note: this doesn't pass the namespaced name
+ $value = elgg_trigger_plugin_hook('usersetting', 'plugin', array(
'user' => $user,
- 'plugin' => $this->getID(),
+ 'plugin' => $this,
+ 'plugin_id' => $this->getID(),
'name' => $name,
'value' => $value
), $value);
--
cgit v1.2.3
From 58ba957e4a3d99e3dde0be9214cc23f581f83cc1 Mon Sep 17 00:00:00 2001
From: Brett Profitt
Date: Wed, 27 Jul 2011 15:31:31 -0700
Subject: Fixed some documentation.
---
engine/classes/ElggBatch.php | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
(limited to 'engine/classes')
diff --git a/engine/classes/ElggBatch.php b/engine/classes/ElggBatch.php
index 49aed800a..62128e34f 100644
--- a/engine/classes/ElggBatch.php
+++ b/engine/classes/ElggBatch.php
@@ -6,7 +6,7 @@
* This is usually used with elgg_get_entities() and friends, elgg_get_annotations()
* and elgg_get_metadata().
*
- * If pass a valid PHP callback, all results will be run through that callback.
+ * If you pass a valid PHP callback, all results will be run through that callback.
* You can still foreach() through the result set after. Valid PHP callbacks
* can be a string, an array, or a closure.
* {@link http://php.net/manual/en/language.pseudo-types.php}
@@ -14,10 +14,10 @@
* The callback function must accept 3 arguments: an entity, the getter used, and the options used.
*
* Results from the callback are stored in callbackResult.
- * If the callback returns only booleans callbackResults will be the combined
+ * If the callback returns only booleans, callbackResults will be the combined
* result of all calls.
*
- * If the callback returns anything else callbackresult will be an indexed array
+ * If the callback returns anything else, callbackresult will be an indexed array
* of whatever the callback returns. If returning error handling information,
* you should include enough information to determine which result you're referring
* to.
@@ -90,7 +90,7 @@ class ElggBatch
private $offset = 0;
/**
- * Stop of this many results.
+ * Stop after this many results.
*
* @var unknown_type
*/
@@ -333,7 +333,7 @@ class ElggBatch
$result = current($this->results);
} else {
- // the function above resets the indexes, so don't only inc if not
+ // the function above resets the indexes, so only inc if not
// getting new set
$this->resultIndex++;
$result = next($this->results);
--
cgit v1.2.3
From 8a2559a63b5eb09dbd736161247bc103c2c4d18a Mon Sep 17 00:00:00 2001
From: Brett Profitt
Date: Mon, 15 Aug 2011 20:52:43 -0700
Subject: Refs #3355. Added ElggPriorityList.
---
engine/classes/ElggPriorityList.php | 306 ++++++++++++++++++++++++++++++++++++
engine/tests/api/helpers.php | 256 +++++++++++++++++++++++++++++-
2 files changed, 561 insertions(+), 1 deletion(-)
create mode 100644 engine/classes/ElggPriorityList.php
(limited to 'engine/classes')
diff --git a/engine/classes/ElggPriorityList.php b/engine/classes/ElggPriorityList.php
new file mode 100644
index 000000000..39fe698da
--- /dev/null
+++ b/engine/classes/ElggPriorityList.php
@@ -0,0 +1,306 @@
+add('Element 0');
+ * $pl->add('Element -5', -5);
+ * $pl->add('Element 10', 10);
+ * $pl->add('Element -10', -10);
+ *
+ * $pl->remove('Element -5');
+ *
+ * $elements = $pl->getElements();
+ * var_dump($elements);
+ *
+ * Yields:
+ *
+ * array(
+ * -10 => 'Element -10',
+ * 0 => 'Element 0',
+ * 10 => 'Element 10',
+ * )
+ *
+ *
+ * // Array
+ * $pl = new ElggPriorityList();
+ * $pl[] = 'Element 0';
+ * $pl[-5] = 'Element -5';
+ * $pl[10] = 'Element 10';
+ * $pl[-10] = 'Element -10';
+ *
+ * $priority = $pl->getPriority('Element -5');
+ * unset($pl[$priority]);
+ *
+ * foreach ($pl as $priority => $element) {
+ * var_dump("$priority => $element");
+ * }
+ *
+ * Yields:
+ * -10 => Element -10
+ * 0 => Element 0
+ * 10 => Element 10
+ *
+ *
+ * Collisions with priority are handled by inserting the element as close to the requested priority
+ * as possible.
+ *
+ * $pl = new ElggPriorityList();
+ * $pl[5] = 'Element 5';
+ * $pl[5] = 'Colliding element 5';
+ * $pl[5] = 'Another colliding element 5';
+ *
+ * var_dump($pl->getElements());
+ *
+ * Yields:
+ *
+ * array(
+ * 5 => 'Element 5',
+ * 6 => 'Colliding element 5',
+ * 7 => 'Another colliding element 5'
+ * )
+ *
+ * @package Elgg.Core
+ * @subpackage Helpers
+ */
+
+class ElggPriorityList
+ implements Iterator, ArrayAccess, Countable {
+
+ /**
+ * The list of elements
+ *
+ * @var array
+ */
+ private $elements = array();
+
+ /**
+ * Create a new priority list.
+ *
+ * @param array $elements An optional array of priorities => element
+ */
+ public function __construct(array $elements = array()) {
+ if ($elements) {
+ foreach ($elements as $priority => $element) {
+ $this->add($element, $priority);
+ }
+ }
+ }
+
+ /**
+ * Adds an element to the list.
+ *
+ * @warning This returns the priority at which the element was added, which can be 0. Use
+ * !== false to check for success.
+ *
+ * @param mixed $element The element to add to the list.
+ * @param mixed $priority Priority to add the element. In priority collisions, the original element
+ * maintains its priority and the new element is to the next available
+ * slot, taking into consideration all previously registered elements.
+ * Negative elements are accepted.
+ * @return int The priority the element was added at.
+ */
+ public function add($element, $priority = null) {
+ if ($priority !== null && !is_numeric($priority)) {
+ return false;
+ } else {
+ $priority = $this->getNextPriority($priority);
+ }
+
+ $this->elements[$priority] = $element;
+ return $priority;
+ }
+
+ /**
+ * Removes an element from the list.
+ *
+ * @warning The element must have the same attributes / values. If using $strict, it must have
+ * the same types. array(10) will fail in strict against array('10') (str vs int).
+ *
+ * @param type $element
+ * @return bool
+ */
+ public function remove($element, $strict = false) {
+ $index = array_search($element, $this->elements, $strict);
+ if ($index !== false) {
+ unset($this->elements[$index]);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Returns the elements
+ *
+ * @param type $elements
+ * @param type $sort
+ */
+ public function getElements() {
+ $this->sortIfUnsorted();
+ return $this->elements;
+ }
+
+ /**
+ * Sort the elements optionally by a callback function.
+ *
+ * If no user function is provided the elements are sorted by priority registered.
+ *
+ * The callback function should accept the array of elements as the first argument and should
+ * return a sorted array.
+ *
+ * This function can be called multiple times.
+ *
+ * @param type $callback
+ * @return bool
+ */
+ public function sort($callback = null) {
+ if (!$callback) {
+ ksort($this->elements, SORT_NUMERIC);
+ } else {
+ $sorted = call_user_func($callback, $this->elements);
+
+ if (!$sorted) {
+ return false;
+ }
+
+ $this->elements = $sorted;
+ }
+
+ $this->sorted = true;
+ return true;
+ }
+
+ /**
+ * Sort the elements if they haven't been sorted yet.
+ *
+ * @return bool
+ */
+ private function sortIfUnsorted() {
+ if (!$this->sorted) {
+ return $this->sort();
+ }
+ }
+
+ /**
+ * Returns the next priority available.
+ *
+ * @param int $near Make the priority as close to $near as possible.
+ * @return int
+ */
+ public function getNextPriority($near = 0) {
+ $near = (int) $near;
+
+ while (array_key_exists($near, $this->elements)) {
+ $near++;
+ }
+
+ return $near;
+ }
+
+
+ /**
+ * Returns the priority of an element if it exists in the list.
+ *
+ * @warning This can return 0 if the element's priority is 0. Use identical operator (===) to
+ * check for false if you want to know if an element exists.
+ *
+ * @param mixed $element
+ * @return mixed False if the element doesn't exists, the priority if it does.
+ */
+ public function getPriority($element, $strict = false) {
+ return array_search($element, $this->elements, $strict);
+ }
+
+ /**********************
+ * Interfaces methods *
+ **********************/
+
+
+ /**
+ * Iterator
+ */
+
+ /**
+ * PHP Iterator Interface
+ *
+ * @see Iterator::rewind()
+ * @return void
+ */
+ public function rewind() {
+ $this->sortIfUnsorted();
+ return rewind($this->elements);
+ }
+
+ /**
+ * PHP Iterator Interface
+ *
+ * @see Iterator::current()
+ * @return mixed
+ */
+ public function current() {
+ $this->sortIfUnsorted();
+ return current($this->elements);
+ }
+
+ /**
+ * PHP Iterator Interface
+ *
+ * @see Iterator::key()
+ * @return int
+ */
+ public function key() {
+ $this->sortIfUnsorted();
+ return key($this->elements);
+ }
+
+ /**
+ * PHP Iterator Interface
+ *
+ * @see Iterator::next()
+ * @return mixed
+ */
+ public function next() {
+ $this->sortIfUnsorted();
+ return next($this->elements);
+ }
+
+ /**
+ * PHP Iterator Interface
+ *
+ * @see Iterator::valid()
+ * @return bool
+ */
+ public function valid() {
+ $this->sortIfUnsorted();
+ $key = key($this->elements);
+ return ($key !== NULL && $key !== FALSE);
+ }
+
+ // Coutable
+ public function count() {
+ return count($this->elements);
+ }
+
+ // ArrayAccess
+ public function offsetExists($offset) {
+ return isset($this->elements[$offset]);
+ }
+
+ public function offsetGet($offset) {
+ return isset($this->elements[$offset]) ? $this->elements[$offset] : null;
+ }
+
+ public function offsetSet($offset, $value) {
+ return $this->add($value, $offset);
+ }
+
+ public function offsetUnset($offset) {
+ if (isset($this->elements[$offset])) {
+ unset($this->elements[$offset]);
+ }
+ }
+}
\ No newline at end of file
diff --git a/engine/tests/api/helpers.php b/engine/tests/api/helpers.php
index 461627547..033970359 100644
--- a/engine/tests/api/helpers.php
+++ b/engine/tests/api/helpers.php
@@ -187,4 +187,258 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
$js_urls = elgg_get_loaded_js('footer');
$this->assertIdentical(array(), $js_urls);
}
-}
+
+ // test ElggPriorityList
+ public function testElggPriorityListAdd() {
+ $pl = new ElggPriorityList();
+ $elements = array(
+ 'Test value',
+ 'Test value 2',
+ 'Test value 3'
+ );
+
+ shuffle($elements);
+
+ foreach ($elements as $element) {
+ $this->assertTrue($pl->add($element) !== false);
+ }
+
+ $test_elements = $pl->getElements();
+
+ $this->assertTrue(is_array($test_elements));
+
+ foreach ($test_elements as $i => $element) {
+ // should be in the array
+ $this->assertTrue(in_array($element, $elements));
+
+ // should be the only element, so priority 0
+ $this->assertEqual($i, array_search($element, $elements));
+ }
+ }
+
+ public function testElggPriorityListAddWithPriority() {
+ $pl = new ElggPriorityList();
+
+ $elements = array(
+ 10 => 'Test Element 10',
+ 5 => 'Test Element 5',
+ 0 => 'Test Element 0',
+ 100 => 'Test Element 100',
+ -1 => 'Test Element -1',
+ -5 => 'Test Element -5'
+ );
+
+ foreach ($elements as $priority => $element) {
+ $pl->add($element, $priority);
+ }
+
+ $test_elements = $pl->getElements();
+
+ // should be sorted by priority
+ $elements_sorted = array(
+ -5 => 'Test Element -5',
+ -1 => 'Test Element -1',
+ 0 => 'Test Element 0',
+ 5 => 'Test Element 5',
+ 10 => 'Test Element 10',
+ 100 => 'Test Element 100',
+ );
+
+ $this->assertIdentical($elements_sorted, $test_elements);
+
+ foreach ($test_elements as $priority => $element) {
+ $this->assertIdentical($elements[$priority], $element);
+ }
+ }
+
+ public function testElggPriorityListGetNextPriority() {
+ $pl = new ElggPriorityList();
+
+ $elements = array(
+ 2 => 'Test Element',
+ 0 => 'Test Element 2',
+ -2 => 'Test Element 3',
+ );
+
+ foreach ($elements as $priority => $element) {
+ $pl->add($element, $priority);
+ }
+
+ // we're not specifying a priority so it should be the next consecutive to 0.
+ $this->assertEqual(1, $pl->getNextPriority());
+
+ // add another one at priority 1
+ $pl->add('Test Element 1');
+
+ // next consecutive to 0 is now 3.
+ $this->assertEqual(3, $pl->getNextPriority());
+ }
+
+ public function testElggPriorityListRemove() {
+ $pl = new ElggPriorityList();
+
+ $elements = array();
+ for ($i=0; $i<3; $i++) {
+ $element = new stdClass();
+ $element->name = "Test Element $i";
+ $element->someAttribute = rand(0, 9999);
+ $elements[] = $element;
+ $pl->add($element);
+ }
+
+ $pl->remove($elements[1]);
+
+ $test_elements = $pl->getElements();
+
+ // make sure it's gone.
+ $this->assertTrue(2, count($test_elements));
+ $this->assertIdentical($elements[0], $test_elements[0]);
+ $this->assertIdentical($elements[2], $test_elements[2]);
+ }
+
+ public function testElggPriorityListConstructor() {
+ $elements = array(
+ 10 => 'Test Element 10',
+ 5 => 'Test Element 5',
+ 0 => 'Test Element 0',
+ 100 => 'Test Element 100',
+ -1 => 'Test Element -1',
+ -5 => 'Test Element -5'
+ );
+
+ $pl = new ElggPriorityList($elements);
+ $test_elements = $pl->getElements();
+
+ $elements_sorted = array(
+ -5 => 'Test Element -5',
+ -1 => 'Test Element -1',
+ 0 => 'Test Element 0',
+ 5 => 'Test Element 5',
+ 10 => 'Test Element 10',
+ 100 => 'Test Element 100',
+ );
+
+ $this->assertIdentical($elements_sorted, $test_elements);
+ }
+
+ public function testElggPriorityListGetPriority() {
+ $pl = new ElggPriorityList();
+
+ $elements = array(
+ 'Test element 0',
+ 'Test element 1',
+ 'Test element 2',
+ );
+
+ foreach ($elements as $element) {
+ $pl->add($element);
+ }
+
+ $this->assertIdentical(0, $pl->getPriority($elements[0]));
+ $this->assertIdentical(1, $pl->getPriority($elements[1]));
+ $this->assertIdentical(2, $pl->getPriority($elements[2]));
+ }
+
+ public function testElggPriorityListPriorityCollision() {
+ $pl = new ElggPriorityList();
+
+ $elements = array(
+ 5 => 'Test element 5',
+ 6 => 'Test element 6',
+ 0 => 'Test element 0',
+ );
+
+ foreach ($elements as $priority => $element) {
+ $pl->add($element, $priority);
+ }
+
+ // add at a colliding priority
+ $pl->add('Colliding element', 5);
+
+ // should float to the top closest to 5, so 7
+ $this->assertEqual(7, $pl->getPriority('Colliding element'));
+ }
+
+ public function testElggPriorityListArrayAccess() {
+ $pl = new ElggPriorityList();
+ $pl[] = 'Test element 0';
+ $pl[-10] = 'Test element -10';
+ $pl[-1] = 'Test element -1';
+ $pl[] = 'Test element 1';
+ $pl[5] = 'Test element 5';
+ $pl[0] = 'Test element collision with 0 (should be 2)';
+
+ $elements = array(
+ -1 => 'Test element -1',
+ 0 => 'Test element 0',
+ 1 => 'Test element 1',
+ 2 => 'Test element collision with 0 (should be 2)',
+ 5 => 'Test element 5',
+ );
+
+ $priority = $pl->getPriority('Test element -10');
+ unset($pl[$priority]);
+
+ $test_elements = $pl->getElements();
+ $this->assertIdentical($elements, $test_elements);
+ }
+
+ public function testElggPriorityListIterator() {
+ $elements = array(
+ -5 => 'Test element -5',
+ 0 => 'Test element 0',
+ 5 => 'Test element 5'
+ );
+
+ $pl = new ElggPriorityList($elements);
+
+ foreach ($pl as $priority => $element) {
+ $this->assertIdentical($elements[$priority], $element);
+ }
+ }
+
+ public function testElggPriorityListCountable() {
+ $pl = new ElggPriorityList();
+
+ $this->assertEqual(0, count($pl));
+
+ $pl[] = 'Test element 0';
+ $this->assertEqual(1, count($pl));
+
+ $pl[] = 'Test element 1';
+ $this->assertEqual(2, count($pl));
+
+ $pl[] = 'Test element 2';
+ $this->assertEqual(3, count($pl));
+ }
+
+ public function testElggPriorityListUserSort() {
+ $elements = array(
+ 'A',
+ 'B',
+ 'C',
+ 'D',
+ 'E',
+ );
+
+ $elements_sorted_string = $elements;
+
+ shuffle($elements);
+ $pl = new ElggPriorityList($elements);
+
+ // will sort by priority
+ $test_elements = $pl->getElements();
+ $this->assertIdentical($elements, $test_elements);
+
+ function test_sort($elements) {
+ sort($elements, SORT_LOCALE_STRING);
+ return $elements;
+ }
+
+ // force a new sort using our function
+ $pl->sort('test_sort');
+ $test_elements = $pl->getElements();
+
+ $this->assertIdentical($elements_sorted_string, $test_elements);
+ }
+}
\ No newline at end of file
--
cgit v1.2.3
From 62a8253d2afbb682d73939bd68e58cf81f54e663 Mon Sep 17 00:00:00 2001
From: Brett Profitt
Date: Wed, 17 Aug 2011 18:22:13 -0700
Subject: Finished ElggPriorityList. Migrated external files to use it.
---
engine/classes/ElggPriorityList.php | 96 ++++++++++++++++++++++++++++---
engine/lib/elgglib.php | 112 ++++++++++++++++++++++++++++--------
engine/tests/api/helpers.php | 75 +++++++++++++++++++++---
3 files changed, 241 insertions(+), 42 deletions(-)
(limited to 'engine/classes')
diff --git a/engine/classes/ElggPriorityList.php b/engine/classes/ElggPriorityList.php
index 39fe698da..931138106 100644
--- a/engine/classes/ElggPriorityList.php
+++ b/engine/classes/ElggPriorityList.php
@@ -26,6 +26,7 @@
*
*
* // Array
+ *
* $pl = new ElggPriorityList();
* $pl[] = 'Element 0';
* $pl[-5] = 'Element -5';
@@ -45,24 +46,45 @@
* 10 => Element 10
*
*
- * Collisions with priority are handled by inserting the element as close to the requested priority
- * as possible.
+ * Collisions with priority are handled by default differently in the OOP and the array interfaces.
+ *
+ * If using the OOP interface, the default is to insert the element as close to the requested
+ * priority as possible.
*
* $pl = new ElggPriorityList();
- * $pl[5] = 'Element 5';
- * $pl[5] = 'Colliding element 5';
- * $pl[5] = 'Another colliding element 5';
+ * $pl->add('Element 5', 5);
+ * $pl->add('Colliding element 5', 5);
+ * $pl->add('Another colliding element 5', 5);
*
* var_dump($pl->getElements());
*
* Yields:
- *
* array(
* 5 => 'Element 5',
* 6 => 'Colliding element 5',
* 7 => 'Another colliding element 5'
* )
*
+ * If using the array interface, elements are added at exactly the priority, displacing other
+ * elements if necessary. This behavior is also available by passing true as the 3rd argument to
+ * ->add():
+ *
+ * $pl = new ElggPriorityList();
+ * $pl[5] = 'Element 5';
+ * $pl[6] = 'Element 6';
+ * $pl[5] = 'Colliding element 5'; // shifts the previous two up by one
+ * $pl->add('Another colliding element 5', 5, true); // shifts the previous three up by one
+ *
+ * var_dump($pl->getElements());
+ *
+ * Yields:
+ * array(
+ * 5 => 'Another colliding element 5',
+ * 6 => 'Colliding element 5',
+ * 7 => 'Element 5',
+ * 8 => 'Element 6'
+ * )
+ *
* @package Elgg.Core
* @subpackage Helpers
*/
@@ -101,16 +123,21 @@ class ElggPriorityList
* maintains its priority and the new element is to the next available
* slot, taking into consideration all previously registered elements.
* Negative elements are accepted.
- * @return int The priority the element was added at.
+ * @param bool $exact If true, will put the element at exactly the priority specified, displacing
+ * other elements.
+ * @return int The priority of the added element.
*/
- public function add($element, $priority = null) {
+ public function add($element, $priority = null, $exact = false) {
if ($priority !== null && !is_numeric($priority)) {
return false;
+ } elseif ($exact) {
+ $this->shiftElementsSegment($priority);
} else {
$priority = $this->getNextPriority($priority);
}
$this->elements[$priority] = $element;
+ $this->sorted = false;
return $priority;
}
@@ -133,6 +160,32 @@ class ElggPriorityList
}
}
+ /**
+ * Move an existing element to a new priority.
+ *
+ * @param int $current_priority
+ * @param int $new_priority
+ * @param bool $exact
+ * @return bool
+ */
+ public function move($current_priority, $new_priority, $exact = false) {
+ $current_priority = (int) $current_priority;
+ $new_priority = (int) $new_priority;
+
+ if (!isset($this->elements[$current_priority])) {
+ return false;
+ }
+
+ if ($current_priority == $new_priority) {
+ return true;
+ }
+
+ $element = $this->elements[$current_priority];
+ unset($this->elements[$current_priority]);
+
+ return $this->add($element, $new_priority, $exact);
+ }
+
/**
* Returns the elements
*
@@ -185,6 +238,29 @@ class ElggPriorityList
}
}
+ /**
+ * Shift a segment of elements starting at $index up by one until the end of the array or
+ * there's a gap in the indexes. This produces a space at $index to insert a new element.
+ *
+ * @param type $index The index to start
+ * @return array
+ */
+ private function shiftElementsSegment($index) {
+ $index = (int) $index;
+ // @todo probably a better way.
+ $replace_elements = array();
+ while (isset($this->elements[$index])) {
+ $replace_elements[$index + 1] = $this->elements[$index];
+ unset($this->elements[$index]);
+ $index++;
+ }
+
+ // insert old ones
+ foreach ($replace_elements as $index => $element) {
+ $this->elements[$index] = $element;
+ }
+ }
+
/**
* Returns the next priority available.
*
@@ -295,7 +371,9 @@ class ElggPriorityList
}
public function offsetSet($offset, $value) {
- return $this->add($value, $offset);
+ // for $pl[] = 'New element'
+ $exact = ($offset !== null);
+ return $this->add($value, $offset, $exact);
}
public function offsetUnset($offset) {
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php
index cb736f418..b6b603e79 100644
--- a/engine/lib/elgglib.php
+++ b/engine/lib/elgglib.php
@@ -172,7 +172,7 @@ function forward($location = "", $reason = 'system') {
* @return bool
* @since 1.8.0
*/
-function elgg_register_js($name, $url, $location = 'head', $priority = 500) {
+function elgg_register_js($name, $url, $location = 'head', $priority = null) {
return elgg_register_external_file('js', $name, $url, $location, $priority);
}
@@ -225,7 +225,7 @@ function elgg_get_loaded_js($location = 'head') {
* @return bool
* @since 1.8.0
*/
-function elgg_register_css($name, $url, $priority = 500) {
+function elgg_register_css($name, $url, $priority = null) {
return elgg_register_external_file('css', $name, $url, 'head', $priority);
}
@@ -278,7 +278,7 @@ function elgg_get_loaded_css() {
* @return bool
* @since 1.8.0
*/
-function elgg_register_external_file($type, $name, $url, $location, $priority = 500) {
+function elgg_register_external_file($type, $name, $url, $location, $priority = null) {
global $CONFIG;
if (empty($name) || empty($url)) {
@@ -292,26 +292,35 @@ function elgg_register_external_file($type, $name, $url, $location, $priority =
$CONFIG->externals = array();
}
- if (!isset($CONFIG->externals[$type])) {
- $CONFIG->externals[$type] = array();
+ if (!$CONFIG->externals[$type] instanceof ElggPriorityList) {
+ $CONFIG->externals[$type] = new ElggPriorityList();
}
$name = trim(strtolower($name));
+ $priority = max((int)$priority, 0);
- if (isset($CONFIG->externals[$type][$name])) {
- // update a registered item
- $item = $CONFIG->externals[$type][$name];
+ $index = elgg_get_external_file_priority($name, $type);
+
+ if ($index !== false) {
+ // updating a registered item
+ $item = $CONFIG->externals[$type][$index];
+ $item->url = $url;
+ $item->location = $location;
+ // remove old saved priority
+ elgg_remove_external_file_priority($name, $type);
+ $priority = $CONFIG->externals[$type]->move($index, $priority);
} else {
$item = new stdClass();
$item->loaded = false;
- }
+ $item->url = $url;
+ $item->location = $location;
- $item->url = $url;
- $item->priority = max((int)$priority, 0);
- $item->location = $location;
+ $priority = $CONFIG->externals[$type]->add($item, $priority);
+ }
- $CONFIG->externals[$type][$name] = $item;
+ // save priority map so we can update if added again
+ elgg_save_external_file_priority($priority, $name, $type);
return true;
}
@@ -332,14 +341,17 @@ function elgg_unregister_external_file($type, $name) {
return false;
}
- if (!isset($CONFIG->externals[$type])) {
+ if (!$CONFIG->externals[$type] instanceof ElggPriorityList) {
return false;
}
$name = trim(strtolower($name));
- if (array_key_exists($name, $CONFIG->externals[$type])) {
- unset($CONFIG->externals[$type][$name]);
+ $priority = elgg_get_external_file_priority($name, $type);
+
+ if ($priority !== false) {
+ elgg_remove_external_file_priority($name, $type);
+ unset($CONFIG->externals[$type][$priority]);
return true;
}
@@ -362,24 +374,75 @@ function elgg_load_external_file($type, $name) {
$CONFIG->externals = array();
}
- if (!isset($CONFIG->externals[$type])) {
- $CONFIG->externals[$type] = array();
+ if (!$CONFIG->externals[$type] instanceof ElggPriorityList) {
+ $CONFIG->externals[$type] = new ElggPriorityList();
}
$name = trim(strtolower($name));
- if (isset($CONFIG->externals[$type][$name])) {
+ $priority = elgg_get_external_file_priority($name, $type);
+
+ if ($priority !== false) {
// update a registered item
- $CONFIG->externals[$type][$name]->loaded = true;
+ $CONFIG->externals[$type][$priority]->loaded = true;
} else {
$item = new stdClass();
$item->loaded = true;
$item->url = '';
$item->location = '';
- $item->priority = 500;
- $CONFIG->externals[$type][$name] = $item;
+ $priority = $CONFIG->externals[$type]->add($item);
+ elgg_save_external_file_priority($priority, $name, $type);
+ }
+}
+
+/**
+ * Gets the priority of an external by name and type.
+ *
+ * @param type $name
+ * @param type $type
+ * @return type
+ */
+function elgg_get_external_file_priority($name, $type) {
+ global $CONFIG;
+
+ if (!isset($CONFIG->externals_priorities[$type][$name])) {
+ return false;
+ }
+
+ return $CONFIG->externals_priorities[$type][$name];
+}
+
+function elgg_save_external_file_priority($priority, $name, $type) {
+ global $CONFIG;
+
+ if (!isset($CONFIG->externals_priorities)) {
+ $CONFIG->externals_priorities = array();
+ }
+
+ if (!isset($CONFIG->externals_priorities[$type])) {
+ $CONFIG->externals_priorities[$type] = array();
+ }
+
+ $CONFIG->externals_priorities[$type][$name] = $priority;
+
+ return true;
+}
+
+function elgg_remove_external_file_priority($name, $type) {
+ global $CONFIG;
+
+ if (!isset($CONFIG->externals_priorities)) {
+ $CONFIG->externals_priorities = array();
}
+
+ if (!isset($CONFIG->externals_priorities[$type])) {
+ $CONFIG->externals_priorities[$type] = array();
+ }
+
+ unset($CONFIG->externals_priorities[$type][$name]);
+
+ return true;
}
/**
@@ -394,13 +457,12 @@ function elgg_load_external_file($type, $name) {
function elgg_get_loaded_external_files($type, $location) {
global $CONFIG;
- if (isset($CONFIG->externals) && isset($CONFIG->externals[$type])) {
- $items = array_values($CONFIG->externals[$type]);
+ if (isset($CONFIG->externals) && $CONFIG->externals[$type] instanceof ElggPriorityList) {
+ $items = $CONFIG->externals[$type]->getElements();
$callback = "return \$v->loaded == true && \$v->location == '$location';";
$items = array_filter($items, create_function('$v', $callback));
if ($items) {
- usort($items, create_function('$a,$b','return $a->priority >= $b->priority;'));
array_walk($items, create_function('&$v,$k', '$v = $v->url;'));
}
return $items;
diff --git a/engine/tests/api/helpers.php b/engine/tests/api/helpers.php
index 033970359..cceb762be 100644
--- a/engine/tests/api/helpers.php
+++ b/engine/tests/api/helpers.php
@@ -31,6 +31,7 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
global $CONFIG;
unset($CONFIG->externals);
+ unset($CONFIG->externals_priorities);
}
/**
@@ -106,7 +107,9 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
// specify name
$result = elgg_register_js('key', 'http://test1.com', 'footer');
$this->assertTrue($result);
- $this->assertIdentical('http://test1.com', $CONFIG->externals['js']['key']->url);
+ $this->assertTrue(isset($CONFIG->externals_priorities['js']['key']));
+ $index = $CONFIG->externals_priorities['js']['key'];
+ $this->assertIdentical('http://test1.com', $CONFIG->externals['js'][$index]->url);
// send a bad url
$result = @elgg_register_js('bad');
@@ -122,7 +125,9 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
// specify name
$result = elgg_register_css('key', 'http://test1.com');
$this->assertTrue($result);
- $this->assertIdentical('http://test1.com', $CONFIG->externals['css']['key']->url);
+ $this->assertTrue(isset($CONFIG->externals_priorities['css']['key']));
+ $index = elgg_get_external_file_priority('css', 'key');
+ $this->assertIdentical('http://test1.com', $CONFIG->externals['css'][$index]->url);
}
/**
@@ -140,7 +145,13 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
$result = elgg_unregister_js('id1');
$this->assertTrue($result);
- @$this->assertNULL($CONFIG->externals['js']['head']['id1']);
+
+ $js = $CONFIG->externals['js'];
+ $elements = $js->getElements();
+ $this->assertFalse(isset($CONFIG->externals_priorities['js']['id1']));
+ foreach ($elements as $element) {
+ $this->assertFalse($element->name == 'id1');
+ }
$result = elgg_unregister_js('id1');
$this->assertFalse($result);
@@ -148,7 +159,15 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
$this->assertFalse($result);
$result = elgg_unregister_js('id2');
- $this->assertIdentical($urls['id3'], $CONFIG->externals['js']['id3']->url);
+ $elements = $js->getElements();
+ $this->assertFalse(isset($CONFIG->externals_priorities['js']['id2']));
+ foreach ($elements as $element) {
+ $this->assertFalse($element->name == 'id2');
+ }
+
+ $this->assertTrue(isset($CONFIG->externals_priorities['js']['id3']));
+ $priority = $CONFIG->externals_priorities['js']['id3'];
+ $this->assertIdentical($urls['id3'], $CONFIG->externals['js'][$priority]->url);
}
/**
@@ -361,18 +380,19 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
public function testElggPriorityListArrayAccess() {
$pl = new ElggPriorityList();
+
$pl[] = 'Test element 0';
$pl[-10] = 'Test element -10';
$pl[-1] = 'Test element -1';
$pl[] = 'Test element 1';
$pl[5] = 'Test element 5';
- $pl[0] = 'Test element collision with 0 (should be 2)';
+ $pl[0] = 'Test element collision with 0';
$elements = array(
-1 => 'Test element -1',
- 0 => 'Test element 0',
- 1 => 'Test element 1',
- 2 => 'Test element collision with 0 (should be 2)',
+ 0 => 'Test element collision with 0',
+ 1 => 'Test element 0',
+ 2 => 'Test element 1',
5 => 'Test element 5',
);
@@ -441,4 +461,43 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
$this->assertIdentical($elements_sorted_string, $test_elements);
}
+
+ function testElggPriorityListShiftElementsSegment() {
+ $elements = array(
+ 0 => 'Element 0',
+ 1 => 'Element 1',
+ 2 => 'Element 2',
+ 4 => 'Element 4',
+ );
+
+ $pl = new ElggPriorityList($elements);
+
+ // add a new element directly at 1.
+ $pl->add('New Element', 1, true);
+
+ $elements_sorted = array(
+ 0 => 'Element 0',
+ 1 => 'New Element',
+ 2 => 'Element 1',
+ 3 => 'Element 2',
+ 4 => 'Element 4',
+ );
+
+ $test_elements = $pl->getElements();
+ $this->assertIdentical($elements_sorted, $test_elements);
+
+ $pl->add('New Element 10', 10, true);
+
+ $elements_sorted = array(
+ 0 => 'Element 0',
+ 1 => 'New Element',
+ 2 => 'Element 1',
+ 3 => 'Element 2',
+ 4 => 'Element 4',
+ 10 => 'New Element 10'
+ );
+
+ $test_elements = $pl->getElements();
+ $this->assertIdentical($elements_sorted, $test_elements);
+ }
}
\ No newline at end of file
--
cgit v1.2.3
From d16573be44658d40ebeb63ca3850b676eb9d309d Mon Sep 17 00:00:00 2001
From: Brett Profitt
Date: Sun, 21 Aug 2011 10:38:44 -0700
Subject: Fixes #3606. Reset password page added to public pages for walled
garden mode.
---
engine/classes/ElggSite.php | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'engine/classes')
diff --git a/engine/classes/ElggSite.php b/engine/classes/ElggSite.php
index e3b8b8f1a..40bfca060 100644
--- a/engine/classes/ElggSite.php
+++ b/engine/classes/ElggSite.php
@@ -410,8 +410,9 @@ class ElggSite extends ElggEntity {
'register',
'action/register',
'forgotpassword',
- 'action/user/requestnewpassword',
'resetpassword',
+ 'action/user/requestnewpassword',
+ 'action/user/passwordreset',
'upgrade\.php',
'xml-rpc\.php',
'mt/mt-xmlrpc\.cgi',
--
cgit v1.2.3
From 5285471b7c6f2b4ef7dc02fb2a9c231e2216eef7 Mon Sep 17 00:00:00 2001
From: Brett Profitt
Date: Tue, 23 Aug 2011 15:46:22 -0700
Subject: Fixes #3355. Added ElggPriorityList. Adapted the externals system to
use it.
---
engine/classes/ElggPriorityList.php | 218 ++++++++++++++++--------------------
engine/lib/elgglib.php | 139 ++++++++---------------
engine/lib/views.php | 29 ++---
engine/tests/api/helpers.php | 167 +++++++++++++--------------
4 files changed, 241 insertions(+), 312 deletions(-)
(limited to 'engine/classes')
diff --git a/engine/classes/ElggPriorityList.php b/engine/classes/ElggPriorityList.php
index 931138106..17ce228bc 100644
--- a/engine/classes/ElggPriorityList.php
+++ b/engine/classes/ElggPriorityList.php
@@ -2,40 +2,11 @@
/**
* Iterate over elements in a specific priority.
*
- * You can add, remove, and access elements using OOP or array interfaces:
- *
- * // OOP
* $pl = new ElggPriorityList();
* $pl->add('Element 0');
- * $pl->add('Element -5', -5);
* $pl->add('Element 10', 10);
* $pl->add('Element -10', -10);
*
- * $pl->remove('Element -5');
- *
- * $elements = $pl->getElements();
- * var_dump($elements);
- *
- * Yields:
- *
- * array(
- * -10 => 'Element -10',
- * 0 => 'Element 0',
- * 10 => 'Element 10',
- * )
- *
- *
- * // Array
- *
- * $pl = new ElggPriorityList();
- * $pl[] = 'Element 0';
- * $pl[-5] = 'Element -5';
- * $pl[10] = 'Element 10';
- * $pl[-10] = 'Element -10';
- *
- * $priority = $pl->getPriority('Element -5');
- * unset($pl[$priority]);
- *
* foreach ($pl as $priority => $element) {
* var_dump("$priority => $element");
* }
@@ -45,52 +16,84 @@
* 0 => Element 0
* 10 => Element 10
*
- *
- * Collisions with priority are handled by default differently in the OOP and the array interfaces.
- *
- * If using the OOP interface, the default is to insert the element as close to the requested
- * priority as possible.
+ * Collisions on priority are handled by inserting the element at or as close to the
+ * requested priority as possible:
*
* $pl = new ElggPriorityList();
* $pl->add('Element 5', 5);
* $pl->add('Colliding element 5', 5);
* $pl->add('Another colliding element 5', 5);
*
- * var_dump($pl->getElements());
+ * foreach ($pl as $priority => $element) {
+ * var_dump("$priority => $element");
+ * }
*
* Yields:
- * array(
* 5 => 'Element 5',
* 6 => 'Colliding element 5',
* 7 => 'Another colliding element 5'
- * )
*
- * If using the array interface, elements are added at exactly the priority, displacing other
- * elements if necessary. This behavior is also available by passing true as the 3rd argument to
- * ->add():
+ * You can do priority lookups by element:
*
* $pl = new ElggPriorityList();
- * $pl[5] = 'Element 5';
- * $pl[6] = 'Element 6';
- * $pl[5] = 'Colliding element 5'; // shifts the previous two up by one
- * $pl->add('Another colliding element 5', 5, true); // shifts the previous three up by one
+ * $pl->add('Element 0');
+ * $pl->add('Element -5', -5);
+ * $pl->add('Element 10', 10);
+ * $pl->add('Element -10', -10);
*
- * var_dump($pl->getElements());
+ * $priority = $pl->getPriority('Element -5');
+ *
+ * Or element lookups by priority.
+ * $element = $pl->getElement(-5);
*
- * Yields:
- * array(
- * 5 => 'Another colliding element 5',
- * 6 => 'Colliding element 5',
- * 7 => 'Element 5',
- * 8 => 'Element 6'
- * )
+ * To remove elements, pass the element.
+ * $pl->remove('Element -10');
+ *
+ * To check if an element exists:
+ * $pl->contains('Element -5');
+ *
+ * To move an element:
+ * $pl->move('Element -5', -3);
+ *
+ * ElggPriorityList only tracks priority. No checking is done in ElggPriorityList for duplicates or
+ * updating. If you need to track this use objects and an external map:
+ *
+ * function elgg_register_something($id, $display_name, $location, $priority = 500) {
+ * // $id => $element.
+ * static $map = array();
+ * static $list;
+ *
+ * if (!$list) {
+ * $list = new ElggPriorityList();
+ * }
+ *
+ * // update if already registered.
+ * if (isset($map[$id])) {
+ * $element = $map[$id];
+ * // move it first because we have to pass the original element.
+ * if (!$list->move($element, $priority)) {
+ * return false;
+ * }
+ * $element->display_name = $display_name;
+ * $element->location = $location;
+ * } else {
+ * $element = new stdClass();
+ * $element->display_name = $display_name;
+ * $element->location = $location;
+ * if (!$list->add($element, $priority)) {
+ * return false;
+ * }
+ * $map[$id] = $element;
+ * }
+ *
+ * return true;
+ * }
*
* @package Elgg.Core
* @subpackage Helpers
*/
-
class ElggPriorityList
- implements Iterator, ArrayAccess, Countable {
+ implements Iterator, Countable {
/**
* The list of elements
@@ -123,15 +126,11 @@ class ElggPriorityList
* maintains its priority and the new element is to the next available
* slot, taking into consideration all previously registered elements.
* Negative elements are accepted.
- * @param bool $exact If true, will put the element at exactly the priority specified, displacing
- * other elements.
* @return int The priority of the added element.
*/
public function add($element, $priority = null, $exact = false) {
if ($priority !== null && !is_numeric($priority)) {
return false;
- } elseif ($exact) {
- $this->shiftElementsSegment($priority);
} else {
$priority = $this->getNextPriority($priority);
}
@@ -163,16 +162,16 @@ class ElggPriorityList
/**
* Move an existing element to a new priority.
*
- * @param int $current_priority
- * @param int $new_priority
- * @param bool $exact
- * @return bool
+ * @param mixed $current_priority
+ * @param int $new_priority
+ *
+ * @return int The new priority.
*/
- public function move($current_priority, $new_priority, $exact = false) {
- $current_priority = (int) $current_priority;
+ public function move($element, $new_priority, $strict = false) {
$new_priority = (int) $new_priority;
-
- if (!isset($this->elements[$current_priority])) {
+
+ $current_priority = $this->getPriority($element, $strict);
+ if (!$current_priority) {
return false;
}
@@ -180,17 +179,16 @@ class ElggPriorityList
return true;
}
- $element = $this->elements[$current_priority];
+ // move the actual element so strict operations still work
+ $element = $this->getElement($current_priority);
unset($this->elements[$current_priority]);
-
- return $this->add($element, $new_priority, $exact);
+ return $this->add($element, $new_priority);
}
/**
* Returns the elements
*
- * @param type $elements
- * @param type $sort
+ * @return array
*/
public function getElements() {
$this->sortIfUnsorted();
@@ -238,29 +236,6 @@ class ElggPriorityList
}
}
- /**
- * Shift a segment of elements starting at $index up by one until the end of the array or
- * there's a gap in the indexes. This produces a space at $index to insert a new element.
- *
- * @param type $index The index to start
- * @return array
- */
- private function shiftElementsSegment($index) {
- $index = (int) $index;
- // @todo probably a better way.
- $replace_elements = array();
- while (isset($this->elements[$index])) {
- $replace_elements[$index + 1] = $this->elements[$index];
- unset($this->elements[$index]);
- $index++;
- }
-
- // insert old ones
- foreach ($replace_elements as $index => $element) {
- $this->elements[$index] = $element;
- }
- }
-
/**
* Returns the next priority available.
*
@@ -277,25 +252,45 @@ class ElggPriorityList
return $near;
}
-
/**
* Returns the priority of an element if it exists in the list.
*
- * @warning This can return 0 if the element's priority is 0. Use identical operator (===) to
- * check for false if you want to know if an element exists.
+ * @warning This can return 0 if the element's priority is 0.
*
- * @param mixed $element
+ * @param mixed $element The element to check for.
+ * @param bool $strict Use strict checking?
* @return mixed False if the element doesn't exists, the priority if it does.
*/
public function getPriority($element, $strict = false) {
return array_search($element, $this->elements, $strict);
}
+ /**
+ * Returns the element at $priority.
+ *
+ * @param int $priority
+ * @return mixed The element or false on fail.
+ */
+ public function getElement($priority) {
+ return (isset($this->elements[$priority])) ? $this->elements[$priority] : false;
+ }
+
+ /**
+ * Returns if the list contains $element.
+ *
+ * @param mixed $element The element to check.
+ * @param bool $strict Use strict checking?
+ * @return bool
+ */
+ public function contains($element, $strict = false) {
+ return $this->getPriority($element, $strict) !== false;
+ }
+
+
/**********************
- * Interfaces methods *
+ * Interface methods *
**********************/
-
/**
* Iterator
*/
@@ -356,29 +351,8 @@ class ElggPriorityList
return ($key !== NULL && $key !== FALSE);
}
- // Coutable
+ // Countable
public function count() {
return count($this->elements);
}
-
- // ArrayAccess
- public function offsetExists($offset) {
- return isset($this->elements[$offset]);
- }
-
- public function offsetGet($offset) {
- return isset($this->elements[$offset]) ? $this->elements[$offset] : null;
- }
-
- public function offsetSet($offset, $value) {
- // for $pl[] = 'New element'
- $exact = ($offset !== null);
- return $this->add($value, $offset, $exact);
- }
-
- public function offsetUnset($offset) {
- if (isset($this->elements[$offset])) {
- unset($this->elements[$offset]);
- }
- }
}
\ No newline at end of file
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php
index b6b603e79..198ffe60c 100644
--- a/engine/lib/elgglib.php
+++ b/engine/lib/elgglib.php
@@ -167,7 +167,7 @@ function forward($location = "", $reason = 'system') {
* @param string $name An identifier for the JavaScript library
* @param string $url URL of the JavaScript file
* @param string $location Page location: head or footer. (default: head)
- * @param int $priority Priority of the CSS file (lower numbers load earlier)
+ * @param int $priority Priority of the JS file (lower numbers load earlier)
*
* @return bool
* @since 1.8.0
@@ -288,28 +288,24 @@ function elgg_register_external_file($type, $name, $url, $location, $priority =
$url = elgg_format_url($url);
$url = elgg_normalize_url($url);
- if (!isset($CONFIG->externals)) {
- $CONFIG->externals = array();
- }
-
- if (!$CONFIG->externals[$type] instanceof ElggPriorityList) {
- $CONFIG->externals[$type] = new ElggPriorityList();
- }
+ elgg_bootstrap_externals_data_structure($type);
$name = trim(strtolower($name));
$priority = max((int)$priority, 0);
+ $item = elgg_extract($name, $CONFIG->externals_map[$type]);
- $index = elgg_get_external_file_priority($name, $type);
-
- if ($index !== false) {
+ if ($item) {
// updating a registered item
- $item = $CONFIG->externals[$type][$index];
+ // don't update loaded because it could already be set
$item->url = $url;
$item->location = $location;
- // remove old saved priority
- elgg_remove_external_file_priority($name, $type);
- $priority = $CONFIG->externals[$type]->move($index, $priority);
+ // if loaded before registered, that means it hasn't been added to the list yet
+ if ($CONFIG->externals[$type]->contains($item)) {
+ $priority = $CONFIG->externals[$type]->move($item, $priority);
+ } else {
+ $priority = $CONFIG->externals[$type]->add($item, $priority);
+ }
} else {
$item = new stdClass();
$item->loaded = false;
@@ -319,10 +315,9 @@ function elgg_register_external_file($type, $name, $url, $location, $priority =
$priority = $CONFIG->externals[$type]->add($item, $priority);
}
- // save priority map so we can update if added again
- elgg_save_external_file_priority($priority, $name, $type);
+ $CONFIG->externals_map[$type][$name] = $item;
- return true;
+ return $priority !== false;
}
/**
@@ -337,22 +332,14 @@ function elgg_register_external_file($type, $name, $url, $location, $priority =
function elgg_unregister_external_file($type, $name) {
global $CONFIG;
- if (!isset($CONFIG->externals)) {
- return false;
- }
-
- if (!$CONFIG->externals[$type] instanceof ElggPriorityList) {
- return false;
- }
+ elgg_bootstrap_externals_data_structure($type);
$name = trim(strtolower($name));
-
- $priority = elgg_get_external_file_priority($name, $type);
+ $item = elgg_extract($name, $CONFIG->externals_map[$type]);
- if ($priority !== false) {
- elgg_remove_external_file_priority($name, $type);
- unset($CONFIG->externals[$type][$priority]);
- return true;
+ if ($item) {
+ unset($CONFIG->externals_map[$type][$name]);
+ return $CONFIG->externals[$type]->remove($item);
}
return false;
@@ -370,21 +357,15 @@ function elgg_unregister_external_file($type, $name) {
function elgg_load_external_file($type, $name) {
global $CONFIG;
- if (!isset($CONFIG->externals)) {
- $CONFIG->externals = array();
- }
-
- if (!$CONFIG->externals[$type] instanceof ElggPriorityList) {
- $CONFIG->externals[$type] = new ElggPriorityList();
- }
+ elgg_bootstrap_externals_data_structure($type);
$name = trim(strtolower($name));
- $priority = elgg_get_external_file_priority($name, $type);
+ $item = elgg_extract($name, $CONFIG->externals_map[$type]);
- if ($priority !== false) {
+ if ($item) {
// update a registered item
- $CONFIG->externals[$type][$priority]->loaded = true;
+ $item->loaded = true;
} else {
$item = new stdClass();
$item->loaded = true;
@@ -392,59 +373,10 @@ function elgg_load_external_file($type, $name) {
$item->location = '';
$priority = $CONFIG->externals[$type]->add($item);
- elgg_save_external_file_priority($priority, $name, $type);
+ $CONFIG->externals_map[$type][$name] = $item;
}
}
-/**
- * Gets the priority of an external by name and type.
- *
- * @param type $name
- * @param type $type
- * @return type
- */
-function elgg_get_external_file_priority($name, $type) {
- global $CONFIG;
-
- if (!isset($CONFIG->externals_priorities[$type][$name])) {
- return false;
- }
-
- return $CONFIG->externals_priorities[$type][$name];
-}
-
-function elgg_save_external_file_priority($priority, $name, $type) {
- global $CONFIG;
-
- if (!isset($CONFIG->externals_priorities)) {
- $CONFIG->externals_priorities = array();
- }
-
- if (!isset($CONFIG->externals_priorities[$type])) {
- $CONFIG->externals_priorities[$type] = array();
- }
-
- $CONFIG->externals_priorities[$type][$name] = $priority;
-
- return true;
-}
-
-function elgg_remove_external_file_priority($name, $type) {
- global $CONFIG;
-
- if (!isset($CONFIG->externals_priorities)) {
- $CONFIG->externals_priorities = array();
- }
-
- if (!isset($CONFIG->externals_priorities[$type])) {
- $CONFIG->externals_priorities[$type] = array();
- }
-
- unset($CONFIG->externals_priorities[$type][$name]);
-
- return true;
-}
-
/**
* Get external resource descriptors
*
@@ -470,6 +402,31 @@ function elgg_get_loaded_external_files($type, $location) {
return array();
}
+/**
+ * Bootstraps the externals data structure in $CONFIG.
+ *
+ * @param string $type The type of external, js or css.
+ */
+function elgg_bootstrap_externals_data_structure($type) {
+ global $CONFIG;
+
+ if (!isset($CONFIG->externals)) {
+ $CONFIG->externals = array();
+ }
+
+ if (!$CONFIG->externals[$type] instanceof ElggPriorityList) {
+ $CONFIG->externals[$type] = new ElggPriorityList();
+ }
+
+ if (!isset($CONFIG->externals_map)) {
+ $CONFIG->externals_map = array();
+ }
+
+ if (!isset($CONFIG->externals_map[$type])) {
+ $CONFIG->externals_map[$type] = array();
+ }
+}
+
/**
* Returns a list of files in $directory.
*
diff --git a/engine/lib/views.php b/engine/lib/views.php
index 7686a8bef..fe3265347 100644
--- a/engine/lib/views.php
+++ b/engine/lib/views.php
@@ -1479,21 +1479,6 @@ function autoregister_views($view_base, $folder, $base_location_path, $viewtype)
return FALSE;
}
-/**
- * Add the core Elgg head elements that could be cached
- *
- * @return void
- */
-function elgg_views_register_core_head_elements() {
- $url = elgg_get_simplecache_url('js', 'elgg');
- elgg_register_js('elgg', $url, 'head', 10);
- elgg_load_js('elgg');
-
- $url = elgg_get_simplecache_url('css', 'elgg');
- elgg_register_css('elgg', $url, 10);
- elgg_load_css('elgg');
-}
-
/**
* Add the rss link to the extras when if needed
*
@@ -1548,12 +1533,17 @@ function elgg_views_boot() {
elgg_register_simplecache_view('css/ie6');
elgg_register_simplecache_view('js/elgg');
- elgg_register_js('jquery', '/vendors/jquery/jquery-1.6.2.min.js', 'head', 1);
- elgg_register_js('jquery-ui', '/vendors/jquery/jquery-ui-1.8.16.min.js', 'head', 2);
+ elgg_register_js('jquery', '/vendors/jquery/jquery-1.6.2.min.js', 'head');
+ elgg_register_js('jquery-ui', '/vendors/jquery/jquery-ui-1.8.16.min.js', 'head');
elgg_register_js('jquery.form', '/vendors/jquery/jquery.form.js');
+
+ $elgg_js_url = elgg_get_simplecache_url('js', 'elgg');
+ elgg_register_js('elgg', $elgg_js_url, 'head');
+
elgg_load_js('jquery');
elgg_load_js('jquery-ui');
elgg_load_js('jquery.form');
+ elgg_load_js('elgg');
elgg_register_simplecache_view('js/lightbox');
$lightbox_js_url = elgg_get_simplecache_url('js', 'lightbox');
@@ -1561,7 +1551,10 @@ function elgg_views_boot() {
$lightbox_css_url = 'vendors/jquery/fancybox/jquery.fancybox-1.3.4.css';
elgg_register_css('lightbox', $lightbox_css_url);
- elgg_register_event_handler('ready', 'system', 'elgg_views_register_core_head_elements');
+ $elgg_css_url = elgg_get_simplecache_url('css', 'elgg');
+ elgg_register_css('elgg', $elgg_css_url, 1);
+ elgg_load_css('elgg');
+
elgg_register_event_handler('pagesetup', 'system', 'elgg_views_add_rss_link');
// discover the built-in view types
diff --git a/engine/tests/api/helpers.php b/engine/tests/api/helpers.php
index cceb762be..ee2e64cfe 100644
--- a/engine/tests/api/helpers.php
+++ b/engine/tests/api/helpers.php
@@ -31,7 +31,7 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
global $CONFIG;
unset($CONFIG->externals);
- unset($CONFIG->externals_priorities);
+ unset($CONFIG->externals_map);
}
/**
@@ -107,9 +107,16 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
// specify name
$result = elgg_register_js('key', 'http://test1.com', 'footer');
$this->assertTrue($result);
- $this->assertTrue(isset($CONFIG->externals_priorities['js']['key']));
- $index = $CONFIG->externals_priorities['js']['key'];
- $this->assertIdentical('http://test1.com', $CONFIG->externals['js'][$index]->url);
+ $this->assertTrue(isset($CONFIG->externals_map['js']['key']));
+
+ $item = $CONFIG->externals_map['js']['key'];
+ $this->assertTrue($CONFIG->externals['js']->contains($item));
+
+ $priority = $CONFIG->externals['js']->getPriority($item);
+ $this->assertTrue($priority !== false);
+
+ $item = $CONFIG->externals['js']->getElement($priority);
+ $this->assertIdentical('http://test1.com', $item->url);
// send a bad url
$result = @elgg_register_js('bad');
@@ -121,13 +128,20 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
*/
public function testElggRegisterCSS() {
global $CONFIG;
-
+
// specify name
$result = elgg_register_css('key', 'http://test1.com');
$this->assertTrue($result);
- $this->assertTrue(isset($CONFIG->externals_priorities['css']['key']));
- $index = elgg_get_external_file_priority('css', 'key');
- $this->assertIdentical('http://test1.com', $CONFIG->externals['css'][$index]->url);
+ $this->assertTrue(isset($CONFIG->externals_map['css']['key']));
+
+ $item = $CONFIG->externals_map['css']['key'];
+ $this->assertTrue($CONFIG->externals['css']->contains($item));
+
+ $priority = $CONFIG->externals['css']->getPriority($item);
+ $this->assertTrue($priority !== false);
+
+ $item = $CONFIG->externals['css']->getElement($priority);
+ $this->assertIdentical('http://test1.com', $item->url);
}
/**
@@ -139,6 +153,7 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
$base = trim(elgg_get_site_url(), "/");
$urls = array('id1' => "$base/urla", 'id2' => "$base/urlb", 'id3' => "$base/urlc");
+
foreach ($urls as $id => $url) {
elgg_register_js($id, $url);
}
@@ -148,26 +163,33 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
$js = $CONFIG->externals['js'];
$elements = $js->getElements();
- $this->assertFalse(isset($CONFIG->externals_priorities['js']['id1']));
+ $this->assertFalse(isset($CONFIG->externals_map['js']['id1']));
+
foreach ($elements as $element) {
$this->assertFalse($element->name == 'id1');
}
$result = elgg_unregister_js('id1');
$this->assertFalse($result);
+
$result = elgg_unregister_js('', 'does_not_exist');
$this->assertFalse($result);
$result = elgg_unregister_js('id2');
$elements = $js->getElements();
- $this->assertFalse(isset($CONFIG->externals_priorities['js']['id2']));
+
+ $this->assertFalse(isset($CONFIG->externals_map['js']['id2']));
foreach ($elements as $element) {
$this->assertFalse($element->name == 'id2');
}
- $this->assertTrue(isset($CONFIG->externals_priorities['js']['id3']));
- $priority = $CONFIG->externals_priorities['js']['id3'];
- $this->assertIdentical($urls['id3'], $CONFIG->externals['js'][$priority]->url);
+ $this->assertTrue(isset($CONFIG->externals_map['js']['id3']));
+
+ $priority = $CONFIG->externals['js']->getPriority($CONFIG->externals_map['js']['id3']);
+ $this->assertTrue($priority !== false);
+
+ $item = $CONFIG->externals['js']->getElement($priority);
+ $this->assertIdentical($urls['id3'], $item->url);
}
/**
@@ -180,6 +202,7 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
elgg_load_js('key');
$result = elgg_register_js('key', 'http://test1.com', 'footer');
$this->assertTrue($result);
+
$js_urls = elgg_get_loaded_js('footer');
$this->assertIdentical(array('http://test1.com'), $js_urls);
}
@@ -192,7 +215,12 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
$base = trim(elgg_get_site_url(), "/");
- $urls = array('id1' => "$base/urla", 'id2' => "$base/urlb", 'id3' => "$base/urlc");
+ $urls = array(
+ 'id1' => "$base/urla",
+ 'id2' => "$base/urlb",
+ 'id3' => "$base/urlc"
+ );
+
foreach ($urls as $id => $url) {
elgg_register_js($id, $url);
elgg_load_js($id);
@@ -315,6 +343,28 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
$this->assertIdentical($elements[2], $test_elements[2]);
}
+ public function testElggPriorityListMove() {
+ $pl = new ElggPriorityList();
+
+ $elements = array(
+ -5 => 'Test Element -5',
+ 0 => 'Test Element 0',
+ 5 => 'Test Element 5',
+ );
+
+ foreach ($elements as $priority => $element) {
+ $pl->add($element, $priority);
+ }
+
+ $this->assertTrue($pl->move($elements[-5], 10));
+
+ // check it's at the new place
+ $this->assertIdentical($elements[-5], $pl->getElement(10));
+
+ // check it's not at the old
+ $this->assertFalse($pl->getElement(-5));
+ }
+
public function testElggPriorityListConstructor() {
$elements = array(
10 => 'Test Element 10',
@@ -358,6 +408,25 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
$this->assertIdentical(2, $pl->getPriority($elements[2]));
}
+ public function testElggPriorityListGetElement() {
+ $pl = new ElggPriorityList();
+ $priorities = array();
+
+ $elements = array(
+ 'Test element 0',
+ 'Test element 1',
+ 'Test element 2',
+ );
+
+ foreach ($elements as $element) {
+ $priorities[] = $pl->add($element);
+ }
+
+ $this->assertIdentical($elements[0], $pl->getElement($priorities[0]));
+ $this->assertIdentical($elements[1], $pl->getElement($priorities[1]));
+ $this->assertIdentical($elements[2], $pl->getElement($priorities[2]));
+ }
+
public function testElggPriorityListPriorityCollision() {
$pl = new ElggPriorityList();
@@ -378,31 +447,6 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
$this->assertEqual(7, $pl->getPriority('Colliding element'));
}
- public function testElggPriorityListArrayAccess() {
- $pl = new ElggPriorityList();
-
- $pl[] = 'Test element 0';
- $pl[-10] = 'Test element -10';
- $pl[-1] = 'Test element -1';
- $pl[] = 'Test element 1';
- $pl[5] = 'Test element 5';
- $pl[0] = 'Test element collision with 0';
-
- $elements = array(
- -1 => 'Test element -1',
- 0 => 'Test element collision with 0',
- 1 => 'Test element 0',
- 2 => 'Test element 1',
- 5 => 'Test element 5',
- );
-
- $priority = $pl->getPriority('Test element -10');
- unset($pl[$priority]);
-
- $test_elements = $pl->getElements();
- $this->assertIdentical($elements, $test_elements);
- }
-
public function testElggPriorityListIterator() {
$elements = array(
-5 => 'Test element -5',
@@ -422,13 +466,13 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
$this->assertEqual(0, count($pl));
- $pl[] = 'Test element 0';
+ $pl->add('Test element 0');
$this->assertEqual(1, count($pl));
- $pl[] = 'Test element 1';
+ $pl->add('Test element 1');
$this->assertEqual(2, count($pl));
- $pl[] = 'Test element 2';
+ $pl->add('Test element 2');
$this->assertEqual(3, count($pl));
}
@@ -461,43 +505,4 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
$this->assertIdentical($elements_sorted_string, $test_elements);
}
-
- function testElggPriorityListShiftElementsSegment() {
- $elements = array(
- 0 => 'Element 0',
- 1 => 'Element 1',
- 2 => 'Element 2',
- 4 => 'Element 4',
- );
-
- $pl = new ElggPriorityList($elements);
-
- // add a new element directly at 1.
- $pl->add('New Element', 1, true);
-
- $elements_sorted = array(
- 0 => 'Element 0',
- 1 => 'New Element',
- 2 => 'Element 1',
- 3 => 'Element 2',
- 4 => 'Element 4',
- );
-
- $test_elements = $pl->getElements();
- $this->assertIdentical($elements_sorted, $test_elements);
-
- $pl->add('New Element 10', 10, true);
-
- $elements_sorted = array(
- 0 => 'Element 0',
- 1 => 'New Element',
- 2 => 'Element 1',
- 3 => 'Element 2',
- 4 => 'Element 4',
- 10 => 'New Element 10'
- );
-
- $test_elements = $pl->getElements();
- $this->assertIdentical($elements_sorted, $test_elements);
- }
}
\ No newline at end of file
--
cgit v1.2.3
From 68c358613cd9fdabd8c6d599223aa0cfb1723138 Mon Sep 17 00:00:00 2001
From: Brett Profitt
Date: Wed, 24 Aug 2011 21:24:35 -0700
Subject: Checking for === false when moving elements in ElggPriorityList
instead of just !$priority. Fixes problems when moving elements to / from 0.
---
engine/classes/ElggPriorityList.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'engine/classes')
diff --git a/engine/classes/ElggPriorityList.php b/engine/classes/ElggPriorityList.php
index 17ce228bc..aa33831ff 100644
--- a/engine/classes/ElggPriorityList.php
+++ b/engine/classes/ElggPriorityList.php
@@ -171,7 +171,7 @@ class ElggPriorityList
$new_priority = (int) $new_priority;
$current_priority = $this->getPriority($element, $strict);
- if (!$current_priority) {
+ if ($current_priority === false) {
return false;
}
--
cgit v1.2.3