From 806439758823e3fe6e51ec56ce653760902af2aa Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Fri, 12 Jun 2009 01:31:22 -0700 Subject: Ticket #1611 and a bunch of code cleanup --- lib/twitterapi.php | 95 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 71 insertions(+), 24 deletions(-) (limited to 'lib') diff --git a/lib/twitterapi.php b/lib/twitterapi.php index ca8b03cdc..569bc6d7a 100644 --- a/lib/twitterapi.php +++ b/lib/twitterapi.php @@ -17,7 +17,9 @@ * along with this program. If not, see . */ -if (!defined('LACONICA')) { exit(1); } +if (!defined('LACONICA')) { + exit(1); +} class TwitterapiAction extends Action { @@ -521,11 +523,11 @@ class TwitterapiAction extends Action function init_document($type='xml') { switch ($type) { - case 'xml': + case 'xml': header('Content-Type: application/xml; charset=utf-8'); $this->startXML(); break; - case 'json': + case 'json': header('Content-Type: application/json; charset=utf-8'); // Check for JSONP callback @@ -534,15 +536,15 @@ class TwitterapiAction extends Action print $callback . '('; } break; - case 'rss': + case 'rss': header("Content-Type: application/rss+xml; charset=utf-8"); $this->init_twitter_rss(); break; - case 'atom': + case 'atom': header('Content-Type: application/atom+xml; charset=utf-8'); $this->init_twitter_atom(); break; - default: + default: $this->client_error(_('Not a supported data format.')); break; } @@ -553,10 +555,10 @@ class TwitterapiAction extends Action function end_document($type='xml') { switch ($type) { - case 'xml': + case 'xml': $this->endXML(); break; - case 'json': + case 'json': // Check for JSONP callback $callback = $this->arg('callback'); @@ -564,13 +566,13 @@ class TwitterapiAction extends Action print ')'; } break; - case 'rss': + case 'rss': $this->end_twitter_rss(); break; - case 'atom': + case 'atom': $this->end_twitter_rss(); break; - default: + default: $this->client_error(_('Not a supported data format.')); break; } @@ -657,13 +659,13 @@ class TwitterapiAction extends Action { $profile_array = $this->twitter_user_array($profile, true); switch ($content_type) { - case 'xml': + case 'xml': $this->show_twitter_xml_user($profile_array); break; - case 'json': + case 'json': $this->show_json_objects($profile_array); break; - default: + default: $this->client_error(_('Not a supported data format.')); return; } @@ -672,8 +674,8 @@ class TwitterapiAction extends Action function get_user($id, $apidata=null) { - if (!$id) { - + if (empty($id)) { + // Twitter supports these other ways of passing the user ID if (is_numeric($this->arg('id'))) { return User::staticGet($this->arg('id')); @@ -681,7 +683,7 @@ class TwitterapiAction extends Action $nickname = common_canonical_nickname($this->arg('id')); return User::staticGet('nickname', $nickname); } else if ($this->arg('user_id')) { - // This is to ensure that a non-numeric user_id still + // This is to ensure that a non-numeric user_id still // overrides screen_name even if it doesn't get used if (is_numeric($this->arg('user_id'))) { return User::staticGet('id', $this->arg('user_id')); @@ -693,7 +695,7 @@ class TwitterapiAction extends Action // Fall back to trying the currently authenticated user return $apidata['user']; } - + } else if (is_numeric($id)) { return User::staticGet($id); } else { @@ -720,13 +722,13 @@ class TwitterapiAction extends Action { $source_name = _($source); switch ($source) { - case 'web': - case 'xmpp': - case 'mail': - case 'omb': - case 'api': + case 'web': + case 'xmpp': + case 'mail': + case 'omb': + case 'api': break; - default: + default: $ns = Notice_source::staticGet($source); if ($ns) { $source_name = '' . $ns->name . ''; @@ -736,4 +738,49 @@ class TwitterapiAction extends Action return $source_name; } + /** + * Returns query argument or default value if not found. Certain + * parameters used throughout the API are lightly scrubbed and + * bounds checked. This overrides Action::arg(). + * + * @param string $key requested argument + * @param string $def default value to return if $key is not provided + * + * @return var $var + */ + function arg($key, $def=null) + { + + // XXX: Do even more input validation/scrubbing? + + if (array_key_exists($key, $this->args)) { + switch($key) { + case 'page': + $page = (int)$this->args['page']; + return ($page < 1) ? 1 : $page; + case 'count': + $count = (int)$this->args['count']; + if ($count < 1) { + return 20; + } elseif ($count > 200) { + return 200; + } else { + return $count; + } + case 'since_id': + $since_id = (int)$this->args['since_id']; + return ($since_id < 1) ? 0 : $since_id; + case 'max_id': + $max_id = (int)$this->args['max_id']; + return ($max_id < 1) ? 0 : $max_id; + case 'since': + return strtotime($this->args['since']); + default: + return parent::arg($key, $def); + } + } else { + return $def; + } + } + } -- cgit v1.2.3-54-g00ecf From e2476307baa8753dc866c7a1aed485d9f6d3fcd0 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 12 Jun 2009 15:41:45 +0000 Subject: Updated Creative Commons namespace to current. Thanks to Toby Inkster for the patch. --- lib/rssaction.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/rssaction.php b/lib/rssaction.php index 2f25ed7e4..0678b8982 100644 --- a/lib/rssaction.php +++ b/lib/rssaction.php @@ -239,7 +239,7 @@ class Rss10Action extends Action 'xmlns:dc' => 'http://purl.org/dc/elements/1.1/', 'xmlns:cc' => - 'http://web.resource.org/cc/', + 'http://creativecommons.org/ns#', 'xmlns:content' => 'http://purl.org/rss/1.0/modules/content/', 'xmlns:foaf' => -- cgit v1.2.3-54-g00ecf From 1627fe8f336d435e328dcc3a58e9e08cd4ef1bfe Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 12 Jun 2009 15:42:53 +0000 Subject: http://laconi.ca/trac/ticket/1368 Site is the space that Container sits in. Thanks to Toby Inkster for the patch. --- lib/rssaction.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/rssaction.php b/lib/rssaction.php index 0678b8982..cfb5ca44a 100644 --- a/lib/rssaction.php +++ b/lib/rssaction.php @@ -253,10 +253,10 @@ class Rss10Action extends Action 'xmlns' => 'http://purl.org/rss/1.0/')); $this->elementStart('sioc:Site', array('rdf:about' => common_root_url())); $this->element('sioc:name', null, common_config('site', 'name')); - $this->elementStart('sioc:container_of'); + $this->elementStart('sioc:space_of'); $this->element('sioc:Container', array('rdf:about' => $channel['url'])); - $this->elementEnd('sioc:container_of'); + $this->elementEnd('sioc:space_of'); $this->elementEnd('sioc:Site'); } -- cgit v1.2.3-54-g00ecf From 392c8d4a967f01533fd7458298e79c82486dc914 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 12 Jun 2009 16:13:45 +0000 Subject: http://laconi.ca/trac/ticket/863 Thanks to Toby Inkster for the patch. --- lib/rssaction.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib') diff --git a/lib/rssaction.php b/lib/rssaction.php index cfb5ca44a..6f30a02f2 100644 --- a/lib/rssaction.php +++ b/lib/rssaction.php @@ -202,6 +202,9 @@ class Rss10Action extends Action $this->element('title', null, $title); $this->element('link', null, $nurl); $this->element('description', null, $profile->nickname."'s status on ".common_exact_date($notice->created)); + if ($notice->rendered) { + $this->element('content:encoded', null, common_xml_safe_str($notice->rendered)); + } $this->element('dc:date', null, common_date_w3dtf($notice->created)); $this->element('dc:creator', null, ($profile->fullname) ? $profile->fullname : $profile->nickname); $this->element('sioc:has_creator', array('rdf:resource' => $creator_uri)); -- cgit v1.2.3-54-g00ecf From 4532babb6f3a7c8d2b155483a4a651f83cfc6c8a Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 12 Jun 2009 16:15:30 +0000 Subject: http://laconi.ca/trac/ticket/1370 Thanks to Toby Inkster for the patch. --- lib/rssaction.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/rssaction.php b/lib/rssaction.php index 6f30a02f2..a3a762317 100644 --- a/lib/rssaction.php +++ b/lib/rssaction.php @@ -170,7 +170,7 @@ class Rss10Action extends Action $this->elementStart('rdf:Seq'); foreach ($this->notices as $notice) { - $this->element('sioct:MicroblogPost', array('rdf:resource' => $notice->uri)); + $this->element('rdf:li', array('rdf:resource' => $notice->uri)); } $this->elementEnd('rdf:Seq'); @@ -197,7 +197,8 @@ class Rss10Action extends Action $profile = Profile::staticGet($notice->profile_id); $nurl = common_local_url('shownotice', array('notice' => $notice->id)); $creator_uri = common_profile_uri($profile); - $this->elementStart('item', array('rdf:about' => $notice->uri)); + $this->elementStart('item', array('rdf:about' => $notice->uri, + 'rdf:type' => 'http://rdfs.org/sioc/types#MicroblogPost')); $title = $profile->nickname . ': ' . common_xml_safe_str(trim($notice->content)); $this->element('title', null, $title); $this->element('link', null, $nurl); -- cgit v1.2.3-54-g00ecf From 8524990512d41e9aa7114b6a3b5af073eeb9aabb Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 12 Jun 2009 16:18:58 +0000 Subject: http://laconi.ca/trac/ticket/1367 Thanks to Toby Inkster for the patch. --- lib/rssaction.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/rssaction.php b/lib/rssaction.php index a3a762317..eafdbf131 100644 --- a/lib/rssaction.php +++ b/lib/rssaction.php @@ -208,7 +208,8 @@ class Rss10Action extends Action } $this->element('dc:date', null, common_date_w3dtf($notice->created)); $this->element('dc:creator', null, ($profile->fullname) ? $profile->fullname : $profile->nickname); - $this->element('sioc:has_creator', array('rdf:resource' => $creator_uri)); + $this->element('foaf:maker', array('rdf:resource' => $creator_uri)); + $this->element('sioc:has_creator', array('rdf:resource' => $creator_uri.'#acct')); $this->element('laconica:postIcon', array('rdf:resource' => $profile->avatarUrl())); $this->element('cc:licence', array('rdf:resource' => common_config('license', 'url'))); $this->elementEnd('item'); @@ -220,15 +221,15 @@ class Rss10Action extends Action foreach ($this->creators as $uri => $profile) { $id = $profile->id; $nickname = $profile->nickname; - $this->elementStart('sioc:User', array('rdf:about' => $uri)); + $this->elementStart('foaf:Agent', array('rdf:about' => $uri)); $this->element('foaf:nick', null, $nickname); if ($profile->fullname) { $this->element('foaf:name', null, $profile->fullname); } - $this->element('sioc:id', null, $id); + $this->element('foaf:holdsAccount', array('rdf:resource' => $uri.'#acct')); $avatar = $profile->avatarUrl(); - $this->element('sioc:avatar', array('rdf:resource' => $avatar)); - $this->elementEnd('sioc:User'); + $this->element('foaf:depiction', array('rdf:resource' => $avatar)); + $this->elementEnd('foaf:Agent'); } } -- cgit v1.2.3-54-g00ecf From fc6154fe4dc093780d610f97c0d9213bb26060fe Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Fri, 12 Jun 2009 16:56:43 -0700 Subject: Add a method to check for registered event handlers --- lib/event.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'lib') diff --git a/lib/event.php b/lib/event.php index d815ae54b..4ccee17e6 100644 --- a/lib/event.php +++ b/lib/event.php @@ -110,4 +110,32 @@ class Event { } return ($result !== false); } + + /** + * Check to see if an event handler exists + * + * Look to see if there's any handler for a given event, or narrow + * by providing the name of a specific plugin class. + * + * @param string $name Name of the event to look for + * @param string $plugin Optional name of the plugin class to look for + * + * @return boolean flag saying whether such a handler exists + * + */ + + public static function hasHandler($name, $plugin=null) { + if (array_key_exists($name, Event::$_handlers)) { + if (isset($plugin)) { + foreach (Event::$_handlers[$name] as $handler) { + if (get_class($handler[0]) == $plugin) { + return true; + } + } + } else { + return true; + } + } + return false; + } } -- cgit v1.2.3-54-g00ecf From 89d0583b91a237448b9f7ea3b0ae303072631447 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Fri, 12 Jun 2009 17:06:42 -0700 Subject: Fixes Ticket #1607 - empty 'page-notice' definition lists were being output in a bunch of places. --- lib/action.php | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/action.php b/lib/action.php index 7643e5afb..89a8c8f4d 100644 --- a/lib/action.php +++ b/lib/action.php @@ -575,20 +575,32 @@ class Action extends HTMLOutputter // lawsuit /** * Show page notice block. * + * Only show the block if a subclassed action has overrided + * Action::showPageNotice(), or an event handler is registered for + * the StartShowPageNotice event, in which case we assume the + * 'page_notice' definition list is desired. This is to prevent + * empty 'page_notice' definition lists from being output everywhere. + * * @return nothing */ function showPageNoticeBlock() { - $this->elementStart('dl', array('id' => 'page_notice', - 'class' => 'system_notice')); - $this->element('dt', null, _('Page notice')); - $this->elementStart('dd'); - if (Event::handle('StartShowPageNotice', array($this))) { - $this->showPageNotice(); - Event::handle('EndShowPageNotice', array($this)); + $rmethod = new ReflectionMethod($this, 'showPageNotice'); + $dclass = $rmethod->getDeclaringClass()->getName(); + + if ($dclass != 'Action' || Event::hasHandler('StartShowPageNotice')) { + + $this->elementStart('dl', array('id' => 'page_notice', + 'class' => 'system_notice')); + $this->element('dt', null, _('Page notice')); + $this->elementStart('dd'); + if (Event::handle('StartShowPageNotice', array($this))) { + $this->showPageNotice(); + Event::handle('EndShowPageNotice', array($this)); + } + $this->elementEnd('dd'); + $this->elementEnd('dl'); } - $this->elementEnd('dd'); - $this->elementEnd('dl'); } /** -- cgit v1.2.3-54-g00ecf From 77c94c44a622052366dcc03fee522232672d71d9 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Sun, 14 Jun 2009 05:57:59 +0000 Subject: Removed hanging skin crapola --- lib/common.php | 1 - lib/theme.php | 27 --------------------------- 2 files changed, 28 deletions(-) (limited to 'lib') diff --git a/lib/common.php b/lib/common.php index 5aafdfe0e..6bf4ad21f 100644 --- a/lib/common.php +++ b/lib/common.php @@ -71,7 +71,6 @@ $config = array('name' => 'Just another Laconica microblog', 'server' => $_server, 'theme' => 'default', - 'skin' => 'default', 'path' => $_path, 'logfile' => null, 'logo' => null, diff --git a/lib/theme.php b/lib/theme.php index bef660cbf..0d8824822 100644 --- a/lib/theme.php +++ b/lib/theme.php @@ -70,30 +70,3 @@ function theme_path($relative, $theme=null) return common_path('theme/'.$theme.'/'.$relative); } } - -/** - * Gets the full URL of a file in a skin dir based on its relative name - * - * @param string $relative relative path within the theme, skin directory - * @param string $theme name of the theme; defaults to current theme - * @param string $skin name of the skin; defaults to current theme - * - * @return string URL of the file - */ - -function skin_path($relative, $theme=null, $skin=null) -{ - if (!$theme) { - $theme = common_config('site', 'theme'); - } - if (!$skin) { - $skin = common_config('site', 'skin'); - } - $server = common_config('theme', 'server'); - if ($server) { - return 'http://'.$server.'/'.$theme.'/skin/'.$skin.'/'.$relative; - } else { - return common_path('theme/'.$theme.'/skin/'.$skin.'/'.$relative); - } -} - -- cgit v1.2.3-54-g00ecf