summaryrefslogtreecommitdiff
path: root/actions
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-06-11 12:05:53 -0700
committerBrion Vibber <brion@pobox.com>2010-06-11 12:05:53 -0700
commit7f3b3620af2af88ced37da1d9f8913cfd1a31b90 (patch)
tree13f137c377c3dfebbb2e749866e958ede08c2d24 /actions
parente81f17e911f59c5ba68fddefd318ea6caf25924c (diff)
parent47665e845ae74e6ee5b9a39565fb45dd9a93f921 (diff)
Merge branch 'testing' of gitorious.org:statusnet/mainline into 0.9.x
Diffstat (limited to 'actions')
-rw-r--r--actions/apidirectmessage.php3
-rw-r--r--actions/apistatusesdestroy.php59
-rw-r--r--actions/apiusershow.php2
-rw-r--r--actions/designadminpanel.php104
-rw-r--r--actions/foaf.php30
5 files changed, 162 insertions, 36 deletions
diff --git a/actions/apidirectmessage.php b/actions/apidirectmessage.php
index 53da9e0c6..7a0f46274 100644
--- a/actions/apidirectmessage.php
+++ b/actions/apidirectmessage.php
@@ -232,7 +232,8 @@ class ApiDirectMessageAction extends ApiAuthAction
function showXmlDirectMessages()
{
$this->initDocument('xml');
- $this->elementStart('direct-messages', array('type' => 'array'));
+ $this->elementStart('direct-messages', array('type' => 'array',
+ 'xmlns:statusnet' => 'http://status.net/schema/api/1/'));
foreach ($this->messages as $m) {
$dm_array = $this->directMessageArray($m);
diff --git a/actions/apistatusesdestroy.php b/actions/apistatusesdestroy.php
index 8d9469063..0dfeb4812 100644
--- a/actions/apistatusesdestroy.php
+++ b/actions/apistatusesdestroy.php
@@ -100,32 +100,43 @@ class ApiStatusesDestroyAction extends ApiAuthAction
parent::handle($args);
if (!in_array($this->format, array('xml', 'json'))) {
- $this->clientError(_('API method not found.'), $code = 404);
- return;
+ $this->clientError(
+ _('API method not found.'),
+ 404
+ );
+ return;
}
- if (!in_array($_SERVER['REQUEST_METHOD'], array('POST', 'DELETE'))) {
- $this->clientError(_('This method requires a POST or DELETE.'),
- 400, $this->format);
- return;
- }
-
- if (empty($this->notice)) {
- $this->clientError(_('No status found with that ID.'),
- 404, $this->format);
- return;
- }
-
- if ($this->user->id == $this->notice->profile_id) {
- $replies = new Reply;
- $replies->get('notice_id', $this->notice_id);
- $replies->delete();
- $this->notice->delete();
- $this->showNotice();
- } else {
- $this->clientError(_('You may not delete another user\'s status.'),
- 403, $this->format);
- }
+ if (!in_array($_SERVER['REQUEST_METHOD'], array('POST', 'DELETE'))) {
+ $this->clientError(
+ _('This method requires a POST or DELETE.'),
+ 400,
+ $this->format
+ );
+ return;
+ }
+
+ if (empty($this->notice)) {
+ $this->clientError(
+ _('No status found with that ID.'),
+ 404, $this->format
+ );
+ return;
+ }
+
+ if ($this->user->id == $this->notice->profile_id) {
+ $replies = new Reply;
+ $replies->get('notice_id', $this->notice_id);
+ $replies->delete();
+ $this->notice->delete();
+ $this->showNotice();
+ } else {
+ $this->clientError(
+ _('You may not delete another user\'s status.'),
+ 403,
+ $this->format
+ );
+ }
}
/**
diff --git a/actions/apiusershow.php b/actions/apiusershow.php
index 6c8fad49b..28993102c 100644
--- a/actions/apiusershow.php
+++ b/actions/apiusershow.php
@@ -113,7 +113,7 @@ class ApiUserShowAction extends ApiPrivateAuthAction
if ($this->format == 'xml') {
$this->initDocument('xml');
- $this->showTwitterXmlUser($twitter_user);
+ $this->showTwitterXmlUser($twitter_user, 'user', true);
$this->endDocument('xml');
} elseif ($this->format == 'json') {
$this->initDocument('json');
diff --git a/actions/designadminpanel.php b/actions/designadminpanel.php
index 8c08581b5..763737175 100644
--- a/actions/designadminpanel.php
+++ b/actions/designadminpanel.php
@@ -126,9 +126,19 @@ class DesignadminpanelAction extends AdminPanelAction
return;
}
- // check for an image upload
+ // check for file uploads
$bgimage = $this->saveBackgroundImage();
+ $customTheme = $this->saveCustomTheme();
+
+ $oldtheme = common_config('site', 'theme');
+ if ($customTheme) {
+ // This feels pretty hacky :D
+ $this->args['theme'] = $customTheme;
+ $themeChanged = true;
+ } else {
+ $themeChanged = ($this->trimmed('theme') != $oldtheme);
+ }
static $settings = array('theme', 'logo');
@@ -140,15 +150,13 @@ class DesignadminpanelAction extends AdminPanelAction
$this->validate($values);
- $oldtheme = common_config('site', 'theme');
-
$config = new Config();
$config->query('BEGIN');
// Only update colors if the theme has not changed.
- if ($oldtheme == $values['theme']) {
+ if (!$themeChanged) {
$bgcolor = new WebColor($this->trimmed('design_background'));
$ccolor = new WebColor($this->trimmed('design_content'));
@@ -190,6 +198,13 @@ class DesignadminpanelAction extends AdminPanelAction
Config::save('design', 'backgroundimage', $bgimage);
}
+ if (common_config('custom_css', 'enabled')) {
+ $css = $this->arg('css');
+ if ($css != common_config('custom_css', 'css')) {
+ Config::save('custom_css', 'css', $css);
+ }
+ }
+
$config->query('COMMIT');
}
@@ -264,6 +279,33 @@ class DesignadminpanelAction extends AdminPanelAction
}
/**
+ * Save the custom theme if the user uploaded one.
+ *
+ * @return mixed custom theme name, if succesful, or null if no theme upload.
+ * @throws ClientException for invalid theme archives
+ * @throws ServerException if trouble saving the theme files
+ */
+
+ function saveCustomTheme()
+ {
+ if (common_config('theme_upload', 'enabled') &&
+ $_FILES['design_upload_theme']['error'] == UPLOAD_ERR_OK) {
+
+ $upload = ThemeUploader::fromUpload('design_upload_theme');
+ $basedir = common_config('local', 'dir');
+ if (empty($basedir)) {
+ $basedir = INSTALLDIR . '/local';
+ }
+ $name = 'custom'; // @todo allow multiples, custom naming?
+ $outdir = $basedir . '/theme/' . $name;
+ $upload->extract($outdir);
+ return $name;
+ } else {
+ return null;
+ }
+ }
+
+ /**
* Attempt to validate setting values
*
* @return void
@@ -371,7 +413,15 @@ class DesignAdminPanelForm extends AdminForm
function formData()
{
+ $this->showLogo();
+ $this->showTheme();
+ $this->showBackground();
+ $this->showColors();
+ $this->showAdvanced();
+ }
+ function showLogo()
+ {
$this->out->elementStart('fieldset', array('id' => 'settings_design_logo'));
$this->out->element('legend', null, _('Change logo'));
@@ -384,6 +434,11 @@ class DesignAdminPanelForm extends AdminForm
$this->out->elementEnd('ul');
$this->out->elementEnd('fieldset');
+
+ }
+
+ function showTheme()
+ {
$this->out->elementStart('fieldset', array('id' => 'settings_design_theme'));
$this->out->element('legend', null, _('Change theme'));
@@ -407,10 +462,23 @@ class DesignAdminPanelForm extends AdminForm
false, $this->value('theme'));
$this->unli();
+ if (common_config('theme_upload', 'enabled')) {
+ $this->li();
+ $this->out->element('label', array('for' => 'design_upload_theme'), _('Custom theme'));
+ $this->out->element('input', array('id' => 'design_upload_theme',
+ 'name' => 'design_upload_theme',
+ 'type' => 'file'));
+ $this->out->element('p', 'form_guide', _('You can upload a custom StatusNet theme as a .ZIP archive.'));
+ $this->unli();
+ }
+
$this->out->elementEnd('ul');
$this->out->elementEnd('fieldset');
+ }
+ function showBackground()
+ {
$design = $this->out->design;
$this->out->elementStart('fieldset', array('id' =>
@@ -486,6 +554,11 @@ class DesignAdminPanelForm extends AdminForm
$this->out->elementEnd('ul');
$this->out->elementEnd('fieldset');
+ }
+
+ function showColors()
+ {
+ $design = $this->out->design;
$this->out->elementStart('fieldset', array('id' => 'settings_design_color'));
$this->out->element('legend', null, _('Change colours'));
@@ -493,6 +566,7 @@ class DesignAdminPanelForm extends AdminForm
$this->out->elementStart('ul', 'form_data');
try {
+ // @fixme avoid loop unrolling in non-performance-critical contexts like this
$bgcolor = new WebColor($design->backgroundcolor);
@@ -560,6 +634,7 @@ class DesignAdminPanelForm extends AdminForm
$this->unli();
} catch (WebColorException $e) {
+ // @fixme normalize them individually!
common_log(LOG_ERR, 'Bad color values in site design: ' .
$e->getMessage());
}
@@ -569,6 +644,27 @@ class DesignAdminPanelForm extends AdminForm
$this->out->elementEnd('ul');
}
+ function showAdvanced()
+ {
+ if (common_config('custom_css', 'enabled')) {
+ $this->out->elementStart('fieldset', array('id' => 'settings_design_advanced'));
+ $this->out->element('legend', null, _('Advanced'));
+ $this->out->elementStart('ul', 'form_data');
+
+ $this->li();
+ $this->out->element('label', array('for' => 'css'), _('Custom CSS'));
+ $this->out->element('textarea', array('name' => 'css',
+ 'id' => 'css',
+ 'cols' => '50',
+ 'rows' => '10'),
+ strval(common_config('custom_css', 'css')));
+ $this->unli();
+
+ $this->out->elementEnd('fieldset');
+ $this->out->elementEnd('ul');
+ }
+ }
+
/**
* Action elements
*
diff --git a/actions/foaf.php b/actions/foaf.php
index 2f054de0c..09af7b502 100644
--- a/actions/foaf.php
+++ b/actions/foaf.php
@@ -154,7 +154,9 @@ class FoafAction extends Action
}
$person = $this->showMicrobloggingAccount($this->profile,
- common_root_url(), $this->user->uri, false);
+ common_root_url(), $this->user->uri,
+ /*$fetchSubscriptions*/true,
+ /*$isSubscriber*/false);
// Get people who subscribe to user
@@ -209,7 +211,8 @@ class FoafAction extends Action
$this->showMicrobloggingAccount($profile,
($local == 'local') ? common_root_url() : null,
$uri,
- true);
+ /*$fetchSubscriptions*/false,
+ /*$isSubscriber*/($type == LISTENER || $type == BOTH));
if ($foaf_url) {
$this->element('rdfs:seeAlso', array('rdf:resource' => $foaf_url));
}
@@ -234,7 +237,21 @@ class FoafAction extends Action
$this->elementEnd('PersonalProfileDocument');
}
- function showMicrobloggingAccount($profile, $service=null, $useruri=null, $isSubscriber=false)
+ /**
+ * Output FOAF <account> bit for the given profile.
+ *
+ * @param Profile $profile
+ * @param mixed $service Root URL of this StatusNet instance for a local
+ * user, otherwise null.
+ * @param mixed $useruri URI string for the referenced profile..
+ * @param boolean $fetchSubscriptions Should we load and list all their subscriptions?
+ * @param boolean $isSubscriber if not fetching subs, we can still mark the user as following the current page.
+ *
+ * @return array if $fetchSubscribers is set, return a list of info on those
+ * subscriptions.
+ */
+
+ function showMicrobloggingAccount($profile, $service=null, $useruri=null, $fetchSubscriptions=false, $isSubscriber=false)
{
$attr = array();
if ($useruri) {
@@ -256,9 +273,7 @@ class FoafAction extends Action
$person = array();
- if ($isSubscriber) {
- $this->element('sioc:follows', array('rdf:resource'=>$this->user->uri . '#acct'));
- } else {
+ if ($fetchSubscriptions) {
// Get people user is subscribed to
$sub = new Subscription();
$sub->subscriber = $profile->id;
@@ -283,6 +298,9 @@ class FoafAction extends Action
}
unset($sub);
+ } else if ($isSubscriber) {
+ // Just declare that they follow the user whose FOAF we're showing.
+ $this->element('sioc:follows', array('rdf:resource' => $this->user->uri . '#acct'));
}
$this->elementEnd('OnlineAccount');