ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilChatroomPostMessageTask.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4
14{
15
16 private $gui;
17
26 {
27 $this->gui = $gui;
28 }
29
38 public function executeDefault($method)
39 {
40 global $ilUser, $ilCtrl;
41
42 require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
43 require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
44
45 if ( !ilChatroom::checkUserPermissions( 'read', $this->gui->ref_id ) )
46 {
47 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", ROOT_FOLDER_ID);
48 $ilCtrl->redirectByClass("ilrepositorygui", "");
49 }
50
51 $room = ilChatroom::byObjectId( $this->gui->object->getId() );
52
53 $chat_user = new ilChatroomUser($ilUser, $room);
54 $user_id = $chat_user->getUserId();
55
56 if( !$room )
57 {
58 throw new Exception('unkown room');
59 }
60 else if( !$room->isSubscribed( $chat_user->getUserId() ) )
61 {
62 throw new Exception('not subscribed');
63 }
64 else if ( isset($_REQUEST['sub']) && !$room->userIsInPrivateRoom( $_REQUEST['sub'], $chat_user->getUserId() ))
65 {
66 $response = json_encode( array(
67 'success' => false,
68 'reason' => 'not subscribed to private room'
69 ) );
70 echo json_encode( $response );
71 exit;
72 }
73
74 $scope = $room->getRoomId();
75 $params = array();
76
77 if( ($recipient = $_REQUEST['recipient'] ) )
78 {
79 $params['recipients'] = join( ',', array_unique( array($user_id, $recipient) ) );
80 $params['recipient_names'] = implode( ',', array($chat_user->getUsername(), $_REQUEST['recipient_name']) );
81 $params['public'] = isset( $_REQUEST['public'] ) ? (int)$_REQUEST['public'] : 0;
82 }
83 else
84 {
85 $params['public'] = 1;
86 }
87
88 if ($_REQUEST['sub'])
89 $params['sub'] = (int)$_REQUEST['sub'];
90
91 $messageObject = $this->buildMessage(
92 ilUtil::stripSlashes( $_REQUEST['message'] ),
93 $params,
94 $chat_user
95 );
96
97 $message = json_encode( $messageObject );
98
99 $params = array_merge( $params, array('message' => $message) );
100 //print_r($params);exit;
101 $query = http_build_query( $params );
102 $connector = $this->gui->getConnector();
103 $response = $connector->post( $scope, $query );
104
105 $responseObject = json_decode( $response );
106
107 if( $responseObject->success == true /*&& $room->getSetting( 'enable_history' )*/ )
108 {
109 $room->addHistoryEntry( $messageObject, $recipient, $publicMessage );
110 }
111
112 echo $response;
113 exit;
114 }
115
126 private function buildMessage($messageString, $params, ilChatroomUser $chat_user)
127 {
128 $data = new stdClass();
129
130 $data->user = $this->gui->object->getPersonalInformation( $chat_user );
131 $data->message = $messageString;
132 $data->timestamp = time() * 1000;//date( 'c' );
133 $data->type = 'message';
134 isset($params['sub']) ? ($data->sub = $params['sub']) : false;
135 $data->public = (int)$params['public'];
136 $data->recipients = $params['recipients']; // ? explode(",", $params['recipients']) : array();
137 $data->recipient_names = $params['recipient_names'];
138
139 return $data;
140 }
141
142}
143
144?>
Class ilChatroomPostMessageTask.
__construct(ilChatroomObjectGUI $gui)
Constructor.
buildMessage($messageString, $params, ilChatroomUser $chat_user)
Instantiates stdClass, sets $data->user, $data->message, $data->public and $data->recipients using gi...
executeDefault($method)
Prepares and posts message fetched from $_REQUEST['message'] to recipients fetched from $_REQUEST['re...
Class ilChatroomUser.
static byObjectId($object_id)
Returns ilChatroom object by given $object_id.
static checkUserPermissions($permissions, $ref_id, $send_info=true)
Checks user permissions by given array and ref_id.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
$data
$params
Definition: example_049.php:96
global $ilCtrl
Definition: ilias.php:18
exit
Definition: login.php:54
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7
global $ilUser
Definition: imgupload.php:15