/**
  * Handle the request
  *
  * @param array $args $_REQUEST data (unused)
  *
  * @return void
  */
 protected function handle()
 {
     parent::handle();
     $user = common_current_user();
     $profile = $user->getProfile();
     // what to toggle
     if (QvitterPlugin::settings('enabledbydefault')) {
         $toggle = 'disable_qvitter';
     } else {
         $toggle = 'enable_qvitter';
     }
     // new value
     $state = Profile_prefs::getConfigData($profile, 'qvitter', $toggle);
     if ($state == 1) {
         $new_state = 0;
     } else {
         $new_state = 1;
     }
     try {
         $pref_saved = Profile_prefs::setData($profile, 'qvitter', $toggle, $new_state);
         $result['success'] = true;
     } catch (ServerException $e) {
         $result['success'] = false;
         $result['error'] = $e;
     }
     if (!$pref_saved) {
         $result['success'] = false;
         $result['error'] = 'Probably couldn\'t get topic from pref table';
     }
     $this->initDocument('json');
     $this->showJsonObjects($result);
     $this->endDocument('json');
 }
 /**
  * Handle the request
  *
  * @param array $args $_REQUEST data (unused)
  *
  * @return void
  */
 protected function handle()
 {
     parent::handle();
     // save the new bookmarks
     $saved = Profile_prefs::setData($this->scoped, $this->prefNamespace, $this->prefTopic, $this->prefData);
     $this->initDocument('json');
     $this->showJsonObjects($saved);
     $this->endDocument('json');
 }
 /**
  * Handle the request
  *
  * @param array $args $_REQUEST data (unused)
  *
  * @return void
  */
 protected function handle()
 {
     parent::handle();
     // save the new bookmarks
     $saved = Profile_prefs::setData($this->scoped, 'qvitter', 'bookmarks', $this->bookmarks);
     $this->initDocument('json');
     $this->showJsonObjects($saved);
     $this->endDocument('json');
 }
 /**
  * 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
  */
 protected function handle()
 {
     parent::handle();
     $validhex = preg_match('/^[a-f0-9]{6}$/i', $this->linkcolor);
     if ($validhex === false || $validhex == 0) {
         $this->clientError(_('Not a valid hex color.'), 400);
     }
     // save the new color
     Profile_prefs::setData($this->scoped, 'theme', 'linkcolor', $this->linkcolor);
     $twitter_user = $this->twitterUserArray($this->scoped, true);
     $this->initDocument('json');
     $this->showJsonObjects($twitter_user);
     $this->endDocument('json');
 }
 /**
  * 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
  */
 protected function handle()
 {
     parent::handle();
     $validhex = preg_match('/^[a-f0-9]{6}$/i', $this->backgroundcolor);
     if ($validhex === false || $validhex == 0) {
         $this->clientError(_('Not a valid hex color.'), 400);
     }
     Profile_prefs::setData($this->scoped, 'theme', 'backgroundcolor', $this->backgroundcolor);
     // unset background-image
     Profile_prefs::setData($this->scoped, 'qvitter', 'background_image', '');
     $twitter_user = $this->twitterUserArray($this->scoped, true);
     $this->initDocument('json');
     $this->showJsonObjects($twitter_user);
     $this->endDocument('json');
 }
 /**
  * Handle the request
  *
  * @return void
  */
 protected function handle()
 {
     parent::handle();
     $profile = $this->user->getProfile();
     $base64img = $this->img;
     if (stristr($base64img, 'image/jpeg')) {
         $base64img_mime = 'image/jpeg';
     } elseif (stristr($base64img, 'image/png')) {
         // should convert to jpg here!!
         $base64img_mime = 'image/png';
     }
     $base64img = str_replace('data:image/jpeg;base64,', '', $base64img);
     $base64img = str_replace('data:image/png;base64,', '', $base64img);
     $base64img = str_replace(' ', '+', $base64img);
     $base64img_hash = md5($base64img);
     $base64img = base64_decode($base64img);
     $base64img_basename = basename('bg');
     $base64img_filename = File::filename($profile, $base64img_basename, $base64img_mime);
     $base64img_path = File::path($base64img_filename);
     $base64img_success = file_put_contents($base64img_path, $base64img);
     $base64img_mimetype = MediaFile::getUploadedMimeType($base64img_path, $base64img_filename);
     $mediafile = new MediaFile($profile, $base64img_filename, $base64img_mimetype);
     $imagefile = new ImageFile($mediafile->fileRecord->id, File::path($mediafile->filename));
     $imagefile->resizeTo(File::path($mediafile->filename), array('width' => 1280, 'height' => 1280, 'x' => $this->cropX, 'y' => $this->cropY, 'w' => $this->cropW, 'h' => $this->cropH));
     $result['url'] = File::url($mediafile->filename);
     Profile_prefs::setData($profile, 'qvitter', 'background_image', $result['url']);
     $this->initDocument('json');
     $this->showJsonObjects($result);
     $this->endDocument('json');
 }
示例#7
0
 public function setPref($namespace, $topic, $data)
 {
     return Profile_prefs::setData($this, $namespace, $topic, $data);
 }
示例#8
0
 /**
  * Handler method
  *
  * @param array $argarray is ignored since it's now passed in in prepare()
  *
  * @return void
  */
 function handlePost()
 {
     $user = common_current_user();
     if (QvitterPlugin::settings('enabledbydefault')) {
         Profile_prefs::setData($user->getProfile(), 'qvitter', 'disable_qvitter', $this->boolean('disable_qvitter'));
     } else {
         Profile_prefs::setData($user->getProfile(), 'qvitter', 'enable_qvitter', $this->boolean('enable_qvitter'));
     }
     Profile_prefs::setData($user->getProfile(), 'qvitter', 'hide_replies', $this->boolean('hide_replies'));
     // TRANS: Confirmation shown when user profile settings are saved.
     $this->showForm(_('Settings saved.'), true);
     return;
 }
 /**
  * Handle the request
  *
  * @return void
  */
 protected function handle()
 {
     parent::handle();
     $profile = $this->user->getProfile();
     // see if we have regular uploaded image data
     try {
         $mediafile = MediaFile::fromUpload('banner', $profile);
     } catch (NoUploadedMediaException $e) {
         // if not we may have base64 data
         $img = $this->img;
         if (stristr($img, 'image/jpeg')) {
             $img_mime = 'image/jpeg';
         } elseif (stristr($img, 'image/png')) {
             // should convert to jpg here!!
             $img_mime = 'image/png';
         }
         // i don't remember why we had to do this
         $img = str_replace('data:image/jpeg;base64,', '', $img);
         $img = str_replace('data:image/png;base64,', '', $img);
         $img = str_replace(' ', '+', $img);
         $img = base64_decode($img, true);
         try {
             $img_filename = File::filename($profile, 'cover', $img_mime);
             $img_path = File::path($img_filename);
             $img_success = file_put_contents($img_path, $img);
             $img_mimetype = MediaFile::getUploadedMimeType($img_path, $img_filename);
             $mediafile = new MediaFile($profile, $img_filename, $img_mimetype);
         } catch (Exception $e) {
             $this->clientError($e, 400);
         }
     }
     if (!$mediafile instanceof MediaFile) {
         $this->clientError(_('Could not process image data.'), 400);
     }
     // maybe resize
     $width = $this->cropW;
     $height = $this->cropH;
     $scale = 1;
     if ($width > 1200) {
         $scale = 1200 / $width;
     } elseif ($height > 600) {
         $scale = 600 / $height;
     }
     $width = round($width * $scale);
     $height = round($height * $scale);
     // crop
     try {
         $imagefile = new ImageFile($mediafile->fileRecord->id, File::path($mediafile->filename));
         $imagefile->resizeTo(File::path($mediafile->filename), array('width' => $width, 'height' => $height, 'x' => $this->cropX, 'y' => $this->cropY, 'w' => $this->cropW, 'h' => $this->cropH));
         $result['url'] = File::url($mediafile->filename);
     } catch (Exception $e) {
         $this->clientError(_('The image could not be resized and cropped. ' . $e), 422);
     }
     // save in profile_prefs
     try {
         Profile_prefs::setData($profile, 'qvitter', 'cover_photo', $result['url']);
     } catch (ServerException $e) {
         $this->clientError(_('The image could not be resized and cropped. ' . $e), 422);
     }
     // return json
     $this->initDocument('json');
     $this->showJsonObjects($result);
     $this->endDocument('json');
 }