. * * @category API * @package StatusNet * @author Hannes Mannerheim * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ if (!defined('STATUSNET')) { exit(1); } require_once INSTALLDIR . '/lib/apiauth.php'; class ApiAccountUpdateBackgroundColorAction extends ApiAuthAction { var $backgroundcolor = null; /** * Take arguments for running * * @param array $args $_REQUEST args * * @return boolean success flag */ function prepare($args) { parent::prepare($args); $this->user = $this->auth_user; $this->backgroundcolor = $this->trimmed('backgroundcolor'); return true; } /** * Handle the request * * Try to save the user's colors in her design. Create a new design * if the user doesn't already have one. * * @param array $args $_REQUEST data (unused) * * @return void */ function handle($args) { parent::handle($args); if ($_SERVER['REQUEST_METHOD'] != 'POST') { $this->clientError( _('This method requires a POST.'), 400, $this->format ); return; } $validhex = preg_match('/^[a-f0-9]{6}$/i',$this->backgroundcolor); if($validhex === false || $validhex == 0) { $this->clientError(_('Not a valid hex color.'),404,'json'); return; } // save the new color $original = clone($this->user); $this->user->backgroundcolor = $this->backgroundcolor; if (!$this->user->update($original)) { $this->clientError(_('Error updating user.'),404,'json'); return; } $profile = $this->user->getProfile(); if (empty($profile)) { $this->clientError(_('User has no profile.'),'json'); return; } $twitter_user = $this->twitterUserArray($profile, true); $this->initDocument('json'); $this->showJsonObjects($twitter_user); $this->endDocument('json'); } }