summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorZach Copley <zach@controlyourself.ca>2009-06-14 00:23:48 +0000
committerZach Copley <zach@controlyourself.ca>2009-06-14 00:23:48 +0000
commitd0eb2058a519941e205f7b0960d9a5e0707207bb (patch)
tree37ed1aa1be3c3a7a58463964ce602565c79f8cdf /lib
parenta887d4fe8b1f5e5adc2d701384acf50cf2cf54c3 (diff)
parentdbbb3a4fb558ee4372e157612f3e053a87a53a8e (diff)
Merge branch '0.8.x' into userdesign
Conflicts: actions/showfavorites.php lib/action.php
Diffstat (limited to 'lib')
-rw-r--r--lib/action.php102
-rw-r--r--lib/event.php28
-rw-r--r--lib/noticeform.php2
-rw-r--r--lib/noticelist.php2
-rw-r--r--lib/rssaction.php25
-rw-r--r--lib/twitterapi.php95
-rw-r--r--lib/util.php1
7 files changed, 138 insertions, 117 deletions
diff --git a/lib/action.php b/lib/action.php
index 55fb7c089..89a8c8f4d 100644
--- a/lib/action.php
+++ b/lib/action.php
@@ -124,7 +124,6 @@ class Action extends HTMLOutputter // lawsuit
$this->showShortcutIcon();
$this->showStylesheets();
$this->showScripts();
- $this->showRelationshipLinks();
$this->showOpenSearch();
$this->showFeeds();
$this->showDescription();
@@ -224,16 +223,6 @@ class Action extends HTMLOutputter // lawsuit
'href="'.theme_path('css/ie.css', null).'?version='.LACONICA_VERSION.'" /><![endif]');
Event::handle('EndShowUAStyles', array($this));
}
- if (Event::handle('StartShowDesign', array($this))) {
- $design = $this->getDesign();
- if (!empty($design)) {
- $cur = common_current_user();
- if (empty($cur) || $cur->viewdesigns) {
- $design->showCSS($this);
- }
- }
- Event::handle('EndShowDesign', array($this, $design));
- }
Event::handle('EndShowStyles', array($this));
}
}
@@ -258,6 +247,7 @@ class Action extends HTMLOutputter // lawsuit
'src' => common_path('js/jquery.joverlay.min.js')),
' ');
+
Event::handle('EndShowJQueryScripts', array($this));
}
if (Event::handle('StartShowLaconicaScripts', array($this))) {
@@ -277,19 +267,6 @@ class Action extends HTMLOutputter // lawsuit
}
/**
- * Show document relationship links
- *
- * SHOULD overload
- *
- * @return nothing
- */
- function showRelationshipLinks()
- {
- // output <link> elements with appropriate HTML4.01 link types:
- // http://www.w3.org/TR/html401/types.html#type-links
- }
-
- /**
* Show OpenSearch headers
*
* @return nothing
@@ -598,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');
}
/**
@@ -1072,51 +1061,4 @@ class Action extends HTMLOutputter // lawsuit
{
return null;
}
-
- /**
- * Generate document metadata for sequential navigation
- *
- * @param boolean $have_before is there something before?
- * @param boolean $have_after is there something after?
- * @param integer $page current page
- * @param string $action current action
- * @param array $args rest of query arguments
- *
- * @return nothing
- */
- function sequenceRelationships($have_next, $have_previous, $page, $action, $args=null)
- {
- // Outputs machine-readable pagination in <link> elements.
- // Pattern taken from $this->pagination() method.
-
- // "next" is equivalent to "after"
- if ($have_next) {
- $pargs = array('page' => $page-1);
- $this->element('link', array('rel' => 'next',
- 'href' => common_local_url($action, $args, $pargs),
- 'title' => _('Next')));
- }
- // "previous" is equivalent to "before"
- if ($have_previous=true) { // FIXME
- $pargs = array('page' => $page+1);
- $this->element('link', array('rel' => 'prev',
- 'href' => common_local_url($action, $args, $pargs),
- 'title' => _('Previous')));
- }
- }
-
- /**
- * A design for this action
- *
- * A design (colors and background) for the current page. May be
- * the user's design, or a group's design, or a site design.
- *
- * @return Design a design object to use
- */
-
- function getDesign()
- {
- // XXX: return site design by default
- return 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/noticeform.php b/lib/noticeform.php
index 5d7cf194e..3212f382a 100644
--- a/lib/noticeform.php
+++ b/lib/noticeform.php
@@ -148,6 +148,7 @@ class NoticeForm extends Form
$this->out->element('dd', array('id' => 'notice_text-count'),
'140');
$this->out->elementEnd('dl');
+ $this->out->hidden('MAX_FILE_SIZE', common_config('attachments', 'file_quota'));
$this->out->element('label', array('for' => 'notice_data-attach'), _('Attach'));
$this->out->element('input', array('id' => 'notice_data-attach',
'type' => 'file',
@@ -157,7 +158,6 @@ class NoticeForm extends Form
$this->out->hidden('notice_return-to', $this->action, 'returnto');
}
$this->out->hidden('notice_in-reply-to', $this->action, 'inreplyto');
- $this->out->hidden('MAX_FILE_SIZE', common_config('attachments', 'file_quota'));
}
/**
diff --git a/lib/noticelist.php b/lib/noticelist.php
index c00942af4..e44997004 100644
--- a/lib/noticelist.php
+++ b/lib/noticelist.php
@@ -365,7 +365,7 @@ class NoticeListItem extends Widget
}
$uploaded = $this->notice->getUploadedAttachment();
if ($uploaded) {
- $this->out->element('a', array('href' => $uploaded, 'class' => 'attachment'), $uploaded);
+ $this->out->element('a', array('href' => $uploaded[0], 'class' => 'attachment', 'id' => 'attachment-' . $uploaded[1]), $uploaded[0]);
}
$this->out->elementEnd('p');
}
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/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;
+ }
+ }
+
}
diff --git a/lib/util.php b/lib/util.php
index 9872d97c4..b3a94a5a0 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -922,7 +922,6 @@ function common_enqueue_notice_transport($notice, $transport)
$last_error = &PEAR::getStaticProperty('DB_DataObject','lastError');
common_log(LOG_ERR, 'DB error inserting queue item: ' . $last_error->message);
throw new ServerException('DB error inserting queue item: ' . $last_error->message);
->>>>>>> 0.7.x:lib/util.php
}
common_log(LOG_DEBUG, 'complete queueing notice ID = ' . $notice->id . ' for ' . $transport);
return true;