From 042c61ed6de1bbc993eefe47552028157f3e1e28 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Fri, 13 Mar 2009 13:21:35 +0100 Subject: Piwik Analytics Plugin This is a rewrite of the Google Analytics Plugin to support Piwik. --- plugins/PiwikAnalyticsPlugin.php | 86 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 plugins/PiwikAnalyticsPlugin.php diff --git a/plugins/PiwikAnalyticsPlugin.php b/plugins/PiwikAnalyticsPlugin.php new file mode 100644 index 000000000..458b577fa --- /dev/null +++ b/plugins/PiwikAnalyticsPlugin.php @@ -0,0 +1,86 @@ +. + * + * @category Plugin + * @package Laconica + * @author Evan Prodromou + * @copyright 2008 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Plugin to use Piwik Analytics (based on the Google Analytics plugin by Evan) + * + * This plugin will spoot out the correct JavaScript spell to invoke Piwik Analytics on a page. + * + * To use this plugin please add the following three lines to your config.php +#Add Piwik Analytics +require_once('plugins/PiwikAnalyticsPlugin.php'); +$pa = new PiwikAnalyticsPlugin("example.com/piwik/","id"); + * + * exchange example.com/piwik/ with the url (without http:// or https:// !) to your + * piwik installation and make sure you don't forget the final / + * exchange id with the ID your laconica installation has in your Piwik analytics + * + * @category Plugin + * @package Laconica + * @author Tobias Diekershoff + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see Event + */ + +class PiwikAnalyticsPlugin extends Plugin +{ + // the base of your Piwik installation + var $piwikroot = null; + // the Piwik Id of your laconica installation + var $piwikId = null; + + function __construct($root=null, $id=null) + { + $this->piwikroot = $root; + $this->piwikid = $id; + parent::__construct(); + } + + function onEndShowScripts($action) + { + $js1 = 'var pkBaseURL = (("https:" == document.location.protocol) ? "https://'. + $this->piwikroot.'" : "http://'.$this->piwikroot. + '"); document.write(unescape("%3Cscript src=\'" + pkBaseURL + "piwik.js\''. + ' type=\'text/javascript\'%3E%3C/script%3E"));'; + $js2 = 'piwik_action_name = ""; piwik_idsite = '.$this->piwikid. + '; piwik_url = pkBaseURL + "piwik.php"; piwik_log(piwik_action_name, piwik_idsite, piwik_url);'; + $action->elementStart('script', array('type' => 'text/javascript')); + $action->raw($js1); + $action->elementEnd('script'); + $action->elementStart('script', array('type' => 'text/javascript')); + $action->raw($js2); + $action->elementEnd('script'); + } +} \ No newline at end of file -- cgit v1.2.3-54-g00ecf From 492704ba441dc0a3c1eca55d37d220e8ee3ed607 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 10 Apr 2009 22:47:40 -0400 Subject: tag stream is read-only --- actions/tag.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/actions/tag.php b/actions/tag.php index d15f64498..c413bf8c3 100644 --- a/actions/tag.php +++ b/actions/tag.php @@ -86,4 +86,9 @@ class TagAction extends Action $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE, $this->page, 'tag', array('tag' => $this->tag)); } + + function isReadOnly() + { + return true; + } } -- cgit v1.2.3-54-g00ecf From d1458a691414e7a01c60c29fbd7ff2bc1c67bbdc Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 12 Apr 2009 15:34:38 -0400 Subject: Update XML generation and list of actions in public XRDS Updated the XML generation calls and list of actions in the public XRDS document. --- actions/publicxrds.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/actions/publicxrds.php b/actions/publicxrds.php index aad59d779..2c52f1246 100644 --- a/actions/publicxrds.php +++ b/actions/publicxrds.php @@ -51,7 +51,7 @@ class PublicxrdsAction extends Action { /** * Is read only? - * + * * @return boolean true */ function isReadOnly() @@ -61,7 +61,7 @@ class PublicxrdsAction extends Action /** * Class handler. - * + * * @param array $args array of arguments * * @return nothing @@ -70,24 +70,24 @@ class PublicxrdsAction extends Action { parent::handle($args); header('Content-Type: application/xrds+xml'); - common_start_xml(); + $this->startXML(); $this->elementStart('XRDS', array('xmlns' => 'xri://$xrds')); $this->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)', 'xmlns:simple' => 'http://xrds-simple.net/core/1.0', 'version' => '2.0')); $this->element('Type', null, 'xri://$xrds*simple'); - foreach (array('finishopenidlogin', 'finishaddopenid', 'finishimmediate') as $finish) { + foreach (array('finishopenidlogin', 'finishaddopenid') as $finish) { $this->showService(Auth_OpenID_RP_RETURN_TO_URL_TYPE, common_local_url($finish)); } $this->elementEnd('XRD'); $this->elementEnd('XRDS'); - common_end_xml(); + $this->endXML(); } /** * Show service. - * + * * @param string $type XRDS type * @param string $uri URI * @param array $params type parameters, null by default -- cgit v1.2.3-54-g00ecf From 7f81597a8146e0fa5f062cf42a30c86914877ec5 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 13 Apr 2009 15:49:26 -0400 Subject: isReadOnly() now takes arguments Add an array of arguments to isReadOnly() method of actions, to let them change their results depending on what actions are called. Primarily used by the 'api' action. Ideally in the future that will be multiple actions. But this might still be useful. --- actions/all.php | 2 +- actions/api.php | 13 ++++++------- actions/avatarbynickname.php | 2 +- actions/doc.php | 2 +- actions/favorited.php | 2 +- actions/featured.php | 2 +- actions/foaf.php | 2 +- actions/groupbyid.php | 2 +- actions/groupmembers.php | 2 +- actions/grouprss.php | 2 +- actions/groups.php | 2 +- actions/invite.php | 2 +- actions/login.php | 2 +- actions/logout.php | 2 +- actions/microsummary.php | 2 +- actions/noticesearchrss.php | 2 +- actions/nudge.php | 2 +- actions/opensearch.php | 2 +- actions/public.php | 2 +- actions/publicrss.php | 2 +- actions/publictagcloud.php | 2 +- actions/publicxrds.php | 2 +- actions/replies.php | 2 +- actions/repliesrss.php | 2 +- actions/requesttoken.php | 2 +- actions/showfavorites.php | 2 +- actions/showgroup.php | 2 +- actions/showmessage.php | 2 +- actions/shownotice.php | 2 +- actions/showstream.php | 2 +- actions/subscribers.php | 2 +- actions/sup.php | 2 +- actions/tag.php | 2 +- actions/tagrss.php | 2 +- actions/twitapisearchjson.php | 2 +- actions/userbyid.php | 2 +- actions/usergroups.php | 2 +- actions/userrss.php | 2 +- actions/xrds.php | 2 +- index.php | 2 +- lib/action.php | 5 ++++- lib/error.php | 2 +- lib/galleryaction.php | 2 +- lib/peoplesearchresults.php | 2 +- lib/personal.php | 2 +- lib/searchaction.php | 2 +- 46 files changed, 54 insertions(+), 52 deletions(-) diff --git a/actions/all.php b/actions/all.php index f5bbfe2e3..69890a70c 100644 --- a/actions/all.php +++ b/actions/all.php @@ -25,7 +25,7 @@ require_once INSTALLDIR.'/lib/feedlist.php'; class AllAction extends ProfileAction { - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/api.php b/actions/api.php index c18d551b6..e40a18798 100644 --- a/actions/api.php +++ b/actions/api.php @@ -134,8 +134,8 @@ class ApiAction extends Action 'favorites/favorites'); $fullname = "$this->api_action/$this->api_method"; - - // If the site is "private", all API methods except laconica/config + + // If the site is "private", all API methods except laconica/config // need authentication if (common_config('site', 'private')) { return $fullname != 'laconica/config' || false; @@ -180,11 +180,11 @@ class ApiAction extends Action } } - function isReadOnly() + function isReadOnly($args)($args) { - # NOTE: before handle(), can't use $this->arg - $apiaction = $_REQUEST['apiaction']; - $method = $_REQUEST['method']; + $apiaction = $args['apiaction']; + $method = $args['method']; + list($cmdtext, $fmt) = explode('.', $method); static $write_methods = array( @@ -207,5 +207,4 @@ class ApiAction extends Action return false; } - } diff --git a/actions/avatarbynickname.php b/actions/avatarbynickname.php index ca58c9653..e92a99372 100644 --- a/actions/avatarbynickname.php +++ b/actions/avatarbynickname.php @@ -98,7 +98,7 @@ class AvatarbynicknameAction extends Action common_redirect($url, 302); } - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/doc.php b/actions/doc.php index ebffb7c15..e6508030b 100644 --- a/actions/doc.php +++ b/actions/doc.php @@ -108,7 +108,7 @@ class DocAction extends Action return ucfirst($this->title); } - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/favorited.php b/actions/favorited.php index 09ab1216a..c902d80f5 100644 --- a/actions/favorited.php +++ b/actions/favorited.php @@ -85,7 +85,7 @@ class FavoritedAction extends Action * @return boolean true */ - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/featured.php b/actions/featured.php index 86fd3f374..79eba2aa6 100644 --- a/actions/featured.php +++ b/actions/featured.php @@ -50,7 +50,7 @@ class FeaturedAction extends Action { var $page = null; - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/foaf.php b/actions/foaf.php index 416935b1b..2d5b78d12 100644 --- a/actions/foaf.php +++ b/actions/foaf.php @@ -25,7 +25,7 @@ define('BOTH', 0); class FoafAction extends Action { - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/groupbyid.php b/actions/groupbyid.php index 678119a94..7d327d56c 100644 --- a/actions/groupbyid.php +++ b/actions/groupbyid.php @@ -59,7 +59,7 @@ class GroupbyidAction extends Action * @return boolean true */ - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/groupmembers.php b/actions/groupmembers.php index 00f43a9f5..a90108e4d 100644 --- a/actions/groupmembers.php +++ b/actions/groupmembers.php @@ -48,7 +48,7 @@ class GroupmembersAction extends Action { var $page = null; - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/grouprss.php b/actions/grouprss.php index de76a5960..a9a2eef87 100644 --- a/actions/grouprss.php +++ b/actions/grouprss.php @@ -57,7 +57,7 @@ class groupRssAction extends Rss10Action * @return boolean true */ - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/groups.php b/actions/groups.php index 39dc2232b..26b52a5fc 100644 --- a/actions/groups.php +++ b/actions/groups.php @@ -51,7 +51,7 @@ class GroupsAction extends Action var $page = null; var $profile = null; - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/invite.php b/actions/invite.php index df6e3b714..7e52cdbcc 100644 --- a/actions/invite.php +++ b/actions/invite.php @@ -27,7 +27,7 @@ class InviteAction extends Action var $subbed = null; var $sent = null; - function isReadOnly() + function isReadOnly($args) { return false; } diff --git a/actions/login.php b/actions/login.php index 59c6b4874..50de83f6f 100644 --- a/actions/login.php +++ b/actions/login.php @@ -55,7 +55,7 @@ class LoginAction extends Action * @return boolean false */ - function isReadOnly() + function isReadOnly($args) { return false; } diff --git a/actions/logout.php b/actions/logout.php index b7681be38..9f3bfe247 100644 --- a/actions/logout.php +++ b/actions/logout.php @@ -52,7 +52,7 @@ class LogoutAction extends Action * * @return boolean true */ - function isReadOnly() + function isReadOnly($args) { return false; } diff --git a/actions/microsummary.php b/actions/microsummary.php index 065a2e0eb..0b408ec95 100644 --- a/actions/microsummary.php +++ b/actions/microsummary.php @@ -74,7 +74,7 @@ class MicrosummaryAction extends Action print $user->nickname . ': ' . $notice->content; } - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/noticesearchrss.php b/actions/noticesearchrss.php index ba5276d06..f6da969ee 100644 --- a/actions/noticesearchrss.php +++ b/actions/noticesearchrss.php @@ -92,7 +92,7 @@ class NoticesearchrssAction extends Rss10Action return null; } - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/nudge.php b/actions/nudge.php index b4e5e01dd..c23d3e643 100644 --- a/actions/nudge.php +++ b/actions/nudge.php @@ -124,7 +124,7 @@ class NudgeAction extends Action } } - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/opensearch.php b/actions/opensearch.php index 2eb818306..d1f4895ce 100644 --- a/actions/opensearch.php +++ b/actions/opensearch.php @@ -84,7 +84,7 @@ class OpensearchAction extends Action $this->endXML(); } - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/public.php b/actions/public.php index 5a380de9a..27153f131 100644 --- a/actions/public.php +++ b/actions/public.php @@ -56,7 +56,7 @@ class PublicAction extends Action var $page = null; - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/publicrss.php b/actions/publicrss.php index 77e26e0f4..bc52f2952 100644 --- a/actions/publicrss.php +++ b/actions/publicrss.php @@ -102,7 +102,7 @@ class PublicrssAction extends Rss10Action // nop } - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/publictagcloud.php b/actions/publictagcloud.php index 855cfed9b..e9f33d58b 100644 --- a/actions/publictagcloud.php +++ b/actions/publictagcloud.php @@ -47,7 +47,7 @@ define('TAGS_PER_PAGE', 100); class PublictagcloudAction extends Action { - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/publicxrds.php b/actions/publicxrds.php index 2c52f1246..283a932ca 100644 --- a/actions/publicxrds.php +++ b/actions/publicxrds.php @@ -54,7 +54,7 @@ class PublicxrdsAction extends Action * * @return boolean true */ - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/replies.php b/actions/replies.php index 2769cb422..eac4d0a3a 100644 --- a/actions/replies.php +++ b/actions/replies.php @@ -196,7 +196,7 @@ class RepliesAction extends Action $this->elementEnd('div'); } - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/repliesrss.php b/actions/repliesrss.php index 985318bf1..2017c4309 100644 --- a/actions/repliesrss.php +++ b/actions/repliesrss.php @@ -83,7 +83,7 @@ class RepliesrssAction extends Rss10Action return ($avatar) ? $avatar->url : null; } - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/requesttoken.php b/actions/requesttoken.php index ca253b97a..fb577fdd5 100644 --- a/actions/requesttoken.php +++ b/actions/requesttoken.php @@ -52,7 +52,7 @@ class RequesttokenAction extends Action * * @return boolean false */ - function isReadOnly() + function isReadOnly($args) { return false; } diff --git a/actions/showfavorites.php b/actions/showfavorites.php index 4d4349505..e8cf1cb01 100644 --- a/actions/showfavorites.php +++ b/actions/showfavorites.php @@ -58,7 +58,7 @@ class ShowfavoritesAction extends Action * @return boolean true */ - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/showgroup.php b/actions/showgroup.php index 79445851f..7e86a79f1 100644 --- a/actions/showgroup.php +++ b/actions/showgroup.php @@ -60,7 +60,7 @@ class ShowgroupAction extends Action * @return boolean true */ - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/showmessage.php b/actions/showmessage.php index 572a71739..4fcaadbe8 100644 --- a/actions/showmessage.php +++ b/actions/showmessage.php @@ -177,7 +177,7 @@ class ShowmessageAction extends MailboxAction return ''; } - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/shownotice.php b/actions/shownotice.php index ccae49bb3..2c469c9de 100644 --- a/actions/shownotice.php +++ b/actions/shownotice.php @@ -106,7 +106,7 @@ class ShownoticeAction extends Action * @return boolean true */ - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/showstream.php b/actions/showstream.php index ce237dae2..c1a2c337a 100644 --- a/actions/showstream.php +++ b/actions/showstream.php @@ -56,7 +56,7 @@ require_once INSTALLDIR.'/lib/feedlist.php'; class ShowstreamAction extends ProfileAction { - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/subscribers.php b/actions/subscribers.php index 7ebb54d33..d91a7d4fd 100644 --- a/actions/subscribers.php +++ b/actions/subscribers.php @@ -130,7 +130,7 @@ class SubscribersList extends ProfileList $bf->show(); } - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/sup.php b/actions/sup.php index 246b3299d..691153d6a 100644 --- a/actions/sup.php +++ b/actions/sup.php @@ -79,7 +79,7 @@ class SupAction extends Action return $updates; } - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/tag.php b/actions/tag.php index c413bf8c3..7f82c2a58 100644 --- a/actions/tag.php +++ b/actions/tag.php @@ -87,7 +87,7 @@ class TagAction extends Action $this->page, 'tag', array('tag' => $this->tag)); } - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/tagrss.php b/actions/tagrss.php index a77fa12c9..83cf3afe2 100644 --- a/actions/tagrss.php +++ b/actions/tagrss.php @@ -65,7 +65,7 @@ class TagrssAction extends Rss10Action return $c; } - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/twitapisearchjson.php b/actions/twitapisearchjson.php index 0f9f523a1..b0e3be687 100644 --- a/actions/twitapisearchjson.php +++ b/actions/twitapisearchjson.php @@ -142,7 +142,7 @@ class TwitapisearchjsonAction extends TwitterapiAction * @return boolean true */ - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/userbyid.php b/actions/userbyid.php index 1e30d1aac..4a985fcd7 100644 --- a/actions/userbyid.php +++ b/actions/userbyid.php @@ -50,7 +50,7 @@ class UserbyidAction extends Action * * @return boolean true */ - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/usergroups.php b/actions/usergroups.php index 06b2334bf..e3088dcbd 100644 --- a/actions/usergroups.php +++ b/actions/usergroups.php @@ -52,7 +52,7 @@ class UsergroupsAction extends Action var $page = null; var $profile = null; - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/userrss.php b/actions/userrss.php index d3bf352d8..5861d9ee3 100644 --- a/actions/userrss.php +++ b/actions/userrss.php @@ -96,7 +96,7 @@ class UserrssAction extends Rss10Action parent::initRss($limit); } - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/actions/xrds.php b/actions/xrds.php index 075831803..1335b6b80 100644 --- a/actions/xrds.php +++ b/actions/xrds.php @@ -52,7 +52,7 @@ class XrdsAction extends Action * * @return boolean true */ - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/index.php b/index.php index e83d08c13..e24bde917 100644 --- a/index.php +++ b/index.php @@ -128,7 +128,7 @@ function main() // XXX: find somewhere for this little block to live - if (common_config('db', 'mirror') && $action_obj->isReadOnly()) { + if (common_config('db', 'mirror') && $action_obj->isReadOnly($args)) { if (is_array(common_config('db', 'mirror'))) { // "load balancing", ha ha $arr = common_config('db', 'mirror'); diff --git a/lib/action.php b/lib/action.php index cc98d4445..673549246 100644 --- a/lib/action.php +++ b/lib/action.php @@ -791,9 +791,12 @@ class Action extends HTMLOutputter // lawsuit * * MAY override * + * @param array $args other arguments + * * @return boolean is read only action? */ - function isReadOnly() + + function isReadOnly($args)($args) { return false; } diff --git a/lib/error.php b/lib/error.php index 526d9f81b..282682133 100644 --- a/lib/error.php +++ b/lib/error.php @@ -93,7 +93,7 @@ class ErrorAction extends Action return $this->message; } - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/lib/galleryaction.php b/lib/galleryaction.php index 8e21d7393..0484918ce 100644 --- a/lib/galleryaction.php +++ b/lib/galleryaction.php @@ -76,7 +76,7 @@ class GalleryAction extends Action return true; } - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/lib/peoplesearchresults.php b/lib/peoplesearchresults.php index f8ab7cf3b..d3f840852 100644 --- a/lib/peoplesearchresults.php +++ b/lib/peoplesearchresults.php @@ -67,7 +67,7 @@ class PeopleSearchResults extends ProfileList return preg_replace($this->pattern, '\\1', htmlspecialchars($text)); } - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/lib/personal.php b/lib/personal.php index e46350c63..f92732375 100644 --- a/lib/personal.php +++ b/lib/personal.php @@ -47,7 +47,7 @@ class PersonalAction extends Action var $user = null; - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/lib/searchaction.php b/lib/searchaction.php index e7ad4affd..e74450e11 100644 --- a/lib/searchaction.php +++ b/lib/searchaction.php @@ -51,7 +51,7 @@ class SearchAction extends Action * * @return boolean true */ - function isReadOnly() + function isReadOnly($args) { return true; } -- cgit v1.2.3-54-g00ecf From a801ee08437a988ebab32b3c92a7380667b446b6 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 13 Apr 2009 15:52:15 -0400 Subject: typo in api.php --- actions/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/api.php b/actions/api.php index e40a18798..d2f0a2eff 100644 --- a/actions/api.php +++ b/actions/api.php @@ -180,7 +180,7 @@ class ApiAction extends Action } } - function isReadOnly($args)($args) + function isReadOnly($args) { $apiaction = $args['apiaction']; $method = $args['method']; -- cgit v1.2.3-54-g00ecf From 1bae34e24fe87ed1abcd5c27e183e8a826fbf775 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 13 Apr 2009 15:54:16 -0400 Subject: typo in lib action --- lib/action.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/action.php b/lib/action.php index 673549246..1ba062812 100644 --- a/lib/action.php +++ b/lib/action.php @@ -796,7 +796,7 @@ class Action extends HTMLOutputter // lawsuit * @return boolean is read only action? */ - function isReadOnly($args)($args) + function isReadOnly($args) { return false; } -- cgit v1.2.3-54-g00ecf From ad5dd9030bf919dba95e1ca066acef71a2d3e6bd Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Mon, 13 Apr 2009 19:19:26 -0700 Subject: Add option to Twitter settings for importing Friends Timeline --- actions/twittersettings.php | 21 +++++++++++++++------ classes/Foreign_link.php | 10 ++++++++-- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/actions/twittersettings.php b/actions/twittersettings.php index 45725d3ff..580d9ecf7 100644 --- a/actions/twittersettings.php +++ b/actions/twittersettings.php @@ -138,7 +138,7 @@ class TwittersettingsAction extends ConnectSettingsAction $this->elementStart('ul', 'form_data'); $this->elementStart('li'); - $this->checkbox('noticesync', + $this->checkbox('noticesend', _('Automatically send my notices to Twitter.'), ($flink) ? ($flink->noticesync & FOREIGN_NOTICE_SEND) : @@ -158,6 +158,13 @@ class TwittersettingsAction extends ConnectSettingsAction ($flink->friendsync & FOREIGN_FRIEND_RECV) : false); $this->elementEnd('li'); + $this->elementStart('li'); + $this->checkbox('noticerecv', + _('Import my Friends Timeline.'), + ($flink) ? + ($flink->noticesync & FOREIGN_NOTICE_RECV) : + false); + $this->elementEnd('li'); $this->elementEnd('ul'); if ($flink) { @@ -261,7 +268,7 @@ class TwittersettingsAction extends ConnectSettingsAction 'alt' => ($other->fullname) ? $other->fullname : $other->nickname)); - + $this->element('span', 'fn nickname', $other->nickname); $this->elementEnd('a'); $this->elementEnd('li'); @@ -320,7 +327,8 @@ class TwittersettingsAction extends ConnectSettingsAction { $screen_name = $this->trimmed('twitter_username'); $password = $this->trimmed('twitter_password'); - $noticesync = $this->boolean('noticesync'); + $noticesend = $this->boolean('noticesend'); + $noticerecv = $this->boolean('noticerecv'); $replysync = $this->boolean('replysync'); $friendsync = $this->boolean('friendsync'); @@ -363,7 +371,7 @@ class TwittersettingsAction extends ConnectSettingsAction $flink->credentials = $password; $flink->created = common_sql_now(); - $flink->set_flags($noticesync, $replysync, $friendsync); + $flink->set_flags($noticesend, $noticerecv, $replysync, $friendsync); $flink_id = $flink->insert(); @@ -419,7 +427,8 @@ class TwittersettingsAction extends ConnectSettingsAction function savePreferences() { - $noticesync = $this->boolean('noticesync'); + $noticesend = $this->boolean('noticesend'); + $noticerecv = $this->boolean('noticerecv'); $friendsync = $this->boolean('friendsync'); $replysync = $this->boolean('replysync'); @@ -448,7 +457,7 @@ class TwittersettingsAction extends ConnectSettingsAction $original = clone($flink); - $flink->set_flags($noticesync, $replysync, $friendsync); + $flink->set_flags($noticesend, $noticerecv, $replysync, $friendsync); $result = $flink->update($original); diff --git a/classes/Foreign_link.php b/classes/Foreign_link.php index afc0e2180..5d9c82a85 100644 --- a/classes/Foreign_link.php +++ b/classes/Foreign_link.php @@ -57,13 +57,19 @@ class Foreign_link extends Memcached_DataObject return null; } - function set_flags($noticesync, $replysync, $friendsync) + function set_flags($noticesend, $noticerecv, $replysync, $friendsync) { - if ($noticesync) { + if ($noticesend) { $this->noticesync |= FOREIGN_NOTICE_SEND; } else { $this->noticesync &= ~FOREIGN_NOTICE_SEND; } + + if ($noticerecv) { + $this->noticesync |= FOREIGN_NOTICE_RECV; + } else { + $this->noticesync &= ~FOREIGN_NOTICE_RECV; + } if ($replysync) { $this->noticesync |= FOREIGN_NOTICE_SEND_REPLY; -- cgit v1.2.3-54-g00ecf From cd9a24798001cfa5e6ecfbfbccc5c0ce07726846 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Mon, 13 Apr 2009 15:03:34 -0700 Subject: Fix bad dates in API's JSON search results --- lib/jsonsearchresultslist.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jsonsearchresultslist.php b/lib/jsonsearchresultslist.php index 0cdcf0c51..f786c20a8 100644 --- a/lib/jsonsearchresultslist.php +++ b/lib/jsonsearchresultslist.php @@ -232,7 +232,7 @@ class ResultItem $this->profile_image_url = ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE); - $this->created_at = date('r', $this->notice->created); + $this->created_at = common_date_rfc2822($this->notice->created); } /** -- cgit v1.2.3-54-g00ecf From 98f6bbb90c8513330a4c382ef80972d861096858 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 14 Apr 2009 16:01:02 -0400 Subject: escape slash in regexp --- plugins/LinkbackPlugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/LinkbackPlugin.php b/plugins/LinkbackPlugin.php index 56a26176b..881ead99e 100644 --- a/plugins/LinkbackPlugin.php +++ b/plugins/LinkbackPlugin.php @@ -99,7 +99,7 @@ class LinkbackPlugin extends Plugin if (array_key_exists('X-Pingback', $result->headers)) { $pb = $result->headers['X-Pingback']; - } else if (preg_match('//', + } else if (preg_match('//', $result->body, $match)) { $pb = $match[1]; -- cgit v1.2.3-54-g00ecf From ff7d71181038ba1e97e9bbcaa7901638aa715574 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 15 Apr 2009 10:05:16 -0400 Subject: add user id to statistics --- lib/profileaction.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/profileaction.php b/lib/profileaction.php index c81924e31..1f2e30994 100644 --- a/lib/profileaction.php +++ b/lib/profileaction.php @@ -179,6 +179,11 @@ class ProfileAction extends Action $this->element('h2', null, _('Statistics')); // Other stats...? + $this->elementStart('dl', 'entity_user-id'); + $this->element('dt', null, _('User ID')); + $this->element('dd', null, $this->profile->id); + $this->elementEnd('dl'); + $this->elementStart('dl', 'entity_member-since'); $this->element('dt', null, _('Member since')); $this->element('dd', null, date('j M Y', -- cgit v1.2.3-54-g00ecf From 3081b2e31708520e6ed83041ce3ba04329d3ec90 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 16 Apr 2009 08:44:48 -0400 Subject: start of querybyid --- classes/User.php | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/classes/User.php b/classes/User.php index 3b9b5cd83..098381f73 100644 --- a/classes/User.php +++ b/classes/User.php @@ -444,21 +444,42 @@ class User extends Memcached_DataObject 'SELECT notice.* ' . 'FROM notice JOIN subscription ON notice.profile_id = subscription.subscribed ' . 'WHERE subscription.subscriber = %d '; - $order = null; + return Notice::getStream(sprintf($qry, $this->id), + 'user:notices_with_friends:' . $this->id, + $offset, $limit, $since_id, $before_id, + $order, $since); } else if ($enabled === true || ($enabled == 'transitional' && $this->inboxed == 1)) { - $qry = - 'SELECT notice.* ' . - 'FROM notice JOIN notice_inbox ON notice.id = notice_inbox.notice_id ' . - 'WHERE notice_inbox.user_id = %d '; - // NOTE: we override ORDER - $order = null; + $cache = common_memcache(); + + if (!empty($cache)) { + + # Get the notices out of the cache + + $notices = $cache->get(common_cache_key($cachekey)); + + # On a cache hit, return a DB-object-like wrapper + + if ($notices !== false) { + $wrapper = new ArrayWrapper(array_slice($notices, $offset, $limit)); + return $wrapper; + } + } + + $inbox = Notice_inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since); + + $ids = array(); + + while ($inbox->fetch()) { + $ids[] = $inbox->notice_id; + } + + $inbox->free(); + unset($inbox); + + return Notice::getStreamByIds($ids, 'user:notices_with_friends:' . $this->id); } - return Notice::getStream(sprintf($qry, $this->id), - 'user:notices_with_friends:' . $this->id, - $offset, $limit, $since_id, $before_id, - $order, $since); } function blowFavesCache() -- cgit v1.2.3-54-g00ecf From 3e3fec39ffd2d8e82c493809967ac22723e2365c Mon Sep 17 00:00:00 2001 From: CiaranG Date: Thu, 16 Apr 2009 17:21:06 +0100 Subject: Clarification in README regarding welcome/default users, as it has tripped a couple of people up --- README | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README b/README index 09d9d301c..7b2dcacc5 100644 --- a/README +++ b/README @@ -1129,6 +1129,9 @@ welcome: nickname of a user account that sends welcome messages to new busy servers it may be a good idea to keep that one just for 'urgent' messages. Default is null; no message. +If either of these special user accounts are specified, the users should +be created before the configuration is updated. + Troubleshooting =============== -- cgit v1.2.3-54-g00ecf From 362cac0a96a48a0568454b6d60306ae10e2175e6 Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Thu, 16 Apr 2009 17:34:19 +0000 Subject: Add a few events (hooks): RegistrationTry, RegistrationForData, ProfileFormData and ProfileSaveForm. --- actions/profilesettings.php | 343 ++++++++++++++++++++++---------------------- actions/register.php | 340 ++++++++++++++++++++++--------------------- 2 files changed, 346 insertions(+), 337 deletions(-) diff --git a/actions/profilesettings.php b/actions/profilesettings.php index 60f7c0796..fb847680b 100644 --- a/actions/profilesettings.php +++ b/actions/profilesettings.php @@ -91,67 +91,68 @@ class ProfilesettingsAction extends AccountSettingsAction $this->element('legend', null, _('Profile information')); $this->hidden('token', common_session_token()); - # too much common patterns here... abstractable? - + // too much common patterns here... abstractable? $this->elementStart('ul', 'form_data'); - $this->elementStart('li'); - $this->input('nickname', _('Nickname'), - ($this->arg('nickname')) ? $this->arg('nickname') : $profile->nickname, - _('1-64 lowercase letters or numbers, no punctuation or spaces')); - $this->elementEnd('li'); - $this->elementStart('li'); - $this->input('fullname', _('Full name'), - ($this->arg('fullname')) ? $this->arg('fullname') : $profile->fullname); - $this->elementEnd('li'); - $this->elementStart('li'); - $this->input('homepage', _('Homepage'), - ($this->arg('homepage')) ? $this->arg('homepage') : $profile->homepage, - _('URL of your homepage, blog, or profile on another site')); - $this->elementEnd('li'); - $this->elementStart('li'); - $this->textarea('bio', _('Bio'), - ($this->arg('bio')) ? $this->arg('bio') : $profile->bio, - _('Describe yourself and your interests in 140 chars')); - $this->elementEnd('li'); - $this->elementStart('li'); - $this->input('location', _('Location'), - ($this->arg('location')) ? $this->arg('location') : $profile->location, - _('Where you are, like "City, State (or Region), Country"')); - $this->elementEnd('li'); - $this->elementStart('li'); - $this->input('tags', _('Tags'), - ($this->arg('tags')) ? $this->arg('tags') : implode(' ', $user->getSelfTags()), - _('Tags for yourself (letters, numbers, -, ., and _), comma- or space- separated')); - $this->elementEnd('li'); - $this->elementStart('li'); - $language = common_language(); - $this->dropdown('language', _('Language'), - get_nice_language_list(), _('Preferred language'), - true, $language); - $this->elementEnd('li'); - $timezone = common_timezone(); - $timezones = array(); - foreach(DateTimeZone::listIdentifiers() as $k => $v) { - $timezones[$v] = $v; + if (Event::handle('StartProfileFormData', array($this))) { + $this->elementStart('li'); + $this->input('nickname', _('Nickname'), + ($this->arg('nickname')) ? $this->arg('nickname') : $profile->nickname, + _('1-64 lowercase letters or numbers, no punctuation or spaces')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->input('fullname', _('Full name'), + ($this->arg('fullname')) ? $this->arg('fullname') : $profile->fullname); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->input('homepage', _('Homepage'), + ($this->arg('homepage')) ? $this->arg('homepage') : $profile->homepage, + _('URL of your homepage, blog, or profile on another site')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->textarea('bio', _('Bio'), + ($this->arg('bio')) ? $this->arg('bio') : $profile->bio, + _('Describe yourself and your interests in 140 chars')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->input('location', _('Location'), + ($this->arg('location')) ? $this->arg('location') : $profile->location, + _('Where you are, like "City, State (or Region), Country"')); + $this->elementEnd('li'); + Event::handle('EndProfileFormData', array($this)); + $this->elementStart('li'); + $this->input('tags', _('Tags'), + ($this->arg('tags')) ? $this->arg('tags') : implode(' ', $user->getSelfTags()), + _('Tags for yourself (letters, numbers, -, ., and _), comma- or space- separated')); + $this->elementEnd('li'); + $this->elementStart('li'); + $language = common_language(); + $this->dropdown('language', _('Language'), + get_nice_language_list(), _('Preferred language'), + false, $language); + $this->elementEnd('li'); + $timezone = common_timezone(); + $timezones = array(); + foreach(DateTimeZone::listIdentifiers() as $k => $v) { + $timezones[$v] = $v; + } + $this->elementStart('li'); + $this->dropdown('timezone', _('Timezone'), + $timezones, _('What timezone are you normally in?'), + true, $timezone); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->checkbox('autosubscribe', + _('Automatically subscribe to whoever '. + 'subscribes to me (best for non-humans)'), + ($this->arg('autosubscribe')) ? + $this->boolean('autosubscribe') : $user->autosubscribe); + $this->elementEnd('li'); } - $this->elementStart('li'); - $this->dropdown('timezone', _('Timezone'), - $timezones, _('What timezone are you normally in?'), - true, $timezone); - $this->elementEnd('li'); - $this->elementStart('li'); - $this->checkbox('autosubscribe', - _('Automatically subscribe to whoever '. - 'subscribes to me (best for non-humans)'), - ($this->arg('autosubscribe')) ? - $this->boolean('autosubscribe') : $user->autosubscribe); - $this->elementEnd('li'); $this->elementEnd('ul'); $this->submit('save', _('Save')); $this->elementEnd('fieldset'); $this->elementEnd('form'); - } /** @@ -165,158 +166,158 @@ class ProfilesettingsAction extends AccountSettingsAction function handlePost() { - # CSRF protection - + // CSRF protection $token = $this->trimmed('token'); if (!$token || $token != common_session_token()) { $this->showForm(_('There was a problem with your session token. '. - 'Try again, please.')); + 'Try again, please.')); return; } - $nickname = $this->trimmed('nickname'); - $fullname = $this->trimmed('fullname'); - $homepage = $this->trimmed('homepage'); - $bio = $this->trimmed('bio'); - $location = $this->trimmed('location'); - $autosubscribe = $this->boolean('autosubscribe'); - $language = $this->trimmed('language'); - $timezone = $this->trimmed('timezone'); - $tagstring = $this->trimmed('tags'); - - # Some validation - - if (!Validate::string($nickname, array('min_length' => 1, - 'max_length' => 64, - 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) { - $this->showForm(_('Nickname must have only lowercase letters and numbers and no spaces.')); - return; - } else if (!User::allowed_nickname($nickname)) { - $this->showForm(_('Not a valid nickname.')); - return; - } else if (!is_null($homepage) && (strlen($homepage) > 0) && - !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) { - $this->showForm(_('Homepage is not a valid URL.')); - return; - } else if (!is_null($fullname) && mb_strlen($fullname) > 255) { - $this->showForm(_('Full name is too long (max 255 chars).')); - return; - } else if (!is_null($bio) && mb_strlen($bio) > 140) { - $this->showForm(_('Bio is too long (max 140 chars).')); - return; - } else if (!is_null($location) && mb_strlen($location) > 255) { - $this->showForm(_('Location is too long (max 255 chars).')); - return; - } else if (is_null($timezone) || !in_array($timezone, DateTimeZone::listIdentifiers())) { - $this->showForm(_('Timezone not selected.')); - return; - } else if ($this->nicknameExists($nickname)) { - $this->showForm(_('Nickname already in use. Try another one.')); - return; - } else if (!is_null($language) && strlen($language) > 50) { - $this->showForm(_('Language is too long (max 50 chars).')); - return; - } + if (Event::handle('StartProfileSaveForm', array($this))) { + + $nickname = $this->trimmed('nickname'); + $fullname = $this->trimmed('fullname'); + $homepage = $this->trimmed('homepage'); + $bio = $this->trimmed('bio'); + $location = $this->trimmed('location'); + $autosubscribe = $this->boolean('autosubscribe'); + $language = $this->trimmed('language'); + $timezone = $this->trimmed('timezone'); + $tagstring = $this->trimmed('tags'); + + // Some validation + if (!Validate::string($nickname, array('min_length' => 1, + 'max_length' => 64, + 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) { + $this->showForm(_('Nickname must have only lowercase letters and numbers and no spaces.')); + return; + } else if (!User::allowed_nickname($nickname)) { + $this->showForm(_('Not a valid nickname.')); + return; + } else if (!is_null($homepage) && (strlen($homepage) > 0) && + !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) { + $this->showForm(_('Homepage is not a valid URL.')); + return; + } else if (!is_null($fullname) && mb_strlen($fullname) > 255) { + $this->showForm(_('Full name is too long (max 255 chars).')); + return; + } else if (!is_null($bio) && mb_strlen($bio) > 140) { + $this->showForm(_('Bio is too long (max 140 chars).')); + return; + } else if (!is_null($location) && mb_strlen($location) > 255) { + $this->showForm(_('Location is too long (max 255 chars).')); + return; + } else if (is_null($timezone) || !in_array($timezone, DateTimeZone::listIdentifiers())) { + $this->showForm(_('Timezone not selected.')); + return; + } else if ($this->nicknameExists($nickname)) { + $this->showForm(_('Nickname already in use. Try another one.')); + return; + } else if (!is_null($language) && strlen($language) > 50) { + $this->showForm(_('Language is too long (max 50 chars).')); + return; + } - if ($tagstring) { - $tags = array_map('common_canonical_tag', preg_split('/[\s,]+/', $tagstring)); - } else { - $tags = array(); - } + if ($tagstring) { + $tags = array_map('common_canonical_tag', preg_split('/[\s,]+/', $tagstring)); + } else { + $tags = array(); + } - foreach ($tags as $tag) { - if (!common_valid_profile_tag($tag)) { - $this->showForm(sprintf(_('Invalid tag: "%s"'), $tag)); - return; + foreach ($tags as $tag) { + if (!common_valid_profile_tag($tag)) { + $this->showForm(sprintf(_('Invalid tag: "%s"'), $tag)); + return; + } } - } - $user = common_current_user(); + $user = common_current_user(); - $user->query('BEGIN'); + $user->query('BEGIN'); - if ($user->nickname != $nickname || - $user->language != $language || - $user->timezone != $timezone) { + if ($user->nickname != $nickname || + $user->language != $language || + $user->timezone != $timezone) { - common_debug('Updating user nickname from ' . $user->nickname . ' to ' . $nickname, - __FILE__); - common_debug('Updating user language from ' . $user->language . ' to ' . $language, - __FILE__); - common_debug('Updating user timezone from ' . $user->timezone . ' to ' . $timezone, - __FILE__); + common_debug('Updating user nickname from ' . $user->nickname . ' to ' . $nickname, + __FILE__); + common_debug('Updating user language from ' . $user->language . ' to ' . $language, + __FILE__); + common_debug('Updating user timezone from ' . $user->timezone . ' to ' . $timezone, + __FILE__); - $original = clone($user); + $original = clone($user); - $user->nickname = $nickname; - $user->language = $language; - $user->timezone = $timezone; + $user->nickname = $nickname; + $user->language = $language; + $user->timezone = $timezone; - $result = $user->updateKeys($original); + $result = $user->updateKeys($original); - if ($result === false) { - common_log_db_error($user, 'UPDATE', __FILE__); - $this->serverError(_('Couldn\'t update user.')); - return; - } else { - # Re-initialize language environment if it changed - common_init_language(); + if ($result === false) { + common_log_db_error($user, 'UPDATE', __FILE__); + $this->serverError(_('Couldn\'t update user.')); + return; + } else { + // Re-initialize language environment if it changed + common_init_language(); + } } - } - - # XXX: XOR - if ($user->autosubscribe ^ $autosubscribe) { +// XXX: XOR + if ($user->autosubscribe ^ $autosubscribe) { - $original = clone($user); + $original = clone($user); - $user->autosubscribe = $autosubscribe; + $user->autosubscribe = $autosubscribe; - $result = $user->update($original); + $result = $user->update($original); - if ($result === false) { - common_log_db_error($user, 'UPDATE', __FILE__); - $this->serverError(_('Couldn\'t update user for autosubscribe.')); - return; + if ($result === false) { + common_log_db_error($user, 'UPDATE', __FILE__); + $this->serverError(_('Couldn\'t update user for autosubscribe.')); + return; + } } - } - - $profile = $user->getProfile(); - $orig_profile = clone($profile); + $profile = $user->getProfile(); - $profile->nickname = $user->nickname; - $profile->fullname = $fullname; - $profile->homepage = $homepage; - $profile->bio = $bio; - $profile->location = $location; - $profile->profileurl = common_profile_url($nickname); + $orig_profile = clone($profile); - common_debug('Old profile: ' . common_log_objstring($orig_profile), __FILE__); - common_debug('New profile: ' . common_log_objstring($profile), __FILE__); + $profile->nickname = $user->nickname; + $profile->fullname = $fullname; + $profile->homepage = $homepage; + $profile->bio = $bio; + $profile->location = $location; + $profile->profileurl = common_profile_url($nickname); - $result = $profile->update($orig_profile); + common_debug('Old profile: ' . common_log_objstring($orig_profile), __FILE__); + common_debug('New profile: ' . common_log_objstring($profile), __FILE__); - if (!$result) { - common_log_db_error($profile, 'UPDATE', __FILE__); - $this->serverError(_('Couldn\'t save profile.')); - return; - } + $result = $profile->update($orig_profile); - # Set the user tags + if (!$result) { + common_log_db_error($profile, 'UPDATE', __FILE__); + $this->serverError(_('Couldn\'t save profile.')); + return; + } - $result = $user->setSelfTags($tags); + // Set the user tags + $result = $user->setSelfTags($tags); - if (!$result) { - $this->serverError(_('Couldn\'t save tags.')); - return; - } + if (!$result) { + $this->serverError(_('Couldn\'t save tags.')); + return; + } - $user->query('COMMIT'); + $user->query('COMMIT'); + Event::handle('EndProfileSaveForm', array($this)); + common_broadcast_profile($profile); - common_broadcast_profile($profile); + $this->showForm(_('Settings saved.'), true); - $this->showForm(_('Settings saved.'), true); + } } function nicknameExists($nickname) diff --git a/actions/register.php b/actions/register.php index 5d7a8ce69..ab49ad3fd 100644 --- a/actions/register.php +++ b/actions/register.php @@ -108,107 +108,109 @@ class RegisterAction extends Action function tryRegister() { - $token = $this->trimmed('token'); - if (!$token || $token != common_session_token()) { - $this->showForm(_('There was a problem with your session token. '. - 'Try again, please.')); - return; - } - - $nickname = $this->trimmed('nickname'); - $email = $this->trimmed('email'); - $fullname = $this->trimmed('fullname'); - $homepage = $this->trimmed('homepage'); - $bio = $this->trimmed('bio'); - $location = $this->trimmed('location'); - - // We don't trim these... whitespace is OK in a password! - - $password = $this->arg('password'); - $confirm = $this->arg('confirm'); + if (Event::handle('StartRegistrationTry', array($this))) { + $token = $this->trimmed('token'); + if (!$token || $token != common_session_token()) { + $this->showForm(_('There was a problem with your session token. '. + 'Try again, please.')); + return; + } - // invitation code, if any + $nickname = $this->trimmed('nickname'); + $email = $this->trimmed('email'); + $fullname = $this->trimmed('fullname'); + $homepage = $this->trimmed('homepage'); + $bio = $this->trimmed('bio'); + $location = $this->trimmed('location'); - $code = $this->trimmed('code'); + // We don't trim these... whitespace is OK in a password! + $password = $this->arg('password'); + $confirm = $this->arg('confirm'); - if ($code) { - $invite = Invitation::staticGet($code); - } + // invitation code, if any + $code = $this->trimmed('code'); - if (common_config('site', 'inviteonly') && !($code && $invite)) { - $this->clientError(_('Sorry, only invited people can register.')); - return; - } + if ($code) { + $invite = Invitation::staticGet($code); + } - // Input scrubbing - - $nickname = common_canonical_nickname($nickname); - $email = common_canonical_email($email); - - if (!$this->boolean('license')) { - $this->showForm(_('You can\'t register if you don\'t '. - 'agree to the license.')); - } else if ($email && !Validate::email($email, true)) { - $this->showForm(_('Not a valid email address.')); - } else if (!Validate::string($nickname, array('min_length' => 1, - 'max_length' => 64, - 'format' => NICKNAME_FMT))) { - $this->showForm(_('Nickname must have only lowercase letters '. - 'and numbers and no spaces.')); - } else if ($this->nicknameExists($nickname)) { - $this->showForm(_('Nickname already in use. Try another one.')); - } else if (!User::allowed_nickname($nickname)) { - $this->showForm(_('Not a valid nickname.')); - } else if ($this->emailExists($email)) { - $this->showForm(_('Email address already exists.')); - } else if (!is_null($homepage) && (strlen($homepage) > 0) && - !Validate::uri($homepage, - array('allowed_schemes' => - array('http', 'https')))) { - $this->showForm(_('Homepage is not a valid URL.')); - return; - } else if (!is_null($fullname) && mb_strlen($fullname) > 255) { - $this->showForm(_('Full name is too long (max 255 chars).')); - return; - } else if (!is_null($bio) && mb_strlen($bio) > 140) { - $this->showForm(_('Bio is too long (max 140 chars).')); - return; - } else if (!is_null($location) && mb_strlen($location) > 255) { - $this->showForm(_('Location is too long (max 255 chars).')); - return; - } else if (strlen($password) < 6) { - $this->showForm(_('Password must be 6 or more characters.')); - return; - } else if ($password != $confirm) { - $this->showForm(_('Passwords don\'t match.')); - } else if ($user = User::register(array('nickname' => $nickname, - 'password' => $password, - 'email' => $email, - 'fullname' => $fullname, - 'homepage' => $homepage, - 'bio' => $bio, - 'location' => $location, - 'code' => $code))) { - if (!$user) { - $this->showForm(_('Invalid username or password.')); + if (common_config('site', 'inviteonly') && !($code && $invite)) { + $this->clientError(_('Sorry, only invited people can register.')); return; } - // success! - if (!common_set_user($user)) { - $this->serverError(_('Error setting user.')); + + // Input scrubbing + $nickname = common_canonical_nickname($nickname); + $email = common_canonical_email($email); + + if (!$this->boolean('license')) { + $this->showForm(_('You can\'t register if you don\'t '. + 'agree to the license.')); + } else if ($email && !Validate::email($email, true)) { + $this->showForm(_('Not a valid email address.')); + } else if (!Validate::string($nickname, array('min_length' => 1, + 'max_length' => 64, + 'format' => NICKNAME_FMT))) { + $this->showForm(_('Nickname must have only lowercase letters '. + 'and numbers and no spaces.')); + } else if ($this->nicknameExists($nickname)) { + $this->showForm(_('Nickname already in use. Try another one.')); + } else if (!User::allowed_nickname($nickname)) { + $this->showForm(_('Not a valid nickname.')); + } else if ($this->emailExists($email)) { + $this->showForm(_('Email address already exists.')); + } else if (!is_null($homepage) && (strlen($homepage) > 0) && + !Validate::uri($homepage, + array('allowed_schemes' => + array('http', 'https')))) { + $this->showForm(_('Homepage is not a valid URL.')); return; + } else if (!is_null($fullname) && mb_strlen($fullname) > 255) { + $this->showForm(_('Full name is too long (max 255 chars).')); + return; + } else if (!is_null($bio) && mb_strlen($bio) > 140) { + $this->showForm(_('Bio is too long (max 140 chars).')); + return; + } else if (!is_null($location) && mb_strlen($location) > 255) { + $this->showForm(_('Location is too long (max 255 chars).')); + return; + } else if (strlen($password) < 6) { + $this->showForm(_('Password must be 6 or more characters.')); + return; + } else if ($password != $confirm) { + $this->showForm(_('Passwords don\'t match.')); + } else if ($user = User::register(array('nickname' => $nickname, + 'password' => $password, + 'email' => $email, + 'fullname' => $fullname, + 'homepage' => $homepage, + 'bio' => $bio, + 'location' => $location, + 'code' => $code))) { + if (!$user) { + $this->showForm(_('Invalid username or password.')); + return; + } + // success! + if (!common_set_user($user)) { + $this->serverError(_('Error setting user.')); + return; + } + // this is a real login + common_real_login(true); + if ($this->boolean('rememberme')) { + common_debug('Adding rememberme cookie for ' . $nickname); + common_rememberme($user); + } + + Event::handle('EndRegistrationTry', array($this)); + + // Re-init language env in case it changed (not yet, but soon) + common_init_language(); + $this->showSuccess(); + } else { + $this->showForm(_('Invalid username or password.')); } - // this is a real login - common_real_login(true); - if ($this->boolean('rememberme')) { - common_debug('Adding rememberme cookie for ' . $nickname); - common_rememberme($user); - } - // Re-init language env in case it changed (not yet, but soon) - common_init_language(); - $this->showSuccess(); - } else { - $this->showForm(_('Invalid username or password.')); } } @@ -250,7 +252,9 @@ class RegisterAction extends Action // overrrided to add entry-title class function showPageTitle() { - $this->element('h1', array('class' => 'entry-title'), $this->title()); + if (Event::handle('StartShowPageTitle', array($this))) { + $this->element('h1', array('class' => 'entry-title'), $this->title()); + } } // overrided to add hentry, and content-inner class @@ -351,9 +355,9 @@ class RegisterAction extends Action } $this->elementStart('form', array('method' => 'post', - 'id' => 'form_register', - 'class' => 'form_settings', - 'action' => common_local_url('register'))); + 'id' => 'form_register', + 'class' => 'form_settings', + 'action' => common_local_url('register'))); $this->elementStart('fieldset'); $this->element('legend', null, 'Account settings'); $this->hidden('token', common_session_token()); @@ -363,77 +367,80 @@ class RegisterAction extends Action } $this->elementStart('ul', 'form_data'); - $this->elementStart('li'); - $this->input('nickname', _('Nickname'), $this->trimmed('nickname'), - _('1-64 lowercase letters or numbers, '. - 'no punctuation or spaces. Required.')); - $this->elementEnd('li'); - $this->elementStart('li'); - $this->password('password', _('Password'), - _('6 or more characters. Required.')); - $this->elementEnd('li'); - $this->elementStart('li'); - $this->password('confirm', _('Confirm'), - _('Same as password above. Required.')); - $this->elementEnd('li'); - $this->elementStart('li'); - if ($invite && $invite->address_type == 'email') { - $this->input('email', _('Email'), $invite->address, - _('Used only for updates, announcements, '. - 'and password recovery')); - } else { - $this->input('email', _('Email'), $this->trimmed('email'), - _('Used only for updates, announcements, '. - 'and password recovery')); - } - $this->elementEnd('li'); - $this->elementStart('li'); - $this->input('fullname', _('Full name'), - $this->trimmed('fullname'), - _('Longer name, preferably your "real" name')); - $this->elementEnd('li'); - $this->elementStart('li'); - $this->input('homepage', _('Homepage'), - $this->trimmed('homepage'), - _('URL of your homepage, blog, '. - 'or profile on another site')); - $this->elementEnd('li'); - $this->elementStart('li'); - $this->textarea('bio', _('Bio'), - $this->trimmed('bio'), - _('Describe yourself and your '. - 'interests in 140 chars')); - $this->elementEnd('li'); - $this->elementStart('li'); - $this->input('location', _('Location'), - $this->trimmed('location'), - _('Where you are, like "City, '. - 'State (or Region), Country"')); - $this->elementEnd('li'); - $this->elementStart('li', array('id' => 'settings_rememberme')); - $this->checkbox('rememberme', _('Remember me'), - $this->boolean('rememberme'), - _('Automatically login in the future; '. - 'not for shared computers!')); - $this->elementEnd('li'); - $attrs = array('type' => 'checkbox', - 'id' => 'license', - 'class' => 'checkbox', - 'name' => 'license', - 'value' => 'true'); - if ($this->boolean('license')) { - $attrs['checked'] = 'checked'; + if (Event::handle('StartRegistrationFormData', array($this))) { + $this->elementStart('li'); + $this->input('nickname', _('Nickname'), $this->trimmed('nickname'), + _('1-64 lowercase letters or numbers, '. + 'no punctuation or spaces. Required.')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->password('password', _('Password'), + _('6 or more characters. Required.')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->password('confirm', _('Confirm'), + _('Same as password above. Required.')); + $this->elementEnd('li'); + $this->elementStart('li'); + if ($invite && $invite->address_type == 'email') { + $this->input('email', _('Email'), $invite->address, + _('Used only for updates, announcements, '. + 'and password recovery')); + } else { + $this->input('email', _('Email'), $this->trimmed('email'), + _('Used only for updates, announcements, '. + 'and password recovery')); + } + $this->elementEnd('li'); + $this->elementStart('li'); + $this->input('fullname', _('Full name'), + $this->trimmed('fullname'), + _('Longer name, preferably your "real" name')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->input('homepage', _('Homepage'), + $this->trimmed('homepage'), + _('URL of your homepage, blog, '. + 'or profile on another site')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->textarea('bio', _('Bio'), + $this->trimmed('bio'), + _('Describe yourself and your '. + 'interests in 140 chars')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->input('location', _('Location'), + $this->trimmed('location'), + _('Where you are, like "City, '. + 'State (or Region), Country"')); + $this->elementEnd('li'); + Event::handle('EndRegistrationFormData', array($this)); + $this->elementStart('li', array('id' => 'settings_rememberme')); + $this->checkbox('rememberme', _('Remember me'), + $this->boolean('rememberme'), + _('Automatically login in the future; '. + 'not for shared computers!')); + $this->elementEnd('li'); + $attrs = array('type' => 'checkbox', + 'id' => 'license', + 'class' => 'checkbox', + 'name' => 'license', + 'value' => 'true'); + if ($this->boolean('license')) { + $attrs['checked'] = 'checked'; + } + $this->elementStart('li'); + $this->element('input', $attrs); + $this->elementStart('label', array('class' => 'checkbox', 'for' => 'license')); + $this->text(_('My text and files are available under ')); + $this->element('a', array('href' => common_config('license', 'url')), + common_config('license', 'title'), _("Creative Commons Attribution 3.0")); + $this->text(_(' except this private data: password, '. + 'email address, IM address, and phone number.')); + $this->elementEnd('label'); + $this->elementEnd('li'); } - $this->elementStart('li'); - $this->element('input', $attrs); - $this->elementStart('label', array('class' => 'checkbox', 'for' => 'license')); - $this->text(_('My text and files are available under ')); - $this->element('a', array('href' => common_config('license', 'url')), - common_config('license', 'title'), _("Creative Commons Attribution 3.0")); - $this->text(_(' except this private data: password, '. - 'email address, IM address, and phone number.')); - $this->elementEnd('label'); - $this->elementEnd('li'); $this->elementEnd('ul'); $this->submit('submit', _('Register')); $this->elementEnd('fieldset'); @@ -515,3 +522,4 @@ class RegisterAction extends Action $nav->show(); } } + -- cgit v1.2.3-54-g00ecf From ed0556971661de1b8748882f48c316afac20b8be Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Thu, 16 Apr 2009 17:58:52 +0000 Subject: Add an even (hook): StartPersonalGroupNav. --- lib/personalgroupnav.php | 68 +++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/lib/personalgroupnav.php b/lib/personalgroupnav.php index 63e6138df..acc033667 100644 --- a/lib/personalgroupnav.php +++ b/lib/personalgroupnav.php @@ -93,43 +93,45 @@ class PersonalGroupNav extends Widget $this->out->elementStart('ul', array('class' => 'nav')); - $this->out->menuItem(common_local_url('all', array('nickname' => - $nickname)), - _('Personal'), - sprintf(_('%s and friends'), (($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname)), - $action == 'all', 'nav_timeline_personal'); - $this->out->menuItem(common_local_url('replies', array('nickname' => - $nickname)), - _('Replies'), - sprintf(_('Replies to %s'), (($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname)), - $action == 'replies', 'nav_timeline_replies'); - $this->out->menuItem(common_local_url('showstream', array('nickname' => - $nickname)), - _('Profile'), - ($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname, - $action == 'showstream', 'nav_profile'); - $this->out->menuItem(common_local_url('showfavorites', array('nickname' => - $nickname)), - _('Favorites'), - sprintf(_('%s\'s favorite notices'), ($user_profile) ? $user_profile->getBestName() : _('User')), - $action == 'showfavorites', 'nav_timeline_favorites'); + if (Event::handle('StartPersonalGroupNav', array($this))) { + $this->out->menuItem(common_local_url('all', array('nickname' => + $nickname)), + _('Personal'), + sprintf(_('%s and friends'), (($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname)), + $action == 'all', 'nav_timeline_personal'); + $this->out->menuItem(common_local_url('replies', array('nickname' => + $nickname)), + _('Replies'), + sprintf(_('Replies to %s'), (($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname)), + $action == 'replies', 'nav_timeline_replies'); + $this->out->menuItem(common_local_url('showstream', array('nickname' => + $nickname)), + _('Profile'), + ($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname, + $action == 'showstream', 'nav_profile'); + $this->out->menuItem(common_local_url('showfavorites', array('nickname' => + $nickname)), + _('Favorites'), + sprintf(_('%s\'s favorite notices'), ($user_profile) ? $user_profile->getBestName() : _('User')), + $action == 'showfavorites', 'nav_timeline_favorites'); - $cur = common_current_user(); + $cur = common_current_user(); - if ($cur && $cur->id == $user->id) { + if ($cur && $cur->id == $user->id) { - $this->out->menuItem(common_local_url('inbox', array('nickname' => - $nickname)), - _('Inbox'), - _('Your incoming messages'), - $action == 'inbox'); - $this->out->menuItem(common_local_url('outbox', array('nickname' => - $nickname)), - _('Outbox'), - _('Your sent messages'), - $action == 'outbox'); + $this->out->menuItem(common_local_url('inbox', array('nickname' => + $nickname)), + _('Inbox'), + _('Your incoming messages'), + $action == 'inbox'); + $this->out->menuItem(common_local_url('outbox', array('nickname' => + $nickname)), + _('Outbox'), + _('Your sent messages'), + $action == 'outbox'); + } + Event::handle('EndPersonalGroupNav', array($this)); } - $this->out->elementEnd('ul'); } } -- cgit v1.2.3-54-g00ecf From bac3ee95c96db10ed51a907f6f9b602a7c887c0f Mon Sep 17 00:00:00 2001 From: CiaranG Date: Thu, 16 Apr 2009 21:07:59 +0100 Subject: Abort the xmpp-related daemons immediately if xmpp is disabled in the config, otherwise they chew up *lots* of CPU doing nothing --- scripts/jabberqueuehandler.php | 9 ++++++++- scripts/publicqueuehandler.php | 7 +++++++ scripts/xmppconfirmhandler.php | 7 +++++++ scripts/xmppdaemon.php | 7 +++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/scripts/jabberqueuehandler.php b/scripts/jabberqueuehandler.php index 924fc4545..8b6e974c0 100755 --- a/scripts/jabberqueuehandler.php +++ b/scripts/jabberqueuehandler.php @@ -54,6 +54,13 @@ class JabberQueueHandler extends XmppQueueHandler } } +// Abort immediately if xmpp is not enabled, otherwise the daemon chews up +// lots of CPU trying to connect to unconfigured servers +if (common_config('xmpp','enabled')==false) { + print "Aborting daemon - xmpp is disabled\n"; + exit(); +} + ini_set("max_execution_time", "0"); ini_set("max_input_time", "0"); set_time_limit(0); @@ -63,4 +70,4 @@ $resource = ($argc > 1) ? $argv[1] : (common_config('xmpp','resource') . '-queue $handler = new JabberQueueHandler($resource); -$handler->runOnce(); \ No newline at end of file +$handler->runOnce(); diff --git a/scripts/publicqueuehandler.php b/scripts/publicqueuehandler.php index 5075c12df..b0fa22d43 100755 --- a/scripts/publicqueuehandler.php +++ b/scripts/publicqueuehandler.php @@ -52,6 +52,13 @@ class PublicQueueHandler extends XmppQueueHandler } } +// Abort immediately if xmpp is not enabled, otherwise the daemon chews up +// lots of CPU trying to connect to unconfigured servers +if (common_config('xmpp','enabled')==false) { + print "Aborting daemon - xmpp is disabled\n"; + exit(); +} + ini_set("max_execution_time", "0"); ini_set("max_input_time", "0"); set_time_limit(0); diff --git a/scripts/xmppconfirmhandler.php b/scripts/xmppconfirmhandler.php index 2b8b085ce..7f39235fe 100755 --- a/scripts/xmppconfirmhandler.php +++ b/scripts/xmppconfirmhandler.php @@ -140,6 +140,13 @@ class XmppConfirmHandler extends XmppQueueHandler } } +// Abort immediately if xmpp is not enabled, otherwise the daemon chews up +// lots of CPU trying to connect to unconfigured servers +if (common_config('xmpp','enabled')==false) { + print "Aborting daemon - xmpp is disabled\n"; + exit(); +} + ini_set("max_execution_time", "0"); ini_set("max_input_time", "0"); set_time_limit(0); diff --git a/scripts/xmppdaemon.php b/scripts/xmppdaemon.php index ef3f8c63d..0ce2f2a28 100755 --- a/scripts/xmppdaemon.php +++ b/scripts/xmppdaemon.php @@ -321,6 +321,13 @@ class XMPPDaemon extends Daemon } } +// Abort immediately if xmpp is not enabled, otherwise the daemon chews up +// lots of CPU trying to connect to unconfigured servers +if (common_config('xmpp','enabled')==false) { + print "Aborting daemon - xmpp is disabled\n"; + exit(); +} + ini_set("max_execution_time", "0"); ini_set("max_input_time", "0"); set_time_limit(0); -- cgit v1.2.3-54-g00ecf From 4d0e4f733bdfa281487f370b70f5f7440a7ef931 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 16 Apr 2009 14:40:57 -0700 Subject: Make API dates more compatible with Twitter - ticket 1432 --- lib/twitterapi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/twitterapi.php b/lib/twitterapi.php index b8357c688..6a90b4e28 100644 --- a/lib/twitterapi.php +++ b/lib/twitterapi.php @@ -418,7 +418,7 @@ class TwitterapiAction extends Action function date_twitter($dt) { $t = strtotime($dt); - return date("D M d G:i:s O Y", $t); + return date("D M d H:i:s O Y", $t); } // XXX: Candidate for a general utility method somewhere? -- cgit v1.2.3-54-g00ecf From c3a44d2ab982c42aaece2785316416a8ea780873 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 16 Apr 2009 21:57:42 +0000 Subject: form_notice textarea is cleared on successful direct message post. Disabled notice posting with XHR on Inbox and Outbox pages. This will be revisited in 0.8.x. --- js/util.js | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/js/util.js b/js/util.js index 81139744f..38d2a9a42 100644 --- a/js/util.js +++ b/js/util.js @@ -166,28 +166,36 @@ $(document).ready(function(){ $("#notice_action-submit").addClass("disabled"); return true; }, - success: function(xml) { if ($("#error", xml).length > 0 || $("#command_result", xml).length > 0) { + success: function(xml) { if ($("#error", xml).length > 0) { var result = document._importNode($("p", xml).get(0), true); result = result.textContent || result.innerHTML; alert(result); } else { - $("#notices_primary .notices").prepend(document._importNode($("li", xml).get(0), true)); + if ($("#command_result", xml).length > 0) { + var result = document._importNode($("p", xml).get(0), true); + result = result.textContent || result.innerHTML; + alert(result); + } + else { + $("#notices_primary .notices").prepend(document._importNode($("li", xml).get(0), true)); + counter(); + $("#notices_primary .notice:first").css({display:"none"}); + $("#notices_primary .notice:first").fadeIn(2500); + NoticeHover(); + NoticeReply(); + } $("#notice_data-text").val(""); - counter(); - $("#notices_primary .notice:first").css({display:"none"}); - $("#notices_primary .notice:first").fadeIn(2500); - NoticeHover(); - NoticeReply(); } $("#form_notice").removeClass("processing"); $("#notice_action-submit").removeAttr("disabled"); $("#notice_action-submit").removeClass("disabled"); } }; - $("#form_notice").ajaxForm(PostNotice); - $("#form_notice").each(addAjaxHidden); - + if (document.body.id != 'inbox' && document.body.id != 'outbox') { + $("#form_notice").ajaxForm(PostNotice); + $("#form_notice").each(addAjaxHidden); + } NoticeHover(); NoticeReply(); }); -- cgit v1.2.3-54-g00ecf From 34d904b180e5caa17eb945292a8a64656424d5d0 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 17 Apr 2009 01:11:38 +0000 Subject: Ticket 1404. Showing the link to the members list page. --- actions/grouprss.php | 2 +- actions/showgroup.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/actions/grouprss.php b/actions/grouprss.php index a9a2eef87..0b7280a11 100644 --- a/actions/grouprss.php +++ b/actions/grouprss.php @@ -34,7 +34,7 @@ if (!defined('LACONICA')) { require_once INSTALLDIR.'/lib/rssaction.php'; -define('MEMBERS_PER_SECTION', 81); +define('MEMBERS_PER_SECTION', 27); /** * Group RSS feed diff --git a/actions/showgroup.php b/actions/showgroup.php index 025f8383a..a7df39727 100644 --- a/actions/showgroup.php +++ b/actions/showgroup.php @@ -35,7 +35,7 @@ if (!defined('LACONICA')) { require_once INSTALLDIR.'/lib/noticelist.php'; require_once INSTALLDIR.'/lib/feedlist.php'; -define('MEMBERS_PER_SECTION', 81); +define('MEMBERS_PER_SECTION', 27); /** * Group main page @@ -361,7 +361,7 @@ class ShowgroupAction extends Action $this->element('p', null, _('(None)')); } - if ($cnt == MEMBERS_PER_SECTION) { + if ($cnt > MEMBERS_PER_SECTION) { $this->element('a', array('href' => common_local_url('groupmembers', array('nickname' => $this->group->nickname))), _('All members')); -- cgit v1.2.3-54-g00ecf From 21873b806d6c5cf3e55ea10e49959c944f708688 Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Fri, 17 Apr 2009 16:46:49 +0000 Subject: cosmetic fixes. --- lib/searchaction.php | 2 +- lib/tagcloudsection.php | 124 ------------------------------------------------ lib/util.php | 3 +- 3 files changed, 3 insertions(+), 126 deletions(-) delete mode 100644 lib/tagcloudsection.php diff --git a/lib/searchaction.php b/lib/searchaction.php index e74450e11..e7ad4affd 100644 --- a/lib/searchaction.php +++ b/lib/searchaction.php @@ -51,7 +51,7 @@ class SearchAction extends Action * * @return boolean true */ - function isReadOnly($args) + function isReadOnly() { return true; } diff --git a/lib/tagcloudsection.php b/lib/tagcloudsection.php deleted file mode 100644 index ff2aca6d6..000000000 --- a/lib/tagcloudsection.php +++ /dev/null @@ -1,124 +0,0 @@ -. - * - * @category Widget - * @package Laconica - * @author Evan Prodromou - * @copyright 2009 Control Yourself, Inc. - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://laconi.ca/ - */ - -if (!defined('LACONICA')) { - exit(1); -} - -define('TAGS_PER_SECTION', 20); - -/** - * Base class for sections - * - * These are the widgets that show interesting data about a person - * group, or site. - * - * @category Widget - * @package Laconica - * @author Evan Prodromou - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://laconi.ca/ - */ - -class TagCloudSection extends Section -{ - function showContent() - { - $tags = $this->getTags(); - - if (!$tags) { - $this->out->element('p', null, _('None')); - return false; - } - - $cnt = 0; - - $tw = array(); - $sum = 0; - - while ($tags->fetch() && ++$cnt <= TAGS_PER_SECTION) { - $tw[$tags->tag] = $tags->weight; - $sum += $tags->weight; - } - - if ($cnt == 0) { - $this->out->element('p', null, _('(None)')); - return false; - } - - ksort($tw); - - $this->out->elementStart('ul', 'tags xoxo tag-cloud'); - foreach ($tw as $tag => $weight) { - $this->showTag($tag, $weight, ($sum == 0) ? 0 : $weight/$sum); - } - $this->out->elementEnd('ul'); - - return ($cnt > TAGS_PER_SECTION); - } - - function getTags() - { - return null; - } - - function showTag($tag, $weight, $relative) - { - if ($relative > 0.1) { - $rel = 'tag-cloud-7'; - } else if ($relative > 0.05) { - $rel = 'tag-cloud-6'; - } else if ($relative > 0.02) { - $rel = 'tag-cloud-5'; - } else if ($relative > 0.01) { - $rel = 'tag-cloud-4'; - } else if ($relative > 0.005) { - $rel = 'tag-cloud-3'; - } else if ($relative > 0.002) { - $rel = 'tag-cloud-2'; - } else { - $rel = 'tag-cloud-1'; - } - - $this->out->elementStart('li', $rel); - $this->out->element('a', array('href' => $this->tagUrl($tag)), - $tag); - $this->out->elementEnd('li'); - } - - function tagUrl($tag) - { - return common_local_url('tag', array('tag' => $tag)); - } - - function divId() - { - return 'tagcloud'; - } -} diff --git a/lib/util.php b/lib/util.php index 675ff51f0..5d16e39b5 100644 --- a/lib/util.php +++ b/lib/util.php @@ -1333,4 +1333,5 @@ function common_database_tablename($tablename) } //table prefixes could be added here later return $tablename; -} \ No newline at end of file +} + -- cgit v1.2.3-54-g00ecf From c024ee935a638d2daf3d54374564a1956916857b Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Fri, 17 Apr 2009 17:23:12 +0000 Subject: file was removed by mistake. --- lib/tagcloudsection.php | 142 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 lib/tagcloudsection.php diff --git a/lib/tagcloudsection.php b/lib/tagcloudsection.php new file mode 100644 index 000000000..f5c305c65 --- /dev/null +++ b/lib/tagcloudsection.php @@ -0,0 +1,142 @@ +. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +define('TAGS_PER_SECTION', 20); + +/** + * Base class for sections + * + * These are the widgets that show interesting data about a person + * group, or site. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class TagCloudSection extends Section +{ + function showContent() + { + $tags = $this->getAllTags(); + + if (!$tags) { + $this->out->element('p', null, _('None')); + return false; + } + + $cnt = count($tags); + + if ($cnt == 0) { + $this->out->element('p', null, _('(None)')); + return false; + } + + ksort($tags); + + $this->out->elementStart('ul', 'tags xoxo tag-cloud'); + foreach ($tags as $tag => $weight) { + $this->showTag($tag, $weight, ($sum == 0) ? 0 : $weight/$sum); + } + $this->out->elementEnd('ul'); + + return ($cnt > TAGS_PER_SECTION); + } + + function getTags($lst, $usr) + { + $profile_tag = new Profile_tag; + $profile_tag->selectAdd(); + $profile_tag->selectAdd('tag'); + $profile_tag->selectAdd('count(tag) as weight'); + $profile_tag->groupBy('tag'); + $profile_tag->orderBy('weight DESC'); + $cnt = $profile_tag->find(); + + $profile_tag->query(" +SELECT tag, count(tag) as weight from profile_tag, (SELECT subscriber, subscribed from subscription where subscriber=$usr and subscribed != subscriber) as t where tagger=subscriber and tagged=subscribed group by tag order by weight dest"); + + $tags = array(); + while ($profile_tag->fetch()) { +// var_dump($profile_tag); + $tags[$profile_tag->tag] = $profile_tag->weight; + } + $profile_tag->free(); + if (0) { + echo 'tags:
';
+            var_dump($tags);
+            echo '
'; + } + return $tags; + } + + function getAllTags() { + return null; + } + + function showTag($tag, $weight, $relative) + { + if ($relative > 0.1) { + $rel = 'tag-cloud-7'; + } else if ($relative > 0.05) { + $rel = 'tag-cloud-6'; + } else if ($relative > 0.02) { + $rel = 'tag-cloud-5'; + } else if ($relative > 0.01) { + $rel = 'tag-cloud-4'; + } else if ($relative > 0.005) { + $rel = 'tag-cloud-3'; + } else if ($relative > 0.002) { + $rel = 'tag-cloud-2'; + } else { + $rel = 'tag-cloud-1'; + } + + $this->out->elementStart('li', $rel); + $this->out->element('a', array('href' => $this->tagUrl($tag)), + $tag); + $this->out->elementEnd('li'); + } + + function tagUrl($tag) + { + return common_local_url('tag', array('tag' => $tag)); + } + + function divId() + { + return 'tagcloud'; + } +} -- cgit v1.2.3-54-g00ecf From 2e06d5a2cb0d05d944bd0f969dbf5a0b10a1d48e Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Fri, 17 Apr 2009 17:24:41 +0000 Subject: file was removed by mistake. --- lib/tagcloudsection.php | 142 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 lib/tagcloudsection.php diff --git a/lib/tagcloudsection.php b/lib/tagcloudsection.php new file mode 100644 index 000000000..f5c305c65 --- /dev/null +++ b/lib/tagcloudsection.php @@ -0,0 +1,142 @@ +. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +define('TAGS_PER_SECTION', 20); + +/** + * Base class for sections + * + * These are the widgets that show interesting data about a person + * group, or site. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class TagCloudSection extends Section +{ + function showContent() + { + $tags = $this->getAllTags(); + + if (!$tags) { + $this->out->element('p', null, _('None')); + return false; + } + + $cnt = count($tags); + + if ($cnt == 0) { + $this->out->element('p', null, _('(None)')); + return false; + } + + ksort($tags); + + $this->out->elementStart('ul', 'tags xoxo tag-cloud'); + foreach ($tags as $tag => $weight) { + $this->showTag($tag, $weight, ($sum == 0) ? 0 : $weight/$sum); + } + $this->out->elementEnd('ul'); + + return ($cnt > TAGS_PER_SECTION); + } + + function getTags($lst, $usr) + { + $profile_tag = new Profile_tag; + $profile_tag->selectAdd(); + $profile_tag->selectAdd('tag'); + $profile_tag->selectAdd('count(tag) as weight'); + $profile_tag->groupBy('tag'); + $profile_tag->orderBy('weight DESC'); + $cnt = $profile_tag->find(); + + $profile_tag->query(" +SELECT tag, count(tag) as weight from profile_tag, (SELECT subscriber, subscribed from subscription where subscriber=$usr and subscribed != subscriber) as t where tagger=subscriber and tagged=subscribed group by tag order by weight dest"); + + $tags = array(); + while ($profile_tag->fetch()) { +// var_dump($profile_tag); + $tags[$profile_tag->tag] = $profile_tag->weight; + } + $profile_tag->free(); + if (0) { + echo 'tags:
';
+            var_dump($tags);
+            echo '
'; + } + return $tags; + } + + function getAllTags() { + return null; + } + + function showTag($tag, $weight, $relative) + { + if ($relative > 0.1) { + $rel = 'tag-cloud-7'; + } else if ($relative > 0.05) { + $rel = 'tag-cloud-6'; + } else if ($relative > 0.02) { + $rel = 'tag-cloud-5'; + } else if ($relative > 0.01) { + $rel = 'tag-cloud-4'; + } else if ($relative > 0.005) { + $rel = 'tag-cloud-3'; + } else if ($relative > 0.002) { + $rel = 'tag-cloud-2'; + } else { + $rel = 'tag-cloud-1'; + } + + $this->out->elementStart('li', $rel); + $this->out->element('a', array('href' => $this->tagUrl($tag)), + $tag); + $this->out->elementEnd('li'); + } + + function tagUrl($tag) + { + return common_local_url('tag', array('tag' => $tag)); + } + + function divId() + { + return 'tagcloud'; + } +} -- cgit v1.2.3-54-g00ecf From 2873940265611d6556eaee7a01dd53587d7ef446 Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Fri, 17 Apr 2009 17:31:22 +0000 Subject: Fixed file that was removed by mistake. --- lib/tagcloudsection.php | 44 +++++++++++++------------------------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/lib/tagcloudsection.php b/lib/tagcloudsection.php index f5c305c65..ff2aca6d6 100644 --- a/lib/tagcloudsection.php +++ b/lib/tagcloudsection.php @@ -50,24 +50,32 @@ class TagCloudSection extends Section { function showContent() { - $tags = $this->getAllTags(); + $tags = $this->getTags(); if (!$tags) { $this->out->element('p', null, _('None')); return false; } - $cnt = count($tags); + $cnt = 0; + + $tw = array(); + $sum = 0; + + while ($tags->fetch() && ++$cnt <= TAGS_PER_SECTION) { + $tw[$tags->tag] = $tags->weight; + $sum += $tags->weight; + } if ($cnt == 0) { $this->out->element('p', null, _('(None)')); return false; } - ksort($tags); + ksort($tw); $this->out->elementStart('ul', 'tags xoxo tag-cloud'); - foreach ($tags as $tag => $weight) { + foreach ($tw as $tag => $weight) { $this->showTag($tag, $weight, ($sum == 0) ? 0 : $weight/$sum); } $this->out->elementEnd('ul'); @@ -75,34 +83,8 @@ class TagCloudSection extends Section return ($cnt > TAGS_PER_SECTION); } - function getTags($lst, $usr) + function getTags() { - $profile_tag = new Profile_tag; - $profile_tag->selectAdd(); - $profile_tag->selectAdd('tag'); - $profile_tag->selectAdd('count(tag) as weight'); - $profile_tag->groupBy('tag'); - $profile_tag->orderBy('weight DESC'); - $cnt = $profile_tag->find(); - - $profile_tag->query(" -SELECT tag, count(tag) as weight from profile_tag, (SELECT subscriber, subscribed from subscription where subscriber=$usr and subscribed != subscriber) as t where tagger=subscriber and tagged=subscribed group by tag order by weight dest"); - - $tags = array(); - while ($profile_tag->fetch()) { -// var_dump($profile_tag); - $tags[$profile_tag->tag] = $profile_tag->weight; - } - $profile_tag->free(); - if (0) { - echo 'tags:
';
-            var_dump($tags);
-            echo '
'; - } - return $tags; - } - - function getAllTags() { return null; } -- cgit v1.2.3-54-g00ecf From cb645558a511e0f4a03923a988bda78ceae5ff0d Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Fri, 17 Apr 2009 17:35:51 +0000 Subject: Fixed file that was removed by mistake. --- lib/tagcloudsection.php | 44 +++++++++++++------------------------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/lib/tagcloudsection.php b/lib/tagcloudsection.php index f5c305c65..ff2aca6d6 100644 --- a/lib/tagcloudsection.php +++ b/lib/tagcloudsection.php @@ -50,24 +50,32 @@ class TagCloudSection extends Section { function showContent() { - $tags = $this->getAllTags(); + $tags = $this->getTags(); if (!$tags) { $this->out->element('p', null, _('None')); return false; } - $cnt = count($tags); + $cnt = 0; + + $tw = array(); + $sum = 0; + + while ($tags->fetch() && ++$cnt <= TAGS_PER_SECTION) { + $tw[$tags->tag] = $tags->weight; + $sum += $tags->weight; + } if ($cnt == 0) { $this->out->element('p', null, _('(None)')); return false; } - ksort($tags); + ksort($tw); $this->out->elementStart('ul', 'tags xoxo tag-cloud'); - foreach ($tags as $tag => $weight) { + foreach ($tw as $tag => $weight) { $this->showTag($tag, $weight, ($sum == 0) ? 0 : $weight/$sum); } $this->out->elementEnd('ul'); @@ -75,34 +83,8 @@ class TagCloudSection extends Section return ($cnt > TAGS_PER_SECTION); } - function getTags($lst, $usr) + function getTags() { - $profile_tag = new Profile_tag; - $profile_tag->selectAdd(); - $profile_tag->selectAdd('tag'); - $profile_tag->selectAdd('count(tag) as weight'); - $profile_tag->groupBy('tag'); - $profile_tag->orderBy('weight DESC'); - $cnt = $profile_tag->find(); - - $profile_tag->query(" -SELECT tag, count(tag) as weight from profile_tag, (SELECT subscriber, subscribed from subscription where subscriber=$usr and subscribed != subscriber) as t where tagger=subscriber and tagged=subscribed group by tag order by weight dest"); - - $tags = array(); - while ($profile_tag->fetch()) { -// var_dump($profile_tag); - $tags[$profile_tag->tag] = $profile_tag->weight; - } - $profile_tag->free(); - if (0) { - echo 'tags:
';
-            var_dump($tags);
-            echo '
'; - } - return $tags; - } - - function getAllTags() { return null; } -- cgit v1.2.3-54-g00ecf From b22f446df2384c5bd3fa5cf428106ea0a62f1b7d Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 17 Apr 2009 19:51:20 +0000 Subject: Clear notice char counter for direct messages as well. --- js/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/util.js b/js/util.js index 38d2a9a42..3753bd989 100644 --- a/js/util.js +++ b/js/util.js @@ -179,12 +179,12 @@ $(document).ready(function(){ } else { $("#notices_primary .notices").prepend(document._importNode($("li", xml).get(0), true)); - counter(); $("#notices_primary .notice:first").css({display:"none"}); $("#notices_primary .notice:first").fadeIn(2500); NoticeHover(); NoticeReply(); } + counter(); $("#notice_data-text").val(""); } $("#form_notice").removeClass("processing"); -- cgit v1.2.3-54-g00ecf From 231c61a7eb3bb79faed696945ccd6d831c80f0f2 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 17 Apr 2009 12:52:26 -0700 Subject: store invite code in session so openidfinish can find it --- actions/finishopenidlogin.php | 33 ++++++-- actions/register.php | 171 ++++++++++++++++++++++++------------------ 2 files changed, 127 insertions(+), 77 deletions(-) diff --git a/actions/finishopenidlogin.php b/actions/finishopenidlogin.php index 952185742..b08b96df6 100644 --- a/actions/finishopenidlogin.php +++ b/actions/finishopenidlogin.php @@ -191,11 +191,28 @@ class FinishopenidloginAction extends Action { # FIXME: save invite code before redirect, and check here - if (common_config('site', 'closed') || common_config('site', 'inviteonly')) { + if (common_config('site', 'closed')) { $this->clientError(_('Registration not allowed.')); return; } + $invite = null; + + if (common_config('site', 'inviteonly')) { + $code = $_SESSION['invitecode']; + if (empty($code)) { + $this->clientError(_('Registration not allowed.')); + return; + } + + $invite = Invitation::staticGet($code); + + if (empty($invite)) { + $this->clientError(_('Not a valid invitation code.')); + return; + } + } + $nickname = $this->trimmed('newname'); if (!Validate::string($nickname, array('min_length' => 1, @@ -257,10 +274,16 @@ class FinishopenidloginAction extends Action # XXX: add language # XXX: add timezone - $user = User::register(array('nickname' => $nickname, - 'email' => $email, - 'fullname' => $fullname, - 'location' => $location)); + $args = array('nickname' => $nickname, + 'email' => $email, + 'fullname' => $fullname, + 'location' => $location); + + if (!empty($invite)) { + $args['code'] = $invite->code; + } + + $user = User::register($args); $result = oid_link_user($user->id, $canonical, $display); diff --git a/actions/register.php b/actions/register.php index ab49ad3fd..4ac7c349d 100644 --- a/actions/register.php +++ b/actions/register.php @@ -55,6 +55,44 @@ class RegisterAction extends Action var $registered = false; + /** + * Prepare page to run + * + * + * @param $args + * @return string title + */ + + function prepare() + { + $this->code = $this->trimmed('code'); + + if (empty($this->code)) { + common_ensure_session(); + if (!empty($_SESSION['invitecode'])) { + $this->code = $_SESSION['invitecode']; + } + } + + if (common_config('site', 'inviteonly') && empty($this->code)) { + $this->clientError(_('Sorry, only invited people can register.')); + return false; + } + + if (!empty($this->code)) { + $this->invite = Invitation::staticGet($code); + if (empty($this->invite)) { + $this->clientError(_('Sorry, invalid invitation code.')); + return false; + } + // Store this in case we need it + common_ensure_session(); + $_SESSION['invitecode'] = $this->code; + } + + return true; + } + /** * Title of the page * @@ -112,7 +150,7 @@ class RegisterAction extends Action $token = $this->trimmed('token'); if (!$token || $token != common_session_token()) { $this->showForm(_('There was a problem with your session token. '. - 'Try again, please.')); + 'Try again, please.')); return; } @@ -145,14 +183,14 @@ class RegisterAction extends Action if (!$this->boolean('license')) { $this->showForm(_('You can\'t register if you don\'t '. - 'agree to the license.')); + 'agree to the license.')); } else if ($email && !Validate::email($email, true)) { $this->showForm(_('Not a valid email address.')); } else if (!Validate::string($nickname, array('min_length' => 1, - 'max_length' => 64, - 'format' => NICKNAME_FMT))) { + 'max_length' => 64, + 'format' => NICKNAME_FMT))) { $this->showForm(_('Nickname must have only lowercase letters '. - 'and numbers and no spaces.')); + 'and numbers and no spaces.')); } else if ($this->nicknameExists($nickname)) { $this->showForm(_('Nickname already in use. Try another one.')); } else if (!User::allowed_nickname($nickname)) { @@ -160,9 +198,9 @@ class RegisterAction extends Action } else if ($this->emailExists($email)) { $this->showForm(_('Email address already exists.')); } else if (!is_null($homepage) && (strlen($homepage) > 0) && - !Validate::uri($homepage, - array('allowed_schemes' => - array('http', 'https')))) { + !Validate::uri($homepage, + array('allowed_schemes' => + array('http', 'https')))) { $this->showForm(_('Homepage is not a valid URL.')); return; } else if (!is_null($fullname) && mb_strlen($fullname) > 255) { @@ -180,13 +218,13 @@ class RegisterAction extends Action } else if ($password != $confirm) { $this->showForm(_('Passwords don\'t match.')); } else if ($user = User::register(array('nickname' => $nickname, - 'password' => $password, - 'email' => $email, - 'fullname' => $fullname, - 'homepage' => $homepage, - 'bio' => $bio, - 'location' => $location, - 'code' => $code))) { + 'password' => $password, + 'email' => $email, + 'fullname' => $fullname, + 'homepage' => $homepage, + 'bio' => $bio, + 'location' => $location, + 'code' => $code))) { if (!$user) { $this->showForm(_('Invalid username or password.')); return; @@ -259,17 +297,17 @@ class RegisterAction extends Action // overrided to add hentry, and content-inner class function showContentBlock() - { - $this->elementStart('div', array('id' => 'content', 'class' => 'hentry')); - $this->showPageTitle(); - $this->showPageNoticeBlock(); - $this->elementStart('div', array('id' => 'content_inner', - 'class' => 'entry-content')); - // show the actual content (forms, lists, whatever) - $this->showContent(); - $this->elementEnd('div'); - $this->elementEnd('div'); - } + { + $this->elementStart('div', array('id' => 'content', 'class' => 'hentry')); + $this->showPageTitle(); + $this->showPageNoticeBlock(); + $this->elementStart('div', array('id' => 'content_inner', + 'class' => 'entry-content')); + // show the actual content (forms, lists, whatever) + $this->showContent(); + $this->elementEnd('div'); + $this->elementEnd('div'); + } /** * Instructions or a notice for the page @@ -343,90 +381,79 @@ class RegisterAction extends Action function showFormContent() { - $code = $this->trimmed('code'); - - if ($code) { - $invite = Invitation::staticGet($code); - } - - if (common_config('site', 'inviteonly') && !($code && $invite)) { - $this->clientError(_('Sorry, only invited people can register.')); - return; - } - $this->elementStart('form', array('method' => 'post', - 'id' => 'form_register', - 'class' => 'form_settings', - 'action' => common_local_url('register'))); + 'id' => 'form_register', + 'class' => 'form_settings', + 'action' => common_local_url('register'))); $this->elementStart('fieldset'); $this->element('legend', null, 'Account settings'); $this->hidden('token', common_session_token()); - if ($code) { - $this->hidden('code', $code); + if ($this->code) { + $this->hidden('code', $this->code); } $this->elementStart('ul', 'form_data'); if (Event::handle('StartRegistrationFormData', array($this))) { $this->elementStart('li'); $this->input('nickname', _('Nickname'), $this->trimmed('nickname'), - _('1-64 lowercase letters or numbers, '. - 'no punctuation or spaces. Required.')); + _('1-64 lowercase letters or numbers, '. + 'no punctuation or spaces. Required.')); $this->elementEnd('li'); $this->elementStart('li'); $this->password('password', _('Password'), - _('6 or more characters. Required.')); + _('6 or more characters. Required.')); $this->elementEnd('li'); $this->elementStart('li'); $this->password('confirm', _('Confirm'), - _('Same as password above. Required.')); + _('Same as password above. Required.')); $this->elementEnd('li'); $this->elementStart('li'); - if ($invite && $invite->address_type == 'email') { - $this->input('email', _('Email'), $invite->address, - _('Used only for updates, announcements, '. - 'and password recovery')); + if ($this->invite && $this->invite->address_type == 'email') { + $this->input('email', _('Email'), $this->invite->address, + _('Used only for updates, announcements, '. + 'and password recovery')); } else { $this->input('email', _('Email'), $this->trimmed('email'), - _('Used only for updates, announcements, '. - 'and password recovery')); + _('Used only for updates, announcements, '. + 'and password recovery')); } $this->elementEnd('li'); $this->elementStart('li'); $this->input('fullname', _('Full name'), - $this->trimmed('fullname'), - _('Longer name, preferably your "real" name')); + $this->trimmed('fullname'), + _('Longer name, preferably your "real" name')); $this->elementEnd('li'); $this->elementStart('li'); $this->input('homepage', _('Homepage'), - $this->trimmed('homepage'), - _('URL of your homepage, blog, '. - 'or profile on another site')); + $this->trimmed('homepage'), + _('URL of your homepage, blog, '. + 'or profile on another site')); $this->elementEnd('li'); $this->elementStart('li'); $this->textarea('bio', _('Bio'), - $this->trimmed('bio'), - _('Describe yourself and your '. - 'interests in 140 chars')); + $this->trimmed('bio'), + _('Describe yourself and your '. + 'interests in 140 chars')); $this->elementEnd('li'); $this->elementStart('li'); $this->input('location', _('Location'), - $this->trimmed('location'), - _('Where you are, like "City, '. - 'State (or Region), Country"')); + $this->trimmed('location'), + _('Where you are, like "City, '. + 'State (or Region), Country"')); $this->elementEnd('li'); Event::handle('EndRegistrationFormData', array($this)); $this->elementStart('li', array('id' => 'settings_rememberme')); $this->checkbox('rememberme', _('Remember me'), - $this->boolean('rememberme'), - _('Automatically login in the future; '. - 'not for shared computers!')); + $this->boolean('rememberme'), + _('Automatically login in the future; '. + 'not for shared computers!')); $this->elementEnd('li'); $attrs = array('type' => 'checkbox', - 'id' => 'license', - 'class' => 'checkbox', - 'name' => 'license', - 'value' => 'true'); + 'id' => 'license', + 'class' => 'checkbox', + 'name' => 'license', + 'value' => 'true'); if ($this->boolean('license')) { $attrs['checked'] = 'checked'; } @@ -435,9 +462,9 @@ class RegisterAction extends Action $this->elementStart('label', array('class' => 'checkbox', 'for' => 'license')); $this->text(_('My text and files are available under ')); $this->element('a', array('href' => common_config('license', 'url')), - common_config('license', 'title'), _("Creative Commons Attribution 3.0")); + common_config('license', 'title'), _("Creative Commons Attribution 3.0")); $this->text(_(' except this private data: password, '. - 'email address, IM address, and phone number.')); + 'email address, IM address, and phone number.')); $this->elementEnd('label'); $this->elementEnd('li'); } -- cgit v1.2.3-54-g00ecf From e8382b1292192d4c393f13ad7cd8da1be19211a8 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 17 Apr 2009 13:03:33 -0700 Subject: incorrect variable access --- actions/register.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/actions/register.php b/actions/register.php index 4ac7c349d..033cf557f 100644 --- a/actions/register.php +++ b/actions/register.php @@ -63,13 +63,14 @@ class RegisterAction extends Action * @return string title */ - function prepare() + function prepare($args) { + parent::prepare($args); $this->code = $this->trimmed('code'); if (empty($this->code)) { common_ensure_session(); - if (!empty($_SESSION['invitecode'])) { + if (array_key_exists('invitecode', $_SESSION)) { $this->code = $_SESSION['invitecode']; } } @@ -80,7 +81,7 @@ class RegisterAction extends Action } if (!empty($this->code)) { - $this->invite = Invitation::staticGet($code); + $this->invite = Invitation::staticGet('code', $this->code); if (empty($this->invite)) { $this->clientError(_('Sorry, invalid invitation code.')); return false; -- cgit v1.2.3-54-g00ecf From 81714c6c31569e35f6b068791870bdfec25d005c Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 17 Apr 2009 20:14:06 +0000 Subject: counter() after val() reset to avoid (weird) bug. --- js/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/util.js b/js/util.js index 3753bd989..53e6eb792 100644 --- a/js/util.js +++ b/js/util.js @@ -184,8 +184,8 @@ $(document).ready(function(){ NoticeHover(); NoticeReply(); } - counter(); $("#notice_data-text").val(""); + counter(); } $("#form_notice").removeClass("processing"); $("#notice_action-submit").removeAttr("disabled"); -- cgit v1.2.3-54-g00ecf From 8edd7001f4440bdd845cbc4b652fec17baf047c8 Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Thu, 16 Apr 2009 17:34:19 +0000 Subject: Add a few events (hooks): RegistrationTry, RegistrationForData, ProfileFormData and ProfileSaveForm. --- actions/profilesettings.php | 343 ++++++++++++++++++++++---------------------- actions/register.php | 340 ++++++++++++++++++++++--------------------- 2 files changed, 346 insertions(+), 337 deletions(-) diff --git a/actions/profilesettings.php b/actions/profilesettings.php index 60f7c0796..fb847680b 100644 --- a/actions/profilesettings.php +++ b/actions/profilesettings.php @@ -91,67 +91,68 @@ class ProfilesettingsAction extends AccountSettingsAction $this->element('legend', null, _('Profile information')); $this->hidden('token', common_session_token()); - # too much common patterns here... abstractable? - + // too much common patterns here... abstractable? $this->elementStart('ul', 'form_data'); - $this->elementStart('li'); - $this->input('nickname', _('Nickname'), - ($this->arg('nickname')) ? $this->arg('nickname') : $profile->nickname, - _('1-64 lowercase letters or numbers, no punctuation or spaces')); - $this->elementEnd('li'); - $this->elementStart('li'); - $this->input('fullname', _('Full name'), - ($this->arg('fullname')) ? $this->arg('fullname') : $profile->fullname); - $this->elementEnd('li'); - $this->elementStart('li'); - $this->input('homepage', _('Homepage'), - ($this->arg('homepage')) ? $this->arg('homepage') : $profile->homepage, - _('URL of your homepage, blog, or profile on another site')); - $this->elementEnd('li'); - $this->elementStart('li'); - $this->textarea('bio', _('Bio'), - ($this->arg('bio')) ? $this->arg('bio') : $profile->bio, - _('Describe yourself and your interests in 140 chars')); - $this->elementEnd('li'); - $this->elementStart('li'); - $this->input('location', _('Location'), - ($this->arg('location')) ? $this->arg('location') : $profile->location, - _('Where you are, like "City, State (or Region), Country"')); - $this->elementEnd('li'); - $this->elementStart('li'); - $this->input('tags', _('Tags'), - ($this->arg('tags')) ? $this->arg('tags') : implode(' ', $user->getSelfTags()), - _('Tags for yourself (letters, numbers, -, ., and _), comma- or space- separated')); - $this->elementEnd('li'); - $this->elementStart('li'); - $language = common_language(); - $this->dropdown('language', _('Language'), - get_nice_language_list(), _('Preferred language'), - true, $language); - $this->elementEnd('li'); - $timezone = common_timezone(); - $timezones = array(); - foreach(DateTimeZone::listIdentifiers() as $k => $v) { - $timezones[$v] = $v; + if (Event::handle('StartProfileFormData', array($this))) { + $this->elementStart('li'); + $this->input('nickname', _('Nickname'), + ($this->arg('nickname')) ? $this->arg('nickname') : $profile->nickname, + _('1-64 lowercase letters or numbers, no punctuation or spaces')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->input('fullname', _('Full name'), + ($this->arg('fullname')) ? $this->arg('fullname') : $profile->fullname); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->input('homepage', _('Homepage'), + ($this->arg('homepage')) ? $this->arg('homepage') : $profile->homepage, + _('URL of your homepage, blog, or profile on another site')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->textarea('bio', _('Bio'), + ($this->arg('bio')) ? $this->arg('bio') : $profile->bio, + _('Describe yourself and your interests in 140 chars')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->input('location', _('Location'), + ($this->arg('location')) ? $this->arg('location') : $profile->location, + _('Where you are, like "City, State (or Region), Country"')); + $this->elementEnd('li'); + Event::handle('EndProfileFormData', array($this)); + $this->elementStart('li'); + $this->input('tags', _('Tags'), + ($this->arg('tags')) ? $this->arg('tags') : implode(' ', $user->getSelfTags()), + _('Tags for yourself (letters, numbers, -, ., and _), comma- or space- separated')); + $this->elementEnd('li'); + $this->elementStart('li'); + $language = common_language(); + $this->dropdown('language', _('Language'), + get_nice_language_list(), _('Preferred language'), + false, $language); + $this->elementEnd('li'); + $timezone = common_timezone(); + $timezones = array(); + foreach(DateTimeZone::listIdentifiers() as $k => $v) { + $timezones[$v] = $v; + } + $this->elementStart('li'); + $this->dropdown('timezone', _('Timezone'), + $timezones, _('What timezone are you normally in?'), + true, $timezone); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->checkbox('autosubscribe', + _('Automatically subscribe to whoever '. + 'subscribes to me (best for non-humans)'), + ($this->arg('autosubscribe')) ? + $this->boolean('autosubscribe') : $user->autosubscribe); + $this->elementEnd('li'); } - $this->elementStart('li'); - $this->dropdown('timezone', _('Timezone'), - $timezones, _('What timezone are you normally in?'), - true, $timezone); - $this->elementEnd('li'); - $this->elementStart('li'); - $this->checkbox('autosubscribe', - _('Automatically subscribe to whoever '. - 'subscribes to me (best for non-humans)'), - ($this->arg('autosubscribe')) ? - $this->boolean('autosubscribe') : $user->autosubscribe); - $this->elementEnd('li'); $this->elementEnd('ul'); $this->submit('save', _('Save')); $this->elementEnd('fieldset'); $this->elementEnd('form'); - } /** @@ -165,158 +166,158 @@ class ProfilesettingsAction extends AccountSettingsAction function handlePost() { - # CSRF protection - + // CSRF protection $token = $this->trimmed('token'); if (!$token || $token != common_session_token()) { $this->showForm(_('There was a problem with your session token. '. - 'Try again, please.')); + 'Try again, please.')); return; } - $nickname = $this->trimmed('nickname'); - $fullname = $this->trimmed('fullname'); - $homepage = $this->trimmed('homepage'); - $bio = $this->trimmed('bio'); - $location = $this->trimmed('location'); - $autosubscribe = $this->boolean('autosubscribe'); - $language = $this->trimmed('language'); - $timezone = $this->trimmed('timezone'); - $tagstring = $this->trimmed('tags'); - - # Some validation - - if (!Validate::string($nickname, array('min_length' => 1, - 'max_length' => 64, - 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) { - $this->showForm(_('Nickname must have only lowercase letters and numbers and no spaces.')); - return; - } else if (!User::allowed_nickname($nickname)) { - $this->showForm(_('Not a valid nickname.')); - return; - } else if (!is_null($homepage) && (strlen($homepage) > 0) && - !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) { - $this->showForm(_('Homepage is not a valid URL.')); - return; - } else if (!is_null($fullname) && mb_strlen($fullname) > 255) { - $this->showForm(_('Full name is too long (max 255 chars).')); - return; - } else if (!is_null($bio) && mb_strlen($bio) > 140) { - $this->showForm(_('Bio is too long (max 140 chars).')); - return; - } else if (!is_null($location) && mb_strlen($location) > 255) { - $this->showForm(_('Location is too long (max 255 chars).')); - return; - } else if (is_null($timezone) || !in_array($timezone, DateTimeZone::listIdentifiers())) { - $this->showForm(_('Timezone not selected.')); - return; - } else if ($this->nicknameExists($nickname)) { - $this->showForm(_('Nickname already in use. Try another one.')); - return; - } else if (!is_null($language) && strlen($language) > 50) { - $this->showForm(_('Language is too long (max 50 chars).')); - return; - } + if (Event::handle('StartProfileSaveForm', array($this))) { + + $nickname = $this->trimmed('nickname'); + $fullname = $this->trimmed('fullname'); + $homepage = $this->trimmed('homepage'); + $bio = $this->trimmed('bio'); + $location = $this->trimmed('location'); + $autosubscribe = $this->boolean('autosubscribe'); + $language = $this->trimmed('language'); + $timezone = $this->trimmed('timezone'); + $tagstring = $this->trimmed('tags'); + + // Some validation + if (!Validate::string($nickname, array('min_length' => 1, + 'max_length' => 64, + 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) { + $this->showForm(_('Nickname must have only lowercase letters and numbers and no spaces.')); + return; + } else if (!User::allowed_nickname($nickname)) { + $this->showForm(_('Not a valid nickname.')); + return; + } else if (!is_null($homepage) && (strlen($homepage) > 0) && + !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) { + $this->showForm(_('Homepage is not a valid URL.')); + return; + } else if (!is_null($fullname) && mb_strlen($fullname) > 255) { + $this->showForm(_('Full name is too long (max 255 chars).')); + return; + } else if (!is_null($bio) && mb_strlen($bio) > 140) { + $this->showForm(_('Bio is too long (max 140 chars).')); + return; + } else if (!is_null($location) && mb_strlen($location) > 255) { + $this->showForm(_('Location is too long (max 255 chars).')); + return; + } else if (is_null($timezone) || !in_array($timezone, DateTimeZone::listIdentifiers())) { + $this->showForm(_('Timezone not selected.')); + return; + } else if ($this->nicknameExists($nickname)) { + $this->showForm(_('Nickname already in use. Try another one.')); + return; + } else if (!is_null($language) && strlen($language) > 50) { + $this->showForm(_('Language is too long (max 50 chars).')); + return; + } - if ($tagstring) { - $tags = array_map('common_canonical_tag', preg_split('/[\s,]+/', $tagstring)); - } else { - $tags = array(); - } + if ($tagstring) { + $tags = array_map('common_canonical_tag', preg_split('/[\s,]+/', $tagstring)); + } else { + $tags = array(); + } - foreach ($tags as $tag) { - if (!common_valid_profile_tag($tag)) { - $this->showForm(sprintf(_('Invalid tag: "%s"'), $tag)); - return; + foreach ($tags as $tag) { + if (!common_valid_profile_tag($tag)) { + $this->showForm(sprintf(_('Invalid tag: "%s"'), $tag)); + return; + } } - } - $user = common_current_user(); + $user = common_current_user(); - $user->query('BEGIN'); + $user->query('BEGIN'); - if ($user->nickname != $nickname || - $user->language != $language || - $user->timezone != $timezone) { + if ($user->nickname != $nickname || + $user->language != $language || + $user->timezone != $timezone) { - common_debug('Updating user nickname from ' . $user->nickname . ' to ' . $nickname, - __FILE__); - common_debug('Updating user language from ' . $user->language . ' to ' . $language, - __FILE__); - common_debug('Updating user timezone from ' . $user->timezone . ' to ' . $timezone, - __FILE__); + common_debug('Updating user nickname from ' . $user->nickname . ' to ' . $nickname, + __FILE__); + common_debug('Updating user language from ' . $user->language . ' to ' . $language, + __FILE__); + common_debug('Updating user timezone from ' . $user->timezone . ' to ' . $timezone, + __FILE__); - $original = clone($user); + $original = clone($user); - $user->nickname = $nickname; - $user->language = $language; - $user->timezone = $timezone; + $user->nickname = $nickname; + $user->language = $language; + $user->timezone = $timezone; - $result = $user->updateKeys($original); + $result = $user->updateKeys($original); - if ($result === false) { - common_log_db_error($user, 'UPDATE', __FILE__); - $this->serverError(_('Couldn\'t update user.')); - return; - } else { - # Re-initialize language environment if it changed - common_init_language(); + if ($result === false) { + common_log_db_error($user, 'UPDATE', __FILE__); + $this->serverError(_('Couldn\'t update user.')); + return; + } else { + // Re-initialize language environment if it changed + common_init_language(); + } } - } - - # XXX: XOR - if ($user->autosubscribe ^ $autosubscribe) { +// XXX: XOR + if ($user->autosubscribe ^ $autosubscribe) { - $original = clone($user); + $original = clone($user); - $user->autosubscribe = $autosubscribe; + $user->autosubscribe = $autosubscribe; - $result = $user->update($original); + $result = $user->update($original); - if ($result === false) { - common_log_db_error($user, 'UPDATE', __FILE__); - $this->serverError(_('Couldn\'t update user for autosubscribe.')); - return; + if ($result === false) { + common_log_db_error($user, 'UPDATE', __FILE__); + $this->serverError(_('Couldn\'t update user for autosubscribe.')); + return; + } } - } - - $profile = $user->getProfile(); - $orig_profile = clone($profile); + $profile = $user->getProfile(); - $profile->nickname = $user->nickname; - $profile->fullname = $fullname; - $profile->homepage = $homepage; - $profile->bio = $bio; - $profile->location = $location; - $profile->profileurl = common_profile_url($nickname); + $orig_profile = clone($profile); - common_debug('Old profile: ' . common_log_objstring($orig_profile), __FILE__); - common_debug('New profile: ' . common_log_objstring($profile), __FILE__); + $profile->nickname = $user->nickname; + $profile->fullname = $fullname; + $profile->homepage = $homepage; + $profile->bio = $bio; + $profile->location = $location; + $profile->profileurl = common_profile_url($nickname); - $result = $profile->update($orig_profile); + common_debug('Old profile: ' . common_log_objstring($orig_profile), __FILE__); + common_debug('New profile: ' . common_log_objstring($profile), __FILE__); - if (!$result) { - common_log_db_error($profile, 'UPDATE', __FILE__); - $this->serverError(_('Couldn\'t save profile.')); - return; - } + $result = $profile->update($orig_profile); - # Set the user tags + if (!$result) { + common_log_db_error($profile, 'UPDATE', __FILE__); + $this->serverError(_('Couldn\'t save profile.')); + return; + } - $result = $user->setSelfTags($tags); + // Set the user tags + $result = $user->setSelfTags($tags); - if (!$result) { - $this->serverError(_('Couldn\'t save tags.')); - return; - } + if (!$result) { + $this->serverError(_('Couldn\'t save tags.')); + return; + } - $user->query('COMMIT'); + $user->query('COMMIT'); + Event::handle('EndProfileSaveForm', array($this)); + common_broadcast_profile($profile); - common_broadcast_profile($profile); + $this->showForm(_('Settings saved.'), true); - $this->showForm(_('Settings saved.'), true); + } } function nicknameExists($nickname) diff --git a/actions/register.php b/actions/register.php index 5d7a8ce69..ab49ad3fd 100644 --- a/actions/register.php +++ b/actions/register.php @@ -108,107 +108,109 @@ class RegisterAction extends Action function tryRegister() { - $token = $this->trimmed('token'); - if (!$token || $token != common_session_token()) { - $this->showForm(_('There was a problem with your session token. '. - 'Try again, please.')); - return; - } - - $nickname = $this->trimmed('nickname'); - $email = $this->trimmed('email'); - $fullname = $this->trimmed('fullname'); - $homepage = $this->trimmed('homepage'); - $bio = $this->trimmed('bio'); - $location = $this->trimmed('location'); - - // We don't trim these... whitespace is OK in a password! - - $password = $this->arg('password'); - $confirm = $this->arg('confirm'); + if (Event::handle('StartRegistrationTry', array($this))) { + $token = $this->trimmed('token'); + if (!$token || $token != common_session_token()) { + $this->showForm(_('There was a problem with your session token. '. + 'Try again, please.')); + return; + } - // invitation code, if any + $nickname = $this->trimmed('nickname'); + $email = $this->trimmed('email'); + $fullname = $this->trimmed('fullname'); + $homepage = $this->trimmed('homepage'); + $bio = $this->trimmed('bio'); + $location = $this->trimmed('location'); - $code = $this->trimmed('code'); + // We don't trim these... whitespace is OK in a password! + $password = $this->arg('password'); + $confirm = $this->arg('confirm'); - if ($code) { - $invite = Invitation::staticGet($code); - } + // invitation code, if any + $code = $this->trimmed('code'); - if (common_config('site', 'inviteonly') && !($code && $invite)) { - $this->clientError(_('Sorry, only invited people can register.')); - return; - } + if ($code) { + $invite = Invitation::staticGet($code); + } - // Input scrubbing - - $nickname = common_canonical_nickname($nickname); - $email = common_canonical_email($email); - - if (!$this->boolean('license')) { - $this->showForm(_('You can\'t register if you don\'t '. - 'agree to the license.')); - } else if ($email && !Validate::email($email, true)) { - $this->showForm(_('Not a valid email address.')); - } else if (!Validate::string($nickname, array('min_length' => 1, - 'max_length' => 64, - 'format' => NICKNAME_FMT))) { - $this->showForm(_('Nickname must have only lowercase letters '. - 'and numbers and no spaces.')); - } else if ($this->nicknameExists($nickname)) { - $this->showForm(_('Nickname already in use. Try another one.')); - } else if (!User::allowed_nickname($nickname)) { - $this->showForm(_('Not a valid nickname.')); - } else if ($this->emailExists($email)) { - $this->showForm(_('Email address already exists.')); - } else if (!is_null($homepage) && (strlen($homepage) > 0) && - !Validate::uri($homepage, - array('allowed_schemes' => - array('http', 'https')))) { - $this->showForm(_('Homepage is not a valid URL.')); - return; - } else if (!is_null($fullname) && mb_strlen($fullname) > 255) { - $this->showForm(_('Full name is too long (max 255 chars).')); - return; - } else if (!is_null($bio) && mb_strlen($bio) > 140) { - $this->showForm(_('Bio is too long (max 140 chars).')); - return; - } else if (!is_null($location) && mb_strlen($location) > 255) { - $this->showForm(_('Location is too long (max 255 chars).')); - return; - } else if (strlen($password) < 6) { - $this->showForm(_('Password must be 6 or more characters.')); - return; - } else if ($password != $confirm) { - $this->showForm(_('Passwords don\'t match.')); - } else if ($user = User::register(array('nickname' => $nickname, - 'password' => $password, - 'email' => $email, - 'fullname' => $fullname, - 'homepage' => $homepage, - 'bio' => $bio, - 'location' => $location, - 'code' => $code))) { - if (!$user) { - $this->showForm(_('Invalid username or password.')); + if (common_config('site', 'inviteonly') && !($code && $invite)) { + $this->clientError(_('Sorry, only invited people can register.')); return; } - // success! - if (!common_set_user($user)) { - $this->serverError(_('Error setting user.')); + + // Input scrubbing + $nickname = common_canonical_nickname($nickname); + $email = common_canonical_email($email); + + if (!$this->boolean('license')) { + $this->showForm(_('You can\'t register if you don\'t '. + 'agree to the license.')); + } else if ($email && !Validate::email($email, true)) { + $this->showForm(_('Not a valid email address.')); + } else if (!Validate::string($nickname, array('min_length' => 1, + 'max_length' => 64, + 'format' => NICKNAME_FMT))) { + $this->showForm(_('Nickname must have only lowercase letters '. + 'and numbers and no spaces.')); + } else if ($this->nicknameExists($nickname)) { + $this->showForm(_('Nickname already in use. Try another one.')); + } else if (!User::allowed_nickname($nickname)) { + $this->showForm(_('Not a valid nickname.')); + } else if ($this->emailExists($email)) { + $this->showForm(_('Email address already exists.')); + } else if (!is_null($homepage) && (strlen($homepage) > 0) && + !Validate::uri($homepage, + array('allowed_schemes' => + array('http', 'https')))) { + $this->showForm(_('Homepage is not a valid URL.')); return; + } else if (!is_null($fullname) && mb_strlen($fullname) > 255) { + $this->showForm(_('Full name is too long (max 255 chars).')); + return; + } else if (!is_null($bio) && mb_strlen($bio) > 140) { + $this->showForm(_('Bio is too long (max 140 chars).')); + return; + } else if (!is_null($location) && mb_strlen($location) > 255) { + $this->showForm(_('Location is too long (max 255 chars).')); + return; + } else if (strlen($password) < 6) { + $this->showForm(_('Password must be 6 or more characters.')); + return; + } else if ($password != $confirm) { + $this->showForm(_('Passwords don\'t match.')); + } else if ($user = User::register(array('nickname' => $nickname, + 'password' => $password, + 'email' => $email, + 'fullname' => $fullname, + 'homepage' => $homepage, + 'bio' => $bio, + 'location' => $location, + 'code' => $code))) { + if (!$user) { + $this->showForm(_('Invalid username or password.')); + return; + } + // success! + if (!common_set_user($user)) { + $this->serverError(_('Error setting user.')); + return; + } + // this is a real login + common_real_login(true); + if ($this->boolean('rememberme')) { + common_debug('Adding rememberme cookie for ' . $nickname); + common_rememberme($user); + } + + Event::handle('EndRegistrationTry', array($this)); + + // Re-init language env in case it changed (not yet, but soon) + common_init_language(); + $this->showSuccess(); + } else { + $this->showForm(_('Invalid username or password.')); } - // this is a real login - common_real_login(true); - if ($this->boolean('rememberme')) { - common_debug('Adding rememberme cookie for ' . $nickname); - common_rememberme($user); - } - // Re-init language env in case it changed (not yet, but soon) - common_init_language(); - $this->showSuccess(); - } else { - $this->showForm(_('Invalid username or password.')); } } @@ -250,7 +252,9 @@ class RegisterAction extends Action // overrrided to add entry-title class function showPageTitle() { - $this->element('h1', array('class' => 'entry-title'), $this->title()); + if (Event::handle('StartShowPageTitle', array($this))) { + $this->element('h1', array('class' => 'entry-title'), $this->title()); + } } // overrided to add hentry, and content-inner class @@ -351,9 +355,9 @@ class RegisterAction extends Action } $this->elementStart('form', array('method' => 'post', - 'id' => 'form_register', - 'class' => 'form_settings', - 'action' => common_local_url('register'))); + 'id' => 'form_register', + 'class' => 'form_settings', + 'action' => common_local_url('register'))); $this->elementStart('fieldset'); $this->element('legend', null, 'Account settings'); $this->hidden('token', common_session_token()); @@ -363,77 +367,80 @@ class RegisterAction extends Action } $this->elementStart('ul', 'form_data'); - $this->elementStart('li'); - $this->input('nickname', _('Nickname'), $this->trimmed('nickname'), - _('1-64 lowercase letters or numbers, '. - 'no punctuation or spaces. Required.')); - $this->elementEnd('li'); - $this->elementStart('li'); - $this->password('password', _('Password'), - _('6 or more characters. Required.')); - $this->elementEnd('li'); - $this->elementStart('li'); - $this->password('confirm', _('Confirm'), - _('Same as password above. Required.')); - $this->elementEnd('li'); - $this->elementStart('li'); - if ($invite && $invite->address_type == 'email') { - $this->input('email', _('Email'), $invite->address, - _('Used only for updates, announcements, '. - 'and password recovery')); - } else { - $this->input('email', _('Email'), $this->trimmed('email'), - _('Used only for updates, announcements, '. - 'and password recovery')); - } - $this->elementEnd('li'); - $this->elementStart('li'); - $this->input('fullname', _('Full name'), - $this->trimmed('fullname'), - _('Longer name, preferably your "real" name')); - $this->elementEnd('li'); - $this->elementStart('li'); - $this->input('homepage', _('Homepage'), - $this->trimmed('homepage'), - _('URL of your homepage, blog, '. - 'or profile on another site')); - $this->elementEnd('li'); - $this->elementStart('li'); - $this->textarea('bio', _('Bio'), - $this->trimmed('bio'), - _('Describe yourself and your '. - 'interests in 140 chars')); - $this->elementEnd('li'); - $this->elementStart('li'); - $this->input('location', _('Location'), - $this->trimmed('location'), - _('Where you are, like "City, '. - 'State (or Region), Country"')); - $this->elementEnd('li'); - $this->elementStart('li', array('id' => 'settings_rememberme')); - $this->checkbox('rememberme', _('Remember me'), - $this->boolean('rememberme'), - _('Automatically login in the future; '. - 'not for shared computers!')); - $this->elementEnd('li'); - $attrs = array('type' => 'checkbox', - 'id' => 'license', - 'class' => 'checkbox', - 'name' => 'license', - 'value' => 'true'); - if ($this->boolean('license')) { - $attrs['checked'] = 'checked'; + if (Event::handle('StartRegistrationFormData', array($this))) { + $this->elementStart('li'); + $this->input('nickname', _('Nickname'), $this->trimmed('nickname'), + _('1-64 lowercase letters or numbers, '. + 'no punctuation or spaces. Required.')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->password('password', _('Password'), + _('6 or more characters. Required.')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->password('confirm', _('Confirm'), + _('Same as password above. Required.')); + $this->elementEnd('li'); + $this->elementStart('li'); + if ($invite && $invite->address_type == 'email') { + $this->input('email', _('Email'), $invite->address, + _('Used only for updates, announcements, '. + 'and password recovery')); + } else { + $this->input('email', _('Email'), $this->trimmed('email'), + _('Used only for updates, announcements, '. + 'and password recovery')); + } + $this->elementEnd('li'); + $this->elementStart('li'); + $this->input('fullname', _('Full name'), + $this->trimmed('fullname'), + _('Longer name, preferably your "real" name')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->input('homepage', _('Homepage'), + $this->trimmed('homepage'), + _('URL of your homepage, blog, '. + 'or profile on another site')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->textarea('bio', _('Bio'), + $this->trimmed('bio'), + _('Describe yourself and your '. + 'interests in 140 chars')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->input('location', _('Location'), + $this->trimmed('location'), + _('Where you are, like "City, '. + 'State (or Region), Country"')); + $this->elementEnd('li'); + Event::handle('EndRegistrationFormData', array($this)); + $this->elementStart('li', array('id' => 'settings_rememberme')); + $this->checkbox('rememberme', _('Remember me'), + $this->boolean('rememberme'), + _('Automatically login in the future; '. + 'not for shared computers!')); + $this->elementEnd('li'); + $attrs = array('type' => 'checkbox', + 'id' => 'license', + 'class' => 'checkbox', + 'name' => 'license', + 'value' => 'true'); + if ($this->boolean('license')) { + $attrs['checked'] = 'checked'; + } + $this->elementStart('li'); + $this->element('input', $attrs); + $this->elementStart('label', array('class' => 'checkbox', 'for' => 'license')); + $this->text(_('My text and files are available under ')); + $this->element('a', array('href' => common_config('license', 'url')), + common_config('license', 'title'), _("Creative Commons Attribution 3.0")); + $this->text(_(' except this private data: password, '. + 'email address, IM address, and phone number.')); + $this->elementEnd('label'); + $this->elementEnd('li'); } - $this->elementStart('li'); - $this->element('input', $attrs); - $this->elementStart('label', array('class' => 'checkbox', 'for' => 'license')); - $this->text(_('My text and files are available under ')); - $this->element('a', array('href' => common_config('license', 'url')), - common_config('license', 'title'), _("Creative Commons Attribution 3.0")); - $this->text(_(' except this private data: password, '. - 'email address, IM address, and phone number.')); - $this->elementEnd('label'); - $this->elementEnd('li'); $this->elementEnd('ul'); $this->submit('submit', _('Register')); $this->elementEnd('fieldset'); @@ -515,3 +522,4 @@ class RegisterAction extends Action $nav->show(); } } + -- cgit v1.2.3-54-g00ecf From 0e6da4f1be4384155a38b2702e2ec39c96f5c359 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 17 Apr 2009 12:52:26 -0700 Subject: store invite code in session so openidfinish can find it --- actions/finishopenidlogin.php | 33 ++++++-- actions/register.php | 171 ++++++++++++++++++++++++------------------ 2 files changed, 127 insertions(+), 77 deletions(-) diff --git a/actions/finishopenidlogin.php b/actions/finishopenidlogin.php index 952185742..b08b96df6 100644 --- a/actions/finishopenidlogin.php +++ b/actions/finishopenidlogin.php @@ -191,11 +191,28 @@ class FinishopenidloginAction extends Action { # FIXME: save invite code before redirect, and check here - if (common_config('site', 'closed') || common_config('site', 'inviteonly')) { + if (common_config('site', 'closed')) { $this->clientError(_('Registration not allowed.')); return; } + $invite = null; + + if (common_config('site', 'inviteonly')) { + $code = $_SESSION['invitecode']; + if (empty($code)) { + $this->clientError(_('Registration not allowed.')); + return; + } + + $invite = Invitation::staticGet($code); + + if (empty($invite)) { + $this->clientError(_('Not a valid invitation code.')); + return; + } + } + $nickname = $this->trimmed('newname'); if (!Validate::string($nickname, array('min_length' => 1, @@ -257,10 +274,16 @@ class FinishopenidloginAction extends Action # XXX: add language # XXX: add timezone - $user = User::register(array('nickname' => $nickname, - 'email' => $email, - 'fullname' => $fullname, - 'location' => $location)); + $args = array('nickname' => $nickname, + 'email' => $email, + 'fullname' => $fullname, + 'location' => $location); + + if (!empty($invite)) { + $args['code'] = $invite->code; + } + + $user = User::register($args); $result = oid_link_user($user->id, $canonical, $display); diff --git a/actions/register.php b/actions/register.php index ab49ad3fd..4ac7c349d 100644 --- a/actions/register.php +++ b/actions/register.php @@ -55,6 +55,44 @@ class RegisterAction extends Action var $registered = false; + /** + * Prepare page to run + * + * + * @param $args + * @return string title + */ + + function prepare() + { + $this->code = $this->trimmed('code'); + + if (empty($this->code)) { + common_ensure_session(); + if (!empty($_SESSION['invitecode'])) { + $this->code = $_SESSION['invitecode']; + } + } + + if (common_config('site', 'inviteonly') && empty($this->code)) { + $this->clientError(_('Sorry, only invited people can register.')); + return false; + } + + if (!empty($this->code)) { + $this->invite = Invitation::staticGet($code); + if (empty($this->invite)) { + $this->clientError(_('Sorry, invalid invitation code.')); + return false; + } + // Store this in case we need it + common_ensure_session(); + $_SESSION['invitecode'] = $this->code; + } + + return true; + } + /** * Title of the page * @@ -112,7 +150,7 @@ class RegisterAction extends Action $token = $this->trimmed('token'); if (!$token || $token != common_session_token()) { $this->showForm(_('There was a problem with your session token. '. - 'Try again, please.')); + 'Try again, please.')); return; } @@ -145,14 +183,14 @@ class RegisterAction extends Action if (!$this->boolean('license')) { $this->showForm(_('You can\'t register if you don\'t '. - 'agree to the license.')); + 'agree to the license.')); } else if ($email && !Validate::email($email, true)) { $this->showForm(_('Not a valid email address.')); } else if (!Validate::string($nickname, array('min_length' => 1, - 'max_length' => 64, - 'format' => NICKNAME_FMT))) { + 'max_length' => 64, + 'format' => NICKNAME_FMT))) { $this->showForm(_('Nickname must have only lowercase letters '. - 'and numbers and no spaces.')); + 'and numbers and no spaces.')); } else if ($this->nicknameExists($nickname)) { $this->showForm(_('Nickname already in use. Try another one.')); } else if (!User::allowed_nickname($nickname)) { @@ -160,9 +198,9 @@ class RegisterAction extends Action } else if ($this->emailExists($email)) { $this->showForm(_('Email address already exists.')); } else if (!is_null($homepage) && (strlen($homepage) > 0) && - !Validate::uri($homepage, - array('allowed_schemes' => - array('http', 'https')))) { + !Validate::uri($homepage, + array('allowed_schemes' => + array('http', 'https')))) { $this->showForm(_('Homepage is not a valid URL.')); return; } else if (!is_null($fullname) && mb_strlen($fullname) > 255) { @@ -180,13 +218,13 @@ class RegisterAction extends Action } else if ($password != $confirm) { $this->showForm(_('Passwords don\'t match.')); } else if ($user = User::register(array('nickname' => $nickname, - 'password' => $password, - 'email' => $email, - 'fullname' => $fullname, - 'homepage' => $homepage, - 'bio' => $bio, - 'location' => $location, - 'code' => $code))) { + 'password' => $password, + 'email' => $email, + 'fullname' => $fullname, + 'homepage' => $homepage, + 'bio' => $bio, + 'location' => $location, + 'code' => $code))) { if (!$user) { $this->showForm(_('Invalid username or password.')); return; @@ -259,17 +297,17 @@ class RegisterAction extends Action // overrided to add hentry, and content-inner class function showContentBlock() - { - $this->elementStart('div', array('id' => 'content', 'class' => 'hentry')); - $this->showPageTitle(); - $this->showPageNoticeBlock(); - $this->elementStart('div', array('id' => 'content_inner', - 'class' => 'entry-content')); - // show the actual content (forms, lists, whatever) - $this->showContent(); - $this->elementEnd('div'); - $this->elementEnd('div'); - } + { + $this->elementStart('div', array('id' => 'content', 'class' => 'hentry')); + $this->showPageTitle(); + $this->showPageNoticeBlock(); + $this->elementStart('div', array('id' => 'content_inner', + 'class' => 'entry-content')); + // show the actual content (forms, lists, whatever) + $this->showContent(); + $this->elementEnd('div'); + $this->elementEnd('div'); + } /** * Instructions or a notice for the page @@ -343,90 +381,79 @@ class RegisterAction extends Action function showFormContent() { - $code = $this->trimmed('code'); - - if ($code) { - $invite = Invitation::staticGet($code); - } - - if (common_config('site', 'inviteonly') && !($code && $invite)) { - $this->clientError(_('Sorry, only invited people can register.')); - return; - } - $this->elementStart('form', array('method' => 'post', - 'id' => 'form_register', - 'class' => 'form_settings', - 'action' => common_local_url('register'))); + 'id' => 'form_register', + 'class' => 'form_settings', + 'action' => common_local_url('register'))); $this->elementStart('fieldset'); $this->element('legend', null, 'Account settings'); $this->hidden('token', common_session_token()); - if ($code) { - $this->hidden('code', $code); + if ($this->code) { + $this->hidden('code', $this->code); } $this->elementStart('ul', 'form_data'); if (Event::handle('StartRegistrationFormData', array($this))) { $this->elementStart('li'); $this->input('nickname', _('Nickname'), $this->trimmed('nickname'), - _('1-64 lowercase letters or numbers, '. - 'no punctuation or spaces. Required.')); + _('1-64 lowercase letters or numbers, '. + 'no punctuation or spaces. Required.')); $this->elementEnd('li'); $this->elementStart('li'); $this->password('password', _('Password'), - _('6 or more characters. Required.')); + _('6 or more characters. Required.')); $this->elementEnd('li'); $this->elementStart('li'); $this->password('confirm', _('Confirm'), - _('Same as password above. Required.')); + _('Same as password above. Required.')); $this->elementEnd('li'); $this->elementStart('li'); - if ($invite && $invite->address_type == 'email') { - $this->input('email', _('Email'), $invite->address, - _('Used only for updates, announcements, '. - 'and password recovery')); + if ($this->invite && $this->invite->address_type == 'email') { + $this->input('email', _('Email'), $this->invite->address, + _('Used only for updates, announcements, '. + 'and password recovery')); } else { $this->input('email', _('Email'), $this->trimmed('email'), - _('Used only for updates, announcements, '. - 'and password recovery')); + _('Used only for updates, announcements, '. + 'and password recovery')); } $this->elementEnd('li'); $this->elementStart('li'); $this->input('fullname', _('Full name'), - $this->trimmed('fullname'), - _('Longer name, preferably your "real" name')); + $this->trimmed('fullname'), + _('Longer name, preferably your "real" name')); $this->elementEnd('li'); $this->elementStart('li'); $this->input('homepage', _('Homepage'), - $this->trimmed('homepage'), - _('URL of your homepage, blog, '. - 'or profile on another site')); + $this->trimmed('homepage'), + _('URL of your homepage, blog, '. + 'or profile on another site')); $this->elementEnd('li'); $this->elementStart('li'); $this->textarea('bio', _('Bio'), - $this->trimmed('bio'), - _('Describe yourself and your '. - 'interests in 140 chars')); + $this->trimmed('bio'), + _('Describe yourself and your '. + 'interests in 140 chars')); $this->elementEnd('li'); $this->elementStart('li'); $this->input('location', _('Location'), - $this->trimmed('location'), - _('Where you are, like "City, '. - 'State (or Region), Country"')); + $this->trimmed('location'), + _('Where you are, like "City, '. + 'State (or Region), Country"')); $this->elementEnd('li'); Event::handle('EndRegistrationFormData', array($this)); $this->elementStart('li', array('id' => 'settings_rememberme')); $this->checkbox('rememberme', _('Remember me'), - $this->boolean('rememberme'), - _('Automatically login in the future; '. - 'not for shared computers!')); + $this->boolean('rememberme'), + _('Automatically login in the future; '. + 'not for shared computers!')); $this->elementEnd('li'); $attrs = array('type' => 'checkbox', - 'id' => 'license', - 'class' => 'checkbox', - 'name' => 'license', - 'value' => 'true'); + 'id' => 'license', + 'class' => 'checkbox', + 'name' => 'license', + 'value' => 'true'); if ($this->boolean('license')) { $attrs['checked'] = 'checked'; } @@ -435,9 +462,9 @@ class RegisterAction extends Action $this->elementStart('label', array('class' => 'checkbox', 'for' => 'license')); $this->text(_('My text and files are available under ')); $this->element('a', array('href' => common_config('license', 'url')), - common_config('license', 'title'), _("Creative Commons Attribution 3.0")); + common_config('license', 'title'), _("Creative Commons Attribution 3.0")); $this->text(_(' except this private data: password, '. - 'email address, IM address, and phone number.')); + 'email address, IM address, and phone number.')); $this->elementEnd('label'); $this->elementEnd('li'); } -- cgit v1.2.3-54-g00ecf From 1cb5490943582f10a3ad52720ca339b4847e4914 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 17 Apr 2009 13:03:33 -0700 Subject: incorrect variable access --- actions/register.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/actions/register.php b/actions/register.php index 4ac7c349d..033cf557f 100644 --- a/actions/register.php +++ b/actions/register.php @@ -63,13 +63,14 @@ class RegisterAction extends Action * @return string title */ - function prepare() + function prepare($args) { + parent::prepare($args); $this->code = $this->trimmed('code'); if (empty($this->code)) { common_ensure_session(); - if (!empty($_SESSION['invitecode'])) { + if (array_key_exists('invitecode', $_SESSION)) { $this->code = $_SESSION['invitecode']; } } @@ -80,7 +81,7 @@ class RegisterAction extends Action } if (!empty($this->code)) { - $this->invite = Invitation::staticGet($code); + $this->invite = Invitation::staticGet('code', $this->code); if (empty($this->invite)) { $this->clientError(_('Sorry, invalid invitation code.')); return false; -- cgit v1.2.3-54-g00ecf From 7196410bb0398c15fbab767a9b7cedc513e6520b Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Sat, 18 Apr 2009 19:00:20 +0200 Subject: shortening links in notices from XMPP This patch enables shortening of links, that where send from XMPP. The problem was, that in util.php common_current_user() is not finding the user account from which is posted, so the service to shorten is not known, so no shortening at all... This patch cleans up the xmppdaemon a little bit and hard codes ur1.ca as shortening service _if_ the user is not set. Ugly but working. --- lib/util.php | 20 ++++++-------------- scripts/xmppdaemon.php | 17 +++++------------ 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/lib/util.php b/lib/util.php index 675ff51f0..ab5e99593 100644 --- a/lib/util.php +++ b/lib/util.php @@ -519,11 +519,16 @@ function common_shorten_links($text) function common_shorten_link($url, $reverse = false) { + static $url_cache = array(); if ($reverse) return isset($url_cache[$url]) ? $url_cache[$url] : $url; $user = common_current_user(); - + if (!isset($user)) { + // common current user does not find a user when called from the XMPP daemon + // therefore we'll set one here fix, so that XMPP given URLs may be shortened + $user->urlshorteningservice = 'ur1.ca'; + } $curlh = curl_init(); curl_setopt($curlh, CURLOPT_CONNECTTIMEOUT, 20); // # seconds to wait curl_setopt($curlh, CURLOPT_USERAGENT, 'Laconica'); @@ -1321,16 +1326,3 @@ function common_compatible_license($from, $to) // XXX: better compatibility check needed here! return ($from == $to); } - -/** - * returns a quoted table name, if required according to config - */ -function common_database_tablename($tablename) -{ - - if(common_config('db','quote_identifiers')) { - $tablename = '"'. $tablename .'"'; - } - //table prefixes could be added here later - return $tablename; -} \ No newline at end of file diff --git a/scripts/xmppdaemon.php b/scripts/xmppdaemon.php index ef3f8c63d..5711f715d 100755 --- a/scripts/xmppdaemon.php +++ b/scripts/xmppdaemon.php @@ -152,11 +152,6 @@ class XMPPDaemon extends Daemon $body = preg_replace('/d[\ ]*('. $to .')[\ ]*/', '', $pl['body']); $this->add_direct($user, $body, $to, $from); } else { - $len = mb_strlen($pl['body']); - if($len > 140) { - $this->from_site($from, 'Message too long - maximum is 140 characters, you sent ' . $len); - return; - } $this->add_notice($user, $pl); } @@ -255,15 +250,13 @@ class XMPPDaemon extends Daemon function add_notice(&$user, &$pl) { $body = trim($pl['body']); - $content_shortened = common_shorten_link($body); + $content_shortened = common_shorten_links($body); if (mb_strlen($content_shortened) > 140) { - $content = trim(mb_substr($body, 0, 140)); - $content_shortened = common_shorten_link($content); - } - else { - $content = $body; + $from = jabber_normalize_jid($pl['from']); + $this->from_site($from, "Message too long - maximum is 140 characters, you sent ".mb_strlen($content_shortened)); + return; } - $notice = Notice::saveNew($user->id, $content, 'xmpp'); + $notice = Notice::saveNew($user->id, $content_shortened, 'xmpp'); if (is_string($notice)) { $this->log(LOG_ERR, $notice); return; -- cgit v1.2.3-54-g00ecf From 4b54a418f3f26b44defdb42b8168ae43f4d1c66c Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Sat, 18 Apr 2009 19:08:33 +0000 Subject: trac#1215, 1216, 1217 and 1219: subscribers/subscriptions people tagclouds --- actions/subscribers.php | 10 ++++ actions/subscriptions.php | 10 ++++ lib/subpeopletagcloudsection.php | 76 ++++++++++++++++++++++++++ lib/subscriberspeopleselftagcloudsection.php | 54 ++++++++++++++++++ lib/subscriberspeopletagcloudsection.php | 60 ++++++++++++++++++++ lib/subscriptionspeopleselftagcloudsection.php | 54 ++++++++++++++++++ lib/subscriptionspeopletagcloudsection.php | 59 ++++++++++++++++++++ 7 files changed, 323 insertions(+) create mode 100644 lib/subpeopletagcloudsection.php create mode 100644 lib/subscriberspeopleselftagcloudsection.php create mode 100644 lib/subscriberspeopletagcloudsection.php create mode 100644 lib/subscriptionspeopleselftagcloudsection.php create mode 100644 lib/subscriptionspeopletagcloudsection.php diff --git a/actions/subscribers.php b/actions/subscribers.php index d91a7d4fd..4482de9a7 100644 --- a/actions/subscribers.php +++ b/actions/subscribers.php @@ -118,6 +118,16 @@ class SubscribersAction extends GalleryAction $this->raw(common_markup_to_html($message)); $this->elementEnd('div'); } + + function showSections() + { + parent::showSections(); + $cloud = new SubscribersPeopleTagCloudSection($this); + $cloud->show(); + + $cloud2 = new SubscribersPeopleSelfTagCloudSection($this); + $cloud2->show(); + } } class SubscribersList extends ProfileList diff --git a/actions/subscriptions.php b/actions/subscriptions.php index e6f3c54db..095b18ad8 100644 --- a/actions/subscriptions.php +++ b/actions/subscriptions.php @@ -125,6 +125,16 @@ class SubscriptionsAction extends GalleryAction $this->raw(common_markup_to_html($message)); $this->elementEnd('div'); } + + function showSections() + { + parent::showSections(); + $cloud = new SubscriptionsPeopleTagCloudSection($this); + $cloud->show(); + + $cloud2 = new SubscriptionsPeopleSelfTagCloudSection($this); + $cloud2->show(); + } } class SubscriptionsList extends ProfileList diff --git a/lib/subpeopletagcloudsection.php b/lib/subpeopletagcloudsection.php new file mode 100644 index 000000000..d98f28afa --- /dev/null +++ b/lib/subpeopletagcloudsection.php @@ -0,0 +1,76 @@ +. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Personal tag cloud section + * + * @category Widget + * @package Laconica + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class SubPeopleTagCloudSection extends TagCloudSection +{ + function getTags() + { + $qry = $this->query(); + $limit = TAGS_PER_SECTION; + $offset = 0; + + if (common_config('db','type') == 'pgsql') { + $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } else { + $qry .= ' LIMIT ' . $offset . ', ' . $limit; + } + + $profile_tag = Memcached_DataObject::cachedQuery('Profile_tag', + sprintf($qry, + $this->out->user->id)); + return $profile_tag; + } + + function tagUrl($tag) { + return common_local_url('peopletag', array('tag' => $tag)); + } + + function showTag($tag, $weight, $relative) { + $rel = 'tag-cloud-'; + $rel .= 1+intval(7 * $relative * $weight - 0.01); + + $this->out->elementStart('li', $rel); + $this->out->element('a', array('href' => $this->tagUrl($tag)), $tag); + $this->out->elementEnd('li'); + } +} diff --git a/lib/subscriberspeopleselftagcloudsection.php b/lib/subscriberspeopleselftagcloudsection.php new file mode 100644 index 000000000..b5a39c6de --- /dev/null +++ b/lib/subscriberspeopleselftagcloudsection.php @@ -0,0 +1,54 @@ +. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Personal tag cloud section + * + * @category Widget + * @package Laconica + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class SubscribersPeopleSelfTagCloudSection extends SubPeopleTagCloudSection +{ + function title() + { + return _('People Tagcloud as self-tagged'); + } + + function query() { + return 'select tag, count(tag) as weight from subscription left join profile_tag on tagger = subscriber where subscribed=%d and subscribed != subscriber and tagger = tagged group by tag order by weight desc'; + } +} diff --git a/lib/subscriberspeopletagcloudsection.php b/lib/subscriberspeopletagcloudsection.php new file mode 100644 index 000000000..23011efdd --- /dev/null +++ b/lib/subscriberspeopletagcloudsection.php @@ -0,0 +1,60 @@ +. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Personal tag cloud section + * + * @category Widget + * @package Laconica + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class SubscribersPeopleTagCloudSection extends SubPeopleTagCloudSection +{ + function title() + { + return _('People Tagcloud as tagged'); + } + + function tagUrl($tag) { + $nickname = $this->out->profile->nickname; + return common_local_url('subscribers', array('nickname' => $nickname, 'tag' => $tag)); + } + + + function query() { + return 'select tag, count(tag) as weight from subscription left join profile_tag on subscriber=tagged and subscribed=tagger where subscribed=%d and subscriber != subscribed group by tag order by weight desc'; + } +} diff --git a/lib/subscriptionspeopleselftagcloudsection.php b/lib/subscriptionspeopleselftagcloudsection.php new file mode 100644 index 000000000..8ac65adb0 --- /dev/null +++ b/lib/subscriptionspeopleselftagcloudsection.php @@ -0,0 +1,54 @@ +. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Personal tag cloud section + * + * @category Widget + * @package Laconica + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class SubscriptionsPeopleSelfTagCloudSection extends SubPeopleTagCloudSection +{ + function title() + { + return _('People Tagcloud as self-tagged'); + } + + function query() { + return 'select tag, count(tag) as weight from subscription left join profile_tag on tagger = subscriber where subscribed=%d and subscriber != subscribed and tagger = tagged group by tag order by weight desc'; + } +} diff --git a/lib/subscriptionspeopletagcloudsection.php b/lib/subscriptionspeopletagcloudsection.php new file mode 100644 index 000000000..c3f7d1763 --- /dev/null +++ b/lib/subscriptionspeopletagcloudsection.php @@ -0,0 +1,59 @@ +. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Personal tag cloud section + * + * @category Widget + * @package Laconica + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class SubscriptionsPeopleTagCloudSection extends SubPeopleTagCloudSection +{ + function title() + { + return _('People Tagcloud as tagged'); + } + + function tagUrl($tag) { + $nickname = $this->out->profile->nickname; + return common_local_url('subscriptions', array('nickname' => $nickname, 'tag' => $tag)); + } + + function query() { + return 'select tag, count(tag) as weight from subscription left join profile_tag on subscriber=tagger and subscribed=tagged where subscriber=%d and subscriber != subscribed group by tag order by weight desc'; + } +} -- cgit v1.2.3-54-g00ecf From 90fb7be99a74689de0d0e2409230d8bd515ac5c3 Mon Sep 17 00:00:00 2001 From: Dan Moore Date: Sat, 18 Apr 2009 15:33:36 -0400 Subject: Bringing the presentation of boolean variables (favorited, truncated, profile_background_tile) and the result from friendships/exist in JSON results from the Twitter Compatible API in line with what the real Twitter API does. Currently, laconica returns text strings enclosed in quotes instead of bare Javascript booleans. This change fixes that. See http://laconi.ca/trac/ticket/1326 for one open issue related to this. --- actions/twitapifriendships.php | 6 +----- actions/twitapiusers.php | 2 +- lib/twitterapi.php | 29 ++++++++++++++++++++++++----- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/actions/twitapifriendships.php b/actions/twitapifriendships.php index c50c5e84a..2f8250e0d 100644 --- a/actions/twitapifriendships.php +++ b/actions/twitapifriendships.php @@ -133,11 +133,7 @@ class TwitapifriendshipsAction extends TwitterapiAction return; } - if ($user_a->isSubscribed($user_b)) { - $result = 'true'; - } else { - $result = 'false'; - } + $result = $user_a->isSubscribed($user_b); switch ($apidata['content-type']) { case 'xml': diff --git a/actions/twitapiusers.php b/actions/twitapiusers.php index 2894b7486..41d0d955b 100644 --- a/actions/twitapiusers.php +++ b/actions/twitapiusers.php @@ -83,7 +83,7 @@ class TwitapiusersAction extends TwitterapiAction $twitter_user['profile_link_color'] = ''; $twitter_user['profile_sidebar_fill_color'] = ''; $twitter_user['profile_sidebar_border_color'] = ''; - $twitter_user['profile_background_tile'] = 'false'; + $twitter_user['profile_background_tile'] = false; $faves = DB_DataObject::factory('fave'); $faves->user_id = $user->id; diff --git a/lib/twitterapi.php b/lib/twitterapi.php index 6a90b4e28..caf8c0716 100644 --- a/lib/twitterapi.php +++ b/lib/twitterapi.php @@ -51,6 +51,26 @@ class TwitterapiAction extends Action parent::handle($args); } + /** + * Overrides XMLOutputter::element to write booleans as strings (true|false). + * See that method's documentation for more info. + * + * @param string $tag Element type or tagname + * @param array $attrs Array of element attributes, as + * key-value pairs + * @param string $content string content of the element + * + * @return void + */ + function element($tag, $attrs=null, $content=null) + { + if (is_bool($content)) { + $content = ($content ? 'true' : 'false'); + } + + return parent::element($tag, $attrs, $content); + } + function twitter_user_array($profile, $get_notice=false) { @@ -66,7 +86,7 @@ class TwitterapiAction extends Action $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE); $twitter_user['profile_image_url'] = ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE); - $twitter_user['protected'] = 'false'; # not supported by Laconica yet + $twitter_user['protected'] = false; # not supported by Laconica yet $twitter_user['url'] = ($profile->homepage) ? $profile->homepage : null; if ($get_notice) { @@ -86,7 +106,7 @@ class TwitterapiAction extends Action $twitter_status = array(); $twitter_status['text'] = $notice->content; - $twitter_status['truncated'] = 'false'; # Not possible on Laconica + $twitter_status['truncated'] = false; # Not possible on Laconica $twitter_status['created_at'] = $this->date_twitter($notice->created); $twitter_status['in_reply_to_status_id'] = ($notice->reply_to) ? intval($notice->reply_to) : null; @@ -108,10 +128,9 @@ class TwitterapiAction extends Action ($replier_profile) ? $replier_profile->nickname : null; if (isset($this->auth_user)) { - $twitter_status['favorited'] = - ($this->auth_user->hasFave($notice)) ? 'true' : 'false'; + $twitter_status['favorited'] = $this->auth_user->hasFave($notice); } else { - $twitter_status['favorited'] = 'false'; + $twitter_status['favorited'] = false; } if ($include_user) { -- cgit v1.2.3-54-g00ecf From b764c3be78aef4305b75b14d7f3e8c9f1c552f9e Mon Sep 17 00:00:00 2001 From: Dan Moore Date: Sat, 18 Apr 2009 15:42:44 -0400 Subject: This should change the JSON representation of the booleans 'following' and 'notifications', but unlike the previous change, I was unable to test this. --- actions/twitapiusers.php | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/actions/twitapiusers.php b/actions/twitapiusers.php index 41d0d955b..92d67454c 100644 --- a/actions/twitapiusers.php +++ b/actions/twitapiusers.php @@ -103,22 +103,14 @@ class TwitapiusersAction extends TwitterapiAction if (isset($apidata['user'])) { - if ($apidata['user']->isSubscribed($profile)) { - $twitter_user['following'] = 'true'; - } else { - $twitter_user['following'] = 'false'; - } + $twitter_user['following'] = $apidata['user']->isSubscribed($profile); // Notifications on? $sub = Subscription::pkeyGet(array('subscriber' => $apidata['user']->id, 'subscribed' => $profile->id)); if ($sub) { - if ($sub->jabber || $sub->sms) { - $twitter_user['notifications'] = 'true'; - } else { - $twitter_user['notifications'] = 'false'; - } + $twitter_user['notifications'] = ($sub->jabber || $sub->sms); } } -- cgit v1.2.3-54-g00ecf From 48846c38057b20bb51814c22456d6907cc2a99e8 Mon Sep 17 00:00:00 2001 From: Dan Moore Date: Sat, 18 Apr 2009 15:54:23 -0400 Subject: Fixing spaces/tabs. --- actions/twitapiusers.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/actions/twitapiusers.php b/actions/twitapiusers.php index 92d67454c..1542cfb33 100644 --- a/actions/twitapiusers.php +++ b/actions/twitapiusers.php @@ -82,8 +82,8 @@ class TwitapiusersAction extends TwitterapiAction $twitter_user['profile_text_color'] = ''; $twitter_user['profile_link_color'] = ''; $twitter_user['profile_sidebar_fill_color'] = ''; - $twitter_user['profile_sidebar_border_color'] = ''; - $twitter_user['profile_background_tile'] = false; + $twitter_user['profile_sidebar_border_color'] = ''; + $twitter_user['profile_background_tile'] = false; $faves = DB_DataObject::factory('fave'); $faves->user_id = $user->id; @@ -103,16 +103,16 @@ class TwitapiusersAction extends TwitterapiAction if (isset($apidata['user'])) { - $twitter_user['following'] = $apidata['user']->isSubscribed($profile); + $twitter_user['following'] = $apidata['user']->isSubscribed($profile); - // Notifications on? - $sub = Subscription::pkeyGet(array('subscriber' => - $apidata['user']->id, 'subscribed' => $profile->id)); + // Notifications on? + $sub = Subscription::pkeyGet(array('subscriber' => + $apidata['user']->id, 'subscribed' => $profile->id)); - if ($sub) { - $twitter_user['notifications'] = ($sub->jabber || $sub->sms); - } - } + if ($sub) { + $twitter_user['notifications'] = ($sub->jabber || $sub->sms); + } + } if ($apidata['content-type'] == 'xml') { $this->init_document('xml'); -- cgit v1.2.3-54-g00ecf From e9213043a820095cceeb6cacbfacf08bba9d3142 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 18 Apr 2009 19:36:25 -0700 Subject: add reply_to index to notice --- db/laconica.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/db/laconica.sql b/db/laconica.sql index a790a3fd2..5b57494d9 100644 --- a/db/laconica.sql +++ b/db/laconica.sql @@ -117,6 +117,7 @@ create table notice ( index notice_profile_id_idx (profile_id), index notice_created_idx (created), + index notice_replyto_idx (reply_to), FULLTEXT(content) ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci; -- cgit v1.2.3-54-g00ecf From 340cd553ec2e028e57f27b30e3a438c4d95584be Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Sun, 19 Apr 2009 23:40:37 +0000 Subject: otalk theme (preliminary) --- theme/otalk/css/base.css | 1201 ++++++++++++++++++++ theme/otalk/css/display.css | 295 +++++ theme/otalk/css/ie.css | 9 + theme/otalk/default-avatar-mini.png | Bin 0 -> 646 bytes theme/otalk/default-avatar-profile.png | Bin 0 -> 2853 bytes theme/otalk/default-avatar-stream.png | Bin 0 -> 1487 bytes .../images/illustrations/illu_arrow-left-01.gif | Bin 0 -> 75 bytes .../otalk/images/illustrations/illu_pattern-01.png | Bin 0 -> 3218 bytes theme/otalk/logo.png | Bin 0 -> 4988 bytes 9 files changed, 1505 insertions(+) create mode 100644 theme/otalk/css/base.css create mode 100644 theme/otalk/css/display.css create mode 100644 theme/otalk/css/ie.css create mode 100644 theme/otalk/default-avatar-mini.png create mode 100644 theme/otalk/default-avatar-profile.png create mode 100644 theme/otalk/default-avatar-stream.png create mode 100644 theme/otalk/images/illustrations/illu_arrow-left-01.gif create mode 100644 theme/otalk/images/illustrations/illu_pattern-01.png create mode 100644 theme/otalk/logo.png diff --git a/theme/otalk/css/base.css b/theme/otalk/css/base.css new file mode 100644 index 000000000..c8737ea16 --- /dev/null +++ b/theme/otalk/css/base.css @@ -0,0 +1,1201 @@ +/** theme: italk base + * + * @package Laconica + * @author Sarven Capadisli + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +* { margin:0; padding:0; } +img { display:block; border:0; } +a abbr { cursor: pointer; border-bottom:0; } +table { border-collapse:collapse; } +ol { list-style-position:inside; } +html { font-size: 87.5%; background-color:#fff; height:100%; } +body { +background-color:#fff; +color:#000; +font-family:sans-serif; +font-size:1em; +line-height:1.65; +position:relative; +} +h1,h2,h3,h4,h5,h6 { +margin-bottom:7px; +overflow:hidden; +} +h1 { +font-size:1.4em; +margin-bottom:18px; +} +#showstream h1 { display:none; } +h2 { font-size:1.3em; } +h3 { font-size:1.2em; } +h4 { font-size:1.1em; } +h5 { font-size:1em; } +h6 { font-size:0.9em; } + +caption { +font-weight:bold; +} +legend { +font-weight:bold; +font-size:1.3em; +} +input, textarea, select, option { +padding:4px; +font-family:sans-serif; +font-size:1em; +} +input, textarea, select { +border-width:2px; +border-style: solid; +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +} + +input.submit { +font-weight:bold; +cursor:pointer; +} +textarea { +overflow:auto; +} +option { +padding-bottom:0; +} +fieldset { +padding:0; +border:0; +} +form ul li { +list-style-type:none; +margin:0 0 18px 0; +} +form label { +font-weight:bold; +} +input.checkbox { +position:relative; +top:2px; +left:0; +border:0; +} + +.error, +.success { +padding:4px 7px; +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +margin-bottom:18px; +} +form label.submit { +display:none; +} + +.form_settings { +clear:both; +} + +.form_settings fieldset { +margin-bottom:29px; +} +.form_settings input.remove { +margin-left:11px; +} +.form_settings .form_data li { +width:100%; +float:left; +} +.form_settings .form_data label { +float:left; +} +.form_settings .form_data textarea, +.form_settings .form_data select, +.form_settings .form_data input { +margin-left:11px; +float:left; +} +.form_settings .form_data input.submit { +margin-left:0; +} + +.form_settings label { +margin-top:2px; +width:152px; +} + +.form_actions label { +display:none; +} +.form_guide { +font-style:italic; +} + +.form_settings #settings_autosubscribe label { +display:inline; +font-weight:bold; +} + +#form_settings_profile legend, +#form_login legend, +#form_register legend, +#form_password legend, +#form_settings_avatar legend, +#newgroup legend, +#editgroup legend, +#form_tag_user legend, +#form_remote_subscribe legend, +#form_openid_login legend, +#form_search legend, +#form_invite legend, +#form_notice_delete legend, +#form_password_recover legend, +#form_password_change legend { +display:none; +} + +.form_settings .form_data p.form_guide { +clear:both; +margin-left:163px; +margin-bottom:0; +} + +.form_settings p { +margin-bottom:11px; +} + +.form_settings input.checkbox { +margin-top:3px; +margin-left:0; +} +.form_settings label.checkbox { +font-weight:normal; +margin-top:0; +margin-right:0; +margin-left:11px; +float:left; +width:90%; +} + + +#form_login p.form_guide, +#form_register #settings_rememberme p.form_guide, +#form_openid_login #settings_rememberme p.form_guide, +#settings_twitter_remove p.form_guide, +#form_search ul.form_data #q { +margin-left:0; +} + +.form_settings .form_note { +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +padding:0 7px; +} + + +.form_settings input.form_action-secondary { +margin-left:29px; +padding:0; +} + +#form_search .submit { +margin-left:11px; +} + +address { +float:left; +margin-bottom:18px; +margin-left:18px; +} +address.vcard img.logo { +margin-right:0; +} +address .fn { +font-weight:bold; +} +address img + .fn { +display:none; +} + +#header { +width:100%; +position:relative; +float:left; +padding-top:18px; +margin-bottom:29px; +} + +#site_nav_global_primary { +float:right; +margin-right:18px; +margin-bottom:11px; +margin-left:18px; +} +#site_nav_global_primary ul li { +display:inline; +margin-left:11px; +} + +.system_notice dt { +font-weight:bold; +text-transform:uppercase; +display:none; +} + +#site_notice { +position:absolute; +top:65px; +right:18px; +width:250px; +width:24%; +} +#page_notice { +clear:both; +margin-bottom:18px; +} + + +#anon_notice { +float:left; +width:43.2%; +padding:1.1%; +border-radius:7px; +-moz-border-radius:7px; +-webkit-border-radius:7px; +border-width:2px; +border-style:solid; +line-height:1.5; +font-size:1.1em; +font-weight:bold; +} + + +#footer { +float:left; +width:64%; +padding:18px; +} + +#site_nav_local_views { +float:left; +} +#site_nav_local_views dt { +display:none; +} +#site_nav_local_views li { +float:left; +margin-right:18px; +list-style-type:none; +} +#site_nav_local_views a { +float:left; +text-decoration:none; +padding:4px 11px; +-moz-border-radius-topleft:4px; +-moz-border-radius-topright:4px; +-webkit-border-top-left-radius:4px; +-webkit-border-top-right-radius:4px; +border-width:0; +border-style:solid; +border-bottom:0; +text-shadow: 2px 2px 2px #ddd; +font-weight:bold; +} +#site_nav_local_views .nav { +float:left; +width:100%; +border-bottom-width:1px; +border-bottom-style:solid; +} + +#site_nav_global_primary dt, +#site_nav_global_secondary dt { +display:none; +} + +#site_nav_global_secondary { +margin-bottom:11px; +} + +#site_nav_global_secondary ul li { +display:inline; +margin-right:11px; +} +#export_data li a { +padding-left:20px; +} +#export_data li a.foaf { +padding-left:30px; +} +#export_data li a.export_vcard { +padding-left:28px; +} + +#export_data ul { +display:inline; +} +#export_data li { +list-style-type:none; +display:inline; +margin-left:11px; +} +#export_data li:first-child { +margin-left:0; +} + +#licenses { +font-size:0.9em; +} + +#licenses dt { +font-weight:bold; +display:none; +} +#licenses dd { +margin-bottom:11px; +line-height:1.5; +} + +#site_content_license_cc { +margin-bottom:0; +} +#site_content_license_cc img { +display:inline; +vertical-align:top; +margin-right:4px; +} + +#wrap { +margin:0 auto; +width:100%; +min-width:760px; +max-width:1003px; +overflow:hidden; +} + +#core { +position:relative; +width:100%; +float:left; +margin-bottom:1em; +} + +#content { +width:100%; +min-height:259px; +padding-top:1.795%; +padding-bottom:1.795%; + +float:left; +border-radius:7px; +-moz-border-radius:7px; +-moz-border-radius-topleft:0; +-webkit-border-radius:7px; +-webkit-border-top-left-radius:0; +border-style:solid; +border-width:0; +margin-bottom:18px; +} + +#content_inner { +position:relative; +width:100%; +float:left; +} + +#aside_primary { +width:96.3%; +min-height:259px; +float:left; +clear:both; +padding:1.795%; +border-radius:7px; +-moz-border-radius:7px; +-webkit-border-radius:7px; +border-width:1px; +border-style:solid; +} + +#form_notice { +width:45.664%; +float:left; +position:relative; +line-height:1; +} +#form_notice fieldset { +border:0; +padding:0; +} +#form_notice legend { +display:none; +} +#form_notice textarea { +float:left; +border-radius:7px; +-moz-border-radius:7px; +-webkit-border-radius:7px; +width:80.789%; +height:67px; +line-height:1.5; +padding:7px 7px 16px 7px; +} +#form_notice label { +display:block; +float:left; +font-size:1.3em; +margin-bottom:7px; +} +#form_notice #notice_submit label { +display:none; +} +#form_notice .form_note { +position:absolute; +top:99px; +right:98px; +z-index:9; +} +#form_notice .form_note dt { +font-weight:bold; +display:none; +} +#notice_text-count { +font-weight:bold; +line-height:1.15; +padding:1px 2px; +} +#form_notice #notice_action-submit { +width:14%; +height:47px; +padding:0; +position:absolute; +bottom:0; +right:0; +} +#form_notice label[for=to] { +margin-top:7px; +} +#form_notice select[id=to] { +margin-bottom:7px; +margin-left:18px; +float:left; +} + + +/* entity_profile */ +.entity_profile { +position:relative; +width:521px; +min-height:123px; +float:left; +margin-bottom:18px; +margin-left:0; +overflow:hidden; +} +.entity_profile dt, +#entity_statistics dt { +font-weight:bold; +} +.entity_profile dd { +display:inline; +} + +.entity_profile .entity_depiction { +float:left; +width:96px; +margin-right:18px; +margin-bottom:18px; +} + +.entity_profile .entity_fn, +.entity_profile .entity_nickname, +.entity_profile .entity_location, +.entity_profile .entity_url, +.entity_profile .entity_note, +.entity_profile .entity_tags { +margin-left:113px; +margin-bottom:4px; +} + +.entity_profile .entity_fn, +.entity_profile .entity_nickname { +margin-left:11px; +display:inline; +font-weight:bold; +} +.entity_profile .entity_nickname { +margin-left:0; +} + +.entity_profile .entity_fn dd:before { +content: "("; +font-weight:normal; +} +.entity_profile .entity_fn dd:after { +content: ")"; +font-weight:normal; +} + +.entity_profile dt { +display:none; +} +.entity_profile h2 { +display:none; +} +/* entity_profile */ + + +/*entity_actions*/ +.entity_actions { +float:left; +margin-left:4.35%; +max-width:25%; +} +.entity_actions h2 { +display:none; +} +.entity_actions ul { +list-style-type:none; +} +.entity_actions li { +margin-bottom:4px; +} +.entity_actions li:first-child { +border-top:0; +} +.entity_actions fieldset { +border:0; +padding:0; +} +.entity_actions legend { +display:none; +} + +.entity_actions input.submit { +display:block; +text-align:left; +width:100%; +} +.entity_actions a, +.entity_nudge p, +.entity_remote_subscribe { +text-decoration:none; +font-weight:bold; +display:block; +} + +.form_user_block input.submit, +.form_user_unblock input.submit, +.entity_send-a-message a, +.entity_edit a, +.form_user_nudge input.submit, +.entity_nudge p { +border:0; +padding-left:20px; +} + +.entity_edit a, +.entity_send-a-message a, +.entity_nudge p { +padding:4px 4px 4px 23px; +} + +.entity_remote_subscribe { +padding:4px; +border-width:2px; +border-style:solid; +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +} +.entity_actions .accept { +margin-bottom:18px; +} + +.entity_tags ul { +list-style-type:none; +display:inline; +} +.entity_tags li { +display:inline; +margin-right:4px; +} + +.aside .section { +margin-bottom:29px; +clear:both; +float:left; +width:100%; +} +.aside .section h2 { +text-transform:uppercase; +font-size:1em; +} + +#entity_statistics dt, +#entity_statistics dd { +display:inline; +} +#entity_statistics dt:after { +content: ":"; +} + +.section ul.entities { +float:left; +width:100%; +} +.section .entities li { +list-style-type:none; +float:left; +margin-right:7px; +margin-bottom:7px; +} +.section .entities li .photo { +margin-right:0; +margin-bottom:0; +} +.section .entities li .fn { +display:none; +} + +.aside .section p, +.aside .section .more { +clear:both; +} + +.profile .entity_profile { +margin-bottom:0; +min-height:60px; +} + + +.profile .form_group_join legend, +.profile .form_group_leave legend, +.profile .form_user_subscribe legend, +.profile .form_user_unsubscribe legend { +display:none; +} + +.profiles { +list-style-type:none; +} +.profile .entity_profile .entity_location { +width:auto; +clear:none; +margin-left:11px; +} +.profile .entity_profile dl, +.profile .entity_profile dd { +display:inline; +float:none; +} +.profile .entity_profile .entity_note, +.profile .entity_profile .entity_url, +.profile .entity_profile .entity_tags, +.profile .entity_profile .form_subscription_edit { +margin-left:59px; +clear:none; +display:block; +width:auto; +} +.profile .entity_profile .entity_tags dt { +display:inline; +margin-right:11px; +} + + +.profile .entity_profile .form_subscription_edit label { +font-weight:normal; +margin-right:11px; +} + + +/* NOTICE */ +.notice, +.profile { +position:relative; +clear:both; +float:left; +width:100%; +border-width:0; +border-style:solid; +margin-bottom:29px; +} +.notices li { +list-style-type:none; +} + +#content .notice { +width:25%; +margin-left:20px; +margin-bottom:47px; +clear:none; +overflow:hidden; +padding: 0 0 0 62px; +min-height:260px; +} + +/* NOTICES */ +#notices_primary { +float:left; +width:100%; +border-radius:7px; +-moz-border-radius:7px; +-webkit-border-radius:7px; +} +#notices_primary h2 { +display:none; +} +.notice-data a span { +display:block; +padding-left:28px; +} + +.notice .author { +margin-right:11px; +} + +#content .notice .author { +/*overflow:hidden;*/ +} + +.fn { +overflow:hidden; +} + +.notice .author .fn { +font-weight:bold; +} + +.notice .author .photo { +margin-bottom:0; +} + +#content .notice .author .photo { +margin-left:-80px; +padding-right:14px; +} + + +.vcard .photo { +display:inline; +margin-right:11px; +margin-bottom:11px; +float:left; +} +.vcard .url { +text-decoration:none; +} +.vcard .url:hover { +text-decoration:underline; +} + +.notice .entry-title { +float:left; +width:100%; +overflow:hidden; +} +#content .notice .entry-title { +overflow:visible; +margin-bottom:11px; +padding:18px; +width:83%; +border-radius:7px; +-moz-border-radius:7px; +-webkit-border-radius:7px; +min-height:165px; +} + +#shownotice .notice .entry-title { +font-size:2.2em; +} + +.notice p.entry-content { +display:inline; +} + +#content .notice p.entry-content +overflow:hidden; +} + +.notice p.entry-content .vcard a { +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +} + +.notice div.entry-content { +clear:left; +float:left; +font-size:0.95em; +} +#showstream .notice div.entry-content { +margin-left:0; +} + +.notice .notice-options a, +.notice .notice-options input { +float:left; +font-size:1.025em; +} + +.notice div.entry-content dl, +.notice div.entry-content dt, +.notice div.entry-content dd { +display:inline; +} + +.notice div.entry-content .timestamp dt, +.notice div.entry-content .response dt { +display:none; +} +.notice div.entry-content .timestamp a { +display:inline-block; +} +.notice div.entry-content .device dt { +text-transform:lowercase; +} + + + +.notice-data { +position:absolute; +top:18px; +right:0; +min-height:50px; +margin-bottom:4px; +} +.notice .entry-content .notice-data dt { +display:none; +} + +.notice-data a { +display:block; +outline:none; +} + +.notice-options { +position:absolute; +bottom:110px; +left:29px; +font-size:0.95em; +float:right; +} + +.notice-options a { +float:left; +} +.notice-options .notice_delete, +.notice-options .notice_reply, +.notice-options .form_favor, +.notice-options .form_disfavor { +position:absolute; +left:0; +} +.notice-options .form_favor, +.notice-options .form_disfavor { +top:0; +} +.notice-options .notice_reply { +top:29px; +} +.notice-options .notice_delete { +top:58px; +} +.notice-options .notice_reply dt { +display:none; +} + +.notice-options input, +.notice-options a { +text-indent:-9999px; +outline:none; +} + +.notice-options .notice_reply a, +.notice-options input.submit { +display:block; +border:0; +} +.notice-options .notice_reply a, +.notice-options .notice_delete a { +text-decoration:none; +padding-left:16px; +} + +.notice-options form input.submit { +width:16px; +padding:2px 0; +} + +.notice-options .notice_delete dt, +.notice-options .form_favor legend, +.notice-options .form_disfavor legend { +display:none; +} +.notice-options .notice_delete fieldset, +.notice-options .form_favor fieldset, +.notice-options .form_disfavor fieldset { +border:0; +padding:0; +} + + +#usergroups #new_group { +float: left; +margin-right: 2em; +} +#new_group, #group_search { +margin-bottom:18px; +} +#new_group a { +padding-left:20px; +} + + +#filter_tags { +margin-bottom:11px; +float:left; +} +#filter_tags dt { +display:none; +} +#filter_tags ul { +list-style-type:none; +} +#filter_tags ul li { +float:left; +margin-left:7px; +padding-left:7px; +border-left-width:1px; +border-left-style:solid; +} +#filter_tags ul li.child_1 { +margin-left:0; +border-left:0; +padding-left:0; +} +#filter_tags ul li#filter_tags_all a { +font-weight:bold; +margin-top:7px; +float:left; +} + +#filter_tags ul li#filter_tags_item label { +margin-right:7px; +} +#filter_tags ul li#filter_tags_item label, +#filter_tags ul li#filter_tags_item select { +display:inline; +} +#filter_tags ul li#filter_tags_item p { +float:left; +margin-left:38px; +} +#filter_tags ul li#filter_tags_item input { +position:relative; +top:3px; +left:3px; +} + + + +.pagination { +float:left; +clear:both; +width:100%; +margin-top:18px; +} + +.pagination dt { +font-weight:bold; +display:none; +} + +.pagination .nav { +float:left; +width:100%; +list-style-type:none; +} + +.pagination .nav_prev { +float:left; +} +.pagination .nav_next { +float:right; +} + +.pagination a { +display:block; +text-decoration:none; +font-weight:bold; +padding:7px; +border-width:1px; +border-style:solid; +-moz-border-radius:7px; +-webkit-border-radius:7px; +border-radius:7px; +} + +.pagination .nav_prev a { +padding-left:30px; +} +.pagination .nav_next a { +padding-right:30px; +} +/* END: NOTICE */ + + +.hentry .entry-content p { +margin-bottom:18px; +} +.hentry entry-content ol, +.hentry .entry-content ul { +list-style-position:inside; +} +.hentry .entry-content li { +margin-bottom:18px; +} +.hentry .entry-content li li { +margin-left:18px; +} + + + + +/* TOP_POSTERS */ +.section tbody td { +padding-right:11px; +padding-bottom:11px; +} +.section .vcard .photo { +margin-right:7px; +margin-bottom:0; +} + +.section .notice { +padding-top:7px; +padding-bottom:7px; +border-top:0; +} + +.section .notice:first-child { +padding-top:0; +} + +.section .notice .author { +margin-right:0; +} +.section .notice .author .fn { +display:none; +} + + +/* tagcloud */ +.tag-cloud { +list-style-type:none; +text-align:center; +} +.aside .tag-cloud { +font-size:0.8em; +} +.tag-cloud li { +display:inline; +margin-right:7px; +line-height:1.25; +} +.aside .tag-cloud li { +line-height:1.5; +} +.tag-cloud li a { +text-decoration:none; +} +#tagcloud.section dt { +text-transform:uppercase; +font-weight:bold; +} +.tag-cloud-1 { +font-size:1em; +} +.tag-cloud-2 { +font-size:1.25em; +} +.tag-cloud-3 { +font-size:1.75em; +} +.tag-cloud-4 { +font-size:2em; +} +.tag-cloud-5 { +font-size:2.25em; +} +.tag-cloud-6 { +font-size:2.75em; +} +.tag-cloud-7 { +font-size:3.25em; +} + +#publictagcloud #tagcloud.section dt { +display:none; +} + +#form_settings_photo .form_data { +clear:both; +} + +#form_settings_avatar li { +width:auto; +} +#form_settings_avatar input { +margin-left:0; +} +#avatar_original, +#avatar_preview { +float:left; +} +#avatar_preview { +margin-left:29px; +} +#avatar_preview_view { +height:96px; +width:96px; +margin-bottom:18px; +overflow:hidden; +} + +#settings_attach, +#form_settings_avatar .form_actions { +clear:both; +} + +#form_settings_avatar .form_actions { +margin-bottom:0; +} + +#form_settings_design #settings_design_color .form_data, +#form_settings_design #color-picker { +float:left; +} +#form_settings_design #settings_design_color .form_data { +width:400px; +margin-right:28px; +} + +.instructions ul { +list-style-position:inside; +} +.instructions p, +.instructions ul { +margin-bottom:18px; +} +.help dt { +display:none; +} +.guide { +clear:both; +} diff --git a/theme/otalk/css/display.css b/theme/otalk/css/display.css new file mode 100644 index 000000000..54350fcc6 --- /dev/null +++ b/theme/otalk/css/display.css @@ -0,0 +1,295 @@ +/** theme: identica + * + * @package Laconica + * @author Sarven Capadisli + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +@import url(base.css); + +html { +} + +html, +body, +a:active { +/*background-color:#F0F2F5;*/ +} +body { +font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; +font-size:1em; +background:#ddd url(../images/illustrations/illu_pattern-01.png) repeat 0 0; +background-color:rgba(127, 127, 127, 0.1); +} +address { +margin-right:7.18%; +} + +input, textarea, select, option { +font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; +} +input, textarea, select, +.entity_remote_subscribe { +border-color:#aaa; +} +#filter_tags ul li { +border-color:#ddd; +} + +.form_settings input.form_action-secondary { +background:none; +} + +input.submit, +#form_notice.warning #notice_text-count, +.form_settings .form_note, +.entity_remote_subscribe { +background-color:#9BB43E; +} + +input:focus, textarea:focus, select:focus, +#form_notice.warning #notice_data-text { +border-color:#9BB43E; +} +input.submit, +.entity_remote_subscribe { +color:#fff; +} + +a, +div.notice-options input, +.form_user_block input.submit, +.form_user_unblock input.submit, +.entity_send-a-message a, +.form_user_nudge input.submit, +.entity_nudge p, +.form_settings input.form_action-secondary { +color:#8F0000; +} + +.notice, +.profile { +border-color:#CEE1E9; +} +#content .notice .entry-title, +input, textarea, select, option { +background-color:rgba(255,255,255,0.8); +} + +#content .notices li.hover .entry-title { +background-color:rgba(255,255,255,0.9); +} + +#content .notice:nth-child(1) .entry-title { +background-color:rgba(255,255,255,0.95); +font-size:2em; +} +#content .notice:nth-child(2) .entry-title { +background-color:rgba(255,255,255,0.9); +font-size:1.9em; +} +#content .notice:nth-child(3) .entry-title { +background-color:rgba(255,255,255,0.8); +font-size:1.8em; +} +#content .notice:nth-child(4) .entry-title { +background-color:rgba(255,255,255,0.7); +font-size:1.7em; +} +#content .notice:nth-child(5) .entry-title { +background-color:rgba(255,255,255,0.6); +} +#content .notice:nth-child(6) .entry-title { +background-color:rgba(255,255,255,0.5); +} +#content .notice:nth-child(7) .entry-title { +background-color:rgba(255,255,255,0.4); +} +#content .notice:nth-child(8) .entry-title { +background-color:rgba(255,255,255,0.3); +} +#content .notice:nth-child(9) .entry-title { +background-color:rgba(255,255,255,0.2); +} +#content .notice:nth-child(10) { +background-color:rgba(255,255,255,0.1); +} + + +#content .notice .author .photo { +background:url(../images/illustrations/illu_arrow-left-01.gif) no-repeat 100% 0; +} + +.section .profile { +border-top-color:#87B4C8; +} + +#aside_primary { +background-color:rgba(206, 225, 233,0.5); +} + +#notice_text-count { +color:#333; +} +#form_notice.warning #notice_text-count { +color:#000; +} +#form_notice.processing #notice_action-submit { +background:#fff url(../../base/images/icons/icon_processing.gif) no-repeat 47% 47%; +cursor:wait; +text-indent:-9999px; +} + +#content, +#site_nav_local_views .nav, +#site_nav_local_views a, +#aside_primary { +border-color:#fff; +} +#content, +#site_nav_local_views .current a { +background-color:transparent; +/*background-color:red;*/ +} + +#site_nav_local_views .current a { +background-color:transparent; +} + +#site_nav_local_views a { +background-color:rgba(127, 127, 127, 0.2); +} +#site_nav_local_views a:hover { +background-color:rgba(255, 255, 255, 0.8); +} + +.error { +background-color:#F7E8E8; +} +.success { +background-color:#EFF3DC; +} + +#anon_notice { +background-color:#87B4C8; +color:#fff; +border-color:#fff; +} + +#showstream #anon_notice { +background-color:#9BB43E; +} + +#export_data li a { +background-repeat:no-repeat; +background-position:0 45%; +} +#export_data li a.rss { +background-image:url(../../base/images/icons/icon_rss.png); +} +#export_data li a.atom { +background-image:url(../../base/images/icons/icon_atom.png); +} +#export_data li a.foaf { +background-image:url(../../base/images/icons/icon_foaf.gif); +} + +.entity_edit a, +.entity_send-a-message a, +.form_user_nudge input.submit, +.form_user_block input.submit, +.form_user_unblock input.submit, +.entity_nudge p { +background-position: 0 40%; +background-repeat: no-repeat; +background-color:transparent; +} +.form_group_join input.submit, +.form_group_leave input.submit +.form_user_subscribe input.submit, +.form_user_unsubscribe input.submit { +background-color:#9BB43E; +color:#fff; +} +.form_user_unsubscribe input.submit, +.form_group_leave input.submit, +.form_user_authorization input.reject { +background-color:#87B4C8; +} + +.entity_edit a { +background-image:url(../../base/images/icons/twotone/green/edit.gif); +} +.entity_send-a-message a { +background-image:url(../../base/images/icons/twotone/green/quote.gif); +} +.entity_nudge p, +.form_user_nudge input.submit { +background-image:url(../../base/images/icons/twotone/green/mail.gif); +} +.form_user_block input.submit, +.form_user_unblock input.submit { +background-image:url(../../base/images/icons/twotone/green/shield.gif); +} + +/* NOTICES */ +.notices li.over { +background-color:#fcfcfc; +} + +.notice-options .notice_reply a, +.notice-options form input.submit { +background-color:transparent; +} +.notice-options .notice_reply a { +background:transparent url(../../base/images/icons/twotone/green/reply.gif) no-repeat 0 45%; +} +.notice-options form.form_favor input.submit { +background:transparent url(../../base/images/icons/twotone/green/favourite.gif) no-repeat 0 45%; +} +.notice-options form.form_disfavor input.submit { +background:transparent url(../../base/images/icons/twotone/green/disfavourite.gif) no-repeat 0 45%; +} +.notice-options .notice_delete a { +background:transparent url(../../base/images/icons/twotone/green/trash.gif) no-repeat 0 45%; +} + +.notices div.entry-content, +.notices div.notice-options { +opacity:0.4; +} +.notices li.hover div.entry-content, +.notices li.hover div.notice-options { +opacity:1; +} +div.entry-content { +color:#333; +} +div.notice-options a, +div.notice-options input { +font-family:sans-serif; +} +.notices li.hover { +/*background-color:#fcfcfc;*/ +} +/*END: NOTICES */ + +#new_group a { +background:transparent url(../../base/images/icons/twotone/green/news.gif) no-repeat 0 45%; +} + +.pagination .nav_prev a, +.pagination .nav_next a { +background-repeat:no-repeat; +border-color:#CEE1E9; +} +.pagination .nav_prev a { +background-image:url(../../base/images/icons/twotone/green/arrow-left.gif); +background-position:10% 45%; +} +.pagination .nav_next a { +background-image:url(../../base/images/icons/twotone/green/arrow-right.gif); +background-position:90% 45%; +} diff --git a/theme/otalk/css/ie.css b/theme/otalk/css/ie.css new file mode 100644 index 000000000..2f463bb44 --- /dev/null +++ b/theme/otalk/css/ie.css @@ -0,0 +1,9 @@ +/* IE specific styles */ + +.notice-options input.submit { +color:#fff; +} + +#site_nav_local_views a { +background-color:#D0DFE7; +} diff --git a/theme/otalk/default-avatar-mini.png b/theme/otalk/default-avatar-mini.png new file mode 100644 index 000000000..38b8692b4 Binary files /dev/null and b/theme/otalk/default-avatar-mini.png differ diff --git a/theme/otalk/default-avatar-profile.png b/theme/otalk/default-avatar-profile.png new file mode 100644 index 000000000..f8357d4fc Binary files /dev/null and b/theme/otalk/default-avatar-profile.png differ diff --git a/theme/otalk/default-avatar-stream.png b/theme/otalk/default-avatar-stream.png new file mode 100644 index 000000000..6b63baa70 Binary files /dev/null and b/theme/otalk/default-avatar-stream.png differ diff --git a/theme/otalk/images/illustrations/illu_arrow-left-01.gif b/theme/otalk/images/illustrations/illu_arrow-left-01.gif new file mode 100644 index 000000000..197775976 Binary files /dev/null and b/theme/otalk/images/illustrations/illu_arrow-left-01.gif differ diff --git a/theme/otalk/images/illustrations/illu_pattern-01.png b/theme/otalk/images/illustrations/illu_pattern-01.png new file mode 100644 index 000000000..5a72eafcb Binary files /dev/null and b/theme/otalk/images/illustrations/illu_pattern-01.png differ diff --git a/theme/otalk/logo.png b/theme/otalk/logo.png new file mode 100644 index 000000000..7c68b34f6 Binary files /dev/null and b/theme/otalk/logo.png differ -- cgit v1.2.3-54-g00ecf From a37bfcbb4344948497f3055c641f174314f07d7b Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Sun, 19 Apr 2009 23:45:03 +0000 Subject: Update to theme name in stylesheets. --- theme/otalk/css/base.css | 2 +- theme/otalk/css/display.css | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/theme/otalk/css/base.css b/theme/otalk/css/base.css index c8737ea16..fc82798c8 100644 --- a/theme/otalk/css/base.css +++ b/theme/otalk/css/base.css @@ -1,4 +1,4 @@ -/** theme: italk base +/** theme: otalk base * * @package Laconica * @author Sarven Capadisli diff --git a/theme/otalk/css/display.css b/theme/otalk/css/display.css index 54350fcc6..b6ee9aaea 100644 --- a/theme/otalk/css/display.css +++ b/theme/otalk/css/display.css @@ -1,4 +1,4 @@ -/** theme: identica +/** theme: otalk * * @package Laconica * @author Sarven Capadisli -- cgit v1.2.3-54-g00ecf From 802c1f121b58651cf2d68207781c09bd8958e546 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Mon, 20 Apr 2009 01:00:40 +0000 Subject: otalk theme update to overflows --- theme/otalk/css/base.css | 24 ++++++++++++++---------- theme/otalk/css/display.css | 8 +++----- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/theme/otalk/css/base.css b/theme/otalk/css/base.css index fc82798c8..379590d30 100644 --- a/theme/otalk/css/base.css +++ b/theme/otalk/css/base.css @@ -731,14 +731,19 @@ list-style-type:none; #content .notice { width:25%; -margin-left:20px; +margin-left:17px; margin-bottom:47px; clear:none; overflow:hidden; -padding: 0 0 0 62px; -min-height:260px; +padding: 0 0 0 65px; +min-height:235px; } +#aside_primary .notice { +margin-bottom:18px; +} + + /* NOTICES */ #notices_primary { float:left; @@ -776,8 +781,8 @@ margin-bottom:0; } #content .notice .author .photo { -margin-left:-80px; -padding-right:14px; +margin-left:-83px; +padding-right:17px; } @@ -803,11 +808,11 @@ overflow:hidden; overflow:visible; margin-bottom:11px; padding:18px; -width:83%; +width:85%; border-radius:7px; -moz-border-radius:7px; -webkit-border-radius:7px; -min-height:165px; +min-height:161px; } #shownotice .notice .entry-title { @@ -880,10 +885,9 @@ outline:none; .notice-options { position:absolute; -bottom:110px; -left:29px; +top:120px; +left:30px; font-size:0.95em; -float:right; } .notice-options a { diff --git a/theme/otalk/css/display.css b/theme/otalk/css/display.css index b6ee9aaea..c03920339 100644 --- a/theme/otalk/css/display.css +++ b/theme/otalk/css/display.css @@ -74,7 +74,9 @@ color:#8F0000; border-color:#CEE1E9; } #content .notice .entry-title, -input, textarea, select, option { +input, textarea, select, option, +.pagination .nav_prev a, +.pagination .nav_next a { background-color:rgba(255,255,255,0.8); } @@ -84,19 +86,15 @@ background-color:rgba(255,255,255,0.9); #content .notice:nth-child(1) .entry-title { background-color:rgba(255,255,255,0.95); -font-size:2em; } #content .notice:nth-child(2) .entry-title { background-color:rgba(255,255,255,0.9); -font-size:1.9em; } #content .notice:nth-child(3) .entry-title { background-color:rgba(255,255,255,0.8); -font-size:1.8em; } #content .notice:nth-child(4) .entry-title { background-color:rgba(255,255,255,0.7); -font-size:1.7em; } #content .notice:nth-child(5) .entry-title { background-color:rgba(255,255,255,0.6); -- cgit v1.2.3-54-g00ecf From 5d9862248bebf41bd1f97c03ec9f4f86fa206e82 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Mon, 20 Apr 2009 01:58:49 +0000 Subject: otalk theme: anon_notice background colour update --- theme/otalk/css/display.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/theme/otalk/css/display.css b/theme/otalk/css/display.css index c03920339..22e0530ec 100644 --- a/theme/otalk/css/display.css +++ b/theme/otalk/css/display.css @@ -171,13 +171,13 @@ background-color:#EFF3DC; } #anon_notice { -background-color:#87B4C8; +background-color:rgba(206, 225, 233, 0.7); color:#fff; border-color:#fff; } #showstream #anon_notice { -background-color:#9BB43E; +background-color:rgba(155, 180, 62, 0.7); } #export_data li a { -- cgit v1.2.3-54-g00ecf From aadad4579fcdd3e62f5b8b8f2fcaa6cc282924f2 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Mon, 20 Apr 2009 04:37:13 +0000 Subject: earthy theme preliminary (colours only) --- theme/earthy/css/base.css | 1176 +++++++++++++++++++++++++++++++ theme/earthy/css/display.css | 245 +++++++ theme/earthy/css/ie.css | 9 + theme/earthy/default-avatar-mini.png | Bin 0 -> 646 bytes theme/earthy/default-avatar-profile.png | Bin 0 -> 2853 bytes theme/earthy/default-avatar-stream.png | Bin 0 -> 1487 bytes theme/earthy/logo.png | Bin 0 -> 4988 bytes 7 files changed, 1430 insertions(+) create mode 100644 theme/earthy/css/base.css create mode 100644 theme/earthy/css/display.css create mode 100644 theme/earthy/css/ie.css create mode 100644 theme/earthy/default-avatar-mini.png create mode 100644 theme/earthy/default-avatar-profile.png create mode 100644 theme/earthy/default-avatar-stream.png create mode 100644 theme/earthy/logo.png diff --git a/theme/earthy/css/base.css b/theme/earthy/css/base.css new file mode 100644 index 000000000..8ff65ad50 --- /dev/null +++ b/theme/earthy/css/base.css @@ -0,0 +1,1176 @@ +/** theme: earthy base + * + * @package Laconica + * @author Sarven Capadisli + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +* { margin:0; padding:0; } +img { display:block; border:0; } +a abbr { cursor: pointer; border-bottom:0; } +table { border-collapse:collapse; } +ol { list-style-position:inside; } +html { background-color:#fff; height:100%; } +body { +background-color:#fff; +color:#000; +font-family:sans-serif; +font-size:1em; +line-height:1.65; +position:relative; +} +h1,h2,h3,h4,h5,h6 { +margin-bottom:7px; +overflow:hidden; +} +h1 { +font-size:1.4em; +margin-bottom:18px; +} +#showstream h1 { display:none; } +h2 { font-size:1.3em; } +h3 { font-size:1.2em; } +h4 { font-size:1.1em; } +h5 { font-size:1em; } +h6 { font-size:0.9em; } + +caption { +font-weight:bold; +} +legend { +font-weight:bold; +font-size:1.3em; +} +input, textarea, select, option { +padding:4px; +font-family:sans-serif; +font-size:1em; +} +input, textarea, select { +border-width:2px; +border-style: solid; +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +} + +input.submit { +font-weight:bold; +cursor:pointer; +} +textarea { +overflow:auto; +} +option { +padding-bottom:0; +} +fieldset { +padding:0; +border:0; +} +form ul li { +list-style-type:none; +margin:0 0 18px 0; +} +form label { +font-weight:bold; +} +input.checkbox { +position:relative; +top:2px; +left:0; +border:0; +} + +.error, +.success { +padding:4px 7px; +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +margin-bottom:18px; +} +form label.submit { +display:none; +} + +.form_settings { +clear:both; +} + +.form_settings fieldset { +margin-bottom:29px; +} +.form_settings input.remove { +margin-left:11px; +} +.form_settings .form_data li { +width:100%; +float:left; +} +.form_settings .form_data label { +float:left; +} +.form_settings .form_data textarea, +.form_settings .form_data select, +.form_settings .form_data input { +margin-left:11px; +float:left; +} +.form_settings .form_data input.submit { +margin-left:0; +} + +.form_settings label { +margin-top:2px; +width:152px; +} + +.form_actions label { +display:none; +} +.form_guide { +font-style:italic; +} + +.form_settings #settings_autosubscribe label { +display:inline; +font-weight:bold; +} + +#form_settings_profile legend, +#form_login legend, +#form_register legend, +#form_password legend, +#form_settings_avatar legend, +#newgroup legend, +#editgroup legend, +#form_tag_user legend, +#form_remote_subscribe legend, +#form_openid_login legend, +#form_search legend, +#form_invite legend, +#form_notice_delete legend, +#form_password_recover legend, +#form_password_change legend { +display:none; +} + +.form_settings .form_data p.form_guide { +clear:both; +margin-left:163px; +margin-bottom:0; +} + +.form_settings p { +margin-bottom:11px; +} + +.form_settings input.checkbox { +margin-top:3px; +margin-left:0; +} +.form_settings label.checkbox { +font-weight:normal; +margin-top:0; +margin-right:0; +margin-left:11px; +float:left; +width:90%; +} + + +#form_login p.form_guide, +#form_register #settings_rememberme p.form_guide, +#form_openid_login #settings_rememberme p.form_guide, +#settings_twitter_remove p.form_guide, +#form_search ul.form_data #q { +margin-left:0; +} + +.form_settings .form_note { +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +padding:0 7px; +} + + +.form_settings input.form_action-secondary { +margin-left:29px; +padding:0; +} + +#form_search .submit { +margin-left:11px; +} + +address { +float:left; +margin-bottom:18px; +margin-left:18px; +} +address.vcard img.logo { +margin-right:0; +} +address .fn { +font-weight:bold; +} +address img + .fn { +display:none; +} + +#header { +width:100%; +position:relative; +float:left; +padding-top:18px; +margin-bottom:29px; +} + +#site_nav_global_primary { +float:right; +margin-right:18px; +margin-bottom:11px; +margin-left:18px; +} +#site_nav_global_primary ul li { +display:inline; +margin-left:11px; +} + +.system_notice dt { +font-weight:bold; +text-transform:uppercase; +display:none; +} + +#site_notice { +position:absolute; +top:65px; +right:18px; +width:250px; +width:24%; +} +#page_notice { +clear:both; +margin-bottom:18px; +} + + +#anon_notice { +float:left; +width:43.2%; +padding:1.1%; +border-radius:7px; +-moz-border-radius:7px; +-webkit-border-radius:7px; +border-width:2px; +border-style:solid; +line-height:1.5; +font-size:1.1em; +font-weight:bold; +} + + +#footer { +float:left; +width:64%; +padding:18px; +} + +#site_nav_local_views { +float:right; +} +#site_nav_local_views dt { +display:none; +} +#site_nav_local_views li { +float:right; +margin-left:11px; +list-style-type:none; +} +#site_nav_local_views a { +float:left; +text-decoration:none; +padding:4px 11px; +-moz-border-radius-topleft:4px; +-moz-border-radius-topright:4px; +-webkit-border-top-left-radius:4px; +-webkit-border-top-right-radius:4px; +border-width:1px; +border-style:solid; +border-bottom:0; +text-shadow: 2px 2px 2px #ddd; +font-weight:bold; +} +#site_nav_local_views .nav { +float:left; +width:100%; +} + +#site_nav_global_primary dt, +#site_nav_global_secondary dt { +display:none; +} + +#site_nav_global_secondary { +margin-bottom:11px; +} + +#site_nav_global_secondary ul li { +display:inline; +margin-right:11px; +} +#export_data li a { +padding-left:20px; +} +#export_data li a.foaf { +padding-left:30px; +} +#export_data li a.export_vcard { +padding-left:28px; +} + +#export_data ul { +display:inline; +} +#export_data li { +list-style-type:none; +display:inline; +margin-left:11px; +} +#export_data li:first-child { +margin-left:0; +} + +#licenses { +font-size:0.9em; +} + +#licenses dt { +font-weight:bold; +display:none; +} +#licenses dd { +margin-bottom:11px; +line-height:1.5; +} + +#site_content_license_cc { +margin-bottom:0; +} +#site_content_license_cc img { +display:inline; +vertical-align:top; +margin-right:4px; +} + +#wrap { +margin:0 auto; +width:100%; +min-width:760px; +max-width:1003px; +overflow:hidden; +} + +#core { +position:relative; +width:100%; +float:left; +margin-bottom:1em; +} + +#content { +width:64.009%; +min-height:259px; +padding:1.795%; +float:right; +border-radius:7px; +-moz-border-radius:7px; +-moz-border-radius-topright:0; +-webkit-border-radius:7px; +-webkit-border-top-right-radius:0; +border-style:solid; +border-width:1px; +} + +#content_inner { +position:relative; +width:100%; +float:left; +} + +#aside_primary { +width:27.917%; +min-height:259px; +float:right; +margin-right:0.385%; +padding:1.795%; +border-radius:7px; +-moz-border-radius:7px; +-webkit-border-radius:7px; +border-width:1px; +border-style:solid; +} + +#form_notice { +width:45.664%; +float:left; +position:relative; +line-height:1; +} +#form_notice fieldset { +border:0; +padding:0; +} +#form_notice legend { +display:none; +} +#form_notice textarea { +float:left; +border-radius:7px; +-moz-border-radius:7px; +-webkit-border-radius:7px; +width:80.789%; +height:67px; +line-height:1.5; +padding:7px 7px 16px 7px; +} +#form_notice label { +display:block; +float:left; +font-size:1.3em; +margin-bottom:7px; +} +#form_notice #notice_submit label { +display:none; +} +#form_notice .form_note { +position:absolute; +top:99px; +right:98px; +z-index:9; +} +#form_notice .form_note dt { +font-weight:bold; +display:none; +} +#notice_text-count { +font-weight:bold; +line-height:1.15; +padding:1px 2px; +} +#form_notice #notice_action-submit { +width:14%; +height:47px; +padding:0; +position:absolute; +bottom:0; +right:0; +} +#form_notice label[for=to] { +margin-top:7px; +} +#form_notice select[id=to] { +margin-bottom:7px; +margin-left:18px; +float:left; +} + + +/* entity_profile */ +.entity_profile { +position:relative; +width:67.702%; +min-height:123px; +float:left; +margin-bottom:18px; +margin-left:0; +overflow:hidden; +} +.entity_profile dt, +#entity_statistics dt { +font-weight:bold; +} +.entity_profile dd { +display:inline; +} + +.entity_profile .entity_depiction { +float:left; +width:96px; +margin-right:18px; +margin-bottom:18px; +} + +.entity_profile .entity_fn, +.entity_profile .entity_nickname, +.entity_profile .entity_location, +.entity_profile .entity_url, +.entity_profile .entity_note, +.entity_profile .entity_tags { +margin-left:113px; +margin-bottom:4px; +} + +.entity_profile .entity_fn, +.entity_profile .entity_nickname { +margin-left:11px; +display:inline; +font-weight:bold; +} +.entity_profile .entity_nickname { +margin-left:0; +} + +.entity_profile .entity_fn dd:before { +content: "("; +font-weight:normal; +} +.entity_profile .entity_fn dd:after { +content: ")"; +font-weight:normal; +} + +.entity_profile dt { +display:none; +} +.entity_profile h2 { +display:none; +} +/* entity_profile */ + + +/*entity_actions*/ +.entity_actions { +float:right; +margin-left:4.35%; +max-width:25%; +} +.entity_actions h2 { +display:none; +} +.entity_actions ul { +list-style-type:none; +} +.entity_actions li { +margin-bottom:4px; +} +.entity_actions li:first-child { +border-top:0; +} +.entity_actions fieldset { +border:0; +padding:0; +} +.entity_actions legend { +display:none; +} + +.entity_actions input.submit { +display:block; +text-align:left; +width:100%; +} +.entity_actions a, +.entity_nudge p, +.entity_remote_subscribe { +text-decoration:none; +font-weight:bold; +display:block; +} + +.form_user_block input.submit, +.form_user_unblock input.submit, +.entity_send-a-message a, +.entity_edit a, +.form_user_nudge input.submit, +.entity_nudge p { +border:0; +padding-left:20px; +} + +.entity_edit a, +.entity_send-a-message a, +.entity_nudge p { +padding:4px 4px 4px 23px; +} + +.entity_remote_subscribe { +padding:4px; +border-width:2px; +border-style:solid; +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +} +.entity_actions .accept { +margin-bottom:18px; +} + +.entity_tags ul { +list-style-type:none; +display:inline; +} +.entity_tags li { +display:inline; +margin-right:4px; +} + +.aside .section { +margin-bottom:29px; +clear:both; +float:left; +width:100%; +} +.aside .section h2 { +text-transform:uppercase; +font-size:1em; +} + +#entity_statistics dt, +#entity_statistics dd { +display:inline; +} +#entity_statistics dt:after { +content: ":"; +} + +.section ul.entities { +float:left; +width:100%; +} +.section .entities li { +list-style-type:none; +float:left; +margin-right:7px; +margin-bottom:7px; +} +.section .entities li .photo { +margin-right:0; +margin-bottom:0; +} +.section .entities li .fn { +display:none; +} + +.aside .section p, +.aside .section .more { +clear:both; +} + +.profile .entity_profile { +margin-bottom:0; +min-height:60px; +} + + +.profile .form_group_join legend, +.profile .form_group_leave legend, +.profile .form_user_subscribe legend, +.profile .form_user_unsubscribe legend { +display:none; +} + +.profiles { +list-style-type:none; +} +.profile .entity_profile .entity_location { +width:auto; +clear:none; +margin-left:11px; +} +.profile .entity_profile dl, +.profile .entity_profile dd { +display:inline; +float:none; +} +.profile .entity_profile .entity_note, +.profile .entity_profile .entity_url, +.profile .entity_profile .entity_tags, +.profile .entity_profile .form_subscription_edit { +margin-left:59px; +clear:none; +display:block; +width:auto; +} +.profile .entity_profile .entity_tags dt { +display:inline; +margin-right:11px; +} + + +.profile .entity_profile .form_subscription_edit label { +font-weight:normal; +margin-right:11px; +} + + +/* NOTICE */ +.notice, +.profile { +position:relative; +padding-top:11px; +padding-bottom:11px; +clear:both; +float:left; +width:100%; +border-top-width:1px; +border-top-style:dotted; +} +.notices li { +list-style-type:none; +} +.notices li.hover { +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +} + +/* NOTICES */ +#notices_primary { +float:left; +width:100%; +border-radius:7px; +-moz-border-radius:7px; +-webkit-border-radius:7px; +} +#notices_primary h2 { +display:none; +} +.notice-data a span { +display:block; +padding-left:28px; +} + +.notice .author { +margin-right:11px; +} + +.fn { +overflow:hidden; +} + +.notice .author .fn { +font-weight:bold; +} + +.notice .author .photo { +margin-bottom:0; +} + +.vcard .photo { +display:inline; +margin-right:11px; +margin-bottom:11px; +float:left; +} +.vcard .url { +text-decoration:none; +} +.vcard .url:hover { +text-decoration:underline; +} + +.notice .entry-title { +float:left; +width:100%; +overflow:hidden; +} +#shownotice .notice .entry-title { +font-size:2.2em; +} + +.notice p.entry-content { +display:inline; +} + +#content .notice p.entry-content a:visited { +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +} +.notice p.entry-content .vcard a { +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +} + +.notice div.entry-content { +clear:left; +float:left; +font-size:0.95em; +margin-left:59px; +width:70%; +} +#showstream .notice div.entry-content { +margin-left:0; +} + +.notice .notice-options a, +.notice .notice-options input { +float:left; +font-size:1.025em; +} + +.notice div.entry-content dl, +.notice div.entry-content dt, +.notice div.entry-content dd { +display:inline; +} + +.notice div.entry-content .timestamp dt, +.notice div.entry-content .response dt { +display:none; +} +.notice div.entry-content .timestamp a { +display:inline-block; +} +.notice div.entry-content .device dt { +text-transform:lowercase; +} + + + +.notice-data { +position:absolute; +top:18px; +right:0; +min-height:50px; +margin-bottom:4px; +} +.notice .entry-content .notice-data dt { +display:none; +} + +.notice-data a { +display:block; +outline:none; +} + +.notice-options { +padding-left:2%; +float:left; +width:50%; +position:relative; +font-size:0.95em; +width:12.5%; +float:right; +} + +.notice-options a { +float:left; +} +.notice-options .notice_delete, +.notice-options .notice_reply, +.notice-options .form_favor, +.notice-options .form_disfavor { +position:absolute; +top:0; +} +.notice-options .form_favor, +.notice-options .form_disfavor { +left:0; +} +.notice-options .notice_reply { +left:29px; +} +.notice-options .notice_delete { +right:0; +} +.notice-options .notice_reply dt { +display:none; +} + +.notice-options input, +.notice-options a { +text-indent:-9999px; +outline:none; +} + +.notice-options .notice_reply a, +.notice-options input.submit { +display:block; +border:0; +} +.notice-options .notice_reply a, +.notice-options .notice_delete a { +text-decoration:none; +padding-left:16px; +} + +.notice-options form input.submit { +width:16px; +padding:2px 0; +} + +.notice-options .notice_delete dt, +.notice-options .form_favor legend, +.notice-options .form_disfavor legend { +display:none; +} +.notice-options .notice_delete fieldset, +.notice-options .form_favor fieldset, +.notice-options .form_disfavor fieldset { +border:0; +padding:0; +} + + +#usergroups #new_group { +float: left; +margin-right: 2em; +} +#new_group, #group_search { +margin-bottom:18px; +} +#new_group a { +padding-left:20px; +} + + +#filter_tags { +margin-bottom:11px; +float:left; +} +#filter_tags dt { +display:none; +} +#filter_tags ul { +list-style-type:none; +} +#filter_tags ul li { +float:left; +margin-left:7px; +padding-left:7px; +border-left-width:1px; +border-left-style:solid; +} +#filter_tags ul li.child_1 { +margin-left:0; +border-left:0; +padding-left:0; +} +#filter_tags ul li#filter_tags_all a { +font-weight:bold; +margin-top:7px; +float:left; +} + +#filter_tags ul li#filter_tags_item label { +margin-right:7px; +} +#filter_tags ul li#filter_tags_item label, +#filter_tags ul li#filter_tags_item select { +display:inline; +} +#filter_tags ul li#filter_tags_item p { +float:left; +margin-left:38px; +} +#filter_tags ul li#filter_tags_item input { +position:relative; +top:3px; +left:3px; +} + + + +.pagination { +float:left; +clear:both; +width:100%; +margin-top:18px; +} + +.pagination dt { +font-weight:bold; +display:none; +} + +.pagination .nav { +float:left; +width:100%; +list-style-type:none; +} + +.pagination .nav_prev { +float:left; +} +.pagination .nav_next { +float:right; +} + +.pagination a { +display:block; +text-decoration:none; +font-weight:bold; +padding:7px; +border-width:1px; +border-style:solid; +-moz-border-radius:7px; +-webkit-border-radius:7px; +border-radius:7px; +} + +.pagination .nav_prev a { +padding-left:30px; +} +.pagination .nav_next a { +padding-right:30px; +} +/* END: NOTICE */ + + +.hentry .entry-content p { +margin-bottom:18px; +} +.hentry entry-content ol, +.hentry .entry-content ul { +list-style-position:inside; +} +.hentry .entry-content li { +margin-bottom:18px; +} +.hentry .entry-content li li { +margin-left:18px; +} + + + + +/* TOP_POSTERS */ +.section tbody td { +padding-right:11px; +padding-bottom:11px; +} +.section .vcard .photo { +margin-right:7px; +margin-bottom:0; +} + +.section .notice { +padding-top:7px; +padding-bottom:7px; +border-top:0; +} + +.section .notice:first-child { +padding-top:0; +} + +.section .notice .author { +margin-right:0; +} +.section .notice .author .fn { +display:none; +} + + +/* tagcloud */ +.tag-cloud { +list-style-type:none; +text-align:center; +} +.aside .tag-cloud { +font-size:0.8em; +} +.tag-cloud li { +display:inline; +margin-right:7px; +line-height:1.25; +} +.aside .tag-cloud li { +line-height:1.5; +} +.tag-cloud li a { +text-decoration:none; +} +#tagcloud.section dt { +text-transform:uppercase; +font-weight:bold; +} +.tag-cloud-1 { +font-size:1em; +} +.tag-cloud-2 { +font-size:1.25em; +} +.tag-cloud-3 { +font-size:1.75em; +} +.tag-cloud-4 { +font-size:2em; +} +.tag-cloud-5 { +font-size:2.25em; +} +.tag-cloud-6 { +font-size:2.75em; +} +.tag-cloud-7 { +font-size:3.25em; +} + +#publictagcloud #tagcloud.section dt { +display:none; +} + +#form_settings_photo .form_data { +clear:both; +} + +#form_settings_avatar li { +width:auto; +} +#form_settings_avatar input { +margin-left:0; +} +#avatar_original, +#avatar_preview { +float:left; +} +#avatar_preview { +margin-left:29px; +} +#avatar_preview_view { +height:96px; +width:96px; +margin-bottom:18px; +overflow:hidden; +} + +#settings_attach, +#form_settings_avatar .form_actions { +clear:both; +} + +#form_settings_avatar .form_actions { +margin-bottom:0; +} + +#form_settings_design #settings_design_color .form_data, +#form_settings_design #color-picker { +float:left; +} +#form_settings_design #settings_design_color .form_data { +width:400px; +margin-right:28px; +} + +.instructions ul { +list-style-position:inside; +} +.instructions p, +.instructions ul { +margin-bottom:18px; +} +.help dt { +display:none; +} +.guide { +clear:both; +} diff --git a/theme/earthy/css/display.css b/theme/earthy/css/display.css new file mode 100644 index 000000000..809ac8bc0 --- /dev/null +++ b/theme/earthy/css/display.css @@ -0,0 +1,245 @@ +/** theme: earthy + * + * @package Laconica + * @author Sarven Capadisli + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +@import url(base.css); + +html, +body, +a:active { +background-color:#665500; +} +body { +font-family: Verdana, sans-serif; +font-size:1em; +} +address { +margin-right:7.18%; +} + +input, textarea, select, option { +font-family: Verdana, sans-serif; +} +input, textarea, select, +.entity_remote_subscribe { +border-color:#aaa; +} +#filter_tags ul li { +border-color:#ddd; +} + +.form_settings input.form_action-secondary { +background:none; +} + +input.submit, +#form_notice.warning #notice_text-count, +.form_settings .form_note, +.entity_remote_subscribe { +background-color:#9BB43E; +} + +input:focus, textarea:focus, select:focus, +#form_notice.warning #notice_data-text { +border-color:#9BB43E; +} +input.submit, +.entity_remote_subscribe { +color:#dddd33; +} + +a, +div.notice-options input, +.form_user_block input.submit, +.form_user_unblock input.submit, +.entity_send-a-message a, +.form_user_nudge input.submit, +.entity_nudge p, +.form_settings input.form_action-secondary { +color:#ee4400; +} + +.notice, +.profile { +border-top-color:#DDAA00; +} +.section .profile { +border-top-color:#aaaa66; +} + +#content .notice p.entry-content a:visited { +background-color:#fcfcfc; +} +#content .notice p.entry-content .vcard a { +background-color:#fcfffc; +} + +#aside_primary { +background-color:#DDAA00; +} + +#notice_text-count { +color:#333; +} +#form_notice.warning #notice_text-count { +color:#000; +} +#form_notice.processing #notice_action-submit { +background:#dddd33 url(../../base/images/icons/icon_processing.gif) no-repeat 47% 47%; +cursor:wait; +text-indent:-9999px; +} + +#content, +#site_nav_local_views a, +#aside_primary { +border-color:#dddd33; +} +#content, +#site_nav_local_views .current a { +background-color:#dddd33; +} +#site_nav_local_views .current a { +color:#EE4400; +} +#site_nav_local_views a { +background-color:rgba(135, 180, 200, 0.3); +color:#fff; +} +#site_nav_local_views a:hover { +background-color:rgba(255, 255, 255, 0.7); +} + +.error { +background-color:#F7E8E8; +} +.success { +background-color:#EFF3DC; +} + +#anon_notice { +background-color:#aaaa66; +color:#dddd33; +border-color:#dddd33; +} + +#showstream #anon_notice { +background-color:#9BB43E; +} + +#export_data li a { +background-repeat:no-repeat; +background-position:0 45%; +} +#export_data li a.rss { +background-image:url(../../base/images/icons/icon_rss.png); +} +#export_data li a.atom { +background-image:url(../../base/images/icons/icon_atom.png); +} +#export_data li a.foaf { +background-image:url(../../base/images/icons/icon_foaf.gif); +} + +.entity_edit a, +.entity_send-a-message a, +.form_user_nudge input.submit, +.form_user_block input.submit, +.form_user_unblock input.submit, +.entity_nudge p { +background-position: 0 40%; +background-repeat: no-repeat; +background-color:transparent; +} +.form_group_join input.submit, +.form_group_leave input.submit +.form_user_subscribe input.submit, +.form_user_unsubscribe input.submit { +background-color:#9BB43E; +color:#dddd33; +} +.form_user_unsubscribe input.submit, +.form_group_leave input.submit, +.form_user_authorization input.reject { +background-color:#aaaa66; +} + +.entity_edit a { +background-image:url(../../base/images/icons/twotone/green/edit.gif); +} +.entity_send-a-message a { +background-image:url(../../base/images/icons/twotone/green/quote.gif); +} +.entity_nudge p, +.form_user_nudge input.submit { +background-image:url(../../base/images/icons/twotone/green/mail.gif); +} +.form_user_block input.submit, +.form_user_unblock input.submit { +background-image:url(../../base/images/icons/twotone/green/shield.gif); +} + +/* NOTICES */ +.notices li.over { +background-color:#fcfcfc; +} + +.notice-options .notice_reply a, +.notice-options form input.submit { +background-color:transparent; +} +.notice-options .notice_reply a { +background:transparent url(../../base/images/icons/twotone/green/reply.gif) no-repeat 0 45%; +} +.notice-options form.form_favor input.submit { +background:transparent url(../../base/images/icons/twotone/green/favourite.gif) no-repeat 0 45%; +} +.notice-options form.form_disfavor input.submit { +background:transparent url(../../base/images/icons/twotone/green/disfavourite.gif) no-repeat 0 45%; +} +.notice-options .notice_delete a { +background:transparent url(../../base/images/icons/twotone/green/trash.gif) no-repeat 0 45%; +} + +.notices div.entry-content, +.notices div.notice-options { +opacity:0.4; +} +.notices li.hover div.entry-content, +.notices li.hover div.notice-options { +opacity:1; +} +div.entry-content { +color:#333; +} +div.notice-options a, +div.notice-options input { +font-family:sans-serif; +} +.notices li.hover { +/*background-color:#fcfcfc;*/ +} +/*END: NOTICES */ + +#new_group a { +background:transparent url(../../base/images/icons/twotone/green/news.gif) no-repeat 0 45%; +} + +.pagination .nav_prev a, +.pagination .nav_next a { +background-repeat:no-repeat; +border-color:#DDAA00; +} +.pagination .nav_prev a { +background-image:url(../../base/images/icons/twotone/green/arrow-left.gif); +background-position:10% 45%; +} +.pagination .nav_next a { +background-image:url(../../base/images/icons/twotone/green/arrow-right.gif); +background-position:90% 45%; +} diff --git a/theme/earthy/css/ie.css b/theme/earthy/css/ie.css new file mode 100644 index 000000000..2f463bb44 --- /dev/null +++ b/theme/earthy/css/ie.css @@ -0,0 +1,9 @@ +/* IE specific styles */ + +.notice-options input.submit { +color:#fff; +} + +#site_nav_local_views a { +background-color:#D0DFE7; +} diff --git a/theme/earthy/default-avatar-mini.png b/theme/earthy/default-avatar-mini.png new file mode 100644 index 000000000..38b8692b4 Binary files /dev/null and b/theme/earthy/default-avatar-mini.png differ diff --git a/theme/earthy/default-avatar-profile.png b/theme/earthy/default-avatar-profile.png new file mode 100644 index 000000000..f8357d4fc Binary files /dev/null and b/theme/earthy/default-avatar-profile.png differ diff --git a/theme/earthy/default-avatar-stream.png b/theme/earthy/default-avatar-stream.png new file mode 100644 index 000000000..6b63baa70 Binary files /dev/null and b/theme/earthy/default-avatar-stream.png differ diff --git a/theme/earthy/logo.png b/theme/earthy/logo.png new file mode 100644 index 000000000..7c68b34f6 Binary files /dev/null and b/theme/earthy/logo.png differ -- cgit v1.2.3-54-g00ecf From af89dcadee63f4de1546abc6cebd50948b4bc42c Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Mon, 20 Apr 2009 05:06:38 +0000 Subject: earthy theme: layout experiment --- theme/earthy/css/base.css | 36 ++++++++++++++++++++++++------------ theme/earthy/css/display.css | 14 ++++++++++---- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/theme/earthy/css/base.css b/theme/earthy/css/base.css index 8ff65ad50..6f46eef97 100644 --- a/theme/earthy/css/base.css +++ b/theme/earthy/css/base.css @@ -28,6 +28,7 @@ overflow:hidden; h1 { font-size:1.4em; margin-bottom:18px; +text-align:right; } #showstream h1 { display:none; } h2 { font-size:1.3em; } @@ -309,6 +310,8 @@ font-weight:bold; #site_nav_local_views .nav { float:left; width:100%; +border-bottom-width:1px; +border-bottom-style:solid; } #site_nav_global_primary dt, @@ -384,17 +387,15 @@ margin-bottom:1em; } #content { -width:64.009%; +width:63.009%; min-height:259px; -padding:1.795%; +padding-top:1.795%; +padding-bottom:1.795%; float:right; +clear:both; border-radius:7px; --moz-border-radius:7px; --moz-border-radius-topright:0; --webkit-border-radius:7px; --webkit-border-top-right-radius:0; border-style:solid; -border-width:1px; +border-width:0; } #content_inner { @@ -407,7 +408,8 @@ float:left; width:27.917%; min-height:259px; float:right; -margin-right:0.385%; +margin-right:4.385%; +margin-top:73px; padding:1.795%; border-radius:7px; -moz-border-radius:7px; @@ -713,14 +715,24 @@ margin-right:11px; .notice, .profile { position:relative; -padding-top:11px; -padding-bottom:11px; clear:both; float:left; width:100%; -border-top-width:1px; -border-top-style:dotted; +border-width:1px; +border-style:solid; +border-radius:7px; +-moz-border-radius:7px; +-webkit-border-radius:7px; } +#content .notice, +#content .profile { +padding:1.795%; +margin-bottom:44px; +} +#content .notice { +width:96.25%; +} + .notices li { list-style-type:none; } diff --git a/theme/earthy/css/display.css b/theme/earthy/css/display.css index 809ac8bc0..b67700f2d 100644 --- a/theme/earthy/css/display.css +++ b/theme/earthy/css/display.css @@ -22,6 +22,10 @@ address { margin-right:7.18%; } +h1 { +color:#fff; +} + input, textarea, select, option { font-family: Verdana, sans-serif; } @@ -66,7 +70,7 @@ color:#ee4400; .notice, .profile { -border-top-color:#DDAA00; +border-color:#DDAA00; } .section .profile { border-top-color:#aaaa66; @@ -96,11 +100,13 @@ text-indent:-9999px; } #content, +#site_nav_local_views .nav, #site_nav_local_views a, #aside_primary { border-color:#dddd33; } -#content, +#content .notice, +#content .profile, #site_nav_local_views .current a { background-color:#dddd33; } @@ -108,11 +114,11 @@ background-color:#dddd33; color:#EE4400; } #site_nav_local_views a { -background-color:rgba(135, 180, 200, 0.3); +background-color:rgba(255, 255, 255, 0.2); color:#fff; } #site_nav_local_views a:hover { -background-color:rgba(255, 255, 255, 0.7); +background-color:rgba(255, 255, 255, 0.4); } .error { -- cgit v1.2.3-54-g00ecf From 4cb0a929806869b09d4325c1464fc2ecb7b5a76e Mon Sep 17 00:00:00 2001 From: CiaranG Date: Tue, 21 Apr 2009 20:43:57 +0100 Subject: Add feed2omb to notice sources --- db/notice_source.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/db/notice_source.sql b/db/notice_source.sql index d5124e223..ce44f3235 100644 --- a/db/notice_source.sql +++ b/db/notice_source.sql @@ -8,6 +8,7 @@ VALUES ('deskbar','Deskbar-Applet','http://www.gnome.org/projects/deskbar-applet/', now()), ('Do','Gnome Do','http://do.davebsd.com/wiki/index.php?title=Microblog_Plugin', now()), ('Facebook','Facebook','http://apps.facebook.com/identica/', now()), + ('feed2omb','feed2omb','http://projects.ciarang.com/p/feed2omb/', now()), ('Gwibber','Gwibber','http://launchpad.net/gwibber', now()), ('HelloTxt','HelloTxt','http://hellotxt.com/', now()), ('identicatools','Laconica Tools','http://bitbucketlabs.net/laconica-tools/', now()), -- cgit v1.2.3-54-g00ecf From ec5e06a542d6b06ea9b1d3de7cb309dd1088b4d4 Mon Sep 17 00:00:00 2001 From: CiaranG Date: Tue, 21 Apr 2009 23:36:15 +0100 Subject: Suppress errors when checking for the existence of files that might be restricted by open_basedir - should resolve issue #1310 --- lib/common.php | 2 +- lib/util.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/common.php b/lib/common.php index b3882d207..f983c4d16 100644 --- a/lib/common.php +++ b/lib/common.php @@ -192,7 +192,7 @@ $_config_files[] = INSTALLDIR.'/config.php'; $_have_a_config = false; foreach ($_config_files as $_config_file) { - if (file_exists($_config_file)) { + if (@file_exists($_config_file)) { include_once($_config_file); $_have_a_config = true; } diff --git a/lib/util.php b/lib/util.php index e0eda0114..e1dd238ba 100644 --- a/lib/util.php +++ b/lib/util.php @@ -966,7 +966,7 @@ function common_root_url($ssl=false) function common_good_rand($bytes) { // XXX: use random.org...? - if (file_exists('/dev/urandom')) { + if (@file_exists('/dev/urandom')) { return common_urandom($bytes); } else { // FIXME: this is probably not good enough return common_mtrand($bytes); -- cgit v1.2.3-54-g00ecf From 5f82ce18f012be4fe8d64a2ae79db99c2fd64670 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 21 Apr 2009 19:09:27 -0700 Subject: Script to import friends timelines from Twitter --- scripts/statusfetcher.php | 453 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 453 insertions(+) create mode 100644 scripts/statusfetcher.php diff --git a/scripts/statusfetcher.php b/scripts/statusfetcher.php new file mode 100644 index 000000000..d303a098c --- /dev/null +++ b/scripts/statusfetcher.php @@ -0,0 +1,453 @@ +#!/usr/bin/env php +. + */ + +// Abort if called from a web server +if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { + print "This script must be run from the command line\n"; + exit(); +} + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); +define('LACONICA', true); + +// Uncomment this to get useful console output +define('SCRIPT_DEBUG', true); + +require_once(INSTALLDIR . '/lib/common.php'); + +$flink = new Foreign_link(); +$flink->service = 1; // Twitter +$cnt = $flink->find(); + +print "Updating Twitter friends subscriptions for $cnt users.\n"; + + +while ($flink->fetch()) { + + if (($flink->noticesync & FOREIGN_NOTICE_RECV) == FOREIGN_NOTICE_RECV) { + + $user = User::staticGet($flink->user_id); + + if (empty($user)) { + common_log(LOG_WARNING, "Unmatched user for ID " . $flink->user_id); + print "Unmatched user for ID $flink->user_id\n"; + continue; + } + + print 'Retrieving Friends Timeline for ' . $flink->user_id . "\n"; + + getTimeline($flink); + + if (defined('SCRIPT_DEBUG')) { + print "\nDONE\n"; + } + } +} + +function getTimeline($flink) +{ + + $fuser = $flink->getForeignUser(); + + if (empty($fuser)) { + common_log(LOG_WARNING, "Unmatched user for ID " . $flink->user_id); + if (defined('SCRIPT_DEBUG')) { + print "Unmatched user for ID $flink->user_id\n"; + } + continue; + } + + $screenname = $fuser->nickname; + + $url = 'http://twitter.com/statuses/friends_timeline.json'; + + $timeline_json = get_twitter_data($url, $fuser->nickname, + $flink->credentials); + + $timeline = json_decode($timeline_json); + + foreach ($timeline as $status) { + + // Hacktastic: filter out stuff coming from Laconica + $source = mb_strtolower(common_config('integration', 'source')); + + if (preg_match("/$source/", mb_strtolower($status->source))) { + continue; + } + + saveStatus($status, $flink); + } + +} + +function saveStatus($status, $flink) +{ + // Do we have a profile for this Twitter user? + + $id = ensureProfile($status->user); + $profile = Profile::staticGet($id); + + if (!$profile) { + common_log(LOG_ERR, 'Problem saving notice. No associated Profile.'); + if (defined('SCRIPT_DEBUG')) { + print "Problem saving notice. No associated Profile.\n"; + } + return null; + } + + $uri = 'http://twitter.com/' . $status->user->screen_name . + '/status/' . $status->id; + + // Skip save if notice source is Laconica or Identi.ca? + + $notice = Notice::staticGet('uri', $uri); + + // check to see if we've already imported the status + if (!$notice) { + + $notice = new Notice(); + + $notice->profile_id = $id; + + $notice->query('BEGIN'); + + // XXX: figure out reply_to + $notice->reply_to = null; + + // XXX: Should this be common_sql_now() instead of status create date? + + $notice->created = strftime('%Y-%m-%d %H:%M:%S', + strtotime($status->created_at)); + $notice->content = $status->text; + $notice->rendered = common_render_content($status->text, $notice); + $notice->source = 'twitter'; + $notice->is_local = 0; + $notice->uri = $uri; + + $notice_id = $notice->insert(); + + if (!$notice_id) { + common_log_db_error($notice, 'INSERT', __FILE__); + if (defined('SCRIPT_DEBUG')) { + print "Could not save notice!\n"; + } + } + + # XXX: do we need to change this for remote users? + + $notice->saveReplies(); + + // XXX: Do we want to polute our tag cloud with hashtags from Twitter? + $notice->saveTags(); + $notice->saveGroups(); + + $notice->query('COMMIT'); + + } + + if (!Notice_inbox::staticGet('notice_id', $notice->id)) { + + // Add to inbox + $inbox = new Notice_inbox(); + $inbox->user_id = $flink->user_id; + $inbox->notice_id = $notice->id; + $inbox->created = common_sql_now(); + + $inbox->insert(); + } + +} + +function ensureProfile($user) +{ + + // check to see if there's already a profile for this user + $profileurl = 'http://twitter.com/' . $user->screen_name; + + $profile = Profile::staticGet('profileurl', $profileurl); + + if ($profile) { + + common_debug("Profile for $profile->nickname found."); + + // Check to see if the user's Avatar has changed + checkAvatar($user, $profile); + return $profile->id; + + } else { + + $debugmsg = 'Adding profile and remote profile ' . + "for Twitter user: $profileurl\n"; + common_debug($debugmsg, __FILE__); + if (defined('SCRIPT_DEBUG')) { + print $debugmsg; + } + + $profile = new Profile(); + $profile->query("BEGIN"); + + $profile->nickname = $user->screen_name; + $profile->fullname = $user->name; + $profile->homepage = $user->url; + $profile->bio = $user->description; + $profile->location = $user->location; + $profile->profileurl = $profileurl; + $profile->created = common_sql_now(); + + $id = $profile->insert(); + + if (empty($id)) { + common_log_db_error($profile, 'INSERT', __FILE__); + if (defined('SCRIPT_DEBUG')) { + print 'Could not insert Profile: ' . + common_log_objstring($profile) . "\n"; + } + $profile->query("ROLLBACK"); + return false; + } + + // check for remote profile + $remote_pro = Remote_profile::staticGet('uri', $profileurl); + + if (!$remote_pro) { + + $remote_pro = new Remote_profile(); + + $remote_pro->id = $id; + $remote_pro->uri = $profileurl; + $remote_pro->created = common_sql_now(); + + $rid = $remote_pro->insert(); + + if (empty($rid)) { + common_log_db_error($profile, 'INSERT', __FILE__); + if (defined('SCRIPT_DEBUG')) { + print 'Could not insert Remote_profile: ' . + common_log_objstring($remote_pro) . "\n"; + } + $profile->query("ROLLBACK"); + return false; + } + } + + $profile->query("COMMIT"); + $profile->free(); + unset($profile); + + saveAvatars($user, $id); + + return $id; + } +} + +function checkAvatar($user, $profile) +{ + common_debug("in check avatar"); + + $path_parts = pathinfo($user->profile_image_url); + $newname = 'Twitter_' . $user->id . '_' . + $path_parts['basename']; + + $oldname = $profile->getAvatar(48)->filename; + + if ($newname != $oldname) { + + common_debug("Avatar for Twitter user $profile->nickname has changed."); + common_debug("old: $oldname new: $newname"); + + if (defined('SCRIPT_DEBUG')) { + print "Avatar for Twitter user $user->id has changed.\n"; + print "old: $oldname\n"; + print "new: $newname\n"; + } + + $img_root = substr($path_parts['basename'], 0, -11); + $ext = $path_parts['extension']; + $mediatype = getMediatype($ext); + + foreach (array('mini', 'normal', 'bigger') as $size) { + $url = $path_parts['dirname'] . '/' . + $img_root . '_' . $size . ".$ext"; + $filename = 'Twitter_' . $user->id . '_' . + $img_root . "_$size.$ext"; + + if (fetchAvatar($url, $filename)) { + updateAvatar($profile->id, $size, $mediatype, $filename); + } + } + } + +} + +function getMediatype($ext) +{ + $mediatype = null; + + switch (strtolower($ext)) { + case 'jpg': + $mediatype = 'image/jpg'; + break; + case 'gif': + $mediatype = 'image/gif'; + break; + default: + $mediatype = 'image/png'; + } + + return $mediatype; +} + + +function saveAvatars($user, $id) +{ + $path_parts = pathinfo($user->profile_image_url); + + // basename minus '_normal.ext' + + $ext = $path_parts['extension']; + $end = strlen('_normal' . $ext); + $img_root = substr($path_parts['basename'], 0, -($end+1)); + $mediatype = getMediatype($ext); + + foreach (array('mini', 'normal', 'bigger') as $size) { + $url = $path_parts['dirname'] . '/' . + $img_root . '_' . $size . ".$ext"; + $filename = 'Twitter_' . $user->id . '_' . + $img_root . "_$size.$ext"; + + if (fetchAvatar($url, $filename)) { + newAvatar($id, $size, $mediatype, $filename); + } else { + common_log(LOG_WARNING, "Problem fetching Avatar: $url", __FILE__); + if (defined('SCRIPT_DEBUG')) { + print "Problem fetching Avatar: $url\n"; + } + } + } +} + +function updateAvatar($profile_id, $size, $mediatype, $filename) { + + common_debug("updating avatar: $size"); + + $profile = Profile::staticGet($profile_id); + + if (!$profile) { + common_debug("Couldn't get profile: $profile_id!"); + if (defined('SCRIPT_DEBUG')) { + print "Couldn't get profile: $profile_id!\n"; + } + return; + } + + $sizes = array('mini' => 24, 'normal' => 48, 'bigger' => 73); + $avatar = $profile->getAvatar($sizes[$size]); + + if ($avatar) { + common_debug("Deleting $size avatar for $profile->nickname."); + @unlink(INSTALLDIR . '/avatar/' . $avatar->filename); + $avatar->delete(); + } + + newAvatar($profile->id, $size, $mediatype, $filename); +} + +function newAvatar($profile_id, $size, $mediatype, $filename) +{ + $avatar = new Avatar(); + $avatar->profile_id = $profile_id; + + switch($size) { + case 'mini': + $avatar->width = 24; + $avatar->height = 24; + break; + case 'normal': + $avatar->width = 48; + $avatar->height = 48; + break; + default: + + // Note: Twitter's big avatars are a different size than + // Laconica's (Laconica's = 96) + + $avatar->width = 73; + $avatar->height = 73; + } + + $avatar->original = 0; // we don't have the original + $avatar->mediatype = $mediatype; + $avatar->filename = $filename; + $avatar->url = Avatar::url($filename); + + common_debug("new filename: $avatar->url"); + + $avatar->created = common_sql_now(); + + $id = $avatar->insert(); + + if (!$id) { + common_log_db_error($avatar, 'INSERT', __FILE__); + if (defined('SCRIPT_DEBUG')) { + print "Could not insert avatar!\n"; + } + + return null; + } + + common_debug("Saved new $size avatar for $profile_id."); + + return $id; +} + +function fetchAvatar($url, $filename) +{ + $avatar_dir = INSTALLDIR . '/avatar/'; + + $avatarfile = $avatar_dir . $filename; + + $out = fopen($avatarfile, 'wb'); + if (!$out) { + common_log(LOG_WARNING, "Couldn't open file $filename", __FILE__); + if (defined('SCRIPT_DEBUG')) { + print "Couldn't open file! $filename\n"; + } + return false; + } + + common_debug("Fetching avatar: $url", __FILE__); + if (defined('SCRIPT_DEBUG')) { + print "Fetching avatar from Twitter: $url\n"; + } + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_FILE, $out); + curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); + $result = curl_exec($ch); + curl_close($ch); + + fclose($out); + + return $result; +} + -- cgit v1.2.3-54-g00ecf From fe3241183e3559442003b9b70435d59126e11b7e Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Thu, 23 Apr 2009 01:03:17 +0000 Subject: fix join a group link from user homepage when he hasn't posted anything yet --- actions/all.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/all.php b/actions/all.php index a92e55462..a53bbea07 100644 --- a/actions/all.php +++ b/actions/all.php @@ -93,7 +93,7 @@ class AllAction extends ProfileAction if (common_logged_in()) { $current_user = common_current_user(); if ($this->user->id === $current_user->id) { - $message .= _('Try subscribing to more people, [join a group](%%action.groups) or post something yourself.'); + $message .= _('Try subscribing to more people, [join a group](%%action.groups%%) or post something yourself.'); } else { $message .= sprintf(_('You can try to [nudge %s](../%s) from his profile or [post something to his or her attention](%%%%action.newnotice%%%%?status_textarea=%s).'), $this->user->nickname, $this->user->nickname, '@' . $this->user->nickname); } -- cgit v1.2.3-54-g00ecf From c4941e904316ef98582290602f8cba1d220b873a Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 23 Apr 2009 02:17:58 +0000 Subject: Added ajax responses --- actions/newmessage.php | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/actions/newmessage.php b/actions/newmessage.php index 82276ff34..52d4899ba 100644 --- a/actions/newmessage.php +++ b/actions/newmessage.php @@ -172,15 +172,54 @@ class NewmessageAction extends Action $this->notify($user, $this->other, $message); - $url = common_local_url('outbox', array('nickname' => $user->nickname)); + if ($this->boolean('ajax')) { + $this->startHTML('text/xml;charset=utf-8'); + $this->elementStart('head'); + $this->element('title', null, _('Message sent')); + $this->elementEnd('head'); + $this->elementStart('body'); + $this->element('p', array('id' => 'command_result'), + sprintf(_('Direct message to %s sent'), + $this->other->nickname)); + $this->elementEnd('body'); + $this->elementEnd('html'); + } else { + $url = common_local_url('outbox', + array('nickname' => $user->nickname)); + common_redirect($url, 303); + } + } - common_redirect($url, 303); + /** + * Show an Ajax-y error message + * + * Goes back to the browser, where it's shown in a popup. + * + * @param string $msg Message to show + * + * @return void + */ + + function ajaxErrorMsg($msg) + { + $this->startHTML('text/xml;charset=utf-8', true); + $this->elementStart('head'); + $this->element('title', null, _('Ajax Error')); + $this->elementEnd('head'); + $this->elementStart('body'); + $this->element('p', array('id' => 'error'), $msg); + $this->elementEnd('body'); + $this->elementEnd('html'); } function showForm($msg = null) { - $this->msg = $msg; + if ($msg && $this->boolean('ajax')) { + $this->ajaxErrorMsg($msg); + return; + } + $this->msg = $msg; $this->showPage(); } -- cgit v1.2.3-54-g00ecf From 63c52784c7acc54b0b7b39ff3ca7763774e4ab9a Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 23 Apr 2009 02:22:00 +0000 Subject: Allowing XHR for Inbox/Outbox pages. --- js/util.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/js/util.js b/js/util.js index 53e6eb792..13036f7ca 100644 --- a/js/util.js +++ b/js/util.js @@ -192,10 +192,8 @@ $(document).ready(function(){ $("#notice_action-submit").removeClass("disabled"); } }; - if (document.body.id != 'inbox' && document.body.id != 'outbox') { - $("#form_notice").ajaxForm(PostNotice); - $("#form_notice").each(addAjaxHidden); - } + $("#form_notice").ajaxForm(PostNotice); + $("#form_notice").each(addAjaxHidden); NoticeHover(); NoticeReply(); }); -- cgit v1.2.3-54-g00ecf From 640628de2d593933e810b4785dfe38923b979713 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 23 Apr 2009 05:03:19 -0400 Subject: A queuehandler for blowing caches offline We add a queuehandler for blowing the memcached caches off-line. This should speed up the processing of new notices. --- classes/Notice.php | 25 ++++++++++++++++- lib/util.php | 14 ++++++++-- scripts/memcachedqueuehandler.php | 58 +++++++++++++++++++++++++++++++++++++++ scripts/startdaemons.sh | 3 +- scripts/stopdaemons.sh | 2 +- 5 files changed, 97 insertions(+), 5 deletions(-) create mode 100644 scripts/memcachedqueuehandler.php diff --git a/classes/Notice.php b/classes/Notice.php index 5fa0d79a1..fbfeb9489 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -207,7 +207,11 @@ class Notice extends Memcached_DataObject # XXX: someone clever could prepend instead of clearing the cache if (common_config('memcached', 'enabled')) { - $notice->blowCaches(); + if (common_config('queues', 'enabled')) { + $notice->blowAuthorCaches(); + } else { + $notice->blowCaches(); + } } return $notice; @@ -271,6 +275,25 @@ class Notice extends Memcached_DataObject $this->blowGroupCache($blowLast); } + function blowAuthorCaches($blowLast=false) + { + // Clear the user's cache + $cache = common_memcache(); + if ($cache) { + $user = User::staticGet($this->profile_id); + if (!empty($user)) { + $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id)); + if ($blowLast) { + $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id . ';last')); + } + } + $user->free(); + unset($user); + } + $this->blowNoticeCache($blowLast); + $this->blowPublicCache($blowLast); + } + function blowGroupCache($blowLast=false) { $cache = common_memcache(); diff --git a/lib/util.php b/lib/util.php index e0eda0114..12797891c 100644 --- a/lib/util.php +++ b/lib/util.php @@ -879,7 +879,17 @@ function common_broadcast_notice($notice, $remote=false) function common_enqueue_notice($notice) { - foreach (array('jabber', 'omb', 'sms', 'public', 'twitter', 'facebook', 'ping') as $transport) { + $transports = array('omb', 'sms', 'twitter', 'facebook', 'ping'); + + if (common_config('xmpp', 'enabled')) { + $transports = array_merge($transports, array('jabber', 'public')); + } + + if (common_config('memcached', 'enabled')) { + $transports[] = 'memcached'; + } + + foreach ($transports as $transport) { $qi = new Queue_item(); $qi->notice_id = $notice->id; $qi->transport = $transport; @@ -1332,7 +1342,7 @@ function common_compatible_license($from, $to) */ function common_database_tablename($tablename) { - + if(common_config('db','quote_identifiers')) { $tablename = '"'. $tablename .'"'; } diff --git a/scripts/memcachedqueuehandler.php b/scripts/memcachedqueuehandler.php new file mode 100644 index 000000000..3fcebcfc3 --- /dev/null +++ b/scripts/memcachedqueuehandler.php @@ -0,0 +1,58 @@ +#!/usr/bin/env php +. + */ + +// Abort if called from a web server + +if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { + print "This script must be run from the command line\n"; + exit(); +} + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); +define('LACONICA', true); + +require_once(INSTALLDIR . '/lib/common.php'); + +set_error_handler('common_error_handler'); + +class MemcachedQueueHandler extends QueueHandler +{ + function transport() + { + return 'memcached'; + } + + function handle_notice($notice) + { + // XXX: fork here + common_log(LOG_INFO, "Blowing memcached for $notice->id\n"; + $notice->blowCaches(); + return true; + } +} + +ini_set("max_execution_time", "0"); +ini_set("max_input_time", "0"); +set_time_limit(0); +mb_internal_encoding('UTF-8'); + +$handler = new MemcachedQueueHandler($resource); + +$handler->runOnce(); diff --git a/scripts/startdaemons.sh b/scripts/startdaemons.sh index c3729761d..08de6d954 100755 --- a/scripts/startdaemons.sh +++ b/scripts/startdaemons.sh @@ -24,7 +24,8 @@ DIR=`dirname $0` for f in xmppdaemon.php jabberqueuehandler.php publicqueuehandler.php \ xmppconfirmhandler.php smsqueuehandler.php ombqueuehandler.php \ - twitterqueuehandler.php facebookqueuehandler.php pingqueuehandler.php; do + twitterqueuehandler.php facebookqueuehandler.php pingqueuehandler.php \ + memcachedqueuehandler.php; do echo -n "Starting $f..."; php $DIR/$f diff --git a/scripts/stopdaemons.sh b/scripts/stopdaemons.sh index 2bb8f9ecb..e5a181cd1 100755 --- a/scripts/stopdaemons.sh +++ b/scripts/stopdaemons.sh @@ -24,7 +24,7 @@ SDIR=`dirname $0` DIR=`php $SDIR/getpiddir.php` for f in jabberhandler ombhandler publichandler smshandler pinghandler \ - xmppconfirmhandler xmppdaemon twitterhandler facebookhandler ; do + xmppconfirmhandler xmppdaemon twitterhandler facebookhandler memcachedhandler; do FILES="$DIR/$f.*.pid" for ff in "$FILES" ; do -- cgit v1.2.3-54-g00ecf From aee45ea91dcec4736d8b9befe17e030b873d9226 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 23 Apr 2009 05:08:48 -0400 Subject: Add an inbox queue handler Handle distributing a notice to multiple inboxes in a queue handler rather than in the Web action. --- classes/Notice.php | 5 +++- lib/util.php | 4 +++ scripts/inboxqueuehandler.php | 57 +++++++++++++++++++++++++++++++++++++++++++ scripts/startdaemons.sh | 2 +- scripts/stopdaemons.sh | 3 ++- 5 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 scripts/inboxqueuehandler.php diff --git a/classes/Notice.php b/classes/Notice.php index fbfeb9489..ff00f2a94 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -197,7 +197,10 @@ class Notice extends Memcached_DataObject $notice->saveTags(); $notice->saveGroups(); - $notice->addToInboxes(); + if (!common_config('queues', 'enabled')) { + $notice->addToInboxes(); + } + $notice->query('COMMIT'); Event::handle('EndNoticeSave', array($notice)); diff --git a/lib/util.php b/lib/util.php index 12797891c..9b6d2941a 100644 --- a/lib/util.php +++ b/lib/util.php @@ -889,6 +889,10 @@ function common_enqueue_notice($notice) $transports[] = 'memcached'; } + if (common_config('queues', 'enabled')) { + $transports[] = 'inbox'; + } + foreach ($transports as $transport) { $qi = new Queue_item(); $qi->notice_id = $notice->id; diff --git a/scripts/inboxqueuehandler.php b/scripts/inboxqueuehandler.php new file mode 100644 index 000000000..16e334b83 --- /dev/null +++ b/scripts/inboxqueuehandler.php @@ -0,0 +1,57 @@ +#!/usr/bin/env php +. + */ + +// Abort if called from a web server + +if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { + print "This script must be run from the command line\n"; + exit(); +} + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); +define('LACONICA', true); + +require_once(INSTALLDIR . '/lib/common.php'); + +set_error_handler('common_error_handler'); + +class InboxQueueHandler extends QueueHandler +{ + function transport() + { + return 'inbox'; + } + + function handle_notice($notice) + { + common_log(LOG_INFO, "Distributing notice to inboxes for $notice->id"); + $notice->addToInboxes(); + return true; + } +} + +ini_set("max_execution_time", "0"); +ini_set("max_input_time", "0"); +set_time_limit(0); +mb_internal_encoding('UTF-8'); + +$handler = new InboxQueueHandler($resource); + +$handler->runOnce(); diff --git a/scripts/startdaemons.sh b/scripts/startdaemons.sh index 08de6d954..66f9ed4e0 100755 --- a/scripts/startdaemons.sh +++ b/scripts/startdaemons.sh @@ -25,7 +25,7 @@ DIR=`dirname $0` for f in xmppdaemon.php jabberqueuehandler.php publicqueuehandler.php \ xmppconfirmhandler.php smsqueuehandler.php ombqueuehandler.php \ twitterqueuehandler.php facebookqueuehandler.php pingqueuehandler.php \ - memcachedqueuehandler.php; do + memcachedqueuehandler.php inboxqueuehandler.php; do echo -n "Starting $f..."; php $DIR/$f diff --git a/scripts/stopdaemons.sh b/scripts/stopdaemons.sh index e5a181cd1..196991de0 100755 --- a/scripts/stopdaemons.sh +++ b/scripts/stopdaemons.sh @@ -24,7 +24,8 @@ SDIR=`dirname $0` DIR=`php $SDIR/getpiddir.php` for f in jabberhandler ombhandler publichandler smshandler pinghandler \ - xmppconfirmhandler xmppdaemon twitterhandler facebookhandler memcachedhandler; do + xmppconfirmhandler xmppdaemon twitterhandler facebookhandler \ + memcachedhandler inboxhandler; do FILES="$DIR/$f.*.pid" for ff in "$FILES" ; do -- cgit v1.2.3-54-g00ecf From 2053bdabef929f4a095d91fbdd3fa62646e9f332 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 23 Apr 2009 05:23:59 -0400 Subject: fix parse error in memcachedqueuehandler --- scripts/memcachedqueuehandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/memcachedqueuehandler.php b/scripts/memcachedqueuehandler.php index 3fcebcfc3..43231fa2c 100644 --- a/scripts/memcachedqueuehandler.php +++ b/scripts/memcachedqueuehandler.php @@ -42,7 +42,7 @@ class MemcachedQueueHandler extends QueueHandler function handle_notice($notice) { // XXX: fork here - common_log(LOG_INFO, "Blowing memcached for $notice->id\n"; + common_log(LOG_INFO, "Blowing memcached for $notice->id"); $notice->blowCaches(); return true; } -- cgit v1.2.3-54-g00ecf From 31b04220bd9fbadbfac01b60276a9c14896b6a45 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 23 Apr 2009 09:34:56 +0000 Subject: incorrect config setting for queues --- classes/Notice.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/Notice.php b/classes/Notice.php index ff00f2a94..ebed0b8af 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -197,7 +197,7 @@ class Notice extends Memcached_DataObject $notice->saveTags(); $notice->saveGroups(); - if (!common_config('queues', 'enabled')) { + if (!common_config('queue', 'enabled')) { $notice->addToInboxes(); } @@ -210,7 +210,7 @@ class Notice extends Memcached_DataObject # XXX: someone clever could prepend instead of clearing the cache if (common_config('memcached', 'enabled')) { - if (common_config('queues', 'enabled')) { + if (common_config('queue', 'enabled')) { $notice->blowAuthorCaches(); } else { $notice->blowCaches(); -- cgit v1.2.3-54-g00ecf From ece70bf326fa680ec7acdef00751e2bb71bceee1 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 23 Apr 2009 09:35:10 +0000 Subject: incorrect config setting for inboxes --- lib/util.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/util.php b/lib/util.php index af4db4f02..d77039b74 100644 --- a/lib/util.php +++ b/lib/util.php @@ -889,7 +889,8 @@ function common_enqueue_notice($notice) $transports[] = 'memcached'; } - if (common_config('queues', 'enabled')) { + if (common_config('inboxes', 'enabled') === true || + common_config('inboxes', 'enabled') === 'transitional') { $transports[] = 'inbox'; } -- cgit v1.2.3-54-g00ecf From a3e727823d01ed9fd5f440eeaf27449092309865 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 23 Apr 2009 09:52:21 +0000 Subject: some basic fixes for inbox and memcached queue handlers --- scripts/inboxqueuehandler.php | 15 +++++++++++++-- scripts/memcachedqueuehandler.php | 16 ++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) mode change 100644 => 100755 scripts/inboxqueuehandler.php mode change 100644 => 100755 scripts/memcachedqueuehandler.php diff --git a/scripts/inboxqueuehandler.php b/scripts/inboxqueuehandler.php old mode 100644 new mode 100755 index 16e334b83..c76b80389 --- a/scripts/inboxqueuehandler.php +++ b/scripts/inboxqueuehandler.php @@ -29,6 +29,7 @@ define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); define('LACONICA', true); require_once(INSTALLDIR . '/lib/common.php'); +require_once(INSTALLDIR . '/lib/queuehandler.php'); set_error_handler('common_error_handler'); @@ -39,12 +40,20 @@ class InboxQueueHandler extends QueueHandler return 'inbox'; } + function start() { + $this->log(LOG_INFO, "INITIALIZE"); + return true; + } + function handle_notice($notice) { - common_log(LOG_INFO, "Distributing notice to inboxes for $notice->id"); + $this->log(LOG_INFO, "Distributing notice to inboxes for $notice->id"); $notice->addToInboxes(); return true; } + + function finish() { + } } ini_set("max_execution_time", "0"); @@ -52,6 +61,8 @@ ini_set("max_input_time", "0"); set_time_limit(0); mb_internal_encoding('UTF-8'); -$handler = new InboxQueueHandler($resource); +$id = ($argc > 1) ? $argv[1] : null; + +$handler = new InboxQueueHandler($id); $handler->runOnce(); diff --git a/scripts/memcachedqueuehandler.php b/scripts/memcachedqueuehandler.php old mode 100644 new mode 100755 index 43231fa2c..6e819b41f --- a/scripts/memcachedqueuehandler.php +++ b/scripts/memcachedqueuehandler.php @@ -29,6 +29,7 @@ define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); define('LACONICA', true); require_once(INSTALLDIR . '/lib/common.php'); +require_once(INSTALLDIR . '/lib/queuehandler.php'); set_error_handler('common_error_handler'); @@ -39,13 +40,22 @@ class MemcachedQueueHandler extends QueueHandler return 'memcached'; } + function start() { + $this->log(LOG_INFO, "INITIALIZE"); + return true; + } + function handle_notice($notice) { // XXX: fork here - common_log(LOG_INFO, "Blowing memcached for $notice->id"); + $this->log(LOG_INFO, "Blowing memcached for $notice->id"); $notice->blowCaches(); return true; } + + function finish() { + } + } ini_set("max_execution_time", "0"); @@ -53,6 +63,8 @@ ini_set("max_input_time", "0"); set_time_limit(0); mb_internal_encoding('UTF-8'); -$handler = new MemcachedQueueHandler($resource); +$id = ($argc > 1) ? $argv[1] : null; + +$handler = new MemcachedQueueHandler($id); $handler->runOnce(); -- cgit v1.2.3-54-g00ecf From 7c383dc1d46cae8abc6d1e5c7eb93ad7cdd91f63 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 23 Apr 2009 10:08:26 +0000 Subject: alert to what transport we're checking for --- lib/queuehandler.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/queuehandler.php b/lib/queuehandler.php index 9ce9e32b3..fde650d9e 100644 --- a/lib/queuehandler.php +++ b/lib/queuehandler.php @@ -36,7 +36,7 @@ class QueueHandler extends Daemon $this->set_id($id); } } - + function class_name() { return ucfirst($this->transport()) . 'Handler'; @@ -46,7 +46,7 @@ class QueueHandler extends Daemon { return strtolower($this->class_name().'.'.$this->get_id()); } - + function get_id() { return $this->_id; @@ -56,16 +56,16 @@ class QueueHandler extends Daemon { $this->_id = $id; } - + function transport() { return null; } - + function start() { } - + function finish() { } @@ -74,14 +74,14 @@ class QueueHandler extends Daemon { return true; } - + function run() { if (!$this->start()) { return false; } - $this->log(LOG_INFO, 'checking for queued notices'); $transport = $this->transport(); + $this->log(LOG_INFO, 'checking for queued notices for "' . $transport . '"'); do { $qi = Queue_item::top($transport); if ($qi) { @@ -113,7 +113,7 @@ class QueueHandler extends Daemon } else { $this->clear_old_claims(); $this->idle(5); - } + } } while (true); if (!$this->finish()) { return false; @@ -127,7 +127,7 @@ class QueueHandler extends Daemon sleep($timeout); } } - + function clear_old_claims() { $qi = new Queue_item(); @@ -137,10 +137,9 @@ class QueueHandler extends Daemon $qi->free(); unset($qi); } - + function log($level, $msg) { common_log($level, $this->class_name() . ' ('. $this->get_id() .'): '.$msg); } } - \ No newline at end of file -- cgit v1.2.3-54-g00ecf From 290ae7888c4d8dbcb703920960b10bca635563ed Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 23 Apr 2009 10:08:51 +0000 Subject: blow subs cache after updating inboxes --- scripts/inboxqueuehandler.php | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/inboxqueuehandler.php b/scripts/inboxqueuehandler.php index c76b80389..73d31e854 100755 --- a/scripts/inboxqueuehandler.php +++ b/scripts/inboxqueuehandler.php @@ -49,6 +49,7 @@ class InboxQueueHandler extends QueueHandler { $this->log(LOG_INFO, "Distributing notice to inboxes for $notice->id"); $notice->addToInboxes(); + $notice->blowSubsCache(); return true; } -- cgit v1.2.3-54-g00ecf From 1c0d82de3bb7f75649a017a7d5632a6e070876c2 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 23 Apr 2009 10:09:08 +0000 Subject: 8-char limit on transports --- lib/util.php | 3 ++- scripts/memcachedqueuehandler.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/util.php b/lib/util.php index d77039b74..f862d7fcc 100644 --- a/lib/util.php +++ b/lib/util.php @@ -886,7 +886,8 @@ function common_enqueue_notice($notice) } if (common_config('memcached', 'enabled')) { - $transports[] = 'memcached'; + // Note: limited to 8 chars + $transports[] = 'memcache'; } if (common_config('inboxes', 'enabled') === true || diff --git a/scripts/memcachedqueuehandler.php b/scripts/memcachedqueuehandler.php index 6e819b41f..185b781f7 100755 --- a/scripts/memcachedqueuehandler.php +++ b/scripts/memcachedqueuehandler.php @@ -37,7 +37,7 @@ class MemcachedQueueHandler extends QueueHandler { function transport() { - return 'memcached'; + return 'memcache'; } function start() { -- cgit v1.2.3-54-g00ecf From a9df5eab100bce97da3e028851d224ea2e9fff80 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 23 Apr 2009 10:38:51 +0000 Subject: insert into user's inbox at Web time --- classes/Notice.php | 76 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 25 deletions(-) diff --git a/classes/Notice.php b/classes/Notice.php index ebed0b8af..27b98de1c 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -197,7 +197,9 @@ class Notice extends Memcached_DataObject $notice->saveTags(); $notice->saveGroups(); - if (!common_config('queue', 'enabled')) { + if (common_config('queue', 'enabled')) { + $notice->addToAuthorInbox(); + } else { $notice->addToInboxes(); } @@ -282,16 +284,8 @@ class Notice extends Memcached_DataObject { // Clear the user's cache $cache = common_memcache(); - if ($cache) { - $user = User::staticGet($this->profile_id); - if (!empty($user)) { - $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id)); - if ($blowLast) { - $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id . ';last')); - } - } - $user->free(); - unset($user); + if (!empty($cache)) { + $cache->delete(common_cache_key('user:notices_with_friends:' . $this->profile_id)); } $this->blowNoticeCache($blowLast); $this->blowPublicCache($blowLast); @@ -665,6 +659,33 @@ class Notice extends Memcached_DataObject return; } + function addToAuthorInbox() + { + $enabled = common_config('inboxes', 'enabled'); + + if ($enabled === true || $enabled === 'transitional') { + $user = User::staticGet('id', $this->profile_id); + if (empty($user)) { + return; + } + $inbox = new Notice_inbox(); + $UT = common_config('db','type')=='pgsql'?'"user"':'user'; + $qry = 'INSERT INTO notice_inbox (user_id, notice_id, created) ' . + "SELECT $UT.id, " . $this->id . ", '" . $this->created . "' " . + "FROM $UT " . + "WHERE $UT.id = " . $this->profile_id . ' ' . + 'AND NOT EXISTS (SELECT user_id, notice_id ' . + 'FROM notice_inbox ' . + "WHERE user_id = " . $this->profile_id . ' '. + 'AND notice_id = ' . $this->id . ' )'; + if ($enabled === 'transitional') { + $qry .= " AND $UT.inboxed = 1"; + } + $inbox->query($qry); + } + return; + } + function saveGroups() { $enabled = common_config('inboxes', 'enabled'); @@ -717,24 +738,29 @@ class Notice extends Memcached_DataObject // FIXME: do this in an offline daemon - $inbox = new Notice_inbox(); - $UT = common_config('db','type')=='pgsql'?'"user"':'user'; - $qry = 'INSERT INTO notice_inbox (user_id, notice_id, created, source) ' . - "SELECT $UT.id, " . $this->id . ", '" . $this->created . "', 2 " . - "FROM $UT JOIN group_member ON $UT.id = group_member.profile_id " . - 'WHERE group_member.group_id = ' . $group->id . ' ' . - 'AND NOT EXISTS (SELECT user_id, notice_id ' . - 'FROM notice_inbox ' . - "WHERE user_id = $UT.id " . - 'AND notice_id = ' . $this->id . ' )'; - if ($enabled === 'transitional') { - $qry .= " AND $UT.inboxed = 1"; - } - $result = $inbox->query($qry); + $this->addToGroupInboxes($group); } } } + function addToGroupInboxes($group) + { + $inbox = new Notice_inbox(); + $UT = common_config('db','type')=='pgsql'?'"user"':'user'; + $qry = 'INSERT INTO notice_inbox (user_id, notice_id, created, source) ' . + "SELECT $UT.id, " . $this->id . ", '" . $this->created . "', 2 " . + "FROM $UT JOIN group_member ON $UT.id = group_member.profile_id " . + 'WHERE group_member.group_id = ' . $group->id . ' ' . + 'AND NOT EXISTS (SELECT user_id, notice_id ' . + 'FROM notice_inbox ' . + "WHERE user_id = $UT.id " . + 'AND notice_id = ' . $this->id . ' )'; + if ($enabled === 'transitional') { + $qry .= " AND $UT.inboxed = 1"; + } + $result = $inbox->query($qry); + } + function saveReplies() { // Alternative reply format -- cgit v1.2.3-54-g00ecf From 2bdf192dabb9dfbbc889c3387bf5261a2d4166ce Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 23 Apr 2009 21:35:21 +0000 Subject: XHR alerts for server-side errors: 404, 502, 503, 504. There is also a 7 second timeout if the server doesn't get back with a response. --- js/util.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/js/util.js b/js/util.js index 13036f7ca..c7b1272c8 100644 --- a/js/util.js +++ b/js/util.js @@ -166,6 +166,25 @@ $(document).ready(function(){ $("#notice_action-submit").addClass("disabled"); return true; }, + timeout: 1000, + error: function (xhr, textStatus, errorThrown) { $("#form_notice").removeClass("processing"); + $("#notice_action-submit").removeAttr("disabled"); + $("#notice_action-submit").removeClass("disabled"); + + if (textStatus == "timeout") { + alert ("Sorry! We had trouble sending your notice. The servers are overloaded. Please try again, and contact the site administrator if this problem persists"); + } + else { + switch(xhr.status) { + default: case 404: + alert("Sorry! We had trouble sending your notice. Please report the problem to the site administrator if this happens again."); + break; + case 502: case 503: case 504: + alert("Sorry! We had trouble sending your notice. The servers are overloaded. Please try again, and contact the site administrator if this problem persists."); + break; + } + } + }, success: function(xml) { if ($("#error", xml).length > 0) { var result = document._importNode($("p", xml).get(0), true); result = result.textContent || result.innerHTML; -- cgit v1.2.3-54-g00ecf From 83ba1b0b5ef10dc1101ba35bcde4710fd13179cc Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 23 Apr 2009 21:51:49 +0000 Subject: The real 7 seconds (7000) timeout for XHR posting. --- js/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/util.js b/js/util.js index c7b1272c8..16422df57 100644 --- a/js/util.js +++ b/js/util.js @@ -166,7 +166,7 @@ $(document).ready(function(){ $("#notice_action-submit").addClass("disabled"); return true; }, - timeout: 1000, + timeout: 7000, error: function (xhr, textStatus, errorThrown) { $("#form_notice").removeClass("processing"); $("#notice_action-submit").removeAttr("disabled"); $("#notice_action-submit").removeClass("disabled"); -- cgit v1.2.3-54-g00ecf From 12867d114d8d40bf9a45b3e1eb9b0e50d736d333 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 24 Apr 2009 17:22:43 +0000 Subject: UI for server errors. --- js/util.js | 15 +++------------ theme/base/css/display.css | 11 +++++++++-- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/js/util.js b/js/util.js index 16422df57..15a14625c 100644 --- a/js/util.js +++ b/js/util.js @@ -166,23 +166,14 @@ $(document).ready(function(){ $("#notice_action-submit").addClass("disabled"); return true; }, - timeout: 7000, error: function (xhr, textStatus, errorThrown) { $("#form_notice").removeClass("processing"); $("#notice_action-submit").removeAttr("disabled"); $("#notice_action-submit").removeClass("disabled"); - - if (textStatus == "timeout") { - alert ("Sorry! We had trouble sending your notice. The servers are overloaded. Please try again, and contact the site administrator if this problem persists"); + if ($(".error", xhr.responseXML).length > 0) { + $('#form_notice').append(document._importNode($(".error", xhr.responseXML).get(0), true)); } else { - switch(xhr.status) { - default: case 404: - alert("Sorry! We had trouble sending your notice. Please report the problem to the site administrator if this happens again."); - break; - case 502: case 503: case 504: - alert("Sorry! We had trouble sending your notice. The servers are overloaded. Please try again, and contact the site administrator if this problem persists."); - break; - } + alert("Sorry! We had trouble sending your notice ("+xhr.status+" "+xhr.statusText+"). Please report the problem to the site administrator if this happens again."); } }, success: function(xml) { if ($("#error", xml).length > 0) { diff --git a/theme/base/css/display.css b/theme/base/css/display.css index 2fb1c007f..0bc2e68b6 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -86,7 +86,7 @@ border:0; .error, .success { -padding:4px 7px; +padding:4px 1.55%; border-radius:4px; -moz-border-radius:4px; -webkit-border-radius:4px; @@ -426,6 +426,7 @@ line-height:1; #form_notice fieldset { border:0; padding:0; +position:relative; } #form_notice legend { display:none; @@ -480,7 +481,13 @@ margin-bottom:7px; margin-left:18px; float:left; } - +#form_notice .error { +float:left; +clear:both; +width:96.9%; +margin-bottom:0; +line-height:1.618; +} /* entity_profile */ .entity_profile { -- cgit v1.2.3-54-g00ecf From ecb09fb8646def7f6a7c5fc0fc2d4df6676edd06 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 24 Apr 2009 13:31:03 -0400 Subject: check for existence of xmlrpc extension in LinkbackPlugin --- plugins/LinkbackPlugin.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/LinkbackPlugin.php b/plugins/LinkbackPlugin.php index 881ead99e..93a0294c4 100644 --- a/plugins/LinkbackPlugin.php +++ b/plugins/LinkbackPlugin.php @@ -121,6 +121,12 @@ class LinkbackPlugin extends Plugin { $args = array($this->notice->uri, $url); + if (!extension_loaded('xmlrpc')) { + if (!dl('xmlrpc.so')) { + common_log(LOG_ERR, "Can't pingback; xmlrpc extension not available."); + } + } + $request = xmlrpc_encode_request('pingback.ping', $args); $context = stream_context_create(array('http' => array('method' => "POST", 'header' => @@ -141,7 +147,7 @@ class LinkbackPlugin extends Plugin } // Largely cadged from trackback_cls.php by - // Ran Aroussi , GPL2 + // Ran Aroussi , GPL2 or any later version // http://phptrackback.sourceforge.net/ function getTrackback($text, $url) -- cgit v1.2.3-54-g00ecf From 4a86823d064e13446733f86218bbe0f49dea7714 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 24 Apr 2009 13:31:03 -0400 Subject: check for existence of xmlrpc extension in LinkbackPlugin --- plugins/LinkbackPlugin.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/LinkbackPlugin.php b/plugins/LinkbackPlugin.php index 881ead99e..93a0294c4 100644 --- a/plugins/LinkbackPlugin.php +++ b/plugins/LinkbackPlugin.php @@ -121,6 +121,12 @@ class LinkbackPlugin extends Plugin { $args = array($this->notice->uri, $url); + if (!extension_loaded('xmlrpc')) { + if (!dl('xmlrpc.so')) { + common_log(LOG_ERR, "Can't pingback; xmlrpc extension not available."); + } + } + $request = xmlrpc_encode_request('pingback.ping', $args); $context = stream_context_create(array('http' => array('method' => "POST", 'header' => @@ -141,7 +147,7 @@ class LinkbackPlugin extends Plugin } // Largely cadged from trackback_cls.php by - // Ran Aroussi , GPL2 + // Ran Aroussi , GPL2 or any later version // http://phptrackback.sourceforge.net/ function getTrackback($text, $url) -- cgit v1.2.3-54-g00ecf From c008c0d4a56ec265ba6e10d208f9954510296f12 Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Fri, 24 Apr 2009 20:01:03 +0000 Subject: fixed trac#1215, 1216, 1217 and 1219: subscribers/subscriptions people tagclouds. --- lib/subpeopletagcloudsection.php | 1 + lib/subscriberspeopleselftagcloudsection.php | 10 +++++++++- lib/subscriberspeopletagcloudsection.php | 5 +++-- lib/subscriptionspeopleselftagcloudsection.php | 9 ++++++++- lib/subscriptionspeopletagcloudsection.php | 4 +++- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/lib/subpeopletagcloudsection.php b/lib/subpeopletagcloudsection.php index d98f28afa..9f6948dc9 100644 --- a/lib/subpeopletagcloudsection.php +++ b/lib/subpeopletagcloudsection.php @@ -74,3 +74,4 @@ class SubPeopleTagCloudSection extends TagCloudSection $this->out->elementEnd('li'); } } + diff --git a/lib/subscriberspeopleselftagcloudsection.php b/lib/subscriberspeopleselftagcloudsection.php index b5a39c6de..115241a53 100644 --- a/lib/subscriberspeopleselftagcloudsection.php +++ b/lib/subscriberspeopleselftagcloudsection.php @@ -49,6 +49,14 @@ class SubscribersPeopleSelfTagCloudSection extends SubPeopleTagCloudSection } function query() { - return 'select tag, count(tag) as weight from subscription left join profile_tag on tagger = subscriber where subscribed=%d and subscribed != subscriber and tagger = tagged group by tag order by weight desc'; +// return 'select tag, count(tag) as weight from subscription left join profile_tag on tagger = subscriber where subscribed=%d and subscribed != subscriber and tagger = tagged group by tag order by weight desc'; + + + return 'select tag, count(tag) as weight from subscription left join profile_tag on tagger = subscriber where subscribed=%d and subscribed != subscriber and tagger = tagged and tag is not null group by tag order by weight desc'; + +// return 'select tag, count(tag) as weight from subscription left join profile_tag on tagger = subscribed where subscriber=%d and subscribed != subscriber and tagger = tagged and tag is not null group by tag order by weight desc'; + + } } + diff --git a/lib/subscriberspeopletagcloudsection.php b/lib/subscriberspeopletagcloudsection.php index 23011efdd..4dafbc1c7 100644 --- a/lib/subscriberspeopletagcloudsection.php +++ b/lib/subscriberspeopletagcloudsection.php @@ -53,8 +53,9 @@ class SubscribersPeopleTagCloudSection extends SubPeopleTagCloudSection return common_local_url('subscribers', array('nickname' => $nickname, 'tag' => $tag)); } - function query() { - return 'select tag, count(tag) as weight from subscription left join profile_tag on subscriber=tagged and subscribed=tagger where subscribed=%d and subscriber != subscribed group by tag order by weight desc'; +// return 'select tag, count(tag) as weight from subscription left join profile_tag on subscriber=tagged and subscribed=tagger where subscribed=%d and subscriber != subscribed group by tag order by weight desc'; + return 'select tag, count(tag) as weight from subscription left join profile_tag on subscriber=tagged and subscribed=tagger where subscribed=%d and subscriber != subscribed and tag is not null group by tag order by weight desc'; } } + diff --git a/lib/subscriptionspeopleselftagcloudsection.php b/lib/subscriptionspeopleselftagcloudsection.php index 8ac65adb0..3896294d2 100644 --- a/lib/subscriptionspeopleselftagcloudsection.php +++ b/lib/subscriptionspeopleselftagcloudsection.php @@ -49,6 +49,13 @@ class SubscriptionsPeopleSelfTagCloudSection extends SubPeopleTagCloudSection } function query() { - return 'select tag, count(tag) as weight from subscription left join profile_tag on tagger = subscriber where subscribed=%d and subscriber != subscribed and tagger = tagged group by tag order by weight desc'; +// return 'select tag, count(tag) as weight from subscription left join profile_tag on tagger = subscriber where subscribed=%d and subscriber != subscribed and tagger = tagged group by tag order by weight desc'; + + + + return 'select tag, count(tag) as weight from subscription left join profile_tag on tagger = subscribed where subscriber=%d and subscribed != subscriber and tagger = tagged and tag is not null group by tag order by weight desc'; + +// return 'select tag, count(tag) as weight from subscription left join profile_tag on tagger = subscriber where subscribed=%d and subscribed != subscriber and tagger = tagged and tag is not null group by tag order by weight desc'; } } + diff --git a/lib/subscriptionspeopletagcloudsection.php b/lib/subscriptionspeopletagcloudsection.php index c3f7d1763..f9c8672e3 100644 --- a/lib/subscriptionspeopletagcloudsection.php +++ b/lib/subscriptionspeopletagcloudsection.php @@ -54,6 +54,8 @@ class SubscriptionsPeopleTagCloudSection extends SubPeopleTagCloudSection } function query() { - return 'select tag, count(tag) as weight from subscription left join profile_tag on subscriber=tagger and subscribed=tagged where subscriber=%d and subscriber != subscribed group by tag order by weight desc'; +// return 'select tag, count(tag) as weight from subscription left join profile_tag on subscriber=tagger and subscribed=tagged where subscriber=%d and subscriber != subscribed group by tag order by weight desc'; + return 'select tag, count(tag) as weight from subscription left join profile_tag on subscriber=tagger and subscribed=tagged where subscriber=%d and subscriber != subscribed and tag is not null group by tag order by weight desc'; } } + -- cgit v1.2.3-54-g00ecf From d71fbe9d9693cd5426be74807ff8f18fc6376c56 Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Fri, 24 Apr 2009 20:28:39 +0000 Subject: fixed subscriptions dropdown action --- lib/galleryaction.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/galleryaction.php b/lib/galleryaction.php index 0484918ce..8fa11a756 100644 --- a/lib/galleryaction.php +++ b/lib/galleryaction.php @@ -134,9 +134,11 @@ class GalleryAction extends Action $this->elementStart('li', array('id'=>'filter_tags_item')); $this->elementStart('form', array('name' => 'bytag', 'id' => 'bytag', + 'action' => common_path('?action=' . $this->trimmed('action')), 'method' => 'post')); $this->dropdown('tag', _('Tag'), $content, _('Choose a tag to narrow list'), false, $tag); + $this->hidden('nickname', $this->user->nickname); $this->submit('submit', _('Go')); $this->elementEnd('form'); $this->elementEnd('li'); @@ -169,4 +171,4 @@ class GalleryAction extends Action { return array(); } -} \ No newline at end of file +} -- cgit v1.2.3-54-g00ecf From 6eb5a2566f5f29a4c129111e1cc86d85d641a3ad Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Fri, 24 Apr 2009 14:27:31 -0700 Subject: Some clean up -- this still doesn't work, yet. The processes all lose their database connections, including the parent process. --- scripts/statusfetcher.php | 324 ++++++++++++++++++++++++++++------------------ 1 file changed, 198 insertions(+), 126 deletions(-) diff --git a/scripts/statusfetcher.php b/scripts/statusfetcher.php index d303a098c..8f4b60cf7 100644 --- a/scripts/statusfetcher.php +++ b/scripts/statusfetcher.php @@ -32,38 +32,117 @@ define('SCRIPT_DEBUG', true); require_once(INSTALLDIR . '/lib/common.php'); -$flink = new Foreign_link(); -$flink->service = 1; // Twitter -$cnt = $flink->find(); +$children = array(); +$flink_ids = null; -print "Updating Twitter friends subscriptions for $cnt users.\n"; +$MAXCHILDREN = 5; +$POLL_INTERVAL = 10; // 10 seconds +do { -while ($flink->fetch()) { + $flink = new Foreign_link(); + $flink->service = 1; // Twitter + $cnt = $flink->find(); - if (($flink->noticesync & FOREIGN_NOTICE_RECV) == FOREIGN_NOTICE_RECV) { + if (defined('SCRIPT_DEBUG')) { + print "Updating Twitter friends subscriptions for $cnt users.\n"; + } - $user = User::staticGet($flink->user_id); + $flink_ids = array(); - if (empty($user)) { - common_log(LOG_WARNING, "Unmatched user for ID " . $flink->user_id); - print "Unmatched user for ID $flink->user_id\n"; - continue; + // XXX: This only reliably happens once. After the first interation of + // the do loop, the ->find() doesn't work ... lost DB connection? + + while ($flink->fetch()) { + + if (($flink->noticesync & FOREIGN_NOTICE_RECV) == FOREIGN_NOTICE_RECV) { + $flink_ids[] = $flink->foreign_id; + } + } + + $flink->free(); + unset($flink); + + foreach ($flink_ids as $f){ + + $pid = pcntl_fork(); + + if ($pid == -1) { + die ("Couldn't fork!"); } - - print 'Retrieving Friends Timeline for ' . $flink->user_id . "\n"; - - getTimeline($flink); - + + // Parent + if ($pid) { + if (defined('SCRIPT_DEBUG')) { + print "Parent: forked " . $pid . "\n"; + } + $children[] = $pid; + } else { + + // Child + + // XXX: Each child needs its own DB connection + + getTimeline($f); + exit(); + } + + // Remove child from ps list as it finishes + while(($c = pcntl_wait($status, WNOHANG OR WUNTRACED)) > 0) { + if (defined('SCRIPT_DEBUG')) { + print "Child $c finished.\n"; + } + remove_ps($children, $c); + } + + // Wait if we have too many kids + if(sizeof($children) > $MAXCHILDREN) { + if (defined('SCRIPT_DEBUG')) { + print "Too many children. Waiting...\n"; + } + if( ($c = pcntl_wait($status, WUNTRACED) ) > 0){ + if (defined('SCRIPT_DEBUG')) { + print "Finished waiting for $c\n"; + } + remove_ps($children, $c); + } + } + } + + // Remove all children from the process list before restarting + while(($c = pcntl_wait($status, WUNTRACED)) > 0) { if (defined('SCRIPT_DEBUG')) { - print "\nDONE\n"; + print "Child $c finished.\n"; + } + remove_ps($children, $c); + } + + // Rest for a bit before we fetch more statuses + if (defined('SCRIPT_DEBUG')) { + print "Waiting $POLL_INTERVAL secs before hitting Twitter again.\n"; + } + + sleep($POLL_INTERVAL); + +} while (true); + + +function remove_ps(&$plist, $ps){ + for($i = 0; $i < sizeof($plist); $i++){ + if($plist[$i] == $ps){ + unset($plist[$i]); + $plist = array_values($plist); + break; } } } -function getTimeline($flink) +function getTimeline($fid) { + // XXX: Need to reconnect to the DB here? + + $flink = Foreign_link::getByForeignID($fid, 1); $fuser = $flink->getForeignUser(); if (empty($fuser)) { @@ -71,7 +150,6 @@ function getTimeline($flink) if (defined('SCRIPT_DEBUG')) { print "Unmatched user for ID $flink->user_id\n"; } - continue; } $screenname = $fuser->nickname; @@ -82,26 +160,34 @@ function getTimeline($flink) $flink->credentials); $timeline = json_decode($timeline_json); - + + if (empty($timeline)) { + common_log(LOG_WARNING, "Empty timeline."); + if (defined('SCRIPT_DEBUG')) { + print "Empty timeline!\n"; + } + return; + } + foreach ($timeline as $status) { - + // Hacktastic: filter out stuff coming from Laconica $source = mb_strtolower(common_config('integration', 'source')); - + if (preg_match("/$source/", mb_strtolower($status->source))) { continue; } - + saveStatus($status, $flink); } - + } function saveStatus($status, $flink) { - // Do we have a profile for this Twitter user? - - $id = ensureProfile($status->user); + // Do we have a profile for this Twitter user? + + $id = ensureProfile($status->user); $profile = Profile::staticGet($id); if (!$profile) { @@ -112,34 +198,33 @@ function saveStatus($status, $flink) return null; } - $uri = 'http://twitter.com/' . $status->user->screen_name . + $uri = 'http://twitter.com/' . $status->user->screen_name . '/status/' . $status->id; - - // Skip save if notice source is Laconica or Identi.ca? - - $notice = Notice::staticGet('uri', $uri); - + + // Skip save if notice source is Laconica or Identi.ca? + + $notice = Notice::staticGet('uri', $uri); + // check to see if we've already imported the status if (!$notice) { - - $notice = new Notice(); + $notice = new Notice(); $notice->profile_id = $id; - $notice->query('BEGIN'); + $notice->query('BEGIN'); // XXX: figure out reply_to - $notice->reply_to = null; - - // XXX: Should this be common_sql_now() instead of status create date? - - $notice->created = strftime('%Y-%m-%d %H:%M:%S', - strtotime($status->created_at)); - $notice->content = $status->text; - $notice->rendered = common_render_content($status->text, $notice); - $notice->source = 'twitter'; - $notice->is_local = 0; - $notice->uri = $uri; + $notice->reply_to = null; + + // XXX: Should this be common_sql_now() instead of status create date? + + $notice->created = strftime('%Y-%m-%d %H:%M:%S', + strtotime($status->created_at)); + $notice->content = $status->text; + $notice->rendered = common_render_content($status->text, $notice); + $notice->source = 'twitter'; + $notice->is_local = 0; + $notice->uri = $uri; $notice_id = $notice->insert(); @@ -150,59 +235,54 @@ function saveStatus($status, $flink) } } - # XXX: do we need to change this for remote users? - + // XXX: Figure out a better way to link replies? $notice->saveReplies(); - + // XXX: Do we want to polute our tag cloud with hashtags from Twitter? $notice->saveTags(); - $notice->saveGroups(); - + $notice->saveGroups(); + $notice->query('COMMIT'); - + } if (!Notice_inbox::staticGet('notice_id', $notice->id)) { - + // Add to inbox $inbox = new Notice_inbox(); $inbox->user_id = $flink->user_id; $inbox->notice_id = $notice->id; $inbox->created = common_sql_now(); - - $inbox->insert(); - } + $inbox->insert(); + } } -function ensureProfile($user) +function ensureProfile($user) { - + // check to see if there's already a profile for this user $profileurl = 'http://twitter.com/' . $user->screen_name; - $profile = Profile::staticGet('profileurl', $profileurl); - + if ($profile) { - common_debug("Profile for $profile->nickname found."); - + // Check to see if the user's Avatar has changed checkAvatar($user, $profile); return $profile->id; - + } else { - $debugmsg = 'Adding profile and remote profile ' . "for Twitter user: $profileurl\n"; common_debug($debugmsg, __FILE__); if (defined('SCRIPT_DEBUG')) { print $debugmsg; } - + $profile = new Profile(); $profile->query("BEGIN"); - + $profile->nickname = $user->screen_name; $profile->fullname = $user->name; $profile->homepage = $user->url; @@ -216,37 +296,37 @@ function ensureProfile($user) if (empty($id)) { common_log_db_error($profile, 'INSERT', __FILE__); if (defined('SCRIPT_DEBUG')) { - print 'Could not insert Profile: ' . + print 'Could not insert Profile: ' . common_log_objstring($profile) . "\n"; } $profile->query("ROLLBACK"); return false; - } - - // check for remote profile + } + + // check for remote profile $remote_pro = Remote_profile::staticGet('uri', $profileurl); - + if (!$remote_pro) { - + $remote_pro = new Remote_profile(); $remote_pro->id = $id; $remote_pro->uri = $profileurl; $remote_pro->created = common_sql_now(); - + $rid = $remote_pro->insert(); - - if (empty($rid)) { + + if (empty($rid)) { common_log_db_error($profile, 'INSERT', __FILE__); if (defined('SCRIPT_DEBUG')) { - print 'Could not insert Remote_profile: ' . + print 'Could not insert Remote_profile: ' . common_log_objstring($remote_pro) . "\n"; } $profile->query("ROLLBACK"); return false; - } + } } - + $profile->query("COMMIT"); $profile->free(); unset($profile); @@ -258,24 +338,22 @@ function ensureProfile($user) } function checkAvatar($user, $profile) -{ - common_debug("in check avatar"); - +{ $path_parts = pathinfo($user->profile_image_url); - $newname = 'Twitter_' . $user->id . '_' . + $newname = 'Twitter_' . $user->id . '_' . $path_parts['basename']; - + $oldname = $profile->getAvatar(48)->filename; if ($newname != $oldname) { - + common_debug("Avatar for Twitter user $profile->nickname has changed."); common_debug("old: $oldname new: $newname"); - + if (defined('SCRIPT_DEBUG')) { print "Avatar for Twitter user $user->id has changed.\n"; print "old: $oldname\n"; - print "new: $newname\n"; + print "new: $newname\n"; } $img_root = substr($path_parts['basename'], 0, -11); @@ -283,23 +361,22 @@ function checkAvatar($user, $profile) $mediatype = getMediatype($ext); foreach (array('mini', 'normal', 'bigger') as $size) { - $url = $path_parts['dirname'] . '/' . + $url = $path_parts['dirname'] . '/' . $img_root . '_' . $size . ".$ext"; - $filename = 'Twitter_' . $user->id . '_' . + $filename = 'Twitter_' . $user->id . '_' . $img_root . "_$size.$ext"; if (fetchAvatar($url, $filename)) { - updateAvatar($profile->id, $size, $mediatype, $filename); + updateAvatar($profile->id, $size, $mediatype, $filename); } } } - } -function getMediatype($ext) +function getMediatype($ext) { $mediatype = null; - + switch (strtolower($ext)) { case 'jpg': $mediatype = 'image/jpg'; @@ -310,26 +387,22 @@ function getMediatype($ext) default: $mediatype = 'image/png'; } - + return $mediatype; } - -function saveAvatars($user, $id) +function saveAvatars($user, $id) { $path_parts = pathinfo($user->profile_image_url); - - // basename minus '_normal.ext' - $ext = $path_parts['extension']; $end = strlen('_normal' . $ext); $img_root = substr($path_parts['basename'], 0, -($end+1)); $mediatype = getMediatype($ext); - + foreach (array('mini', 'normal', 'bigger') as $size) { - $url = $path_parts['dirname'] . '/' . + $url = $path_parts['dirname'] . '/' . $img_root . '_' . $size . ".$ext"; - $filename = 'Twitter_' . $user->id . '_' . + $filename = 'Twitter_' . $user->id . '_' . $img_root . "_$size.$ext"; if (fetchAvatar($url, $filename)) { @@ -348,7 +421,7 @@ function updateAvatar($profile_id, $size, $mediatype, $filename) { common_debug("updating avatar: $size"); $profile = Profile::staticGet($profile_id); - + if (!$profile) { common_debug("Couldn't get profile: $profile_id!"); if (defined('SCRIPT_DEBUG')) { @@ -356,17 +429,17 @@ function updateAvatar($profile_id, $size, $mediatype, $filename) { } return; } - + $sizes = array('mini' => 24, 'normal' => 48, 'bigger' => 73); $avatar = $profile->getAvatar($sizes[$size]); - + if ($avatar) { common_debug("Deleting $size avatar for $profile->nickname."); @unlink(INSTALLDIR . '/avatar/' . $avatar->filename); $avatar->delete(); } - - newAvatar($profile->id, $size, $mediatype, $filename); + + newAvatar($profile->id, $size, $mediatype, $filename); } function newAvatar($profile_id, $size, $mediatype, $filename) @@ -376,19 +449,19 @@ function newAvatar($profile_id, $size, $mediatype, $filename) switch($size) { case 'mini': - $avatar->width = 24; + $avatar->width = 24; $avatar->height = 24; break; case 'normal': - $avatar->width = 48; + $avatar->width = 48; $avatar->height = 48; break; default: - - // Note: Twitter's big avatars are a different size than + + // Note: Twitter's big avatars are a different size than // Laconica's (Laconica's = 96) - - $avatar->width = 73; + + $avatar->width = 73; $avatar->height = 73; } @@ -396,33 +469,33 @@ function newAvatar($profile_id, $size, $mediatype, $filename) $avatar->mediatype = $mediatype; $avatar->filename = $filename; $avatar->url = Avatar::url($filename); - + common_debug("new filename: $avatar->url"); - + $avatar->created = common_sql_now(); $id = $avatar->insert(); - if (!$id) { + if (!$id) { common_log_db_error($avatar, 'INSERT', __FILE__); if (defined('SCRIPT_DEBUG')) { print "Could not insert avatar!\n"; } - + return null; } - + common_debug("Saved new $size avatar for $profile_id."); - + return $id; } -function fetchAvatar($url, $filename) +function fetchAvatar($url, $filename) { $avatar_dir = INSTALLDIR . '/avatar/'; - + $avatarfile = $avatar_dir . $filename; - + $out = fopen($avatarfile, 'wb'); if (!$out) { common_log(LOG_WARNING, "Couldn't open file $filename", __FILE__); @@ -431,12 +504,12 @@ function fetchAvatar($url, $filename) } return false; } - + common_debug("Fetching avatar: $url", __FILE__); if (defined('SCRIPT_DEBUG')) { print "Fetching avatar from Twitter: $url\n"; } - + $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FILE, $out); @@ -447,7 +520,6 @@ function fetchAvatar($url, $filename) curl_close($ch); fclose($out); - + return $result; } - -- cgit v1.2.3-54-g00ecf From 5e6eb27f843a22b80ac114f382682fba0c37589e Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 25 Apr 2009 14:20:24 -0400 Subject: first pass at Comet plugin; doesn't yet update --- plugins/Comet/CometPlugin.php | 138 ++++++++++++++ plugins/Comet/bayeux.class.inc.php | 129 +++++++++++++ plugins/Comet/bayeux.class.inc.phps | 123 ++++++++++++ plugins/Comet/jquery.comet.js | 363 ++++++++++++++++++++++++++++++++++++ plugins/Comet/updatetimeline.js | 3 + 5 files changed, 756 insertions(+) create mode 100644 plugins/Comet/CometPlugin.php create mode 100644 plugins/Comet/bayeux.class.inc.php create mode 100644 plugins/Comet/bayeux.class.inc.phps create mode 100644 plugins/Comet/jquery.comet.js create mode 100644 plugins/Comet/updatetimeline.js diff --git a/plugins/Comet/CometPlugin.php b/plugins/Comet/CometPlugin.php new file mode 100644 index 000000000..10f8c198c --- /dev/null +++ b/plugins/Comet/CometPlugin.php @@ -0,0 +1,138 @@ +. + * + * @category Plugin + * @package Laconica + * @author Evan Prodromou + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Plugin to do realtime updates using Comet + * + * @category Plugin + * @package Laconica + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class CometPlugin extends Plugin +{ + var $server = null; + + function __construct($server=null) + { + $this->server = $server; + + parent::__construct(); + } + + function onEndShowScripts($action) + { + $timeline = null; + + switch ($action->trimmed('action')) { + case 'public': + $timeline = '/timelines/public'; + break; + default: + return true; + } + + $action->element('script', array('type' => 'text/javascript', + 'src' => common_path('plugins/Comet/jquery.comet.js')), + ' '); + $action->elementStart('script', array('type' => 'text/javascript')); + $action->raw("var _timelineServer = \"$this->server\"; ". + "var _timeline = \"$timeline\";"); + $action->elementEnd('script'); + $action->element('script', array('type' => 'text/javascript', + 'src' => common_path('plugins/Comet/updatetimeline.js')), + ' '); + return true; + } + + function onEndNoticeSave($notice) + { + $this->log(LOG_INFO, "Called for save notice."); + + $timelines = array(); + + // XXX: Add other timelines; this is just for the public one + + if ($notice->is_local || + ($notice->is_local == 0 && !common_config('public', 'localonly'))) { + $timelines[] = '/timelines/public'; + } + + if (count($timelines) > 0) { + // Require this, since we need it + require_once(INSTALLDIR.'/plugins/Comet/bayeux.class.inc.php'); + + $json = $this->noticeAsJson($notice); + + $this->log(LOG_DEBUG, "JSON = '$json'"); + + // Bayeux? Comet? Huh? These terms confuse me + $bay = new Bayeux($this->server); + + foreach ($timelines as $timeline) { + $this->log(LOG_INFO, "Posting notice $notice->id to '$timeline'."); + $bay->publish($timeline, $json); + $this->log(LOG_DEBUG, "Done posting notice $notice->id to '$timeline'."); + } + + $bay = NULL; + } + + $this->log(LOG_DEBUG, "All done."); + return true; + } + + function noticeAsJson($notice) + { + // 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! + + require_once(INSTALLDIR.'/lib/twitterapi.php'); + + $act = new TwitterApiAction('/dev/null'); + + $arr = $act->twitter_status_array($notice, true); + return $arr; + } + + // Push this up to Plugin + + function log($level, $msg) + { + common_log($level, get_class($this) . ': '.$msg); + } +} diff --git a/plugins/Comet/bayeux.class.inc.php b/plugins/Comet/bayeux.class.inc.php new file mode 100644 index 000000000..602a7b644 --- /dev/null +++ b/plugins/Comet/bayeux.class.inc.php @@ -0,0 +1,129 @@ + http://morglog.alleycatracing.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +class Bayeux +{ + private $oCurl = ''; + private $nNextId = 0; + + public $sUrl = ''; + + function __construct($sUrl) + { + $this->sUrl = $sUrl; + + $this->oCurl = curl_init(); + + $aHeaders = array(); + $aHeaders[] = 'Connection: Keep-Alive'; + + curl_setopt($this->oCurl, CURLOPT_URL, $sUrl); + curl_setopt($this->oCurl, CURLOPT_HTTPHEADER, $aHeaders); + curl_setopt($this->oCurl, CURLOPT_HEADER, 0); + curl_setopt($this->oCurl, CURLOPT_POST, 1); + curl_setopt($this->oCurl, CURLOPT_RETURNTRANSFER,1); + + $this->handShake(); + } + + function __destruct() + { + $this->disconnect(); + } + + function handShake() + { + $msgHandshake = array(); + $msgHandshake['channel'] = '/meta/handshake'; + $msgHandshake['version'] = "1.0"; + $msgHandshake['minimumVersion'] = "0.9"; + $msgHandshake['supportedConnectionTypes'] = array('long-polling'); + $msgHandshake['id'] = $this->nNextId++; + + curl_setopt($this->oCurl, CURLOPT_POSTFIELDS, "message=".urlencode(str_replace('\\', '', json_encode(array($msgHandshake))))); + + $data = curl_exec($this->oCurl); + + if(curl_errno($this->oCurl)) + die("Error: " . curl_error($this->oCurl)); + + $oReturn = json_decode($data); + + common_debug(print_r($oReturn, true)); + + if (is_array($oReturn)) { + $oReturn = $oReturn[0]; + } + + $bSuccessful = ($oReturn->successful) ? true : false; + + if($bSuccessful) + { + $this->clientId = $oReturn->clientId; + + $this->connect(); + } + } + + public function connect() + { + $aMsg['channel'] = '/meta/connect'; + $aMsg['id'] = $this->nNextId++; + $aMsg['clientId'] = $this->clientId; + $aMsg['connectionType'] = 'long-polling'; + + curl_setopt($this->oCurl, CURLOPT_POSTFIELDS, "message=".urlencode(str_replace('\\', '', json_encode(array($aMsg))))); + + $data = curl_exec($this->oCurl); + } + + function disconnect() + { + $msgHandshake = array(); + $msgHandshake['channel'] = '/meta/disconnect'; + $msgHandshake['id'] = $this->nNextId++; + $msgHandshake['clientId'] = $this->clientId; + + curl_setopt($this->oCurl, CURLOPT_POSTFIELDS, "message=".urlencode(str_replace('\\', '', json_encode(array($msgHandshake))))); + + curl_exec($this->oCurl); + } + + public function publish($sChannel, $oData) + { + if(!$sChannel || !$oData) + return; + + $aMsg = array(); + + $aMsg['channel'] = $sChannel; + $aMsg['id'] = $this->nNextId++; + $aMsg['data'] = $oData; + $aMsg['clientId'] = $this->clientId; + + curl_setopt($this->oCurl, CURLOPT_POSTFIELDS, "message=".urlencode(str_replace('\\', '', json_encode(array($aMsg))))); + + $data = curl_exec($this->oCurl); +// var_dump($data); + } +} diff --git a/plugins/Comet/bayeux.class.inc.phps b/plugins/Comet/bayeux.class.inc.phps new file mode 100644 index 000000000..ea004a453 --- /dev/null +++ b/plugins/Comet/bayeux.class.inc.phps @@ -0,0 +1,123 @@ + http://morglog.alleycatracing.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +class Bayeux + { + private $oCurl = ''; + private $nNextId = 0; + + public $sUrl = ''; + + function __construct($sUrl) + { + $this->sUrl = $sUrl; + + $this->oCurl = curl_init(); + + $aHeaders = array(); + $aHeaders[] = 'Connection: Keep-Alive'; + + curl_setopt($this->oCurl, CURLOPT_URL, $sUrl); + curl_setopt($this->oCurl, CURLOPT_HTTPHEADER, $aHeaders); + curl_setopt($this->oCurl, CURLOPT_HEADER, 0); + curl_setopt($this->oCurl, CURLOPT_POST, 1); + curl_setopt($this->oCurl, CURLOPT_RETURNTRANSFER,1); + + $this->handShake(); + } + + function __destruct() + { + $this->disconnect(); + } + + function handShake() + { + $msgHandshake = array(); + $msgHandshake['channel'] = '/meta/handshake'; + $msgHandshake['version'] = "1.0"; + $msgHandshake['minimumVersion'] = "0.9"; + $msgHandshake['id'] = $this->nNextId++; + + curl_setopt($this->oCurl, CURLOPT_POSTFIELDS, "message=".urlencode(str_replace('\\', '', json_encode(array($msgHandshake))))); + + $data = curl_exec($this->oCurl); + + if(curl_errno($this->oCurl)) + die("Error: " . curl_error($this->oCurl)); + + $oReturn = json_decode($data); + $oReturn = $oReturn[0]; + + $bSuccessful = ($oReturn->successful) ? true : false; + + if($bSuccessful) + { + $this->clientId = $oReturn->clientId; + + $this->connect(); + } + } + + public function connect() + { + $aMsg['channel'] = '/meta/connect'; + $aMsg['id'] = $this->nNextId++; + $aMsg['clientId'] = $this->clientId; + $aMsg['connectionType'] = 'long-polling'; + + curl_setopt($this->oCurl, CURLOPT_POSTFIELDS, "message=".urlencode(str_replace('\\', '', json_encode(array($aMsg))))); + + $data = curl_exec($this->oCurl); + } + + function disconnect() + { + $msgHandshake = array(); + $msgHandshake['channel'] = '/meta/disconnect'; + $msgHandshake['id'] = $this->nNextId++; + $msgHandshake['clientId'] = $this->clientId; + + curl_setopt($this->oCurl, CURLOPT_POSTFIELDS, "message=".urlencode(str_replace('\\', '', json_encode(array($msgHandshake))))); + + curl_exec($this->oCurl); + } + + public function publish($sChannel, $oData) + { + if(!$sChannel || !$oData) + return; + + $aMsg = array(); + + $aMsg['channel'] = $sChannel; + $aMsg['id'] = $this->nNextId++; + $aMsg['data'] = $oData; + $aMsg['clientId'] = $this->clientId; + + curl_setopt($this->oCurl, CURLOPT_POSTFIELDS, "message=".urlencode(str_replace('\\', '', json_encode(array($aMsg))))); + + $data = curl_exec($this->oCurl); +// var_dump($data); + } + } diff --git a/plugins/Comet/jquery.comet.js b/plugins/Comet/jquery.comet.js new file mode 100644 index 000000000..2124e882c --- /dev/null +++ b/plugins/Comet/jquery.comet.js @@ -0,0 +1,363 @@ +(function($) +{ + var msgHandshake = + { + version: '1.0', + minimumVersion: '0.9', + channel: '/meta/handshake' + }; + + var oTransport = function() + { + this._bXD = + (($.comet._sUrl.substring(0,4) == 'http') && ($.comet._sUrl.substr(7,location.href.length).replace(/\/.*/, '') != location.host)) + ? + true + :false; + + this.connectionType = (this._bXD) ? 'callback-polling' : 'long-polling'; + + this.startup = function(oReturn) + { + if(this._comet._bConnected) return; + this.tunnelInit(); + }; + + this.tunnelInit = function() + { + var msgConnect = + { + channel: '/meta/connect', + clientId: $.comet.clientId, + id: String($.comet._nNextId++), + connectionType: $.comet._oTransport.connectionType + }; + + this.openTunnel(msgConnect); + }; + + this.openTunnel = function(oMsg) + { + $.comet._bPolling = true; + + this._send($.comet._sUrl, oMsg, function(sReturn) + { + var oReturn = (typeof sReturn != "object") ? (eval('(' + sReturn + ')')) : sReturn; + $.comet._bPolling = false; + $.comet.deliver(oReturn); + $.comet._oTransport.closeTunnel(); + }); + }; + + this.closeTunnel = function() + { + if(!$.comet._bInitialized) return; + + if($.comet._advice) + { + if($.comet._advice.reconnect == 'none') return; + + if($.comet._advice.interval > 0) + { + setTimeout($.comet._oTransport._connect, $.comet._advice.interval); + } + else + { + $.comet._oTransport._connect(); + } + } + else + { + $.comet._oTransport._connect(); + } + }; + + this._connect = function() + { + if(!$.comet._bInitialized) return; + + if($.comet._bPolling) return; + + if($.comet._advice && $.comet._advice.reconnect == 'handshake') + { + $.comet._bConnected = false; + $.comet.init($.comet._sUrl); + } + else if($.comet._bConnected) + { + var msgConnect = + { + //jsonp: 'test', + clientId: $.comet.clientId, + id: String($.comet._nNextId++), + channel: '/meta/connect', + connectionType: $.comet._oTransport.connectionType + }; + $.comet._oTransport.openTunnel(msgConnect); + } + }; + + this._send = function(sUrl, oMsg, fCallback) { + //default callback will check advice, deliver messages, and reconnect + var fCallback = (fCallback) ? fCallback : function(sReturn) + { + var oReturn = (typeof sReturn != "object") ? (eval('(' + sReturn + ')')) : sReturn; + + $.comet.deliver(oReturn); + + if($.comet._advice) + { + if($.comet._advice.reconnect == 'none') + return; + + if($.comet._advice.interval > 0) + { + setTimeout($.comet._oTransport._connect, $.comet._advice.interval); + } + else + { + $.comet._oTransport._connect(); + } + } + else + { + $.comet._oTransport._connect(); + } + }; + + //regular AJAX for same domain calls + if((!this._bXD) && (this.connectionType == 'long-polling')) + { + this._pollRequest = $.ajax({ + url: sUrl, + type: 'post', + beforeSend: function(oXhr) { oXhr.setRequestHeader('Connection', 'Keep-Alive'); }, + data: { message: JSON.stringify(oMsg) }, + success: fCallback + }); + } + else // JSONP callback for cross domain + { + this._pollRequest = $.ajax({ + url: sUrl, + dataType: 'jsonp', + jsonp: 'jsonp', + beforeSend: function(oXhr) { oXhr.setRequestHeader('Connection', 'Keep-Alive'); }, + data: + { + message: JSON.stringify($.extend(oMsg,{connectionType: 'callback-polling' })) + }, + success: fCallback + }); + } + } + }; + + $.comet = new function() + { + this.CONNECTED = 'CONNECTED'; + this.CONNECTING = 'CONNECTING'; + this.DISCONNECTED = 'DISCONNECTED'; + this.DISCONNECTING = 'DISCONNECTING'; + + this._aMessageQueue = []; + this._aSubscriptions = []; + this._aSubscriptionCallbacks = []; + this._bInitialized = false; + this._bConnected = false; + this._nBatch = 0; + this._nNextId = 0; + // just define the transport, do not assign it yet. + this._oTransport = ''; //oTransport; + this._sUrl = ''; + + this.supportedConectionTypes = [ 'long-polling', 'callback-polling' ]; + + this.clientId = ''; + + this._bTrigger = true; // this sends $.event.trigger(channel, data) + + this.init = function(sUrl) + { + this._sUrl = (sUrl) ? sUrl : '/cometd'; + + this._oTransport = new oTransport(); + + this._aMessageQueue = []; + this._aSubscriptions = []; + this._bInitialized = true; + this.startBatch(); + + var oMsg = $.extend(msgHandshake, {id: String(this._nNextId++)}); + + this._oTransport._send(this._sUrl, oMsg, $.comet._finishInit); + }; + + this._finishInit = function(sReturn) + { + var oReturn = (typeof sReturn != "object") ? (eval('(' + sReturn + ')')[0]) : sReturn[0]; + + if(oReturn.advice) + $.comet._advice = oReturn.advice; + + var bSuccess = (oReturn.successful) ? oReturn.successful : false; + // do version check + + if(bSuccess) + { + // pick transport ? + // ...... + + $.comet._oTransport._comet = $.comet; + $.comet._oTransport.version = $.comet.version; + + $.comet.clientId = oReturn.clientId; + $.comet._oTransport.startup(oReturn); + $.comet.endBatch(); + } + }; + + this._sendMessage = function(oMsg) + { + if($.comet._nBatch <= 0) + { + if(oMsg.length > 0) + for(var i in oMsg) + { + oMsg[i].clientId = String($.comet.clientId); + oMsg[i].id = String($.comet._nNextId++); + } + else + { + oMsg.clientId = String($.comet.clientId); + oMsg.id = String($.comet._nNextId++); + } + + $.comet._oTransport._send($.comet._sUrl, oMsg); + } + else + { + $.comet._aMessageQueue.push(oMsg); + } + }; + + + this.startBatch = function() { this._nBatch++ }; + this.endBatch = function() { + if(--this._nBatch <= 0) + { + this._nBatch = 0; + if(this._aMessageQueue.length > 0) + { + this._sendMessage(this._aMessageQueue); + this._aMessageQueue = []; + } + } + }; + + this.subscribe = function(sSubscription, fCallback) + { + // if this topic has not been subscribed to yet, send the message now + if(!this._aSubscriptions[sSubscription]) + { + this._aSubscriptions.push(sSubscription) + + if (fCallback) { + this._aSubscriptionCallbacks[sSubscription] = fCallback; + } + + this._sendMessage({ channel: '/meta/subscribe', subscription: sSubscription }); + } + + //$.event.add(window, sSubscription, fCallback); + }; + + this.unsubscribe = function(sSubscription) { + $.comet._sendMessage({ channel: '/meta/unsubscribe', subscription: sSubscription }); + }; + + this.publish = function(sChannel, oData) + { + $.comet._sendMessage({channel: sChannel, data: oData}); + }; + + this.deliver = function(sReturn) + { + var oReturn = sReturn;//eval(sReturn); + + $(oReturn).each(function() + { + $.comet._deliver(this); + }); + }; + + this.disconnect = function() + { + $($.comet._aSubscriptions).each(function(i) + { + $.comet.unsubscribe($.comet._aSubscriptions[i]); + }); + + $.comet._sendMessage({channel:'/meta/disconnect'}); + + $.comet._bInitialized = false; + } + + this._deliver = function(oMsg,oData) + { + if(oMsg.advice) + { + $.comet._advice = oMsg.advice; + } + + switch(oMsg.channel) + { + case '/meta/connect': + if(oMsg.successful && !$.comet._bConnected) + { + $.comet._bConnected = $.comet._bInitialized; + $.comet.endBatch(); + /* + $.comet._sendMessage(msgConnect); + */ + } + else + {} + //$.comet._bConnected = false; + break; + + // add in subscription handling stuff + case '/meta/subscribe': + if(!oMsg.successful) + { + $.comet._oTransport._cancelConnect(); + return; + } + break; + + case '/meta/unsubscribe': + if(!oMsg.successful) + { + $.comet._oTransport._cancelConnect(); + return; + } + break; + + } + + if(oMsg.data) + { + if($.comet._bTrigger) + { + $.event.trigger(oMsg.channel, [oMsg]); + } + + var cb = $.comet._aSubscriptionCallbacks[oMsg.channel]; + if (cb) { + cb(oMsg); + } + } + }; +}; + +})(jQuery); diff --git a/plugins/Comet/updatetimeline.js b/plugins/Comet/updatetimeline.js new file mode 100644 index 000000000..f4da1f47c --- /dev/null +++ b/plugins/Comet/updatetimeline.js @@ -0,0 +1,3 @@ +// update the local timeline from a Comet server +// + -- cgit v1.2.3-54-g00ecf From 056d0a2555bb6783a2bb4632d2c6ad9f52dde5ec Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 25 Apr 2009 14:20:57 -0400 Subject: remove unused duplicate file --- plugins/Comet/bayeux.class.inc.phps | 123 ------------------------------------ 1 file changed, 123 deletions(-) delete mode 100644 plugins/Comet/bayeux.class.inc.phps diff --git a/plugins/Comet/bayeux.class.inc.phps b/plugins/Comet/bayeux.class.inc.phps deleted file mode 100644 index ea004a453..000000000 --- a/plugins/Comet/bayeux.class.inc.phps +++ /dev/null @@ -1,123 +0,0 @@ - http://morglog.alleycatracing.com - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -class Bayeux - { - private $oCurl = ''; - private $nNextId = 0; - - public $sUrl = ''; - - function __construct($sUrl) - { - $this->sUrl = $sUrl; - - $this->oCurl = curl_init(); - - $aHeaders = array(); - $aHeaders[] = 'Connection: Keep-Alive'; - - curl_setopt($this->oCurl, CURLOPT_URL, $sUrl); - curl_setopt($this->oCurl, CURLOPT_HTTPHEADER, $aHeaders); - curl_setopt($this->oCurl, CURLOPT_HEADER, 0); - curl_setopt($this->oCurl, CURLOPT_POST, 1); - curl_setopt($this->oCurl, CURLOPT_RETURNTRANSFER,1); - - $this->handShake(); - } - - function __destruct() - { - $this->disconnect(); - } - - function handShake() - { - $msgHandshake = array(); - $msgHandshake['channel'] = '/meta/handshake'; - $msgHandshake['version'] = "1.0"; - $msgHandshake['minimumVersion'] = "0.9"; - $msgHandshake['id'] = $this->nNextId++; - - curl_setopt($this->oCurl, CURLOPT_POSTFIELDS, "message=".urlencode(str_replace('\\', '', json_encode(array($msgHandshake))))); - - $data = curl_exec($this->oCurl); - - if(curl_errno($this->oCurl)) - die("Error: " . curl_error($this->oCurl)); - - $oReturn = json_decode($data); - $oReturn = $oReturn[0]; - - $bSuccessful = ($oReturn->successful) ? true : false; - - if($bSuccessful) - { - $this->clientId = $oReturn->clientId; - - $this->connect(); - } - } - - public function connect() - { - $aMsg['channel'] = '/meta/connect'; - $aMsg['id'] = $this->nNextId++; - $aMsg['clientId'] = $this->clientId; - $aMsg['connectionType'] = 'long-polling'; - - curl_setopt($this->oCurl, CURLOPT_POSTFIELDS, "message=".urlencode(str_replace('\\', '', json_encode(array($aMsg))))); - - $data = curl_exec($this->oCurl); - } - - function disconnect() - { - $msgHandshake = array(); - $msgHandshake['channel'] = '/meta/disconnect'; - $msgHandshake['id'] = $this->nNextId++; - $msgHandshake['clientId'] = $this->clientId; - - curl_setopt($this->oCurl, CURLOPT_POSTFIELDS, "message=".urlencode(str_replace('\\', '', json_encode(array($msgHandshake))))); - - curl_exec($this->oCurl); - } - - public function publish($sChannel, $oData) - { - if(!$sChannel || !$oData) - return; - - $aMsg = array(); - - $aMsg['channel'] = $sChannel; - $aMsg['id'] = $this->nNextId++; - $aMsg['data'] = $oData; - $aMsg['clientId'] = $this->clientId; - - curl_setopt($this->oCurl, CURLOPT_POSTFIELDS, "message=".urlencode(str_replace('\\', '', json_encode(array($aMsg))))); - - $data = curl_exec($this->oCurl); -// var_dump($data); - } - } -- cgit v1.2.3-54-g00ecf From 262dbeac787ad3aecb28c470484eb3fc8d036d93 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 26 Apr 2009 12:06:50 -0400 Subject: Some updates for testing Comet --- plugins/Comet/bayeux.class.inc.php | 2 - plugins/Comet/jquery.comet.js | 1814 ++++++++++++++++++++++++++++-------- plugins/Comet/updatetimeline.js | 27 + 3 files changed, 1478 insertions(+), 365 deletions(-) diff --git a/plugins/Comet/bayeux.class.inc.php b/plugins/Comet/bayeux.class.inc.php index 602a7b644..785d3e393 100644 --- a/plugins/Comet/bayeux.class.inc.php +++ b/plugins/Comet/bayeux.class.inc.php @@ -69,8 +69,6 @@ class Bayeux $oReturn = json_decode($data); - common_debug(print_r($oReturn, true)); - if (is_array($oReturn)) { $oReturn = $oReturn[0]; } diff --git a/plugins/Comet/jquery.comet.js b/plugins/Comet/jquery.comet.js index 2124e882c..6de437fa8 100644 --- a/plugins/Comet/jquery.comet.js +++ b/plugins/Comet/jquery.comet.js @@ -1,363 +1,1451 @@ -(function($) -{ - var msgHandshake = - { - version: '1.0', - minimumVersion: '0.9', - channel: '/meta/handshake' - }; - - var oTransport = function() - { - this._bXD = - (($.comet._sUrl.substring(0,4) == 'http') && ($.comet._sUrl.substr(7,location.href.length).replace(/\/.*/, '') != location.host)) - ? - true - :false; - - this.connectionType = (this._bXD) ? 'callback-polling' : 'long-polling'; - - this.startup = function(oReturn) - { - if(this._comet._bConnected) return; - this.tunnelInit(); - }; - - this.tunnelInit = function() - { - var msgConnect = - { - channel: '/meta/connect', - clientId: $.comet.clientId, - id: String($.comet._nNextId++), - connectionType: $.comet._oTransport.connectionType - }; - - this.openTunnel(msgConnect); - }; - - this.openTunnel = function(oMsg) - { - $.comet._bPolling = true; - - this._send($.comet._sUrl, oMsg, function(sReturn) - { - var oReturn = (typeof sReturn != "object") ? (eval('(' + sReturn + ')')) : sReturn; - $.comet._bPolling = false; - $.comet.deliver(oReturn); - $.comet._oTransport.closeTunnel(); - }); - }; - - this.closeTunnel = function() - { - if(!$.comet._bInitialized) return; - - if($.comet._advice) - { - if($.comet._advice.reconnect == 'none') return; - - if($.comet._advice.interval > 0) - { - setTimeout($.comet._oTransport._connect, $.comet._advice.interval); - } - else - { - $.comet._oTransport._connect(); - } - } - else - { - $.comet._oTransport._connect(); - } - }; - - this._connect = function() - { - if(!$.comet._bInitialized) return; - - if($.comet._bPolling) return; - - if($.comet._advice && $.comet._advice.reconnect == 'handshake') - { - $.comet._bConnected = false; - $.comet.init($.comet._sUrl); - } - else if($.comet._bConnected) - { - var msgConnect = - { - //jsonp: 'test', - clientId: $.comet.clientId, - id: String($.comet._nNextId++), - channel: '/meta/connect', - connectionType: $.comet._oTransport.connectionType - }; - $.comet._oTransport.openTunnel(msgConnect); - } - }; - - this._send = function(sUrl, oMsg, fCallback) { - //default callback will check advice, deliver messages, and reconnect - var fCallback = (fCallback) ? fCallback : function(sReturn) - { - var oReturn = (typeof sReturn != "object") ? (eval('(' + sReturn + ')')) : sReturn; - - $.comet.deliver(oReturn); - - if($.comet._advice) - { - if($.comet._advice.reconnect == 'none') - return; - - if($.comet._advice.interval > 0) - { - setTimeout($.comet._oTransport._connect, $.comet._advice.interval); - } - else - { - $.comet._oTransport._connect(); - } - } - else - { - $.comet._oTransport._connect(); - } - }; - - //regular AJAX for same domain calls - if((!this._bXD) && (this.connectionType == 'long-polling')) - { - this._pollRequest = $.ajax({ - url: sUrl, - type: 'post', - beforeSend: function(oXhr) { oXhr.setRequestHeader('Connection', 'Keep-Alive'); }, - data: { message: JSON.stringify(oMsg) }, - success: fCallback - }); - } - else // JSONP callback for cross domain - { - this._pollRequest = $.ajax({ - url: sUrl, - dataType: 'jsonp', - jsonp: 'jsonp', - beforeSend: function(oXhr) { oXhr.setRequestHeader('Connection', 'Keep-Alive'); }, - data: - { - message: JSON.stringify($.extend(oMsg,{connectionType: 'callback-polling' })) - }, - success: fCallback - }); - } - } - }; - - $.comet = new function() - { - this.CONNECTED = 'CONNECTED'; - this.CONNECTING = 'CONNECTING'; - this.DISCONNECTED = 'DISCONNECTED'; - this.DISCONNECTING = 'DISCONNECTING'; - - this._aMessageQueue = []; - this._aSubscriptions = []; - this._aSubscriptionCallbacks = []; - this._bInitialized = false; - this._bConnected = false; - this._nBatch = 0; - this._nNextId = 0; - // just define the transport, do not assign it yet. - this._oTransport = ''; //oTransport; - this._sUrl = ''; - - this.supportedConectionTypes = [ 'long-polling', 'callback-polling' ]; - - this.clientId = ''; - - this._bTrigger = true; // this sends $.event.trigger(channel, data) - - this.init = function(sUrl) - { - this._sUrl = (sUrl) ? sUrl : '/cometd'; - - this._oTransport = new oTransport(); - - this._aMessageQueue = []; - this._aSubscriptions = []; - this._bInitialized = true; - this.startBatch(); - - var oMsg = $.extend(msgHandshake, {id: String(this._nNextId++)}); - - this._oTransport._send(this._sUrl, oMsg, $.comet._finishInit); - }; - - this._finishInit = function(sReturn) - { - var oReturn = (typeof sReturn != "object") ? (eval('(' + sReturn + ')')[0]) : sReturn[0]; - - if(oReturn.advice) - $.comet._advice = oReturn.advice; - - var bSuccess = (oReturn.successful) ? oReturn.successful : false; - // do version check - - if(bSuccess) - { - // pick transport ? - // ...... - - $.comet._oTransport._comet = $.comet; - $.comet._oTransport.version = $.comet.version; - - $.comet.clientId = oReturn.clientId; - $.comet._oTransport.startup(oReturn); - $.comet.endBatch(); - } - }; - - this._sendMessage = function(oMsg) - { - if($.comet._nBatch <= 0) - { - if(oMsg.length > 0) - for(var i in oMsg) - { - oMsg[i].clientId = String($.comet.clientId); - oMsg[i].id = String($.comet._nNextId++); - } - else - { - oMsg.clientId = String($.comet.clientId); - oMsg.id = String($.comet._nNextId++); - } - - $.comet._oTransport._send($.comet._sUrl, oMsg); - } - else - { - $.comet._aMessageQueue.push(oMsg); - } - }; - - - this.startBatch = function() { this._nBatch++ }; - this.endBatch = function() { - if(--this._nBatch <= 0) - { - this._nBatch = 0; - if(this._aMessageQueue.length > 0) - { - this._sendMessage(this._aMessageQueue); - this._aMessageQueue = []; - } - } - }; - - this.subscribe = function(sSubscription, fCallback) - { - // if this topic has not been subscribed to yet, send the message now - if(!this._aSubscriptions[sSubscription]) - { - this._aSubscriptions.push(sSubscription) - - if (fCallback) { - this._aSubscriptionCallbacks[sSubscription] = fCallback; - } - - this._sendMessage({ channel: '/meta/subscribe', subscription: sSubscription }); - } - - //$.event.add(window, sSubscription, fCallback); - }; - - this.unsubscribe = function(sSubscription) { - $.comet._sendMessage({ channel: '/meta/unsubscribe', subscription: sSubscription }); - }; - - this.publish = function(sChannel, oData) - { - $.comet._sendMessage({channel: sChannel, data: oData}); - }; - - this.deliver = function(sReturn) - { - var oReturn = sReturn;//eval(sReturn); - - $(oReturn).each(function() - { - $.comet._deliver(this); - }); - }; - - this.disconnect = function() - { - $($.comet._aSubscriptions).each(function(i) - { - $.comet.unsubscribe($.comet._aSubscriptions[i]); - }); - - $.comet._sendMessage({channel:'/meta/disconnect'}); - - $.comet._bInitialized = false; - } - - this._deliver = function(oMsg,oData) - { - if(oMsg.advice) - { - $.comet._advice = oMsg.advice; - } - - switch(oMsg.channel) - { - case '/meta/connect': - if(oMsg.successful && !$.comet._bConnected) - { - $.comet._bConnected = $.comet._bInitialized; - $.comet.endBatch(); - /* - $.comet._sendMessage(msgConnect); - */ - } - else - {} - //$.comet._bConnected = false; - break; - - // add in subscription handling stuff - case '/meta/subscribe': - if(!oMsg.successful) - { - $.comet._oTransport._cancelConnect(); - return; - } - break; - - case '/meta/unsubscribe': - if(!oMsg.successful) - { - $.comet._oTransport._cancelConnect(); - return; - } - break; - - } - - if(oMsg.data) - { - if($.comet._bTrigger) - { - $.event.trigger(oMsg.channel, [oMsg]); - } - - var cb = $.comet._aSubscriptionCallbacks[oMsg.channel]; - if (cb) { - cb(oMsg); - } - } - }; -}; - -})(jQuery); +/** + * Copyright 2008 Mort Bay Consulting Pty. Ltd. + * Dual licensed under the Apache License 2.0 and the MIT license. + * ---------------------------------------------------------------------------- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http: *www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---------------------------------------------------------------------------- + * Licensed under the MIT license; + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * ---------------------------------------------------------------------------- + * $Revision$ $Date$ + */ +(function($) +{ + /** + * The constructor for a Comet object. + * There is a default Comet instance already created at the variable $.cometd, + * and hence that can be used to start a comet conversation with a server. + * In the rare case a page needs more than one comet conversation, a new instance can be + * created via: + *
+     * var url2 = ...;
+     * var cometd2 = new $.Cometd();
+     * cometd2.init(url2);
+     * 
+ */ + $.Cometd = function(name) + { + var _name = name || 'default'; + var _logPriorities = { debug: 1, info: 2, warn: 3, error: 4 }; + var _logLevel = 'info'; + var _url; + var _xd = false; + var _transport; + var _status = 'disconnected'; + var _messageId = 0; + var _clientId = null; + var _batch = 0; + var _messageQueue = []; + var _listeners = {}; + var _backoff = 0; + var _backoffIncrement = 1000; + var _maxBackoff = 60000; + var _scheduledSend = null; + var _extensions = []; + var _advice = {}; + var _handshakeProps; + + /** + * Returns the name assigned to this Comet object, or the string 'default' + * if no name has been explicitely passed as parameter to the constructor. + */ + this.getName = function() + { + return _name; + }; + + /** + * Configures the initial comet communication with the comet server. + * @param cometURL the URL of the comet server + */ + this.configure = function(cometURL) + { + _configure(cometURL); + }; + + function _configure(cometURL) + { + _url = cometURL; + _debug('Initializing comet with url: {}', _url); + + // Check immediately if we're cross domain + // If cross domain, the handshake must not send the long polling transport type + var urlParts = /(^https?:)?(\/\/(([^:\/\?#]+)(:(\d+))?))?([^\?#]*)/.exec(cometURL); + if (urlParts[3]) _xd = urlParts[3] != location.host; + + // Temporary setup a transport to send the initial handshake + // The transport may be changed as a result of handshake + if (_xd) + _transport = newCallbackPollingTransport(); + else + _transport = newLongPollingTransport(); + _debug('Initial transport is {}', _transport.getType()); + }; + + /** + * Configures and establishes the comet communication with the comet server + * via a handshake and a subsequent connect. + * @param cometURL the URL of the comet server + * @param handshakeProps an object to be merged with the handshake message + * @see #configure(cometURL) + * @see #handshake(handshakeProps) + */ + this.init = function(cometURL, handshakeProps) + { + _configure(cometURL); + _handshake(handshakeProps); + }; + + /** + * Establishes the comet communication with the comet server + * via a handshake and a subsequent connect. + * @param handshakeProps an object to be merged with the handshake message + */ + this.handshake = function(handshakeProps) + { + _handshake(handshakeProps); + }; + + /** + * Disconnects from the comet server. + * @param disconnectProps an object to be merged with the disconnect message + */ + this.disconnect = function(disconnectProps) + { + var bayeuxMessage = { + channel: '/meta/disconnect' + }; + var message = $.extend({}, disconnectProps, bayeuxMessage); + // Deliver immediately + // The handshake and connect mechanism make use of startBatch(), and in case + // of a failed handshake the disconnect would not be delivered if using _send(). + _setStatus('disconnecting'); + _deliver([message], false); + }; + + /** + * Marks the start of a batch of application messages to be sent to the server + * in a single request, obtaining a single response containing (possibly) many + * application reply messages. + * Messages are held in a queue and not sent until {@link #endBatch()} is called. + * If startBatch() is called multiple times, then an equal number of endBatch() + * calls must be made to close and send the batch of messages. + * @see #endBatch() + */ + this.startBatch = function() + { + _startBatch(); + }; + + /** + * Marks the end of a batch of application messages to be sent to the server + * in a single request. + * @see #startBatch() + */ + this.endBatch = function() + { + _endBatch(true); + }; + + /** + * Subscribes to the given channel, performing the given callback in the given scope + * when a message for the channel arrives. + * @param channel the channel to subscribe to + * @param scope the scope of the callback + * @param callback the callback to call when a message is delivered to the channel + * @param subscribeProps an object to be merged with the subscribe message + * @return the subscription handle to be passed to {@link #unsubscribe(object)} + */ + this.subscribe = function(channel, scope, callback, subscribeProps) + { + var subscription = this.addListener(channel, scope, callback); + + // Send the subscription message after the subscription registration to avoid + // races where the server would deliver a message to the subscribers, but here + // on the client the subscription has not been added yet to the data structures + var bayeuxMessage = { + channel: '/meta/subscribe', + subscription: channel + }; + var message = $.extend({}, subscribeProps, bayeuxMessage); + _send(message); + + return subscription; + }; + + /** + * Unsubscribes the subscription obtained with a call to {@link #subscribe(string, object, function)}. + * @param subscription the subscription to unsubscribe. + */ + this.unsubscribe = function(subscription, unsubscribeProps) + { + // Remove the local listener before sending the message + // This ensures that if the server fails, this client does not get notifications + this.removeListener(subscription); + var bayeuxMessage = { + channel: '/meta/unsubscribe', + subscription: subscription[0] + }; + var message = $.extend({}, unsubscribeProps, bayeuxMessage); + _send(message); + }; + + /** + * Publishes a message on the given channel, containing the given content. + * @param channel the channel to publish the message to + * @param content the content of the message + * @param publishProps an object to be merged with the publish message + */ + this.publish = function(channel, content, publishProps) + { + var bayeuxMessage = { + channel: channel, + data: content + }; + var message = $.extend({}, publishProps, bayeuxMessage); + _send(message); + }; + + /** + * Adds a listener for bayeux messages, performing the given callback in the given scope + * when a message for the given channel arrives. + * @param channel the channel the listener is interested to + * @param scope the scope of the callback + * @param callback the callback to call when a message is delivered to the channel + * @returns the subscription handle to be passed to {@link #removeListener(object)} + * @see #removeListener(object) + */ + this.addListener = function(channel, scope, callback) + { + // The data structure is a map, where each subscription + // holds the callback to be called and its scope. + + // Normalize arguments + if (!callback) + { + callback = scope; + scope = undefined; + } + + var subscription = { + scope: scope, + callback: callback + }; + + var subscriptions = _listeners[channel]; + if (!subscriptions) + { + subscriptions = []; + _listeners[channel] = subscriptions; + } + // Pushing onto an array appends at the end and returns the id associated with the element increased by 1. + // Note that if: + // a.push('a'); var hb=a.push('b'); delete a[hb-1]; var hc=a.push('c'); + // then: + // hc==3, a.join()=='a',,'c', a.length==3 + var subscriptionIndex = subscriptions.push(subscription) - 1; + _debug('Added listener: channel \'{}\', callback \'{}\', index {}', channel, callback.name, subscriptionIndex); + + // The subscription to allow removal of the listener is made of the channel and the index + return [channel, subscriptionIndex]; + }; + + /** + * Removes the subscription obtained with a call to {@link #addListener(string, object, function)}. + * @param subscription the subscription to unsubscribe. + */ + this.removeListener = function(subscription) + { + var subscriptions = _listeners[subscription[0]]; + if (subscriptions) + { + delete subscriptions[subscription[1]]; + _debug('Removed listener: channel \'{}\', index {}', subscription[0], subscription[1]); + } + }; + + /** + * Removes all listeners registered with {@link #addListener(channel, scope, callback)} or + * {@link #subscribe(channel, scope, callback)}. + */ + this.clearListeners = function() + { + _listeners = {}; + }; + + /** + * Returns a string representing the status of the bayeux communication with the comet server. + */ + this.getStatus = function() + { + return _status; + }; + + /** + * Sets the backoff period used to increase the backoff time when retrying an unsuccessful or failed message. + * Default value is 1 second, which means if there is a persistent failure the retries will happen + * after 1 second, then after 2 seconds, then after 3 seconds, etc. So for example with 15 seconds of + * elapsed time, there will be 5 retries (at 1, 3, 6, 10 and 15 seconds elapsed). + * @param period the backoff period to set + * @see #getBackoffIncrement() + */ + this.setBackoffIncrement = function(period) + { + _backoffIncrement = period; + }; + + /** + * Returns the backoff period used to increase the backoff time when retrying an unsuccessful or failed message. + * @see #setBackoffIncrement(period) + */ + this.getBackoffIncrement = function() + { + return _backoffIncrement; + }; + + /** + * Returns the backoff period to wait before retrying an unsuccessful or failed message. + */ + this.getBackoffPeriod = function() + { + return _backoff; + }; + + /** + * Sets the log level for console logging. + * Valid values are the strings 'error', 'warn', 'info' and 'debug', from + * less verbose to more verbose. + * @param level the log level string + */ + this.setLogLevel = function(level) + { + _logLevel = level; + }; + + /** + * Registers an extension whose callbacks are called for every incoming message + * (that comes from the server to this client implementation) and for every + * outgoing message (that originates from this client implementation for the + * server). + * The format of the extension object is the following: + *
+         * {
+         *     incoming: function(message) { ... },
+         *     outgoing: function(message) { ... }
+         * }
+         * Both properties are optional, but if they are present they will be called
+         * respectively for each incoming message and for each outgoing message.
+         * 
+ * @param name the name of the extension + * @param extension the extension to register + * @return true if the extension was registered, false otherwise + * @see #unregisterExtension(name) + */ + this.registerExtension = function(name, extension) + { + var existing = false; + for (var i = 0; i < _extensions.length; ++i) + { + var existingExtension = _extensions[i]; + if (existingExtension.name == name) + { + existing = true; + return false; + } + } + if (!existing) + { + _extensions.push({ + name: name, + extension: extension + }); + _debug('Registered extension \'{}\'', name); + return true; + } + else + { + _info('Could not register extension with name \'{}\': another extension with the same name already exists'); + return false; + } + }; + + /** + * Unregister an extension previously registered with + * {@link #registerExtension(name, extension)}. + * @param name the name of the extension to unregister. + * @return true if the extension was unregistered, false otherwise + */ + this.unregisterExtension = function(name) + { + var unregistered = false; + $.each(_extensions, function(index, extension) + { + if (extension.name == name) + { + _extensions.splice(index, 1); + unregistered = true; + _debug('Unregistered extension \'{}\'', name); + return false; + } + }); + return unregistered; + }; + + /** + * Starts a the batch of messages to be sent in a single request. + * @see _endBatch(deliverMessages) + */ + function _startBatch() + { + ++_batch; + }; + + /** + * Ends the batch of messages to be sent in a single request, + * optionally delivering messages present in the message queue depending + * on the given argument. + * @param deliverMessages whether to deliver the messages in the queue or not + * @see _startBatch() + */ + function _endBatch(deliverMessages) + { + --_batch; + if (_batch < 0) _batch = 0; + if (deliverMessages && _batch == 0 && !_isDisconnected()) + { + var messages = _messageQueue; + _messageQueue = []; + if (messages.length > 0) _deliver(messages, false); + } + }; + + function _nextMessageId() + { + return ++_messageId; + }; + + /** + * Converts the given response into an array of bayeux messages + * @param response the response to convert + * @return an array of bayeux messages obtained by converting the response + */ + function _convertToMessages(response) + { + if (response === undefined) return []; + if (response instanceof Array) return response; + if (response instanceof String || typeof response == 'string') return eval('(' + response + ')'); + if (response instanceof Object) return [response]; + throw 'Conversion Error ' + response + ', typeof ' + (typeof response); + }; + + function _setStatus(newStatus) + { + _debug('{} -> {}', _status, newStatus); + _status = newStatus; + }; + + function _isDisconnected() + { + return _status == 'disconnecting' || _status == 'disconnected'; + }; + + /** + * Sends the initial handshake message + */ + function _handshake(handshakeProps) + { + _debug('Starting handshake'); + _clientId = null; + + // Start a batch. + // This is needed because handshake and connect are async. + // It may happen that the application calls init() then subscribe() + // and the subscribe message is sent before the connect message, if + // the subscribe message is not held until the connect message is sent. + // So here we start a batch to hold temporarly any message until + // the connection is fully established. + _batch = 0; + _startBatch(); + + // Save the original properties provided by the user + // Deep copy to avoid the user to be able to change them later + _handshakeProps = $.extend(true, {}, handshakeProps); + + var bayeuxMessage = { + version: '1.0', + minimumVersion: '0.9', + channel: '/meta/handshake', + supportedConnectionTypes: _xd ? ['callback-polling'] : ['long-polling', 'callback-polling'] + }; + // Do not allow the user to mess with the required properties, + // so merge first the user properties and *then* the bayeux message + var message = $.extend({}, handshakeProps, bayeuxMessage); + + // We started a batch to hold the application messages, + // so here we must bypass it and deliver immediately. + _setStatus('handshaking'); + _deliver([message], false); + }; + + function _findTransport(handshakeResponse) + { + var transportTypes = handshakeResponse.supportedConnectionTypes; + if (_xd) + { + // If we are cross domain, check if the server supports it, that's the only option + if ($.inArray('callback-polling', transportTypes) >= 0) return _transport; + } + else + { + // Check if we can keep long-polling + if ($.inArray('long-polling', transportTypes) >= 0) return _transport; + + // The server does not support long-polling + if ($.inArray('callback-polling', transportTypes) >= 0) return newCallbackPollingTransport(); + } + return null; + }; + + function _delayedHandshake() + { + _setStatus('handshaking'); + _delayedSend(function() + { + _handshake(_handshakeProps); + }); + }; + + function _delayedConnect() + { + _setStatus('connecting'); + _delayedSend(function() + { + _connect(); + }); + }; + + function _delayedSend(operation) + { + _cancelDelayedSend(); + var delay = _backoff; + _debug("Delayed send: backoff {}, interval {}", _backoff, _advice.interval); + if (_advice.interval && _advice.interval > 0) + delay += _advice.interval; + _scheduledSend = _setTimeout(operation, delay); + }; + + function _cancelDelayedSend() + { + if (_scheduledSend !== null) clearTimeout(_scheduledSend); + _scheduledSend = null; + }; + + function _setTimeout(funktion, delay) + { + return setTimeout(function() + { + try + { + funktion(); + } + catch (x) + { + _debug('Exception during scheduled execution of function \'{}\': {}', funktion.name, x); + } + }, delay); + }; + + /** + * Sends the connect message + */ + function _connect() + { + _debug('Starting connect'); + var message = { + channel: '/meta/connect', + connectionType: _transport.getType() + }; + _setStatus('connecting'); + _deliver([message], true); + _setStatus('connected'); + }; + + function _send(message) + { + if (_batch > 0) + _messageQueue.push(message); + else + _deliver([message], false); + }; + + /** + * Delivers the messages to the comet server + * @param messages the array of messages to send + */ + function _deliver(messages, comet) + { + // We must be sure that the messages have a clientId. + // This is not guaranteed since the handshake may take time to return + // (and hence the clientId is not known yet) and the application + // may create other messages. + $.each(messages, function(index, message) + { + message['id'] = _nextMessageId(); + if (_clientId) message['clientId'] = _clientId; + messages[index] = _applyOutgoingExtensions(message); + }); + + var self = this; + var envelope = { + url: _url, + messages: messages, + onSuccess: function(request, response) + { + try + { + _handleSuccess.call(self, request, response, comet); + } + catch (x) + { + _debug('Exception during execution of success callback: {}', x); + } + }, + onFailure: function(request, reason, exception) + { + try + { + _handleFailure.call(self, request, messages, reason, exception, comet); + } + catch (x) + { + _debug('Exception during execution of failure callback: {}', x); + } + } + }; + _debug('Sending request to {}, message(s): {}', envelope.url, JSON.stringify(envelope.messages)); + _transport.send(envelope, comet); + }; + + function _applyIncomingExtensions(message) + { + for (var i = 0; i < _extensions.length; ++i) + { + var extension = _extensions[i]; + var callback = extension.extension.incoming; + if (callback && typeof callback === 'function') + { + _debug('Calling incoming extension \'{}\', callback \'{}\'', extension.name, callback.name); + message = _applyExtension(extension.name, callback, message) || message; + } + } + return message; + }; + + function _applyOutgoingExtensions(message) + { + for (var i = 0; i < _extensions.length; ++i) + { + var extension = _extensions[i]; + var callback = extension.extension.outgoing; + if (callback && typeof callback === 'function') + { + _debug('Calling outgoing extension \'{}\', callback \'{}\'', extension.name, callback.name); + message = _applyExtension(extension.name, callback, message) || message; + } + } + return message; + }; + + function _applyExtension(name, callback, message) + { + try + { + return callback(message); + } + catch (x) + { + _debug('Exception during execution of extension \'{}\': {}', name, x); + return message; + } + }; + + function _handleSuccess(request, response, comet) + { + var messages = _convertToMessages(response); + _debug('Received response {}', JSON.stringify(messages)); + + // Signal the transport it can deliver other queued requests + _transport.complete(request, true, comet); + + for (var i = 0; i < messages.length; ++i) + { + var message = messages[i]; + message = _applyIncomingExtensions(message); + + if (message.advice) _advice = message.advice; + + var channel = message.channel; + switch (channel) + { + case '/meta/handshake': + _handshakeSuccess(message); + break; + case '/meta/connect': + _connectSuccess(message); + break; + case '/meta/disconnect': + _disconnectSuccess(message); + break; + case '/meta/subscribe': + _subscribeSuccess(message); + break; + case '/meta/unsubscribe': + _unsubscribeSuccess(message); + break; + default: + _messageSuccess(message); + break; + } + } + }; + + function _handleFailure(request, messages, reason, exception, comet) + { + var xhr = request.xhr; + _debug('Request failed, status: {}, reason: {}, exception: {}', xhr && xhr.status, reason, exception); + + // Signal the transport it can deliver other queued requests + _transport.complete(request, false, comet); + + for (var i = 0; i < messages.length; ++i) + { + var message = messages[i]; + var channel = message.channel; + switch (channel) + { + case '/meta/handshake': + _handshakeFailure(xhr, message); + break; + case '/meta/connect': + _connectFailure(xhr, message); + break; + case '/meta/disconnect': + _disconnectFailure(xhr, message); + break; + case '/meta/subscribe': + _subscribeFailure(xhr, message); + break; + case '/meta/unsubscribe': + _unsubscribeFailure(xhr, message); + break; + default: + _messageFailure(xhr, message); + break; + } + } + }; + + function _handshakeSuccess(message) + { + if (message.successful) + { + _debug('Handshake successful'); + // Save clientId, figure out transport, then follow the advice to connect + _clientId = message.clientId; + + var newTransport = _findTransport(message); + if (newTransport === null) + { + throw 'Could not agree on transport with server'; + } + else + { + if (_transport.getType() != newTransport.getType()) + { + _debug('Changing transport from {} to {}', _transport.getType(), newTransport.getType()); + _transport = newTransport; + } + } + + // Notify the listeners + // Here the new transport is in place, as well as the clientId, so + // the listener can perform a publish() if it wants, and the listeners + // are notified before the connect below. + _notifyListeners('/meta/handshake', message); + + var action = _advice.reconnect ? _advice.reconnect : 'retry'; + switch (action) + { + case 'retry': + _delayedConnect(); + break; + default: + break; + } + } + else + { + _debug('Handshake unsuccessful'); + + var retry = !_isDisconnected() && _advice.reconnect != 'none'; + if (!retry) _setStatus('disconnected'); + + _notifyListeners('/meta/handshake', message); + _notifyListeners('/meta/unsuccessful', message); + + // Only try again if we haven't been disconnected and + // the advice permits us to retry the handshake + if (retry) + { + _increaseBackoff(); + _debug('Handshake failure, backing off and retrying in {} ms', _backoff); + _delayedHandshake(); + } + } + }; + + function _handshakeFailure(xhr, message) + { + _debug('Handshake failure'); + + // Notify listeners + var failureMessage = { + successful: false, + failure: true, + channel: '/meta/handshake', + request: message, + xhr: xhr, + advice: { + action: 'retry', + interval: _backoff + } + }; + + var retry = !_isDisconnected() && _advice.reconnect != 'none'; + if (!retry) _setStatus('disconnected'); + + _notifyListeners('/meta/handshake', failureMessage); + _notifyListeners('/meta/unsuccessful', failureMessage); + + // Only try again if we haven't been disconnected and the + // advice permits us to try again + if (retry) + { + _increaseBackoff(); + _debug('Handshake failure, backing off and retrying in {} ms', _backoff); + _delayedHandshake(); + } + }; + + function _connectSuccess(message) + { + var action = _isDisconnected() ? 'none' : (_advice.reconnect ? _advice.reconnect : 'retry'); + if (!_isDisconnected()) _setStatus(action == 'retry' ? 'connecting' : 'disconnecting'); + + if (message.successful) + { + _debug('Connect successful'); + + // End the batch and allow held messages from the application + // to go to the server (see _handshake() where we start the batch). + // The batch is ended before notifying the listeners, so that + // listeners can batch other cometd operations + _endBatch(true); + + // Notify the listeners after the status change but before the next connect + _notifyListeners('/meta/connect', message); + + // Connect was successful. + // Normally, the advice will say "reconnect: 'retry', interval: 0" + // and the server will hold the request, so when a response returns + // we immediately call the server again (long polling) + switch (action) + { + case 'retry': + _resetBackoff(); + _delayedConnect(); + break; + default: + _resetBackoff(); + _setStatus('disconnected'); + break; + } + } + else + { + _debug('Connect unsuccessful'); + + // Notify the listeners after the status change but before the next action + _notifyListeners('/meta/connect', message); + _notifyListeners('/meta/unsuccessful', message); + + // Connect was not successful. + // This may happen when the server crashed, the current clientId + // will be invalid, and the server will ask to handshake again + switch (action) + { + case 'retry': + _increaseBackoff(); + _delayedConnect(); + break; + case 'handshake': + // End the batch but do not deliver the messages until we connect successfully + _endBatch(false); + _resetBackoff(); + _delayedHandshake(); + break; + case 'none': + _resetBackoff(); + _setStatus('disconnected'); + break; + } + } + }; + + function _connectFailure(xhr, message) + { + _debug('Connect failure'); + + // Notify listeners + var failureMessage = { + successful: false, + failure: true, + channel: '/meta/connect', + request: message, + xhr: xhr, + advice: { + action: 'retry', + interval: _backoff + } + }; + _notifyListeners('/meta/connect', failureMessage); + _notifyListeners('/meta/unsuccessful', failureMessage); + + if (!_isDisconnected()) + { + var action = _advice.reconnect ? _advice.reconnect : 'retry'; + switch (action) + { + case 'retry': + _increaseBackoff(); + _debug('Connect failure, backing off and retrying in {} ms', _backoff); + _delayedConnect(); + break; + case 'handshake': + _resetBackoff(); + _delayedHandshake(); + break; + case 'none': + _resetBackoff(); + break; + default: + _debug('Unrecognized reconnect value: {}', action); + break; + } + } + }; + + function _disconnectSuccess(message) + { + if (message.successful) + { + _debug('Disconnect successful'); + _disconnect(false); + _notifyListeners('/meta/disconnect', message); + } + else + { + _debug('Disconnect unsuccessful'); + _disconnect(true); + _notifyListeners('/meta/disconnect', message); + _notifyListeners('/meta/usuccessful', message); + } + }; + + function _disconnect(abort) + { + _cancelDelayedSend(); + if (abort) _transport.abort(); + _clientId = null; + _setStatus('disconnected'); + _batch = 0; + _messageQueue = []; + _resetBackoff(); + }; + + function _disconnectFailure(xhr, message) + { + _debug('Disconnect failure'); + _disconnect(true); + + var failureMessage = { + successful: false, + failure: true, + channel: '/meta/disconnect', + request: message, + xhr: xhr, + advice: { + action: 'none', + interval: 0 + } + }; + _notifyListeners('/meta/disconnect', failureMessage); + _notifyListeners('/meta/unsuccessful', failureMessage); + }; + + function _subscribeSuccess(message) + { + if (message.successful) + { + _debug('Subscribe successful'); + _notifyListeners('/meta/subscribe', message); + } + else + { + _debug('Subscribe unsuccessful'); + _notifyListeners('/meta/subscribe', message); + _notifyListeners('/meta/unsuccessful', message); + } + }; + + function _subscribeFailure(xhr, message) + { + _debug('Subscribe failure'); + + var failureMessage = { + successful: false, + failure: true, + channel: '/meta/subscribe', + request: message, + xhr: xhr, + advice: { + action: 'none', + interval: 0 + } + }; + _notifyListeners('/meta/subscribe', failureMessage); + _notifyListeners('/meta/unsuccessful', failureMessage); + }; + + function _unsubscribeSuccess(message) + { + if (message.successful) + { + _debug('Unsubscribe successful'); + _notifyListeners('/meta/unsubscribe', message); + } + else + { + _debug('Unsubscribe unsuccessful'); + _notifyListeners('/meta/unsubscribe', message); + _notifyListeners('/meta/unsuccessful', message); + } + }; + + function _unsubscribeFailure(xhr, message) + { + _debug('Unsubscribe failure'); + + var failureMessage = { + successful: false, + failure: true, + channel: '/meta/unsubscribe', + request: message, + xhr: xhr, + advice: { + action: 'none', + interval: 0 + } + }; + _notifyListeners('/meta/unsubscribe', failureMessage); + _notifyListeners('/meta/unsuccessful', failureMessage); + }; + + function _messageSuccess(message) + { + if (message.successful === undefined) + { + if (message.data) + { + // It is a plain message, and not a bayeux meta message + _notifyListeners(message.channel, message); + } + else + { + _debug('Unknown message {}', JSON.stringify(message)); + } + } + else + { + if (message.successful) + { + _debug('Publish successful'); + _notifyListeners('/meta/publish', message); + } + else + { + _debug('Publish unsuccessful'); + _notifyListeners('/meta/publish', message); + _notifyListeners('/meta/unsuccessful', message); + } + } + }; + + function _messageFailure(xhr, message) + { + _debug('Publish failure'); + + var failureMessage = { + successful: false, + failure: true, + channel: message.channel, + request: message, + xhr: xhr, + advice: { + action: 'none', + interval: 0 + } + }; + _notifyListeners('/meta/publish', failureMessage); + _notifyListeners('/meta/unsuccessful', failureMessage); + }; + + function _notifyListeners(channel, message) + { + // Notify direct listeners + _notify(channel, message); + + // Notify the globbing listeners + var channelParts = channel.split("/"); + var last = channelParts.length - 1; + for (var i = last; i > 0; --i) + { + var channelPart = channelParts.slice(0, i).join('/') + '/*'; + // We don't want to notify /foo/* if the channel is /foo/bar/baz, + // so we stop at the first non recursive globbing + if (i == last) _notify(channelPart, message); + // Add the recursive globber and notify + channelPart += '*'; + _notify(channelPart, message); + } + }; + + function _notify(channel, message) + { + var subscriptions = _listeners[channel]; + if (subscriptions && subscriptions.length > 0) + { + for (var i = 0; i < subscriptions.length; ++i) + { + var subscription = subscriptions[i]; + // Subscriptions may come and go, so the array may have 'holes' + if (subscription) + { + try + { + _debug('Notifying subscription: channel \'{}\', callback \'{}\'', channel, subscription.callback.name); + subscription.callback.call(subscription.scope, message); + } + catch (x) + { + // Ignore exceptions from callbacks + _warn('Exception during execution of callback \'{}\' on channel \'{}\' for message {}, exception: {}', subscription.callback.name, channel, JSON.stringify(message), x); + } + } + } + } + }; + + function _resetBackoff() + { + _backoff = 0; + }; + + function _increaseBackoff() + { + if (_backoff < _maxBackoff) _backoff += _backoffIncrement; + }; + + var _error = this._error = function(text, args) + { + _log('error', _format.apply(this, arguments)); + }; + + var _warn = this._warn = function(text, args) + { + _log('warn', _format.apply(this, arguments)); + }; + + var _info = this._info = function(text, args) + { + _log('info', _format.apply(this, arguments)); + }; + + var _debug = this._debug = function(text, args) + { + _log('debug', _format.apply(this, arguments)); + }; + + function _log(level, text) + { + var priority = _logPriorities[level]; + var configPriority = _logPriorities[_logLevel]; + if (!configPriority) configPriority = _logPriorities['info']; + if (priority >= configPriority) + { + if (window.console) window.console.log(text); + } + }; + + function _format(text) + { + var braces = /\{\}/g; + var result = ''; + var start = 0; + var count = 0; + while (braces.test(text)) + { + result += text.substr(start, braces.lastIndex - start - 2); + var arg = arguments[++count]; + result += arg !== undefined ? arg : '{}'; + start = braces.lastIndex; + } + result += text.substr(start, text.length - start); + return result; + }; + + function newLongPollingTransport() + { + return $.extend({}, new Transport('long-polling'), new LongPollingTransport()); + }; + + function newCallbackPollingTransport() + { + return $.extend({}, new Transport('callback-polling'), new CallbackPollingTransport()); + }; + + /** + * Base object with the common functionality for transports. + * The key responsibility is to allow at most 2 outstanding requests to the server, + * to avoid that requests are sent behind a long poll. + * To achieve this, we have one reserved request for the long poll, and all other + * requests are serialized one after the other. + */ + var Transport = function(type) + { + var _maxRequests = 2; + var _requestIds = 0; + var _cometRequest = null; + var _requests = []; + var _packets = []; + + this.getType = function() + { + return type; + }; + + this.send = function(packet, comet) + { + if (comet) + _cometSend(this, packet); + else + _send(this, packet); + }; + + function _cometSend(self, packet) + { + if (_cometRequest !== null) throw 'Concurrent comet requests not allowed, request ' + _cometRequest.id + ' not yet completed'; + + var requestId = ++_requestIds; + _debug('Beginning comet request {}', requestId); + + var request = {id: requestId}; + _debug('Delivering comet request {}', requestId); + self.deliver(packet, request); + _cometRequest = request; + }; + + function _send(self, packet) + { + var requestId = ++_requestIds; + _debug('Beginning request {}, {} other requests, {} queued requests', requestId, _requests.length, _packets.length); + + var request = {id: requestId}; + // Consider the comet request which should always be present + if (_requests.length < _maxRequests - 1) + { + _debug('Delivering request {}', requestId); + self.deliver(packet, request); + _requests.push(request); + } + else + { + _packets.push([packet, request]); + _debug('Queued request {}, {} queued requests', requestId, _packets.length); + } + }; + + this.complete = function(request, success, comet) + { + if (comet) + _cometComplete(request); + else + _complete(this, request, success); + }; + + function _cometComplete(request) + { + var requestId = request.id; + if (_cometRequest !== request) throw 'Comet request mismatch, completing request ' + requestId; + + // Reset comet request + _cometRequest = null; + _debug('Ended comet request {}', requestId); + }; + + function _complete(self, request, success) + { + var requestId = request.id; + var index = $.inArray(request, _requests); + // The index can be negative the request has been aborted + if (index >= 0) _requests.splice(index, 1); + _debug('Ended request {}, {} other requests, {} queued requests', requestId, _requests.length, _packets.length); + + if (_packets.length > 0) + { + var packet = _packets.shift(); + if (success) + { + _debug('Dequeueing and sending request {}, {} queued requests', packet[1].id, _packets.length); + _send(self, packet[0]); + } + else + { + _debug('Dequeueing and failing request {}, {} queued requests', packet[1].id, _packets.length); + // Keep the semantic of calling response callbacks asynchronously after the request + setTimeout(function() { packet[0].onFailure(packet[1], 'error'); }, 0); + } + } + }; + + this.abort = function() + { + for (var i = 0; i < _requests.length; ++i) + { + var request = _requests[i]; + _debug('Aborting request {}', request.id); + if (request.xhr) request.xhr.abort(); + } + if (_cometRequest) + { + _debug('Aborting comet request {}', _cometRequest.id); + if (_cometRequest.xhr) _cometRequest.xhr.abort(); + } + _cometRequest = null; + _requests = []; + _packets = []; + }; + }; + + var LongPollingTransport = function() + { + this.deliver = function(packet, request) + { + request.xhr = $.ajax({ + url: packet.url, + type: 'POST', + contentType: 'text/json;charset=UTF-8', + beforeSend: function(xhr) + { + xhr.setRequestHeader('Connection', 'Keep-Alive'); + return true; + }, + data: JSON.stringify(packet.messages), + success: function(response) { packet.onSuccess(request, response); }, + error: function(xhr, reason, exception) { packet.onFailure(request, reason, exception); } + }); + }; + }; + + var CallbackPollingTransport = function() + { + var _maxLength = 2000; + this.deliver = function(packet, request) + { + // Microsoft Internet Explorer has a 2083 URL max length + // We must ensure that we stay within that length + var messages = JSON.stringify(packet.messages); + // Encode the messages because all brackets, quotes, commas, colons, etc + // present in the JSON will be URL encoded, taking many more characters + var urlLength = packet.url.length + encodeURI(messages).length; + _debug('URL length: {}', urlLength); + // Let's stay on the safe side and use 2000 instead of 2083 + // also because we did not count few characters among which + // the parameter name 'message' and the parameter 'jsonp', + // which sum up to about 50 chars + if (urlLength > _maxLength) + { + var x = packet.messages.length > 1 ? + 'Too many bayeux messages in the same batch resulting in message too big ' + + '(' + urlLength + ' bytes, max is ' + _maxLength + ') for transport ' + this.getType() : + 'Bayeux message too big (' + urlLength + ' bytes, max is ' + _maxLength + ') ' + + 'for transport ' + this.getType(); + // Keep the semantic of calling response callbacks asynchronously after the request + _setTimeout(function() { packet.onFailure(request, 'error', x); }, 0); + } + else + { + $.ajax({ + url: packet.url, + type: 'GET', + dataType: 'jsonp', + jsonp: 'jsonp', + beforeSend: function(xhr) + { + xhr.setRequestHeader('Connection', 'Keep-Alive'); + return true; + }, + data: + { + // In callback-polling, the content must be sent via the 'message' parameter + message: messages + }, + success: function(response) { packet.onSuccess(request, response); }, + error: function(xhr, reason, exception) { packet.onFailure(request, reason, exception); } + }); + } + }; + }; + }; + + /** + * The JS object that exposes the comet API to applications + */ + $.cometd = new $.Cometd(); // The default instance + +})(jQuery); diff --git a/plugins/Comet/updatetimeline.js b/plugins/Comet/updatetimeline.js index f4da1f47c..6612b5116 100644 --- a/plugins/Comet/updatetimeline.js +++ b/plugins/Comet/updatetimeline.js @@ -1,3 +1,30 @@ // update the local timeline from a Comet server // +var updater = function() +{ + var _handshook = false; + var _connected = false; + var _cometd; + + return { + init: function() + { + _cometd = $.cometd; // Uses the default Comet object + _cometd.init(_timelineServer); + _cometd.subscribe(_timeline, this, receive); + $(window).unload(leave); + } + } + + function leave() + { + _cometd.disconnect(); + } + + function receive(message) + { + var noticeItem = makeNoticeItem(message.data); + var noticeList = $('ul.notices'); + } +}(); -- cgit v1.2.3-54-g00ecf From 84072aa5cf6124d59a06a7f0a7945c00ee2836da Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 26 Apr 2009 12:13:49 -0400 Subject: run 'set names' after each connection to deal with UTF8 correctly --- classes/Memcached_DataObject.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index 5f71f716b..877bbf2e0 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -227,4 +227,20 @@ class Memcached_DataObject extends DB_DataObject $c->set($ckey, $cached, MEMCACHE_COMPRESSED, $expiry); return new ArrayWrapper($cached); } + + // We overload so that 'SET NAMES "utf8"' is called for + // each connection + + function _connect() + { + global $_DB_DATAOBJECT; + $exists = !empty($this->_database_dsn_md5) && + isset($_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5]); + $result = parent::_connect(); + if (!$exists) { + $DB = &$_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5]; + $DB->query('SET NAMES "utf8"'); + } + return $result; + } } -- cgit v1.2.3-54-g00ecf From a7089de22851060c551c9f43366bc197bddebb07 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 26 Apr 2009 12:13:49 -0400 Subject: run 'set names' after each connection to deal with UTF8 correctly --- classes/Memcached_DataObject.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index 5f71f716b..877bbf2e0 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -227,4 +227,20 @@ class Memcached_DataObject extends DB_DataObject $c->set($ckey, $cached, MEMCACHE_COMPRESSED, $expiry); return new ArrayWrapper($cached); } + + // We overload so that 'SET NAMES "utf8"' is called for + // each connection + + function _connect() + { + global $_DB_DATAOBJECT; + $exists = !empty($this->_database_dsn_md5) && + isset($_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5]); + $result = parent::_connect(); + if (!$exists) { + $DB = &$_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5]; + $DB->query('SET NAMES "utf8"'); + } + return $result; + } } -- cgit v1.2.3-54-g00ecf From 068f6801cc59488bfc50ef399a2a4d22b1b7e9c2 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 26 Apr 2009 12:27:32 -0400 Subject: Revert "run 'set names' after each connection to deal with UTF8 correctly" This reverts commit 84072aa5cf6124d59a06a7f0a7945c00ee2836da. This commit caused grievous harm to old notices on identi.ca. Reverting until we figure out how to convert the old notices. --- classes/Memcached_DataObject.php | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index 877bbf2e0..5f71f716b 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -227,20 +227,4 @@ class Memcached_DataObject extends DB_DataObject $c->set($ckey, $cached, MEMCACHE_COMPRESSED, $expiry); return new ArrayWrapper($cached); } - - // We overload so that 'SET NAMES "utf8"' is called for - // each connection - - function _connect() - { - global $_DB_DATAOBJECT; - $exists = !empty($this->_database_dsn_md5) && - isset($_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5]); - $result = parent::_connect(); - if (!$exists) { - $DB = &$_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5]; - $DB->query('SET NAMES "utf8"'); - } - return $result; - } } -- cgit v1.2.3-54-g00ecf From 86770ccde7914219a0a572ced6dd21fa65566e1d Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 26 Apr 2009 12:27:32 -0400 Subject: Revert "run 'set names' after each connection to deal with UTF8 correctly" This reverts commit 84072aa5cf6124d59a06a7f0a7945c00ee2836da. This commit caused grievous harm to old notices on identi.ca. Reverting until we figure out how to convert the old notices. --- classes/Memcached_DataObject.php | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index 877bbf2e0..5f71f716b 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -227,20 +227,4 @@ class Memcached_DataObject extends DB_DataObject $c->set($ckey, $cached, MEMCACHE_COMPRESSED, $expiry); return new ArrayWrapper($cached); } - - // We overload so that 'SET NAMES "utf8"' is called for - // each connection - - function _connect() - { - global $_DB_DATAOBJECT; - $exists = !empty($this->_database_dsn_md5) && - isset($_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5]); - $result = parent::_connect(); - if (!$exists) { - $DB = &$_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5]; - $DB->query('SET NAMES "utf8"'); - } - return $result; - } } -- cgit v1.2.3-54-g00ecf From ccf45d454c68f7f667d07e0db608569e049ec285 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 26 Apr 2009 15:08:49 -0400 Subject: Lots of tweaking to make things work Did some tweaking and maneuvering to make things work. This version will now show a "notice received" alert box -- lots of progress! Had to test with Java server, not Python server. --- plugins/Comet/CometPlugin.php | 22 +- plugins/Comet/json2.js | 478 ++++++++++++++++++++++++++++++++++++++++ plugins/Comet/updatetimeline.js | 48 ++-- 3 files changed, 516 insertions(+), 32 deletions(-) create mode 100644 plugins/Comet/json2.js diff --git a/plugins/Comet/CometPlugin.php b/plugins/Comet/CometPlugin.php index 10f8c198c..f60d40075 100644 --- a/plugins/Comet/CometPlugin.php +++ b/plugins/Comet/CometPlugin.php @@ -56,6 +56,8 @@ class CometPlugin extends Plugin { $timeline = null; + $this->log(LOG_DEBUG, 'got action ' . $action->trimmed('action')); + switch ($action->trimmed('action')) { case 'public': $timeline = '/timelines/public'; @@ -64,16 +66,18 @@ class CometPlugin extends Plugin return true; } - $action->element('script', array('type' => 'text/javascript', - 'src' => common_path('plugins/Comet/jquery.comet.js')), + $scripts = array('jquery.comet.js', 'json2.js', 'updatetimeline.js'); + + foreach ($scripts as $script) { + $action->element('script', array('type' => 'text/javascript', + 'src' => common_path('plugins/Comet/'.$script)), ' '); + } + $action->elementStart('script', array('type' => 'text/javascript')); - $action->raw("var _timelineServer = \"$this->server\"; ". - "var _timeline = \"$timeline\";"); + $action->raw("$(document).ready(function() { updater.init(\"$this->server\", \"$timeline\");});"); $action->elementEnd('script'); - $action->element('script', array('type' => 'text/javascript', - 'src' => common_path('plugins/Comet/updatetimeline.js')), - ' '); + return true; } @@ -96,21 +100,17 @@ class CometPlugin extends Plugin $json = $this->noticeAsJson($notice); - $this->log(LOG_DEBUG, "JSON = '$json'"); - // Bayeux? Comet? Huh? These terms confuse me $bay = new Bayeux($this->server); foreach ($timelines as $timeline) { $this->log(LOG_INFO, "Posting notice $notice->id to '$timeline'."); $bay->publish($timeline, $json); - $this->log(LOG_DEBUG, "Done posting notice $notice->id to '$timeline'."); } $bay = NULL; } - $this->log(LOG_DEBUG, "All done."); return true; } diff --git a/plugins/Comet/json2.js b/plugins/Comet/json2.js new file mode 100644 index 000000000..7e27df518 --- /dev/null +++ b/plugins/Comet/json2.js @@ -0,0 +1,478 @@ +/* + http://www.JSON.org/json2.js + 2009-04-16 + + Public Domain. + + NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. + + See http://www.JSON.org/js.html + + This file creates a global JSON object containing two methods: stringify + and parse. + + JSON.stringify(value, replacer, space) + value any JavaScript value, usually an object or array. + + replacer an optional parameter that determines how object + values are stringified for objects. It can be a + function or an array of strings. + + space an optional parameter that specifies the indentation + of nested structures. If it is omitted, the text will + be packed without extra whitespace. If it is a number, + it will specify the number of spaces to indent at each + level. If it is a string (such as '\t' or ' '), + it contains the characters used to indent at each level. + + This method produces a JSON text from a JavaScript value. + + When an object value is found, if the object contains a toJSON + method, its toJSON method will be called and the result will be + stringified. A toJSON method does not serialize: it returns the + value represented by the name/value pair that should be serialized, + or undefined if nothing should be serialized. The toJSON method + will be passed the key associated with the value, and this will be + bound to the object holding the key. + + For example, this would serialize Dates as ISO strings. + + Date.prototype.toJSON = function (key) { + function f(n) { + // Format integers to have at least two digits. + return n < 10 ? '0' + n : n; + } + + return this.getUTCFullYear() + '-' + + f(this.getUTCMonth() + 1) + '-' + + f(this.getUTCDate()) + 'T' + + f(this.getUTCHours()) + ':' + + f(this.getUTCMinutes()) + ':' + + f(this.getUTCSeconds()) + 'Z'; + }; + + You can provide an optional replacer method. It will be passed the + key and value of each member, with this bound to the containing + object. The value that is returned from your method will be + serialized. If your method returns undefined, then the member will + be excluded from the serialization. + + If the replacer parameter is an array of strings, then it will be + used to select the members to be serialized. It filters the results + such that only members with keys listed in the replacer array are + stringified. + + Values that do not have JSON representations, such as undefined or + functions, will not be serialized. Such values in objects will be + dropped; in arrays they will be replaced with null. You can use + a replacer function to replace those with JSON values. + JSON.stringify(undefined) returns undefined. + + The optional space parameter produces a stringification of the + value that is filled with line breaks and indentation to make it + easier to read. + + If the space parameter is a non-empty string, then that string will + be used for indentation. If the space parameter is a number, then + the indentation will be that many spaces. + + Example: + + text = JSON.stringify(['e', {pluribus: 'unum'}]); + // text is '["e",{"pluribus":"unum"}]' + + + text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t'); + // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]' + + text = JSON.stringify([new Date()], function (key, value) { + return this[key] instanceof Date ? + 'Date(' + this[key] + ')' : value; + }); + // text is '["Date(---current time---)"]' + + + JSON.parse(text, reviver) + This method parses a JSON text to produce an object or array. + It can throw a SyntaxError exception. + + The optional reviver parameter is a function that can filter and + transform the results. It receives each of the keys and values, + and its return value is used instead of the original value. + If it returns what it received, then the structure is not modified. + If it returns undefined then the member is deleted. + + Example: + + // Parse the text. Values that look like ISO date strings will + // be converted to Date objects. + + myData = JSON.parse(text, function (key, value) { + var a; + if (typeof value === 'string') { + a = +/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value); + if (a) { + return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4], + +a[5], +a[6])); + } + } + return value; + }); + + myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) { + var d; + if (typeof value === 'string' && + value.slice(0, 5) === 'Date(' && + value.slice(-1) === ')') { + d = new Date(value.slice(5, -1)); + if (d) { + return d; + } + } + return value; + }); + + + This is a reference implementation. You are free to copy, modify, or + redistribute. + + This code should be minified before deployment. + See http://javascript.crockford.com/jsmin.html + + USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO + NOT CONTROL. +*/ + +/*jslint evil: true */ + +/*global JSON */ + +/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply, + call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours, + getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join, + lastIndex, length, parse, prototype, push, replace, slice, stringify, + test, toJSON, toString, valueOf +*/ + +// Create a JSON object only if one does not already exist. We create the +// methods in a closure to avoid creating global variables. + +if (!this.JSON) { + JSON = {}; +} +(function () { + + function f(n) { + // Format integers to have at least two digits. + return n < 10 ? '0' + n : n; + } + + if (typeof Date.prototype.toJSON !== 'function') { + + Date.prototype.toJSON = function (key) { + + return this.getUTCFullYear() + '-' + + f(this.getUTCMonth() + 1) + '-' + + f(this.getUTCDate()) + 'T' + + f(this.getUTCHours()) + ':' + + f(this.getUTCMinutes()) + ':' + + f(this.getUTCSeconds()) + 'Z'; + }; + + String.prototype.toJSON = + Number.prototype.toJSON = + Boolean.prototype.toJSON = function (key) { + return this.valueOf(); + }; + } + + var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, + escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, + gap, + indent, + meta = { // table of character substitutions + '\b': '\\b', + '\t': '\\t', + '\n': '\\n', + '\f': '\\f', + '\r': '\\r', + '"' : '\\"', + '\\': '\\\\' + }, + rep; + + + function quote(string) { + +// If the string contains no control characters, no quote characters, and no +// backslash characters, then we can safely slap some quotes around it. +// Otherwise we must also replace the offending characters with safe escape +// sequences. + + escapable.lastIndex = 0; + return escapable.test(string) ? + '"' + string.replace(escapable, function (a) { + var c = meta[a]; + return typeof c === 'string' ? c : + '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); + }) + '"' : + '"' + string + '"'; + } + + + function str(key, holder) { + +// Produce a string from holder[key]. + + var i, // The loop counter. + k, // The member key. + v, // The member value. + length, + mind = gap, + partial, + value = holder[key]; + +// If the value has a toJSON method, call it to obtain a replacement value. + + if (value && typeof value === 'object' && + typeof value.toJSON === 'function') { + value = value.toJSON(key); + } + +// If we were called with a replacer function, then call the replacer to +// obtain a replacement value. + + if (typeof rep === 'function') { + value = rep.call(holder, key, value); + } + +// What happens next depends on the value's type. + + switch (typeof value) { + case 'string': + return quote(value); + + case 'number': + +// JSON numbers must be finite. Encode non-finite numbers as null. + + return isFinite(value) ? String(value) : 'null'; + + case 'boolean': + case 'null': + +// If the value is a boolean or null, convert it to a string. Note: +// typeof null does not produce 'null'. The case is included here in +// the remote chance that this gets fixed someday. + + return String(value); + +// If the type is 'object', we might be dealing with an object or an array or +// null. + + case 'object': + +// Due to a specification blunder in ECMAScript, typeof null is 'object', +// so watch out for that case. + + if (!value) { + return 'null'; + } + +// Make an array to hold the partial results of stringifying this object value. + + gap += indent; + partial = []; + +// Is the value an array? + + if (Object.prototype.toString.apply(value) === '[object Array]') { + +// The value is an array. Stringify every element. Use null as a placeholder +// for non-JSON values. + + length = value.length; + for (i = 0; i < length; i += 1) { + partial[i] = str(i, value) || 'null'; + } + +// Join all of the elements together, separated with commas, and wrap them in +// brackets. + + v = partial.length === 0 ? '[]' : + gap ? '[\n' + gap + + partial.join(',\n' + gap) + '\n' + + mind + ']' : + '[' + partial.join(',') + ']'; + gap = mind; + return v; + } + +// If the replacer is an array, use it to select the members to be stringified. + + if (rep && typeof rep === 'object') { + length = rep.length; + for (i = 0; i < length; i += 1) { + k = rep[i]; + if (typeof k === 'string') { + v = str(k, value); + if (v) { + partial.push(quote(k) + (gap ? ': ' : ':') + v); + } + } + } + } else { + +// Otherwise, iterate through all of the keys in the object. + + for (k in value) { + if (Object.hasOwnProperty.call(value, k)) { + v = str(k, value); + if (v) { + partial.push(quote(k) + (gap ? ': ' : ':') + v); + } + } + } + } + +// Join all of the member texts together, separated with commas, +// and wrap them in braces. + + v = partial.length === 0 ? '{}' : + gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + + mind + '}' : '{' + partial.join(',') + '}'; + gap = mind; + return v; + } + } + +// If the JSON object does not yet have a stringify method, give it one. + + if (typeof JSON.stringify !== 'function') { + JSON.stringify = function (value, replacer, space) { + +// The stringify method takes a value and an optional replacer, and an optional +// space parameter, and returns a JSON text. The replacer can be a function +// that can replace values, or an array of strings that will select the keys. +// A default replacer method can be provided. Use of the space parameter can +// produce text that is more easily readable. + + var i; + gap = ''; + indent = ''; + +// If the space parameter is a number, make an indent string containing that +// many spaces. + + if (typeof space === 'number') { + for (i = 0; i < space; i += 1) { + indent += ' '; + } + +// If the space parameter is a string, it will be used as the indent string. + + } else if (typeof space === 'string') { + indent = space; + } + +// If there is a replacer, it must be a function or an array. +// Otherwise, throw an error. + + rep = replacer; + if (replacer && typeof replacer !== 'function' && + (typeof replacer !== 'object' || + typeof replacer.length !== 'number')) { + throw new Error('JSON.stringify'); + } + +// Make a fake root object containing our value under the key of ''. +// Return the result of stringifying the value. + + return str('', {'': value}); + }; + } + + +// If the JSON object does not yet have a parse method, give it one. + + if (typeof JSON.parse !== 'function') { + JSON.parse = function (text, reviver) { + +// The parse method takes a text and an optional reviver function, and returns +// a JavaScript value if the text is a valid JSON text. + + var j; + + function walk(holder, key) { + +// The walk method is used to recursively walk the resulting structure so +// that modifications can be made. + + var k, v, value = holder[key]; + if (value && typeof value === 'object') { + for (k in value) { + if (Object.hasOwnProperty.call(value, k)) { + v = walk(value, k); + if (v !== undefined) { + value[k] = v; + } else { + delete value[k]; + } + } + } + } + return reviver.call(holder, key, value); + } + + +// Parsing happens in four stages. In the first stage, we replace certain +// Unicode characters with escape sequences. JavaScript handles many characters +// incorrectly, either silently deleting them, or treating them as line endings. + + cx.lastIndex = 0; + if (cx.test(text)) { + text = text.replace(cx, function (a) { + return '\\u' + + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); + }); + } + +// In the second stage, we run the text against regular expressions that look +// for non-JSON patterns. We are especially concerned with '()' and 'new' +// because they can cause invocation, and '=' because it can cause mutation. +// But just to be safe, we want to reject all unexpected forms. + +// We split the second stage into 4 regexp operations in order to work around +// crippling inefficiencies in IE's and Safari's regexp engines. First we +// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we +// replace all simple value tokens with ']' characters. Third, we delete all +// open brackets that follow a colon or comma or that begin the text. Finally, +// we look to see that the remaining characters are only whitespace or ']' or +// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval. + + if (/^[\],:{}\s]*$/. +test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@'). +replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']'). +replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { + +// In the third stage we use the eval function to compile the text into a +// JavaScript structure. The '{' operator is subject to a syntactic ambiguity +// in JavaScript: it can begin a block or an object literal. We wrap the text +// in parens to eliminate the ambiguity. + + j = eval('(' + text + ')'); + +// In the optional fourth stage, we recursively walk the new structure, passing +// each name/value pair to a reviver function for possible transformation. + + return typeof reviver === 'function' ? + walk({'': j}, '') : j; + } + +// If the text is not JSON parseable, then a SyntaxError is thrown. + + throw new SyntaxError('JSON.parse'); + }; + } +}()); diff --git a/plugins/Comet/updatetimeline.js b/plugins/Comet/updatetimeline.js index 6612b5116..7b22445e3 100644 --- a/plugins/Comet/updatetimeline.js +++ b/plugins/Comet/updatetimeline.js @@ -3,28 +3,34 @@ var updater = function() { - var _handshook = false; - var _connected = false; - var _cometd; + var _cometd; - return { - init: function() - { - _cometd = $.cometd; // Uses the default Comet object - _cometd.init(_timelineServer); - _cometd.subscribe(_timeline, this, receive); - $(window).unload(leave); - } - } + return { + init: function(server, timeline) + { + _cometd = $.cometd; // Uses the default Comet object + _cometd.setLogLevel('debug'); + _cometd.init(server); + _cometd.subscribe(timeline, receive); + $(window).unload(leave); + } + } - function leave() - { - _cometd.disconnect(); - } + function leave() + { + _cometd.disconnect(); + } - function receive(message) - { - var noticeItem = makeNoticeItem(message.data); - var noticeList = $('ul.notices'); - } + function receive(message) + { + alert("Received notice."); + var noticeItem = makeNoticeItem(message.data); + var noticeList = $('ul.notices'); + } + + function makeNoticeItem(data) + { + return ''; + } }(); + -- cgit v1.2.3-54-g00ecf From 7dbb5fb8fdf7c4f82c212863a17793a50f887f58 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 26 Apr 2009 15:37:00 -0400 Subject: Make notice auto-update Shows notices auto-updating --- plugins/Comet/CometPlugin.php | 5 +++++ plugins/Comet/updatetimeline.js | 37 ++++++++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/plugins/Comet/CometPlugin.php b/plugins/Comet/CometPlugin.php index f60d40075..a7a4f4b23 100644 --- a/plugins/Comet/CometPlugin.php +++ b/plugins/Comet/CometPlugin.php @@ -126,6 +126,11 @@ class CometPlugin extends Plugin $act = new TwitterApiAction('/dev/null'); $arr = $act->twitter_status_array($notice, true); + $arr['url'] = $notice->bestUrl(); + + $profile = $notice->getProfile(); + $arr['user']['profile_url'] = $profile->profileurl; + return $arr; } diff --git a/plugins/Comet/updatetimeline.js b/plugins/Comet/updatetimeline.js index 7b22445e3..c6eefb447 100644 --- a/plugins/Comet/updatetimeline.js +++ b/plugins/Comet/updatetimeline.js @@ -23,14 +23,45 @@ var updater = function() function receive(message) { - alert("Received notice."); var noticeItem = makeNoticeItem(message.data); - var noticeList = $('ul.notices'); + $("#notices_primary .notices").prepend(noticeItem, true); + $("#notices_primary .notice:first").css({display:"none"}); + $("#notices_primary .notice:first").fadeIn(2500); + NoticeHover(); + NoticeReply(); } function makeNoticeItem(data) { - return ''; + user = data['user']; + ni = "
  • "+ + "
    "+ + ""+ + ""+ + "\""+user['screen_name']+"\"/"+ + ""+user['screen_name']+""+ + ""+ + ""+ + "

    "+data['text']+"

    "+ + "
    "+ + "
    "+ + "
    "+ + "
    Published
    "+ + "
    "+ + ""+ + "a few seconds ago"+ + " "+ + "
    "+ + "
    "+ + "
    "+ + "
    From
    "+ + "
    "+data['source']+"
    "+ + "
    "+ + "
    "+ + "
    "+ + "
    "+ + "
  • "; + return ni; } }(); -- cgit v1.2.3-54-g00ecf From 781341d91fd4c7406d8687e7828ab86f9696cf66 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 26 Apr 2009 15:41:55 -0400 Subject: README for the comet plugin --- plugins/Comet/README | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 plugins/Comet/README diff --git a/plugins/Comet/README b/plugins/Comet/README new file mode 100644 index 000000000..4abd40af7 --- /dev/null +++ b/plugins/Comet/README @@ -0,0 +1,26 @@ +This is a plugin to automatically load notices in the browser no +matter who creates them -- the kind of thing we see with +search.twitter.com, rejaw.com, or FriendFeed's "real time" news. + +NOTE: this is an insecure version; don't roll it out on a production +server. + +It requires a cometd server. I've only had the cometd-java server work +correctly; something's wiggy with the Twisted-based server. + +After you have a cometd server installed, just add this code to your +config.php: + + require_once(INSTALLDIR.'/plugins/Comet/CometPlugin.php'); + $cp = new CometPlugin('http://example.com:8080/cometd/'); + +Change 'example.com:8080' to the name and port of the server you +installed cometd on. + +TODO: + +* Needs to be tested with Ajax submission. Probably messes everything + up. +* Add more timelines: personal inbox and tags would be great. +* Add security. In particular, only let the PHP code publish notices + to the cometd server. Currently, it doesn't try to authenticate. -- cgit v1.2.3-54-g00ecf From e438334c00ebe29c01bfc5b02aa64cffdb43cb46 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 26 Apr 2009 18:00:06 -0400 Subject: add live updating for tag pages --- plugins/Comet/CometPlugin.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/plugins/Comet/CometPlugin.php b/plugins/Comet/CometPlugin.php index a7a4f4b23..cff0d4c9d 100644 --- a/plugins/Comet/CometPlugin.php +++ b/plugins/Comet/CometPlugin.php @@ -62,6 +62,14 @@ class CometPlugin extends Plugin case 'public': $timeline = '/timelines/public'; break; + case 'tag': + $tag = $action->trimmed('tag'); + if (!empty($tag)) { + $timeline = '/timelines/tag/'.$tag; + } else { + return true; + } + break; default: return true; } @@ -94,6 +102,14 @@ class CometPlugin extends Plugin $timelines[] = '/timelines/public'; } + $tags = $this->getNoticeTags($notice); + + if (!empty($tags)) { + foreach ($tags as $tag) { + $timelines[] = '/timelines/tag/' . $tag; + } + } + if (count($timelines) > 0) { // Require this, since we need it require_once(INSTALLDIR.'/plugins/Comet/bayeux.class.inc.php'); @@ -134,6 +150,26 @@ class CometPlugin extends Plugin return $arr; } + function getNoticeTags($notice) + { + $tags = null; + + $nt = new Notice_tag(); + $nt->notice_id = $notice->id; + + if ($nt->find()) { + $tags = array(); + while ($nt->fetch()) { + $tags[] = $nt->tag; + } + } + + $nt->free(); + $nt = null; + + return $tags; + } + // Push this up to Plugin function log($level, $msg) -- cgit v1.2.3-54-g00ecf From db3b56a2fdf51e97e9859aa731674947571667aa Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 26 Apr 2009 20:50:39 -0400 Subject: Display rendered HTML for a notice Display the rendered HTML for a notice --- plugins/Comet/CometPlugin.php | 1 + plugins/Comet/updatetimeline.js | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/Comet/CometPlugin.php b/plugins/Comet/CometPlugin.php index cff0d4c9d..2e0bb40a4 100644 --- a/plugins/Comet/CometPlugin.php +++ b/plugins/Comet/CometPlugin.php @@ -143,6 +143,7 @@ class CometPlugin extends Plugin $arr = $act->twitter_status_array($notice, true); $arr['url'] = $notice->bestUrl(); + $arr['html'] = htmlspecialchars($notice->rendered); $profile = $notice->getProfile(); $arr['user']['profile_url'] = $profile->profileurl; diff --git a/plugins/Comet/updatetimeline.js b/plugins/Comet/updatetimeline.js index c6eefb447..55511d35f 100644 --- a/plugins/Comet/updatetimeline.js +++ b/plugins/Comet/updatetimeline.js @@ -34,6 +34,8 @@ var updater = function() function makeNoticeItem(data) { user = data['user']; + html = data['html'].replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>'); + ni = "
  • "+ "
    "+ ""+ @@ -42,7 +44,7 @@ var updater = function() ""+user['screen_name']+""+ ""+ ""+ - "

    "+data['text']+"

    "+ + "

    "+html+"

    "+ "
    "+ "
    "+ "
    "+ -- cgit v1.2.3-54-g00ecf From e97223b2ba3f9f1818ba12b707c53c0ebdcab144 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 26 Apr 2009 21:15:11 -0400 Subject: Don't add a notice if it already exists on the page Try not to interfere with Ajax posting; don't show something if it's already on the page. --- plugins/Comet/updatetimeline.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/Comet/updatetimeline.js b/plugins/Comet/updatetimeline.js index 55511d35f..de750baba 100644 --- a/plugins/Comet/updatetimeline.js +++ b/plugins/Comet/updatetimeline.js @@ -23,6 +23,14 @@ var updater = function() function receive(message) { + id = message.data.id; + + // Don't add it if it already exists + + if ($("#notice-"+id).length > 0) { + return; + } + var noticeItem = makeNoticeItem(message.data); $("#notices_primary .notices").prepend(noticeItem, true); $("#notices_primary .notice:first").css({display:"none"}); -- cgit v1.2.3-54-g00ecf From 7405d9dfa684975309150537069a1268a67ed6be Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 26 Apr 2009 21:16:09 -0400 Subject: Don't add a node if it's already there Try not to double-add a node on Ajax submit. Normally not a big deal, but may happen if the CometPlugin (or in the future Strophe or other auto-update plugins) is enabled. --- js/util.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/js/util.js b/js/util.js index 15a14625c..f15c4f2bb 100644 --- a/js/util.js +++ b/js/util.js @@ -188,11 +188,15 @@ $(document).ready(function(){ alert(result); } else { - $("#notices_primary .notices").prepend(document._importNode($("li", xml).get(0), true)); - $("#notices_primary .notice:first").css({display:"none"}); - $("#notices_primary .notice:first").fadeIn(2500); - NoticeHover(); - NoticeReply(); + li = $("li", xml).get(0); + id = li.id; + if ($("#"+li.id).length == 0) { + $("#notices_primary .notices").prepend(document._importNode(li, true)); + $("#notices_primary .notice:first").css({display:"none"}); + $("#notices_primary .notice:first").fadeIn(2500); + NoticeHover(); + NoticeReply(); + } } $("#notice_data-text").val(""); counter(); -- cgit v1.2.3-54-g00ecf From efe8c47d7d9e91eb8308845b8b0717e84e36e346 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Mon, 27 Apr 2009 20:07:22 +0000 Subject: Minor CSS order/cleanup. --- theme/base/css/display.css | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/theme/base/css/display.css b/theme/base/css/display.css index 0bc2e68b6..dc6b4bc29 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -842,23 +842,6 @@ text-transform:lowercase; } - -.notice-data { -position:absolute; -top:18px; -right:0; -min-height:50px; -margin-bottom:4px; -} -.notice .entry-content .notice-data dt { -display:none; -} - -.notice-data a { -display:block; -outline:none; -} - .notice-options { padding-left:2%; float:left; @@ -1036,6 +1019,8 @@ padding-right:30px; .hentry .entry-content p { margin-bottom:18px; } +.system_notice ul, +.instructions ul, .hentry entry-content ol, .hentry .entry-content ul { list-style-position:inside; @@ -1160,9 +1145,6 @@ clear:both; margin-bottom:0; } -.instructions ul { -list-style-position:inside; -} .instructions p, .instructions ul { margin-bottom:18px; -- cgit v1.2.3-54-g00ecf From 6a20ef71d3b2b325ce24318e2ba4483d6c8732ce Mon Sep 17 00:00:00 2001 From: CiaranG Date: Tue, 28 Apr 2009 13:05:48 +0100 Subject: Fixed typo in stopdaemons.sh - was not stopping the new memcached queue handler --- scripts/stopdaemons.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/stopdaemons.sh b/scripts/stopdaemons.sh index 196991de0..f6d71eddf 100755 --- a/scripts/stopdaemons.sh +++ b/scripts/stopdaemons.sh @@ -25,7 +25,7 @@ DIR=`php $SDIR/getpiddir.php` for f in jabberhandler ombhandler publichandler smshandler pinghandler \ xmppconfirmhandler xmppdaemon twitterhandler facebookhandler \ - memcachedhandler inboxhandler; do + memcachehandler inboxhandler; do FILES="$DIR/$f.*.pid" for ff in "$FILES" ; do -- cgit v1.2.3-54-g00ecf From 5b78f95e972f9f19ea46607e8b9544b8f7c4207a Mon Sep 17 00:00:00 2001 From: CiaranG Date: Tue, 28 Apr 2009 13:30:54 +0100 Subject: Only start daemons that are required, according to the site config. There is the potential to not start some more - see the checks in getvaliddaemons.php --- scripts/getvaliddaemons.php | 52 +++++++++++++++++++++++++++++++++++++++++++++ scripts/startdaemons.sh | 6 ++---- 2 files changed, 54 insertions(+), 4 deletions(-) create mode 100755 scripts/getvaliddaemons.php diff --git a/scripts/getvaliddaemons.php b/scripts/getvaliddaemons.php new file mode 100755 index 000000000..482e63af7 --- /dev/null +++ b/scripts/getvaliddaemons.php @@ -0,0 +1,52 @@ +#!/usr/bin/env php +. + */ + +/** + * Utility script to get a list of daemons that should run, based on the + * current configuration. This is used by startdaemons.sh to determine what + * it should and shouldn't start up. The output is a list of space-separated + * daemon names. + */ + + +# Abort if called from a web server +if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { + print "This script must be run from the command line\n"; + exit(); +} + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); +define('LACONICA', true); + +require_once(INSTALLDIR . '/lib/common.php'); + +if(common_config('xmpp','enabled')) { + echo "xmppdaemon.php jabberqueuehandler.php publicqueuehandler.php "; + echo "xmppconfirmhandler.php "; +} +if(common_config('memcached','enabled')) { + echo "memcachedqueuehandler.php "; +} +echo "ombqueuehandler.php "; +echo "twitterqueuehandler.php "; +echo "facebookqueuehandler.php "; +echo "pingqueuehandler.php "; +echo "inboxqueuehandler.php "; +echo "smsqueuehandler.php "; diff --git a/scripts/startdaemons.sh b/scripts/startdaemons.sh index 66f9ed4e0..3869e95c4 100755 --- a/scripts/startdaemons.sh +++ b/scripts/startdaemons.sh @@ -21,11 +21,9 @@ # Note that the 'maildaemon' needs to run as a mail filter. DIR=`dirname $0` +DAEMONS=`php $DIR/getvaliddaemons.php` -for f in xmppdaemon.php jabberqueuehandler.php publicqueuehandler.php \ - xmppconfirmhandler.php smsqueuehandler.php ombqueuehandler.php \ - twitterqueuehandler.php facebookqueuehandler.php pingqueuehandler.php \ - memcachedqueuehandler.php inboxqueuehandler.php; do +for f in $DAEMONS; do echo -n "Starting $f..."; php $DIR/$f -- cgit v1.2.3-54-g00ecf From c7105c2af1ebe3cddd477265c6fea59a61d0c7e5 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 28 Apr 2009 13:07:05 -0400 Subject: Change to avoid a join in notice inbox The join in notice_inbox is causing temp-table sorting on identi.ca, so I'm trying a finer-tuned approach. --- classes/Notice.php | 31 ++++++++++++--- classes/Notice_inbox.php | 101 ++++++++++++++++++++++++++++++++++++++++++++++- classes/User.php | 29 +------------- 3 files changed, 127 insertions(+), 34 deletions(-) diff --git a/classes/Notice.php b/classes/Notice.php index 27b98de1c..b087c94bc 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -215,6 +215,7 @@ class Notice extends Memcached_DataObject if (common_config('queue', 'enabled')) { $notice->blowAuthorCaches(); } else { + common_debug("Blowing caches for new notice."); $notice->blowCaches(); } } @@ -285,7 +286,7 @@ class Notice extends Memcached_DataObject // Clear the user's cache $cache = common_memcache(); if (!empty($cache)) { - $cache->delete(common_cache_key('user:notices_with_friends:' . $this->profile_id)); + $cache->delete(common_cache_key('notice_inbox:by_user:'.$this->profile_id)); } $this->blowNoticeCache($blowLast); $this->blowPublicCache($blowLast); @@ -307,9 +308,9 @@ class Notice extends Memcached_DataObject $member->group_id = $group_inbox->group_id; if ($member->find()) { while ($member->fetch()) { - $cache->delete(common_cache_key('user:notices_with_friends:' . $member->profile_id)); + $cache->delete(common_cache_key('notice_inbox:by_user:' . $member->profile_id)); if ($blowLast) { - $cache->delete(common_cache_key('user:notices_with_friends:' . $member->profile_id . ';last')); + $cache->delete(common_cache_key('notice_inbox:by_user:' . $member->profile_id . ';last')); } } } @@ -352,9 +353,9 @@ class Notice extends Memcached_DataObject 'WHERE subscription.subscribed = ' . $this->profile_id); while ($user->fetch()) { - $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id)); + $cache->delete(common_cache_key('notice_inbox:by_user:'.$user_id)); if ($blowLast) { - $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id . ';last')); + $cache->delete(common_cache_key('notice_inbox:by_user:'.$user_id.';last')); } } $user->free(); @@ -613,6 +614,26 @@ class Notice extends Memcached_DataObject return $wrapper; } + function getStreamByIds($ids) + { + $cache = common_memcache(); + + if (!empty($cache)) { + $notices = array(); + foreach ($ids as $id) { + $notices[] = Notice::staticGet('id', $id); + } + return new ArrayWrapper($notices); + } else { + $notice = new Notice(); + $notice->whereAdd('id in (' . implode(', ', $ids) . ')'); + $notice->orderBy('id DESC'); + + $notice->find(); + return $notice; + } + } + function publicStream($offset=0, $limit=20, $since_id=0, $before_id=0, $since=null) { diff --git a/classes/Notice_inbox.php b/classes/Notice_inbox.php index 81ddb4538..162da74fe 100644 --- a/classes/Notice_inbox.php +++ b/classes/Notice_inbox.php @@ -1,7 +1,7 @@ INBOX_CACHE_WINDOW) { + common_debug('Doing direct DB hit for notice_inbox since the params are screwy.'); + return Notice_inbox::_streamDirect($user_id, $offset, $limit, $since_id, $before_id, $since); + } + + $idkey = common_cache_key('notice_inbox:by_user:'.$user_id); + + $idstr = $cache->get($idkey); + + if (!empty($idstr)) { + // Cache hit! Woohoo! + common_debug('Cache hit for notice_inbox.'); + $window = explode(',', $idstr); + $ids = array_slice($window, $offset, $limit); + return $ids; + } + + $laststr = common_cache_key($idkey.';last'); + + if (!empty($laststr)) { + common_debug('Cache hit for notice_inbox on last item.'); + + $window = explode(',', $laststr); + $last_id = $window[0]; + $new_ids = Notice_inbox::_streamDirect($user_id, 0, INBOX_CACHE_WINDOW, + $last_id, null, null); + + $new_window = array_merge($new_ids, $window); + + $new_windowstr = implode(',', $new_window); + + $result = $cache->set($idkey, $new_windowstr); + $result = $cache->set($idkey . ';last', $new_windowstr); + + $ids = array_slice($new_window, $offset, $limit); + + return $ids; + } + + $window = Notice_inbox::_streamDirect($user_id, 0, INBOX_CACHE_WINDOW, + null, null, null); + + $windowstr = implode(',', $new_window); + + $result = $cache->set($idkey, $windowstr); + $result = $cache->set($idkey . ';last', $windowstr); + + $ids = array_slice($window, $offset, $limit); + + return $ids; + } + + function _streamDirect($user_id, $offset, $limit, $since_id, $before_id, $since) + { + $inbox = new Notice_inbox(); + + $inbox->user_id = $user_id; + + if ($since_id != 0) { + $inbox->whereAdd('notice_id > ' . $since_id); + } + + if ($before_id != 0) { + $inbox->whereAdd('notice_id < ' . $before_id); + } + + if (!is_null($since)) { + $inbox->whereAdd('created > \'' . date('Y-m-d H:i:s', $since) . '\''); + } + + $inbox->orderBy('notice_id DESC'); + + if (!is_null($offset)) { + $inbox->limit($offset, $limit); + } + + $ids = array(); + + if ($inbox->find()) { + while ($inbox->fetch()) { + $ids[] = $inbox->notice_id; + } + } + + return $ids; + } } diff --git a/classes/User.php b/classes/User.php index 098381f73..ce7ea1464 100644 --- a/classes/User.php +++ b/classes/User.php @@ -451,34 +451,9 @@ class User extends Memcached_DataObject } else if ($enabled === true || ($enabled == 'transitional' && $this->inboxed == 1)) { - $cache = common_memcache(); + $ids = Notice_inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since); - if (!empty($cache)) { - - # Get the notices out of the cache - - $notices = $cache->get(common_cache_key($cachekey)); - - # On a cache hit, return a DB-object-like wrapper - - if ($notices !== false) { - $wrapper = new ArrayWrapper(array_slice($notices, $offset, $limit)); - return $wrapper; - } - } - - $inbox = Notice_inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since); - - $ids = array(); - - while ($inbox->fetch()) { - $ids[] = $inbox->notice_id; - } - - $inbox->free(); - unset($inbox); - - return Notice::getStreamByIds($ids, 'user:notices_with_friends:' . $this->id); + return Notice::getStreamByIds($ids); } } -- cgit v1.2.3-54-g00ecf From fe53e780be5db4ceb2831a1d69faec6130a10deb Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 28 Apr 2009 13:31:56 -0400 Subject: Remove some debug comments in query-by-id --- classes/Notice.php | 5 ++--- classes/Notice_inbox.php | 4 ---- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/classes/Notice.php b/classes/Notice.php index b087c94bc..49d0939c1 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -215,7 +215,6 @@ class Notice extends Memcached_DataObject if (common_config('queue', 'enabled')) { $notice->blowAuthorCaches(); } else { - common_debug("Blowing caches for new notice."); $notice->blowCaches(); } } @@ -353,9 +352,9 @@ class Notice extends Memcached_DataObject 'WHERE subscription.subscribed = ' . $this->profile_id); while ($user->fetch()) { - $cache->delete(common_cache_key('notice_inbox:by_user:'.$user_id)); + $cache->delete(common_cache_key('notice_inbox:by_user:'.$user->id)); if ($blowLast) { - $cache->delete(common_cache_key('notice_inbox:by_user:'.$user_id.';last')); + $cache->delete(common_cache_key('notice_inbox:by_user:'.$user->id.';last')); } } $user->free(); diff --git a/classes/Notice_inbox.php b/classes/Notice_inbox.php index 162da74fe..f32137038 100644 --- a/classes/Notice_inbox.php +++ b/classes/Notice_inbox.php @@ -50,7 +50,6 @@ class Notice_inbox extends Memcached_DataObject if (empty($cache) || $since_id != 0 || $before_id != 0 || !is_null($since) || ($offset + $limit) > INBOX_CACHE_WINDOW) { - common_debug('Doing direct DB hit for notice_inbox since the params are screwy.'); return Notice_inbox::_streamDirect($user_id, $offset, $limit, $since_id, $before_id, $since); } @@ -60,7 +59,6 @@ class Notice_inbox extends Memcached_DataObject if (!empty($idstr)) { // Cache hit! Woohoo! - common_debug('Cache hit for notice_inbox.'); $window = explode(',', $idstr); $ids = array_slice($window, $offset, $limit); return $ids; @@ -69,8 +67,6 @@ class Notice_inbox extends Memcached_DataObject $laststr = common_cache_key($idkey.';last'); if (!empty($laststr)) { - common_debug('Cache hit for notice_inbox on last item.'); - $window = explode(',', $laststr); $last_id = $window[0]; $new_ids = Notice_inbox::_streamDirect($user_id, 0, INBOX_CACHE_WINDOW, -- cgit v1.2.3-54-g00ecf From f798d1ea430d25c2f4a60179c65b39b1257a5340 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 28 Apr 2009 17:08:20 -0700 Subject: Added dirty dates to Foreign_link --- classes/Foreign_link.php | 2 ++ classes/laconica.ini | 2 ++ db/laconica.sql | 2 ++ 3 files changed, 6 insertions(+) diff --git a/classes/Foreign_link.php b/classes/Foreign_link.php index 5d9c82a85..606560951 100644 --- a/classes/Foreign_link.php +++ b/classes/Foreign_link.php @@ -17,6 +17,8 @@ class Foreign_link extends Memcached_DataObject public $noticesync; // tinyint(1) not_null default_1 public $friendsync; // tinyint(1) not_null default_2 public $profilesync; // tinyint(1) not_null default_1 + public $last_noticesync; // datetime() + public $last_friendsync; // datetime() public $created; // datetime() not_null public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP diff --git a/classes/laconica.ini b/classes/laconica.ini index dd424bbdd..5a905a4bb 100755 --- a/classes/laconica.ini +++ b/classes/laconica.ini @@ -55,6 +55,8 @@ credentials = 2 noticesync = 145 friendsync = 145 profilesync = 145 +last_noticesync = 14 +last_friendsync = 14 created = 142 modified = 384 diff --git a/db/laconica.sql b/db/laconica.sql index 83d610f0d..d9e21a7b5 100644 --- a/db/laconica.sql +++ b/db/laconica.sql @@ -291,6 +291,8 @@ create table foreign_link ( noticesync tinyint not null default 1 comment 'notice synchronization, bit 1 = sync outgoing, bit 2 = sync incoming, bit 3 = filter local replies', friendsync tinyint not null default 2 comment 'friend synchronization, bit 1 = sync outgoing, bit 2 = sync incoming', profilesync tinyint not null default 1 comment 'profile synchronization, bit 1 = sync outgoing, bit 2 = sync incoming', + last_noticesync datetime default null comment 'last time notices were imported', + last_friendsync datetime default null comment 'last time friends were imported', created datetime not null comment 'date this record was created', modified timestamp comment 'date this record was modified', -- cgit v1.2.3-54-g00ecf From e85cddba45c2ce02d135f00acdcfa37cb9168130 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 28 Apr 2009 23:31:00 -0700 Subject: Ticket #1428 - Changed replies API method to "mentions". --- actions/twitapistatuses.php | 38 +++++++++++++++++++++----------------- lib/router.php | 4 ++-- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/actions/twitapistatuses.php b/actions/twitapistatuses.php index 323c4f1f8..3abeba367 100644 --- a/actions/twitapistatuses.php +++ b/actions/twitapistatuses.php @@ -144,10 +144,10 @@ class TwitapistatusesAction extends TwitterapiAction break; case 'atom': if (isset($apidata['api_arg'])) { - $selfuri = $selfuri = common_root_url() . + $selfuri = common_root_url() . 'api/statuses/friends_timeline/' . $apidata['api_arg'] . '.atom'; } else { - $selfuri = $selfuri = common_root_url() . + $selfuri = common_root_url() . 'api/statuses/friends_timeline.atom'; } $this->show_atom_timeline($notice, $title, $id, $link, $subtitle, null, $selfuri); @@ -231,10 +231,10 @@ class TwitapistatusesAction extends TwitterapiAction break; case 'atom': if (isset($apidata['api_arg'])) { - $selfuri = $selfuri = common_root_url() . + $selfuri = common_root_url() . 'api/statuses/user_timeline/' . $apidata['api_arg'] . '.atom'; } else { - $selfuri = $selfuri = common_root_url() . + $selfuri = common_root_url() . 'api/statuses/user_timeline.atom'; } $this->show_atom_timeline($notice, $title, $id, $link, $subtitle, $suplink, $selfuri); @@ -344,7 +344,7 @@ class TwitapistatusesAction extends TwitterapiAction $this->show($args, $apidata); } - function replies($args, $apidata) + function mentions($args, $apidata) { parent::handle($args); @@ -360,11 +360,13 @@ class TwitapistatusesAction extends TwitterapiAction $profile = $user->getProfile(); $sitename = common_config('site', 'name'); - $title = sprintf(_('%1$s / Updates replying to %2$s'), $sitename, $user->nickname); + $title = sprintf(_('%1$s / Updates mentioning %2$s'), + $sitename, $user->nickname); $taguribase = common_config('integration', 'taguri'); - $id = "tag:$taguribase:Replies:".$user->id; + $id = "tag:$taguribase:Mentions:".$user->id; $link = common_local_url('replies', array('nickname' => $user->nickname)); - $subtitle = sprintf(_('%1$s updates that reply to updates from %2$s / %3$s.'), $sitename, $user->nickname, $profile->getBestName()); + $subtitle = sprintf(_('%1$s updates that reply to updates from %2$s / %3$s.'), + $sitename, $user->nickname, $profile->getBestName()); if (!$page) { $page = 1; @@ -385,7 +387,8 @@ class TwitapistatusesAction extends TwitterapiAction $since = strtotime($this->arg('since')); - $notice = $user->getReplies((($page-1)*20), $count, $since_id, $before_id, $since); + $notice = $user->getReplies((($page-1)*20), + $count, $since_id, $before_id, $since); $notices = array(); while ($notice->fetch()) { @@ -400,14 +403,10 @@ class TwitapistatusesAction extends TwitterapiAction $this->show_rss_timeline($notices, $title, $link, $subtitle); break; case 'atom': - if (isset($apidata['api_arg'])) { - $selfuri = $selfuri = common_root_url() . - 'api/statuses/replies/' . $apidata['api_arg'] . '.atom'; - } else { - $selfuri = $selfuri = common_root_url() . - 'api/statuses/replies.atom'; - } - $this->show_atom_timeline($notices, $title, $id, $link, $subtitle, null, $selfuri); + $selfuri = common_root_url() . + ltrim($_SERVER['QUERY_STRING'], 'p='); + $this->show_atom_timeline($notices, $title, $id, $link, $subtitle, + null, $selfuri); break; case 'json': $this->show_json_timeline($notices); @@ -418,6 +417,11 @@ class TwitapistatusesAction extends TwitterapiAction } + function replies($args, $apidata) + { + call_user_func(array($this, 'mentions'), $args, $apidata); + } + function show($args, $apidata) { parent::handle($args); diff --git a/lib/router.php b/lib/router.php index 6fb2f9487..12590b790 100644 --- a/lib/router.php +++ b/lib/router.php @@ -231,12 +231,12 @@ class Router $m->connect('api/statuses/:method', array('action' => 'api', 'apiaction' => 'statuses'), - array('method' => '(public_timeline|friends_timeline|user_timeline|update|replies|friends|followers|featured)(\.(atom|rss|xml|json))?')); + array('method' => '(public_timeline|friends_timeline|user_timeline|update|replies|mentions|friends|followers|featured)(\.(atom|rss|xml|json))?')); $m->connect('api/statuses/:method/:argument', array('action' => 'api', 'apiaction' => 'statuses'), - array('method' => '(user_timeline|friends_timeline|replies|show|destroy|friends|followers)')); + array('method' => '(user_timeline|friends_timeline|replies|mentions|show|destroy|friends|followers)')); // users -- cgit v1.2.3-54-g00ecf From 10ef8a2f7112a83188e9702d480abd3c6062c26c Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 29 Apr 2009 11:27:45 -0400 Subject: Move algorithm for caching to Notice class Moved the algorithm for notice stream caching to the Notice class. --- classes/Notice.php | 55 +++++++++++++++++++++++++++++++++++++++++++++++ classes/Notice_inbox.php | 56 +++++------------------------------------------- 2 files changed, 60 insertions(+), 51 deletions(-) diff --git a/classes/Notice.php b/classes/Notice.php index 49d0939c1..faabb1e14 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -967,4 +967,59 @@ class Notice extends Memcached_DataObject array('notice' => $this->id)); } } + + function stream($fn, $args, $cachekey, $offset=0, $limit=20, $since_id=0, $before_id=0, $since=null) + { + $cache = common_memcache(); + + if (empty($cache) || + $since_id != 0 || $before_id != 0 || !is_null($since) || + ($offset + $limit) > NOTICE_CACHE_WINDOW) { + return call_user_func_array($fn, array_merge($args, array($offset, $limit, $since_id, + $before_id, $since))); + } + + $idkey = common_cache_key($cachekey); + + $idstr = $cache->get($idkey); + + if (!empty($idstr)) { + // Cache hit! Woohoo! + $window = explode(',', $idstr); + $ids = array_slice($window, $offset, $limit); + return $ids; + } + + $laststr = common_cache_key($idkey.';last'); + + if (!empty($laststr)) { + $window = explode(',', $laststr); + $last_id = $window[0]; + $new_ids = call_user_func_array($fn, array_merge($args, array(0, NOTICE_CACHE_WINDOW, + $last_id, 0, null))); + + $new_window = array_merge($new_ids, $window); + + $new_windowstr = implode(',', $new_window); + + $result = $cache->set($idkey, $new_windowstr); + $result = $cache->set($idkey . ';last', $new_windowstr); + + $ids = array_slice($new_window, $offset, $limit); + + return $ids; + } + + $window = call_user_func_array($fn, array_merge($args, array(0, NOTICE_CACHE_WINDOW, + 0, 0, null))); + + $windowstr = implode(',', $new_window); + + $result = $cache->set($idkey, $windowstr); + $result = $cache->set($idkey . ';last', $windowstr); + + $ids = array_slice($window, $offset, $limit); + + return $ids; + } } diff --git a/classes/Notice_inbox.php b/classes/Notice_inbox.php index f32137038..dec14b0d1 100644 --- a/classes/Notice_inbox.php +++ b/classes/Notice_inbox.php @@ -43,58 +43,12 @@ class Notice_inbox extends Memcached_DataObject /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE - function stream($user_id, $offset=0, $limit=20, $since_id=0, $before_id=0, $since=null) + function stream($user_id, $offset, $limit, $since_id, $before_id, $since) { - $cache = common_memcache(); - - if (empty($cache) || - $since_id != 0 || $before_id != 0 || !is_null($since) || - ($offset + $limit) > INBOX_CACHE_WINDOW) { - return Notice_inbox::_streamDirect($user_id, $offset, $limit, $since_id, $before_id, $since); - } - - $idkey = common_cache_key('notice_inbox:by_user:'.$user_id); - - $idstr = $cache->get($idkey); - - if (!empty($idstr)) { - // Cache hit! Woohoo! - $window = explode(',', $idstr); - $ids = array_slice($window, $offset, $limit); - return $ids; - } - - $laststr = common_cache_key($idkey.';last'); - - if (!empty($laststr)) { - $window = explode(',', $laststr); - $last_id = $window[0]; - $new_ids = Notice_inbox::_streamDirect($user_id, 0, INBOX_CACHE_WINDOW, - $last_id, null, null); - - $new_window = array_merge($new_ids, $window); - - $new_windowstr = implode(',', $new_window); - - $result = $cache->set($idkey, $new_windowstr); - $result = $cache->set($idkey . ';last', $new_windowstr); - - $ids = array_slice($new_window, $offset, $limit); - - return $ids; - } - - $window = Notice_inbox::_streamDirect($user_id, 0, INBOX_CACHE_WINDOW, - null, null, null); - - $windowstr = implode(',', $new_window); - - $result = $cache->set($idkey, $windowstr); - $result = $cache->set($idkey . ';last', $windowstr); - - $ids = array_slice($window, $offset, $limit); - - return $ids; + return Notice::stream(array('Notice_inbox', '_streamDirect'), + array($user_id), + 'notice_inbox:by_user:'.$user_id, + $offset, $limit, $since_id, $before_id, $since); } function _streamDirect($user_id, $offset, $limit, $since_id, $before_id, $since) -- cgit v1.2.3-54-g00ecf From a4d959b8a2254d173bdf45f418f6add9f6f62cda Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 29 Apr 2009 12:05:31 -0400 Subject: Public stream uses IDs method Public stream now uses IDs method --- classes/Notice.php | 55 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/classes/Notice.php b/classes/Notice.php index faabb1e14..6a7522bd3 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -635,25 +635,58 @@ class Notice extends Memcached_DataObject function publicStream($offset=0, $limit=20, $since_id=0, $before_id=0, $since=null) { + $ids = Notice::stream(array('Notice', '_publicStreamDirect'), + array(), + 'public', + $offset, $limit, $since_id, $before_id, $since); - $parts = array(); + return Notice::getStreamByIds($ids); + } + + function _publicStreamDirect($offset=0, $limit=20, $since_id=0, $before_id=0, $since=null) + { + $notice = new Notice(); + + $notice->selectAdd(); // clears it + $notice->selectAdd('id'); - $qry = 'SELECT * FROM notice '; + $notice->orderBy('id DESC'); + + if (!is_null($offset)) { + $notice->limit($offset, $limit); + } if (common_config('public', 'localonly')) { - $parts[] = 'is_local = 1'; + $notice->whereAdd('is_local = 1'); } else { # -1 == blacklisted - $parts[] = 'is_local != -1'; + $notice->whereAdd('is_local != -1'); } - if ($parts) { - $qry .= ' WHERE ' . implode(' AND ', $parts); + if ($since_id != 0) { + $notice->whereAdd('id > ' . $since_id); } - return Notice::getStream($qry, - 'public', - $offset, $limit, $since_id, $before_id, null, $since); + if ($before_id != 0) { + $notice->whereAdd('id < ' . $before_id); + } + + if (!is_null($since)) { + $notice->whereAdd('created > \'' . date('Y-m-d H:i:s', $since) . '\''); + } + + $ids = array(); + + if ($notice->find()) { + while ($notice->fetch()) { + $ids[] = $notice->id; + } + } + + $notice->free(); + $notice = NULL; + + return $ids; } function addToInboxes() @@ -990,7 +1023,7 @@ class Notice extends Memcached_DataObject return $ids; } - $laststr = common_cache_key($idkey.';last'); + $laststr = $cache->get($idkey.';last'); if (!empty($laststr)) { $window = explode(',', $laststr); @@ -1013,7 +1046,7 @@ class Notice extends Memcached_DataObject $window = call_user_func_array($fn, array_merge($args, array(0, NOTICE_CACHE_WINDOW, 0, 0, null))); - $windowstr = implode(',', $new_window); + $windowstr = implode(',', $window); $result = $cache->set($idkey, $windowstr); $result = $cache->set($idkey . ';last', $windowstr); -- cgit v1.2.3-54-g00ecf From 1e8ea1eb460b163176c4d7d1e7dffa500024ef91 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 29 Apr 2009 16:09:03 -0400 Subject: Make the tag stream use ID mechanism --- classes/Notice.php | 5 +---- classes/Notice_tag.php | 61 +++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/classes/Notice.php b/classes/Notice.php index 6a7522bd3..2bb466155 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -328,10 +328,7 @@ class Notice extends Memcached_DataObject $tag->notice_id = $this->id; if ($tag->find()) { while ($tag->fetch()) { - $cache->delete(common_cache_key('notice_tag:notice_stream:' . $tag->tag)); - if ($blowLast) { - $cache->delete(common_cache_key('notice_tag:notice_stream:' . $tag->tag . ';last')); - } + $tag->blowCache($blowLast); } } $tag->free(); diff --git a/classes/Notice_tag.php b/classes/Notice_tag.php index f2247299a..e5b772243 100644 --- a/classes/Notice_tag.php +++ b/classes/Notice_tag.php @@ -37,21 +37,62 @@ class Notice_tag extends Memcached_DataObject ###END_AUTOCODE static function getStream($tag, $offset=0, $limit=20) { - $qry = - 'SELECT notice.* ' . - 'FROM notice JOIN notice_tag ON notice.id = notice_tag.notice_id ' . - "WHERE notice_tag.tag = '%s' "; - - return Notice::getStream(sprintf($qry, $tag), - 'notice_tag:notice_stream:' . common_keyize($tag), - $offset, $limit); + + $ids = Notice::stream(array('Notice_tag', '_streamDirect'), + array($tag), + 'notice_tag:notice_ids:' . common_keyize($tag), + $offset, $limit); + + return Notice::getStreamByIds($ids); + } + + function _streamDirect($tag, $offset, $limit, $since_id, $before_id, $since) + { + $nt = new Notice_tag(); + + $nt->tag = $tag; + + $nt->selectAdd(); + $nt->selectAdd('notice_id'); + + if ($since_id != 0) { + $nt->whereAdd('notice_id > ' . $since_id); + } + + if ($before_id != 0) { + $nt->whereAdd('notice_id < ' . $before_id); + } + + if (!is_null($since)) { + $nt->whereAdd('created > \'' . date('Y-m-d H:i:s', $since) . '\''); + } + + $nt->orderBy('notice_id DESC'); + + if (!is_null($offset)) { + $nt->limit($offset, $limit); + } + + $ids = array(); + + if ($nt->find()) { + while ($nt->fetch()) { + $ids[] = $nt->notice_id; + } + } + + return $ids; } - function blowCache() + function blowCache($blowLast=false) { $cache = common_memcache(); if ($cache) { - $cache->delete(common_cache_key('notice_tag:notice_stream:' . $this->tag)); + $idkey = common_cache_key('notice_tag:notice_ids:' . common_keyize($this->tag)); + $cache->delete($idkey); + if ($blowLast) { + $cache->delete($idkey.';last'); + } } } -- cgit v1.2.3-54-g00ecf From 8295402fb30a3854bae3b9d6c457c7c0e432c51a Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Wed, 29 Apr 2009 13:16:52 -0700 Subject: Added 'mentions' the the list of API methods requiring bare auth --- actions/api.php | 1 + 1 file changed, 1 insertion(+) diff --git a/actions/api.php b/actions/api.php index d2f0a2eff..8762b4bcd 100644 --- a/actions/api.php +++ b/actions/api.php @@ -130,6 +130,7 @@ class ApiAction extends Action 'statuses/friends_timeline', 'statuses/friends', 'statuses/replies', + 'statuses/mentions', 'statuses/followers', 'favorites/favorites'); -- cgit v1.2.3-54-g00ecf From b79fef307481b36b4d04dbabb54e3f6d9edf6896 Mon Sep 17 00:00:00 2001 From: CiaranG Date: Wed, 29 Apr 2009 23:43:42 +0100 Subject: Fixed remote subscription, broken in fc6cedd2227d9d560736e494f431e2b40b26b45c --- actions/accesstoken.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/accesstoken.php b/actions/accesstoken.php index bb68d3314..46b43c702 100644 --- a/actions/accesstoken.php +++ b/actions/accesstoken.php @@ -59,7 +59,7 @@ class AccesstokenAction extends Action try { common_debug('getting request from env variables', __FILE__); common_remove_magic_from_request(); - $req = OAuthRequest::from_request('POST', common_locale_url('accesstoken')); + $req = OAuthRequest::from_request('POST', common_local_url('accesstoken')); common_debug('getting a server', __FILE__); $server = omb_oauth_server(); common_debug('fetching the access token', __FILE__); -- cgit v1.2.3-54-g00ecf From aee641ee1e311fb0af0f9f6d75ca7fae2c7d8477 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 29 Apr 2009 20:45:33 -0400 Subject: make replies use new query format --- classes/Notice.php | 4 ++-- classes/Reply.php | 47 +++++++++++++++++++++++++++++++++++++++++++++-- classes/User.php | 10 +++------- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/classes/Notice.php b/classes/Notice.php index 2bb466155..808631f4d 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -380,9 +380,9 @@ class Notice extends Memcached_DataObject $reply->notice_id = $this->id; if ($reply->find()) { while ($reply->fetch()) { - $cache->delete(common_cache_key('user:replies:'.$reply->profile_id)); + $cache->delete(common_cache_key('reply:stream:'.$reply->profile_id)); if ($blowLast) { - $cache->delete(common_cache_key('user:replies:'.$reply->profile_id.';last')); + $cache->delete(common_cache_key('reply:stream:'.$reply->profile_id.';last')); } } } diff --git a/classes/Reply.php b/classes/Reply.php index af86aaf87..4439053b4 100644 --- a/classes/Reply.php +++ b/classes/Reply.php @@ -4,7 +4,7 @@ */ require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; -class Reply extends Memcached_DataObject +class Reply extends Memcached_DataObject { ###START_AUTOCODE /* the code below is auto generated do not remove the above tag */ @@ -13,7 +13,7 @@ class Reply extends Memcached_DataObject public $notice_id; // int(4) primary_key not_null public $profile_id; // int(4) primary_key not_null public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP - public $replied_id; // int(4) + public $replied_id; // int(4) /* Static get */ function staticGet($k,$v=null) @@ -21,4 +21,47 @@ class Reply extends Memcached_DataObject /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE + + function stream($user_id, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null) + { + $ids = Notice::stream(array('Reply', '_streamDirect'), + array($user_id), + 'reply:stream:' . $user_id, + $offset, $limit, $since_id, $before_id, $since); + return $ids; + } + + function _streamDirect($user_id, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null) + { + $reply = new Reply(); + $reply->profile_id = $user_id; + + if ($since_id != 0) { + $reply->whereAdd('notice_id > ' . $since_id); + } + + if ($before_id != 0) { + $reply->whereAdd('notice_id < ' . $before_id); + } + + if (!is_null($since)) { + $reply->whereAdd('modified > \'' . date('Y-m-d H:i:s', $since) . '\''); + } + + $reply->orderBy('notice_id DESC'); + + if (!is_null($offset)) { + $reply->limit($offset, $limit); + } + + $ids = array(); + + if ($reply->find()) { + while ($reply->fetch()) { + $ids[] = $reply->notice_id; + } + } + + return $ids; + } } diff --git a/classes/User.php b/classes/User.php index ce7ea1464..b76e45c33 100644 --- a/classes/User.php +++ b/classes/User.php @@ -401,13 +401,9 @@ class User extends Memcached_DataObject function getReplies($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null) { - $qry = - 'SELECT notice.* ' . - 'FROM notice JOIN reply ON notice.id = reply.notice_id ' . - 'WHERE reply.profile_id = %d '; - return Notice::getStream(sprintf($qry, $this->id), - 'user:replies:'.$this->id, - $offset, $limit, $since_id, $before_id, null, $since); + $ids = Reply::stream($this->id, $offset, $limit, $since_id, $before_id, $since); + common_debug("Ids = " . implode(',', $ids)); + return Notice::getStreamByIds($ids); } function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null) -- cgit v1.2.3-54-g00ecf From fb8340fb5429e632841b0be66d63dbdc512382ca Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 1 May 2009 03:50:24 +0000 Subject: Added laconica logo Updated installation page markup --- install.php | 161 ++++++++++++++++++++++++++++--------------------- theme/default/logo.png | Bin 0 -> 2228 bytes 2 files changed, 93 insertions(+), 68 deletions(-) create mode 100644 theme/default/logo.png diff --git a/install.php b/install.php index 87a99a650..66e8e8712 100644 --- a/install.php +++ b/install.php @@ -52,23 +52,21 @@ function checkPrereqs() foreach ($reqs as $req) { if (!checkExtension($req)) { - ?>

    Cannot load required extension "".

    Cannot load required extension:

    Cannot write config file to "".

    -

    On your server, try this command:

    -
    chmod a+w
    + ?>

    Cannot write config file to:

    +

    On your server, try this command: chmod a+w

    Cannot write avatar directory "/avatar/".

    -

    On your server, try this command:

    -
    chmod a+w /avatar/
    + ?>

    Cannot write avatar directory: /avatar/

    +

    On your server, try this command: chmod a+w /avatar/

    -

    Enter your database connection information below to initialize the database.

    -
    -
    -
      -
    • - - -

      The name of your site

      -
    • -
    • -
    • - - -

      Database hostname

      -
    • -
    • - - -

      Database name

      -
    • -
    • - - -

      Database username

      -
    • -
    • - - -

      Database password

      -
    • -
    - -
    + + +
    +
    +
    Page notice
    +
    +
    +

    Enter your database connection information below to initialize the database.

    +
    +
    +
    + +
    + Connection settings +
      +
    • + + +

      The name of your site

      +
    • +
    • +
    • + + +

      Database hostname

      +
    • +
    • + + +

      Database name

      +
    • +
    • + + +

      Database username

      +
    • +
    • + + +

      Database password

      +
    • +
    + +
    - -
  • - -
  • -> + + -
      - +
      +
      Page notice
      +
      +
        + -
      - - - - Install Laconica - - - - - -
      -
      -
      -

      Install Laconica

      + xml version="1.0" encoding="UTF-8" "; ?> + + + + Install Laconica + + + + + + + +
      + +
      +
      +

      Install Laconica

      -
      -
      -
      - +
      +
      +
      + diff --git a/theme/default/logo.png b/theme/default/logo.png new file mode 100644 index 000000000..fdead6c4a Binary files /dev/null and b/theme/default/logo.png differ -- cgit v1.2.3-54-g00ecf From 10d42ce3920596ec6f36179e597dd3db257b8def Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 1 May 2009 04:39:49 +0000 Subject: Giving more contrast between the background colour and the laconica logo. --- theme/default/css/display.css | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/theme/default/css/display.css b/theme/default/css/display.css index 0c8fae166..1fc99eff7 100644 --- a/theme/default/css/display.css +++ b/theme/default/css/display.css @@ -12,7 +12,7 @@ html, body, a:active { -background-color:#97BFD1; +background-color:#C3D6DF; } body { font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; @@ -30,7 +30,7 @@ input, textarea, select, border-color:#aaa; } #filter_tags ul li { -border-color:#97BFD1; +border-color:#C3D6DF; } .form_settings input.form_action-secondary { @@ -69,7 +69,7 @@ color:#002E6E; border-top-color:#D1D9E4; } .section .profile { -border-top-color:#97BFD1; +border-top-color:#C3D6DF; } #content .notice p.entry-content a:visited { @@ -120,7 +120,7 @@ background-color:#EFF3DC; } #anon_notice { -background-color:#97BFD1; +background-color:#C3D6DF; color:#fff; border-color:#fff; } @@ -163,7 +163,7 @@ color:#fff; .form_user_unsubscribe input.submit, .form_group_leave input.submit, .form_user_authorization input.reject { -background-color:#97BFD1; +background-color:#C3D6DF; } .entity_edit a { -- cgit v1.2.3-54-g00ecf From 8a142b272c87678268106df48497b90664be323a Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 1 May 2009 07:08:01 -0400 Subject: ignore Eclipse project files --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 83a53dfa3..da6947bfd 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,6 @@ dataobject.ini *.rej .#* *.swp +.buildpath +.project +.settings -- cgit v1.2.3-54-g00ecf From 9cac6413a342445a998773458b215d129c2be2d1 Mon Sep 17 00:00:00 2001 From: Ori Avtalion Date: Fri, 1 May 2009 07:11:28 -0400 Subject: Add s to user favorite notices --- actions/favoritesrss.php | 2 +- actions/showfavorites.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/actions/favoritesrss.php b/actions/favoritesrss.php index f85bf1b19..6b46b8dec 100644 --- a/actions/favoritesrss.php +++ b/actions/favoritesrss.php @@ -107,7 +107,7 @@ class FavoritesrssAction extends Rss10Action $c = array('url' => common_local_url('favoritesrss', array('nickname' => $user->nickname)), - 'title' => sprintf(_("%s favorite notices"), $user->nickname), + 'title' => sprintf(_("%s's favorite notices"), $user->nickname), 'link' => common_local_url('showfavorites', array('nickname' => $user->nickname)), diff --git a/actions/showfavorites.php b/actions/showfavorites.php index 6e011d5ca..eed62a2ab 100644 --- a/actions/showfavorites.php +++ b/actions/showfavorites.php @@ -74,9 +74,9 @@ class ShowfavoritesAction extends Action function title() { if ($this->page == 1) { - return sprintf(_("%s favorite notices"), $this->user->nickname); + return sprintf(_("%s's favorite notices"), $this->user->nickname); } else { - return sprintf(_("%s favorite notices, page %d"), + return sprintf(_("%s's favorite notices, page %d"), $this->user->nickname, $this->page); } -- cgit v1.2.3-54-g00ecf From c5e72e248fa70b5e038c74b73b581884112706d5 Mon Sep 17 00:00:00 2001 From: Ori Avtalion Date: Fri, 1 May 2009 07:12:13 -0400 Subject: Several whitespace fixes --- actions/openidsettings.php | 4 ++-- actions/recoverpassword.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/actions/openidsettings.php b/actions/openidsettings.php index 92469d20f..5f59ebc01 100644 --- a/actions/openidsettings.php +++ b/actions/openidsettings.php @@ -67,8 +67,8 @@ class OpenidsettingsAction extends AccountSettingsAction function getInstructions() { - return _('[OpenID](%%doc.openid%%) lets you log into many sites ' . - ' with the same user account. '. + return _('[OpenID](%%doc.openid%%) lets you log into many sites' . + ' with the same user account.'. ' Manage your associated OpenIDs from here.'); } diff --git a/actions/recoverpassword.php b/actions/recoverpassword.php index 620fe7eb8..82263fcd5 100644 --- a/actions/recoverpassword.php +++ b/actions/recoverpassword.php @@ -151,11 +151,11 @@ class RecoverpasswordAction extends Action $this->element('p', null, _('If you\'ve forgotten or lost your' . ' password, you can get a new one sent to' . - ' the email address you have stored ' . + ' the email address you have stored' . ' in your account.')); } else if ($this->mode == 'reset') { $this->element('p', null, - _('You\'ve been identified. Enter a ' . + _('You\'ve been identified. Enter a' . ' new password below. ')); } $this->elementEnd('div'); -- cgit v1.2.3-54-g00ecf From 609ac4c22463af88c206968134ab16e75e500edd Mon Sep 17 00:00:00 2001 From: Ori Avtalion Date: Fri, 1 May 2009 07:12:37 -0400 Subject: Fix link to identi.ca in JavaScript badge --- js/identica-badge.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/identica-badge.js b/js/identica-badge.js index 869230b7a..ffa55ae93 100644 --- a/js/identica-badge.js +++ b/js/identica-badge.js @@ -128,7 +128,7 @@ var a = document.createElement('A'); a.innerHTML = 'get this'; a.target = '_blank'; - a.href = 'http://identica/doc/badge'; + a.href = 'http://identi.ca/doc/badge'; $.s.f.appendChild(a); $.s.appendChild($.s.f); $.f.getUser(); -- cgit v1.2.3-54-g00ecf From a86a0e91a5acb5ea894a3d066f9adf3b1ef305ae Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 1 May 2009 08:00:37 -0700 Subject: add favor, reply, delete buttons for cometed notices --- plugins/Comet/CometPlugin.php | 16 ++++++++- plugins/Comet/updatetimeline.js | 74 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 85 insertions(+), 5 deletions(-) diff --git a/plugins/Comet/CometPlugin.php b/plugins/Comet/CometPlugin.php index 2e0bb40a4..48ac9dcad 100644 --- a/plugins/Comet/CometPlugin.php +++ b/plugins/Comet/CometPlugin.php @@ -82,8 +82,22 @@ class CometPlugin extends Plugin ' '); } + $user = common_current_user(); + + if (!empty($user->id)) { + $user_id = $user->id; + } else { + $user_id = 0; + } + + $replyurl = common_local_url('newnotice'); + $favorurl = common_local_url('favor'); + // FIXME: need to find a better way to pass this pattern in + $deleteurl = common_local_url('deletenotice', + array('notice' => '0000000000')); + $action->elementStart('script', array('type' => 'text/javascript')); - $action->raw("$(document).ready(function() { updater.init(\"$this->server\", \"$timeline\");});"); + $action->raw("$(document).ready(function() { updater.init(\"$this->server\", \"$timeline\", $user_id, \"$replyurl\", \"$favorurl\", \"$deleteurl\"); });"); $action->elementEnd('script'); return true; diff --git a/plugins/Comet/updatetimeline.js b/plugins/Comet/updatetimeline.js index de750baba..e89b3bddf 100644 --- a/plugins/Comet/updatetimeline.js +++ b/plugins/Comet/updatetimeline.js @@ -3,14 +3,26 @@ var updater = function() { + var _server; + var _timeline; + var _userid; + var _replyurl; + var _favorurl; + var _deleteurl; var _cometd; return { - init: function(server, timeline) + init: function(server, timeline, userid, replyurl, favorurl, deleteurl) { _cometd = $.cometd; // Uses the default Comet object _cometd.setLogLevel('debug'); _cometd.init(server); + _server = server; + _timeline = timeline; + _userid = userid; + _favorurl = favorurl; + _replyurl = replyurl; + _deleteurl = deleteurl; _cometd.subscribe(timeline, receive); $(window).unload(leave); } @@ -34,7 +46,7 @@ var updater = function() var noticeItem = makeNoticeItem(message.data); $("#notices_primary .notices").prepend(noticeItem, true); $("#notices_primary .notice:first").css({display:"none"}); - $("#notices_primary .notice:first").fadeIn(2500); + $("#notices_primary .notice:first").fadeIn(1000); NoticeHover(); NoticeReply(); } @@ -68,10 +80,64 @@ var updater = function() "
      "+data['source']+"
      "+ "
      "+ ""+ - "
      "+ - "
      "+ + "
      "; + + if (_userid != 0) { + var input = $("form#form_notice fieldset input#token"); + var session_key = input.val(); + ni = ni+makeFavoriteForm(data['id'], session_key); + ni = ni+makeReplyLink(data['id'], data['user']['screen_name']); + if (_userid == data['user']['id']) { + ni = ni+makeDeleteLink(data['id']); + } + } + + ni = ni+"
      "+ ""; return ni; } + + function makeFavoriteForm(id, session_key) + { + var ff; + + ff = "
      "+ + "
      "+ + "Favor this notice"+ // XXX: i18n + ""+ + ""+ + ""+ + "
      "+ + "
      "; + return ff; + } + + function makeReplyLink(id, nickname) + { + var rl; + rl = "
      "+ + "
      Reply to this notice
      "+ + "
      "+ + "Reply "+id+""+ + ""+ + "
      "+ + "
      "; + return rl; + } + + function makeDeleteLink(id) + { + var dl, delurl; + delurl = _deleteurl.replace("0000000000", id); + + dl = "
      "+ + "
      Delete this notice
      "+ + "
      "+ + "Delete"+ + "
      "+ + "
      "; + + return dl; + } }(); -- cgit v1.2.3-54-g00ecf From 5affe093aba97a0e4ac559b685a240d568929ffb Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 1 May 2009 08:39:47 -0700 Subject: add in_reply_to link and make HTML in source work correctly --- plugins/Comet/CometPlugin.php | 9 +++++++++ plugins/Comet/updatetimeline.js | 19 +++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/plugins/Comet/CometPlugin.php b/plugins/Comet/CometPlugin.php index 48ac9dcad..0f2fcd701 100644 --- a/plugins/Comet/CometPlugin.php +++ b/plugins/Comet/CometPlugin.php @@ -158,6 +158,15 @@ class CometPlugin extends Plugin $arr = $act->twitter_status_array($notice, true); $arr['url'] = $notice->bestUrl(); $arr['html'] = htmlspecialchars($notice->rendered); + $arr['source'] = htmlspecialchars($arr['source']); + + if (!empty($notice->reply_to)) { + $reply_to = Notice::staticGet('id', $notice->reply_to); + if (!empty($reply_to)) { + $arr['in_reply_to_status_url'] = $reply_to->bestUrl(); + } + $reply_to = null; + } $profile = $notice->getProfile(); $arr['user']['profile_url'] = $profile->profileurl; diff --git a/plugins/Comet/updatetimeline.js b/plugins/Comet/updatetimeline.js index e89b3bddf..170949e9b 100644 --- a/plugins/Comet/updatetimeline.js +++ b/plugins/Comet/updatetimeline.js @@ -54,7 +54,8 @@ var updater = function() function makeNoticeItem(data) { user = data['user']; - html = data['html'].replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>'); + html = data['html'].replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"'); + source = data['source'].replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"'); ni = "
    • "+ "
      "+ @@ -77,9 +78,19 @@ var updater = function() ""+ "
      "+ "
      From
      "+ - "
      "+data['source']+"
      "+ - "
      "+ - "
      "+ + "
      "+source+"
      "+ // may have a link, I think + ""; + + if (data['in_reply_to_status_id']) { + ni = ni+"
      "+ + "
      To
      "+ + "
      "+ + "in reply to"+ + "
      "+ + "
      "; + } + + ni = ni+""+ "
      "; if (_userid != 0) { -- cgit v1.2.3-54-g00ecf From b12e72ae312488caf7cb1e1a396eb05dd38326a9 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 1 May 2009 09:42:38 -0700 Subject: optionally add a username/password on server side for Comet --- plugins/Comet/CometPlugin.php | 8 +++++--- plugins/Comet/bayeux.class.inc.php | 9 ++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/plugins/Comet/CometPlugin.php b/plugins/Comet/CometPlugin.php index 0f2fcd701..45251c66f 100644 --- a/plugins/Comet/CometPlugin.php +++ b/plugins/Comet/CometPlugin.php @@ -45,9 +45,11 @@ class CometPlugin extends Plugin { var $server = null; - function __construct($server=null) + function __construct($server=null, $username=null, $password=null) { - $this->server = $server; + $this->server = $server; + $this->username = $username; + $this->password = $password; parent::__construct(); } @@ -131,7 +133,7 @@ class CometPlugin extends Plugin $json = $this->noticeAsJson($notice); // Bayeux? Comet? Huh? These terms confuse me - $bay = new Bayeux($this->server); + $bay = new Bayeux($this->server, $this->user, $this->password); foreach ($timelines as $timeline) { $this->log(LOG_INFO, "Posting notice $notice->id to '$timeline'."); diff --git a/plugins/Comet/bayeux.class.inc.php b/plugins/Comet/bayeux.class.inc.php index 785d3e393..39ad8a8fc 100644 --- a/plugins/Comet/bayeux.class.inc.php +++ b/plugins/Comet/bayeux.class.inc.php @@ -26,9 +26,12 @@ class Bayeux private $oCurl = ''; private $nNextId = 0; + private $sUser = ''; + private $sPassword = ''; + public $sUrl = ''; - function __construct($sUrl) + function __construct($sUrl, $sUser='', $sPassword='') { $this->sUrl = $sUrl; @@ -43,6 +46,10 @@ class Bayeux curl_setopt($this->oCurl, CURLOPT_POST, 1); curl_setopt($this->oCurl, CURLOPT_RETURNTRANSFER,1); + if (!is_null($sUser) && mb_strlen($sUser) > 0) { + curl_setopt($this->oCurl, CURLOPT_USERPWD,"$sUser:$sPassword"); + } + $this->handShake(); } -- cgit v1.2.3-54-g00ecf From deb07487bd0802fa6a89cfc8ddd56af93945eb4c Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 1 May 2009 17:00:36 +0000 Subject: 60 seconds hard timeout for XHR notice posting. JavaScript throws an alert message to the client if the server doesn't respond back in any way. --- js/util.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/js/util.js b/js/util.js index f15c4f2bb..3f14bc61c 100644 --- a/js/util.js +++ b/js/util.js @@ -166,14 +166,20 @@ $(document).ready(function(){ $("#notice_action-submit").addClass("disabled"); return true; }, + timeout: '60000', error: function (xhr, textStatus, errorThrown) { $("#form_notice").removeClass("processing"); $("#notice_action-submit").removeAttr("disabled"); $("#notice_action-submit").removeClass("disabled"); - if ($(".error", xhr.responseXML).length > 0) { - $('#form_notice').append(document._importNode($(".error", xhr.responseXML).get(0), true)); + if (textStatus == "timeout") { + alert ("Sorry! We had trouble sending your notice. The servers are overloaded. Please try again, and contact the site administrator if this problem persists"); } else { - alert("Sorry! We had trouble sending your notice ("+xhr.status+" "+xhr.statusText+"). Please report the problem to the site administrator if this happens again."); + if ($(".error", xhr.responseXML).length > 0) { + $('#form_notice').append(document._importNode($(".error", xhr.responseXML).get(0), true)); + } + else { + alert("Sorry! We had trouble sending your notice ("+xhr.status+" "+xhr.statusText+"). Please report the problem to the site administrator if this happens again."); + } } }, success: function(xml) { if ($("#error", xml).length > 0) { @@ -189,7 +195,6 @@ $(document).ready(function(){ } else { li = $("li", xml).get(0); - id = li.id; if ($("#"+li.id).length == 0) { $("#notices_primary .notices").prepend(document._importNode(li, true)); $("#notices_primary .notice:first").css({display:"none"}); -- cgit v1.2.3-54-g00ecf From 3328ec545c36fc2408cdb9d048effe24feafe218 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 1 May 2009 11:27:57 -0700 Subject: make profile notice getting use ids --- classes/Notice.php | 6 +++--- classes/Profile.php | 53 +++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/classes/Notice.php b/classes/Notice.php index 808631f4d..eceed325b 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -363,10 +363,10 @@ class Notice extends Memcached_DataObject { if ($this->is_local) { $cache = common_memcache(); - if ($cache) { - $cache->delete(common_cache_key('profile:notices:'.$this->profile_id)); + if (!empty($cache)) { + $cache->delete(common_cache_key('profile:notice_ids:'.$this->profile_id)); if ($blowLast) { - $cache->delete(common_cache_key('profile:notices:'.$this->profile_id.';last')); + $cache->delete(common_cache_key('profile:notice_ids:'.$this->profile_id.';last')); } } } diff --git a/classes/Profile.php b/classes/Profile.php index f3bfe299c..ae5641d79 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -155,14 +155,51 @@ class Profile extends Memcached_DataObject function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0) { - $qry = - 'SELECT * ' . - 'FROM notice ' . - 'WHERE profile_id = %d '; - - return Notice::getStream(sprintf($qry, $this->id), - 'profile:notices:'.$this->id, - $offset, $limit, $since_id, $before_id); + // XXX: I'm not sure this is going to be any faster. It probably isn't. + $ids = Notice::stream(array($this, '_streamDirect'), + array(), + 'profile:notice_ids:' . $this->id, + $offset, $limit, $since_id, $before_id); + + return Notice::getStreamByIds($ids); + } + + function _streamDirect($offset, $limit, $since_id, $before_id, $since) + { + $notice = new Notice(); + + $notice->profile_id = $this->id; + + $notice->selectAdd(); + $notice->selectAdd('id'); + + if ($since_id != 0) { + $notice->whereAdd('id > ' . $since_id); + } + + if ($before_id != 0) { + $notice->whereAdd('id < ' . $before_id); + } + + if (!is_null($since)) { + $notice->whereAdd('created > \'' . date('Y-m-d H:i:s', $since) . '\''); + } + + $notice->orderBy('id DESC'); + + if (!is_null($offset)) { + $notice->limit($offset, $limit); + } + + $ids = array(); + + if ($notice->find()) { + while ($notice->fetch()) { + $ids[] = $notice->id; + } + } + + return $ids; } function isMember($group) -- cgit v1.2.3-54-g00ecf From 021b520a11d3449a1476182e1ad117582999d364 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 1 May 2009 11:38:50 -0700 Subject: Make user group stream use IDs --- classes/Notice.php | 4 ++-- classes/User_group.php | 53 ++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/classes/Notice.php b/classes/Notice.php index eceed325b..c036e6e9e 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -299,9 +299,9 @@ class Notice extends Memcached_DataObject $group_inbox->notice_id = $this->id; if ($group_inbox->find()) { while ($group_inbox->fetch()) { - $cache->delete(common_cache_key('group:notices:'.$group_inbox->group_id)); + $cache->delete(common_cache_key('user_group:notice_ids:' . $group_inbox->group_id)); if ($blowLast) { - $cache->delete(common_cache_key('group:notices:'.$group_inbox->group_id.';last')); + $cache->delete(common_cache_key('user_group:notice_ids:' . $group_inbox->group_id.';last')); } $member = new Group_member(); $member->group_id = $group_inbox->group_id; diff --git a/classes/User_group.php b/classes/User_group.php index d152f9d56..7cc31e702 100755 --- a/classes/User_group.php +++ b/classes/User_group.php @@ -50,13 +50,50 @@ class User_group extends Memcached_DataObject function getNotices($offset, $limit) { - $qry = - 'SELECT notice.* ' . - 'FROM notice JOIN group_inbox ON notice.id = group_inbox.notice_id ' . - 'WHERE group_inbox.group_id = %d '; - return Notice::getStream(sprintf($qry, $this->id), - 'group:notices:'.$this->id, - $offset, $limit); + $ids = Notice::stream(array($this, '_streamDirect'), + array(), + 'user_group:notice_ids:' . $this->id, + $offset, $limit); + + return Notice::getStreamByIds($ids); + } + + function _streamDirect($offset, $limit, $since_id, $before_id, $since) + { + $inbox = new Group_inbox(); + + $inbox->group_id = $this->id; + + $inbox->selectAdd(); + $inbox->selectAdd('notice_id'); + + if ($since_id != 0) { + $inbox->whereAdd('notice_id > ' . $since_id); + } + + if ($before_id != 0) { + $inbox->whereAdd('notice_id < ' . $before_id); + } + + if (!is_null($since)) { + $inbox->whereAdd('created > \'' . date('Y-m-d H:i:s', $since) . '\''); + } + + $inbox->orderBy('notice_id DESC'); + + if (!is_null($offset)) { + $inbox->limit($offset, $limit); + } + + $ids = array(); + + if ($inbox->find()) { + while ($inbox->fetch()) { + $ids[] = $inbox->notice_id; + } + } + + return $ids; } function allowedNickname($nickname) @@ -91,7 +128,7 @@ class User_group extends Memcached_DataObject function setOriginal($filename) { $imagefile = new ImageFile($this->id, Avatar::path($filename)); - + $orig = clone($this); $this->original_logo = Avatar::url($filename); $this->homepage_logo = Avatar::url($imagefile->resize(AVATAR_PROFILE_SIZE)); -- cgit v1.2.3-54-g00ecf From 5314d9b2cfaef3f2fd0ead262e18d1776fd99c8d Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 1 May 2009 12:01:28 -0700 Subject: make faves work with ids --- classes/Fave.php | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++-- classes/Notice.php | 4 ++-- classes/User.php | 38 +++++++++++++++++--------------------- 3 files changed, 70 insertions(+), 25 deletions(-) diff --git a/classes/Fave.php b/classes/Fave.php index 24df5938c..915b4572f 100644 --- a/classes/Fave.php +++ b/classes/Fave.php @@ -4,7 +4,7 @@ */ require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; -class Fave extends Memcached_DataObject +class Fave extends Memcached_DataObject { ###START_AUTOCODE /* the code below is auto generated do not remove the above tag */ @@ -31,9 +31,58 @@ class Fave extends Memcached_DataObject } return $fave; } - + function &pkeyGet($kv) { return Memcached_DataObject::pkeyGet('Fave', $kv); } + + function stream($user_id, $offset=0, $limit=NOTICES_PER_PAGE) + { + $ids = Notice::stream(array('Fave', '_streamDirect'), + array($user_id), + 'fave:ids_by_user:'.$user_id, + $offset, $limit); + return $ids; + } + + function _streamDirect($user_id, $offset, $limit, $since_id, $before_id, $since) + { + $fav = new Fave(); + + $fav->user_id = $user_id; + + $fav->selectAdd(); + $fav->selectAdd('notice_id'); + + if ($since_id != 0) { + $fav->whereAdd('notice_id > ' . $since_id); + } + + if ($before_id != 0) { + $fav->whereAdd('notice_id < ' . $before_id); + } + + if (!is_null($since)) { + $fav->whereAdd('modified > \'' . date('Y-m-d H:i:s', $since) . '\''); + } + + // NOTE: we sort by fave time, not by notice time! + + $fav->orderBy('modified DESC'); + + if (!is_null($offset)) { + $fav->limit($offset, $limit); + } + + $ids = array(); + + if ($fav->find()) { + while ($fav->fetch()) { + $ids[] = $fav->notice_id; + } + } + + return $ids; + } } diff --git a/classes/Notice.php b/classes/Notice.php index c036e6e9e..771a4e715 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -412,9 +412,9 @@ class Notice extends Memcached_DataObject $fave->notice_id = $this->id; if ($fave->find()) { while ($fave->fetch()) { - $cache->delete(common_cache_key('user:faves:'.$fave->user_id)); + $cache->delete(common_cache_key('fave:ids_by_user:'.$fave->user_id)); if ($blowLast) { - $cache->delete(common_cache_key('user:faves:'.$fave->user_id.';last')); + $cache->delete(common_cache_key('fave:ids_by_user:'.$fave->user_id.';last')); } } } diff --git a/classes/User.php b/classes/User.php index b76e45c33..b5ac7b220 100644 --- a/classes/User.php +++ b/classes/User.php @@ -349,30 +349,31 @@ class User extends Memcached_DataObject $cache = common_memcache(); // XXX: Kind of a hack. + if ($cache) { // This is the stream of favorite notices, in rev chron // order. This forces it into cache. - $faves = $this->favoriteNotices(0, NOTICE_CACHE_WINDOW); - $cnt = 0; - while ($faves->fetch()) { - if ($faves->id < $notice->id) { - // If we passed it, it's not a fave - return false; - } else if ($faves->id == $notice->id) { - // If it matches a cached notice, then it's a fave - return true; - } - $cnt++; + + $ids = Fave::stream($this->id, 0, NOTICE_CACHE_WINDOW); + + // If it's in the list, then it's a fave + + if (in_array($notice->id, $ids)) { + return true; } + // If we're not past the end of the cache window, // then the cache has all available faves, so this one // is not a fave. - if ($cnt < NOTICE_CACHE_WINDOW) { + + if (count($ids) < NOTICE_CACHE_WINDOW) { return false; } + // Otherwise, cache doesn't have all faves; // fall through to the default } + $fave = Fave::pkeyGet(array('user_id' => $this->id, 'notice_id' => $notice->id)); return ((is_null($fave)) ? false : true); @@ -418,13 +419,8 @@ class User extends Memcached_DataObject function favoriteNotices($offset=0, $limit=NOTICES_PER_PAGE) { - $qry = - 'SELECT notice.* ' . - 'FROM notice JOIN fave ON notice.id = fave.notice_id ' . - 'WHERE fave.user_id = %d '; - return Notice::getStream(sprintf($qry, $this->id), - 'user:faves:'.$this->id, - $offset, $limit); + $ids = Fave::stream($this->id, $offset, $limit); + return Notice::getStreamByIds($ids); } function noticesWithFriends($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null) @@ -459,8 +455,8 @@ class User extends Memcached_DataObject if ($cache) { // Faves don't happen chronologically, so we need to blow // ;last cache, too - $cache->delete(common_cache_key('user:faves:'.$this->id)); - $cache->delete(common_cache_key('user:faves:'.$this->id).';last'); + $cache->delete(common_cache_key('fave:ids_by_user:'.$this->id)); + $cache->delete(common_cache_key('fave:ids_by_user:'.$this->id.';last')); } } -- cgit v1.2.3-54-g00ecf From 1fde80cf73c3cf43e3613f7f57fe213df688a1ec Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 1 May 2009 23:32:59 +0000 Subject: Minor CSS updates (No min-height on shownotice page, site_notice is floated instead of positioned absolutely, notice entry-content is aligned with the nickname on shownotice page) --- theme/base/css/display.css | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/theme/base/css/display.css b/theme/base/css/display.css index efa5f4ac6..c242977a9 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -248,10 +248,10 @@ display:none; } #site_notice { -position:absolute; -top:65px; -right:18px; -width:250px; +float:right; +clear:right; +margin-top:7px; +margin-right:18px; width:24%; } #page_notice { @@ -397,6 +397,9 @@ border-radius:7px; border-style:solid; border-width:1px; } +#shownotice #content { +min-height:0; +} #content_inner { position:relative; @@ -812,11 +815,14 @@ clear:left; float:left; font-size:0.95em; margin-left:59px; -width:70%; +width:65%; } #showstream .notice div.entry-content { margin-left:0; } +#shownotice .notice div.entry-content { +margin-left:108px; +} .notice .notice-options a, .notice .notice-options input { -- cgit v1.2.3-54-g00ecf From 51377258a1660fee02a3f92436dc40ee40f2a88d Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Sat, 2 May 2009 00:10:50 +0000 Subject: Aligned shownotice page's entry-content to left. Fixing vcard photo margin bottom value. --- theme/base/css/display.css | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/theme/base/css/display.css b/theme/base/css/display.css index c242977a9..10fc63638 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -769,16 +769,14 @@ overflow:hidden; font-weight:bold; } -.notice .author .photo { -margin-bottom:0; -} - .vcard .photo { display:inline; margin-right:11px; -margin-bottom:11px; float:left; } +#shownotice .vcard .photo { +margin-bottom:4px; +} .vcard .url { text-decoration:none; } @@ -817,11 +815,9 @@ font-size:0.95em; margin-left:59px; width:65%; } -#showstream .notice div.entry-content { -margin-left:0; -} +#showstream .notice div.entry-content, #shownotice .notice div.entry-content { -margin-left:108px; +margin-left:0; } .notice .notice-options a, -- cgit v1.2.3-54-g00ecf From 6a12598695637e7ebdc613977c797413957cc464 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 3 May 2009 21:36:03 -0700 Subject: add pingvine notice source --- db/notice_source.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/db/notice_source.sql b/db/notice_source.sql index ce44f3235..17720028d 100644 --- a/db/notice_source.sql +++ b/db/notice_source.sql @@ -24,6 +24,7 @@ VALUES ('peoplebrowsr', 'PeopleBrowsr', 'http://www.peoplebrowsr.com/', now()), ('Pikchur','Pikchur','http://www.pikchur.com/', now()), ('Ping.fm','Ping.fm','http://ping.fm/', now()), + ('pingvine','PingVine','http://pingvine.com/', now()), ('pocketwit','PockeTwit','http://code.google.com/p/pocketwit/', now()), ('posty','Posty','http://spreadingfunkyness.com/posty/', now()), ('royalewithcheese','Royale With Cheese','http://p.hellyeah.org/', now()), -- cgit v1.2.3-54-g00ecf From 7f417cfee023b372a281f5e45a7593c09e279233 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 5 May 2009 19:28:57 +0000 Subject: More work on 2-way Twitter sync. Works better now with lastest version of DB_DataObject that automatically reconnects to the DB, but forked processes still lose connections occassionally. --- scripts/statusfetcher.php | 135 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 96 insertions(+), 39 deletions(-) diff --git a/scripts/statusfetcher.php b/scripts/statusfetcher.php index 8f4b60cf7..8c3ee4330 100644 --- a/scripts/statusfetcher.php +++ b/scripts/statusfetcher.php @@ -27,41 +27,20 @@ if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); define('LACONICA', true); +// Tune number of processes and how often to poll Twitter +define('MAXCHILDREN', 5); +define('POLL_INTERVAL', 60 * 5); // in seconds + // Uncomment this to get useful console output define('SCRIPT_DEBUG', true); require_once(INSTALLDIR . '/lib/common.php'); $children = array(); -$flink_ids = null; - -$MAXCHILDREN = 5; -$POLL_INTERVAL = 10; // 10 seconds do { - $flink = new Foreign_link(); - $flink->service = 1; // Twitter - $cnt = $flink->find(); - - if (defined('SCRIPT_DEBUG')) { - print "Updating Twitter friends subscriptions for $cnt users.\n"; - } - - $flink_ids = array(); - - // XXX: This only reliably happens once. After the first interation of - // the do loop, the ->find() doesn't work ... lost DB connection? - - while ($flink->fetch()) { - - if (($flink->noticesync & FOREIGN_NOTICE_RECV) == FOREIGN_NOTICE_RECV) { - $flink_ids[] = $flink->foreign_id; - } - } - - $flink->free(); - unset($flink); + $flink_ids = refreshFlinks(); foreach ($flink_ids as $f){ @@ -82,7 +61,6 @@ do { // Child // XXX: Each child needs its own DB connection - getTimeline($f); exit(); } @@ -96,11 +74,11 @@ do { } // Wait if we have too many kids - if(sizeof($children) > $MAXCHILDREN) { + if(sizeof($children) > MAXCHILDREN) { if (defined('SCRIPT_DEBUG')) { print "Too many children. Waiting...\n"; } - if( ($c = pcntl_wait($status, WUNTRACED) ) > 0){ + if(($c = pcntl_wait($status, WUNTRACED)) > 0){ if (defined('SCRIPT_DEBUG')) { print "Finished waiting for $c\n"; } @@ -119,14 +97,44 @@ do { // Rest for a bit before we fetch more statuses if (defined('SCRIPT_DEBUG')) { - print "Waiting $POLL_INTERVAL secs before hitting Twitter again.\n"; + print 'Waiting ' . POLL_INTERVAL . + " secs before hitting Twitter again.\n"; } - sleep($POLL_INTERVAL); + sleep(POLL_INTERVAL); } while (true); +function refreshFlinks() { + + global $config; + + $flink = new Foreign_link(); + $flink->service = 1; // Twitter + $flink->orderBy('last_noticesync'); + + $cnt = $flink->find(); + + if (defined('SCRIPT_DEBUG')) { + print "Updating Twitter friends subscriptions for $cnt users.\n"; + } + + $flinks = array(); + + while ($flink->fetch()) { + + if (($flink->noticesync & FOREIGN_NOTICE_RECV) == FOREIGN_NOTICE_RECV) { + $flinks[] = clone($flink); + } + } + + $flink->free(); + unset($flink); + + return $flinks; +} + function remove_ps(&$plist, $ps){ for($i = 0; $i < sizeof($plist); $i++){ if($plist[$i] == $ps){ @@ -137,22 +145,43 @@ function remove_ps(&$plist, $ps){ } } -function getTimeline($fid) +function getTimeline($flink) { - // XXX: Need to reconnect to the DB here? + global $config; + $config['db'] = &PEAR::getStaticProperty('DB_DataObject','options'); + require_once(INSTALLDIR . '/lib/common.php'); - $flink = Foreign_link::getByForeignID($fid, 1); - $fuser = $flink->getForeignUser(); + if (defined('SCRIPT_DEBUG')) { + print "Trying to get timeline for $flink->foreign_id\n"; + } + + if (empty($flink)) { + common_log(LOG_WARNING, "Can't retrieve Foreign_link for foreign ID $fid"); + if (defined('SCRIPT_DEBUG')) { + print "Can't retrieve Foreign_link for foreign ID $fid\n"; + } + return; + } + + $fuser = new Foreign_user(); + $fuser->service = 1; + $fuser->id = $flink->foreign_id; + $fuser->limit(1); + $fuser->find(true); if (empty($fuser)) { common_log(LOG_WARNING, "Unmatched user for ID " . $flink->user_id); if (defined('SCRIPT_DEBUG')) { print "Unmatched user for ID $flink->user_id\n"; } + return; } - $screenname = $fuser->nickname; + if (defined('SCRIPT_DEBUG')) { + // XXX: This is horrible and must be removed before releasing this + print 'username: ' . $fuser->nickname . ' password: ' . $flink->credentials . "\n"; + } $url = 'http://twitter.com/statuses/friends_timeline.json'; @@ -181,10 +210,19 @@ function getTimeline($fid) saveStatus($status, $flink); } + // Okay, record the time we synced with Twitter for posterity + + $flink->last_noticesync = common_sql_now(); + $flink->update(); } function saveStatus($status, $flink) { + + global $config; + $config['db'] = &PEAR::getStaticProperty('DB_DataObject','options'); + require_once(INSTALLDIR . '/lib/common.php'); + // Do we have a profile for this Twitter user? $id = ensureProfile($status->user); @@ -244,6 +282,9 @@ function saveStatus($status, $flink) $notice->query('COMMIT'); + if (defined('SCRIPT_DEBUG')) { + print "Saved status $status->id as notice $notice->id.\n"; + } } if (!Notice_inbox::staticGet('notice_id', $notice->id)) { @@ -260,6 +301,7 @@ function saveStatus($status, $flink) function ensureProfile($user) { + global $config; // check to see if there's already a profile for this user $profileurl = 'http://twitter.com/' . $user->screen_name; @@ -328,8 +370,6 @@ function ensureProfile($user) } $profile->query("COMMIT"); - $profile->free(); - unset($profile); saveAvatars($user, $id); @@ -339,6 +379,8 @@ function ensureProfile($user) function checkAvatar($user, $profile) { + global $config; + $path_parts = pathinfo($user->profile_image_url); $newname = 'Twitter_' . $user->id . '_' . $path_parts['basename']; @@ -393,6 +435,8 @@ function getMediatype($ext) function saveAvatars($user, $id) { + global $config; + $path_parts = pathinfo($user->profile_image_url); $ext = $path_parts['extension']; $end = strlen('_normal' . $ext); @@ -418,7 +462,12 @@ function saveAvatars($user, $id) function updateAvatar($profile_id, $size, $mediatype, $filename) { - common_debug("updating avatar: $size"); + global $config; + + common_debug("Updating avatar: $size"); + if (defined('SCRIPT_DEBUG')) { + print "Updating avatar: $size\n"; + } $profile = Profile::staticGet($profile_id); @@ -444,6 +493,8 @@ function updateAvatar($profile_id, $size, $mediatype, $filename) { function newAvatar($profile_id, $size, $mediatype, $filename) { + global $config; + $avatar = new Avatar(); $avatar->profile_id = $profile_id; @@ -471,6 +522,9 @@ function newAvatar($profile_id, $size, $mediatype, $filename) $avatar->url = Avatar::url($filename); common_debug("new filename: $avatar->url"); + if (defined('SCRIPT_DEBUG')) { + print "New filename: $avatar->url\n"; + } $avatar->created = common_sql_now(); @@ -486,6 +540,9 @@ function newAvatar($profile_id, $size, $mediatype, $filename) } common_debug("Saved new $size avatar for $profile_id."); + if (defined('SCRIPT_DEBUG')) { + print "Saved new $size avatar for $profile_id.\n"; + } return $id; } -- cgit v1.2.3-54-g00ecf From 99e8f3235f2718f46cc95966ae39e725ee31a7df Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Wed, 6 May 2009 01:12:26 +0000 Subject: This finally works (provided the newer version of DB_DataObject that auto-reconnects to the DB). --- scripts/statusfetcher.php | 85 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 81 insertions(+), 4 deletions(-) diff --git a/scripts/statusfetcher.php b/scripts/statusfetcher.php index 8c3ee4330..82ae5bfd4 100644 --- a/scripts/statusfetcher.php +++ b/scripts/statusfetcher.php @@ -29,7 +29,11 @@ define('LACONICA', true); // Tune number of processes and how often to poll Twitter define('MAXCHILDREN', 5); +<<<<<<< HEAD:scripts/statusfetcher.php +define('POLL_INTERVAL', 60 * 10); // in seconds +======= define('POLL_INTERVAL', 60 * 5); // in seconds +>>>>>>> b8c700a7454db825b3867eadfa22afa1e5eb4f6c:scripts/statusfetcher.php // Uncomment this to get useful console output define('SCRIPT_DEBUG', true); @@ -40,9 +44,20 @@ $children = array(); do { +<<<<<<< HEAD:scripts/statusfetcher.php + $flinks = refreshFlinks(); + + foreach ($flinks as $f){ + + // We have to disconnect from the DB before forking so + // each process will open its own connection and + // avoid stomping on each other +======= $flink_ids = refreshFlinks(); +>>>>>>> b8c700a7454db825b3867eadfa22afa1e5eb4f6c:scripts/statusfetcher.php - foreach ($flink_ids as $f){ + $conn = &$f->getDatabaseConnection(); + $conn->disconnect(); $pid = pcntl_fork(); @@ -50,38 +65,60 @@ do { die ("Couldn't fork!"); } - // Parent if ($pid) { + + // Parent + if (defined('SCRIPT_DEBUG')) { print "Parent: forked " . $pid . "\n"; } + $children[] = $pid; + } else { // Child +<<<<<<< HEAD:scripts/statusfetcher.php + getTimeline($f, $child_db_name); +======= // XXX: Each child needs its own DB connection getTimeline($f); +>>>>>>> b8c700a7454db825b3867eadfa22afa1e5eb4f6c:scripts/statusfetcher.php exit(); } // Remove child from ps list as it finishes while(($c = pcntl_wait($status, WNOHANG OR WUNTRACED)) > 0) { + if (defined('SCRIPT_DEBUG')) { print "Child $c finished.\n"; } + remove_ps($children, $c); } // Wait if we have too many kids +<<<<<<< HEAD:scripts/statusfetcher.php + if (sizeof($children) > MAXCHILDREN) { + + if (defined('SCRIPT_DEBUG')) { + print "Too many children. Waiting...\n"; + } + + if (($c = pcntl_wait($status, WUNTRACED)) > 0){ + +======= if(sizeof($children) > MAXCHILDREN) { if (defined('SCRIPT_DEBUG')) { print "Too many children. Waiting...\n"; } if(($c = pcntl_wait($status, WUNTRACED)) > 0){ +>>>>>>> b8c700a7454db825b3867eadfa22afa1e5eb4f6c:scripts/statusfetcher.php if (defined('SCRIPT_DEBUG')) { print "Finished waiting for $c\n"; } + remove_ps($children, $c); } } @@ -89,13 +126,17 @@ do { // Remove all children from the process list before restarting while(($c = pcntl_wait($status, WUNTRACED)) > 0) { + if (defined('SCRIPT_DEBUG')) { print "Child $c finished.\n"; } + remove_ps($children, $c); } // Rest for a bit before we fetch more statuses + common_debug('Waiting ' . POLL_INTERVAL . + ' secs before hitting Twitter again.'); if (defined('SCRIPT_DEBUG')) { print 'Waiting ' . POLL_INTERVAL . " secs before hitting Twitter again.\n"; @@ -108,8 +149,11 @@ do { function refreshFlinks() { +<<<<<<< HEAD:scripts/statusfetcher.php +======= global $config; +>>>>>>> b8c700a7454db825b3867eadfa22afa1e5eb4f6c:scripts/statusfetcher.php $flink = new Foreign_link(); $flink->service = 1; // Twitter $flink->orderBy('last_noticesync'); @@ -136,8 +180,8 @@ function refreshFlinks() { } function remove_ps(&$plist, $ps){ - for($i = 0; $i < sizeof($plist); $i++){ - if($plist[$i] == $ps){ + for ($i = 0; $i < sizeof($plist); $i++) { + if ($plist[$i] == $ps) { unset($plist[$i]); $plist = array_values($plist); break; @@ -148,6 +192,17 @@ function remove_ps(&$plist, $ps){ function getTimeline($flink) { +<<<<<<< HEAD:scripts/statusfetcher.php + if (empty($flink)) { + common_log(LOG_WARNING, "Can't retrieve Foreign_link for foreign ID $fid"); + if (defined('SCRIPT_DEBUG')) { + print "Can't retrieve Foreign_link for foreign ID $fid\n"; + } + return; + } + + $fuser = $flink->getForeignUser(); +======= global $config; $config['db'] = &PEAR::getStaticProperty('DB_DataObject','options'); require_once(INSTALLDIR . '/lib/common.php'); @@ -169,6 +224,7 @@ function getTimeline($flink) $fuser->id = $flink->foreign_id; $fuser->limit(1); $fuser->find(true); +>>>>>>> b8c700a7454db825b3867eadfa22afa1e5eb4f6c:scripts/statusfetcher.php if (empty($fuser)) { common_log(LOG_WARNING, "Unmatched user for ID " . $flink->user_id); @@ -178,9 +234,17 @@ function getTimeline($flink) return; } +<<<<<<< HEAD:scripts/statusfetcher.php + common_debug('Trying to get timeline for Twitter user ' . + "$fuser->nickname ($flink->foreign_id)."); + if (defined('SCRIPT_DEBUG')) { + print 'Trying to get timeline for Twitter user ' . + "$fuser->nickname ($flink->foreign_id).\n"; +======= if (defined('SCRIPT_DEBUG')) { // XXX: This is horrible and must be removed before releasing this print 'username: ' . $fuser->nickname . ' password: ' . $flink->credentials . "\n"; +>>>>>>> b8c700a7454db825b3867eadfa22afa1e5eb4f6c:scripts/statusfetcher.php } $url = 'http://twitter.com/statuses/friends_timeline.json'; @@ -218,6 +282,8 @@ function getTimeline($flink) function saveStatus($status, $flink) { +<<<<<<< HEAD:scripts/statusfetcher.php +======= global $config; $config['db'] = &PEAR::getStaticProperty('DB_DataObject','options'); @@ -225,6 +291,7 @@ function saveStatus($status, $flink) // Do we have a profile for this Twitter user? +>>>>>>> b8c700a7454db825b3867eadfa22afa1e5eb4f6c:scripts/statusfetcher.php $id = ensureProfile($status->user); $profile = Profile::staticGet($id); @@ -282,6 +349,10 @@ function saveStatus($status, $flink) $notice->query('COMMIT'); +<<<<<<< HEAD:scripts/statusfetcher.php + common_debug("Saved status $status->id as notice $notice->id."); +======= +>>>>>>> b8c700a7454db825b3867eadfa22afa1e5eb4f6c:scripts/statusfetcher.php if (defined('SCRIPT_DEBUG')) { print "Saved status $status->id as notice $notice->id.\n"; } @@ -301,8 +372,11 @@ function saveStatus($status, $flink) function ensureProfile($user) { +<<<<<<< HEAD:scripts/statusfetcher.php +======= global $config; +>>>>>>> b8c700a7454db825b3867eadfa22afa1e5eb4f6c:scripts/statusfetcher.php // check to see if there's already a profile for this user $profileurl = 'http://twitter.com/' . $user->screen_name; $profile = Profile::staticGet('profileurl', $profileurl); @@ -462,8 +536,11 @@ function saveAvatars($user, $id) function updateAvatar($profile_id, $size, $mediatype, $filename) { +<<<<<<< HEAD:scripts/statusfetcher.php +======= global $config; +>>>>>>> b8c700a7454db825b3867eadfa22afa1e5eb4f6c:scripts/statusfetcher.php common_debug("Updating avatar: $size"); if (defined('SCRIPT_DEBUG')) { print "Updating avatar: $size\n"; -- cgit v1.2.3-54-g00ecf From b291cb8a1be0eb272e1663fbf6c6dea17bdb71db Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Wed, 6 May 2009 01:26:06 +0000 Subject: Fix for previous bad patch I pushed (had conflict markers) Sorry about that. --- scripts/statusfetcher.php | 80 ----------------------------------------------- 1 file changed, 80 deletions(-) diff --git a/scripts/statusfetcher.php b/scripts/statusfetcher.php index 82ae5bfd4..5518e3aa8 100644 --- a/scripts/statusfetcher.php +++ b/scripts/statusfetcher.php @@ -29,11 +29,7 @@ define('LACONICA', true); // Tune number of processes and how often to poll Twitter define('MAXCHILDREN', 5); -<<<<<<< HEAD:scripts/statusfetcher.php define('POLL_INTERVAL', 60 * 10); // in seconds -======= -define('POLL_INTERVAL', 60 * 5); // in seconds ->>>>>>> b8c700a7454db825b3867eadfa22afa1e5eb4f6c:scripts/statusfetcher.php // Uncomment this to get useful console output define('SCRIPT_DEBUG', true); @@ -44,7 +40,6 @@ $children = array(); do { -<<<<<<< HEAD:scripts/statusfetcher.php $flinks = refreshFlinks(); foreach ($flinks as $f){ @@ -52,9 +47,6 @@ do { // We have to disconnect from the DB before forking so // each process will open its own connection and // avoid stomping on each other -======= - $flink_ids = refreshFlinks(); ->>>>>>> b8c700a7454db825b3867eadfa22afa1e5eb4f6c:scripts/statusfetcher.php $conn = &$f->getDatabaseConnection(); $conn->disconnect(); @@ -79,12 +71,7 @@ do { // Child -<<<<<<< HEAD:scripts/statusfetcher.php getTimeline($f, $child_db_name); -======= - // XXX: Each child needs its own DB connection - getTimeline($f); ->>>>>>> b8c700a7454db825b3867eadfa22afa1e5eb4f6c:scripts/statusfetcher.php exit(); } @@ -99,7 +86,6 @@ do { } // Wait if we have too many kids -<<<<<<< HEAD:scripts/statusfetcher.php if (sizeof($children) > MAXCHILDREN) { if (defined('SCRIPT_DEBUG')) { @@ -108,13 +94,6 @@ do { if (($c = pcntl_wait($status, WUNTRACED)) > 0){ -======= - if(sizeof($children) > MAXCHILDREN) { - if (defined('SCRIPT_DEBUG')) { - print "Too many children. Waiting...\n"; - } - if(($c = pcntl_wait($status, WUNTRACED)) > 0){ ->>>>>>> b8c700a7454db825b3867eadfa22afa1e5eb4f6c:scripts/statusfetcher.php if (defined('SCRIPT_DEBUG')) { print "Finished waiting for $c\n"; } @@ -149,11 +128,6 @@ do { function refreshFlinks() { -<<<<<<< HEAD:scripts/statusfetcher.php -======= - global $config; - ->>>>>>> b8c700a7454db825b3867eadfa22afa1e5eb4f6c:scripts/statusfetcher.php $flink = new Foreign_link(); $flink->service = 1; // Twitter $flink->orderBy('last_noticesync'); @@ -192,7 +166,6 @@ function remove_ps(&$plist, $ps){ function getTimeline($flink) { -<<<<<<< HEAD:scripts/statusfetcher.php if (empty($flink)) { common_log(LOG_WARNING, "Can't retrieve Foreign_link for foreign ID $fid"); if (defined('SCRIPT_DEBUG')) { @@ -202,29 +175,6 @@ function getTimeline($flink) } $fuser = $flink->getForeignUser(); -======= - global $config; - $config['db'] = &PEAR::getStaticProperty('DB_DataObject','options'); - require_once(INSTALLDIR . '/lib/common.php'); - - if (defined('SCRIPT_DEBUG')) { - print "Trying to get timeline for $flink->foreign_id\n"; - } - - if (empty($flink)) { - common_log(LOG_WARNING, "Can't retrieve Foreign_link for foreign ID $fid"); - if (defined('SCRIPT_DEBUG')) { - print "Can't retrieve Foreign_link for foreign ID $fid\n"; - } - return; - } - - $fuser = new Foreign_user(); - $fuser->service = 1; - $fuser->id = $flink->foreign_id; - $fuser->limit(1); - $fuser->find(true); ->>>>>>> b8c700a7454db825b3867eadfa22afa1e5eb4f6c:scripts/statusfetcher.php if (empty($fuser)) { common_log(LOG_WARNING, "Unmatched user for ID " . $flink->user_id); @@ -234,17 +184,11 @@ function getTimeline($flink) return; } -<<<<<<< HEAD:scripts/statusfetcher.php common_debug('Trying to get timeline for Twitter user ' . "$fuser->nickname ($flink->foreign_id)."); if (defined('SCRIPT_DEBUG')) { print 'Trying to get timeline for Twitter user ' . "$fuser->nickname ($flink->foreign_id).\n"; -======= - if (defined('SCRIPT_DEBUG')) { - // XXX: This is horrible and must be removed before releasing this - print 'username: ' . $fuser->nickname . ' password: ' . $flink->credentials . "\n"; ->>>>>>> b8c700a7454db825b3867eadfa22afa1e5eb4f6c:scripts/statusfetcher.php } $url = 'http://twitter.com/statuses/friends_timeline.json'; @@ -282,16 +226,6 @@ function getTimeline($flink) function saveStatus($status, $flink) { -<<<<<<< HEAD:scripts/statusfetcher.php -======= - - global $config; - $config['db'] = &PEAR::getStaticProperty('DB_DataObject','options'); - require_once(INSTALLDIR . '/lib/common.php'); - - // Do we have a profile for this Twitter user? - ->>>>>>> b8c700a7454db825b3867eadfa22afa1e5eb4f6c:scripts/statusfetcher.php $id = ensureProfile($status->user); $profile = Profile::staticGet($id); @@ -349,10 +283,6 @@ function saveStatus($status, $flink) $notice->query('COMMIT'); -<<<<<<< HEAD:scripts/statusfetcher.php - common_debug("Saved status $status->id as notice $notice->id."); -======= ->>>>>>> b8c700a7454db825b3867eadfa22afa1e5eb4f6c:scripts/statusfetcher.php if (defined('SCRIPT_DEBUG')) { print "Saved status $status->id as notice $notice->id.\n"; } @@ -372,11 +302,6 @@ function saveStatus($status, $flink) function ensureProfile($user) { -<<<<<<< HEAD:scripts/statusfetcher.php -======= - global $config; - ->>>>>>> b8c700a7454db825b3867eadfa22afa1e5eb4f6c:scripts/statusfetcher.php // check to see if there's already a profile for this user $profileurl = 'http://twitter.com/' . $user->screen_name; $profile = Profile::staticGet('profileurl', $profileurl); @@ -536,11 +461,6 @@ function saveAvatars($user, $id) function updateAvatar($profile_id, $size, $mediatype, $filename) { -<<<<<<< HEAD:scripts/statusfetcher.php -======= - global $config; - ->>>>>>> b8c700a7454db825b3867eadfa22afa1e5eb4f6c:scripts/statusfetcher.php common_debug("Updating avatar: $size"); if (defined('SCRIPT_DEBUG')) { print "Updating avatar: $size\n"; -- cgit v1.2.3-54-g00ecf From 48226e0c48e9bb2a7d97dbfd8f048ae299fbb7bf Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 7 May 2009 00:25:15 -0700 Subject: Properly daemonized 2-way Twitter bridge code --- scripts/statusfetcher.php | 795 ++++++++++++++++++++++++---------------------- 1 file changed, 413 insertions(+), 382 deletions(-) diff --git a/scripts/statusfetcher.php b/scripts/statusfetcher.php index 5518e3aa8..5275a4575 100644 --- a/scripts/statusfetcher.php +++ b/scripts/statusfetcher.php @@ -28,378 +28,439 @@ define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); define('LACONICA', true); // Tune number of processes and how often to poll Twitter -define('MAXCHILDREN', 5); -define('POLL_INTERVAL', 60 * 10); // in seconds +// XXX: Should these things be in config.php? +define('MAXCHILDREN', 2); +define('POLL_INTERVAL', 60); // in seconds // Uncomment this to get useful console output define('SCRIPT_DEBUG', true); require_once(INSTALLDIR . '/lib/common.php'); +require_once(INSTALLDIR . '/lib/daemon.php'); -$children = array(); +class TwitterStatusFetcher extends Daemon +{ -do { + private $children = array(); - $flinks = refreshFlinks(); + function name() + { + return 'twitterstatusfetcher'; + } - foreach ($flinks as $f){ + function run() + { + do { - // We have to disconnect from the DB before forking so - // each process will open its own connection and - // avoid stomping on each other + $flinks = $this->refreshFlinks(); - $conn = &$f->getDatabaseConnection(); - $conn->disconnect(); + foreach ($flinks as $f){ - $pid = pcntl_fork(); + // We have to disconnect from the DB before forking so + // each sub-process will open its own connection and + // avoid stomping on the others - if ($pid == -1) { - die ("Couldn't fork!"); - } + $conn = &$f->getDatabaseConnection(); + $conn->disconnect(); - if ($pid) { + $pid = pcntl_fork(); - // Parent + if ($pid == -1) { + die ("Couldn't fork!"); + } - if (defined('SCRIPT_DEBUG')) { - print "Parent: forked " . $pid . "\n"; - } + if ($pid) { - $children[] = $pid; + // Parent + common_debug("Parent: forked new status fetcher process " . $pid); - } else { + if (defined('SCRIPT_DEBUG')) { + print "Parent: forked fetcher process " . $pid . "\n"; + } - // Child + $this->children[] = $pid; - getTimeline($f, $child_db_name); - exit(); - } + } else { - // Remove child from ps list as it finishes - while(($c = pcntl_wait($status, WNOHANG OR WUNTRACED)) > 0) { + // Child + $this->getTimeline($f); + exit(); + } - if (defined('SCRIPT_DEBUG')) { - print "Child $c finished.\n"; - } + // Remove child from ps list as it finishes + while(($c = pcntl_wait($status, WNOHANG OR WUNTRACED)) > 0) { - remove_ps($children, $c); - } + common_debug("Child $c finished."); - // Wait if we have too many kids - if (sizeof($children) > MAXCHILDREN) { + if (defined('SCRIPT_DEBUG')) { + print "Child $c finished.\n"; + } - if (defined('SCRIPT_DEBUG')) { - print "Too many children. Waiting...\n"; + $this->remove_ps($this->children, $c); + } + + // Wait! We have too many damn kids. + if (sizeof($this->children) > MAXCHILDREN) { + + common_debug('Too many children. Waiting...'); + + if (defined('SCRIPT_DEBUG')) { + print "Too many children. Waiting...\n"; + } + + if (($c = pcntl_wait($status, WUNTRACED)) > 0){ + + common_debug("Finished waiting for $c"); + + if (defined('SCRIPT_DEBUG')) { + print "Finished waiting for $c\n"; + } + + $this->remove_ps($this->children, $c); + } + } } - if (($c = pcntl_wait($status, WUNTRACED)) > 0){ + // Remove all children from the process list before restarting + while(($c = pcntl_wait($status, WUNTRACED)) > 0) { + + common_debug("Child $c finished."); if (defined('SCRIPT_DEBUG')) { - print "Finished waiting for $c\n"; + print "Child $c finished.\n"; } - remove_ps($children, $c); + $this->remove_ps($this->children, $c); } - } - } - - // Remove all children from the process list before restarting - while(($c = pcntl_wait($status, WUNTRACED)) > 0) { - if (defined('SCRIPT_DEBUG')) { - print "Child $c finished.\n"; - } + // Rest for a bit before we fetch more statuses + common_debug('Waiting ' . POLL_INTERVAL . + ' secs before hitting Twitter again.'); + if (defined('SCRIPT_DEBUG')) { + print 'Waiting ' . POLL_INTERVAL . + " secs before hitting Twitter again.\n"; + } - remove_ps($children, $c); - } + sleep(POLL_INTERVAL); - // Rest for a bit before we fetch more statuses - common_debug('Waiting ' . POLL_INTERVAL . - ' secs before hitting Twitter again.'); - if (defined('SCRIPT_DEBUG')) { - print 'Waiting ' . POLL_INTERVAL . - " secs before hitting Twitter again.\n"; + } while (true); } - sleep(POLL_INTERVAL); + function refreshFlinks() { -} while (true); + $flink = new Foreign_link(); + $flink->service = 1; // Twitter + $flink->orderBy('last_noticesync'); + $cnt = $flink->find(); -function refreshFlinks() { + if (defined('SCRIPT_DEBUG')) { + print "Updating Twitter friends subscriptions for $cnt users.\n"; + } - $flink = new Foreign_link(); - $flink->service = 1; // Twitter - $flink->orderBy('last_noticesync'); + $flinks = array(); - $cnt = $flink->find(); + while ($flink->fetch()) { - if (defined('SCRIPT_DEBUG')) { - print "Updating Twitter friends subscriptions for $cnt users.\n"; - } + if (($flink->noticesync & FOREIGN_NOTICE_RECV) == FOREIGN_NOTICE_RECV) { + $flinks[] = clone($flink); + } + } - $flinks = array(); + $flink->free(); + unset($flink); - while ($flink->fetch()) { + return $flinks; + } - if (($flink->noticesync & FOREIGN_NOTICE_RECV) == FOREIGN_NOTICE_RECV) { - $flinks[] = clone($flink); + function remove_ps(&$plist, $ps){ + for ($i = 0; $i < sizeof($plist); $i++) { + if ($plist[$i] == $ps) { + unset($plist[$i]); + $plist = array_values($plist); + break; + } } } - $flink->free(); - unset($flink); + function getTimeline($flink) + { - return $flinks; -} - -function remove_ps(&$plist, $ps){ - for ($i = 0; $i < sizeof($plist); $i++) { - if ($plist[$i] == $ps) { - unset($plist[$i]); - $plist = array_values($plist); - break; + if (empty($flink)) { + common_log(LOG_WARNING, "Can't retrieve Foreign_link for foreign ID $fid"); + if (defined('SCRIPT_DEBUG')) { + print "Can't retrieve Foreign_link for foreign ID $fid\n"; + } + return; } - } -} -function getTimeline($flink) -{ + $fuser = $flink->getForeignUser(); - if (empty($flink)) { - common_log(LOG_WARNING, "Can't retrieve Foreign_link for foreign ID $fid"); - if (defined('SCRIPT_DEBUG')) { - print "Can't retrieve Foreign_link for foreign ID $fid\n"; + if (empty($fuser)) { + common_log(LOG_WARNING, "Unmatched user for ID " . $flink->user_id); + if (defined('SCRIPT_DEBUG')) { + print "Unmatched user for ID $flink->user_id\n"; + } + return; } - return; - } - $fuser = $flink->getForeignUser(); - - if (empty($fuser)) { - common_log(LOG_WARNING, "Unmatched user for ID " . $flink->user_id); + common_debug('Trying to get timeline for Twitter user ' . + "$fuser->nickname ($flink->foreign_id)."); if (defined('SCRIPT_DEBUG')) { - print "Unmatched user for ID $flink->user_id\n"; + print 'Trying to get timeline for Twitter user ' . + "$fuser->nickname ($flink->foreign_id).\n"; } - return; - } - common_debug('Trying to get timeline for Twitter user ' . - "$fuser->nickname ($flink->foreign_id)."); - if (defined('SCRIPT_DEBUG')) { - print 'Trying to get timeline for Twitter user ' . - "$fuser->nickname ($flink->foreign_id).\n"; - } - - $url = 'http://twitter.com/statuses/friends_timeline.json'; + $url = 'http://twitter.com/statuses/friends_timeline.json'; - $timeline_json = get_twitter_data($url, $fuser->nickname, - $flink->credentials); + $timeline_json = get_twitter_data($url, $fuser->nickname, + $flink->credentials); - $timeline = json_decode($timeline_json); + $timeline = json_decode($timeline_json); - if (empty($timeline)) { - common_log(LOG_WARNING, "Empty timeline."); - if (defined('SCRIPT_DEBUG')) { - print "Empty timeline!\n"; + if (empty($timeline)) { + common_log(LOG_WARNING, "Empty timeline."); + if (defined('SCRIPT_DEBUG')) { + print "Empty timeline!\n"; + } + return; } - return; - } - foreach ($timeline as $status) { + foreach ($timeline as $status) { + + // Hacktastic: filter out stuff coming from Laconica + $source = mb_strtolower(common_config('integration', 'source')); - // Hacktastic: filter out stuff coming from Laconica - $source = mb_strtolower(common_config('integration', 'source')); + if (preg_match("/$source/", mb_strtolower($status->source))) { + continue; + } - if (preg_match("/$source/", mb_strtolower($status->source))) { - continue; + $this->saveStatus($status, $flink); } - saveStatus($status, $flink); + // Okay, record the time we synced with Twitter for posterity + + $flink->last_noticesync = common_sql_now(); + $flink->update(); } - // Okay, record the time we synced with Twitter for posterity + function saveStatus($status, $flink) + { + $id = $this->ensureProfile($status->user); + $profile = Profile::staticGet($id); - $flink->last_noticesync = common_sql_now(); - $flink->update(); -} - -function saveStatus($status, $flink) -{ - $id = ensureProfile($status->user); - $profile = Profile::staticGet($id); - - if (!$profile) { - common_log(LOG_ERR, 'Problem saving notice. No associated Profile.'); - if (defined('SCRIPT_DEBUG')) { - print "Problem saving notice. No associated Profile.\n"; + if (!$profile) { + common_log(LOG_ERR, 'Problem saving notice. No associated Profile.'); + if (defined('SCRIPT_DEBUG')) { + print "Problem saving notice. No associated Profile.\n"; + } + return null; } - return null; - } - $uri = 'http://twitter.com/' . $status->user->screen_name . - '/status/' . $status->id; + $uri = 'http://twitter.com/' . $status->user->screen_name . + '/status/' . $status->id; - // Skip save if notice source is Laconica or Identi.ca? + // Skip save if notice source is Laconica or Identi.ca? - $notice = Notice::staticGet('uri', $uri); + $notice = Notice::staticGet('uri', $uri); - // check to see if we've already imported the status - if (!$notice) { + // check to see if we've already imported the status + if (!$notice) { - $notice = new Notice(); - $notice->profile_id = $id; + $notice = new Notice(); + $notice->profile_id = $id; - $notice->query('BEGIN'); + $notice->query('BEGIN'); - // XXX: figure out reply_to - $notice->reply_to = null; + // XXX: figure out reply_to + $notice->reply_to = null; - // XXX: Should this be common_sql_now() instead of status create date? + // XXX: Should this be common_sql_now() instead of status create date? - $notice->created = strftime('%Y-%m-%d %H:%M:%S', - strtotime($status->created_at)); - $notice->content = $status->text; - $notice->rendered = common_render_content($status->text, $notice); - $notice->source = 'twitter'; - $notice->is_local = 0; - $notice->uri = $uri; + $notice->created = strftime('%Y-%m-%d %H:%M:%S', + strtotime($status->created_at)); + $notice->content = $status->text; + $notice->rendered = common_render_content($status->text, $notice); + $notice->source = 'twitter'; + $notice->is_local = 0; + $notice->uri = $uri; - $notice_id = $notice->insert(); + $notice_id = $notice->insert(); - if (!$notice_id) { - common_log_db_error($notice, 'INSERT', __FILE__); - if (defined('SCRIPT_DEBUG')) { - print "Could not save notice!\n"; + if (!$notice_id) { + common_log_db_error($notice, 'INSERT', __FILE__); + if (defined('SCRIPT_DEBUG')) { + print "Could not save notice!\n"; + } } - } - // XXX: Figure out a better way to link replies? - $notice->saveReplies(); + // XXX: Figure out a better way to link replies? + $notice->saveReplies(); - // XXX: Do we want to polute our tag cloud with hashtags from Twitter? - $notice->saveTags(); - $notice->saveGroups(); + // XXX: Do we want to polute our tag cloud with hashtags from Twitter? + $notice->saveTags(); + $notice->saveGroups(); - $notice->query('COMMIT'); + $notice->query('COMMIT'); - if (defined('SCRIPT_DEBUG')) { - print "Saved status $status->id as notice $notice->id.\n"; + if (defined('SCRIPT_DEBUG')) { + print "Saved status $status->id as notice $notice->id.\n"; + } } - } - if (!Notice_inbox::staticGet('notice_id', $notice->id)) { + if (!Notice_inbox::staticGet('notice_id', $notice->id)) { - // Add to inbox - $inbox = new Notice_inbox(); - $inbox->user_id = $flink->user_id; - $inbox->notice_id = $notice->id; - $inbox->created = common_sql_now(); + // Add to inbox + $inbox = new Notice_inbox(); + $inbox->user_id = $flink->user_id; + $inbox->notice_id = $notice->id; + $inbox->created = common_sql_now(); - $inbox->insert(); + $inbox->insert(); + } } -} -function ensureProfile($user) -{ - // check to see if there's already a profile for this user - $profileurl = 'http://twitter.com/' . $user->screen_name; - $profile = Profile::staticGet('profileurl', $profileurl); + function ensureProfile($user) + { + // check to see if there's already a profile for this user + $profileurl = 'http://twitter.com/' . $user->screen_name; + $profile = Profile::staticGet('profileurl', $profileurl); - if ($profile) { - common_debug("Profile for $profile->nickname found."); + if ($profile) { + common_debug("Profile for $profile->nickname found."); - // Check to see if the user's Avatar has changed - checkAvatar($user, $profile); - return $profile->id; + // Check to see if the user's Avatar has changed + $this->checkAvatar($user, $profile); + return $profile->id; - } else { - $debugmsg = 'Adding profile and remote profile ' . - "for Twitter user: $profileurl\n"; - common_debug($debugmsg, __FILE__); - if (defined('SCRIPT_DEBUG')) { - print $debugmsg; - } + } else { + $debugmsg = 'Adding profile and remote profile ' . + "for Twitter user: $profileurl\n"; + common_debug($debugmsg, __FILE__); + if (defined('SCRIPT_DEBUG')) { + print $debugmsg; + } - $profile = new Profile(); - $profile->query("BEGIN"); + $profile = new Profile(); + $profile->query("BEGIN"); - $profile->nickname = $user->screen_name; - $profile->fullname = $user->name; - $profile->homepage = $user->url; - $profile->bio = $user->description; - $profile->location = $user->location; - $profile->profileurl = $profileurl; - $profile->created = common_sql_now(); + $profile->nickname = $user->screen_name; + $profile->fullname = $user->name; + $profile->homepage = $user->url; + $profile->bio = $user->description; + $profile->location = $user->location; + $profile->profileurl = $profileurl; + $profile->created = common_sql_now(); - $id = $profile->insert(); + $id = $profile->insert(); - if (empty($id)) { - common_log_db_error($profile, 'INSERT', __FILE__); - if (defined('SCRIPT_DEBUG')) { - print 'Could not insert Profile: ' . - common_log_objstring($profile) . "\n"; + if (empty($id)) { + common_log_db_error($profile, 'INSERT', __FILE__); + if (defined('SCRIPT_DEBUG')) { + print 'Could not insert Profile: ' . + common_log_objstring($profile) . "\n"; + } + $profile->query("ROLLBACK"); + return false; } - $profile->query("ROLLBACK"); - return false; - } - // check for remote profile - $remote_pro = Remote_profile::staticGet('uri', $profileurl); + // check for remote profile + $remote_pro = Remote_profile::staticGet('uri', $profileurl); - if (!$remote_pro) { + if (!$remote_pro) { - $remote_pro = new Remote_profile(); + $remote_pro = new Remote_profile(); - $remote_pro->id = $id; - $remote_pro->uri = $profileurl; - $remote_pro->created = common_sql_now(); + $remote_pro->id = $id; + $remote_pro->uri = $profileurl; + $remote_pro->created = common_sql_now(); - $rid = $remote_pro->insert(); + $rid = $remote_pro->insert(); - if (empty($rid)) { - common_log_db_error($profile, 'INSERT', __FILE__); - if (defined('SCRIPT_DEBUG')) { - print 'Could not insert Remote_profile: ' . - common_log_objstring($remote_pro) . "\n"; + if (empty($rid)) { + common_log_db_error($profile, 'INSERT', __FILE__); + if (defined('SCRIPT_DEBUG')) { + print 'Could not insert Remote_profile: ' . + common_log_objstring($remote_pro) . "\n"; + } + $profile->query("ROLLBACK"); + return false; } - $profile->query("ROLLBACK"); - return false; } - } - $profile->query("COMMIT"); + $profile->query("COMMIT"); - saveAvatars($user, $id); + $this->saveAvatars($user, $id); - return $id; + return $id; + } } -} -function checkAvatar($user, $profile) -{ - global $config; + function checkAvatar($user, $profile) + { + global $config; - $path_parts = pathinfo($user->profile_image_url); - $newname = 'Twitter_' . $user->id . '_' . - $path_parts['basename']; + $path_parts = pathinfo($user->profile_image_url); + $newname = 'Twitter_' . $user->id . '_' . + $path_parts['basename']; - $oldname = $profile->getAvatar(48)->filename; + $oldname = $profile->getAvatar(48)->filename; - if ($newname != $oldname) { + if ($newname != $oldname) { - common_debug("Avatar for Twitter user $profile->nickname has changed."); - common_debug("old: $oldname new: $newname"); + common_debug("Avatar for Twitter user $profile->nickname has changed."); + common_debug("old: $oldname new: $newname"); - if (defined('SCRIPT_DEBUG')) { - print "Avatar for Twitter user $user->id has changed.\n"; - print "old: $oldname\n"; - print "new: $newname\n"; + if (defined('SCRIPT_DEBUG')) { + print "Avatar for Twitter user $user->id has changed.\n"; + print "old: $oldname\n"; + print "new: $newname\n"; + } + + $img_root = substr($path_parts['basename'], 0, -11); + $ext = $path_parts['extension']; + $mediatype = $this->getMediatype($ext); + + foreach (array('mini', 'normal', 'bigger') as $size) { + $url = $path_parts['dirname'] . '/' . + $img_root . '_' . $size . ".$ext"; + $filename = 'Twitter_' . $user->id . '_' . + $img_root . "_$size.$ext"; + + if ($this->fetchAvatar($url, $filename)) { + $this->updateAvatar($profile->id, $size, $mediatype, $filename); + } + } + } + } + + function getMediatype($ext) + { + $mediatype = null; + + switch (strtolower($ext)) { + case 'jpg': + $mediatype = 'image/jpg'; + break; + case 'gif': + $mediatype = 'image/gif'; + break; + default: + $mediatype = 'image/png'; } - $img_root = substr($path_parts['basename'], 0, -11); + return $mediatype; + } + + function saveAvatars($user, $id) + { + global $config; + + $path_parts = pathinfo($user->profile_image_url); $ext = $path_parts['extension']; - $mediatype = getMediatype($ext); + $end = strlen('_normal' . $ext); + $img_root = substr($path_parts['basename'], 0, -($end+1)); + $mediatype = $this->getMediatype($ext); foreach (array('mini', 'normal', 'bigger') as $size) { $url = $path_parts['dirname'] . '/' . @@ -407,173 +468,143 @@ function checkAvatar($user, $profile) $filename = 'Twitter_' . $user->id . '_' . $img_root . "_$size.$ext"; - if (fetchAvatar($url, $filename)) { - updateAvatar($profile->id, $size, $mediatype, $filename); + if ($this->fetchAvatar($url, $filename)) { + $this->newAvatar($id, $size, $mediatype, $filename); + } else { + common_log(LOG_WARNING, "Problem fetching Avatar: $url", __FILE__); + if (defined('SCRIPT_DEBUG')) { + print "Problem fetching Avatar: $url\n"; + } } } } -} -function getMediatype($ext) -{ - $mediatype = null; - - switch (strtolower($ext)) { - case 'jpg': - $mediatype = 'image/jpg'; - break; - case 'gif': - $mediatype = 'image/gif'; - break; - default: - $mediatype = 'image/png'; - } + function updateAvatar($profile_id, $size, $mediatype, $filename) { - return $mediatype; -} + common_debug("Updating avatar: $size"); + if (defined('SCRIPT_DEBUG')) { + print "Updating avatar: $size\n"; + } -function saveAvatars($user, $id) -{ - global $config; - - $path_parts = pathinfo($user->profile_image_url); - $ext = $path_parts['extension']; - $end = strlen('_normal' . $ext); - $img_root = substr($path_parts['basename'], 0, -($end+1)); - $mediatype = getMediatype($ext); - - foreach (array('mini', 'normal', 'bigger') as $size) { - $url = $path_parts['dirname'] . '/' . - $img_root . '_' . $size . ".$ext"; - $filename = 'Twitter_' . $user->id . '_' . - $img_root . "_$size.$ext"; - - if (fetchAvatar($url, $filename)) { - newAvatar($id, $size, $mediatype, $filename); - } else { - common_log(LOG_WARNING, "Problem fetching Avatar: $url", __FILE__); + $profile = Profile::staticGet($profile_id); + + if (!$profile) { + common_debug("Couldn't get profile: $profile_id!"); if (defined('SCRIPT_DEBUG')) { - print "Problem fetching Avatar: $url\n"; + print "Couldn't get profile: $profile_id!\n"; } + return; } - } -} -function updateAvatar($profile_id, $size, $mediatype, $filename) { + $sizes = array('mini' => 24, 'normal' => 48, 'bigger' => 73); + $avatar = $profile->getAvatar($sizes[$size]); - common_debug("Updating avatar: $size"); - if (defined('SCRIPT_DEBUG')) { - print "Updating avatar: $size\n"; + if ($avatar) { + common_debug("Deleting $size avatar for $profile->nickname."); + @unlink(INSTALLDIR . '/avatar/' . $avatar->filename); + $avatar->delete(); + } + + $this->newAvatar($profile->id, $size, $mediatype, $filename); } - $profile = Profile::staticGet($profile_id); + function newAvatar($profile_id, $size, $mediatype, $filename) + { + global $config; - if (!$profile) { - common_debug("Couldn't get profile: $profile_id!"); - if (defined('SCRIPT_DEBUG')) { - print "Couldn't get profile: $profile_id!\n"; - } - return; - } + $avatar = new Avatar(); + $avatar->profile_id = $profile_id; - $sizes = array('mini' => 24, 'normal' => 48, 'bigger' => 73); - $avatar = $profile->getAvatar($sizes[$size]); + switch($size) { + case 'mini': + $avatar->width = 24; + $avatar->height = 24; + break; + case 'normal': + $avatar->width = 48; + $avatar->height = 48; + break; + default: - if ($avatar) { - common_debug("Deleting $size avatar for $profile->nickname."); - @unlink(INSTALLDIR . '/avatar/' . $avatar->filename); - $avatar->delete(); - } + // Note: Twitter's big avatars are a different size than + // Laconica's (Laconica's = 96) - newAvatar($profile->id, $size, $mediatype, $filename); -} + $avatar->width = 73; + $avatar->height = 73; + } -function newAvatar($profile_id, $size, $mediatype, $filename) -{ - global $config; - - $avatar = new Avatar(); - $avatar->profile_id = $profile_id; - - switch($size) { - case 'mini': - $avatar->width = 24; - $avatar->height = 24; - break; - case 'normal': - $avatar->width = 48; - $avatar->height = 48; - break; - default: - - // Note: Twitter's big avatars are a different size than - // Laconica's (Laconica's = 96) - - $avatar->width = 73; - $avatar->height = 73; - } + $avatar->original = 0; // we don't have the original + $avatar->mediatype = $mediatype; + $avatar->filename = $filename; + $avatar->url = Avatar::url($filename); + + common_debug("new filename: $avatar->url"); + if (defined('SCRIPT_DEBUG')) { + print "New filename: $avatar->url\n"; + } - $avatar->original = 0; // we don't have the original - $avatar->mediatype = $mediatype; - $avatar->filename = $filename; - $avatar->url = Avatar::url($filename); + $avatar->created = common_sql_now(); - common_debug("new filename: $avatar->url"); - if (defined('SCRIPT_DEBUG')) { - print "New filename: $avatar->url\n"; - } + $id = $avatar->insert(); - $avatar->created = common_sql_now(); + if (!$id) { + common_log_db_error($avatar, 'INSERT', __FILE__); + if (defined('SCRIPT_DEBUG')) { + print "Could not insert avatar!\n"; + } - $id = $avatar->insert(); + return null; + } - if (!$id) { - common_log_db_error($avatar, 'INSERT', __FILE__); + common_debug("Saved new $size avatar for $profile_id."); if (defined('SCRIPT_DEBUG')) { - print "Could not insert avatar!\n"; + print "Saved new $size avatar for $profile_id.\n"; } - return null; - } - - common_debug("Saved new $size avatar for $profile_id."); - if (defined('SCRIPT_DEBUG')) { - print "Saved new $size avatar for $profile_id.\n"; + return $id; } - return $id; -} + function fetchAvatar($url, $filename) + { + $avatar_dir = INSTALLDIR . '/avatar/'; -function fetchAvatar($url, $filename) -{ - $avatar_dir = INSTALLDIR . '/avatar/'; + $avatarfile = $avatar_dir . $filename; - $avatarfile = $avatar_dir . $filename; + $out = fopen($avatarfile, 'wb'); + if (!$out) { + common_log(LOG_WARNING, "Couldn't open file $filename", __FILE__); + if (defined('SCRIPT_DEBUG')) { + print "Couldn't open file! $filename\n"; + } + return false; + } - $out = fopen($avatarfile, 'wb'); - if (!$out) { - common_log(LOG_WARNING, "Couldn't open file $filename", __FILE__); + common_debug("Fetching avatar: $url", __FILE__); if (defined('SCRIPT_DEBUG')) { - print "Couldn't open file! $filename\n"; + print "Fetching avatar from Twitter: $url\n"; } - return false; - } - common_debug("Fetching avatar: $url", __FILE__); - if (defined('SCRIPT_DEBUG')) { - print "Fetching avatar from Twitter: $url\n"; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_FILE, $out); + curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); + $result = curl_exec($ch); + curl_close($ch); + + fclose($out); + + return $result; } +} - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_FILE, $out); - curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); - $result = curl_exec($ch); - curl_close($ch); +ini_set("max_execution_time", "0"); +ini_set("max_input_time", "0"); +set_time_limit(0); +mb_internal_encoding('UTF-8'); +declare(ticks = 1); - fclose($out); +$fetcher = new TwitterStatusFetcher(); +$fetcher->runOnce(); - return $result; -} -- cgit v1.2.3-54-g00ecf From 2621a5471f9a3fa75d206ed5b3a4a91df1e28bdc Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 7 May 2009 00:26:42 -0700 Subject: Better name --- scripts/statusfetcher.php | 610 --------------------------------------- scripts/twitterstatusfetcher.php | 610 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 610 insertions(+), 610 deletions(-) delete mode 100644 scripts/statusfetcher.php create mode 100644 scripts/twitterstatusfetcher.php diff --git a/scripts/statusfetcher.php b/scripts/statusfetcher.php deleted file mode 100644 index 5275a4575..000000000 --- a/scripts/statusfetcher.php +++ /dev/null @@ -1,610 +0,0 @@ -#!/usr/bin/env php -. - */ - -// Abort if called from a web server -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(); -} - -define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('LACONICA', true); - -// Tune number of processes and how often to poll Twitter -// XXX: Should these things be in config.php? -define('MAXCHILDREN', 2); -define('POLL_INTERVAL', 60); // in seconds - -// Uncomment this to get useful console output -define('SCRIPT_DEBUG', true); - -require_once(INSTALLDIR . '/lib/common.php'); -require_once(INSTALLDIR . '/lib/daemon.php'); - -class TwitterStatusFetcher extends Daemon -{ - - private $children = array(); - - function name() - { - return 'twitterstatusfetcher'; - } - - function run() - { - do { - - $flinks = $this->refreshFlinks(); - - foreach ($flinks as $f){ - - // We have to disconnect from the DB before forking so - // each sub-process will open its own connection and - // avoid stomping on the others - - $conn = &$f->getDatabaseConnection(); - $conn->disconnect(); - - $pid = pcntl_fork(); - - if ($pid == -1) { - die ("Couldn't fork!"); - } - - if ($pid) { - - // Parent - common_debug("Parent: forked new status fetcher process " . $pid); - - if (defined('SCRIPT_DEBUG')) { - print "Parent: forked fetcher process " . $pid . "\n"; - } - - $this->children[] = $pid; - - } else { - - // Child - $this->getTimeline($f); - exit(); - } - - // Remove child from ps list as it finishes - while(($c = pcntl_wait($status, WNOHANG OR WUNTRACED)) > 0) { - - common_debug("Child $c finished."); - - if (defined('SCRIPT_DEBUG')) { - print "Child $c finished.\n"; - } - - $this->remove_ps($this->children, $c); - } - - // Wait! We have too many damn kids. - if (sizeof($this->children) > MAXCHILDREN) { - - common_debug('Too many children. Waiting...'); - - if (defined('SCRIPT_DEBUG')) { - print "Too many children. Waiting...\n"; - } - - if (($c = pcntl_wait($status, WUNTRACED)) > 0){ - - common_debug("Finished waiting for $c"); - - if (defined('SCRIPT_DEBUG')) { - print "Finished waiting for $c\n"; - } - - $this->remove_ps($this->children, $c); - } - } - } - - // Remove all children from the process list before restarting - while(($c = pcntl_wait($status, WUNTRACED)) > 0) { - - common_debug("Child $c finished."); - - if (defined('SCRIPT_DEBUG')) { - print "Child $c finished.\n"; - } - - $this->remove_ps($this->children, $c); - } - - // Rest for a bit before we fetch more statuses - common_debug('Waiting ' . POLL_INTERVAL . - ' secs before hitting Twitter again.'); - if (defined('SCRIPT_DEBUG')) { - print 'Waiting ' . POLL_INTERVAL . - " secs before hitting Twitter again.\n"; - } - - sleep(POLL_INTERVAL); - - } while (true); - } - - function refreshFlinks() { - - $flink = new Foreign_link(); - $flink->service = 1; // Twitter - $flink->orderBy('last_noticesync'); - - $cnt = $flink->find(); - - if (defined('SCRIPT_DEBUG')) { - print "Updating Twitter friends subscriptions for $cnt users.\n"; - } - - $flinks = array(); - - while ($flink->fetch()) { - - if (($flink->noticesync & FOREIGN_NOTICE_RECV) == FOREIGN_NOTICE_RECV) { - $flinks[] = clone($flink); - } - } - - $flink->free(); - unset($flink); - - return $flinks; - } - - function remove_ps(&$plist, $ps){ - for ($i = 0; $i < sizeof($plist); $i++) { - if ($plist[$i] == $ps) { - unset($plist[$i]); - $plist = array_values($plist); - break; - } - } - } - - function getTimeline($flink) - { - - if (empty($flink)) { - common_log(LOG_WARNING, "Can't retrieve Foreign_link for foreign ID $fid"); - if (defined('SCRIPT_DEBUG')) { - print "Can't retrieve Foreign_link for foreign ID $fid\n"; - } - return; - } - - $fuser = $flink->getForeignUser(); - - if (empty($fuser)) { - common_log(LOG_WARNING, "Unmatched user for ID " . $flink->user_id); - if (defined('SCRIPT_DEBUG')) { - print "Unmatched user for ID $flink->user_id\n"; - } - return; - } - - common_debug('Trying to get timeline for Twitter user ' . - "$fuser->nickname ($flink->foreign_id)."); - if (defined('SCRIPT_DEBUG')) { - print 'Trying to get timeline for Twitter user ' . - "$fuser->nickname ($flink->foreign_id).\n"; - } - - $url = 'http://twitter.com/statuses/friends_timeline.json'; - - $timeline_json = get_twitter_data($url, $fuser->nickname, - $flink->credentials); - - $timeline = json_decode($timeline_json); - - if (empty($timeline)) { - common_log(LOG_WARNING, "Empty timeline."); - if (defined('SCRIPT_DEBUG')) { - print "Empty timeline!\n"; - } - return; - } - - foreach ($timeline as $status) { - - // Hacktastic: filter out stuff coming from Laconica - $source = mb_strtolower(common_config('integration', 'source')); - - if (preg_match("/$source/", mb_strtolower($status->source))) { - continue; - } - - $this->saveStatus($status, $flink); - } - - // Okay, record the time we synced with Twitter for posterity - - $flink->last_noticesync = common_sql_now(); - $flink->update(); - } - - function saveStatus($status, $flink) - { - $id = $this->ensureProfile($status->user); - $profile = Profile::staticGet($id); - - if (!$profile) { - common_log(LOG_ERR, 'Problem saving notice. No associated Profile.'); - if (defined('SCRIPT_DEBUG')) { - print "Problem saving notice. No associated Profile.\n"; - } - return null; - } - - $uri = 'http://twitter.com/' . $status->user->screen_name . - '/status/' . $status->id; - - // Skip save if notice source is Laconica or Identi.ca? - - $notice = Notice::staticGet('uri', $uri); - - // check to see if we've already imported the status - if (!$notice) { - - $notice = new Notice(); - $notice->profile_id = $id; - - $notice->query('BEGIN'); - - // XXX: figure out reply_to - $notice->reply_to = null; - - // XXX: Should this be common_sql_now() instead of status create date? - - $notice->created = strftime('%Y-%m-%d %H:%M:%S', - strtotime($status->created_at)); - $notice->content = $status->text; - $notice->rendered = common_render_content($status->text, $notice); - $notice->source = 'twitter'; - $notice->is_local = 0; - $notice->uri = $uri; - - $notice_id = $notice->insert(); - - if (!$notice_id) { - common_log_db_error($notice, 'INSERT', __FILE__); - if (defined('SCRIPT_DEBUG')) { - print "Could not save notice!\n"; - } - } - - // XXX: Figure out a better way to link replies? - $notice->saveReplies(); - - // XXX: Do we want to polute our tag cloud with hashtags from Twitter? - $notice->saveTags(); - $notice->saveGroups(); - - $notice->query('COMMIT'); - - if (defined('SCRIPT_DEBUG')) { - print "Saved status $status->id as notice $notice->id.\n"; - } - } - - if (!Notice_inbox::staticGet('notice_id', $notice->id)) { - - // Add to inbox - $inbox = new Notice_inbox(); - $inbox->user_id = $flink->user_id; - $inbox->notice_id = $notice->id; - $inbox->created = common_sql_now(); - - $inbox->insert(); - } - } - - function ensureProfile($user) - { - // check to see if there's already a profile for this user - $profileurl = 'http://twitter.com/' . $user->screen_name; - $profile = Profile::staticGet('profileurl', $profileurl); - - if ($profile) { - common_debug("Profile for $profile->nickname found."); - - // Check to see if the user's Avatar has changed - $this->checkAvatar($user, $profile); - return $profile->id; - - } else { - $debugmsg = 'Adding profile and remote profile ' . - "for Twitter user: $profileurl\n"; - common_debug($debugmsg, __FILE__); - if (defined('SCRIPT_DEBUG')) { - print $debugmsg; - } - - $profile = new Profile(); - $profile->query("BEGIN"); - - $profile->nickname = $user->screen_name; - $profile->fullname = $user->name; - $profile->homepage = $user->url; - $profile->bio = $user->description; - $profile->location = $user->location; - $profile->profileurl = $profileurl; - $profile->created = common_sql_now(); - - $id = $profile->insert(); - - if (empty($id)) { - common_log_db_error($profile, 'INSERT', __FILE__); - if (defined('SCRIPT_DEBUG')) { - print 'Could not insert Profile: ' . - common_log_objstring($profile) . "\n"; - } - $profile->query("ROLLBACK"); - return false; - } - - // check for remote profile - $remote_pro = Remote_profile::staticGet('uri', $profileurl); - - if (!$remote_pro) { - - $remote_pro = new Remote_profile(); - - $remote_pro->id = $id; - $remote_pro->uri = $profileurl; - $remote_pro->created = common_sql_now(); - - $rid = $remote_pro->insert(); - - if (empty($rid)) { - common_log_db_error($profile, 'INSERT', __FILE__); - if (defined('SCRIPT_DEBUG')) { - print 'Could not insert Remote_profile: ' . - common_log_objstring($remote_pro) . "\n"; - } - $profile->query("ROLLBACK"); - return false; - } - } - - $profile->query("COMMIT"); - - $this->saveAvatars($user, $id); - - return $id; - } - } - - function checkAvatar($user, $profile) - { - global $config; - - $path_parts = pathinfo($user->profile_image_url); - $newname = 'Twitter_' . $user->id . '_' . - $path_parts['basename']; - - $oldname = $profile->getAvatar(48)->filename; - - if ($newname != $oldname) { - - common_debug("Avatar for Twitter user $profile->nickname has changed."); - common_debug("old: $oldname new: $newname"); - - if (defined('SCRIPT_DEBUG')) { - print "Avatar for Twitter user $user->id has changed.\n"; - print "old: $oldname\n"; - print "new: $newname\n"; - } - - $img_root = substr($path_parts['basename'], 0, -11); - $ext = $path_parts['extension']; - $mediatype = $this->getMediatype($ext); - - foreach (array('mini', 'normal', 'bigger') as $size) { - $url = $path_parts['dirname'] . '/' . - $img_root . '_' . $size . ".$ext"; - $filename = 'Twitter_' . $user->id . '_' . - $img_root . "_$size.$ext"; - - if ($this->fetchAvatar($url, $filename)) { - $this->updateAvatar($profile->id, $size, $mediatype, $filename); - } - } - } - } - - function getMediatype($ext) - { - $mediatype = null; - - switch (strtolower($ext)) { - case 'jpg': - $mediatype = 'image/jpg'; - break; - case 'gif': - $mediatype = 'image/gif'; - break; - default: - $mediatype = 'image/png'; - } - - return $mediatype; - } - - function saveAvatars($user, $id) - { - global $config; - - $path_parts = pathinfo($user->profile_image_url); - $ext = $path_parts['extension']; - $end = strlen('_normal' . $ext); - $img_root = substr($path_parts['basename'], 0, -($end+1)); - $mediatype = $this->getMediatype($ext); - - foreach (array('mini', 'normal', 'bigger') as $size) { - $url = $path_parts['dirname'] . '/' . - $img_root . '_' . $size . ".$ext"; - $filename = 'Twitter_' . $user->id . '_' . - $img_root . "_$size.$ext"; - - if ($this->fetchAvatar($url, $filename)) { - $this->newAvatar($id, $size, $mediatype, $filename); - } else { - common_log(LOG_WARNING, "Problem fetching Avatar: $url", __FILE__); - if (defined('SCRIPT_DEBUG')) { - print "Problem fetching Avatar: $url\n"; - } - } - } - } - - function updateAvatar($profile_id, $size, $mediatype, $filename) { - - common_debug("Updating avatar: $size"); - if (defined('SCRIPT_DEBUG')) { - print "Updating avatar: $size\n"; - } - - $profile = Profile::staticGet($profile_id); - - if (!$profile) { - common_debug("Couldn't get profile: $profile_id!"); - if (defined('SCRIPT_DEBUG')) { - print "Couldn't get profile: $profile_id!\n"; - } - return; - } - - $sizes = array('mini' => 24, 'normal' => 48, 'bigger' => 73); - $avatar = $profile->getAvatar($sizes[$size]); - - if ($avatar) { - common_debug("Deleting $size avatar for $profile->nickname."); - @unlink(INSTALLDIR . '/avatar/' . $avatar->filename); - $avatar->delete(); - } - - $this->newAvatar($profile->id, $size, $mediatype, $filename); - } - - function newAvatar($profile_id, $size, $mediatype, $filename) - { - global $config; - - $avatar = new Avatar(); - $avatar->profile_id = $profile_id; - - switch($size) { - case 'mini': - $avatar->width = 24; - $avatar->height = 24; - break; - case 'normal': - $avatar->width = 48; - $avatar->height = 48; - break; - default: - - // Note: Twitter's big avatars are a different size than - // Laconica's (Laconica's = 96) - - $avatar->width = 73; - $avatar->height = 73; - } - - $avatar->original = 0; // we don't have the original - $avatar->mediatype = $mediatype; - $avatar->filename = $filename; - $avatar->url = Avatar::url($filename); - - common_debug("new filename: $avatar->url"); - if (defined('SCRIPT_DEBUG')) { - print "New filename: $avatar->url\n"; - } - - $avatar->created = common_sql_now(); - - $id = $avatar->insert(); - - if (!$id) { - common_log_db_error($avatar, 'INSERT', __FILE__); - if (defined('SCRIPT_DEBUG')) { - print "Could not insert avatar!\n"; - } - - return null; - } - - common_debug("Saved new $size avatar for $profile_id."); - if (defined('SCRIPT_DEBUG')) { - print "Saved new $size avatar for $profile_id.\n"; - } - - return $id; - } - - function fetchAvatar($url, $filename) - { - $avatar_dir = INSTALLDIR . '/avatar/'; - - $avatarfile = $avatar_dir . $filename; - - $out = fopen($avatarfile, 'wb'); - if (!$out) { - common_log(LOG_WARNING, "Couldn't open file $filename", __FILE__); - if (defined('SCRIPT_DEBUG')) { - print "Couldn't open file! $filename\n"; - } - return false; - } - - common_debug("Fetching avatar: $url", __FILE__); - if (defined('SCRIPT_DEBUG')) { - print "Fetching avatar from Twitter: $url\n"; - } - - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_FILE, $out); - curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); - $result = curl_exec($ch); - curl_close($ch); - - fclose($out); - - return $result; - } -} - -ini_set("max_execution_time", "0"); -ini_set("max_input_time", "0"); -set_time_limit(0); -mb_internal_encoding('UTF-8'); -declare(ticks = 1); - -$fetcher = new TwitterStatusFetcher(); -$fetcher->runOnce(); - diff --git a/scripts/twitterstatusfetcher.php b/scripts/twitterstatusfetcher.php new file mode 100644 index 000000000..5275a4575 --- /dev/null +++ b/scripts/twitterstatusfetcher.php @@ -0,0 +1,610 @@ +#!/usr/bin/env php +. + */ + +// Abort if called from a web server +if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { + print "This script must be run from the command line\n"; + exit(); +} + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); +define('LACONICA', true); + +// Tune number of processes and how often to poll Twitter +// XXX: Should these things be in config.php? +define('MAXCHILDREN', 2); +define('POLL_INTERVAL', 60); // in seconds + +// Uncomment this to get useful console output +define('SCRIPT_DEBUG', true); + +require_once(INSTALLDIR . '/lib/common.php'); +require_once(INSTALLDIR . '/lib/daemon.php'); + +class TwitterStatusFetcher extends Daemon +{ + + private $children = array(); + + function name() + { + return 'twitterstatusfetcher'; + } + + function run() + { + do { + + $flinks = $this->refreshFlinks(); + + foreach ($flinks as $f){ + + // We have to disconnect from the DB before forking so + // each sub-process will open its own connection and + // avoid stomping on the others + + $conn = &$f->getDatabaseConnection(); + $conn->disconnect(); + + $pid = pcntl_fork(); + + if ($pid == -1) { + die ("Couldn't fork!"); + } + + if ($pid) { + + // Parent + common_debug("Parent: forked new status fetcher process " . $pid); + + if (defined('SCRIPT_DEBUG')) { + print "Parent: forked fetcher process " . $pid . "\n"; + } + + $this->children[] = $pid; + + } else { + + // Child + $this->getTimeline($f); + exit(); + } + + // Remove child from ps list as it finishes + while(($c = pcntl_wait($status, WNOHANG OR WUNTRACED)) > 0) { + + common_debug("Child $c finished."); + + if (defined('SCRIPT_DEBUG')) { + print "Child $c finished.\n"; + } + + $this->remove_ps($this->children, $c); + } + + // Wait! We have too many damn kids. + if (sizeof($this->children) > MAXCHILDREN) { + + common_debug('Too many children. Waiting...'); + + if (defined('SCRIPT_DEBUG')) { + print "Too many children. Waiting...\n"; + } + + if (($c = pcntl_wait($status, WUNTRACED)) > 0){ + + common_debug("Finished waiting for $c"); + + if (defined('SCRIPT_DEBUG')) { + print "Finished waiting for $c\n"; + } + + $this->remove_ps($this->children, $c); + } + } + } + + // Remove all children from the process list before restarting + while(($c = pcntl_wait($status, WUNTRACED)) > 0) { + + common_debug("Child $c finished."); + + if (defined('SCRIPT_DEBUG')) { + print "Child $c finished.\n"; + } + + $this->remove_ps($this->children, $c); + } + + // Rest for a bit before we fetch more statuses + common_debug('Waiting ' . POLL_INTERVAL . + ' secs before hitting Twitter again.'); + if (defined('SCRIPT_DEBUG')) { + print 'Waiting ' . POLL_INTERVAL . + " secs before hitting Twitter again.\n"; + } + + sleep(POLL_INTERVAL); + + } while (true); + } + + function refreshFlinks() { + + $flink = new Foreign_link(); + $flink->service = 1; // Twitter + $flink->orderBy('last_noticesync'); + + $cnt = $flink->find(); + + if (defined('SCRIPT_DEBUG')) { + print "Updating Twitter friends subscriptions for $cnt users.\n"; + } + + $flinks = array(); + + while ($flink->fetch()) { + + if (($flink->noticesync & FOREIGN_NOTICE_RECV) == FOREIGN_NOTICE_RECV) { + $flinks[] = clone($flink); + } + } + + $flink->free(); + unset($flink); + + return $flinks; + } + + function remove_ps(&$plist, $ps){ + for ($i = 0; $i < sizeof($plist); $i++) { + if ($plist[$i] == $ps) { + unset($plist[$i]); + $plist = array_values($plist); + break; + } + } + } + + function getTimeline($flink) + { + + if (empty($flink)) { + common_log(LOG_WARNING, "Can't retrieve Foreign_link for foreign ID $fid"); + if (defined('SCRIPT_DEBUG')) { + print "Can't retrieve Foreign_link for foreign ID $fid\n"; + } + return; + } + + $fuser = $flink->getForeignUser(); + + if (empty($fuser)) { + common_log(LOG_WARNING, "Unmatched user for ID " . $flink->user_id); + if (defined('SCRIPT_DEBUG')) { + print "Unmatched user for ID $flink->user_id\n"; + } + return; + } + + common_debug('Trying to get timeline for Twitter user ' . + "$fuser->nickname ($flink->foreign_id)."); + if (defined('SCRIPT_DEBUG')) { + print 'Trying to get timeline for Twitter user ' . + "$fuser->nickname ($flink->foreign_id).\n"; + } + + $url = 'http://twitter.com/statuses/friends_timeline.json'; + + $timeline_json = get_twitter_data($url, $fuser->nickname, + $flink->credentials); + + $timeline = json_decode($timeline_json); + + if (empty($timeline)) { + common_log(LOG_WARNING, "Empty timeline."); + if (defined('SCRIPT_DEBUG')) { + print "Empty timeline!\n"; + } + return; + } + + foreach ($timeline as $status) { + + // Hacktastic: filter out stuff coming from Laconica + $source = mb_strtolower(common_config('integration', 'source')); + + if (preg_match("/$source/", mb_strtolower($status->source))) { + continue; + } + + $this->saveStatus($status, $flink); + } + + // Okay, record the time we synced with Twitter for posterity + + $flink->last_noticesync = common_sql_now(); + $flink->update(); + } + + function saveStatus($status, $flink) + { + $id = $this->ensureProfile($status->user); + $profile = Profile::staticGet($id); + + if (!$profile) { + common_log(LOG_ERR, 'Problem saving notice. No associated Profile.'); + if (defined('SCRIPT_DEBUG')) { + print "Problem saving notice. No associated Profile.\n"; + } + return null; + } + + $uri = 'http://twitter.com/' . $status->user->screen_name . + '/status/' . $status->id; + + // Skip save if notice source is Laconica or Identi.ca? + + $notice = Notice::staticGet('uri', $uri); + + // check to see if we've already imported the status + if (!$notice) { + + $notice = new Notice(); + $notice->profile_id = $id; + + $notice->query('BEGIN'); + + // XXX: figure out reply_to + $notice->reply_to = null; + + // XXX: Should this be common_sql_now() instead of status create date? + + $notice->created = strftime('%Y-%m-%d %H:%M:%S', + strtotime($status->created_at)); + $notice->content = $status->text; + $notice->rendered = common_render_content($status->text, $notice); + $notice->source = 'twitter'; + $notice->is_local = 0; + $notice->uri = $uri; + + $notice_id = $notice->insert(); + + if (!$notice_id) { + common_log_db_error($notice, 'INSERT', __FILE__); + if (defined('SCRIPT_DEBUG')) { + print "Could not save notice!\n"; + } + } + + // XXX: Figure out a better way to link replies? + $notice->saveReplies(); + + // XXX: Do we want to polute our tag cloud with hashtags from Twitter? + $notice->saveTags(); + $notice->saveGroups(); + + $notice->query('COMMIT'); + + if (defined('SCRIPT_DEBUG')) { + print "Saved status $status->id as notice $notice->id.\n"; + } + } + + if (!Notice_inbox::staticGet('notice_id', $notice->id)) { + + // Add to inbox + $inbox = new Notice_inbox(); + $inbox->user_id = $flink->user_id; + $inbox->notice_id = $notice->id; + $inbox->created = common_sql_now(); + + $inbox->insert(); + } + } + + function ensureProfile($user) + { + // check to see if there's already a profile for this user + $profileurl = 'http://twitter.com/' . $user->screen_name; + $profile = Profile::staticGet('profileurl', $profileurl); + + if ($profile) { + common_debug("Profile for $profile->nickname found."); + + // Check to see if the user's Avatar has changed + $this->checkAvatar($user, $profile); + return $profile->id; + + } else { + $debugmsg = 'Adding profile and remote profile ' . + "for Twitter user: $profileurl\n"; + common_debug($debugmsg, __FILE__); + if (defined('SCRIPT_DEBUG')) { + print $debugmsg; + } + + $profile = new Profile(); + $profile->query("BEGIN"); + + $profile->nickname = $user->screen_name; + $profile->fullname = $user->name; + $profile->homepage = $user->url; + $profile->bio = $user->description; + $profile->location = $user->location; + $profile->profileurl = $profileurl; + $profile->created = common_sql_now(); + + $id = $profile->insert(); + + if (empty($id)) { + common_log_db_error($profile, 'INSERT', __FILE__); + if (defined('SCRIPT_DEBUG')) { + print 'Could not insert Profile: ' . + common_log_objstring($profile) . "\n"; + } + $profile->query("ROLLBACK"); + return false; + } + + // check for remote profile + $remote_pro = Remote_profile::staticGet('uri', $profileurl); + + if (!$remote_pro) { + + $remote_pro = new Remote_profile(); + + $remote_pro->id = $id; + $remote_pro->uri = $profileurl; + $remote_pro->created = common_sql_now(); + + $rid = $remote_pro->insert(); + + if (empty($rid)) { + common_log_db_error($profile, 'INSERT', __FILE__); + if (defined('SCRIPT_DEBUG')) { + print 'Could not insert Remote_profile: ' . + common_log_objstring($remote_pro) . "\n"; + } + $profile->query("ROLLBACK"); + return false; + } + } + + $profile->query("COMMIT"); + + $this->saveAvatars($user, $id); + + return $id; + } + } + + function checkAvatar($user, $profile) + { + global $config; + + $path_parts = pathinfo($user->profile_image_url); + $newname = 'Twitter_' . $user->id . '_' . + $path_parts['basename']; + + $oldname = $profile->getAvatar(48)->filename; + + if ($newname != $oldname) { + + common_debug("Avatar for Twitter user $profile->nickname has changed."); + common_debug("old: $oldname new: $newname"); + + if (defined('SCRIPT_DEBUG')) { + print "Avatar for Twitter user $user->id has changed.\n"; + print "old: $oldname\n"; + print "new: $newname\n"; + } + + $img_root = substr($path_parts['basename'], 0, -11); + $ext = $path_parts['extension']; + $mediatype = $this->getMediatype($ext); + + foreach (array('mini', 'normal', 'bigger') as $size) { + $url = $path_parts['dirname'] . '/' . + $img_root . '_' . $size . ".$ext"; + $filename = 'Twitter_' . $user->id . '_' . + $img_root . "_$size.$ext"; + + if ($this->fetchAvatar($url, $filename)) { + $this->updateAvatar($profile->id, $size, $mediatype, $filename); + } + } + } + } + + function getMediatype($ext) + { + $mediatype = null; + + switch (strtolower($ext)) { + case 'jpg': + $mediatype = 'image/jpg'; + break; + case 'gif': + $mediatype = 'image/gif'; + break; + default: + $mediatype = 'image/png'; + } + + return $mediatype; + } + + function saveAvatars($user, $id) + { + global $config; + + $path_parts = pathinfo($user->profile_image_url); + $ext = $path_parts['extension']; + $end = strlen('_normal' . $ext); + $img_root = substr($path_parts['basename'], 0, -($end+1)); + $mediatype = $this->getMediatype($ext); + + foreach (array('mini', 'normal', 'bigger') as $size) { + $url = $path_parts['dirname'] . '/' . + $img_root . '_' . $size . ".$ext"; + $filename = 'Twitter_' . $user->id . '_' . + $img_root . "_$size.$ext"; + + if ($this->fetchAvatar($url, $filename)) { + $this->newAvatar($id, $size, $mediatype, $filename); + } else { + common_log(LOG_WARNING, "Problem fetching Avatar: $url", __FILE__); + if (defined('SCRIPT_DEBUG')) { + print "Problem fetching Avatar: $url\n"; + } + } + } + } + + function updateAvatar($profile_id, $size, $mediatype, $filename) { + + common_debug("Updating avatar: $size"); + if (defined('SCRIPT_DEBUG')) { + print "Updating avatar: $size\n"; + } + + $profile = Profile::staticGet($profile_id); + + if (!$profile) { + common_debug("Couldn't get profile: $profile_id!"); + if (defined('SCRIPT_DEBUG')) { + print "Couldn't get profile: $profile_id!\n"; + } + return; + } + + $sizes = array('mini' => 24, 'normal' => 48, 'bigger' => 73); + $avatar = $profile->getAvatar($sizes[$size]); + + if ($avatar) { + common_debug("Deleting $size avatar for $profile->nickname."); + @unlink(INSTALLDIR . '/avatar/' . $avatar->filename); + $avatar->delete(); + } + + $this->newAvatar($profile->id, $size, $mediatype, $filename); + } + + function newAvatar($profile_id, $size, $mediatype, $filename) + { + global $config; + + $avatar = new Avatar(); + $avatar->profile_id = $profile_id; + + switch($size) { + case 'mini': + $avatar->width = 24; + $avatar->height = 24; + break; + case 'normal': + $avatar->width = 48; + $avatar->height = 48; + break; + default: + + // Note: Twitter's big avatars are a different size than + // Laconica's (Laconica's = 96) + + $avatar->width = 73; + $avatar->height = 73; + } + + $avatar->original = 0; // we don't have the original + $avatar->mediatype = $mediatype; + $avatar->filename = $filename; + $avatar->url = Avatar::url($filename); + + common_debug("new filename: $avatar->url"); + if (defined('SCRIPT_DEBUG')) { + print "New filename: $avatar->url\n"; + } + + $avatar->created = common_sql_now(); + + $id = $avatar->insert(); + + if (!$id) { + common_log_db_error($avatar, 'INSERT', __FILE__); + if (defined('SCRIPT_DEBUG')) { + print "Could not insert avatar!\n"; + } + + return null; + } + + common_debug("Saved new $size avatar for $profile_id."); + if (defined('SCRIPT_DEBUG')) { + print "Saved new $size avatar for $profile_id.\n"; + } + + return $id; + } + + function fetchAvatar($url, $filename) + { + $avatar_dir = INSTALLDIR . '/avatar/'; + + $avatarfile = $avatar_dir . $filename; + + $out = fopen($avatarfile, 'wb'); + if (!$out) { + common_log(LOG_WARNING, "Couldn't open file $filename", __FILE__); + if (defined('SCRIPT_DEBUG')) { + print "Couldn't open file! $filename\n"; + } + return false; + } + + common_debug("Fetching avatar: $url", __FILE__); + if (defined('SCRIPT_DEBUG')) { + print "Fetching avatar from Twitter: $url\n"; + } + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_FILE, $out); + curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); + $result = curl_exec($ch); + curl_close($ch); + + fclose($out); + + return $result; + } +} + +ini_set("max_execution_time", "0"); +ini_set("max_input_time", "0"); +set_time_limit(0); +mb_internal_encoding('UTF-8'); +declare(ticks = 1); + +$fetcher = new TwitterStatusFetcher(); +$fetcher->runOnce(); + -- cgit v1.2.3-54-g00ecf From 856e05a08ff8d09fbd580ed35906e3dda0475a0a Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 7 May 2009 01:10:31 -0700 Subject: Less pychotic debugging statements --- scripts/twitterstatusfetcher.php | 140 +++++++++++++++------------------------ 1 file changed, 52 insertions(+), 88 deletions(-) mode change 100644 => 100755 scripts/twitterstatusfetcher.php diff --git a/scripts/twitterstatusfetcher.php b/scripts/twitterstatusfetcher.php old mode 100644 new mode 100755 index 5275a4575..e8819f665 --- a/scripts/twitterstatusfetcher.php +++ b/scripts/twitterstatusfetcher.php @@ -72,10 +72,8 @@ class TwitterStatusFetcher extends Daemon if ($pid) { // Parent - common_debug("Parent: forked new status fetcher process " . $pid); - if (defined('SCRIPT_DEBUG')) { - print "Parent: forked fetcher process " . $pid . "\n"; + common_debug("Parent: forked new status fetcher process " . $pid); } $this->children[] = $pid; @@ -90,10 +88,8 @@ class TwitterStatusFetcher extends Daemon // Remove child from ps list as it finishes while(($c = pcntl_wait($status, WNOHANG OR WUNTRACED)) > 0) { - common_debug("Child $c finished."); - if (defined('SCRIPT_DEBUG')) { - print "Child $c finished.\n"; + common_debug("Child $c finished."); } $this->remove_ps($this->children, $c); @@ -102,18 +98,14 @@ class TwitterStatusFetcher extends Daemon // Wait! We have too many damn kids. if (sizeof($this->children) > MAXCHILDREN) { - common_debug('Too many children. Waiting...'); - if (defined('SCRIPT_DEBUG')) { - print "Too many children. Waiting...\n"; + common_debug('Too many children. Waiting...'); } if (($c = pcntl_wait($status, WUNTRACED)) > 0){ - common_debug("Finished waiting for $c"); - if (defined('SCRIPT_DEBUG')) { - print "Finished waiting for $c\n"; + common_debug("Finished waiting for $c"); } $this->remove_ps($this->children, $c); @@ -124,21 +116,18 @@ class TwitterStatusFetcher extends Daemon // Remove all children from the process list before restarting while(($c = pcntl_wait($status, WUNTRACED)) > 0) { - common_debug("Child $c finished."); - if (defined('SCRIPT_DEBUG')) { - print "Child $c finished.\n"; + common_debug("Child $c finished."); } $this->remove_ps($this->children, $c); } // Rest for a bit before we fetch more statuses - common_debug('Waiting ' . POLL_INTERVAL . - ' secs before hitting Twitter again.'); + if (defined('SCRIPT_DEBUG')) { - print 'Waiting ' . POLL_INTERVAL . - " secs before hitting Twitter again.\n"; + common_debug('Waiting ' . POLL_INTERVAL . + ' secs before hitting Twitter again.'); } sleep(POLL_INTERVAL); @@ -155,14 +144,16 @@ class TwitterStatusFetcher extends Daemon $cnt = $flink->find(); if (defined('SCRIPT_DEBUG')) { - print "Updating Twitter friends subscriptions for $cnt users.\n"; + common_debug('Updating Twitter friends subscriptions' . + " for $cnt users."); } $flinks = array(); while ($flink->fetch()) { - if (($flink->noticesync & FOREIGN_NOTICE_RECV) == FOREIGN_NOTICE_RECV) { + if (($flink->noticesync & FOREIGN_NOTICE_RECV) == + FOREIGN_NOTICE_RECV) { $flinks[] = clone($flink); } } @@ -187,30 +178,28 @@ class TwitterStatusFetcher extends Daemon { if (empty($flink)) { - common_log(LOG_WARNING, "Can't retrieve Foreign_link for foreign ID $fid"); - if (defined('SCRIPT_DEBUG')) { - print "Can't retrieve Foreign_link for foreign ID $fid\n"; - } + common_log(LOG_WARNING, + "Can't retrieve Foreign_link for foreign ID $fid"); return; } $fuser = $flink->getForeignUser(); if (empty($fuser)) { - common_log(LOG_WARNING, "Unmatched user for ID " . $flink->user_id); - if (defined('SCRIPT_DEBUG')) { - print "Unmatched user for ID $flink->user_id\n"; - } + common_log(LOG_WARNING, "Unmatched user for ID " . + $flink->user_id); return; } - common_debug('Trying to get timeline for Twitter user ' . - "$fuser->nickname ($flink->foreign_id)."); if (defined('SCRIPT_DEBUG')) { - print 'Trying to get timeline for Twitter user ' . - "$fuser->nickname ($flink->foreign_id).\n"; + common_debug('Trying to get timeline for Twitter user ' . + "$fuser->nickname ($flink->foreign_id)."); } + // XXX: Biggest remaining issue - How do we know at which status + // to start importing? How many statuses? Right now I'm going + // with the default last 20. + $url = 'http://twitter.com/statuses/friends_timeline.json'; $timeline_json = get_twitter_data($url, $fuser->nickname, @@ -220,18 +209,19 @@ class TwitterStatusFetcher extends Daemon if (empty($timeline)) { common_log(LOG_WARNING, "Empty timeline."); - if (defined('SCRIPT_DEBUG')) { - print "Empty timeline!\n"; - } return; } foreach ($timeline as $status) { - // Hacktastic: filter out stuff coming from Laconica + // Hacktastic: filter out stuff coming from this Laconica $source = mb_strtolower(common_config('integration', 'source')); if (preg_match("/$source/", mb_strtolower($status->source))) { + if (defined('SCRIPT_DEBUG')) { + common_debug('Skipping import of status ' . $status->id . + ' with source ' . $source); + } continue; } @@ -239,7 +229,6 @@ class TwitterStatusFetcher extends Daemon } // Okay, record the time we synced with Twitter for posterity - $flink->last_noticesync = common_sql_now(); $flink->update(); } @@ -250,18 +239,14 @@ class TwitterStatusFetcher extends Daemon $profile = Profile::staticGet($id); if (!$profile) { - common_log(LOG_ERR, 'Problem saving notice. No associated Profile.'); - if (defined('SCRIPT_DEBUG')) { - print "Problem saving notice. No associated Profile.\n"; - } + common_log(LOG_ERR, + 'Problem saving notice. No associated Profile.'); return null; } $uri = 'http://twitter.com/' . $status->user->screen_name . '/status/' . $status->id; - // Skip save if notice source is Laconica or Identi.ca? - $notice = Notice::staticGet('uri', $uri); // check to see if we've already imported the status @@ -290,21 +275,23 @@ class TwitterStatusFetcher extends Daemon if (!$notice_id) { common_log_db_error($notice, 'INSERT', __FILE__); if (defined('SCRIPT_DEBUG')) { - print "Could not save notice!\n"; + common_debug('Could not save notice!'); } } - // XXX: Figure out a better way to link replies? + // XXX: Figure out a better way to link Twitter replies? $notice->saveReplies(); - // XXX: Do we want to polute our tag cloud with hashtags from Twitter? + // XXX: Do we want to polute our tag cloud with + // hashtags from Twitter? $notice->saveTags(); $notice->saveGroups(); $notice->query('COMMIT'); if (defined('SCRIPT_DEBUG')) { - print "Saved status $status->id as notice $notice->id.\n"; + common_debug("Saved status $status->id" . + " as notice $notice->id."); } } @@ -327,18 +314,19 @@ class TwitterStatusFetcher extends Daemon $profile = Profile::staticGet('profileurl', $profileurl); if ($profile) { - common_debug("Profile for $profile->nickname found."); + if (defined('SCRIPT_DEBUG')) { + common_debug("Profile for $profile->nickname found."); + } // Check to see if the user's Avatar has changed $this->checkAvatar($user, $profile); + return $profile->id; } else { - $debugmsg = 'Adding profile and remote profile ' . - "for Twitter user: $profileurl\n"; - common_debug($debugmsg, __FILE__); if (defined('SCRIPT_DEBUG')) { - print $debugmsg; + common_debug('Adding profile and remote profile ' . + "for Twitter user: $profileurl"); } $profile = new Profile(); @@ -356,10 +344,6 @@ class TwitterStatusFetcher extends Daemon if (empty($id)) { common_log_db_error($profile, 'INSERT', __FILE__); - if (defined('SCRIPT_DEBUG')) { - print 'Could not insert Profile: ' . - common_log_objstring($profile) . "\n"; - } $profile->query("ROLLBACK"); return false; } @@ -379,10 +363,6 @@ class TwitterStatusFetcher extends Daemon if (empty($rid)) { common_log_db_error($profile, 'INSERT', __FILE__); - if (defined('SCRIPT_DEBUG')) { - print 'Could not insert Remote_profile: ' . - common_log_objstring($remote_pro) . "\n"; - } $profile->query("ROLLBACK"); return false; } @@ -408,13 +388,10 @@ class TwitterStatusFetcher extends Daemon if ($newname != $oldname) { - common_debug("Avatar for Twitter user $profile->nickname has changed."); - common_debug("old: $oldname new: $newname"); - if (defined('SCRIPT_DEBUG')) { - print "Avatar for Twitter user $user->id has changed.\n"; - print "old: $oldname\n"; - print "new: $newname\n"; + common_debug('Avatar for Twitter user ' . + "$profile->nickname has changed."); + common_debug("old: $oldname new: $newname"); } $img_root = substr($path_parts['basename'], 0, -11); @@ -472,26 +449,21 @@ class TwitterStatusFetcher extends Daemon $this->newAvatar($id, $size, $mediatype, $filename); } else { common_log(LOG_WARNING, "Problem fetching Avatar: $url", __FILE__); - if (defined('SCRIPT_DEBUG')) { - print "Problem fetching Avatar: $url\n"; - } } } } function updateAvatar($profile_id, $size, $mediatype, $filename) { - common_debug("Updating avatar: $size"); if (defined('SCRIPT_DEBUG')) { - print "Updating avatar: $size\n"; + common_debug("Updating avatar: $size"); } $profile = Profile::staticGet($profile_id); if (!$profile) { - common_debug("Couldn't get profile: $profile_id!"); if (defined('SCRIPT_DEBUG')) { - print "Couldn't get profile: $profile_id!\n"; + common_debug("Couldn't get profile: $profile_id!"); } return; } @@ -500,7 +472,9 @@ class TwitterStatusFetcher extends Daemon $avatar = $profile->getAvatar($sizes[$size]); if ($avatar) { - common_debug("Deleting $size avatar for $profile->nickname."); + if (defined('SCRIPT_DEBUG')) { + common_debug("Deleting $size avatar for $profile->nickname."); + } @unlink(INSTALLDIR . '/avatar/' . $avatar->filename); $avatar->delete(); } @@ -538,9 +512,8 @@ class TwitterStatusFetcher extends Daemon $avatar->filename = $filename; $avatar->url = Avatar::url($filename); - common_debug("new filename: $avatar->url"); if (defined('SCRIPT_DEBUG')) { - print "New filename: $avatar->url\n"; + common_debug("new filename: $avatar->url"); } $avatar->created = common_sql_now(); @@ -549,16 +522,11 @@ class TwitterStatusFetcher extends Daemon if (!$id) { common_log_db_error($avatar, 'INSERT', __FILE__); - if (defined('SCRIPT_DEBUG')) { - print "Could not insert avatar!\n"; - } - return null; } - common_debug("Saved new $size avatar for $profile_id."); if (defined('SCRIPT_DEBUG')) { - print "Saved new $size avatar for $profile_id.\n"; + common_debug("Saved new $size avatar for $profile_id."); } return $id; @@ -573,15 +541,11 @@ class TwitterStatusFetcher extends Daemon $out = fopen($avatarfile, 'wb'); if (!$out) { common_log(LOG_WARNING, "Couldn't open file $filename", __FILE__); - if (defined('SCRIPT_DEBUG')) { - print "Couldn't open file! $filename\n"; - } return false; } - common_debug("Fetching avatar: $url", __FILE__); if (defined('SCRIPT_DEBUG')) { - print "Fetching avatar from Twitter: $url\n"; + common_debug("Fetching avatar: $url"); } $ch = curl_init(); -- cgit v1.2.3-54-g00ecf From bc190595d1dfd56bf7e68597b3d574909eb27260 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 7 May 2009 02:07:31 -0700 Subject: Added TwitterStatusFetcher into daemon startup and shutdown subsystem --- config.php.sample | 3 +++ lib/common.php | 2 ++ scripts/getvaliddaemons.php | 3 +++ scripts/stopdaemons.sh | 2 +- scripts/twitterstatusfetcher.php | 10 ++++++---- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/config.php.sample b/config.php.sample index b8ed45fa8..6d6a9b533 100644 --- a/config.php.sample +++ b/config.php.sample @@ -150,6 +150,9 @@ $config['sphinx']['port'] = 3312; #$config['memcached']['server'] = 'localhost'; #$config['memcached']['port'] = 11211; +# Enable bidirectional Twitter bridge +#$config['twitterbridge']['enabled'] = true; + #Twitter integration source attribute. Note: default is Laconica #$config['integration']['source'] = 'Laconica'; diff --git a/lib/common.php b/lib/common.php index 00e5b0bc2..abdc22c0e 100644 --- a/lib/common.php +++ b/lib/common.php @@ -143,6 +143,8 @@ $config = array('piddir' => '/var/run', 'user' => false, 'group' => false), + 'twitterbridge' => + array('enabled' => false), 'integration' => array('source' => 'Laconica', # source attribute for Twitter 'taguri' => $_server.',2009'), # base for tag URIs diff --git a/scripts/getvaliddaemons.php b/scripts/getvaliddaemons.php index 482e63af7..a10233e69 100755 --- a/scripts/getvaliddaemons.php +++ b/scripts/getvaliddaemons.php @@ -44,6 +44,9 @@ if(common_config('xmpp','enabled')) { if(common_config('memcached','enabled')) { echo "memcachedqueuehandler.php "; } +if(common_config('twitterbridge','enabled')) { + echo "twitterstatusfetcher.php "; +} echo "ombqueuehandler.php "; echo "twitterqueuehandler.php "; echo "facebookqueuehandler.php "; diff --git a/scripts/stopdaemons.sh b/scripts/stopdaemons.sh index f6d71eddf..764037e8f 100755 --- a/scripts/stopdaemons.sh +++ b/scripts/stopdaemons.sh @@ -25,7 +25,7 @@ DIR=`php $SDIR/getpiddir.php` for f in jabberhandler ombhandler publichandler smshandler pinghandler \ xmppconfirmhandler xmppdaemon twitterhandler facebookhandler \ - memcachehandler inboxhandler; do + memcachehandler inboxhandler twitterstatusfetcher; do FILES="$DIR/$f.*.pid" for ff in "$FILES" ; do diff --git a/scripts/twitterstatusfetcher.php b/scripts/twitterstatusfetcher.php index e8819f665..9dfadc760 100755 --- a/scripts/twitterstatusfetcher.php +++ b/scripts/twitterstatusfetcher.php @@ -32,7 +32,7 @@ define('LACONICA', true); define('MAXCHILDREN', 2); define('POLL_INTERVAL', 60); // in seconds -// Uncomment this to get useful console output +// Uncomment this to get useful logging define('SCRIPT_DEBUG', true); require_once(INSTALLDIR . '/lib/common.php'); @@ -45,7 +45,7 @@ class TwitterStatusFetcher extends Daemon function name() { - return 'twitterstatusfetcher'; + return ('twitterstatusfetcher.generic'); } function run() @@ -130,7 +130,9 @@ class TwitterStatusFetcher extends Daemon ' secs before hitting Twitter again.'); } - sleep(POLL_INTERVAL); + if (POLL_INTERVAL > 0) { + sleep(POLL_INTERVAL); + } } while (true); } @@ -282,7 +284,7 @@ class TwitterStatusFetcher extends Daemon // XXX: Figure out a better way to link Twitter replies? $notice->saveReplies(); - // XXX: Do we want to polute our tag cloud with + // XXX: Do we want to pollute our tag cloud with // hashtags from Twitter? $notice->saveTags(); $notice->saveGroups(); -- cgit v1.2.3-54-g00ecf From 5771f413bb28502540d3bc017bc58433e9b0abf9 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 7 May 2009 02:08:49 -0700 Subject: Fil's Patch to DB_DataObject to make it reconnect to the DB if there's no connection. This patch has been added upstream and will be in the next release, but I need it now for the bidirectional bridge to work. --- extlib/DB/DataObject.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/extlib/DB/DataObject.php b/extlib/DB/DataObject.php index b1a1a4e21..0c6a13dc2 100644 --- a/extlib/DB/DataObject.php +++ b/extlib/DB/DataObject.php @@ -2357,6 +2357,8 @@ class DB_DataObject extends DB_DataObject_Overload $t= explode(' ',microtime()); $_DB_DATAOBJECT['QUERYENDTIME'] = $time = $t[0]+$t[1]; + + do { if ($_DB_driver == 'DB') { $result = $DB->query($string); @@ -2374,8 +2376,19 @@ class DB_DataObject extends DB_DataObject_Overload break; } } - - + + // try to reconnect, at most 3 times + $again = false; + if (is_a($result, 'PEAR_Error') + AND $result->getCode() == DB_ERROR_NODBSELECTED + AND $cpt++<3) { + $DB->disconnect(); + sleep(1); + $DB->connect($DB->dsn); + $again = true; + } + + } while ($again); if (is_a($result,'PEAR_Error')) { if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) { -- cgit v1.2.3-54-g00ecf From 4b0e5ff271d4ac0af3256b2716f1e1362ddb02d8 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 7 May 2009 14:07:03 -0700 Subject: Added Twitter to notice sources --- db/notice_source.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/db/notice_source.sql b/db/notice_source.sql index ce44f3235..e6e2180a5 100644 --- a/db/notice_source.sql +++ b/db/notice_source.sql @@ -43,6 +43,7 @@ VALUES ('twidge','Twidge','http://software.complete.org/twidge', now()), ('twidroid','twidroid','http://www.twidroid.com/', now()), ('twittelator','Twittelator','http://www.stone.com/iPhone/Twittelator/', now()), + ('twitter','Twitter','http://twitter.com/', now()), ('twitterfeed','twitterfeed','http://twitterfeed.com/', now()), ('twitterphoto','TwitterPhoto','http://richfish.org/twitterphoto/', now()), ('twitterpm','Net::Twitter','http://search.cpan.org/dist/Net-Twitter/', now()), -- cgit v1.2.3-54-g00ecf From fbf23ae0ee4c8c63e80e3511aa7fce980b8d1ed5 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 7 May 2009 14:41:53 -0700 Subject: Only show import friends timeline option if bidirectional bridge enabled --- actions/twittersettings.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/actions/twittersettings.php b/actions/twittersettings.php index 580d9ecf7..1bce57695 100644 --- a/actions/twittersettings.php +++ b/actions/twittersettings.php @@ -158,13 +158,22 @@ class TwittersettingsAction extends ConnectSettingsAction ($flink->friendsync & FOREIGN_FRIEND_RECV) : false); $this->elementEnd('li'); - $this->elementStart('li'); - $this->checkbox('noticerecv', - _('Import my Friends Timeline.'), - ($flink) ? - ($flink->noticesync & FOREIGN_NOTICE_RECV) : - false); - $this->elementEnd('li'); + + if (common_config('twitterbridge','enabled')) { + $this->elementStart('li'); + $this->checkbox('noticerecv', + _('Import my Friends Timeline.'), + ($flink) ? + ($flink->noticesync & FOREIGN_NOTICE_RECV) : + false); + $this->elementEnd('li'); + } else { + // preserve setting even if bidrection bridge toggled off + if ($flink && ($flink->noticesync & FOREIGN_NOTICE_RECV)) { + $this->hidden('noticerecv', true, 'noticerecv'); + } + } + $this->elementEnd('ul'); if ($flink) { -- cgit v1.2.3-54-g00ecf From 3e7b1e69e3e97ac007465376b62084f10bcf97ca Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 28 Apr 2009 17:08:20 -0700 Subject: Added dirty dates to Foreign_link --- classes/Foreign_link.php | 2 ++ classes/laconica.ini | 2 ++ db/laconica.sql | 2 ++ 3 files changed, 6 insertions(+) diff --git a/classes/Foreign_link.php b/classes/Foreign_link.php index afc0e2180..af2b3f189 100644 --- a/classes/Foreign_link.php +++ b/classes/Foreign_link.php @@ -17,6 +17,8 @@ class Foreign_link extends Memcached_DataObject public $noticesync; // tinyint(1) not_null default_1 public $friendsync; // tinyint(1) not_null default_2 public $profilesync; // tinyint(1) not_null default_1 + public $last_noticesync; // datetime() + public $last_friendsync; // datetime() public $created; // datetime() not_null public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP diff --git a/classes/laconica.ini b/classes/laconica.ini index 529454d99..c05419588 100755 --- a/classes/laconica.ini +++ b/classes/laconica.ini @@ -55,6 +55,8 @@ credentials = 2 noticesync = 145 friendsync = 145 profilesync = 145 +last_noticesync = 14 +last_friendsync = 14 created = 142 modified = 384 diff --git a/db/laconica.sql b/db/laconica.sql index 5b57494d9..c9730098e 100644 --- a/db/laconica.sql +++ b/db/laconica.sql @@ -289,6 +289,8 @@ create table foreign_link ( noticesync tinyint not null default 1 comment 'notice synchronization, bit 1 = sync outgoing, bit 2 = sync incoming, bit 3 = filter local replies', friendsync tinyint not null default 2 comment 'friend synchronization, bit 1 = sync outgoing, bit 2 = sync incoming', profilesync tinyint not null default 1 comment 'profile synchronization, bit 1 = sync outgoing, bit 2 = sync incoming', + last_noticesync datetime default null comment 'last time notices were imported', + last_friendsync datetime default null comment 'last time friends were imported', created datetime not null comment 'date this record was created', modified timestamp comment 'date this record was modified', -- cgit v1.2.3-54-g00ecf From 11e0db8c2cec18337fd960ccda055dd14d89f9d7 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 7 May 2009 18:22:14 -0700 Subject: Twitter friends sync now does 25 users at a time and uses last_friendsync field to prioritize --- actions/twittersettings.php | 4 +++- scripts/synctwitterfriends.php | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/actions/twittersettings.php b/actions/twittersettings.php index 45725d3ff..0b98eef59 100644 --- a/actions/twittersettings.php +++ b/actions/twittersettings.php @@ -261,7 +261,7 @@ class TwittersettingsAction extends ConnectSettingsAction 'alt' => ($other->fullname) ? $other->fullname : $other->nickname)); - + $this->element('span', 'fn nickname', $other->nickname); $this->elementEnd('a'); $this->elementEnd('li'); @@ -375,6 +375,8 @@ class TwittersettingsAction extends ConnectSettingsAction if ($friendsync) { save_twitter_friends($user, $twit_user->id, $screen_name, $password); + $flink->last_friendsync = common_sql_now(); + $flink->update(); } $this->showForm(_('Twitter settings saved.'), true); diff --git a/scripts/synctwitterfriends.php b/scripts/synctwitterfriends.php index 794301f0f..bd08ba58d 100755 --- a/scripts/synctwitterfriends.php +++ b/scripts/synctwitterfriends.php @@ -32,8 +32,25 @@ define('LACONICA', true); require_once(INSTALLDIR . '/lib/common.php'); +// Make a lockfile +$lockfilename = lockFilename(); +if (!($lockfile = @fopen($lockfilename, "w"))) { + print "Already running... exiting.\n"; + exit(1); +} + +// Obtain an exlcusive lock on file (will fail if script is already going) +if (!@flock( $lockfile, LOCK_EX | LOCK_NB, &$wouldblock) || $wouldblock) { + // Script already running - abort + @fclose($lockfile); + print "Already running... exiting.\n"; + exit(1); +} + $flink = new Foreign_link(); $flink->service = 1; // Twitter +$flink->orderBy('last_friendsync'); +$flink->limit(25); // sync this many users during this run $cnt = $flink->find(); print "Updating Twitter friends subscriptions for $cnt users.\n"; @@ -60,8 +77,11 @@ while ($flink->fetch()) { continue; } - $result = save_twitter_friends($user, $fuser->id, - $fuser->nickname, $flink->credentials); + save_twitter_friends($user, $fuser->id, $fuser->nickname, $flink->credentials); + + $flink->last_friendsync = common_sql_now(); + $flink->update(); + if (defined('SCRIPT_DEBUG')) { print "\nDONE\n"; } else { @@ -70,4 +90,18 @@ while ($flink->fetch()) { } } +function lockFilename() +{ + $piddir = common_config('daemon', 'piddir'); + if (!$piddir) { + $piddir = '/var/run'; + } + + return $piddir . '/synctwitterfriends.lock'; +} + +// Cleanup +fclose($lockfile); +unlink($lockfilename); + exit(0); -- cgit v1.2.3-54-g00ecf From 9a8095079dc602c7f2b74e48237445d682844de6 Mon Sep 17 00:00:00 2001 From: CiaranG Date: Fri, 8 May 2009 08:14:50 +0100 Subject: PostgreSQL - added dirty dates to Foreign_link - see 3e7b1e69e3e97ac007465376b62084f10bcf97ca --- db/laconica_pg.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db/laconica_pg.sql b/db/laconica_pg.sql index f879d7936..a27a616f2 100644 --- a/db/laconica_pg.sql +++ b/db/laconica_pg.sql @@ -291,6 +291,8 @@ create table foreign_link ( noticesync int not null default 1 /* comment 'notice synchronisation, bit 1 = sync outgoing, bit 2 = sync incoming, bit 3 = filter local replies' */, friendsync int not null default 2 /* comment 'friend synchronisation, bit 1 = sync outgoing, bit 2 = sync incoming */, profilesync int not null default 1 /* comment 'profile synchronization, bit 1 = sync outgoing, bit 2 = sync incoming' */, + last_noticesync timestamp default null /* comment 'last time notices were imported' */, + last_friendsync timestamp default null /* comment 'last time friends were imported' */, created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */, modified timestamp /* comment 'date this record was modified' */, -- cgit v1.2.3-54-g00ecf From 8fc8eaa1b6199d74f0e17197650c6316b4594203 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Sun, 10 May 2009 23:14:42 +0000 Subject: Init biz theme Design is similar (inspired) to http://drupal.org/project/acquia_marina Two of the background illustrations are reused. --- theme/biz/css/base.css | 1170 ++++++++++++++++++++ theme/biz/css/display.css | 252 +++++ theme/biz/css/ie.css | 9 + theme/biz/default-avatar-mini.png | Bin 0 -> 646 bytes theme/biz/default-avatar-profile.png | Bin 0 -> 2853 bytes theme/biz/default-avatar-stream.png | Bin 0 -> 1487 bytes theme/biz/images/illustrations/illu_pattern-01.png | Bin 0 -> 935 bytes theme/biz/images/illustrations/illu_pattern-02.png | Bin 0 -> 9498 bytes theme/biz/logo.png | Bin 0 -> 4988 bytes 9 files changed, 1431 insertions(+) create mode 100644 theme/biz/css/base.css create mode 100644 theme/biz/css/display.css create mode 100644 theme/biz/css/ie.css create mode 100644 theme/biz/default-avatar-mini.png create mode 100644 theme/biz/default-avatar-profile.png create mode 100644 theme/biz/default-avatar-stream.png create mode 100644 theme/biz/images/illustrations/illu_pattern-01.png create mode 100644 theme/biz/images/illustrations/illu_pattern-02.png create mode 100644 theme/biz/logo.png diff --git a/theme/biz/css/base.css b/theme/biz/css/base.css new file mode 100644 index 000000000..22bbced08 --- /dev/null +++ b/theme/biz/css/base.css @@ -0,0 +1,1170 @@ +/** theme: biz base + * + * @package Laconica + * @author Sarven Capadisli + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +* { margin:0; padding:0; } +img { display:block; border:0; } +a abbr { cursor: pointer; border-bottom:0; } +table { border-collapse:collapse; } +ol { list-style-position:inside; } +html { font-size: 87.5%; background-color:#fff; height:100%; } +body { +background-color:#fff; +color:#000; +font-family:sans-serif; +font-size:1em; +line-height:1.65; +position:relative; +} +h1,h2,h3,h4,h5,h6 { +margin-bottom:7px; +overflow:hidden; +} +h1 { +font-size:1.4em; +margin-bottom:18px; +} +#showstream h1 { display:none; } +h2 { font-size:1.3em; } +h3 { font-size:1.2em; } +h4 { font-size:1.1em; } +h5 { font-size:1em; } +h6 { font-size:0.9em; } + +caption { +font-weight:bold; +} +legend { +font-weight:bold; +font-size:1.3em; +} +input, textarea, select, option { +padding:4px; +font-family:sans-serif; +font-size:1em; +} +input, textarea, select { +border-width:2px; +border-style: solid; +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +} + +input.submit { +font-weight:bold; +cursor:pointer; +} +textarea { +overflow:auto; +} +option { +padding-bottom:0; +} +fieldset { +padding:0; +border:0; +} +form ul li { +list-style-type:none; +margin:0 0 18px 0; +} +form label { +font-weight:bold; +} +input.checkbox { +position:relative; +top:2px; +left:0; +border:0; +} + +.error, +.success { +padding:4px 1.55%; +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +margin-bottom:18px; +} +form label.submit { +display:none; +} + +.form_settings { +clear:both; +} + +.form_settings fieldset { +margin-bottom:29px; +} +.form_settings input.remove { +margin-left:11px; +} +.form_settings .form_data li { +width:100%; +float:left; +} +.form_settings .form_data label { +float:left; +} +.form_settings .form_data textarea, +.form_settings .form_data select, +.form_settings .form_data input { +margin-left:11px; +float:left; +} +.form_settings .form_data input.submit { +margin-left:0; +} + +.form_settings label { +margin-top:2px; +width:113px; +} + +.form_actions label { +display:none; +} +.form_guide { +font-style:italic; +} + +.form_settings #settings_autosubscribe label { +display:inline; +font-weight:bold; +} + +#form_settings_profile legend, +#form_login legend, +#form_register legend, +#form_password legend, +#form_settings_avatar legend, +#newgroup legend, +#editgroup legend, +#form_tag_user legend, +#form_remote_subscribe legend, +#form_openid_login legend, +#form_search legend, +#form_invite legend, +#form_notice_delete legend, +#form_password_recover legend, +#form_password_change legend { +display:none; +} + +.form_settings .form_data p.form_guide { +clear:both; +margin-left:124px; +margin-bottom:0; +} + +.form_settings p { +margin-bottom:11px; +} + +.form_settings input.checkbox { +margin-top:3px; +margin-left:0; +} +.form_settings label.checkbox { +font-weight:normal; +margin-top:0; +margin-right:0; +margin-left:11px; +float:left; +width:90%; +} + + +#form_login p.form_guide, +#form_register #settings_rememberme p.form_guide, +#form_openid_login #settings_rememberme p.form_guide, +#settings_twitter_remove p.form_guide, +#form_search ul.form_data #q { +margin-left:0; +} + +.form_settings .form_note { +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +padding:0 7px; +} + + +.form_settings input.form_action-secondary { +margin-left:29px; +padding:0; +} + +#form_search .submit { +margin-left:11px; +} + +address { +float:left; +margin-bottom:18px; +margin-left:18px; +} +address.vcard img.logo { +margin-right:0; +} +address .fn { +font-weight:bold; +} +address img + .fn { +display:none; +} + +#header { +width:100%; +position:relative; +float:left; +padding-top:18px; +margin-bottom:18px; +} + +#site_nav_global_primary { +float:left; +margin-right:18px; +margin-bottom:11px; +width:50%; +} +#site_nav_global_primary ul li { +display:inline; +margin-right:11px; +} + +.system_notice dt { +font-weight:bold; +text-transform:uppercase; +display:none; +} + +#site_notice { +float:right; +clear:right; +margin-top:7px; +margin-right:18px; +width:24%; +} +#page_notice { +clear:both; +margin-bottom:18px; +} + + +#anon_notice { +float:left; +width:45.4%; +/* +border-radius:7px; +-moz-border-radius:7px; +-webkit-border-radius:7px; +border-width:2px; +border-style:solid; +*/ +line-height:1.5; +font-size:1.1em; +font-weight:bold; +} + + +#footer { +float:left; +width:64%; +padding:18px; +} + +#site_nav_local_views { +width:14.5%; +float:left; +} +#site_nav_local_views dt { +display:none; +} +#site_nav_local_views li { +list-style-type:none; +} +#site_nav_local_views a { +display:block; +text-decoration:none; +padding:4px 11px; +-moz-border-radius-topleft:4px; +-moz-border-radius-bottomleft:4px; +-webkit-border-top-left-radius:4px; +-webkit-border-bottom-left-radius:4px; +border-width:1px; +border-style:solid; +border-right:0; +text-shadow: 2px 2px 2px #ddd; +font-weight:bold; +} +#site_nav_local_views .nav { +float:left; +width:100%; +} + +#site_nav_global_primary dt, +#site_nav_global_secondary dt { +display:none; +} + +#site_nav_global_secondary { +margin-bottom:11px; +} + +#site_nav_global_secondary ul li { +display:inline; +margin-right:11px; +} +#export_data li a { +padding-left:20px; +} +#export_data li a.foaf { +padding-left:30px; +} +#export_data li a.export_vcard { +padding-left:28px; +} + +#export_data ul { +display:inline; +} +#export_data li { +list-style-type:none; +display:inline; +margin-left:11px; +} +#export_data li:first-child { +margin-left:0; +} + +#licenses { +font-size:0.9em; +} + +#licenses dt { +font-weight:bold; +display:none; +} +#licenses dd { +margin-bottom:11px; +line-height:1.5; +} + +#site_content_license_cc { +margin-bottom:0; +} +#site_content_license_cc img { +display:inline; +vertical-align:top; +margin-right:4px; +} + +#wrap { +margin:0 auto; +width:100%; +min-width:760px; +max-width:1003px; +overflow:hidden; +} + +#core { +position:relative; +width:100%; +float:left; +margin-bottom:1em; +} + +#content { +width:51.009%; +min-height:259px; +padding:1.795%; +float:left; +border-radius:7px; +-moz-border-radius:7px; +-moz-border-radius-topleft:0; +-webkit-border-radius:7px; +-webkit-border-top-left-radius:0; +border-style:solid; +border-width:1px; +} +#shownotice #content { +min-height:0; +} + +#content_inner { +position:relative; +width:100%; +float:left; +} + +#aside_primary { +width:29.917%; +min-height:259px; +float:left; +margin-left:0.385%; +} + +#form_notice { +width:45.664%; +float:left; +position:relative; +line-height:1; +} +#form_notice fieldset { +border:0; +padding:0; +position:relative; +} +#form_notice legend { +display:none; +} +#form_notice textarea { +float:left; +border-radius:7px; +-moz-border-radius:7px; +-webkit-border-radius:7px; +width:80.789%; +height:67px; +line-height:1.5; +padding:7px 7px 16px 7px; +} +#form_notice label { +display:block; +float:left; +font-size:1.3em; +margin-bottom:7px; +} +#form_notice #notice_submit label { +display:none; +} +#form_notice .form_note { +position:absolute; +top:99px; +right:98px; +z-index:9; +} +#form_notice .form_note dt { +font-weight:bold; +display:none; +} +#notice_text-count { +font-weight:bold; +line-height:1.15; +padding:1px 2px; +} +#form_notice #notice_action-submit { +width:14%; +height:47px; +padding:0; +position:absolute; +bottom:0; +right:0; +} +#form_notice label[for=to] { +margin-top:7px; +} +#form_notice select[id=to] { +margin-bottom:7px; +margin-left:18px; +float:left; +} +#form_notice .error { +float:left; +clear:both; +width:96.9%; +margin-bottom:0; +line-height:1.618; +} + +/* entity_profile */ +.entity_profile { +position:relative; +width:67.702%; +min-height:123px; +float:left; +margin-bottom:18px; +margin-left:0; +overflow:hidden; +} +.entity_profile dt, +#entity_statistics dt { +font-weight:bold; +} +.entity_profile dd { +display:inline; +} + +.entity_profile .entity_depiction { +float:left; +width:96px; +margin-right:18px; +margin-bottom:18px; +} + +.entity_profile .entity_fn, +.entity_profile .entity_nickname, +.entity_profile .entity_location, +.entity_profile .entity_url, +.entity_profile .entity_note, +.entity_profile .entity_tags { +margin-left:113px; +margin-bottom:4px; +} + +.entity_profile .entity_fn, +.entity_profile .entity_nickname { +margin-left:11px; +display:inline; +font-weight:bold; +} +.entity_profile .entity_nickname { +margin-left:0; +} + +.entity_profile .entity_fn dd:before { +content: "("; +font-weight:normal; +} +.entity_profile .entity_fn dd:after { +content: ")"; +font-weight:normal; +} + +.entity_profile dt { +display:none; +} +.entity_profile h2 { +display:none; +} +/* entity_profile */ + + +/*entity_actions*/ +.entity_actions { +float:right; +margin-left:4.35%; +max-width:25%; +} +.entity_actions h2 { +display:none; +} +.entity_actions ul { +list-style-type:none; +} +.entity_actions li { +margin-bottom:4px; +} +.entity_actions li:first-child { +border-top:0; +} +.entity_actions fieldset { +border:0; +padding:0; +} +.entity_actions legend { +display:none; +} + +.entity_actions input.submit { +display:block; +text-align:left; +width:100%; +} +.entity_actions a, +.entity_nudge p, +.entity_remote_subscribe { +text-decoration:none; +font-weight:bold; +display:block; +} + +.form_user_block input.submit, +.form_user_unblock input.submit, +.entity_send-a-message a, +.entity_edit a, +.form_user_nudge input.submit, +.entity_nudge p { +border:0; +padding-left:20px; +} + +.entity_edit a, +.entity_send-a-message a, +.entity_nudge p { +padding:4px 4px 4px 23px; +} + +.entity_remote_subscribe { +padding:4px; +border-width:2px; +border-style:solid; +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +} +.entity_actions .accept { +margin-bottom:18px; +} + +.entity_tags ul { +list-style-type:none; +display:inline; +} +.entity_tags li { +display:inline; +margin-right:4px; +} + +.aside .section { +margin-bottom:18px; +clear:both; +float:left; +width:87.985%; +padding:6%; +border-radius:7px; +-moz-border-radius:7px; +-webkit-border-radius:7px; +border-width:1px; +border-style:solid; +} +.aside .section h2 { +text-transform:uppercase; +font-size:1em; +} + +#entity_statistics dt, +#entity_statistics dd { +display:inline; +} +#entity_statistics dt:after { +content: ":"; +} + +.section ul.entities { +float:left; +width:100%; +} +.section .entities li { +list-style-type:none; +float:left; +margin-right:7px; +margin-bottom:7px; +} +.section .entities li .photo { +margin-right:0; +margin-bottom:0; +} +.section .entities li .fn { +display:none; +} + +.aside .section p, +.aside .section .more { +clear:both; +} + +.profile .entity_profile { +margin-bottom:0; +min-height:60px; +} + + +.profile .form_group_join legend, +.profile .form_group_leave legend, +.profile .form_user_subscribe legend, +.profile .form_user_unsubscribe legend { +display:none; +} + +.profiles { +list-style-type:none; +} +.profile .entity_profile .entity_location { +width:auto; +clear:none; +margin-left:11px; +} +.profile .entity_profile dl, +.profile .entity_profile dd { +display:inline; +float:none; +} +.profile .entity_profile .entity_note, +.profile .entity_profile .entity_url, +.profile .entity_profile .entity_tags, +.profile .entity_profile .form_subscription_edit { +margin-left:59px; +clear:none; +display:block; +width:auto; +} +.profile .entity_profile .entity_tags dt { +display:inline; +margin-right:11px; +} + + +.profile .entity_profile .form_subscription_edit label { +font-weight:normal; +margin-right:11px; +} + + +/* NOTICE */ +.notice, +.profile { +position:relative; +padding-top:11px; +padding-bottom:11px; +clear:both; +float:left; +width:100%; +border-top-width:1px; +border-top-style:dotted; +} +.notices li { +list-style-type:none; +} +.notices li.hover { +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +} + +/* NOTICES */ +#notices_primary { +float:left; +width:100%; +border-radius:7px; +-moz-border-radius:7px; +-webkit-border-radius:7px; +} +#notices_primary h2 { +display:none; +} +.notice-data a span { +display:block; +padding-left:28px; +} + +.notice .author { +margin-right:11px; +} + +.fn { +overflow:hidden; +} + +.notice .author .fn { +font-weight:bold; +} + +.vcard .photo { +display:inline; +margin-right:11px; +float:left; +} +#shownotice .vcard .photo { +margin-bottom:4px; +} +.vcard .url { +text-decoration:none; +} +.vcard .url:hover { +text-decoration:underline; +} + +.notice .entry-title { +float:left; +width:100%; +overflow:hidden; +} +#shownotice .notice .entry-title { +font-size:2.2em; +} + +.notice p.entry-content { +display:inline; +} + +#content .notice p.entry-content a:visited { +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +} +.notice p.entry-content .vcard a { +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +} + +.notice div.entry-content { +clear:left; +float:left; +font-size:0.95em; +margin-left:59px; +width:65%; +} +#showstream .notice div.entry-content, +#shownotice .notice div.entry-content { +margin-left:0; +} + +.notice .notice-options a, +.notice .notice-options input { +float:left; +font-size:1.025em; +} + +.notice div.entry-content dl, +.notice div.entry-content dt, +.notice div.entry-content dd { +display:inline; +} + +.notice div.entry-content .timestamp dt, +.notice div.entry-content .response dt { +display:none; +} +.notice div.entry-content .timestamp a { +display:inline-block; +} +.notice div.entry-content .device dt { +text-transform:lowercase; +} + + +.notice-options { +padding-left:2%; +float:left; +width:50%; +position:relative; +font-size:0.95em; +width:12.5%; +float:right; +} + +.notice-options a { +float:left; +} +.notice-options .notice_delete, +.notice-options .notice_reply, +.notice-options .form_favor, +.notice-options .form_disfavor { +position:absolute; +top:0; +} +.notice-options .form_favor, +.notice-options .form_disfavor { +left:0; +} +.notice-options .notice_reply { +left:29px; +} +.notice-options .notice_delete { +right:0; +} +.notice-options .notice_reply dt { +display:none; +} + +.notice-options input, +.notice-options a { +text-indent:-9999px; +outline:none; +} + +.notice-options .notice_reply a, +.notice-options input.submit { +display:block; +border:0; +} +.notice-options .notice_reply a, +.notice-options .notice_delete a { +text-decoration:none; +padding-left:16px; +} + +.notice-options form input.submit { +width:16px; +padding:2px 0; +} + +.notice-options .notice_delete dt, +.notice-options .form_favor legend, +.notice-options .form_disfavor legend { +display:none; +} +.notice-options .notice_delete fieldset, +.notice-options .form_favor fieldset, +.notice-options .form_disfavor fieldset { +border:0; +padding:0; +} + + +#usergroups #new_group { +float: left; +margin-right: 2em; +} +#new_group, #group_search { +margin-bottom:18px; +} +#new_group a { +padding-left:20px; +} + + +#filter_tags { +margin-bottom:11px; +float:left; +} +#filter_tags dt { +display:none; +} +#filter_tags ul { +list-style-type:none; +} +#filter_tags ul li { +float:left; +margin-left:7px; +padding-left:7px; +border-left-width:1px; +border-left-style:solid; +} +#filter_tags ul li.child_1 { +margin-left:0; +border-left:0; +padding-left:0; +} +#filter_tags ul li#filter_tags_all a { +font-weight:bold; +margin-top:7px; +float:left; +} + +#filter_tags ul li#filter_tags_item label { +margin-right:7px; +} +#filter_tags ul li#filter_tags_item label, +#filter_tags ul li#filter_tags_item select { +display:inline; +} +#filter_tags ul li#filter_tags_item p { +float:left; +margin-left:38px; +} +#filter_tags ul li#filter_tags_item input { +position:relative; +top:3px; +left:3px; +} + + + +.pagination { +float:left; +clear:both; +width:100%; +margin-top:18px; +} + +.pagination dt { +font-weight:bold; +display:none; +} + +.pagination .nav { +float:left; +width:100%; +list-style-type:none; +} + +.pagination .nav_prev { +float:left; +} +.pagination .nav_next { +float:right; +} + +.pagination a { +display:block; +text-decoration:none; +font-weight:bold; +padding:7px; +border-width:1px; +border-style:solid; +-moz-border-radius:7px; +-webkit-border-radius:7px; +border-radius:7px; +} + +.pagination .nav_prev a { +padding-left:30px; +} +.pagination .nav_next a { +padding-right:30px; +} +/* END: NOTICE */ + + +.hentry .entry-content p { +margin-bottom:18px; +} +.system_notice ul, +.instructions ul, +.hentry entry-content ol, +.hentry .entry-content ul { +list-style-position:inside; +} +.hentry .entry-content li { +margin-bottom:18px; +} +.hentry .entry-content li li { +margin-left:18px; +} + + + + +/* TOP_POSTERS */ +.section tbody td { +padding-right:11px; +padding-bottom:11px; +} +.section .vcard .photo { +margin-right:7px; +margin-bottom:0; +} + +.section .notice { +padding-top:7px; +padding-bottom:7px; +border-top:0; +} + +.section .notice:first-child { +padding-top:0; +} + +.section .notice .author { +margin-right:0; +} +.section .notice .author .fn { +display:none; +} + + +/* tagcloud */ +.tag-cloud { +list-style-type:none; +text-align:center; +} +.aside .tag-cloud { +font-size:0.8em; +} +.tag-cloud li { +display:inline; +margin-right:7px; +line-height:1.25; +} +.aside .tag-cloud li { +line-height:1.5; +} +.tag-cloud li a { +text-decoration:none; +} +#tagcloud.section dt { +text-transform:uppercase; +font-weight:bold; +} +.tag-cloud-1 { +font-size:1em; +} +.tag-cloud-2 { +font-size:1.25em; +} +.tag-cloud-3 { +font-size:1.75em; +} +.tag-cloud-4 { +font-size:2em; +} +.tag-cloud-5 { +font-size:2.25em; +} +.tag-cloud-6 { +font-size:2.75em; +} +.tag-cloud-7 { +font-size:3.25em; +} + +#publictagcloud #tagcloud.section dt { +display:none; +} + +#form_settings_photo .form_data { +clear:both; +} + +#form_settings_avatar li { +width:auto; +} +#form_settings_avatar input { +margin-left:0; +} +#avatar_original, +#avatar_preview { +float:left; +} +#avatar_preview { +margin-left:29px; +} +#avatar_preview_view { +height:96px; +width:96px; +margin-bottom:18px; +overflow:hidden; +} + +#settings_attach, +#form_settings_avatar .form_actions { +clear:both; +} + +#form_settings_avatar .form_actions { +margin-bottom:0; +} + +#form_settings_design #settings_design_color .form_data, +#form_settings_design #color-picker { +float:left; +} +#form_settings_design #settings_design_color .form_data { +width:400px; +margin-right:28px; +} + +.instructions ul { +list-style-position:inside; +} +.instructions p, +.instructions ul { +margin-bottom:18px; +} +.help dt { +display:none; +} +.guide { +clear:both; +} diff --git a/theme/biz/css/display.css b/theme/biz/css/display.css new file mode 100644 index 000000000..a7d360c53 --- /dev/null +++ b/theme/biz/css/display.css @@ -0,0 +1,252 @@ +/** theme: biz + * + * @package Laconica + * @author Sarven Capadisli + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +@import url(base.css); + +html { +background-color:#144A6E; +} +a:active { +background-color:#F4F7E7; +} +body { +font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; +font-size:1em; +background:#144A6E url(../images/illustrations/illu_pattern-01.png) repeat-x; +} + +address { +margin-right:7.18%; +} + +input, textarea, select, option { +font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; +} +input, textarea, select, +.entity_remote_subscribe { +border-color:#aaa; +} +#filter_tags ul li { +border-color:#ddd; +} + +.form_settings input.form_action-secondary { +background:none; +} + +input.submit, +#form_notice.warning #notice_text-count, +.form_settings .form_note, +.entity_remote_subscribe { +background-color:#9BB43E; +} + +input:focus, textarea:focus, select:focus, +#form_notice.warning #notice_data-text { +border-color:#9BB43E; +} +input.submit, +.entity_remote_subscribe, +#site_nav_local_views a { +color:#fff; +} + +a, +#site_nav_local_views .current a, +div.notice-options input, +.form_user_block input.submit, +.form_user_unblock input.submit, +.entity_send-a-message a, +.form_user_nudge input.submit, +.entity_nudge p, +.form_settings input.form_action-secondary { +color:#002E6E; +} + +#header a, +#footer a { +color:#87B4C8; +} + +.notice, +.profile { +border-top-color:#CEE1E9; +} +.section .profile { +border-top-color:#87B4C8; +} + +#content .notice p.entry-content a:visited { +background-color:#fcfcfc; +} +#content .notice p.entry-content .vcard a { +background-color:#fcfffc; +} + +.aside .section { +background-color:#F1F5F8; +background-position:100% 0; +background-image:url(../images/illustrations/illu_pattern-02.png); +background-repeat:no-repeat; +} + +#notice_text-count { +color:#333; +} +#form_notice.warning #notice_text-count { +color:#000; +} +#form_notice.processing #notice_action-submit { +background:#fff url(../../base/images/icons/icon_processing.gif) no-repeat 47% 47%; +cursor:wait; +text-indent:-9999px; +} + +#content, +#site_nav_local_views a, +.aside .section { +border-color:#fff; +} +#content, +#site_nav_local_views .current a { +background-color:#fff; +} + +#site_nav_local_views a { +background-color:rgba(135, 180, 200, 0.3); +} +#site_nav_local_views a:hover { +background-color:rgba(255, 255, 255, 0.7); +} + +.error { +background-color:#F7E8E8; +} +.success { +background-color:#EFF3DC; +} + +#anon_notice { +color:#fff; +} + +#showstream #anon_notice { +} + +#export_data li a { +background-repeat:no-repeat; +background-position:0 45%; +} +#export_data li a.rss { +background-image:url(../../base/images/icons/icon_rss.png); +} +#export_data li a.atom { +background-image:url(../../base/images/icons/icon_atom.png); +} +#export_data li a.foaf { +background-image:url(../../base/images/icons/icon_foaf.gif); +} + +.entity_edit a, +.entity_send-a-message a, +.form_user_nudge input.submit, +.form_user_block input.submit, +.form_user_unblock input.submit, +.entity_nudge p { +background-position: 0 40%; +background-repeat: no-repeat; +background-color:transparent; +} +.form_group_join input.submit, +.form_group_leave input.submit +.form_user_subscribe input.submit, +.form_user_unsubscribe input.submit { +background-color:#9BB43E; +color:#fff; +} +.form_user_unsubscribe input.submit, +.form_group_leave input.submit, +.form_user_authorization input.reject { +background-color:#87B4C8; +} + +.entity_edit a { +background-image:url(../../base/images/icons/twotone/green/edit.gif); +} +.entity_send-a-message a { +background-image:url(../../base/images/icons/twotone/green/quote.gif); +} +.entity_nudge p, +.form_user_nudge input.submit { +background-image:url(../../base/images/icons/twotone/green/mail.gif); +} +.form_user_block input.submit, +.form_user_unblock input.submit { +background-image:url(../../base/images/icons/twotone/green/shield.gif); +} + +/* NOTICES */ +.notices li.over { +background-color:#fcfcfc; +} + +.notice-options .notice_reply a, +.notice-options form input.submit { +background-color:transparent; +} +.notice-options .notice_reply a { +background:transparent url(../../base/images/icons/twotone/green/reply.gif) no-repeat 0 45%; +} +.notice-options form.form_favor input.submit { +background:transparent url(../../base/images/icons/twotone/green/favourite.gif) no-repeat 0 45%; +} +.notice-options form.form_disfavor input.submit { +background:transparent url(../../base/images/icons/twotone/green/disfavourite.gif) no-repeat 0 45%; +} +.notice-options .notice_delete a { +background:transparent url(../../base/images/icons/twotone/green/trash.gif) no-repeat 0 45%; +} + +.notices div.entry-content, +.notices div.notice-options { +opacity:0.4; +} +.notices li.hover div.entry-content, +.notices li.hover div.notice-options { +opacity:1; +} +div.entry-content { +color:#333; +} +div.notice-options a, +div.notice-options input { +font-family:sans-serif; +} +.notices li.hover { +background-color:#fcfcfc; +} +/*END: NOTICES */ + +#new_group a { +background:transparent url(../../base/images/icons/twotone/green/news.gif) no-repeat 0 45%; +} + +.pagination .nav_prev a, +.pagination .nav_next a { +background-repeat:no-repeat; +border-color:#CEE1E9; +} +.pagination .nav_prev a { +background-image:url(../../base/images/icons/twotone/green/arrow-left.gif); +background-position:10% 45%; +} +.pagination .nav_next a { +background-image:url(../../base/images/icons/twotone/green/arrow-right.gif); +background-position:90% 45%; +} diff --git a/theme/biz/css/ie.css b/theme/biz/css/ie.css new file mode 100644 index 000000000..2f463bb44 --- /dev/null +++ b/theme/biz/css/ie.css @@ -0,0 +1,9 @@ +/* IE specific styles */ + +.notice-options input.submit { +color:#fff; +} + +#site_nav_local_views a { +background-color:#D0DFE7; +} diff --git a/theme/biz/default-avatar-mini.png b/theme/biz/default-avatar-mini.png new file mode 100644 index 000000000..38b8692b4 Binary files /dev/null and b/theme/biz/default-avatar-mini.png differ diff --git a/theme/biz/default-avatar-profile.png b/theme/biz/default-avatar-profile.png new file mode 100644 index 000000000..f8357d4fc Binary files /dev/null and b/theme/biz/default-avatar-profile.png differ diff --git a/theme/biz/default-avatar-stream.png b/theme/biz/default-avatar-stream.png new file mode 100644 index 000000000..6b63baa70 Binary files /dev/null and b/theme/biz/default-avatar-stream.png differ diff --git a/theme/biz/images/illustrations/illu_pattern-01.png b/theme/biz/images/illustrations/illu_pattern-01.png new file mode 100644 index 000000000..79bb46b60 Binary files /dev/null and b/theme/biz/images/illustrations/illu_pattern-01.png differ diff --git a/theme/biz/images/illustrations/illu_pattern-02.png b/theme/biz/images/illustrations/illu_pattern-02.png new file mode 100644 index 000000000..4438b751a Binary files /dev/null and b/theme/biz/images/illustrations/illu_pattern-02.png differ diff --git a/theme/biz/logo.png b/theme/biz/logo.png new file mode 100644 index 000000000..7c68b34f6 Binary files /dev/null and b/theme/biz/logo.png differ -- cgit v1.2.3-54-g00ecf From 251fd2c232d96ea09db971a6608231c679395c01 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Mon, 11 May 2009 04:04:56 +0000 Subject: Init pigeon thoughts theme. Inspired by http://csarven.ca/labs/csszengarden.com/pigeon-thoughts/zengarden-sample.html --- theme/pigeonthoughts/css/base.css | 1153 ++++++++++++++++++++ theme/pigeonthoughts/css/display.css | 295 +++++ theme/pigeonthoughts/css/ie.css | 9 + theme/pigeonthoughts/default-avatar-mini.png | Bin 0 -> 646 bytes theme/pigeonthoughts/default-avatar-profile.png | Bin 0 -> 2853 bytes theme/pigeonthoughts/default-avatar-stream.png | Bin 0 -> 1487 bytes .../images/illustrations/illu_pigeons-01.png | Bin 0 -> 72649 bytes .../images/illustrations/illu_pigeons-02.png | Bin 0 -> 3538 bytes theme/pigeonthoughts/logo.png | Bin 0 -> 4988 bytes 9 files changed, 1457 insertions(+) create mode 100644 theme/pigeonthoughts/css/base.css create mode 100644 theme/pigeonthoughts/css/display.css create mode 100644 theme/pigeonthoughts/css/ie.css create mode 100644 theme/pigeonthoughts/default-avatar-mini.png create mode 100644 theme/pigeonthoughts/default-avatar-profile.png create mode 100644 theme/pigeonthoughts/default-avatar-stream.png create mode 100644 theme/pigeonthoughts/images/illustrations/illu_pigeons-01.png create mode 100644 theme/pigeonthoughts/images/illustrations/illu_pigeons-02.png create mode 100644 theme/pigeonthoughts/logo.png diff --git a/theme/pigeonthoughts/css/base.css b/theme/pigeonthoughts/css/base.css new file mode 100644 index 000000000..179719820 --- /dev/null +++ b/theme/pigeonthoughts/css/base.css @@ -0,0 +1,1153 @@ +/** theme: pigeonthoughts base + * + * @package Laconica + * @author Sarven Capadisli + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +* { margin:0; padding:0; } +img { display:block; border:0; } +a abbr { cursor: pointer; border-bottom:0; } +table { border-collapse:collapse; } +ol { list-style-position:inside; } +html { font-size: 87.5%; background-color:#fff; } +body { +background-color:#fff; +color:#000; +font-family:sans-serif; +font-size:1em; +line-height:1.65; +position:relative; +margin-left:183px; +} +h1,h2,h3,h4,h5,h6 { +margin-bottom:7px; +overflow:hidden; +} +h1 { +font-size:1.4em; +margin-bottom:18px; +} +#showstream h1 { display:none; } +h2 { font-size:1.3em; } +h3 { font-size:1.2em; } +h4 { font-size:1.1em; } +h5 { font-size:1em; } +h6 { font-size:0.9em; } + +caption { +font-weight:bold; +} +legend { +font-weight:bold; +font-size:1.3em; +} +input, textarea, select, option { +padding:4px; +font-family:sans-serif; +font-size:1em; +} +input, textarea, select { +border-width:2px; +border-style: solid; +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +} + +input.submit { +font-weight:bold; +cursor:pointer; +} +textarea { +overflow:auto; +} +option { +padding-bottom:0; +} +fieldset { +padding:0; +border:0; +} +form ul li { +list-style-type:none; +margin:0 0 18px 0; +} +form label { +font-weight:bold; +} +input.checkbox { +position:relative; +top:2px; +left:0; +border:0; +} + +.error, +.success { +padding:4px 1.55%; +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +margin-bottom:18px; +} +form label.submit { +display:none; +} + +.form_settings { +clear:both; +} + +.form_settings fieldset { +margin-bottom:29px; +} +.form_settings input.remove { +margin-left:11px; +} +.form_settings .form_data li { +width:100%; +float:left; +} +.form_settings .form_data label { +float:left; +} +.form_settings .form_data textarea, +.form_settings .form_data select, +.form_settings .form_data input { +margin-left:11px; +float:left; +} +.form_settings .form_data input.submit { +margin-left:0; +} + +.form_settings label { +margin-top:2px; +width:152px; +} + +.form_actions label { +display:none; +} +.form_guide { +font-style:italic; +} + +.form_settings #settings_autosubscribe label { +display:inline; +font-weight:bold; +} + +#form_settings_profile legend, +#form_login legend, +#form_register legend, +#form_password legend, +#form_settings_avatar legend, +#newgroup legend, +#editgroup legend, +#form_tag_user legend, +#form_remote_subscribe legend, +#form_openid_login legend, +#form_search legend, +#form_invite legend, +#form_notice_delete legend, +#form_password_recover legend, +#form_password_change legend { +display:none; +} + +.form_settings .form_data p.form_guide { +clear:both; +margin-left:163px; +margin-bottom:0; +} + +.form_settings p { +margin-bottom:11px; +} + +.form_settings input.checkbox { +margin-top:3px; +margin-left:0; +} +.form_settings label.checkbox { +font-weight:normal; +margin-top:0; +margin-right:0; +margin-left:11px; +float:left; +width:90%; +} + + +#form_login p.form_guide, +#form_register #settings_rememberme p.form_guide, +#form_openid_login #settings_rememberme p.form_guide, +#settings_twitter_remove p.form_guide, +#form_search ul.form_data #q { +margin-left:0; +} + +.form_settings .form_note { +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +padding:0 7px; +} + + +.form_settings input.form_action-secondary { +margin-left:29px; +padding:0; +} + +#form_search .submit { +margin-left:11px; +} + +address { +float:right; +margin-bottom:18px; +margin-right:18px; +} +address.vcard img.logo { +margin-right:0; +} +address .fn { +font-weight:bold; +} +address img + .fn { +display:none; +} + +#header { +width:98.5%; +position:relative; +float:left; +padding-top:18px; +padding-left:18px; +margin-bottom:29px; +} + +#site_nav_global_primary { +float:left; +margin-right:18px; +margin-bottom:11px; +} +#site_nav_global_primary ul li { +display:inline; +margin-right:11px; +} + +.system_notice dt { +font-weight:bold; +text-transform:uppercase; +display:none; +} + +#site_notice { +float:right; +margin-top:7px; +margin-right:18px; +width:26%; +} +#page_notice { +clear:both; +margin-bottom:18px; +} + + +#anon_notice { +float:left; +width:50.2%; +line-height:1.5; +font-size:1.1em; +font-weight:bold; +} + + +#footer { +float:left; +width:64%; +padding:18px; +} + +#site_nav_local_views { +width:183px; +float:left; +margin-bottom:29px; +position:fixed; +top:179px; +left:0; +} +#site_nav_local_views dt { +display:none; +} +#site_nav_local_views li { +list-style-type:none; +} +#site_nav_local_views a { +text-decoration:none; +padding:4px 11px; +text-shadow: 1px 1px 1px #ddd; +font-weight:bold; +display:block; +} +#site_nav_local_views .nav { +float:left; +width:100%; +} + +#site_nav_global_primary dt, +#site_nav_global_secondary dt { +display:none; +} + +#site_nav_global_secondary { +margin-bottom:11px; +} + +#site_nav_global_secondary ul li { +display:inline; +margin-right:11px; +} +#export_data li a { +padding-left:20px; +} +#export_data li a.foaf { +padding-left:30px; +} +#export_data li a.export_vcard { +padding-left:28px; +} + +#export_data ul { +display:inline; +} +#export_data li { +list-style-type:none; +display:inline; +margin-left:11px; +} +#export_data li:first-child { +margin-left:0; +} + +#licenses { +font-size:0.9em; +} + +#licenses dt { +font-weight:bold; +display:none; +} +#licenses dd { +margin-bottom:11px; +line-height:1.5; +} + +#site_content_license_cc { +margin-bottom:0; +} +#site_content_license_cc img { +display:inline; +vertical-align:top; +margin-right:4px; +} + +#wrap { +width:100%; +min-width:760px; +max-width:1003px; +overflow:hidden; +} + +#core { +position:relative; +width:100%; +float:left; +margin-bottom:1em; +} + +#content { +width:50.009%; +min-height:259px; +float:left; +margin-left:18px; +} +#shownotice #content { +min-height:0; +} + +#content_inner { +position:relative; +width:100%; +float:left; +} + +#aside_primary { +width:45.917%; +min-height:259px; +float:left; +margin-left:1.385%; +padding-bottom:47px; +} + +#form_notice { +width:45.664%; +float:left; +position:relative; +line-height:1; +} +#form_notice fieldset { +border:0; +padding:0; +position:relative; +} +#form_notice legend { +display:none; +} +#form_notice textarea { +float:left; +border-radius:7px; +-moz-border-radius:7px; +-webkit-border-radius:7px; +width:80.789%; +height:46px; +line-height:1.5; +padding:7px 7px 16px 7px; +} +#form_notice label { +display:block; +float:left; +font-size:1.3em; +margin-bottom:7px; +} +#form_notice #notice_submit label { +display:none; +} +#form_notice .form_note { +position:absolute; +top:76px; +right:98px; +z-index:9; +} +#form_notice .form_note dt { +font-weight:bold; +display:none; +} +#notice_text-count { +font-weight:bold; +line-height:1.15; +padding:1px 2px; +} +#form_notice #notice_action-submit { +width:14%; +height:47px; +padding:0; +position:absolute; +bottom:0; +right:0; +} +#form_notice label[for=to] { +margin-top:7px; +} +#form_notice select[id=to] { +margin-bottom:7px; +margin-left:18px; +float:left; +} +#form_notice .error { +float:left; +clear:both; +width:96.9%; +margin-bottom:0; +line-height:1.618; +} + +/* entity_profile */ +.entity_profile { +position:relative; +width:67.702%; +min-height:123px; +float:left; +margin-bottom:18px; +margin-left:0; +overflow:hidden; +} +.entity_profile dt, +#entity_statistics dt { +font-weight:bold; +} +.entity_profile dd { +display:inline; +} + +.entity_profile .entity_depiction { +float:left; +width:96px; +margin-right:18px; +margin-bottom:18px; +} + +.entity_profile .entity_fn, +.entity_profile .entity_nickname, +.entity_profile .entity_location, +.entity_profile .entity_url, +.entity_profile .entity_note, +.entity_profile .entity_tags { +margin-left:113px; +margin-bottom:4px; +} + +.entity_profile .entity_fn, +.entity_profile .entity_nickname { +margin-left:11px; +display:inline; +font-weight:bold; +} +.entity_profile .entity_nickname { +margin-left:0; +} + +.entity_profile .entity_fn dd:before { +content: "("; +font-weight:normal; +} +.entity_profile .entity_fn dd:after { +content: ")"; +font-weight:normal; +} + +.entity_profile dt { +display:none; +} +.entity_profile h2 { +display:none; +} +/* entity_profile */ + + +/*entity_actions*/ +.entity_actions { +float:right; +margin-left:4.35%; +max-width:25%; +} +.entity_actions h2 { +display:none; +} +.entity_actions ul { +list-style-type:none; +} +.entity_actions li { +margin-bottom:4px; +} +.entity_actions li:first-child { +border-top:0; +} +.entity_actions fieldset { +border:0; +padding:0; +} +.entity_actions legend { +display:none; +} + +.entity_actions input.submit { +display:block; +text-align:left; +width:100%; +} +.entity_actions a, +.entity_nudge p, +.entity_remote_subscribe { +text-decoration:none; +font-weight:bold; +display:block; +} + +.form_user_block input.submit, +.form_user_unblock input.submit, +.entity_send-a-message a, +.entity_edit a, +.form_user_nudge input.submit, +.entity_nudge p { +border:0; +padding-left:20px; +} + +.entity_edit a, +.entity_send-a-message a, +.entity_nudge p { +padding:4px 4px 4px 23px; +} + +.entity_remote_subscribe { +padding:4px; +border-width:2px; +border-style:solid; +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +} +.entity_actions .accept { +margin-bottom:18px; +} + +.entity_tags ul { +list-style-type:none; +display:inline; +} +.entity_tags li { +display:inline; +margin-right:4px; +} + +.aside .section { +margin-bottom:29px; +float:right; +width:44%; +padding:1%; +border-width:1px; +border-style:solid; +margin-left:2.5%; +} +.aside .section h2 { +text-transform:uppercase; +font-size:1em; +} + +#entity_statistics dt, +#entity_statistics dd { +display:inline; +} +#entity_statistics dt:after { +content: ":"; +} + +.section ul.entities { +float:left; +width:100%; +} +.section .entities li { +list-style-type:none; +float:left; +margin-right:7px; +margin-bottom:7px; +} +.section .entities li .photo { +margin-right:0; +margin-bottom:0; +} +.section .entities li .fn { +display:none; +} + +.aside .section p, +.aside .section .more { +clear:both; +} + +.profile .entity_profile { +margin-bottom:0; +min-height:60px; +} + + +.profile .form_group_join legend, +.profile .form_group_leave legend, +.profile .form_user_subscribe legend, +.profile .form_user_unsubscribe legend { +display:none; +} + +.profiles { +list-style-type:none; +} +.profile .entity_profile .entity_location { +width:auto; +clear:none; +margin-left:11px; +} +.profile .entity_profile dl, +.profile .entity_profile dd { +display:inline; +float:none; +} +.profile .entity_profile .entity_note, +.profile .entity_profile .entity_url, +.profile .entity_profile .entity_tags, +.profile .entity_profile .form_subscription_edit { +margin-left:59px; +clear:none; +display:block; +width:auto; +} +.profile .entity_profile .entity_tags dt { +display:inline; +margin-right:11px; +} + + +.profile .entity_profile .form_subscription_edit label { +font-weight:normal; +margin-right:11px; +} + + +/* NOTICE */ +.notice, +.profile { +position:relative; +padding-top:11px; +padding-bottom:11px; +clear:both; +float:left; +width:96.41%; +border-width:1px; +border-style:solid; +padding:1.795%; +margin-bottom:11px; +} +.notices li { +list-style-type:none; +} + +#aside_primary .notice, +#aside_primary .profile { +border:0; +margin-bottom:11px; +} + +/* NOTICES */ +#notices_primary { +float:left; +width:100%; +border-radius:7px; +-moz-border-radius:7px; +-webkit-border-radius:7px; +} +#notices_primary h2 { +display:none; +} +.notice-data a span { +display:block; +padding-left:28px; +} + +.notice .author { +margin-right:11px; +} + +.fn { +overflow:hidden; +} + +.notice .author .fn { +font-weight:bold; +} + +.vcard .photo { +display:inline; +margin-right:11px; +float:left; +} +#shownotice .vcard .photo { +margin-bottom:4px; +} +.vcard .url { +text-decoration:none; +} +.vcard .url:hover { +text-decoration:underline; +} + +.notice .entry-title { +float:left; +width:100%; +overflow:hidden; +} +#shownotice .notice .entry-title { +font-size:2.2em; +} + +.notice p.entry-content { +display:inline; +} + +#content .notice p.entry-content a:visited { +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +} +.notice p.entry-content .vcard a { +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +} + +.notice div.entry-content { +clear:left; +float:left; +font-size:0.95em; +margin-left:59px; +width:65%; +} +#showstream .notice div.entry-content, +#shownotice .notice div.entry-content { +margin-left:0; +} + +.notice .notice-options a, +.notice .notice-options input { +float:left; +font-size:1.025em; +} + +.notice div.entry-content dl, +.notice div.entry-content dt, +.notice div.entry-content dd { +display:inline; +} + +.notice div.entry-content .timestamp dt, +.notice div.entry-content .response dt { +display:none; +} +.notice div.entry-content .timestamp a { +display:inline-block; +} +.notice div.entry-content .device dt { +text-transform:lowercase; +} + + +.notice-options { +padding-left:2%; +float:left; +width:50%; +position:relative; +font-size:0.95em; +width:12.5%; +float:right; +} + +.notice-options a { +float:left; +} +.notice-options .notice_delete, +.notice-options .notice_reply, +.notice-options .form_favor, +.notice-options .form_disfavor { +position:absolute; +top:0; +} +.notice-options .form_favor, +.notice-options .form_disfavor { +left:0; +} +.notice-options .notice_reply { +left:29px; +} +.notice-options .notice_delete { +right:0; +} +.notice-options .notice_reply dt { +display:none; +} + +.notice-options input, +.notice-options a { +text-indent:-9999px; +outline:none; +} + +.notice-options .notice_reply a, +.notice-options input.submit { +display:block; +border:0; +} +.notice-options .notice_reply a, +.notice-options .notice_delete a { +text-decoration:none; +padding-left:16px; +} + +.notice-options form input.submit { +width:16px; +padding:2px 0; +} + +.notice-options .notice_delete dt, +.notice-options .form_favor legend, +.notice-options .form_disfavor legend { +display:none; +} +.notice-options .notice_delete fieldset, +.notice-options .form_favor fieldset, +.notice-options .form_disfavor fieldset { +border:0; +padding:0; +} + + +#usergroups #new_group { +float: left; +margin-right: 2em; +} +#new_group, #group_search { +margin-bottom:18px; +} +#new_group a { +padding-left:20px; +} + + +#filter_tags { +margin-bottom:11px; +float:left; +} +#filter_tags dt { +display:none; +} +#filter_tags ul { +list-style-type:none; +} +#filter_tags ul li { +float:left; +margin-left:7px; +padding-left:7px; +border-left-width:1px; +border-left-style:solid; +} +#filter_tags ul li.child_1 { +margin-left:0; +border-left:0; +padding-left:0; +} +#filter_tags ul li#filter_tags_all a { +font-weight:bold; +margin-top:7px; +float:left; +} + +#filter_tags ul li#filter_tags_item label { +margin-right:7px; +} +#filter_tags ul li#filter_tags_item label, +#filter_tags ul li#filter_tags_item select { +display:inline; +} +#filter_tags ul li#filter_tags_item p { +float:left; +margin-left:38px; +} +#filter_tags ul li#filter_tags_item input { +position:relative; +top:3px; +left:3px; +} + + + +.pagination { +float:left; +clear:both; +width:100%; +margin-top:18px; +} + +.pagination dt { +font-weight:bold; +display:none; +} + +.pagination .nav { +float:left; +width:100%; +list-style-type:none; +} + +.pagination .nav_prev { +float:left; +} +.pagination .nav_next { +float:right; +} + +.pagination a { +display:block; +text-decoration:none; +font-weight:bold; +padding:7px; +border-width:1px; +border-style:solid; +-moz-border-radius:7px; +-webkit-border-radius:7px; +border-radius:7px; +} + +.pagination .nav_prev a { +padding-left:30px; +} +.pagination .nav_next a { +padding-right:30px; +} +/* END: NOTICE */ + + +.hentry .entry-content p { +margin-bottom:18px; +} +.system_notice ul, +.instructions ul, +.hentry entry-content ol, +.hentry .entry-content ul { +list-style-position:inside; +} +.hentry .entry-content li { +margin-bottom:18px; +} +.hentry .entry-content li li { +margin-left:18px; +} + + + + +/* TOP_POSTERS */ +.section tbody td { +padding-right:11px; +padding-bottom:11px; +} +.section .vcard .photo { +margin-right:7px; +margin-bottom:0; +} + +.section .notice { +padding-top:7px; +padding-bottom:7px; +border-top:0; +} + +.section .notice:first-child { +padding-top:0; +} + +.section .notice .author { +margin-right:0; +} +.section .notice .author .fn { +display:none; +} + + +/* tagcloud */ +.tag-cloud { +list-style-type:none; +text-align:center; +} +.aside .tag-cloud { +font-size:0.8em; +} +.tag-cloud li { +display:inline; +margin-right:7px; +line-height:1.25; +} +.aside .tag-cloud li { +line-height:1.5; +} +.tag-cloud li a { +text-decoration:none; +} +#tagcloud.section dt { +text-transform:uppercase; +font-weight:bold; +} +.tag-cloud-1 { +font-size:1em; +} +.tag-cloud-2 { +font-size:1.25em; +} +.tag-cloud-3 { +font-size:1.75em; +} +.tag-cloud-4 { +font-size:2em; +} +.tag-cloud-5 { +font-size:2.25em; +} +.tag-cloud-6 { +font-size:2.75em; +} +.tag-cloud-7 { +font-size:3.25em; +} + +#publictagcloud #tagcloud.section dt { +display:none; +} + +#form_settings_photo .form_data { +clear:both; +} + +#form_settings_avatar li { +width:auto; +} +#form_settings_avatar input { +margin-left:0; +} +#avatar_original, +#avatar_preview { +float:left; +} +#avatar_preview { +margin-left:29px; +} +#avatar_preview_view { +height:96px; +width:96px; +margin-bottom:18px; +overflow:hidden; +} + +#settings_attach, +#form_settings_avatar .form_actions { +clear:both; +} + +#form_settings_avatar .form_actions { +margin-bottom:0; +} + +#form_settings_design #settings_design_color .form_data, +#form_settings_design #color-picker { +float:left; +} +#form_settings_design #settings_design_color .form_data { +width:400px; +margin-right:28px; +} + +.instructions ul { +list-style-position:inside; +} +.instructions p, +.instructions ul { +margin-bottom:18px; +} +.help dt { +display:none; +} +.guide { +clear:both; +} diff --git a/theme/pigeonthoughts/css/display.css b/theme/pigeonthoughts/css/display.css new file mode 100644 index 000000000..19341ef7f --- /dev/null +++ b/theme/pigeonthoughts/css/display.css @@ -0,0 +1,295 @@ +/** theme: pigeonthoughts + * + * @package Laconica + * @author Sarven Capadisli + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +@import url(base.css); + +html { +background:#fff url(../images/illustrations/illu_pigeons-01.png) no-repeat 0 100%; +} + +body, +a:active { +background-color:#AEA187; +} +body { +font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; +font-size:1em; +} +address { +margin-left:2%; +} + +input, textarea, select, option { +font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; +} +input, textarea, select, +.entity_remote_subscribe { +border-color:#aaa; +} +#filter_tags ul li { +border-color:#ddd; +} + +.form_settings input.form_action-secondary { +background:none; +} + +input.submit, +#form_notice.warning #notice_text-count, +.form_settings .form_note, +.entity_remote_subscribe { +background-color:#8F0000; +} + +input:focus, textarea:focus, select:focus, +#form_notice.warning #notice_data-text { +border-color:#8F0000; +} +input.submit, +.entity_remote_subscribe { +color:#fff; +} + +a, +div.notice-options input, +.form_user_block input.submit, +.form_user_unblock input.submit, +.entity_send-a-message a, +.form_user_nudge input.submit, +.entity_nudge p, +.form_settings input.form_action-secondary { +color:#000; +} + +.notice, +.profile { +border-color:#000; +} +.notice a, +.profile a { +color:#fff; +} + +.notice:nth-child(3n-1), +.profile:nth-child(3n-1) { +border-color:#fff; +} +.notice:nth-child(3n-1) a, +.profile:nth-child(3n-1) a { +color:#7F1114; +} +.notice:nth-child(3n), +.profile:nth-child(3n) { +border-color:#7F1114; +} +.notice:nth-child(3n) a, +.profile:nth-child(3n) a { +color:#000; +} + +.aside .section .notice, +.aside .section .profile, +.aside .section .notice:nth-child(3n-1), +.aside .section .profile:nth-child(3n-1), +.aside .section .notice:nth-child(3n), +.aside .section .profile:nth-child(3n) { +background-color:transparent; +color:#000; +} + + +.aside .section { +border-color:#fff; +background-color:#fff; +color:#000; +} + +.aside .section:nth-child(n) { +border-color:#000; +background-color:#000; +color:#fff; +} +.aside .section:nth-child(3n-1) { +border-color:#fff; +background-color:#fff; +color:#000; +} +.aside .section:nth-child(3n) { +background-color:#7F1114; +border-color:#7F1114; +color:#000; +} +.aside .section a { +color:#7F1114; +} +.aside .section:nth-child(3n-1) a { +color:#7F1114; +} +.aside .section:nth-child(3n) a { +color:#fff; +} + + +.section .profile { +border-top-color:#87B4C8; +} + +#aside_primary { +background:url(../images/illustrations/illu_pigeons-02.png) no-repeat 10% 100%; +} + +#notice_text-count { +color:#333; +} +#form_notice.warning #notice_text-count { +color:#000; +} +#form_notice.processing #notice_action-submit { +background:#fff url(../../base/images/icons/icon_processing.gif) no-repeat 47% 47%; +cursor:wait; +text-indent:-9999px; +} + +#content, +#site_nav_local_views a { +border-color:#fff; +} +#site_nav_local_views .current a { +background-color:rgba(143, 0, 0, 0.8); +color:#fff; +} + +#site_nav_local_views a { +background-color:rgba(255, 255, 255, 0.3); +} +#site_nav_local_views a:hover { +background-color:#fff; +color:#8F0000; +} + +.error { +background-color:#F7E8E8; +} +.success { +background-color:#EFF3DC; +} + +#anon_notice { +color:#000; +} + + +#export_data li a { +background-repeat:no-repeat; +background-position:0 45%; +} +#export_data li a.rss { +background-image:url(../../base/images/icons/icon_rss.png); +} +#export_data li a.atom { +background-image:url(../../base/images/icons/icon_atom.png); +} +#export_data li a.foaf { +background-image:url(../../base/images/icons/icon_foaf.gif); +} + +.entity_edit a, +.entity_send-a-message a, +.form_user_nudge input.submit, +.form_user_block input.submit, +.form_user_unblock input.submit, +.entity_nudge p { +background-position: 0 40%; +background-repeat: no-repeat; +background-color:transparent; +} +.form_group_join input.submit, +.form_group_leave input.submit +.form_user_subscribe input.submit, +.form_user_unsubscribe input.submit { +background-color:#8F0000; +color:#fff; +} +.form_user_unsubscribe input.submit, +.form_group_leave input.submit, +.form_user_authorization input.reject { +background-color:#87B4C8; +} + +.entity_edit a { +background-image:url(../../base/images/icons/twotone/green/edit.gif); +} +.entity_send-a-message a { +background-image:url(../../base/images/icons/twotone/green/quote.gif); +} +.entity_nudge p, +.form_user_nudge input.submit { +background-image:url(../../base/images/icons/twotone/green/mail.gif); +} +.form_user_block input.submit, +.form_user_unblock input.submit { +background-image:url(../../base/images/icons/twotone/green/shield.gif); +} + +/* NOTICES */ +.notices li.over { +background-color:#fcfcfc; +} + +.notice-options .notice_reply a, +.notice-options form input.submit { +background-color:transparent; +} +.notice-options .notice_reply a { +background:transparent url(../../base/images/icons/twotone/green/reply.gif) no-repeat 0 45%; +} +.notice-options form.form_favor input.submit { +background:transparent url(../../base/images/icons/twotone/green/favourite.gif) no-repeat 0 45%; +} +.notice-options form.form_disfavor input.submit { +background:transparent url(../../base/images/icons/twotone/green/disfavourite.gif) no-repeat 0 45%; +} +.notice-options .notice_delete a { +background:transparent url(../../base/images/icons/twotone/green/trash.gif) no-repeat 0 45%; +} + +.notices div.entry-content, +.notices div.notice-options { +opacity:0.4; +} +.notices li.hover div.entry-content, +.notices li.hover div.notice-options { +opacity:1; +} +div.entry-content { +color:#333; +} +div.notice-options a, +div.notice-options input { +font-family:sans-serif; +} +/*END: NOTICES */ + +#new_group a { +background:transparent url(../../base/images/icons/twotone/green/news.gif) no-repeat 0 45%; +} + +.pagination .nav_prev a, +.pagination .nav_next a { +background-repeat:no-repeat; +border-color:#000; +} +.pagination .nav_prev a { +background-image:url(../../base/images/icons/twotone/green/arrow-left.gif); +background-position:10% 45%; +} +.pagination .nav_next a { +background-image:url(../../base/images/icons/twotone/green/arrow-right.gif); +background-position:90% 45%; +} diff --git a/theme/pigeonthoughts/css/ie.css b/theme/pigeonthoughts/css/ie.css new file mode 100644 index 000000000..2f463bb44 --- /dev/null +++ b/theme/pigeonthoughts/css/ie.css @@ -0,0 +1,9 @@ +/* IE specific styles */ + +.notice-options input.submit { +color:#fff; +} + +#site_nav_local_views a { +background-color:#D0DFE7; +} diff --git a/theme/pigeonthoughts/default-avatar-mini.png b/theme/pigeonthoughts/default-avatar-mini.png new file mode 100644 index 000000000..38b8692b4 Binary files /dev/null and b/theme/pigeonthoughts/default-avatar-mini.png differ diff --git a/theme/pigeonthoughts/default-avatar-profile.png b/theme/pigeonthoughts/default-avatar-profile.png new file mode 100644 index 000000000..f8357d4fc Binary files /dev/null and b/theme/pigeonthoughts/default-avatar-profile.png differ diff --git a/theme/pigeonthoughts/default-avatar-stream.png b/theme/pigeonthoughts/default-avatar-stream.png new file mode 100644 index 000000000..6b63baa70 Binary files /dev/null and b/theme/pigeonthoughts/default-avatar-stream.png differ diff --git a/theme/pigeonthoughts/images/illustrations/illu_pigeons-01.png b/theme/pigeonthoughts/images/illustrations/illu_pigeons-01.png new file mode 100644 index 000000000..4fdaaeb25 Binary files /dev/null and b/theme/pigeonthoughts/images/illustrations/illu_pigeons-01.png differ diff --git a/theme/pigeonthoughts/images/illustrations/illu_pigeons-02.png b/theme/pigeonthoughts/images/illustrations/illu_pigeons-02.png new file mode 100644 index 000000000..187c6c8a6 Binary files /dev/null and b/theme/pigeonthoughts/images/illustrations/illu_pigeons-02.png differ diff --git a/theme/pigeonthoughts/logo.png b/theme/pigeonthoughts/logo.png new file mode 100644 index 000000000..7c68b34f6 Binary files /dev/null and b/theme/pigeonthoughts/logo.png differ -- cgit v1.2.3-54-g00ecf From d010d811ba812ccc8fbb1a49fcba7a30226ea779 Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Mon, 11 May 2009 13:45:00 -0400 Subject: db stuff for URLs: redirections, oembed, etc. --- actions/newnotice.php | 33 ++++++++++++ classes/File.php | 47 +++++++++++++++++ classes/File_oembed.php | 53 +++++++++++++++++++ classes/File_redirection.php | 45 ++++++++++++++++ classes/File_thumbnail.php | 45 ++++++++++++++++ classes/File_to_post.php | 43 +++++++++++++++ classes/laconica.ini | 123 +++++++++++++++++++++++++++++++++++++++++++ classes/laconica.links.ini | 71 +++++++++++++++++++++++++ lib/util.php | 8 ++- 9 files changed, 466 insertions(+), 2 deletions(-) create mode 100644 classes/File.php create mode 100644 classes/File_oembed.php create mode 100644 classes/File_redirection.php create mode 100644 classes/File_thumbnail.php create mode 100644 classes/File_to_post.php mode change 100755 => 100644 classes/laconica.ini diff --git a/actions/newnotice.php b/actions/newnotice.php index cbd04c58b..8b03abc62 100644 --- a/actions/newnotice.php +++ b/actions/newnotice.php @@ -166,6 +166,8 @@ class NewnoticeAction extends Action return; } + $this->saveUrls($notice); + common_broadcast_notice($notice); if ($this->boolean('ajax')) { @@ -191,6 +193,37 @@ class NewnoticeAction extends Action } } + /** save all urls in the notice to the db + * + * follow redirects and save all available file information + * (mimetype, date, size, oembed, etc.) + * + * @param class $notice Notice to pull URLs from + * + * @return void + */ + function saveUrls($notice) { + common_debug("Saving all URLs"); + common_replace_urls_callback($notice->content, array($this, 'saveUrl'), $notice->id); + } + + function saveUrl($data) { + list($url, $notice_id) = $data; + common_debug("Saving $url for $notice_id"); + $file = File::staticGet('url', $url); + if (empty($file)) { + common_debug('unknown file/url'); + $file = new File; + $file->url = $url; + $file->insert(); + } + common_debug('File: ' . print_r($file, true)); + $f2p = new File_to_post; + $f2p->file_id = $file->id; + $f2p->post_id = $notice_id; + $f2p->insert(); + } + /** * Show an Ajax-y error message * diff --git a/classes/File.php b/classes/File.php new file mode 100644 index 000000000..8dd017b79 --- /dev/null +++ b/classes/File.php @@ -0,0 +1,47 @@ +. + */ + +if (!defined('LACONICA')) { exit(1); } + +require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; + +/** + * Table Definition for file + */ + +class File extends Memcached_DataObject +{ + ###START_AUTOCODE + /* the code below is auto generated do not remove the above tag */ + + public $__table = 'file'; // table name + public $id; // int(11) not_null primary_key group_by + public $url; // varchar(255) unique_key + public $mimetype; // varchar(50) + public $size; // int(11) group_by + public $title; // varchar(255) + public $date; // int(11) group_by + public $protected; // int(1) group_by + + /* Static get */ + function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('File',$k,$v); } + + /* the code above is auto generated do not remove the tag below */ + ###END_AUTOCODE +} diff --git a/classes/File_oembed.php b/classes/File_oembed.php new file mode 100644 index 000000000..33dd8200c --- /dev/null +++ b/classes/File_oembed.php @@ -0,0 +1,53 @@ +. + */ + +if (!defined('LACONICA')) { exit(1); } + +require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; + +/** + * Table Definition for file_oembed + */ + +class File_oembed extends Memcached_DataObject +{ + ###START_AUTOCODE + /* the code below is auto generated do not remove the above tag */ + + public $__table = 'file_oembed'; // table name + public $id; // int(11) not_null primary_key group_by + public $file_id; // int(11) unique_key group_by + public $version; // varchar(20) + public $type; // varchar(20) + public $provider; // varchar(50) + public $provider_url; // varchar(255) + public $width; // int(11) group_by + public $height; // int(11) group_by + public $html; // blob(65535) blob + public $title; // varchar(255) + public $author_name; // varchar(50) + public $author_url; // varchar(255) + public $url; // varchar(255) + + /* Static get */ + function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('File_oembed',$k,$v); } + + /* the code above is auto generated do not remove the tag below */ + ###END_AUTOCODE +} diff --git a/classes/File_redirection.php b/classes/File_redirection.php new file mode 100644 index 000000000..e2d1e69c3 --- /dev/null +++ b/classes/File_redirection.php @@ -0,0 +1,45 @@ +. + */ + +if (!defined('LACONICA')) { exit(1); } + +require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; + +/** + * Table Definition for file_redirection + */ + +class File_redirection extends Memcached_DataObject +{ + ###START_AUTOCODE + /* the code below is auto generated do not remove the above tag */ + + public $__table = 'file_redirection'; // table name + public $id; // int(11) not_null primary_key group_by + public $url; // varchar(255) unique_key + public $file_id; // int(11) group_by + public $redirections; // int(11) group_by + public $httpcode; // int(11) group_by + + /* Static get */ + function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('File_redirection',$k,$v); } + + /* the code above is auto generated do not remove the tag below */ + ###END_AUTOCODE +} diff --git a/classes/File_thumbnail.php b/classes/File_thumbnail.php new file mode 100644 index 000000000..7b906a07c --- /dev/null +++ b/classes/File_thumbnail.php @@ -0,0 +1,45 @@ +. + */ + +if (!defined('LACONICA')) { exit(1); } + +require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; + +/** + * Table Definition for file_thumbnail + */ + +class File_thumbnail extends Memcached_DataObject +{ + ###START_AUTOCODE + /* the code below is auto generated do not remove the above tag */ + + public $__table = 'file_thumbnail'; // table name + public $id; // int(11) not_null primary_key group_by + public $file_id; // int(11) unique_key group_by + public $url; // varchar(255) unique_key + public $width; // int(11) group_by + public $height; // int(11) group_by + + /* Static get */ + function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('File_thumbnail',$k,$v); } + + /* the code above is auto generated do not remove the tag below */ + ###END_AUTOCODE +} diff --git a/classes/File_to_post.php b/classes/File_to_post.php new file mode 100644 index 000000000..bd0528d98 --- /dev/null +++ b/classes/File_to_post.php @@ -0,0 +1,43 @@ +. + */ + +if (!defined('LACONICA')) { exit(1); } + +require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; + +/** + * Table Definition for file_to_post + */ + +class File_to_post extends Memcached_DataObject +{ + ###START_AUTOCODE + /* the code below is auto generated do not remove the above tag */ + + public $__table = 'file_to_post'; // table name + public $id; // int(11) not_null primary_key group_by + public $file_id; // int(11) multiple_key group_by + public $post_id; // int(11) group_by + + /* Static get */ + function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('File_to_post',$k,$v); } + + /* the code above is auto generated do not remove the tag below */ + ###END_AUTOCODE +} diff --git a/classes/laconica.ini b/classes/laconica.ini old mode 100755 new mode 100644 index 5a905a4bb..00a1b8936 --- a/classes/laconica.ini +++ b/classes/laconica.ini @@ -1,4 +1,67 @@ +[file] +id = 129 +url = 2 +mimetype = 2 +size = 1 +title = 2 +date = 1 +protected = 17 + +[file__keys] +id = K +url = U + +[file_oembed] +id = 129 +file_id = 1 +version = 2 +type = 2 +provider = 2 +provider_url = 2 +width = 1 +height = 1 +html = 66 +title = 2 +author_name = 2 +author_url = 2 +url = 2 + +[file_oembed__keys] +id = K +file_id = U + +[file_redirection] +id = 129 +url = 2 +file_id = 1 +redirections = 1 +httpcode = 1 + +[file_redirection__keys] +id = K +url = U + +[file_thumbnail] +id = 129 +file_id = 1 +url = 2 +width = 1 +height = 1 + +[file_thumbnail__keys] +id = K +file_id = U +url = U + +[file_to_post] +id = 129 +file_id = 1 +post_id = 1 + +[file_to_post__keys] +id = K + [avatar] profile_id = 129 original = 17 @@ -393,3 +456,63 @@ modified = 384 [user_openid__keys] canonical = K display = U + +[file] +id = 129 +url = 2 +mimetype = 2 +size = 1 +title = 2 +date = 1 +protected = 1 + +[file__keys] +id = N + +[file_oembed] +id = 129 +file_id = 129 +version = 2 +type = 2 +provider = 2 +provider_url = 2 +width = 1 +height = 1 +html = 34 +title = 2 +author_name = 2 +author_url = 2 +url = 2 + +[file_oembed__keys] +id = N + +[file_redirection] +id = 129 +url = 2 +file_id = 129 +redirections = 1 +httpcode = 1 + +[file_redirection__keys] +id = N + +[file_thumbnail] +id = 129 +file_id = 129 +url = 2 +width = 1 +height = 1 + +[file_thumbnail__keys] +id = N + +[file_to_post] +id = 129 +file_id = 129 +post_id = 129 + +[file_to_post__keys] +id = N + + diff --git a/classes/laconica.links.ini b/classes/laconica.links.ini index 173b18726..bc52ce578 100644 --- a/classes/laconica.links.ini +++ b/classes/laconica.links.ini @@ -41,3 +41,74 @@ subscribed = profile:id [fave] notice_id = notice:id user_id = user:id + +[file_oembed] +file_id = file:id + +[file_redirection] +file_id = file:id + +[file_thumbnail] +file_id = file:id + +[file_to_post] +file_id = file:id +post_id = post:id + +[avatar] +profile_id = profile:id + +[user] +id = profile:id +carrier = sms_carrier:id + +[remote_profile] +id = profile:id + +[notice] +profile_id = profile:id +reply_to = notice:id + +[reply] +notice_id = notice:id +profile_id = profile:id + +[token] +consumer_key = consumer:consumer_key + +[nonce] +consumer_key,token = token:consumer_key,token + +[user_openid] +user_id = user:id + +[confirm_address] +user_id = user:id + +[remember_me] +user_id = user:id + +[queue_item] +notice_id = notice:id + +[subscription] +subscriber = profile:id +subscribed = profile:id + +[fave] +notice_id = notice:id +user_id = user:id + +[file_oembed] +file_id = file:id + +[file_redirection] +file_id = file:id + +[file_thumbnail] +file_id = file:id + +[file_to_post] +file_id = file:id +post_id = post:id + diff --git a/lib/util.php b/lib/util.php index 198185338..c4a63a441 100644 --- a/lib/util.php +++ b/lib/util.php @@ -395,7 +395,7 @@ function common_render_text($text) return $r; } -function common_replace_urls_callback($text, $callback) { +function common_replace_urls_callback($text, $callback, $notice_id = null) { // Start off with a regex $regex = '#'. '(?:'. @@ -466,7 +466,11 @@ function common_replace_urls_callback($text, $callback) { $url = (mb_strpos($orig_url, htmlspecialchars($url)) === FALSE) ? $url:htmlspecialchars($url); // Call user specified func - $modified_url = call_user_func($callback, $url); + if (isset($notice_id)) { + $modified_url = call_user_func($callback, array($url, $notice_id)); + } else { + $modified_url = call_user_func($callback, $url); + } // Replace it! $start = mb_strpos($text, $url, $offset); -- cgit v1.2.3-54-g00ecf From 78e5572b38ee3f71c0a5cf8743141817cc81079e Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Wed, 13 May 2009 15:56:44 +0000 Subject: Init h4ck3r theme. Originally suggested by Zach ( http://identi.ca/user/25 ). Background image (aka matrix h4x0r animated chars) is copied from Google neonblade2 theme ( http://ur1.ca/49wv ). Original creator of the image is unknown at this time. --- theme/h4ck3r/css/base.css | 1136 ++++++++++++++++++++ theme/h4ck3r/css/display.css | 236 ++++ theme/h4ck3r/css/ie.css | 9 + theme/h4ck3r/default-avatar-mini.png | Bin 0 -> 646 bytes theme/h4ck3r/default-avatar-profile.png | Bin 0 -> 2853 bytes theme/h4ck3r/default-avatar-stream.png | Bin 0 -> 1487 bytes .../h4ck3r/images/illustrations/illu_h4x0r1ng.gif | Bin 0 -> 432979 bytes theme/h4ck3r/logo.png | Bin 0 -> 4988 bytes 8 files changed, 1381 insertions(+) create mode 100644 theme/h4ck3r/css/base.css create mode 100644 theme/h4ck3r/css/display.css create mode 100644 theme/h4ck3r/css/ie.css create mode 100644 theme/h4ck3r/default-avatar-mini.png create mode 100644 theme/h4ck3r/default-avatar-profile.png create mode 100644 theme/h4ck3r/default-avatar-stream.png create mode 100644 theme/h4ck3r/images/illustrations/illu_h4x0r1ng.gif create mode 100644 theme/h4ck3r/logo.png diff --git a/theme/h4ck3r/css/base.css b/theme/h4ck3r/css/base.css new file mode 100644 index 000000000..54763006b --- /dev/null +++ b/theme/h4ck3r/css/base.css @@ -0,0 +1,1136 @@ +/** theme: h4ck3r base + * + * @package Laconica + * @author Sarven Capadisli + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +* { margin:0; padding:0; } +img { display:block; border:0; } +a abbr { cursor: pointer; border-bottom:0; } +table { border-collapse:collapse; } +ol { list-style-position:inside; } +html { font-size: 100%; background-color:#fff; height:100%; } +body { +background-color:#fff; +color:#000; +font-family:sans-serif; +font-size:1em; +line-height:1.65; +position:relative; +} +h1,h2,h3,h4,h5,h6 { +margin-bottom:7px; +overflow:hidden; +} +h1 { +font-size:1.4em; +margin-bottom:18px; +} +#showstream h1 { display:none; } +h2 { font-size:1.3em; } +h3 { font-size:1.2em; } +h4 { font-size:1.1em; } +h5 { font-size:1em; } +h6 { font-size:0.9em; } + +caption { +font-weight:bold; +} +legend { +font-weight:bold; +font-size:1.3em; +} +input, textarea, select, option { +padding:4px; +font-family:sans-serif; +font-size:1em; +} +input, textarea, select { +border-width:2px; +border-style: solid; +} + +input.submit { +font-weight:bold; +cursor:pointer; +} +textarea { +overflow:auto; +} +option { +padding-bottom:0; +} +fieldset { +padding:0; +border:0; +} +form ul li { +list-style-type:none; +margin:0 0 18px 0; +} +form label { +font-weight:bold; +} +input.checkbox { +position:relative; +top:2px; +left:0; +border:0; +} + +.error, +.success { +padding:4px 1.55%; +margin-bottom:18px; +} +form label.submit { +display:none; +} + +.form_settings { +clear:both; +} + +.form_settings fieldset { +margin-bottom:29px; +} +.form_settings input.remove { +margin-left:11px; +} +.form_settings .form_data li { +width:100%; +float:left; +} +.form_settings .form_data label { +float:left; +} +.form_settings .form_data textarea, +.form_settings .form_data select, +.form_settings .form_data input { +margin-left:11px; +float:left; +} +.form_settings .form_data input.submit { +margin-left:0; +} + +.form_settings label { +margin-top:2px; +width:152px; +} + +.form_actions label { +display:none; +} +.form_guide { +font-style:italic; +} + +.form_settings #settings_autosubscribe label { +display:inline; +font-weight:bold; +} + +#form_settings_profile legend, +#form_login legend, +#form_register legend, +#form_password legend, +#form_settings_avatar legend, +#newgroup legend, +#editgroup legend, +#form_tag_user legend, +#form_remote_subscribe legend, +#form_openid_login legend, +#form_search legend, +#form_invite legend, +#form_notice_delete legend, +#form_password_recover legend, +#form_password_change legend { +display:none; +} + +.form_settings .form_data p.form_guide { +clear:both; +margin-left:163px; +margin-bottom:0; +} + +.form_settings p { +margin-bottom:11px; +} + +.form_settings input.checkbox { +margin-top:3px; +margin-left:0; +} +.form_settings label.checkbox { +font-weight:normal; +margin-top:0; +margin-right:0; +margin-left:11px; +float:left; +width:90%; +} + + +#form_login p.form_guide, +#form_register #settings_rememberme p.form_guide, +#form_openid_login #settings_rememberme p.form_guide, +#settings_twitter_remove p.form_guide, +#form_search ul.form_data #q { +margin-left:0; +} + +.form_settings .form_note { +padding:0 7px; +} + + +.form_settings input.form_action-secondary { +margin-left:29px; +padding:0; +} + +#form_search .submit { +margin-left:11px; +} + +address { +float:left; +margin-bottom:18px; +margin-left:18px; +} +address.vcard img.logo { +margin-right:0; +} +address .fn { +font-weight:bold; +} +address img + .fn { +display:none; +} + +#header { +width:100%; +position:relative; +float:left; +padding-top:18px; +margin-bottom:29px; +} + +#site_nav_global_primary { +float:right; +margin-right:18px; +margin-bottom:11px; +margin-left:18px; +} +#site_nav_global_primary ul li { +display:inline; +margin-left:11px; +} + +.system_notice dt { +font-weight:bold; +text-transform:uppercase; +display:none; +} + +#site_notice { +float:left; +clear:right; +margin-top:7px; +margin-right:18px; +width:31%; +} +#page_notice { +clear:both; +margin-bottom:18px; +} + + +#anon_notice { +float:right; +width:41.2%; +padding:1.1%; +border-width:2px; +border-style:dashed; +line-height:1.5; +font-size:1.1em; +font-weight:bold; +-moz-transform:skewX(-30deg) scale(0.85); +-webkit-transform:skewX(-30deg) scale(0.85); +} + + +#footer { +float:left; +width:64%; +padding:18px; +} + +#site_nav_local_views { +width:100%; +float:right; +} +#site_nav_local_views dt { +display:none; +} +#site_nav_local_views li { +float:right; +margin-left:11px; +list-style-type:none; +} +#site_nav_local_views a { +float:left; +text-decoration:none; +padding:4px 11px; +border-width:1px; +border-style:dashed; +border-bottom:0; +text-shadow: 2px 2px 2px #ddd; +font-weight:bold; +} +#site_nav_local_views .nav { +float:left; +width:100%; +} + +#site_nav_global_primary dt, +#site_nav_global_secondary dt { +display:none; +} + +#site_nav_global_secondary { +margin-bottom:11px; +} + +#site_nav_global_secondary ul li { +display:inline; +margin-right:11px; +} +#export_data li a { +padding-left:20px; +} +#export_data li a.foaf { +padding-left:30px; +} +#export_data li a.export_vcard { +padding-left:28px; +} + +#export_data ul { +display:inline; +} +#export_data li { +list-style-type:none; +display:inline; +margin-left:11px; +} +#export_data li:first-child { +margin-left:0; +} + +#licenses { +font-size:0.9em; +} + +#licenses dt { +font-weight:bold; +display:none; +} +#licenses dd { +margin-bottom:11px; +line-height:1.5; +} + +#site_content_license_cc { +margin-bottom:0; +} +#site_content_license_cc img { +display:inline; +vertical-align:top; +margin-right:4px; +} + +#wrap { +margin:0 auto; +width:100%; +min-width:760px; +max-width:1003px; +overflow:hidden; +} + +#core { +position:relative; +width:100%; +float:left; +margin-bottom:1em; +} + +#content { +width:60.009%; +min-height:259px; +padding:1.795%; +float:right; +border-style:dashed; +border-width:1px; +} +#shownotice #content { +min-height:0; +} + +#content_inner { +position:relative; +width:100%; +float:left; +} + +#aside_primary { +width:27.917%; +min-height:259px; +float:right; +margin-right:4.385%; +padding:1.795%; +border-width:1px; +border-style:dashed; +} + +#form_notice { +width:43.664%; +float:right; +position:relative; +line-height:1; +} +#form_notice fieldset { +border:0; +padding:0; +position:relative; +} +#form_notice legend { +display:none; +} +#form_notice textarea { +float:left; +width:80.789%; +height:67px; +line-height:1.5; +padding:7px 7px 16px 7px; +} +#form_notice label { +display:block; +float:left; +font-size:1.3em; +margin-bottom:7px; +} +#form_notice #notice_submit label { +display:none; +} +#form_notice .form_note { +position:absolute; +top:99px; +right:98px; +z-index:9; +} +#form_notice .form_note dt { +font-weight:bold; +display:none; +} +#notice_text-count { +font-weight:bold; +line-height:1.15; +padding:1px 2px; +} +#form_notice #notice_action-submit { +width:14%; +height:47px; +padding:0; +position:absolute; +bottom:0; +right:0; +} +#form_notice label[for=to] { +margin-top:7px; +} +#form_notice select[id=to] { +margin-bottom:7px; +margin-left:18px; +float:left; +} +#form_notice .error { +float:left; +clear:both; +width:96.9%; +margin-bottom:0; +line-height:1.618; +} + +/* entity_profile */ +.entity_profile { +position:relative; +width:67.702%; +min-height:123px; +float:left; +margin-bottom:18px; +margin-left:0; +overflow:hidden; +} +.entity_profile dt, +#entity_statistics dt { +font-weight:bold; +} +.entity_profile dd { +display:inline; +} + +.entity_profile .entity_depiction { +float:left; +width:96px; +margin-right:18px; +margin-bottom:18px; +} + +.entity_profile .entity_fn, +.entity_profile .entity_nickname, +.entity_profile .entity_location, +.entity_profile .entity_url, +.entity_profile .entity_note, +.entity_profile .entity_tags { +margin-left:113px; +margin-bottom:4px; +} + +.entity_profile .entity_fn, +.entity_profile .entity_nickname { +margin-left:11px; +display:inline; +font-weight:bold; +} +.entity_profile .entity_nickname { +margin-left:0; +} + +.entity_profile .entity_fn dd:before { +content: "("; +font-weight:normal; +} +.entity_profile .entity_fn dd:after { +content: ")"; +font-weight:normal; +} + +.entity_profile dt { +display:none; +} +.entity_profile h2 { +display:none; +} +/* entity_profile */ + + +/*entity_actions*/ +.entity_actions { +float:right; +margin-left:4.35%; +max-width:25%; +} +.entity_actions h2 { +display:none; +} +.entity_actions ul { +list-style-type:none; +} +.entity_actions li { +margin-bottom:4px; +} +.entity_actions li:first-child { +border-top:0; +} +.entity_actions fieldset { +border:0; +padding:0; +} +.entity_actions legend { +display:none; +} + +.entity_actions input.submit { +display:block; +text-align:left; +width:100%; +} +.entity_actions a, +.entity_nudge p, +.entity_remote_subscribe { +text-decoration:none; +font-weight:bold; +display:block; +} + +.form_user_block input.submit, +.form_user_unblock input.submit, +.entity_send-a-message a, +.entity_edit a, +.form_user_nudge input.submit, +.entity_nudge p { +border:0; +padding-left:20px; +} + +.entity_edit a, +.entity_send-a-message a, +.entity_nudge p { +padding:4px 4px 4px 23px; +} + +.entity_remote_subscribe { +padding:4px; +border-width:2px; +border-style:solid; +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +} +.entity_actions .accept { +margin-bottom:18px; +} + +.entity_tags ul { +list-style-type:none; +display:inline; +} +.entity_tags li { +display:inline; +margin-right:4px; +} + +.aside .section { +margin-bottom:29px; +clear:both; +float:left; +width:100%; +} +.aside .section h2 { +text-transform:uppercase; +font-size:1em; +} + +#entity_statistics dt, +#entity_statistics dd { +display:inline; +} +#entity_statistics dt:after { +content: ":"; +} + +.section ul.entities { +float:left; +width:100%; +} +.section .entities li { +list-style-type:none; +float:left; +margin-right:7px; +margin-bottom:7px; +} +.section .entities li .photo { +margin-right:0; +margin-bottom:0; +} +.section .entities li .fn { +display:none; +} + +.aside .section p, +.aside .section .more { +clear:both; +} + +.profile .entity_profile { +margin-bottom:0; +min-height:60px; +} + + +.profile .form_group_join legend, +.profile .form_group_leave legend, +.profile .form_user_subscribe legend, +.profile .form_user_unsubscribe legend { +display:none; +} + +.profiles { +list-style-type:none; +} +.profile .entity_profile .entity_location { +width:auto; +clear:none; +margin-left:11px; +} +.profile .entity_profile dl, +.profile .entity_profile dd { +display:inline; +float:none; +} +.profile .entity_profile .entity_note, +.profile .entity_profile .entity_url, +.profile .entity_profile .entity_tags, +.profile .entity_profile .form_subscription_edit { +margin-left:59px; +clear:none; +display:block; +width:auto; +} +.profile .entity_profile .entity_tags dt { +display:inline; +margin-right:11px; +} + + +.profile .entity_profile .form_subscription_edit label { +font-weight:normal; +margin-right:11px; +} + + +/* NOTICE */ +.notice, +.profile { +position:relative; +padding-top:11px; +padding-bottom:11px; +clear:both; +float:left; +width:100%; +border-top-width:1px; +border-top-style:dashed; +} +.notices li { +list-style-type:none; +} + + +/* NOTICES */ +#notices_primary { +float:left; +width:100%; +border-radius:7px; +-moz-border-radius:7px; +-webkit-border-radius:7px; +} +#notices_primary h2 { +display:none; +} +.notice-data a span { +display:block; +padding-left:28px; +} + +.notice .author { +margin-right:11px; +} + +.fn { +overflow:hidden; +} + +.notice .author .fn { +font-weight:bold; +} + +.vcard .photo { +display:inline; +margin-right:11px; +float:left; +} +#shownotice .vcard .photo { +margin-bottom:4px; +} +.vcard .url { +text-decoration:none; +} +.vcard .url:hover { +text-decoration:underline; +} + +.notice .entry-title { +display:inline; +width:100%; +overflow:hidden; +} +#shownotice .notice .entry-title { +font-size:2.2em; +} + +.notice p.entry-content { +display:inline; +} + +#content .notice p.entry-content a:visited { +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +} +.notice p.entry-content .vcard a { +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +} + +.notice div.entry-content { +float:left; +font-size:0.95em; +width:65%; +} + +.notice .notice-options a, +.notice .notice-options input { +float:left; +font-size:1.025em; +} + +.notice div.entry-content dl, +.notice div.entry-content dt, +.notice div.entry-content dd { +display:inline; +} + +.notice div.entry-content .timestamp dt, +.notice div.entry-content .response dt { +display:none; +} +.notice div.entry-content .timestamp a { +display:inline-block; +} +.notice div.entry-content .device dt { +text-transform:lowercase; +} + + +.notice-options { +padding-left:2%; +float:left; +width:50%; +position:relative; +font-size:0.95em; +width:12.5%; +float:right; +} + +.notice-options a { +float:left; +} +.notice-options .notice_delete, +.notice-options .notice_reply, +.notice-options .form_favor, +.notice-options .form_disfavor { +position:absolute; +top:0; +} +.notice-options .form_favor, +.notice-options .form_disfavor { +left:0; +} +.notice-options .notice_reply { +left:29px; +} +.notice-options .notice_delete { +right:0; +} +.notice-options .notice_reply dt { +display:none; +} + +.notice-options input, +.notice-options a { +text-indent:-9999px; +outline:none; +} + +.notice-options .notice_reply a, +.notice-options input.submit { +display:block; +border:0; +} +.notice-options .notice_reply a, +.notice-options .notice_delete a { +text-decoration:none; +padding-left:16px; +} + +.notice-options form input.submit { +width:16px; +padding:2px 0; +} + +.notice-options .notice_delete dt, +.notice-options .form_favor legend, +.notice-options .form_disfavor legend { +display:none; +} +.notice-options .notice_delete fieldset, +.notice-options .form_favor fieldset, +.notice-options .form_disfavor fieldset { +border:0; +padding:0; +} + + +#usergroups #new_group { +float: left; +margin-right: 2em; +} +#new_group, #group_search { +margin-bottom:18px; +} +#new_group a { +padding-left:20px; +} + + +#filter_tags { +margin-bottom:11px; +float:left; +} +#filter_tags dt { +display:none; +} +#filter_tags ul { +list-style-type:none; +} +#filter_tags ul li { +float:left; +margin-left:7px; +padding-left:7px; +border-left-width:1px; +border-left-style:solid; +} +#filter_tags ul li.child_1 { +margin-left:0; +border-left:0; +padding-left:0; +} +#filter_tags ul li#filter_tags_all a { +font-weight:bold; +margin-top:7px; +float:left; +} + +#filter_tags ul li#filter_tags_item label { +margin-right:7px; +} +#filter_tags ul li#filter_tags_item label, +#filter_tags ul li#filter_tags_item select { +display:inline; +} +#filter_tags ul li#filter_tags_item p { +float:left; +margin-left:38px; +} +#filter_tags ul li#filter_tags_item input { +position:relative; +top:3px; +left:3px; +} + + + +.pagination { +float:left; +clear:both; +width:100%; +margin-top:18px; +} + +.pagination dt { +font-weight:bold; +display:none; +} + +.pagination .nav { +float:left; +width:100%; +list-style-type:none; +} + +.pagination .nav_prev { +float:left; +} +.pagination .nav_next { +float:right; +} + +.pagination a { +display:block; +text-decoration:none; +font-weight:bold; +padding:7px; +border-width:1px; +border-style:solid; +-moz-border-radius:7px; +-webkit-border-radius:7px; +border-radius:7px; +} + +.pagination .nav_prev a { +padding-left:30px; +} +.pagination .nav_next a { +padding-right:30px; +} +/* END: NOTICE */ + + +.hentry .entry-content p { +margin-bottom:18px; +} +.system_notice ul, +.instructions ul, +.hentry entry-content ol, +.hentry .entry-content ul { +list-style-position:inside; +} +.hentry .entry-content li { +margin-bottom:18px; +} +.hentry .entry-content li li { +margin-left:18px; +} + + + + +/* TOP_POSTERS */ +.section tbody td { +padding-right:11px; +padding-bottom:11px; +} +.section .vcard .photo { +margin-right:7px; +margin-bottom:0; +} + +.section .notice { +padding-top:7px; +padding-bottom:7px; +border-top:0; +} + +.section .notice:first-child { +padding-top:0; +} + +.section .notice .author { +margin-right:0; +} +.section .notice .author .fn { +display:none; +} + + +/* tagcloud */ +.tag-cloud { +list-style-type:none; +text-align:center; +} +.aside .tag-cloud { +font-size:0.8em; +} +.tag-cloud li { +display:inline; +margin-right:7px; +line-height:1.25; +} +.aside .tag-cloud li { +line-height:1.5; +} +.tag-cloud li a { +text-decoration:none; +} +#tagcloud.section dt { +text-transform:uppercase; +font-weight:bold; +} +.tag-cloud-1 { +font-size:1em; +} +.tag-cloud-2 { +font-size:1.25em; +} +.tag-cloud-3 { +font-size:1.75em; +} +.tag-cloud-4 { +font-size:2em; +} +.tag-cloud-5 { +font-size:2.25em; +} +.tag-cloud-6 { +font-size:2.75em; +} +.tag-cloud-7 { +font-size:3.25em; +} + +#publictagcloud #tagcloud.section dt { +display:none; +} + +#form_settings_photo .form_data { +clear:both; +} + +#form_settings_avatar li { +width:auto; +} +#form_settings_avatar input { +margin-left:0; +} +#avatar_original, +#avatar_preview { +float:left; +} +#avatar_preview { +margin-left:29px; +} +#avatar_preview_view { +height:96px; +width:96px; +margin-bottom:18px; +overflow:hidden; +} + +#settings_attach, +#form_settings_avatar .form_actions { +clear:both; +} + +#form_settings_avatar .form_actions { +margin-bottom:0; +} + +#form_settings_design #settings_design_color .form_data, +#form_settings_design #color-picker { +float:left; +} +#form_settings_design #settings_design_color .form_data { +width:400px; +margin-right:28px; +} + +.instructions ul { +list-style-position:inside; +} +.instructions p, +.instructions ul { +margin-bottom:18px; +} +.help dt { +display:none; +} +.guide { +clear:both; +} diff --git a/theme/h4ck3r/css/display.css b/theme/h4ck3r/css/display.css new file mode 100644 index 000000000..c7631a8eb --- /dev/null +++ b/theme/h4ck3r/css/display.css @@ -0,0 +1,236 @@ +/** theme: h4ck3r + * + * @package Laconica + * @author Sarven Capadisli + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +@import url(base.css); + +html, +body, +a:active { +background-color:#000; +} + +body { +background-image:url(../images/illustrations/illu_h4x0r1ng.gif); +font-family: monospace; +font-size:1em; +color:#647819; +} +address { +margin-right:7.18%; +} + +input, textarea, select, option { +font-family: monospace; +} +input, textarea, select, +.entity_remote_subscribe { +border-color:#aaa; +background-color:#000; +color:#ccc; +} +#filter_tags ul li { +border-color:#ddd; +} + +.form_settings input.form_action-secondary { +background:none; +} + +input.submit, +#form_notice.warning #notice_text-count, +.form_settings .form_note, +.entity_remote_subscribe { +background-color:rgba(0, 255, 0, 0.5); +} + +input:focus, textarea:focus, select:focus, +#form_notice.warning #notice_data-text { +border-color:#9BB43E; +} +input.submit, +.entity_remote_subscribe { +color:#fff; +} + +a, +div.notice-options input, +.form_user_block input.submit, +.form_user_unblock input.submit, +.entity_send-a-message a, +.form_user_nudge input.submit, +.entity_nudge p, +.form_settings input.form_action-secondary { +color:#0f0; +} + +.notice, +.profile { +border-top-color:#333; +} +.section .profile { +border-top-color:#87B4C8; +} + +#aside_primary { +background-color:rgba(0,128,0,0.3); +} + +#notice_text-count { +color:#0f0; +} +#form_notice.warning #notice_text-count { +color:#000; +} +#form_notice.processing #notice_action-submit { +background:#ccc url(../../base/images/icons/icon_processing.gif) no-repeat 47% 47%; +cursor:wait; +text-indent:-9999px; +} + +#content, +#site_nav_local_views a, +#aside_primary { +border-color:#50964D; +} +#content, +#site_nav_local_views .current a { +background-color:rgba(0, 0, 0, 0.698); +} + +#site_nav_local_views a { +background-color:rgba(0, 200, 0, 0.3); +} +#site_nav_local_views a:hover { +background-color:rgba(255, 255, 255, 0.4); +} + +.error { +background-color:#F7E8E8; +} +.success { +background-color:#EFF3DC; +} + +#anon_notice { +color:#ccc; +border-color:#50964D; +} + +#showstream #anon_notice { +} + +#export_data li a { +background-repeat:no-repeat; +background-position:0 45%; +} +#export_data li a.rss { +background-image:url(../../base/images/icons/icon_rss.png); +} +#export_data li a.atom { +background-image:url(../../base/images/icons/icon_atom.png); +} +#export_data li a.foaf { +background-image:url(../../base/images/icons/icon_foaf.gif); +} + +.entity_edit a, +.entity_send-a-message a, +.form_user_nudge input.submit, +.form_user_block input.submit, +.form_user_unblock input.submit, +.entity_nudge p { +background-position: 0 40%; +background-repeat: no-repeat; +background-color:transparent; +} +.form_group_join input.submit, +.form_group_leave input.submit +.form_user_subscribe input.submit, +.form_user_unsubscribe input.submit { +background-color:#9BB43E; +color:#ccc; +} +.form_user_unsubscribe input.submit, +.form_group_leave input.submit, +.form_user_authorization input.reject { +background-color:#87B4C8; +} + +.entity_edit a { +background-image:url(../../base/images/icons/twotone/green/edit.gif); +} +.entity_send-a-message a { +background-image:url(../../base/images/icons/twotone/green/quote.gif); +} +.entity_nudge p, +.form_user_nudge input.submit { +background-image:url(../../base/images/icons/twotone/green/mail.gif); +} +.form_user_block input.submit, +.form_user_unblock input.submit { +background-image:url(../../base/images/icons/twotone/green/shield.gif); +} + +/* NOTICES */ +.notices li.over { +background-color:#fcfcfc; +} + +.notice-options .notice_reply a, +.notice-options form input.submit { +background-color:transparent; +} +.notice-options .notice_reply a { +background:transparent url(../../base/images/icons/twotone/green/reply.gif) no-repeat 0 45%; +} +.notice-options form.form_favor input.submit { +background:transparent url(../../base/images/icons/twotone/green/favourite.gif) no-repeat 0 45%; +} +.notice-options form.form_disfavor input.submit { +background:transparent url(../../base/images/icons/twotone/green/disfavourite.gif) no-repeat 0 45%; +} +.notice-options .notice_delete a { +background:transparent url(../../base/images/icons/twotone/green/trash.gif) no-repeat 0 45%; +} + +.notices div.entry-content, +.notices div.notice-options { +opacity:0.4; +} +.notices li.hover div.entry-content, +.notices li.hover div.notice-options { +opacity:1; +} +div.entry-content { +color:#ccc; +} +div.notice-options a, +div.notice-options input { +font-family:sans-serif; +} + +/*END: NOTICES */ + +#new_group a { +background:transparent url(../../base/images/icons/twotone/green/news.gif) no-repeat 0 45%; +} + +.pagination .nav_prev a, +.pagination .nav_next a { +background-repeat:no-repeat; +border-color:#000; +} +.pagination .nav_prev a { +background-image:url(../../base/images/icons/twotone/green/arrow-left.gif); +background-position:10% 45%; +} +.pagination .nav_next a { +background-image:url(../../base/images/icons/twotone/green/arrow-right.gif); +background-position:90% 45%; +} diff --git a/theme/h4ck3r/css/ie.css b/theme/h4ck3r/css/ie.css new file mode 100644 index 000000000..2f463bb44 --- /dev/null +++ b/theme/h4ck3r/css/ie.css @@ -0,0 +1,9 @@ +/* IE specific styles */ + +.notice-options input.submit { +color:#fff; +} + +#site_nav_local_views a { +background-color:#D0DFE7; +} diff --git a/theme/h4ck3r/default-avatar-mini.png b/theme/h4ck3r/default-avatar-mini.png new file mode 100644 index 000000000..38b8692b4 Binary files /dev/null and b/theme/h4ck3r/default-avatar-mini.png differ diff --git a/theme/h4ck3r/default-avatar-profile.png b/theme/h4ck3r/default-avatar-profile.png new file mode 100644 index 000000000..f8357d4fc Binary files /dev/null and b/theme/h4ck3r/default-avatar-profile.png differ diff --git a/theme/h4ck3r/default-avatar-stream.png b/theme/h4ck3r/default-avatar-stream.png new file mode 100644 index 000000000..6b63baa70 Binary files /dev/null and b/theme/h4ck3r/default-avatar-stream.png differ diff --git a/theme/h4ck3r/images/illustrations/illu_h4x0r1ng.gif b/theme/h4ck3r/images/illustrations/illu_h4x0r1ng.gif new file mode 100644 index 000000000..c233af391 Binary files /dev/null and b/theme/h4ck3r/images/illustrations/illu_h4x0r1ng.gif differ diff --git a/theme/h4ck3r/logo.png b/theme/h4ck3r/logo.png new file mode 100644 index 000000000..7c68b34f6 Binary files /dev/null and b/theme/h4ck3r/logo.png differ -- cgit v1.2.3-54-g00ecf From 06e012cc713bf7212b4060840091d4c18cd8cfbd Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Wed, 13 May 2009 16:06:52 +0000 Subject: Minor clearing. --- theme/h4ck3r/css/base.css | 1 + 1 file changed, 1 insertion(+) diff --git a/theme/h4ck3r/css/base.css b/theme/h4ck3r/css/base.css index 54763006b..5060bbb8b 100644 --- a/theme/h4ck3r/css/base.css +++ b/theme/h4ck3r/css/base.css @@ -253,6 +253,7 @@ margin-bottom:18px; #anon_notice { float:right; +clear:right; width:41.2%; padding:1.1%; border-width:2px; -- cgit v1.2.3-54-g00ecf From d8e49a21745bfde9a18a6d6e1047decc3c7e356f Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Wed, 13 May 2009 17:29:13 +0000 Subject: otalk theme: Using two columns for notice list --- theme/otalk/css/base.css | 16 ++++++++++------ theme/otalk/css/display.css | 1 - 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/theme/otalk/css/base.css b/theme/otalk/css/base.css index 379590d30..32e8891d2 100644 --- a/theme/otalk/css/base.css +++ b/theme/otalk/css/base.css @@ -12,7 +12,7 @@ img { display:block; border:0; } a abbr { cursor: pointer; border-bottom:0; } table { border-collapse:collapse; } ol { list-style-position:inside; } -html { font-size: 87.5%; background-color:#fff; height:100%; } +html { font-size: 87.5%; background-color:#fff; } body { background-color:#fff; color:#000; @@ -386,12 +386,12 @@ margin-bottom:1em; } #content { -width:100%; +width:67.9%; min-height:259px; padding-top:1.795%; padding-bottom:1.795%; - float:left; +clear:left; border-radius:7px; -moz-border-radius:7px; -moz-border-radius-topleft:0; @@ -409,11 +409,11 @@ float:left; } #aside_primary { -width:96.3%; +width:27.917%; min-height:259px; float:left; -clear:both; padding:1.795%; +margin-left:0.385%; border-radius:7px; -moz-border-radius:7px; -webkit-border-radius:7px; @@ -730,7 +730,7 @@ list-style-type:none; } #content .notice { -width:25%; +width:37%; margin-left:17px; margin-bottom:47px; clear:none; @@ -743,6 +743,10 @@ min-height:235px; margin-bottom:18px; } +#shownotice #content .notice { +width:96%; +} + /* NOTICES */ #notices_primary { diff --git a/theme/otalk/css/display.css b/theme/otalk/css/display.css index 22e0530ec..6c646791b 100644 --- a/theme/otalk/css/display.css +++ b/theme/otalk/css/display.css @@ -15,7 +15,6 @@ html { html, body, a:active { -/*background-color:#F0F2F5;*/ } body { font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; -- cgit v1.2.3-54-g00ecf From 3b7ee5a5f9a2cd3066aff8a7a12d09878be3b06c Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Wed, 13 May 2009 14:27:32 -0400 Subject: rewrote short url stuff to handle new file/url classes (redirections, oembed, mimetypes, etc.) --- actions/newnotice.php | 18 +--- classes/File.php | 65 ++++++++++++ classes/File_oembed.php | 43 ++++++++ classes/File_redirection.php | 231 +++++++++++++++++++++++++++++++++++++++++++ classes/File_to_post.php | 17 ++++ classes/Notice.php | 6 +- classes/laconica.ini | 64 ------------ classes/laconica.links.ini | 59 +---------- lib/Shorturl_api.php | 3 +- lib/util.php | 112 ++++----------------- 10 files changed, 382 insertions(+), 236 deletions(-) diff --git a/actions/newnotice.php b/actions/newnotice.php index 8b03abc62..ae0ff9636 100644 --- a/actions/newnotice.php +++ b/actions/newnotice.php @@ -158,7 +158,8 @@ class NewnoticeAction extends Action $replyto = 'false'; } - $notice = Notice::saveNew($user->id, $content, 'web', 1, +// $notice = Notice::saveNew($user->id, $content_shortened, 'web', 1, + $notice = Notice::saveNew($user->id, $content_shortened, 'web', 1, ($replyto == 'false') ? null : $replyto); if (is_string($notice)) { @@ -203,25 +204,12 @@ class NewnoticeAction extends Action * @return void */ function saveUrls($notice) { - common_debug("Saving all URLs"); common_replace_urls_callback($notice->content, array($this, 'saveUrl'), $notice->id); } function saveUrl($data) { list($url, $notice_id) = $data; - common_debug("Saving $url for $notice_id"); - $file = File::staticGet('url', $url); - if (empty($file)) { - common_debug('unknown file/url'); - $file = new File; - $file->url = $url; - $file->insert(); - } - common_debug('File: ' . print_r($file, true)); - $f2p = new File_to_post; - $f2p->file_id = $file->id; - $f2p->post_id = $notice_id; - $f2p->insert(); + $zzz = File::processNew($url, $notice_id); } /** diff --git a/classes/File.php b/classes/File.php index 8dd017b79..2ddc5deb8 100644 --- a/classes/File.php +++ b/classes/File.php @@ -20,6 +20,11 @@ if (!defined('LACONICA')) { exit(1); } require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; +require_once INSTALLDIR.'/classes/File_redirection.php'; +require_once INSTALLDIR.'/classes/File_oembed.php'; +require_once INSTALLDIR.'/classes/File_thumbnail.php'; +require_once INSTALLDIR.'/classes/File_to_post.php'; +//require_once INSTALLDIR.'/classes/File_redirection.php'; /** * Table Definition for file @@ -44,4 +49,64 @@ class File extends Memcached_DataObject /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE + + function isProtected($url) { + return 'http://www.facebook.com/login.php' === $url; + } + + function saveNew($redir_data, $given_url) { + $x = new File; + $x->url = $given_url; + if (!empty($redir_data['protected'])) $x->protected = $redir_data['protected']; + if (!empty($redir_data['title'])) $x->title = $redir_data['title']; + if (!empty($redir_data['type'])) $x->mimetype = $redir_data['type']; + if (!empty($redir_data['size'])) $x->size = intval($redir_data['size']); + if (isset($redir_data['time']) && $redir_data['time'] > 0) $x->date = intval($redir_data['time']); + $file_id = $x->insert(); + + if (isset($redir_data['type']) + && ('text/html' === substr($redir_data['type'], 0, 9)) + && ($oembed_data = File_oembed::_getOembed($given_url)) + && isset($oembed_data['json'])) { + + File_oembed::saveNew($oembed_data['json'], $file_id); + } + return $x; + } + + function processNew($given_url, $notice_id) { + if (empty($given_url)) return -1; // error, no url to process + $given_url = File_redirection::_canonUrl($given_url); + if (empty($given_url)) return -1; // error, no url to process + $file = File::staticGet('url', $given_url); + if (empty($file->id)) { + $file_redir = File_redirection::staticGet('url', $given_url); + if (empty($file_redir->id)) { + $redir_data = File_redirection::where($given_url); + $redir_url = $redir_data['url']; + if ($redir_url === $given_url) { + $x = File::saveNew($redir_data, $given_url); + $file_id = $x->id; + + } else { + $x = File::processNew($redir_url, $notice_id); + $file_id = $x->id; + File_redirection::saveNew($redir_data, $file_id, $given_url); + } + } else { + $file_id = $file_redir->file_id; + } + } else { + $file_id = $file->id; + $x = $file; + } + + if (empty($x)) { + $x = File::staticGet($file_id); + if (empty($x)) die('Impossible!'); + } + + File_to_post::processNew($file_id, $notice_id); + return $x; + } } diff --git a/classes/File_oembed.php b/classes/File_oembed.php index 33dd8200c..2846f49db 100644 --- a/classes/File_oembed.php +++ b/classes/File_oembed.php @@ -50,4 +50,47 @@ class File_oembed extends Memcached_DataObject /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE + + + function _getOembed($url, $maxwidth = 500, $maxheight = 400, $format = 'json') { + $cmd = 'http://oohembed.com/oohembed/?url=' . urlencode($url); + if (is_int($maxwidth)) $cmd .= "&maxwidth=$maxwidth"; + if (is_int($maxheight)) $cmd .= "&maxheight=$maxheight"; + if (is_string($format)) $cmd .= "&format=$format"; + $oe = @file_get_contents($cmd); + if (false === $oe) return false; + return array($format => (('json' === $format) ? json_decode($oe, true) : $oe)); + } + + function saveNew($data, $file_id) { + $file_oembed = new File_oembed; + $file_oembed->file_id = $file_id; + $file_oembed->version = $data['version']; + $file_oembed->type = $data['type']; + if (!empty($data['provider_name'])) $file_oembed->provider = $data['provider_name']; + if (!isset($file_oembed->provider) && !empty($data['provide'])) $file_oembed->provider = $data['provider']; + if (!empty($data['provide_url'])) $file_oembed->provider_url = $data['provider_url']; + if (!empty($data['width'])) $file_oembed->width = intval($data['width']); + if (!empty($data['height'])) $file_oembed->height = intval($data['height']); + if (!empty($data['html'])) $file_oembed->html = $data['html']; + if (!empty($data['title'])) $file_oembed->title = $data['title']; + if (!empty($data['author_name'])) $file_oembed->author_name = $data['author_name']; + if (!empty($data['author_url'])) $file_oembed->author_url = $data['author_url']; + if (!empty($data['url'])) $file_oembed->url = $data['url']; + $file_oembed->insert(); + + if (!empty($data['thumbnail_url'])) { + $tn = new File_thumbnail; + $tn->file_id = $file_id; + $tn->url = $data['thumbnail_url']; + $tn->width = intval($data['thumbnail_width']); + $tn->height = intval($data['thumbnail_height']); + $tn->insert(); + } + + + + } } + + diff --git a/classes/File_redirection.php b/classes/File_redirection.php index e2d1e69c3..a71d1c083 100644 --- a/classes/File_redirection.php +++ b/classes/File_redirection.php @@ -20,6 +20,11 @@ if (!defined('LACONICA')) { exit(1); } require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; +require_once INSTALLDIR.'/classes/File.php'; +require_once INSTALLDIR.'/classes/File_oembed.php'; + +define('USER_AGENT', 'Laconica user agent / file probe'); + /** * Table Definition for file_redirection @@ -42,4 +47,230 @@ class File_redirection extends Memcached_DataObject /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE + + + + function _commonCurl($url, $redirs) { + $curlh = curl_init(); + curl_setopt($curlh, CURLOPT_URL, $url); + curl_setopt($curlh, CURLOPT_AUTOREFERER, true); // # setup referer header when folowing redirects + curl_setopt($curlh, CURLOPT_CONNECTTIMEOUT, 10); // # seconds to wait + curl_setopt($curlh, CURLOPT_MAXREDIRS, $redirs); // # max number of http redirections to follow + curl_setopt($curlh, CURLOPT_USERAGENT, USER_AGENT); + curl_setopt($curlh, CURLOPT_FOLLOWLOCATION, true); // Follow redirects + curl_setopt($curlh, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curlh, CURLOPT_FILETIME, true); + curl_setopt($curlh, CURLOPT_HEADER, true); // Include header in output + return $curlh; + } + + function _redirectWhere_imp($short_url, $redirs = 10, $protected = false) { + if ($redirs < 0) return false; + + // let's see if we know this... + $a = File::staticGet('url', $short_url); + if (empty($a->id)) { + $b = File_redirection::staticGet('url', $short_url); + if (empty($b->id)) { + // we'll have to figure it out + } else { + // this is a redirect to $b->file_id + $a = File::staticGet($b->file_id); + $url = $a->url; + } + } else { + // this is a direct link to $a->url + $url = $a->url; + } + if (isset($url)) { + return $url; + } + + + + $curlh = File_redirection::_commonCurl($short_url, $redirs); + // Don't include body in output + curl_setopt($curlh, CURLOPT_NOBODY, true); + curl_exec($curlh); + $info = curl_getinfo($curlh); + curl_close($curlh); + + if (405 == $info['http_code']) { + $curlh = File_redirection::_commonCurl($short_url, $redirs); + curl_exec($curlh); + $info = curl_getinfo($curlh); + curl_close($curlh); + } + + if (!empty($info['redirect_count']) && File::isProtected($info['url'])) { + return File_redirection::_redirectWhere_imp($short_url, $info['redirect_count'] - 1, true); + } + + $ret = array('code' => $info['http_code'] + , 'redirects' => $info['redirect_count'] + , 'url' => $info['url']); + + if (!empty($info['content_type'])) $ret['type'] = $info['content_type']; + if ($protected) $ret['protected'] = true; + if (!empty($info['download_content_length'])) $ret['size'] = $info['download_content_length']; + if (isset($info['filetime']) && ($info['filetime'] > 0)) $ret['time'] = $info['filetime']; + return $ret; + } + + function where($in_url) { + $ret = File_redirection::_redirectWhere_imp($in_url); + return $ret; + } + + function makeShort($long_url) { + $long_url = File_redirection::_canonUrl($long_url); + // do we already know this long_url and have a short redirection for it? + $file = new File; + $file_redir = new File_redirection; + $file->url = $long_url; + $file->joinAdd($file_redir); + $file->selectAdd('length(file_redirection.url) as len'); + $file->limit(1); + $file->orderBy('len'); + $file->find(true); + if (!empty($file->id)) { + return $file->url; + } + + // if yet unknown, we must find a short url according to user settings + $short_url = File_redirection::_userMakeShort($long_url, common_current_user()); + return $short_url; + } + + function _userMakeShort($long_url, $user) { + if (empty($user)) { + // common current user does not find a user when called from the XMPP daemon + // therefore we'll set one here fix, so that XMPP given URLs may be shortened + $user->urlshorteningservice = 'ur1.ca'; + } + $curlh = curl_init(); + curl_setopt($curlh, CURLOPT_CONNECTTIMEOUT, 20); // # seconds to wait + curl_setopt($curlh, CURLOPT_USERAGENT, 'Laconica'); + curl_setopt($curlh, CURLOPT_RETURNTRANSFER, true); + + switch($user->urlshorteningservice) { + case 'ur1.ca': + require_once INSTALLDIR.'/lib/Shorturl_api.php'; + $short_url_service = new LilUrl; + $short_url = $short_url_service->shorten($long_url); + break; + + case '2tu.us': + $short_url_service = new TightUrl; + require_once INSTALLDIR.'/lib/Shorturl_api.php'; + $short_url = $short_url_service->shorten($long_url); + break; + + case 'ptiturl.com': + require_once INSTALLDIR.'/lib/Shorturl_api.php'; + $short_url_service = new PtitUrl; + $short_url = $short_url_service->shorten($long_url); + break; + + case 'bit.ly': + curl_setopt($curlh, CURLOPT_URL, 'http://bit.ly/api?method=shorten&long_url='.urlencode($long_url)); + $short_url = current(json_decode(curl_exec($curlh))->results)->hashUrl; + break; + + case 'is.gd': + curl_setopt($curlh, CURLOPT_URL, 'http://is.gd/api.php?longurl='.urlencode($long_url)); + $short_url = curl_exec($curlh); + break; + case 'snipr.com': + curl_setopt($curlh, CURLOPT_URL, 'http://snipr.com/site/snip?r=simple&link='.urlencode($long_url)); + $short_url = curl_exec($curlh); + break; + case 'metamark.net': + curl_setopt($curlh, CURLOPT_URL, 'http://metamark.net/api/rest/simple?long_url='.urlencode($long_url)); + $short_url = curl_exec($curlh); + break; + case 'tinyurl.com': + curl_setopt($curlh, CURLOPT_URL, 'http://tinyurl.com/api-create.php?url='.urlencode($long_url)); + $short_url = curl_exec($curlh); + break; + default: + $short_url = false; + } + + curl_close($curlh); + + if ($short_url) { + $short_url = (string)$short_url; +if(1) { + // store it + $file = File::staticGet('url', $long_url); + if (empty($file)) { + $redir_data = File_redirection::where($long_url); + $file = File::saveNew($redir_data, $long_url); + $file_id = $file->id; + if (!empty($redir_data['oembed']['json'])) { + File_oembed::saveNew($redir_data['oembed']['json'], $file_id); + } + } else { + $file_id = $file->id; + } + $file_redir = File_redirection::staticGet('url', $short_url); + if (empty($file_redir)) { + $file_redir = new File_redirection; + $file_redir->url = $short_url; + $file_redir->file_id = $file_id; + $file_redir->insert(); + } } + return $short_url; + } + return $long_url; + } + + function _canonUrl($in_url, $default_scheme = 'http://') { + if (empty($in_url)) return false; + $out_url = $in_url; + $p = parse_url($out_url); + if (empty($p['host']) || empty($p['scheme'])) { + list($scheme) = explode(':', $in_url, 2); + switch ($scheme) { + case 'fax': + case 'tel': + $out_url = str_replace('.-()', '', $out_url); + break; + + case 'mailto': + case 'aim': + case 'jabber': + case 'xmpp': + // don't touch anything + break; + + default: + $out_url = $default_scheme . ltrim($out_url, '/'); + $p = parse_url($out_url); + if (empty($p['scheme'])) return false; + break; + } + } + + if (('ftp' == $p['scheme']) || ('http' == $p['scheme']) || ('https' == $p['scheme'])) { + if (empty($p['host'])) return false; + if (empty($p['path'])) { + $out_url .= '/'; + } + } + + return $out_url; + } + + function saveNew($data, $file_id, $url) { + $file_redir = new File_redirection; + $file_redir->url = $url; + $file_redir->file_id = $file_id; + $file_redir->redirections = intval($data['redirects']); + $file_redir->httpcode = intval($data['code']); + $file_redir->insert(); + } +} + diff --git a/classes/File_to_post.php b/classes/File_to_post.php index bd0528d98..00ddebe6b 100644 --- a/classes/File_to_post.php +++ b/classes/File_to_post.php @@ -40,4 +40,21 @@ class File_to_post extends Memcached_DataObject /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE + + function processNew($file_id, $notice_id) { + static $seen = array(); + if (empty($seen[$notice_id]) || !in_array($file_id, $seen[$notice_id])) { + $f2p = new File_to_post; + $f2p->file_id = $file_id; + $f2p->post_id = $notice_id; + $f2p->insert(); + if (empty($seen[$notice_id])) { + $seen[$notice_id] = array($file_id); + } else { + $seen[$notice_id][] = $file_id; + } + } + + } } + diff --git a/classes/Notice.php b/classes/Notice.php index 382d160ab..c2fa2d19e 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -124,7 +124,7 @@ class Notice extends Memcached_DataObject $profile = Profile::staticGet($profile_id); - $final = common_shorten_links($content); +// $final = common_shorten_links($content); if (!$profile) { common_log(LOG_ERR, 'Problem saving notice. Unknown user.'); @@ -167,8 +167,8 @@ class Notice extends Memcached_DataObject $notice->reply_to = $reply_to; $notice->created = common_sql_now(); - $notice->content = $final; - $notice->rendered = common_render_content($final, $notice); + $notice->content = $content; + $notice->rendered = common_render_content($content, $notice); $notice->source = $source; $notice->uri = $uri; diff --git a/classes/laconica.ini b/classes/laconica.ini index 00a1b8936..316923af0 100644 --- a/classes/laconica.ini +++ b/classes/laconica.ini @@ -1,67 +1,3 @@ - -[file] -id = 129 -url = 2 -mimetype = 2 -size = 1 -title = 2 -date = 1 -protected = 17 - -[file__keys] -id = K -url = U - -[file_oembed] -id = 129 -file_id = 1 -version = 2 -type = 2 -provider = 2 -provider_url = 2 -width = 1 -height = 1 -html = 66 -title = 2 -author_name = 2 -author_url = 2 -url = 2 - -[file_oembed__keys] -id = K -file_id = U - -[file_redirection] -id = 129 -url = 2 -file_id = 1 -redirections = 1 -httpcode = 1 - -[file_redirection__keys] -id = K -url = U - -[file_thumbnail] -id = 129 -file_id = 1 -url = 2 -width = 1 -height = 1 - -[file_thumbnail__keys] -id = K -file_id = U -url = U - -[file_to_post] -id = 129 -file_id = 1 -post_id = 1 - -[file_to_post__keys] -id = K - [avatar] profile_id = 129 original = 17 diff --git a/classes/laconica.links.ini b/classes/laconica.links.ini index bc52ce578..95c63f3c0 100644 --- a/classes/laconica.links.ini +++ b/classes/laconica.links.ini @@ -53,62 +53,5 @@ file_id = file:id [file_to_post] file_id = file:id -post_id = post:id - -[avatar] -profile_id = profile:id - -[user] -id = profile:id -carrier = sms_carrier:id - -[remote_profile] -id = profile:id - -[notice] -profile_id = profile:id -reply_to = notice:id - -[reply] -notice_id = notice:id -profile_id = profile:id - -[token] -consumer_key = consumer:consumer_key - -[nonce] -consumer_key,token = token:consumer_key,token - -[user_openid] -user_id = user:id - -[confirm_address] -user_id = user:id - -[remember_me] -user_id = user:id - -[queue_item] -notice_id = notice:id - -[subscription] -subscriber = profile:id -subscribed = profile:id - -[fave] -notice_id = notice:id -user_id = user:id - -[file_oembed] -file_id = file:id - -[file_redirection] -file_id = file:id - -[file_thumbnail] -file_id = file:id - -[file_to_post] -file_id = file:id -post_id = post:id +post_id = notice:id diff --git a/lib/Shorturl_api.php b/lib/Shorturl_api.php index fe106cb83..924aa93a8 100644 --- a/lib/Shorturl_api.php +++ b/lib/Shorturl_api.php @@ -22,6 +22,7 @@ if (!defined('LACONICA')) { exit(1); } class ShortUrlApi { protected $service_url; + protected $long_limit = 27; function __construct($service_url) { @@ -39,7 +40,7 @@ class ShortUrlApi } private function is_long($url) { - return strlen($url) >= 30; + return strlen($url) >= $this->long_limit; } protected function http_post($data) { diff --git a/lib/util.php b/lib/util.php index c4a63a441..25c0fb0a1 100644 --- a/lib/util.php +++ b/lib/util.php @@ -466,10 +466,10 @@ function common_replace_urls_callback($text, $callback, $notice_id = null) { $url = (mb_strpos($orig_url, htmlspecialchars($url)) === FALSE) ? $url:htmlspecialchars($url); // Call user specified func - if (isset($notice_id)) { - $modified_url = call_user_func($callback, array($url, $notice_id)); - } else { + if (empty($notice_id)) { $modified_url = call_user_func($callback, $url); + } else { + $modified_url = call_user_func($callback, array($url, $notice_id)); } // Replace it! @@ -485,107 +485,29 @@ function common_linkify($url) { // It comes in special'd, so we unspecial it before passing to the stringifying // functions $url = htmlspecialchars_decode($url); - $display = $url; - $url = (!preg_match('#^([a-z]+://|(mailto|aim|tel):)#i', $url)) ? 'http://'.$url : $url; - - $attrs = array('href' => $url, 'rel' => 'external'); + $display = File_redirection::_canonUrl($url); + $longurl_data = File_redirection::where($url); + if (is_array($longurl_data)) { + $longurl = $longurl_data['url']; + } elseif (is_string($longurl_data)) { + $longurl = $longurl_data; + } else { + die('impossible to linkify'); + } - if ($longurl = common_longurl($url)) { + $attrs = array('href' => $longurl, 'rel' => 'external'); +if(0){ + if ($longurl !== $url) { $attrs['title'] = $longurl; } - - return XMLStringer::estring('a', $attrs, $display); -} - -function common_longurl($short_url) -{ - $long_url = common_shorten_link($short_url, true); - if ($long_url === $short_url) return false; - return $long_url; } - -function common_longurl2($uri) -{ - $uri_e = urlencode($uri); - $longurl = unserialize(file_get_contents("http://api.longurl.org/v1/expand?format=php&url=$uri_e")); - if (empty($longurl['long_url']) || $uri === $longurl['long_url']) return false; - return stripslashes($longurl['long_url']); + return XMLStringer::estring('a', $attrs, $display); } function common_shorten_links($text) { if (mb_strlen($text) <= 140) return $text; - static $cache = array(); - if (isset($cache[$text])) return $cache[$text]; - // \s = not a horizontal whitespace character (since PHP 5.2.4) - return $cache[$text] = common_replace_urls_callback($text, 'common_shorten_link');; -} - -function common_shorten_link($url, $reverse = false) -{ - - static $url_cache = array(); - if ($reverse) return isset($url_cache[$url]) ? $url_cache[$url] : $url; - - $user = common_current_user(); - if (!isset($user)) { - // common current user does not find a user when called from the XMPP daemon - // therefore we'll set one here fix, so that XMPP given URLs may be shortened - $user->urlshorteningservice = 'ur1.ca'; - } - $curlh = curl_init(); - curl_setopt($curlh, CURLOPT_CONNECTTIMEOUT, 20); // # seconds to wait - curl_setopt($curlh, CURLOPT_USERAGENT, 'Laconica'); - curl_setopt($curlh, CURLOPT_RETURNTRANSFER, true); - - switch($user->urlshorteningservice) { - case 'ur1.ca': - $short_url_service = new LilUrl; - $short_url = $short_url_service->shorten($url); - break; - - case '2tu.us': - $short_url_service = new TightUrl; - $short_url = $short_url_service->shorten($url); - break; - - case 'ptiturl.com': - $short_url_service = new PtitUrl; - $short_url = $short_url_service->shorten($url); - break; - - case 'bit.ly': - curl_setopt($curlh, CURLOPT_URL, 'http://bit.ly/api?method=shorten&long_url='.urlencode($url)); - $short_url = current(json_decode(curl_exec($curlh))->results)->hashUrl; - break; - - case 'is.gd': - curl_setopt($curlh, CURLOPT_URL, 'http://is.gd/api.php?longurl='.urlencode($url)); - $short_url = curl_exec($curlh); - break; - case 'snipr.com': - curl_setopt($curlh, CURLOPT_URL, 'http://snipr.com/site/snip?r=simple&link='.urlencode($url)); - $short_url = curl_exec($curlh); - break; - case 'metamark.net': - curl_setopt($curlh, CURLOPT_URL, 'http://metamark.net/api/rest/simple?long_url='.urlencode($url)); - $short_url = curl_exec($curlh); - break; - case 'tinyurl.com': - curl_setopt($curlh, CURLOPT_URL, 'http://tinyurl.com/api-create.php?url='.urlencode($url)); - $short_url = curl_exec($curlh); - break; - default: - $short_url = false; - } - - curl_close($curlh); - - if ($short_url) { - $url_cache[(string)$short_url] = $url; - return (string)$short_url; - } - return $url; + return common_replace_urls_callback($text, array('File_redirection', 'makeShort')); } function common_xml_safe_str($str) -- cgit v1.2.3-54-g00ecf From 4a8c993ed01ed338bb94ba74a48982e0be8c64d1 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 14 May 2009 20:22:04 +0000 Subject: Updated instructions for creating a theme. Removed earthy theme ~ which was too basic to be unique. --- theme/earthy/css/base.css | 1188 ------------------------------- theme/earthy/css/display.css | 251 ------- theme/earthy/css/ie.css | 9 - theme/earthy/default-avatar-mini.png | Bin 646 -> 0 bytes theme/earthy/default-avatar-profile.png | Bin 2853 -> 0 bytes theme/earthy/default-avatar-stream.png | Bin 1487 -> 0 bytes theme/earthy/logo.png | Bin 4988 -> 0 bytes theme/readme.txt | 10 +- 8 files changed, 6 insertions(+), 1452 deletions(-) delete mode 100644 theme/earthy/css/base.css delete mode 100644 theme/earthy/css/display.css delete mode 100644 theme/earthy/css/ie.css delete mode 100644 theme/earthy/default-avatar-mini.png delete mode 100644 theme/earthy/default-avatar-profile.png delete mode 100644 theme/earthy/default-avatar-stream.png delete mode 100644 theme/earthy/logo.png diff --git a/theme/earthy/css/base.css b/theme/earthy/css/base.css deleted file mode 100644 index 6f46eef97..000000000 --- a/theme/earthy/css/base.css +++ /dev/null @@ -1,1188 +0,0 @@ -/** theme: earthy base - * - * @package Laconica - * @author Sarven Capadisli - * @copyright 2009 Control Yourself, Inc. - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://laconi.ca/ - */ - -* { margin:0; padding:0; } -img { display:block; border:0; } -a abbr { cursor: pointer; border-bottom:0; } -table { border-collapse:collapse; } -ol { list-style-position:inside; } -html { background-color:#fff; height:100%; } -body { -background-color:#fff; -color:#000; -font-family:sans-serif; -font-size:1em; -line-height:1.65; -position:relative; -} -h1,h2,h3,h4,h5,h6 { -margin-bottom:7px; -overflow:hidden; -} -h1 { -font-size:1.4em; -margin-bottom:18px; -text-align:right; -} -#showstream h1 { display:none; } -h2 { font-size:1.3em; } -h3 { font-size:1.2em; } -h4 { font-size:1.1em; } -h5 { font-size:1em; } -h6 { font-size:0.9em; } - -caption { -font-weight:bold; -} -legend { -font-weight:bold; -font-size:1.3em; -} -input, textarea, select, option { -padding:4px; -font-family:sans-serif; -font-size:1em; -} -input, textarea, select { -border-width:2px; -border-style: solid; -border-radius:4px; --moz-border-radius:4px; --webkit-border-radius:4px; -} - -input.submit { -font-weight:bold; -cursor:pointer; -} -textarea { -overflow:auto; -} -option { -padding-bottom:0; -} -fieldset { -padding:0; -border:0; -} -form ul li { -list-style-type:none; -margin:0 0 18px 0; -} -form label { -font-weight:bold; -} -input.checkbox { -position:relative; -top:2px; -left:0; -border:0; -} - -.error, -.success { -padding:4px 7px; -border-radius:4px; --moz-border-radius:4px; --webkit-border-radius:4px; -margin-bottom:18px; -} -form label.submit { -display:none; -} - -.form_settings { -clear:both; -} - -.form_settings fieldset { -margin-bottom:29px; -} -.form_settings input.remove { -margin-left:11px; -} -.form_settings .form_data li { -width:100%; -float:left; -} -.form_settings .form_data label { -float:left; -} -.form_settings .form_data textarea, -.form_settings .form_data select, -.form_settings .form_data input { -margin-left:11px; -float:left; -} -.form_settings .form_data input.submit { -margin-left:0; -} - -.form_settings label { -margin-top:2px; -width:152px; -} - -.form_actions label { -display:none; -} -.form_guide { -font-style:italic; -} - -.form_settings #settings_autosubscribe label { -display:inline; -font-weight:bold; -} - -#form_settings_profile legend, -#form_login legend, -#form_register legend, -#form_password legend, -#form_settings_avatar legend, -#newgroup legend, -#editgroup legend, -#form_tag_user legend, -#form_remote_subscribe legend, -#form_openid_login legend, -#form_search legend, -#form_invite legend, -#form_notice_delete legend, -#form_password_recover legend, -#form_password_change legend { -display:none; -} - -.form_settings .form_data p.form_guide { -clear:both; -margin-left:163px; -margin-bottom:0; -} - -.form_settings p { -margin-bottom:11px; -} - -.form_settings input.checkbox { -margin-top:3px; -margin-left:0; -} -.form_settings label.checkbox { -font-weight:normal; -margin-top:0; -margin-right:0; -margin-left:11px; -float:left; -width:90%; -} - - -#form_login p.form_guide, -#form_register #settings_rememberme p.form_guide, -#form_openid_login #settings_rememberme p.form_guide, -#settings_twitter_remove p.form_guide, -#form_search ul.form_data #q { -margin-left:0; -} - -.form_settings .form_note { -border-radius:4px; --moz-border-radius:4px; --webkit-border-radius:4px; -padding:0 7px; -} - - -.form_settings input.form_action-secondary { -margin-left:29px; -padding:0; -} - -#form_search .submit { -margin-left:11px; -} - -address { -float:left; -margin-bottom:18px; -margin-left:18px; -} -address.vcard img.logo { -margin-right:0; -} -address .fn { -font-weight:bold; -} -address img + .fn { -display:none; -} - -#header { -width:100%; -position:relative; -float:left; -padding-top:18px; -margin-bottom:29px; -} - -#site_nav_global_primary { -float:right; -margin-right:18px; -margin-bottom:11px; -margin-left:18px; -} -#site_nav_global_primary ul li { -display:inline; -margin-left:11px; -} - -.system_notice dt { -font-weight:bold; -text-transform:uppercase; -display:none; -} - -#site_notice { -position:absolute; -top:65px; -right:18px; -width:250px; -width:24%; -} -#page_notice { -clear:both; -margin-bottom:18px; -} - - -#anon_notice { -float:left; -width:43.2%; -padding:1.1%; -border-radius:7px; --moz-border-radius:7px; --webkit-border-radius:7px; -border-width:2px; -border-style:solid; -line-height:1.5; -font-size:1.1em; -font-weight:bold; -} - - -#footer { -float:left; -width:64%; -padding:18px; -} - -#site_nav_local_views { -float:right; -} -#site_nav_local_views dt { -display:none; -} -#site_nav_local_views li { -float:right; -margin-left:11px; -list-style-type:none; -} -#site_nav_local_views a { -float:left; -text-decoration:none; -padding:4px 11px; --moz-border-radius-topleft:4px; --moz-border-radius-topright:4px; --webkit-border-top-left-radius:4px; --webkit-border-top-right-radius:4px; -border-width:1px; -border-style:solid; -border-bottom:0; -text-shadow: 2px 2px 2px #ddd; -font-weight:bold; -} -#site_nav_local_views .nav { -float:left; -width:100%; -border-bottom-width:1px; -border-bottom-style:solid; -} - -#site_nav_global_primary dt, -#site_nav_global_secondary dt { -display:none; -} - -#site_nav_global_secondary { -margin-bottom:11px; -} - -#site_nav_global_secondary ul li { -display:inline; -margin-right:11px; -} -#export_data li a { -padding-left:20px; -} -#export_data li a.foaf { -padding-left:30px; -} -#export_data li a.export_vcard { -padding-left:28px; -} - -#export_data ul { -display:inline; -} -#export_data li { -list-style-type:none; -display:inline; -margin-left:11px; -} -#export_data li:first-child { -margin-left:0; -} - -#licenses { -font-size:0.9em; -} - -#licenses dt { -font-weight:bold; -display:none; -} -#licenses dd { -margin-bottom:11px; -line-height:1.5; -} - -#site_content_license_cc { -margin-bottom:0; -} -#site_content_license_cc img { -display:inline; -vertical-align:top; -margin-right:4px; -} - -#wrap { -margin:0 auto; -width:100%; -min-width:760px; -max-width:1003px; -overflow:hidden; -} - -#core { -position:relative; -width:100%; -float:left; -margin-bottom:1em; -} - -#content { -width:63.009%; -min-height:259px; -padding-top:1.795%; -padding-bottom:1.795%; -float:right; -clear:both; -border-radius:7px; -border-style:solid; -border-width:0; -} - -#content_inner { -position:relative; -width:100%; -float:left; -} - -#aside_primary { -width:27.917%; -min-height:259px; -float:right; -margin-right:4.385%; -margin-top:73px; -padding:1.795%; -border-radius:7px; --moz-border-radius:7px; --webkit-border-radius:7px; -border-width:1px; -border-style:solid; -} - -#form_notice { -width:45.664%; -float:left; -position:relative; -line-height:1; -} -#form_notice fieldset { -border:0; -padding:0; -} -#form_notice legend { -display:none; -} -#form_notice textarea { -float:left; -border-radius:7px; --moz-border-radius:7px; --webkit-border-radius:7px; -width:80.789%; -height:67px; -line-height:1.5; -padding:7px 7px 16px 7px; -} -#form_notice label { -display:block; -float:left; -font-size:1.3em; -margin-bottom:7px; -} -#form_notice #notice_submit label { -display:none; -} -#form_notice .form_note { -position:absolute; -top:99px; -right:98px; -z-index:9; -} -#form_notice .form_note dt { -font-weight:bold; -display:none; -} -#notice_text-count { -font-weight:bold; -line-height:1.15; -padding:1px 2px; -} -#form_notice #notice_action-submit { -width:14%; -height:47px; -padding:0; -position:absolute; -bottom:0; -right:0; -} -#form_notice label[for=to] { -margin-top:7px; -} -#form_notice select[id=to] { -margin-bottom:7px; -margin-left:18px; -float:left; -} - - -/* entity_profile */ -.entity_profile { -position:relative; -width:67.702%; -min-height:123px; -float:left; -margin-bottom:18px; -margin-left:0; -overflow:hidden; -} -.entity_profile dt, -#entity_statistics dt { -font-weight:bold; -} -.entity_profile dd { -display:inline; -} - -.entity_profile .entity_depiction { -float:left; -width:96px; -margin-right:18px; -margin-bottom:18px; -} - -.entity_profile .entity_fn, -.entity_profile .entity_nickname, -.entity_profile .entity_location, -.entity_profile .entity_url, -.entity_profile .entity_note, -.entity_profile .entity_tags { -margin-left:113px; -margin-bottom:4px; -} - -.entity_profile .entity_fn, -.entity_profile .entity_nickname { -margin-left:11px; -display:inline; -font-weight:bold; -} -.entity_profile .entity_nickname { -margin-left:0; -} - -.entity_profile .entity_fn dd:before { -content: "("; -font-weight:normal; -} -.entity_profile .entity_fn dd:after { -content: ")"; -font-weight:normal; -} - -.entity_profile dt { -display:none; -} -.entity_profile h2 { -display:none; -} -/* entity_profile */ - - -/*entity_actions*/ -.entity_actions { -float:right; -margin-left:4.35%; -max-width:25%; -} -.entity_actions h2 { -display:none; -} -.entity_actions ul { -list-style-type:none; -} -.entity_actions li { -margin-bottom:4px; -} -.entity_actions li:first-child { -border-top:0; -} -.entity_actions fieldset { -border:0; -padding:0; -} -.entity_actions legend { -display:none; -} - -.entity_actions input.submit { -display:block; -text-align:left; -width:100%; -} -.entity_actions a, -.entity_nudge p, -.entity_remote_subscribe { -text-decoration:none; -font-weight:bold; -display:block; -} - -.form_user_block input.submit, -.form_user_unblock input.submit, -.entity_send-a-message a, -.entity_edit a, -.form_user_nudge input.submit, -.entity_nudge p { -border:0; -padding-left:20px; -} - -.entity_edit a, -.entity_send-a-message a, -.entity_nudge p { -padding:4px 4px 4px 23px; -} - -.entity_remote_subscribe { -padding:4px; -border-width:2px; -border-style:solid; -border-radius:4px; --moz-border-radius:4px; --webkit-border-radius:4px; -} -.entity_actions .accept { -margin-bottom:18px; -} - -.entity_tags ul { -list-style-type:none; -display:inline; -} -.entity_tags li { -display:inline; -margin-right:4px; -} - -.aside .section { -margin-bottom:29px; -clear:both; -float:left; -width:100%; -} -.aside .section h2 { -text-transform:uppercase; -font-size:1em; -} - -#entity_statistics dt, -#entity_statistics dd { -display:inline; -} -#entity_statistics dt:after { -content: ":"; -} - -.section ul.entities { -float:left; -width:100%; -} -.section .entities li { -list-style-type:none; -float:left; -margin-right:7px; -margin-bottom:7px; -} -.section .entities li .photo { -margin-right:0; -margin-bottom:0; -} -.section .entities li .fn { -display:none; -} - -.aside .section p, -.aside .section .more { -clear:both; -} - -.profile .entity_profile { -margin-bottom:0; -min-height:60px; -} - - -.profile .form_group_join legend, -.profile .form_group_leave legend, -.profile .form_user_subscribe legend, -.profile .form_user_unsubscribe legend { -display:none; -} - -.profiles { -list-style-type:none; -} -.profile .entity_profile .entity_location { -width:auto; -clear:none; -margin-left:11px; -} -.profile .entity_profile dl, -.profile .entity_profile dd { -display:inline; -float:none; -} -.profile .entity_profile .entity_note, -.profile .entity_profile .entity_url, -.profile .entity_profile .entity_tags, -.profile .entity_profile .form_subscription_edit { -margin-left:59px; -clear:none; -display:block; -width:auto; -} -.profile .entity_profile .entity_tags dt { -display:inline; -margin-right:11px; -} - - -.profile .entity_profile .form_subscription_edit label { -font-weight:normal; -margin-right:11px; -} - - -/* NOTICE */ -.notice, -.profile { -position:relative; -clear:both; -float:left; -width:100%; -border-width:1px; -border-style:solid; -border-radius:7px; --moz-border-radius:7px; --webkit-border-radius:7px; -} -#content .notice, -#content .profile { -padding:1.795%; -margin-bottom:44px; -} -#content .notice { -width:96.25%; -} - -.notices li { -list-style-type:none; -} -.notices li.hover { -border-radius:4px; --moz-border-radius:4px; --webkit-border-radius:4px; -} - -/* NOTICES */ -#notices_primary { -float:left; -width:100%; -border-radius:7px; --moz-border-radius:7px; --webkit-border-radius:7px; -} -#notices_primary h2 { -display:none; -} -.notice-data a span { -display:block; -padding-left:28px; -} - -.notice .author { -margin-right:11px; -} - -.fn { -overflow:hidden; -} - -.notice .author .fn { -font-weight:bold; -} - -.notice .author .photo { -margin-bottom:0; -} - -.vcard .photo { -display:inline; -margin-right:11px; -margin-bottom:11px; -float:left; -} -.vcard .url { -text-decoration:none; -} -.vcard .url:hover { -text-decoration:underline; -} - -.notice .entry-title { -float:left; -width:100%; -overflow:hidden; -} -#shownotice .notice .entry-title { -font-size:2.2em; -} - -.notice p.entry-content { -display:inline; -} - -#content .notice p.entry-content a:visited { -border-radius:4px; --moz-border-radius:4px; --webkit-border-radius:4px; -} -.notice p.entry-content .vcard a { -border-radius:4px; --moz-border-radius:4px; --webkit-border-radius:4px; -} - -.notice div.entry-content { -clear:left; -float:left; -font-size:0.95em; -margin-left:59px; -width:70%; -} -#showstream .notice div.entry-content { -margin-left:0; -} - -.notice .notice-options a, -.notice .notice-options input { -float:left; -font-size:1.025em; -} - -.notice div.entry-content dl, -.notice div.entry-content dt, -.notice div.entry-content dd { -display:inline; -} - -.notice div.entry-content .timestamp dt, -.notice div.entry-content .response dt { -display:none; -} -.notice div.entry-content .timestamp a { -display:inline-block; -} -.notice div.entry-content .device dt { -text-transform:lowercase; -} - - - -.notice-data { -position:absolute; -top:18px; -right:0; -min-height:50px; -margin-bottom:4px; -} -.notice .entry-content .notice-data dt { -display:none; -} - -.notice-data a { -display:block; -outline:none; -} - -.notice-options { -padding-left:2%; -float:left; -width:50%; -position:relative; -font-size:0.95em; -width:12.5%; -float:right; -} - -.notice-options a { -float:left; -} -.notice-options .notice_delete, -.notice-options .notice_reply, -.notice-options .form_favor, -.notice-options .form_disfavor { -position:absolute; -top:0; -} -.notice-options .form_favor, -.notice-options .form_disfavor { -left:0; -} -.notice-options .notice_reply { -left:29px; -} -.notice-options .notice_delete { -right:0; -} -.notice-options .notice_reply dt { -display:none; -} - -.notice-options input, -.notice-options a { -text-indent:-9999px; -outline:none; -} - -.notice-options .notice_reply a, -.notice-options input.submit { -display:block; -border:0; -} -.notice-options .notice_reply a, -.notice-options .notice_delete a { -text-decoration:none; -padding-left:16px; -} - -.notice-options form input.submit { -width:16px; -padding:2px 0; -} - -.notice-options .notice_delete dt, -.notice-options .form_favor legend, -.notice-options .form_disfavor legend { -display:none; -} -.notice-options .notice_delete fieldset, -.notice-options .form_favor fieldset, -.notice-options .form_disfavor fieldset { -border:0; -padding:0; -} - - -#usergroups #new_group { -float: left; -margin-right: 2em; -} -#new_group, #group_search { -margin-bottom:18px; -} -#new_group a { -padding-left:20px; -} - - -#filter_tags { -margin-bottom:11px; -float:left; -} -#filter_tags dt { -display:none; -} -#filter_tags ul { -list-style-type:none; -} -#filter_tags ul li { -float:left; -margin-left:7px; -padding-left:7px; -border-left-width:1px; -border-left-style:solid; -} -#filter_tags ul li.child_1 { -margin-left:0; -border-left:0; -padding-left:0; -} -#filter_tags ul li#filter_tags_all a { -font-weight:bold; -margin-top:7px; -float:left; -} - -#filter_tags ul li#filter_tags_item label { -margin-right:7px; -} -#filter_tags ul li#filter_tags_item label, -#filter_tags ul li#filter_tags_item select { -display:inline; -} -#filter_tags ul li#filter_tags_item p { -float:left; -margin-left:38px; -} -#filter_tags ul li#filter_tags_item input { -position:relative; -top:3px; -left:3px; -} - - - -.pagination { -float:left; -clear:both; -width:100%; -margin-top:18px; -} - -.pagination dt { -font-weight:bold; -display:none; -} - -.pagination .nav { -float:left; -width:100%; -list-style-type:none; -} - -.pagination .nav_prev { -float:left; -} -.pagination .nav_next { -float:right; -} - -.pagination a { -display:block; -text-decoration:none; -font-weight:bold; -padding:7px; -border-width:1px; -border-style:solid; --moz-border-radius:7px; --webkit-border-radius:7px; -border-radius:7px; -} - -.pagination .nav_prev a { -padding-left:30px; -} -.pagination .nav_next a { -padding-right:30px; -} -/* END: NOTICE */ - - -.hentry .entry-content p { -margin-bottom:18px; -} -.hentry entry-content ol, -.hentry .entry-content ul { -list-style-position:inside; -} -.hentry .entry-content li { -margin-bottom:18px; -} -.hentry .entry-content li li { -margin-left:18px; -} - - - - -/* TOP_POSTERS */ -.section tbody td { -padding-right:11px; -padding-bottom:11px; -} -.section .vcard .photo { -margin-right:7px; -margin-bottom:0; -} - -.section .notice { -padding-top:7px; -padding-bottom:7px; -border-top:0; -} - -.section .notice:first-child { -padding-top:0; -} - -.section .notice .author { -margin-right:0; -} -.section .notice .author .fn { -display:none; -} - - -/* tagcloud */ -.tag-cloud { -list-style-type:none; -text-align:center; -} -.aside .tag-cloud { -font-size:0.8em; -} -.tag-cloud li { -display:inline; -margin-right:7px; -line-height:1.25; -} -.aside .tag-cloud li { -line-height:1.5; -} -.tag-cloud li a { -text-decoration:none; -} -#tagcloud.section dt { -text-transform:uppercase; -font-weight:bold; -} -.tag-cloud-1 { -font-size:1em; -} -.tag-cloud-2 { -font-size:1.25em; -} -.tag-cloud-3 { -font-size:1.75em; -} -.tag-cloud-4 { -font-size:2em; -} -.tag-cloud-5 { -font-size:2.25em; -} -.tag-cloud-6 { -font-size:2.75em; -} -.tag-cloud-7 { -font-size:3.25em; -} - -#publictagcloud #tagcloud.section dt { -display:none; -} - -#form_settings_photo .form_data { -clear:both; -} - -#form_settings_avatar li { -width:auto; -} -#form_settings_avatar input { -margin-left:0; -} -#avatar_original, -#avatar_preview { -float:left; -} -#avatar_preview { -margin-left:29px; -} -#avatar_preview_view { -height:96px; -width:96px; -margin-bottom:18px; -overflow:hidden; -} - -#settings_attach, -#form_settings_avatar .form_actions { -clear:both; -} - -#form_settings_avatar .form_actions { -margin-bottom:0; -} - -#form_settings_design #settings_design_color .form_data, -#form_settings_design #color-picker { -float:left; -} -#form_settings_design #settings_design_color .form_data { -width:400px; -margin-right:28px; -} - -.instructions ul { -list-style-position:inside; -} -.instructions p, -.instructions ul { -margin-bottom:18px; -} -.help dt { -display:none; -} -.guide { -clear:both; -} diff --git a/theme/earthy/css/display.css b/theme/earthy/css/display.css deleted file mode 100644 index b67700f2d..000000000 --- a/theme/earthy/css/display.css +++ /dev/null @@ -1,251 +0,0 @@ -/** theme: earthy - * - * @package Laconica - * @author Sarven Capadisli - * @copyright 2009 Control Yourself, Inc. - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://laconi.ca/ - */ - -@import url(base.css); - -html, -body, -a:active { -background-color:#665500; -} -body { -font-family: Verdana, sans-serif; -font-size:1em; -} -address { -margin-right:7.18%; -} - -h1 { -color:#fff; -} - -input, textarea, select, option { -font-family: Verdana, sans-serif; -} -input, textarea, select, -.entity_remote_subscribe { -border-color:#aaa; -} -#filter_tags ul li { -border-color:#ddd; -} - -.form_settings input.form_action-secondary { -background:none; -} - -input.submit, -#form_notice.warning #notice_text-count, -.form_settings .form_note, -.entity_remote_subscribe { -background-color:#9BB43E; -} - -input:focus, textarea:focus, select:focus, -#form_notice.warning #notice_data-text { -border-color:#9BB43E; -} -input.submit, -.entity_remote_subscribe { -color:#dddd33; -} - -a, -div.notice-options input, -.form_user_block input.submit, -.form_user_unblock input.submit, -.entity_send-a-message a, -.form_user_nudge input.submit, -.entity_nudge p, -.form_settings input.form_action-secondary { -color:#ee4400; -} - -.notice, -.profile { -border-color:#DDAA00; -} -.section .profile { -border-top-color:#aaaa66; -} - -#content .notice p.entry-content a:visited { -background-color:#fcfcfc; -} -#content .notice p.entry-content .vcard a { -background-color:#fcfffc; -} - -#aside_primary { -background-color:#DDAA00; -} - -#notice_text-count { -color:#333; -} -#form_notice.warning #notice_text-count { -color:#000; -} -#form_notice.processing #notice_action-submit { -background:#dddd33 url(../../base/images/icons/icon_processing.gif) no-repeat 47% 47%; -cursor:wait; -text-indent:-9999px; -} - -#content, -#site_nav_local_views .nav, -#site_nav_local_views a, -#aside_primary { -border-color:#dddd33; -} -#content .notice, -#content .profile, -#site_nav_local_views .current a { -background-color:#dddd33; -} -#site_nav_local_views .current a { -color:#EE4400; -} -#site_nav_local_views a { -background-color:rgba(255, 255, 255, 0.2); -color:#fff; -} -#site_nav_local_views a:hover { -background-color:rgba(255, 255, 255, 0.4); -} - -.error { -background-color:#F7E8E8; -} -.success { -background-color:#EFF3DC; -} - -#anon_notice { -background-color:#aaaa66; -color:#dddd33; -border-color:#dddd33; -} - -#showstream #anon_notice { -background-color:#9BB43E; -} - -#export_data li a { -background-repeat:no-repeat; -background-position:0 45%; -} -#export_data li a.rss { -background-image:url(../../base/images/icons/icon_rss.png); -} -#export_data li a.atom { -background-image:url(../../base/images/icons/icon_atom.png); -} -#export_data li a.foaf { -background-image:url(../../base/images/icons/icon_foaf.gif); -} - -.entity_edit a, -.entity_send-a-message a, -.form_user_nudge input.submit, -.form_user_block input.submit, -.form_user_unblock input.submit, -.entity_nudge p { -background-position: 0 40%; -background-repeat: no-repeat; -background-color:transparent; -} -.form_group_join input.submit, -.form_group_leave input.submit -.form_user_subscribe input.submit, -.form_user_unsubscribe input.submit { -background-color:#9BB43E; -color:#dddd33; -} -.form_user_unsubscribe input.submit, -.form_group_leave input.submit, -.form_user_authorization input.reject { -background-color:#aaaa66; -} - -.entity_edit a { -background-image:url(../../base/images/icons/twotone/green/edit.gif); -} -.entity_send-a-message a { -background-image:url(../../base/images/icons/twotone/green/quote.gif); -} -.entity_nudge p, -.form_user_nudge input.submit { -background-image:url(../../base/images/icons/twotone/green/mail.gif); -} -.form_user_block input.submit, -.form_user_unblock input.submit { -background-image:url(../../base/images/icons/twotone/green/shield.gif); -} - -/* NOTICES */ -.notices li.over { -background-color:#fcfcfc; -} - -.notice-options .notice_reply a, -.notice-options form input.submit { -background-color:transparent; -} -.notice-options .notice_reply a { -background:transparent url(../../base/images/icons/twotone/green/reply.gif) no-repeat 0 45%; -} -.notice-options form.form_favor input.submit { -background:transparent url(../../base/images/icons/twotone/green/favourite.gif) no-repeat 0 45%; -} -.notice-options form.form_disfavor input.submit { -background:transparent url(../../base/images/icons/twotone/green/disfavourite.gif) no-repeat 0 45%; -} -.notice-options .notice_delete a { -background:transparent url(../../base/images/icons/twotone/green/trash.gif) no-repeat 0 45%; -} - -.notices div.entry-content, -.notices div.notice-options { -opacity:0.4; -} -.notices li.hover div.entry-content, -.notices li.hover div.notice-options { -opacity:1; -} -div.entry-content { -color:#333; -} -div.notice-options a, -div.notice-options input { -font-family:sans-serif; -} -.notices li.hover { -/*background-color:#fcfcfc;*/ -} -/*END: NOTICES */ - -#new_group a { -background:transparent url(../../base/images/icons/twotone/green/news.gif) no-repeat 0 45%; -} - -.pagination .nav_prev a, -.pagination .nav_next a { -background-repeat:no-repeat; -border-color:#DDAA00; -} -.pagination .nav_prev a { -background-image:url(../../base/images/icons/twotone/green/arrow-left.gif); -background-position:10% 45%; -} -.pagination .nav_next a { -background-image:url(../../base/images/icons/twotone/green/arrow-right.gif); -background-position:90% 45%; -} diff --git a/theme/earthy/css/ie.css b/theme/earthy/css/ie.css deleted file mode 100644 index 2f463bb44..000000000 --- a/theme/earthy/css/ie.css +++ /dev/null @@ -1,9 +0,0 @@ -/* IE specific styles */ - -.notice-options input.submit { -color:#fff; -} - -#site_nav_local_views a { -background-color:#D0DFE7; -} diff --git a/theme/earthy/default-avatar-mini.png b/theme/earthy/default-avatar-mini.png deleted file mode 100644 index 38b8692b4..000000000 Binary files a/theme/earthy/default-avatar-mini.png and /dev/null differ diff --git a/theme/earthy/default-avatar-profile.png b/theme/earthy/default-avatar-profile.png deleted file mode 100644 index f8357d4fc..000000000 Binary files a/theme/earthy/default-avatar-profile.png and /dev/null differ diff --git a/theme/earthy/default-avatar-stream.png b/theme/earthy/default-avatar-stream.png deleted file mode 100644 index 6b63baa70..000000000 Binary files a/theme/earthy/default-avatar-stream.png and /dev/null differ diff --git a/theme/earthy/logo.png b/theme/earthy/logo.png deleted file mode 100644 index 7c68b34f6..000000000 Binary files a/theme/earthy/logo.png and /dev/null differ diff --git a/theme/readme.txt b/theme/readme.txt index 4998b3c98..83b5a61d0 100644 --- a/theme/readme.txt +++ b/theme/readme.txt @@ -23,14 +23,16 @@ Only alter this file if you want to change the layout of the site. Please note t ./default/css/display.css contains only the background images and colour rules: This file is a good basis for creating your own theme. +Let's create a theme: -1. Copy over the default theme to start off (replace 'mytheme'): -cp -r ./default ./mytheme +1. To start off, copy over the default theme: +cp -r default mytheme 2. Edit your mytheme stylesheet: -nano ./mytheme/css/display.css +nano mytheme/css/display.css -3. Search and replace a colour or a path to the background image of your choice. +a) Search and replace your colours and background images, or +b) Create your own layout either importing a separate stylesheet (e.g., change to @import url(base.css);) or simply place it before the rest of the rules. 4. Set /config.php to load 'mytheme': $config['site']['theme'] = 'mytheme'; -- cgit v1.2.3-54-g00ecf From af5e0dab694c20840f397c2f6897c9d2565f3016 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 14 May 2009 20:27:08 +0000 Subject: Updated logos to use laconica as default. --- theme/biz/logo.png | Bin 4988 -> 2228 bytes theme/cloudy/logo.png | Bin 4988 -> 2228 bytes theme/h4ck3r/logo.png | Bin 4988 -> 2228 bytes theme/otalk/logo.png | Bin 4988 -> 2228 bytes theme/pigeonthoughts/logo.png | Bin 4988 -> 2228 bytes 5 files changed, 0 insertions(+), 0 deletions(-) diff --git a/theme/biz/logo.png b/theme/biz/logo.png index 7c68b34f6..fdead6c4a 100644 Binary files a/theme/biz/logo.png and b/theme/biz/logo.png differ diff --git a/theme/cloudy/logo.png b/theme/cloudy/logo.png index 7c68b34f6..fdead6c4a 100644 Binary files a/theme/cloudy/logo.png and b/theme/cloudy/logo.png differ diff --git a/theme/h4ck3r/logo.png b/theme/h4ck3r/logo.png index 7c68b34f6..fdead6c4a 100644 Binary files a/theme/h4ck3r/logo.png and b/theme/h4ck3r/logo.png differ diff --git a/theme/otalk/logo.png b/theme/otalk/logo.png index 7c68b34f6..fdead6c4a 100644 Binary files a/theme/otalk/logo.png and b/theme/otalk/logo.png differ diff --git a/theme/pigeonthoughts/logo.png b/theme/pigeonthoughts/logo.png index 7c68b34f6..fdead6c4a 100644 Binary files a/theme/pigeonthoughts/logo.png and b/theme/pigeonthoughts/logo.png differ -- cgit v1.2.3-54-g00ecf From fbb0d1dd54bb1455c25eabfa333f599d5e494f00 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 14 May 2009 23:43:41 +0000 Subject: Updated Cloudy theme default avatars and minor CSS --- theme/cloudy/css/display.css | 4 ++-- theme/cloudy/default-avatar-mini.png | Bin 1006 -> 1349 bytes theme/cloudy/default-avatar-profile.png | Bin 9026 -> 9256 bytes theme/cloudy/default-avatar-stream.png | Bin 2963 -> 3829 bytes 4 files changed, 2 insertions(+), 2 deletions(-) diff --git a/theme/cloudy/css/display.css b/theme/cloudy/css/display.css index b87722eec..e97889685 100644 --- a/theme/cloudy/css/display.css +++ b/theme/cloudy/css/display.css @@ -12,7 +12,7 @@ img { display:block; border:0; } a abbr { cursor: pointer; border-bottom:0; } table { border-collapse:collapse; } ol { list-style-position:inside; } -html { font-size: 100%; background-color:#fff; height:100%; } +html { font-size: 100%; background-color:#fff; } body { background-color:#fff; color:#000; @@ -126,7 +126,7 @@ margin-left:0; .form_settings label { margin-top:2px; -width:145px; +width:143px; } .form_actions label { diff --git a/theme/cloudy/default-avatar-mini.png b/theme/cloudy/default-avatar-mini.png index c0f1d411f..4fd8bd9e1 100644 Binary files a/theme/cloudy/default-avatar-mini.png and b/theme/cloudy/default-avatar-mini.png differ diff --git a/theme/cloudy/default-avatar-profile.png b/theme/cloudy/default-avatar-profile.png index 9f281f94f..eb08571d9 100644 Binary files a/theme/cloudy/default-avatar-profile.png and b/theme/cloudy/default-avatar-profile.png differ diff --git a/theme/cloudy/default-avatar-stream.png b/theme/cloudy/default-avatar-stream.png index 8d505871c..926b8a9ca 100644 Binary files a/theme/cloudy/default-avatar-stream.png and b/theme/cloudy/default-avatar-stream.png differ -- cgit v1.2.3-54-g00ecf From 4ac7a4054e31241813404cdfdf2cb5e8cf97b4f1 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 15 May 2009 13:55:49 -0400 Subject: conversation tree interface --- actions/conversation.php | 96 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 2 deletions(-) diff --git a/actions/conversation.php b/actions/conversation.php index 05cfb76e3..f3beade6c 100644 --- a/actions/conversation.php +++ b/actions/conversation.php @@ -42,6 +42,7 @@ require_once(INSTALLDIR.'/lib/noticelist.php'); * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 * @link http://laconi.ca/ */ + class ConversationAction extends Action { var $id = null; @@ -95,9 +96,9 @@ class ConversationAction extends Action 'notice:conversation:'.$this->id, $offset, $limit); - $nl = new NoticeList($notices, $this); + $ct = new ConversationTree($notices, $this); - $cnt = $nl->show(); + $cnt = $ct->show(); $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE, $this->page, 'conversation', array('id' => $this->id)); @@ -105,3 +106,94 @@ class ConversationAction extends Action } +class ConversationTree extends NoticeList +{ + var $tree = null; + var $table = null; + + function show() + { + $cnt = 0; + + $this->tree = array(); + $table = array(); + + while ($this->notice->fetch()) { + $cnt++; + $this->table[$this->notice->id] = clone($this->notice); + if (is_null($notice->reply_to)) { + // We assume no notice has -1 ID + $this->tree[-1] = array($notice->id); + } else if (array_key_exists($notice->reply_to, $this->tree)) { + $this->tree[$notice->reply_to][] = $notice->id; + } else { + $this->tree[$notice->reply_to] = array($notice->id); + } + } + + $this->out->elementStart('div', array('id' =>'notices_primary')); + $this->out->element('h2', null, _('Notices')); + $this->out->elementStart('ul', array('class' => 'notices')); + + if (array_key_exists(-1, $this->tree)) { + $this->showNoticePlus($this->tree[-1][0]); + } + + $this->out->elementEnd('ul'); + $this->out->elementEnd('div'); + + return $cnt; + } + + function showNoticePlus($id) + { + $notice = $this->table[$id]; + + print_r($notice); + + // We take responsibility for doing the li + + $this->out->elementStart('li', array('class' => 'hentry notice', + 'id' => 'notice-' . $this->notice->id)); + + $item = $this->newListItem($notice); + $item->show(); + + if (array_key_exists($id, $this->tree)) { + $children = $this->tree[$id]; + + $this->out->elementStart('ul', array('class' => 'notices')); + + foreach ($children as $child) { + $this->showNoticePlus($child); + } + + $this->out->elementEnd('ul'); + } + + $this->out->elementEnd('li'); + } + + function newListItem($notice) + { + return new ConversationTreeItem($notice, $this->out); + } +} + +class ConversationTreeItem extends NoticeListItem +{ + function showStart() + { + // skip; ConversationTree draws the list + } + + function showEnd() + { + // skip; ConversationTree draws the list + } + + function showContext() + { + // skip; this _is_ the context! + } +} \ No newline at end of file -- cgit v1.2.3-54-g00ecf From c6816c163e813ac4bc8163cba7ab08c54d8320d5 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 15 May 2009 14:18:04 -0400 Subject: reformat action.php --- lib/action.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/action.php b/lib/action.php index 2ec9329e0..4bd41c226 100644 --- a/lib/action.php +++ b/lib/action.php @@ -98,15 +98,15 @@ class Action extends HTMLOutputter // lawsuit Event::handle('EndShowHTML', array($this)); } if (Event::handle('StartShowHead', array($this))) { - $this->showHead(); + $this->showHead(); Event::handle('EndShowHead', array($this)); } if (Event::handle('StartShowBody', array($this))) { - $this->showBody(); + $this->showBody(); Event::handle('EndShowBody', array($this)); } if (Event::handle('StartEndHTML', array($this))) { - $this->endHTML(); + $this->endHTML(); Event::handle('EndEndHTML', array($this)); } } @@ -347,7 +347,7 @@ class Action extends HTMLOutputter // lawsuit { $this->elementStart('body', (common_current_user()) ? array('id' => $this->trimmed('action'), 'class' => 'user_in') - : array('id' => $this->trimmed('action'))); + : array('id' => $this->trimmed('action'))); $this->elementStart('div', array('id' => 'wrap')); if (Event::handle('StartShowHeader', array($this))) { $this->showHeader(); @@ -431,10 +431,10 @@ class Action extends HTMLOutputter // lawsuit _('Connect'), _('Connect to SMS, Twitter'), false, 'nav_connect'); } $this->menuItem(common_local_url('invite'), - _('Invite'), - sprintf(_('Invite friends and colleagues to join you on %s'), - common_config('site', 'name')), - false, 'nav_invitecontact'); + _('Invite'), + sprintf(_('Invite friends and colleagues to join you on %s'), + common_config('site', 'name')), + false, 'nav_invitecontact'); $this->menuItem(common_local_url('logout'), _('Logout'), _('Logout from the site'), false, 'nav_logout'); } @@ -629,7 +629,7 @@ class Action extends HTMLOutputter // lawsuit $this->elementStart('div', array('id' => 'aside_primary', 'class' => 'aside')); if (Event::handle('StartShowExportData', array($this))) { - $this->showExportData(); + $this->showExportData(); Event::handle('EndShowExportData', array($this)); } if (Event::handle('StartShowSections', array($this))) { -- cgit v1.2.3-54-g00ecf From 14662354dc501e811dd714aa72fd8001842ee672 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 15 May 2009 14:22:49 -0400 Subject: add hooks for subgroupnav showing --- EVENTS.txt | 6 +++++ lib/subgroupnav.php | 68 +++++++++++++++++++++++++++++------------------------ 2 files changed, 43 insertions(+), 31 deletions(-) diff --git a/EVENTS.txt b/EVENTS.txt index 5edf59245..07fc446c3 100644 --- a/EVENTS.txt +++ b/EVENTS.txt @@ -100,6 +100,12 @@ StartPublicGroupNav: Showing the public group nav menu EndPublicGroupNav: At the end of the public group nav menu - $action: the current action +StartSubGroupNav: Showing the subscriptions group nav menu +- $action: the current action + +EndSubGroupNav: At the end of the subscriptions group nav menu +- $action: the current action + RouterInitialized: After the router instance has been initialized - $m: the Net_URL_Mapper that has just been set up diff --git a/lib/subgroupnav.php b/lib/subgroupnav.php index 31c3ea0b5..4a9b36ae8 100644 --- a/lib/subgroupnav.php +++ b/lib/subgroupnav.php @@ -74,38 +74,44 @@ class SubGroupNav extends Widget $this->out->elementStart('ul', array('class' => 'nav')); - $this->out->menuItem(common_local_url('subscriptions', - array('nickname' => - $this->user->nickname)), - _('Subscriptions'), - sprintf(_('People %s subscribes to'), - $this->user->nickname), - $action == 'subscriptions', - 'nav_subscriptions'); - $this->out->menuItem(common_local_url('subscribers', - array('nickname' => - $this->user->nickname)), - _('Subscribers'), - sprintf(_('People subscribed to %s'), - $this->user->nickname), - $action == 'subscribers', - 'nav_subscribers'); - $this->out->menuItem(common_local_url('usergroups', - array('nickname' => - $this->user->nickname)), - _('Groups'), - sprintf(_('Groups %s is a member of'), - $this->user->nickname), - $action == 'usergroups', - 'nav_usergroups'); - if (!is_null($cur) && $this->user->id === $cur->id) { - $this->out->menuItem(common_local_url('invite'), - _('Invite'), - sprintf(_('Invite friends and colleagues to join you on %s'), - common_config('site', 'name')), - $action == 'invite', - 'nav_invite'); + if (Event::handle('StartSubGroupNav', array($this))) { + + $this->out->menuItem(common_local_url('subscriptions', + array('nickname' => + $this->user->nickname)), + _('Subscriptions'), + sprintf(_('People %s subscribes to'), + $this->user->nickname), + $action == 'subscriptions', + 'nav_subscriptions'); + $this->out->menuItem(common_local_url('subscribers', + array('nickname' => + $this->user->nickname)), + _('Subscribers'), + sprintf(_('People subscribed to %s'), + $this->user->nickname), + $action == 'subscribers', + 'nav_subscribers'); + $this->out->menuItem(common_local_url('usergroups', + array('nickname' => + $this->user->nickname)), + _('Groups'), + sprintf(_('Groups %s is a member of'), + $this->user->nickname), + $action == 'usergroups', + 'nav_usergroups'); + if (!is_null($cur) && $this->user->id === $cur->id) { + $this->out->menuItem(common_local_url('invite'), + _('Invite'), + sprintf(_('Invite friends and colleagues to join you on %s'), + common_config('site', 'name')), + $action == 'invite', + 'nav_invite'); + } + + Event::handle('EndSubGroupNav', array($this)); } + $this->out->elementEnd('ul'); } } -- cgit v1.2.3-54-g00ecf From fecb8c706dadb790c3a8c219275b4ba88e00b8ea Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Fri, 15 May 2009 15:04:58 -0400 Subject: Attachments and their list now provide "ajax" view. Also added a few sidebars relating tags and attachments. --- actions/attachment.php | 250 +++++++++++++++++++++++++++++ actions/attachment_ajax.php | 141 ++++++++++++++++ actions/attachments.php | 292 ++++++++++++++++++++++++++++++++++ actions/attachments_ajax.php | 115 ++++++++++++++ actions/tag.php | 12 +- classes/File.php | 11 ++ classes/File_oembed.php | 11 +- classes/File_thumbnail.php | 10 ++ classes/Notice.php | 12 +- js/jquery.joverlay.min.js | 6 + js/util.js | 4 + lib/action.php | 12 +- lib/attachmentlist.php | 300 +++++++++++++++++++++++++++++++++++ lib/noticelist.php | 71 ++++++++- lib/router.php | 14 ++ theme/base/images/icons/clip-big.png | Bin 0 -> 11245 bytes theme/base/images/icons/clip.png | Bin 0 -> 2298 bytes 17 files changed, 1243 insertions(+), 18 deletions(-) create mode 100644 actions/attachment.php create mode 100644 actions/attachment_ajax.php create mode 100644 actions/attachments.php create mode 100644 actions/attachments_ajax.php create mode 100644 js/jquery.joverlay.min.js create mode 100644 lib/attachmentlist.php create mode 100644 theme/base/images/icons/clip-big.png create mode 100644 theme/base/images/icons/clip.png diff --git a/actions/attachment.php b/actions/attachment.php new file mode 100644 index 000000000..981882a5b --- /dev/null +++ b/actions/attachment.php @@ -0,0 +1,250 @@ +. + * + * @category Personal + * @package Laconica + * @author Evan Prodromou + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +//require_once INSTALLDIR.'/lib/personalgroupnav.php'; +//require_once INSTALLDIR.'/lib/feedlist.php'; +require_once INSTALLDIR.'/lib/attachmentlist.php'; + +/** + * Show notice attachments + * + * @category Personal + * @package Laconica + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class AttachmentAction extends Action +{ + /** + * Attachment object to show + */ + + var $attachment = null; + + /** + * Profile of the notice object + */ + +// var $profile = null; + + /** + * Avatar of the profile of the notice object + */ + +// var $avatar = null; + + /** + * Load attributes based on database arguments + * + * Loads all the DB stuff + * + * @param array $args $_REQUEST array + * + * @return success flag + */ + + function prepare($args) + { + parent::prepare($args); + + $id = $this->arg('attachment'); + + $this->attachment = File::staticGet($id); + + if (!$this->attachment) { + $this->clientError(_('No such attachment.'), 404); + return false; + } + return true; + } + + /** + * Is this action read-only? + * + * @return boolean true + */ + + function isReadOnly($args) + { + return true; + } + + /** + * Title of the page + * + * @return string title of the page + */ + function title() + { + $a = new Attachment($this->attachment); + return $a->title(); + } + + + + /** + * Last-modified date for page + * + * When was the content of this page last modified? Based on notice, + * profile, avatar. + * + * @return int last-modified date as unix timestamp + */ +/* + function lastModified() + { + return max(strtotime($this->notice->created), + strtotime($this->profile->modified), + ($this->avatar) ? strtotime($this->avatar->modified) : 0); + } +*/ + + /** + * An entity tag for this page + * + * Shows the ETag for the page, based on the notice ID and timestamps + * for the notice, profile, and avatar. It's weak, since we change + * the date text "one hour ago", etc. + * + * @return string etag + */ +/* + function etag() + { + $avtime = ($this->avatar) ? + strtotime($this->avatar->modified) : 0; + + return 'W/"' . implode(':', array($this->arg('action'), + common_language(), + $this->notice->id, + strtotime($this->notice->created), + strtotime($this->profile->modified), + $avtime)) . '"'; + } +*/ + + + /** + * Handle input + * + * Only handles get, so just show the page. + * + * @param array $args $_REQUEST data (unused) + * + * @return void + */ + + function handle($args) + { + parent::handle($args); + $this->showPage(); + } + + /** + * Don't show local navigation + * + * @return void + */ + + function showLocalNavBlock() + { + } + + /** + * Fill the content area of the page + * + * Shows a single notice list item. + * + * @return void + */ + + function showContent() + { + $this->elementStart('ul', array('class' => 'attachments')); + $ali = new Attachment($this->attachment, $this); + $cnt = $ali->show(); + $this->elementEnd('ul'); + } + + /** + * Don't show page notice + * + * @return void + */ + + function showPageNoticeBlock() + { + } + + /** + * Show aside: this attachments appears in what notices + * + * @return void + */ + + function showAside() { + $notice = new Notice; + $f2p = new File_to_post; + $f2p->file_id = $this->attachment->id; + $notice->joinAdd($f2p); + $notice->orderBy('created desc'); + $x = $notice->find(); + $this->elementStart('ol'); + while($notice->fetch()) { + $this->elementStart('li'); + $profile = $notice->getProfile(); + $this->element('a', array('href' => $notice->uri), $profile->nickname . ' on ' . $notice->created); + $this->elementEnd('li'); + } + $this->elementEnd('ol'); + $notice->free(); + $f2p->free(); + + $notice_tag = new Notice_tag; + $attachment = new File; + + $query = 'select tag,count(tag) as c from notice_tag join file_to_post on (notice_tag.notice_id=post_id) join notice on notice_id = notice.id where file_id=' . $notice_tag->escape($this->attachment->id) . ' group by tag order by c desc'; + + $notice_tag->query($query); + $this->elementStart('ol'); + while($notice_tag->fetch()) { + $this->elementStart('li'); + $href = common_local_url('tag', array('tag' => $notice_tag->tag)); + $this->element('a', array('href' => $href), $notice_tag->tag . ' (' . $notice_tag->c . ')'); + $this->elementEnd('li'); + } + $this->elementEnd('ol'); + } +} diff --git a/actions/attachment_ajax.php b/actions/attachment_ajax.php new file mode 100644 index 000000000..1620b27dd --- /dev/null +++ b/actions/attachment_ajax.php @@ -0,0 +1,141 @@ +. + * + * @category Personal + * @package Laconica + * @author Evan Prodromou + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/actions/attachment.php'; + +/** + * Show notice attachments + * + * @category Personal + * @package Laconica + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class Attachment_ajaxAction extends AttachmentAction +{ + /** + * Load attributes based on database arguments + * + * Loads all the DB stuff + * + * @param array $args $_REQUEST array + * + * @return success flag + */ + + function prepare($args) + { + parent::prepare($args); + if (!$this->attachment) { + $this->clientError(_('No such attachment.'), 404); + return false; + } + return true; + } + + /** + * Show page, a template method. + * + * @return nothing + */ + function showPage() + { + if (Event::handle('StartShowBody', array($this))) { + $this->showCore(); + Event::handle('EndShowBody', array($this)); + } + } + + /** + * Show core. + * + * Shows local navigation, content block and aside. + * + * @return nothing + */ + function showCore() + { + $this->elementStart('div', array('id' => 'core')); + if (Event::handle('StartShowContentBlock', array($this))) { + $this->showContentBlock(); + Event::handle('EndShowContentBlock', array($this)); + } + $this->elementEnd('div'); + } + + + + /** + * Last-modified date for page + * + * When was the content of this page last modified? Based on notice, + * profile, avatar. + * + * @return int last-modified date as unix timestamp + */ +/* + function lastModified() + { + return max(strtotime($this->notice->created), + strtotime($this->profile->modified), + ($this->avatar) ? strtotime($this->avatar->modified) : 0); + } +*/ + + /** + * An entity tag for this page + * + * Shows the ETag for the page, based on the notice ID and timestamps + * for the notice, profile, and avatar. It's weak, since we change + * the date text "one hour ago", etc. + * + * @return string etag + */ +/* + function etag() + { + $avtime = ($this->avatar) ? + strtotime($this->avatar->modified) : 0; + + return 'W/"' . implode(':', array($this->arg('action'), + common_language(), + $this->notice->id, + strtotime($this->notice->created), + strtotime($this->profile->modified), + $avtime)) . '"'; + } +*/ +} + diff --git a/actions/attachments.php b/actions/attachments.php new file mode 100644 index 000000000..6b31c839d --- /dev/null +++ b/actions/attachments.php @@ -0,0 +1,292 @@ +. + * + * @category Personal + * @package Laconica + * @author Evan Prodromou + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +//require_once INSTALLDIR.'/lib/personalgroupnav.php'; +//require_once INSTALLDIR.'/lib/feedlist.php'; +require_once INSTALLDIR.'/lib/attachmentlist.php'; + +/** + * Show notice attachments + * + * @category Personal + * @package Laconica + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class AttachmentsAction extends Action +{ + /** + * Notice object to show + */ + + var $notice = null; + + /** + * Profile of the notice object + */ + + var $profile = null; + + /** + * Avatar of the profile of the notice object + */ + + var $avatar = null; + + /** + * Is this action read-only? + * + * @return boolean true + */ + + function isReadOnly($args) + { + return true; + } + + /** + * Last-modified date for page + * + * When was the content of this page last modified? Based on notice, + * profile, avatar. + * + * @return int last-modified date as unix timestamp + */ + + function lastModified() + { + return max(strtotime($this->notice->created), + strtotime($this->profile->modified), + ($this->avatar) ? strtotime($this->avatar->modified) : 0); + } + + /** + * An entity tag for this page + * + * Shows the ETag for the page, based on the notice ID and timestamps + * for the notice, profile, and avatar. It's weak, since we change + * the date text "one hour ago", etc. + * + * @return string etag + */ + + function etag() + { + $avtime = ($this->avatar) ? + strtotime($this->avatar->modified) : 0; + + return 'W/"' . implode(':', array($this->arg('action'), + common_language(), + $this->notice->id, + strtotime($this->notice->created), + strtotime($this->profile->modified), + $avtime)) . '"'; + } + + /** + * Title of the page + * + * @return string title of the page + */ + + function title() + { + return sprintf(_('%1$s\'s status on %2$s'), + $this->profile->nickname, + common_exact_date($this->notice->created)); + } + + + /** + * Load attributes based on database arguments + * + * Loads all the DB stuff + * + * @param array $args $_REQUEST array + * + * @return success flag + */ + + function prepare($args) + { + parent::prepare($args); + + $id = $this->arg('notice'); + + $this->notice = Notice::staticGet($id); + + if (!$this->notice) { + $this->clientError(_('No such notice.'), 404); + return false; + } + + +/* +// STOP if there are no attachments +// maybe even redirect if there's a single one +// RYM FIXME TODO + $this->clientError(_('No such attachment.'), 404); + return false; + +*/ + + + + + $this->profile = $this->notice->getProfile(); + + if (!$this->profile) { + $this->serverError(_('Notice has no profile'), 500); + return false; + } + + $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE); + return true; + } + + + + /** + * Handle input + * + * Only handles get, so just show the page. + * + * @param array $args $_REQUEST data (unused) + * + * @return void + */ + + function handle($args) + { + parent::handle($args); + + if ($this->notice->is_local == 0) { + if (!empty($this->notice->url)) { + common_redirect($this->notice->url, 301); + } else if (!empty($this->notice->uri) && preg_match('/^https?:/', $this->notice->uri)) { + common_redirect($this->notice->uri, 301); + } + } else { + $f2p = new File_to_post; + $f2p->post_id = $this->notice->id; + $file = new File; + $file->joinAdd($f2p); + $file->selectAdd(); + $file->selectAdd('file.id as id'); + $count = $file->find(true); + if (!$count) return; + if (1 === $count) { + common_redirect(common_local_url('attachment', array('attachment' => $file->id)), 301); + } else { + $this->showPage(); + } + } + } + + /** + * Don't show local navigation + * + * @return void + */ + + function showLocalNavBlock() + { + } + + /** + * Fill the content area of the page + * + * Shows a single notice list item. + * + * @return void + */ + + function showContent() + { + $al = new AttachmentList($this->notice, $this); + $cnt = $al->show(); + } + + /** + * Don't show page notice + * + * @return void + */ + + function showPageNoticeBlock() + { + } + + /** + * Don't show aside + * + * @return void + */ + + function showAside() { + } + + /** + * Extra content + * + * We show the microid(s) for the author, if any. + * + * @return void + */ + + function extraHead() + { + $user = User::staticGet($this->profile->id); + + if (!$user) { + return; + } + + if ($user->emailmicroid && $user->email && $this->notice->uri) { + $id = new Microid('mailto:'. $user->email, + $this->notice->uri); + $this->element('meta', array('name' => 'microid', + 'content' => $id->toString())); + } + + if ($user->jabbermicroid && $user->jabber && $this->notice->uri) { + $id = new Microid('xmpp:', $user->jabber, + $this->notice->uri); + $this->element('meta', array('name' => 'microid', + 'content' => $id->toString())); + } + } +} + diff --git a/actions/attachments_ajax.php b/actions/attachments_ajax.php new file mode 100644 index 000000000..402d8b5e7 --- /dev/null +++ b/actions/attachments_ajax.php @@ -0,0 +1,115 @@ +. + * + * @category Personal + * @package Laconica + * @author Evan Prodromou + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +//require_once INSTALLDIR.'/lib/personalgroupnav.php'; +//require_once INSTALLDIR.'/lib/feedlist.php'; +require_once INSTALLDIR.'/actions/attachments.php'; + +/** + * Show notice attachments + * + * @category Personal + * @package Laconica + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class Attachments_ajaxAction extends AttachmentsAction +{ + function showContent() + { + } + + /** + * Fill the content area of the page + * + * Shows a single notice list item. + * + * @return void + */ + + function showContentBlock() + { + $al = new AttachmentList($this->notice, $this); + $cnt = $al->show(); + } + + /** + * Extra content + * + * We show the microid(s) for the author, if any. + * + * @return void + */ + + function extraHead() + { + } + + + /** + * Show page, a template method. + * + * @return nothing + */ + function showPage() + { + if (Event::handle('StartShowBody', array($this))) { + $this->showCore(); + Event::handle('EndShowBody', array($this)); + } + } + + /** + * Show core. + * + * Shows local navigation, content block and aside. + * + * @return nothing + */ + function showCore() + { + $this->elementStart('div', array('id' => 'core')); + if (Event::handle('StartShowContentBlock', array($this))) { + $this->showContentBlock(); + Event::handle('EndShowContentBlock', array($this)); + } + $this->elementEnd('div'); + } + + + + +} + diff --git a/actions/tag.php b/actions/tag.php index 02f3e3522..2202f9bb0 100644 --- a/actions/tag.php +++ b/actions/tag.php @@ -49,8 +49,18 @@ class TagAction extends Action { $pop = new PopularNoticeSection($this); $pop->show(); - } + $notice_tag = new Notice_tag; + $query = 'select file_id, count(file_id) as c from notice_tag join file_to_post on post_id = notice_id where tag="' . $notice_tag->escape($this->tag) . '" group by file_id order by c desc'; + $notice_tag->query($query); + $this->elementStart('ol'); + while ($notice_tag->fetch()) { + $this->elementStart('li'); + $this->element('a', array('class' => 'attachment', 'href' => common_local_url('attachment', array('attachment' => $notice_tag->file_id))), "Attachment tagged {$notice_tag->c} times"); + $this->elementEnd('li'); + } + $this->elementEnd('ol'); + } function title() { diff --git a/classes/File.php b/classes/File.php index 2ddc5deb8..e5913115b 100644 --- a/classes/File.php +++ b/classes/File.php @@ -54,6 +54,17 @@ class File extends Memcached_DataObject return 'http://www.facebook.com/login.php' === $url; } + function getAttachments($post_id) { + $query = "select file.* from file join file_to_post on (file_id = file.id) join notice on (post_id = notice.id) where post_id = " . $this->escape($post_id); + $this->query($query); + $att = array(); + while ($this->fetch()) { + $att[] = clone($this); + } + $this->free(); + return $att; + } + function saveNew($redir_data, $given_url) { $x = new File; $x->url = $given_url; diff --git a/classes/File_oembed.php b/classes/File_oembed.php index 2846f49db..f1b2cb13c 100644 --- a/classes/File_oembed.php +++ b/classes/File_oembed.php @@ -78,18 +78,9 @@ class File_oembed extends Memcached_DataObject if (!empty($data['author_url'])) $file_oembed->author_url = $data['author_url']; if (!empty($data['url'])) $file_oembed->url = $data['url']; $file_oembed->insert(); - if (!empty($data['thumbnail_url'])) { - $tn = new File_thumbnail; - $tn->file_id = $file_id; - $tn->url = $data['thumbnail_url']; - $tn->width = intval($data['thumbnail_width']); - $tn->height = intval($data['thumbnail_height']); - $tn->insert(); + File_thumbnail::saveNew($data, $file_id); } - - - } } diff --git a/classes/File_thumbnail.php b/classes/File_thumbnail.php index 7b906a07c..1a65b92c9 100644 --- a/classes/File_thumbnail.php +++ b/classes/File_thumbnail.php @@ -42,4 +42,14 @@ class File_thumbnail extends Memcached_DataObject /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE + + function saveNew($data, $file_id) { + $tn = new File_thumbnail; + $tn->file_id = $file_id; + $tn->url = $data['thumbnail_url']; + $tn->width = intval($data['thumbnail_width']); + $tn->height = intval($data['thumbnail_height']); + $tn->insert(); + } } + diff --git a/classes/Notice.php b/classes/Notice.php index c2fa2d19e..30508070e 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -124,8 +124,6 @@ class Notice extends Memcached_DataObject $profile = Profile::staticGet($profile_id); -// $final = common_shorten_links($content); - if (!$profile) { common_log(LOG_ERR, 'Problem saving notice. Unknown user.'); return _('Problem saving notice. Unknown user.'); @@ -279,6 +277,16 @@ class Notice extends Memcached_DataObject return true; } + function hasAttachments() { + $post = clone($this); + $query = "select count(file_id) as n_attachments from file join file_to_post on (file_id = file.id) join notice on (post_id = notice.id) where post_id = " . $post->escape($this->id); + $post->query($query); + $post->fetch(); + $n_attachments = intval($post->n_attachments); + $post->free(); + return $n_attachments; + } + function blowCaches($blowLast=false) { $this->blowSubsCache($blowLast); diff --git a/js/jquery.joverlay.min.js b/js/jquery.joverlay.min.js new file mode 100644 index 000000000..c9168506a --- /dev/null +++ b/js/jquery.joverlay.min.js @@ -0,0 +1,6 @@ +/* Copyright (c) 2009 Alvaro A. Lima Jr http://alvarojunior.com/jquery/joverlay.html + * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) + * Version: 0.6 (Abr 23, 2009) + * Requires: jQuery 1.3+ + */ +(function($){var f=$.browser.msie&&$.browser.version==6.0;var g=null;$.fn.jOverlay=function(b){var b=$.extend({},$.fn.jOverlay.options,b);if(g!=null){clearTimeout(g)}var c=this.is('*')?this:'#jOverlayContent';var d=f?'absolute':'fixed';var e=b.imgLoading?"":'';$('body').prepend(e+"
      "+"
    • ', + $logout_url, $title, $logout_url, $text); + + $action->raw($html); + + } + else { + if (!common_config('site', 'closed')) { + $action->menuItem(common_local_url('register'), + _('Register'), _('Create an account'), false, 'nav_register'); + } + $action->menuItem(common_local_url('openidlogin'), + _('OpenID'), _('Login with OpenID'), false, 'nav_openid'); + $action->menuItem(common_local_url('login'), + _('Login'), _('Login to the site'), false, 'nav_login'); + } + + $action->menuItem(common_local_url('doc', array('title' => 'help')), + _('Help'), _('Help me!'), false, 'nav_help'); + $action->menuItem(common_local_url('peoplesearch'), + _('Search'), _('Search for people or text'), false, 'nav_search'); + + // Tack on "Connect with Facebook" button + + // XXX: Maybe this looks bad and should not go here. Where should it go? + + if (!$user) { + $action->elementStart('li'); + $action->element('fb:login-button', array('onlogin' => 'refresh_page()', + 'length' => 'long')); + $action->elementEnd('li'); + } + + return false; + } + + function checkFacebookUser() { + + try { + + $facebook = getFacebook(); + $fbuid = $facebook->get_loggedin_user(); + $user = common_current_user(); + + // If you're a Facebook user and you're logged in do nothing + + // If you're a Facebook user and you're not logged in + // redirect to Facebook connect login page because that means you have clicked + // the 'connect with Facebook' button and have cookies + + if ($fbuid > 0) { + + if ($facebook->api_client->users_isAppUser($fbuid) || + $facebook->api_client->added) { + + // user should be connected... + + common_debug("Facebook user found: $fbuid"); + + if ($user) { + common_debug("Facebook user is logged in."); + return; + + } else { + common_debug("Facebook user is NOT logged in."); + common_redirect(common_local_url('fbconnectlogin'), 303); + } + + } else { + common_debug("No Facebook connect user found."); + } + } + + } catch (Exception $e) { + common_debug('Expired FB session.'); + } + + } + + function onStartLogout($action) + { + common_debug("onEndLogout()"); + + common_set_user(null); + common_real_login(false); // not logged in + common_forgetme(); // don't log back in! + + try { + + $facebook = getFacebook(); + $fbuid = $facebook->get_loggedin_user(); + + // XXX: ARGGGH this doesn't work right! + + if ($fbuid) { + $facebook->expire_session(); + $facebook->logout(common_local_url('public')); + } + + } catch (Exception $e) { + common_debug('Problem expiring FB session'); + } + + common_debug("logged out."); + + return false; + } + +} + + diff --git a/plugins/FBConnect/xd_receiver.htm b/plugins/FBConnect/xd_receiver.htm new file mode 100644 index 000000000..43fb2c4e4 --- /dev/null +++ b/plugins/FBConnect/xd_receiver.htm @@ -0,0 +1,10 @@ + + + + cross domain receiver page + + + + + -- cgit v1.2.3-54-g00ecf From f3ea79a12a7bdf0d4efcd7eb706d25ae81b7fad9 Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Sun, 17 May 2009 00:05:07 -0400 Subject: Added site path field to installer + fancy URL javascript auto-detection. --- index.php | 4 ++++ install.php | 31 ++++++++++++++++++++++++++----- js/install.js | 18 ++++++++++++++++++ 3 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 js/install.js diff --git a/index.php b/index.php index e24bde917..cfef21189 100644 --- a/index.php +++ b/index.php @@ -63,6 +63,10 @@ function handleError($error) function main() { + // quick check for fancy URL auto-detection support in installer. + if ('/check-fancy' === $_SERVER['REDIRECT_URL']) { + die("Fancy URL support detection succeeded. We suggest you enable this to get fancy (pretty) URLs."); + } global $user, $action, $config; if (!_have_config()) { diff --git a/install.php b/install.php index 66e8e8712..32915200b 100644 --- a/install.php +++ b/install.php @@ -86,7 +86,8 @@ function checkExtension($name) function showForm() { -?> + $config_path = htmlentities(trim(dirname($_SERVER['REQUEST_URI']), '/')); + echo<< @@ -108,11 +109,21 @@ function showForm()

      The name of your site

    • + + enable
      + disable
      +

      Enable fancy (pretty) URLs. Auto-detection failed, it depends on Javascript.

      +
    • Database hostname

    • +
    • + + +

      Site path, following the "/" after the domain name in the URL. Empty is fine. Field should be filled automatically.

      +
    • @@ -132,7 +143,8 @@ function showForm() -
      Page notice
      @@ -225,29 +239,34 @@ function handlePost() } updateStatus("Writing config file..."); $sqlUrl = "mysqli://$username:$password@$host/$database"; - $res = writeConf($sitename, $sqlUrl); + $res = writeConf($sitename, $sqlUrl, $fancy, $path); if (!$res) { updateStatus("Can't write config file.", true); showForm(); return; } updateStatus("Done!"); + if ($path) $path .= '/'; + updateStatus("You can visit your new Laconica site + +
      diff --git a/js/install.js b/js/install.js new file mode 100644 index 000000000..32a54111e --- /dev/null +++ b/js/install.js @@ -0,0 +1,18 @@ +$(document).ready(function(){ + $.ajax({url:'check-fancy', + type:'GET', + success:function(data, textStatus) { + $('#fancy-enable').attr('checked', true); + $('#fancy-disable').attr('checked', false); + $('#fancy-form_guide').text(data); + }, + error:function(XMLHttpRequest, textStatus, errorThrown) { + $('#fancy-enable').attr('checked', false); + $('#fancy-disable').attr('checked', true); + $('#fancy-enable').attr('disabled', true); + $('#fancy-disable').attr('disabled', true); + $('#fancy-form_guide').text("Fancy URL support detection failed, disabling this option. Make sure you renamed htaccess.sample to .htaccess."); + } + }); +}); + -- cgit v1.2.3-54-g00ecf From 5a0edc9b8cbfa10d4dd72603d95708c50e3b8cdb Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 17 May 2009 12:37:04 -0400 Subject: remove debugging calls --- plugins/WikiHashtagsPlugin.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/plugins/WikiHashtagsPlugin.php b/plugins/WikiHashtagsPlugin.php index 141cb07d2..6d186a5fe 100644 --- a/plugins/WikiHashtagsPlugin.php +++ b/plugins/WikiHashtagsPlugin.php @@ -54,32 +54,25 @@ class WikiHashtagsPlugin extends Plugin function onStartShowSections($action) { - common_debug('WikiHashtags: got called'); $name = $action->trimmed('action'); if ($name == 'tag') { - common_debug('WikiHashtags: called by tag'); $taginput = $action->trimmed('tag'); $tag = common_canonical_tag($taginput); if (!empty($tag)) { - common_debug('WikiHashtags: have a tag: ' . $tag); $url = sprintf('http://hashtags.wikia.com/index.php?title=%s&action=render', urlencode($tag)); $editurl = sprintf('http://hashtags.wikia.com/index.php?title=%s&action=edit', urlencode($tag)); - common_debug('WikiHashtags: have an url: ' . $url); - $context = stream_context_create(array('http' => array('method' => "GET", 'header' => "User-Agent: " . $this->userAgent()))); $html = @file_get_contents($url, false, $context); - common_debug('WikiHashtags: results are: ' . $html); - $action->elementStart('div', array('id' => 'wikihashtags', 'class' => 'section')); if (!empty($html)) { -- cgit v1.2.3-54-g00ecf From 5897dfa4c37d6a44bcde5dc7569c8b0d30f21b84 Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Sun, 17 May 2009 22:06:08 -0400 Subject: Refactored new sections code to proper classes and added notice link to links in notice sections. --- actions/attachment.php | 53 +++---------------------- actions/tag.php | 13 +----- classes/Notice.php | 6 +-- config.php.sample | 6 +++ index.php | 2 +- lib/attachmentnoticesection.php | 75 +++++++++++++++++++++++++++++++++++ lib/attachmentsection.php | 80 +++++++++++++++++++++++++++++++++++++ lib/attachmenttagcloudsection.php | 83 +++++++++++++++++++++++++++++++++++++++ lib/frequentattachmentsection.php | 66 +++++++++++++++++++++++++++++++ lib/noticesection.php | 35 +++++++++++++++-- lib/popularnoticesection.php | 2 +- 11 files changed, 354 insertions(+), 67 deletions(-) create mode 100644 lib/attachmentnoticesection.php create mode 100644 lib/attachmentsection.php create mode 100644 lib/attachmenttagcloudsection.php create mode 100644 lib/frequentattachmentsection.php diff --git a/actions/attachment.php b/actions/attachment.php index 981882a5b..b9187ff08 100644 --- a/actions/attachment.php +++ b/actions/attachment.php @@ -53,18 +53,6 @@ class AttachmentAction extends Action var $attachment = null; - /** - * Profile of the notice object - */ - -// var $profile = null; - - /** - * Avatar of the profile of the notice object - */ - -// var $avatar = null; - /** * Load attributes based on database arguments * @@ -112,8 +100,6 @@ class AttachmentAction extends Action return $a->title(); } - - /** * Last-modified date for page * @@ -213,38 +199,11 @@ class AttachmentAction extends Action * * @return void */ - - function showAside() { - $notice = new Notice; - $f2p = new File_to_post; - $f2p->file_id = $this->attachment->id; - $notice->joinAdd($f2p); - $notice->orderBy('created desc'); - $x = $notice->find(); - $this->elementStart('ol'); - while($notice->fetch()) { - $this->elementStart('li'); - $profile = $notice->getProfile(); - $this->element('a', array('href' => $notice->uri), $profile->nickname . ' on ' . $notice->created); - $this->elementEnd('li'); - } - $this->elementEnd('ol'); - $notice->free(); - $f2p->free(); - - $notice_tag = new Notice_tag; - $attachment = new File; - - $query = 'select tag,count(tag) as c from notice_tag join file_to_post on (notice_tag.notice_id=post_id) join notice on notice_id = notice.id where file_id=' . $notice_tag->escape($this->attachment->id) . ' group by tag order by c desc'; - - $notice_tag->query($query); - $this->elementStart('ol'); - while($notice_tag->fetch()) { - $this->elementStart('li'); - $href = common_local_url('tag', array('tag' => $notice_tag->tag)); - $this->element('a', array('href' => $href), $notice_tag->tag . ' (' . $notice_tag->c . ')'); - $this->elementEnd('li'); - } - $this->elementEnd('ol'); + function showSections() { + $ns = new AttachmentNoticeSection($this); + $ns->show(); + $atcs = new AttachmentTagCloudSection($this); + $atcs->show(); } } + diff --git a/actions/tag.php b/actions/tag.php index 2202f9bb0..47420e4c3 100644 --- a/actions/tag.php +++ b/actions/tag.php @@ -49,17 +49,8 @@ class TagAction extends Action { $pop = new PopularNoticeSection($this); $pop->show(); - - $notice_tag = new Notice_tag; - $query = 'select file_id, count(file_id) as c from notice_tag join file_to_post on post_id = notice_id where tag="' . $notice_tag->escape($this->tag) . '" group by file_id order by c desc'; - $notice_tag->query($query); - $this->elementStart('ol'); - while ($notice_tag->fetch()) { - $this->elementStart('li'); - $this->element('a', array('class' => 'attachment', 'href' => common_local_url('attachment', array('attachment' => $notice_tag->file_id))), "Attachment tagged {$notice_tag->c} times"); - $this->elementEnd('li'); - } - $this->elementEnd('ol'); + $freqatt = new FrequentAttachmentSection($this); + $freqatt->show(); } function title() diff --git a/classes/Notice.php b/classes/Notice.php index 30508070e..f6ac4f780 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -134,7 +134,7 @@ class Notice extends Memcached_DataObject return _('Too many notices too fast; take a breather and post again in a few minutes.'); } - if (common_config('site', 'dupelimit') > 0 && !Notice::checkDupes($profile_id, $final)) { + if (common_config('site', 'dupelimit') > 0 && !Notice::checkDupes($profile_id, $content)) { common_log(LOG_WARNING, 'Dupe posting by profile #' . $profile_id . '; throttled.'); return _('Too many duplicate messages too quickly; take a breather and post again in a few minutes.'); } @@ -278,8 +278,8 @@ class Notice extends Memcached_DataObject } function hasAttachments() { - $post = clone($this); - $query = "select count(file_id) as n_attachments from file join file_to_post on (file_id = file.id) join notice on (post_id = notice.id) where post_id = " . $post->escape($this->id); + $post = clone $this; + $query = "select count(file_id) as n_attachments from file join file_to_post on (file_id = file.id) join notice on (post_id = notice.id) where post_id = " . $post->escape($post->id); $post->query($query); $post->fetch(); $n_attachments = intval($post->n_attachments); diff --git a/config.php.sample b/config.php.sample index 0e6bf0e5f..826b086a3 100644 --- a/config.php.sample +++ b/config.php.sample @@ -33,6 +33,12 @@ $config['site']['path'] = 'laconica'; #Make the site invisible to non-logged-in users #$config['site']['private'] = true; +# 'direct' for direct notice links in sections +# 'attachment' for notice attachment links in sections +# left undefined, no link is showed +#$config['site']['notice_link'] = 'attachment'; +#$config['site']['notice_link'] = 'direct'; + # If you want logging sent to a file instead of syslog #$config['site']['logfile'] = '/tmp/laconica.log'; diff --git a/index.php b/index.php index cfef21189..1b4fbf81b 100644 --- a/index.php +++ b/index.php @@ -64,7 +64,7 @@ function handleError($error) function main() { // quick check for fancy URL auto-detection support in installer. - if ('/check-fancy' === $_SERVER['REDIRECT_URL']) { + if (isset($_SERVER['REDIRECT_URL']) && ('/check-fancy' === $_SERVER['REDIRECT_URL'])) { die("Fancy URL support detection succeeded. We suggest you enable this to get fancy (pretty) URLs."); } global $user, $action, $config; diff --git a/lib/attachmentnoticesection.php b/lib/attachmentnoticesection.php new file mode 100644 index 000000000..eb3176376 --- /dev/null +++ b/lib/attachmentnoticesection.php @@ -0,0 +1,75 @@ +. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * FIXME + * + * These are the widgets that show interesting data about a person * group, or site. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class AttachmentNoticeSection extends NoticeSection +{ + function showContent() { + parent::showContent(); + return false; + } + + function getNotices() + { + $notice = new Notice; + $f2p = new File_to_post; + $f2p->file_id = $this->out->attachment->id; + $notice->joinAdd($f2p); + $notice->orderBy('created desc'); + $notice->selectAdd('post_id as id'); + $notice->find(); + return $notice; + } + + function title() + { + return _('Notices where this attachment appears'); + } + + function divId() + { + return 'popular_notices'; + } +} + diff --git a/lib/attachmentsection.php b/lib/attachmentsection.php new file mode 100644 index 000000000..20e620b9b --- /dev/null +++ b/lib/attachmentsection.php @@ -0,0 +1,80 @@ +. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +define('ATTACHMENTS_PER_SECTION', 6); + +/** + * Base class for sections showing lists of attachments + * + * These are the widgets that show interesting data about a person + * group, or site. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class AttachmentSection extends Section +{ + function showContent() + { + $attachments = $this->getAttachments(); + + $cnt = 0; + + $this->out->elementStart('ul', 'attachments'); + + while ($attachments->fetch() && ++$cnt <= ATTACHMENTS_PER_SECTION) { + $this->showAttachment($attachments); + } + + $this->out->elementEnd('ul'); + + return ($cnt > ATTACHMENTS_PER_SECTION); + } + + function getAttachments() + { + return null; + } + + function showAttachment($attachment) + { + $this->out->elementStart('li'); + $this->out->element('a', array('class' => 'attachment', 'href' => common_local_url('attachment', array('attachment' => $attachment->file_id))), "Attachment tagged {$attachment->c} times"); + $this->out->elementEnd('li'); + } +} + diff --git a/lib/attachmenttagcloudsection.php b/lib/attachmenttagcloudsection.php new file mode 100644 index 000000000..50bfceccb --- /dev/null +++ b/lib/attachmenttagcloudsection.php @@ -0,0 +1,83 @@ +. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Attachment tag cloud section + * + * @category Widget + * @package Laconica + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class AttachmentTagCloudSection extends TagCloudSection +{ + function title() + { + return _('Tags for this attachment'); + } + + function showTag($tag, $weight, $relative) + { + if ($relative > 0.5) { + $rel = 'tag-cloud-7'; + } else if ($relative > 0.4) { + $rel = 'tag-cloud-6'; + } else if ($relative > 0.3) { + $rel = 'tag-cloud-5'; + } else if ($relative > 0.2) { + $rel = 'tag-cloud-4'; + } else if ($relative > 0.1) { + $rel = 'tag-cloud-3'; + } else if ($relative > 0.05) { + $rel = 'tag-cloud-2'; + } else { + $rel = 'tag-cloud-1'; + } + + $this->out->elementStart('li', $rel); + $this->out->element('a', array('href' => $this->tagUrl($tag)), + $tag); + $this->out->elementEnd('li'); + } + + function getTags() + { + $notice_tag = new Notice_tag; + $query = 'select tag,count(tag) as weight from notice_tag join file_to_post on (notice_tag.notice_id=post_id) join notice on notice_id = notice.id where file_id=' . $notice_tag->escape($this->out->attachment->id) . ' group by tag order by weight desc'; + $notice_tag->query($query); + return $notice_tag; + } +} + diff --git a/lib/frequentattachmentsection.php b/lib/frequentattachmentsection.php new file mode 100644 index 000000000..0ce0d1871 --- /dev/null +++ b/lib/frequentattachmentsection.php @@ -0,0 +1,66 @@ +. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * FIXME + * + * These are the widgets that show interesting data about a person + * group, or site. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class FrequentAttachmentSection extends AttachmentSection +{ + function getAttachments() { + $notice_tag = new Notice_tag; + $query = 'select file_id, count(file_id) as c from notice_tag join file_to_post on post_id = notice_id where tag="' . $notice_tag->escape($this->out->tag) . '" group by file_id order by c desc'; + $notice_tag->query($query); + return $notice_tag; + } + + function title() + { + return sprintf(_('Attachments frequently tagged with %s'), $this->out->tag); + } + + function divId() + { + return 'frequent_attachments'; + } +} + diff --git a/lib/noticesection.php b/lib/noticesection.php index 94c2738ef..37aafdaf6 100644 --- a/lib/noticesection.php +++ b/lib/noticesection.php @@ -51,17 +51,13 @@ class NoticeSection extends Section function showContent() { $notices = $this->getNotices(); - $cnt = 0; - $this->out->elementStart('ul', 'notices'); - while ($notices->fetch() && ++$cnt <= NOTICES_PER_SECTION) { $this->showNotice($notices); } $this->out->elementEnd('ul'); - return ($cnt > NOTICES_PER_SECTION); } @@ -100,6 +96,37 @@ class NoticeSection extends Section $this->out->elementStart('p', 'entry-content'); $this->out->raw($notice->rendered); + + $notice_link_cfg = common_config('site', 'notice_link'); + if ('direct' === $notice_link_cfg) { + $this->out->text(' ('); + $this->out->element('a', array('href' => $notice->uri), 'see'); + $this->out->text(')'); + } elseif ('attachment' === $notice_link_cfg) { + if ($count = $notice->hasAttachments()) { + // link to attachment(s) pages + if (1 === $count) { + $f2p = File_to_post::staticGet('post_id', $notice->id); + $href = common_local_url('attachment', array('attachment' => $f2p->file_id)); + $att_class = 'attachment'; + } else { + $href = common_local_url('attachments', array('notice' => $notice->id)); + $att_class = 'attachments'; + } + + $clip = theme_path('images/icons/clip.png', 'base'); + $this->out->elementStart('a', array('class' => $att_class, 'style' => "font-style: italic;", 'href' => $href, 'title' => "# of attachments: $count")); + $this->out->raw(" ($count "); + $this->out->element('img', array('style' => 'display: inline', 'align' => 'top', 'width' => 20, 'height' => 20, 'src' => $clip, 'alt' => 'alt')); + $this->out->text(')'); + $this->out->elementEnd('a'); + } else { + $this->out->text(' ('); + $this->out->element('a', array('href' => $notice->uri), 'see'); + $this->out->text(')'); + } + } + $this->out->elementEnd('p'); if (!empty($notice->value)) { $this->out->elementStart('p'); diff --git a/lib/popularnoticesection.php b/lib/popularnoticesection.php index a8d47ef54..375d5538b 100644 --- a/lib/popularnoticesection.php +++ b/lib/popularnoticesection.php @@ -51,7 +51,7 @@ class PopularNoticeSection extends NoticeSection if (common_config('db', 'type') == 'pgsql') { $weightexpr='sum(exp(-extract(epoch from (now() - fave.modified)) / %s))'; if (!empty($this->out->tag)) { - $tag = pg_escape_string($this->tag); + $tag = pg_escape_string($this->out->tag); } } else { $weightexpr='sum(exp(-(now() - fave.modified) / %s))'; -- cgit v1.2.3-54-g00ecf From 806200379d2e35a5cbf5ce4940474e1cbdd1f1a0 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Mon, 18 May 2009 20:10:46 +0000 Subject: Dynamic color updates to page elements when user picks a color. Using JSON to create swatches in HTML output. --- actions/designsettings.php | 73 +++++++++++++++++++++++++----------------- js/farbtastic/farbtastic.go.js | 69 +++++++++++++++++++++++++++++++++++---- 2 files changed, 107 insertions(+), 35 deletions(-) diff --git a/actions/designsettings.php b/actions/designsettings.php index cdd950e78..0deb3f684 100644 --- a/actions/designsettings.php +++ b/actions/designsettings.php @@ -76,7 +76,6 @@ class DesignsettingsAction extends AccountSettingsAction 'action' => common_local_url('designsettings'))); $this->elementStart('fieldset'); -// $this->element('legend', null, _('Design settings')); $this->hidden('token', common_session_token()); $this->elementStart('fieldset', array('id' => 'settings_design_background-image')); @@ -91,28 +90,46 @@ class DesignsettingsAction extends AccountSettingsAction $this->elementStart('fieldset', array('id' => 'settings_design_color')); $this->element('legend', null, _('Change colours')); $this->elementStart('ul', 'form_data'); - $this->elementStart('li'); - $this->input('color-1', _('Background color'), '#F0F2F5', null); - $this->elementEnd('li'); - $this->elementStart('li'); - $this->input('color-2', _('Content background color'), '#FFFFFF', null); - $this->elementEnd('li'); - $this->elementStart('li'); - $this->input('color-3', _('Sidebar background color'), '#CEE1E9', null); - $this->elementEnd('li'); - $this->elementStart('li'); - $this->input('color-4', _('Text color'), '#000000', null); - $this->elementEnd('li'); - $this->elementStart('li'); - $this->input('color-5', _('Link color'), '#002E6E', null); - $this->elementEnd('li'); + + //This is a JSON object in the DB field. Here for testing. Remove later. + $userSwatch = '{"body":{"background-color":"#F0F2F5"}, + "#content":{"background-color":"#FFFFFF"}, + "#aside_primary":{"background-color":"#CEE1E9"}, + "html body":{"color":"#000000"}, + "a":{"color":"#002E6E"}}'; + + //Default theme swatch -- Where should this be stored? + $defaultSwatch = array('body' => array('background-color' => '#F0F2F5'), + '#content' => array('background-color' => '#FFFFFF'), + '#aside_primary' => array('background-color' => '#CEE1E9'), + 'html body' => array('color' => '#000000'), + 'a' => array('color' => '#002E6E')); + + $userSwatch = ($userSwatch) ? json_decode($userSwatch, true) : $defaultSwatch; + + $s = 0; + $labelSwatch = array('Background color', + 'Content background color', + 'Sidebar background color', + 'Text color', + 'Link color'); + foreach($userSwatch as $propertyvalue => $value) { + $foo = array_values($value); //Is this necessary? $value[0] doesn't work because of invalid key + $this->elementStart('li'); + $this->input("swatch-".$s, $labelSwatch[$s], $foo[0]); + $this->elementEnd('li'); + $s++; + } + $this->elementEnd('ul'); - $this->element('div', array('id' => 'color-picker')); $this->elementEnd('fieldset'); - $this->submit('save', _('Save')); - +/*TODO: Check submitted form values: +json_encode(form values) +if submitted Swatch == DefaultSwatch, don't store in DB. +else store in BD +*/ $this->elementEnd('fieldset'); $this->elementEnd('form'); @@ -187,7 +204,7 @@ class DesignsettingsAction extends AccountSettingsAction /** - * Add the jCrop stylesheet + * Add the Farbtastic stylesheet * * @return void */ @@ -205,7 +222,7 @@ class DesignsettingsAction extends AccountSettingsAction } /** - * Add the jCrop scripts + * Add the Farbtastic scripts * * @return void */ @@ -214,14 +231,12 @@ class DesignsettingsAction extends AccountSettingsAction { parent::showScripts(); -// if ($this->mode == 'crop') { - $farbtasticPack = common_path('js/farbtastic/farbtastic.js'); - $farbtasticGo = common_path('js/farbtastic/farbtastic.go.js'); + $farbtasticPack = common_path('js/farbtastic/farbtastic.js'); + $farbtasticGo = common_path('js/farbtastic/farbtastic.go.js'); - $this->element('script', array('type' => 'text/javascript', - 'src' => $farbtasticPack)); - $this->element('script', array('type' => 'text/javascript', - 'src' => $farbtasticGo)); -// } + $this->element('script', array('type' => 'text/javascript', + 'src' => $farbtasticPack)); + $this->element('script', array('type' => 'text/javascript', + 'src' => $farbtasticGo)); } } diff --git a/js/farbtastic/farbtastic.go.js b/js/farbtastic/farbtastic.go.js index 21a1530bc..64dd7db20 100644 --- a/js/farbtastic/farbtastic.go.js +++ b/js/farbtastic/farbtastic.go.js @@ -1,10 +1,67 @@ $(document).ready(function() { - var f = $.farbtastic('#color-picker'); - var colors = $('#settings_design_color input'); + function UpdateColors(e) { + var S = f.linked; + var C = f.color; - colors - .each(function () { f.linkTo(this); }) - .focus(function() { - f.linkTo(this); + if (S && S.value && S.value != C) { + UpdateSwatch(S); + + switch (parseInt(f.linked.id.slice(-1))) { + case 1: default: + $('body').css({'background-color':C}); + break; + case 2: + $('#content').css({'background-color':C}); + break; + case 3: + $('#aside_primary').css({'background-color':C}); + break; + case 4: + $('body').css({'color':C}); + break; + case 5: + $('a').css({'color':C}); + break; + } + S.value = C; + } + } + + function UpdateFarbtastic(e) { + f.linked = e; + f.setColor(e.value); + } + + function UpdateSwatch(e) { + $(e).css({ + "background-color": e.value, + "color": f.hsl[2] > 0.5 ? "#000": "#fff" }); + } + + $('#settings_design_color').append('
      '); + $('#color-picker').hide(); + + var f = $.farbtastic('#color-picker', UpdateColors); + var swatches = $('#settings_design_color input'); + + swatches + .each(UpdateColors) + + .blur(function() { + $(this).val($(this).val().toUpperCase()); + }) + + .focus(function() { + $('#color-picker').show(); + UpdateFarbtastic(this); + }) + + .change(function() { + UpdateFarbtastic(this); + UpdateSwatch(this); + }).change() + + ; + }); -- cgit v1.2.3-54-g00ecf From 0271859c2425daff6fbaeac74aee6d6a9fcdce16 Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Mon, 18 May 2009 17:18:57 -0400 Subject: Added personal tag page: http://example.com/MY_NICK/tag/A_TAG --- actions/showstream.php | 7 ++++++- classes/Notice.php | 8 ++++---- classes/Profile.php | 54 ++++++++++++++++++++++++++++++++++++++++++++++--- classes/User.php | 11 +++++++++- lib/profileaction.php | 13 ++++++------ lib/router.php | 5 +++++ lib/tagcloudsection.php | 6 +++++- 7 files changed, 88 insertions(+), 16 deletions(-) diff --git a/actions/showstream.php b/actions/showstream.php index 82665e5b8..1654f589c 100644 --- a/actions/showstream.php +++ b/actions/showstream.php @@ -68,6 +68,9 @@ class ShowstreamAction extends ProfileAction } else { $base = $this->user->nickname; } + if (!empty($this->tag)) { + $base .= sprintf(_(' tagged %s'), $this->tag); + } if ($this->page == 1) { return $base; @@ -363,7 +366,9 @@ class ShowstreamAction extends ProfileAction function showNotices() { - $notice = $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); + $notice = empty($this->tag) + ? $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1) + : $this->user->getTaggedNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1, 0, 0, null, $this->tag); $pnl = new ProfileNoticeList($notice, $this); $cnt = $pnl->show(); diff --git a/classes/Notice.php b/classes/Notice.php index f6ac4f780..1b5c0ab0a 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1024,7 +1024,7 @@ class Notice extends Memcached_DataObject } } - function stream($fn, $args, $cachekey, $offset=0, $limit=20, $since_id=0, $before_id=0, $since=null) + function stream($fn, $args, $cachekey, $offset=0, $limit=20, $since_id=0, $before_id=0, $since=null, $tag=null) { $cache = common_memcache(); @@ -1032,7 +1032,7 @@ class Notice extends Memcached_DataObject $since_id != 0 || $before_id != 0 || !is_null($since) || ($offset + $limit) > NOTICE_CACHE_WINDOW) { return call_user_func_array($fn, array_merge($args, array($offset, $limit, $since_id, - $before_id, $since))); + $before_id, $since, $tag))); } $idkey = common_cache_key($cachekey); @@ -1052,7 +1052,7 @@ class Notice extends Memcached_DataObject $window = explode(',', $laststr); $last_id = $window[0]; $new_ids = call_user_func_array($fn, array_merge($args, array(0, NOTICE_CACHE_WINDOW, - $last_id, 0, null))); + $last_id, 0, null, $tag))); $new_window = array_merge($new_ids, $window); @@ -1067,7 +1067,7 @@ class Notice extends Memcached_DataObject } $window = call_user_func_array($fn, array_merge($args, array(0, NOTICE_CACHE_WINDOW, - 0, 0, null))); + 0, 0, null, $tag))); $windowstr = implode(',', $window); diff --git a/classes/Profile.php b/classes/Profile.php index ae5641d79..afc0ea4f7 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -153,18 +153,66 @@ class Profile extends Memcached_DataObject return null; } - function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0) + function getTaggedNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null, $tag=null) + { + // XXX: I'm not sure this is going to be any faster. It probably isn't. + $ids = Notice::stream(array($this, '_streamTaggedDirect'), + array(), + 'profile:notice_ids:' . $this->id, + $offset, $limit, $since_id, $before_id, $since, $tag); + common_debug(print_r($ids, true)); + return Notice::getStreamByIds($ids); + } + + function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null) { // XXX: I'm not sure this is going to be any faster. It probably isn't. $ids = Notice::stream(array($this, '_streamDirect'), array(), 'profile:notice_ids:' . $this->id, - $offset, $limit, $since_id, $before_id); + $offset, $limit, $since_id, $before_id, $since); return Notice::getStreamByIds($ids); } - function _streamDirect($offset, $limit, $since_id, $before_id, $since) + function _streamTaggedDirect($offset, $limit, $since_id, $before_id, $since=null, $tag=null) + { + common_debug('_streamTaggedDirect()'); + $notice = new Notice(); + $notice->profile_id = $this->id; + $query = "select id from notice join notice_tag on id=notice_id where tag='" . $notice->escape($tag) . "' and profile_id=" . $notice->escape($notice->profile_id); + if ($since_id != 0) { + $query .= " and id > $since_id"; + } + + if ($before_id != 0) { + $query .= " and id < $before_id"; + } + + if (!is_null($since)) { + $query .= " and created > '" . date('Y-m-d H:i:s', $since) . "'"; + } + + $query .= ' order by id DESC'; + + if (!is_null($offset)) { + $query .= " limit $offset, $limit"; + } + $notice->query($query); + $ids = array(); + + while ($notice->fetch()) { + common_debug(print_r($notice, true)); + $ids[] = $notice->id; + } + + return $ids; + } + + + + + function _streamDirect($offset, $limit, $since_id, $before_id, $since = null) { $notice = new Notice(); diff --git a/classes/User.php b/classes/User.php index b5ac7b220..ea8ba4081 100644 --- a/classes/User.php +++ b/classes/User.php @@ -407,13 +407,22 @@ class User extends Memcached_DataObject return Notice::getStreamByIds($ids); } + function getTaggedNotices($tag, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null) { + $profile = $this->getProfile(); + if (!$profile) { + return null; + } else { + return $profile->getTaggedNotices($tag, $offset, $limit, $since_id, $before_id, $since); + } + } + function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null) { $profile = $this->getProfile(); if (!$profile) { return null; } else { - return $profile->getNotices($offset, $limit, $since_id, $before_id); + return $profile->getNotices($offset, $limit, $since_id, $before_id, $since); } } diff --git a/lib/profileaction.php b/lib/profileaction.php index 1f2e30994..a3437ff4d 100644 --- a/lib/profileaction.php +++ b/lib/profileaction.php @@ -49,16 +49,17 @@ require_once INSTALLDIR.'/lib/groupminilist.php'; class ProfileAction extends Action { - var $user = null; - var $page = null; + var $user = null; + var $page = null; var $profile = null; + var $tag = null; function prepare($args) { parent::prepare($args); $nickname_arg = $this->arg('nickname'); - $nickname = common_canonical_nickname($nickname_arg); + $nickname = common_canonical_nickname($nickname_arg); // Permanent redirect on non-canonical nickname @@ -85,10 +86,9 @@ class ProfileAction extends Action return false; } + $this->tag = $this->trimmed('tag'); $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; - common_set_returnto($this->selfUrl()); - return true; } @@ -244,4 +244,5 @@ class ProfileAction extends Action $this->elementEnd('div'); } -} \ No newline at end of file +} + diff --git a/lib/router.php b/lib/router.php index 635e1d77e..f07e59373 100644 --- a/lib/router.php +++ b/lib/router.php @@ -426,6 +426,11 @@ class Router array('size' => '(original|96|48|24)', 'nickname' => '[a-zA-Z0-9]{1,64}')); + $m->connect(':nickname/tag/:tag', + array('action' => 'showstream'), + array('nickname' => '[a-zA-Z0-9]{1,64}'), + array('tag' => '[a-zA-Z0-9]+')); + $m->connect(':nickname', array('action' => 'showstream'), array('nickname' => '[a-zA-Z0-9]{1,64}')); diff --git a/lib/tagcloudsection.php b/lib/tagcloudsection.php index ff2aca6d6..62f7d8961 100644 --- a/lib/tagcloudsection.php +++ b/lib/tagcloudsection.php @@ -114,7 +114,11 @@ class TagCloudSection extends Section function tagUrl($tag) { - return common_local_url('tag', array('tag' => $tag)); + if ('showstream' === $this->out->trimmed('action')) { + return common_local_url('showstream', array('nickname' => $this->out->profile->nickname, 'tag' => $tag)); + } else { + return common_local_url('tag', array('tag' => $tag)); + } } function divId() -- cgit v1.2.3-54-g00ecf From f5606b6aa3868d777c6c697cf1bbc5348cb2ccc3 Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Mon, 18 May 2009 18:18:08 -0400 Subject: Added RSS for personal tags --- actions/showstream.php | 9 +++++++++ actions/userrss.php | 24 ++++++++++++++++++++++-- lib/router.php | 5 +++++ lib/rssaction.php | 6 +++++- 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/actions/showstream.php b/actions/showstream.php index 1654f589c..678a3174c 100644 --- a/actions/showstream.php +++ b/actions/showstream.php @@ -113,6 +113,15 @@ class ShowstreamAction extends ProfileAction function getFeeds() { + if (!empty($this->tag)) { + return array(new Feed(Feed::RSS1, + common_local_url('userrss', + array('nickname' => $this->user->nickname, + 'tag' => $this->tag)), + sprintf(_('Notice feed for %s tagged %s (RSS 1.0)'), + $this->user->nickname, $this->tag))); + } + return array(new Feed(Feed::RSS1, common_local_url('userrss', array('nickname' => $this->user->nickname)), diff --git a/actions/userrss.php b/actions/userrss.php index 5861d9ee3..2280509b2 100644 --- a/actions/userrss.php +++ b/actions/userrss.php @@ -25,14 +25,15 @@ require_once(INSTALLDIR.'/lib/rssaction.php'); class UserrssAction extends Rss10Action { - var $user = null; + var $tag = null; function prepare($args) { parent::prepare($args); - $nickname = $this->trimmed('nickname'); + $nickname = $this->trimmed('nickname'); $this->user = User::staticGet('nickname', $nickname); + $this->tag = $this->trimmed('tag'); if (!$this->user) { $this->clientError(_('No such user.')); @@ -42,6 +43,25 @@ class UserrssAction extends Rss10Action } } + function getTaggedNotices($tag = null, $limit=0) + { + $user = $this->user; + + if (is_null($user)) { + return null; + } + + $notice = $user->getTaggedNotices(0, ($limit == 0) ? NOTICES_PER_PAGE : $limit, 0, 0, null, $tag); + + $notices = array(); + while ($notice->fetch()) { + $notices[] = clone($notice); + } + + return $notices; + } + + function getNotices($limit=0) { diff --git a/lib/router.php b/lib/router.php index f07e59373..70ee0f3fb 100644 --- a/lib/router.php +++ b/lib/router.php @@ -426,6 +426,11 @@ class Router array('size' => '(original|96|48|24)', 'nickname' => '[a-zA-Z0-9]{1,64}')); + $m->connect(':nickname/tag/:tag/rss', + array('action' => 'userrss'), + array('nickname' => '[a-zA-Z0-9]{1,64}'), + array('tag' => '[a-zA-Z0-9]+')); + $m->connect(':nickname/tag/:tag', array('action' => 'showstream'), array('nickname' => '[a-zA-Z0-9]{1,64}'), diff --git a/lib/rssaction.php b/lib/rssaction.php index ddba862dc..2f25ed7e4 100644 --- a/lib/rssaction.php +++ b/lib/rssaction.php @@ -97,7 +97,11 @@ class Rss10Action extends Action // Parent handling, including cache check parent::handle($args); // Get the list of notices - $this->notices = $this->getNotices($this->limit); + if (empty($this->tag)) { + $this->notices = $this->getNotices($this->limit); + } else { + $this->notices = $this->getTaggedNotices($this->tag, $this->limit); + } $this->showRss(); } -- cgit v1.2.3-54-g00ecf From dcd69eec9098fd6bc6340a233796d6b242953057 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Mon, 18 May 2009 23:23:00 +0000 Subject: Increase entity_profile fn, nickname font-size slightly. Gave entity_profile more width. --- theme/base/css/display.css | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/theme/base/css/display.css b/theme/base/css/display.css index dc6b4bc29..8029a5eee 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -492,7 +492,7 @@ line-height:1.618; /* entity_profile */ .entity_profile { position:relative; -width:67.702%; +width:74.702%; min-height:123px; float:left; margin-bottom:18px; @@ -528,12 +528,15 @@ margin-bottom:4px; .entity_profile .entity_nickname { margin-left:11px; display:inline; -font-weight:bold; } .entity_profile .entity_nickname { margin-left:0; } - +.entity_profile .fn, +.entity_profile .nickname { +font-size:1.1em; +font-weight:bold; +} .entity_profile .entity_fn dd:before { content: "("; font-weight:normal; @@ -555,7 +558,7 @@ display:none; /*entity_actions*/ .entity_actions { float:right; -margin-left:4.35%; +margin-left:2.35%; max-width:25%; } .entity_actions h2 { -- cgit v1.2.3-54-g00ecf From 9261e48ef039869fb3709d374b7e4346d8773a49 Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Mon, 18 May 2009 19:23:18 -0400 Subject: Removed dead code. --- classes/File_redirection.php | 2 -- lib/noticelist.php | 4 ++-- lib/util.php | 5 ----- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/classes/File_redirection.php b/classes/File_redirection.php index a71d1c083..0eae68178 100644 --- a/classes/File_redirection.php +++ b/classes/File_redirection.php @@ -201,7 +201,6 @@ class File_redirection extends Memcached_DataObject if ($short_url) { $short_url = (string)$short_url; -if(1) { // store it $file = File::staticGet('url', $long_url); if (empty($file)) { @@ -221,7 +220,6 @@ if(1) { $file_redir->file_id = $file_id; $file_redir->insert(); } -} return $short_url; } return $long_url; diff --git a/lib/noticelist.php b/lib/noticelist.php index 55dd902b4..004905056 100644 --- a/lib/noticelist.php +++ b/lib/noticelist.php @@ -187,7 +187,7 @@ class NoticeListItem extends Widget function showNotice() { -if (0) +if(0) $this->out->elementStart('entry-title'); else @@ -236,7 +236,7 @@ else $clip .= '.png'; $top = '20px'; } -if (0) +if(0) $this->out->elementStart('div', 'entry-attachments'); else $this->out->elementStart('p', array('class' => 'entry-attachments', 'style' => "float: right; width: $width_att; background: url($clip) no-repeat; text-align: right; height: $height;")); diff --git a/lib/util.php b/lib/util.php index 25c0fb0a1..fbef8764a 100644 --- a/lib/util.php +++ b/lib/util.php @@ -496,11 +496,6 @@ function common_linkify($url) { } $attrs = array('href' => $longurl, 'rel' => 'external'); -if(0){ - if ($longurl !== $url) { - $attrs['title'] = $longurl; - } -} return XMLStringer::estring('a', $attrs, $display); } -- cgit v1.2.3-54-g00ecf From da74a29e0385042e974dbe50c03acd160f982e18 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Mon, 18 May 2009 23:45:45 +0000 Subject: Using list-style-position:inside for lists so that bullets don't leak out of the container. Added more padding to groups with most posts table --- theme/base/css/display.css | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/theme/base/css/display.css b/theme/base/css/display.css index 547752b51..eda04be77 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -639,6 +639,7 @@ margin-bottom:29px; clear:both; float:left; width:100%; +list-style-position:inside; } .aside .section h2 { text-transform:uppercase; @@ -662,6 +663,7 @@ list-style-type:none; float:left; margin-right:7px; margin-bottom:7px; +display:inline; } .section .entities li .photo { margin-right:0; @@ -1042,7 +1044,7 @@ margin-left:18px; /* TOP_POSTERS */ .section tbody td { -padding-right:11px; +padding-right:18px; padding-bottom:11px; } .section .vcard .photo { -- cgit v1.2.3-54-g00ecf From 8c5d1b63df63bdf73ef08f8b8c46699089939fc8 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Tue, 19 May 2009 00:09:06 +0000 Subject: Removed visited and vcard a background colors. --- theme/identica/css/display.css | 7 ------- 1 file changed, 7 deletions(-) diff --git a/theme/identica/css/display.css b/theme/identica/css/display.css index cc19da0f7..9d625848f 100644 --- a/theme/identica/css/display.css +++ b/theme/identica/css/display.css @@ -72,13 +72,6 @@ border-top-color:#CEE1E9; border-top-color:#87B4C8; } -#content .notice p.entry-content a:visited { -background-color:#fcfcfc; -} -#content .notice p.entry-content .vcard a { -background-color:#fcfffc; -} - #aside_primary { background-color:#CEE1E9; } -- cgit v1.2.3-54-g00ecf From 35b39342337fed5916e06876c8a37068d2052937 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 19 May 2009 01:07:45 +0000 Subject: Logout works properly now. --- plugins/FBConnect/FBConnectLogin.php | 9 +++---- plugins/FBConnect/FBConnectPlugin.php | 51 +++++++++++------------------------ 2 files changed, 20 insertions(+), 40 deletions(-) diff --git a/plugins/FBConnect/FBConnectLogin.php b/plugins/FBConnect/FBConnectLogin.php index a544352f3..c2a288571 100644 --- a/plugins/FBConnect/FBConnectLogin.php +++ b/plugins/FBConnect/FBConnectLogin.php @@ -254,6 +254,8 @@ class FBConnectloginAction extends Action function tryLogin() { + common_debug("Trying Facebook Login..."); + $flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_SERVICE); if ($flink) { @@ -261,7 +263,7 @@ class FBConnectloginAction extends Action if ($user) { - common_debug("Logged in Facebook user $flink->foreign_id as user $user->id"); + common_debug("Logged in Facebook user $flink->foreign_id as user $user->id ($user->nickname)"); common_set_user($user); common_real_login(true); @@ -284,6 +286,7 @@ class FBConnectloginAction extends Action array('nickname' => $nickname)); } + common_redirect($url, 303); } @@ -302,10 +305,6 @@ class FBConnectloginAction extends Action function bestNewNickname() { - - common_debug("bestNewNickname()"); - common_debug(print_r($this->fb_fields, true)); - if (!empty($this->fb_fields['name'])) { $nickname = $this->nicknamize($this->fb_fields['name']); if ($this->isNewNickname($nickname)) { diff --git a/plugins/FBConnect/FBConnectPlugin.php b/plugins/FBConnect/FBConnectPlugin.php index 30532e5ec..342a62492 100644 --- a/plugins/FBConnect/FBConnectPlugin.php +++ b/plugins/FBConnect/FBConnectPlugin.php @@ -67,10 +67,8 @@ class FBConnectPlugin extends Plugin $name = get_class($action); - common_debug("action: $name"); - // Avoid a redirect loop - if ($name != 'FBConnectloginAction') { + if (!in_array($name, array('FBConnectloginAction', 'ClientErrorAction'))) { $this->checkFacebookUser($action); @@ -122,7 +120,14 @@ class FBConnectPlugin extends Plugin $apikey = common_config('facebook', 'apikey'); $plugin_path = common_path('plugins/FBConnect'); - $login_url = common_get_returnto() || common_local_url('public'); + $url = common_get_returnto(); + + if ($url) { + // We don't have to return to it again + common_set_returnto(null); + } else { + $url = common_local_url('public'); + } $html = sprintf('', $apikey, $plugin_path, $login_url); + ', $apikey, $plugin_path, $url); $action->raw($html); @@ -203,11 +208,16 @@ class FBConnectPlugin extends Plugin function checkFacebookUser() { + $user = common_current_user(); + + if ($user) { + return; + } + try { $facebook = getFacebook(); $fbuid = $facebook->get_loggedin_user(); - $user = common_current_user(); // If you're a Facebook user and you're logged in do nothing @@ -244,35 +254,6 @@ class FBConnectPlugin extends Plugin } - function onStartLogout($action) - { - common_debug("onEndLogout()"); - - common_set_user(null); - common_real_login(false); // not logged in - common_forgetme(); // don't log back in! - - try { - - $facebook = getFacebook(); - $fbuid = $facebook->get_loggedin_user(); - - // XXX: ARGGGH this doesn't work right! - - if ($fbuid) { - $facebook->expire_session(); - $facebook->logout(common_local_url('public')); - } - - } catch (Exception $e) { - common_debug('Problem expiring FB session'); - } - - common_debug("logged out."); - - return false; - } - } -- cgit v1.2.3-54-g00ecf From 62d2229573f5191ed330dadb1637dfb12b62f590 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Tue, 19 May 2009 01:24:35 +0000 Subject: Removed visited and vcard background (matches identica theme) --- theme/default/css/display.css | 7 ------- 1 file changed, 7 deletions(-) diff --git a/theme/default/css/display.css b/theme/default/css/display.css index 1fc99eff7..e4b57ef49 100644 --- a/theme/default/css/display.css +++ b/theme/default/css/display.css @@ -72,13 +72,6 @@ border-top-color:#D1D9E4; border-top-color:#C3D6DF; } -#content .notice p.entry-content a:visited { -background-color:#fcfcfc; -} -#content .notice p.entry-content .vcard a { -background-color:#fcfffc; -} - #aside_primary { background-color:#CEE1E9; } -- cgit v1.2.3-54-g00ecf From 0c442e459e42b5d5aa168f7e2d3a0ff9f6bb0cd5 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Tue, 19 May 2009 17:05:30 +0000 Subject: Added reset button Rearranged swatch layout Added background image upload input file --- actions/designsettings.php | 36 ++++++++++++++++++++++++++++-------- js/farbtastic/farbtastic.go.js | 2 +- theme/base/css/display.css | 11 +++++++++++ 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/actions/designsettings.php b/actions/designsettings.php index 0deb3f684..a85b36a25 100644 --- a/actions/designsettings.php +++ b/actions/designsettings.php @@ -82,7 +82,16 @@ class DesignsettingsAction extends AccountSettingsAction $this->element('legend', null, _('Change background image')); $this->elementStart('ul', 'form_data'); $this->elementStart('li'); - $this->element('p', null, _('Upload background image')); + $this->element('label', array('for' => 'design_ background-image_file'), + _('Upload file')); + $this->element('input', array('name' => 'design_background-image_file', + 'type' => 'file', + 'id' => 'design_background-image_file')); + $this->element('p', 'form_guide', _('You can upload your personal background image. The maximum file size is 2Mb.')); + $this->element('input', array('name' => 'MAX_FILE_SIZE', + 'type' => 'hidden', + 'id' => 'MAX_FILE_SIZE', + 'value' => ImageFile::maxFileSizeInt())); $this->elementEnd('li'); $this->elementEnd('ul'); $this->elementEnd('fieldset'); @@ -108,15 +117,22 @@ class DesignsettingsAction extends AccountSettingsAction $userSwatch = ($userSwatch) ? json_decode($userSwatch, true) : $defaultSwatch; $s = 0; - $labelSwatch = array('Background color', - 'Content background color', - 'Sidebar background color', - 'Text color', - 'Link color'); + $labelSwatch = array('Background', + 'Content', + 'Sidebar', + 'Text', + 'Links'); foreach($userSwatch as $propertyvalue => $value) { - $foo = array_values($value); //Is this necessary? $value[0] doesn't work because of invalid key + $foo = array_values($value); $this->elementStart('li'); - $this->input("swatch-".$s, $labelSwatch[$s], $foo[0]); + $this->element('label', array('for' => 'swatch-'.$s), _($labelSwatch[$s])); + $this->element('input', array('name' => 'swatch-'.$s, //prefer swatch[$s] ? + 'type' => 'text', + 'id' => 'swatch-'.$s, + 'class' => 'swatch', + 'maxlength' => '7', + 'size' => '7', + 'value' => $foo[0])); $this->elementEnd('li'); $s++; } @@ -125,6 +141,10 @@ class DesignsettingsAction extends AccountSettingsAction $this->elementEnd('fieldset'); $this->submit('save', _('Save')); + $this->element('input', array('type' => 'reset', + 'value' => 'Reset', + 'class' => 'form_action-secondary')); + /*TODO: Check submitted form values: json_encode(form values) if submitted Swatch == DefaultSwatch, don't store in DB. diff --git a/js/farbtastic/farbtastic.go.js b/js/farbtastic/farbtastic.go.js index 64dd7db20..77e213513 100644 --- a/js/farbtastic/farbtastic.go.js +++ b/js/farbtastic/farbtastic.go.js @@ -43,7 +43,7 @@ $(document).ready(function() { $('#color-picker').hide(); var f = $.farbtastic('#color-picker', UpdateColors); - var swatches = $('#settings_design_color input'); + var swatches = $('#settings_design_color .swatch'); swatches .each(UpdateColors) diff --git a/theme/base/css/display.css b/theme/base/css/display.css index eda04be77..8bd0ae1c4 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -1161,6 +1161,17 @@ width:400px; margin-right:28px; } +#settings_design_color .form_data li { +width:33%; +} +#settings_design_color .form_data label { +float:none; +} +#settings_design_color .form_data .swatch { +padding:11px; +margin-left:0; +} + .instructions ul { list-style-position:inside; } -- cgit v1.2.3-54-g00ecf From 09e95cc33fb2228066d524e399bcc549e85eb565 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Tue, 19 May 2009 17:31:43 +0000 Subject: Fixed array index --- js/farbtastic/farbtastic.go.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/js/farbtastic/farbtastic.go.js b/js/farbtastic/farbtastic.go.js index 77e213513..e298c1dab 100644 --- a/js/farbtastic/farbtastic.go.js +++ b/js/farbtastic/farbtastic.go.js @@ -7,19 +7,19 @@ $(document).ready(function() { UpdateSwatch(S); switch (parseInt(f.linked.id.slice(-1))) { - case 1: default: + case 0: default: $('body').css({'background-color':C}); break; - case 2: + case 1: $('#content').css({'background-color':C}); break; - case 3: + case 2: $('#aside_primary').css({'background-color':C}); break; - case 4: + case 3: $('body').css({'color':C}); break; - case 5: + case 4: $('a').css({'color':C}); break; } -- cgit v1.2.3-54-g00ecf From f841dd6af4a0367f5589fa2b18a0043c0133cdd2 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Wed, 20 May 2009 00:55:59 +0000 Subject: Fixed sporatic problem with logout. --- plugins/FBConnect/FBConnectPlugin.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/plugins/FBConnect/FBConnectPlugin.php b/plugins/FBConnect/FBConnectPlugin.php index 342a62492..191cede76 100644 --- a/plugins/FBConnect/FBConnectPlugin.php +++ b/plugins/FBConnect/FBConnectPlugin.php @@ -120,22 +120,28 @@ class FBConnectPlugin extends Plugin $apikey = common_config('facebook', 'apikey'); $plugin_path = common_path('plugins/FBConnect'); - $url = common_get_returnto(); + $login_url = common_get_returnto(); - if ($url) { + if ($login_url) { // We don't have to return to it again common_set_returnto(null); } else { $url = common_local_url('public'); } + + $logout_url = common_local_url('logout'); $html = sprintf('', $apikey, $plugin_path, $url); + ', $apikey, $plugin_path, $login_url, $logout_url); $action->raw($html); @@ -170,8 +176,8 @@ class FBConnectPlugin extends Plugin $text = _('Logout'); $html = sprintf('
      ', - $logout_url, $title, $logout_url, $text); + 'onclick="FB.Connect.logout(function() { goto_logout() })">%s
    • ', + $logout_url, $title, $text); $action->raw($html); @@ -198,7 +204,7 @@ class FBConnectPlugin extends Plugin if (!$user) { $action->elementStart('li'); - $action->element('fb:login-button', array('onlogin' => 'refresh_page()', + $action->element('fb:login-button', array('onlogin' => 'goto_login()', 'length' => 'long')); $action->elementEnd('li'); } -- cgit v1.2.3-54-g00ecf From 8545a1c5fe65e056b4dd7fca5464cc927a43b38a Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Wed, 20 May 2009 06:46:11 +0000 Subject: Reorganized some stuff and made new Facebook Login tab --- plugins/FBConnect/FBCLoginGroupNav.php | 112 ++++++++++ plugins/FBConnect/FBConnectAuth.php | 370 +++++++++++++++++++++++++++++++++ plugins/FBConnect/FBConnectLogin.php | 358 +++---------------------------- plugins/FBConnect/FBConnectPlugin.php | 39 +++- 4 files changed, 544 insertions(+), 335 deletions(-) create mode 100644 plugins/FBConnect/FBCLoginGroupNav.php create mode 100644 plugins/FBConnect/FBConnectAuth.php diff --git a/plugins/FBConnect/FBCLoginGroupNav.php b/plugins/FBConnect/FBCLoginGroupNav.php new file mode 100644 index 000000000..9aa01a094 --- /dev/null +++ b/plugins/FBConnect/FBCLoginGroupNav.php @@ -0,0 +1,112 @@ +. + * + * @category Menu + * @package Laconica + * @author Evan Prodromou + * @author Zach Copley + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR . '/lib/widget.php'; + +/** + * Menu for login group of actions + * + * @category Output + * @package Laconica + * @author Evan Prodromou + * @author Zach Copley + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see Widget + */ + +class FBCLoginGroupNav extends Widget +{ + var $action = null; + + /** + * Construction + * + * @param Action $action current action, used for output + */ + + function __construct($action=null) + { + parent::__construct($action); + $this->action = $action; + } + + /** + * Show the menu + * + * @return void + */ + + function show() + { + common_debug('FBCLoginGroupNav'); + + $this->action->elementStart('dl', array('id' => 'site_nav_local_views')); + $this->action->element('dt', null, _('Local views')); + $this->action->elementStart('dd'); + + // action => array('prompt', 'title') + $menu = array(); + + $menu['login'] = array(_('Login'), + _('Login with a username and password')); + + if (!(common_config('site','closed') || common_config('site','inviteonly'))) { + $menu['register'] = array(_('Register'), + _('Sign up for a new account')); + } + + $menu['openidlogin'] = array(_('OpenID'), + _('Login or register with OpenID')); + + $menu['FBConnectLogin'] = array(_('Facebook'), + _('Login or register using Facebook')); + + $action_name = $this->action->trimmed('action'); + $this->action->elementStart('ul', array('class' => 'nav')); + + foreach ($menu as $menuaction => $menudesc) { + $this->action->menuItem(common_local_url($menuaction), + $menudesc[0], + $menudesc[1], + $action_name === $menuaction); + } + + $this->action->elementEnd('ul'); + + $this->action->elementEnd('dd'); + $this->action->elementEnd('dl'); + } +} diff --git a/plugins/FBConnect/FBConnectAuth.php b/plugins/FBConnect/FBConnectAuth.php new file mode 100644 index 000000000..0dc016c05 --- /dev/null +++ b/plugins/FBConnect/FBConnectAuth.php @@ -0,0 +1,370 @@ +. + * + * @category Plugin + * @package Laconica + * @author Zach Copley + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +require_once INSTALLDIR . '/plugins/FBConnect/FBConnectPlugin.php'; + +class FbconnectauthAction extends Action +{ + + var $fbuid = null; + var $fb_fields = null; + + function prepare($args) { + parent::prepare($args); + + $this->fbuid = getFacebook()->get_loggedin_user(); + $this->fb_fields = $this->getFacebookFields($this->fbuid, + array('first_name', 'last_name', 'name')); + + return true; + } + + function handle($args) + { + parent::handle($args); + + if (common_is_real_login()) { + $this->clientError(_('Already logged in.')); + } else if ($_SERVER['REQUEST_METHOD'] == 'POST') { + $token = $this->trimmed('token'); + if (!$token || $token != common_session_token()) { + $this->showForm(_('There was a problem with your session token. Try again, please.')); + return; + } + if ($this->arg('create')) { + if (!$this->boolean('license')) { + $this->showForm(_('You can\'t register if you don\'t agree to the license.'), + $this->trimmed('newname')); + return; + } + $this->createNewUser(); + } else if ($this->arg('connect')) { + $this->connectUser(); + } else { + common_debug(print_r($this->args, true), __FILE__); + $this->showForm(_('Something weird happened.'), + $this->trimmed('newname')); + } + } else { + $this->tryLogin(); + } + } + + function showPageNotice() + { + if ($this->error) { + $this->element('div', array('class' => 'error'), $this->error); + } else { + $this->element('div', 'instructions', + sprintf(_('This is the first time you\'ve logged into %s so we must connect your Facebook to a local account. You can either create a new account, or connect with your existing account, if you have one.'), common_config('site', 'name'))); + } + } + + function title() + { + return _('Facebook Account Setup'); + } + + function showForm($error=null, $username=null) + { + $this->error = $error; + $this->username = $username; + + $this->showPage(); + } + + function showPage() + { + parent::showPage(); + } + + function showContent() + { + if (!empty($this->message_text)) { + $this->element('p', null, $this->message); + return; + } + + $this->elementStart('form', array('method' => 'post', + 'id' => 'account_connect', + 'action' => common_local_url('fbconnectlogin'))); + $this->hidden('token', common_session_token()); + $this->element('h2', null, + _('Create new account')); + $this->element('p', null, + _('Create a new user with this nickname.')); + $this->input('newname', _('New nickname'), + ($this->username) ? $this->username : '', + _('1-64 lowercase letters or numbers, no punctuation or spaces')); + $this->elementStart('p'); + $this->element('input', array('type' => 'checkbox', + 'id' => 'license', + 'name' => 'license', + 'value' => 'true')); + $this->text(_('My text and files are available under ')); + $this->element('a', array('href' => common_config('license', 'url')), + common_config('license', 'title')); + $this->text(_(' except this private data: password, email address, IM address, phone number.')); + $this->elementEnd('p'); + $this->submit('create', _('Create')); + $this->element('h2', null, + _('Connect existing account')); + $this->element('p', null, + _('If you already have an account, login with your username and password to connect it to your Facebook.')); + $this->input('nickname', _('Existing nickname')); + $this->password('password', _('Password')); + $this->submit('connect', _('Connect')); + $this->elementEnd('form'); + } + + function message($msg) + { + $this->message_text = $msg; + $this->showPage(); + } + + function createNewUser() + { + + if (common_config('site', 'closed')) { + $this->clientError(_('Registration not allowed.')); + return; + } + + $invite = null; + + if (common_config('site', 'inviteonly')) { + $code = $_SESSION['invitecode']; + if (empty($code)) { + $this->clientError(_('Registration not allowed.')); + return; + } + + $invite = Invitation::staticGet($code); + + if (empty($invite)) { + $this->clientError(_('Not a valid invitation code.')); + return; + } + } + + $nickname = $this->trimmed('newname'); + + if (!Validate::string($nickname, array('min_length' => 1, + 'max_length' => 64, + 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) { + $this->showForm(_('Nickname must have only lowercase letters and numbers and no spaces.')); + return; + } + + if (!User::allowed_nickname($nickname)) { + $this->showForm(_('Nickname not allowed.')); + return; + } + + if (User::staticGet('nickname', $nickname)) { + $this->showForm(_('Nickname already in use. Try another one.')); + return; + } + + $fullname = trim($this->fb_fields['firstname'] . + ' ' . $this->fb_fields['lastname']); + + $args = array('nickname' => $nickname, 'fullname' => $fullname); + + if (!empty($invite)) { + $args['code'] = $invite->code; + } + + $user = User::register($args); + + $result = $this->flinkUser($user->id, $this->fbuid); + + if (!$result) { + $this->serverError(_('Error connecting user to Facebook.')); + return; + } + + common_set_user($user); + common_real_login(true); + + common_debug("Registered new user $user->id from Facebook user $this->fbuid"); + + common_redirect(common_local_url('showstream', array('nickname' => $user->nickname)), + 303); + } + + function connectUser() + { + $nickname = $this->trimmed('nickname'); + $password = $this->trimmed('password'); + + if (!common_check_user($nickname, $password)) { + $this->showForm(_('Invalid username or password.')); + return; + } + + $user = User::staticGet('nickname', $nickname); + + if ($user) { + common_debug("Legit user to connect to Facebook: $nickname"); + } + + $result = $this->flinkUser($user->id, $this->fbuid); + + if (!$result) { + $this->serverError(_('Error connecting user to Facebook.')); + return; + } + + common_debug("Connected Facebook user $this->fbuid to local user $user->id"); + + common_set_user($user); + common_real_login(true); + + $this->goHome($user->nickname); + } + + function tryLogin() + { + common_debug("Trying Facebook Login..."); + + $flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_SERVICE); + + if ($flink) { + $user = $flink->getUser(); + + if ($user) { + + common_debug("Logged in Facebook user $flink->foreign_id as user $user->id ($user->nickname)"); + + common_set_user($user); + common_real_login(true); + $this->goHome($user->nickname); + } + + } else { + $this->showForm(null, $this->bestNewNickname()); + } + } + + function goHome($nickname) + { + $url = common_get_returnto(); + if ($url) { + // We don't have to return to it again + common_set_returnto(null); + } else { + $url = common_local_url('all', + array('nickname' => + $nickname)); + } + + common_redirect($url, 303); + } + + function flinkUser($user_id, $fbuid) + { + $flink = new Foreign_link(); + $flink->user_id = $user_id; + $flink->foreign_id = $fbuid; + $flink->service = FACEBOOK_SERVICE; + $flink->created = common_sql_now(); + + $flink_id = $flink->insert(); + + return $flink_id; + } + + function bestNewNickname() + { + if (!empty($this->fb_fields['name'])) { + $nickname = $this->nicknamize($this->fb_fields['name']); + if ($this->isNewNickname($nickname)) { + return $nickname; + } + } + + // Try the full name + + $fullname = trim($this->fb_fields['firstname'] . + ' ' . $this->fb_fields['lastname']); + + if (!empty($fullname)) { + $fullname = $this->nicknamize($fullname); + if ($this->isNewNickname($fullname)) { + return $fullname; + } + } + + return null; + } + + // Given a string, try to make it work as a nickname + + function nicknamize($str) + { + $str = preg_replace('/\W/', '', $str); + return strtolower($str); + } + + function isNewNickname($str) + { + if (!Validate::string($str, array('min_length' => 1, + 'max_length' => 64, + 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) { + return false; + } + if (!User::allowed_nickname($str)) { + return false; + } + if (User::staticGet('nickname', $str)) { + return false; + } + return true; + } + + // XXX: Consider moving this to lib/facebookutil.php + function getFacebookFields($fb_uid, $fields) { + try { + $infos = getFacebook()->api_client->users_getInfo($fb_uid, $fields); + + if (empty($infos)) { + return null; + } + return reset($infos); + + } catch (Exception $e) { + error_log("Failure in the api when requesting " . join(",", $fields) + ." on uid " . $fb_uid . " : ". $e->getMessage()); + return null; + } + } + +} diff --git a/plugins/FBConnect/FBConnectLogin.php b/plugins/FBConnect/FBConnectLogin.php index c2a288571..70710eb70 100644 --- a/plugins/FBConnect/FBConnectLogin.php +++ b/plugins/FBConnect/FBConnectLogin.php @@ -1,12 +1,9 @@ . - * - * @category Plugin - * @package Laconica - * @author Zach Copley - * @copyright 2009 Control Yourself, Inc. - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://laconi.ca/ */ -require_once INSTALLDIR . '/plugins/FBConnect/FBConnectLogin.php'; -require_once INSTALLDIR . '/lib/facebookutil.php'; - -class FBConnectloginAction extends Action -{ - - var $fbuid = null; - var $fb_fields = null; - - function prepare($args) { - parent::prepare($args); +if (!defined('LACONICA')) { + exit(1); +} - $this->fbuid = getFacebook()->get_loggedin_user(); - $this->fb_fields = $this->getFacebookFields($this->fbuid, - array('first_name', 'last_name', 'name')); - - return true; - } +require_once INSTALLDIR . '/plugins/FBConnect/FBConnectPlugin.php'; +class FBConnectLoginAction extends Action +{ function handle($args) { parent::handle($args); if (common_is_real_login()) { $this->clientError(_('Already logged in.')); - } else if ($_SERVER['REQUEST_METHOD'] == 'POST') { - $token = $this->trimmed('token'); - if (!$token || $token != common_session_token()) { - $this->showForm(_('There was a problem with your session token. Try again, please.')); - return; - } - if ($this->arg('create')) { - if (!$this->boolean('license')) { - $this->showForm(_('You can\'t register if you don\'t agree to the license.'), - $this->trimmed('newname')); - return; - } - $this->createNewUser(); - } else if ($this->arg('connect')) { - $this->connectUser(); - } else { - common_debug(print_r($this->args, true), __FILE__); - $this->showForm(_('Something weird happened.'), - $this->trimmed('newname')); - } - } else { - $this->tryLogin(); - } - } - - function showPageNotice() - { - if ($this->error) { - $this->element('div', array('class' => 'error'), $this->error); - } else { - $this->element('div', 'instructions', - sprintf(_('This is the first time you\'ve logged into %s so we must connect your Facebook to a local account. You can either create a new account, or connect with your existing account, if you have one.'), common_config('site', 'name'))); - } - } - - function title() - { - return _('Facebook Account Setup'); - } - - function showForm($error=null, $username=null) - { - $this->error = $error; - $this->username = $username; - - $this->showPage(); - } - - function showPage() - { - parent::showPage(); - } - - function showContent() - { - if (!empty($this->message_text)) { - $this->element('p', null, $this->message); - return; - } - - $this->elementStart('form', array('method' => 'post', - 'id' => 'account_connect', - 'action' => common_local_url('fbconnectlogin'))); - $this->hidden('token', common_session_token()); - $this->element('h2', null, - _('Create new account')); - $this->element('p', null, - _('Create a new user with this nickname.')); - $this->input('newname', _('New nickname'), - ($this->username) ? $this->username : '', - _('1-64 lowercase letters or numbers, no punctuation or spaces')); - $this->elementStart('p'); - $this->element('input', array('type' => 'checkbox', - 'id' => 'license', - 'name' => 'license', - 'value' => 'true')); - $this->text(_('My text and files are available under ')); - $this->element('a', array('href' => common_config('license', 'url')), - common_config('license', 'title')); - $this->text(_(' except this private data: password, email address, IM address, phone number.')); - $this->elementEnd('p'); - $this->submit('create', _('Create')); - $this->element('h2', null, - _('Connect existing account')); - $this->element('p', null, - _('If you already have an account, login with your username and password to connect it to your Facebook.')); - $this->input('nickname', _('Existing nickname')); - $this->password('password', _('Password')); - $this->submit('connect', _('Connect')); - $this->elementEnd('form'); - } - - function message($msg) - { - $this->message_text = $msg; + } + $this->showPage(); } - function createNewUser() - { - - if (common_config('site', 'closed')) { - $this->clientError(_('Registration not allowed.')); - return; - } - - $invite = null; - - if (common_config('site', 'inviteonly')) { - $code = $_SESSION['invitecode']; - if (empty($code)) { - $this->clientError(_('Registration not allowed.')); - return; - } - - $invite = Invitation::staticGet($code); - - if (empty($invite)) { - $this->clientError(_('Not a valid invitation code.')); - return; - } - } - - $nickname = $this->trimmed('newname'); - - if (!Validate::string($nickname, array('min_length' => 1, - 'max_length' => 64, - 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) { - $this->showForm(_('Nickname must have only lowercase letters and numbers and no spaces.')); - return; - } - - if (!User::allowed_nickname($nickname)) { - $this->showForm(_('Nickname not allowed.')); - return; - } - - if (User::staticGet('nickname', $nickname)) { - $this->showForm(_('Nickname already in use. Try another one.')); - return; - } - - $fullname = trim($this->fb_fields['firstname'] . - ' ' . $this->fb_fields['lastname']); - - $args = array('nickname' => $nickname, 'fullname' => $fullname); - - if (!empty($invite)) { - $args['code'] = $invite->code; - } - - $user = User::register($args); - - $result = $this->flinkUser($user->id, $this->fbuid); - - if (!$result) { - $this->serverError(_('Error connecting user to Facebook.')); - return; - } - - common_set_user($user); - common_real_login(true); - - common_debug("Registered new user $user->id from Facebook user $this->fbuid"); - - common_redirect(common_local_url('showstream', array('nickname' => $user->nickname)), - 303); - } - - function connectUser() - { - $nickname = $this->trimmed('nickname'); - $password = $this->trimmed('password'); - - if (!common_check_user($nickname, $password)) { - $this->showForm(_('Invalid username or password.')); - return; - } - - $user = User::staticGet('nickname', $nickname); - - if ($user) { - common_debug("Legit user to connect to Facebook: $nickname"); - } - - $result = $this->flinkUser($user->id, $this->fbuid); - - if (!$result) { - $this->serverError(_('Error connecting user to Facebook.')); - return; - } - - common_debug("Connected Facebook user $this->fbuid to local user $user->id"); - - common_set_user($user); - common_real_login(true); - - $this->goHome($user->nickname); - } - - function tryLogin() + function getInstructions() { - common_debug("Trying Facebook Login..."); - - $flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_SERVICE); - - if ($flink) { - $user = $flink->getUser(); - - if ($user) { - - common_debug("Logged in Facebook user $flink->foreign_id as user $user->id ($user->nickname)"); - - common_set_user($user); - common_real_login(true); - $this->goHome($user->nickname); - } - - } else { - $this->showForm(null, $this->bestNewNickname()); - } + return _('Login with your Facebook Account'); } - function goHome($nickname) - { - $url = common_get_returnto(); - if ($url) { - // We don't have to return to it again - common_set_returnto(null); - } else { - $url = common_local_url('all', - array('nickname' => - $nickname)); - } - - common_redirect($url, 303); - } - - function flinkUser($user_id, $fbuid) + function showPageNotice() { - $flink = new Foreign_link(); - $flink->user_id = $user_id; - $flink->foreign_id = $fbuid; - $flink->service = FACEBOOK_SERVICE; - $flink->created = common_sql_now(); - - $flink_id = $flink->insert(); - - return $flink_id; + $instr = $this->getInstructions(); + $output = common_markup_to_html($instr); + $this->elementStart('div', 'instructions'); + $this->raw($output); + $this->elementEnd('div'); } - function bestNewNickname() + function title() { - if (!empty($this->fb_fields['name'])) { - $nickname = $this->nicknamize($this->fb_fields['name']); - if ($this->isNewNickname($nickname)) { - return $nickname; - } - } - - // Try the full name - - $fullname = trim($this->fb_fields['firstname'] . - ' ' . $this->fb_fields['lastname']); - - if (!empty($fullname)) { - $fullname = $this->nicknamize($fullname); - if ($this->isNewNickname($fullname)) { - return $fullname; - } - } - - return null; + return _('Facebook Login'); } - // Given a string, try to make it work as a nickname - - function nicknamize($str) - { - $str = preg_replace('/\W/', '', $str); - return strtolower($str); - } - - function isNewNickname($str) - { - if (!Validate::string($str, array('min_length' => 1, - 'max_length' => 64, - 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) { - return false; - } - if (!User::allowed_nickname($str)) { - return false; - } - if (User::staticGet('nickname', $str)) { - return false; - } - return true; - } + function showContent() { - // XXX: Consider moving this to lib/facebookutil.php - function getFacebookFields($fb_uid, $fields) { - try { - $infos = getFacebook()->api_client->users_getInfo($fb_uid, $fields); + $this->elementStart('fieldset'); + - if (empty($infos)) { - return null; - } - return reset($infos); + $this->element('fb:login-button', array('onlogin' => 'goto_login()', + 'length' => 'long')); - } catch (Exception $e) { - error_log("Failure in the api when requesting " . join(",", $fields) - ." on uid " . $fb_uid . " : ". $e->getMessage()); - return null; - } + $this->elementEnd('fieldset'); } } diff --git a/plugins/FBConnect/FBConnectPlugin.php b/plugins/FBConnect/FBConnectPlugin.php index 191cede76..079270510 100644 --- a/plugins/FBConnect/FBConnectPlugin.php +++ b/plugins/FBConnect/FBConnectPlugin.php @@ -31,8 +31,10 @@ if (!defined('LACONICA')) { exit(1); } -require_once INSTALLDIR . '/plugins/FBConnect/FBConnectLogin.php'; require_once INSTALLDIR . '/lib/facebookutil.php'; +require_once INSTALLDIR . '/plugins/FBConnect/FBConnectAuth.php'; +require_once INSTALLDIR . '/plugins/FBConnect/FBConnectLogin.php'; +require_once INSTALLDIR . '/plugins/FBConnect/FBCLoginGroupNav.php'; /** * Plugin to enable Facebook Connect @@ -54,7 +56,11 @@ class FBConnectPlugin extends Plugin // Hook in new actions function onRouterInitialized(&$m) { - $m->connect('main/facebookconnect', array('action' => 'fbconnectlogin')); + + common_debug("onRouterIntialized()"); + + $m->connect('main/facebookconnect', array('action' => 'FBConnectAuth')); + $m->connect('main/facebooklogin', array('action' => 'FBConnectLogin')); } // Add in xmlns:fb @@ -67,8 +73,10 @@ class FBConnectPlugin extends Plugin $name = get_class($action); + common_debug("onStartShowHTML: action = $name"); + // Avoid a redirect loop - if (!in_array($name, array('FBConnectloginAction', 'ClientErrorAction'))) { + if (!in_array($name, array('FBConnectAuthAction', 'ClientErrorAction'))) { $this->checkFacebookUser($action); @@ -246,7 +254,7 @@ class FBConnectPlugin extends Plugin } else { common_debug("Facebook user is NOT logged in."); - common_redirect(common_local_url('fbconnectlogin'), 303); + common_redirect(common_local_url('FBConnectAuth'), 303); } } else { @@ -259,7 +267,28 @@ class FBConnectPlugin extends Plugin } } - + + function onStartShowLocalNavBlock($action) + { + $action_name = get_class($action); + + common_debug($action_name); + + $login_actions = array('LoginAction', 'RegisterAction', + 'OpenidloginAction', 'FacebookStart'); + + if (in_array($action_name, $login_actions)) { + + common_debug("LoginAction found!"); + + $nav = new FBCLoginGroupNav($action); + $nav->show(); + return false; + } + + return true; + + } } -- cgit v1.2.3-54-g00ecf From dbf82f7c1e995f25de6ed2c80b49677118df1a35 Mon Sep 17 00:00:00 2001 From: Eric Helgeson Date: Wed, 20 May 2009 15:14:04 -0500 Subject: fixed missing closing php tag when installer.php wrote to config.php --- install.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/install.php b/install.php index 32915200b..a25f69467 100644 --- a/install.php +++ b/install.php @@ -260,7 +260,8 @@ function writeConf($sitename, $sqlUrl, $fancy, $path) "\$config['site']['name'] = \"$sitename\";\n\n". ($fancy ? "\$config['site']['fancy'] = true;\n\n":''). "\$config['site']['path'] = \"$path\";\n\n". - "\$config['db']['database'] = \"$sqlUrl\";\n\n"); + "\$config['db']['database'] = \"$sqlUrl\";\n\n". + "?>"); return $res; } -- cgit v1.2.3-54-g00ecf From a3280961d2d92724dcdb451192450662f26eee8e Mon Sep 17 00:00:00 2001 From: Eric Helgeson Date: Wed, 20 May 2009 16:39:08 -0500 Subject: Removed return from 1st line of runDbScript() fixed broken html tag on success page. handlePost() now will show as many errors as it can (instead of one at a time) checkPrereqs() will show all errors at once instead of failing on first one, installer will be able to try to fix all instead of fixing one at a time and trying again. writeConf(): added if LACONICA is !defined exit Tests: drop database and remove config.php, ran installer. Passed. --- install.php | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/install.php b/install.php index a25f69467..bc82e5e37 100644 --- a/install.php +++ b/install.php @@ -35,15 +35,17 @@ function main() function checkPrereqs() { + $pass = true; + if (file_exists(INSTALLDIR.'/config.php')) { ?>

      Config file "config.php" already exists.

      Require PHP version 5 or greater.

      Cannot load required extension:

      Cannot write config file to:

      On your server, try this command: chmod a+w

      Cannot write avatar directory: /avatar/

      On your server, try this command: chmod a+w /avatar/

        new Laconica sitenew Laconica site."); ?> Date: Wed, 20 May 2009 22:08:08 +0000 Subject: Preserve order of imported Tweets --- scripts/twitterstatusfetcher.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/twitterstatusfetcher.php b/scripts/twitterstatusfetcher.php index 9dfadc760..a61ce1b0d 100755 --- a/scripts/twitterstatusfetcher.php +++ b/scripts/twitterstatusfetcher.php @@ -214,7 +214,8 @@ class TwitterStatusFetcher extends Daemon return; } - foreach ($timeline as $status) { + // Reverse to preserve order + foreach (array_reverse($timeline) as $status) { // Hacktastic: filter out stuff coming from this Laconica $source = mb_strtolower(common_config('integration', 'source')); -- cgit v1.2.3-54-g00ecf From b561962b59e8194e6622f87394e7b8565d78c182 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Wed, 20 May 2009 23:11:35 +0000 Subject: Color picker reset: Resetting form values will also dynamically update the page colors back to their original. --- actions/designsettings.php | 3 +- js/farbtastic/farbtastic.go.js | 108 ++++++++++++++++++++++------------------- 2 files changed, 61 insertions(+), 50 deletions(-) diff --git a/actions/designsettings.php b/actions/designsettings.php index a85b36a25..8a7c26104 100644 --- a/actions/designsettings.php +++ b/actions/designsettings.php @@ -141,7 +141,8 @@ class DesignsettingsAction extends AccountSettingsAction $this->elementEnd('fieldset'); $this->submit('save', _('Save')); - $this->element('input', array('type' => 'reset', + $this->element('input', array('id' => 'settings_design_reset', + 'type' => 'reset', 'value' => 'Reset', 'class' => 'form_action-secondary')); diff --git a/js/farbtastic/farbtastic.go.js b/js/farbtastic/farbtastic.go.js index e298c1dab..6a0a5c56b 100644 --- a/js/farbtastic/farbtastic.go.js +++ b/js/farbtastic/farbtastic.go.js @@ -1,29 +1,22 @@ $(document).ready(function() { - function UpdateColors(e) { - var S = f.linked; - var C = f.color; - - if (S && S.value && S.value != C) { - UpdateSwatch(S); - - switch (parseInt(f.linked.id.slice(-1))) { - case 0: default: - $('body').css({'background-color':C}); - break; - case 1: - $('#content').css({'background-color':C}); - break; - case 2: - $('#aside_primary').css({'background-color':C}); - break; - case 3: - $('body').css({'color':C}); - break; - case 4: - $('a').css({'color':C}); - break; - } - S.value = C; + function UpdateColors(S) { + C = $(S).val(); + switch (parseInt(S.id.slice(-1))) { + case 0: default: + $('body').css({'background-color':C}); + break; + case 1: + $('#content').css({'background-color':C}); + break; + case 2: + $('#aside_primary').css({'background-color':C}); + break; + case 3: + $('body').css({'color':C}); + break; + case 4: + $('a').css({'color':C}); + break; } } @@ -33,35 +26,52 @@ $(document).ready(function() { } function UpdateSwatch(e) { - $(e).css({ - "background-color": e.value, - "color": f.hsl[2] > 0.5 ? "#000": "#fff" - }); + $(e).css({"background-color": e.value, + "color": f.hsl[2] > 0.5 ? "#000": "#fff"}); } - $('#settings_design_color').append('
        '); - $('#color-picker').hide(); - - var f = $.farbtastic('#color-picker', UpdateColors); - var swatches = $('#settings_design_color .swatch'); - - swatches - .each(UpdateColors) + function SynchColors(e) { + var S = f.linked; + var C = f.color; - .blur(function() { - $(this).val($(this).val().toUpperCase()); - }) + if (S && S.value && S.value != C) { + S.value = C; + UpdateSwatch(S); + UpdateColors(S); + } + } - .focus(function() { - $('#color-picker').show(); - UpdateFarbtastic(this); - }) + function Init() { + $('#settings_design_color').append('
        '); + $('#color-picker').hide(); - .change(function() { - UpdateFarbtastic(this); - UpdateSwatch(this); - }).change() + f = $.farbtastic('#color-picker', SynchColors); + swatches = $('#settings_design_color .swatch'); - ; + swatches + .each(SynchColors) + .blur(function() { + $(this).val($(this).val().toUpperCase()); + }) + .focus(function() { + $('#color-picker').show(); + UpdateFarbtastic(this); + }) + .change(function() { + UpdateFarbtastic(this); + UpdateSwatch(this); + UpdateColors(this); + }).change(); + } + var f, swatches; + Init(); + $('#form_settings_design').bind('reset', function(){ + setTimeout(function(){ + swatches.each(function(){UpdateColors(this);}); + $('#color-picker').remove(); + swatches.unbind(); + Init(); + },10); + }); }); -- cgit v1.2.3-54-g00ecf From b23d4230811db02266b9df0a3cefc5e54c36d169 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Wed, 20 May 2009 23:37:20 +0000 Subject: Added licensing information for jcrop.go and farbtastic.go scripts --- js/farbtastic/farbtastic.go.js | 8 +++++ js/jcrop/jquery.Jcrop.go.js | 77 +++++++++++++++++++++++------------------- 2 files changed, 51 insertions(+), 34 deletions(-) diff --git a/js/farbtastic/farbtastic.go.js b/js/farbtastic/farbtastic.go.js index 6a0a5c56b..0149eca7d 100644 --- a/js/farbtastic/farbtastic.go.js +++ b/js/farbtastic/farbtastic.go.js @@ -1,3 +1,11 @@ +/** Init for Farbtastic library and page setup + * + * @package Laconica + * @author Sarven Capadisli + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ $(document).ready(function() { function UpdateColors(S) { C = $(S).val(); diff --git a/js/jcrop/jquery.Jcrop.go.js b/js/jcrop/jquery.Jcrop.go.js index a0399d540..4e1cbfd1e 100644 --- a/js/jcrop/jquery.Jcrop.go.js +++ b/js/jcrop/jquery.Jcrop.go.js @@ -1,39 +1,48 @@ - $(function(){ - var x = ($('#avatar_crop_x').val()) ? $('#avatar_crop_x').val() : 0; - var y = ($('#avatar_crop_y').val()) ? $('#avatar_crop_y').val() : 0; - var w = ($('#avatar_crop_w').val()) ? $('#avatar_crop_w').val() : $("#avatar_original img").attr("width"); - var h = ($('#avatar_crop_h').val()) ? $('#avatar_crop_h').val() : $("#avatar_original img").attr("height"); +/** Init for Jcrop library and page setup + * + * @package Laconica + * @author Sarven Capadisli + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ - jQuery("#avatar_original img").Jcrop({ - onChange: showPreview, - setSelect: [ x, y, w, h ], - onSelect: updateCoords, - aspectRatio: 1, - boxWidth: 480, - boxHeight: 480, - bgColor: '#000', - bgOpacity: .4 - }); - }); +$(function(){ + var x = ($('#avatar_crop_x').val()) ? $('#avatar_crop_x').val() : 0; + var y = ($('#avatar_crop_y').val()) ? $('#avatar_crop_y').val() : 0; + var w = ($('#avatar_crop_w').val()) ? $('#avatar_crop_w').val() : $("#avatar_original img").attr("width"); + var h = ($('#avatar_crop_h').val()) ? $('#avatar_crop_h').val() : $("#avatar_original img").attr("height"); - function showPreview(coords) { - var rx = 96 / coords.w; - var ry = 96 / coords.h; + jQuery("#avatar_original img").Jcrop({ + onChange: showPreview, + setSelect: [ x, y, w, h ], + onSelect: updateCoords, + aspectRatio: 1, + boxWidth: 480, + boxHeight: 480, + bgColor: '#000', + bgOpacity: .4 + }); +}); - var img_width = $("#avatar_original img").attr("width"); - var img_height = $("#avatar_original img").attr("height"); +function showPreview(coords) { + var rx = 96 / coords.w; + var ry = 96 / coords.h; - $('#avatar_preview img').css({ - width: Math.round(rx *img_width) + 'px', - height: Math.round(ry * img_height) + 'px', - marginLeft: '-' + Math.round(rx * coords.x) + 'px', - marginTop: '-' + Math.round(ry * coords.y) + 'px' - }); - }; + var img_width = $("#avatar_original img").attr("width"); + var img_height = $("#avatar_original img").attr("height"); - function updateCoords(c) { - $('#avatar_crop_x').val(c.x); - $('#avatar_crop_y').val(c.y); - $('#avatar_crop_w').val(c.w); - $('#avatar_crop_h').val(c.h); - }; + $('#avatar_preview img').css({ + width: Math.round(rx *img_width) + 'px', + height: Math.round(ry * img_height) + 'px', + marginLeft: '-' + Math.round(rx * coords.x) + 'px', + marginTop: '-' + Math.round(ry * coords.y) + 'px' + }); +}; + +function updateCoords(c) { + $('#avatar_crop_x').val(c.x); + $('#avatar_crop_y').val(c.y); + $('#avatar_crop_w').val(c.w); + $('#avatar_crop_h').val(c.h); +}; -- cgit v1.2.3-54-g00ecf From 56a8a255fff0037c29db09d4abf6631e9c45c730 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 21 May 2009 00:12:48 +0000 Subject: Changed No/Yes and Reset/Save locations. They are now a little more usable by first offering the option to undo and than do. --- actions/deletenotice.php | 4 ++-- actions/designsettings.php | 5 +++-- theme/base/css/display.css | 4 +++- theme/default/css/display.css | 4 ++-- theme/identica/css/display.css | 4 ++-- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/actions/deletenotice.php b/actions/deletenotice.php index 6c350b33a..e733f9650 100644 --- a/actions/deletenotice.php +++ b/actions/deletenotice.php @@ -112,8 +112,8 @@ class DeletenoticeAction extends DeleteAction $this->hidden('token', common_session_token()); $this->hidden('notice', $this->trimmed('notice')); $this->element('p', null, _('Are you sure you want to delete this notice?')); - $this->submit('form_action-yes', _('Yes'), 'submit form_action-primary', 'yes'); - $this->submit('form_action-no', _('No'), 'submit form_action-secondary', 'no'); + $this->submit('form_action-no', _('No'), 'submit form_action-primary', 'no', _("Do not delete this notice")); + $this->submit('form_action-yes', _('Yes'), 'submit form_action-secondary', 'yes', _('Delete this notice')); $this->elementEnd('fieldset'); $this->elementEnd('form'); } diff --git a/actions/designsettings.php b/actions/designsettings.php index 8a7c26104..315e5a199 100644 --- a/actions/designsettings.php +++ b/actions/designsettings.php @@ -140,11 +140,12 @@ class DesignsettingsAction extends AccountSettingsAction $this->elementEnd('ul'); $this->elementEnd('fieldset'); - $this->submit('save', _('Save')); $this->element('input', array('id' => 'settings_design_reset', 'type' => 'reset', 'value' => 'Reset', - 'class' => 'form_action-secondary')); + 'class' => 'submit form_action-primary', + 'title' => _('Reset back to default'))); + $this->submit('save', _('Save'), 'submit form_action-secondary', 'save', _('Save design')); /*TODO: Check submitted form values: json_encode(form values) diff --git a/theme/base/css/display.css b/theme/base/css/display.css index 8bd0ae1c4..edec14163 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -198,9 +198,11 @@ padding:0 7px; } +.form_settings input.form_action-primary { +padding:0; +} .form_settings input.form_action-secondary { margin-left:29px; -padding:0; } #form_search .submit { diff --git a/theme/default/css/display.css b/theme/default/css/display.css index e4b57ef49..fce2e7e29 100644 --- a/theme/default/css/display.css +++ b/theme/default/css/display.css @@ -33,7 +33,7 @@ border-color:#aaa; border-color:#C3D6DF; } -.form_settings input.form_action-secondary { +.form_settings input.form_action-primary { background:none; } @@ -60,7 +60,7 @@ div.notice-options input, .entity_send-a-message a, .form_user_nudge input.submit, .entity_nudge p, -.form_settings input.form_action-secondary { +.form_settings input.form_action-primary { color:#002E6E; } diff --git a/theme/identica/css/display.css b/theme/identica/css/display.css index 9d625848f..df114417e 100644 --- a/theme/identica/css/display.css +++ b/theme/identica/css/display.css @@ -33,7 +33,7 @@ border-color:#aaa; border-color:#ddd; } -.form_settings input.form_action-secondary { +.form_settings input.form_action-primary { background:none; } @@ -60,7 +60,7 @@ div.notice-options input, .entity_send-a-message a, .form_user_nudge input.submit, .entity_nudge p, -.form_settings input.form_action-secondary { +.form_settings input.form_action-primary { color:#002E6E; } -- cgit v1.2.3-54-g00ecf From 689dd9ee5f81e3e2472e92b10248fecd39638160 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 21 May 2009 00:18:11 +0000 Subject: Updated primary and secondary styles for biz, cloudy, h4ck3r, otalk, pigeonthoughts themes. --- theme/biz/css/base.css | 5 ++++- theme/biz/css/display.css | 4 ++-- theme/cloudy/css/display.css | 8 +++++--- theme/h4ck3r/css/base.css | 4 +++- theme/h4ck3r/css/display.css | 4 ++-- theme/otalk/css/base.css | 4 +++- theme/otalk/css/display.css | 4 ++-- theme/pigeonthoughts/css/base.css | 4 +++- theme/pigeonthoughts/css/display.css | 4 ++-- 9 files changed, 26 insertions(+), 15 deletions(-) diff --git a/theme/biz/css/base.css b/theme/biz/css/base.css index 22bbced08..0e37a6ee4 100644 --- a/theme/biz/css/base.css +++ b/theme/biz/css/base.css @@ -198,11 +198,14 @@ padding:0 7px; } +.form_settings input.form_action-primary { +padding:0; +} .form_settings input.form_action-secondary { margin-left:29px; -padding:0; } + #form_search .submit { margin-left:11px; } diff --git a/theme/biz/css/display.css b/theme/biz/css/display.css index a7d360c53..14092d964 100644 --- a/theme/biz/css/display.css +++ b/theme/biz/css/display.css @@ -36,7 +36,7 @@ border-color:#aaa; border-color:#ddd; } -.form_settings input.form_action-secondary { +.form_settings input.form_action-primary { background:none; } @@ -65,7 +65,7 @@ div.notice-options input, .entity_send-a-message a, .form_user_nudge input.submit, .entity_nudge p, -.form_settings input.form_action-secondary { +.form_settings input.form_action-primary { color:#002E6E; } diff --git a/theme/cloudy/css/display.css b/theme/cloudy/css/display.css index e97889685..12f186a56 100644 --- a/theme/cloudy/css/display.css +++ b/theme/cloudy/css/display.css @@ -199,9 +199,11 @@ padding:0 7px; } +.form_settings input.form_action-primary { +padding:0; +} .form_settings input.form_action-secondary { margin-left:29px; -padding:0; } #form_search .submit { @@ -1267,7 +1269,7 @@ border-color:#aaa; border-color:#ddd; } -.form_settings input.form_action-secondary { +.form_settings input.form_action-primary { background:none; } @@ -1296,7 +1298,7 @@ div.notice-options input, .entity_send-a-message a, .form_user_nudge input.submit, .entity_nudge p, -.form_settings input.form_action-secondary { +.form_settings input.form_action-primary { color:#0084B4; } diff --git a/theme/h4ck3r/css/base.css b/theme/h4ck3r/css/base.css index 5060bbb8b..41b3a77e6 100644 --- a/theme/h4ck3r/css/base.css +++ b/theme/h4ck3r/css/base.css @@ -189,9 +189,11 @@ padding:0 7px; } +.form_settings input.form_action-primary { +padding:0; +} .form_settings input.form_action-secondary { margin-left:29px; -padding:0; } #form_search .submit { diff --git a/theme/h4ck3r/css/display.css b/theme/h4ck3r/css/display.css index c7631a8eb..31d49a58e 100644 --- a/theme/h4ck3r/css/display.css +++ b/theme/h4ck3r/css/display.css @@ -38,7 +38,7 @@ color:#ccc; border-color:#ddd; } -.form_settings input.form_action-secondary { +.form_settings input.form_action-primary { background:none; } @@ -65,7 +65,7 @@ div.notice-options input, .entity_send-a-message a, .form_user_nudge input.submit, .entity_nudge p, -.form_settings input.form_action-secondary { +.form_settings input.form_action-primary { color:#0f0; } diff --git a/theme/otalk/css/base.css b/theme/otalk/css/base.css index 32e8891d2..b39992570 100644 --- a/theme/otalk/css/base.css +++ b/theme/otalk/css/base.css @@ -198,9 +198,11 @@ padding:0 7px; } +.form_settings input.form_action-primary { +padding:0; +} .form_settings input.form_action-secondary { margin-left:29px; -padding:0; } #form_search .submit { diff --git a/theme/otalk/css/display.css b/theme/otalk/css/display.css index 6c646791b..d2a4719a8 100644 --- a/theme/otalk/css/display.css +++ b/theme/otalk/css/display.css @@ -37,7 +37,7 @@ border-color:#aaa; border-color:#ddd; } -.form_settings input.form_action-secondary { +.form_settings input.form_action-primary { background:none; } @@ -64,7 +64,7 @@ div.notice-options input, .entity_send-a-message a, .form_user_nudge input.submit, .entity_nudge p, -.form_settings input.form_action-secondary { +.form_settings input.form_action-primary { color:#8F0000; } diff --git a/theme/pigeonthoughts/css/base.css b/theme/pigeonthoughts/css/base.css index 179719820..08427d3c8 100644 --- a/theme/pigeonthoughts/css/base.css +++ b/theme/pigeonthoughts/css/base.css @@ -199,9 +199,11 @@ padding:0 7px; } +.form_settings input.form_action-primary { +padding:0; +} .form_settings input.form_action-secondary { margin-left:29px; -padding:0; } #form_search .submit { diff --git a/theme/pigeonthoughts/css/display.css b/theme/pigeonthoughts/css/display.css index 19341ef7f..af31cf78d 100644 --- a/theme/pigeonthoughts/css/display.css +++ b/theme/pigeonthoughts/css/display.css @@ -36,7 +36,7 @@ border-color:#aaa; border-color:#ddd; } -.form_settings input.form_action-secondary { +.form_settings input.form_action-primary { background:none; } @@ -63,7 +63,7 @@ div.notice-options input, .entity_send-a-message a, .form_user_nudge input.submit, .entity_nudge p, -.form_settings input.form_action-secondary { +.form_settings input.form_action-primary { color:#000; } -- cgit v1.2.3-54-g00ecf From 54cd0a2046c417fd072bb4cf79aeda163cf760af Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 21 May 2009 05:43:11 +0000 Subject: - Reworked login / logout workflow - Added Facebook Connect tab to login nav - Show Facebook mini-avatar when logged in - Added Facebook Connect tab to connect settings nav - Option to disconnect from Facebook --- db/foreign_services.sql | 3 +- plugins/FBConnect/FBCSettingsNav.php | 113 ++++++++++++++++++++ plugins/FBConnect/FBConnectAuth.php | 31 ++++-- plugins/FBConnect/FBConnectLogin.php | 10 +- plugins/FBConnect/FBConnectPlugin.php | 179 +++++++++++-------------------- plugins/FBConnect/FBConnectSettings.php | 184 ++++++++++++++++++++++++++++++++ 6 files changed, 393 insertions(+), 127 deletions(-) create mode 100644 plugins/FBConnect/FBCSettingsNav.php create mode 100644 plugins/FBConnect/FBConnectSettings.php diff --git a/db/foreign_services.sql b/db/foreign_services.sql index 557ede024..79c04cee5 100644 --- a/db/foreign_services.sql +++ b/db/foreign_services.sql @@ -2,4 +2,5 @@ insert into foreign_service (id, name, description, created) values ('1','Twitter', 'Twitter Micro-blogging service', now()), - ('2','Facebook', 'Facebook', now()); + ('2','Facebook', 'Facebook', now()), + ('3','FacebookConnect', 'Facebook Connect', now()); diff --git a/plugins/FBConnect/FBCSettingsNav.php b/plugins/FBConnect/FBCSettingsNav.php new file mode 100644 index 000000000..8b8411853 --- /dev/null +++ b/plugins/FBConnect/FBCSettingsNav.php @@ -0,0 +1,113 @@ +. + * + * @category Menu + * @package Laconica + * @author Evan Prodromou + * @author Zach Copley + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR . '/lib/widget.php'; + +/** + * A widget for showing the connect group local nav menu + * + * @category Output + * @package Laconica + * @author Evan Prodromou + * @author Zach Copley + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see Widget + */ + +class FBCSettingsNav extends Widget +{ + var $action = null; + + /** + * Construction + * + * @param Action $action current action, used for output + */ + + function __construct($action=null) + { + parent::__construct($action); + $this->action = $action; + } + + /** + * Show the menu + * + * @return void + */ + + function show() + { + + $this->action->elementStart('dl', array('id' => 'site_nav_local_views')); + $this->action->element('dt', null, _('Local views')); + $this->action->elementStart('dd'); + + # action => array('prompt', 'title') + $menu = + array('imsettings' => + array(_('IM'), + _('Updates by instant messenger (IM)')), + 'smssettings' => + array(_('SMS'), + _('Updates by SMS')), + 'twittersettings' => + array(_('Twitter'), + _('Twitter integration options')), + 'FBConnectSettings' => + array(_('Facebook'), + _('Facebook Connect settings'))); + + $action_name = $this->action->trimmed('action'); + $this->action->elementStart('ul', array('class' => 'nav')); + + foreach ($menu as $menuaction => $menudesc) { + if ($menuaction == 'imsettings' && + !common_config('xmpp', 'enabled')) { + continue; + } + $this->action->menuItem(common_local_url($menuaction), + $menudesc[0], + $menudesc[1], + $action_name === $menuaction); + } + + $this->action->elementEnd('ul'); + + $this->action->elementEnd('dd'); + $this->action->elementEnd('dl'); + } +} diff --git a/plugins/FBConnect/FBConnectAuth.php b/plugins/FBConnect/FBConnectAuth.php index 0dc016c05..e8724cdf9 100644 --- a/plugins/FBConnect/FBConnectAuth.php +++ b/plugins/FBConnect/FBConnectAuth.php @@ -29,7 +29,7 @@ require_once INSTALLDIR . '/plugins/FBConnect/FBConnectPlugin.php'; -class FbconnectauthAction extends Action +class FBConnectauthAction extends Action { var $fbuid = null; @@ -38,9 +38,20 @@ class FbconnectauthAction extends Action function prepare($args) { parent::prepare($args); - $this->fbuid = getFacebook()->get_loggedin_user(); - $this->fb_fields = $this->getFacebookFields($this->fbuid, - array('first_name', 'last_name', 'name')); + try { + + $this->fbuid = getFacebook()->get_loggedin_user(); + + if ($this->fbuid > 0) { + $this->fb_fields = $this->getFacebookFields($this->fbuid, + array('first_name', 'last_name', 'name')); + } else { + common_debug("No Facebook User found."); + } + + } catch (Exception $e) { + common_debug("Problem getting fbuid."); + } return true; } @@ -52,6 +63,7 @@ class FbconnectauthAction extends Action if (common_is_real_login()) { $this->clientError(_('Already logged in.')); } else if ($_SERVER['REQUEST_METHOD'] == 'POST') { + $token = $this->trimmed('token'); if (!$token || $token != common_session_token()) { $this->showForm(_('There was a problem with your session token. Try again, please.')); @@ -113,7 +125,7 @@ class FbconnectauthAction extends Action $this->elementStart('form', array('method' => 'post', 'id' => 'account_connect', - 'action' => common_local_url('fbconnectlogin'))); + 'action' => common_local_url('FBConnectAuth'))); $this->hidden('token', common_session_token()); $this->element('h2', null, _('Create new account')); @@ -255,7 +267,7 @@ class FbconnectauthAction extends Action { common_debug("Trying Facebook Login..."); - $flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_SERVICE); + $flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_CONNECT_SERVICE); if ($flink) { $user = $flink->getUser(); @@ -270,6 +282,9 @@ class FbconnectauthAction extends Action } } else { + + common_debug("no flink found for fbuid: $this->fbuid"); + $this->showForm(null, $this->bestNewNickname()); } } @@ -291,10 +306,12 @@ class FbconnectauthAction extends Action function flinkUser($user_id, $fbuid) { + common_debug("flinkUser()"); + $flink = new Foreign_link(); $flink->user_id = $user_id; $flink->foreign_id = $fbuid; - $flink->service = FACEBOOK_SERVICE; + $flink->service = FACEBOOK_CONNECT_SERVICE; $flink->created = common_sql_now(); $flink_id = $flink->insert(); diff --git a/plugins/FBConnect/FBConnectLogin.php b/plugins/FBConnect/FBConnectLogin.php index 70710eb70..7989dc854 100644 --- a/plugins/FBConnect/FBConnectLogin.php +++ b/plugins/FBConnect/FBConnectLogin.php @@ -17,8 +17,8 @@ * along with this program. If not, see . */ -if (!defined('LACONICA')) { - exit(1); +if (!defined('LACONICA')) { + exit(1); } require_once INSTALLDIR . '/plugins/FBConnect/FBConnectPlugin.php'; @@ -31,8 +31,8 @@ class FBConnectLoginAction extends Action if (common_is_real_login()) { $this->clientError(_('Already logged in.')); - } - + } + $this->showPage(); } @@ -58,7 +58,7 @@ class FBConnectLoginAction extends Action function showContent() { $this->elementStart('fieldset'); - + $this->element('fb:login-button', array('onlogin' => 'goto_login()', 'length' => 'long')); diff --git a/plugins/FBConnect/FBConnectPlugin.php b/plugins/FBConnect/FBConnectPlugin.php index 079270510..36dee0448 100644 --- a/plugins/FBConnect/FBConnectPlugin.php +++ b/plugins/FBConnect/FBConnectPlugin.php @@ -31,10 +31,15 @@ if (!defined('LACONICA')) { exit(1); } +define("FACEBOOK_CONNECT_SERVICE", 3); + require_once INSTALLDIR . '/lib/facebookutil.php'; require_once INSTALLDIR . '/plugins/FBConnect/FBConnectAuth.php'; require_once INSTALLDIR . '/plugins/FBConnect/FBConnectLogin.php'; +require_once INSTALLDIR . '/plugins/FBConnect/FBConnectSettings.php'; require_once INSTALLDIR . '/plugins/FBConnect/FBCLoginGroupNav.php'; +require_once INSTALLDIR . '/plugins/FBConnect/FBCSettingsNav.php'; + /** * Plugin to enable Facebook Connect @@ -56,32 +61,14 @@ class FBConnectPlugin extends Plugin // Hook in new actions function onRouterInitialized(&$m) { - - common_debug("onRouterIntialized()"); - $m->connect('main/facebookconnect', array('action' => 'FBConnectAuth')); $m->connect('main/facebooklogin', array('action' => 'FBConnectLogin')); + $m->connect('settings/facebook', array('action' => 'FBConnectSettings')); } // Add in xmlns:fb function onStartShowHTML($action) { - - // XXX: This is probably a bad place to do general processing - // so maybe I need to make some new events? Maybe in - // Action::prepare? - - $name = get_class($action); - - common_debug("onStartShowHTML: action = $name"); - - // Avoid a redirect loop - if (!in_array($name, array('FBConnectAuthAction', 'ClientErrorAction'))) { - - $this->checkFacebookUser($action); - - } - $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : null; @@ -128,15 +115,7 @@ class FBConnectPlugin extends Plugin $apikey = common_config('facebook', 'apikey'); $plugin_path = common_path('plugins/FBConnect'); - $login_url = common_get_returnto(); - - if ($login_url) { - // We don't have to return to it again - common_set_returnto(null); - } else { - $url = common_local_url('public'); - } - + $login_url = common_local_url('FBConnectAuth'); $logout_url = common_local_url('logout'); $html = sprintf('