summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEvan Prodromou <evan@status.net>2009-12-08 14:43:21 -0500
committerEvan Prodromou <evan@status.net>2009-12-08 14:43:21 -0500
commit78fc9483d4d1fde4561905edf6594b86c4dc374e (patch)
tree7172cabba4c36bb3a7bd00a78ab09f1791a9a60c /lib
parent75b11527c7efb1d3d9c7d53b99d80480ce06a9f5 (diff)
parent3536f01258dc43bee764c98fbdda5a6f1df7bcb2 (diff)
Merge branch '0.9.x' into testing
Diffstat (limited to 'lib')
-rw-r--r--lib/action.php2
-rw-r--r--lib/api.php10
-rw-r--r--lib/command.php32
-rw-r--r--lib/commandinterpreter.php6
-rw-r--r--lib/default.php3
-rw-r--r--lib/error.php2
-rw-r--r--lib/htmloutputter.php100
-rw-r--r--lib/messageform.php3
-rw-r--r--lib/noticeform.php3
-rw-r--r--lib/plugin.php10
-rw-r--r--lib/router.php2
-rw-r--r--lib/rssaction.php2
-rw-r--r--lib/schema.php18
-rw-r--r--lib/subs.php6
-rw-r--r--lib/util.php27
-rw-r--r--lib/xmloutputter.php5
16 files changed, 170 insertions, 61 deletions
diff --git a/lib/action.php b/lib/action.php
index 8ad391755..87d8a4399 100644
--- a/lib/action.php
+++ b/lib/action.php
@@ -68,7 +68,7 @@ class Action extends HTMLOutputter // lawsuit
* @see XMLOutputter::__construct
* @see HTMLOutputter::__construct
*/
- function __construct($output='php://output', $indent=true)
+ function __construct($output='php://output', $indent=null)
{
parent::__construct($output, $indent);
}
diff --git a/lib/api.php b/lib/api.php
index 5a3bb5ee4..eacb80dbe 100644
--- a/lib/api.php
+++ b/lib/api.php
@@ -134,19 +134,17 @@ class ApiAction extends Action
$twitter_user['protected'] = false; # not supported by StatusNet yet
$twitter_user['followers_count'] = $profile->subscriberCount();
- $design = null;
$user = $profile->getUser();
+ $design = null;
// Note: some profiles don't have an associated user
+ $defaultDesign = Design::siteDesign();
+
if (!empty($user)) {
$design = $user->getDesign();
}
- if (empty($design)) {
- $design = Design::siteDesign();
- }
-
$color = Design::toWebColor(empty($design->backgroundcolor) ? $defaultDesign->backgroundcolor : $design->backgroundcolor);
$twitter_user['profile_background_color'] = ($color == null) ? '' : '#'.$color->hexValue();
$color = Design::toWebColor(empty($design->textcolor) ? $defaultDesign->textcolor : $design->textcolor);
@@ -165,7 +163,7 @@ class ApiAction extends Action
$timezone = 'UTC';
- if ($user->timezone) {
+ if (!empty($user) && !empty($user->timezone)) {
$timezone = $user->timezone;
}
diff --git a/lib/command.php b/lib/command.php
index bcc551c81..e2a665511 100644
--- a/lib/command.php
+++ b/lib/command.php
@@ -579,6 +579,37 @@ class OnCommand extends Command
}
}
+class LoginCommand extends Command
+{
+ function execute($channel)
+ {
+ $disabled = common_config('logincommand','disabled');
+ if(isset($disabled)) {
+ $channel->error($this->user, _('Login command is disabled'));
+ return;
+ }
+ $login_token = Login_token::staticGet('user_id',$this->user->id);
+ if($login_token){
+ $login_token->delete();
+ }
+ $login_token = new Login_token();
+ $login_token->user_id = $this->user->id;
+ $login_token->token = common_good_rand(16);
+ $login_token->created = common_sql_now();
+ $result = $login_token->insert();
+ if (!$result) {
+ common_log_db_error($login_token, 'INSERT', __FILE__);
+ $channel->error($this->user, sprintf(_('Could not create login token for %s'),
+ $this->user->nickname));
+ return;
+ }
+ $channel->output($this->user,
+ sprintf(_('This link is useable only once, and is good for only 2 minutes: %s'),
+ common_local_url('login',
+ array('user_id'=>$login_token->user_id, 'token'=>$login_token->token))));
+ }
+}
+
class SubscriptionsCommand extends Command
{
function execute($channel)
@@ -666,6 +697,7 @@ class HelpCommand extends Command
"reply #<notice_id> - reply to notice with a given id\n".
"reply <nickname> - reply to the last notice from user\n".
"join <group> - join group\n".
+ "login - Get a link to login to the web interface\n".
"drop <group> - leave group\n".
"stats - get your stats\n".
"stop - same as 'off'\n".
diff --git a/lib/commandinterpreter.php b/lib/commandinterpreter.php
index 25f2e4b3e..665015afc 100644
--- a/lib/commandinterpreter.php
+++ b/lib/commandinterpreter.php
@@ -41,6 +41,12 @@ class CommandInterpreter
return null;
}
return new HelpCommand($user);
+ case 'login':
+ if ($arg) {
+ return null;
+ } else {
+ return new LoginCommand($user);
+ }
case 'subscribers':
if ($arg) {
return null;
diff --git a/lib/default.php b/lib/default.php
index d4ef045ea..ebb6f8d01 100644
--- a/lib/default.php
+++ b/lib/default.php
@@ -53,6 +53,7 @@ $default =
'shorturllength' => 30,
'dupelimit' => 60, # default for same person saying the same thing
'textlimit' => 140,
+ 'indent' => true,
),
'db' =>
array('database' => 'YOU HAVE TO SET THIS IN config.php',
@@ -74,7 +75,7 @@ $default =
array('enabled' => false,
'subsystem' => 'db', # default to database, or 'stomp'
'stomp_server' => null,
- 'queue_basename' => 'statusnet',
+ 'queue_basename' => '/queue/statusnet/',
'stomp_username' => null,
'stomp_password' => null,
),
diff --git a/lib/error.php b/lib/error.php
index 3162cfe65..87a4d913b 100644
--- a/lib/error.php
+++ b/lib/error.php
@@ -50,7 +50,7 @@ class ErrorAction extends Action
var $message = null;
var $default = null;
- function __construct($message, $code, $output='php://output', $indent=true)
+ function __construct($message, $code, $output='php://output', $indent=null)
{
parent::__construct($output, $indent);
diff --git a/lib/htmloutputter.php b/lib/htmloutputter.php
index d267526c8..2091c6e2c 100644
--- a/lib/htmloutputter.php
+++ b/lib/htmloutputter.php
@@ -67,7 +67,7 @@ class HTMLOutputter extends XMLOutputter
* @param boolean $indent Whether to indent output, default true
*/
- function __construct($output='php://output', $indent=true)
+ function __construct($output='php://output', $indent=null)
{
parent::__construct($output, $indent);
}
@@ -350,14 +350,43 @@ class HTMLOutputter extends XMLOutputter
*/
function script($src, $type='text/javascript')
{
- $url = parse_url($src);
- if( empty($url->scheme) && empty($url->host) && empty($url->query) && empty($url->fragment))
- {
- $src = common_path($src) . '?version=' . STATUSNET_VERSION;
+ if(Event::handle('StartScriptElement', array($this,&$src,&$type))) {
+ $url = parse_url($src);
+ if( empty($url->scheme) && empty($url->host) && empty($url->query) && empty($url->fragment))
+ {
+ $src = common_path($src) . '?version=' . STATUSNET_VERSION;
+ }
+ $this->element('script', array('type' => $type,
+ 'src' => $src),
+ ' ');
+ Event::handle('EndScriptElement', array($this,$src,$type));
+ }
+ }
+
+ /**
+ * output a script (almost always javascript) tag with inline
+ * code.
+ *
+ * @param string $code code to put in the script tag
+ * @param string $type 'type' attribute value of the tag
+ *
+ * @return void
+ */
+
+ function inlineScript($code, $type='text/javascript')
+ {
+ if(Event::handle('StartInlineScriptElement', array($this,&$code,&$type))) {
+ $this->elementStart('script', array('type' => $type));
+ if($type == 'text/javascript') {
+ $this->raw('/*<![CDATA[*/ '); // XHTML compat
+ }
+ $this->raw($code);
+ if($type == 'text/javascript') {
+ $this->raw(' /*]]>*/'); // XHTML compat
+ }
+ $this->elementEnd('script');
+ Event::handle('EndInlineScriptElement', array($this,$code,$type));
}
- $this->element('script', array('type' => $type,
- 'src' => $src),
- ' ');
}
/**
@@ -371,19 +400,44 @@ class HTMLOutputter extends XMLOutputter
*/
function cssLink($src,$theme=null,$media=null)
{
- $url = parse_url($src);
- if( empty($url->scheme) && empty($url->host) && empty($url->query) && empty($url->fragment))
- {
- if(file_exists(Theme::file($src,$theme))){
- $src = Theme::path($src, $theme) . '?version=' . STATUSNET_VERSION;
- }else{
- $src = common_path($src);
+ if(Event::handle('StartCssLinkElement', array($this,&$src,&$theme,&$media))) {
+ $url = parse_url($src);
+ if( empty($url->scheme) && empty($url->host) && empty($url->query) && empty($url->fragment))
+ {
+ if(file_exists(Theme::file($src,$theme))){
+ $src = Theme::path($src, $theme);
+ }else{
+ $src = common_path($src);
+ }
+ $src.= '?version=' . STATUSNET_VERSION;
}
+ $this->element('link', array('rel' => 'stylesheet',
+ 'type' => 'text/css',
+ 'href' => $src,
+ 'media' => $media));
+ Event::handle('EndCssLinkElement', array($this,$src,$theme,$media));
+ }
+ }
+
+ /**
+ * output a style (almost always css) tag with inline
+ * code.
+ *
+ * @param string $code code to put in the style tag
+ * @param string $type 'type' attribute value of the tag
+ * @param string $media 'media' attribute value of the tag
+ *
+ * @return void
+ */
+
+ function style($code, $type = 'text/css', $media = null)
+ {
+ if(Event::handle('StartStyleElement', array($this,&$code,&$type,&$media))) {
+ $this->elementStart('style', array('type' => $type, 'media' => $media));
+ $this->raw($code);
+ $this->elementEnd('style');
+ Event::handle('EndStyleElement', array($this,$code,$type,$media));
}
- $this->element('link', array('rel' => 'stylesheet',
- 'type' => 'text/css',
- 'href' => $src,
- 'media' => $media));
}
/**
@@ -414,7 +468,6 @@ class HTMLOutputter extends XMLOutputter
}
}
-
/**
* Internal script to autofocus the given element on page onload.
*
@@ -425,13 +478,10 @@ class HTMLOutputter extends XMLOutputter
*/
function autofocus($id)
{
- $this->elementStart('script', array('type' => 'text/javascript'));
- $this->raw('/*<![CDATA[*/'.
+ $this->inlineScript(
' $(document).ready(function() {'.
' var el = $("#' . $id . '");'.
' if (el.length) { el.focus(); }'.
- ' });'.
- ' /*]]>*/');
- $this->elementEnd('script');
+ ' });');
}
}
diff --git a/lib/messageform.php b/lib/messageform.php
index b034be312..4df193c6d 100644
--- a/lib/messageform.php
+++ b/lib/messageform.php
@@ -154,8 +154,7 @@ class MessageForm extends Form
$contentLimit = Message::maxContent();
- $this->out->element('script', array('type' => 'text/javascript'),
- 'maxLength = ' . $contentLimit . ';');
+ $this->out->inlineScript('maxLength = ' . $contentLimit . ';');
if ($contentLimit > 0) {
$this->out->elementStart('dl', 'form_note');
diff --git a/lib/noticeform.php b/lib/noticeform.php
index ec8624597..0dd3f2d77 100644
--- a/lib/noticeform.php
+++ b/lib/noticeform.php
@@ -178,8 +178,7 @@ class NoticeForm extends Form
$contentLimit = Notice::maxContent();
- $this->out->element('script', array('type' => 'text/javascript'),
- 'maxLength = ' . $contentLimit . ';');
+ $this->out->inlineScript('maxLength = ' . $contentLimit . ';');
if ($contentLimit > 0) {
$this->out->elementStart('dl', 'form_note');
diff --git a/lib/plugin.php b/lib/plugin.php
index 87d7be5a7..2c77c3e12 100644
--- a/lib/plugin.php
+++ b/lib/plugin.php
@@ -76,4 +76,14 @@ class Plugin
{
return true;
}
+
+ protected function log($level, $msg)
+ {
+ common_log($level, get_class($this) . ': '.$msg);
+ }
+
+ protected function debug($msg)
+ {
+ $this->log(LOG_DEBUG, $msg);
+ }
}
diff --git a/lib/router.php b/lib/router.php
index 1a090861e..37525319f 100644
--- a/lib/router.php
+++ b/lib/router.php
@@ -88,6 +88,8 @@ class Router
$m->connect('doc/:title', array('action' => 'doc'));
+ $m->connect('main/login?user_id=:user_id&token=:token', array('action'=>'login'), array('user_id'=> '[0-9]+', 'token'=>'.+'));
+
// main stuff is repetitive
$main = array('login', 'logout', 'register', 'subscribe',
diff --git a/lib/rssaction.php b/lib/rssaction.php
index d591c99ed..62e3f21b6 100644
--- a/lib/rssaction.php
+++ b/lib/rssaction.php
@@ -52,7 +52,7 @@ class Rss10Action extends Action
* @see Action::__construct
*/
- function __construct($output='php://output', $indent=true)
+ function __construct($output='php://output', $indent=null)
{
parent::__construct($output, $indent);
}
diff --git a/lib/schema.php b/lib/schema.php
index df7cb65f5..a8ba91b87 100644
--- a/lib/schema.php
+++ b/lib/schema.php
@@ -94,7 +94,7 @@ class Schema
public function getTableDef($name)
{
- $res =& $this->conn->query('DESCRIBE ' . $name);
+ $res = $this->conn->query('DESCRIBE ' . $name);
if (PEAR::isError($res)) {
throw new Exception($res->getMessage());
@@ -213,7 +213,7 @@ class Schema
$sql .= "); ";
- $res =& $this->conn->query($sql);
+ $res = $this->conn->query($sql);
if (PEAR::isError($res)) {
throw new Exception($res->getMessage());
@@ -234,7 +234,7 @@ class Schema
public function dropTable($name)
{
- $res =& $this->conn->query("DROP TABLE $name");
+ $res = $this->conn->query("DROP TABLE $name");
if (PEAR::isError($res)) {
throw new Exception($res->getMessage());
@@ -269,7 +269,7 @@ class Schema
$name = "$table_".implode("_", $columnNames)."_idx";
}
- $res =& $this->conn->query("ALTER TABLE $table ".
+ $res = $this->conn->query("ALTER TABLE $table ".
"ADD INDEX $name (".
implode(",", $columnNames).")");
@@ -291,7 +291,7 @@ class Schema
public function dropIndex($table, $name)
{
- $res =& $this->conn->query("ALTER TABLE $table DROP INDEX $name");
+ $res = $this->conn->query("ALTER TABLE $table DROP INDEX $name");
if (PEAR::isError($res)) {
throw new Exception($res->getMessage());
@@ -314,7 +314,7 @@ class Schema
{
$sql = "ALTER TABLE $table ADD COLUMN " . $this->_columnSql($columndef);
- $res =& $this->conn->query($sql);
+ $res = $this->conn->query($sql);
if (PEAR::isError($res)) {
throw new Exception($res->getMessage());
@@ -339,7 +339,7 @@ class Schema
$sql = "ALTER TABLE $table MODIFY COLUMN " .
$this->_columnSql($columndef);
- $res =& $this->conn->query($sql);
+ $res = $this->conn->query($sql);
if (PEAR::isError($res)) {
throw new Exception($res->getMessage());
@@ -363,7 +363,7 @@ class Schema
{
$sql = "ALTER TABLE $table DROP COLUMN $columnName";
- $res =& $this->conn->query($sql);
+ $res = $this->conn->query($sql);
if (PEAR::isError($res)) {
throw new Exception($res->getMessage());
@@ -446,7 +446,7 @@ class Schema
$sql = 'ALTER TABLE ' . $tableName . ' ' . implode(', ', $phrase);
- $res =& $this->conn->query($sql);
+ $res = $this->conn->query($sql);
if (PEAR::isError($res)) {
throw new Exception($res->getMessage());
diff --git a/lib/subs.php b/lib/subs.php
index 2fc3160de..4b6b03967 100644
--- a/lib/subs.php
+++ b/lib/subs.php
@@ -127,6 +127,12 @@ function subs_unsubscribe_to($user, $other)
if (!$user->isSubscribed($other))
return _('Not subscribed!');
+ // Don't allow deleting self subs
+
+ if ($user->id == $other->id) {
+ return _('Couldn\'t delete self-subscription.');
+ }
+
$sub = DB_DataObject::factory('subscription');
$sub->subscriber = $user->id;
diff --git a/lib/util.php b/lib/util.php
index 99a0a1db3..14d666503 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -127,7 +127,7 @@ function common_check_user($nickname, $password)
if (0 == strcmp(common_munge_password($password, $user->id),
$user->password)) {
//internal checking passed
- $authenticatedUser =& $user;
+ $authenticatedUser = $user;
}
}
}
@@ -1070,18 +1070,21 @@ function common_request_id()
function common_log($priority, $msg, $filename=null)
{
- $msg = '[' . common_request_id() . '] ' . $msg;
- $logfile = common_config('site', 'logfile');
- if ($logfile) {
- $log = fopen($logfile, "a");
- if ($log) {
- $output = common_log_line($priority, $msg);
- fwrite($log, $output);
- fclose($log);
+ if(Event::handle('StartLog', array(&$priority, &$msg, &$filename))){
+ $msg = '[' . common_request_id() . '] ' . $msg;
+ $logfile = common_config('site', 'logfile');
+ if ($logfile) {
+ $log = fopen($logfile, "a");
+ if ($log) {
+ $output = common_log_line($priority, $msg);
+ fwrite($log, $output);
+ fclose($log);
+ }
+ } else {
+ common_ensure_syslog();
+ syslog($priority, $msg);
}
- } else {
- common_ensure_syslog();
- syslog($priority, $msg);
+ Event::handle('EndLog', array($priority, $msg, $filename));
}
}
diff --git a/lib/xmloutputter.php b/lib/xmloutputter.php
index 5f06e491d..15b18e7d9 100644
--- a/lib/xmloutputter.php
+++ b/lib/xmloutputter.php
@@ -67,10 +67,13 @@ class XMLOutputter
* @param boolean $indent Whether to indent output, default true
*/
- function __construct($output='php://output', $indent=true)
+ function __construct($output='php://output', $indent=null)
{
$this->xw = new XMLWriter();
$this->xw->openURI($output);
+ if(is_null($indent)) {
+ $indent = common_config('site', 'indent');
+ }
$this->xw->setIndent($indent);
}