aboutsummaryrefslogtreecommitdiffstats
path: root/mod
diff options
context:
space:
mode:
Diffstat (limited to 'mod')
-rw-r--r--mod/attach.php4
-rw-r--r--mod/chat.php147
-rw-r--r--mod/chatsvc.php126
3 files changed, 275 insertions, 2 deletions
diff --git a/mod/attach.php b/mod/attach.php
index c52966ce0..d0d3296e1 100644
--- a/mod/attach.php
+++ b/mod/attach.php
@@ -25,7 +25,7 @@ function attach_init(&$a) {
return;
header('Content-type: ' . $r['data']['filetype']);
- header('Content-disposition: attachment; filename=' . $r['data']['filename']);
+ header('Content-disposition: attachment; filename="' . $r['data']['filename'] . '"');
if($r['data']['flags'] & ATTACH_FLAG_OS ) {
$istream = fopen('store/' . $c[0]['channel_address'] . '/' . $r['data']['data'],'rb');
$ostream = fopen('php://output','wb');
@@ -39,4 +39,4 @@ function attach_init(&$a) {
echo $r['data']['data'];
killme();
-} \ No newline at end of file
+}
diff --git a/mod/chat.php b/mod/chat.php
new file mode 100644
index 000000000..54fa58092
--- /dev/null
+++ b/mod/chat.php
@@ -0,0 +1,147 @@
+<?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_post(&$a) {
+
+ if($_POST['room_name'])
+ $room = strip_tags(trim($_POST['room_name']));
+
+ if((! $room) || (! local_user()))
+ return;
+
+ $channel = $a->get_channel();
+
+
+ if($_POST['action'] === 'drop') {
+ chatroom_destroy($channel,array('cr_name' => $room));
+ goaway(z_root() . '/chat/' . $channel['channel_address']);
+ }
+
+
+ $arr = array('name' => $room);
+ $arr['allow_gid'] = perms2str($_REQUEST['group_allow']);
+ $arr['allow_cid'] = perms2str($_REQUEST['contact_allow']);
+ $arr['deny_gid'] = perms2str($_REQUEST['group_deny']);
+ $arr['deny_cid'] = perms2str($_REQUEST['contact_deny']);
+
+ chatroom_create($channel,$arr);
+
+ $x = q("select cr_id from chatroom where cr_name = '%s' and cr_uid = %d limit 1",
+ dbesc($room),
+ intval(local_user())
+ );
+
+ if($x)
+ goaway(z_root() . '/chat/' . $channel['channel_address'] . '/' . $x[0]['cr_id']);
+
+ // that failed. Try again perhaps?
+
+ goaway(z_root() . '/chat/' . $channel['channel_address'] . '/new');
+
+
+}
+
+
+function chat_content(&$a) {
+
+ $observer = get_observer_hash();
+ if(! $observer) {
+ notice( t('Permission denied.') . EOL);
+ return;
+ }
+
+ if(! perm_is_allowed($a->profile['profile_uid'],$observer,'chat')) {
+ notice( t('Permission denied.') . EOL);
+ return;
+ }
+
+ if((argc() > 3) && intval(argv(2)) && (argv(3) === 'leave')) {
+ chatroom_leave($observer,$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($observer,$room_id,'online',$_SERVER['REMOTE_ADDR']);
+ if(! $x)
+ return;
+ $o = replace_macros(get_markup_template('chat.tpl'),array(
+ '$room_name' => '', // should we get this from the API?
+ '$room_id' => $room_id,
+ '$submit' => t('Submit')
+ ));
+ return $o;
+ }
+
+
+
+
+
+ if(local_user() && argc() > 2 && argv(2) === 'new') {
+
+
+ $channel = $a->get_channel();
+ $channel_acl = array(
+ 'allow_cid' => $channel['channel_allow_cid'],
+ 'allow_gid' => $channel['channel_allow_gid'],
+ 'deny_cid' => $channel['channel_deny_cid'],
+ 'deny_gid' => $channel['channel_deny_gid']
+ );
+
+ require_once('include/acl_selectors.php');
+
+ $o = replace_macros(get_markup_template('chatroom_new.tpl'),array(
+ '$header' => t('New Chatroom'),
+ '$name' => array('room_name',t('Chatroom Name'),'', ''),
+ '$acl' => populate_acl($channel_acl),
+ '$submit' => t('Submit')
+ ));
+ return $o;
+ }
+
+
+
+
+
+
+ require_once('include/widgets.php');
+
+ return widget_chatroom_list(array());
+
+} \ No newline at end of file
diff --git a/mod/chatsvc.php b/mod/chatsvc.php
new file mode 100644
index 000000000..d76a87462
--- /dev/null
+++ b/mod/chatsvc.php
@@ -0,0 +1,126 @@
+<?php /** @file */
+
+require_once('include/security.php');
+
+function chatsvc_init(&$a) {
+
+//logger('chatsvc');
+
+ $ret = array('success' => false);
+
+ $a->data['chat']['room_id'] = intval($_REQUEST['room_id']);
+ $x = q("select cr_uid from chatroom where cr_id = %d and cr_id != 0 limit 1",
+ intval($a->data['chat']['room_id'])
+ );
+ if(! $x)
+ json_return_and_die($ret);
+
+ $a->data['chat']['uid'] = $x[0]['cr_uid'];
+
+ if(! perm_is_allowed($a->data['chat']['uid'],get_observer_hash(),'chat')) {
+ json_return_and_die($ret);
+ }
+
+}
+
+function chatsvc_post(&$a) {
+
+ $ret = array('success' => false);
+
+ $room_id = $a->data['chat']['room_id'];
+ $text = escape_tags($_REQUEST['chat_text']);
+ $status = strip_tags($_REQUEST['status']);
+
+ if($status && $room_id) {
+ $r = q("update chatpresence set cp_status = '%s', cp_last = '%s' where cp_room = %d and cp_xchan = '%s' and cp_client = '%s' limit 1",
+ dbesc($status),
+ dbesc(datetime_convert()),
+ intval($room_id),
+ dbesc(get_observer_hash()),
+ dbesc($_SERVER['REMOTE_ADDR'])
+ );
+ }
+ if(! $text)
+ return;
+
+ $sql_extra = permissions_sql($a->data['chat']['uid']);
+
+ $r = q("select * from chatroom where cr_uid = %d and cr_id = %d $sql_extra",
+ intval($a->data['chat']['uid']),
+ intval($a->data['chat']['room_id'])
+ );
+ if(! $r)
+ json_return_and_die($ret);
+
+ $x = q("insert into chat ( chat_room, chat_xchan, created, chat_text )
+ values( %d, '%s', '%s', '%s' )",
+ intval($a->data['chat']['room_id']),
+ dbesc(get_observer_hash()),
+ dbesc(datetime_convert()),
+ dbesc($text)
+ );
+ $ret['success'] = true;
+ json_return_and_die($ret);
+}
+
+function chatsvc_content(&$a) {
+
+ $lastseen = intval($_REQUEST['last']);
+
+ $ret = array('success' => false);
+
+ $sql_extra = permissions_sql($a->data['chat']['uid']);
+
+ $r = q("select * from chatroom where cr_uid = %d and cr_id = %d $sql_extra",
+ intval($a->data['chat']['uid']),
+ intval($a->data['chat']['room_id'])
+ );
+ if(! $r)
+ json_return_and_die($ret);
+
+ $inroom = array();
+
+ $r = q("select * from chatpresence left join xchan on xchan_hash = cp_xchan where cp_room = %d order by xchan_name",
+ intval($a->data['chat']['room_id'])
+ );
+ if($r) {
+ foreach($r as $rr) {
+ $inroom[] = array('img' => zid($rr['xchan_photo_m']), 'img_type' => $rr['xchan_photo_mimetype'],'name' => $rr['xchan_name']);
+ }
+ }
+
+ $chats = array();
+
+ $r = q("select * from chat left join xchan on chat_xchan = xchan_hash where chat_room = %d and chat_id > %d",
+ intval($a->data['chat']['room_id']),
+ intval($lastseen)
+ );
+ if($r) {
+ foreach($r as $rr) {
+ $chats[] = array(
+ 'id' => $rr['chat_id'],
+ 'img' => zid($rr['xchan_photo_m']),
+ 'img_type' => $rr['xchan_photo_mimetype'],
+ 'name' => $rr['xchan_name'],
+ 'isotime' => datetime_convert('UTC', date_default_timezone_get(), $rr['created'], 'c'),
+ 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $rr['created'], 'r'),
+ 'text' => smilies(bbcode($rr['chat_text']))
+ );
+ }
+ }
+
+ $r = q("update chatpresence set cp_last = '%s' where cp_room = %d and cp_xchan = '%s' and cp_client = '%s' limit 1",
+ dbesc(datetime_convert()),
+ intval($room_id),
+ dbesc(get_observer_hash()),
+ dbesc($_SERVER['REMOTE_ADDR'])
+ );
+
+ $ret['success'] = true;
+ $ret['inroom'] = $inroom;
+ $ret['chats'] = $chats;
+
+ json_return_and_die($ret);
+
+}
+ \ No newline at end of file