1<?php 2/** 3 * @package tikiwiki 4 */ 5// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 6// 7// All Rights Reserved. See copyright.txt for details and a complete list of authors. 8// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 9// $Id$ 10 11require_once('tiki-setup.php'); 12include_once('lib/shoutbox/shoutboxlib.php'); 13 14$access->check_feature('feature_shoutbox'); 15$access->check_permission('tiki_p_view_shoutbox'); 16 17if (! isset($_REQUEST["msgId"])) { 18 $_REQUEST["msgId"] = 0; 19} 20$smarty->assign('msgId', $_REQUEST["msgId"]); 21if ($_REQUEST["msgId"]) { 22 $info = $shoutboxlib->get_shoutbox($_REQUEST["msgId"]); 23 $owner = $info["user"]; 24 if ($tiki_p_admin_shoutbox != 'y' && $owner != $user) { 25 $smarty->assign('msg', tr("You do not have permission to edit messages %0", $owner)); 26 $smarty->display("error.tpl"); 27 die; 28 } 29} else { 30 $info = []; 31 $info["message"] = ''; 32 $info["user"] = $user; 33 $owner = $info["user"]; 34} 35$smarty->assign('message', $info["message"]); 36if ($tiki_p_admin_shoutbox == 'y' || $user == $owner) { 37 if (isset($_REQUEST["remove"])) { 38 $access->check_authenticity(); 39 $shoutboxlib->remove_shoutbox($_REQUEST["remove"]); 40 } elseif (isset($_REQUEST["shoutbox_admin"])) { 41 $prefs['shoutbox_autolink'] = (isset($_REQUEST["shoutbox_autolink"])) ? 'y' : 'n'; 42 $tikilib->set_preference('shoutbox_autolink', $prefs['shoutbox_autolink']); 43 } 44} 45if ($tiki_p_post_shoutbox == 'y') { 46 if (isset($_REQUEST["save"]) && ! empty($_REQUEST['message'])) { 47 check_ticket('shoutbox'); 48 if (($prefs['feature_antibot'] == 'y' && empty($user)) && ! $captchalib->validate()) { 49 Feedback::error(['mes' => $captchalib->getErrors()]); 50 if (! empty($_REQUEST['message'])) { 51 $smarty->assign_by_ref('message', $_REQUEST['message']); 52 } 53 } else { 54 $shoutboxlib->replace_shoutbox($_REQUEST['msgId'], $owner, $_REQUEST['message'], ($_REQUEST['tweet'] == 1)); 55 $smarty->assign('msgId', '0'); 56 $smarty->assign('message', ''); 57 } 58 } 59} 60if (! isset($_REQUEST["sort_mode"])) { 61 $sort_mode = 'timestamp_desc'; 62} else { 63 $sort_mode = $_REQUEST["sort_mode"]; 64} 65if (! isset($_REQUEST["offset"])) { 66 $offset = 0; 67} else { 68 $offset = $_REQUEST["offset"]; 69} 70$smarty->assign_by_ref('offset', $offset); 71if (isset($_REQUEST["find"])) { 72 $find = $_REQUEST["find"]; 73} else { 74 $find = ''; 75} 76if (isset($_REQUEST["get"])) { 77 $get = $_REQUEST["get"]; 78} else { 79 $get = 0; 80} 81/* additions for ajax (formerly shoutjax) */ 82/** 83 * @param $formValues 84 * @param string $destDiv 85 */ 86function processShout($formValues, $destDiv = 'mod-shoutbox') 87{ 88 // AJAX_TODO 89 global $user, $prefs, $tiki_p_admin_shoutbox; 90 global $shoutboxlib; 91 $smarty = TikiLib::lib('smarty'); 92 $smarty->assign('tweet', $formValues['tweet']); 93 $smarty->assign('facebook', $formValues['facebook']); 94 if (array_key_exists('shout_msg', $formValues) && strlen($formValues['shout_msg']) > 2) { 95 if (empty($user) && $prefs['feature_antibot'] == 'y' && ! $captchalib->validate()) { 96 $smarty->assign('shout_error', $captchalib->getErrors()); 97 $smarty->assign_by_ref('shout_msg', $formValues['shout_msg']); 98 } else { 99 $shoutboxlib->replace_shoutbox(0, $user, $formValues['shout_msg'], ($formValues['shout_tweet'] == 1), ($formValues['shout_facebook'] == 1)); 100 } 101 } elseif (array_key_exists('shout_remove', $formValues) && $formValues['shout_remove'] > 0) { 102 $info = $shoutboxlib->get_shoutbox($formValues['shout_remove']); 103 if ($tiki_p_admin_shoutbox == 'y' || $info['user'] == $user) { 104 $shoutboxlib->remove_shoutbox($formValues['shout_remove']); 105 } 106 } 107 //$ajaxlib->registerTemplate('mod-shoutbox.tpl'); 108 include('lib/wiki-plugins/wikiplugin_module.php'); 109 $data = wikiplugin_module('', ['module' => 'shoutbox', 'max' => 10, 'np' => 0, 'nobox' => 'y', 'notitle' => 'y', 'tweet' => $formValues['tweet']]); 110 //$objResponse->assign($destDiv, "innerHTML", $data); 111 //return $objResponse; 112} 113/* end additions for ajax */ 114$smarty->assign('find', $find); 115$smarty->assign_by_ref('sort_mode', $sort_mode); 116if ($get) { 117 $data = $shoutboxlib->get_shoutbox($get); 118 $channels['data'] = [$data]; 119 $channels['cant'] = 1; 120} else { 121 $channels = $shoutboxlib->list_shoutbox($offset, $maxRecords, $sort_mode, $find); 122} 123$smarty->assign_by_ref('cant_pages', $channels["cant"]); 124$smarty->assign_by_ref('channels', $channels["data"]); 125ask_ticket('shoutbox'); 126// Display the template 127$smarty->assign('mid', 'tiki-shoutbox.tpl'); 128$smarty->display("tiki.tpl"); 129