summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/Realtime/RealtimePlugin.php9
-rw-r--r--plugins/Realtime/jquery.getUrlParam.js72
-rw-r--r--plugins/Realtime/realtimeupdate.js77
-rwxr-xr-xscripts/console.php162
4 files changed, 226 insertions, 94 deletions
diff --git a/plugins/Realtime/RealtimePlugin.php b/plugins/Realtime/RealtimePlugin.php
index 0f0d0f9f4..0c7c1240c 100644
--- a/plugins/Realtime/RealtimePlugin.php
+++ b/plugins/Realtime/RealtimePlugin.php
@@ -230,6 +230,7 @@ class RealtimePlugin extends Plugin
}
$action->showContentBlock();
+ $action->showScripts();
$action->elementEnd('body');
return false; // No default processing
}
@@ -239,13 +240,13 @@ class RealtimePlugin extends Plugin
// FIXME: this code should be abstracted to a neutral third
// party, like Notice::asJson(). I'm not sure of the ethics
// of refactoring from within a plugin, so I'm just abusing
- // the TwitterApiAction method. Don't do this unless you're me!
+ // the ApiAction method. Don't do this unless you're me!
- require_once(INSTALLDIR.'/lib/twitterapi.php');
+ require_once(INSTALLDIR.'/lib/api.php');
- $act = new TwitterApiAction('/dev/null');
+ $act = new ApiAction('/dev/null');
- $arr = $act->twitter_status_array($notice, true);
+ $arr = $act->twitterStatusArray($notice, true);
$arr['url'] = $notice->bestUrl();
$arr['html'] = htmlspecialchars($notice->rendered);
$arr['source'] = htmlspecialchars($arr['source']);
diff --git a/plugins/Realtime/jquery.getUrlParam.js b/plugins/Realtime/jquery.getUrlParam.js
deleted file mode 100644
index e8f73eb47..000000000
--- a/plugins/Realtime/jquery.getUrlParam.js
+++ /dev/null
@@ -1,72 +0,0 @@
-/* Copyright (c) 2006-2007 Mathias Bank (http://www.mathias-bank.de)
- * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
- * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
- *
- * Version 2.1
- *
- * Thanks to
- * Hinnerk Ruemenapf - http://hinnerk.ruemenapf.de/ for bug reporting and fixing.
- * Tom Leonard for some improvements
- *
- */
-jQuery.fn.extend({
-/**
-* Returns get parameters.
-*
-* If the desired param does not exist, null will be returned
-*
-* To get the document params:
-* @example value = $(document).getUrlParam("paramName");
-*
-* To get the params of a html-attribut (uses src attribute)
-* @example value = $('#imgLink').getUrlParam("paramName");
-*/
- getUrlParam: function(strParamName){
- strParamName = escape(unescape(strParamName));
-
- var returnVal = new Array();
- var qString = null;
-
- if ($(this).attr("nodeName")=="#document") {
- //document-handler
-
- if (window.location.search.search(strParamName) > -1 ){
-
- qString = window.location.search.substr(1,window.location.search.length).split("&");
- }
-
- } else if ($(this).attr("src")!="undefined") {
-
- var strHref = $(this).attr("src")
- if ( strHref.indexOf("?") > -1 ){
- var strQueryString = strHref.substr(strHref.indexOf("?")+1);
- qString = strQueryString.split("&");
- }
- } else if ($(this).attr("href")!="undefined") {
-
- var strHref = $(this).attr("href")
- if ( strHref.indexOf("?") > -1 ){
- var strQueryString = strHref.substr(strHref.indexOf("?")+1);
- qString = strQueryString.split("&");
- }
- } else {
- return null;
- }
-
-
- if (qString==null) return null;
-
-
- for (var i=0;i<qString.length; i++){
- if (escape(unescape(qString[i].split("=")[0])) == strParamName){
- returnVal.push(qString[i].split("=")[1]);
- }
-
- }
-
-
- if (returnVal.length==0) return null;
- else if (returnVal.length==1) return returnVal[0];
- else return returnVal;
- }
-}); \ No newline at end of file
diff --git a/plugins/Realtime/realtimeupdate.js b/plugins/Realtime/realtimeupdate.js
index 4cd68a816..e82b4dbfb 100644
--- a/plugins/Realtime/realtimeupdate.js
+++ b/plugins/Realtime/realtimeupdate.js
@@ -1,5 +1,31 @@
-// add a notice encoded as JSON into the current timeline
-//
+/*
+ * StatusNet - a distributed open-source microblogging tool
+ * Copyright (C) 2008, StatusNet, Inc.
+ *
+ * Add a notice encoded as JSON into the current timeline
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category Plugin
+ * @package StatusNet
+ * @author Evan Prodromou <evan@status.net>
+ * @author Sarven Capadisli <csarven@status.net>
+ * @copyright 2009 StatusNet, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://status.net/
+ */
+
// TODO: i18n
RealtimeUpdate = {
@@ -7,6 +33,7 @@ RealtimeUpdate = {
_replyurl: '',
_favorurl: '',
_deleteurl: '',
+ _updatecounter: 0,
init: function(userid, replyurl, favorurl, deleteurl)
{
@@ -15,6 +42,8 @@ RealtimeUpdate = {
RealtimeUpdate._favorurl = favorurl;
RealtimeUpdate._deleteurl = deleteurl;
+ DT = document.title;
+
$(window).blur(function() {
$('#notices_primary .notice').css({
'border-top-color':$('#notices_primary .notice:last').css('border-top-color'),
@@ -25,24 +54,33 @@ RealtimeUpdate = {
'border-top-color':'#AAAAAA',
'border-top-style':'solid'
});
+
+ RealtimeUpdate._updatecounter = 0;
+ document.title = DT;
+
+ return false;
});
},
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);
- $("#notices_primary .notice:first").css({display:"none"});
- $("#notices_primary .notice:first").fadeIn(1000);
- NoticeReply();
+ setTimeout(function() {
+ 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);
+ $("#notices_primary .notice:first").css({display:"none"});
+ $("#notices_primary .notice:first").fadeIn(1000);
+ NoticeReply();
+
+ RealtimeUpdate._updatecounter += 1;
+ document.title = '('+RealtimeUpdate._updatecounter+') ' + DT;
+ }, 500);
},
makeNoticeItem: function(data)
@@ -125,14 +163,17 @@ RealtimeUpdate = {
addPopup: function(url, timeline, iconurl)
{
- $('#content').prepend('<button id="realtime_timeline" title="Pop up in a window">Pop up</button>');
+ $('#notices_primary').css({'position':'relative'});
+ $('#notices_primary').prepend('<button id="realtime_timeline" title="Pop up in a window">Pop up</button>');
$('#realtime_timeline').css({
- 'margin':'0 0 18px 0',
+ 'margin':'0 0 11px 0',
'background':'transparent url('+ iconurl + ') no-repeat 0% 30%',
'padding':'0 0 0 20px',
'display':'block',
- 'float':'right',
+ 'position':'absolute',
+ 'top':'-20px',
+ 'right':'0',
'border':'none',
'cursor':'pointer',
'color':$("a").css("color"),
diff --git a/scripts/console.php b/scripts/console.php
new file mode 100755
index 000000000..41dd43f28
--- /dev/null
+++ b/scripts/console.php
@@ -0,0 +1,162 @@
+#!/usr/bin/env php
+<?php
+/*
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2009, StatusNet, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+# Abort if called from a web server
+
+define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
+
+$helptext = <<<ENDOFHELP
+console.php - provide an interactive PHP interpreter for testing
+
+ENDOFHELP;
+
+require_once INSTALLDIR.'/scripts/commandline.inc';
+
+if (function_exists('posix_isatty')) {
+ define('CONSOLE_INTERACTIVE', posix_isatty(0));
+} else {
+ // Windows? Assume we're on a terminal. :P
+ define('CONSOLE_INTERACTIVE', false);
+}
+if (CONSOLE_INTERACTIVE) {
+ define('CONSOLE_READLINE', function_exists('readline'));
+}
+
+if (CONSOLE_READLINE && CONSOLE_INTERACTIVE && file_exists(CONSOLE_HISTORY)) {
+ define(CONSOLE_HISTORY, getenv("HOME") . "/.statusnet_console_history");
+ readline_read_history(CONSOLE_HISTORY);
+}
+
+function read_input_line($prompt)
+{
+ if (CONSOLE_INTERACTIVE) {
+ if (CONSOLE_READLINE) {
+ $line = readline($prompt);
+ readline_add_history($line);
+ return $line;
+ } else {
+ return readline_emulation($prompt);
+ }
+ } else {
+ return fgets(STDIN);
+ }
+}
+
+/**
+ * On Unix-like systems where PHP readline extension isn't present,
+ * -cough- Mac OS X -cough- we can shell out to bash to do it for us.
+ * This lets us at least handle things like arrow keys, but we don't
+ * get any entry history. :(
+ *
+ * Shamelessly ripped from when I wrote the same code for MediaWiki. :)
+ * @author Brion Vibber <brion@status.net>
+ *
+ * @param string $prompt
+ * @return mixed string on success, false on fail or EOF
+ */
+function readline_emulation($prompt)
+{
+ if(file_exists(trim(shell_exec('which bash')))) {
+ $encPrompt = escapeshellarg($prompt);
+ $command = "read -er -p $encPrompt && echo \"\$REPLY\"";
+ $encCommand = escapeshellarg($command);
+ $metaCommand = "bash -c $encCommand";
+
+ // passthru passes our STDIN and TTY to the child...
+ // We can pull the returned string via output buffering.
+ ob_start();
+ $retval = false;
+ passthru($metaCommand, $retval);
+ $line = ob_get_contents();
+ ob_end_clean();
+
+ if ($retval == 0) {
+ return $line;
+ } elseif ($retval == 127) {
+ // Couldn't execute bash even though we thought we saw it.
+ // Shell probably spit out an error message, sorry :(
+ // Fall through to fgets()...
+ } else {
+ // EOF/ctrl+D
+ return false;
+ }
+ }
+
+ // Fallback... we'll have no editing controls, EWWW
+ if (feof(STDIN)) {
+ return false;
+ }
+ print $prompt;
+ return fgets(STDIN);
+}
+
+function console_help()
+{
+ print "Welcome to StatusNet's interactive PHP console!\n";
+ print "Type some PHP code and it'll execute...\n";
+ print "\n";
+ print "Hint: return a value of any type to output it via var_export():\n";
+ print " \$profile = new Profile();\n";
+ print " \$profile->find();\n";
+ print " \$profile->fetch();\n";
+ print " return \$profile;\n";
+ print "\n";
+ print "Note that PHP is cranky and you can easily kill your session by mistyping.\n";
+ print "\n";
+ print "Type ctrl+D or enter 'exit' to exit.\n";
+}
+
+
+print "StatusNet interactive PHP console... type ctrl+D or enter 'exit' to exit.\n";
+$prompt = common_config('site', 'name') . '> ';
+while (!feof(STDIN)) {
+ $line = read_input_line($prompt);
+ if ($line === false) {
+ print "\n";
+ break;
+ } elseif ($line !== '') {
+ try {
+ if (trim($line) == 'exit') {
+ break;
+ } elseif (trim($line) == 'help') {
+ console_help();
+ continue;
+ }
+
+ // Let's do this!
+ $result = eval($line);
+ if ($result === false) {
+ // parse error
+ } elseif ($result === null) {
+ // no return
+ } else {
+ // return value from eval'd code
+ var_export($result);
+ }
+ } catch(Exception $e) {
+ print get_class($e) . ": " . $e->getMessage() . "\n";
+ }
+ }
+ print "\n";
+}
+
+if (CONSOLE_READLINE && CONSOLE_INTERACTIVE) {
+ @readline_write_history(CONSOLE_HISTORY);
+}