1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 20:58:30 +01:00

359 lines
7.9 KiB
PHP
Raw Normal View History

2006-12-02 04:36:16 +00:00
<?php
/*
2009-11-17 12:59:03 +00:00
* e107 website system
*
2013-03-10 12:23:45 +01:00
* Copyright (C) 2008-2013 e107 Inc (e107.org)
2009-11-17 12:59:03 +00:00
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* e107 chatbox_menu Plugin
*
*/
2006-12-02 04:36:16 +00:00
2021-01-01 10:45:26 -08:00
if(isset($_POST['chatbox_ajax']))
2020-12-18 19:55:12 -08:00
{
define('e_MINIMAL', true);
2021-01-01 10:45:26 -08:00
if(!defined('e107_INIT'))
2020-12-18 19:55:12 -08:00
{
2021-01-21 09:38:38 -08:00
require_once(__DIR__.'/../../class2.php');
}
2013-04-26 21:49:09 -07:00
}
2013-03-10 12:23:45 +01:00
global $e107cache, $e_event, $e107;
2013-04-26 21:49:09 -07:00
2013-03-10 12:23:45 +01:00
$tp = e107::getParser();
$pref = e107::getPref();
2013-04-26 21:49:09 -07:00
2021-01-01 10:45:26 -08:00
if(!e107::isInstalled('chatbox_menu'))
2020-12-18 19:55:12 -08:00
{
return '';
}
2006-12-02 04:36:16 +00:00
e107::lan('chatbox_menu', e_LANGUAGE);
2013-03-10 12:23:45 +01:00
2006-12-02 04:36:16 +00:00
$emessage = '';
2006-12-02 04:36:16 +00:00
2013-04-26 21:49:09 -07:00
2021-01-01 10:45:26 -08:00
if((isset($_POST['chat_submit']) || e_AJAX_REQUEST) && $_POST['cmessage'] !== '')
2020-12-18 19:55:12 -08:00
{
2013-04-26 21:49:09 -07:00
2021-01-01 10:45:26 -08:00
if(!USER && !$pref['anon_post'])
2020-12-08 12:21:12 -08:00
{
2020-12-18 19:55:12 -08:00
$cmessage = ''; // disallow post
2020-12-08 12:21:12 -08:00
}
else
{
2020-12-18 19:55:12 -08:00
$nick = trim(preg_replace("#\[.*\]#s", '', $tp->toDB($_POST['nick'])));
2006-12-02 04:36:16 +00:00
$cmessage = $_POST['cmessage'];
$cmessage = preg_replace("#\[.*?\](.*?)\[/.*?\]#s", "\\1", $cmessage);
2006-12-02 04:36:16 +00:00
$fp = new floodprotect;
2021-01-01 10:45:26 -08:00
if($fp->flood('chatbox', 'cb_datestamp'))
2020-12-18 19:55:12 -08:00
{
2021-01-01 10:45:26 -08:00
if(trim($cmessage) !== '' && (strlen(trim($cmessage)) < 1000))
2020-12-18 19:55:12 -08:00
{
$cmessage = $tp->toDB($cmessage);
2021-01-01 10:45:26 -08:00
if($sql->select('chatbox', '*',
2020-12-18 19:55:12 -08:00
"cb_message='{$cmessage}' AND cb_datestamp+84600>" . time()))
{
2006-12-02 04:36:16 +00:00
$emessage = CHATBOX_L17;
2020-12-18 19:55:12 -08:00
}
else
{
2006-12-02 04:36:16 +00:00
$datestamp = time();
$ip = e107::getIPHandler()->getIP(false);
2021-01-01 10:45:26 -08:00
if(USER)
2020-12-18 19:55:12 -08:00
{
2020-12-18 19:55:12 -08:00
$nick = USERID . '.' . USERNAME;
$postTime = time();
$sql->update('user', "user_chats = user_chats + 1, user_lastpost = {$postTime} WHERE user_id = " . USERID);
2020-12-18 19:55:12 -08:00
}
2021-01-01 10:45:26 -08:00
elseif(!$nick)
2020-12-18 19:55:12 -08:00
{
$nick = '0.Anonymous';
2020-12-18 19:55:12 -08:00
}
else
{
2021-01-01 10:45:26 -08:00
if($sql->select('user', '*', "user_name='$nick' "))
2020-12-18 19:55:12 -08:00
{
2006-12-02 04:36:16 +00:00
$emessage = CHATBOX_L1;
2020-12-18 19:55:12 -08:00
}
else
{
$nick = "0." . $nick;
2006-12-02 04:36:16 +00:00
}
2006-12-02 04:36:16 +00:00
}
2021-01-01 10:45:26 -08:00
if(!$emessage)
2020-12-18 19:55:12 -08:00
{
$insertId = $sql->insert('chatbox',
"0, '{$nick}', '{$cmessage}', '{$datestamp}', 0, '{$ip}' ");
2021-01-01 10:45:26 -08:00
if($insertId)
2020-12-18 19:55:12 -08:00
{
$edata_cb = [
'id' => $insertId,
'nick' => $nick,
'cmessage' => $cmessage,
'datestamp' => $datestamp,
'ip' => $ip,
];
2020-12-18 19:55:12 -08:00
$e_event->trigger('cboxpost', $edata_cb); // deprecated
e107::getEvent()->trigger('user_chatbox_post_created', $edata_cb);
$e107cache->clear('nq_chatbox');
}
2006-12-02 04:36:16 +00:00
}
}
2020-12-18 19:55:12 -08:00
}
else
{
2006-12-02 04:36:16 +00:00
$emessage = CHATBOX_L15;
}
2020-12-18 19:55:12 -08:00
}
else
{
$emessage = $tp->lanVars(CHATBOX_L19, FLOODTIMEOUT ?: 'n/a');
2006-12-02 04:36:16 +00:00
}
}
}
2021-01-01 10:45:26 -08:00
if(!USER && !$pref['anon_post'])
2020-12-18 19:55:12 -08:00
{
2021-01-01 10:45:26 -08:00
if($pref['user_reg'])
2020-12-18 19:55:12 -08:00
{
2020-12-18 19:55:12 -08:00
$text1 = str_replace(['[', ']'], ["<a href='" . e_LOGIN . "'>", '</a>'],
CHATBOX_L3);
2021-01-01 10:45:26 -08:00
if($pref['user_reg'] === 1)
2020-12-18 19:55:12 -08:00
{
$text1 .= str_replace(['[', ']'],
2020-12-18 19:55:12 -08:00
["<a href='" . e_SIGNUP . "'>", '</a>'], CHATBOX_L3b);
}
2006-12-02 04:36:16 +00:00
$texta =
2020-12-18 19:55:12 -08:00
"<div style='text-align:center'>" . $text1 . '</div><br /><br />';
2006-12-02 04:36:16 +00:00
}
2020-12-18 19:55:12 -08:00
}
else
{
$cb_width = (defined('CBWIDTH') ? CBWIDTH : '');
2021-01-01 10:45:26 -08:00
if(varset($pref['cb_layer']) === 2)
2020-12-18 19:55:12 -08:00
{
2020-12-18 19:55:12 -08:00
$texta = "\n<form id='chatbox' action='" . e_SELF . '?' . e_QUERY . "' method='post' onsubmit='return(false);'>
<div>
<input type='hidden' name='chatbox_ajax' id='chatbox_ajax' value='1' />
</div>";
2020-12-18 19:55:12 -08:00
}
else
{
$texta = (e_QUERY
2020-12-18 19:55:12 -08:00
? "\n<form id='chatbox' method='post' action='" . e_SELF . '?' . e_QUERY . "'>"
: "\n<form id='chatbox' method='post' action='" . e_SELF . "'>");
2006-12-02 04:36:16 +00:00
}
2015-01-30 02:48:54 -08:00
$texta .= "<div class='control-group form-group' id='chatbox-input-block'>";
2006-12-02 04:36:16 +00:00
2021-01-01 10:45:26 -08:00
if(($pref['anon_post'] == '1' && USER === false))
2020-12-18 19:55:12 -08:00
{
$texta .= "\n<input class='tbox chatbox' type='text' id='nick' name='nick' value='' maxlength='50' " . ($cb_width
2020-12-18 19:55:12 -08:00
? "style='width: " . $cb_width . ";'" : '') . ' /><br />';
2006-12-02 04:36:16 +00:00
}
2021-01-01 10:45:26 -08:00
if($pref['cb_layer'] === 2)
2020-12-18 19:55:12 -08:00
{
$oc =
"onclick=\"javascript:sendInfo('" . SITEURLBASE . e_PLUGIN_ABS . "chatbox_menu/chatbox_menu.php', 'chatbox_posts', this.form);\"";
2020-12-18 19:55:12 -08:00
}
else
{
$oc = '';
2006-12-02 04:36:16 +00:00
}
2020-12-18 19:55:12 -08:00
$texta .= '
<textarea placeholder="' . LAN_CHATBOX_100 . "\" required class='tbox chatbox form-control input-xlarge' id='cmessage' name='cmessage' cols='20' rows='5' style='max-width:97%; " . ($cb_width
? 'width:' . $cb_width . ';' : '') . " overflow: auto' onselect='storeCaret(this);' onclick='storeCaret(this);' onkeyup='storeCaret(this);'></textarea>
2006-12-02 04:36:16 +00:00
<br />
<input class='btn btn-sm btn-primary button' type='submit' id='chat_submit' name='chat_submit' value='" . CHATBOX_L4 . "' {$oc}/>";
// $texta .= "<input type='reset' name='reset' value='".CHATBOX_L5."' />"; // How often do we see these lately? ;-)
2006-12-02 04:36:16 +00:00
2021-01-01 10:45:26 -08:00
if(!empty($pref['cb_emote']) && !empty($pref['smiley_activate']))
2020-12-18 19:55:12 -08:00
{
2006-12-02 04:36:16 +00:00
$texta .= "
<input class='btn btn-default btn-secondary button' type='button' style='cursor:pointer' size='30' value='" . CHATBOX_L14 . "' onclick=\"expandit('emote')\" />
<div class='well' style='display:none' id='emote'>" . r_emote() . "</div>\n";
2006-12-02 04:36:16 +00:00
}
$texta .= "</div>\n</form>\n";
2006-12-02 04:36:16 +00:00
}
2021-01-01 10:45:26 -08:00
if($emessage !== '')
2020-12-18 19:55:12 -08:00
{
$texta .= "<div style='text-align:center'><b>" . $emessage . '</b></div>';
2006-12-02 04:36:16 +00:00
}
2021-01-21 09:38:38 -08:00
if(!$text = e107::getCache()->retrieve('nq_chatbox'))
2020-12-18 19:55:12 -08:00
{
global $pref, $tp;
2021-01-01 10:45:26 -08:00
$pref['chatbox_posts'] = (!empty($pref['chatbox_posts']) ? (int) $pref['chatbox_posts'] : 10);
2006-12-02 04:36:16 +00:00
$chatbox_posts = $pref['chatbox_posts'];
2021-01-01 10:45:26 -08:00
if(!isset($pref['cb_mod']))
2020-12-18 19:55:12 -08:00
{
2006-12-02 04:36:16 +00:00
$pref['cb_mod'] = e_UC_ADMIN;
}
2021-01-01 10:45:26 -08:00
if(!defined('CB_MOD'))
2020-12-18 19:55:12 -08:00
{
define('CB_MOD', check_class($pref['cb_mod']));
}
2006-12-02 04:36:16 +00:00
$qry = "SELECT c.*, u.user_name, u.user_image FROM #chatbox AS c
LEFT JOIN #user AS u ON SUBSTRING_INDEX(c.cb_nick, '.', 1) = u.user_id
2020-12-18 19:55:12 -08:00
ORDER BY c.cb_datestamp DESC LIMIT 0, " . (int) $chatbox_posts;
2006-12-02 04:36:16 +00:00
2013-04-26 21:49:09 -07:00
global $CHATBOXSTYLE;
2021-01-01 10:45:26 -08:00
if($CHATBOXSTYLE) // legacy chatbox style
2013-04-26 21:49:09 -07:00
{
$legacyIconSrc = e_IMAGE_ABS . 'admin_images/chatbox_16.png';
$currentIconSrc = e_PLUGIN . 'chatbox_menu/images/chatbox_16.png';
$legacySrch = array($legacyIconSrc, '{USERNAME}', '{MESSAGE}', '{TIMEDATE}');
2020-12-18 19:55:12 -08:00
$legacyRepl = array($currentIconSrc, '{CB_USERNAME}', '{CB_MESSAGE}', '{CB_TIMEDATE}');
$CHATBOX_TEMPLATE['start'] = '';
$CHATBOX_TEMPLATE['item'] = str_replace($legacySrch, $legacyRepl, $CHATBOXSTYLE);
$CHATBOX_TEMPLATE['end'] = '';
2013-04-26 21:49:09 -07:00
}
2020-12-18 19:55:12 -08:00
else // default chatbox style
2006-12-02 04:36:16 +00:00
{
$CHATBOX_TEMPLATE = e107::getTemplate('chatbox_menu', null, 'menu');
2013-04-26 21:49:09 -07:00
}
// FIX - don't call getScBatch() if don't need to globally register the methods
// $sc = e107::getScBatch('chatbox');
// the good way in this case - it works with any object having sc_*, models too
//$sc = new chatbox_shortcodes();
$sc = e107::getScBatch('chatbox_menu', true);
2021-01-01 10:45:26 -08:00
if($sql->gen($qry))
2020-12-18 19:55:12 -08:00
{
$cbpost = $sql->rows();
2013-04-29 19:40:16 -07:00
$text .= "<div id='chatbox-posts-block'>\n";
2013-04-29 19:40:16 -07:00
2013-04-27 13:16:08 -07:00
$text .= $tp->parseTemplate($CHATBOX_TEMPLATE['start'], false, $sc);
2013-04-29 19:40:16 -07:00
2021-01-01 10:45:26 -08:00
foreach($cbpost as $cb)
2020-12-18 19:55:12 -08:00
{
2013-04-26 21:49:09 -07:00
$sc->setVars($cb);
$text .= $tp->parseTemplate($CHATBOX_TEMPLATE['item'], false, $sc);
2006-12-02 04:36:16 +00:00
}
2013-04-27 13:16:08 -07:00
$text .= $tp->parseTemplate($CHATBOX_TEMPLATE['end'], false, $sc);
2013-04-29 19:40:16 -07:00
2020-12-18 19:55:12 -08:00
$text .= '</div>';
2020-12-18 19:55:12 -08:00
}
else
{
$text .= "<span class='mediumtext'>" . CHATBOX_L11 . '</span>';
2006-12-02 04:36:16 +00:00
}
2020-12-18 19:55:12 -08:00
$total_chats = $sql->count('chatbox');
2021-01-01 10:45:26 -08:00
if($total_chats > $chatbox_posts || CB_MOD)
2020-12-18 19:55:12 -08:00
{
$text .= "<br /><div style='text-align:center'><a href='" . e_PLUGIN_ABS . "chatbox_menu/chat.php'>" . (CB_MOD
? CHATBOX_L13
2020-12-18 19:55:12 -08:00
: CHATBOX_L12) . '</a> (' . $total_chats . ')</div>';
2006-12-02 04:36:16 +00:00
}
2021-01-21 09:38:38 -08:00
e107::getCache()->set('nq_chatbox', $text);
2006-12-02 04:36:16 +00:00
}
2013-04-26 21:49:09 -07:00
2020-12-18 19:55:12 -08:00
$caption = (file_exists(THEME . 'images/chatbox_menu.png')
? "<img src='" . THEME_ABS . "images/chatbox_menu.png' alt='' /> " . LAN_PLUGIN_CHATBOX_MENU_NAME
: LAN_PLUGIN_CHATBOX_MENU_NAME);
2013-04-26 21:49:09 -07:00
2021-01-01 10:45:26 -08:00
if(varset($pref['cb_layer']) === 1)
2020-12-18 19:55:12 -08:00
{
2013-04-27 13:16:08 -07:00
$text =
2020-12-18 19:55:12 -08:00
$texta . "<div style='border : 0; padding : 4px; width : auto; height : " . $pref['cb_layer_height'] . "px; overflow : auto; '>" . $text . '</div>';
2006-12-02 04:36:16 +00:00
$ns->tablerender($caption, $text, 'chatbox');
2020-12-18 19:55:12 -08:00
}
2021-01-01 10:45:26 -08:00
elseif(varset($pref['cb_layer']) === 2 && e_AJAX_REQUEST)
2020-12-18 19:55:12 -08:00
{
$text = $texta . $text;
2006-12-02 04:36:16 +00:00
$text = str_replace(e_IMAGE, e_IMAGE_ABS, $text);
echo $text;
2020-12-18 19:55:12 -08:00
}
else
{
$text = $texta . $text;
2006-12-02 04:36:16 +00:00
2021-01-01 10:45:26 -08:00
if($pref['cb_layer'] === 2)
2020-12-18 19:55:12 -08:00
{
$text = "<div id='chatbox_posts'>" . $text . '</div>';
}
$ns->tablerender($caption, $text, 'chatbox');
}
2013-04-26 21:49:09 -07:00