function getInstructions()
{
- return _('Customize the way your profile looks with a background image and a colour palette of your choice.');
+ return _('Customize the way your profile looks ' .
+ 'with a background image and a colour palette of your choice.');
}
/**
{
$user = common_current_user();
$this->elementStart('form', array('method' => 'post',
+ 'enctype' => 'multipart/form-data',
'id' => 'form_settings_design',
'class' => 'form_settings',
'action' =>
- common_local_url('designsettings')));
+ common_local_url('designsettings')));
$this->elementStart('fieldset');
$this->hidden('token', common_session_token());
- $this->elementStart('fieldset', array('id' => 'settings_design_background-image'));
+ $this->elementStart('fieldset', array('id' =>
+ 'settings_design_background-image'));
$this->element('legend', null, _('Change background image'));
$this->elementStart('ul', 'form_data');
$this->elementStart('li');
$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('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',
function handlePost()
{
+ // XXX: Robin's workaround for a bug in PHP where $_POST
+ // and $_FILE are empty in the case that the uploaded
+ // file is bigger than PHP is configured to handle.
+
+ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+ if (empty($_POST) && $_SERVER['CONTENT_LENGTH']) {
+
+ $msg = _('The server was unable to handle that much POST ' .
+ 'data (%s bytes) due to its current configuration.');
+
+ $this->showForm(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
+ }
+ }
+
// CSRF protection
$token = $this->trimmed('token');
if (!$token || $token != common_session_token()) {
function saveDesign()
{
- $user = common_current_user();
-
try {
$bgcolor = new WebColor($this->trimmed('design_background'));
return;
}
+ $user = common_current_user();
$design = $user->getDesign();
if (!empty($design)) {
$design->sidebarcolor = $sbcolor->intValue();
$design->textcolor = $tcolor->intValue();
$design->linkcolor = $lcolor->intValue();
+ $design->backgroundimage = $filepath;
$result = $design->update($original);
$design->sidebarcolor = $sbcolor->intValue();
$design->textcolor = $tcolor->intValue();
$design->linkcolor = $lcolor->intValue();
- $design->backgroundimage = $defaults['backgroundimage'];
+ $design->backgroundimage = $filepath;
$id = $design->insert();
}
+ // Now that we have a Design ID we can add a file to the design.
+ // XXX: This is an additional DB hit, but figured having the image
+ // associated with the Design rather than the User was worth
+ // it. -- Zach
+
+ if ($_FILES['design_background-image_file']['error'] ==
+ UPLOAD_ERR_OK) {
+
+ $filepath = null;
+
+ try {
+ $imagefile =
+ ImageFile::fromUpload('design_background-image_file');
+ } catch (Exception $e) {
+ $this->showForm($e->getMessage());
+ return;
+ }
+
+ $filename = Design::filename($design->id,
+ image_type_to_extension($imagefile->type),
+ common_timestamp());
+
+ $filepath = Design::path($filename);
+
+ move_uploaded_file($imagefile->filepath, $filepath);
+
+ $original = clone($design);
+ $design->backgroundimage = $filename;
+ $result = $design->update($original);
+
+ if ($result === false) {
+ common_log_db_error($design, 'UPDATE', __FILE__);
+ $this->showForm(_('Couldn\'t update your design.'));
+ return;
+ }
+ }
+
$this->showForm(_('Design preferences saved.'), true);
}
__FILE__);
}
- $out->element('style', array('type' => 'text/css'),
- 'html, body { background-color: #' . $bgcolor->hexValue() . '} '."\n".
- '#content, #site_nav_local_views .current a { background-color: #' .
- $ccolor->hexValue() . '} '."\n".
- '#aside_primary { background-color: #'. $sbcolor->hexValue() .'} '."\n".
- 'html body { color: #'. $tcolor->hexValue() .'} '."\n".
- 'a { color: #' . $lcolor->hexValue() . '} '."\n");
+ $css = 'html, body { background-color: #' . $bgcolor->hexValue() . '} ' . "\n";
+ $css .= '#content, #site_nav_local_views .current a { background-color: #';
+ $css .= $ccolor->hexValue() . '} '."\n";
+ $css .= '#aside_primary { background-color: #'. $sbcolor->hexValue() . '} ' . "\n";
+ $css .= 'html body { color: #'. $tcolor->hexValue() . '} '. "\n";
+ $css .= 'a { color: #' . $lcolor->hexValue() . '} ' . "\n";
+
+ if (!empty($this->backgroundimage)) {
+
+ $css .= 'body { background-image:url(' .
+ Design::url($this->backgroundimage) .
+ '); background-repeat:no-repeat; }' . "\n";
+ }
+
+ $out->element('style', array('type' => 'text/css'), $css);
+
+ }
+
+ static function filename($id, $extension, $extra=null)
+ {
+ return $id . (($extra) ? ('-' . $extra) : '') . $extension;
+ }
+
+ static function path($filename)
+ {
+ $dir = common_config('background', 'dir');
+
+ if ($dir[strlen($dir)-1] != '/') {
+ $dir .= '/';
+ }
+
+ return $dir . $filename;
}
+
+ static function url($filename)
+ {
+ $path = common_config('background', 'path');
+
+ if ($path[strlen($path)-1] != '/') {
+ $path .= '/';
+ }
+
+ if ($path[0] != '/') {
+ $path = '/'.$path;
+ }
+
+ $server = common_config('background', 'server');
+
+ if (empty($server)) {
+ $server = common_config('site', 'server');
+ }
+
+ // XXX: protocol
+
+ return 'http://'.$server.$path.$filename;
+ }
+
}