From 0b6994516c91890753a1b18404f77a60de543980 Mon Sep 17 00:00:00 2001 From: Dan Moore Date: Fri, 5 Jun 2009 01:01:25 -0400 Subject: Cleaning up comments at top of favor.php. --- actions/favor.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/actions/favor.php b/actions/favor.php index 3b7d979eb..a7aff87f2 100644 --- a/actions/favor.php +++ b/actions/favor.php @@ -12,8 +12,6 @@ * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 * @link http://laconi.ca/ * - -/* * Laconica - a distributed open-source microblogging tool * Copyright (C) 2008, Controlez-Vous, Inc. * -- cgit v1.2.3-54-g00ecf From 40e05a3e86559bb9bd7094519003d3c7d90501a5 Mon Sep 17 00:00:00 2001 From: Dan Moore Date: Fri, 5 Jun 2009 12:53:17 -0400 Subject: Bringing users/show in line with Twitter as far as specifying user. --- actions/twitapiusers.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/actions/twitapiusers.php b/actions/twitapiusers.php index b90bbfa98..0461efcb4 100644 --- a/actions/twitapiusers.php +++ b/actions/twitapiusers.php @@ -35,20 +35,13 @@ class TwitapiusersAction extends TwitterapiAction $user = null; $email = $this->arg('email'); - $user_id = $this->arg('user_id'); // XXX: email field deprecated in Twitter's API - // XXX: Also: need to add screen_name param - if ($email) { $user = User::staticGet('email', $email); - } elseif ($user_id) { - $user = $this->get_user($user_id); - } elseif (isset($apidata['api_arg'])) { + } else { $user = $this->get_user($apidata['api_arg']); - } elseif (isset($apidata['user'])) { - $user = $apidata['user']; } if (!$user) { -- cgit v1.2.3-54-g00ecf From 10d4191bd103d177734ce4cf8006cd7af88e139b Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Thu, 11 Jun 2009 13:07:41 +0000 Subject: Add site-wide option to change the length at which URLs are auto-shortened --- README | 3 +++ lib/Shorturl_api.php | 2 +- lib/common.php | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README b/README index 769c416d3..679a096b3 100644 --- a/README +++ b/README @@ -901,6 +901,9 @@ sslserver: use an alternate server name for SSL URLs, like parameters correctly so that both the SSL server and the "normal" server can access the session cookie and preferably other cookies as well. +shorturllength: Length of URL at which URLs in a message exceeding 140 + characters will be sent to the user's chosen + shortening service. db -- diff --git a/lib/Shorturl_api.php b/lib/Shorturl_api.php index fe106cb83..d1fc5eb6d 100644 --- a/lib/Shorturl_api.php +++ b/lib/Shorturl_api.php @@ -39,7 +39,7 @@ class ShortUrlApi } private function is_long($url) { - return strlen($url) >= 30; + return strlen($url) >= common_config('site', 'shorturllength'); } protected function http_post($data) { diff --git a/lib/common.php b/lib/common.php index 01d2c78ea..151b31d80 100644 --- a/lib/common.php +++ b/lib/common.php @@ -89,6 +89,7 @@ $config = 'private' => false, 'ssl' => 'never', 'sslserver' => null, + 'shorturllength' => 30, 'dupelimit' => 60), # default for same person saying the same thing 'syslog' => array('appname' => 'laconica', # for syslog -- cgit v1.2.3-54-g00ecf From 91684830e55dd0e6a9e069ff140e17a929dd2364 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Mon, 6 Jul 2009 15:49:26 -0700 Subject: fix bad function call --- actions/twitapiusers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/twitapiusers.php b/actions/twitapiusers.php index 0461efcb4..a47fdfbc3 100644 --- a/actions/twitapiusers.php +++ b/actions/twitapiusers.php @@ -45,7 +45,7 @@ class TwitapiusersAction extends TwitterapiAction } if (!$user) { - $this->client_error(_('Not found.'), 404, $apidata['content-type']); + $this->clientError(_('Not found.'), 404, $apidata['content-type']); return; } -- cgit v1.2.3-54-g00ecf From 8b65883f9ddf1cb1b7bdec323722da351fa0cb69 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 9 Jul 2009 17:28:38 -0700 Subject: cache frequently-used subscriber, subscription, notice and fave count values --- classes/Notice.php | 2 + classes/Profile.php | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++ classes/User.php | 2 + lib/command.php | 15 ++---- lib/profileaction.php | 21 +++------ lib/subs.php | 13 +++-- lib/twitterapi.php | 20 ++------ 7 files changed, 157 insertions(+), 44 deletions(-) diff --git a/classes/Notice.php b/classes/Notice.php index e975cab93..75044cf63 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -356,6 +356,8 @@ class Notice extends Memcached_DataObject $this->blowTagCache($blowLast); $this->blowGroupCache($blowLast); $this->blowConversationCache($blowLast); + $profile = Profile::staticGet($this->profile_id); + $profile->blowNoticeCount(); } function blowConversationCache($blowLast=false) diff --git a/classes/Profile.php b/classes/Profile.php index a0ed6b3ca..224b61bd2 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -337,4 +337,132 @@ class Profile extends Memcached_DataObject return $profile; } + + function subscriptionCount() + { + $c = common_memcache(); + + if (!empty($c)) { + $cnt = $c->get(common_cache_key('profile:subscription_count:'.$this->id)); + if (is_integer($cnt)) { + return (int) $cnt; + } + } + + $sub = new Subscription(); + $sub->subscriber = $this->id; + + $cnt = (int) $sub->count('distinct subscribed'); + + $cnt = ($cnt > 0) ? $cnt - 1 : $cnt; + + if (!empty($c)) { + $c->set(common_cache_key('profile:subscription_count:'.$this->id), $cnt); + } + + common_debug("subscriptionCount == $cnt"); + return $cnt; + } + + function subscriberCount() + { + $c = common_memcache(); + if (!empty($c)) { + $cnt = $c->get(common_cache_key('profile:subscriber_count:'.$this->id)); + if (is_integer($cnt)) { + return (int) $cnt; + } + } + + $sub = new Subscription(); + $sub->subscribed = $this->id; + + $cnt = (int) $sub->count('distinct subscriber'); + + $cnt = ($cnt > 0) ? $cnt - 1 : $cnt; + + if (!empty($c)) { + $c->set(common_cache_key('profile:subscriber_count:'.$this->id), $cnt); + } + + common_debug("subscriberCount == $cnt"); + return $cnt; + } + + function faveCount() + { + $c = common_memcache(); + if (!empty($c)) { + $cnt = $c->get(common_cache_key('profile:fave_count:'.$this->id)); + if (is_integer($cnt)) { + return (int) $cnt; + } + } + + $faves = new Fave(); + $faves->user_id = $this->id; + $cnt = (int) $faves->count('distinct notice_id'); + + if (!empty($c)) { + $c->set(common_cache_key('profile:fave_count:'.$this->id), $cnt); + } + + common_debug("faveCount == $cnt"); + return $cnt; + } + + function noticeCount() + { + $c = common_memcache(); + + if (!empty($c)) { + $cnt = $c->get(common_cache_key('profile:notice_count:'.$this->id)); + if (is_integer($cnt)) { + return (int) $cnt; + } + } + + $notices = new Notice(); + $notices->profile_id = $this->id; + $cnt = (int) $notices->count('distinct id'); + + if (!empty($c)) { + $c->set(common_cache_key('profile:notice_count:'.$this->id), $cnt); + } + + common_debug("noticeCount == $cnt"); + return $cnt; + } + + function blowSubscriberCount() + { + $c = common_memcache(); + if (!empty($c)) { + $c->delete(common_cache_key('profile:subscriber_count:'.$this->id)); + } + } + + function blowSubscriptionCount() + { + $c = common_memcache(); + if (!empty($c)) { + $c->delete(common_cache_key('profile:subscription_count:'.$this->id)); + } + } + + function blowFaveCount() + { + $c = common_memcache(); + if (!empty($c)) { + $c->delete(common_cache_key('profile:fave_count:'.$this->id)); + } + } + + function blowNoticeCount() + { + $c = common_memcache(); + if (!empty($c)) { + $c->delete(common_cache_key('profile:notice_count:'.$this->id)); + } + } } diff --git a/classes/User.php b/classes/User.php index 04b38a0d2..6c1f149e4 100644 --- a/classes/User.php +++ b/classes/User.php @@ -494,6 +494,8 @@ class User extends Memcached_DataObject $cache->delete(common_cache_key('fave:ids_by_user_own:'.$this->id)); $cache->delete(common_cache_key('fave:ids_by_user_own:'.$this->id.';last')); } + $profile = $this->getProfile(); + $profile->blowFaveCount(); } function getSelfTags() diff --git a/lib/command.php b/lib/command.php index 564661382..4e2280bc8 100644 --- a/lib/command.php +++ b/lib/command.php @@ -97,18 +97,11 @@ class StatsCommand extends Command { function execute($channel) { + $profile = $this->user->getProfile(); - $subs = new Subscription(); - $subs->subscriber = $this->user->id; - $subs_count = (int) $subs->count() - 1; - - $subbed = new Subscription(); - $subbed->subscribed = $this->user->id; - $subbed_count = (int) $subbed->count() - 1; - - $notices = new Notice(); - $notices->profile_id = $this->user->id; - $notice_count = (int) $notices->count(); + $subs_count = $profile->subscriptionCount(); + $subbed_count = $profile->subscriberCount(); + $notice_count = $profile->noticeCount(); $channel->output($this->user, sprintf(_("Subscriptions: %1\$s\n". "Subscribers: %2\$s\n". diff --git a/lib/profileaction.php b/lib/profileaction.php index eeb5dbe48..9e9c79c78 100644 --- a/lib/profileaction.php +++ b/lib/profileaction.php @@ -163,18 +163,9 @@ class ProfileAction extends OwnerDesignAction function showStatistics() { - // XXX: WORM cache this - $subs = new Subscription(); - $subs->subscriber = $this->profile->id; - $subs_count = (int) $subs->count() - 1; - - $subbed = new Subscription(); - $subbed->subscribed = $this->profile->id; - $subbed_count = (int) $subbed->count() - 1; - - $notices = new Notice(); - $notices->profile_id = $this->profile->id; - $notice_count = (int) $notices->count(); + $subs_count = $this->profile->subscriptionCount(); + $subbed_count = $this->profile->subscriberCount(); + $notice_count = $this->profile->noticeCount(); $this->elementStart('div', array('id' => 'entity_statistics', 'class' => 'section')); @@ -199,7 +190,7 @@ class ProfileAction extends OwnerDesignAction array('nickname' => $this->profile->nickname))), _('Subscriptions')); $this->elementEnd('dt'); - $this->element('dd', null, (is_int($subs_count)) ? $subs_count : '0'); + $this->element('dd', null, $subs_count); $this->elementEnd('dl'); $this->elementStart('dl', 'entity_subscribers'); @@ -208,12 +199,12 @@ class ProfileAction extends OwnerDesignAction array('nickname' => $this->profile->nickname))), _('Subscribers')); $this->elementEnd('dt'); - $this->element('dd', 'subscribers', (is_int($subbed_count)) ? $subbed_count : '0'); + $this->element('dd', 'subscribers', $subbed_count); $this->elementEnd('dl'); $this->elementStart('dl', 'entity_notices'); $this->element('dt', null, _('Notices')); - $this->element('dd', null, (is_int($notice_count)) ? $notice_count : '0'); + $this->element('dd', null, $notice_count); $this->elementEnd('dl'); $this->elementEnd('div'); diff --git a/lib/subs.php b/lib/subs.php index 3bd67b39c..e76023752 100644 --- a/lib/subs.php +++ b/lib/subs.php @@ -44,7 +44,6 @@ function subs_subscribe_user($user, $other_nickname) function subs_subscribe_to($user, $other) { - if ($user->isSubscribed($other)) { return _('Already subscribed!.'); } @@ -60,12 +59,16 @@ function subs_subscribe_to($user, $other) subs_notify($other, $user); - $cache = common_memcache(); + $cache = common_memcache(); if ($cache) { $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id)); } + $profile = $user->getProfile(); + + $profile->blowSubscriptionsCount(); + $other->blowSubscribersCount(); if ($other->autosubscribe && !$other->isSubscribed($user) && !$user->hasBlocked($other)) { if (!$other->subscribeTo($user)) { @@ -117,7 +120,6 @@ function subs_unsubscribe_user($user, $other_nickname) function subs_unsubscribe_to($user, $other) { - if (!$user->isSubscribed($other)) return _('Not subscribed!.'); @@ -139,6 +141,11 @@ function subs_unsubscribe_to($user, $other) $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id)); } + $profile = $user->getProfile(); + + $profile->blowSubscriptionsCount(); + $other->blowSubscribersCount(); + return true; } diff --git a/lib/twitterapi.php b/lib/twitterapi.php index 8f902cbca..f48513e67 100644 --- a/lib/twitterapi.php +++ b/lib/twitterapi.php @@ -89,7 +89,7 @@ class TwitterapiAction extends Action $twitter_user['url'] = ($profile->homepage) ? $profile->homepage : null; $twitter_user['protected'] = false; # not supported by Laconica yet - $twitter_user['followers_count'] = $this->count_subscriptions($profile); + $twitter_user['followers_count'] = $profile->subscriberCount(); // To be supported soon... $twitter_user['profile_background_color'] = ''; @@ -98,17 +98,11 @@ class TwitterapiAction extends Action $twitter_user['profile_sidebar_fill_color'] = ''; $twitter_user['profile_sidebar_border_color'] = ''; - $subbed = DB_DataObject::factory('subscription'); - $subbed->subscriber = $profile->id; - $subbed_count = (int) $subbed->count() - 1; - $twitter_user['friends_count'] = (is_int($subbed_count)) ? $subbed_count : 0; + $twitter_user['friends_count'] = $profile->subscriptionCount(); $twitter_user['created_at'] = $this->date_twitter($profile->created); - $faves = DB_DataObject::factory('fave'); - $faves->user_id = $user->id; - $faves_count = (int) $faves->count(); - $twitter_user['favourites_count'] = $faves_count; // British spelling! + $twitter_user['favourites_count'] = $profile->faveCount(); // British spelling! // Need to pull up the user for some of this $user = User::staticGet($profile->id); @@ -129,11 +123,7 @@ class TwitterapiAction extends Action $twitter_user['profile_background_image_url'] = ''; $twitter_user['profile_background_tile'] = false; - $notices = DB_DataObject::factory('notice'); - $notices->profile_id = $profile->id; - $notice_count = (int) $notices->count(); - - $twitter_user['statuses_count'] = (is_int($notice_count)) ? $notice_count : 0; + $twitter_user['statuses_count'] = $profile->noticeCount(); // Is the requesting user following this user? $twitter_user['following'] = false; @@ -396,7 +386,7 @@ class TwitterapiAction extends Action $enclosure = $entry['enclosures'][0]; $this->element('enclosure', array('url'=>$enclosure['url'],'type'=>$enclosure['mimetype'],'length'=>$enclosure['size']), null); } - + $this->elementEnd('item'); } -- cgit v1.2.3-54-g00ecf From f527b8a8d7cf38e21c0ceb8d54cfae2d679e1564 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 9 Jul 2009 17:40:11 -0700 Subject: wrong order for span and a in profilesection --- lib/profilesection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/profilesection.php b/lib/profilesection.php index 8ed290e03..9ff243fb5 100644 --- a/lib/profilesection.php +++ b/lib/profilesection.php @@ -94,8 +94,8 @@ class ProfileSection extends Section $profile->fullname : $profile->nickname)); $this->out->element('span', 'fn nickname', $profile->nickname); - $this->out->elementEnd('span'); $this->out->elementEnd('a'); + $this->out->elementEnd('span'); $this->out->elementEnd('td'); if ($profile->value) { $this->out->element('td', 'value', $profile->value); -- cgit v1.2.3-54-g00ecf From 15f6309deacf64e6b408d45a4eb19852d36f9f72 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 9 Jul 2009 23:12:53 -0700 Subject: add a little syntactical sugar for adding plugins --- lib/common.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/common.php b/lib/common.php index 832667d81..c47702779 100644 --- a/lib/common.php +++ b/lib/common.php @@ -282,6 +282,39 @@ if (function_exists('date_default_timezone_set')) { date_default_timezone_set('UTC'); } +function addPlugin($name, $attrs = null) +{ + $name = ucfirst($name); + $pluginclass = "{$name}Plugin"; + + if (!class_exists($pluginclass)) { + + $files = array("local/plugins/{$pluginclass}.php", + "local/plugins/{$name}/{$pluginclass}.php", + "local/{$pluginclass}.php", + "local/{$name}/{$pluginclass}.php", + "plugins/{$pluginclass}.php", + "plugins/{$name}/{$pluginclass}.php"); + + foreach ($files as $file) { + $fullpath = INSTALLDIR.'/'.$file; + if (@file_exists($fullpath)) { + include_once($fullpath); + break; + } + } + } + + $inst = new $pluginclass(); + + if (!empty($attrs)) { + foreach ($attrs as $aname => $avalue) { + $inst->$aname = $avalue; + } + } + return $inst; +} + // From most general to most specific: // server-wide, then vhost-wide, then for a path, // finally for a dir (usually only need one of the last two). -- cgit v1.2.3-54-g00ecf