From e6cbe3a26938ca8d88d44bacc6c40ba09f5f1fd1 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 23 Sep 2009 11:07:22 -0400 Subject: [PATCH 01/18] Revert "Added a check for any URL param. If found, strips them out before" This reverts commit 13de845e95da9ea579516c4480789819c9a26edd. --- plugins/Meteor/meteorupdater.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/plugins/Meteor/meteorupdater.js b/plugins/Meteor/meteorupdater.js index 91d12cde9c..a7c87330c9 100644 --- a/plugins/Meteor/meteorupdater.js +++ b/plugins/Meteor/meteorupdater.js @@ -11,17 +11,11 @@ var MeteorUpdater = function() Meteor.callbacks["process"] = function(data) { var d = JSON.parse(data); - var user_url = $('address .url')[0].href+d['user']['screen_name']; - - var wlh = window.location.href; - - if (wlh.indexOf('?') > 0) { - wlh = wlh.slice(0, wlh.indexOf('?')) - } + $user_url = $('address .url')[0].href+d['user']['screen_name']; if (timeline == 'public' || - user_url+'/all' == wlh || - user_url == wlh) { + $user_url+'/all' == window.location.href || + $user_url == window.location.href) { RealtimeUpdate.receive(d); } From 87ff03890e6512bf4cf336c5583382e22bb75414 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 23 Sep 2009 11:07:56 -0400 Subject: [PATCH 02/18] Revert "Made it slighly more compact with less jQuery selection" This reverts commit c9bc3900909a85b9b4be31c4dac7f809127a8bf0. --- plugins/Meteor/meteorupdater.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/Meteor/meteorupdater.js b/plugins/Meteor/meteorupdater.js index a7c87330c9..82594d91c7 100644 --- a/plugins/Meteor/meteorupdater.js +++ b/plugins/Meteor/meteorupdater.js @@ -8,15 +8,15 @@ var MeteorUpdater = function() init: function(server, port, timeline) { + var screen_name; + Meteor.callbacks["process"] = function(data) { var d = JSON.parse(data); - - $user_url = $('address .url')[0].href+d['user']['screen_name']; + screen_name = d['user']['screen_name']; if (timeline == 'public' || - $user_url+'/all' == window.location.href || - $user_url == window.location.href) { - + $('address .url')[0].href+screen_name+'/all' == window.location.href || + $('address .url')[0].href+screen_name == window.location.href) { RealtimeUpdate.receive(d); } }; From 35eb33fe2bd0d41fb4c03000c557c36125b2c809 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 23 Sep 2009 11:08:12 -0400 Subject: [PATCH 03/18] Revert "Fixed indenting" This reverts commit 182257cbbf1557c2671b1995c9126c45b0bd8e79. --- plugins/Meteor/meteorupdater.js | 38 ++++++++++++++++----------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/plugins/Meteor/meteorupdater.js b/plugins/Meteor/meteorupdater.js index 82594d91c7..de01d430a1 100644 --- a/plugins/Meteor/meteorupdater.js +++ b/plugins/Meteor/meteorupdater.js @@ -4,28 +4,28 @@ var MeteorUpdater = function() { - return { + return { - init: function(server, port, timeline) - { - var screen_name; + init: function(server, port, timeline) + { + var screen_name; - Meteor.callbacks["process"] = function(data) { - var d = JSON.parse(data); - screen_name = d['user']['screen_name']; + Meteor.callbacks["process"] = function(data) { + var d = JSON.parse(data); + screen_name = d['user']['screen_name']; - if (timeline == 'public' || - $('address .url')[0].href+screen_name+'/all' == window.location.href || - $('address .url')[0].href+screen_name == window.location.href) { - RealtimeUpdate.receive(d); - } - }; + if (timeline == 'public' || + $('address .url')[0].href+screen_name+'/all' == window.location.href || + $('address .url')[0].href+screen_name == window.location.href) { + RealtimeUpdate.receive(d); + } + }; - Meteor.host = server; - Meteor.port = port; - Meteor.joinChannel(timeline, 0); - Meteor.connect(); - } - } + Meteor.host = server; + Meteor.port = port; + Meteor.joinChannel(timeline, 0); + Meteor.connect(); + } + } }(); From 6cb2f89983f89fb7f4559fe607ca2af2c6729d27 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 23 Sep 2009 11:08:35 -0400 Subject: [PATCH 04/18] Revert "Added realtime streams for all and showstream timelines" This reverts commit 49e91ec7d068fa7b98576207696d2192418baf5b. --- plugins/Meteor/meteorupdater.js | 11 +--------- plugins/Realtime/RealtimePlugin.php | 34 +++++++++++++---------------- 2 files changed, 16 insertions(+), 29 deletions(-) diff --git a/plugins/Meteor/meteorupdater.js b/plugins/Meteor/meteorupdater.js index de01d430a1..9ce68775bf 100644 --- a/plugins/Meteor/meteorupdater.js +++ b/plugins/Meteor/meteorupdater.js @@ -8,17 +8,8 @@ var MeteorUpdater = function() init: function(server, port, timeline) { - var screen_name; - Meteor.callbacks["process"] = function(data) { - var d = JSON.parse(data); - screen_name = d['user']['screen_name']; - - if (timeline == 'public' || - $('address .url')[0].href+screen_name+'/all' == window.location.href || - $('address .url')[0].href+screen_name == window.location.href) { - RealtimeUpdate.receive(d); - } + RealtimeUpdate.receive(JSON.parse(data)); }; Meteor.host = server; diff --git a/plugins/Realtime/RealtimePlugin.php b/plugins/Realtime/RealtimePlugin.php index 611b1d86c9..4548822610 100644 --- a/plugins/Realtime/RealtimePlugin.php +++ b/plugins/Realtime/RealtimePlugin.php @@ -63,22 +63,20 @@ class RealtimePlugin extends Plugin { $path = null; - $a = $action->trimmed('action'); - - switch ($a) { - case 'public': case 'all': case 'replies': case 'showstream': - $path = array($a); - break; - case 'tag': - $tag = $action->trimmed('tag'); - if (!empty($tag)) { - $path = array('tag', $tag); - } else { - return true; - } - break; - default: + switch ($action->trimmed('action')) { + case 'public': + $path = array('public'); + break; + case 'tag': + $tag = $action->trimmed('tag'); + if (!empty($tag)) { + $path = array('tag', $tag); + } else { return true; + } + break; + default: + return true; } $timeline = $this->_pathToChannel($path); @@ -116,13 +114,11 @@ class RealtimePlugin extends Plugin { $paths = array(); - // TODO: Replies timeline + // XXX: Add other timelines; this is just for the public one if ($notice->is_local || ($notice->is_local == 0 && !common_config('public', 'localonly'))) { - foreach (array('public', 'all', 'replies', 'showstream') as $a) { - $paths[] = array($a); - } + $paths[] = array('public'); } $tags = $this->getNoticeTags($notice); From 13976f5796f24725280f4ff33901349df4668f50 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Wed, 23 Sep 2009 17:22:51 +0000 Subject: [PATCH 05/18] JavaScript fixes for IE --- plugins/Realtime/realtimeupdate.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/Realtime/realtimeupdate.js b/plugins/Realtime/realtimeupdate.js index da2f9ed3aa..d034deef16 100644 --- a/plugins/Realtime/realtimeupdate.js +++ b/plugins/Realtime/realtimeupdate.js @@ -17,7 +17,7 @@ $(document).ready(function() { $('#realtime_timeline').click(function() { window.open($(this).parent('a').attr('href')+'?realtime=1', - $(this).parent('a').attr('title'), + $('body').attr('id'), 'toolbar=no,resizable=yes,scrollbars=yes,status=yes'); return false; @@ -25,8 +25,8 @@ $(document).ready(function() { } else { window.resizeTo(575, 640); - address = $('address'); - content = $('#content'); + var address = $('address'); + var content = $('#content'); $('body').html(address); $('address').hide(); $('body').append(content); From 1fe11eabb675fa876bdbcd5884231ffd6fa278ff Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 23 Sep 2009 17:07:20 -0400 Subject: [PATCH 06/18] Do realtime popup with PHP instead of Javascript Move the realtime detection code to PHP extension rather than JavaScript. --- plugins/Realtime/RealtimePlugin.php | 110 ++++++++++---- plugins/Realtime/realtimeupdate.js | 222 ++++++++++++---------------- 2 files changed, 177 insertions(+), 155 deletions(-) diff --git a/plugins/Realtime/RealtimePlugin.php b/plugins/Realtime/RealtimePlugin.php index 4548822610..22851a6c14 100644 --- a/plugins/Realtime/RealtimePlugin.php +++ b/plugins/Realtime/RealtimePlugin.php @@ -50,6 +50,11 @@ class RealtimePlugin extends Plugin protected $favorurl = null; protected $deleteurl = null; + /** + * When it's time to initialize the plugin, calculate and + * pass the URLs we need. + */ + function onInitializePlugin() { $this->replyurl = common_local_url('newnotice'); @@ -57,30 +62,20 @@ class RealtimePlugin extends Plugin // FIXME: need to find a better way to pass this pattern in $this->deleteurl = common_local_url('deletenotice', array('notice' => '0000000000')); + return true; } function onEndShowScripts($action) { - $path = null; + $timeline = $this->_getTimeline($action); - switch ($action->trimmed('action')) { - case 'public': - $path = array('public'); - break; - case 'tag': - $tag = $action->trimmed('tag'); - if (!empty($tag)) { - $path = array('tag', $tag); - } else { - return true; - } - break; - default: + // If there's not a timeline on this page, + // just return true + + if (empty($timeline)) { return true; } - $timeline = $this->_pathToChannel($path); - $scripts = $this->_getScripts(); foreach ($scripts as $script) { @@ -95,16 +90,14 @@ class RealtimePlugin extends Plugin $user_id = 0; } - $action->script('plugins/Realtime/jquery.getUrlParam.js'); - $action->elementStart('script', array('type' => 'text/javascript')); - $action->raw(' - - '); + + $script = ' $(document).ready(function() { '. + $this->_updateInitialize($timeline, $user_id). + '}); '; + + $action->raw($script); + $action->elementEnd('script'); return true; @@ -146,6 +139,47 @@ class RealtimePlugin extends Plugin return true; } + function onStartShowPageNotice($action) + { + $timeline = $this->_getTimeline($action); + if (!empty($timeline)) { + $base = $action->selfUrl(); + if (mb_strstr($url, '?')) { + $url = $base . '&realtime=1'; + } else { + $url = $base . '?realtime=1'; + } + $title = $action->title(); + $code = "window.open('$url', '$title', 'toolbar=no,resizable=yes,scrollbars=yes,status=yes,height=640,width=575');"; + $action->element('a', array('href' => $base, + 'onclick' => $code, + 'id' => 'realtime_timeline', + 'title' => _('Pop up')), + 'Pop up'); + + } + return true; + } + + function onStartShowBody($action) + { + $realtime = $action->boolean('realtime'); + if (!$realtime) { + return true; + } + + $action->elementStart('body', + (common_current_user()) ? array('id' => $action->trimmed('action'), + 'class' => 'user_in') + : array('id' => $action->trimmed('action'))); + if (common_logged_in()) { + $action->showNoticeForm(); + } + $action->showContent(); + $action->elementEnd('body'); + return false; // No default processing + } + function noticeAsJson($notice) { // FIXME: this code should be abstracted to a neutral third @@ -230,4 +264,30 @@ class RealtimePlugin extends Plugin { return ''; } + + function _getTimeline($action) + { + $path = null; + $timeline = null; + + switch ($action->trimmed('action')) { + case 'public': + $path = array('public'); + break; + case 'tag': + $tag = $action->trimmed('tag'); + if (!empty($tag)) { + $path = array('tag', $tag); + } + break; + default: + break; + } + + if (!is_null($path)) { + $timeline = $this->_pathToChannel($path); + } + + return $timeline; + } } diff --git a/plugins/Realtime/realtimeupdate.js b/plugins/Realtime/realtimeupdate.js index da2f9ed3aa..3293ef6e9f 100644 --- a/plugins/Realtime/realtimeupdate.js +++ b/plugins/Realtime/realtimeupdate.js @@ -1,152 +1,114 @@ -$(document).ready(function() { - if (!$(document).getUrlParam('realtime')) { - $('#site_nav_local_views .current a').append(''); +// add a notice encoded as JSON into the current timeline +// +// TODO: i18n - $('#realtime_timeline').css({ - 'margin':'2px 0 0 11px', - 'background':'transparent url('+$('address .url')[0].href+'/plugins/Realtime/icon_external.gif) no-repeat 45% 45%', - 'text-indent':'-9999px', - 'width':'16px', - 'height':'16px', - 'padding':'0', - 'display':'block', - 'float':'right', - 'border':'none', - 'cursor':'pointer' - }); +RealtimeUpdate = { + _userid: 0, + _replyurl: '', + _favorurl: '', + _deleteurl: '', - $('#realtime_timeline').click(function() { - window.open($(this).parent('a').attr('href')+'?realtime=1', - $(this).parent('a').attr('title'), - 'toolbar=no,resizable=yes,scrollbars=yes,status=yes'); + init: function(userid, replyurl, favorurl, deleteurl) + { + RealtimeUpdate._userid = userid; + RealtimeUpdate._replyurl = replyurl; + RealtimeUpdate._favorurl = favorurl; + RealtimeUpdate._deleteurl = deleteurl; + }, - return false; - }); - } - else { - window.resizeTo(575, 640); - address = $('address'); - content = $('#content'); - $('body').html(address); - $('address').hide(); - $('body').append(content); - $('#content').css({'width':'92%'}); - } + receive: function(data) + { + id = data.id; + // Don't add it if it already exists + // + if ($("#notice-"+id).length > 0) { + return; + } - // add a notice encoded as JSON into the current timeline - // - // TODO: i18n + var noticeItem = RealtimeUpdate.makeNoticeItem(data); + $("#notices_primary .notices").prepend(noticeItem, true); + $("#notices_primary .notice:first").css({display:"none"}); + $("#notices_primary .notice:first").fadeIn(1000); + NoticeReply(); + }, - RealtimeUpdate = { - _userid: 0, - _replyurl: '', - _favorurl: '', - _deleteurl: '', + makeNoticeItem: function(data) + { + user = data['user']; + html = data['html'].replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"'); + source = data['source'].replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"'); - init: function(userid, replyurl, favorurl, deleteurl) - { - RealtimeUpdate._userid = userid; - RealtimeUpdate._replyurl = replyurl; - RealtimeUpdate._favorurl = favorurl; - RealtimeUpdate._deleteurl = deleteurl; - }, - - receive: function(data) - { - id = data.id; - - // Don't add it if it already exists - - if ($("#notice-"+id).length > 0) { - return; - } - - var noticeItem = RealtimeUpdate.makeNoticeItem(data); - $("#notices_primary .notices").prepend(noticeItem, true); - $("#notices_primary .notice:first").css({display:"none"}); - $("#notices_primary .notice:first").fadeIn(1000); - NoticeReply(); - }, - - makeNoticeItem: function(data) - { - user = data['user']; - html = data['html'].replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"'); - source = data['source'].replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"'); - - ni = "
  • "+ - "
    "+ - ""+ - ""+ - "\""+user['screen_name']+"\"/"+ - ""+user['screen_name']+""+ - ""+ - ""+ - "

    "+html+"

    "+ - "
    "+ - "
    "+ - ""+ - "a few seconds ago"+ - " "+ - ""+ - "from "+ + ni = "
  • "+ + "
    "+ + ""+ + ""+ + "\""+user['screen_name']+"\"/"+ + ""+user['screen_name']+""+ + ""+ + ""+ + "

    "+html+"

    "+ + "
    "+ + "
    "+ + ""+ + "a few seconds ago"+ + " "+ + ""+ + "from "+ ""+source+""+ // may have a link - ""; - if (data['in_reply_to_status_id']) { - ni = ni+" in context"; - } + ""; + if (data['in_reply_to_status_id']) { + ni = ni+" in context"; + } - ni = ni+"
    "+ + ni = ni+""+ "
    "; - if (RealtimeUpdate._userid != 0) { - var input = $("form#form_notice fieldset input#token"); - var session_key = input.val(); - ni = ni+RealtimeUpdate.makeFavoriteForm(data['id'], session_key); - ni = ni+RealtimeUpdate.makeReplyLink(data['id'], data['user']['screen_name']); - if (RealtimeUpdate._userid == data['user']['id']) { + if (RealtimeUpdate._userid != 0) { + var input = $("form#form_notice fieldset input#token"); + var session_key = input.val(); + ni = ni+RealtimeUpdate.makeFavoriteForm(data['id'], session_key); + ni = ni+RealtimeUpdate.makeReplyLink(data['id'], data['user']['screen_name']); + if (RealtimeUpdate._userid == data['user']['id']) { ni = ni+RealtimeUpdate.makeDeleteLink(data['id']); - } - } + } + } - ni = ni+"
    "+ - "
  • "; - return ni; - }, + ni = ni+""+ + ""; + return ni; + }, - makeFavoriteForm: function(id, session_key) - { - var ff; + makeFavoriteForm: function(id, session_key) + { + var ff; - ff = "
    "+ + ff = ""+ "
    "+ - "Favor this notice"+ - ""+ - ""+ - ""+ + "Favor this notice"+ + ""+ + ""+ + ""+ "
    "+ - "
    "; - return ff; + ""; + return ff; + }, + + makeReplyLink: function(id, nickname) + { + var rl; + rl = "Reply "+id+""; + return rl; }, - makeReplyLink: function(id, nickname) - { - var rl; - rl = "Reply "+id+""; - return rl; - }, + makeDeleteLink: function(id) + { + var dl, delurl; + delurl = RealtimeUpdate._deleteurl.replace("0000000000", id); - makeDeleteLink: function(id) - { - var dl, delurl; - delurl = RealtimeUpdate._deleteurl.replace("0000000000", id); + dl = "Delete"; - dl = "Delete"; - - return dl; - } - } - -}); + return dl; + } +} From 5152d31d2a4199306d656480ca5ff8d0978d8984 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 23 Sep 2009 17:28:14 -0400 Subject: [PATCH 07/18] Add some more realtime feeds --- plugins/Realtime/RealtimePlugin.php | 67 +++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 3 deletions(-) diff --git a/plugins/Realtime/RealtimePlugin.php b/plugins/Realtime/RealtimePlugin.php index 22851a6c14..0f3e310714 100644 --- a/plugins/Realtime/RealtimePlugin.php +++ b/plugins/Realtime/RealtimePlugin.php @@ -107,13 +107,23 @@ class RealtimePlugin extends Plugin { $paths = array(); - // XXX: Add other timelines; this is just for the public one + // Add to the author's timeline + + $user = User::staticGet('id', $notice->profile_id); + + if (!empty($user)) { + $paths[] = array('showstream', $user->nickname); + } + + // Add to the public timeline if ($notice->is_local || ($notice->is_local == 0 && !common_config('public', 'localonly'))) { $paths[] = array('public'); } + // Add to the tags timeline + $tags = $this->getNoticeTags($notice); if (!empty($tags)) { @@ -122,6 +132,46 @@ class RealtimePlugin extends Plugin } } + // Add to inbox timelines + // XXX: do a join + + $inbox = new Notice_inbox(); + $inbox->notice_id = $notice->id; + + if ($inbox->find()) { + while ($inbox->fetch()) { + $user = User::staticGet('id', $inbox->user_id); + $paths[] = array('all', $user->nickname); + } + } + + // Add to the replies timeline + + $reply = new Reply(); + $reply->notice_id = $notice->id; + + if ($reply->find()) { + while ($reply->fetch()) { + $user = User::staticGet('id', $reply->profile_id); + if (!empty($user)) { + $paths[] = array('replies', $user->nickname); + } + } + } + + // Add to the group timeline + // XXX: join + + $gi = new Group_inbox(); + $gi->notice_id = $notice->id; + + if ($gi->find()) { + while ($gi->fetch()) { + $ug = User_group::staticGet('id', $gi->group_id); + $paths[] = array('showgroup', $ug->nickname); + } + } + if (count($paths) > 0) { $json = $this->noticeAsJson($notice); @@ -270,7 +320,9 @@ class RealtimePlugin extends Plugin $path = null; $timeline = null; - switch ($action->trimmed('action')) { + $action_name = $action->trimmed('action'); + + switch ($action_name) { case 'public': $path = array('public'); break; @@ -280,11 +332,20 @@ class RealtimePlugin extends Plugin $path = array('tag', $tag); } break; + case 'showstream': + case 'all': + case 'replies': + case 'showgroup': + $nickname = common_canonical_nickname($action->trimmed('nickname')); + if (!empty($nickname)) { + $path = array($action_name, $nickname); + } + break; default: break; } - if (!is_null($path)) { + if (!empty($path)) { $timeline = $this->_pathToChannel($path); } From 36e009349d68d8f34fc50d77c26e6e3307116b2c Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 23 Sep 2009 14:58:42 -0400 Subject: [PATCH 08/18] hack around address hack in util.js --- plugins/Realtime/RealtimePlugin.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugins/Realtime/RealtimePlugin.php b/plugins/Realtime/RealtimePlugin.php index 0f3e310714..c41c9ce4ac 100644 --- a/plugins/Realtime/RealtimePlugin.php +++ b/plugins/Realtime/RealtimePlugin.php @@ -222,6 +222,16 @@ class RealtimePlugin extends Plugin (common_current_user()) ? array('id' => $action->trimmed('action'), 'class' => 'user_in') : array('id' => $action->trimmed('action'))); + + // XXX hack to deal with JS that tries to get the + // root url from page output + + $action->elementStart('address'); + $action->element('a', array('class' => 'url', + 'href' => common_local_url('public')), + ''); + $action->elementEnd('address'); + if (common_logged_in()) { $action->showNoticeForm(); } From bdbc2cb8de370eef6d5d06412746f52797ea0458 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 23 Sep 2009 15:24:12 -0400 Subject: [PATCH 09/18] move some stuff around for realtime --- plugins/Realtime/RealtimePlugin.php | 32 +++++++++-------------------- plugins/Realtime/realtimeupdate.js | 5 +++++ 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/plugins/Realtime/RealtimePlugin.php b/plugins/Realtime/RealtimePlugin.php index c41c9ce4ac..fde3060216 100644 --- a/plugins/Realtime/RealtimePlugin.php +++ b/plugins/Realtime/RealtimePlugin.php @@ -76,6 +76,15 @@ class RealtimePlugin extends Plugin return true; } + $base = $action->selfUrl(); + if (mb_strstr($url, '?')) { + $url = $base . '&realtime=1'; + } else { + $url = $base . '?realtime=1'; + } + + $title = $action->title(); + $scripts = $this->_getScripts(); foreach ($scripts as $script) { @@ -94,6 +103,7 @@ class RealtimePlugin extends Plugin $script = ' $(document).ready(function() { '. $this->_updateInitialize($timeline, $user_id). + ' RealtimeUpdate.addPopup("'.$url.'", "'.$title.'"); '. '}); '; $action->raw($script); @@ -189,28 +199,6 @@ class RealtimePlugin extends Plugin return true; } - function onStartShowPageNotice($action) - { - $timeline = $this->_getTimeline($action); - if (!empty($timeline)) { - $base = $action->selfUrl(); - if (mb_strstr($url, '?')) { - $url = $base . '&realtime=1'; - } else { - $url = $base . '?realtime=1'; - } - $title = $action->title(); - $code = "window.open('$url', '$title', 'toolbar=no,resizable=yes,scrollbars=yes,status=yes,height=640,width=575');"; - $action->element('a', array('href' => $base, - 'onclick' => $code, - 'id' => 'realtime_timeline', - 'title' => _('Pop up')), - 'Pop up'); - - } - return true; - } - function onStartShowBody($action) { $realtime = $action->boolean('realtime'); diff --git a/plugins/Realtime/realtimeupdate.js b/plugins/Realtime/realtimeupdate.js index 3293ef6e9f..04e07956d5 100644 --- a/plugins/Realtime/realtimeupdate.js +++ b/plugins/Realtime/realtimeupdate.js @@ -109,6 +109,11 @@ RealtimeUpdate = { dl = "Delete"; return dl; + }, + + addPopup: function(url, title) + { + // FIXME: need to add the realtime popup button here } } From 4d4bb089a5e3addfd4be2f82e5e4e257070f4058 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Wed, 23 Sep 2009 21:58:35 +0000 Subject: [PATCH 10/18] Created addPop() for Realtime plugin and added param to include iconurl --- plugins/Realtime/RealtimePlugin.php | 4 +++- plugins/Realtime/realtimeupdate.js | 25 +++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/plugins/Realtime/RealtimePlugin.php b/plugins/Realtime/RealtimePlugin.php index fde3060216..157c800d95 100644 --- a/plugins/Realtime/RealtimePlugin.php +++ b/plugins/Realtime/RealtimePlugin.php @@ -99,11 +99,13 @@ class RealtimePlugin extends Plugin $user_id = 0; } + $iconurl = $base.'plugins/Realtime/icon_external.gif'; + $action->elementStart('script', array('type' => 'text/javascript')); $script = ' $(document).ready(function() { '. $this->_updateInitialize($timeline, $user_id). - ' RealtimeUpdate.addPopup("'.$url.'", "'.$title.'"); '. + ' RealtimeUpdate.addPopup("'.$url.'", "'.$title.'", "'. $iconurl .'");' '}); '; $action->raw($script); diff --git a/plugins/Realtime/realtimeupdate.js b/plugins/Realtime/realtimeupdate.js index 04e07956d5..2910e4a802 100644 --- a/plugins/Realtime/realtimeupdate.js +++ b/plugins/Realtime/realtimeupdate.js @@ -111,9 +111,30 @@ RealtimeUpdate = { return dl; }, - addPopup: function(url, title) + addPopup: function(url, title, iconurl) { - // FIXME: need to add the realtime popup button here + $('#site_nav_local_views .current a').append(''); + + $('#realtime_timeline').css({ + 'margin':'2px 0 0 11px', + 'background':'transparent url('+ iconurl + ') no-repeat 45% 45%', + 'text-indent':'-9999px', + 'width':'16px', + 'height':'16px', + 'padding':'0', + 'display':'block', + 'float':'right', + 'border':'none', + 'cursor':'pointer' + }); + + $('#realtime_timeline').click(function() { + window.open(url, + title, + 'toolbar=no,resizable=yes,scrollbars=yes,status=yes'); + + return false; + }); } } From ddb9518c9949989f99c3e7b0323c9bbd01c1d5ee Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Wed, 23 Sep 2009 22:00:22 +0000 Subject: [PATCH 11/18] Some layout and rendering adjustment for Realtime plugin --- plugins/Realtime/RealtimePlugin.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/Realtime/RealtimePlugin.php b/plugins/Realtime/RealtimePlugin.php index 157c800d95..f211c01f94 100644 --- a/plugins/Realtime/RealtimePlugin.php +++ b/plugins/Realtime/RealtimePlugin.php @@ -213,9 +213,9 @@ class RealtimePlugin extends Plugin 'class' => 'user_in') : array('id' => $action->trimmed('action'))); + $action->elementStart('div', array('id' => 'header')); // XXX hack to deal with JS that tries to get the // root url from page output - $action->elementStart('address'); $action->element('a', array('class' => 'url', 'href' => common_local_url('public')), @@ -225,7 +225,9 @@ class RealtimePlugin extends Plugin if (common_logged_in()) { $action->showNoticeForm(); } - $action->showContent(); + $action->elementEnd('div'); + + $action->showContentBlock(); $action->elementEnd('body'); return false; // No default processing } From 1f12993a4ddad8eba29c604c55f6b82d08dc0127 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Wed, 23 Sep 2009 22:02:42 +0000 Subject: [PATCH 12/18] Added JavaScript to initialize the poped Window --- plugins/Realtime/RealtimePlugin.php | 13 ++++++++++--- plugins/Realtime/realtimeupdate.js | 7 +++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/plugins/Realtime/RealtimePlugin.php b/plugins/Realtime/RealtimePlugin.php index f211c01f94..4fb8bf84e5 100644 --- a/plugins/Realtime/RealtimePlugin.php +++ b/plugins/Realtime/RealtimePlugin.php @@ -99,15 +99,22 @@ class RealtimePlugin extends Plugin $user_id = 0; } - $iconurl = $base.'plugins/Realtime/icon_external.gif'; + // FIXME: Need to check if the current URL is a poped realtime window + if (1==2) { + $realtimeUI = ' RealtimeUpdate.initPopupWindow();'; + } + else { + // FIXME: This icon URL is no good if fancy URLs are off. + $iconurl = $base.'plugins/Realtime/icon_external.gif'; + $realtimeUI = ' RealtimeUpdate.addPopup("'.$url.'", "'.$title.'", "'. $iconurl .'");'; + } $action->elementStart('script', array('type' => 'text/javascript')); $script = ' $(document).ready(function() { '. $this->_updateInitialize($timeline, $user_id). - ' RealtimeUpdate.addPopup("'.$url.'", "'.$title.'", "'. $iconurl .'");' + $realtimeUI. '}); '; - $action->raw($script); $action->elementEnd('script'); diff --git a/plugins/Realtime/realtimeupdate.js b/plugins/Realtime/realtimeupdate.js index 2910e4a802..4fda5079d4 100644 --- a/plugins/Realtime/realtimeupdate.js +++ b/plugins/Realtime/realtimeupdate.js @@ -135,6 +135,13 @@ RealtimeUpdate = { return false; }); + }, + + initPopupWindow: function() + { + window.resizeTo(575, 640); + $('address').hide(); + $('#content').css({'width':'92%'}); } } From d86155ad943032918c2fab070ca49f0a3586f25d Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Wed, 23 Sep 2009 22:04:39 +0000 Subject: [PATCH 13/18] Using timeline string instead of title for WindowName because IE doesn't like names with whitespace. --- plugins/Realtime/RealtimePlugin.php | 4 +--- plugins/Realtime/realtimeupdate.js | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/plugins/Realtime/RealtimePlugin.php b/plugins/Realtime/RealtimePlugin.php index 4fb8bf84e5..7334f56572 100644 --- a/plugins/Realtime/RealtimePlugin.php +++ b/plugins/Realtime/RealtimePlugin.php @@ -83,8 +83,6 @@ class RealtimePlugin extends Plugin $url = $base . '?realtime=1'; } - $title = $action->title(); - $scripts = $this->_getScripts(); foreach ($scripts as $script) { @@ -106,7 +104,7 @@ class RealtimePlugin extends Plugin else { // FIXME: This icon URL is no good if fancy URLs are off. $iconurl = $base.'plugins/Realtime/icon_external.gif'; - $realtimeUI = ' RealtimeUpdate.addPopup("'.$url.'", "'.$title.'", "'. $iconurl .'");'; + $realtimeUI = ' RealtimeUpdate.addPopup("'.$url.'", "'.$timeline.'", "'. $iconurl .'");'; } $action->elementStart('script', array('type' => 'text/javascript')); diff --git a/plugins/Realtime/realtimeupdate.js b/plugins/Realtime/realtimeupdate.js index 4fda5079d4..57fe0a8436 100644 --- a/plugins/Realtime/realtimeupdate.js +++ b/plugins/Realtime/realtimeupdate.js @@ -111,7 +111,7 @@ RealtimeUpdate = { return dl; }, - addPopup: function(url, title, iconurl) + addPopup: function(url, timeline, iconurl) { $('#site_nav_local_views .current a').append(''); @@ -130,7 +130,7 @@ RealtimeUpdate = { $('#realtime_timeline').click(function() { window.open(url, - title, + timeline, 'toolbar=no,resizable=yes,scrollbars=yes,status=yes'); return false; From 543e3e797277526ac0f0c6ac99be64897955258a Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 23 Sep 2009 23:04:25 -0400 Subject: [PATCH 14/18] some UI fixes --- plugins/Realtime/RealtimePlugin.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/Realtime/RealtimePlugin.php b/plugins/Realtime/RealtimePlugin.php index 7334f56572..e30c411567 100644 --- a/plugins/Realtime/RealtimePlugin.php +++ b/plugins/Realtime/RealtimePlugin.php @@ -77,7 +77,7 @@ class RealtimePlugin extends Plugin } $base = $action->selfUrl(); - if (mb_strstr($url, '?')) { + if (mb_strstr($base, '?')) { $url = $base . '&realtime=1'; } else { $url = $base . '?realtime=1'; @@ -97,21 +97,19 @@ class RealtimePlugin extends Plugin $user_id = 0; } - // FIXME: Need to check if the current URL is a poped realtime window - if (1==2) { + if ($action->boolean('realtime')) { $realtimeUI = ' RealtimeUpdate.initPopupWindow();'; } else { - // FIXME: This icon URL is no good if fancy URLs are off. - $iconurl = $base.'plugins/Realtime/icon_external.gif'; + $iconurl = common_path('plugins/Realtime/icon_external.gif'); $realtimeUI = ' RealtimeUpdate.addPopup("'.$url.'", "'.$timeline.'", "'. $iconurl .'");'; } $action->elementStart('script', array('type' => 'text/javascript')); $script = ' $(document).ready(function() { '. - $this->_updateInitialize($timeline, $user_id). $realtimeUI. + $this->_updateInitialize($timeline, $user_id). '}); '; $action->raw($script); @@ -219,8 +217,10 @@ class RealtimePlugin extends Plugin : array('id' => $action->trimmed('action'))); $action->elementStart('div', array('id' => 'header')); + // XXX hack to deal with JS that tries to get the // root url from page output + $action->elementStart('address'); $action->element('a', array('class' => 'url', 'href' => common_local_url('public')), From a5ed805aeabab3930d066b2777dbab9663bc487f Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 23 Sep 2009 23:23:13 -0400 Subject: [PATCH 15/18] move scripts to just before , add event for scripts that need to be in --- EVENTS.txt | 6 ++++++ lib/action.php | 19 +++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/EVENTS.txt b/EVENTS.txt index 68cb28603b..dfaf34a66e 100644 --- a/EVENTS.txt +++ b/EVENTS.txt @@ -134,3 +134,9 @@ StartAddressData: Allows the site owner to provide additional information about EndAddressData: At the end of
    - $action: the current action + +StartShowHeadElements: Right after the tag +- $action: the current action + +EndShowHeadElements: Right before the tag; put