# # 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); global $db; global $_USER; global $mailing; if (isset($_GET['page'])) $start = getStart($_GET['page']); else $start = getStart(1); if ($_USER['ignored']) $ignored = $_USER['ignored']; else $ignored = false; switch (PARAMS) { case 'public': case 'replies': case 'friends': case 'private': case 'private_sent': case 'favorites': case 'twitter': case 'archive': case 'user': case 'all': if (PARAMS == 'all') { if (!$_USER) die(); else setUpdate(); } if (PARAMS == 'friends' || (PARAMS == 'all')) $result = $db->getNotes(PARAMS, $start, NOTES_PER_PAGE, $_USER['ID'], false, $ignored); elseif (PARAMS == 'private' || (PARAMS == 'private_sent')) $result = $db->getNotes(PARAMS, $start, NOTES_PER_PAGE, $_USER['ID'], $_USER['username']); elseif (PARAMS == 'archive' || (PARAMS == 'favorites' || (PARAMS == 'twitter'))) $result = $db->getNotes(PARAMS, $start, NOTES_PER_PAGE, $_USER['ID'], false); elseif (PARAMS == 'replies') $result = $db->getNotes(PARAMS, $start, NOTES_PER_PAGE, $_USER['ID'], $_USER['username'], $ignored); elseif (PARAMS == 'user') { if ($_GET['user']) $result = $db->getNotes('archive', $start, NOTES_PER_PAGE, $db->getIdByUser($_GET['user']), false, $ignored); } else $result = $db->getNotes(PARAMS, $start, NOTES_PER_PAGE, false, false, $ignored); if (!$result) echo json_encode(array('error' => 'No notes were found')); else { $return = array(); if ($_GET['iphone']) import('mobile'); foreach ($result as $note) { $returni = array(); if (!$_GET['iphone']) $returni['timestamp'] = $note['orderby']; $returni['id'] = $note['id']; $returni['type'] = $note['type']; if ($_GET['iphone']) $shownote = showNoteMobileiPhone($note, true); else $shownote = showNote($note, false, true); if ($shownote) { $returni = array_merge($returni, $shownote); $return[] = $returni; } } echo json_encode($return); } break; case 'favorite': if ($_USER) { $noteID = intval($_GET['id']); if (!$noteID) die(); else { $userID = intval($_USER['ID']); $favorited = $db->checkFavorite($userID, $noteID); if (empty($favorited)) { $db->newFavorite($userID, $noteID); echo ''; } else { $db->deleteFavorite($userID, $noteID); echo ''; } } } break; case 'post': if (!$_USER) die; if ($_POST) { if ($_USER['twitter_username'] && ($_USER['twitter_username'])) { if ($_USER['post_tweets'] == '1') $twitter = true; else $twitter = false; } else $twitter = false; if ($_POST['usemobile']) { if(!$_POST['note']) header(BASE.'mobile'); $post = postNote($_POST['note'], $_USER, 'mobile', $_POST['auth'], false, false, false, $twitter); } else $post = postNote($_POST['note'], $_USER, 'web', $_POST['auth'], false, false, false, $twitter); if ($post) { switch ($post) { case 'SHORT_NOTE': $error = __('The note is too short'); break; case 'LONG_NOTE': $error = __('The note is too long'); break; case 'INVALID': $error = __('You are not logged in correctly.'); break; case 'INVALID_USER': $error = __('The user doesn\'t exist'); break; /*case 'INVALID_GROUP': $error = __('Group doesn\'t exist'); break;*/ case 'NOT_FOLLOWING': $error = __('The user isn\'t following you'); break; case 'CANT_SEND_OWN_USER': $error = __('You cant\'t send a private note to yourself'); break; case 'COWBOY': $error = __('Cowboy!'); break; } if ($error) { echo 'ERROR: '.$error; } } } break; case 'normalform': doNoteFormSimple($_GET['extra'] == 'upload', $_POST['note']); break; case 'note': $return = array(); $return['type'] = 'note'; list($timestamp, $nick) = explode('-', $_GET['id']); $timestamp = (int) $timestamp; $note = $db->getLastNoteOf($nick, $timestamp, $_USER['ID']); if ($_GET['nav'] == 'link') { if ($_GET['mode'] == 'mi') header('Location: '.BASE.'mobile/statuses/'.$note['ID']); elseif ($_GET['mode'] == 'm') header('Location: '.BASE.'mobile/'.$nick.'/'.$note['ID']); else header('Location: '.BASE.$nick.'/'.$note['ID']); die; } if (!$note) $return['error'] = ''; else { $return['text'] = utf8_htmlentities($note['note']); $return['text'] = preg_replace_callback('/\[(\*|\/|_|\-)(.+)\]/U', create_function('$matches', ' switch ($matches[1]) { case "*": return "" . $matches[2] . ""; case "/": return "" . $matches[2] . ""; case "_": return "" . $matches[2] . ""; case "-": return "" . $matches[2] . ""; } '), $return['text']); $return['text'] = stripslashes(put_smileys($return['text'])); //echo '
'.__('In reply to:').' '.stripslashes($text).'
'; } echo json_encode($return); break; case 'profile': $profile = $db->getUserInfo($_GET['id']); $return = array(); if ($profile) { if ($profile['realname']) $return['realname'] = utf8_htmlentities($profile['realname']); if ($profile['url']) $return['url'] = str_replace(array('http://', 'www.'), '', utf8_htmlentities($profile['url'])); if ($profile['location']) $return['location'] = utf8_htmlentities($profile['locations']); if ($profile['bio']) $return['bio'] = utf8_htmlentities($profile['bio']); $return['type'] = 'profile'; $return['since'] = date('d/m/Y', $profile['since']); } else $return['error'] = ''; echo json_encode($return); break; case 'mainpage': $return = array(); $privates = $db->countNotes('private', $_USER['username']); $notes = $db->countNotes('archive', $_USER['ID']); if ($_GET['privates'] != $privates) $return['privates'] = $privates; if ($_GET['notes'] != $notes) $return['notes'] = $notes; echo json_encode($return); break; case 'follow': if ($_USER) { if ($_POST['who']) { $following = (int) $_USER['ID']; $who = (int) $_POST['who']; $follows = (bool) $db->checkFollowing($following, $who); if (!$follows) { $diff = time() - $_USER['last_follow']; if ($diff < WAIT_UNTIL_REFOLLOW) die('ERROR: Cowboy!'); else { $ignored = (bool) in_array($who, $_USER['ignored']); if (!$ignored) { $userInfo = $db->getUserInfo($who); if (!in_array($following, $userInfo['ignored'])) { if ($userInfo['notification_level'] == 3 || ($userInfo['notification_level'] == 1)) { if ($_USER['realname']) $content = $_USER['realname'].' ('.$_USER['username'].')'; else $content = $_USER['username']; $mailing->newFollower($userInfo['username'], $userInfo['email'], $_USER['username'], $content, $userInfo['language']); } $db->dumpRelationship($following, $who); } else { die('ERROR: Ignored user'); } } else { die('ERROR: Ignored user'); } } } else { $db->removeRelationship($following, $who); } } } break; case 'ignore': if (!$_USER || (!$_POST['who'])) die(); $ignored = (bool) in_array($_POST['who'], $_USER['ignored']); if ($ignored) $return = array_diff($_USER['ignored'],array($_POST['who'])); else { $db->removeRelationship($_USER['ID'], $_POST['who']); array_push($_USER['ignored'], $_POST['who']); $return = $_USER['ignored']; } $db->updateIgnored($_USER['ID'], array_unique($return)); break; } ?>