# # This program 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 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY 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 this program. If not, see . define('NO_GUI', 1); ignore_user_abort(true); set_time_limit(1800); global $db; global $_USER; $PARAMS = PARAMS; switch($PARAMS) { case 'clean': if ($_GET['p'] == CRON_PW) $db->cleanTwitter(); else die('

Invalid password.

'); break; case 'update': ob_start(); $user = (int) $_GET['user']; if(!$user) die; updateTimeline($user); break; case 'twitter': if (!$_GET['note']) die("There's no note."); if (!$_GET['user_id']) die("There's no user."); else $user_id = $_GET['user_id']; $note = $db->getNoteInfo($_GET['note']); if (!$note) die("It doesn't exists. (note)"); $user = $db->getUserInfo($user_id); if (!$user) die("It doesn't exists. (user)"); if ($_GET['auth'] != md5($user['salt'])) die("403. Forbidden"); else { if (empty($user['twitter_username']) || empty($user['twitter_password'])) return; //Removing note's format. $note['note'] = preg_replace('/\[(\*|\/|_|\-)(.+)\]/U', '$2', $note['note']); if ($note['attached_file']) { //The URL of the file. $url = BASE.'download/'.$note['ID'].'/'.$note['attached_file']; //We're trying to short the download URL. $shorter_service = unserialize($user['shorter_service']); if ($shorter_service['service'] == 'default') { if (defined('DEFAULT_SHORTER_SERVICE')) $sh_service = DEFAULT_SHORTER_SERVICE; else $sh_service = 'none'; } else $sh_service = $shorter_service['service']; if ($sh_service != 'none') { $url = shorter_url(array($url), $sh_service); } if ((strlen($note['note']) + strlen($url)) > 140) { $calc = strlen($url) + 9; $note['note'] = substr($note['note'], 0, (strlen($note['note']) - $calc))." (...) - ".$url; } else $note['note'] = $note['note']." - $url"; } $curl_handle = curl_init(); $note['note'] = stripslashes($note['note']); curl_setopt($curl_handle, CURLOPT_URL, "http://twitter.com/statuses/update.json"); curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_handle, CURLOPT_POST, 1); curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=".$note['note']."&source=".NAME); curl_setopt($curl_handle, CURLOPT_USERPWD, $user['twitter_username'].':'.base64_decode($user['twitter_password'])); $buffer = curl_exec($curl_handle); curl_close($curl_handle); } break; } ?>