aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/chat.php15
-rw-r--r--mod/chat.php62
-rw-r--r--view/tpl/chat.tpl18
3 files changed, 89 insertions, 6 deletions
diff --git a/include/chat.php b/include/chat.php
index f682fe6fe..a8c3db429 100644
--- a/include/chat.php
+++ b/include/chat.php
@@ -83,8 +83,10 @@ function chatroom_enter($observer_xchan,$room_id,$status,$client) {
$r = q("select * from chatroom where cr_id = %d limit 1",
intval($room_id)
);
- if(! $r)
- return;
+ if(! $r) {
+ notice( t('Room not found.') . EOL);
+ return false;
+ }
require_once('include/security.php');
$sql_extra = permissions_sql($r[0]['cr_uid']);
@@ -94,7 +96,7 @@ function chatroom_enter($observer_xchan,$room_id,$status,$client) {
);
if(! $x) {
notice( t('Permission denied.') . EOL);
- return;
+ return false;
}
$r = q("select * from chatpresence where cp_xchan = '%s' and cp_room = %d limit 1",
@@ -122,12 +124,13 @@ function chatroom_enter($observer_xchan,$room_id,$status,$client) {
}
-function chatroom_leave($observer_xchan,$room_id,$status) {
+function chatroom_leave($observer_xchan,$room_id,$client) {
if(! $room_id || ! $observer_xchan)
return;
- $r = q("select * from chatpresence where cp_xchan = '%s' and cp_room = %d limit 1",
+ $r = q("select * from chatpresence where cp_xchan = '%s' and cp_room = %d and cp_client = '%s' limit 1",
dbesc($observer_xchan),
- intval($room_id)
+ intval($room_id),
+ dbesc($client)
);
if($r) {
q("delete from chatpresence where cp_id = %d limit 1",
diff --git a/mod/chat.php b/mod/chat.php
new file mode 100644
index 000000000..bc981b76b
--- /dev/null
+++ b/mod/chat.php
@@ -0,0 +1,62 @@
+<?php /** @file */
+
+require_once('include/chat.php');
+
+function chat_init(&$a) {
+
+ $which = null;
+ if(argc() > 1)
+ $which = argv(1);
+ if(! $which) {
+ if(local_user()) {
+ $channel = $a->get_channel();
+ if($channel && $channel['channel_address'])
+ $which = $channel['channel_address'];
+ }
+ }
+ if(! $which) {
+ notice( t('You must be logged in to see this page.') . EOL );
+ return;
+ }
+
+ $profile = 0;
+ $channel = $a->get_channel();
+
+ if((local_user()) && (argc() > 2) && (argv(2) === 'view')) {
+ $which = $channel['channel_address'];
+ $profile = argv(1);
+ }
+
+ $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $a->get_baseurl() . '/feed/' . $which .'" />' . "\r\n" ;
+
+ // Run profile_load() here to make sure the theme is set before
+ // we start loading content
+
+ profile_load($a,$which,$profile);
+
+}
+
+
+function chat_content(&$a) {
+
+ if(! perm_is_allowed($a->profile['profile_uid'],get_observer_hash(),'chat')) {
+ notice( t('Permission denied.') . EOL);
+ return;
+ }
+
+ if((argc() > 3) && intval(argv(2)) && (argv(3) === 'leave')) {
+ chatroom_leave(get_observer_hash(),$room_id,$_SERVER['REMOTE_ADDR']);
+ goaway(z_root() . '/channel/' . argv(1));
+ }
+
+
+ if(argc() > 2 && intval(argv(2))) {
+ $room_id = intval(argv(2));
+ $x = chatroom_enter(get_observer_hash(),$room_id,'online',$_SERVER['REMOTE_ADDR']);
+ if(! $x)
+ return;
+ $o = replace_macros(get_markup_template('chat.tpl'),array());
+ return $o;
+ }
+
+} \ No newline at end of file
diff --git a/view/tpl/chat.tpl b/view/tpl/chat.tpl
new file mode 100644
index 000000000..6378b8776
--- /dev/null
+++ b/view/tpl/chat.tpl
@@ -0,0 +1,18 @@
+<div id="chatContainer">
+
+ <div id="chatTopBar" class="rounded"></div>
+ <div id="chatLineHolder"></div>
+
+ <div id="chatUsers" class="rounded"></div>
+
+ <div id="chatBottomBar" class="rounded">
+ <div class="tip"></div>
+
+ <form id="submitForm" method="post" action="">
+ <input id="chatText" name="chatText" class="rounded" maxlength="255" />
+ <input type="submit" class="blueButton" value="Submit" />
+ </form>
+
+ </div>
+
+</div> \ No newline at end of file