X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=actions%2Ftwittersettings.php;h=cf50be62af59396bdf63adde15e30751c2b4eddc;hb=485247e9011e08a6ff0b9a2ff3d7a60bad515a26;hp=a7c70c287662514a4dfa7a85a97da8a9bc4b535c;hpb=06859cc14e5d68c83e4ecb38a0a32f354bc6ed80;p=quix0rs-gnu-social.git diff --git a/actions/twittersettings.php b/actions/twittersettings.php index a7c70c2876..cf50be62af 100644 --- a/actions/twittersettings.php +++ b/actions/twittersettings.php @@ -69,21 +69,19 @@ class TwittersettingsAction extends SettingsAction { common_element('h2', NULL, _('Preferences')); - if ($flink) { - common_checkbox('noticesync', _('Automatically send my notices to Twitter.'), - ($flink->noticesync > 0) ? true : false); + common_checkbox('noticesync', _('Automatically send my notices to Twitter.'), + ($flink) ? ($flink->noticesync & FOREIGN_NOTICE_SEND) : true); - common_checkbox('replysync', _('Don\'t send local "@" replies to Twitter.'), - ($flink->noticesync == 3) ? true : false, NULL, 'true'); + common_checkbox('replysync', _('Send local "@" replies to Twitter.'), + ($flink) ? ($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) : true); - common_checkbox('friendsync', _('Subscribe to my Twitter friends here.'), - ($flink->friendsync) ? true : false, NULL, 'true', true); + common_checkbox('friendsync', _('Subscribe to my Twitter friends here.'), + ($flink) ? ($flink->friendsync & FOREIGN_FRIEND_RECV) : false, + NULL, 'true', true); + if ($flink) { common_submit('save', _('Save')); } else { - common_checkbox('noticesync', _('Automatically send my notices to Twitter.'), true); - common_checkbox('replysync', _('Don\'t send local "@" replies to Twitter.'), false, NULL, 'true'); - common_checkbox('friendsync', _('Subscribe to my Twitter friends here.'), false, NULL, 'true', true); common_submit('add', _('Add')); } @@ -163,16 +161,8 @@ class TwittersettingsAction extends SettingsAction { $flink->credentials = $twitter_password; $flink->created = common_sql_now(); - if ($noticesync) { - if ($replysync) { - $flink->noticesync = 3; - } else { - $flink->noticesync = 1; - } - } - - $flink->friendsync = ($friendsync) ? 2 : 0; - $flink->profilesync = 0; // XXX: leave as default? + $this->set_flags($flink, $noticesync, $replysync, $friendsync); + $flink_id = $flink->insert(); if (!$flink_id) { @@ -236,24 +226,22 @@ class TwittersettingsAction extends SettingsAction { return; } - if ($noticesync) { - if ($replysync) { - $flink->noticesync = 3; - } else { - $flink->noticesync = 1; - } - } + $flink->query('BEGIN'); - $flink->friendsync = ($friendsync) ? 2 : 0; - // $flink->profilesync = 0; // XXX: leave as default? - $result = $flink->update(); + $original = clone($flink); + + $this->set_flags($flink, $noticesync, $replysync, $friendsync); - if (!$result) { + $result = $flink->update($original); + + if ($result === FALSE) { common_log_db_error($flink, 'UPDATE', __FILE__); $this->show_form(_('Couldn\'t save Twitter preferences.')); return; } + $flink->query('COMMIT'); + $this->show_form(_('Twitter preferences saved.')); return; @@ -324,4 +312,25 @@ class TwittersettingsAction extends SettingsAction { return $data; } + function set_flags(&$flink, $noticesync, $replysync, $friendsync) { + if ($noticesync) { + $flink->noticesync |= FOREIGN_NOTICE_SEND; + } else { + $flink->noticesync &= ~FOREIGN_NOTICE_SEND; + } + + if ($replysync) { + $flink->noticesync |= FOREIGN_NOTICE_SEND_REPLY; + } else { + $flink->noticesync &= ~FOREIGN_NOTICE_SEND_REPLY; + } + + if ($friendsync) { + $flink->friendsync |= FOREIGN_FRIEND_RECV; + } else { + $flink->friendsync &= ~FOREIGN_FRIEND_RECV; + } + + $flink->profilesync = 0; // XXX: leave as default? + } } \ No newline at end of file