From c5cc2821311012a8a4385a304a043c4b41f2afbb Mon Sep 17 00:00:00 2001
From: brettp
Date: Mon, 31 Aug 2009 19:05:21 +0000
Subject: All line endings are now Unix-style.
git-svn-id: https://code.elgg.org/elgg/trunk@3451 36083f99-b078-4883-b0ff-0f9b5a30f544
---
CONTRIBUTORS.txt | 70 +-
INSTALL.txt | 238 +-
README.txt | 70 +-
_css/css.php | 68 +-
_css/js.php | 82 +-
account/register.php | 54 +-
actions/admin/plugins/disable.php | 4 +-
actions/admin/plugins/disableall.php | 4 +-
actions/admin/plugins/enable.php | 2 +-
actions/admin/plugins/reorder.php | 98 +-
actions/admin/site/update_basic.php | 190 +-
actions/admin/user/ban.php | 12 +-
actions/comments/add.php | 110 +-
actions/comments/delete.php | 64 +-
actions/email/save.php | 4 +-
actions/friends/add.php | 72 +-
actions/friends/addcollection.php | 92 +-
actions/friends/deletecollection.php | 92 +-
actions/friends/editcollection.php | 34 +-
actions/friends/remove.php | 64 +-
actions/login.php | 108 +-
actions/logout.php | 44 +-
actions/register.php | 62 +-
actions/systemsettings/install.php | 234 +-
actions/user/default_access.php | 8 +-
actions/user/requestnewpassword.php | 20 +-
actions/user/spotlight.php | 28 +-
actions/useradd.php | 8 +-
actions/usersettings/save.php | 38 +-
actions/widgets/add.php | 80 +-
actions/widgets/reorder.php | 58 +-
actions/widgets/save.php | 68 +-
admin/index.php | 36 +-
admin/plugins.php | 6 +-
admin/site.php | 46 +-
admin/user.php | 88 +-
dashboard/index.php | 60 +-
dashboard/latest.php | 54 +-
engine/handlers/action_handler.php | 38 +-
engine/handlers/cron_handler.php | 2 +-
engine/handlers/pagehandler.php | 48 +-
engine/handlers/xml-rpc_handler.php | 2 +-
engine/lib/access.php | 1324 ++---
engine/lib/activity.php | 302 +-
engine/lib/admin.php | 348 +-
engine/lib/api.php | 4 +-
engine/lib/configuration.php | 266 +-
engine/lib/database.php | 750 +--
engine/lib/elgglib.php | 20 +-
engine/lib/entities.php | 5534 ++++++++++----------
engine/lib/extender.php | 100 +-
engine/lib/input.php | 348 +-
engine/lib/install.php | 100 +-
engine/lib/languages.php | 312 +-
engine/lib/metadata.php | 1820 +++----
engine/lib/metastrings.php | 40 +-
engine/lib/notification.php | 846 +--
engine/lib/objects.php | 416 +-
engine/lib/pagehandler.php | 230 +-
engine/lib/pageowner.php | 306 +-
engine/lib/pam.php | 24 +-
engine/lib/plugins.php | 1384 ++---
engine/lib/query.php | 12 +-
engine/lib/relationships.php | 316 +-
engine/lib/river2.php | 596 +--
engine/lib/sessions.php | 384 +-
engine/lib/sites.php | 140 +-
engine/lib/social.php | 214 +-
engine/lib/statistics.php | 4 +-
engine/lib/tags.php | 322 +-
engine/lib/upgrades/2008101303.php | 20 +-
engine/lib/users.php | 3000 +++++------
engine/lib/version.php | 116 +-
engine/lib/widgets.php | 1050 ++--
engine/settings.example.php | 208 +-
engine/start.php | 432 +-
entities/index.php | 130 +-
entities/list.php | 36 +-
friends/add.php | 50 +-
friends/collections.php | 50 +-
friends/edit.php | 72 +-
friends/index.php | 46 +-
friends/of.php | 46 +-
friends/pickercallback.php | 116 +-
index.php | 66 +-
install.php | 70 +-
languages/en.php | 2154 ++++----
mod/garbagecollector/languages/en.php | 2 +-
mod/logbrowser/index.php | 126 +-
mod/logbrowser/languages/en.php | 14 +-
mod/logbrowser/start.php | 44 +-
.../views/default/logbrowser/adminlinks.php | 6 +-
mod/logbrowser/views/default/logbrowser/form.php | 130 +-
mod/logbrowser/views/default/object/logwrapper.php | 94 +-
mod/uservalidationbyemail/start.php | 4 +-
settings/index.php | 22 +-
simplecache/view.php | 124 +-
upgrade.php | 20 +-
vendors/calendarpopup/CalendarPopup.js | 2924 +++++------
vendors/jquery/jquery.form.js | 1286 ++---
version.php | 32 +-
views/default/account/forms/login.php | 56 +-
views/default/account/forms/register.php | 42 +-
views/default/admin/main.php | 32 +-
views/default/admin/plugins_opt/plugin.php | 64 +-
views/default/admin/statistics.php | 24 +-
views/default/admin/statistics_opt/numentities.php | 102 +-
views/default/admin/statistics_opt/online.php | 40 +-
views/default/admin/user_opt/search.php | 10 +-
views/default/ajax/loader.php | 52 +-
views/default/annotation/annotate.php | 46 +-
views/default/annotation/generic_comment.php | 120 +-
views/default/basic_elements/welcome.php | 32 +-
views/default/canvas/default.php | 36 +-
views/default/canvas/layouts/edit_layout.php | 34 +-
views/default/canvas/layouts/sidebar_boxes.php | 60 +-
views/default/canvas_header/submenu_group.php | 28 +-
views/default/canvas_header/submenu_template.php | 30 +-
views/default/comments/forms/edit.php | 44 +-
views/default/dashboard/blurb.php | 22 +-
views/default/embed/addcontentjs.php | 6 +-
views/default/embed/js.php | 12 +-
views/default/friends/collection.php | 114 +-
views/default/friends/collections.php | 104 +-
views/default/friends/collectiontabs.php | 96 +-
views/default/friends/forms/collectionfields.php | 44 +-
views/default/friends/forms/edit.php | 4 +-
views/default/friends/list.php | 48 +-
views/default/friends/picker.php | 652 +--
views/default/friends/river/create.php | 36 +-
views/default/friends/tablelistcountupdate.php | 38 +-
views/default/input/access.php | 108 +-
views/default/input/calendar.php | 82 +-
views/default/input/checkboxes.php | 84 +-
views/default/input/email.php | 38 +-
views/default/input/file.php | 42 +-
views/default/input/longtext.php | 38 +-
views/default/input/password.php | 38 +-
views/default/input/plaintext.php | 44 +-
views/default/input/pulldown.php | 70 +-
views/default/input/radio.php | 62 +-
views/default/input/tags.php | 78 +-
views/default/input/text.php | 38 +-
views/default/input/url.php | 38 +-
views/default/js/friendsPickerv1.php | 186 +-
views/default/js/initialise_elgg.php | 592 +--
views/default/js/upload_js.php | 112 +-
views/default/messages/errors/error.php | 34 +-
views/default/messages/errors/list.php | 112 +-
views/default/messages/exceptions/exception.php | 30 +-
views/default/messages/list.php | 44 +-
views/default/messages/messages/list.php | 114 +-
views/default/messages/messages/message.php | 34 +-
views/default/navigation/viewtype.php | 62 +-
.../notifications/settings/usersettings.php | 84 +-
views/default/object/widget.php | 26 +-
views/default/output/calendar.php | 26 +-
views/default/output/checkboxes.php | 32 +-
views/default/output/confirmlink.php | 54 +-
views/default/output/date.php | 36 +-
views/default/output/email.php | 36 +-
views/default/output/longtext.php | 36 +-
views/default/output/pulldown.php | 32 +-
views/default/output/radio.php | 32 +-
views/default/output/tagcloud.php | 98 +-
views/default/output/tags.php | 104 +-
views/default/output/text.php | 32 +-
views/default/output/url.php | 46 +-
views/default/page_elements/contentwrapper.php | 20 +-
views/default/page_elements/header_contents.php | 44 +-
views/default/page_elements/owner_block.php | 194 +-
views/default/river/item/list.php | 100 +-
views/default/river/item/noaccess.php | 8 +-
views/default/river/item/wrapper.php | 74 +-
views/default/river/wrapper.php | 20 +-
views/default/settings/install.php | 32 +-
views/default/settings/system.php | 138 +-
views/default/settings/upgrading.php | 36 +-
views/default/spotlight/default.php | 72 +-
views/default/text/about.php | 28 +-
views/default/text/privacy_view.php | 30 +-
views/default/text/tos_view.php | 22 +-
views/default/upload/upload_form_content.php | 230 +-
views/default/user/default.php | 40 +-
views/default/user/settings/default_access.php | 54 +-
views/default/user/settings/email.php | 48 +-
views/default/user/settings/name.php | 48 +-
views/default/user/settings/password.php | 50 +-
.../usersettings/statistics_opt/numentities.php | 100 +-
views/default/welcome.php | 34 +-
views/default/widgets/editwrapper.php | 74 +-
views/default/widgets/wrapper.php | 224 +-
views/failsafe/canvas/default.php | 36 +-
views/failsafe/input/access.php | 100 +-
views/failsafe/input/checkboxes.php | 78 +-
views/failsafe/input/longtext.php | 38 +-
views/failsafe/input/pulldown.php | 70 +-
views/failsafe/input/text.php | 38 +-
views/failsafe/messages/errors/error.php | 34 +-
views/failsafe/messages/errors/list.php | 94 +-
views/failsafe/messages/list.php | 44 +-
views/failsafe/messages/messages/list.php | 100 +-
views/failsafe/messages/messages/message.php | 34 +-
views/failsafe/messages/sanitisation/htaccess.php | 22 +-
views/failsafe/settings/install.php | 32 +-
views/failsafe/settings/system.php | 126 +-
views/foaf/canvas/default.php | 36 +-
views/foaf/page_elements/contentwrapper.php | 8 +-
views/foaf/pageshells/pageshell.php | 64 +-
views/foaf/user/default.php | 46 +-
views/js/object/default.php | 34 +-
views/js/pageshells/pageshell.php | 48 +-
views/js/user/default.php | 34 +-
views/json/api/output.php | 6 +-
views/json/canvas/default.php | 4 +-
views/json/export/entity.php | 8 +-
views/json/export/metadata.php | 4 +-
views/json/export/relationship.php | 4 +-
views/json/messages/exceptions/exception.php | 4 +-
views/json/page_elements/contentwrapper.php | 8 +-
views/json/pageshells/pageshell.php | 16 +-
views/json/river/item/list.php | 96 +-
views/opendd/messages/exceptions/exception.php | 32 +-
views/rss/annotation/default.php | 54 +-
views/rss/canvas/default.php | 36 +-
views/rss/group/default.php | 40 +-
views/rss/object/default.php | 56 +-
views/rss/page_elements/contentwrapper.php | 8 +-
views/rss/river/item/list.php | 82 +-
views/rss/user/default.php | 40 +-
views/xml/messages/exceptions/exception.php | 32 +-
231 files changed, 19830 insertions(+), 19830 deletions(-)
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt
index af850a2b4..dc10fafaf 100644
--- a/CONTRIBUTORS.txt
+++ b/CONTRIBUTORS.txt
@@ -1,36 +1,36 @@
-
-CONTRIBUTORS
-
-The core Elgg team:
-
-David Tosh
-http://twitter.com/davetosh
-
-Marcus Povey
-http://marcuspovey.co.uk/
-http://twitter.com/mapkyca
-
-Brett Profitt
-http://twitter.com/brettprofitt
-
-Pete Harris
-
-
-CONTRIBUTING/ALUMNI DEVELOPERS
-
-Kevin Jardine
-http://radagast.biz/
-
-Milan Magudia
-
-Ben Werdmuller
-http://benwerd.com/
-http://twitter.com/benwerd
-
-
-Thanks to the following developers for contributing patches and/or suggestions
-
-Diego Andrés Ramírez Aragón
-Corporación Somos Más
-
+
+CONTRIBUTORS
+
+The core Elgg team:
+
+David Tosh
+http://twitter.com/davetosh
+
+Marcus Povey
+http://marcuspovey.co.uk/
+http://twitter.com/mapkyca
+
+Brett Profitt
+http://twitter.com/brettprofitt
+
+Pete Harris
+
+
+CONTRIBUTING/ALUMNI DEVELOPERS
+
+Kevin Jardine
+http://radagast.biz/
+
+Milan Magudia
+
+Ben Werdmuller
+http://benwerd.com/
+http://twitter.com/benwerd
+
+
+Thanks to the following developers for contributing patches and/or suggestions
+
+Diego Andrés Ramírez Aragón
+Corporación Somos Más
+
Cash Costello
\ No newline at end of file
diff --git a/INSTALL.txt b/INSTALL.txt
index 2df994a87..b5a6e1e8b 100644
--- a/INSTALL.txt
+++ b/INSTALL.txt
@@ -1,120 +1,120 @@
-
-ELGG INSTALLATION INSTRUCTIONS
-
-TECHNICAL REQUIREMENTS
-
-Elgg runs on a combination of the Apache web server, MySQL database
-system and the PHP interpreted scripting language. This is the most
-popular web server environment in the world.
-
-Due to Elgg's advanced functionality, there are some extra
-configuration requirements:
-
- * The Apache web server needs to be installed with the following
- modules:
- o mod_rewrite
- o PHP
- * MySQL 5+ is needed for data storage
- * PHP 5.2+ needs to be installed as an Apache module (not in CGI
- mode or safe mode) with the following libraries:
- o GD (for graphics processing, eg user icon rescaling)
- o JSON (for API functionality)
-
-It is recommended that you increase the memory available to PHP
-threads beyond the standard 8 or 12M, and increase the maximum
-uploaded filesize (which defaults to 2M). In both cases, this can be
-found in your php.ini.
-
- * The following PHP libraries are also recommended for some
- plugins and extra functionality:
- o mbstring (to allow emails to be sent with non-Latin
- characters)
- o SOAP
- o DOM
-
-
-INSTALLING ELGG
-
-Before you begin, make sure you have read Elgg's technical
-requirements. If you discover problems after following these
-instructions, check out the troubleshooting page at
-[http://docs.elgg.org/wiki/Troubleshooting].
-
-
-1. Upload Elgg
-
-Unzip Elgg and upload it to your site's document root.
-
-
-2. Create a data folder
-
-Elgg needs a special folder to store uploaded files, including
-profile icons and photos. You will need to create this for it.
-
-We recommend that this folder is called data, and is stored outside
-of your document root. For example, if Elgg is installed in
-/home/elgg/html/, you might create it in /home/elgg/data.
-
-Once this folder has been created, you'll need to make sure Elgg has
-permission to write to it. This shouldn't be a problem on Windows-
-based servers, but if your server runs Linux or a UNIX variant,
-you'll need to type something like:
-
-chmod 777 /home/elgg/data/
-
-If you use a graphical client to upload files, you can usually set
-this by right or shift-clicking on the folder and selecting
-'properties'.
-
-
-3. Create a database
-
-Using your database administration tool of choice (if you're unsure
-about this, ask your system administrator), create a new database for
-Elgg. Make sure you know the username and password necessary to
-access this.
-
-4. Install your crontab (UNIX ONLY)
-
-Cron is a UNIX command which allows programs to be run at set
-times of the day.
-
-If you want to take advantage of some of the maintenance
-functions such as log rotation or garbage collection, you must
-install a cron tab to trigger these events.
-
-We have provided an example crontab as /crontab.example. Edit this
-with a text editor to provide the details of your site, rename it
-to another filename (eg 'crontab.mine') and install it with the
-following command:
-
- crontab crontab.mine
-
-Substitute your filename for 'crontab.mine'.
-
-5. Visit your Elgg site
-
-Once you've performed these steps, visit your Elgg site in your web
-browser. Elgg will take you through the rest of the installation
-process from there.
-
-A note on settings and .htaccess
-
-The Elgg installer will try and create two files for you:
-
- * engine/settings.php, which contains the database settings for
- your installation
- * .htaccess, which allows Elgg to generate dynamic URLs
-
-If these files can't be automatically generated, for example because
-you don't have the correct directory permissions, Elgg will tell you
-how to create them. If, for some reason, this won't work, you will
-need to:
-
- * Copy engine/settings.example.php to engine/settings.php, open
- it up in a text editor and fill in your database details
- * Copy /htaccess_dist to /.htaccess
-
-
-The latest version of this document is available at:
+
+ELGG INSTALLATION INSTRUCTIONS
+
+TECHNICAL REQUIREMENTS
+
+Elgg runs on a combination of the Apache web server, MySQL database
+system and the PHP interpreted scripting language. This is the most
+popular web server environment in the world.
+
+Due to Elgg's advanced functionality, there are some extra
+configuration requirements:
+
+ * The Apache web server needs to be installed with the following
+ modules:
+ o mod_rewrite
+ o PHP
+ * MySQL 5+ is needed for data storage
+ * PHP 5.2+ needs to be installed as an Apache module (not in CGI
+ mode or safe mode) with the following libraries:
+ o GD (for graphics processing, eg user icon rescaling)
+ o JSON (for API functionality)
+
+It is recommended that you increase the memory available to PHP
+threads beyond the standard 8 or 12M, and increase the maximum
+uploaded filesize (which defaults to 2M). In both cases, this can be
+found in your php.ini.
+
+ * The following PHP libraries are also recommended for some
+ plugins and extra functionality:
+ o mbstring (to allow emails to be sent with non-Latin
+ characters)
+ o SOAP
+ o DOM
+
+
+INSTALLING ELGG
+
+Before you begin, make sure you have read Elgg's technical
+requirements. If you discover problems after following these
+instructions, check out the troubleshooting page at
+[http://docs.elgg.org/wiki/Troubleshooting].
+
+
+1. Upload Elgg
+
+Unzip Elgg and upload it to your site's document root.
+
+
+2. Create a data folder
+
+Elgg needs a special folder to store uploaded files, including
+profile icons and photos. You will need to create this for it.
+
+We recommend that this folder is called data, and is stored outside
+of your document root. For example, if Elgg is installed in
+/home/elgg/html/, you might create it in /home/elgg/data.
+
+Once this folder has been created, you'll need to make sure Elgg has
+permission to write to it. This shouldn't be a problem on Windows-
+based servers, but if your server runs Linux or a UNIX variant,
+you'll need to type something like:
+
+chmod 777 /home/elgg/data/
+
+If you use a graphical client to upload files, you can usually set
+this by right or shift-clicking on the folder and selecting
+'properties'.
+
+
+3. Create a database
+
+Using your database administration tool of choice (if you're unsure
+about this, ask your system administrator), create a new database for
+Elgg. Make sure you know the username and password necessary to
+access this.
+
+4. Install your crontab (UNIX ONLY)
+
+Cron is a UNIX command which allows programs to be run at set
+times of the day.
+
+If you want to take advantage of some of the maintenance
+functions such as log rotation or garbage collection, you must
+install a cron tab to trigger these events.
+
+We have provided an example crontab as /crontab.example. Edit this
+with a text editor to provide the details of your site, rename it
+to another filename (eg 'crontab.mine') and install it with the
+following command:
+
+ crontab crontab.mine
+
+Substitute your filename for 'crontab.mine'.
+
+5. Visit your Elgg site
+
+Once you've performed these steps, visit your Elgg site in your web
+browser. Elgg will take you through the rest of the installation
+process from there.
+
+A note on settings and .htaccess
+
+The Elgg installer will try and create two files for you:
+
+ * engine/settings.php, which contains the database settings for
+ your installation
+ * .htaccess, which allows Elgg to generate dynamic URLs
+
+If these files can't be automatically generated, for example because
+you don't have the correct directory permissions, Elgg will tell you
+how to create them. If, for some reason, this won't work, you will
+need to:
+
+ * Copy engine/settings.example.php to engine/settings.php, open
+ it up in a text editor and fill in your database details
+ * Copy /htaccess_dist to /.htaccess
+
+
+The latest version of this document is available at:
[http://docs.elgg.org/wiki/Installation]
\ No newline at end of file
diff --git a/README.txt b/README.txt
index b7196c842..4ae9a4358 100644
--- a/README.txt
+++ b/README.txt
@@ -1,35 +1,35 @@
-Elgg version 1.5
-Copyright (c) 2008-2009 Curverider Ltd
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
-USA
-
-
-ABOUT:
-
-See CONTRIBUTORS.txt for development credits.
-
-Elgg concept originally by:
-Ben Werdmuller and David Tosh
-
-Commercial services: http://elgg.com/
-
-The open source project site can be found at http://elgg.org/
-
-Elgg 1.5 is released under the GNU Public License (GPL), which
-is supplied in this distribution as LICENSE.
-
-For installation instructions, please see the INSTALL file.
-
+Elgg version 1.5
+Copyright (c) 2008-2009 Curverider Ltd
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+USA
+
+
+ABOUT:
+
+See CONTRIBUTORS.txt for development credits.
+
+Elgg concept originally by:
+Ben Werdmuller and David Tosh
+
+Commercial services: http://elgg.com/
+
+The open source project site can be found at http://elgg.org/
+
+Elgg 1.5 is released under the GNU Public License (GPL), which
+is supplied in this distribution as LICENSE.
+
+For installation instructions, please see the INSTALL file.
+
diff --git a/_css/css.php b/_css/css.php
index 1cc3eb038..0db16d8a9 100644
--- a/_css/css.php
+++ b/_css/css.php
@@ -1,44 +1,44 @@
-
\ No newline at end of file
diff --git a/_css/js.php b/_css/js.php
index 3839b76e4..89c748cab 100644
--- a/_css/js.php
+++ b/_css/js.php
@@ -1,44 +1,44 @@
-
\ No newline at end of file
diff --git a/account/register.php b/account/register.php
index 350a770e9..be7f9892e 100644
--- a/account/register.php
+++ b/account/register.php
@@ -1,30 +1,30 @@
- $friend_guid, 'invitecode' => $invitecode)));
- // Otherwise, forward to the index page
- } else {
- forward();
- }
-
+ * @author Curverider Ltd
+
+ * @link http://elgg.org/
+ */
+
+ /**
+ * Start the Elgg engine
+ */
+ require_once(dirname(dirname(__FILE__)) . "/engine/start.php");
+
+ $friend_guid = (int) get_input('friend_guid',0);
+ $invitecode = get_input('invitecode');
+
+ // If we're not logged in, display the registration page
+ if (!isloggedin()) {
+ page_draw(elgg_echo('register'), elgg_view("account/forms/register", array('friend_guid' => $friend_guid, 'invitecode' => $invitecode)));
+ // Otherwise, forward to the index page
+ } else {
+ forward();
+ }
+
?>
\ No newline at end of file
diff --git a/actions/admin/plugins/disable.php b/actions/admin/plugins/disable.php
index 2241730ad..90825bc2f 100644
--- a/actions/admin/plugins/disable.php
+++ b/actions/admin/plugins/disable.php
@@ -29,9 +29,9 @@
else
register_error(sprintf(elgg_echo('admin:plugins:disable:no'), $p));
}
-
+
elgg_view_regenerate_simplecache();
- elgg_filepath_cache_reset();
+ elgg_filepath_cache_reset();
forward($_SERVER['HTTP_REFERER']);
exit;
diff --git a/actions/admin/plugins/disableall.php b/actions/admin/plugins/disableall.php
index 5d0be4ad6..672915bce 100644
--- a/actions/admin/plugins/disableall.php
+++ b/actions/admin/plugins/disableall.php
@@ -26,9 +26,9 @@
else
register_error(sprintf(elgg_echo('admin:plugins:disable:no'), $p));
}
-
+
elgg_view_regenerate_simplecache();
- elgg_filepath_cache_reset();
+ elgg_filepath_cache_reset();
forward($_SERVER['HTTP_REFERER']);
exit;
diff --git a/actions/admin/plugins/enable.php b/actions/admin/plugins/enable.php
index 26d7abaf4..890e6648e 100644
--- a/actions/admin/plugins/enable.php
+++ b/actions/admin/plugins/enable.php
@@ -29,7 +29,7 @@
else
register_error(sprintf(elgg_echo('admin:plugins:enable:no'), $p));
}
-
+
elgg_view_regenerate_simplecache();
elgg_filepath_cache_reset();
diff --git a/actions/admin/plugins/reorder.php b/actions/admin/plugins/reorder.php
index 50409df95..36ba1f66d 100644
--- a/actions/admin/plugins/reorder.php
+++ b/actions/admin/plugins/reorder.php
@@ -1,54 +1,54 @@
-
\ No newline at end of file
diff --git a/actions/admin/site/update_basic.php b/actions/admin/site/update_basic.php
index d56e1d296..31a6b401e 100644
--- a/actions/admin/site/update_basic.php
+++ b/actions/admin/site/update_basic.php
@@ -1,103 +1,103 @@
-description = get_input('sitedescription');
- $site->name = get_input('sitename');
- $site->email = get_input('siteemail');
- $site->url = get_input('wwwroot');
-
- datalist_set('path',sanitise_filepath(get_input('path')));
- datalist_set('dataroot',sanitise_filepath(get_input('dataroot')));
- if (get_input('simplecache_enabled')) {
- elgg_view_enable_simplecache();
- } else {
- elgg_view_disable_simplecache();
+ * @author Curverider Ltd
+
+ * @link http://elgg.org/
+ */
+
+ global $CONFIG;
+
+ // block non-admin users
+ admin_gatekeeper();
+ action_gatekeeper();
+
+ if (get_input('settings') == 'go') {
+
+ if (datalist_get('default_site')) {
+
+ $site = get_entity(datalist_get('default_site'));
+ if (!($site instanceof ElggSite))
+ throw new InstallationException(elgg_echo('InvalidParameterException:NonElggSite'));
+
+ $site->description = get_input('sitedescription');
+ $site->name = get_input('sitename');
+ $site->email = get_input('siteemail');
+ $site->url = get_input('wwwroot');
+
+ datalist_set('path',sanitise_filepath(get_input('path')));
+ datalist_set('dataroot',sanitise_filepath(get_input('dataroot')));
+ if (get_input('simplecache_enabled')) {
+ elgg_view_enable_simplecache();
+ } else {
+ elgg_view_disable_simplecache();
}
if (get_input('viewpath_cache_enabled')) {
elgg_enable_filepath_cache();
} else {
elgg_disable_filepath_cache();
- }
-
- set_config('language', get_input('language'), $site->getGUID());
-
- set_config('default_access', get_input('default_access'), $site->getGUID());
-
- if (get_input('allow_user_default_access')) {
- set_config('allow_user_default_access', 1, $site->getGUID());
- } else {
- set_config('allow_user_default_access', 0, $site->getGUID());
- }
-
- set_config('view', get_input('view'), $site->getGUID());
-
- $debug = get_input('debug');
- if ($debug)
- set_config('debug', 1, $site->getGUID());
- else
- unset_config('debug', $site->getGUID());
-
- $https_login = get_input('https_login');
- if ($https_login)
- set_config('https_login', 1, $site->getGUID());
- else
- unset_config('https_login', $site->getGUID());
-
- $usage = get_input('usage');
- if ($usage)
- unset_config('ping_home', $site->getGUID());
- else
- set_config('ping_home', 'disabled', $site->getGUID());
-
- $api = get_input('api');
- if ($api)
- unset_config('disable_api', $site->getGUID());
- else
- set_config('disable_api', 'disabled', $site->getGUID());
-
- // Now ping home
- //if ((!isset($usage)) || ($usage!='disabled'))
- //{
- // ping_home($site);
- //}
-
- if ($site->save())
- system_message(elgg_echo("admin:configuration:success"));
- else
- register_error(elgg_echo("admin:configuration:fail"));
-
- //header("Location: {$CONFIG->wwwroot}admin/site/");
- forward($_SERVER['HTTP_REFERER']);
- exit;
-
- }
-
- }
-
+ }
+
+ set_config('language', get_input('language'), $site->getGUID());
+
+ set_config('default_access', get_input('default_access'), $site->getGUID());
+
+ if (get_input('allow_user_default_access')) {
+ set_config('allow_user_default_access', 1, $site->getGUID());
+ } else {
+ set_config('allow_user_default_access', 0, $site->getGUID());
+ }
+
+ set_config('view', get_input('view'), $site->getGUID());
+
+ $debug = get_input('debug');
+ if ($debug)
+ set_config('debug', 1, $site->getGUID());
+ else
+ unset_config('debug', $site->getGUID());
+
+ $https_login = get_input('https_login');
+ if ($https_login)
+ set_config('https_login', 1, $site->getGUID());
+ else
+ unset_config('https_login', $site->getGUID());
+
+ $usage = get_input('usage');
+ if ($usage)
+ unset_config('ping_home', $site->getGUID());
+ else
+ set_config('ping_home', 'disabled', $site->getGUID());
+
+ $api = get_input('api');
+ if ($api)
+ unset_config('disable_api', $site->getGUID());
+ else
+ set_config('disable_api', 'disabled', $site->getGUID());
+
+ // Now ping home
+ //if ((!isset($usage)) || ($usage!='disabled'))
+ //{
+ // ping_home($site);
+ //}
+
+ if ($site->save())
+ system_message(elgg_echo("admin:configuration:success"));
+ else
+ register_error(elgg_echo("admin:configuration:fail"));
+
+ //header("Location: {$CONFIG->wwwroot}admin/site/");
+ forward($_SERVER['HTTP_REFERER']);
+ exit;
+
+ }
+
+ }
+
?>
\ No newline at end of file
diff --git a/actions/admin/user/ban.php b/actions/admin/user/ban.php
index 831513a29..1033ec00a 100644
--- a/actions/admin/user/ban.php
+++ b/actions/admin/user/ban.php
@@ -21,15 +21,15 @@
if ( ($obj instanceof ElggUser) && ($obj->canEdit()))
{
// Now actually disable it
- if ($obj->ban('banned')) {
- system_message(elgg_echo('admin:user:ban:yes'));
+ if ($obj->ban('banned')) {
+ system_message(elgg_echo('admin:user:ban:yes'));
}
else
register_error(elgg_echo('admin:user:ban:no'));
- } else {
- $canedit = $obj->canEdit();
- $isinstance = ($obj instanceof ElggUser);
- register_error(elgg_echo('admin:user:ban:no'));
+ } else {
+ $canedit = $obj->canEdit();
+ $isinstance = ($obj instanceof ElggUser);
+ register_error(elgg_echo('admin:user:ban:no'));
}
forward('pg/admin/user/');
diff --git a/actions/comments/add.php b/actions/comments/add.php
index b026c64f0..80478b9ad 100644
--- a/actions/comments/add.php
+++ b/actions/comments/add.php
@@ -1,58 +1,58 @@
-
+ /**
+ * Elgg add comment action
+ *
+ * @package Elgg
+
+ * @author Curverider
+
+ * @link http://elgg.org/
+ */
+
+ // Make sure we're logged in; forward to the front page if not
+ gatekeeper();
+ action_gatekeeper();
+
+ // Get input
+ $entity_guid = (int) get_input('entity_guid');
+ $comment_text = get_input('generic_comment');
+
+ // Let's see if we can get an entity with the specified GUID
+ if ($entity = get_entity($entity_guid)) {
+
+ // If posting the comment was successful, say so
+ if ($entity->annotate('generic_comment',$comment_text,$entity->access_id, $_SESSION['guid'])) {
+
+ if ($entity->owner_guid != $_SESSION['user']->getGUID())
+ notify_user($entity->owner_guid, $_SESSION['user']->getGUID(), elgg_echo('generic_comment:email:subject'),
+ sprintf(
+ elgg_echo('generic_comment:email:body'),
+ $entity->title,
+ $_SESSION['user']->name,
+ $comment_text,
+ $entity->getURL(),
+ $_SESSION['user']->name,
+ $_SESSION['user']->getURL()
+ )
+ );
+
+ system_message(elgg_echo("generic_comment:posted"));
+ //add to river
+ add_to_river('annotation/annotate','comment',$_SESSION['user']->guid,$entity->guid);
+
+
+ } else {
+ register_error(elgg_echo("generic_comment:failure"));
+ }
+
+ } else {
+
+ register_error(elgg_echo("generic_comment:notfound"));
+
+ }
+
+ // Forward to the
+ forward($entity->getURL());
- * @link http://elgg.org/
- */
-
- // Make sure we're logged in; forward to the front page if not
- gatekeeper();
- action_gatekeeper();
-
- // Get input
- $entity_guid = (int) get_input('entity_guid');
- $comment_text = get_input('generic_comment');
-
- // Let's see if we can get an entity with the specified GUID
- if ($entity = get_entity($entity_guid)) {
-
- // If posting the comment was successful, say so
- if ($entity->annotate('generic_comment',$comment_text,$entity->access_id, $_SESSION['guid'])) {
-
- if ($entity->owner_guid != $_SESSION['user']->getGUID())
- notify_user($entity->owner_guid, $_SESSION['user']->getGUID(), elgg_echo('generic_comment:email:subject'),
- sprintf(
- elgg_echo('generic_comment:email:body'),
- $entity->title,
- $_SESSION['user']->name,
- $comment_text,
- $entity->getURL(),
- $_SESSION['user']->name,
- $_SESSION['user']->getURL()
- )
- );
-
- system_message(elgg_echo("generic_comment:posted"));
- //add to river
- add_to_river('annotation/annotate','comment',$_SESSION['user']->guid,$entity->guid);
-
-
- } else {
- register_error(elgg_echo("generic_comment:failure"));
- }
-
- } else {
-
- register_error(elgg_echo("generic_comment:notfound"));
-
- }
-
- // Forward to the
- forward($entity->getURL());
-
?>
\ No newline at end of file
diff --git a/actions/comments/delete.php b/actions/comments/delete.php
index 2d3b9b3fd..dc701973b 100644
--- a/actions/comments/delete.php
+++ b/actions/comments/delete.php
@@ -1,35 +1,35 @@
-
+ /**
+ * Elgg delete comment action
+ *
+ * @package Elgg
+
+ * @author Curverider
+
+ * @link http://elgg.org/
+ */
+
+ // Ensure we're logged in
+ if (!isloggedin()) forward();
+
+ // Make sure we can get the comment in question
+ $annotation_id = (int) get_input('annotation_id');
+ if ($comment = get_annotation($annotation_id)) {
+
+ $entity = get_entity($comment->entity_guid);
+
+ if ($comment->canEdit()) {
+ $comment->delete();
+ system_message(elgg_echo("generic_comment:deleted"));
+ forward($entity->getURL());
+ }
+
+ } else {
+ $url = "";
+ }
+
+ register_error(elgg_echo("generic_comment:notdeleted"));
+ forward($entity->getURL());
- * @link http://elgg.org/
- */
-
- // Ensure we're logged in
- if (!isloggedin()) forward();
-
- // Make sure we can get the comment in question
- $annotation_id = (int) get_input('annotation_id');
- if ($comment = get_annotation($annotation_id)) {
-
- $entity = get_entity($comment->entity_guid);
-
- if ($comment->canEdit()) {
- $comment->delete();
- system_message(elgg_echo("generic_comment:deleted"));
- forward($entity->getURL());
- }
-
- } else {
- $url = "";
- }
-
- register_error(elgg_echo("generic_comment:notdeleted"));
- forward($entity->getURL());
-
?>
\ No newline at end of file
diff --git a/actions/email/save.php b/actions/email/save.php
index 6c166242b..2d226552a 100644
--- a/actions/email/save.php
+++ b/actions/email/save.php
@@ -29,7 +29,7 @@
if (!get_user_by_email($email))
{
-
+
if ($user->email != $email) {
$user->email = $email;
if ($user->save())
@@ -38,7 +38,7 @@
system_message(elgg_echo('email:save:success'));
}
else
- register_error(elgg_echo('email:save:fail'));
+ register_error(elgg_echo('email:save:fail'));
}
}
else
diff --git a/actions/friends/add.php b/actions/friends/add.php
index 004b0eaad..63f1e2d94 100644
--- a/actions/friends/add.php
+++ b/actions/friends/add.php
@@ -1,40 +1,40 @@
-addFriend($friend_guid)) $errors = true;
- } catch (Exception $e) {
- register_error(sprintf(elgg_echo("friends:add:failure"),$friend->name));
- $errors = true;
- }
- if (!$errors){
- // add to river
- add_to_river('friends/river/create','friend',$_SESSION['user']->guid,$friend_guid);
- system_message(sprintf(elgg_echo("friends:add:successful"),$friend->name));
- }
-
- // Forward to the user friends page
- forward("pg/friends/" . $_SESSION['user']->username . "/");
-
+ action_gatekeeper();
+
+ // Get the GUID of the user to friend
+ $friend_guid = get_input('friend');
+ $friend = get_entity($friend_guid);
+
+ $errors = false;
+
+ // Get the user
+ try {
+ if (!$_SESSION['user']->addFriend($friend_guid)) $errors = true;
+ } catch (Exception $e) {
+ register_error(sprintf(elgg_echo("friends:add:failure"),$friend->name));
+ $errors = true;
+ }
+ if (!$errors){
+ // add to river
+ add_to_river('friends/river/create','friend',$_SESSION['user']->guid,$friend_guid);
+ system_message(sprintf(elgg_echo("friends:add:successful"),$friend->name));
+ }
+
+ // Forward to the user friends page
+ forward("pg/friends/" . $_SESSION['user']->username . "/");
+
?>
\ No newline at end of file
diff --git a/actions/friends/addcollection.php b/actions/friends/addcollection.php
index bda98984b..7dfba1ee7 100644
--- a/actions/friends/addcollection.php
+++ b/actions/friends/addcollection.php
@@ -1,50 +1,50 @@
-getGUID());
-
- //if the collection was created and the user passed some friends from the form, add them
- if($create_collection && (!empty($friends))){
-
- //add friends to the collection
- foreach($friends as $friend){
- add_user_to_access_collection($friend, $create_collection);
- }
-
- }
-
- // Success message
- system_message(elgg_echo("friends:collectionadded"));
- // Forward to the collections page
- forward("pg/collections/" . $_SESSION['user']->username);
-
- } else {
-
- register_error(elgg_echo("friends:nocollectionname"));
- // Forward to the add collection page
- forward("pg/collections/add");
-
- }
-
+ action_gatekeeper();
+
+ $collection_name = get_input('collection_name');
+ $friends = get_input('friends_collection');
+
+ //first check to make sure that a collection name has been set and create the new colection
+ if($collection_name){
+
+ //create the collection
+ $create_collection = create_access_collection($collection_name, $_SESSION['user']->getGUID());
+
+ //if the collection was created and the user passed some friends from the form, add them
+ if($create_collection && (!empty($friends))){
+
+ //add friends to the collection
+ foreach($friends as $friend){
+ add_user_to_access_collection($friend, $create_collection);
+ }
+
+ }
+
+ // Success message
+ system_message(elgg_echo("friends:collectionadded"));
+ // Forward to the collections page
+ forward("pg/collections/" . $_SESSION['user']->username);
+
+ } else {
+
+ register_error(elgg_echo("friends:nocollectionname"));
+ // Forward to the add collection page
+ forward("pg/collections/add");
+
+ }
+
?>
\ No newline at end of file
diff --git a/actions/friends/deletecollection.php b/actions/friends/deletecollection.php
index 674e68751..bdfcc9b2c 100644
--- a/actions/friends/deletecollection.php
+++ b/actions/friends/deletecollection.php
@@ -1,52 +1,52 @@
-owner_guid == $_SESSION['user']->getGUID()){
-
- $delete_collection = delete_access_collection($collection_id);
-
- // Success message
+ * @author Curverider Ltd
+
+ * @link http://elgg.org/
+ */
+
+ // Make sure we're logged in (send us to the front page if not)
+ gatekeeper();
+
+ // Get input data
+ $collection_id = (int) get_input('collection');
+
+ // Check to see that the access collection exist and grab its owner
+ $get_collection = get_access_collection($collection_id);
+
+ if($get_collection){
+
+ if($get_collection->owner_guid == $_SESSION['user']->getGUID()){
+
+ $delete_collection = delete_access_collection($collection_id);
+
+ // Success message
if ($delete_collection)
system_message(elgg_echo("friends:collectiondeleted"));
else
- register_error(elgg_echo("friends:collectiondeletefailed"));
-
- } else {
-
- // Failure message
- register_error(elgg_echo("friends:collectiondeletefailed"));
-
- }
-
- } else {
-
- // Failure message
- register_error(elgg_echo("friends:collectiondeletefailed"));
-
- }
-
- // Forward to the collections page
- forward("pg/collections/" . $_SESSION['user']->username);
-
+ register_error(elgg_echo("friends:collectiondeletefailed"));
+
+ } else {
+
+ // Failure message
+ register_error(elgg_echo("friends:collectiondeletefailed"));
+
+ }
+
+ } else {
+
+ // Failure message
+ register_error(elgg_echo("friends:collectiondeletefailed"));
+
+ }
+
+ // Forward to the collections page
+ forward("pg/collections/" . $_SESSION['user']->username);
+
?>
\ No newline at end of file
diff --git a/actions/friends/editcollection.php b/actions/friends/editcollection.php
index a1a38845f..ede61b4b0 100644
--- a/actions/friends/editcollection.php
+++ b/actions/friends/editcollection.php
@@ -1,20 +1,20 @@
-
\ No newline at end of file
diff --git a/actions/friends/remove.php b/actions/friends/remove.php
index d1911bb90..20181bc84 100644
--- a/actions/friends/remove.php
+++ b/actions/friends/remove.php
@@ -1,42 +1,42 @@
-removeFriend($friend_guid);
else
{
register_error(sprintf(elgg_echo("friends:remove:failure"),$friend->name));
$errors = true;
- }
- } catch (Exception $e) {
- register_error(sprintf(elgg_echo("friends:remove:failure"),$friend->name));
- $errors = true;
- }
- if (!$errors)
- system_message(sprintf(elgg_echo("friends:remove:successful"),$friend->name));
-
- // Forward to the user friends page
- forward("pg/friends/" . $_SESSION['user']->username . "/");
-
+ }
+ } catch (Exception $e) {
+ register_error(sprintf(elgg_echo("friends:remove:failure"),$friend->name));
+ $errors = true;
+ }
+ if (!$errors)
+ system_message(sprintf(elgg_echo("friends:remove:successful"),$friend->name));
+
+ // Forward to the user friends page
+ forward("pg/friends/" . $_SESSION['user']->username . "/");
+
?>
\ No newline at end of file
diff --git a/actions/login.php b/actions/login.php
index 1d2b7bc07..f3a60af6d 100644
--- a/actions/login.php
+++ b/actions/login.php
@@ -1,37 +1,37 @@
-validated) {
- // give plugins a chance to respond
- if (!trigger_plugin_hook('unvalidated_login_attempt','user',array('entity'=>$user))) {
- // if plugins have not registered an action, the default action is to
- // trigger the validation event again and assume that the validation
- // event will display an appropriate message
- trigger_elgg_event('validate', 'user', $user);
- }
- } else {
- register_error(elgg_echo('loginerror'));
- }
- access_show_hidden_entities($access_status);
- } else {
- register_error(elgg_echo('loginerror'));
- }
- }
-
+ }
+ } else {
+ $error_msg = elgg_echo('loginerror');
+ // figure out why the login failed
+ if (!empty($username) && !empty($password)) {
+ // See if it exists and is disabled
+ $access_status = access_get_show_hidden_status();
+ access_show_hidden_entities(true);
+ if (($user = get_user_by_username($username)) && !$user->validated) {
+ // give plugins a chance to respond
+ if (!trigger_plugin_hook('unvalidated_login_attempt','user',array('entity'=>$user))) {
+ // if plugins have not registered an action, the default action is to
+ // trigger the validation event again and assume that the validation
+ // event will display an appropriate message
+ trigger_elgg_event('validate', 'user', $user);
+ }
+ } else {
+ register_error(elgg_echo('loginerror'));
+ }
+ access_show_hidden_entities($access_status);
+ } else {
+ register_error(elgg_echo('loginerror'));
+ }
+ }
+
?>
\ No newline at end of file
diff --git a/actions/logout.php b/actions/logout.php
index 078e5a7aa..67ca6ad65 100644
--- a/actions/logout.php
+++ b/actions/logout.php
@@ -1,25 +1,25 @@
-
\ No newline at end of file
diff --git a/actions/register.php b/actions/register.php
index 75721822c..5c69624b3 100644
--- a/actions/register.php
+++ b/actions/register.php
@@ -1,39 +1,39 @@
-disable_registration)
- {
+ {
// For now, just try and register the user
- try {
+ try {
if (
(
(trim($password)!="") &&
@@ -49,21 +49,21 @@
$new_user->admin = 'yes';
}
- // Send user validation request on register only
- global $registering_admin;
+ // Send user validation request on register only
+ global $registering_admin;
if (!$registering_admin)
request_user_validation($guid);
if (!$new_user->admin)
- $new_user->disable('new_user', false); // Now disable if not an admin
- // Don't do a recursive disable. Any entities owned by the user at this point
+ $new_user->disable('new_user', false); // Now disable if not an admin
+ // Don't do a recursive disable. Any entities owned by the user at this point
// are products of plugins that
-
+
system_message(sprintf(elgg_echo("registerok"),$CONFIG->sitename));
- forward(); // Forward on success, assume everything else is an error...
- } else {
- register_error(elgg_echo("registerbad"));
+ forward(); // Forward on success, assume everything else is an error...
+ } else {
+ register_error(elgg_echo("registerbad"));
}
} catch (RegistrationException $r) {
register_error($r->getMessage());
@@ -76,6 +76,6 @@
$qs = $qs[0];
$qs .= "?u=" . urlencode($username) . "&e=" . urlencode($email) . "&n=" . urlencode($name) . "&friend_guid=" . $friend_guid;
- forward($qs);
-
+ forward($qs);
+
?>
\ No newline at end of file
diff --git a/actions/systemsettings/install.php b/actions/systemsettings/install.php
index 1d9f63a9f..8b0a31ced 100644
--- a/actions/systemsettings/install.php
+++ b/actions/systemsettings/install.php
@@ -1,125 +1,125 @@
-name = get_input('sitename');
- $site->url = get_input('wwwroot');
- $site->description = get_input('sitedescription');
- $site->email = get_input('siteemail');
- $site->access_id = ACCESS_PUBLIC;
- $guid = $site->save();
-
- if (!$guid)
- throw new InstallationException(sprintf(elgg_echo('InstallationException:CantCreateSite'), get_input('sitename'), get_input('wwwroot')));
-
- datalist_set('installed',time());
-
- datalist_set('path', $path);
- datalist_set('dataroot', $dataroot);
-
- datalist_set('default_site',$site->getGUID());
-
- set_config('view', get_input('view'), $site->getGUID());
- set_config('language', get_input('language'), $site->getGUID());
- set_config('default_access', get_input('default_access'), $site->getGUID());
-
- $debug = get_input('debug');
- if ($debug)
- set_config('debug', 1, $site->getGUID());
- else
- unset_config('debug', $site->getGUID());
-
- $usage = get_input('usage');
- if (is_array($usage)) $usage = $usage[0];
-
- if ($usage)
- unset_config('ping_home', $site->getGUID());
- else
- set_config('ping_home', 'disabled', $site->getGUID());
-
- $api = get_input('api');
- if ($api)
- unset_config('disable_api', $site->getGUID());
- else
- set_config('disable_api', 'disabled', $site->getGUID());
-
- $https_login = get_input('https_login');
- if ($https_login)
- set_config('https_login', 1, $site->getGUID());
- else
- unset_config('https_login', $site->getGUID());
-
- // activate some plugins by default
- if (isset($CONFIG->default_plugins))
+ * @author Curverider Ltd
+
+ * @link http://elgg.org/
+ */
+
+ elgg_set_viewtype('failsafe'); // Set failsafe again incase we get an exception thrown
+
+ if (is_installed()) forward();
+
+ if (get_input('settings') == 'go') {
+
+ if (!datalist_get('default_site')) {
+
+ // Sanitise
+ $path = sanitise_filepath(get_input('path'));
+ $dataroot = sanitise_filepath(get_input('dataroot'));
+
+ // Blank?
+ if ($dataroot == "/")
+ throw new InstallationException(elgg_echo('InstallationException:DatarootBlank'));
+
+ // That it's valid
+ if (stripos($dataroot, $path)!==false)
+ throw new InstallationException(sprintf(elgg_echo('InstallationException:DatarootUnderPath'), $dataroot));
+
+ // Check data root is writable
+ if (!is_writable($dataroot))
+ throw new InstallationException(sprintf(elgg_echo('InstallationException:DatarootNotWritable'), $dataroot));
+
+
+ $site = new ElggSite();
+ $site->name = get_input('sitename');
+ $site->url = get_input('wwwroot');
+ $site->description = get_input('sitedescription');
+ $site->email = get_input('siteemail');
+ $site->access_id = ACCESS_PUBLIC;
+ $guid = $site->save();
+
+ if (!$guid)
+ throw new InstallationException(sprintf(elgg_echo('InstallationException:CantCreateSite'), get_input('sitename'), get_input('wwwroot')));
+
+ datalist_set('installed',time());
+
+ datalist_set('path', $path);
+ datalist_set('dataroot', $dataroot);
+
+ datalist_set('default_site',$site->getGUID());
+
+ set_config('view', get_input('view'), $site->getGUID());
+ set_config('language', get_input('language'), $site->getGUID());
+ set_config('default_access', get_input('default_access'), $site->getGUID());
+
+ $debug = get_input('debug');
+ if ($debug)
+ set_config('debug', 1, $site->getGUID());
+ else
+ unset_config('debug', $site->getGUID());
+
+ $usage = get_input('usage');
+ if (is_array($usage)) $usage = $usage[0];
+
+ if ($usage)
+ unset_config('ping_home', $site->getGUID());
+ else
+ set_config('ping_home', 'disabled', $site->getGUID());
+
+ $api = get_input('api');
+ if ($api)
+ unset_config('disable_api', $site->getGUID());
+ else
+ set_config('disable_api', 'disabled', $site->getGUID());
+
+ $https_login = get_input('https_login');
+ if ($https_login)
+ set_config('https_login', 1, $site->getGUID());
+ else
+ unset_config('https_login', $site->getGUID());
+
+ // activate some plugins by default
+ if (isset($CONFIG->default_plugins))
{
- if (!is_array($CONFIG->default_plugins))
+ if (!is_array($CONFIG->default_plugins))
$plugins = explode(',', $CONFIG->default_plugins);
else
$CONFIG->default_plugins = $CONFIG->default_plugins;
-
- foreach ($plugins as $plugin)
- enable_plugin(trim($plugin), $site->getGUID());
- }
- else
- {
- enable_plugin('profile', $site->getGUID());
- enable_plugin('river', $site->getGUID());
- enable_plugin('logbrowser', $site->getGUID());
- enable_plugin('diagnostics', $site->getGUID());
+
+ foreach ($plugins as $plugin)
+ enable_plugin(trim($plugin), $site->getGUID());
+ }
+ else
+ {
+ enable_plugin('profile', $site->getGUID());
+ enable_plugin('river', $site->getGUID());
+ enable_plugin('logbrowser', $site->getGUID());
+ enable_plugin('diagnostics', $site->getGUID());
enable_plugin('uservalidationbyemail', $site->getGUID());
- enable_plugin('htmlawed', $site->getGUID());
- }
-
- // Now ping home
- if ($usage)
- {
- ping_home($site);
- }
-
- system_message(elgg_echo("installation:configuration:success"));
-
- header("Location: ../../account/register.php");
- exit;
-
- }
-
- }
-
+ enable_plugin('htmlawed', $site->getGUID());
+ }
+
+ // Now ping home
+ if ($usage)
+ {
+ ping_home($site);
+ }
+
+ system_message(elgg_echo("installation:configuration:success"));
+
+ header("Location: ../../account/register.php");
+ exit;
+
+ }
+
+ }
+
?>
\ No newline at end of file
diff --git a/actions/user/default_access.php b/actions/user/default_access.php
index 0f062ed19..b79200ad0 100644
--- a/actions/user/default_access.php
+++ b/actions/user/default_access.php
@@ -9,8 +9,8 @@
*/
require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
- global $CONFIG;
-
+ global $CONFIG;
+
if ($CONFIG->allow_user_default_access) {
gatekeeper();
@@ -25,7 +25,7 @@
$user = get_entity($user_id);
if ($user)
- {
+ {
$current_default_access = $user->getPrivateSetting('elgg_default_access');
if ($default_access != $current_default_access)
{
@@ -36,7 +36,7 @@
}
}
else
- register_error(elgg_echo('user:default_access:fail'));
+ register_error(elgg_echo('user:default_access:fail'));
}
//forward($_SERVER['HTTP_REFERER']);
diff --git a/actions/user/requestnewpassword.php b/actions/user/requestnewpassword.php
index 2dff5f34d..a54e71b7e 100644
--- a/actions/user/requestnewpassword.php
+++ b/actions/user/requestnewpassword.php
@@ -14,26 +14,26 @@
action_gatekeeper();
$username = get_input('username');
-
- $access_status = access_get_show_hidden_status();
+
+ $access_status = access_get_show_hidden_status();
access_show_hidden_entities(true);
$user = get_user_by_username($username);
if ($user)
- {
+ {
if ($user->validated) {
if (send_new_password_request($user->guid))
system_message(elgg_echo('user:password:resetreq:success'));
else
- register_error(elgg_echo('user:password:resetreq:fail'));
- } else if (!trigger_plugin_hook('unvalidated_requestnewpassword','user',array('entity'=>$user))) {
- // if plugins have not registered an action, the default action is to
- // trigger the validation event again and assume that the validation
- // event will display an appropriate message
- trigger_elgg_event('validate', 'user', $user);
+ register_error(elgg_echo('user:password:resetreq:fail'));
+ } else if (!trigger_plugin_hook('unvalidated_requestnewpassword','user',array('entity'=>$user))) {
+ // if plugins have not registered an action, the default action is to
+ // trigger the validation event again and assume that the validation
+ // event will display an appropriate message
+ trigger_elgg_event('validate', 'user', $user);
}
}
else
- register_error(sprintf(elgg_echo('user:username:notfound'), $username));
+ register_error(sprintf(elgg_echo('user:username:notfound'), $username));
access_show_hidden_entities($access_status);
forward();
diff --git a/actions/user/spotlight.php b/actions/user/spotlight.php
index b43af2f16..8f50df2c8 100644
--- a/actions/user/spotlight.php
+++ b/actions/user/spotlight.php
@@ -1,15 +1,15 @@
-spotlightclosed = $closed;
- exit;
-
+spotlightclosed = $closed;
+ exit;
+
?>
\ No newline at end of file
diff --git a/actions/useradd.php b/actions/useradd.php
index cf4f03ffe..0149a9753 100644
--- a/actions/useradd.php
+++ b/actions/useradd.php
@@ -14,7 +14,7 @@
admin_gatekeeper(); // Only admins can add a user
action_gatekeeper();
- // Get variables
+ // Get variables
global $CONFIG;
$username = get_input('username');
$password = get_input('password');
@@ -40,9 +40,9 @@
$new_user->admin_created = true;
$new_user->created_by_guid = get_loggedin_userid();
-
-
- notify_user($new_user->guid, $CONFIG->site->guid, elgg_echo('useradd:subject'), sprintf(elgg_echo('useradd:body'), $name, $CONFIG->site->name, $CONFIG->site->url, $username, $password));
+
+
+ notify_user($new_user->guid, $CONFIG->site->guid, elgg_echo('useradd:subject'), sprintf(elgg_echo('useradd:body'), $name, $CONFIG->site->name, $CONFIG->site->url, $username, $password));
system_message(sprintf(elgg_echo("adduser:ok"),$CONFIG->sitename));
} else {
diff --git a/actions/usersettings/save.php b/actions/usersettings/save.php
index b720c371a..8c920def1 100644
--- a/actions/usersettings/save.php
+++ b/actions/usersettings/save.php
@@ -1,22 +1,22 @@
-
+ action_gatekeeper();
+
+ trigger_plugin_hook('usersettings:save','user');
+
+ forward($_SERVER['HTTP_REFERER']);
+
+?>
diff --git a/actions/widgets/add.php b/actions/widgets/add.php
index 76aaa3b17..14653eb18 100644
--- a/actions/widgets/add.php
+++ b/actions/widgets/add.php
@@ -1,43 +1,43 @@
-canEdit()) {
+
+ $result = add_widget($user->getGUID(),$handler,$context,0,$column);
+
+ }
+
+ }
+
+ }
+
+ if ($result) {
+ system_message(elgg_echo('widgets:save:success'));
+ } else {
+ register_error(elgg_echo('widgets:save:failure'));
+ }
+
+ forward($_SERVER['HTTP_REFERER']);
- * @link http://elgg.org/
- */
-
- $guid = get_input('user');
- $handler = get_input('handler');
- $context = get_input('context');
- $column = get_input('column');
-
- $result = false;
-
- if (!empty($guid)) {
-
- if ($user = get_entity($guid)) {
-
- if ($user->canEdit()) {
-
- $result = add_widget($user->getGUID(),$handler,$context,0,$column);
-
- }
-
- }
-
- }
-
- if ($result) {
- system_message(elgg_echo('widgets:save:success'));
- } else {
- register_error(elgg_echo('widgets:save:failure'));
- }
-
- forward($_SERVER['HTTP_REFERER']);
-
?>
\ No newline at end of file
diff --git a/actions/widgets/reorder.php b/actions/widgets/reorder.php
index 6f3142e8d..3e3a98ebb 100644
--- a/actions/widgets/reorder.php
+++ b/actions/widgets/reorder.php
@@ -1,32 +1,32 @@
-
\ No newline at end of file
diff --git a/actions/widgets/save.php b/actions/widgets/save.php
index c6e06a12f..6fdf79c11 100644
--- a/actions/widgets/save.php
+++ b/actions/widgets/save.php
@@ -1,38 +1,38 @@
-
\ No newline at end of file
diff --git a/admin/index.php b/admin/index.php
index 969d91f7e..98466cb20 100644
--- a/admin/index.php
+++ b/admin/index.php
@@ -1,21 +1,21 @@
-
\ No newline at end of file
diff --git a/admin/plugins.php b/admin/plugins.php
index dcf0fead0..9900c98e9 100644
--- a/admin/plugins.php
+++ b/admin/plugins.php
@@ -17,9 +17,9 @@
admin_gatekeeper();
// Set admin user for user block
- //set_page_owner($_SESSION['guid']);
-
- // Regenerate plugin list
+ //set_page_owner($_SESSION['guid']);
+
+ // Regenerate plugin list
regenerate_plugin_list();
// Display main admin menu
diff --git a/admin/site.php b/admin/site.php
index dc8aed1a1..c66dc290a 100644
--- a/admin/site.php
+++ b/admin/site.php
@@ -1,26 +1,26 @@
-
\ No newline at end of file
diff --git a/admin/user.php b/admin/user.php
index 84e4f1d83..16b5bf172 100644
--- a/admin/user.php
+++ b/admin/user.php
@@ -1,45 +1,45 @@
-
\ No newline at end of file
diff --git a/dashboard/index.php b/dashboard/index.php
index 260d5b46e..101e74d6d 100644
--- a/dashboard/index.php
+++ b/dashboard/index.php
@@ -1,33 +1,33 @@
-
\ No newline at end of file
diff --git a/dashboard/latest.php b/dashboard/latest.php
index c49b6fc20..cf214a060 100644
--- a/dashboard/latest.php
+++ b/dashboard/latest.php
@@ -1,30 +1,30 @@
-
\ No newline at end of file
diff --git a/engine/handlers/action_handler.php b/engine/handlers/action_handler.php
index 1e769eebd..4878084ad 100644
--- a/engine/handlers/action_handler.php
+++ b/engine/handlers/action_handler.php
@@ -1,21 +1,21 @@
-
+ * @author Curverider Ltd
+
+ * @link http://elgg.org/
+ */
+ /**
+ * Load Elgg framework
+ */
+ define('externalpage',true);
+ require_once("../start.php");
+ $action = get_input("action");
+ action($action);
+
+?>
diff --git a/engine/handlers/cron_handler.php b/engine/handlers/cron_handler.php
index a379a0e20..71a8cf2a4 100644
--- a/engine/handlers/cron_handler.php
+++ b/engine/handlers/cron_handler.php
@@ -8,7 +8,7 @@
* @link http://elgg.org/
*/
- // Load Elgg engine
+ // Load Elgg engine
define('externalpage',true);
require_once("../start.php");
global $CONFIG;
diff --git a/engine/handlers/pagehandler.php b/engine/handlers/pagehandler.php
index 167d54957..506ae9802 100644
--- a/engine/handlers/pagehandler.php
+++ b/engine/handlers/pagehandler.php
@@ -1,27 +1,27 @@
-
\ No newline at end of file
diff --git a/engine/handlers/xml-rpc_handler.php b/engine/handlers/xml-rpc_handler.php
index 6be9b4a09..bc87306c7 100644
--- a/engine/handlers/xml-rpc_handler.php
+++ b/engine/handlers/xml-rpc_handler.php
@@ -8,7 +8,7 @@
* @link http://elgg.org/
*/
- // Load Elgg engine
+ // Load Elgg engine
define('externalpage',true);
require_once("../start.php");
global $CONFIG;
diff --git a/engine/lib/access.php b/engine/lib/access.php
index 7f3a8131f..392c89a2f 100644
--- a/engine/lib/access.php
+++ b/engine/lib/access.php
@@ -1,665 +1,665 @@
-site_id))) $site_id = $CONFIG->site_id;
- $user_id = (int) $user_id;
- $site_id = (int) $site_id;
-
- if (isset($access_list[$user_id])) return $access_list[$user_id];
-
- $access_list[$user_id] = "(" . implode(",",get_access_array($user_id, $site_id, $flush)) . ")";
-
- return $access_list[$user_id];
-
- }
-
- /**
- * Gets an array of access restrictions the given user is allowed to see on this site
- *
- * @param int $user_id User ID; defaults to currently logged in user
- * @param int $site_id Site ID; defaults to current site
- * @param boolean $flush If set to true, will refresh the access list from the database
- * @return array An array of access collections suitable for injection in an SQL call
- */
- function get_access_array($user_id = 0, $site_id = 0, $flush = false) {
-
- global $CONFIG, $init_finished;
- static $access_array, $acm, $ac; // Caches. $ac* flag whether we have executed a query previously, and stop it being run again if no data is returned.
-
- if (!isset($access_array) || (!isset($init_finished)) || (!$init_finished))
- $access_array = array();
-
- if ($user_id == 0) $user_id = get_loggedin_userid();
-
- if (($site_id == 0) && (isset($CONFIG->site_guid))) $site_id = $CONFIG->site_guid;
- $user_id = (int) $user_id;
- $site_id = (int) $site_id;
-
- if (empty($access_array[$user_id]) || $flush == true) {
-
- $query = "SELECT am.access_collection_id FROM {$CONFIG->dbprefix}access_collection_membership am ";
- $query .= " LEFT JOIN {$CONFIG->dbprefix}access_collections ag ON ag.id = am.access_collection_id ";
- $query .= " WHERE am.user_guid = {$user_id} AND (ag.site_guid = {$site_id} OR ag.site_guid = 0)";
-
- $tmp_access_array = array(ACCESS_PUBLIC);
- if (isloggedin()) {
- $tmp_access_array[] = ACCESS_LOGGED_IN;
-
- // The following can only return sensible data if the user is logged in.
-
- if ($collections = get_data($query)) {
- foreach($collections as $collection)
- if (!empty($collection->access_collection_id)) $tmp_access_array[] = $collection->access_collection_id;
-
- }
-
- $query = "SELECT ag.id FROM {$CONFIG->dbprefix}access_collections ag ";
- $query .= " WHERE ag.owner_guid = {$user_id} AND (ag.site_guid = {$site_id} OR ag.site_guid = 0)";
-
- if ($collections = get_data($query)) {
- foreach($collections as $collection)
- if (!empty($collection->id)) $tmp_access_array[] = $collection->id;
- }
-
-
- global $is_admin;
-
- if (isset($is_admin) && $is_admin == true) {
- $tmp_access_array[] = ACCESS_PRIVATE;
- }
-
- $access_array[$user_id] = $tmp_access_array;
- }
- else
- $tmp_return = $tmp_access_array; // No user id logged in so we can only access public info
-
-
- } else {
- $tmp_access_array = $access_array[$user_id];
- }
-
- $tmp_return = $access_array[$user_id];
-
- return trigger_plugin_hook('access:collections:read','user',array('user_id' => $user_id, 'site_id' => $site_id),$tmp_access_array);
- }
-
- /**
- * Gets the default access permission for new content
- *
- * @return int default access id (see ACCESS defines in elgglib.php)
- */
- function get_default_access($user=null)
- {
- global $CONFIG;
-
- if (!$CONFIG->allow_user_default_access) {
- return $CONFIG->default_access;
- }
-
- if (!$user) {
- if (isloggedin()) {
- $user = $_SESSION['user'];
- } else {
- return $CONFIG->default_access;
- }
- }
-
- if (false !== ($default_access = $user->getPrivateSetting('elgg_default_access'))) {
- return $default_access;
- } else {
- return $CONFIG->default_access;
- }
- }
-
- /**
- * Override the default behaviour and allow results to show hidden entities as well.
- * THIS IS A HACK.
- *
- * TODO: Replace this with query object!
- */
- $ENTITY_SHOW_HIDDEN_OVERRIDE = false;
-
- /**
- * This will be replaced. Do not use in plugins!
- *
- * @param bool $show
- */
- function access_show_hidden_entities($show_hidden)
- {
- global $ENTITY_SHOW_HIDDEN_OVERRIDE;
- $ENTITY_SHOW_HIDDEN_OVERRIDE = $show_hidden;
- }
-
- /**
- * This will be replaced. Do not use in plugins!
- */
- function access_get_show_hidden_status()
- {
- global $ENTITY_SHOW_HIDDEN_OVERRIDE;
- return $ENTITY_SHOW_HIDDEN_OVERRIDE;
- }
-
- /**
- * Add annotation restriction
- *
- * Returns an SQL fragment that is true (or optionally false) if the given user has
- * added an annotation with the given name to the given entity.
- *
- * TODO: This is fairly generic so perhaps it could be moved to annotations.php
- *
- * @param string $annotation_name name of the annotation
- * @param string $entity_guid SQL string that evaluates to the GUID of the entity the annotation should be attached to
- * @param string $owner_guid SQL string that evaluates to the GUID of the owner of the annotation *
- * @param boolean $exists If set to true, will return true if the annotation exists, otherwise returns false
- * @return string An SQL fragment suitable for inserting into a WHERE clause
- */
-
- function get_annotation_sql($annotation_name,$entity_guid,$owner_guid,$exists) {
- global $CONFIG;
-
- if ($exists) {
- $not = '';
- } else {
- $not = 'NOT';
- }
-
- $sql = <<dbprefix}annotations a
-INNER JOIN {$CONFIG->dbprefix}metastrings ms ON (a.name_id = ms.id)
-WHERE ms.string = '$annotation_name'
-AND a.entity_guid = $entity_guid
-AND a.owner_guid = $owner_guid)
-END;
- return $sql;
- }
-
- /**
- * Add access restriction sql code to a given query.
- *
- * Note that if this code is executed in privileged mode it will return blank.
- *
- * TODO: DELETE once Query classes are fully integrated
- *
- * @param string $table_prefix Optional xxx. prefix for the access code.
- */
- function get_access_sql_suffix($table_prefix = "",$owner=null)
- {
- global $ENTITY_SHOW_HIDDEN_OVERRIDE, $CONFIG;
-
- $sql = "";
- $friends_bit = "";
- $enemies_bit = "";
-
- if ($table_prefix)
- $table_prefix = sanitise_string($table_prefix) . ".";
-
- $access = get_access_list();
-
- if (!isset($owner)) {
- $owner = get_loggedin_userid();
- }
- if (!$owner) $owner = -1;
-
- global $is_admin;
-
- if (isset($is_admin) && $is_admin == true) {
- $sql = " (1 = 1) ";
- } else if ($owner != -1) {
- $friends_bit = $table_prefix.'access_id = '.ACCESS_FRIENDS.' AND ';
- $friends_bit .= "{$table_prefix}owner_guid IN (SELECT guid_one FROM {$CONFIG->dbprefix}entity_relationships WHERE relationship='friend' AND guid_two=$owner)";
- $friends_bit = '('.$friends_bit.') OR ';
-
- if ((isset($CONFIG->user_block_and_filter_enabled)) && ($CONFIG->user_block_and_filter_enabled)) {
- // check to see if the user is in the entity owner's block list
- // or if the entity owner is in the user's filter list
- // if so, disallow access
-
- $enemies_bit = get_annotation_sql('elgg_block_list',"{$table_prefix}owner_guid",$owner,false);
- $enemies_bit = '('.$enemies_bit. ' AND '.get_annotation_sql('elgg_filter_list',$owner,"{$table_prefix}owner_guid",false).')';
- }
- }
-
- if (empty($sql))
- $sql = " $friends_bit ({$table_prefix}access_id in {$access} or ({$table_prefix}owner_guid = {$owner}) or ({$table_prefix}access_id = " . ACCESS_PRIVATE . " and {$table_prefix}owner_guid = $owner))";
-
- if ($enemies_bit) {
- $sql = "$enemies_bit AND ($sql)";
- }
-
- if (!$ENTITY_SHOW_HIDDEN_OVERRIDE)
- $sql .= " and {$table_prefix}enabled='yes'";
- return '('.$sql.')';
- }
-
- /**
- * Determines whether the given user has access to the given entity
- *
- * @param ElggEntity $entity The entity to check access for.
- * @param ElggUser $user Optionally the user to check access for.
- *
- * @return boolean True if the user can access the entity
- */
-
- function has_access_to_entity($entity,$user = null) {
- global $CONFIG;
-
- if (!isset($user)) {
- $access_bit = get_access_sql_suffix("e");
- } else {
- $access_bit = get_access_sql_suffix("e",$user->getGUID());
- }
-
- $query = "SELECT guid from {$CONFIG->dbprefix}entities e WHERE e.guid = ".$entity->getGUID();
- $query .= " AND ".$access_bit; // Add access controls
- if (get_data($query)) {
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * Returns an array of access permissions that the specified user is allowed to save objects with.
- * Permissions are of the form ('id' => 'Description')
- *
- * @param int $user_id The user's GUID.
- * @param int $site_id The current site.
- * @param true|false $flush If this is set to true, this will shun any cached version
- * @return array List of access permissions=
- */
- function get_write_access_array($user_id = 0, $site_id = 0, $flush = false) {
-
- global $CONFIG;
- static $access_array;
-
- if ($user_id == 0) $user_id = get_loggedin_userid();
- if (($site_id == 0) && (isset($CONFIG->site_id))) $site_id = $CONFIG->site_id;
- $user_id = (int) $user_id;
- $site_id = (int) $site_id;
-
- if (empty($access_array[$user_id]) || $flush == true) {
-
- $query = "SELECT ag.* FROM {$CONFIG->dbprefix}access_collections ag ";
- $query .= " WHERE (ag.site_guid = {$site_id} OR ag.site_guid = 0)";
- $query .= " AND (ag.owner_guid = {$user_id})";
- $query .= " AND ag.id >= 3";
-
- $tmp_access_array = array(0 => elgg_echo("PRIVATE"), ACCESS_FRIENDS => elgg_echo("access:friends:label"), 1 => elgg_echo("LOGGED_IN"), 2 => elgg_echo("PUBLIC"));
- if ($collections = get_data($query)) {
- foreach($collections as $collection)
- $tmp_access_array[$collection->id] = $collection->name;
- }
-
- $access_array[$user_id] = $tmp_access_array;
-
- } else {
- $tmp_access_array = $access_array[$user_id];
- }
-
- $tmp_access_array = trigger_plugin_hook('access:collections:write','user',array('user_id' => $user_id, 'site_id' => $site_id),$tmp_access_array);
-
- return $tmp_access_array;
-
- }
-
- /**
- * Creates a new access control collection owned by the specified user.
- *
- * @param string $name The name of the collection.
- * @param int $owner_guid The GUID of the owner (default: currently logged in user).
- * @param int $site_guid The GUID of the site (default: current site).
- * @return int|false Depending on success (the collection ID if successful).
- */
- function create_access_collection($name, $owner_guid = 0, $site_guid = 0) {
-
- global $CONFIG;
-
- $name = trim($name);
- if (empty($name)) return false;
-
- if ($owner_guid == 0) $owner_guid = get_loggedin_userid();
- if (($site_id == 0) && (isset($CONFIG->site_guid))) $site_id = $CONFIG->site_guid;
- $name = sanitise_string($name);
-
- return insert_data("insert into {$CONFIG->dbprefix}access_collections set name = '{$name}', owner_guid = {$owner_guid}, site_guid = {$site_id}");
-
- }
-
- /**
- * Updates the membership in an access collection.
- *
- * @param int $collection_id The ID of the collection.
- * @param array $members Array of member GUIDs
- * @return true|false Depending on success
- */
- function update_access_collection($collection_id, $members) {
-
- global $CONFIG;
- $collection_id = (int) $collection_id;
-
- $collections = get_write_access_array();
-
- if (array_key_exists($collection_id, $collections)) {
-
- delete_data("delete from {$CONFIG->dbprefix}access_collection_membership where access_collection_id = {$collection_id}");
-
- if (is_array($members) && sizeof($members) > 0) {
- foreach($members as $member) {
- $member = (int) $member;
- if (get_user($member))
- insert_data("insert into {$CONFIG->dbprefix}access_collection_membership set access_collection_id = {$collection_id}, user_guid = {$member}");
- }
- return true;
- }
-
- }
-
- return false;
- }
-
- /**
- * Deletes a specified access collection
- *
- * @param int $collection_id The collection ID
- * @return true|false Depending on success
- */
- function delete_access_collection($collection_id) {
-
- $collection_id = (int) $collection_id;
- $collections = get_write_access_array();
- if (array_key_exists($collection_id, $collections)) {
- global $CONFIG;
- delete_data("delete from {$CONFIG->dbprefix}access_collection_membership where access_collection_id = {$collection_id}");
- delete_data("delete from {$CONFIG->dbprefix}access_collections where id = {$collection_id}");
- return true;
- } else {
- return false;
- }
-
- }
-
- /**
- * Get a specified access collection
- *
- * @param int $collection_id The collection ID
- * @return array|false Depending on success
- */
- function get_access_collection($collection_id) {
-
- $collection_id = (int) $collection_id;
- global $CONFIG;
- $get_collection = get_data_row("SELECT * FROM {$CONFIG->dbprefix}access_collections WHERE id = {$collection_id}");
-
- return $get_collection;
-
- }
-
- /**
- * Adds a user to the specified user collection
- *
- * @param int $user_guid The GUID of the user to add
- * @param int $collection_id The ID of the collection to add them to
- * @return true|false Depending on success
- */
- function add_user_to_access_collection($user_guid, $collection_id) {
-
- $collection_id = (int) $collection_id;
- $user_guid = (int) $user_guid;
- $collections = get_write_access_array();
-
- if (!($collection = get_access_collection($collection_id)))
- return false;
-
- if ((array_key_exists($collection_id, $collections) || $collection->owner_guid == 0)
- && $user = get_user($user_guid)) {
-
- global $CONFIG;
- try {
- insert_data("insert into {$CONFIG->dbprefix}access_collection_membership set access_collection_id = {$collection_id}, user_guid = {$user_guid}");
- } catch (DatabaseException $e) {}
- return true;
-
- }
-
- return false;
-
- }
-
- /**
- * Removes a user from an access collection
- *
- * @param int $user_guid The user GUID
- * @param int $collection_id The access collection ID
- * @return true|false Depending on success
- */
- function remove_user_from_access_collection($user_guid, $collection_id) {
-
- $collection_id = (int) $collection_id;
- $user_guid = (int) $user_guid;
- $collections = get_write_access_array();
-
- if (!($collection = get_access_collection($collection_id)))
- return false;
-
- if ((array_key_exists($collection_id, $collections) || $collection->owner_guid == 0) && $user = get_user($user_guid)) {
-
- global $CONFIG;
- delete_data("delete from {$CONFIG->dbprefix}access_collection_membership where access_collection_id = {$collection_id} and user_guid = {$user_guid}");
- return true;
-
- }
-
- return false;
-
- }
-
- /**
- * Get all of a users collections
- *
- * @param int $owner_guid The user ID
- * @return true|false Depending on success
- */
- function get_user_access_collections($owner_guid) {
-
- $owner_guid = (int) $owner_guid;
-
- global $CONFIG;
-
- $collections = get_data("SELECT * FROM {$CONFIG->dbprefix}access_collections WHERE owner_guid = {$owner_guid}");
-
- return $collections;
-
- }
-
- /**
- * Get all of members of a friend collection
- *
- * @param int $collection The collection's ID
- * @param true|false $idonly If set to true, will only return the members' IDs (default: false)
- * @return ElggUser entities if successful, false if not
- */
- function get_members_of_access_collection($collection, $idonly = false) {
-
- $collection = (int)$collection;
-
- global $CONFIG;
-
- if (!$idonly) {
- $query = "SELECT e.* FROM {$CONFIG->dbprefix}access_collection_membership m JOIN {$CONFIG->dbprefix}entities e ON e.guid = m.user_guid WHERE m.access_collection_id = {$collection}";
- $collection_members = get_data($query, "entity_row_to_elggstar");
- } else {
- $query = "SELECT e.guid FROM {$CONFIG->dbprefix}access_collection_membership m JOIN {$CONFIG->dbprefix}entities e ON e.guid = m.user_guid WHERE m.access_collection_id = {$collection}";
- $collection_members = get_data($query);
- foreach($collection_members as $key => $val)
- $collection_members[$key] = $val->guid;
- }
-
- return $collection_members;
-
- }
-
- /**
- * Displays a user's access collections, using the friends/collections view
- *
- * @param int $owner_guid The GUID of the owning user
- * @return string A formatted rendition of the collections
- */
- function elgg_view_access_collections($owner_guid) {
-
- if ($collections = get_user_access_collections($owner_guid)) {
-
- foreach($collections as $key => $collection) {
- $collections[$key]->members = get_members_of_access_collection($collection->id, true);
- $collections[$key]->entities = get_user_friends($owner_guid,"",9999);
- }
-
- }
-
- return elgg_view('friends/collections',array('collections' => $collections));
-
- }
-
- /**
- * Get entities with the specified access collection id.
- *
- * @param $collection_id
- * @param $entity_type
- * @param $entity_subtype
- * @param $owner_guid
- * @param $limit
- * @param $offset
- * @param $order_by
- * @param $site_guid
- * @param $count
- * @return unknown_type
- */
- function get_entities_from_access_collection($collection_id, $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $offset = 0, $order_by = "", $site_guid = 0, $count = false) {
- global $CONFIG;
-
- if (!$collection_id)
- return false;
-
- $entity_type = sanitise_string($entity_type);
- $entity_subtype = get_subtype_id($entity_type, $entity_subtype);
- $limit = (int)$limit;
- $offset = (int)$offset;
- if ($order_by == "")
- $order_by = "e.time_created desc";
- else
- $order_by = "e.time_created, {$order_by}";
- $order_by = sanitise_string($order_by);
- $site_guid = (int) $site_guid;
- if ((is_array($owner_guid) && (count($owner_guid)))) {
- foreach($owner_guid as $key => $guid) {
- $owner_guid[$key] = (int) $guid;
- }
- } else {
- $owner_guid = (int) $owner_guid;
- }
- if ($site_guid == 0)
- $site_guid = $CONFIG->site_guid;
-
- //$access = get_access_list();
-
- $where = array("e.access_id = $collection_id");
-
- if ($entity_type!=="")
- $where[] = "e.type='$entity_type'";
- if ($entity_subtype)
- $where[] = "e.subtype=$entity_subtype";
- if ($site_guid > 0)
- $where[] = "e.site_guid = {$site_guid}";
- if (is_array($owner_guid)) {
- $where[] = "e.container_guid in (".implode(",",$owner_guid).")";
- } else if ($owner_guid > 0)
- $where[] = "e.container_guid = {$owner_guid}";
-
- if (!$count) {
- $query = "SELECT distinct e.* ";
- } else {
- $query = "SELECT count(distinct e.guid) as total ";
- }
-
- $query .= "from {$CONFIG->dbprefix}entities e where";
- foreach ($where as $w)
- $query .= " $w and ";
- $query .= get_access_sql_suffix("e"); // Add access controls
- //$query .= ' and ' . get_access_sql_suffix("m"); // Add access controls
-
- if (!$count) {
- $query .= " order by $order_by limit $offset, $limit"; // Add order and limit
- return get_data($query, "entity_row_to_elggstar");
- } else {
- if ($row = get_data_row($query))
- return $row->total;
- }
- return false;
- }
-
- /**
- * Lists entities from an access collection
- *
- * @param $collection_id
- * @param $entity_type
- * @param $entity_subtype
- * @param $owner_guid
- * @param $limit
- * @param $fullview
- * @param $viewtypetoggle
- * @param $pagination
- * @return str
- */
- function list_entities_from_access_collection($collection_id, $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $fullview = true, $viewtypetoggle = true, $pagination = true) {
- $offset = (int) get_input('offset');
- $limit = (int) $limit;
- $count = get_entities_from_access_collection($collection_id, $entity_type, $entity_subtype, $owner_guid, $limit, $offset, "", 0, true);
- $entities = get_entities_from_access_collection($collection_id, $entity_type, $entity_subtype, $owner_guid, $limit, $offset, "", 0, false);
-
- return elgg_view_entity_list($entities, $count, $offset, $limit, $fullview, $viewtypetoggle, $pagination);
- }
-
- global $init_finished;
- $init_finished = false;
-
- /**
- * A quick and dirty way to make sure the access permissions have been correctly set up
- *
- */
- function access_init() {
- global $init_finished;
- $init_finished = true;
- }
-
- // This function will let us know when 'init' has finished
- register_elgg_event_handler('init','system','access_init',9999);
-
+ * @author Curverider Ltd
+
+ * @link http://elgg.org/
+ */
+
+ /**
+ * Get the list of access restrictions the given user is allowed to see on this site
+ *
+ * @uses get_access_array
+ * @param int $user_id User ID; defaults to currently logged in user
+ * @param int $site_id Site ID; defaults to current site
+ * @param boolean $flush If set to true, will refresh the access list from the database
+ * @return string A list of access collections suitable for injection in an SQL call
+ */
+ function get_access_list($user_id = 0, $site_id = 0, $flush = false) {
+
+ global $CONFIG, $init_finished, $SESSION;
+ static $access_list;
+
+ if (!isset($access_list) || !$init_finished)
+ $access_list = array();
+
+ if ($user_id == 0) $user_id = $SESSION['id'];
+ if (($site_id == 0) && (isset($CONFIG->site_id))) $site_id = $CONFIG->site_id;
+ $user_id = (int) $user_id;
+ $site_id = (int) $site_id;
+
+ if (isset($access_list[$user_id])) return $access_list[$user_id];
+
+ $access_list[$user_id] = "(" . implode(",",get_access_array($user_id, $site_id, $flush)) . ")";
+
+ return $access_list[$user_id];
+
+ }
+
+ /**
+ * Gets an array of access restrictions the given user is allowed to see on this site
+ *
+ * @param int $user_id User ID; defaults to currently logged in user
+ * @param int $site_id Site ID; defaults to current site
+ * @param boolean $flush If set to true, will refresh the access list from the database
+ * @return array An array of access collections suitable for injection in an SQL call
+ */
+ function get_access_array($user_id = 0, $site_id = 0, $flush = false) {
+
+ global $CONFIG, $init_finished;
+ static $access_array, $acm, $ac; // Caches. $ac* flag whether we have executed a query previously, and stop it being run again if no data is returned.
+
+ if (!isset($access_array) || (!isset($init_finished)) || (!$init_finished))
+ $access_array = array();
+
+ if ($user_id == 0) $user_id = get_loggedin_userid();
+
+ if (($site_id == 0) && (isset($CONFIG->site_guid))) $site_id = $CONFIG->site_guid;
+ $user_id = (int) $user_id;
+ $site_id = (int) $site_id;
+
+ if (empty($access_array[$user_id]) || $flush == true) {
+
+ $query = "SELECT am.access_collection_id FROM {$CONFIG->dbprefix}access_collection_membership am ";
+ $query .= " LEFT JOIN {$CONFIG->dbprefix}access_collections ag ON ag.id = am.access_collection_id ";
+ $query .= " WHERE am.user_guid = {$user_id} AND (ag.site_guid = {$site_id} OR ag.site_guid = 0)";
+
+ $tmp_access_array = array(ACCESS_PUBLIC);
+ if (isloggedin()) {
+ $tmp_access_array[] = ACCESS_LOGGED_IN;
+
+ // The following can only return sensible data if the user is logged in.
+
+ if ($collections = get_data($query)) {
+ foreach($collections as $collection)
+ if (!empty($collection->access_collection_id)) $tmp_access_array[] = $collection->access_collection_id;
+
+ }
+
+ $query = "SELECT ag.id FROM {$CONFIG->dbprefix}access_collections ag ";
+ $query .= " WHERE ag.owner_guid = {$user_id} AND (ag.site_guid = {$site_id} OR ag.site_guid = 0)";
+
+ if ($collections = get_data($query)) {
+ foreach($collections as $collection)
+ if (!empty($collection->id)) $tmp_access_array[] = $collection->id;
+ }
+
+
+ global $is_admin;
+
+ if (isset($is_admin) && $is_admin == true) {
+ $tmp_access_array[] = ACCESS_PRIVATE;
+ }
+
+ $access_array[$user_id] = $tmp_access_array;
+ }
+ else
+ $tmp_return = $tmp_access_array; // No user id logged in so we can only access public info
+
+
+ } else {
+ $tmp_access_array = $access_array[$user_id];
+ }
+
+ $tmp_return = $access_array[$user_id];
+
+ return trigger_plugin_hook('access:collections:read','user',array('user_id' => $user_id, 'site_id' => $site_id),$tmp_access_array);
+ }
+
+ /**
+ * Gets the default access permission for new content
+ *
+ * @return int default access id (see ACCESS defines in elgglib.php)
+ */
+ function get_default_access($user=null)
+ {
+ global $CONFIG;
+
+ if (!$CONFIG->allow_user_default_access) {
+ return $CONFIG->default_access;
+ }
+
+ if (!$user) {
+ if (isloggedin()) {
+ $user = $_SESSION['user'];
+ } else {
+ return $CONFIG->default_access;
+ }
+ }
+
+ if (false !== ($default_access = $user->getPrivateSetting('elgg_default_access'))) {
+ return $default_access;
+ } else {
+ return $CONFIG->default_access;
+ }
+ }
+
+ /**
+ * Override the default behaviour and allow results to show hidden entities as well.
+ * THIS IS A HACK.
+ *
+ * TODO: Replace this with query object!
+ */
+ $ENTITY_SHOW_HIDDEN_OVERRIDE = false;
+
+ /**
+ * This will be replaced. Do not use in plugins!
+ *
+ * @param bool $show
+ */
+ function access_show_hidden_entities($show_hidden)
+ {
+ global $ENTITY_SHOW_HIDDEN_OVERRIDE;
+ $ENTITY_SHOW_HIDDEN_OVERRIDE = $show_hidden;
+ }
+
+ /**
+ * This will be replaced. Do not use in plugins!
+ */
+ function access_get_show_hidden_status()
+ {
+ global $ENTITY_SHOW_HIDDEN_OVERRIDE;
+ return $ENTITY_SHOW_HIDDEN_OVERRIDE;
+ }
+
+ /**
+ * Add annotation restriction
+ *
+ * Returns an SQL fragment that is true (or optionally false) if the given user has
+ * added an annotation with the given name to the given entity.
+ *
+ * TODO: This is fairly generic so perhaps it could be moved to annotations.php
+ *
+ * @param string $annotation_name name of the annotation
+ * @param string $entity_guid SQL string that evaluates to the GUID of the entity the annotation should be attached to
+ * @param string $owner_guid SQL string that evaluates to the GUID of the owner of the annotation *
+ * @param boolean $exists If set to true, will return true if the annotation exists, otherwise returns false
+ * @return string An SQL fragment suitable for inserting into a WHERE clause
+ */
+
+ function get_annotation_sql($annotation_name,$entity_guid,$owner_guid,$exists) {
+ global $CONFIG;
+
+ if ($exists) {
+ $not = '';
+ } else {
+ $not = 'NOT';
+ }
+
+ $sql = <<dbprefix}annotations a
+INNER JOIN {$CONFIG->dbprefix}metastrings ms ON (a.name_id = ms.id)
+WHERE ms.string = '$annotation_name'
+AND a.entity_guid = $entity_guid
+AND a.owner_guid = $owner_guid)
+END;
+ return $sql;
+ }
+
+ /**
+ * Add access restriction sql code to a given query.
+ *
+ * Note that if this code is executed in privileged mode it will return blank.
+ *
+ * TODO: DELETE once Query classes are fully integrated
+ *
+ * @param string $table_prefix Optional xxx. prefix for the access code.
+ */
+ function get_access_sql_suffix($table_prefix = "",$owner=null)
+ {
+ global $ENTITY_SHOW_HIDDEN_OVERRIDE, $CONFIG;
+
+ $sql = "";
+ $friends_bit = "";
+ $enemies_bit = "";
+
+ if ($table_prefix)
+ $table_prefix = sanitise_string($table_prefix) . ".";
+
+ $access = get_access_list();
+
+ if (!isset($owner)) {
+ $owner = get_loggedin_userid();
+ }
+ if (!$owner) $owner = -1;
+
+ global $is_admin;
+
+ if (isset($is_admin) && $is_admin == true) {
+ $sql = " (1 = 1) ";
+ } else if ($owner != -1) {
+ $friends_bit = $table_prefix.'access_id = '.ACCESS_FRIENDS.' AND ';
+ $friends_bit .= "{$table_prefix}owner_guid IN (SELECT guid_one FROM {$CONFIG->dbprefix}entity_relationships WHERE relationship='friend' AND guid_two=$owner)";
+ $friends_bit = '('.$friends_bit.') OR ';
+
+ if ((isset($CONFIG->user_block_and_filter_enabled)) && ($CONFIG->user_block_and_filter_enabled)) {
+ // check to see if the user is in the entity owner's block list
+ // or if the entity owner is in the user's filter list
+ // if so, disallow access
+
+ $enemies_bit = get_annotation_sql('elgg_block_list',"{$table_prefix}owner_guid",$owner,false);
+ $enemies_bit = '('.$enemies_bit. ' AND '.get_annotation_sql('elgg_filter_list',$owner,"{$table_prefix}owner_guid",false).')';
+ }
+ }
+
+ if (empty($sql))
+ $sql = " $friends_bit ({$table_prefix}access_id in {$access} or ({$table_prefix}owner_guid = {$owner}) or ({$table_prefix}access_id = " . ACCESS_PRIVATE . " and {$table_prefix}owner_guid = $owner))";
+
+ if ($enemies_bit) {
+ $sql = "$enemies_bit AND ($sql)";
+ }
+
+ if (!$ENTITY_SHOW_HIDDEN_OVERRIDE)
+ $sql .= " and {$table_prefix}enabled='yes'";
+ return '('.$sql.')';
+ }
+
+ /**
+ * Determines whether the given user has access to the given entity
+ *
+ * @param ElggEntity $entity The entity to check access for.
+ * @param ElggUser $user Optionally the user to check access for.
+ *
+ * @return boolean True if the user can access the entity
+ */
+
+ function has_access_to_entity($entity,$user = null) {
+ global $CONFIG;
+
+ if (!isset($user)) {
+ $access_bit = get_access_sql_suffix("e");
+ } else {
+ $access_bit = get_access_sql_suffix("e",$user->getGUID());
+ }
+
+ $query = "SELECT guid from {$CONFIG->dbprefix}entities e WHERE e.guid = ".$entity->getGUID();
+ $query .= " AND ".$access_bit; // Add access controls
+ if (get_data($query)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Returns an array of access permissions that the specified user is allowed to save objects with.
+ * Permissions are of the form ('id' => 'Description')
+ *
+ * @param int $user_id The user's GUID.
+ * @param int $site_id The current site.
+ * @param true|false $flush If this is set to true, this will shun any cached version
+ * @return array List of access permissions=
+ */
+ function get_write_access_array($user_id = 0, $site_id = 0, $flush = false) {
+
+ global $CONFIG;
+ static $access_array;
+
+ if ($user_id == 0) $user_id = get_loggedin_userid();
+ if (($site_id == 0) && (isset($CONFIG->site_id))) $site_id = $CONFIG->site_id;
+ $user_id = (int) $user_id;
+ $site_id = (int) $site_id;
+
+ if (empty($access_array[$user_id]) || $flush == true) {
+
+ $query = "SELECT ag.* FROM {$CONFIG->dbprefix}access_collections ag ";
+ $query .= " WHERE (ag.site_guid = {$site_id} OR ag.site_guid = 0)";
+ $query .= " AND (ag.owner_guid = {$user_id})";
+ $query .= " AND ag.id >= 3";
+
+ $tmp_access_array = array(0 => elgg_echo("PRIVATE"), ACCESS_FRIENDS => elgg_echo("access:friends:label"), 1 => elgg_echo("LOGGED_IN"), 2 => elgg_echo("PUBLIC"));
+ if ($collections = get_data($query)) {
+ foreach($collections as $collection)
+ $tmp_access_array[$collection->id] = $collection->name;
+ }
+
+ $access_array[$user_id] = $tmp_access_array;
+
+ } else {
+ $tmp_access_array = $access_array[$user_id];
+ }
+
+ $tmp_access_array = trigger_plugin_hook('access:collections:write','user',array('user_id' => $user_id, 'site_id' => $site_id),$tmp_access_array);
+
+ return $tmp_access_array;
+
+ }
+
+ /**
+ * Creates a new access control collection owned by the specified user.
+ *
+ * @param string $name The name of the collection.
+ * @param int $owner_guid The GUID of the owner (default: currently logged in user).
+ * @param int $site_guid The GUID of the site (default: current site).
+ * @return int|false Depending on success (the collection ID if successful).
+ */
+ function create_access_collection($name, $owner_guid = 0, $site_guid = 0) {
+
+ global $CONFIG;
+
+ $name = trim($name);
+ if (empty($name)) return false;
+
+ if ($owner_guid == 0) $owner_guid = get_loggedin_userid();
+ if (($site_id == 0) && (isset($CONFIG->site_guid))) $site_id = $CONFIG->site_guid;
+ $name = sanitise_string($name);
+
+ return insert_data("insert into {$CONFIG->dbprefix}access_collections set name = '{$name}', owner_guid = {$owner_guid}, site_guid = {$site_id}");
+
+ }
+
+ /**
+ * Updates the membership in an access collection.
+ *
+ * @param int $collection_id The ID of the collection.
+ * @param array $members Array of member GUIDs
+ * @return true|false Depending on success
+ */
+ function update_access_collection($collection_id, $members) {
+
+ global $CONFIG;
+ $collection_id = (int) $collection_id;
+
+ $collections = get_write_access_array();
+
+ if (array_key_exists($collection_id, $collections)) {
+
+ delete_data("delete from {$CONFIG->dbprefix}access_collection_membership where access_collection_id = {$collection_id}");
+
+ if (is_array($members) && sizeof($members) > 0) {
+ foreach($members as $member) {
+ $member = (int) $member;
+ if (get_user($member))
+ insert_data("insert into {$CONFIG->dbprefix}access_collection_membership set access_collection_id = {$collection_id}, user_guid = {$member}");
+ }
+ return true;
+ }
+
+ }
+
+ return false;
+ }
+
+ /**
+ * Deletes a specified access collection
+ *
+ * @param int $collection_id The collection ID
+ * @return true|false Depending on success
+ */
+ function delete_access_collection($collection_id) {
+
+ $collection_id = (int) $collection_id;
+ $collections = get_write_access_array();
+ if (array_key_exists($collection_id, $collections)) {
+ global $CONFIG;
+ delete_data("delete from {$CONFIG->dbprefix}access_collection_membership where access_collection_id = {$collection_id}");
+ delete_data("delete from {$CONFIG->dbprefix}access_collections where id = {$collection_id}");
+ return true;
+ } else {
+ return false;
+ }
+
+ }
+
+ /**
+ * Get a specified access collection
+ *
+ * @param int $collection_id The collection ID
+ * @return array|false Depending on success
+ */
+ function get_access_collection($collection_id) {
+
+ $collection_id = (int) $collection_id;
+ global $CONFIG;
+ $get_collection = get_data_row("SELECT * FROM {$CONFIG->dbprefix}access_collections WHERE id = {$collection_id}");
+
+ return $get_collection;
+
+ }
+
+ /**
+ * Adds a user to the specified user collection
+ *
+ * @param int $user_guid The GUID of the user to add
+ * @param int $collection_id The ID of the collection to add them to
+ * @return true|false Depending on success
+ */
+ function add_user_to_access_collection($user_guid, $collection_id) {
+
+ $collection_id = (int) $collection_id;
+ $user_guid = (int) $user_guid;
+ $collections = get_write_access_array();
+
+ if (!($collection = get_access_collection($collection_id)))
+ return false;
+
+ if ((array_key_exists($collection_id, $collections) || $collection->owner_guid == 0)
+ && $user = get_user($user_guid)) {
+
+ global $CONFIG;
+ try {
+ insert_data("insert into {$CONFIG->dbprefix}access_collection_membership set access_collection_id = {$collection_id}, user_guid = {$user_guid}");
+ } catch (DatabaseException $e) {}
+ return true;
+
+ }
+
+ return false;
+
+ }
+
+ /**
+ * Removes a user from an access collection
+ *
+ * @param int $user_guid The user GUID
+ * @param int $collection_id The access collection ID
+ * @return true|false Depending on success
+ */
+ function remove_user_from_access_collection($user_guid, $collection_id) {
+
+ $collection_id = (int) $collection_id;
+ $user_guid = (int) $user_guid;
+ $collections = get_write_access_array();
+
+ if (!($collection = get_access_collection($collection_id)))
+ return false;
+
+ if ((array_key_exists($collection_id, $collections) || $collection->owner_guid == 0) && $user = get_user($user_guid)) {
+
+ global $CONFIG;
+ delete_data("delete from {$CONFIG->dbprefix}access_collection_membership where access_collection_id = {$collection_id} and user_guid = {$user_guid}");
+ return true;
+
+ }
+
+ return false;
+
+ }
+
+ /**
+ * Get all of a users collections
+ *
+ * @param int $owner_guid The user ID
+ * @return true|false Depending on success
+ */
+ function get_user_access_collections($owner_guid) {
+
+ $owner_guid = (int) $owner_guid;
+
+ global $CONFIG;
+
+ $collections = get_data("SELECT * FROM {$CONFIG->dbprefix}access_collections WHERE owner_guid = {$owner_guid}");
+
+ return $collections;
+
+ }
+
+ /**
+ * Get all of members of a friend collection
+ *
+ * @param int $collection The collection's ID
+ * @param true|false $idonly If set to true, will only return the members' IDs (default: false)
+ * @return ElggUser entities if successful, false if not
+ */
+ function get_members_of_access_collection($collection, $idonly = false) {
+
+ $collection = (int)$collection;
+
+ global $CONFIG;
+
+ if (!$idonly) {
+ $query = "SELECT e.* FROM {$CONFIG->dbprefix}access_collection_membership m JOIN {$CONFIG->dbprefix}entities e ON e.guid = m.user_guid WHERE m.access_collection_id = {$collection}";
+ $collection_members = get_data($query, "entity_row_to_elggstar");
+ } else {
+ $query = "SELECT e.guid FROM {$CONFIG->dbprefix}access_collection_membership m JOIN {$CONFIG->dbprefix}entities e ON e.guid = m.user_guid WHERE m.access_collection_id = {$collection}";
+ $collection_members = get_data($query);
+ foreach($collection_members as $key => $val)
+ $collection_members[$key] = $val->guid;
+ }
+
+ return $collection_members;
+
+ }
+
+ /**
+ * Displays a user's access collections, using the friends/collections view
+ *
+ * @param int $owner_guid The GUID of the owning user
+ * @return string A formatted rendition of the collections
+ */
+ function elgg_view_access_collections($owner_guid) {
+
+ if ($collections = get_user_access_collections($owner_guid)) {
+
+ foreach($collections as $key => $collection) {
+ $collections[$key]->members = get_members_of_access_collection($collection->id, true);
+ $collections[$key]->entities = get_user_friends($owner_guid,"",9999);
+ }
+
+ }
+
+ return elgg_view('friends/collections',array('collections' => $collections));
+
+ }
+
+ /**
+ * Get entities with the specified access collection id.
+ *
+ * @param $collection_id
+ * @param $entity_type
+ * @param $entity_subtype
+ * @param $owner_guid
+ * @param $limit
+ * @param $offset
+ * @param $order_by
+ * @param $site_guid
+ * @param $count
+ * @return unknown_type
+ */
+ function get_entities_from_access_collection($collection_id, $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $offset = 0, $order_by = "", $site_guid = 0, $count = false) {
+ global $CONFIG;
+
+ if (!$collection_id)
+ return false;
+
+ $entity_type = sanitise_string($entity_type);
+ $entity_subtype = get_subtype_id($entity_type, $entity_subtype);
+ $limit = (int)$limit;
+ $offset = (int)$offset;
+ if ($order_by == "")
+ $order_by = "e.time_created desc";
+ else
+ $order_by = "e.time_created, {$order_by}";
+ $order_by = sanitise_string($order_by);
+ $site_guid = (int) $site_guid;
+ if ((is_array($owner_guid) && (count($owner_guid)))) {
+ foreach($owner_guid as $key => $guid) {
+ $owner_guid[$key] = (int) $guid;
+ }
+ } else {
+ $owner_guid = (int) $owner_guid;
+ }
+ if ($site_guid == 0)
+ $site_guid = $CONFIG->site_guid;
+
+ //$access = get_access_list();
+
+ $where = array("e.access_id = $collection_id");
+
+ if ($entity_type!=="")
+ $where[] = "e.type='$entity_type'";
+ if ($entity_subtype)
+ $where[] = "e.subtype=$entity_subtype";
+ if ($site_guid > 0)
+ $where[] = "e.site_guid = {$site_guid}";
+ if (is_array($owner_guid)) {
+ $where[] = "e.container_guid in (".implode(",",$owner_guid).")";
+ } else if ($owner_guid > 0)
+ $where[] = "e.container_guid = {$owner_guid}";
+
+ if (!$count) {
+ $query = "SELECT distinct e.* ";
+ } else {
+ $query = "SELECT count(distinct e.guid) as total ";
+ }
+
+ $query .= "from {$CONFIG->dbprefix}entities e where";
+ foreach ($where as $w)
+ $query .= " $w and ";
+ $query .= get_access_sql_suffix("e"); // Add access controls
+ //$query .= ' and ' . get_access_sql_suffix("m"); // Add access controls
+
+ if (!$count) {
+ $query .= " order by $order_by limit $offset, $limit"; // Add order and limit
+ return get_data($query, "entity_row_to_elggstar");
+ } else {
+ if ($row = get_data_row($query))
+ return $row->total;
+ }
+ return false;
+ }
+
+ /**
+ * Lists entities from an access collection
+ *
+ * @param $collection_id
+ * @param $entity_type
+ * @param $entity_subtype
+ * @param $owner_guid
+ * @param $limit
+ * @param $fullview
+ * @param $viewtypetoggle
+ * @param $pagination
+ * @return str
+ */
+ function list_entities_from_access_collection($collection_id, $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $fullview = true, $viewtypetoggle = true, $pagination = true) {
+ $offset = (int) get_input('offset');
+ $limit = (int) $limit;
+ $count = get_entities_from_access_collection($collection_id, $entity_type, $entity_subtype, $owner_guid, $limit, $offset, "", 0, true);
+ $entities = get_entities_from_access_collection($collection_id, $entity_type, $entity_subtype, $owner_guid, $limit, $offset, "", 0, false);
+
+ return elgg_view_entity_list($entities, $count, $offset, $limit, $fullview, $viewtypetoggle, $pagination);
+ }
+
+ global $init_finished;
+ $init_finished = false;
+
+ /**
+ * A quick and dirty way to make sure the access permissions have been correctly set up
+ *
+ */
+ function access_init() {
+ global $init_finished;
+ $init_finished = true;
+ }
+
+ // This function will let us know when 'init' has finished
+ register_elgg_event_handler('init','system','access_init',9999);
+
?>
\ No newline at end of file
diff --git a/engine/lib/activity.php b/engine/lib/activity.php
index 2528f2d3c..10374e386 100644
--- a/engine/lib/activity.php
+++ b/engine/lib/activity.php
@@ -1,154 +1,154 @@
-owner_guid"
- * @return array An array of system log entries.
- */
- function get_activity_stream_data($limit = 10, $offset = 0, $type = "", $subtype = "", $owner_guid = "", $owner_relationship = "")
- {
- global $CONFIG;
-
- $limit = (int)$limit;
- $offset = (int)$offset;
-
- if ($type) {
- if (!is_array($type))
- $type = array(sanitise_string($type));
- else
- foreach ($type as $k => $v)
- $type[$k] = sanitise_string($v);
- }
-
- if ($subtype) {
- if (!is_array($subtype))
- $subtype = array(sanitise_string($subtype));
- else
- foreach ($subtype as $k => $v)
- $subtype[$k] = sanitise_string($v);
- }
-
- if ($owner_guid) {
- if (is_array($owner_guid))
- foreach ($owner_guid as $k => $v)
- $owner_guid[$k] = (int)$v;
- else
- $owner_guid = array((int)$owner_guid);
- }
-
- $owner_relationship = sanitise_string($owner_relationship);
-
- // Get a list of possible views
- $activity_events= array();
- $activity_views = array_merge(elgg_view_tree('activity', 'default'), elgg_view_tree('river', 'default')); // Join activity with river
-
- $done = array();
-
- foreach ($activity_views as $view)
- {
- $fragments = explode('/', $view);
- $tmp = explode('/',$view, 2);
- $tmp = $tmp[1];
-
- if ((isset($fragments[0])) && (($fragments[0] == 'river') || ($fragments[0] == 'activity'))
- && (!in_array($tmp, $done)))
- {
- if (isset($fragments[1]))
- {
- $f = array();
- for ($n = 1; $n < count($fragments); $n++)
- {
- $val = sanitise_string($fragments[$n]);
- switch($n)
- {
- case 1: $key = 'type'; break;
- case 2: $key = 'subtype'; break;
- case 3: $key = 'event'; break;
- }
- $f[$key] = $val;
- }
-
- // Filter result based on parameters
- $add = true;
- if ($type) {
- if (!in_array($f['type'], $type)) $add = false;
- }
- if (($add) && ($subtype)) {
- if (!in_array($f['subtype'], $subtype)) $add = false;
- }
- if (($add) && ($event)) {
- if (!in_array($f['event'], $event)) $add = false;
- }
-
- if ($add)
- $activity_events[] = $f;
- }
-
- $done[] = $tmp;
- }
-
-
- }
-
- $n = 0;
- foreach ($activity_events as $details)
- {
- // Get what we're talking about
-
- if ($details['subtype'] == 'default') $details['subtype'] = '';
-
- if (($details['type']) && ($details['event'])) {
- if ($n>0) $obj_query .= " or ";
-
- $access = "";
- if ($details['type']!='relationship')
- $access = " and " . get_access_sql_suffix('sl');
-
- $obj_query .= "( sl.object_type='{$details['type']}' and sl.object_subtype='{$details['subtype']}' and sl.event='{$details['event']}' $access )";
-
- $n++;
- }
-
- }
-
- // User
- if ((count($owner_guid)) && ($owner_guid[0]!=0)) {
- $user = " and sl.performed_by_guid in (".implode(',', $owner_guid).")";
-
- if ($owner_relationship)
- {
- $friendsarray = "";
- if ($friends = get_entities_from_relationship($owner_relationship,$owner_guid[0],false,"user",$subtype,0,"time_created desc",9999)) {
- $friendsarray = array();
- foreach($friends as $friend) {
- $friendsarray[] = $friend->getGUID();
- }
-
- $user = " and sl.performed_by_guid in (".implode(',', $friendsarray).")";
- }
-
- }
- }
-
- $query = "SELECT sl.* from {$CONFIG->dbprefix}system_log sl where 1 $user and ($obj_query) order by sl.time_created desc limit $offset, $limit";
- return get_data($query);
- }
+ * @link http://elgg.org/
+ */
+
+ /**
+ * Construct and execute the query required for the activity stream.
+ *
+ * @param int $limit Limit the query.
+ * @param int $offset Execute from the given object
+ * @param mixed $type A type, or array of types to look for. Note: This is how they appear in the SYSTEM LOG.
+ * @param mixed $subtype A subtype, or array of types to look for. Note: This is how they appear in the SYSTEM LOG.
+ * @param mixed $owner_guid The guid or a collection of GUIDs
+ * @param string $owner_relationship If defined, the relationship between $owner_guid and the entity owner_guid - so "is $owner_guid $owner_relationship with $entity->owner_guid"
+ * @return array An array of system log entries.
+ */
+ function get_activity_stream_data($limit = 10, $offset = 0, $type = "", $subtype = "", $owner_guid = "", $owner_relationship = "")
+ {
+ global $CONFIG;
+
+ $limit = (int)$limit;
+ $offset = (int)$offset;
+
+ if ($type) {
+ if (!is_array($type))
+ $type = array(sanitise_string($type));
+ else
+ foreach ($type as $k => $v)
+ $type[$k] = sanitise_string($v);
+ }
+
+ if ($subtype) {
+ if (!is_array($subtype))
+ $subtype = array(sanitise_string($subtype));
+ else
+ foreach ($subtype as $k => $v)
+ $subtype[$k] = sanitise_string($v);
+ }
+
+ if ($owner_guid) {
+ if (is_array($owner_guid))
+ foreach ($owner_guid as $k => $v)
+ $owner_guid[$k] = (int)$v;
+ else
+ $owner_guid = array((int)$owner_guid);
+ }
+
+ $owner_relationship = sanitise_string($owner_relationship);
+
+ // Get a list of possible views
+ $activity_events= array();
+ $activity_views = array_merge(elgg_view_tree('activity', 'default'), elgg_view_tree('river', 'default')); // Join activity with river
+
+ $done = array();
+
+ foreach ($activity_views as $view)
+ {
+ $fragments = explode('/', $view);
+ $tmp = explode('/',$view, 2);
+ $tmp = $tmp[1];
+
+ if ((isset($fragments[0])) && (($fragments[0] == 'river') || ($fragments[0] == 'activity'))
+ && (!in_array($tmp, $done)))
+ {
+ if (isset($fragments[1]))
+ {
+ $f = array();
+ for ($n = 1; $n < count($fragments); $n++)
+ {
+ $val = sanitise_string($fragments[$n]);
+ switch($n)
+ {
+ case 1: $key = 'type'; break;
+ case 2: $key = 'subtype'; break;
+ case 3: $key = 'event'; break;
+ }
+ $f[$key] = $val;
+ }
+
+ // Filter result based on parameters
+ $add = true;
+ if ($type) {
+ if (!in_array($f['type'], $type)) $add = false;
+ }
+ if (($add) && ($subtype)) {
+ if (!in_array($f['subtype'], $subtype)) $add = false;
+ }
+ if (($add) && ($event)) {
+ if (!in_array($f['event'], $event)) $add = false;
+ }
+
+ if ($add)
+ $activity_events[] = $f;
+ }
+
+ $done[] = $tmp;
+ }
+
+
+ }
+
+ $n = 0;
+ foreach ($activity_events as $details)
+ {
+ // Get what we're talking about
+
+ if ($details['subtype'] == 'default') $details['subtype'] = '';
+
+ if (($details['type']) && ($details['event'])) {
+ if ($n>0) $obj_query .= " or ";
+
+ $access = "";
+ if ($details['type']!='relationship')
+ $access = " and " . get_access_sql_suffix('sl');
+
+ $obj_query .= "( sl.object_type='{$details['type']}' and sl.object_subtype='{$details['subtype']}' and sl.event='{$details['event']}' $access )";
+
+ $n++;
+ }
+
+ }
+
+ // User
+ if ((count($owner_guid)) && ($owner_guid[0]!=0)) {
+ $user = " and sl.performed_by_guid in (".implode(',', $owner_guid).")";
+
+ if ($owner_relationship)
+ {
+ $friendsarray = "";
+ if ($friends = get_entities_from_relationship($owner_relationship,$owner_guid[0],false,"user",$subtype,0,"time_created desc",9999)) {
+ $friendsarray = array();
+ foreach($friends as $friend) {
+ $friendsarray[] = $friend->getGUID();
+ }
+
+ $user = " and sl.performed_by_guid in (".implode(',', $friendsarray).")";
+ }
+
+ }
+ }
+
+ $query = "SELECT sl.* from {$CONFIG->dbprefix}system_log sl where 1 $user and ($obj_query) order by sl.time_created desc limit $offset, $limit";
+ return get_data($query);
+ }
?>
\ No newline at end of file
diff --git a/engine/lib/admin.php b/engine/lib/admin.php
index a8272dc83..f09167bfa 100644
--- a/engine/lib/admin.php
+++ b/engine/lib/admin.php
@@ -1,177 +1,177 @@
-wwwroot . 'pg/admin/statistics/');
- add_submenu_item(elgg_echo('admin:site'), $CONFIG->wwwroot . 'pg/admin/site/');
- add_submenu_item(elgg_echo('admin:user'), $CONFIG->wwwroot . 'pg/admin/user/');
- add_submenu_item(elgg_echo('admin:plugins'), $CONFIG->wwwroot . 'pg/admin/plugins/');
-
- }
-
- }
-
- function admin_settings_page_handler($page)
- {
- global $CONFIG;
-
- $path = $CONFIG->path . "admin/index.php";
-
- if ($page[0])
- {
- switch ($page[0])
- {
- case 'user' : $path = $CONFIG->path . "admin/user.php"; break;
- case 'statistics' : $path = $CONFIG->path . "admin/statistics.php"; break;
- case 'plugins' : $path = $CONFIG->path . "admin/plugins.php"; break;
- case 'site' : $path = $CONFIG->path . "admin/site.php"; break;
- }
- }
-
- if ($page[1])
- set_input('username', $page[1]);
-
- include($path);
- }
-
-
- /**
- * Admin permissions system
- *
- * @return true|null True if the current user is an admin.
- */
- function admin_permissions($hook, $type, $returnval, $params) {
-
- if (is_array($params) && !empty($params['user']) && $params['user'] instanceof ElggUser) {
- $admin = $params['user']->admin;
- if ($admin) {
- return true;
- }
- }
-
- }
-
- /**
- * Write a persistent message to the administrator's notification window.
- *
- * Currently this writes a message to the admin store, we may want to come up with another way at some point.
- *
- * @param string $subject Subject of the message
- * @param string $message Body of the message
- */
- function send_admin_message($subject, $message)
- {
- $subject = sanitise_string($subject);
- $message = sanitise_string($message);
-
- if (($subject) && ($message))
- {
- $admin_message = new ElggObject();
- $admin_message->subtype = 'admin_message';
- $admin_message->access_id = ACCESS_PUBLIC;
- $admin_message->title = $subject;
- $admin_message->description = $message;
-
- return $admin_message->save();
- }
-
- return false;
- }
-
- /**
- * List all admin messages.
- *
- * @param int $limit Limit
- */
- function list_admin_messages($limit = 10)
- {
- return list_entities('object','admin_message',0,$limit);
- }
-
- /**
- * Remove an admin message.
- *
- * @param int $guid The
- */
- function clear_admin_message($guid)
- {
- return delete_entity($guid);
- }
-
- /// Register init functions
- register_elgg_event_handler('init','system','admin_init');
- register_elgg_event_handler('pagesetup','system','admin_pagesetup');
-
- // Register a plugin hook for permissions
- register_plugin_hook('permissions_check','all','admin_permissions');
- register_plugin_hook('container_permissions_check','all','admin_permissions');
-
-?>
+ register_action('admin/user/removeadmin', false, "", true);
+
+ // Register some actions
+ register_action('admin/site/update_basic', false, "", true); // Register basic site admin action
+
+ // Page handler
+ register_page_handler('admin','admin_settings_page_handler');
+
+ if (isadminloggedin()) {
+ global $is_admin;
+ $is_admin = true;
+ }
+
+ }
+
+ function admin_pagesetup() {
+
+ if (get_context() == 'admin') {
+
+ global $CONFIG;
+ add_submenu_item(elgg_echo('admin:statistics'), $CONFIG->wwwroot . 'pg/admin/statistics/');
+ add_submenu_item(elgg_echo('admin:site'), $CONFIG->wwwroot . 'pg/admin/site/');
+ add_submenu_item(elgg_echo('admin:user'), $CONFIG->wwwroot . 'pg/admin/user/');
+ add_submenu_item(elgg_echo('admin:plugins'), $CONFIG->wwwroot . 'pg/admin/plugins/');
+
+ }
+
+ }
+
+ function admin_settings_page_handler($page)
+ {
+ global $CONFIG;
+
+ $path = $CONFIG->path . "admin/index.php";
+
+ if ($page[0])
+ {
+ switch ($page[0])
+ {
+ case 'user' : $path = $CONFIG->path . "admin/user.php"; break;
+ case 'statistics' : $path = $CONFIG->path . "admin/statistics.php"; break;
+ case 'plugins' : $path = $CONFIG->path . "admin/plugins.php"; break;
+ case 'site' : $path = $CONFIG->path . "admin/site.php"; break;
+ }
+ }
+
+ if ($page[1])
+ set_input('username', $page[1]);
+
+ include($path);
+ }
+
+
+ /**
+ * Admin permissions system
+ *
+ * @return true|null True if the current user is an admin.
+ */
+ function admin_permissions($hook, $type, $returnval, $params) {
+
+ if (is_array($params) && !empty($params['user']) && $params['user'] instanceof ElggUser) {
+ $admin = $params['user']->admin;
+ if ($admin) {
+ return true;
+ }
+ }
+
+ }
+
+ /**
+ * Write a persistent message to the administrator's notification window.
+ *
+ * Currently this writes a message to the admin store, we may want to come up with another way at some point.
+ *
+ * @param string $subject Subject of the message
+ * @param string $message Body of the message
+ */
+ function send_admin_message($subject, $message)
+ {
+ $subject = sanitise_string($subject);
+ $message = sanitise_string($message);
+
+ if (($subject) && ($message))
+ {
+ $admin_message = new ElggObject();
+ $admin_message->subtype = 'admin_message';
+ $admin_message->access_id = ACCESS_PUBLIC;
+ $admin_message->title = $subject;
+ $admin_message->description = $message;
+
+ return $admin_message->save();
+ }
+
+ return false;
+ }
+
+ /**
+ * List all admin messages.
+ *
+ * @param int $limit Limit
+ */
+ function list_admin_messages($limit = 10)
+ {
+ return list_entities('object','admin_message',0,$limit);
+ }
+
+ /**
+ * Remove an admin message.
+ *
+ * @param int $guid The
+ */
+ function clear_admin_message($guid)
+ {
+ return delete_entity($guid);
+ }
+
+ /// Register init functions
+ register_elgg_event_handler('init','system','admin_init');
+ register_elgg_event_handler('pagesetup','system','admin_pagesetup');
+
+ // Register a plugin hook for permissions
+ register_plugin_hook('permissions_check','all','admin_permissions');
+ register_plugin_hook('container_permissions_check','all','admin_permissions');
+
+?>
diff --git a/engine/lib/api.php b/engine/lib/api.php
index a8e8549fc..3f5cd198f 100644
--- a/engine/lib/api.php
+++ b/engine/lib/api.php
@@ -259,7 +259,7 @@
/**
* Clean out old stuff.
*
- */
+ */
public function __destruct()
{
global $CONFIG;
@@ -270,7 +270,7 @@
$expires = $time-$age;
delete_data("DELETE from {$CONFIG->dbprefix}hmac_cache where ts<$expires");
- }
+ }
}
// API Call functions /////////////////////////////////////////////////////////////////////
diff --git a/engine/lib/configuration.php b/engine/lib/configuration.php
index 0317c821c..9aa5d2174 100644
--- a/engine/lib/configuration.php
+++ b/engine/lib/configuration.php
@@ -1,17 +1,17 @@
-dbprefix}config where name='$name' and site_guid=$site_guid");
}
-
- /**
- * Sets a configuration value
- *
- * @param string $name The name of the configuration value
- * @param string $value Its value
- * @param int $site_guid Optionally, the GUID of the site (current site is assumed by default)
- * @return false|int 1 or false depending on success or failure
- */
- function set_config($name, $value, $site_guid = 0) {
-
+
+ /**
+ * Sets a configuration value
+ *
+ * @param string $name The name of the configuration value
+ * @param string $value Its value
+ * @param int $site_guid Optionally, the GUID of the site (current site is assumed by default)
+ * @return false|int 1 or false depending on success or failure
+ */
+ function set_config($name, $value, $site_guid = 0) {
+
global $CONFIG;
// Unset existing
unset_config($name,$site_guid);
-
- $name = mysql_real_escape_string($name);
- $value = mysql_real_escape_string($value);
- $site_guid = (int) $site_guid;
- if ($site_guid == 0)
- $site_guid = (int) $CONFIG->site_id;
- $CONFIG->$name = $value;
+
+ $name = mysql_real_escape_string($name);
+ $value = mysql_real_escape_string($value);
+ $site_guid = (int) $site_guid;
+ if ($site_guid == 0)
+ $site_guid = (int) $CONFIG->site_id;
+ $CONFIG->$name = $value;
$value = sanitise_string(serialize($value));
-
- return insert_data("insert into {$CONFIG->dbprefix}config set name = '{$name}', value = '{$value}', site_guid = {$site_guid}");
-
- }
-
- /**
- * Gets a configuration value
- *
- * @param string $name The name of the config value
- * @param int $site_guid Optionally, the GUID of the site (current site is assumed by default)
- * @return mixed|false Depending on success
- */
- function get_config($name, $site_guid = 0) {
-
- global $CONFIG;
- if (isset($CONFIG->$name))
- return $CONFIG->$name;
- $name = mysql_real_escape_string($name);
- $site_guid = (int) $site_guid;
- if ($site_guid == 0)
- $site_guid = (int) $CONFIG->site_id;
- if ($result = get_data_row("SELECT value from {$CONFIG->dbprefix}config where name = '{$name}' and site_guid = {$site_guid}")) {
- $result = $result->value;
- $result = unserialize($result->value);
- $CONFIG->$name = $result;
- return $result;
- }
- return false;
-
+
+ return insert_data("insert into {$CONFIG->dbprefix}config set name = '{$name}', value = '{$value}', site_guid = {$site_guid}");
+
+ }
+
+ /**
+ * Gets a configuration value
+ *
+ * @param string $name The name of the config value
+ * @param int $site_guid Optionally, the GUID of the site (current site is assumed by default)
+ * @return mixed|false Depending on success
+ */
+ function get_config($name, $site_guid = 0) {
+
+ global $CONFIG;
+ if (isset($CONFIG->$name))
+ return $CONFIG->$name;
+ $name = mysql_real_escape_string($name);
+ $site_guid = (int) $site_guid;
+ if ($site_guid == 0)
+ $site_guid = (int) $CONFIG->site_id;
+ if ($result = get_data_row("SELECT value from {$CONFIG->dbprefix}config where name = '{$name}' and site_guid = {$site_guid}")) {
+ $result = $result->value;
+ $result = unserialize($result->value);
+ $CONFIG->$name = $result;
+ return $result;
+ }
+ return false;
+
}
/**
@@ -110,28 +110,28 @@
return true;
}
return false;
- }
-
- /**
- * If certain configuration elements don't exist, autodetect sensible defaults
- *
- * @uses $CONFIG The main configuration global
- *
- */
- function set_default_config() {
-
- global $CONFIG;
- if (empty($CONFIG->path))
- $CONFIG->path = str_replace("\\","/",dirname(dirname(dirname(__FILE__)))) . "/";
-
- if (empty($CONFIG->viewpath))
- $CONFIG->viewpath = $CONFIG->path . "views/";
-
- if (empty($CONFIG->pluginspath))
- $CONFIG->pluginspath = $CONFIG->path . "mod/";
-
- if (empty($CONFIG->wwwroot)) {
- /*
+ }
+
+ /**
+ * If certain configuration elements don't exist, autodetect sensible defaults
+ *
+ * @uses $CONFIG The main configuration global
+ *
+ */
+ function set_default_config() {
+
+ global $CONFIG;
+ if (empty($CONFIG->path))
+ $CONFIG->path = str_replace("\\","/",dirname(dirname(dirname(__FILE__)))) . "/";
+
+ if (empty($CONFIG->viewpath))
+ $CONFIG->viewpath = $CONFIG->path . "views/";
+
+ if (empty($CONFIG->pluginspath))
+ $CONFIG->pluginspath = $CONFIG->path . "mod/";
+
+ if (empty($CONFIG->wwwroot)) {
+ /*
$CONFIG->wwwroot = "http://" . $_SERVER['SERVER_NAME'];
$request = $_SERVER['REQUEST_URI'];
@@ -142,72 +142,72 @@
}
$CONFIG->wwwroot .= $request;
- */
- $pathpart = str_replace("//","/",str_replace($_SERVER['DOCUMENT_ROOT'],"",$CONFIG->path));
- if (substr($pathpart,0,1) != "/") $pathpart = "/" . $pathpart;
+ */
+ $pathpart = str_replace("//","/",str_replace($_SERVER['DOCUMENT_ROOT'],"",$CONFIG->path));
+ if (substr($pathpart,0,1) != "/") $pathpart = "/" . $pathpart;
$CONFIG->wwwroot = "http://" . $_SERVER['HTTP_HOST'] . $pathpart;
-
- }
-
- if (empty($CONFIG->url))
- $CONFIG->url = $CONFIG->wwwroot;
-
- if (empty($CONFIG->sitename))
- $CONFIG->sitename = "New Elgg site";
+
+ }
+
+ if (empty($CONFIG->url))
+ $CONFIG->url = $CONFIG->wwwroot;
+
+ if (empty($CONFIG->sitename))
+ $CONFIG->sitename = "New Elgg site";
if (empty($CONFIG->language))
$CONFIG->language = "en";
-
- }
-
- /**
- * Function that provides some config initialisation on system init
- *
- */
-
- function configuration_init() {
-
- global $CONFIG;
-
+
+ }
+
+ /**
+ * Function that provides some config initialisation on system init
+ *
+ */
+
+ function configuration_init() {
+
+ global $CONFIG;
+
if (is_installed() || is_db_installed()) {
-
- $path = datalist_get('path');
- if (!empty($path))
- $CONFIG->path = $path;
- $dataroot = datalist_get('dataroot');
- if (!empty($dataroot))
- $CONFIG->dataroot = $dataroot;
- $simplecache_enabled = datalist_get('simplecache_enabled');
- if ($simplecache_enabled !== false) {
- $CONFIG->simplecache_enabled = $simplecache_enabled;
- } else {
- $CONFIG->simplecache_enabled = 1;
+
+ $path = datalist_get('path');
+ if (!empty($path))
+ $CONFIG->path = $path;
+ $dataroot = datalist_get('dataroot');
+ if (!empty($dataroot))
+ $CONFIG->dataroot = $dataroot;
+ $simplecache_enabled = datalist_get('simplecache_enabled');
+ if ($simplecache_enabled !== false) {
+ $CONFIG->simplecache_enabled = $simplecache_enabled;
+ } else {
+ $CONFIG->simplecache_enabled = 1;
}
$viewpath_cache_enabled = datalist_get('viewpath_cache_enabled');
if ($viewpath_cache_enabled !== false) {
$CONFIG->viewpath_cache_enabled = $viewpath_cache_enabled;
} else {
$CONFIG->viewpath_cache_enabled = 1;
- }
- if (isset($CONFIG->site) && ($CONFIG->site instanceof ElggSite)) {
- $CONFIG->wwwroot = $CONFIG->site->url;
+ }
+ if (isset($CONFIG->site) && ($CONFIG->site instanceof ElggSite)) {
+ $CONFIG->wwwroot = $CONFIG->site->url;
$CONFIG->sitename = $CONFIG->site->name;
$CONFIG->sitedescription = $CONFIG->site->description;
- $CONFIG->siteemail = $CONFIG->site->email;
- }
- $CONFIG->url = $CONFIG->wwwroot;
+ $CONFIG->siteemail = $CONFIG->site->email;
+ }
+ $CONFIG->url = $CONFIG->wwwroot;
// Load default settings from database
get_all_config();
-
- return true;
- }
- }
-
- /**
- * Register config_init
- */
-
- register_elgg_event_handler('boot','system','configuration_init',10);
-
+
+ return true;
+ }
+ }
+
+ /**
+ * Register config_init
+ */
+
+ register_elgg_event_handler('boot','system','configuration_init',10);
+
?>
\ No newline at end of file
diff --git a/engine/lib/database.php b/engine/lib/database.php
index 8b154eefe..fa3a91fbb 100644
--- a/engine/lib/database.php
+++ b/engine/lib/database.php
@@ -1,60 +1,60 @@
-db[$dblinkname])) {
- if (is_array($CONFIG->db[$dblinkname])) {
- $index = rand(0,sizeof($CONFIG->db[$dblinkname]));
- $dbhost = $CONFIG->db[$dblinkname][$index]->dbhost;
- $dbuser = $CONFIG->db[$dblinkname][$index]->dbuser;
- $dbpass = $CONFIG->db[$dblinkname][$index]->dbpass;
- $dbname = $CONFIG->db[$dblinkname][$index]->dbname;
- } else {
- $dbhost = $CONFIG->db[$dblinkname]->dbhost;
- $dbuser = $CONFIG->db[$dblinkname]->dbuser;
- $dbpass = $CONFIG->db[$dblinkname]->dbpass;
- $dbname = $CONFIG->db[$dblinkname]->dbname;
- }
- } else {
- $dbhost = $CONFIG->dbhost;
- $dbuser = $CONFIG->dbuser;
- $dbpass = $CONFIG->dbpass;
- $dbname = $CONFIG->dbname;
- }
-
- // Connect to database
- if (!$dblink[$dblinkname] = mysql_connect($CONFIG->dbhost, $CONFIG->dbuser, $CONFIG->dbpass, true))
- throw new DatabaseException(sprintf(elgg_echo('DatabaseException:WrongCredentials'), $CONFIG->dbuser, $CONFIG->dbhost, $CONFIG->debug ? $CONFIG->dbpass : "****"));
- if (!mysql_select_db($CONFIG->dbname, $dblink[$dblinkname]))
- throw new DatabaseException(sprintf(elgg_echo('DatabaseException:NoConnect'), $CONFIG->dbname));
+
+ /**
+ * Connect to the database server and use the Elgg database for a particular database link
+ *
+ * @param string $dblinkname Default "readwrite"; you can change this to set up additional global database links, eg "read" and "write"
+ */
+ function establish_db_link($dblinkname = "readwrite") {
+
+ // Get configuration, and globalise database link
+ global $CONFIG, $dblink, $DB_QUERY_CACHE, $dbcalls;
+
+ if (!isset($dblink)) {
+ $dblink = array();
+ }
+
+ if ($dblinkname != "readwrite" && isset($CONFIG->db[$dblinkname])) {
+ if (is_array($CONFIG->db[$dblinkname])) {
+ $index = rand(0,sizeof($CONFIG->db[$dblinkname]));
+ $dbhost = $CONFIG->db[$dblinkname][$index]->dbhost;
+ $dbuser = $CONFIG->db[$dblinkname][$index]->dbuser;
+ $dbpass = $CONFIG->db[$dblinkname][$index]->dbpass;
+ $dbname = $CONFIG->db[$dblinkname][$index]->dbname;
+ } else {
+ $dbhost = $CONFIG->db[$dblinkname]->dbhost;
+ $dbuser = $CONFIG->db[$dblinkname]->dbuser;
+ $dbpass = $CONFIG->db[$dblinkname]->dbpass;
+ $dbname = $CONFIG->db[$dblinkname]->dbname;
+ }
+ } else {
+ $dbhost = $CONFIG->dbhost;
+ $dbuser = $CONFIG->dbuser;
+ $dbpass = $CONFIG->dbpass;
+ $dbname = $CONFIG->dbname;
+ }
+
+ // Connect to database
+ if (!$dblink[$dblinkname] = mysql_connect($CONFIG->dbhost, $CONFIG->dbuser, $CONFIG->dbpass, true))
+ throw new DatabaseException(sprintf(elgg_echo('DatabaseException:WrongCredentials'), $CONFIG->dbuser, $CONFIG->dbhost, $CONFIG->debug ? $CONFIG->dbpass : "****"));
+ if (!mysql_select_db($CONFIG->dbname, $dblink[$dblinkname]))
+ throw new DatabaseException(sprintf(elgg_echo('DatabaseException:NoConnect'), $CONFIG->dbname));
// Set up cache
if ((!$DB_QUERY_CACHE) && (!$CONFIG->db_disable_query_cache))
@@ -62,29 +62,29 @@
//$DB_QUERY_CACHE = select_default_memcache('db_query_cache'); //array();
//if ($DB_QUERY_CACHE instanceof ElggMemcache)
- // $DB_QUERY_CACHE->setDefaultExpiry(30);
- }
-
- /**
- * Establish all database connections
- *
- * If the configuration has been set up for multiple read/write databases, set those
- * links up separately; otherwise just create the one database link
- *
- */
-
- function setup_db_connections() {
-
- // Get configuration and globalise database link
- global $CONFIG, $dblink;
-
- if (!empty($CONFIG->db->split)) {
- establish_db_link('read');
- establish_db_link('write');
- } else {
- establish_db_link('readwrite');
- }
-
+ // $DB_QUERY_CACHE->setDefaultExpiry(30);
+ }
+
+ /**
+ * Establish all database connections
+ *
+ * If the configuration has been set up for multiple read/write databases, set those
+ * links up separately; otherwise just create the one database link
+ *
+ */
+
+ function setup_db_connections() {
+
+ // Get configuration and globalise database link
+ global $CONFIG, $dblink;
+
+ if (!empty($CONFIG->db->split)) {
+ establish_db_link('read');
+ establish_db_link('write');
+ } else {
+ establish_db_link('readwrite');
+ }
+
}
/**
@@ -125,43 +125,43 @@
if (isset($CONFIG->debug) && $CONFIG->debug) error_log($e);
}
}
- }
-
- /**
- * Alias to setup_db_connections, for use in the event handler
- *
- * @param string $event The event type
- * @param string $object_type The object type
- * @param mixed $object Used for nothing in this context
- */
+ }
+
+ /**
+ * Alias to setup_db_connections, for use in the event handler
+ *
+ * @param string $event The event type
+ * @param string $object_type The object type
+ * @param mixed $object Used for nothing in this context
+ */
function init_db($event, $object_type, $object = null) {
register_shutdown_function('db_delayedexecution_shutdown_hook');
- register_shutdown_function('db_profiling_shutdown_hook');
- //setup_db_connections(); // [Marcus Povey 20090213: Db connection moved to first db connection attempt]
- return true;
- }
-
- /**
- * Gets the appropriate db link for the operation mode requested
- *
- * @param string $dblinktype The type of link we want - "read", "write" or "readwrite" (the default)
- * @return object Database link
- */
- function get_db_link($dblinktype) {
-
- global $dblink;
-
-
- if (isset($dblink[$dblinktype])) {
- return $dblink[$dblinktype];
- } else if (isset($dblink['readwrite'])) {
- return $dblink['readwrite'];
- }
- else
- {
- setup_db_connections();
- return get_db_link($dblinktype);
- }
+ register_shutdown_function('db_profiling_shutdown_hook');
+ //setup_db_connections(); // [Marcus Povey 20090213: Db connection moved to first db connection attempt]
+ return true;
+ }
+
+ /**
+ * Gets the appropriate db link for the operation mode requested
+ *
+ * @param string $dblinktype The type of link we want - "read", "write" or "readwrite" (the default)
+ * @return object Database link
+ */
+ function get_db_link($dblinktype) {
+
+ global $dblink;
+
+
+ if (isset($dblink[$dblinktype])) {
+ return $dblink[$dblinktype];
+ } else if (isset($dblink['readwrite'])) {
+ return $dblink['readwrite'];
+ }
+ else
+ {
+ setup_db_connections();
+ return get_db_link($dblinktype);
+ }
}
/**
@@ -185,7 +185,7 @@
*/
function execute_query($query, $dblink)
{
- global $CONFIG, $dbcalls, $DB_PROFILE, $DB_QUERY_CACHE;
+ global $CONFIG, $dbcalls, $DB_PROFILE, $DB_QUERY_CACHE;
$dbcalls++;
@@ -244,18 +244,18 @@
* @param string $query The query to execute
* @param string $handler The handler if you care about the result.
*/
- function execute_delayed_read_query($query, $handler = "") { return execute_delayed_query($query, get_db_link('read'), $handler); }
-
- /**
- * Use this function to get data from the database
- * @param mixed $query The query being passed.
- * @param string $call Optionally, the name of a function to call back to on each row (which takes $row as a single parameter)
- * @return array An array of database result objects
- */
-
- function get_data($query, $callback = "") {
-
- global $CONFIG, $DB_QUERY_CACHE;
+ function execute_delayed_read_query($query, $handler = "") { return execute_delayed_query($query, get_db_link('read'), $handler); }
+
+ /**
+ * Use this function to get data from the database
+ * @param mixed $query The query being passed.
+ * @param string $call Optionally, the name of a function to call back to on each row (which takes $row as a single parameter)
+ * @return array An array of database result objects
+ */
+
+ function get_data($query, $callback = "") {
+
+ global $CONFIG, $DB_QUERY_CACHE;
// Is cached?
if ($DB_QUERY_CACHE) $cached_query = $DB_QUERY_CACHE[$query];
@@ -270,17 +270,17 @@
}
$dblink = get_db_link('read');
-
- $resultarray = array();
-
- if ($result = execute_query("$query", $dblink)) {
- while ($row = mysql_fetch_object($result)) {
- if (!empty($callback) && is_callable($callback)) {
- $row = $callback($row);
- }
- if ($row) $resultarray[] = $row;
- }
- }
+
+ $resultarray = array();
+
+ if ($result = execute_query("$query", $dblink)) {
+ while ($row = mysql_fetch_object($result)) {
+ if (!empty($callback) && is_callable($callback)) {
+ $row = $callback($row);
+ }
+ if ($row) $resultarray[] = $row;
+ }
+ }
if (empty($resultarray)) {
if ((isset($CONFIG->debug)) && ($CONFIG->debug==true))
@@ -293,18 +293,18 @@
if ((isset($CONFIG->debug)) && ($CONFIG->debug==true))
error_log("$query results cached");
if ($DB_QUERY_CACHE) $DB_QUERY_CACHE[$query] = $resultarray;
-
- return $resultarray;
- }
-
- /**
- * Use this function to get a single data row from the database
- * @param mixed $query The query to run.
- * @return object A single database result object
- */
-
- function get_data_row($query, $callback = "") {
-
+
+ return $resultarray;
+ }
+
+ /**
+ * Use this function to get a single data row from the database
+ * @param mixed $query The query to run.
+ * @return object A single database result object
+ */
+
+ function get_data_row($query, $callback = "") {
+
global $CONFIG, $DB_QUERY_CACHE;
// Is cached
@@ -317,10 +317,10 @@
return false; // Last time this query returned nothing, so return false
return $cached_query;
- }
-
+ }
+
$dblink = get_db_link('read');
-
+
if ($result = execute_query("$query", $dblink)) {
$row = mysql_fetch_object($result);
@@ -333,127 +333,127 @@
if (!empty($callback) && is_callable($callback)) {
$row = $callback($row);
}
-
- if ($row) return $row;
+
+ if ($row) return $row;
}
if ((isset($CONFIG->debug)) && ($CONFIG->debug==true))
error_log("WARNING: DB query \"$query\" returned no results.");
-
- return false;
- }
-
- /**
- * Use this function to insert database data; returns id or false
- *
- * @param mixed $query The query to run.
- * @return int $id the database id of the inserted row.
- */
-
- function insert_data($query) {
-
- global $CONFIG, $DB_QUERY_CACHE;
-
- $dblink = get_db_link('write');
+
+ return false;
+ }
+
+ /**
+ * Use this function to insert database data; returns id or false
+ *
+ * @param mixed $query The query to run.
+ * @return int $id the database id of the inserted row.
+ */
+
+ function insert_data($query) {
+
+ global $CONFIG, $DB_QUERY_CACHE;
+
+ $dblink = get_db_link('write');
// Invalidate query cache
if ($DB_QUERY_CACHE) $DB_QUERY_CACHE->clear();
if ((isset($CONFIG->debug)) && ($CONFIG->debug==true))
- error_log("Query cache invalidated");
-
- if (execute_query("$query", $dblink))
+ error_log("Query cache invalidated");
+
+ if (execute_query("$query", $dblink))
return mysql_insert_id($dblink);
- return false;
- }
-
- /**
- * Update database data
- *
- * @param mixed $query The query to run.
- * @return int|false Either the number of affected rows, or false on failure
- */
-
- function update_data($query) {
-
- global $CONFIG, $DB_QUERY_CACHE;
-
+ return false;
+ }
+
+ /**
+ * Update database data
+ *
+ * @param mixed $query The query to run.
+ * @return int|false Either the number of affected rows, or false on failure
+ */
+
+ function update_data($query) {
+
+ global $CONFIG, $DB_QUERY_CACHE;
+
$dblink = get_db_link('write');
// Invalidate query cache
if ($DB_QUERY_CACHE) $DB_QUERY_CACHE->clear();
if ((isset($CONFIG->debug)) && ($CONFIG->debug==true))
- error_log("Query cache invalidated");
-
- if (execute_query("$query", $dblink))
+ error_log("Query cache invalidated");
+
+ if (execute_query("$query", $dblink))
return true; //return mysql_affected_rows();
-
- return false;
-
- }
-
- /**
- * Use this function to delete data
- *
- * @param mixed $query The SQL query to run
- * @return int|false Either the number of affected rows, or false on failure
- */
-
- function delete_data($query) {
-
- global $CONFIG, $DB_QUERY_CACHE;
-
- $dblink = get_db_link('write');
+
+ return false;
+
+ }
+
+ /**
+ * Use this function to delete data
+ *
+ * @param mixed $query The SQL query to run
+ * @return int|false Either the number of affected rows, or false on failure
+ */
+
+ function delete_data($query) {
+
+ global $CONFIG, $DB_QUERY_CACHE;
+
+ $dblink = get_db_link('write');
// Invalidate query cache
if ($DB_QUERY_CACHE) $DB_QUERY_CACHE->clear();
if ((isset($CONFIG->debug)) && ($CONFIG->debug==true))
error_log("Query cache invalidated");
-
- if (execute_query("$query", $dblink))
- return mysql_affected_rows($dblink);
+
+ if (execute_query("$query", $dblink))
+ return mysql_affected_rows($dblink);
- return false;
- }
-
-
- /**
- * Get the tables currently installed in the Elgg database
- *
- * @return array List of tables
- */
- function get_db_tables() {
- global $CONFIG;
- static $tables, $count;
-
- if (isset($tables)) {
- return $tables;
- }
+ return false;
+ }
+
+
+ /**
+ * Get the tables currently installed in the Elgg database
+ *
+ * @return array List of tables
+ */
+ function get_db_tables() {
+ global $CONFIG;
+ static $tables, $count;
+
+ if (isset($tables)) {
+ return $tables;
+ }
- try{
+ try{
$result = get_data("show tables like '" . $CONFIG->dbprefix . "%'");
} catch (DatabaseException $d)
{
// Likely we can't handle an exception here, so just return false.
return false;
- }
-
- $tables = array();
-
- if (is_array($result) && !empty($result)) {
- foreach($result as $row) {
- $row = (array) $row;
- if (is_array($row) && !empty($row))
- foreach($row as $element) {
- $tables[] = $element;
- }
- }
+ }
+
+ $tables = array();
+
+ if (is_array($result) && !empty($result)) {
+ foreach($result as $row) {
+ $row = (array) $row;
+ if (is_array($row) && !empty($row))
+ foreach($row as $element) {
+ $tables[] = $element;
+ }
+ }
}
else
- return false;
-
- return $tables;
+ return false;
+
+ return $tables;
}
/**
@@ -464,57 +464,57 @@
{
$table = sanitise_string($table);
return update_data("optimize table $table");
- }
-
- /**
- * Get the last database error for a particular database link
- *
- * @param database link $dblink
- * @return string Database error message
- */
- function get_db_error($dblink) {
- return mysql_error($dblink);
- }
-
- /**
- * Runs a full database script from disk
- *
- * @uses $CONFIG
- * @param string $scriptlocation The full path to the script
- */
- function run_sql_script($scriptlocation) {
-
- if ($script = file_get_contents($scriptlocation)) {
-
- global $CONFIG;
-
- $errors = array();
-
- $script = preg_replace('/\-\-.*\n/', '', $script);
- $sql_statements = preg_split('/;[\n\r]+/', $script);
- foreach($sql_statements as $statement) {
- $statement = trim($statement);
- $statement = str_replace("prefix_",$CONFIG->dbprefix,$statement);
- if (!empty($statement)) {
- try {
- $result = update_data($statement);
- } catch (DatabaseException $e) {
- $errors[] = $e->getMessage();
- }
- }
- }
- if (!empty($errors)) {
- $errortxt = "";
- foreach($errors as $error)
- $errortxt .= " {$error};";
- throw new DatabaseException(elgg_echo('DatabaseException:DBSetupIssues') . $errortxt);
- }
-
- } else {
- throw new DatabaseException(sprintf(elgg_echo('DatabaseException:ScriptNotFound'), $scriptlocation));
- }
-
- }
+ }
+
+ /**
+ * Get the last database error for a particular database link
+ *
+ * @param database link $dblink
+ * @return string Database error message
+ */
+ function get_db_error($dblink) {
+ return mysql_error($dblink);
+ }
+
+ /**
+ * Runs a full database script from disk
+ *
+ * @uses $CONFIG
+ * @param string $scriptlocation The full path to the script
+ */
+ function run_sql_script($scriptlocation) {
+
+ if ($script = file_get_contents($scriptlocation)) {
+
+ global $CONFIG;
+
+ $errors = array();
+
+ $script = preg_replace('/\-\-.*\n/', '', $script);
+ $sql_statements = preg_split('/;[\n\r]+/', $script);
+ foreach($sql_statements as $statement) {
+ $statement = trim($statement);
+ $statement = str_replace("prefix_",$CONFIG->dbprefix,$statement);
+ if (!empty($statement)) {
+ try {
+ $result = update_data($statement);
+ } catch (DatabaseException $e) {
+ $errors[] = $e->getMessage();
+ }
+ }
+ }
+ if (!empty($errors)) {
+ $errortxt = "";
+ foreach($errors as $error)
+ $errortxt .= " {$error};";
+ throw new DatabaseException(elgg_echo('DatabaseException:DBSetupIssues') . $errortxt);
+ }
+
+ } else {
+ throw new DatabaseException(sprintf(elgg_echo('DatabaseException:ScriptNotFound'), $scriptlocation));
+ }
+
+ }
/**
* Upgrade the database schema in an ordered sequence.
@@ -526,49 +526,49 @@
* @param int $version The version you are upgrading from (usually given in the Elgg version format of YYYYMMDDXX - see version.php for example)
* @param string $fromdir Optional directory to load upgrades from (default: engine/schema/upgrades/)
* @return bool
- */
- function db_upgrade($version, $fromdir = "") {
-
- global $CONFIG;
-
- // Elgg and its database must be installed to upgrade it!
+ */
+ function db_upgrade($version, $fromdir = "") {
+
+ global $CONFIG;
+
+ // Elgg and its database must be installed to upgrade it!
if (!is_db_installed() || !is_installed()) return false;
-
+
$version = (int) $version;
if (!$fromdir)
- $fromdir = $CONFIG->path . 'engine/schema/upgrades/';
-
- if ($handle = opendir($fromdir)) {
-
- $sqlupgrades = array();
-
- while ($sqlfile = readdir($handle)) {
-
- if (!is_dir($fromdir . $sqlfile)) {
- if (preg_match('/([0-9]*)\.sql/',$sqlfile,$matches)) {
- $sql_version = (int) $matches[1];
- if ($sql_version > $version) {
- $sqlupgrades[] = $sqlfile;
- }
- }
- }
-
- }
-
- asort($sqlupgrades);
- if (sizeof($sqlupgrades) > 0) {
- foreach($sqlupgrades as $sqlfile) {
- try {
- run_sql_script($fromdir . $sqlfile);
- } catch (DatabaseException $e) {
- error_log($e->getmessage());
- }
- }
- }
-
- }
+ $fromdir = $CONFIG->path . 'engine/schema/upgrades/';
- return true;
+ if ($handle = opendir($fromdir)) {
+
+ $sqlupgrades = array();
+
+ while ($sqlfile = readdir($handle)) {
+
+ if (!is_dir($fromdir . $sqlfile)) {
+ if (preg_match('/([0-9]*)\.sql/',$sqlfile,$matches)) {
+ $sql_version = (int) $matches[1];
+ if ($sql_version > $version) {
+ $sqlupgrades[] = $sqlfile;
+ }
+ }
+ }
+
+ }
+
+ asort($sqlupgrades);
+ if (sizeof($sqlupgrades) > 0) {
+ foreach($sqlupgrades as $sqlfile) {
+ try {
+ run_sql_script($fromdir . $sqlfile);
+ } catch (DatabaseException $e) {
+ error_log($e->getmessage());
+ }
+ }
+ }
+
+ }
+
+ return true;
}
/**
@@ -603,52 +603,52 @@
$string = str_replace($extra_escapeable[$n], "\\" . $extra_escapeable[$n], $string);
return $string;
- }
-
- /**
- * Sanitise a string for database use
- *
- * @param string $string The string to sanitise
- * @return string Sanitised string
- */
- function sanitise_string($string) {
- return mysql_real_escape_string(trim($string));
- }
-
- /**
- * Wrapper function for alternate English spelling
- *
- * @param string $string The string to sanitise
- * @return string Sanitised string
- * @uses sanitise_string
- */
- function sanitize_string($string) {
- return sanitise_string($string);
- }
-
- /**
- * Sanitises an integer for database use
- *
- * @param int $int
- * @return int Sanitised integer
- */
- function sanitise_int($int) {
- return (int) $int;
- }
-
- /**
- * Wrapper function for alternate English spelling
- *
- * @param int $int
- * @return int Sanitised integer
- * @uses sanitise_string
- */
- function sanitize_int($int) {
- return (int) $int;
- }
-
- // Stuff for initialisation
-
- register_elgg_event_handler('boot','system','init_db',0);
-
+ }
+
+ /**
+ * Sanitise a string for database use
+ *
+ * @param string $string The string to sanitise
+ * @return string Sanitised string
+ */
+ function sanitise_string($string) {
+ return mysql_real_escape_string(trim($string));
+ }
+
+ /**
+ * Wrapper function for alternate English spelling
+ *
+ * @param string $string The string to sanitise
+ * @return string Sanitised string
+ * @uses sanitise_string
+ */
+ function sanitize_string($string) {
+ return sanitise_string($string);
+ }
+
+ /**
+ * Sanitises an integer for database use
+ *
+ * @param int $int
+ * @return int Sanitised integer
+ */
+ function sanitise_int($int) {
+ return (int) $int;
+ }
+
+ /**
+ * Wrapper function for alternate English spelling
+ *
+ * @param int $int
+ * @return int Sanitised integer
+ * @uses sanitise_string
+ */
+ function sanitize_int($int) {
+ return (int) $int;
+ }
+
+ // Stuff for initialisation
+
+ register_elgg_event_handler('boot','system','init_db',0);
+
?>
\ No newline at end of file
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php
index 06af14fcb..fc87c1dc1 100644
--- a/engine/lib/elgglib.php
+++ b/engine/lib/elgglib.php
@@ -131,13 +131,13 @@
/**
* Return the location of a given view.
*
- * @param string $view The view.
+ * @param string $view The view.
* @param string $viewtype The viewtype
*/
function elgg_get_view_location($view, $viewtype = '')
{
global $CONFIG;
-
+
if (empty($viewtype))
$viewtype = elgg_get_viewtype();
@@ -162,7 +162,7 @@
* @param string $view The name and location of the view to use
* @param array $vars Any variables that the view requires, passed as an array
* @param boolean $bypass If set to true, elgg_view will bypass any specified alternative template handler; by default, it will hand off to this if requested (see set_template_handler)
- * @param boolean $debug If set to true, the viewer will complain if it can't find a view
+ * @param boolean $debug If set to true, the viewer will complain if it can't find a view
* @param string $viewtype If set, forces the viewtype for the elgg_view call to be this value (default: standard detection)
* @return string The HTML content
*/
@@ -228,7 +228,7 @@
}
- // Get the current viewtype
+ // Get the current viewtype
if (empty($viewtype))
$viewtype = elgg_get_viewtype();
@@ -278,7 +278,7 @@
/**
* Returns whether the specified view exists
*
- * @param string $view The view name
+ * @param string $view The view name
* @param string $viewtype If set, forces the viewtype
* @return true|false Depending on success
*/
@@ -286,7 +286,7 @@
global $CONFIG;
- // Detect view type
+ // Detect view type
if (empty($viewtype))
$viewtype = elgg_get_viewtype();
@@ -625,14 +625,14 @@
$subtype = $entity->getSubtype();
if (empty($subtype)) { $subtype = $entity_type; }
-
+
$contents = '';
if (elgg_view_exists("{$entity_type}/{$subtype}")) {
$contents = elgg_view("{$entity_type}/{$subtype}",array(
'entity' => $entity,
'full' => $full
), $bypass, $debug);
- }
+ }
if (empty($contents)) {
$contents = elgg_view("{$entity_type}/default",array(
'entity' => $entity,
@@ -645,7 +645,7 @@
if ($annotations)
$contents .= $annotations;
- }
+ }
return $contents;
}
@@ -2303,7 +2303,7 @@
define('ACCESS_DEFAULT',-1);
define('ACCESS_PRIVATE',0);
define('ACCESS_LOGGED_IN',1);
- define('ACCESS_PUBLIC',2);
+ define('ACCESS_PUBLIC',2);
define('ACCESS_FRIENDS',-2);
register_elgg_event_handler('init','system','elgg_init');
diff --git a/engine/lib/entities.php b/engine/lib/entities.php
index b8c92ec42..4d2e17b56 100644
--- a/engine/lib/entities.php
+++ b/engine/lib/entities.php
@@ -1,2750 +1,2750 @@
-
+
+ * @link http://elgg.org/
+ */
+
+ /// Cache objects in order to minimise database access.
+ $ENTITY_CACHE = NULL;
+
+ /// Cache subtype searches
+ $SUBTYPE_CACHE = NULL;
+
+ /// Require the locatable interface TODO: Move this into start.php?
+ require_once('location.php');
+
+ /**
+ * ElggEntity The elgg entity superclass
+ * This class holds methods for accessing the main entities table.
+ *
+ * @author Curverider Ltd
+ * @package Elgg
+ * @subpackage Core
+ */
+ abstract class ElggEntity implements
+ Notable, // Calendar interface
+ Locatable, // Geocoding interface
+ Exportable, // Allow export of data
+ Importable, // Allow import of data
+ Loggable, // Can events related to this object class be logged
+ Iterator, // Override foreach behaviour
+ ArrayAccess // Override for array access
+ {
+ /**
+ * The main attributes of an entity.
+ * Blank entries for all database fields should be created by the constructor.
+ * Subclasses should add to this in their constructors.
+ * Any field not appearing in this will be viewed as a
+ */
+ protected $attributes;
+
+ /**
+ * If set, overrides the value of getURL()
+ */
+ protected $url_override;
+
+ /**
+ * Icon override, overrides the value of getIcon().
+ */
+ protected $icon_override;
+
+ /**
+ * Temporary cache for metadata, permitting meta data access before a guid has obtained.
+ */
+ protected $temp_metadata;
+
+ /**
+ * Temporary cache for annotations, permitting meta data access before a guid has obtained.
+ */
+ protected $temp_annotations;
+
+ /**
+ * Initialise the attributes array.
+ * This is vital to distinguish between metadata and base parameters.
+ *
+ * Place your base parameters here.
+ *
+ * @return void
+ */
+ protected function initialise_attributes()
+ {
+ initialise_entity_cache();
+
+ // Create attributes array if not already created
+ if (!is_array($this->attributes)) $this->attributes = array();
+ if (!is_array($this->temp_metadata)) $this->temp_metadata = array();
+ if (!is_array($this->temp_annotations)) $this->temp_annotations = array();
+
+ $this->attributes['guid'] = "";
+ $this->attributes['type'] = "";
+ $this->attributes['subtype'] = "";
+
+ $this->attributes['owner_guid'] = get_loggedin_userid();
+ $this->attributes['container_guid'] = get_loggedin_userid();
+
+ $this->attributes['site_guid'] = 0;
+ $this->attributes['access_id'] = ACCESS_PRIVATE;
+ $this->attributes['time_created'] = "";
+ $this->attributes['time_updated'] = "";
+ $this->attributes['enabled'] = "yes";
+
+ // There now follows a bit of a hack
+ /* Problem: To speed things up, some objects are split over several tables, this means that it requires
+ * n number of database reads to fully populate an entity. This causes problems for caching and create events
+ * since it is not possible to tell whether a subclassed entity is complete.
+ * Solution: We have two counters, one 'tables_split' which tells whatever is interested how many tables
+ * are going to need to be searched in order to fully populate this object, and 'tables_loaded' which is how
+ * many have been loaded thus far.
+ * If the two are the same then this object is complete.
+ *
+ * Use: isFullyLoaded() to check
+ */
+ $this->attributes['tables_split'] = 1;
+ $this->attributes['tables_loaded'] = 0;
+ }
+
+ /**
+ * Return the value of a given key.
+ * If $name is a key field (as defined in $this->attributes) that value is returned, otherwise it will
+ * then look to see if the value is in this object's metadata.
+ *
+ * Q: Why are we not using __get overload here?
+ * A: Because overload operators cause problems during subclassing, so we put the code here and
+ * create overloads in subclasses.
+ *
+ * @param string $name
+ * @return mixed Returns the value of a given value, or null.
+ */
+ public function get($name)
+ {
+ // See if its in our base attribute
+ if (isset($this->attributes[$name])) {
+ return $this->attributes[$name];
+ }
+
+ // No, so see if its in the meta data for this entity
+ $meta = $this->getMetaData($name);
+ if ($meta)
+ return $meta;
+
+ // Can't find it, so return null
+ return null;
+ }
- * @author Curverider Ltd
+ /**
+ * Set the value of a given key, replacing it if necessary.
+ * If $name is a base attribute (as defined in $this->attributes) that value is set, otherwise it will
+ * set the appropriate item of metadata.
+ *
+ * Note: It is important that your class populates $this->attributes with keys for all base attributes, anything
+ * not in their gets set as METADATA.
+ *
+ * Q: Why are we not using __set overload here?
+ * A: Because overload operators cause problems during subclassing, so we put the code here and
+ * create overloads in subclasses.
+ *
+ * @param string $name
+ * @param mixed $value
+ */
+ public function set($name, $value)
+ {
+ if (array_key_exists($name, $this->attributes))
+ {
+ // Check that we're not trying to change the guid!
+ if ((array_key_exists('guid', $this->attributes)) && ($name=='guid'))
+ return false;
+
+ $this->attributes[$name] = $value;
+ }
+ else
+ return $this->setMetaData($name, $value);
+
+ return true;
+ }
+
+ /**
+ * Get a given piece of metadata.
+ *
+ * @param string $name
+ */
+ public function getMetaData($name)
+ {
+ if ((int) ($this->guid) > 0) {
+ $md = get_metadata_byname($this->getGUID(), $name);
+ } else {
+ if (isset($this->temp_metadata[$name]))
+ return $this->temp_metadata[$name];
+ }
- * @link http://elgg.org/
- */
-
- /// Cache objects in order to minimise database access.
- $ENTITY_CACHE = NULL;
-
- /// Cache subtype searches
- $SUBTYPE_CACHE = NULL;
-
- /// Require the locatable interface TODO: Move this into start.php?
- require_once('location.php');
-
- /**
- * ElggEntity The elgg entity superclass
- * This class holds methods for accessing the main entities table.
- *
- * @author Curverider Ltd
- * @package Elgg
- * @subpackage Core
- */
- abstract class ElggEntity implements
- Notable, // Calendar interface
- Locatable, // Geocoding interface
- Exportable, // Allow export of data
- Importable, // Allow import of data
- Loggable, // Can events related to this object class be logged
- Iterator, // Override foreach behaviour
- ArrayAccess // Override for array access
- {
- /**
- * The main attributes of an entity.
- * Blank entries for all database fields should be created by the constructor.
- * Subclasses should add to this in their constructors.
- * Any field not appearing in this will be viewed as a
- */
- protected $attributes;
-
- /**
- * If set, overrides the value of getURL()
- */
- protected $url_override;
-
- /**
- * Icon override, overrides the value of getIcon().
- */
- protected $icon_override;
-
- /**
- * Temporary cache for metadata, permitting meta data access before a guid has obtained.
- */
- protected $temp_metadata;
-
- /**
- * Temporary cache for annotations, permitting meta data access before a guid has obtained.
- */
- protected $temp_annotations;
-
- /**
- * Initialise the attributes array.
- * This is vital to distinguish between metadata and base parameters.
- *
- * Place your base parameters here.
- *
- * @return void
- */
- protected function initialise_attributes()
- {
- initialise_entity_cache();
-
- // Create attributes array if not already created
- if (!is_array($this->attributes)) $this->attributes = array();
- if (!is_array($this->temp_metadata)) $this->temp_metadata = array();
- if (!is_array($this->temp_annotations)) $this->temp_annotations = array();
-
- $this->attributes['guid'] = "";
- $this->attributes['type'] = "";
- $this->attributes['subtype'] = "";
-
- $this->attributes['owner_guid'] = get_loggedin_userid();
- $this->attributes['container_guid'] = get_loggedin_userid();
-
- $this->attributes['site_guid'] = 0;
- $this->attributes['access_id'] = ACCESS_PRIVATE;
- $this->attributes['time_created'] = "";
- $this->attributes['time_updated'] = "";
- $this->attributes['enabled'] = "yes";
-
- // There now follows a bit of a hack
- /* Problem: To speed things up, some objects are split over several tables, this means that it requires
- * n number of database reads to fully populate an entity. This causes problems for caching and create events
- * since it is not possible to tell whether a subclassed entity is complete.
- * Solution: We have two counters, one 'tables_split' which tells whatever is interested how many tables
- * are going to need to be searched in order to fully populate this object, and 'tables_loaded' which is how
- * many have been loaded thus far.
- * If the two are the same then this object is complete.
- *
- * Use: isFullyLoaded() to check
- */
- $this->attributes['tables_split'] = 1;
- $this->attributes['tables_loaded'] = 0;
- }
-
- /**
- * Return the value of a given key.
- * If $name is a key field (as defined in $this->attributes) that value is returned, otherwise it will
- * then look to see if the value is in this object's metadata.
- *
- * Q: Why are we not using __get overload here?
- * A: Because overload operators cause problems during subclassing, so we put the code here and
- * create overloads in subclasses.
- *
- * @param string $name
- * @return mixed Returns the value of a given value, or null.
- */
- public function get($name)
- {
- // See if its in our base attribute
- if (isset($this->attributes[$name])) {
- return $this->attributes[$name];
- }
-
- // No, so see if its in the meta data for this entity
- $meta = $this->getMetaData($name);
- if ($meta)
- return $meta;
-
- // Can't find it, so return null
- return null;
- }
-
- /**
- * Set the value of a given key, replacing it if necessary.
- * If $name is a base attribute (as defined in $this->attributes) that value is set, otherwise it will
- * set the appropriate item of metadata.
- *
- * Note: It is important that your class populates $this->attributes with keys for all base attributes, anything
- * not in their gets set as METADATA.
- *
- * Q: Why are we not using __set overload here?
- * A: Because overload operators cause problems during subclassing, so we put the code here and
- * create overloads in subclasses.
- *
- * @param string $name
- * @param mixed $value
- */
- public function set($name, $value)
- {
- if (array_key_exists($name, $this->attributes))
- {
- // Check that we're not trying to change the guid!
- if ((array_key_exists('guid', $this->attributes)) && ($name=='guid'))
- return false;
-
- $this->attributes[$name] = $value;
- }
- else
- return $this->setMetaData($name, $value);
-
- return true;
- }
-
- /**
- * Get a given piece of metadata.
- *
- * @param string $name
- */
- public function getMetaData($name)
- {
- if ((int) ($this->guid) > 0) {
- $md = get_metadata_byname($this->getGUID(), $name);
- } else {
- if (isset($this->temp_metadata[$name]))
- return $this->temp_metadata[$name];
- }
-
- if ($md && !is_array($md)) {
- return $md->value;
- } else if ($md && is_array($md)) {
- return metadata_array_to_values($md);
- }
-
- return null;
- }
-
- /**
- * Class member get overloading
- *
- * @param string $name
- * @return mixed
- */
- function __get($name) { return $this->get($name); }
-
- /**
- * Class member set overloading
- *
- * @param string $name
- * @param mixed $value
- * @return mixed
- */
- function __set($name, $value) { return $this->set($name, $value); }
-
- /**
- * Supporting isset.
- *
- * @param string $name The name of the attribute or metadata.
- * @return bool
- */
- function __isset($name) { if ($this->$name!="") return true; else return false; }
-
- /**
- * Supporting unsetting of magic attributes.
- *
- * @param string $name The name of the attribute or metadata.
- */
- function __unset($name)
- {
- if (array_key_exists($name, $this->attributes))
- $this->attributes[$name] = "";
- else
- $this->clearMetaData($name);
- }
-
- /**
- * Set a piece of metadata.
- *
- * @param string $name
- * @param mixed $value
- * @param string $value_type
- * @param bool $multiple
- * @return bool
- */
- public function setMetaData($name, $value, $value_type = "", $multiple = false)
- {
- if (is_array($value))
- {
- unset($this->temp_metadata[$name]);
- remove_metadata($this->getGUID(), $name);
- foreach ($value as $v) {
- if ((int) $this->guid > 0) {
- $multiple = true;
- if (!create_metadata($this->getGUID(), $name, $v, $value_type, $this->getOwner(), $this->getAccessID(), $multiple)) return false;
- } else {
- if (($multiple) && (isset($this->temp_metadata[$name])))
- {
- if (!is_array($this->temp_metadata[$name]))
- {
- $tmp = $this->temp_metadata[$name];
- $this->temp_metadata[$name] = array();
- $this->temp_metadata[$name][] = $tmp;
- }
-
- $this->temp_metadata[$name][] = $value;
- }
- else
- $this->temp_metadata[$name] = $value;
- }
- }
-
- return true;
- }
- else
- {
- unset($this->temp_metadata[$name]);
- if ((int) $this->guid > 0) {
- return create_metadata($this->getGUID(), $name, $value, $value_type, $this->getOwner(), $this->getAccessID(), $multiple);
- } else {
- //$this->temp_metadata[$name] = $value;
-
- if (($multiple) && (isset($this->temp_metadata[$name])))
- {
- if (!is_array($this->temp_metadata[$name]))
- {
- $tmp = $this->temp_metadata[$name];
- $this->temp_metadata[$name] = array();
- $this->temp_metadata[$name][] = $tmp;
- }
-
- $this->temp_metadata[$name][] = $value;
- }
- else
- $this->temp_metadata[$name] = $value;
-
- return true;
- }
- }
- }
-
- /**
- * Clear metadata.
- */
- public function clearMetaData($name = "")
- {
- if (empty($name)) {
- return clear_metadata($this->getGUID());
- } else {
- return remove_metadata($this->getGUID(),$name);
- }
- }
-
- /**
- * Remove all entities associated with this entity
- *
- * @return true
- */
- public function clearRelationships() {
- remove_entity_relationships($this->getGUID());
- remove_entity_relationships($this->getGUID(),"",true);
- return true;
- }
-
- /**
- * Add a relationship.
- *
- * @param int $guid Relationship to link to.
- * @param string $relationship The type of relationship.
- */
- public function addRelationship($guid, $relationship)
- {
- return add_entity_relationship($this->getGUID(), $relationship, $guid);
- }
-
- function setPrivateSetting($name, $value) {
- return set_private_setting($this->getGUID(), $name, $value);
- }
-
- function getPrivateSetting($name) {
- return get_private_setting($this->getGUID(), $name);
- }
-
- function removePrivateSetting($name) {
- return remove_private_setting($this->getGUID(), $name);
- }
-
- /**
- * Adds an annotation to an entity. By default, the type is detected automatically; however,
- * it can also be set. Note that by default, annotations are private.
- *
- * @param string $name
- * @param mixed $value
- * @param int $access_id
- * @param int $owner_id
- * @param string $vartype
- */
- function annotate($name, $value, $access_id = ACCESS_PRIVATE, $owner_id = 0, $vartype = "")
- {
- if ((int) $this->guid > 0) {
- return create_annotation($this->getGUID(), $name, $value, $vartype, $owner_id, $access_id);
- } else {
- $this->temp_annotations[$name] = $value;
- }
- return true;
- }
-
- /**
- * Get the annotations for an entity.
- *
- * @param string $name
- * @param int $limit
- * @param int $offset
- * @param string $order
- */
- function getAnnotations($name, $limit = 50, $offset = 0, $order="asc")
- {
- if ((int) ($this->guid) > 0) {
- return get_annotations($this->getGUID(), "", "", $name, "", 0, $limit, $offset, $order);
- } else {
- return $this->temp_annotations[$name];
- }
- }
-
- /**
- * Remove all annotations or all annotations for this entity.
- *
- * @param string $name
- */
- function clearAnnotations($name = "")
- {
- return clear_annotations($this->getGUID(), $name);
- }
-
- /**
- * Return the annotations for the entity.
- *
- * @param string $name The type of annotation.
- */
- function countAnnotations($name = "")
- {
- return count_annotations($this->getGUID(), "","",$name);
- }
-
- /**
- * Get the average of an integer type annotation.
- *
- * @param string $name
- */
- function getAnnotationsAvg($name)
- {
- return get_annotations_avg($this->getGUID(), "","",$name);
- }
-
- /**
- * Get the sum of integer type annotations of a given name.
- *
- * @param string $name
- */
- function getAnnotationsSum($name)
- {
- return get_annotations_sum($this->getGUID(), "","",$name);
- }
-
- /**
- * Get the minimum of integer type annotations of given name.
- *
- * @param string $name
- */
- function getAnnotationsMin($name)
- {
- return get_annotations_min($this->getGUID(), "","",$name);
- }
-
- /**
- * Get the maximum of integer type annotations of a given name.
- *
- * @param string $name
- */
- function getAnnotationsMax($name)
- {
- return get_annotations_max($this->getGUID(), "","",$name);
- }
-
- /**
- * Gets an array of entities from a specific relationship type
- *
- * @param string $relationship Relationship type (eg "friends")
- * @param true|false $inverse Is this an inverse relationship?
- * @param int $limit Number of elements to return
- * @param int $offset Indexing offset
- * @return array|false An array of entities or false on failure
- */
- function getEntitiesFromRelationship($relationship, $inverse = false, $limit = 50, $offset = 0) {
- return get_entities_from_relationship($relationship,$this->getGUID(),$inverse,"","","","time_created desc",$limit,$offset);
- }
-
- /**
- * Gets the number of of entities from a specific relationship type
- *
- * @param string $relationship Relationship type (eg "friends")
- * @return int|false The number of entities or false on failure
- */
- function countEntitiesFromRelationship($relationship) {
- return get_entities_from_relationship($relationship,$this->getGUID(),false,"","","","time_created desc",null,null,true);
- }
-
- /**
- * Determines whether or not the specified user (by default the current one) can edit the entity
- *
- * @param int $user_guid The user GUID, optionally (defaults to the currently logged in user)
- * @return true|false
- */
- function canEdit($user_guid = 0) {
- return can_edit_entity($this->getGUID(),$user_guid);
- }
-
- /**
- * Determines whether or not the specified user (by default the current one) can edit metadata on the entity
- *
- * @param ElggMetadata $metadata The piece of metadata to specifically check
- * @param int $user_guid The user GUID, optionally (defaults to the currently logged in user)
- * @return true|false
- */
- function canEditMetadata($metadata = null, $user_guid = 0) {
- return can_edit_entity_metadata($this->getGUID(), $user_guid, $metadata);
- }
-
- /**
- * Returns whether the given user (or current user) has the ability to write to this group.
- *
- * @param int $user_guid The user.
- * @return bool
- */
- public function canWriteToContainer($user_guid = 0)
- {
- return can_write_to_container($user_guid, $this->getGUID());
- }
-
- /**
- * Obtain this entity's access ID
- *
- * @return int The access ID
- */
- public function getAccessID() { return $this->get('access_id'); }
-
- /**
- * Obtain this entity's GUID
- *
- * @return int GUID
- */
- public function getGUID() { return $this->get('guid'); }
-
- /**
- * Get the owner of this entity
- *
- * @return int The owner GUID
- */
- public function getOwner() { return $this->get('owner_guid'); }
-
- /**
- * Returns the actual entity of the user who owns this entity, if any
- *
- * @return ElggEntity The owning user
- */
- public function getOwnerEntity() { return get_entity($this->get('owner_guid')); }
-
- /**
- * Gets the type of entity this is
- *
- * @return string Entity type
- */
- public function getType() { return $this->get('type'); }
-
- /**
- * Returns the subtype of this entity
- *
- * @return string The entity subtype
- */
- public function getSubtype() {
- if (!((int) $this->guid > 0)) return $this->get('subtype'); // If this object hasn't been saved, then return the subtype string.
-
- return get_subtype_from_id($this->get('subtype'));
- }
-
- /**
- * Gets the UNIX epoch time that this entity was created
- *
- * @return int UNIX epoch time
- */
- public function getTimeCreated() { return $this->get('time_created'); }
-
- /**
- * Gets the UNIX epoch time that this entity was last updated
- *
- * @return int UNIX epoch time
- */
- public function getTimeUpdated() { return $this->get('time_updated'); }
-
- /**
- * Gets the display URL for this entity
- *
- * @return string The URL
- */
- public function getURL() {
- if (!empty($this->url_override)) return $this->url_override;
- return get_entity_url($this->getGUID());
- }
-
- /**
- * Overrides the URL returned by getURL
- *
- * @param string $url The new item URL
- * @return string The URL
- */
- public function setURL($url) {
- $this->url_override = $url;
- return $url;
- }
-
- /**
- * Return a url for the entity's icon, trying multiple alternatives.
- *
- * @param string $size Either 'large','medium','small' or 'tiny'
- * @return string The url or false if no url could be worked out.
- */
- public function getIcon($size = 'medium')
- {
- if (isset($this->icon_override[$size])) return $this->icon_override[$size];
- return get_entity_icon_url($this, $size);
- }
-
- /**
- * Set an icon override for an icon and size.
- *
- * @param string $url The url of the icon.
- * @param string $size The size its for.
- * @return bool
- */
- public function setIcon($url, $size = 'medium')
- {
- $url = sanitise_string($url);
- $size = sanitise_string($size);
-
- if (!$this->icon_override) $this->icon_override = array();
- $this->icon_override[$size] = $url;
-
- return true;
- }
-
- /**
- * Tests to see whether the object has been fully loaded.
- *
- * @return bool
- */
- public function isFullyLoaded() { return ! ($this->attributes['tables_loaded'] < $this->attributes['tables_split']); }
-
- /**
- * Save generic attributes to the entities table.
- */
- public function save()
- {
- $guid = (int) $this->guid;
- if ($guid > 0)
- {
- cache_entity($this);
-
- return update_entity(
- $this->get('guid'),
- $this->get('owner_guid'),
- $this->get('access_id'),
- $this->get('container_guid')
- );
- }
- else
- {
- $this->attributes['guid'] = create_entity($this->attributes['type'], $this->attributes['subtype'], $this->attributes['owner_guid'], $this->attributes['access_id'], $this->attributes['site_guid'], $this->attributes['container_guid']); // Create a new entity (nb: using attribute array directly 'cos set function does something special!)
- if (!$this->attributes['guid']) throw new IOException(elgg_echo('IOException:BaseEntitySaveFailed'));
-
- // Save any unsaved metadata TODO: How to capture extra information (access id etc)
- if (sizeof($this->temp_metadata) > 0) {
- foreach($this->temp_metadata as $name => $value) {
- $this->$name = $value;
- unset($this->temp_metadata[$name]);
- }
- }
-
- // Save any unsaved annotations metadata. TODO: How to capture extra information (access id etc)
- if (sizeof($this->temp_annotations) > 0) {
- foreach($this->temp_annotations as $name => $value) {
- $this->annotate($name, $value);
- unset($this->temp_annotations[$name]);
- }
- }
-
- // Cache object handle
- if ($this->attributes['guid']) cache_entity($this);
-
- return $this->attributes['guid'];
- }
- }
-
- /**
- * Load the basic entity information and populate base attributes array.
- *
- * @param int $guid
- */
- protected function load($guid)
- {
- $row = get_entity_as_row($guid);
-
- if ($row)
- {
- // Create the array if necessary - all subclasses should test before creating
- if (!is_array($this->attributes)) $this->attributes = array();
-
- // Now put these into the attributes array as core values
- $objarray = (array) $row;
- foreach($objarray as $key => $value)
- $this->attributes[$key] = $value;
-
- // Increment the portion counter
- if (!$this->isFullyLoaded()) $this->attributes['tables_loaded'] ++;
-
- // Cache object handle
- if ($this->attributes['guid']) cache_entity($this);
-
- return true;
- }
-
- return false;
- }
-
- /**
- * Disable this entity.
- *
- * @param string $reason Optional reason
- * @param bool $recursive Recursively disable all contained entities?
- */
- public function disable($reason = "", $recursive = true)
- {
- return disable_entity($this->get('guid'), $reason, $recursive);
- }
-
- /**
- * Re-enable this entity.
- */
- public function enable()
- {
- return enable_entity($this->get('guid'));
- }
-
- /**
- * Is this entity enabled?
- *
- * @return boolean
- */
- public function isEnabled()
- {
- if ($this->enabled == 'yes')
- return true;
-
- return false;
- }
-
- /**
- * Delete this entity.
- */
- public function delete()
- {
- return delete_entity($this->get('guid'));
- }
-
- // LOCATABLE INTERFACE /////////////////////////////////////////////////////////////
-
- /** Interface to set the location */
- public function setLocation($location)
- {
- $location = sanitise_string($location);
-
- $this->location = $location;
-
- return true;
- }
-
- /**
- * Set latitude and longitude tags for a given entity.
- *
- * @param float $lat
- * @param float $long
- */
- public function setLatLong($lat, $long)
- {
- $lat = sanitise_string($lat);
- $long = sanitise_string($long);
-
- $this->set('geo:lat', $lat);
- $this->set('geo:long', $long);
-
- return true;
- }
-
- /**
- * Get the contents of the ->geo:lat field.
- *
- */
- public function getLatitude() { return $this->get('geo:lat'); }
-
- /**
- * Get the contents of the ->geo:lat field.
- *
- */
- public function getLongitude() { return $this->get('geo:long'); }
-
- /**
- * Get the ->location metadata.
- *
- */
- public function getLocation() { return $this->get('location'); }
-
- // NOTABLE INTERFACE ///////////////////////////////////////////////////////////////
-
- /**
- * Calendar functionality.
- * This function sets the time of an object on a calendar listing.
- *
- * @param int $hour If ommitted, now is assumed.
- * @param int $minute If ommitted, now is assumed.
- * @param int $second If ommitted, now is assumed.
- * @param int $day If ommitted, now is assumed.
- * @param int $month If ommitted, now is assumed.
- * @param int $year If ommitted, now is assumed.
- * @param int $duration Duration of event, remainder of the day is assumed.
- */
- public function setCalendarTimeAndDuration($hour = NULL, $minute = NULL, $second = NULL, $day = NULL, $month = NULL, $year = NULL, $duration = NULL)
- {
- $start = mktime($hour, $minute, $second, $month, $day, $year);
- $end = $start + abs($duration);
- if (!$duration)
- $end = get_day_end($day,$month,$year);
-
- $this->calendar_start = $start;
- $this->calendar_end = $end;
-
- return true;
- }
-
- /**
- * Return the start timestamp.
- */
- public function getCalendarStartTime() { return (int)$this->calendar_start; }
-
- /**
- * Return the end timestamp.
- */
- public function getCalendarEndTime() { return (int)$this->calendar_end; }
-
- // EXPORTABLE INTERFACE ////////////////////////////////////////////////////////////
-
- /**
- * Return an array of fields which can be exported.
- */
- public function getExportableValues()
- {
- return array(
- 'guid',
- 'type',
- 'subtype',
- 'time_created',
- 'container_guid',
- 'owner_guid',
- );
- }
-
- /**
- * Export this class into an array of ODD Elements containing all necessary fields.
- * Override if you wish to return more information than can be found in $this->attributes (shouldn't happen)
- */
- public function export()
- {
- $tmp = array();
-
- // Generate uuid
- $uuid = guid_to_uuid($this->getGUID());
-
- // Create entity
- $odd = new ODDEntity(
- $uuid,
- $this->attributes['type'],
- get_subtype_from_id($this->attributes['subtype'])
- );
-
- $tmp[] = $odd;
-
- $exportable_values = $this->getExportableValues();
-
- // Now add its attributes
- foreach ($this->attributes as $k => $v)
- {
- $meta = NULL;
-
- if (in_array( $k, $exportable_values)) {
- switch ($k)
- {
- case 'guid' : // Dont use guid in OpenDD
- case 'type' : // Type and subtype already taken care of
- case 'subtype' :
- break;
-
- case 'time_created' : // Created = published
- $odd->setAttribute('published', date("r", $v));
- break;
-
- case 'site_guid' : // Container
- $k = 'site_uuid';
- $v = guid_to_uuid($v);
- $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
- break;
-
- case 'container_guid' : // Container
- $k = 'container_uuid';
- $v = guid_to_uuid($v);
- $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
- break;
-
- case 'owner_guid' : // Convert owner guid to uuid, this will be stored in metadata
- $k = 'owner_uuid';
- $v = guid_to_uuid($v);
- $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
- break;
-
- default :
- $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
- }
-
- // set the time of any metadata created
- if ($meta)
- {
- $meta->setAttribute('published', date("r",$this->time_created));
- $tmp[] = $meta;
- }
- }
- }
-
- // Now we do something a bit special.
- /*
- * This provides a rendered view of the entity to foreign sites.
- */
-
- elgg_set_viewtype('default');
- $view = elgg_view_entity($this, true);
- elgg_set_viewtype();
-
- $tmp[] = new ODDMetaData($uuid . "volatile/renderedentity/", $uuid, 'renderedentity', $view , 'volatile');
-
-
- return $tmp;
- }
-
- // IMPORTABLE INTERFACE ////////////////////////////////////////////////////////////
-
- /**
- * Import data from an parsed xml data array.
- *
- * @param array $data
- * @param int $version
- */
- public function import(ODD $data)
- {
- if (!($data instanceof ODDEntity))
- throw new InvalidParameterException(elgg_echo('InvalidParameterException:UnexpectedODDClass'));
-
- // Set type and subtype
- $this->attributes['type'] = $data->getAttribute('class');
- $this->attributes['subtype'] = $data->getAttribute('subclass');
-
- // Set owner
- $this->attributes['owner_guid'] = get_loggedin_userid(); // Import as belonging to importer.
-
- // Set time
- $this->attributes['time_created'] = strtotime($data->getAttribute('published'));
- $this->attributes['time_updated'] = time();
-
- return true;
- }
-
- // SYSTEM LOG INTERFACE ////////////////////////////////////////////////////////////
-
- /**
- * Return an identification for the object for storage in the system log.
- * This id must be an integer.
- *
- * @return int
- */
- public function getSystemLogID() { return $this->getGUID(); }
-
- /**
- * Return the class name of the object.
- */
- public function getClassName() { return get_class($this); }
-
- /**
- * For a given ID, return the object associated with it.
- * This is used by the river functionality primarily.
- * This is useful for checking access permissions etc on objects.
- */
- public function getObjectFromID($id) { return get_entity($id); }
-
- /**
- * Return the GUID of the owner of this object.
- */
- public function getObjectOwnerGUID() { return $this->owner_guid; }
-
- // ITERATOR INTERFACE //////////////////////////////////////////////////////////////
- /*
- * This lets an entity's attributes be displayed using foreach as a normal array.
- * Example: http://www.sitepoint.com/print/php5-standard-library
- */
-
- private $valid = FALSE;
-
- function rewind()
- {
- $this->valid = (FALSE !== reset($this->attributes));
- }
-
- function current()
- {
- return current($this->attributes);
- }
-
- function key()
- {
- return key($this->attributes);
- }
-
- function next()
- {
- $this->valid = (FALSE !== next($this->attributes));
- }
-
- function valid()
- {
- return $this->valid;
- }
-
- // ARRAY ACCESS INTERFACE //////////////////////////////////////////////////////////
- /*
- * This lets an entity's attributes be accessed like an associative array.
- * Example: http://www.sitepoint.com/print/php5-standard-library
- */
-
- function offsetSet($key, $value)
- {
- if ( array_key_exists($key, $this->attributes) ) {
- $this->attributes[$key] = $value;
- }
- }
-
- function offsetGet($key)
- {
- if ( array_key_exists($key, $this->attributes) ) {
- return $this->attributes[$key];
- }
- }
-
- function offsetUnset($key)
- {
- if ( array_key_exists($key, $this->attributes) ) {
- $this->attributes[$key] = ""; // Full unsetting is dangerious for our objects
- }
- }
-
- function offsetExists($offset)
- {
- return array_key_exists($offset, $this->attributes);
- }
- }
-
- /**
- * Initialise the entity cache.
- */
- function initialise_entity_cache()
- {
- global $ENTITY_CACHE;
-
- if (!$ENTITY_CACHE)
- $ENTITY_CACHE = array(); //select_default_memcache('entity_cache'); // TODO: Replace with memcache?
- }
-
- /**
- * Invalidate this class' entry in the cache.
- *
- * @param int $guid The guid
- */
- function invalidate_cache_for_entity($guid)
- {
- global $ENTITY_CACHE;
-
- $guid = (int)$guid;
-
- unset($ENTITY_CACHE[$guid]);
- //$ENTITY_CACHE->delete($guid);
- }
-
- /**
- * Cache an entity.
- *
- * @param ElggEntity $entity Entity to cache
- */
- function cache_entity(ElggEntity $entity)
- {
- global $ENTITY_CACHE;
-
- $ENTITY_CACHE[$entity->guid] = $entity;
- }
-
- /**
- * Retrieve a entity from the cache.
- *
- * @param int $guid The guid
- */
- function retrieve_cached_entity($guid)
- {
- global $ENTITY_CACHE;
-
- $guid = (int)$guid;
-
- if (isset($ENTITY_CACHE[$guid]))
- if ($ENTITY_CACHE[$guid]->isFullyLoaded()) return $ENTITY_CACHE[$guid];
-
- return false;
- }
-
- /**
- * As retrieve_cached_entity, but returns the result as a stdClass (compatible with load functions that
- * expect a database row.)
- *
- * @param int $guid The guid
- */
- function retrieve_cached_entity_row($guid)
- {
- $obj = retrieve_cached_entity($guid);
- if ($obj)
- {
- $tmp = new stdClass;
-
- foreach ($obj as $k => $v)
- $tmp->$k = $v;
-
- return $tmp;
- }
-
- return false;
- }
-
- /**
- * Return the integer ID for a given subtype, or false.
- *
- * TODO: Move to a nicer place?
- *
- * @param string $type
- * @param string $subtype
- */
- function get_subtype_id($type, $subtype)
- {
- global $CONFIG, $SUBTYPE_CACHE;
-
- $type = sanitise_string($type);
- $subtype = sanitise_string($subtype);
-
- if ($subtype=="") return $subtype;
-
- // Todo: cache here? Or is looping less efficient that going to the db each time?
-
- $result = get_data_row("SELECT * from {$CONFIG->dbprefix}entity_subtypes where type='$type' and subtype='$subtype'");
-
- if ($result) {
-
- if (!$SUBTYPE_CACHE)
- $SUBTYPE_CACHE = array(); //select_default_memcache('subtype_cache');
-
- $SUBTYPE_CACHE[$result->id] = $result;
- return $result->id;
- }
-
- return 0;
- }
-
- /**
- * For a given subtype ID, return its identifier text.
- *
- * TODO: Move to a nicer place?
- *
- * @param int $subtype_id
- */
- function get_subtype_from_id($subtype_id)
- {
- global $CONFIG, $SUBTYPE_CACHE;
-
- $subtype_id = (int)$subtype_id;
-
- if (!$subtype_id) return false;
-
- if (isset($SUBTYPE_CACHE[$subtype_id]))
- return $SUBTYPE_CACHE[$subtype_id]->subtype;
-
- $result = get_data_row("SELECT * from {$CONFIG->dbprefix}entity_subtypes where id=$subtype_id");
- if ($result) {
-
- if (!$SUBTYPE_CACHE)
- $SUBTYPE_CACHE = array(); //select_default_memcache('subtype_cache');
-
- $SUBTYPE_CACHE[$subtype_id] = $result;
- return $result->subtype;
- }
-
- return false;
- }
-
- /**
- * This function tests to see if a subtype has a registered class handler.
- *
- * @param string $type The type
- * @param string $subtype The subtype
- * @return a class name or null
- */
- function get_subtype_class($type, $subtype)
- {
- global $CONFIG, $SUBTYPE_CACHE;
-
- $type = sanitise_string($type);
- $subtype = sanitise_string($subtype);
-
- // Todo: cache here? Or is looping less efficient that going to the db each time?
-
- $result = get_data_row("SELECT * from {$CONFIG->dbprefix}entity_subtypes where type='$type' and subtype='$subtype'");
- if ($result) {
-
- if (!$SUBTYPE_CACHE)
- $SUBTYPE_CACHE = array(); //select_default_memcache('subtype_cache');
-
- $SUBTYPE_CACHE[$result->id] = $result;
- return $result->class;
- }
-
- return NULL;
- }
-
- /**
- * This function tests to see if a subtype has a registered class handler by its id.
- *
- * @param int $subtype_id The subtype
- * @return a class name or null
- */
- function get_subtype_class_from_id($subtype_id)
- {
- global $CONFIG, $SUBTYPE_CACHE;
-
- $subtype_id = (int)$subtype_id;
-
- if (!$subtype_id) return false;
-
- if (isset($SUBTYPE_CACHE[$subtype_id]))
- return $SUBTYPE_CACHE[$subtype_id]->class;
-
- $result = get_data_row("SELECT * from {$CONFIG->dbprefix}entity_subtypes where id=$subtype_id");
- if ($result) {
-
- if (!$SUBTYPE_CACHE)
- $SUBTYPE_CACHE = array(); //select_default_memcache('subtype_cache');
-
- $SUBTYPE_CACHE[$subtype_id] = $result;
- return $result->class;
- }
-
- return NULL;
- }
-
- /**
- * This function will register a new subtype, returning its ID as required.
- *
- * @param string $type The type you're subtyping
- * @param string $subtype The subtype label
- * @param string $class Optional class handler (if you don't want it handled by the generic elgg handler for the type)
- */
- function add_subtype($type, $subtype, $class = "")
- {
- global $CONFIG;
- $type = sanitise_string($type);
- $subtype = sanitise_string($subtype);
- $class = sanitise_string($class);
-
- // Short circuit if no subtype is given
- if ($subtype == "")
- return 0;
-
- $id = get_subtype_id($type, $subtype);
-
- if ($id==0)
- return insert_data("insert into {$CONFIG->dbprefix}entity_subtypes (type, subtype, class) values ('$type','$subtype','$class')");
-
- return $id;
- }
-
- /**
- * Update an existing entity.
- *
- * @param int $guid
- * @param int $owner_guid
- * @param int $access_id
- * @param int $container_guid
- */
- function update_entity($guid, $owner_guid, $access_id, $container_guid = null)
- {
- global $CONFIG, $ENTITY_CACHE;
-
- $guid = (int)$guid;
- $owner_guid = (int)$owner_guid;
- $access_id = (int)$access_id;
- $container_guid = (int) $container_guid;
- if (is_null($container_guid)) $container_guid = $owner_guid;
- $time = time();
-
- $entity = get_entity($guid);
-
- if ($entity->canEdit()) {
-
- if (trigger_elgg_event('update',$entity->type,$entity)) {
- $ret = update_data("UPDATE {$CONFIG->dbprefix}entities set owner_guid='$owner_guid', access_id='$access_id', container_guid='$container_guid', time_updated='$time' WHERE guid=$guid");
-
- if ($entity instanceof ElggObject)
- update_river_access_by_object($guid,$access_id);
-
- // If memcache is available then delete this entry from the cache
- static $newentity_cache;
- if ((!$newentity_cache) && (is_memcache_available()))
- $newentity_cache = new ElggMemcache('new_entity_cache');
- if ($newentity_cache) $new_entity = $newentity_cache->delete($guid);
-
- // Handle cases where there was no error BUT no rows were updated!
- if ($ret===false)
- return false;
-
- return true;
- }
-
- }
- }
-
- /**
- * Determine whether a given user is able to write to a given container.
- *
- * @param int $user_guid The user guid, or 0 for get_loggedin_userid()
- * @param int $container_guid The container, or 0 for the current page owner.
- */
- function can_write_to_container($user_guid = 0, $container_guid = 0, $entity_type = 'all')
- {
- global $CONFIG;
-
- $user_guid = (int)$user_guid;
- $user = get_entity($user_guid);
- if (!$user) $user = get_loggedin_user();
-
- $container_guid = (int)$container_guid;
- if (!$container_guid) $container_guid = page_owner();
- if (!$container_guid) return true;
-
- $container = get_entity($container_guid);
-
- if ($container)
- {
-
- // If the user can edit the container, they can also write to it
- if ($container->canEdit($user_guid)) return true;
-
- // Basics, see if the user is a member of the group.
- if ($user && $container instanceof ElggGroup) {
- if (!$container->isMember($user)) {
- return false;
- } else {
- return true;
- }
- }
-
- // See if anyone else has anything to say
- return trigger_plugin_hook('container_permissions_check',$entity_type,array('container' => $container, 'user' => $user), false);
-
- }
-
- return false;
- }
-
- /**
- * Create a new entity of a given type.
- *
- * @param string $type The type of the entity (site, user, object).
- * @param string $subtype The subtype of the entity.
- * @param int $owner_guid The GUID of the object's owner.
- * @param int $access_id The access control group to create the entity with.
- * @param int $site_guid The site to add this entity to. Leave as 0 (default) for the current site.
- * @return mixed The new entity's GUID, or false on failure
- */
- function create_entity($type, $subtype, $owner_guid, $access_id, $site_guid = 0, $container_guid = 0)
- {
- global $CONFIG;
-
- $type = sanitise_string($type);
- $subtype = add_subtype($type, $subtype);
- $owner_guid = (int)$owner_guid;
- $access_id = (int)$access_id;
- $time = time();
- if ($site_guid == 0)
- $site_guid = $CONFIG->site_guid;
- $site_guid = (int) $site_guid;
- if ($container_guid == 0) $container_guid = $owner_guid;
-
- $user = get_loggedin_user();
- if (!can_write_to_container($user->guid, $owner_guid, $type)) return false;
- if ($owner_guid != $container_guid)
- if (!can_write_to_container($user->guid, $container_guid, $type)) return false;
-
- if ($type=="") throw new InvalidParameterException(elgg_echo('InvalidParameterException:EntityTypeNotSet'));
-
- return insert_data("INSERT into {$CONFIG->dbprefix}entities (type, subtype, owner_guid, site_guid, container_guid, access_id, time_created, time_updated) values ('$type',$subtype, $owner_guid, $site_guid, $container_guid, $access_id, $time, $time)");
- }
-
- /**
- * Retrieve the entity details for a specific GUID, returning it as a stdClass db row.
- *
- * You will only get an object if a) it exists, b) you have access to it.
- *
- * @param int $guid The GUID of the object to extract
- */
- function get_entity_as_row($guid)
- {
- global $CONFIG;
-
- if (!$guid) return false;
-
- $guid = (int) $guid;
-
- /*$row = retrieve_cached_entity_row($guid);
- if ($row)
- {
- // We have already cached this object, so retrieve its value from the cache
- if (isset($CONFIG->debug) && $CONFIG->debug)
- error_log("** Retrieving GUID:$guid from cache");
-
- return $row;
- }
- else
- {*/
- // Object not cached, load it.
- if (isset($CONFIG->debug) && $CONFIG->debug == true)
- error_log("** GUID:$guid loaded from DB");
-
- $access = get_access_sql_suffix();
-
- return get_data_row("SELECT * from {$CONFIG->dbprefix}entities where guid=$guid and $access");
- //}
- }
-
- /**
- * Create an Elgg* object from a given entity row.
- */
- function entity_row_to_elggstar($row)
- {
- if (!($row instanceof stdClass))
- return $row;
-
- if ((!isset($row->guid)) || (!isset($row->subtype)))
- return $row;
-
- $new_entity = false;
-
- // Create a memcache cache if we can
- static $newentity_cache;
- if ((!$newentity_cache) && (is_memcache_available()))
- $newentity_cache = new ElggMemcache('new_entity_cache');
- if ($newentity_cache) $new_entity = $newentity_cache->load($row->guid);
- if ($new_entity) return $new_entity;
-
- $classname = get_subtype_class_from_id($row->subtype);
- if ($classname!="")
- {
- if (class_exists($classname))
- {
- $new_entity = new $classname($row);
-
- if (!($new_entity instanceof ElggEntity))
- throw new ClassException(sprintf(elgg_echo('ClassException:ClassnameNotClass'), $classname, 'ElggEntity'));
- }
- else
- error_log(sprintf(elgg_echo('ClassNotFoundException:MissingClass'), $classname));
- }
- else
- {
- switch ($row->type)
- {
- case 'object' :
- $new_entity = new ElggObject($row); break;
- case 'user' :
- $new_entity = new ElggUser($row); break;
- case 'group' :
- $new_entity = new ElggGroup($row); break;
- case 'site' :
- $new_entity = new ElggSite($row); break;
- default: throw new InstallationException(sprintf(elgg_echo('InstallationException:TypeNotSupported'), $row->type));
- }
-
- }
-
- // Cache entity if we have a cache available
- if (($newentity_cache) && ($new_entity)) $newentity_cache->save($new_entity->guid, $new_entity);
-
- return $new_entity;
- }
-
- /**
- * Return the entity for a given guid as the correct object.
- * @param int $guid The GUID of the entity
- * @return a child of ElggEntity appropriate for the type.
- */
- function get_entity($guid)
- {
- static $newentity_cache;
- $new_entity = false;
- if ((!$newentity_cache) && (is_memcache_available()))
- $newentity_cache = new ElggMemcache('new_entity_cache');
- if ($newentity_cache) $new_entity = $newentity_cache->load($guid);
- if ($new_entity) return $new_entity;
-
- return entity_row_to_elggstar(get_entity_as_row($guid));
- }
-
- /**
- * Return entities matching a given query, or the number thereof
- *
- * @param string $type The type of entity (eg "user", "object" etc)
- * @param string|array $subtype The arbitrary subtype of the entity or array(type1 => array('subtype1', ...'subtypeN'), ...)
- * @param int $owner_guid The GUID of the owning user
- * @param string $order_by The field to order by; by default, time_created desc
- * @param int $limit The number of entities to return; 10 by default
- * @param int $offset The indexing offset, 0 by default
- * @param boolean $count Set to true to get a count rather than the entities themselves (limits and offsets don't apply in this context). Defaults to false.
- * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
- * @param int|array $container_guid The container or containers to get entities from (default: all containers).
- * @param int $timelower The earliest time the entity can have been created. Default: all
- * @param int $timeupper The latest time the entity can have been created. Default: all
- * @return array A list of entities.
- */
- function get_entities($type = "", $subtype = "", $owner_guid = 0, $order_by = "", $limit = 10, $offset = 0, $count = false, $site_guid = 0, $container_guid = null, $timelower = 0, $timeupper = 0)
- {
- global $CONFIG;
-
- if ($subtype === false || $subtype === null || $subtype === 0)
- return false;
-
- if ($order_by == "") $order_by = "time_created desc";
- $order_by = sanitise_string($order_by);
- $limit = (int)$limit;
- $offset = (int)$offset;
- $site_guid = (int) $site_guid;
- $timelower = (int) $timelower;
- $timeupper = (int) $timeupper;
- if ($site_guid == 0)
- $site_guid = $CONFIG->site_guid;
-
- $where = array();
-
- if (is_array($subtype)) {
- $tempwhere = "";
- if (sizeof($subtype))
- foreach($subtype as $typekey => $subtypearray) {
- foreach($subtypearray as $subtypeval) {
- $typekey = sanitise_string($typekey);
- if (!empty($subtypeval)) {
- if (!$subtypeval = (int) get_subtype_id($typekey, $subtypeval))
- return false;
- } else {
- // @todo: Setting subtype to 0 when $subtype = '' returns entities with
- // no subtype. This is different to the non-array behavior
- // but may be required in some cases.
- $subtypeval = 0;
- }
- if (!empty($tempwhere)) $tempwhere .= " or ";
- $tempwhere .= "(type = '{$typekey}' and subtype = {$subtypeval})";
- }
- }
- if (!empty($tempwhere)) $where[] = "({$tempwhere})";
-
- } else {
-
- $type = sanitise_string($type);
- if ($subtype !== "" AND !$subtype = get_subtype_id($type, $subtype))
- return false;
-
- if ($type != "")
- $where[] = "type='$type'";
- if ($subtype!=="")
- $where[] = "subtype=$subtype";
- }
-
- if ($owner_guid != "") {
- if (!is_array($owner_guid)) {
- $owner_array = array($owner_guid);
- $owner_guid = (int) $owner_guid;
- // $where[] = "owner_guid = '$owner_guid'";
- } else if (sizeof($owner_guid) > 0) {
- $owner_array = array_map('sanitise_int', $owner_guid);
- // Cast every element to the owner_guid array to int
- // $owner_guid = array_map("sanitise_int", $owner_guid);
- // $owner_guid = implode(",",$owner_guid);
- // $where[] = "owner_guid in ({$owner_guid})";
- }
- if (is_null($container_guid)) {
- $container_guid = $owner_array;
- }
- }
- if ($site_guid > 0)
- $where[] = "site_guid = {$site_guid}";
-
- if (!is_null($container_guid)) {
- if (is_array($container_guid)) {
- foreach($container_guid as $key => $val) $container_guid[$key] = (int) $val;
- $where[] = "container_guid in (" . implode(",",$container_guid) . ")";
- } else {
- $container_guid = (int) $container_guid;
- $where[] = "container_guid = {$container_guid}";
- }
- }
- if ($timelower)
- $where[] = "time_created >= {$timelower}";
- if ($timeupper)
- $where[] = "time_created <= {$timeupper}";
-
- if (!$count) {
- $query = "SELECT * from {$CONFIG->dbprefix}entities where ";
- } else {
- $query = "SELECT count(guid) as total from {$CONFIG->dbprefix}entities where ";
- }
- foreach ($where as $w)
- $query .= " $w and ";
- $query .= get_access_sql_suffix(); // Add access controls
- if (!$count) {
- $query .= " order by $order_by";
- if ($limit) $query .= " limit $offset, $limit"; // Add order and limit
- $dt = get_data($query, "entity_row_to_elggstar");
- return $dt;
- } else {
- $total = get_data_row($query);
- return $total->total;
- }
- }
-
- /**
- * Returns a viewable list of entities
- *
- * @see elgg_view_entity_list
- *
- * @param string $type The type of entity (eg "user", "object" etc)
- * @param string $subtype The arbitrary subtype of the entity
- * @param int $owner_guid The GUID of the owning user
- * @param int $limit The number of entities to display per page (default: 10)
- * @param true|false $fullview Whether or not to display the full view (default: true)
- * @param true|false $viewtypetoggle Whether or not to allow gallery view
- * @param true|false $pagination Display pagination? Default: true
- * @return string A viewable list of entities
- */
- function list_entities($type= "", $subtype = "", $owner_guid = 0, $limit = 10, $fullview = true, $viewtypetoggle = false, $pagination = true) {
-
- $offset = (int) get_input('offset');
- $count = get_entities($type, $subtype, $owner_guid, "", $limit, $offset, true);
- $entities = get_entities($type, $subtype, $owner_guid, "", $limit, $offset);
-
- return elgg_view_entity_list($entities, $count, $offset, $limit, $fullview, $viewtypetoggle, $pagination);
-
- }
-
- /**
- * Returns a viewable list of entities contained in a number of groups.
- *
- * @param string $subtype The arbitrary subtype of the entity
- * @param int $owner_guid The GUID of the owning user
- * @param int $container_guid The GUID of the containing group
- * @param int $limit The number of entities to display per page (default: 10)
- * @param true|false $fullview Whether or not to display the full view (default: true)
- * @return string A viewable list of entities
- */
- function list_entities_groups($subtype = "", $owner_guid = 0, $container_guid = 0, $limit = 10, $fullview = true)
- {
- $offset = (int) get_input('offset');
- $count = get_objects_in_group($container_guid, $subtype, $owner_guid, 0, "", $limit, $offset, true);
- $entities = get_objects_in_group($container_guid, $subtype, $owner_guid, 0, "", $limit, $offset);
-
- return elgg_view_entity_list($entities, $count, $offset, $limit, $fullview);
- }
-
- /**
- * Returns a list of months containing content specified by the parameters
- *
- * @param string $type The type of entity
- * @param string $subtype The subtype of entity
- * @param int $container_guid The container GUID that the entinties belong to
- * @param int $site_guid The site GUID
- * @return array|false Either an array of timestamps, or false on failure
- */
- function get_entity_dates($type = '', $subtype = '', $container_guid = 0, $site_guid = 0) {
-
- global $CONFIG;
-
- $site_guid = (int) $site_guid;
- if ($site_guid == 0)
- $site_guid = $CONFIG->site_guid;
-
- $where = array();
-
- if ($type != "") {
- $type = sanitise_string($type);
- $where[] = "type='$type'";
- }
-
- if (is_array($subtype)) {
- $tempwhere = "";
- if (sizeof($subtype))
- foreach($subtype as $typekey => $subtypearray) {
- foreach($subtypearray as $subtypeval) {
- $typekey = sanitise_string($typekey);
- if (!empty($subtypeval)) {
- if (!$subtypeval = (int) get_subtype_id($typekey, $subtypeval))
- return false;
- } else {
- $subtypeval = 0;
- }
- if (!empty($tempwhere)) $tempwhere .= " or ";
- $tempwhere .= "(type = '{$typekey}' and subtype = {$subtypeval})";
- }
- }
- if (!empty($tempwhere)) $where[] = "({$tempwhere})";
-
- } else {
- if ($subtype AND !$subtype = get_subtype_id($type, $subtype)) {
- return false;
- } else {
- $where[] = "subtype=$subtype";
- }
- }
-
- if ($container_guid !== 0) {
- if (is_array($container_guid)) {
- foreach($container_guid as $key => $val) $container_guid[$key] = (int) $val;
- $where[] = "container_guid in (" . implode(",",$container_guid) . ")";
- } else {
- $container_guid = (int) $container_guid;
- $where[] = "container_guid = {$container_guid}";
- }
- }
-
- if ($site_guid > 0)
- $where[] = "site_guid = {$site_guid}";
-
- $where[] = get_access_sql_suffix();
-
- $sql = "SELECT DISTINCT EXTRACT(YEAR_MONTH FROM FROM_UNIXTIME(time_created)) AS yearmonth FROM {$CONFIG->dbprefix}entities where ";
- foreach ($where as $w)
- $sql .= " $w and ";
- $sql .= "1=1";
- if ($result = get_data($sql)) {
- $endresult = array();
- foreach($result as $res) {
- $endresult[] = $res->yearmonth;
- }
- return $endresult;
- }
- return false;
-
- }
-
- /**
- * Disable an entity but not delete it.
- *
- * @param int $guid The guid
- * @param string $reason Optional reason
- */
- function disable_entity($guid, $reason = "", $recursive = true)
- {
- global $CONFIG;
-
- $guid = (int)$guid;
- $reason = sanitise_string($reason);
-
- if ($entity = get_entity($guid)) {
- if (trigger_elgg_event('disable',$entity->type,$entity)) {
- if ($entity->canEdit()) {
-
- if ($reason)
- create_metadata($guid, 'disable_reason', $reason,'', 0, ACCESS_PUBLIC);
-
- if ($recursive)
- {
- // Temporary token overriding access controls TODO: Do this better.
- static $__RECURSIVE_DELETE_TOKEN;
- $__RECURSIVE_DELETE_TOKEN = md5(get_loggedin_userid()); // Make it slightly harder to guess
-
- $sub_entities = get_data("SELECT * from {$CONFIG->dbprefix}entities WHERE container_guid=$guid or owner_guid=$guid or site_guid=$guid", 'entity_row_to_elggstar');
- if ($sub_entities) {
- foreach ($sub_entities as $e)
- $e->disable($reason);
- }
-
- $__RECURSIVE_DELETE_TOKEN = null;
- }
-
- $res = update_data("UPDATE {$CONFIG->dbprefix}entities set enabled='no' where guid={$guid}");
-
- return $res;
- }
- }
- }
- return false;
- }
-
- /**
- * Enable an entity again.
- *
- * @param int $guid
- */
- function enable_entity($guid)
- {
- global $CONFIG;
-
- $guid = (int)$guid;
-
- // Override access only visible entities
- $access_status = access_get_show_hidden_status();
- access_show_hidden_entities(true);
-
- if ($entity = get_entity($guid)) {
- if (trigger_elgg_event('enable',$entity->type,$entity)) {
- if ($entity->canEdit()) {
-
- access_show_hidden_entities($access_status);
-
- $result = update_data("UPDATE {$CONFIG->dbprefix}entities set enabled='yes' where guid={$guid}");
- $entity->clearMetaData('disable_reason');
-
- return $result;
- }
- }
- }
-
- access_show_hidden_entities($access_status);
- return false;
- }
-
- /**
- * Delete a given entity.
- *
- * @param int $guid
- * @param bool $recursive If true (default) then all entities which are owned or contained by $guid will also be deleted.
- * Note: this bypasses ownership of sub items.
- */
- function delete_entity($guid, $recursive = true)
- {
- global $CONFIG;
-
- $guid = (int)$guid;
- if ($entity = get_entity($guid)) {
- if (trigger_elgg_event('delete',$entity->type,$entity)) {
- if ($entity->canEdit()) {
-
- // Delete contained owned and otherwise releated objects (depth first)
- if ($recursive)
- {
- // Temporary token overriding access controls TODO: Do this better.
- static $__RECURSIVE_DELETE_TOKEN;
- $__RECURSIVE_DELETE_TOKEN = md5(get_loggedin_userid()); // Make it slightly harder to guess
-
- $sub_entities = get_data("SELECT * from {$CONFIG->dbprefix}entities WHERE container_guid=$guid or owner_guid=$guid or site_guid=$guid", 'entity_row_to_elggstar');
- if ($sub_entities) {
- foreach ($sub_entities as $e)
- $e->delete();
- }
-
- $__RECURSIVE_DELETE_TOKEN = null;
- }
-
- // Now delete the entity itself
- $entity->clearMetadata();
- $entity->clearAnnotations();
- $entity->clearRelationships();
- remove_from_river_by_subject($guid);
+ if ($md && !is_array($md)) {
+ return $md->value;
+ } else if ($md && is_array($md)) {
+ return metadata_array_to_values($md);
+ }
+
+ return null;
+ }
+
+ /**
+ * Class member get overloading
+ *
+ * @param string $name
+ * @return mixed
+ */
+ function __get($name) { return $this->get($name); }
+
+ /**
+ * Class member set overloading
+ *
+ * @param string $name
+ * @param mixed $value
+ * @return mixed
+ */
+ function __set($name, $value) { return $this->set($name, $value); }
+
+ /**
+ * Supporting isset.
+ *
+ * @param string $name The name of the attribute or metadata.
+ * @return bool
+ */
+ function __isset($name) { if ($this->$name!="") return true; else return false; }
+
+ /**
+ * Supporting unsetting of magic attributes.
+ *
+ * @param string $name The name of the attribute or metadata.
+ */
+ function __unset($name)
+ {
+ if (array_key_exists($name, $this->attributes))
+ $this->attributes[$name] = "";
+ else
+ $this->clearMetaData($name);
+ }
+
+ /**
+ * Set a piece of metadata.
+ *
+ * @param string $name
+ * @param mixed $value
+ * @param string $value_type
+ * @param bool $multiple
+ * @return bool
+ */
+ public function setMetaData($name, $value, $value_type = "", $multiple = false)
+ {
+ if (is_array($value))
+ {
+ unset($this->temp_metadata[$name]);
+ remove_metadata($this->getGUID(), $name);
+ foreach ($value as $v) {
+ if ((int) $this->guid > 0) {
+ $multiple = true;
+ if (!create_metadata($this->getGUID(), $name, $v, $value_type, $this->getOwner(), $this->getAccessID(), $multiple)) return false;
+ } else {
+ if (($multiple) && (isset($this->temp_metadata[$name])))
+ {
+ if (!is_array($this->temp_metadata[$name]))
+ {
+ $tmp = $this->temp_metadata[$name];
+ $this->temp_metadata[$name] = array();
+ $this->temp_metadata[$name][] = $tmp;
+ }
+
+ $this->temp_metadata[$name][] = $value;
+ }
+ else
+ $this->temp_metadata[$name] = $value;
+ }
+ }
+
+ return true;
+ }
+ else
+ {
+ unset($this->temp_metadata[$name]);
+ if ((int) $this->guid > 0) {
+ return create_metadata($this->getGUID(), $name, $value, $value_type, $this->getOwner(), $this->getAccessID(), $multiple);
+ } else {
+ //$this->temp_metadata[$name] = $value;
+
+ if (($multiple) && (isset($this->temp_metadata[$name])))
+ {
+ if (!is_array($this->temp_metadata[$name]))
+ {
+ $tmp = $this->temp_metadata[$name];
+ $this->temp_metadata[$name] = array();
+ $this->temp_metadata[$name][] = $tmp;
+ }
+
+ $this->temp_metadata[$name][] = $value;
+ }
+ else
+ $this->temp_metadata[$name] = $value;
+
+ return true;
+ }
+ }
+ }
+
+ /**
+ * Clear metadata.
+ */
+ public function clearMetaData($name = "")
+ {
+ if (empty($name)) {
+ return clear_metadata($this->getGUID());
+ } else {
+ return remove_metadata($this->getGUID(),$name);
+ }
+ }
+
+ /**
+ * Remove all entities associated with this entity
+ *
+ * @return true
+ */
+ public function clearRelationships() {
+ remove_entity_relationships($this->getGUID());
+ remove_entity_relationships($this->getGUID(),"",true);
+ return true;
+ }
+
+ /**
+ * Add a relationship.
+ *
+ * @param int $guid Relationship to link to.
+ * @param string $relationship The type of relationship.
+ */
+ public function addRelationship($guid, $relationship)
+ {
+ return add_entity_relationship($this->getGUID(), $relationship, $guid);
+ }
+
+ function setPrivateSetting($name, $value) {
+ return set_private_setting($this->getGUID(), $name, $value);
+ }
+
+ function getPrivateSetting($name) {
+ return get_private_setting($this->getGUID(), $name);
+ }
+
+ function removePrivateSetting($name) {
+ return remove_private_setting($this->getGUID(), $name);
+ }
+
+ /**
+ * Adds an annotation to an entity. By default, the type is detected automatically; however,
+ * it can also be set. Note that by default, annotations are private.
+ *
+ * @param string $name
+ * @param mixed $value
+ * @param int $access_id
+ * @param int $owner_id
+ * @param string $vartype
+ */
+ function annotate($name, $value, $access_id = ACCESS_PRIVATE, $owner_id = 0, $vartype = "")
+ {
+ if ((int) $this->guid > 0) {
+ return create_annotation($this->getGUID(), $name, $value, $vartype, $owner_id, $access_id);
+ } else {
+ $this->temp_annotations[$name] = $value;
+ }
+ return true;
+ }
+
+ /**
+ * Get the annotations for an entity.
+ *
+ * @param string $name
+ * @param int $limit
+ * @param int $offset
+ * @param string $order
+ */
+ function getAnnotations($name, $limit = 50, $offset = 0, $order="asc")
+ {
+ if ((int) ($this->guid) > 0) {
+ return get_annotations($this->getGUID(), "", "", $name, "", 0, $limit, $offset, $order);
+ } else {
+ return $this->temp_annotations[$name];
+ }
+ }
+
+ /**
+ * Remove all annotations or all annotations for this entity.
+ *
+ * @param string $name
+ */
+ function clearAnnotations($name = "")
+ {
+ return clear_annotations($this->getGUID(), $name);
+ }
+
+ /**
+ * Return the annotations for the entity.
+ *
+ * @param string $name The type of annotation.
+ */
+ function countAnnotations($name = "")
+ {
+ return count_annotations($this->getGUID(), "","",$name);
+ }
+
+ /**
+ * Get the average of an integer type annotation.
+ *
+ * @param string $name
+ */
+ function getAnnotationsAvg($name)
+ {
+ return get_annotations_avg($this->getGUID(), "","",$name);
+ }
+
+ /**
+ * Get the sum of integer type annotations of a given name.
+ *
+ * @param string $name
+ */
+ function getAnnotationsSum($name)
+ {
+ return get_annotations_sum($this->getGUID(), "","",$name);
+ }
+
+ /**
+ * Get the minimum of integer type annotations of given name.
+ *
+ * @param string $name
+ */
+ function getAnnotationsMin($name)
+ {
+ return get_annotations_min($this->getGUID(), "","",$name);
+ }
+
+ /**
+ * Get the maximum of integer type annotations of a given name.
+ *
+ * @param string $name
+ */
+ function getAnnotationsMax($name)
+ {
+ return get_annotations_max($this->getGUID(), "","",$name);
+ }
+
+ /**
+ * Gets an array of entities from a specific relationship type
+ *
+ * @param string $relationship Relationship type (eg "friends")
+ * @param true|false $inverse Is this an inverse relationship?
+ * @param int $limit Number of elements to return
+ * @param int $offset Indexing offset
+ * @return array|false An array of entities or false on failure
+ */
+ function getEntitiesFromRelationship($relationship, $inverse = false, $limit = 50, $offset = 0) {
+ return get_entities_from_relationship($relationship,$this->getGUID(),$inverse,"","","","time_created desc",$limit,$offset);
+ }
+
+ /**
+ * Gets the number of of entities from a specific relationship type
+ *
+ * @param string $relationship Relationship type (eg "friends")
+ * @return int|false The number of entities or false on failure
+ */
+ function countEntitiesFromRelationship($relationship) {
+ return get_entities_from_relationship($relationship,$this->getGUID(),false,"","","","time_created desc",null,null,true);
+ }
+
+ /**
+ * Determines whether or not the specified user (by default the current one) can edit the entity
+ *
+ * @param int $user_guid The user GUID, optionally (defaults to the currently logged in user)
+ * @return true|false
+ */
+ function canEdit($user_guid = 0) {
+ return can_edit_entity($this->getGUID(),$user_guid);
+ }
+
+ /**
+ * Determines whether or not the specified user (by default the current one) can edit metadata on the entity
+ *
+ * @param ElggMetadata $metadata The piece of metadata to specifically check
+ * @param int $user_guid The user GUID, optionally (defaults to the currently logged in user)
+ * @return true|false
+ */
+ function canEditMetadata($metadata = null, $user_guid = 0) {
+ return can_edit_entity_metadata($this->getGUID(), $user_guid, $metadata);
+ }
+
+ /**
+ * Returns whether the given user (or current user) has the ability to write to this group.
+ *
+ * @param int $user_guid The user.
+ * @return bool
+ */
+ public function canWriteToContainer($user_guid = 0)
+ {
+ return can_write_to_container($user_guid, $this->getGUID());
+ }
+
+ /**
+ * Obtain this entity's access ID
+ *
+ * @return int The access ID
+ */
+ public function getAccessID() { return $this->get('access_id'); }
+
+ /**
+ * Obtain this entity's GUID
+ *
+ * @return int GUID
+ */
+ public function getGUID() { return $this->get('guid'); }
+
+ /**
+ * Get the owner of this entity
+ *
+ * @return int The owner GUID
+ */
+ public function getOwner() { return $this->get('owner_guid'); }
+
+ /**
+ * Returns the actual entity of the user who owns this entity, if any
+ *
+ * @return ElggEntity The owning user
+ */
+ public function getOwnerEntity() { return get_entity($this->get('owner_guid')); }
+
+ /**
+ * Gets the type of entity this is
+ *
+ * @return string Entity type
+ */
+ public function getType() { return $this->get('type'); }
+
+ /**
+ * Returns the subtype of this entity
+ *
+ * @return string The entity subtype
+ */
+ public function getSubtype() {
+ if (!((int) $this->guid > 0)) return $this->get('subtype'); // If this object hasn't been saved, then return the subtype string.
+
+ return get_subtype_from_id($this->get('subtype'));
+ }
+
+ /**
+ * Gets the UNIX epoch time that this entity was created
+ *
+ * @return int UNIX epoch time
+ */
+ public function getTimeCreated() { return $this->get('time_created'); }
+
+ /**
+ * Gets the UNIX epoch time that this entity was last updated
+ *
+ * @return int UNIX epoch time
+ */
+ public function getTimeUpdated() { return $this->get('time_updated'); }
+
+ /**
+ * Gets the display URL for this entity
+ *
+ * @return string The URL
+ */
+ public function getURL() {
+ if (!empty($this->url_override)) return $this->url_override;
+ return get_entity_url($this->getGUID());
+ }
+
+ /**
+ * Overrides the URL returned by getURL
+ *
+ * @param string $url The new item URL
+ * @return string The URL
+ */
+ public function setURL($url) {
+ $this->url_override = $url;
+ return $url;
+ }
+
+ /**
+ * Return a url for the entity's icon, trying multiple alternatives.
+ *
+ * @param string $size Either 'large','medium','small' or 'tiny'
+ * @return string The url or false if no url could be worked out.
+ */
+ public function getIcon($size = 'medium')
+ {
+ if (isset($this->icon_override[$size])) return $this->icon_override[$size];
+ return get_entity_icon_url($this, $size);
+ }
+
+ /**
+ * Set an icon override for an icon and size.
+ *
+ * @param string $url The url of the icon.
+ * @param string $size The size its for.
+ * @return bool
+ */
+ public function setIcon($url, $size = 'medium')
+ {
+ $url = sanitise_string($url);
+ $size = sanitise_string($size);
+
+ if (!$this->icon_override) $this->icon_override = array();
+ $this->icon_override[$size] = $url;
+
+ return true;
+ }
+
+ /**
+ * Tests to see whether the object has been fully loaded.
+ *
+ * @return bool
+ */
+ public function isFullyLoaded() { return ! ($this->attributes['tables_loaded'] < $this->attributes['tables_split']); }
+
+ /**
+ * Save generic attributes to the entities table.
+ */
+ public function save()
+ {
+ $guid = (int) $this->guid;
+ if ($guid > 0)
+ {
+ cache_entity($this);
+
+ return update_entity(
+ $this->get('guid'),
+ $this->get('owner_guid'),
+ $this->get('access_id'),
+ $this->get('container_guid')
+ );
+ }
+ else
+ {
+ $this->attributes['guid'] = create_entity($this->attributes['type'], $this->attributes['subtype'], $this->attributes['owner_guid'], $this->attributes['access_id'], $this->attributes['site_guid'], $this->attributes['container_guid']); // Create a new entity (nb: using attribute array directly 'cos set function does something special!)
+ if (!$this->attributes['guid']) throw new IOException(elgg_echo('IOException:BaseEntitySaveFailed'));
+
+ // Save any unsaved metadata TODO: How to capture extra information (access id etc)
+ if (sizeof($this->temp_metadata) > 0) {
+ foreach($this->temp_metadata as $name => $value) {
+ $this->$name = $value;
+ unset($this->temp_metadata[$name]);
+ }
+ }
+
+ // Save any unsaved annotations metadata. TODO: How to capture extra information (access id etc)
+ if (sizeof($this->temp_annotations) > 0) {
+ foreach($this->temp_annotations as $name => $value) {
+ $this->annotate($name, $value);
+ unset($this->temp_annotations[$name]);
+ }
+ }
+
+ // Cache object handle
+ if ($this->attributes['guid']) cache_entity($this);
+
+ return $this->attributes['guid'];
+ }
+ }
+
+ /**
+ * Load the basic entity information and populate base attributes array.
+ *
+ * @param int $guid
+ */
+ protected function load($guid)
+ {
+ $row = get_entity_as_row($guid);
+
+ if ($row)
+ {
+ // Create the array if necessary - all subclasses should test before creating
+ if (!is_array($this->attributes)) $this->attributes = array();
+
+ // Now put these into the attributes array as core values
+ $objarray = (array) $row;
+ foreach($objarray as $key => $value)
+ $this->attributes[$key] = $value;
+
+ // Increment the portion counter
+ if (!$this->isFullyLoaded()) $this->attributes['tables_loaded'] ++;
+
+ // Cache object handle
+ if ($this->attributes['guid']) cache_entity($this);
+
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Disable this entity.
+ *
+ * @param string $reason Optional reason
+ * @param bool $recursive Recursively disable all contained entities?
+ */
+ public function disable($reason = "", $recursive = true)
+ {
+ return disable_entity($this->get('guid'), $reason, $recursive);
+ }
+
+ /**
+ * Re-enable this entity.
+ */
+ public function enable()
+ {
+ return enable_entity($this->get('guid'));
+ }
+
+ /**
+ * Is this entity enabled?
+ *
+ * @return boolean
+ */
+ public function isEnabled()
+ {
+ if ($this->enabled == 'yes')
+ return true;
+
+ return false;
+ }
+
+ /**
+ * Delete this entity.
+ */
+ public function delete()
+ {
+ return delete_entity($this->get('guid'));
+ }
+
+ // LOCATABLE INTERFACE /////////////////////////////////////////////////////////////
+
+ /** Interface to set the location */
+ public function setLocation($location)
+ {
+ $location = sanitise_string($location);
+
+ $this->location = $location;
+
+ return true;
+ }
+
+ /**
+ * Set latitude and longitude tags for a given entity.
+ *
+ * @param float $lat
+ * @param float $long
+ */
+ public function setLatLong($lat, $long)
+ {
+ $lat = sanitise_string($lat);
+ $long = sanitise_string($long);
+
+ $this->set('geo:lat', $lat);
+ $this->set('geo:long', $long);
+
+ return true;
+ }
+
+ /**
+ * Get the contents of the ->geo:lat field.
+ *
+ */
+ public function getLatitude() { return $this->get('geo:lat'); }
+
+ /**
+ * Get the contents of the ->geo:lat field.
+ *
+ */
+ public function getLongitude() { return $this->get('geo:long'); }
+
+ /**
+ * Get the ->location metadata.
+ *
+ */
+ public function getLocation() { return $this->get('location'); }
+
+ // NOTABLE INTERFACE ///////////////////////////////////////////////////////////////
+
+ /**
+ * Calendar functionality.
+ * This function sets the time of an object on a calendar listing.
+ *
+ * @param int $hour If ommitted, now is assumed.
+ * @param int $minute If ommitted, now is assumed.
+ * @param int $second If ommitted, now is assumed.
+ * @param int $day If ommitted, now is assumed.
+ * @param int $month If ommitted, now is assumed.
+ * @param int $year If ommitted, now is assumed.
+ * @param int $duration Duration of event, remainder of the day is assumed.
+ */
+ public function setCalendarTimeAndDuration($hour = NULL, $minute = NULL, $second = NULL, $day = NULL, $month = NULL, $year = NULL, $duration = NULL)
+ {
+ $start = mktime($hour, $minute, $second, $month, $day, $year);
+ $end = $start + abs($duration);
+ if (!$duration)
+ $end = get_day_end($day,$month,$year);
+
+ $this->calendar_start = $start;
+ $this->calendar_end = $end;
+
+ return true;
+ }
+
+ /**
+ * Return the start timestamp.
+ */
+ public function getCalendarStartTime() { return (int)$this->calendar_start; }
+
+ /**
+ * Return the end timestamp.
+ */
+ public function getCalendarEndTime() { return (int)$this->calendar_end; }
+
+ // EXPORTABLE INTERFACE ////////////////////////////////////////////////////////////
+
+ /**
+ * Return an array of fields which can be exported.
+ */
+ public function getExportableValues()
+ {
+ return array(
+ 'guid',
+ 'type',
+ 'subtype',
+ 'time_created',
+ 'container_guid',
+ 'owner_guid',
+ );
+ }
+
+ /**
+ * Export this class into an array of ODD Elements containing all necessary fields.
+ * Override if you wish to return more information than can be found in $this->attributes (shouldn't happen)
+ */
+ public function export()
+ {
+ $tmp = array();
+
+ // Generate uuid
+ $uuid = guid_to_uuid($this->getGUID());
+
+ // Create entity
+ $odd = new ODDEntity(
+ $uuid,
+ $this->attributes['type'],
+ get_subtype_from_id($this->attributes['subtype'])
+ );
+
+ $tmp[] = $odd;
+
+ $exportable_values = $this->getExportableValues();
+
+ // Now add its attributes
+ foreach ($this->attributes as $k => $v)
+ {
+ $meta = NULL;
+
+ if (in_array( $k, $exportable_values)) {
+ switch ($k)
+ {
+ case 'guid' : // Dont use guid in OpenDD
+ case 'type' : // Type and subtype already taken care of
+ case 'subtype' :
+ break;
+
+ case 'time_created' : // Created = published
+ $odd->setAttribute('published', date("r", $v));
+ break;
+
+ case 'site_guid' : // Container
+ $k = 'site_uuid';
+ $v = guid_to_uuid($v);
+ $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
+ break;
+
+ case 'container_guid' : // Container
+ $k = 'container_uuid';
+ $v = guid_to_uuid($v);
+ $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
+ break;
+
+ case 'owner_guid' : // Convert owner guid to uuid, this will be stored in metadata
+ $k = 'owner_uuid';
+ $v = guid_to_uuid($v);
+ $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
+ break;
+
+ default :
+ $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
+ }
+
+ // set the time of any metadata created
+ if ($meta)
+ {
+ $meta->setAttribute('published', date("r",$this->time_created));
+ $tmp[] = $meta;
+ }
+ }
+ }
+
+ // Now we do something a bit special.
+ /*
+ * This provides a rendered view of the entity to foreign sites.
+ */
+
+ elgg_set_viewtype('default');
+ $view = elgg_view_entity($this, true);
+ elgg_set_viewtype();
+
+ $tmp[] = new ODDMetaData($uuid . "volatile/renderedentity/", $uuid, 'renderedentity', $view , 'volatile');
+
+
+ return $tmp;
+ }
+
+ // IMPORTABLE INTERFACE ////////////////////////////////////////////////////////////
+
+ /**
+ * Import data from an parsed xml data array.
+ *
+ * @param array $data
+ * @param int $version
+ */
+ public function import(ODD $data)
+ {
+ if (!($data instanceof ODDEntity))
+ throw new InvalidParameterException(elgg_echo('InvalidParameterException:UnexpectedODDClass'));
+
+ // Set type and subtype
+ $this->attributes['type'] = $data->getAttribute('class');
+ $this->attributes['subtype'] = $data->getAttribute('subclass');
+
+ // Set owner
+ $this->attributes['owner_guid'] = get_loggedin_userid(); // Import as belonging to importer.
+
+ // Set time
+ $this->attributes['time_created'] = strtotime($data->getAttribute('published'));
+ $this->attributes['time_updated'] = time();
+
+ return true;
+ }
+
+ // SYSTEM LOG INTERFACE ////////////////////////////////////////////////////////////
+
+ /**
+ * Return an identification for the object for storage in the system log.
+ * This id must be an integer.
+ *
+ * @return int
+ */
+ public function getSystemLogID() { return $this->getGUID(); }
+
+ /**
+ * Return the class name of the object.
+ */
+ public function getClassName() { return get_class($this); }
+
+ /**
+ * For a given ID, return the object associated with it.
+ * This is used by the river functionality primarily.
+ * This is useful for checking access permissions etc on objects.
+ */
+ public function getObjectFromID($id) { return get_entity($id); }
+
+ /**
+ * Return the GUID of the owner of this object.
+ */
+ public function getObjectOwnerGUID() { return $this->owner_guid; }
+
+ // ITERATOR INTERFACE //////////////////////////////////////////////////////////////
+ /*
+ * This lets an entity's attributes be displayed using foreach as a normal array.
+ * Example: http://www.sitepoint.com/print/php5-standard-library
+ */
+
+ private $valid = FALSE;
+
+ function rewind()
+ {
+ $this->valid = (FALSE !== reset($this->attributes));
+ }
+
+ function current()
+ {
+ return current($this->attributes);
+ }
+
+ function key()
+ {
+ return key($this->attributes);
+ }
+
+ function next()
+ {
+ $this->valid = (FALSE !== next($this->attributes));
+ }
+
+ function valid()
+ {
+ return $this->valid;
+ }
+
+ // ARRAY ACCESS INTERFACE //////////////////////////////////////////////////////////
+ /*
+ * This lets an entity's attributes be accessed like an associative array.
+ * Example: http://www.sitepoint.com/print/php5-standard-library
+ */
+
+ function offsetSet($key, $value)
+ {
+ if ( array_key_exists($key, $this->attributes) ) {
+ $this->attributes[$key] = $value;
+ }
+ }
+
+ function offsetGet($key)
+ {
+ if ( array_key_exists($key, $this->attributes) ) {
+ return $this->attributes[$key];
+ }
+ }
+
+ function offsetUnset($key)
+ {
+ if ( array_key_exists($key, $this->attributes) ) {
+ $this->attributes[$key] = ""; // Full unsetting is dangerious for our objects
+ }
+ }
+
+ function offsetExists($offset)
+ {
+ return array_key_exists($offset, $this->attributes);
+ }
+ }
+
+ /**
+ * Initialise the entity cache.
+ */
+ function initialise_entity_cache()
+ {
+ global $ENTITY_CACHE;
+
+ if (!$ENTITY_CACHE)
+ $ENTITY_CACHE = array(); //select_default_memcache('entity_cache'); // TODO: Replace with memcache?
+ }
+
+ /**
+ * Invalidate this class' entry in the cache.
+ *
+ * @param int $guid The guid
+ */
+ function invalidate_cache_for_entity($guid)
+ {
+ global $ENTITY_CACHE;
+
+ $guid = (int)$guid;
+
+ unset($ENTITY_CACHE[$guid]);
+ //$ENTITY_CACHE->delete($guid);
+ }
+
+ /**
+ * Cache an entity.
+ *
+ * @param ElggEntity $entity Entity to cache
+ */
+ function cache_entity(ElggEntity $entity)
+ {
+ global $ENTITY_CACHE;
+
+ $ENTITY_CACHE[$entity->guid] = $entity;
+ }
+
+ /**
+ * Retrieve a entity from the cache.
+ *
+ * @param int $guid The guid
+ */
+ function retrieve_cached_entity($guid)
+ {
+ global $ENTITY_CACHE;
+
+ $guid = (int)$guid;
+
+ if (isset($ENTITY_CACHE[$guid]))
+ if ($ENTITY_CACHE[$guid]->isFullyLoaded()) return $ENTITY_CACHE[$guid];
+
+ return false;
+ }
+
+ /**
+ * As retrieve_cached_entity, but returns the result as a stdClass (compatible with load functions that
+ * expect a database row.)
+ *
+ * @param int $guid The guid
+ */
+ function retrieve_cached_entity_row($guid)
+ {
+ $obj = retrieve_cached_entity($guid);
+ if ($obj)
+ {
+ $tmp = new stdClass;
+
+ foreach ($obj as $k => $v)
+ $tmp->$k = $v;
+
+ return $tmp;
+ }
+
+ return false;
+ }
+
+ /**
+ * Return the integer ID for a given subtype, or false.
+ *
+ * TODO: Move to a nicer place?
+ *
+ * @param string $type
+ * @param string $subtype
+ */
+ function get_subtype_id($type, $subtype)
+ {
+ global $CONFIG, $SUBTYPE_CACHE;
+
+ $type = sanitise_string($type);
+ $subtype = sanitise_string($subtype);
+
+ if ($subtype=="") return $subtype;
+
+ // Todo: cache here? Or is looping less efficient that going to the db each time?
+
+ $result = get_data_row("SELECT * from {$CONFIG->dbprefix}entity_subtypes where type='$type' and subtype='$subtype'");
+
+ if ($result) {
+
+ if (!$SUBTYPE_CACHE)
+ $SUBTYPE_CACHE = array(); //select_default_memcache('subtype_cache');
+
+ $SUBTYPE_CACHE[$result->id] = $result;
+ return $result->id;
+ }
+
+ return 0;
+ }
+
+ /**
+ * For a given subtype ID, return its identifier text.
+ *
+ * TODO: Move to a nicer place?
+ *
+ * @param int $subtype_id
+ */
+ function get_subtype_from_id($subtype_id)
+ {
+ global $CONFIG, $SUBTYPE_CACHE;
+
+ $subtype_id = (int)$subtype_id;
+
+ if (!$subtype_id) return false;
+
+ if (isset($SUBTYPE_CACHE[$subtype_id]))
+ return $SUBTYPE_CACHE[$subtype_id]->subtype;
+
+ $result = get_data_row("SELECT * from {$CONFIG->dbprefix}entity_subtypes where id=$subtype_id");
+ if ($result) {
+
+ if (!$SUBTYPE_CACHE)
+ $SUBTYPE_CACHE = array(); //select_default_memcache('subtype_cache');
+
+ $SUBTYPE_CACHE[$subtype_id] = $result;
+ return $result->subtype;
+ }
+
+ return false;
+ }
+
+ /**
+ * This function tests to see if a subtype has a registered class handler.
+ *
+ * @param string $type The type
+ * @param string $subtype The subtype
+ * @return a class name or null
+ */
+ function get_subtype_class($type, $subtype)
+ {
+ global $CONFIG, $SUBTYPE_CACHE;
+
+ $type = sanitise_string($type);
+ $subtype = sanitise_string($subtype);
+
+ // Todo: cache here? Or is looping less efficient that going to the db each time?
+
+ $result = get_data_row("SELECT * from {$CONFIG->dbprefix}entity_subtypes where type='$type' and subtype='$subtype'");
+ if ($result) {
+
+ if (!$SUBTYPE_CACHE)
+ $SUBTYPE_CACHE = array(); //select_default_memcache('subtype_cache');
+
+ $SUBTYPE_CACHE[$result->id] = $result;
+ return $result->class;
+ }
+
+ return NULL;
+ }
+
+ /**
+ * This function tests to see if a subtype has a registered class handler by its id.
+ *
+ * @param int $subtype_id The subtype
+ * @return a class name or null
+ */
+ function get_subtype_class_from_id($subtype_id)
+ {
+ global $CONFIG, $SUBTYPE_CACHE;
+
+ $subtype_id = (int)$subtype_id;
+
+ if (!$subtype_id) return false;
+
+ if (isset($SUBTYPE_CACHE[$subtype_id]))
+ return $SUBTYPE_CACHE[$subtype_id]->class;
+
+ $result = get_data_row("SELECT * from {$CONFIG->dbprefix}entity_subtypes where id=$subtype_id");
+ if ($result) {
+
+ if (!$SUBTYPE_CACHE)
+ $SUBTYPE_CACHE = array(); //select_default_memcache('subtype_cache');
+
+ $SUBTYPE_CACHE[$subtype_id] = $result;
+ return $result->class;
+ }
+
+ return NULL;
+ }
+
+ /**
+ * This function will register a new subtype, returning its ID as required.
+ *
+ * @param string $type The type you're subtyping
+ * @param string $subtype The subtype label
+ * @param string $class Optional class handler (if you don't want it handled by the generic elgg handler for the type)
+ */
+ function add_subtype($type, $subtype, $class = "")
+ {
+ global $CONFIG;
+ $type = sanitise_string($type);
+ $subtype = sanitise_string($subtype);
+ $class = sanitise_string($class);
+
+ // Short circuit if no subtype is given
+ if ($subtype == "")
+ return 0;
+
+ $id = get_subtype_id($type, $subtype);
+
+ if ($id==0)
+ return insert_data("insert into {$CONFIG->dbprefix}entity_subtypes (type, subtype, class) values ('$type','$subtype','$class')");
+
+ return $id;
+ }
+
+ /**
+ * Update an existing entity.
+ *
+ * @param int $guid
+ * @param int $owner_guid
+ * @param int $access_id
+ * @param int $container_guid
+ */
+ function update_entity($guid, $owner_guid, $access_id, $container_guid = null)
+ {
+ global $CONFIG, $ENTITY_CACHE;
+
+ $guid = (int)$guid;
+ $owner_guid = (int)$owner_guid;
+ $access_id = (int)$access_id;
+ $container_guid = (int) $container_guid;
+ if (is_null($container_guid)) $container_guid = $owner_guid;
+ $time = time();
+
+ $entity = get_entity($guid);
+
+ if ($entity->canEdit()) {
+
+ if (trigger_elgg_event('update',$entity->type,$entity)) {
+ $ret = update_data("UPDATE {$CONFIG->dbprefix}entities set owner_guid='$owner_guid', access_id='$access_id', container_guid='$container_guid', time_updated='$time' WHERE guid=$guid");
+
+ if ($entity instanceof ElggObject)
+ update_river_access_by_object($guid,$access_id);
+
+ // If memcache is available then delete this entry from the cache
+ static $newentity_cache;
+ if ((!$newentity_cache) && (is_memcache_available()))
+ $newentity_cache = new ElggMemcache('new_entity_cache');
+ if ($newentity_cache) $new_entity = $newentity_cache->delete($guid);
+
+ // Handle cases where there was no error BUT no rows were updated!
+ if ($ret===false)
+ return false;
+
+ return true;
+ }
+
+ }
+ }
+
+ /**
+ * Determine whether a given user is able to write to a given container.
+ *
+ * @param int $user_guid The user guid, or 0 for get_loggedin_userid()
+ * @param int $container_guid The container, or 0 for the current page owner.
+ */
+ function can_write_to_container($user_guid = 0, $container_guid = 0, $entity_type = 'all')
+ {
+ global $CONFIG;
+
+ $user_guid = (int)$user_guid;
+ $user = get_entity($user_guid);
+ if (!$user) $user = get_loggedin_user();
+
+ $container_guid = (int)$container_guid;
+ if (!$container_guid) $container_guid = page_owner();
+ if (!$container_guid) return true;
+
+ $container = get_entity($container_guid);
+
+ if ($container)
+ {
+
+ // If the user can edit the container, they can also write to it
+ if ($container->canEdit($user_guid)) return true;
+
+ // Basics, see if the user is a member of the group.
+ if ($user && $container instanceof ElggGroup) {
+ if (!$container->isMember($user)) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ // See if anyone else has anything to say
+ return trigger_plugin_hook('container_permissions_check',$entity_type,array('container' => $container, 'user' => $user), false);
+
+ }
+
+ return false;
+ }
+
+ /**
+ * Create a new entity of a given type.
+ *
+ * @param string $type The type of the entity (site, user, object).
+ * @param string $subtype The subtype of the entity.
+ * @param int $owner_guid The GUID of the object's owner.
+ * @param int $access_id The access control group to create the entity with.
+ * @param int $site_guid The site to add this entity to. Leave as 0 (default) for the current site.
+ * @return mixed The new entity's GUID, or false on failure
+ */
+ function create_entity($type, $subtype, $owner_guid, $access_id, $site_guid = 0, $container_guid = 0)
+ {
+ global $CONFIG;
+
+ $type = sanitise_string($type);
+ $subtype = add_subtype($type, $subtype);
+ $owner_guid = (int)$owner_guid;
+ $access_id = (int)$access_id;
+ $time = time();
+ if ($site_guid == 0)
+ $site_guid = $CONFIG->site_guid;
+ $site_guid = (int) $site_guid;
+ if ($container_guid == 0) $container_guid = $owner_guid;
+
+ $user = get_loggedin_user();
+ if (!can_write_to_container($user->guid, $owner_guid, $type)) return false;
+ if ($owner_guid != $container_guid)
+ if (!can_write_to_container($user->guid, $container_guid, $type)) return false;
+
+ if ($type=="") throw new InvalidParameterException(elgg_echo('InvalidParameterException:EntityTypeNotSet'));
+
+ return insert_data("INSERT into {$CONFIG->dbprefix}entities (type, subtype, owner_guid, site_guid, container_guid, access_id, time_created, time_updated) values ('$type',$subtype, $owner_guid, $site_guid, $container_guid, $access_id, $time, $time)");
+ }
+
+ /**
+ * Retrieve the entity details for a specific GUID, returning it as a stdClass db row.
+ *
+ * You will only get an object if a) it exists, b) you have access to it.
+ *
+ * @param int $guid The GUID of the object to extract
+ */
+ function get_entity_as_row($guid)
+ {
+ global $CONFIG;
+
+ if (!$guid) return false;
+
+ $guid = (int) $guid;
+
+ /*$row = retrieve_cached_entity_row($guid);
+ if ($row)
+ {
+ // We have already cached this object, so retrieve its value from the cache
+ if (isset($CONFIG->debug) && $CONFIG->debug)
+ error_log("** Retrieving GUID:$guid from cache");
+
+ return $row;
+ }
+ else
+ {*/
+ // Object not cached, load it.
+ if (isset($CONFIG->debug) && $CONFIG->debug == true)
+ error_log("** GUID:$guid loaded from DB");
+
+ $access = get_access_sql_suffix();
+
+ return get_data_row("SELECT * from {$CONFIG->dbprefix}entities where guid=$guid and $access");
+ //}
+ }
+
+ /**
+ * Create an Elgg* object from a given entity row.
+ */
+ function entity_row_to_elggstar($row)
+ {
+ if (!($row instanceof stdClass))
+ return $row;
+
+ if ((!isset($row->guid)) || (!isset($row->subtype)))
+ return $row;
+
+ $new_entity = false;
+
+ // Create a memcache cache if we can
+ static $newentity_cache;
+ if ((!$newentity_cache) && (is_memcache_available()))
+ $newentity_cache = new ElggMemcache('new_entity_cache');
+ if ($newentity_cache) $new_entity = $newentity_cache->load($row->guid);
+ if ($new_entity) return $new_entity;
+
+ $classname = get_subtype_class_from_id($row->subtype);
+ if ($classname!="")
+ {
+ if (class_exists($classname))
+ {
+ $new_entity = new $classname($row);
+
+ if (!($new_entity instanceof ElggEntity))
+ throw new ClassException(sprintf(elgg_echo('ClassException:ClassnameNotClass'), $classname, 'ElggEntity'));
+ }
+ else
+ error_log(sprintf(elgg_echo('ClassNotFoundException:MissingClass'), $classname));
+ }
+ else
+ {
+ switch ($row->type)
+ {
+ case 'object' :
+ $new_entity = new ElggObject($row); break;
+ case 'user' :
+ $new_entity = new ElggUser($row); break;
+ case 'group' :
+ $new_entity = new ElggGroup($row); break;
+ case 'site' :
+ $new_entity = new ElggSite($row); break;
+ default: throw new InstallationException(sprintf(elgg_echo('InstallationException:TypeNotSupported'), $row->type));
+ }
+
+ }
+
+ // Cache entity if we have a cache available
+ if (($newentity_cache) && ($new_entity)) $newentity_cache->save($new_entity->guid, $new_entity);
+
+ return $new_entity;
+ }
+
+ /**
+ * Return the entity for a given guid as the correct object.
+ * @param int $guid The GUID of the entity
+ * @return a child of ElggEntity appropriate for the type.
+ */
+ function get_entity($guid)
+ {
+ static $newentity_cache;
+ $new_entity = false;
+ if ((!$newentity_cache) && (is_memcache_available()))
+ $newentity_cache = new ElggMemcache('new_entity_cache');
+ if ($newentity_cache) $new_entity = $newentity_cache->load($guid);
+ if ($new_entity) return $new_entity;
+
+ return entity_row_to_elggstar(get_entity_as_row($guid));
+ }
+
+ /**
+ * Return entities matching a given query, or the number thereof
+ *
+ * @param string $type The type of entity (eg "user", "object" etc)
+ * @param string|array $subtype The arbitrary subtype of the entity or array(type1 => array('subtype1', ...'subtypeN'), ...)
+ * @param int $owner_guid The GUID of the owning user
+ * @param string $order_by The field to order by; by default, time_created desc
+ * @param int $limit The number of entities to return; 10 by default
+ * @param int $offset The indexing offset, 0 by default
+ * @param boolean $count Set to true to get a count rather than the entities themselves (limits and offsets don't apply in this context). Defaults to false.
+ * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
+ * @param int|array $container_guid The container or containers to get entities from (default: all containers).
+ * @param int $timelower The earliest time the entity can have been created. Default: all
+ * @param int $timeupper The latest time the entity can have been created. Default: all
+ * @return array A list of entities.
+ */
+ function get_entities($type = "", $subtype = "", $owner_guid = 0, $order_by = "", $limit = 10, $offset = 0, $count = false, $site_guid = 0, $container_guid = null, $timelower = 0, $timeupper = 0)
+ {
+ global $CONFIG;
+
+ if ($subtype === false || $subtype === null || $subtype === 0)
+ return false;
+
+ if ($order_by == "") $order_by = "time_created desc";
+ $order_by = sanitise_string($order_by);
+ $limit = (int)$limit;
+ $offset = (int)$offset;
+ $site_guid = (int) $site_guid;
+ $timelower = (int) $timelower;
+ $timeupper = (int) $timeupper;
+ if ($site_guid == 0)
+ $site_guid = $CONFIG->site_guid;
+
+ $where = array();
+
+ if (is_array($subtype)) {
+ $tempwhere = "";
+ if (sizeof($subtype))
+ foreach($subtype as $typekey => $subtypearray) {
+ foreach($subtypearray as $subtypeval) {
+ $typekey = sanitise_string($typekey);
+ if (!empty($subtypeval)) {
+ if (!$subtypeval = (int) get_subtype_id($typekey, $subtypeval))
+ return false;
+ } else {
+ // @todo: Setting subtype to 0 when $subtype = '' returns entities with
+ // no subtype. This is different to the non-array behavior
+ // but may be required in some cases.
+ $subtypeval = 0;
+ }
+ if (!empty($tempwhere)) $tempwhere .= " or ";
+ $tempwhere .= "(type = '{$typekey}' and subtype = {$subtypeval})";
+ }
+ }
+ if (!empty($tempwhere)) $where[] = "({$tempwhere})";
+
+ } else {
+
+ $type = sanitise_string($type);
+ if ($subtype !== "" AND !$subtype = get_subtype_id($type, $subtype))
+ return false;
+
+ if ($type != "")
+ $where[] = "type='$type'";
+ if ($subtype!=="")
+ $where[] = "subtype=$subtype";
+ }
+
+ if ($owner_guid != "") {
+ if (!is_array($owner_guid)) {
+ $owner_array = array($owner_guid);
+ $owner_guid = (int) $owner_guid;
+ // $where[] = "owner_guid = '$owner_guid'";
+ } else if (sizeof($owner_guid) > 0) {
+ $owner_array = array_map('sanitise_int', $owner_guid);
+ // Cast every element to the owner_guid array to int
+ // $owner_guid = array_map("sanitise_int", $owner_guid);
+ // $owner_guid = implode(",",$owner_guid);
+ // $where[] = "owner_guid in ({$owner_guid})";
+ }
+ if (is_null($container_guid)) {
+ $container_guid = $owner_array;
+ }
+ }
+ if ($site_guid > 0)
+ $where[] = "site_guid = {$site_guid}";
+
+ if (!is_null($container_guid)) {
+ if (is_array($container_guid)) {
+ foreach($container_guid as $key => $val) $container_guid[$key] = (int) $val;
+ $where[] = "container_guid in (" . implode(",",$container_guid) . ")";
+ } else {
+ $container_guid = (int) $container_guid;
+ $where[] = "container_guid = {$container_guid}";
+ }
+ }
+ if ($timelower)
+ $where[] = "time_created >= {$timelower}";
+ if ($timeupper)
+ $where[] = "time_created <= {$timeupper}";
+
+ if (!$count) {
+ $query = "SELECT * from {$CONFIG->dbprefix}entities where ";
+ } else {
+ $query = "SELECT count(guid) as total from {$CONFIG->dbprefix}entities where ";
+ }
+ foreach ($where as $w)
+ $query .= " $w and ";
+ $query .= get_access_sql_suffix(); // Add access controls
+ if (!$count) {
+ $query .= " order by $order_by";
+ if ($limit) $query .= " limit $offset, $limit"; // Add order and limit
+ $dt = get_data($query, "entity_row_to_elggstar");
+ return $dt;
+ } else {
+ $total = get_data_row($query);
+ return $total->total;
+ }
+ }
+
+ /**
+ * Returns a viewable list of entities
+ *
+ * @see elgg_view_entity_list
+ *
+ * @param string $type The type of entity (eg "user", "object" etc)
+ * @param string $subtype The arbitrary subtype of the entity
+ * @param int $owner_guid The GUID of the owning user
+ * @param int $limit The number of entities to display per page (default: 10)
+ * @param true|false $fullview Whether or not to display the full view (default: true)
+ * @param true|false $viewtypetoggle Whether or not to allow gallery view
+ * @param true|false $pagination Display pagination? Default: true
+ * @return string A viewable list of entities
+ */
+ function list_entities($type= "", $subtype = "", $owner_guid = 0, $limit = 10, $fullview = true, $viewtypetoggle = false, $pagination = true) {
+
+ $offset = (int) get_input('offset');
+ $count = get_entities($type, $subtype, $owner_guid, "", $limit, $offset, true);
+ $entities = get_entities($type, $subtype, $owner_guid, "", $limit, $offset);
+
+ return elgg_view_entity_list($entities, $count, $offset, $limit, $fullview, $viewtypetoggle, $pagination);
+
+ }
+
+ /**
+ * Returns a viewable list of entities contained in a number of groups.
+ *
+ * @param string $subtype The arbitrary subtype of the entity
+ * @param int $owner_guid The GUID of the owning user
+ * @param int $container_guid The GUID of the containing group
+ * @param int $limit The number of entities to display per page (default: 10)
+ * @param true|false $fullview Whether or not to display the full view (default: true)
+ * @return string A viewable list of entities
+ */
+ function list_entities_groups($subtype = "", $owner_guid = 0, $container_guid = 0, $limit = 10, $fullview = true)
+ {
+ $offset = (int) get_input('offset');
+ $count = get_objects_in_group($container_guid, $subtype, $owner_guid, 0, "", $limit, $offset, true);
+ $entities = get_objects_in_group($container_guid, $subtype, $owner_guid, 0, "", $limit, $offset);
+
+ return elgg_view_entity_list($entities, $count, $offset, $limit, $fullview);
+ }
+
+ /**
+ * Returns a list of months containing content specified by the parameters
+ *
+ * @param string $type The type of entity
+ * @param string $subtype The subtype of entity
+ * @param int $container_guid The container GUID that the entinties belong to
+ * @param int $site_guid The site GUID
+ * @return array|false Either an array of timestamps, or false on failure
+ */
+ function get_entity_dates($type = '', $subtype = '', $container_guid = 0, $site_guid = 0) {
+
+ global $CONFIG;
+
+ $site_guid = (int) $site_guid;
+ if ($site_guid == 0)
+ $site_guid = $CONFIG->site_guid;
+
+ $where = array();
+
+ if ($type != "") {
+ $type = sanitise_string($type);
+ $where[] = "type='$type'";
+ }
+
+ if (is_array($subtype)) {
+ $tempwhere = "";
+ if (sizeof($subtype))
+ foreach($subtype as $typekey => $subtypearray) {
+ foreach($subtypearray as $subtypeval) {
+ $typekey = sanitise_string($typekey);
+ if (!empty($subtypeval)) {
+ if (!$subtypeval = (int) get_subtype_id($typekey, $subtypeval))
+ return false;
+ } else {
+ $subtypeval = 0;
+ }
+ if (!empty($tempwhere)) $tempwhere .= " or ";
+ $tempwhere .= "(type = '{$typekey}' and subtype = {$subtypeval})";
+ }
+ }
+ if (!empty($tempwhere)) $where[] = "({$tempwhere})";
+
+ } else {
+ if ($subtype AND !$subtype = get_subtype_id($type, $subtype)) {
+ return false;
+ } else {
+ $where[] = "subtype=$subtype";
+ }
+ }
+
+ if ($container_guid !== 0) {
+ if (is_array($container_guid)) {
+ foreach($container_guid as $key => $val) $container_guid[$key] = (int) $val;
+ $where[] = "container_guid in (" . implode(",",$container_guid) . ")";
+ } else {
+ $container_guid = (int) $container_guid;
+ $where[] = "container_guid = {$container_guid}";
+ }
+ }
+
+ if ($site_guid > 0)
+ $where[] = "site_guid = {$site_guid}";
+
+ $where[] = get_access_sql_suffix();
+
+ $sql = "SELECT DISTINCT EXTRACT(YEAR_MONTH FROM FROM_UNIXTIME(time_created)) AS yearmonth FROM {$CONFIG->dbprefix}entities where ";
+ foreach ($where as $w)
+ $sql .= " $w and ";
+ $sql .= "1=1";
+ if ($result = get_data($sql)) {
+ $endresult = array();
+ foreach($result as $res) {
+ $endresult[] = $res->yearmonth;
+ }
+ return $endresult;
+ }
+ return false;
+
+ }
+
+ /**
+ * Disable an entity but not delete it.
+ *
+ * @param int $guid The guid
+ * @param string $reason Optional reason
+ */
+ function disable_entity($guid, $reason = "", $recursive = true)
+ {
+ global $CONFIG;
+
+ $guid = (int)$guid;
+ $reason = sanitise_string($reason);
+
+ if ($entity = get_entity($guid)) {
+ if (trigger_elgg_event('disable',$entity->type,$entity)) {
+ if ($entity->canEdit()) {
+
+ if ($reason)
+ create_metadata($guid, 'disable_reason', $reason,'', 0, ACCESS_PUBLIC);
+
+ if ($recursive)
+ {
+ // Temporary token overriding access controls TODO: Do this better.
+ static $__RECURSIVE_DELETE_TOKEN;
+ $__RECURSIVE_DELETE_TOKEN = md5(get_loggedin_userid()); // Make it slightly harder to guess
+
+ $sub_entities = get_data("SELECT * from {$CONFIG->dbprefix}entities WHERE container_guid=$guid or owner_guid=$guid or site_guid=$guid", 'entity_row_to_elggstar');
+ if ($sub_entities) {
+ foreach ($sub_entities as $e)
+ $e->disable($reason);
+ }
+
+ $__RECURSIVE_DELETE_TOKEN = null;
+ }
+
+ $res = update_data("UPDATE {$CONFIG->dbprefix}entities set enabled='no' where guid={$guid}");
+
+ return $res;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Enable an entity again.
+ *
+ * @param int $guid
+ */
+ function enable_entity($guid)
+ {
+ global $CONFIG;
+
+ $guid = (int)$guid;
+
+ // Override access only visible entities
+ $access_status = access_get_show_hidden_status();
+ access_show_hidden_entities(true);
+
+ if ($entity = get_entity($guid)) {
+ if (trigger_elgg_event('enable',$entity->type,$entity)) {
+ if ($entity->canEdit()) {
+
+ access_show_hidden_entities($access_status);
+
+ $result = update_data("UPDATE {$CONFIG->dbprefix}entities set enabled='yes' where guid={$guid}");
+ $entity->clearMetaData('disable_reason');
+
+ return $result;
+ }
+ }
+ }
+
+ access_show_hidden_entities($access_status);
+ return false;
+ }
+
+ /**
+ * Delete a given entity.
+ *
+ * @param int $guid
+ * @param bool $recursive If true (default) then all entities which are owned or contained by $guid will also be deleted.
+ * Note: this bypasses ownership of sub items.
+ */
+ function delete_entity($guid, $recursive = true)
+ {
+ global $CONFIG;
+
+ $guid = (int)$guid;
+ if ($entity = get_entity($guid)) {
+ if (trigger_elgg_event('delete',$entity->type,$entity)) {
+ if ($entity->canEdit()) {
+
+ // Delete contained owned and otherwise releated objects (depth first)
+ if ($recursive)
+ {
+ // Temporary token overriding access controls TODO: Do this better.
+ static $__RECURSIVE_DELETE_TOKEN;
+ $__RECURSIVE_DELETE_TOKEN = md5(get_loggedin_userid()); // Make it slightly harder to guess
+
+ $sub_entities = get_data("SELECT * from {$CONFIG->dbprefix}entities WHERE container_guid=$guid or owner_guid=$guid or site_guid=$guid", 'entity_row_to_elggstar');
+ if ($sub_entities) {
+ foreach ($sub_entities as $e)
+ $e->delete();
+ }
+
+ $__RECURSIVE_DELETE_TOKEN = null;
+ }
+
+ // Now delete the entity itself
+ $entity->clearMetadata();
+ $entity->clearAnnotations();
+ $entity->clearRelationships();
+ remove_from_river_by_subject($guid);
remove_from_river_by_object($guid);
- remove_all_private_settings($guid);
+ remove_all_private_settings($guid);
$res = delete_data("DELETE from {$CONFIG->dbprefix}entities where guid={$guid}");
if ($res)
{
$sub_table = "";
- // Where appropriate delete the sub table
- switch ($entity->type)
- {
- case 'object' : $sub_table = $CONFIG->dbprefix . 'objects_entity'; break;
- case 'user' : $sub_table = $CONFIG->dbprefix . 'users_entity'; break;
- case 'group' : $sub_table = $CONFIG->dbprefix . 'groups_entity'; break;
- case 'site' : $sub_table = $CONFIG->dbprefix . 'sites_entity'; break;
- }
+ // Where appropriate delete the sub table
+ switch ($entity->type)
+ {
+ case 'object' : $sub_table = $CONFIG->dbprefix . 'objects_entity'; break;
+ case 'user' : $sub_table = $CONFIG->dbprefix . 'users_entity'; break;
+ case 'group' : $sub_table = $CONFIG->dbprefix . 'groups_entity'; break;
+ case 'site' : $sub_table = $CONFIG->dbprefix . 'sites_entity'; break;
+ }
+
+ if ($sub_table)
+ delete_data("DELETE from $sub_table where guid={$guid}");
+ }
+
+ return $res;
+ }
+ }
+ }
+ return false;
+
+ }
+
+ /**
+ * Delete multiple entities that match a given query.
+ * This function itterates through and calls delete_entity on each one, this is somewhat inefficient but lets
+ * the 'delete' even be called for each entity.
+ *
+ * @param string $type The type of entity (eg "user", "object" etc)
+ * @param string $subtype The arbitrary subtype of the entity
+ * @param int $owner_guid The GUID of the owning user
+ */
+ function delete_entities($type = "", $subtype = "", $owner_guid = 0)
+ {
+ $entities = get_entities($type, $subtype, $owner_guid, "time_created desc", 0);
+
+ foreach ($entities as $entity)
+ delete_entity($entity->guid);
+
+ return true;
+ }
+
+ /**
+ * A plugin hook to get certain volitile (generated on the fly) attributes about an entity in order to export them.
+ *
+ * @param unknown_type $hook
+ * @param unknown_type $entity_type
+ * @param unknown_type $returnvalue
+ * @param unknown_type $params The parameters, passed 'guid' and 'varname'
+ * @return unknown
+ */
+ function volatile_data_export_plugin_hook($hook, $entity_type, $returnvalue, $params)
+ {
+ $guid = (int)$params['guid'];
+ $variable_name = sanitise_string($params['varname']);
+
+ if (($hook == 'volatile') && ($entity_type == 'metadata'))
+ {
+ if (($guid) && ($variable_name))
+ {
+ switch ($variable_name)
+ {
+ case 'renderedentity' :
+ elgg_set_viewtype('default');
+ $view = elgg_view_entity(get_entity($guid));
+ elgg_set_viewtype();
+
+ $tmp = new ElggMetadata();
+ $tmp->type = 'volatile';
+ $tmp->name = 'renderedentity';
+ $tmp->value = $view;
+ $tmp->entity_guid = $guid;
- if ($sub_table)
- delete_data("DELETE from $sub_table where guid={$guid}");
- }
-
- return $res;
- }
- }
- }
- return false;
-
- }
-
- /**
- * Delete multiple entities that match a given query.
- * This function itterates through and calls delete_entity on each one, this is somewhat inefficient but lets
- * the 'delete' even be called for each entity.
- *
- * @param string $type The type of entity (eg "user", "object" etc)
- * @param string $subtype The arbitrary subtype of the entity
- * @param int $owner_guid The GUID of the owning user
- */
- function delete_entities($type = "", $subtype = "", $owner_guid = 0)
- {
- $entities = get_entities($type, $subtype, $owner_guid, "time_created desc", 0);
-
- foreach ($entities as $entity)
- delete_entity($entity->guid);
-
- return true;
- }
-
- /**
- * A plugin hook to get certain volitile (generated on the fly) attributes about an entity in order to export them.
- *
- * @param unknown_type $hook
- * @param unknown_type $entity_type
- * @param unknown_type $returnvalue
- * @param unknown_type $params The parameters, passed 'guid' and 'varname'
- * @return unknown
- */
- function volatile_data_export_plugin_hook($hook, $entity_type, $returnvalue, $params)
- {
- $guid = (int)$params['guid'];
- $variable_name = sanitise_string($params['varname']);
-
- if (($hook == 'volatile') && ($entity_type == 'metadata'))
- {
- if (($guid) && ($variable_name))
- {
- switch ($variable_name)
- {
- case 'renderedentity' :
- elgg_set_viewtype('default');
- $view = elgg_view_entity(get_entity($guid));
- elgg_set_viewtype();
-
- $tmp = new ElggMetadata();
- $tmp->type = 'volatile';
- $tmp->name = 'renderedentity';
- $tmp->value = $view;
- $tmp->entity_guid = $guid;
-
- return $tmp;
-
- break;
- }
- }
- }
- }
-
- /**
- * Handler called by trigger_plugin_hook on the "export" event.
- */
- function export_entity_plugin_hook($hook, $entity_type, $returnvalue, $params)
- {
- // Sanity check values
- if ((!is_array($params)) && (!isset($params['guid'])))
- throw new InvalidParameterException(elgg_echo('InvalidParameterException:GUIDNotForExport'));
-
- if (!is_array($returnvalue))
- throw new InvalidParameterException(elgg_echo('InvalidParameterException:NonArrayReturnValue'));
-
- $guid = (int)$params['guid'];
-
- // Get the entity
- $entity = get_entity($guid);
- if (!($entity instanceof ElggEntity))
- throw new InvalidClassException(sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $guid, get_class()));
-
- $export = $entity->export();
-
- if (is_array($export))
- foreach ($export as $e)
- $returnvalue[] = $e;
- else
- $returnvalue[] = $export;
-
- return $returnvalue;
- }
-
- /**
- * Utility function used by import_entity_plugin_hook() to process an ODDEntity into an unsaved ElggEntity.
- *
- * @param ODDEntity $element The OpenDD element
- * @return ElggEntity the unsaved entity which should be populated by items.
- */
- function oddentity_to_elggentity(ODDEntity $element)
- {
- $class = $element->getAttribute('class');
- $subclass = $element->getAttribute('subclass');
-
- // See if we already have imported this uuid
- $tmp = get_entity_from_uuid($element->getAttribute('uuid'));
-
- if (!$tmp)
- {
- // Construct new class with owner from session
- $classname = get_subtype_class($class, $subclass);
- if ($classname!="")
- {
- if (class_exists($classname))
- {
- $tmp = new $classname();
-
- if (!($tmp instanceof ElggEntity))
- throw new ClassException(sprintf(elgg_echo('ClassException:ClassnameNotClass', $classname, get_class())));
- }
- else
- error_log(sprintf(elgg_echo('ClassNotFoundException:MissingClass'), $classname));
- }
- else
- {
- switch ($class)
- {
- case 'object' : $tmp = new ElggObject($row); break;
- case 'user' : $tmp = new ElggUser($row); break;
- case 'group' : $tmp = new ElggGroup($row); break;
- case 'site' : $tmp = new ElggSite($row); break;
- default: throw new InstallationException(sprintf(elgg_echo('InstallationException:TypeNotSupported'), $class));
- }
- }
- }
-
- if ($tmp)
- {
- if (!$tmp->import($element))
- throw new ImportException(sprintf(elgg_echo('ImportException:ImportFailed'), $element->getAttribute('uuid')));
-
- return $tmp;
- }
-
- return NULL;
- }
-
- /**
- * Import an entity.
- * This function checks the passed XML doc (as array) to see if it is a user, if so it constructs a new
- * elgg user and returns "true" to inform the importer that it's been handled.
- */
- function import_entity_plugin_hook($hook, $entity_type, $returnvalue, $params)
- {
- $element = $params['element'];
-
- $tmp = NULL;
-
- if ($element instanceof ODDEntity)
- {
- $tmp = oddentity_to_elggentity($element);
-
- if ($tmp)
- {
- if (!$tmp->save()) // Make sure its saved
- throw new ImportException(sprintf(elgg_echo('ImportException:ProblemSaving'), $element->getAttribute('uuid')));
-
- // Belts and braces
- if (!$tmp->guid)
- throw new ImportException(elgg_echo('ImportException:NoGUID'));
-
- add_uuid_to_guid($tmp->guid, $element->getAttribute('uuid')); // We have saved, so now tag
-
- return $tmp;
- }
-
- }
- }
-
- /**
- * Determines whether or not the specified user can edit the specified entity.
- *
- * This is extendible by registering a plugin hook taking in the parameters 'entity' and 'user',
- * which are the entity and user entities respectively
- *
- * @see register_plugin_hook
- *
- * @param int $entity_guid The GUID of the entity
- * @param int $user_guid The GUID of the user
- * @return true|false Whether the specified user can edit the specified entity.
- */
- function can_edit_entity($entity_guid, $user_guid = 0) {
- global $CONFIG;
-
- $user_guid = (int)$user_guid;
- $user = get_entity($user_guid);
- if (!$user) $user = get_loggedin_user();
-
- if ($entity = get_entity($entity_guid)) {
-
- $return = false;
-
- // Test user if possible - should default to false unless a plugin hook says otherwise
- if (!is_null($user))
- {
- if ($entity->getOwner() == $user->getGUID()) $return = true;
- if ($entity->container_guid == $user->getGUID()) $return = true;
- if ($entity->type == "user" && $entity->getGUID() == $user->getGUID()) $return = true;
- if ($container_entity = get_entity($entity->container_guid)) {
- if ($container_entity->canEdit()) $return = true;
- }
- }
-
- return trigger_plugin_hook('permissions_check',$entity->type,array('entity' => $entity, 'user' => $user), $return);
-
- } else {
- return false;
-
- }
-
- }
-
- /**
- * Determines whether or not the specified user can edit metadata on the specified entity.
- *
- * This is extendible by registering a plugin hook taking in the parameters 'entity' and 'user',
- * which are the entity and user entities respectively
- *
- * @see register_plugin_hook
- *
- * @param int $entity_guid The GUID of the entity
- * @param int $user_guid The GUID of the user
- * @param ElggMetadata $metadata The metadata to specifically check (if any; default null)
- * @return true|false Whether the specified user can edit the specified entity.
- */
- function can_edit_entity_metadata($entity_guid, $user_guid = 0, $metadata = null) {
-
- if ($entity = get_entity($entity_guid)) {
-
- $return = null;
-
- if ($metadata->owner_guid == 0) $return = true;
- if (is_null($return))
- $return = can_edit_entity($entity_guid, $user_guid);
-
- $user = get_entity($user_guid);
- $return = trigger_plugin_hook('permissions_check:metadata',$entity->type,array('entity' => $entity, 'user' => $user, 'metadata' => $metadata),$return);
- return $return;
-
- } else {
- return false;
- }
-
- }
-
-
- /**
- * Get the icon for an entity
- *
- * @param ElggEntity $entity The entity (passed an entity rather than a guid to handle non-created entities)
- * @param string $size
- */
- function get_entity_icon_url(ElggEntity $entity, $size = 'medium')
- {
- global $CONFIG;
-
- $size = sanitise_string($size);
- switch (strtolower($size))
- {
+ return $tmp;
+
+ break;
+ }
+ }
+ }
+ }
+
+ /**
+ * Handler called by trigger_plugin_hook on the "export" event.
+ */
+ function export_entity_plugin_hook($hook, $entity_type, $returnvalue, $params)
+ {
+ // Sanity check values
+ if ((!is_array($params)) && (!isset($params['guid'])))
+ throw new InvalidParameterException(elgg_echo('InvalidParameterException:GUIDNotForExport'));
+
+ if (!is_array($returnvalue))
+ throw new InvalidParameterException(elgg_echo('InvalidParameterException:NonArrayReturnValue'));
+
+ $guid = (int)$params['guid'];
+
+ // Get the entity
+ $entity = get_entity($guid);
+ if (!($entity instanceof ElggEntity))
+ throw new InvalidClassException(sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $guid, get_class()));
+
+ $export = $entity->export();
+
+ if (is_array($export))
+ foreach ($export as $e)
+ $returnvalue[] = $e;
+ else
+ $returnvalue[] = $export;
+
+ return $returnvalue;
+ }
+
+ /**
+ * Utility function used by import_entity_plugin_hook() to process an ODDEntity into an unsaved ElggEntity.
+ *
+ * @param ODDEntity $element The OpenDD element
+ * @return ElggEntity the unsaved entity which should be populated by items.
+ */
+ function oddentity_to_elggentity(ODDEntity $element)
+ {
+ $class = $element->getAttribute('class');
+ $subclass = $element->getAttribute('subclass');
+
+ // See if we already have imported this uuid
+ $tmp = get_entity_from_uuid($element->getAttribute('uuid'));
+
+ if (!$tmp)
+ {
+ // Construct new class with owner from session
+ $classname = get_subtype_class($class, $subclass);
+ if ($classname!="")
+ {
+ if (class_exists($classname))
+ {
+ $tmp = new $classname();
+
+ if (!($tmp instanceof ElggEntity))
+ throw new ClassException(sprintf(elgg_echo('ClassException:ClassnameNotClass', $classname, get_class())));
+ }
+ else
+ error_log(sprintf(elgg_echo('ClassNotFoundException:MissingClass'), $classname));
+ }
+ else
+ {
+ switch ($class)
+ {
+ case 'object' : $tmp = new ElggObject($row); break;
+ case 'user' : $tmp = new ElggUser($row); break;
+ case 'group' : $tmp = new ElggGroup($row); break;
+ case 'site' : $tmp = new ElggSite($row); break;
+ default: throw new InstallationException(sprintf(elgg_echo('InstallationException:TypeNotSupported'), $class));
+ }
+ }
+ }
+
+ if ($tmp)
+ {
+ if (!$tmp->import($element))
+ throw new ImportException(sprintf(elgg_echo('ImportException:ImportFailed'), $element->getAttribute('uuid')));
+
+ return $tmp;
+ }
+
+ return NULL;
+ }
+
+ /**
+ * Import an entity.
+ * This function checks the passed XML doc (as array) to see if it is a user, if so it constructs a new
+ * elgg user and returns "true" to inform the importer that it's been handled.
+ */
+ function import_entity_plugin_hook($hook, $entity_type, $returnvalue, $params)
+ {
+ $element = $params['element'];
+
+ $tmp = NULL;
+
+ if ($element instanceof ODDEntity)
+ {
+ $tmp = oddentity_to_elggentity($element);
+
+ if ($tmp)
+ {
+ if (!$tmp->save()) // Make sure its saved
+ throw new ImportException(sprintf(elgg_echo('ImportException:ProblemSaving'), $element->getAttribute('uuid')));
+
+ // Belts and braces
+ if (!$tmp->guid)
+ throw new ImportException(elgg_echo('ImportException:NoGUID'));
+
+ add_uuid_to_guid($tmp->guid, $element->getAttribute('uuid')); // We have saved, so now tag
+
+ return $tmp;
+ }
+
+ }
+ }
+
+ /**
+ * Determines whether or not the specified user can edit the specified entity.
+ *
+ * This is extendible by registering a plugin hook taking in the parameters 'entity' and 'user',
+ * which are the entity and user entities respectively
+ *
+ * @see register_plugin_hook
+ *
+ * @param int $entity_guid The GUID of the entity
+ * @param int $user_guid The GUID of the user
+ * @return true|false Whether the specified user can edit the specified entity.
+ */
+ function can_edit_entity($entity_guid, $user_guid = 0) {
+ global $CONFIG;
+
+ $user_guid = (int)$user_guid;
+ $user = get_entity($user_guid);
+ if (!$user) $user = get_loggedin_user();
+
+ if ($entity = get_entity($entity_guid)) {
+
+ $return = false;
+
+ // Test user if possible - should default to false unless a plugin hook says otherwise
+ if (!is_null($user))
+ {
+ if ($entity->getOwner() == $user->getGUID()) $return = true;
+ if ($entity->container_guid == $user->getGUID()) $return = true;
+ if ($entity->type == "user" && $entity->getGUID() == $user->getGUID()) $return = true;
+ if ($container_entity = get_entity($entity->container_guid)) {
+ if ($container_entity->canEdit()) $return = true;
+ }
+ }
+
+ return trigger_plugin_hook('permissions_check',$entity->type,array('entity' => $entity, 'user' => $user), $return);
+
+ } else {
+ return false;
+
+ }
+
+ }
+
+ /**
+ * Determines whether or not the specified user can edit metadata on the specified entity.
+ *
+ * This is extendible by registering a plugin hook taking in the parameters 'entity' and 'user',
+ * which are the entity and user entities respectively
+ *
+ * @see register_plugin_hook
+ *
+ * @param int $entity_guid The GUID of the entity
+ * @param int $user_guid The GUID of the user
+ * @param ElggMetadata $metadata The metadata to specifically check (if any; default null)
+ * @return true|false Whether the specified user can edit the specified entity.
+ */
+ function can_edit_entity_metadata($entity_guid, $user_guid = 0, $metadata = null) {
+
+ if ($entity = get_entity($entity_guid)) {
+
+ $return = null;
+
+ if ($metadata->owner_guid == 0) $return = true;
+ if (is_null($return))
+ $return = can_edit_entity($entity_guid, $user_guid);
+
+ $user = get_entity($user_guid);
+ $return = trigger_plugin_hook('permissions_check:metadata',$entity->type,array('entity' => $entity, 'user' => $user, 'metadata' => $metadata),$return);
+ return $return;
+
+ } else {
+ return false;
+ }
+
+ }
+
+
+ /**
+ * Get the icon for an entity
+ *
+ * @param ElggEntity $entity The entity (passed an entity rather than a guid to handle non-created entities)
+ * @param string $size
+ */
+ function get_entity_icon_url(ElggEntity $entity, $size = 'medium')
+ {
+ global $CONFIG;
+
+ $size = sanitise_string($size);
+ switch (strtolower($size))
+ {
case 'master': $size = 'master'; break;
-
- case 'large' : $size = 'large'; break;
-
- case 'topbar' : $size = 'topbar'; break;
-
- case 'tiny' : $size = 'tiny'; break;
-
- case 'small' : $size = 'small'; break;
-
- case 'medium' :
- default: $size = 'medium';
- }
-
- $url = false;
-
- $viewtype = elgg_get_viewtype();
-
- // Step one, see if anyone knows how to render this in the current view
- $url = trigger_plugin_hook('entity:icon:url', $entity->getType(), array('entity' => $entity, 'viewtype' => $viewtype, 'size' => $size), $url);
-
- // Fail, so use default
- if (!$url) {
-
- $type = $entity->getType();
- $subtype = $entity->getSubtype();
-
- if (!empty($subtype)) {
- $overrideurl = elgg_view("icon/{$type}/{$subtype}/{$size}",array('entity' => $entity));
- if (!empty($overrideurl)) return $overrideurl;
- }
-
- $overrideurl = elgg_view("icon/{$type}/default/{$size}",array('entity' => $entity));
- if (!empty($overrideurl)) return $overrideurl;
-
- $url = $CONFIG->url . "_graphics/icons/default/$size.png";
- }
-
- return $url;
- }
-
- /**
- * Gets the URL for an entity, given a particular GUID
- *
- * @param int $entity_guid The GUID of the entity
- * @return string The URL of the entity
- */
- function get_entity_url($entity_guid) {
-
- global $CONFIG;
- if ($entity = get_entity($entity_guid)) {
-
- $url = "";
-
- if (isset($CONFIG->entity_url_handler[$entity->getType()][$entity->getSubType()])) {
- $function = $CONFIG->entity_url_handler[$entity->getType()][$entity->getSubType()];
- if (is_callable($function)) {
- $url = $function($entity);
- }
- } elseif (isset($CONFIG->entity_url_handler[$entity->getType()]['all'])) {
- $function = $CONFIG->entity_url_handler[$entity->getType()]['all'];
- if (is_callable($function)) {
- $url = $function($entity);
- }
- } elseif (isset($CONFIG->entity_url_handler['all']['all'])) {
- $function = $CONFIG->entity_url_handler['all']['all'];
- if (is_callable($function)) {
- $url = $function($entity);
- }
- }
-
- if ($url == "") {
- $url = $CONFIG->url . "pg/view/" . $entity_guid;
- }
- return $url;
-
- }
- return false;
-
- }
-
- /**
- * Sets the URL handler for a particular entity type and subtype
- *
- * @param string $function_name The function to register
- * @param string $entity_type The entity type
- * @param string $entity_subtype The entity subtype
- * @return true|false Depending on success
- */
- function register_entity_url_handler($function_name, $entity_type = "all", $entity_subtype = "all") {
- global $CONFIG;
-
- if (!is_callable($function_name)) return false;
-
- if (!isset($CONFIG->entity_url_handler)) {
- $CONFIG->entity_url_handler = array();
- }
- if (!isset($CONFIG->entity_url_handler[$entity_type])) {
- $CONFIG->entity_url_handler[$entity_type] = array();
- }
- $CONFIG->entity_url_handler[$entity_type][$entity_subtype] = $function_name;
-
- return true;
-
- }
-
- /**
- * Default Icon URL handler for entities.
- * This will attempt to find a default entity for the current view and return a url. This is registered at
- * a low priority so that other handlers will pick it up first.
- *
- * @param unknown_type $hook
- * @param unknown_type $entity_type
- * @param unknown_type $returnvalue
- * @param unknown_type $params
- */
- function default_entity_icon_hook($hook, $entity_type, $returnvalue, $params)
- {
- global $CONFIG;
-
- if ((!$returnvalue) && ($hook == 'entity:icon:url'))
- {
- $entity = $params['entity'];
- $type = $entity->type;
- $subtype = get_subtype_from_id($entity->subtype);
- $viewtype = $params['viewtype'];
- $size = $params['size'];
-
- $url = "views/$viewtype/graphics/icons/$type/$subtype/$size.png";
-
- if (!@file_exists($CONFIG->path . $url))
- $url = "views/$viewtype/graphics/icons/$type/default/$size.png";
-
- if(!@file_exists($CONFIG->path . $url))
- $url = "views/$viewtype/graphics/icons/default/$size.png";
-
- if (@file_exists($CONFIG->path . $url))
- return $CONFIG->url . $url;
- }
- }
-
- /**
- * Registers and entity type and subtype to return in search and other places.
- * A description in the elgg_echo languages file of the form item:type:subtype
- * is also expected.
- *
- * @param string $type The type of entity (object, site, user, group)
- * @param string $subtype The subtype to register (may be blank)
- * @return true|false Depending on success
- */
- function register_entity_type($type, $subtype) {
-
- global $CONFIG;
-
- $type = strtolower($type);
- if (!in_array($type,array('object','site','group','user'))) return false;
-
- if (!isset($CONFIG->registered_entities)) $CONFIG->registered_entities = array();
- $CONFIG->registered_entities[$type][] = $subtype;
-
- return true;
-
- }
-
- /**
- * Returns registered entity types and subtypes
- *
- * @see register_entity_type
- *
- * @param string $type The type of entity (object, site, user, group) or blank for all
- * @return array|false Depending on whether entities have been registered
- */
- function get_registered_entity_types($type = '') {
-
- global $CONFIG;
-
- if (!isset($CONFIG->registered_entities)) return false;
- if (!empty($type)) $type = strtolower($type);
- if (!empty($type) && empty($CONFIG->registered_entities[$type])) return false;
-
- if (empty($type))
- return $CONFIG->registered_entities;
-
- return $CONFIG->registered_entities[$type];
-
- }
-
- /**
- * Determines whether or not the specified entity type and subtype have been registered in the system
- *
- * @param string $type The type of entity (object, site, user, group)
- * @param string $subtype The subtype (may be blank)
- * @return true|false Depending on whether or not the type has been registered
- */
- function is_registered_entity_type($type, $subtype) {
-
- global $CONFIG;
-
- if (!isset($CONFIG->registered_entities)) return false;
- $type = strtolower($type);
- if (empty($CONFIG->registered_entities[$type])) return false;
- if (in_array($subtype, $CONFIG->registered_entities[$type])) return true;
-
- }
-
- /**
- * Page handler for generic entities view system
- *
- * @param array $page Page elements from pain page handler
- */
- function entities_page_handler($page) {
- if (isset($page[0])) {
- global $CONFIG;
- set_input('guid',$page[0]);
- @include($CONFIG->path . "entities/index.php");
- }
- }
-
- /**
- * Returns a viewable list of entities based on the registered types
- *
- * @see elgg_view_entity_list
- *
- * @param string $type The type of entity (eg "user", "object" etc)
- * @param string $subtype The arbitrary subtype of the entity
- * @param int $owner_guid The GUID of the owning user
- * @param int $limit The number of entities to display per page (default: 10)
- * @param true|false $fullview Whether or not to display the full view (default: true)
- * @param true|false $viewtypetoggle Whether or not to allow gallery view
- * @return string A viewable list of entities
- */
- function list_registered_entities($owner_guid = 0, $limit = 10, $fullview = true, $viewtypetoggle = false, $allowedtypes = true) {
-
- $typearray = array();
-
- if ($object_types = get_registered_entity_types()) {
- foreach($object_types as $object_type => $subtype_array) {
- if (is_array($subtype_array) && sizeof($subtype_array) && (in_array($object_type,$allowedtypes) || $allowedtypes === true))
- foreach($subtype_array as $object_subtype) {
- $typearray[$object_type][] = $object_subtype;
- }
- }
- }
-
- $offset = (int) get_input('offset');
- $count = get_entities('', $typearray, $owner_guid, "", $limit, $offset, true);
- $entities = get_entities('', $typearray,$owner_guid, "", $limit, $offset);
-
- return elgg_view_entity_list($entities, $count, $offset, $limit, $fullview, $viewtypetoggle);
-
- }
-
- /**
- * Get entities based on their private data, in a similar way to metadata.
- *
- * @param string $name The name of the setting
- * @param string $value The value of the setting
- * @param string $type The type of entity (eg "user", "object" etc)
- * @param string $subtype The arbitrary subtype of the entity
- * @param int $owner_guid The GUID of the owning user
- * @param string $order_by The field to order by; by default, time_created desc
- * @param int $limit The number of entities to return; 10 by default
- * @param int $offset The indexing offset, 0 by default
- * @param boolean $count Set to true to get a count rather than the entities themselves (limits and offsets don't apply in this context). Defaults to false.
- * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
- * @param int|array $container_guid The container or containers to get entities from (default: all containers).
- * @return array A list of entities.
- */
- function get_entities_from_private_setting($name = "", $value = "", $type = "", $subtype = "", $owner_guid = 0, $order_by = "", $limit = 10, $offset = 0, $count = false, $site_guid = 0, $container_guid = null)
- {
- global $CONFIG;
-
- if ($subtype === false || $subtype === null || $subtype === 0)
- return false;
-
- $name = sanitise_string($name);
- $value = sanitise_string($value);
-
- if ($order_by == "") $order_by = "e.time_created desc";
- $order_by = sanitise_string($order_by);
- $limit = (int)$limit;
- $offset = (int)$offset;
- $site_guid = (int) $site_guid;
- if ($site_guid == 0)
- $site_guid = $CONFIG->site_guid;
-
- $where = array();
-
- if (is_array($type)) {
- $tempwhere = "";
- if (sizeof($type))
- foreach($type as $typekey => $subtypearray) {
- foreach($subtypearray as $subtypeval) {
- $typekey = sanitise_string($typekey);
- if (!empty($subtypeval)) {
- if (!$subtypeval = (int) get_subtype_id($typekey, $subtypeval)) {
- return false;
- }
- } else {
- $subtypeval = 0;
- }
- if (!empty($tempwhere)) $tempwhere .= " or ";
- $tempwhere .= "(e.type = '{$typekey}' and e.subtype = {$subtypeval})";
- }
- }
- if (!empty($tempwhere)) $where[] = "({$tempwhere})";
-
- } else {
-
- $type = sanitise_string($type);
- if ($subtype AND !$subtype = get_subtype_id($type, $subtype)) {
- return false;
- }
-
- if ($type != "")
- $where[] = "e.type='$type'";
- if ($subtype!=="")
- $where[] = "e.subtype=$subtype";
-
- }
-
- if ($owner_guid != "") {
- if (!is_array($owner_guid)) {
- $owner_array = array($owner_guid);
- $owner_guid = (int) $owner_guid;
- // $where[] = "owner_guid = '$owner_guid'";
- } else if (sizeof($owner_guid) > 0) {
- $owner_array = array_map('sanitise_int', $owner_guid);
- // Cast every element to the owner_guid array to int
- // $owner_guid = array_map("sanitise_int", $owner_guid);
- // $owner_guid = implode(",",$owner_guid);
- // $where[] = "owner_guid in ({$owner_guid})";
- }
- if (is_null($container_guid)) {
- $container_guid = $owner_array;
- }
- }
- if ($site_guid > 0)
- $where[] = "e.site_guid = {$site_guid}";
-
- if (!is_null($container_guid)) {
- if (is_array($container_guid)) {
- foreach($container_guid as $key => $val) $container_guid[$key] = (int) $val;
- $where[] = "e.container_guid in (" . implode(",",$container_guid) . ")";
- } else {
- $container_guid = (int) $container_guid;
- $where[] = "e.container_guid = {$container_guid}";
- }
- }
-
- if ($name!="")
- $where[] = "s.name = '$name'";
- if ($value!="")
- $where[] = "s.value='$value'";
-
- if (!$count) {
- $query = "SELECT distinct e.* from {$CONFIG->dbprefix}entities e JOIN {$CONFIG->dbprefix}private_settings s ON e.guid=s.entity_guid where ";
- } else {
- $query = "SELECT count(distinct e.guid) as total from {$CONFIG->dbprefix}entities e JOIN {$CONFIG->dbprefix}private_settings s ON e.guid=s.entity_guid where ";
- }
- foreach ($where as $w)
- $query .= " $w and ";
- $query .= get_access_sql_suffix('e'); // Add access controls
- if (!$count) {
- $query .= " order by $order_by";
- if ($limit) $query .= " limit $offset, $limit"; // Add order and limit
-
- $dt = get_data($query, "entity_row_to_elggstar");
- return $dt;
- } else {
- $total = get_data_row($query);
- return $total->total;
- }
- }
-
- /**
- * Get entities based on their private data by multiple keys, in a similar way to metadata.
- *
- * @param string $name The name of the setting
- * @param string $value The value of the setting
- * @param string|array $type The type of entity (eg "user", "object" etc) or array(type1 => array('subtype1', ...'subtypeN'), ...)
- * @param string $subtype The arbitrary subtype of the entity
- * @param int $owner_guid The GUID of the owning user
- * @param string $order_by The field to order by; by default, time_created desc
- * @param int $limit The number of entities to return; 10 by default
- * @param int $offset The indexing offset, 0 by default
- * @param boolean $count Set to true to get a count rather than the entities themselves (limits and offsets don't apply in this context). Defaults to false.
- * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
- * @param int|array $container_guid The container or containers to get entities from (default: all containers).
- * @return array A list of entities.
- */
- function get_entities_from_private_setting_multi(array $name, $type = "", $subtype = "", $owner_guid = 0, $order_by = "", $limit = 10, $offset = 0, $count = false, $site_guid = 0, $container_guid = null)
- {
- global $CONFIG;
-
- if ($subtype === false || $subtype === null || $subtype === 0)
- return false;
-
- if ($order_by == "") $order_by = "e.time_created desc";
- $order_by = sanitise_string($order_by);
- $limit = (int)$limit;
- $offset = (int)$offset;
- $site_guid = (int) $site_guid;
- if ($site_guid == 0)
- $site_guid = $CONFIG->site_guid;
-
- $where = array();
-
- if (is_array($type)) {
- $tempwhere = "";
- if (sizeof($type))
- foreach($type as $typekey => $subtypearray) {
- foreach($subtypearray as $subtypeval) {
- $typekey = sanitise_string($typekey);
- if (!empty($subtypeval)) {
- if (!$subtypeval = (int) get_subtype_id($typekey, $subtypeval)) {
- return false;
- }
- } else {
- $subtypeval = 0;
- }
- if (!empty($tempwhere)) $tempwhere .= " or ";
- $tempwhere .= "(e.type = '{$typekey}' and e.subtype = {$subtypeval})";
- }
- }
- if (!empty($tempwhere)) $where[] = "({$tempwhere})";
-
- } else {
- $type = sanitise_string($type);
- if ($subtype AND !$subtype = get_subtype_id($type, $subtype))
- return false;
-
- if ($type != "")
- $where[] = "e.type='$type'";
- if ($subtype!=="")
- $where[] = "e.subtype=$subtype";
-
- }
-
- if ($owner_guid != "") {
- if (!is_array($owner_guid)) {
- $owner_array = array($owner_guid);
- $owner_guid = (int) $owner_guid;
- // $where[] = "owner_guid = '$owner_guid'";
- } else if (sizeof($owner_guid) > 0) {
- $owner_array = array_map('sanitise_int', $owner_guid);
- // Cast every element to the owner_guid array to int
- // $owner_guid = array_map("sanitise_int", $owner_guid);
- // $owner_guid = implode(",",$owner_guid);
- // $where[] = "owner_guid in ({$owner_guid})";
- }
- if (is_null($container_guid)) {
- $container_guid = $owner_array;
- }
- }
- if ($site_guid > 0)
- $where[] = "e.site_guid = {$site_guid}";
-
- if (!is_null($container_guid)) {
- if (is_array($container_guid)) {
- foreach($container_guid as $key => $val) $container_guid[$key] = (int) $val;
- $where[] = "e.container_guid in (" . implode(",",$container_guid) . ")";
- } else {
- $container_guid = (int) $container_guid;
- $where[] = "e.container_guid = {$container_guid}";
- }
- }
-
- if ($name)
- {
- $s_join = "";
- $i = 1;
- foreach ($name as $k => $n)
- {
- $k = sanitise_string($k);
- $s_join .= " JOIN {$CONFIG->dbprefix}private_settings s$i ON e.guid=s$i.entity_guid";
- $where[] = "s$i.name = '$k'";
- $where[] = "s$i.value = '$n'";
- $i++;
- }
- }
-
- if (!$count) {
- $query = "SELECT distinct e.* from {$CONFIG->dbprefix}entities e $s_join where ";
- } else {
- $query = "SELECT count(distinct e.guid) as total from {$CONFIG->dbprefix}entities e $s_join where ";
- }
- foreach ($where as $w)
- $query .= " $w and ";
- $query .= get_access_sql_suffix('e'); // Add access controls
- if (!$count) {
- $query .= " order by $order_by";
- if ($limit) $query .= " limit $offset, $limit"; // Add order and limit
-
- $dt = get_data($query, "entity_row_to_elggstar");
- return $dt;
- } else {
- $total = get_data_row($query);
- return $total->total;
- }
- }
-
- /**
- * Gets a private setting for an entity.
- *
- * @param int $entity_guid The entity GUID
- * @param string $name The name of the setting
- * @return mixed The setting value, or false on failure
- */
- function get_private_setting($entity_guid, $name) {
-
- global $CONFIG;
- $entity_guid = (int) $entity_guid;
- $name = sanitise_string($name);
-
- if ($setting = get_data_row("SELECT value from {$CONFIG->dbprefix}private_settings where name = '{$name}' and entity_guid = {$entity_guid}")) {
- return $setting->value;
- }
- return false;
-
- }
-
- /**
- * Return an array of all private settings for a given
- *
- * @param int $entity_guid The entity GUID
- */
- function get_all_private_settings($entity_guid) {
- global $CONFIG;
-
- $entity_guid = (int) $entity_guid;
-
- $result = get_data("SELECT * from {$CONFIG->dbprefix}private_settings where entity_guid = {$entity_guid}");
- if ($result)
- {
- $return = array();
- foreach ($result as $r)
- $return[$r->name] = $r->value;
-
- return $return;
- }
-
- return false;
- }
-
- /**
- * Sets a private setting for an entity.
- *
- * @param int $entity_guid The entity GUID
- * @param string $name The name of the setting
- * @param string $value The value of the setting
- * @return mixed The setting ID, or false on failure
- */
- function set_private_setting($entity_guid, $name, $value) {
-
- global $CONFIG;
- $entity_guid = (int) $entity_guid;
- $name = sanitise_string($name);
- $value = sanitise_string($value);
-
- $result = insert_data("INSERT into {$CONFIG->dbprefix}private_settings (entity_guid, name, value) VALUES ($entity_guid, '{$name}', '{$value}') ON DUPLICATE KEY UPDATE value='$value'");
- if ($result === 0) return true;
- return $result;
-
- }
-
- /**
- * Deletes a private setting for an entity.
- *
- * @param int $entity_guid The Entity GUID
- * @param string $name The name of the setting
- * @return true|false depending on success
- *
- */
- function remove_private_setting($entity_guid, $name) {
-
- global $CONFIG;
- $entity_guid = (int) $entity_guid;
- $name = sanitise_string($name);
- return delete_data("DELETE from {$CONFIG->dbprefix}private_settings where name = '{$name}' and entity_guid = {$entity_guid}");
-
- }
-
- /**
- * Deletes all private settings for an entity.
- *
- * @param int $entity_guid The Entity GUID
- * @return true|false depending on success
- *
- */
- function remove_all_private_settings($entity_guid) {
-
- global $CONFIG;
- $entity_guid = (int) $entity_guid;
- return delete_data("DELETE from {$CONFIG->dbprefix}private_settings where entity_guid = {$entity_guid}");
- }
-
- function recursive_delete_permissions_check($hook, $entity_type, $returnvalue, $params)
- {
- static $__RECURSIVE_DELETE_TOKEN;
-
- $entity = $params['entity'];
-
- if ((isloggedin()) && ($__RECURSIVE_DELETE_TOKEN) && (strcmp($__RECURSIVE_DELETE_TOKEN, md5(get_loggedin_userid()))))
- return true;
-
+
+ case 'large' : $size = 'large'; break;
+
+ case 'topbar' : $size = 'topbar'; break;
+
+ case 'tiny' : $size = 'tiny'; break;
+
+ case 'small' : $size = 'small'; break;
+
+ case 'medium' :
+ default: $size = 'medium';
+ }
+
+ $url = false;
+
+ $viewtype = elgg_get_viewtype();
+
+ // Step one, see if anyone knows how to render this in the current view
+ $url = trigger_plugin_hook('entity:icon:url', $entity->getType(), array('entity' => $entity, 'viewtype' => $viewtype, 'size' => $size), $url);
+
+ // Fail, so use default
+ if (!$url) {
+
+ $type = $entity->getType();
+ $subtype = $entity->getSubtype();
+
+ if (!empty($subtype)) {
+ $overrideurl = elgg_view("icon/{$type}/{$subtype}/{$size}",array('entity' => $entity));
+ if (!empty($overrideurl)) return $overrideurl;
+ }
+
+ $overrideurl = elgg_view("icon/{$type}/default/{$size}",array('entity' => $entity));
+ if (!empty($overrideurl)) return $overrideurl;
+
+ $url = $CONFIG->url . "_graphics/icons/default/$size.png";
+ }
+
+ return $url;
+ }
+
+ /**
+ * Gets the URL for an entity, given a particular GUID
+ *
+ * @param int $entity_guid The GUID of the entity
+ * @return string The URL of the entity
+ */
+ function get_entity_url($entity_guid) {
+
+ global $CONFIG;
+ if ($entity = get_entity($entity_guid)) {
+
+ $url = "";
+
+ if (isset($CONFIG->entity_url_handler[$entity->getType()][$entity->getSubType()])) {
+ $function = $CONFIG->entity_url_handler[$entity->getType()][$entity->getSubType()];
+ if (is_callable($function)) {
+ $url = $function($entity);
+ }
+ } elseif (isset($CONFIG->entity_url_handler[$entity->getType()]['all'])) {
+ $function = $CONFIG->entity_url_handler[$entity->getType()]['all'];
+ if (is_callable($function)) {
+ $url = $function($entity);
+ }
+ } elseif (isset($CONFIG->entity_url_handler['all']['all'])) {
+ $function = $CONFIG->entity_url_handler['all']['all'];
+ if (is_callable($function)) {
+ $url = $function($entity);
+ }
+ }
+
+ if ($url == "") {
+ $url = $CONFIG->url . "pg/view/" . $entity_guid;
+ }
+ return $url;
+
+ }
+ return false;
+
+ }
+
+ /**
+ * Sets the URL handler for a particular entity type and subtype
+ *
+ * @param string $function_name The function to register
+ * @param string $entity_type The entity type
+ * @param string $entity_subtype The entity subtype
+ * @return true|false Depending on success
+ */
+ function register_entity_url_handler($function_name, $entity_type = "all", $entity_subtype = "all") {
+ global $CONFIG;
+
+ if (!is_callable($function_name)) return false;
+
+ if (!isset($CONFIG->entity_url_handler)) {
+ $CONFIG->entity_url_handler = array();
+ }
+ if (!isset($CONFIG->entity_url_handler[$entity_type])) {
+ $CONFIG->entity_url_handler[$entity_type] = array();
+ }
+ $CONFIG->entity_url_handler[$entity_type][$entity_subtype] = $function_name;
+
+ return true;
+
+ }
+
+ /**
+ * Default Icon URL handler for entities.
+ * This will attempt to find a default entity for the current view and return a url. This is registered at
+ * a low priority so that other handlers will pick it up first.
+ *
+ * @param unknown_type $hook
+ * @param unknown_type $entity_type
+ * @param unknown_type $returnvalue
+ * @param unknown_type $params
+ */
+ function default_entity_icon_hook($hook, $entity_type, $returnvalue, $params)
+ {
+ global $CONFIG;
+
+ if ((!$returnvalue) && ($hook == 'entity:icon:url'))
+ {
+ $entity = $params['entity'];
+ $type = $entity->type;
+ $subtype = get_subtype_from_id($entity->subtype);
+ $viewtype = $params['viewtype'];
+ $size = $params['size'];
+
+ $url = "views/$viewtype/graphics/icons/$type/$subtype/$size.png";
+
+ if (!@file_exists($CONFIG->path . $url))
+ $url = "views/$viewtype/graphics/icons/$type/default/$size.png";
+
+ if(!@file_exists($CONFIG->path . $url))
+ $url = "views/$viewtype/graphics/icons/default/$size.png";
+
+ if (@file_exists($CONFIG->path . $url))
+ return $CONFIG->url . $url;
+ }
+ }
+
+ /**
+ * Registers and entity type and subtype to return in search and other places.
+ * A description in the elgg_echo languages file of the form item:type:subtype
+ * is also expected.
+ *
+ * @param string $type The type of entity (object, site, user, group)
+ * @param string $subtype The subtype to register (may be blank)
+ * @return true|false Depending on success
+ */
+ function register_entity_type($type, $subtype) {
+
+ global $CONFIG;
+
+ $type = strtolower($type);
+ if (!in_array($type,array('object','site','group','user'))) return false;
+
+ if (!isset($CONFIG->registered_entities)) $CONFIG->registered_entities = array();
+ $CONFIG->registered_entities[$type][] = $subtype;
+
+ return true;
+
+ }
+
+ /**
+ * Returns registered entity types and subtypes
+ *
+ * @see register_entity_type
+ *
+ * @param string $type The type of entity (object, site, user, group) or blank for all
+ * @return array|false Depending on whether entities have been registered
+ */
+ function get_registered_entity_types($type = '') {
+
+ global $CONFIG;
+
+ if (!isset($CONFIG->registered_entities)) return false;
+ if (!empty($type)) $type = strtolower($type);
+ if (!empty($type) && empty($CONFIG->registered_entities[$type])) return false;
+
+ if (empty($type))
+ return $CONFIG->registered_entities;
+
+ return $CONFIG->registered_entities[$type];
+
+ }
+
+ /**
+ * Determines whether or not the specified entity type and subtype have been registered in the system
+ *
+ * @param string $type The type of entity (object, site, user, group)
+ * @param string $subtype The subtype (may be blank)
+ * @return true|false Depending on whether or not the type has been registered
+ */
+ function is_registered_entity_type($type, $subtype) {
+
+ global $CONFIG;
+
+ if (!isset($CONFIG->registered_entities)) return false;
+ $type = strtolower($type);
+ if (empty($CONFIG->registered_entities[$type])) return false;
+ if (in_array($subtype, $CONFIG->registered_entities[$type])) return true;
+
+ }
+
+ /**
+ * Page handler for generic entities view system
+ *
+ * @param array $page Page elements from pain page handler
+ */
+ function entities_page_handler($page) {
+ if (isset($page[0])) {
+ global $CONFIG;
+ set_input('guid',$page[0]);
+ @include($CONFIG->path . "entities/index.php");
+ }
+ }
+
+ /**
+ * Returns a viewable list of entities based on the registered types
+ *
+ * @see elgg_view_entity_list
+ *
+ * @param string $type The type of entity (eg "user", "object" etc)
+ * @param string $subtype The arbitrary subtype of the entity
+ * @param int $owner_guid The GUID of the owning user
+ * @param int $limit The number of entities to display per page (default: 10)
+ * @param true|false $fullview Whether or not to display the full view (default: true)
+ * @param true|false $viewtypetoggle Whether or not to allow gallery view
+ * @return string A viewable list of entities
+ */
+ function list_registered_entities($owner_guid = 0, $limit = 10, $fullview = true, $viewtypetoggle = false, $allowedtypes = true) {
+
+ $typearray = array();
+
+ if ($object_types = get_registered_entity_types()) {
+ foreach($object_types as $object_type => $subtype_array) {
+ if (is_array($subtype_array) && sizeof($subtype_array) && (in_array($object_type,$allowedtypes) || $allowedtypes === true))
+ foreach($subtype_array as $object_subtype) {
+ $typearray[$object_type][] = $object_subtype;
+ }
+ }
+ }
+
+ $offset = (int) get_input('offset');
+ $count = get_entities('', $typearray, $owner_guid, "", $limit, $offset, true);
+ $entities = get_entities('', $typearray,$owner_guid, "", $limit, $offset);
+
+ return elgg_view_entity_list($entities, $count, $offset, $limit, $fullview, $viewtypetoggle);
+
+ }
+
+ /**
+ * Get entities based on their private data, in a similar way to metadata.
+ *
+ * @param string $name The name of the setting
+ * @param string $value The value of the setting
+ * @param string $type The type of entity (eg "user", "object" etc)
+ * @param string $subtype The arbitrary subtype of the entity
+ * @param int $owner_guid The GUID of the owning user
+ * @param string $order_by The field to order by; by default, time_created desc
+ * @param int $limit The number of entities to return; 10 by default
+ * @param int $offset The indexing offset, 0 by default
+ * @param boolean $count Set to true to get a count rather than the entities themselves (limits and offsets don't apply in this context). Defaults to false.
+ * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
+ * @param int|array $container_guid The container or containers to get entities from (default: all containers).
+ * @return array A list of entities.
+ */
+ function get_entities_from_private_setting($name = "", $value = "", $type = "", $subtype = "", $owner_guid = 0, $order_by = "", $limit = 10, $offset = 0, $count = false, $site_guid = 0, $container_guid = null)
+ {
+ global $CONFIG;
+
+ if ($subtype === false || $subtype === null || $subtype === 0)
+ return false;
+
+ $name = sanitise_string($name);
+ $value = sanitise_string($value);
+
+ if ($order_by == "") $order_by = "e.time_created desc";
+ $order_by = sanitise_string($order_by);
+ $limit = (int)$limit;
+ $offset = (int)$offset;
+ $site_guid = (int) $site_guid;
+ if ($site_guid == 0)
+ $site_guid = $CONFIG->site_guid;
+
+ $where = array();
+
+ if (is_array($type)) {
+ $tempwhere = "";
+ if (sizeof($type))
+ foreach($type as $typekey => $subtypearray) {
+ foreach($subtypearray as $subtypeval) {
+ $typekey = sanitise_string($typekey);
+ if (!empty($subtypeval)) {
+ if (!$subtypeval = (int) get_subtype_id($typekey, $subtypeval)) {
+ return false;
+ }
+ } else {
+ $subtypeval = 0;
+ }
+ if (!empty($tempwhere)) $tempwhere .= " or ";
+ $tempwhere .= "(e.type = '{$typekey}' and e.subtype = {$subtypeval})";
+ }
+ }
+ if (!empty($tempwhere)) $where[] = "({$tempwhere})";
+
+ } else {
+
+ $type = sanitise_string($type);
+ if ($subtype AND !$subtype = get_subtype_id($type, $subtype)) {
+ return false;
+ }
+
+ if ($type != "")
+ $where[] = "e.type='$type'";
+ if ($subtype!=="")
+ $where[] = "e.subtype=$subtype";
+
+ }
+
+ if ($owner_guid != "") {
+ if (!is_array($owner_guid)) {
+ $owner_array = array($owner_guid);
+ $owner_guid = (int) $owner_guid;
+ // $where[] = "owner_guid = '$owner_guid'";
+ } else if (sizeof($owner_guid) > 0) {
+ $owner_array = array_map('sanitise_int', $owner_guid);
+ // Cast every element to the owner_guid array to int
+ // $owner_guid = array_map("sanitise_int", $owner_guid);
+ // $owner_guid = implode(",",$owner_guid);
+ // $where[] = "owner_guid in ({$owner_guid})";
+ }
+ if (is_null($container_guid)) {
+ $container_guid = $owner_array;
+ }
+ }
+ if ($site_guid > 0)
+ $where[] = "e.site_guid = {$site_guid}";
+
+ if (!is_null($container_guid)) {
+ if (is_array($container_guid)) {
+ foreach($container_guid as $key => $val) $container_guid[$key] = (int) $val;
+ $where[] = "e.container_guid in (" . implode(",",$container_guid) . ")";
+ } else {
+ $container_guid = (int) $container_guid;
+ $where[] = "e.container_guid = {$container_guid}";
+ }
+ }
+
+ if ($name!="")
+ $where[] = "s.name = '$name'";
+ if ($value!="")
+ $where[] = "s.value='$value'";
+
+ if (!$count) {
+ $query = "SELECT distinct e.* from {$CONFIG->dbprefix}entities e JOIN {$CONFIG->dbprefix}private_settings s ON e.guid=s.entity_guid where ";
+ } else {
+ $query = "SELECT count(distinct e.guid) as total from {$CONFIG->dbprefix}entities e JOIN {$CONFIG->dbprefix}private_settings s ON e.guid=s.entity_guid where ";
+ }
+ foreach ($where as $w)
+ $query .= " $w and ";
+ $query .= get_access_sql_suffix('e'); // Add access controls
+ if (!$count) {
+ $query .= " order by $order_by";
+ if ($limit) $query .= " limit $offset, $limit"; // Add order and limit
+
+ $dt = get_data($query, "entity_row_to_elggstar");
+ return $dt;
+ } else {
+ $total = get_data_row($query);
+ return $total->total;
+ }
+ }
+
+ /**
+ * Get entities based on their private data by multiple keys, in a similar way to metadata.
+ *
+ * @param string $name The name of the setting
+ * @param string $value The value of the setting
+ * @param string|array $type The type of entity (eg "user", "object" etc) or array(type1 => array('subtype1', ...'subtypeN'), ...)
+ * @param string $subtype The arbitrary subtype of the entity
+ * @param int $owner_guid The GUID of the owning user
+ * @param string $order_by The field to order by; by default, time_created desc
+ * @param int $limit The number of entities to return; 10 by default
+ * @param int $offset The indexing offset, 0 by default
+ * @param boolean $count Set to true to get a count rather than the entities themselves (limits and offsets don't apply in this context). Defaults to false.
+ * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
+ * @param int|array $container_guid The container or containers to get entities from (default: all containers).
+ * @return array A list of entities.
+ */
+ function get_entities_from_private_setting_multi(array $name, $type = "", $subtype = "", $owner_guid = 0, $order_by = "", $limit = 10, $offset = 0, $count = false, $site_guid = 0, $container_guid = null)
+ {
+ global $CONFIG;
+
+ if ($subtype === false || $subtype === null || $subtype === 0)
+ return false;
+
+ if ($order_by == "") $order_by = "e.time_created desc";
+ $order_by = sanitise_string($order_by);
+ $limit = (int)$limit;
+ $offset = (int)$offset;
+ $site_guid = (int) $site_guid;
+ if ($site_guid == 0)
+ $site_guid = $CONFIG->site_guid;
+
+ $where = array();
+
+ if (is_array($type)) {
+ $tempwhere = "";
+ if (sizeof($type))
+ foreach($type as $typekey => $subtypearray) {
+ foreach($subtypearray as $subtypeval) {
+ $typekey = sanitise_string($typekey);
+ if (!empty($subtypeval)) {
+ if (!$subtypeval = (int) get_subtype_id($typekey, $subtypeval)) {
+ return false;
+ }
+ } else {
+ $subtypeval = 0;
+ }
+ if (!empty($tempwhere)) $tempwhere .= " or ";
+ $tempwhere .= "(e.type = '{$typekey}' and e.subtype = {$subtypeval})";
+ }
+ }
+ if (!empty($tempwhere)) $where[] = "({$tempwhere})";
+
+ } else {
+ $type = sanitise_string($type);
+ if ($subtype AND !$subtype = get_subtype_id($type, $subtype))
+ return false;
+
+ if ($type != "")
+ $where[] = "e.type='$type'";
+ if ($subtype!=="")
+ $where[] = "e.subtype=$subtype";
+
+ }
+
+ if ($owner_guid != "") {
+ if (!is_array($owner_guid)) {
+ $owner_array = array($owner_guid);
+ $owner_guid = (int) $owner_guid;
+ // $where[] = "owner_guid = '$owner_guid'";
+ } else if (sizeof($owner_guid) > 0) {
+ $owner_array = array_map('sanitise_int', $owner_guid);
+ // Cast every element to the owner_guid array to int
+ // $owner_guid = array_map("sanitise_int", $owner_guid);
+ // $owner_guid = implode(",",$owner_guid);
+ // $where[] = "owner_guid in ({$owner_guid})";
+ }
+ if (is_null($container_guid)) {
+ $container_guid = $owner_array;
+ }
+ }
+ if ($site_guid > 0)
+ $where[] = "e.site_guid = {$site_guid}";
+
+ if (!is_null($container_guid)) {
+ if (is_array($container_guid)) {
+ foreach($container_guid as $key => $val) $container_guid[$key] = (int) $val;
+ $where[] = "e.container_guid in (" . implode(",",$container_guid) . ")";
+ } else {
+ $container_guid = (int) $container_guid;
+ $where[] = "e.container_guid = {$container_guid}";
+ }
+ }
+
+ if ($name)
+ {
+ $s_join = "";
+ $i = 1;
+ foreach ($name as $k => $n)
+ {
+ $k = sanitise_string($k);
+ $s_join .= " JOIN {$CONFIG->dbprefix}private_settings s$i ON e.guid=s$i.entity_guid";
+ $where[] = "s$i.name = '$k'";
+ $where[] = "s$i.value = '$n'";
+ $i++;
+ }
+ }
+
+ if (!$count) {
+ $query = "SELECT distinct e.* from {$CONFIG->dbprefix}entities e $s_join where ";
+ } else {
+ $query = "SELECT count(distinct e.guid) as total from {$CONFIG->dbprefix}entities e $s_join where ";
+ }
+ foreach ($where as $w)
+ $query .= " $w and ";
+ $query .= get_access_sql_suffix('e'); // Add access controls
+ if (!$count) {
+ $query .= " order by $order_by";
+ if ($limit) $query .= " limit $offset, $limit"; // Add order and limit
+
+ $dt = get_data($query, "entity_row_to_elggstar");
+ return $dt;
+ } else {
+ $total = get_data_row($query);
+ return $total->total;
+ }
+ }
+
+ /**
+ * Gets a private setting for an entity.
+ *
+ * @param int $entity_guid The entity GUID
+ * @param string $name The name of the setting
+ * @return mixed The setting value, or false on failure
+ */
+ function get_private_setting($entity_guid, $name) {
+
+ global $CONFIG;
+ $entity_guid = (int) $entity_guid;
+ $name = sanitise_string($name);
+
+ if ($setting = get_data_row("SELECT value from {$CONFIG->dbprefix}private_settings where name = '{$name}' and entity_guid = {$entity_guid}")) {
+ return $setting->value;
+ }
+ return false;
+
+ }
+
+ /**
+ * Return an array of all private settings for a given
+ *
+ * @param int $entity_guid The entity GUID
+ */
+ function get_all_private_settings($entity_guid) {
+ global $CONFIG;
+
+ $entity_guid = (int) $entity_guid;
+
+ $result = get_data("SELECT * from {$CONFIG->dbprefix}private_settings where entity_guid = {$entity_guid}");
+ if ($result)
+ {
+ $return = array();
+ foreach ($result as $r)
+ $return[$r->name] = $r->value;
+
+ return $return;
+ }
+
+ return false;
+ }
+
+ /**
+ * Sets a private setting for an entity.
+ *
+ * @param int $entity_guid The entity GUID
+ * @param string $name The name of the setting
+ * @param string $value The value of the setting
+ * @return mixed The setting ID, or false on failure
+ */
+ function set_private_setting($entity_guid, $name, $value) {
+
+ global $CONFIG;
+ $entity_guid = (int) $entity_guid;
+ $name = sanitise_string($name);
+ $value = sanitise_string($value);
+
+ $result = insert_data("INSERT into {$CONFIG->dbprefix}private_settings (entity_guid, name, value) VALUES ($entity_guid, '{$name}', '{$value}') ON DUPLICATE KEY UPDATE value='$value'");
+ if ($result === 0) return true;
+ return $result;
+
+ }
+
+ /**
+ * Deletes a private setting for an entity.
+ *
+ * @param int $entity_guid The Entity GUID
+ * @param string $name The name of the setting
+ * @return true|false depending on success
+ *
+ */
+ function remove_private_setting($entity_guid, $name) {
+
+ global $CONFIG;
+ $entity_guid = (int) $entity_guid;
+ $name = sanitise_string($name);
+ return delete_data("DELETE from {$CONFIG->dbprefix}private_settings where name = '{$name}' and entity_guid = {$entity_guid}");
+
+ }
+
+ /**
+ * Deletes all private settings for an entity.
+ *
+ * @param int $entity_guid The Entity GUID
+ * @return true|false depending on success
+ *
+ */
+ function remove_all_private_settings($entity_guid) {
+
+ global $CONFIG;
+ $entity_guid = (int) $entity_guid;
+ return delete_data("DELETE from {$CONFIG->dbprefix}private_settings where entity_guid = {$entity_guid}");
+ }
+
+ function recursive_delete_permissions_check($hook, $entity_type, $returnvalue, $params)
+ {
+ static $__RECURSIVE_DELETE_TOKEN;
+
+ $entity = $params['entity'];
+
+ if ((isloggedin()) && ($__RECURSIVE_DELETE_TOKEN) && (strcmp($__RECURSIVE_DELETE_TOKEN, md5(get_loggedin_userid()))))
+ return true;
+
}
/**
@@ -2763,37 +2763,37 @@
foreach ($tables as $table) {
delete_data("DELETE from {$CONFIG->dbprefix}{$table} where guid NOT IN (SELECT guid from {$CONFIG->dbprefix}entities)");
}
- }
-
- /**
- * Entities init function; establishes the page handler
- *
- */
+ }
+
+ /**
+ * Entities init function; establishes the page handler
+ *
+ */
function entities_init()
- {
- register_page_handler('view','entities_page_handler');
-
- // Allow a permission override for recursive entity deletion
- // TODO: Can this be done better?
+ {
+ register_page_handler('view','entities_page_handler');
+
+ // Allow a permission override for recursive entity deletion
+ // TODO: Can this be done better?
register_plugin_hook('permissions_check','all','recursive_delete_permissions_check');
register_plugin_hook('permissions_check:metadata','all','recursive_delete_permissions_check');
- register_plugin_hook('gc','system','entities_gc');
- }
-
- /** Register the import hook */
- register_plugin_hook("import", "all", "import_entity_plugin_hook", 0);
-
- /** Register the hook, ensuring entities are serialised first */
- register_plugin_hook("export", "all", "export_entity_plugin_hook", 0);
-
- /** Hook to get certain named bits of volatile data about an entity */
- register_plugin_hook('volatile', 'metadata', 'volatile_data_export_plugin_hook');
-
- /** Hook for rendering a default icon for entities */
- register_plugin_hook('entity:icon:url', 'all', 'default_entity_icon_hook', 1000);
-
- /** Register init system event **/
- register_elgg_event_handler('init','system','entities_init');
-
-?>
+ register_plugin_hook('gc','system','entities_gc');
+ }
+
+ /** Register the import hook */
+ register_plugin_hook("import", "all", "import_entity_plugin_hook", 0);
+
+ /** Register the hook, ensuring entities are serialised first */
+ register_plugin_hook("export", "all", "export_entity_plugin_hook", 0);
+
+ /** Hook to get certain named bits of volatile data about an entity */
+ register_plugin_hook('volatile', 'metadata', 'volatile_data_export_plugin_hook');
+
+ /** Hook for rendering a default icon for entities */
+ register_plugin_hook('entity:icon:url', 'all', 'default_entity_icon_hook', 1000);
+
+ /** Register init system event **/
+ register_elgg_event_handler('init','system','entities_init');
+
+?>
diff --git a/engine/lib/extender.php b/engine/lib/extender.php
index a298671f3..f3f3753bc 100644
--- a/engine/lib/extender.php
+++ b/engine/lib/extender.php
@@ -66,7 +66,7 @@
*/
protected function set($name, $value, $value_type = "") {
- $this->attributes[$name] = $value;
+ $this->attributes[$name] = $value;
if ($name == 'value')
$this->attributes['value_type'] = detect_extender_valuetype($value, $value_type);
@@ -82,15 +82,15 @@
{
return get_user($this->owner_guid);
}
-
- /**
- * Returns the entity this is attached to
- *
- * @return ElggEntity The enttiy
- */
- public function getEntity() {
- return get_entity($this->entity_guid);
- }
+
+ /**
+ * Returns the entity this is attached to
+ *
+ * @return ElggEntity The enttiy
+ */
+ public function getEntity() {
+ return get_entity($this->entity_guid);
+ }
/**
* Save this data to the appropriate database table.
@@ -101,15 +101,15 @@
* Delete this data.
*/
abstract public function delete();
-
- /**
- * Determines whether or not the specified user can edit this
- *
- * @param int $user_guid The GUID of the user (defaults to currently logged in user)
- * @return true|false
- */
- public function canEdit($user_guid = 0) {
- return can_edit_extender($this->id,$this->type,$user_guid);
+
+ /**
+ * Determines whether or not the specified user can edit this
+ *
+ * @param int $user_guid The GUID of the user (defaults to currently logged in user)
+ * @return true|false
+ */
+ public function canEdit($user_guid = 0) {
+ return can_edit_extender($this->id,$this->type,$user_guid);
}
/**
@@ -333,40 +333,40 @@
return true;
}
}
-
- /**
- * Determines whether or not the specified user can edit the specified piece of extender
- *
- * @param int $extender_id The ID of the piece of extender
- * @param string $type 'metadata' or 'annotation'
- * @param int $user_guid The GUID of the user
- * @return true|false
- */
+
+ /**
+ * Determines whether or not the specified user can edit the specified piece of extender
+ *
+ * @param int $extender_id The ID of the piece of extender
+ * @param string $type 'metadata' or 'annotation'
+ * @param int $user_guid The GUID of the user
+ * @return true|false
+ */
function can_edit_extender($extender_id, $type, $user_guid = 0) {
-
- if (!isloggedin())
- return false;
+
+ if (!isloggedin())
+ return false;
$user_guid = (int)$user_guid;
$user = get_entity($user_guid);
- if (!$user) $user = get_loggedin_user();
-
- $functionname = "get_{$type}";
- if (is_callable($functionname)) {
- $extender = $functionname($extender_id);
- } else return false;
-
- if (!is_a($extender,"ElggExtender")) return false;
-
- // If the owner is the specified user, great! They can edit.
- if ($extender->getOwner() == $user->getGUID()) return true;
-
- // If the user can edit the entity this is attached to, great! They can edit.
- if (can_edit_entity($extender->entity_guid,$user->getGUID())) return true;
-
- // Trigger plugin hooks
- return trigger_plugin_hook('permissions_check',$type,array('entity' => $entity, 'user' => $user),false);
-
+ if (!$user) $user = get_loggedin_user();
+
+ $functionname = "get_{$type}";
+ if (is_callable($functionname)) {
+ $extender = $functionname($extender_id);
+ } else return false;
+
+ if (!is_a($extender,"ElggExtender")) return false;
+
+ // If the owner is the specified user, great! They can edit.
+ if ($extender->getOwner() == $user->getGUID()) return true;
+
+ // If the user can edit the entity this is attached to, great! They can edit.
+ if (can_edit_entity($extender->entity_guid,$user->getGUID())) return true;
+
+ // Trigger plugin hooks
+ return trigger_plugin_hook('permissions_check',$type,array('entity' => $entity, 'user' => $user),false);
+
}
/**
@@ -432,7 +432,7 @@
$url = $CONFIG->wwwroot . "export/$view/$guid/$type/$nameid/";
}
return $url;
- }
+ }
/** Register the hook */
register_plugin_hook("import", "all", "import_extender_plugin_hook", 2);
diff --git a/engine/lib/input.php b/engine/lib/input.php
index 338df2a08..71abbb330 100644
--- a/engine/lib/input.php
+++ b/engine/lib/input.php
@@ -1,66 +1,66 @@
-
- * @author Curverider Ltd
+ * @link http://elgg.org/
+ */
- * @link http://elgg.org/
- */
-
- /**
- * Get some input from variables passed on the GET or POST line.
- *
- * @param $variable string The variable we want to return.
+ /**
+ * Get some input from variables passed on the GET or POST line.
+ *
+ * @param $variable string The variable we want to return.
* @param $default mixed A default value for the variable if it is not found.
- * @param $filter_result If true then the result is filtered for bad tags.
- */
- function get_input($variable, $default = "", $filter_result = true)
- {
-
- global $CONFIG;
-
- if (isset($CONFIG->input[$variable])) {
+ * @param $filter_result If true then the result is filtered for bad tags.
+ */
+ function get_input($variable, $default = "", $filter_result = true)
+ {
+
+ global $CONFIG;
+
+ if (isset($CONFIG->input[$variable])) {
$var = $CONFIG->input[$variable];
if ($filter_result)
$var = filter_tags($var);
return $var;
- }
-
+ }
+
if (isset($_REQUEST[$variable])) {
-
+
if (is_array($_REQUEST[$variable])) {
$var = $_REQUEST[$variable];
} else {
- $var = trim($_REQUEST[$variable]);
- }
+ $var = trim($_REQUEST[$variable]);
+ }
if ($filter_result)
- $var = filter_tags($var);
-
- return $var;
-
- }
-
- return $default;
-
- }
-
- /**
- * Sets an input value that may later be retrieved by get_input
- *
- * @param string $variable The name of the variable
- * @param string $value The value of the variable
- */
- function set_input($variable, $value) {
-
- global $CONFIG;
- if (!isset($CONFIG->input))
+ $var = filter_tags($var);
+
+ return $var;
+
+ }
+
+ return $default;
+
+ }
+
+ /**
+ * Sets an input value that may later be retrieved by get_input
+ *
+ * @param string $variable The name of the variable
+ * @param string $value The value of the variable
+ */
+ function set_input($variable, $value) {
+
+ global $CONFIG;
+ if (!isset($CONFIG->input))
$CONFIG->input = array();
if (is_array($value))
@@ -70,19 +70,19 @@
$CONFIG->input[trim($variable)] = $value;
}
- else
- $CONFIG->input[trim($variable)] = trim($value);
-
- }
-
- /**
- * Filter tags from a given string based on registered hooks.
- * @param $var
- * @return mixed The filtered result
- */
- function filter_tags($var)
- {
- return trigger_plugin_hook('validate', 'input', null, $var);
+ else
+ $CONFIG->input[trim($variable)] = trim($value);
+
+ }
+
+ /**
+ * Filter tags from a given string based on registered hooks.
+ * @param $var
+ * @return mixed The filtered result
+ */
+ function filter_tags($var)
+ {
+ return trigger_plugin_hook('validate', 'input', null, $var);
}
/**
@@ -102,15 +102,15 @@
$path = $path . "/";
return $path;
- }
+ }
+
-
- /**
- * Takes a string and turns any URLs into formatted links
- *
- * @param string $text The input string
- * @return string The output stirng with formatted links
- **/
+ /**
+ * Takes a string and turns any URLs into formatted links
+ *
+ * @param string $text The input string
+ * @return string The output stirng with formatted links
+ **/
function parse_urls($text) {
return preg_replace_callback('/(?"\'\!\(\)]+)/i',
@@ -121,110 +121,110 @@
$urltext = str_replace("/", "/", $url);
return "$urltext";
'
- ), $text);
- }
-
- function autop($pee, $br = 1) {
- $pee = $pee . "\n"; // just to make things a little easier, pad the end
- $pee = preg_replace('|
\s*
|', "\n\n", $pee);
- // Space things out a little
- $allblocks = '(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|map|area|blockquote|address|math|style|input|p|h[1-6]|hr)';
- $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee);
- $pee = preg_replace('!(' . $allblocks . '>)!', "$1\n\n", $pee);
- $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines
- if ( strpos($pee, '
', '', $pee);
- $pee = preg_replace('!\s*(?' . $allblocks . '[^>]*>)!', "$1", $pee);
- $pee = preg_replace('!(?' . $allblocks . '[^>]*>)\s*
!', "$1", $pee);
- if ($br) {
- $pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', create_function('$matches', 'return str_replace("\n", "", $matches[0]);'), $pee);
- $pee = preg_replace('|(?)\s*\n|', "
\n", $pee); // optionally make line breaks
- $pee = str_replace('', "\n", $pee);
- }
- $pee = preg_replace('!(?' . $allblocks . '[^>]*>)\s*
!', "$1", $pee);
- $pee = preg_replace('!
(\s*?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
- if (strpos($pee, ')(.*?)
!is', 'clean_pre', $pee );
- $pee = preg_replace( "|\n$|", '', $pee );
-
- return $pee;
- }
-
- function input_init() {
-
- if (ini_get_bool('magic_quotes_gpc') ) {
-
- //do keys as well, cos array_map ignores them
- function stripslashes_arraykeys($array) {
- if (is_array($array)) {
- $array2 = array();
- foreach ($array as $key => $data) {
- if ($key != stripslashes($key)) {
- $array2[stripslashes($key)] = $data;
- } else {
- $array2[$key] = $data;
- }
- }
- return $array2;
- } else {
- return $array;
- }
- }
-
- function stripslashes_deep($value) {
- if (is_array($value)) {
- $value = stripslashes_arraykeys($value);
- $value = array_map('stripslashes_deep', $value);
- } else {
- $value = stripslashes($value);
- }
- return $value;
- }
-
- $_POST = stripslashes_arraykeys($_POST);
- $_GET = stripslashes_arraykeys($_GET);
- $_COOKIE = stripslashes_arraykeys($_COOKIE);
- $_REQUEST = stripslashes_arraykeys($_REQUEST);
-
- $_POST = array_map('stripslashes_deep', $_POST);
- $_GET = array_map('stripslashes_deep', $_GET);
- $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
- $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
- if (!empty($_SERVER['REQUEST_URI'])) {
- $_SERVER['REQUEST_URI'] = stripslashes($_SERVER['REQUEST_URI']);
- }
- if (!empty($_SERVER['QUERY_STRING'])) {
- $_SERVER['QUERY_STRING'] = stripslashes($_SERVER['QUERY_STRING']);
- }
- if (!empty($_SERVER['HTTP_REFERER'])) {
- $_SERVER['HTTP_REFERER'] = stripslashes($_SERVER['HTTP_REFERER']);
- }
- if (!empty($_SERVER['PATH_INFO'])) {
- $_SERVER['PATH_INFO'] = stripslashes($_SERVER['PATH_INFO']);
- }
- if (!empty($_SERVER['PHP_SELF'])) {
- $_SERVER['PHP_SELF'] = stripslashes($_SERVER['PHP_SELF']);
- }
- if (!empty($_SERVER['PATH_TRANSLATED'])) {
- $_SERVER['PATH_TRANSLATED'] = stripslashes($_SERVER['PATH_TRANSLATED']);
- }
-
+ ), $text);
+ }
+
+ function autop($pee, $br = 1) {
+ $pee = $pee . "\n"; // just to make things a little easier, pad the end
+ $pee = preg_replace('|
\s*
|', "\n\n", $pee);
+ // Space things out a little
+ $allblocks = '(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|map|area|blockquote|address|math|style|input|p|h[1-6]|hr)';
+ $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee);
+ $pee = preg_replace('!(' . $allblocks . '>)!', "$1\n\n", $pee);
+ $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines
+ if ( strpos($pee, '