diff options
author | Evan Prodromou <evan@controlyourself.ca> | 2009-06-14 11:27:48 -0700 |
---|---|---|
committer | Evan Prodromou <evan@controlyourself.ca> | 2009-06-14 11:27:48 -0700 |
commit | 7f76c36f24bd51fd4f204f363d5ddf35e9ea9950 (patch) | |
tree | 4879f89f393e1a71d721cdaff8bcd7e45d3721c2 /lib | |
parent | e0bdaa787ddf5102417ec35a4996e68cfc8981f2 (diff) | |
parent | 77c94c44a622052366dcc03fee522232672d71d9 (diff) |
Merge branch '0.8.x' of git@gitorious.org:+laconica-developers/laconica/dev into 0.8.x
Diffstat (limited to 'lib')
-rw-r--r-- | lib/action.php | 30 | ||||
-rw-r--r-- | lib/common.php | 1 | ||||
-rw-r--r-- | lib/event.php | 28 | ||||
-rw-r--r-- | lib/rssaction.php | 25 | ||||
-rw-r--r-- | lib/theme.php | 27 | ||||
-rw-r--r-- | lib/twitterapi.php | 95 |
6 files changed, 135 insertions, 71 deletions
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'); } /** 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/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; + } } diff --git a/lib/rssaction.php b/lib/rssaction.php index 2f25ed7e4..eafdbf131 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,14 +197,19 @@ 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); $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)); + $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'); @@ -216,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'); } } @@ -239,7 +244,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' => @@ -253,10 +258,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'); } 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); - } -} - 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 <http://www.gnu.org/licenses/>. */ -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 = '<a href="' . $ns->url . '">' . $ns->name . '</a>'; @@ -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; + } + } + } |