aboutsummaryrefslogtreecommitdiff
path: root/views/default
diff options
context:
space:
mode:
authorSem <sembrestels@riseup.net>2012-01-06 16:07:45 +0100
committerSem <sembrestels@riseup.net>2012-01-06 16:07:45 +0100
commit479e5b1bb819967665bb1933d268e16c16c69b70 (patch)
tree4e2a98cf72dfd72109f18263991d61cf407852c4 /views/default
parent9895df4280a7be9465fe148a356327edf370f6fa (diff)
downloadelgg-479e5b1bb819967665bb1933d268e16c16c69b70.tar.gz
elgg-479e5b1bb819967665bb1933d268e16c16c69b70.tar.bz2
Refactored javascripts. Added elgg.get_friendly_time() function.
Diffstat (limited to 'views/default')
-rw-r--r--views/default/identica/identi.ca.js.php76
-rw-r--r--views/default/identica/js.php40
-rw-r--r--views/default/js/friendly_time.php50
-rw-r--r--views/default/widgets/identica/content.php9
4 files changed, 93 insertions, 82 deletions
diff --git a/views/default/identica/identi.ca.js.php b/views/default/identica/identi.ca.js.php
deleted file mode 100644
index 1d782d040..000000000
--- a/views/default/identica/identi.ca.js.php
+++ /dev/null
@@ -1,76 +0,0 @@
- /**
- * Elgg identica JS
- *
- * @package ElggIdentica
- * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
- * @author Simon Leblanc <contact@leblanc-simon.eu>
- * @copyright Simon Leblanc 2009
- * @link http://elgg.com/
- */
-<?php
-$id = $_GET['id'];
-?>
-var identica_less_60 = 'less than a minute ago';
-var identica_minute = 'about a minute ago';
-var identica_more_minute_first = '';
-var identica_more_minute = ' minutes ago';
-var identica_hour = 'about an hour ago';
-var identica_more_hour_first = 'about ';
-var identica_more_hour = ' hours ago';
-var identica_day = '1 day ago';
-var identica_more_day_first = '';
-var identica_more_day = ' days ago';
-
-/**
- * Parse the JSON result for show this in HTML
- *
- * @param JSON string the JSON result of the identi.ca's call
- */
-function identicaCallback(identicas) {
- var statusHTML = [];
- for (var i=0; i<identicas.length; i++){
- var username = identicas[i].user.screen_name;
- var status = identicas[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
- return '<a href="'+url+'">'+url+'</a>';
- }).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
- return reply.charAt(0)+'<a href="http://identi.ca/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
- }).replace(/\B#([-_a-z0-9]+)/ig, function(tag) {
- return tag.charAt(0)+'<a href="http://identi.ca/tag/'+tag.substring(1).replace(/[^a-z0-9]+/ig, '')+'">'+tag.substring(1)+'</a>';
- }).replace(/\B!([_a-z0-9]+)/ig, function(group) {
- return group.charAt(0)+'<a href="http://identi.ca/group/'+group.substring(1)+'">'+group.substring(1)+'</a>';
- });
- statusHTML.push('<li><span>'+status+'</span> <a style="font-size:85%" href="http://identi.ca/notice/'+identicas[i].id+'">'+relative_time(identicas[i].created_at)+'</a></li>');
- }
- document.getElementById('identica_update_list').innerHTML = statusHTML.join('');
-}
-
-/**
- * Modified the time in human readable
- *
- * @param string time_value The time in RFC format
- * @return string The time in human readable format
- */
-function relative_time(time_value) {
- var values = time_value.split(" ");
- time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
- var parsed_date = Date.parse(time_value);
- var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
- var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
- delta = delta + (relative_to.getTimezoneOffset() * 60);
-
- if (delta < 60) {
- return identica_less_60;
- } else if(delta < 120) {
- return identica_minute;
- } else if(delta < (60*60)) {
- return identica_more_minute_first + (parseInt(delta / 60)).toString() + identica_more_minute;
- } else if(delta < (120*60)) {
- return identica_hour;
- } else if(delta < (24*60*60)) {
- return identica_more_hour_first + (parseInt(delta / 3600)).toString() + identica_more_hour;
- } else if(delta < (48*60*60)) {
- return identica_day;
- } else {
- return identica_more_day_first + (parseInt(delta / 86400)).toString() + identica_more_day;
- }
-}
diff --git a/views/default/identica/js.php b/views/default/identica/js.php
new file mode 100644
index 000000000..1dd560836
--- /dev/null
+++ b/views/default/identica/js.php
@@ -0,0 +1,40 @@
+/**
+ * Elgg identi.ca widget
+ * This plugin allows users to pull in their identi.ca feed to display on their profile
+ *
+ * @package ElggIdentica
+ */
+
+elgg.identica = {};
+
+/**
+ * Parse the JSON result for show this in HTML
+ *
+ * @param JSON string the JSON result of the identi.ca's call
+ */
+elgg.identica.callback = function(identicas) {
+ var statusHTML = [];
+ for (var i=0; i<identicas.length; i++){
+ var username = identicas[i].user.screen_name;
+ var status = identicas[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
+ return '<a href="'+url+'">'+url+'</a>';
+ }).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
+ return reply.charAt(0)+'<a href="http://identi.ca/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
+ }).replace(/\B#([-_a-z0-9]+)/ig, function(tag) {
+ return tag.charAt(0)+'<a href="http://identi.ca/tag/'+tag.substring(1).replace(/[^a-z0-9]+/ig, '')+'">'+tag.substring(1)+'</a>';
+ }).replace(/\B!([_a-z0-9]+)/ig, function(group) {
+ return group.charAt(0)+'<a href="http://identi.ca/group/'+group.substring(1)+'">'+group.substring(1)+'</a>';
+ });
+ statusHTML.push('<li><span>'+status+'</span> <a style="font-size:85%" href="http://identi.ca/notice/'+identicas[i].id+'">'+elgg.get_friendly_time(identicas[i].created_at)+'</a></li>');
+ }
+ document.getElementById('identica_update_list').innerHTML = statusHTML.join('');
+}
+
+elgg.identica.init = function() {
+ username = $('#identica_update_list').data('username');
+ num = $('#identica_update_list').data('num');
+ js = "https://identi.ca/api/statuses/user_timeline/"+username+".json?callback=elgg.identica.callback&count="+num;
+ $.getScript(js);
+};
+
+elgg.register_hook_handler('init', 'system', elgg.identica.init);
diff --git a/views/default/js/friendly_time.php b/views/default/js/friendly_time.php
new file mode 100644
index 000000000..0b0275206
--- /dev/null
+++ b/views/default/js/friendly_time.php
@@ -0,0 +1,50 @@
+elgg.get_friendly_time = function(time) {
+
+ if (!time) {
+ time = new Date();
+ } else {
+ time = new Date(time);
+ }
+ diff = (new Date().getTime() - time.getTime()) / 1000;
+
+ minute = 60;
+ hour = minute * 60;
+ day = hour * 24;
+
+ if (diff < minute) {
+ return elgg.echo("friendlytime:justnow");
+ } else if (diff < hour) {
+ diff = Math.round(diff / minute);
+ if (diff == 0) {
+ diff = 1;
+ }
+
+ if (diff > 1) {
+ return elgg.echo("friendlytime:minutes", [diff]);
+ } else {
+ return elgg.echo("friendlytime:minutes:singular", [diff]);
+ }
+ } else if (diff < day) {
+ diff = Math.round(diff / hour);
+ if (diff == 0) {
+ diff = 1;
+ }
+
+ if (diff > 1) {
+ return elgg.echo("friendlytime:hours", [diff]);
+ } else {
+ return elgg.echo("friendlytime:hours:singular", [diff]);
+ }
+ } else {
+ diff = Math.round(diff / day);
+ if (diff == 0) {
+ diff = 1;
+ }
+
+ if (diff > 1) {
+ return elgg.echo("friendlytime:days", [diff]);
+ } else {
+ return elgg.echo("friendlytime:days:singular", [diff]);
+ }
+ }
+};
diff --git a/views/default/widgets/identica/content.php b/views/default/widgets/identica/content.php
index 9209e01a6..42cbd1853 100644
--- a/views/default/widgets/identica/content.php
+++ b/views/default/widgets/identica/content.php
@@ -10,19 +10,16 @@
$username = $vars['entity']->identica_username;
$num = $vars['entity']->identica_num;
-$id = md5($vars['entity']->identica_username.rand(0, 99999));
// if the identi.ca username is empty, then do not show
if ($username) {
-
+ elgg_load_js('friendly_time');
+ elgg_load_js('identica');
?>
<div id="identica_widget">
- <ul id="identica_update_list"></ul>
+ <ul id="identica_update_list" data-username="<?php echo $username; ?>" data-num="<?php echo $num; ?>"></ul>
<p class="visit_identica"><a href="http://identi.ca/<?php echo $username; ?>"><?php echo elgg_echo("identica:visit"); ?></a></p>
- <script type="text/javascript" src="<?php echo $vars['url']; ?>mod/identica/views/default/identica/identi.ca.js.php?id=<?php echo $id ?>"></script>
-
- <script type="text/javascript" src="https://identi.ca/api/statuses/user_timeline/<?php echo $username; ?>.json?callback=identicaCallback&count=<?php echo $num; ?>"></script>
</div>
<?php