public function destroy($id) { $message = Message::find($id); $this->deletePicture($message); $message->delete(); return Redirect::route('admin'); }
public static function check_message_rights($message_id) { $user = self::get_user_logged_in(); $message = new Message(Message::find($message_id)); $id = $message->user_id; if ($user->userrole != 'ADMIN' && $user->id != $id) { Redirect::to('/', array('message' => 'You have no authority to perform that action.')); } }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id) { $message = Message::find($id); $message->fill(Input::all()); $message->save(); $material = Material::find(Input::get('materialid')); $material->status = 'ok'; $material->save(); return Redirect::to('/beheer'); }
public static function destroyMessage($id) { $message = new Message(Message::find($id)); $user_id = $message->user_id; $thread_id = $message->thread_id; $message->delete(); //Updating participants list ForumUser::changePostAmount($user_id, $thread_id, -1); Redirect::to('/thread/' . $message->thread_id, array('message' => 'Message deleted.')); }
/** * gets message regardless of the error state of this ValueTO. * use this message ONLY WHEN valueTO is error. * * @return string|array */ public function message() { if (!$this->message) { $type = $this->getType(); $method = $this->getErrorMethod(); $parameter = $this->getParameter(); $this->message = $this->messenger->find($type, $method, $parameter); } return $this->message; }
public function actionEdit() { $languages = Message::getLanguages(); $model = new Message(); $model->language = $_GET['language']; $model->file = $_GET['file']; $model->messageId = $_GET['message-id']; $model->message = Message::find($_GET['language'], $_GET['file'], $_GET['message-id']); $files = Message::getFiles($_GET['language']); $this->render('edit', array('languages' => $languages, 'files' => $files, 'language' => $model->language, 'file' => $model->file, 'message' => $model->message, 'messageId' => $model->messageId)); }
public function messageformAction($id = NULL, $nom, $nomfrm, $idFil) { $p = $this->getInstance($id); $user = User::findFirst(); $message = Message::find("idProjet=" . $p->getId() . " AND idFil is NULL"); foreach ($message as $msg) { $reponse = Message::find("idFil=" . $msg->getId()); } $this->view->setVars(array("message" => $message, "reponse" => $reponse, "projet" => $p, "user" => $user, "nom" => $nom, "idFil" => $idFil, "nomfrm" => $nomfrm)); $this->jquery->postFormOnClick(".validate", "Messages/repondre", "frmAjoutMessage", "#divMessages"); $this->jquery->compile($this->view); }
/** * retrieve the messages for this user and this page * * Does a query for the right messages * * @return Message data object with stream for messages * * @see MailboxAction::getMessages() */ function getMessages() { $message = new Message(); $message->from_profile = $this->user->id; $message->orderBy('created DESC, id DESC'); $message->limit(($this->page - 1) * MESSAGES_PER_PAGE, MESSAGES_PER_PAGE + 1); if ($message->find()) { return $message; } else { return null; } }
public function deleteMessage($message_id) { try { $message = Message::find($message_id); if ($message) { $message->delete(); MessageState::where('message_id', '=', $message_id)->delete(); } return true; } catch (Exception $e) { return false; } }
public function testHABTMRelation() { $this->assertCount(2, User::first()->messages()->get()); User::first()->messages()->insert([['title' => 'sdf'], ['title' => '123123']]); $this->assertCount(4, User::first()->messages()->get()); $this->assertCount(1, User::first()->messages()->get(['title'], ['sdf'])); $ids = User::last()->messages()->insert([['title' => 'new title']]); $this->assertSame(4, User::first()->messages()->count()); $this->assertSame(1, User::last()->messages()->count()); $this->assertTrue(User::last()->messages()->has($ids[0])); $this->assertTrue(User::last()->messages()->delete($ids[0])); $this->assertFalse(User::last()->messages()->has($ids[0])); $this->assertFalse(User::last()->messages()->has(Message::find($ids[0]))); // @todo test sync method }
public function loadMessagesAction($idProjet, $idFil = NULL) { $sql = "idProjet=" . $idProjet; if ($idFil == null) { $sql .= " AND idFil IS NULL"; } else { $sql .= " AND idFil=" . $idFil; } $messages = Message::find($sql); foreach ($messages as $msg) { $reponses[$msg->getId()] = $responses = count(Message::find("idFil=" . $msg->getId())); } $this->view->setVars(array("messages" => $messages, "responses" => $responses)); $this->view->pick("messages/main"); }
public function loadMessagesAction($idProjet, $idFil = NULL) { $sql = "idProjet=" . $idProjet; if ($idFil == null) { $sql .= " AND idFil IS NULL"; } else { $sql .= " AND idFil=" . $idFil; } $messages = Message::find($sql); $result = array(); foreach ($messages as $message) { $responses = count(Message::find("idFil=" . $message->getId())); array_push($result, array("id" => $message->getId(), "objet" => $message->getObjet(), "content" => $message->getContent(), "author" => $message->getUser()->__toString(), "responses" => $responses, "date" => $message->getSince())); } print_r(json_encode($result)); $this->view->disable(); }
public function projectAction($id = NULL) { $p = Projet::findFirst("id=" . $id); $user = User::findFirst("id=" . $p->getId()); //image a mettre if ($p->getImage() == NULL) { $source = "../../public/img/increase.png"; } else { $source = $p->getImage(); } $message = Message::find("idProjet=" . $p->getId() . " AND idFil is NULL"); $nbMsg = 0; foreach ($message as $msg) { $nbMsg = $nbMsg + 1; } $this->view->setVars(array("project" => $p, "user" => $user, "source" => $source, "nbMsg" => $nbMsg)); $this->jquery->get("Projects/equipe/" . $p->getId(), "#detailProject"); $this->jquery->click(".btnMessages", "\$('#divMessages').slideToggle('slow');"); $this->jquery->get("Projects/messages/" . $p->getId(), "#divMessages"); $this->jquery->compile($this->view); }
public function actionView($mid = null) { if (defined('DISABLE_MESSAGING') && DISABLE_MESSAGING) { throw new Lvc_Exception('Messaging disabled'); } $active_user = User::require_active_user(); $this->setLayoutVar('active_user', $active_user); $this->setLayoutVar('pageHead', 'Message'); $this->setLayoutVar('pageTitle', 'Message'); if (is_null($mid)) { throw new Lvc_Exception('Null message id on view action'); } if ($message = Message::find(array('mid' => $mid, 'user' => $active_user))) { if ($message->to_user->uid = $active_user->uid) { $message->mark_read(); } $this->setVar('message', $message); } else { throw new Lvc_Exception('Message Not Found: ' . $mid); } }
public function indexAction() { if ($this->request->isAjax()) { // $name = $_POST['name']; // $content = $_POST['content']; // $name = $_REQUEST['name']; // $content = $_REQUEST['content']; $data = $_REQUEST; // $data = [ // 'name' => $name, // 'content' => $content // ]; $result = json_decode((new \Message())->addList($data), true); print_r($result); die; } // $list = (new \Message())->getList(); // $this->view->setVar('list',$list); $data = Message::find(); $page = (new \Message())->paging($data); $this->view->setVar('page', $page); }
public function showAction($id = NULL) { $this->view->pick("projects/show"); $projet = $this->getInstance($id); $ucs = Usecase::find("idProjet=" . $id); //recupere le pourcentage de temps écoulé $tmpEcoule = $this->tmpEcoule($id); //messages $messages = Message::find("idProjet=" . $id); //users $users = User::find(); $count = count(Message::find("idProjet=" . $id . " AND idFil IS NULL")); //recupere les taches $tachesUcs = $this->listAction($id); $this->view->setVars(array("baseHref" => $this->url->getBaseUri(), "currUser" => $this->session->get("user"), "projet" => $projet, "ucs" => $ucs, "tmpEcoule" => $tmpEcoule, "messages" => $messages, "users" => $users, "tachesUcs" => $tachesUcs, "nbMessages" => $count, "rights" => $this->session->get("rights"))); $_SESSION['bread']['object'] = $projet; $this->jquery->jsonArrayOn("click", ".loadTasks", ".taskRepeat > *", "", array("context" => "\$('table[id=\"'+self.attr('id')+'\"]')", "attr" => "data-ajax", "jsCallback" => "\n\t\t\t\t\t\t\t\$('table[id=\"'+self.attr('id')+'\"]').show();\n\t\t\t\t\t\t\tself.hide();\n\t\t\t\t\t\t\tself.parent().parent().find('.hideTasks').show();\n\t\t\t\t\t\t\t\$('.ticket').css('height', \$('.projectContent').height());\n\t\t\t\t\t\t")); $this->jquery->execOn("click", ".hideTasks", "\n\t\t\t\t\$(this).hide();\n\t\t\t\t\$(this).parent().parent().find('.loadTasks').show();\n\t\t\t\t\$(this).parent().parent().parent().find('table').hide();\n\t\t\t\t"); $this->jquery->execOn("click", ".displayUcs", "\$('.ucs').show();\$('.hideUcs').show();\$('.displayUcs').hide();\$('.ticket').css('height', \$('.projectContent').height());"); $this->jquery->execOn("click", ".hideUcs", "\$('.ucs').hide();\$('.displayUcs').show();\$('.hideUcs').hide();\$('.ticket').css('height', \$('.projectContent').height());"); $_SESSION['bread']['object'] = $projet; $event = "function loadResponses(){"; $event .= $this->jquery->jsonArrayOn("click", ".loadReponses", ".msgTemplate", "", array("immediatly" => true, "attr" => "data-ajax", "jsCallback" => "loadResponses(); \$('.unloadResponses.'+self.attr('id')).show();self.hide(); \$('.responses.'+self.attr('id')).slideDown();", "context" => "\$('.responses.'+self.attr('id'))")); $event .= $this->jquery->execOn("click", ".newMessage", "loadMsgForm(\$(this), false)", array("immediatly" => true)); $event .= $this->jquery->execOn("click", ".newResponse", "loadMsgForm(\$(this), true)", array("immediatly" => true)); $event .= $this->jquery->execOn("click", ".cancel", "\n\t\t\t\t\$('.msgForm:not(.model)').empty();\n\t\t\t\t\$('.newResponse').removeClass('disabled');\n\t\t\t\t\$('.newMessage').removeClass('disabled');\n\t\t\t\t\$('.ticket').css('height', \$('.projectContent').height());\n\t\t\t\t", array("immediatly" => true)); $event .= "}"; $event .= "\$('.ticket').css('height', \$('.projectContent').height());"; $this->jquery->exec("\n\t\t\t\tfunction loadMsgForm(elt, response){\n\t\t\t\t\t\$('.msgForm:not(.model)').remove();\n\t\t\t\t\t\$('.newResponse').removeClass('disabled');\n\t\t\t\t\tvar newMsg = \$('.msgForm').clone(true, true);\n\t\t\t\t\tnewMsg.removeClass('model');\n\t\t\t\t\t\n\t\t\t\t\tif(response){\n\t\t\t\t\t\tnewMsg.appendTo(\$('.responses.'+elt.attr('id')));\n\t\t\t\t\t\tnewMsg.find('#idFil').attr('value', elt.attr('id'));\n\t\t\t\t\t\tnewMsg.find('.validate').attr('data-target', '.responses.'+elt.attr('id'));\n\t\t\t\t\t\tnewMsg.find('.validate').attr('id', elt.attr('id'));\n\t\t\t\t\t}else{\n\t\t\t\t\t\tnewMsg.appendTo(\$('.messages-list'));\n\t\t\t\t\t\tnewMsg.find('#idFil').remove();\n\t\t\t\t\t\tnewMsg.find('.validate').attr('id', '0');\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\telt.addClass('disabled');\n\t\t\t\t\t\$('.newMessage').addClass('disabled');\n\t\t\t\t\tnewMsg.show(true);\n\t\t\t\t\tnewMsg.attr('id', 'sendMessage');\n\t\t\t\t\t\$('.ticket').css('height', \$('.projectContent').height());\n\t\t\t\t}\n\t\t\t\t", true); $this->jquery->jsonArrayOn("click", ".loadMessages", ".msgTemplate", "", array("attr" => "data-ajax", "jsCallback" => "\$('.messages').slideDown();\$('.loadMessages').hide();loadResponses();\$('.ticket').css('height', \$('.projectContent').height());")); $this->jquery->postFormOn('click', ".validate", "Messages/updateProject", 'sendMessage', "self.getAttribute('data-target')"); $this->jquery->getOnClick(".manageBtn", "", ".content", array("attr" => "data-ajax")); $this->jquery->exec($event, true); $this->jquery->execOn("click", ".hideMessages", "\$('.messages').slideUp();\$('.loadMessages').show();\$('.ticket').css('height', \$('.projectContent').height());"); $this->jquery->compile($this->view); }
function deletemessage($project_id, $media_id, $id) { $from = $this->client->firstname . ' ' . $this->client->lastname; $message = Message::find($id); if ($message->from == $this->client->firstname . " " . $this->client->lastname) { $message->delete(); } if (!$message) { $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_delete_message_error')); } else { $this->session->set_flashdata('message', 'success:' . $this->lang->line('messages_delete_message_success')); } redirect('cprojects/media/' . $project_id . '/view/' . $media_id); }
/** * Get notices * * @return array notices */ function getMessages() { $message = new Message(); if ($this->arg('sent')) { $message->from_profile = $this->user->id; } else { $message->to_profile = $this->user->id; } if (!empty($this->max_id)) { $message->whereAdd('id <= ' . $this->max_id); } if (!empty($this->since_id)) { $message->whereAdd('id > ' . $this->since_id); } $message->orderBy('created DESC, id DESC'); $message->limit(($this->page - 1) * $this->count, $this->count); $message->find(); $messages = array(); while ($message->fetch()) { $messages[] = clone $message; } return $messages; }
function homepage() { App::import('Model', 'Message'); $alerta = new Message(); $recipient_id = $this->Session->read('Auth.User.id'); $alertas = $alerta->find('all', array('conditions' => array('recipient_id' => $recipient_id, 'datainicio <=' => date('Y-m-d') . ' 23:59:59', 'datafim >=' => date('Y-m-d') . ' 00:00:00'))); $this->set('alertas', $alertas); }
public function postMessageComment() { if (!Auth::check()) { return Response::json(array('errCode' => 1, 'message' => '请登录!')); } $user = Auth::getUser(); $message_id = Input::get('message_id'); // 留言的id $comment_id = Input::get('comment_id'); // 留言下评论的id,当comment_type为1时可用 $comment_type = Input::get('comment_type'); // comment_type参数有两种取值,0代表是直接在留言下回复,1代表是在留言的评论下回复 $content = Input::get('content'); $comment = new MessageComment(); $comment->message_id = $message_id; $comment->content = $content; $comment->sender_id = $user->id; if ($comment_type == 1) { $comment->receiver_id = MessageComment::find($comment_id)->sender_id; } else { $comment->receiver_id = Message::find($message_id)->sender_id; } if (!$comment->save()) { return Response::json(array('errCode' => 2, 'message' => '[数据库错误]评论创建失败!')); } $comment['sender_name'] = $user->username; $comment['avatar'] = $user->avatar; $comment['receiver_name'] = User::find($comment->receiver_id)->username; return Response::json(array('errCode' => 0, 'comment' => $comment)); }
/** * View messages * @access authenticated user * @param string $msgType */ public function actionView($msgType = 'unread') { $this->setHeaderTitle("My Messages"); $userId = Rays::user()->id; $curPage = $this->getPage('page'); $pageSize = $this->getPageSize("pagesize", 5); /* TODO: Maybe move these model-related things into Message model directly */ $query = Message::find("receiverId", $userId); switch ($msgType) { case "all": $query = $query->where("[status] != ? ", array(Message::STATUS_TRASH)); break; case "read": $query = $query->find("status", Message::STATUS_READ); break; case "unread": $query = $query->find("status", Message::STATUS_UNREAD); break; case "trash": $query = $query->find("status", Message::STATUS_TRASH); break; default: $this->page404(); return; } $count = $query->count(); $messages = $query->join('type')->order_desc("id")->range(($curPage - 1) * $pageSize, $pageSize); $data = array('msgs' => $messages, 'type' => $msgType, 'count' => $count); if ($count > $pageSize) { $url = RHtml::siteUrl('message/view/' . $msgType); $pager = new RPager('page', $count, $pageSize, $url, $curPage); $data['pager'] = $pager->showPager(); } $this->render('view', $data, false); }
public function modify_message_status() { $message = Message::find(Input::get('message_id')); $status = (int) Input::get('status'); if ($status != 3 && $status != 4) { return Response::json(array('error_code' => 2, 'message' => '参数错误')); } if (!isset($message)) { return Response::json(array('error_code' => 3, 'message' => '不存在该消息')); } if ($message->to_uid != Session::get('user.id')) { return Response::json(array('error_code' => 4, 'message' => '无效消息')); } $message->status = $status; if (!$message->save()) { return Response::json(array('error_code' => 1, 'message' => '修改失败')); } return Response::json(array('error_code' => 0, 'message' => '修改成功')); }
public function getView($id) { return View::make('messages.view')->with('message', Message::find($id)); }
/** * Executes the actions to display the Home Page */ public function executeHome() { $timer = new sfTimer('executeHome'); $mobile_version = c2cTools::mobileVersion(); // user filters: $perso = c2cPersonalization::getInstance(); if ($perso->isMainFilterSwitchOn()) { $langs = $perso->getLanguagesFilter(); $ranges = $perso->getPlacesFilter(); $activities = $perso->getActivitiesFilter(); } else { $langs = $ranges = $activities = array(); } // some of the latest documents published on the site $latest_outings = Outing::listLatest($mobile_version ? sfConfig::get('app_recent_documents_outings_mobile_limit') : sfConfig::get('app_recent_documents_outings_limit'), $langs, $ranges, $activities); // choose best language for outings and regions names $latest_outings = Language::getTheBest($latest_outings, 'Outing'); $this->latest_outings = Language::getTheBestForAssociatedAreas($latest_outings); $this->latest_articles = Article::listLatest($mobile_version ? sfConfig::get('app_recent_documents_articles_mobile_limit') : sfConfig::get('app_recent_documents_articles_limit'), $langs, $activities); $latest_images = Image::listLatest($mobile_version ? sfConfig::get('app_recent_documents_images_mobile_limit') : sfConfig::get('app_recent_documents_images_limit'), $langs, $ranges, $activities); $this->latest_images = Language::getTheBest($latest_images, 'Image'); // outings from metaengine: $region_ids = c2cTools::convertC2cRangeIdsToMetaIds($ranges); $activity_ids = c2cTools::convertC2cActivityIdsToMetaIds($activities); $this->meta_feed_url = str_replace('http:', '', sfConfig::get('app_meta_engine_base_url')) . 'outings?system_id=2,3,4' . '&orderby=outing_date' . '&outing_lang=' . implode(',', $langs) . '&activity_ids=' . implode(',', $activity_ids) . '®ion_id=' . implode(',', $region_ids); // forum 'mountain news' latest active threads $news_filter_ids = PunbbTopics::getForumIds('app_forum_mountain_news', $langs, $activities); $this->latest_mountain_news = PunbbTopics::listLatestById($mobile_version ? sfConfig::get('app_recent_documents_mountain_news_mobile_limit') : sfConfig::get('app_recent_documents_mountain_news_limit'), $news_filter_ids); $this->news_filter_ids = implode('-', $news_filter_ids); // forum latest active threads $forum_filter_ids = PunbbTopics::getForumIds('app_forum_public_ids', $langs, $activities); $this->latest_threads = PunbbTopics::listLatestById($mobile_version ? sfConfig::get('app_recent_documents_threads_mobile_limit') : sfConfig::get('app_recent_documents_threads_limit'), $forum_filter_ids); $this->forum_filter_ids = implode('-', array_merge($news_filter_ids, $forum_filter_ids)); // Custom welcome message: $prefered_langs = $this->getUser()->getCulturesForDocuments(); $this->message = Message::find($prefered_langs[0]); if (!$mobile_version) { // c2c news $this->latest_c2c_news = PunbbTopics::listLatestC2cNews(sfConfig::get('app_recent_documents_c2c_news_limit'), $langs); $this->figures = sfConfig::get('app_figures_list'); } // mobile version $this->getResponse()->addMeta('robots', 'index, follow'); c2cActions::statsdTiming('document.executeHome', $timer->getElapsedTime('executeHome')); }
public function personalDelete($id) { $message = Message::find($id); $message->DelFlag = 1; $message->save(); }
public function delete_action($message_id) { $message = Message::find($message_id); $ticket = Request::get('studip-ticket'); if (Request::isPost() && $ticket && check_ticket($ticket)) { $success = $this->delete_message($message_id); if ($success) { PageLayout::postMessage(MessageBox::success(_('Nachricht gelöscht!'))); } else { PageLayout::postMessage(MessageBox::error(_('Nachricht konnte nicht gelöscht werden.'))); } } $redirect = $message->autor_id === $GLOBALS['user']->id ? $this->url_for('messages/sent') : $this->url_for('messages/overview'); $this->redirect($redirect); }
function getMessages() { $message = new Message(); $from = $this->fromUserId; $to = $this->toUserId; /* $qry = 'SELECT * FROM message WHERE'. '('. '((from_profile=%d AND to_profile=%d) OR( from_profile=%d AND to_profile=%d))'. 'AND (id > %d or id = %d)'. 'AND (id < %d or id = %d)'. ')'. 'ORDER BY created DESC LIMIT %d'; $var = sprintf($qry, $from, $to, $to, $from, $this->sinceId, $this->sinceId, $this->max_id, $this->max_id, $this->count); $message->query($var);*/ $sql = null; if ($this->since_id != 0 && $this->max_id == 0) { $str = '((from_profile=%d AND to_profile=%d) OR( from_profile=%d AND to_profile=%d))' . 'AND (id > %d)'; $sql = sprintf($str, $from, $to, $to, $from, $this->sinceId); } else { if ($this->since_id == 0 && $this->max_id != 0) { $str = '((from_profile=%d AND to_profile=%d) OR( from_profile=%d AND to_profile=%d))' . 'AND (id < %d)'; $sql = sprintf($str, $from, $to, $to, $from, $this->max_id); } else { if ($this->since_id != 0 && $this->max_id != 0) { $str = '((from_profile=%d AND to_profile=%d) OR( from_profile=%d AND to_profile=%d))' . 'AND (id > %d)' . 'AND (id < %d)'; $sql = sprintf($str, $from, $to, $to, $from, $this->sinceId, $this->max_id); } else { $str = '((from_profile=%d AND to_profile=%d) OR( from_profile=%d AND to_profile=%d))'; $sql = sprintf($str, $from, $to, $to, $from); } } } $message->whereAdd($sql); $message->limit($this->count); $message->orderBy('created DESC, id DESC'); $message->find(); return $message; }
public function search() { fallback($_GET['query'], ""); $config = Config::current(); if ($config->clean_urls and substr_count($_SERVER['REQUEST_URI'], "?") and !substr_count($_SERVER['REQUEST_URI'], "%2F")) { # Searches with / and clean URLs = server 404 redirect("search/" . urlencode($_GET['query']) . "/"); } if (empty($_GET['query'])) { return Flash::warning(__("Please enter a search term.")); } list($where, $params) = keywords($_GET['query'], "name LIKE :query OR url LIKE :query", "forums"); $forums = Forum::find(array("placeholders" => true, "where" => $where, "params" => $params)); list($where, $params) = keywords($_GET['query'], "title LIKE :query OR description LIKE :query OR url LIKE :query", "topics"); $topics = Topic::find(array("placeholders" => true, "where" => $where, "params" => $params)); list($where, $params) = keywords($_GET['query'], "body LIKE :query", "messages"); $messages = Message::find(array("placeholders" => true, "where" => $where, "params" => $params)); $this->display("discuss/search", array("forums" => new Paginator($forums, 25, "forums_page"), "topics" => new Paginator($topics, 25, "topics_pave"), "messages" => new Paginator($messages, 25, "messages_page"), "search" => $_GET['query']), fix(_f("Search results for \"%s\"", $_GET['query']))); }
public function deleteAction() { $this->view->disable(); if ($this->request->hasPost('d_id') && $this->request->isAjax()) { $dialog_ids = $this->request->getPost('d_id'); foreach (Message::find(array("dialogs_id = {$dialog_ids}")) as $mes) { $mes->delete(); } foreach (DialogsHasUser::find(array("dialogs_id = {$dialog_ids}")) as $ds) { $ds->delete(); } Dialogs::findFirst($dialog_ids)->delete(); echo 1; } }
function show_messages($args, $apidata, $type) { $user = $apidata['user']; $count = $this->arg('count'); $since = $this->arg('since'); $since_id = $this->arg('since_id'); $before_id = $this->arg('before_id'); $page = $this->arg('page'); if (!$page) { $page = 1; } if (!$count) { $count = 20; } $message = new Message(); $title = null; $subtitle = null; $link = null; $server = common_root_url(); if ($type == 'received') { $message->to_profile = $user->id; $title = sprintf(_("Direct messages to %s"), $user->nickname); $subtitle = sprintf(_("All the direct messages sent to %s"), $user->nickname); $link = $server . $user->nickname . '/inbox'; } else { $message->from_profile = $user->id; $title = _('Direct Messages You\'ve Sent'); $subtitle = sprintf(_("All the direct messages sent from %s"), $user->nickname); $link = $server . $user->nickname . '/outbox'; } if ($before_id) { $message->whereAdd("id < {$before_id}"); } if ($since_id) { $message->whereAdd("id > {$since_id}"); } $since = strtotime($this->arg('since')); if ($since) { $d = date('Y-m-d H:i:s', $since); $message->whereAdd("created > '{$d}'"); } $message->orderBy('created DESC, id DESC'); $message->limit(($page - 1) * 20, $count); $message->find(); switch ($apidata['content-type']) { case 'xml': $this->show_xml_dmsgs($message); break; case 'rss': $this->show_rss_dmsgs($message, $title, $link, $subtitle); break; case 'atom': $selfuri = common_root_url() . 'api/direct_messages'; $selfuri .= $type == 'received' ? '.atom' : '/sent.atom'; $taguribase = common_config('integration', 'taguri'); if ($type == 'sent') { $id = "tag:{$taguribase}:SentDirectMessages:" . $user->id; } else { $id = "tag:{$taguribase}:DirectMessages:" . $user->id; } $this->show_atom_dmsgs($message, $title, $link, $subtitle, $selfuri, $id); break; case 'json': $this->show_json_dmsgs($message); break; default: $this->clientError(_('API method not found!'), $code = 404); } }