104 lines
4.3 KiB
PHP
104 lines
4.3 KiB
PHP
<?php
|
|
|
|
/* · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
|
|
· ·
|
|
· ·
|
|
· Q V I T T E R ·
|
|
· ·
|
|
· https://git.gnu.io/h2p/Qvitter ·
|
|
· ·
|
|
· ·
|
|
· <o) ·
|
|
· /_//// ·
|
|
· (____/ ·
|
|
· (o< ·
|
|
· o> \\\\_\ ·
|
|
· \\) \____) ·
|
|
· ·
|
|
· ·
|
|
· ·
|
|
· Qvitter is free software: you can redistribute it and / or modify it ·
|
|
· under the terms of the GNU Affero General Public License as published by ·
|
|
· the Free Software Foundation, either version three of the License or (at ·
|
|
· your option) any later version. ·
|
|
· ·
|
|
· Qvitter is distributed in hope that it will be useful but WITHOUT ANY ·
|
|
· WARRANTY; without even the implied warranty of MERCHANTABILTY or FITNESS ·
|
|
· FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for ·
|
|
· more details. ·
|
|
· ·
|
|
· You should have received a copy of the GNU Affero General Public License ·
|
|
· along with Qvitter. If not, see <http://www.gnu.org/licenses/>. ·
|
|
· ·
|
|
· Contact h@nnesmannerhe.im if you have any questions. ·
|
|
· ·
|
|
· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */
|
|
|
|
|
|
if (!defined('GNUSOCIAL')) { exit(1); }
|
|
|
|
class ApiToggleQvitterAction extends ApiAuthAction
|
|
{
|
|
|
|
/**
|
|
* Take arguments for running
|
|
*
|
|
* @param array $args $_REQUEST args
|
|
*
|
|
* @return boolean success flag
|
|
*/
|
|
protected function prepare(array $args=array())
|
|
{
|
|
parent::prepare($args);
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 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');
|
|
}
|
|
}
|