summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README17
-rw-r--r--actions/public.php2
-rw-r--r--classes/Design.php92
-rw-r--r--classes/Notice.php158
-rw-r--r--config.php.sample16
-rw-r--r--lib/action.php28
-rw-r--r--lib/common.php20
-rw-r--r--lib/currentuserdesignaction.php37
-rw-r--r--lib/groupdesignaction.php30
-rw-r--r--lib/ownerdesignaction.php31
10 files changed, 277 insertions, 154 deletions
diff --git a/README b/README
index 0bf1319c6..ef5a13934 100644
--- a/README
+++ b/README
@@ -964,9 +964,6 @@ sslserver: use an alternate server name for SSL URLs, like
shorturllength: Length of URL at which URLs in a message exceeding 140
characters will be sent to the user's chosen
shortening service.
-design: a default design (colors and background) for the site.
- Sub-items are: backgroundcolor, contentcolor, sidebarcolor,
- textcolor, linkcolor, backgroundimage, disposition.
dupelimit: minimum time allowed for one person to say the same thing
twice. Default 60s. Anything lower is considered a user
or UI error.
@@ -1432,6 +1429,20 @@ notify third-party servers of updates.
notify: an array of URLs for ping endpoints. Default is the empty
array (no notification).
+design
+------
+
+Default design (colors and background) for the site. Actual appearance
+depends on the theme. Null values mean to use the theme defaults.
+
+backgroundcolor: Hex color of the site background.
+contentcolor: Hex color of the content area background.
+sidebarcolor: Hex color of the sidebar background.
+textcolor: Hex color of all non-link text.
+linkcolor: Hex color of all links.
+backgroundimage: Image to use for the background.
+disposition: Flags for whether or not to tile the background image.
+
Plugins
=======
diff --git a/actions/public.php b/actions/public.php
index ef9ef0d1a..d0317ac70 100644
--- a/actions/public.php
+++ b/actions/public.php
@@ -229,7 +229,7 @@ class PublicAction extends Action
// $top->show();
$pop = new PopularNoticeSection($this);
$pop->show();
- $gbp = new GroupsByPostsSection($this);
+ $gbp = new GroupsByMembersSection($this);
$gbp->show();
$feat = new FeaturedUsersSection($this);
$feat->show();
diff --git a/classes/Design.php b/classes/Design.php
index 0927fcda7..43544f1c9 100644
--- a/classes/Design.php
+++ b/classes/Design.php
@@ -55,26 +55,38 @@ class Design extends Memcached_DataObject
function showCSS($out)
{
- try {
+ $css = '';
- $bgcolor = new WebColor($this->backgroundcolor);
- $ccolor = new WebColor($this->contentcolor);
- $sbcolor = new WebColor($this->sidebarcolor);
- $tcolor = new WebColor($this->textcolor);
- $lcolor = new WebColor($this->linkcolor);
+ $bgcolor = Design::toWebColor($this->backgroundcolor);
- } catch (WebColorException $e) {
- // This shouldn't happen
- common_log(LOG_ERR, "Unable to create color for design $id.",
- __FILE__);
+ if (!empty($bgcolor)) {
+ $css .= 'body { background-color: #' . $bgcolor->hexValue() . ' }' . "\n";
+ }
+
+ $ccolor = Design::toWebColor($this->contentcolor);
+
+ if (!empty($ccolor)) {
+ $css .= '#content, #site_nav_local_views .current a { background-color: #';
+ $css .= $ccolor->hexValue() . '} '."\n";
+ }
+
+ $sbcolor = Design::toWebColor($this->sidebarcolor);
+
+ if (!empty($sbcolor)) {
+ $css .= '#aside_primary { background-color: #'. $sbcolor->hexValue() . ' }' . "\n";
+ }
+
+ $tcolor = Design::toWebColor($this->textcolor);
+
+ if (!empty($tcolor)) {
+ $css .= 'html body { color: #'. $tcolor->hexValue() . ' }'. "\n";
}
- $css = 'body { background-color: #' . $bgcolor->hexValue() . ' }' . "\n";
- $css .= '#content, #site_nav_local_views .current a { background-color: #';
- $css .= $ccolor->hexValue() . '} '."\n";
- $css .= '#aside_primary { background-color: #'. $sbcolor->hexValue() . ' }' . "\n";
- $css .= 'html body { color: #'. $tcolor->hexValue() . ' }'. "\n";
- $css .= 'a { color: #' . $lcolor->hexValue() . ' }' . "\n";
+ $lcolor = Design::toWebColor($this->linkcolor);
+
+ if (!empty($lcolor)) {
+ $css .= 'a { color: #' . $lcolor->hexValue() . ' }' . "\n";
+ }
if (!empty($this->backgroundimage) &&
$this->disposition & BACKGROUND_ON) {
@@ -88,8 +100,25 @@ class Design extends Memcached_DataObject
'); ' . $repeat . ' background-attachment:fixed; }' . "\n";
}
- $out->element('style', array('type' => 'text/css'), $css);
+ if (0 != mb_strlen($css)) {
+ $out->element('style', array('type' => 'text/css'), $css);
+ }
+ }
+
+ static function toWebColor($color)
+ {
+ if (is_null($color)) {
+ return null;
+ }
+ try {
+ return new WebColor($color);
+ } catch (WebColorException $e) {
+ // This shouldn't happen
+ common_log(LOG_ERR, "Unable to create color for design $id.",
+ __FILE__);
+ return null;
+ }
}
static function filename($id, $extension, $extra=null)
@@ -152,4 +181,33 @@ class Design extends Memcached_DataObject
}
}
+ /**
+ * Return a design object based on the configured site design.
+ *
+ * @return Design a singleton design object for the site.
+ */
+
+ static function siteDesign()
+ {
+ static $siteDesign = null;
+
+ if (empty($siteDesign)) {
+
+ $siteDesign = new Design();
+
+ $attrs = array('backgroundcolor',
+ 'contentcolor',
+ 'sidebarcolor',
+ 'textcolor',
+ 'linkcolor',
+ 'backgroundimage',
+ 'disposition');
+
+ foreach ($attrs as $attr) {
+ $siteDesign->$attr = common_config('design', $attr);
+ }
+ }
+
+ return $siteDesign;
+ }
}
diff --git a/classes/Notice.php b/classes/Notice.php
index c2770edbe..ebd5e1efd 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -102,15 +102,14 @@ class Notice extends Memcached_DataObject
if (!$count) {
return true;
}
-
+
//turn each into their canonical tag
//this is needed to remove dupes before saving e.g. #hash.tag = #hashtag
$hashtags = array();
for($i=0; $i<count($match[1]); $i++) {
- $hashtags[] = common_canonical_tag($match[1][$i]);
+ $hashtags[] = common_canonical_tag($match[1][$i]);
}
-
/* Add them to the database */
foreach(array_unique($hashtags) as $hashtag) {
/* elide characters we don't want in the tag */
@@ -183,29 +182,30 @@ class Notice extends Memcached_DataObject
$notice->is_local = $is_local;
}
- $notice->query('BEGIN');
-
- $notice->reply_to = $reply_to;
if (!empty($created)) {
$notice->created = $created;
} else {
$notice->created = common_sql_now();
}
+
$notice->content = $final;
$notice->rendered = common_render_content($final, $notice);
$notice->source = $source;
$notice->uri = $uri;
- if (!empty($reply_to)) {
- $reply_notice = Notice::staticGet('id', $reply_to);
- if (!empty($reply_notice)) {
- $notice->reply_to = $reply_to;
- $notice->conversation = $reply_notice->conversation;
- }
+ $notice->reply_to = self::getReplyTo($reply_to, $profile_id, $source, $final);
+
+ if (!empty($notice->reply_to)) {
+ $reply = Notice::staticGet('id', $notice->reply_to);
+ $notice->conversation = $reply->conversation;
}
if (Event::handle('StartNoticeSave', array(&$notice))) {
+ // XXX: some of these functions write to the DB
+
+ $notice->query('BEGIN');
+
$id = $notice->insert();
if (!$id) {
@@ -213,18 +213,33 @@ class Notice extends Memcached_DataObject
return _('Problem saving notice.');
}
- # Update the URI after the notice is in the database
- if (!$uri) {
- $orig = clone($notice);
+ // Update ID-dependent columns: URI, conversation
+
+ $orig = clone($notice);
+
+ $changed = false;
+
+ if (empty($uri)) {
$notice->uri = common_notice_uri($notice);
+ $changed = true;
+ }
+
+ // If it's not part of a conversation, it's
+ // the beginning of a new conversation.
+ if (empty($notice->conversation)) {
+ $notice->conversation = $notice->id;
+ $changed = true;
+ }
+
+ if ($changed) {
if (!$notice->update($orig)) {
common_log_db_error($notice, 'UPDATE', __FILE__);
return _('Problem saving notice.');
}
}
- # XXX: do we need to change this for remote users?
+ // XXX: do we need to change this for remote users?
$notice->saveReplies();
$notice->saveTags();
@@ -232,8 +247,13 @@ class Notice extends Memcached_DataObject
$notice->addToInboxes();
$notice->saveUrls();
+
+ // FIXME: why do we have to re-render the content?
+ // Remove this if it's not necessary.
+
$orig2 = clone($notice);
- $notice->rendered = common_render_content($final, $notice);
+
+ $notice->rendered = common_render_content($final, $notice);
if (!$notice->update($orig2)) {
common_log_db_error($notice, 'UPDATE', __FILE__);
return _('Problem saving notice.');
@@ -290,9 +310,9 @@ class Notice extends Memcached_DataObject
$notice->profile_id = $profile_id;
$notice->content = $content;
if (common_config('db','type') == 'pgsql')
- $notice->whereAdd('extract(epoch from now() - created) < ' . common_config('site', 'dupelimit'));
+ $notice->whereAdd('extract(epoch from now() - created) < ' . common_config('site', 'dupelimit'));
else
- $notice->whereAdd('now() - created < ' . common_config('site', 'dupelimit'));
+ $notice->whereAdd('now() - created < ' . common_config('site', 'dupelimit'));
$cnt = $notice->count();
return ($cnt == 0);
@@ -906,14 +926,14 @@ class Notice extends Memcached_DataObject
{
$user = new User();
- if(common_config('db','quote_identifiers'))
- $user_table = '"user"';
- else $user_table = 'user';
+ if(common_config('db','quote_identifiers'))
+ $user_table = '"user"';
+ else $user_table = 'user';
$qry =
'SELECT id ' .
- 'FROM '. $user_table .' JOIN subscription '.
- 'ON '. $user_table .'.id = subscription.subscriber ' .
+ 'FROM '. $user_table .' JOIN subscription '.
+ 'ON '. $user_table .'.id = subscription.subscriber ' .
'WHERE subscription.subscribed = %d ';
$user->query(sprintf($qry, $this->profile_id));
@@ -1031,16 +1051,6 @@ class Notice extends Memcached_DataObject
if (!$recipient) {
continue;
}
- if ($i == 0 && ($recipient->id != $sender->id) && !$this->reply_to) { // Don't save reply to self
- $reply_for = $recipient;
- $recipient_notice = $reply_for->getCurrentNotice();
- if ($recipient_notice) {
- $orig = clone($this);
- $this->reply_to = $recipient_notice->id;
- $this->conversation = $recipient_notice->conversation;
- $this->update($orig);
- }
- }
// Don't save replies from blocked profile to local user
$recipient_user = User::staticGet('id', $recipient->id);
if ($recipient_user && $recipient_user->hasBlocked($sender)) {
@@ -1087,14 +1097,6 @@ class Notice extends Memcached_DataObject
}
}
- // If it's not a reply, make it the root of a new conversation
-
- if (empty($this->conversation)) {
- $orig = clone($this);
- $this->conversation = $this->id;
- $this->update($orig);
- }
-
foreach (array_keys($replied) as $recipient) {
$user = User::staticGet('id', $recipient);
if ($user) {
@@ -1266,4 +1268,76 @@ class Notice extends Memcached_DataObject
return $ids;
}
+
+ /**
+ * Determine which notice, if any, a new notice is in reply to.
+ *
+ * For conversation tracking, we try to see where this notice fits
+ * in the tree. Rough algorithm is:
+ *
+ * if (reply_to is set and valid) {
+ * return reply_to;
+ * } else if ((source not API or Web) and (content starts with "T NAME" or "@name ")) {
+ * return ID of last notice by initial @name in content;
+ * }
+ *
+ * Note that all @nickname instances will still be used to save "reply" records,
+ * so the notice shows up in the mentioned users' "replies" tab.
+ *
+ * @param integer $reply_to ID passed in by Web or API
+ * @param integer $profile_id ID of author
+ * @param string $source Source tag, like 'web' or 'gwibber'
+ * @param string $content Final notice content
+ *
+ * @return integer ID of replied-to notice, or null for not a reply.
+ */
+
+ static function getReplyTo($reply_to, $profile_id, $source, $content)
+ {
+ static $lb = array('xmpp', 'mail', 'sms', 'omb');
+
+ // If $reply_to is specified, we check that it exists, and then
+ // return it if it does
+
+ if (!empty($reply_to)) {
+ $reply_notice = Notice::staticGet('id', $reply_to);
+ if (!empty($reply_notice)) {
+ return $reply_to;
+ }
+ }
+
+ // If it's not a "low bandwidth" source (one where you can't set
+ // a reply_to argument), we return. This is mostly web and API
+ // clients.
+
+ if (!in_array($source, $lb)) {
+ return null;
+ }
+
+ // Is there an initial @ or T?
+
+ if (preg_match('/^T ([A-Z0-9]{1,64}) /', $content, $match) ||
+ preg_match('/^@([a-z0-9]{1,64})\s+/', $content, $match)) {
+ $nickname = common_canonical_nickname($match[1]);
+ } else {
+ return null;
+ }
+
+ // Figure out who that is.
+
+ $sender = Profile::staticGet('id', $profile_id);
+ $recipient = common_relative_profile($sender, $nickname, common_sql_now());
+
+ if (empty($recipient)) {
+ return null;
+ }
+
+ // Get their last notice
+
+ $last = $recipient->getCurrentNotice();
+
+ if (!empty($last)) {
+ return $last->id;
+ }
+ }
}
diff --git a/config.php.sample b/config.php.sample
index 36e62f70f..c27645ff8 100644
--- a/config.php.sample
+++ b/config.php.sample
@@ -18,14 +18,14 @@ $config['site']['server'] = 'localhost';
$config['site']['path'] = 'laconica';
// $config['site']['fancy'] = false;
// $config['site']['theme'] = 'default';
-// Sets the site's default design values (match it with the values in the theme)
-// $config['site']['design']['backgroundcolor'] = '#F0F2F5';
-// $config['site']['design']['contentcolor'] = '#FFFFFF';
-// $config['site']['design']['sidebarcolor'] = '#CEE1E9';
-// $config['site']['design']['textcolor'] = '#000000';
-// $config['site']['design']['linkcolor'] = '#002E6E';
-// $config['site']['design']['backgroundimage'] = null;
-// $config['site']['design']['disposition'] = 1;
+// Sets the site's default design values
+// $config['design']['backgroundcolor'] = '#F0F2F5';
+// $config['design']['contentcolor'] = '#FFFFFF';
+// $config['design']['sidebarcolor'] = '#CEE1E9';
+// $config['design']['textcolor'] = '#000000';
+// $config['design']['linkcolor'] = '#002E6E';
+// $config['design']['backgroundimage'] = null;
+// $config['design']['disposition'] = 1;
// To enable the built-in mobile style sheet, defaults to false.
// $config['site']['mobile'] = true;
// For contact email, defaults to $_SERVER["SERVER_ADMIN"]
diff --git a/lib/action.php b/lib/action.php
index 95ee10c64..a5244371a 100644
--- a/lib/action.php
+++ b/lib/action.php
@@ -191,6 +191,7 @@ class Action extends HTMLOutputter // lawsuit
function showStylesheets()
{
if (Event::handle('StartShowStyles', array($this))) {
+
if (Event::handle('StartShowLaconicaStyles', array($this))) {
$this->element('link', array('rel' => 'stylesheet',
'type' => 'text/css',
@@ -209,6 +210,7 @@ class Action extends HTMLOutputter // lawsuit
'media' => 'print'));
Event::handle('EndShowLaconicaStyles', array($this));
}
+
if (Event::handle('StartShowUAStyles', array($this))) {
$this->comment('[if IE]><link rel="stylesheet" type="text/css" '.
'href="'.theme_path('css/ie.css', 'base').'?version='.LACONICA_VERSION.'" /><![endif]');
@@ -223,6 +225,21 @@ class Action extends HTMLOutputter // lawsuit
'href="'.theme_path('css/ie.css', null).'?version='.LACONICA_VERSION.'" /><![endif]');
Event::handle('EndShowUAStyles', array($this));
}
+
+ if (Event::handle('StartShowDesign', array($this))) {
+
+ $user = common_current_user();
+
+ if (empty($user) || $user->viewdesigns) {
+ $design = $this->getDesign();
+
+ if (!empty($design)) {
+ $design->showCSS($this);
+ }
+ }
+
+ Event::handle('EndShowDesign', array($this));
+ }
Event::handle('EndShowStyles', array($this));
}
}
@@ -1074,4 +1091,15 @@ class Action extends HTMLOutputter // lawsuit
{
return null;
}
+
+ /**
+ * A design for this action
+ *
+ * @return Design a design object to use
+ */
+
+ function getDesign()
+ {
+ return Design::siteDesign();
+ }
}
diff --git a/lib/common.php b/lib/common.php
index 9d7954fa9..b3d301862 100644
--- a/lib/common.php
+++ b/lib/common.php
@@ -94,14 +94,6 @@ $config =
array('name' => 'Just another Laconica microblog',
'server' => $_server,
'theme' => 'default',
- 'design' =>
- array('backgroundcolor' => '#CEE1E9',
- 'contentcolor' => '#FFFFFF',
- 'sidebarcolor' => '#C8D1D5',
- 'textcolor' => '#000000',
- 'linkcolor' => '#002E6E',
- 'backgroundimage' => null,
- 'disposition' => 1),
'path' => $_path,
'logfile' => null,
'logo' => null,
@@ -261,6 +253,14 @@ $config =
'sessions' =>
array('handle' => false, // whether to handle sessions ourselves
'debug' => false), // debugging output for sessions
+ 'design' =>
+ array('backgroundcolor' => null, // null -> 'use theme default'
+ 'contentcolor' => null,
+ 'sidebarcolor' => null,
+ 'textcolor' => null,
+ 'linkcolor' => null,
+ 'backgroundimage' => null,
+ 'disposition' => null),
);
$config['db'] = &PEAR::getStaticProperty('DB_DataObject','options');
@@ -277,6 +277,10 @@ $config['db'] =
'quote_identifiers' => false,
'type' => 'mysql' );
+// Backward compatibility
+
+$config['site']['design'] =& $config['design'];
+
if (function_exists('date_default_timezone_set')) {
/* Work internally in UTC */
date_default_timezone_set('UTC');
diff --git a/lib/currentuserdesignaction.php b/lib/currentuserdesignaction.php
index 4c7e15a8b..52516b624 100644
--- a/lib/currentuserdesignaction.php
+++ b/lib/currentuserdesignaction.php
@@ -47,33 +47,10 @@ if (!defined('LACONICA')) {
class CurrentUserDesignAction extends Action
{
-
- /**
- * Show the user's design stylesheet
- *
- * @return nothing
- */
-
- function showStylesheets()
- {
- parent::showStylesheets();
-
- $user = common_current_user();
-
- if (empty($user) || $user->viewdesigns) {
- $design = $this->getDesign();
-
- if (!empty($design)) {
- $design->showCSS($this);
- }
- }
- }
-
/**
* A design for this action
*
- * if the user attribute has been set, returns that user's
- * design.
+ * Returns the design preferences for the current user.
*
* @return Design a design object to use
*/
@@ -82,11 +59,15 @@ class CurrentUserDesignAction extends Action
{
$cur = common_current_user();
- if (empty($cur)) {
- return null;
+ if (!empty($cur)) {
+
+ $design = $cur->getDesign();
+
+ if (!empty($design)) {
+ return $design;
+ }
}
- return $cur->getDesign();
+ return parent::getDesign();
}
-
}
diff --git a/lib/groupdesignaction.php b/lib/groupdesignaction.php
index 58777c283..c7cdff1fe 100644
--- a/lib/groupdesignaction.php
+++ b/lib/groupdesignaction.php
@@ -50,26 +50,6 @@ class GroupDesignAction extends Action {
var $group = null;
/**
- * Show the groups's design stylesheet
- *
- * @return nothing
- */
- function showStylesheets()
- {
- parent::showStylesheets();
-
- $user = common_current_user();
-
- if (empty($user) || $user->viewdesigns) {
- $design = $this->getDesign();
-
- if (!empty($design)) {
- $design->showCSS($this);
- }
- }
- }
-
- /**
* A design for this action
*
* if the group attribute has been set, returns that group's
@@ -80,10 +60,12 @@ class GroupDesignAction extends Action {
function getDesign()
{
- if (empty($this->group)) {
- return null;
+ if (!empty($this->group)) {
+ $design = $this->group->getDesign();
+ if (!empty($design)) {
+ return $design;
+ }
}
-
- return $this->group->getDesign();
+ return parent::getDesign();
}
}
diff --git a/lib/ownerdesignaction.php b/lib/ownerdesignaction.php
index 785b8a93d..b42df926d 100644
--- a/lib/ownerdesignaction.php
+++ b/lib/ownerdesignaction.php
@@ -53,26 +53,6 @@ class OwnerDesignAction extends Action {
var $user = null;
/**
- * Show the owner's design stylesheet
- *
- * @return nothing
- */
- function showStylesheets()
- {
- parent::showStylesheets();
-
- $user = common_current_user();
-
- if (empty($user) || $user->viewdesigns) {
- $design = $this->getDesign();
-
- if (!empty($design)) {
- $design->showCSS($this);
- }
- }
- }
-
- /**
* A design for this action
*
* if the user attribute has been set, returns that user's
@@ -83,10 +63,15 @@ class OwnerDesignAction extends Action {
function getDesign()
{
- if (empty($this->user)) {
- return null;
+ if (!empty($this->user)) {
+
+ $design = $this->user->getDesign();
+
+ if (!empty($design)) {
+ return $design;
+ }
}
- return $this->user->getDesign();
+ return parent::getDesign();
}
}