aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-11-01 22:11:20 +0000
committerewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-11-01 22:11:20 +0000
commit4a2721032e5adb4ad2460befd9af77be4996d2a0 (patch)
treec635a38df6406055a1a0d111bdc02d4dcb41b71b
parent7e4cc929919f05e5b31c6ff7d1ed9b8e53e8a95a (diff)
downloadelgg-4a2721032e5adb4ad2460befd9af77be4996d2a0.tar.gz
elgg-4a2721032e5adb4ad2460befd9af77be4996d2a0.tar.bz2
Refs #2538: Added some models, inheritance, more bootstrapping code
git-svn-id: http://code.elgg.org/elgg/trunk@7183 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--actions/security/refreshtoken.php5
-rw-r--r--engine/js/classes/ElggEntity.js20
-rw-r--r--engine/js/classes/ElggUser.js12
-rw-r--r--engine/js/lib/elgglib.js29
-rw-r--r--engine/js/lib/languages.js4
-rw-r--r--engine/js/tests/ElggLibTest.js11
-rw-r--r--jsTestDriver.conf1
-rw-r--r--views/default/js/initialise_elgg.php93
-rw-r--r--views/default/js/languages.php9
-rw-r--r--views/default/js/languages/en.php2
-rw-r--r--views/default/page_elements/html_begin.php2
-rw-r--r--views/default/page_elements/html_begin_admin.php2
-rw-r--r--views/default/scripts/initialize_elgg.php45
13 files changed, 165 insertions, 70 deletions
diff --git a/actions/security/refreshtoken.php b/actions/security/refreshtoken.php
new file mode 100644
index 000000000..74a72c4af
--- /dev/null
+++ b/actions/security/refreshtoken.php
@@ -0,0 +1,5 @@
+<?php
+$ts = time();
+$token = generate_action_token($ts);
+
+echo json_encode(array('__elgg_ts' => $ts, '__elgg_token' => $token)); \ No newline at end of file
diff --git a/engine/js/classes/ElggEntity.js b/engine/js/classes/ElggEntity.js
new file mode 100644
index 000000000..9461a463f
--- /dev/null
+++ b/engine/js/classes/ElggEntity.js
@@ -0,0 +1,20 @@
+/**
+ * Create a new ElggEntity
+ *
+ * @class Represents an ElggEntity
+ * @property {number} guid
+ * @property {string} type
+ * @property {string} subtype
+ * @property {number} owner_guid
+ * @property {number} site_guid
+ * @property {number} container_guid
+ * @property {number} access_id
+ * @property {number} time_created
+ * @property {number} time_updated
+ * @property {number} last_action
+ * @property {string} enabled
+ *
+ */
+elgg.ElggEntity = function(o) {
+ $.extend(this, o);
+}; \ No newline at end of file
diff --git a/engine/js/classes/ElggUser.js b/engine/js/classes/ElggUser.js
index dec7431de..8a7a8b7eb 100644
--- a/engine/js/classes/ElggUser.js
+++ b/engine/js/classes/ElggUser.js
@@ -8,15 +8,7 @@
* @property {string} username
*/
elgg.ElggUser = function(o) {
- //elgg.ElggEntity.call(this, o);
- this = o;
+ elgg.ElggEntity.call(this, o);
};
-//elgg.inherit(elgg.ElggUser, elgg.ElggEntity);
-
-/**
- * @return {boolean} Whether the user is an admin
- */
-elgg.ElggUser.prototype.isAdmin = function() {
- return this.admin === 'yes';
-}; \ No newline at end of file
+elgg.inherit(elgg.ElggUser, elgg.ElggEntity); \ No newline at end of file
diff --git a/engine/js/lib/elgglib.js b/engine/js/lib/elgglib.js
index 28cae8f8f..208c02716 100644
--- a/engine/js/lib/elgglib.js
+++ b/engine/js/lib/elgglib.js
@@ -92,7 +92,8 @@ elgg.provide = function(pkg) {
* @param {Function} parentCtor Parent class.
*/
elgg.inherit = function(Child, Parent) {
- Child.prototype = Parent;
+ Child.prototype = new Parent();
+ Child.prototype.constructor = Child;
};
/**
@@ -130,9 +131,9 @@ elgg.system_messages = function(msgs, delay, type) {
delay = 6000;
}
- var messages_class = 'messages';
+ classes = ['elgg_system_message', 'radius8'];
if (type == 'error') {
- messages_class = 'messages_error';
+ classes.push('messages_error');
}
//Handle non-arrays
@@ -140,16 +141,20 @@ elgg.system_messages = function(msgs, delay, type) {
msgs = [msgs];
}
- var messages_html = '<div class="' + messages_class + '">'
- + '<span class="closeMessages">'
- + '<a href="#">'
- + elgg.echo('systemmessages:dismiss')
- + '</a>'
- + '</span>'
- + '<p>' + msgs.join('</p><p>') + '</p>'
- + '</div>';
+ var messages_html = [];
- $(messages_html).appendTo('#elgg_system_messages').show().animate({opacity:'1.0'},delay).fadeOut('slow');
+ for (var i in msgs) {
+ messages_html.push('<div class="' + classes.join(' ') + '">'
+ + '<span class="closeMessages">'
+ + '<a href="#">'
+ + elgg.echo('systemmessages:dismiss')
+ + '</a>'
+ + '</span>'
+ + '<p>' + msgs[i] + '</p>'
+ + '</div>');
+ }
+
+ $(messages_html.join('')).appendTo('#elgg_system_messages').animate({opacity:'1.0'},delay).fadeOut('slow');
};
/**
diff --git a/engine/js/lib/languages.js b/engine/js/lib/languages.js
index 7bae74e6b..6ac83f350 100644
--- a/engine/js/lib/languages.js
+++ b/engine/js/lib/languages.js
@@ -12,9 +12,7 @@ elgg.config.translations.init = function() {
elgg.add_translation = function(lang, translations) {
elgg.provide('elgg.config.translations.' + lang);
- var t = elgg.config.translations;
-
- t[lang] = $.extend(t[lang], translations);
+ $.extend(elgg.config.translations[lang], translations);
}
/**
diff --git a/engine/js/tests/ElggLibTest.js b/engine/js/tests/ElggLibTest.js
index d5474c605..920296408 100644
--- a/engine/js/tests/ElggLibTest.js
+++ b/engine/js/tests/ElggLibTest.js
@@ -33,6 +33,17 @@ ElggLibTest.prototype.testRequire = function() {
assertNoException(function(){ elgg.require('elgg.security'); });
};
+ElggLibTest.prototype.testInherit = function() {
+ function Base() {}
+ function Child() {}
+
+ elgg.inherit(Child, Base);
+
+
+ assertInstanceOf(Base, new Child());
+ assertEquals(Child, Child.prototype.constructor);
+};
+
ElggLibTest.prototype.testExtendUrl = function() {
var url;
elgg.config.wwwroot = "http://www.elgg.org/";
diff --git a/jsTestDriver.conf b/jsTestDriver.conf
index 347627dab..fc1fe0b8b 100644
--- a/jsTestDriver.conf
+++ b/jsTestDriver.conf
@@ -3,5 +3,6 @@ server: http://localhost:42442
load:
- vendors/jquery/jquery-1.4.2.min.js
- engine/js/lib/elgglib.js
+ - engine/js/classes/*.js
- engine/js/lib/*.js
- engine/js/tests/*.js \ No newline at end of file
diff --git a/views/default/js/initialise_elgg.php b/views/default/js/initialise_elgg.php
index 6b7a318e7..b6c3f7ecd 100644
--- a/views/default/js/initialise_elgg.php
+++ b/views/default/js/initialise_elgg.php
@@ -1,3 +1,50 @@
+<?php
+/**
+ * Bootstrap Elgg javascript
+ */
+global $CONFIG;
+
+//Include library files
+$lib_files = array(
+ //core
+ 'elgglib',
+
+ //libraries
+ 'security',
+ 'languages',
+ 'ajax',
+ 'session',
+
+ //ui
+ 'ui',
+ 'ui.widgets',
+);
+
+foreach($lib_files as $file) {
+ include("{$CONFIG->path}engine/js/lib/$file.js");
+}
+
+//Include classes
+$model_files = array(
+ 'ElggEntity',
+
+ 'ElggUser',
+);
+
+foreach($model_files as $file) {
+ include("{$CONFIG->path}engine/js/classes/$file.js");
+}
+
+/**
+ * Finally, set some values that are cacheable
+ */
+?>
+
+elgg.version = '<?php echo get_version(); ?>';
+elgg.release = '<?php echo get_version(true); ?>';
+elgg.config.wwwroot = '<?php echo elgg_get_site_url(); ?>';
+elgg.security.interval = 5 * 60 * 1000; <?php //TODO make this configurable ?>
+
$(document).ready(function () {
// COLLAPSABLE WIDGETS (on Dashboard? & Profile pages)
@@ -79,6 +126,8 @@ $(document).ready(function () {
$(this).next(".likes_list").animate({opacity: "toggle", top: topPosition}, 500);
}
});
+
+ elgg_system_message();
}); /* end document ready function */
@@ -196,50 +245,6 @@ function widget_moreinfo() {
});
};
-// COOKIES
-jQuery.cookie = function(name, value, options) {
- if (typeof value != 'undefined') { // name and value given, set cookie
- options = options || {};
- if (value === null) {
- value = '';
- options.expires = -1;
- }
- var expires = '';
- if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
- var date;
- if (typeof options.expires == 'number') {
- date = new Date();
- date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
- } else {
- date = options.expires;
- }
- expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
- }
- // CAUTION: Needed to parenthesize options.path and options.domain
- // in the following expressions, otherwise they evaluate to undefined
- // in the packed version for some reason.
- var path = options.path ? '; path=' + (options.path) : '';
- var domain = options.domain ? '; domain=' + (options.domain) : '';
- var secure = options.secure ? '; secure' : '';
- document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
-
- } else { // only name given, get cookie
- var cookieValue = null;
- if (document.cookie && document.cookie != '') {
- var cookies = document.cookie.split(';');
- for (var i = 0; i < cookies.length; i++) {
- var cookie = jQuery.trim(cookies[i]);
- // Does this cookie string begin with the name we want?
- if (cookie.substring(0, name.length + 1) == (name + '=')) {
- cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
- break;
- }
- }
- }
- return cookieValue;
- }
-};
-
// ELGG DROP DOWN MENU
$.fn.elgg_dropdownmenu = function(options) {
diff --git a/views/default/js/languages.php b/views/default/js/languages.php
new file mode 100644
index 000000000..34367aaf1
--- /dev/null
+++ b/views/default/js/languages.php
@@ -0,0 +1,9 @@
+<?php
+/**
+ * @uses $vars['language']
+ */
+global $CONFIG;
+
+$language = $vars['language'];
+
+echo json_encode($CONFIG->translations[$language]); \ No newline at end of file
diff --git a/views/default/js/languages/en.php b/views/default/js/languages/en.php
new file mode 100644
index 000000000..afcf4bb7f
--- /dev/null
+++ b/views/default/js/languages/en.php
@@ -0,0 +1,2 @@
+<?php
+echo elgg_view('js/languages', array('language' => 'en')); \ No newline at end of file
diff --git a/views/default/page_elements/html_begin.php b/views/default/page_elements/html_begin.php
index 37a9999f0..9b4e79268 100644
--- a/views/default/page_elements/html_begin.php
+++ b/views/default/page_elements/html_begin.php
@@ -56,8 +56,8 @@ $release = get_version(true);
<script type="text/javascript" src="<?php echo elgg_get_site_url(); ?>_css/js.php?lastcache=<?php echo $vars['config']->lastcache; ?>&amp;js=initialise_elgg&amp;viewtype=<?php echo $vars['view']; ?>"></script>
<?php
+ echo elgg_view('scripts/initialize_elgg');
echo $feedref;
-
?>
<?php
diff --git a/views/default/page_elements/html_begin_admin.php b/views/default/page_elements/html_begin_admin.php
index 34a70b60e..fcb61c25c 100644
--- a/views/default/page_elements/html_begin_admin.php
+++ b/views/default/page_elements/html_begin_admin.php
@@ -25,7 +25,9 @@ $release = get_version(true);
<script type="text/javascript" src="<?php echo elgg_get_site_url(); ?>_css/js.php?lastcache=<?php echo $vars['config']->lastcache; ?>&amp;js=initialise_elgg&amp;viewtype=<?php echo $vars['view']; ?>"></script>
<?php
+ echo elgg_view('scripts/initialize_elgg');
echo $feedref;
+
if (elgg_view_exists('metatags')) {
echo elgg_view('metatags', $vars);
}
diff --git a/views/default/scripts/initialize_elgg.php b/views/default/scripts/initialize_elgg.php
new file mode 100644
index 000000000..03d5adc5a
--- /dev/null
+++ b/views/default/scripts/initialize_elgg.php
@@ -0,0 +1,45 @@
+<?php
+/**
+ *
+ */
+
+?>
+<script type="text/javascript">
+/**
+ * Don't want to cache these -- they could change for every request
+ */
+elgg.config.lastcache = <?php echo (int)($vars['config']->lastcache); ?>;
+
+elgg.security.token.__elgg_ts = <?php echo $ts = time(); ?>;
+elgg.security.token.__elgg_token = '<?php echo generate_action_token($ts); ?>';
+
+<?php
+$page_owner = elgg_get_page_owner();
+
+if ($page_owner instanceof ElggEntity) {
+ $page_owner_json = array();
+ foreach ($page_owner->getExportableValues() as $v) {
+ $page_owner_json[$v] = $page_owner->$v;
+ }
+
+ $page_owner_json['subtype'] = $page_owner->getSubtype();
+ $page_owner_json['url'] = $page_owner->getURL();
+
+ echo 'elgg.page_owner = '.json_encode($page_owner_json).';';
+}
+
+$user = get_loggedin_user();
+
+if ($user instanceof ElggUser) {
+ $user_json = array();
+ foreach ($user->getExportableValues() as $v) {
+ $user_json[$v] = $user->$v;
+ }
+
+ $user_json['subtype'] = $user->getSubtype();
+ $user_json['url'] = $user->getURL();
+
+ echo 'elgg.session.user = new elgg.ElggUser('.json_encode($user_json).');';
+}
+?>;
+</script> \ No newline at end of file