# # 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 . # IMPORTANT: We keep this API while JMS [http://wiki.jisko.net/wiki/JMS] is # being adapted to v2. It works in official copy only at jisko.net, sorry. define('NO_GUI', 1); global $db; $params = PARAMS; $module = MODULE; if ($_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW']) { $userInfo = $db->getUserInfoAPI($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); if (!empty($userInfo)) { define('AUTH', true); extract($userInfo); $ignored = explode(',', $ignored); } else { header('WWW-Authenticate: Basic realm="Jisko"'); header('HTTP/1.0 401 Unauthorized'); define('AUTH', false); } } else { header('WWW-Authenticate: Basic realm="Jisko"'); header('HTTP/1.0 401 Unauthorized'); die('You must fill your info'); } if (!AUTH) die('AUTH ERROR'); switch ($params) { case 'getArchive': if ($_REQUEST['page']) $page = (int)$_REQUEST['page']; else $page = 0; $result = $db->getNotes('archive', $page, NOTES_PER_PAGE, $ID); $count = count($result); $i = 0; if ($_REQUEST['format'] == 'json') { header('Content-Type: text/javascript; charset=utf-8'); if($result) echo '{"notes":['; foreach ($result as $note) { $i++; if ($i == $count) showNoteJSON($note['id'], true); else showNoteJSON($note['id']); } if($result) echo ']}'; } else createXML('notes', $result); break; case 'getPublic': if ($_REQUEST['page']) $page = (int)$_REQUEST['page']; else $page = 0; $result = $db->getNotes('public', $page, NOTES_PER_PAGE, false, false, $ignored); $count = count($result); $i = 0; if ($_REQUEST['format'] == 'json') { header('Content-Type: text/javascript; charset=utf-8'); if($result) echo '{"notes":['; foreach ($result as $note) { $i++; if ($i == $count) showNoteJSON($note['id'], true); else showNoteJSON($note['id']); } if($result) echo ']}'; } else createXML('notes', $result); break; case 'getFriends': if (!AUTH) die('ERROR'); if ($_REQUEST['page']) $page = (int)$_REQUEST['page']; else $page = 0; $result = $db->getNotes('friends', $page, NOTES_PER_PAGE, $ID, false, $ignored); $count = count($result); $i = 0; if ($_REQUEST['format'] == 'json') { header('Content-Type: text/javascript; charset=utf-8'); if($result) echo '{"notes":['; foreach ($result as $note) { $i++; if ($i == $count) showNoteJSON($note['id'], true); else showNoteJSON($note['id']); } if($result) echo ']}'; } else createXML('notes', $result); break; case 'getPrivate': if (!AUTH) die('ERROR'); if ($_REQUEST['page']) $page = (int)$_REQUEST['page']; else $page = 0; $result = $db->getNotes('private', $page, NOTES_PER_PAGE, false, $username); $count = count($result); $i = 0; if ($_REQUEST['format'] == 'json') { header('Content-Type: text/javascript; charset=utf-8'); if($result) echo '{"notes":['; foreach ($result as $note) { $i++; if ($i == $count) showNoteJSON($note['id'], true); else showNoteJSON($note['id']); } if($result) echo ']}'; } else createXML('notes', $result); break; case 'getReplies': if (!AUTH) die('ERROR'); if ($_REQUEST['page']) $page = (int)$_REQUEST['page']; else $page = 0; $result = $db->getNotes('replies', $page, NOTES_PER_PAGE, false, $username, $ignored); $count = count($result); $i = 0; if ($_REQUEST['format'] == 'json') { header('Content-Type: text/javascript; charset=utf-8'); if($result) echo '{"notes":['; foreach ($result as $note) { $i++; if ($i == $count) showNoteJSON($note['id'], true); else showNoteJSON($note['id']); } if($result) echo ']}'; } else createXML('notes', $result); break; case 'getFavorites': if (!AUTH) die('ERROR'); if ($_REQUEST['page']) $page = (int)$_REQUEST['page']; else $page = 0; $result = $db->getNotes('favorites', $page, NOTES_PER_PAGE, $ID); $count = count($result); $i = 0; if ($_REQUEST['format'] == 'json') { header('Content-Type: text/javascript; charset=utf-8'); if($result) echo '{"notes":['; foreach ($result as $note) { $i++; if ($i == $count) showNoteJSON($note['id'], true); else showNoteJSON($note['id']); } if($result) echo ']}'; } else createXML('notes', $result); break; case 'updateStatus': global $skipauth; $skipauth = 1; if (!AUTH) die('ERROR'); if (!$_REQUEST['note']) die('MISSING_NOTE'); if ($_REQUEST['twitter'] == 0) $twitter = 0; else $twitter = 1; if (empty($_REQUEST['from'])) $from = 'api'; else $from = $_REQUEST['from']; if ($_REQUEST['test']) echo $_REQUEST['note'].', '.$userInfo.', '.$from.', '.$twitter; else echo postNote($_REQUEST['note'], $userInfo, $from, $twitter); break; } ?>