# # 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('THETIME', time()); class JiskoBot { var $_list = array(); var $_last = 0; var $_public = array(); var $_all_last = 0; function JiskoBot () { mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); mysql_select_db(DB_NAME); mysql_query('SET NAMES `utf8`'); $query = mysql_query("SELECT MAX(ID) FROM notes WHERE `notes`.`type` = 'public'"); $this->_last = mysql_result($query, 0); $this->_public = explode(';', JABBER_FEED_ALLOWED); } function get_jid ($from) { list($jid) = explode('/', $from, 2); return $jid; } function unregister_jid ($jid) { unset($this->_list[$jid]); } function check_jid($jid) { return (bool) (isset($this->_list[$jid])); } function register_jid ($jid) { $this->unregister_jid($jid); $this->_list[$jid] = 1; } function is_online($jid) { return (bool) (array_key_exists($jid, $this->_list)); } function set_off ($jid) { mysql_query("UPDATE `users` SET `users`.`jabber_notifications` = 0 WHERE `users`.`jabber` = '$jid'"); } function set_on ($jid) { mysql_query("UPDATE `users` SET `users`.`jabber_notifications` = 1 WHERE `users`.`jabber` = '$jid'"); } function check_off ($jid) { return (bool) (!array_key_exists($jid, $this->_off)); } function get_profile ($jid) { $jid = filter_var($jid, FILTER_VALIDATE_EMAIL); if(!$jid) return false; $query = mysql_query("SELECT * FROM users WHERE jabber = '$jid' LIMIT 1"); if(!mysql_num_rows($query)) return false; return mysql_fetch_assoc($query); } function allowable ($jid) { if(!$this->is_online($jid)) return false; return true; } function get_dests ($user) { $query = mysql_query("SELECT `users`.`ID` AS user_id, `users`.`jabber` AS `jabber`, `users`.`ignored` AS `ignored`, `users`.`jabber_notifications`, `relationships`.`both` AS `both` FROM `users` , `relationships` WHERE `relationships`.`who` = ".(int)$user." AND `relationships`.`creator` = `users`.`ID` AND `users`.`jabber` <> ''"); $resp = array(); while($row = mysql_fetch_assoc($query)) { $row['ignored'] = explode(',', $row['ignored']); $resp[] = $row; } return $resp; } function get_queue () { $sql = "SELECT `notes`.`ID`, `notes`.`user_id`, `notes`.`note`, `notes`.`from`, `users`.`username`, `notes`.`from`, `notes`.`reply_user`, `notes`.`attached_file`, `notes`.`type` AS type FROM users, notes WHERE `notes`.`type` = 'public' AND `notes`.`user_id` = `users`.`ID` AND `notes`.`ID` > ".(int)$this->_last." ORDER BY `notes`.`ID` ASC LIMIT 50"; $query = mysql_query($sql); $resp = array(); $ids = array(); while($row = mysql_fetch_assoc($query)) { $resp[] = $row; $ids[] = $row['ID']; } if(count($ids)) $this->_last = max($ids); unset($ids); return $resp; } function send_update ($username, $api, $status) { $status = urlencode(stripslashes($status)); $url = BASE.'statuses/update'; $credentials = "$username:$api"; $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_URL, $url); curl_setopt($curl_handle, CURLOPT_USERPWD, $credentials); curl_setopt($curl_handle, CURLOPT_POST, 1); curl_setopt($curl_handle, CURLOPT_POSTFIELDS, 'status='.$status.'&source=jabber'); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, TRUE); curl_exec($curl_handle); curl_close($curl_handle); } function last_note_id ($userid) { $query = mysql_query("SELECT MAX(ID) FROM `notes` WHERE `notes`.`type` = 'public' AND `notes`.`user_id` = $userid"); if(!mysql_num_rows($query)) return false; return mysql_result($query, 0); } function get_id($nick) { $nick = mysql_real_escape_string($nick); $query = mysql_query("SELECT `users`.`ID` FROM `users` WHERE `users`.`username` = '$nick'"); if(!mysql_num_rows($query)) return false; return mysql_result($query, 0); } function note_of ($user) { $id = $this->get_id($user); if(!$id) return false; $query = mysql_query("SELECT * FROM `notes` WHERE `notes`.`user_id` = $id AND `notes`.`type` = 'public' ORDER BY `notes`.`ID` DESC LIMIT 1"); if(!mysql_num_rows($query)) return false; return mysql_fetch_assoc($query); } } /* function deflang($lang) { if(empty($lang)) return DEFAULT_LANG; return $lang; } */ /* GETTEXT STUFF (WORDPRESS) */ /* function __($string) { global $gettext_tables; if (!$gettext_tables) return $string; else return $gettext_tables->translate($string); } */