public function handle_process($process, $options = array()) { switch ($process) { case 'send_social_message': check_admin_referer('social_send-message'); $message_count = 0; if (isset($options['social_message_id']) && (int) $options['social_message_id'] > 0 && isset($_POST['twitter_message']) && !empty($_POST['twitter_message'])) { // we have a social message id, ready to send! // which twitter accounts are we sending too? $twitter_accounts = isset($_POST['compose_twitter_id']) && is_array($_POST['compose_twitter_id']) ? $_POST['compose_twitter_id'] : array(); foreach ($twitter_accounts as $twitter_account_id => $tf) { if (!$tf) { continue; } // shoulnd't happen, as checkbox shouldn't post. $twitter_account = new ucm_twitter_account($twitter_account_id); if ($twitter_account->get('social_twitter_id') == $twitter_account_id) { // good to go! send us a message! $twitter_message = new ucm_twitter_message($twitter_account, false); $twitter_message->create_new(); $twitter_message->update('social_twitter_id', $twitter_account->get('social_twitter_id')); $twitter_message->update('social_message_id', $options['social_message_id']); $twitter_message->update('summary', isset($_POST['twitter_message']) ? $_POST['twitter_message'] : ''); if (isset($_POST['track_links']) && $_POST['track_links']) { $twitter_message->parse_links(); } $twitter_message->update('type', 'pending'); $twitter_message->update('data', json_encode($_POST)); $twitter_message->update('user_id', get_current_user_id()); // do we send this one now? or schedule it later. $twitter_message->update('status', _SOCIAL_MESSAGE_STATUS_PENDINGSEND); if (isset($options['send_time']) && !empty($options['send_time'])) { // schedule for sending at a different time (now or in the past) $twitter_message->update('message_time', $options['send_time']); } else { // send it now. $twitter_message->update('message_time', 0); } if (isset($_FILES['picture']['tmp_name']) && is_uploaded_file($_FILES['picture']['tmp_name'])) { $twitter_message->add_attachment($_FILES['picture']['tmp_name']); } $now = time(); if (!$twitter_message->get('message_time') || $twitter_message->get('message_time') <= $now) { // send now! otherwise we wait for cron job.. if ($twitter_message->send_queued(isset($_POST['debug']) && $_POST['debug'])) { $message_count++; } } else { $message_count++; if (isset($_POST['debug']) && $_POST['debug']) { echo "Message will be sent in cron job after " . print_date($twitter_message->get('message_time'), true); } } } } } return $message_count; break; case 'save_twitter_settings': check_admin_referer('save-twitter-settings'); if (isset($_POST['twitter_app_api_key'])) { $this->update('api_key', $_POST['twitter_app_api_key']); } if (isset($_POST['twitter_app_api_secret'])) { $this->update('api_secret', $_POST['twitter_app_api_secret']); } break; case 'save_twitter': $social_twitter_id = isset($_REQUEST['social_twitter_id']) ? (int) $_REQUEST['social_twitter_id'] : 0; check_admin_referer('save-twitter' . $social_twitter_id); $twitter = new ucm_twitter_account($social_twitter_id); if (isset($_POST['butt_delete'])) { $twitter->delete(); $redirect = 'admin.php?page=simple_social_inbox_twitter_settings'; } else { $twitter->save_data($_POST); $social_twitter_id = $twitter->get('social_twitter_id'); if (isset($_POST['butt_save_reconnect'])) { $redirect = $twitter->link_connect(); } else { $redirect = $twitter->link_edit(); } } header("Location: {$redirect}"); exit; break; } }