PageRenderTime 25ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/social/lib/social/controller/settings.php

https://gitlab.com/Blueprint-Marketing/interoccupy.net
PHP | 185 lines | 111 code | 27 blank | 47 comment | 21 complexity | 9a81476f0a463f0acd7d339d0fbd7c9b MD5 | raw file
  1. <?php
  2. /**
  3. * Settings Controller
  4. *
  5. * @package Social
  6. * @subpackage controllers
  7. */
  8. final class Social_Controller_Settings extends Social_Controller {
  9. /**
  10. * Handles the request for Social's settings.
  11. *
  12. * @return void
  13. */
  14. public function action_index() {
  15. if ($this->request->post('submit')) {
  16. Social::option('broadcast_format', $this->request->post('social_broadcast_format'));
  17. Social::option('comment_broadcast_format', $this->request->post('social_comment_broadcast_format'));
  18. Social::option('debug', $this->request->post('social_debug'));
  19. if (!Social::option('debug')) {
  20. delete_option('social_log_write_error');
  21. }
  22. if (isset($_POST['social_broadcast_by_default'])) {
  23. Social::option('broadcast_by_default', $_POST['social_broadcast_by_default']);
  24. }
  25. else {
  26. delete_option('social_broadcast_by_default');
  27. }
  28. if (isset($_POST['social_aggregate_comments'])) {
  29. Social::option('aggregate_comments', $_POST['social_aggregate_comments']);
  30. }
  31. else {
  32. delete_option('social_aggregate_comments');
  33. }
  34. // Store the default accounts
  35. $accounts = array();
  36. if (is_array($this->request->post('social_default_accounts'))) {
  37. foreach ($this->request->post('social_default_accounts') as $account) {
  38. $account = explode('|', $account);
  39. $accounts[$account[0]][] = $account[1];
  40. }
  41. }
  42. $accounts = apply_filters('social_settings_default_accounts', $accounts, $this);
  43. if (count($accounts)) {
  44. Social::option('default_accounts', $accounts);
  45. }
  46. else {
  47. delete_option('social_default_accounts');
  48. }
  49. // API accounts
  50. if ($this->request->post('social_api_accounts')) {
  51. Social::option('social_api_accounts', $this->request->post('social_api_accounts'));
  52. }
  53. // System CRON
  54. if ($this->request->post('social_cron') !== null) {
  55. Social::option('cron', $this->request->post('social_cron'));
  56. // Unschedule the CRONs
  57. if ($this->request->post('social_cron') != '1' and ($timestamp = wp_next_scheduled('social_cron_15_init')) !== false) {
  58. wp_unschedule_event($timestamp, 'social_cron_15_init');
  59. }
  60. }
  61. // Disable Social's comment display feature
  62. if (isset($_POST['social_use_standard_comments'])) {
  63. Social::option('use_standard_comments', '1');
  64. }
  65. else {
  66. delete_option('social_use_standard_comments');
  67. }
  68. // Disable Social's broadcast feature
  69. if (isset($_POST['social_disable_broadcasting'])) {
  70. Social::option('disable_broadcasting', '1');
  71. }
  72. else {
  73. delete_option('social_disable_broadcasting');
  74. }
  75. do_action('social_settings_save', $this);
  76. wp_redirect(Social::settings_url(array('saved' => 'true')));
  77. exit;
  78. }
  79. $accounts = array();
  80. foreach ($this->social->services() as $key => $service) {
  81. if (!isset($accounts[$key])) {
  82. $accounts[$key] = array();
  83. }
  84. foreach ($service->accounts() as $account) {
  85. if ($account->universal()) {
  86. $accounts[$key][] = $account->id();
  87. }
  88. }
  89. }
  90. echo Social_View::factory('wp-admin/options', array(
  91. 'services' => $this->social->services(),
  92. 'accounts' => $accounts,
  93. 'defaults' => Social::option('default_accounts'),
  94. ));
  95. }
  96. /**
  97. * Suppresses the enable notice.
  98. *
  99. * @return void
  100. */
  101. public function action_suppress_enable_notice() {
  102. update_user_meta(get_current_user_id(), 'social_suppress_enable_notice', 'true');
  103. }
  104. /**
  105. * Supress the no accounts notice.
  106. *
  107. * @return void
  108. */
  109. public function action_suppress_no_accounts_notice() {
  110. update_user_meta(get_current_user_id(), 'social_suppress_no_accounts_notice', 'true');
  111. }
  112. /**
  113. * Clears the deauthorized notice.
  114. *
  115. * @return void
  116. */
  117. public function action_clear_deauth() {
  118. $id = $_GET['clear_deauth'];
  119. $service = $_GET['service'];
  120. $deauthed = get_option('social_deauthed', array());
  121. if (isset($deauthed[$service][$id])) {
  122. unset($deauthed[$service][$id]);
  123. update_option('social_deauthed', $deauthed);
  124. $this->social->remove_from_default_accounts($service, $id);
  125. }
  126. }
  127. /**
  128. * Clears the log write error notice.
  129. *
  130. * @return void
  131. */
  132. public function action_clear_log_write_error() {
  133. delete_option('social_log_write_error');
  134. }
  135. /**
  136. * Clears the 2.0 upgrade notice.
  137. *
  138. * @return void
  139. */
  140. public function action_clear_2_0_upgrade() {
  141. delete_user_meta(get_current_user_id(), 'social_2.0_upgrade');
  142. }
  143. /**
  144. * Regenerates the API key.
  145. *
  146. * @return void
  147. */
  148. public function action_regenerate_api_key() {
  149. $this->verify_nonce();
  150. if (!$this->request->is_ajax()) {
  151. wp_die('Oops, this method can only be accessed via an AJAX request.');
  152. }
  153. $key = wp_generate_password(16, false);
  154. Social::option('system_cron_api_key', $key, true);
  155. echo $key;
  156. exit;
  157. }
  158. } // End Social_Controller_Settings