1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-29 19:00:26 +02:00

Chatbox working again with ajax

This commit is contained in:
Cameron
2013-04-26 21:49:09 -07:00
parent c62313466b
commit 94a4ba34e6
4 changed files with 206 additions and 59 deletions

View File

@@ -29,7 +29,7 @@ class convert
* System time offset is considered.
*
* @param integer $datestamp unix stamp
* @param string $mask [optional] long|short|forum or any strftime() valid string
* @param string $mask [optional] long|short|forum|relative or any strftime() valid string
*
* @return string parsed date
*/
@@ -76,6 +76,10 @@ class convert
// $datestamp += TIMEOFFSET;
break;
case 'relative':
return $this->computeLapse($datestamp, time(), false, false, 'short') ;
break;
default:
if(strpos($mask, '%') === FALSE)
{
@@ -84,7 +88,6 @@ class convert
break;
}
//
return strftime($mask, $datestamp);
}

View File

@@ -14,12 +14,23 @@
* @package e107_plugins
* @subpackage chatbox
*/
error_reporting(0);
error_reporting(E_ALL);
if(isset($_POST['chatbox_ajax']))
{
define('e_MINIMAL',true);
}
include_once('../../class2.php');
global $e107cache, $e_event, $e107;
$tp = e107::getParser();
$pref = e107::getPref();
if (!plugInstalled('chatbox_menu'))
{
return '';
@@ -28,11 +39,12 @@ if (!plugInstalled('chatbox_menu'))
include_lan(e_PLUGIN.'chatbox_menu/languages/'.e_LANGUAGE.'/'.e_LANGUAGE.'.php');
// FIXME - start - LAN is not loaded
/*
if(($pref['cb_layer']==2) || isset($_POST['chatbox_ajax']))
{
if(isset($_POST['chat_submit']))
{
include_once('../../class2.php');
//Normally the menu.sc file will auto-load the language file, this is needed in case
//ajax is turned on and the menu is not loaded from the menu.sc
@@ -40,13 +52,103 @@ if(($pref['cb_layer']==2) || isset($_POST['chatbox_ajax']))
}
}
// FIXME - end
*/
if(!defined('e_HANDLER')){ exit; }
// if(!defined('e_HANDLER')){ exit; }
require_once(e_HANDLER.'emote.php');
$emessage='';
if(isset($_POST['chat_submit']) && $_POST['cmessage'] != '')
class chatbox_shortcodes extends e_shortcode
{
function sc_username($parm='')
{
list($cb_uid, $cb_nick) = explode(".", $this->var['cb_nick'], 2);
if($this->var['user_name'])
{
$cb_nick = "<a href='".e_HTTP."user.php?id.{$cb_uid}'>".$this->var['user_name']."</a>";
}
else
{
$cb_nick = $tp -> toHTML($cb_nick,FALSE,'USER_TITLE, emotes_off, no_make_clickable');
$cb_nick = str_replace("Anonymous", LAN_ANONYMOUS, $cb_nick);
}
return $cb_nick;
}
function sc_timedate($parm='')
{
return e107::getDate()->convert_date($this->var['cb_datestamp'], "relative");
}
function sc_message($parm = '')
{
if($this->var['cb_blocked'])
{
return CHATBOX_L6;
}
$pref = e107::getPref();
$emotes_active = $pref['cb_emote'] ? 'USER_BODY, emotes_on' : 'USER_BODY, emotes_off';
list($cb_uid, $cb_nick) = explode(".", $this->var['cb_nick'], 2);
$cb_message = e107::getParser()->toHTML($this->var['cb_message'], false, $emotes_active, $cb_uid, $pref['menu_wordwrap']);
return $cb_message;
$replace[0] = "["; $replace[1] = "]";
$search[0] = "&lsqb;"; $search[1] = "&rsqb;";
$cb_message = str_replace($search, $replace, $cb_message);
}
function sc_avatar($parm='')
{
return e107::getParser()->parseTemplate("{USER_AVATAR=".$this->var['user_image']."}");
}
function sc_bullet($parm = '')
{
$bullet = "";
if(defined('BULLET'))
{
$bullet = '<img src="'.THEME_ABS.'images/'.BULLET.'" alt="" class="icon" />';
}
elseif(file_exists(THEME.'images/bullet2.gif'))
{
$bullet = '<img src="'.THEME_ABS.'images/bullet2.gif" alt="" class="icon" />';
}
return $bullet;
}
}
if((isset($_POST['chat_submit']) || e_AJAX_REQUEST) && $_POST['cmessage'] != '')
{
if(!USER && !$pref['anon_post'])
{
@@ -65,7 +167,7 @@ if(isset($_POST['chat_submit']) && $_POST['cmessage'] != '')
if((strlen(trim($cmessage)) < 1000) && trim($cmessage) != "")
{
$cmessage = $tp -> toDB($cmessage);
if($sql -> db_Select("chatbox", "*", "cb_message='$cmessage' AND cb_datestamp+84600>".time()))
if($sql->select("chatbox", "*", "cb_message='$cmessage' AND cb_datestamp+84600>".time()))
{
$emessage = CHATBOX_L17;
}
@@ -84,7 +186,7 @@ if(isset($_POST['chat_submit']) && $_POST['cmessage'] != '')
}
else
{
if($sql -> db_Select("user", "*", "user_name='$nick' ")){
if($sql->select("user", "*", "user_name='$nick' ")){
$emessage = CHATBOX_L1;
}
else
@@ -94,7 +196,7 @@ if(isset($_POST['chat_submit']) && $_POST['cmessage'] != '')
}
if(!$emessage)
{
$sql -> db_Insert("chatbox", "0, '$nick', '$cmessage', '".time()."', '0' , '$ip' ");
$sql->insert("chatbox", "0, '$nick', '$cmessage', '".time()."', '0' , '$ip' ");
$edata_cb = array("cmessage" => $cmessage, "ip" => $ip);
$e_event -> trigger("cboxpost", $edata_cb);
$e107cache->clear("nq_chatbox");
@@ -150,12 +252,15 @@ else
$oc = "";
}
$texta .= "
<textarea class='tbox chatbox' id='cmessage' name='cmessage' cols='20' rows='5' style='".($cb_width ? "width:".$cb_width.";" : '')." overflow: auto' onselect='storeCaret(this);' onclick='storeCaret(this);' onkeyup='storeCaret(this);'></textarea>
<textarea placeholder=\"".LAN_CHATBOX_100."\" required class='tbox chatbox input-xlarge' id='cmessage' name='cmessage' cols='20' rows='5' style='".($cb_width ? "width:".$cb_width.";" : '')." overflow: auto' onselect='storeCaret(this);' onclick='storeCaret(this);' onkeyup='storeCaret(this);'></textarea>
<br />
<input class='btn button' type='submit' id='chat_submit' name='chat_submit' value='".CHATBOX_L4."' {$oc}/>
<input class='btn button' type='reset' name='reset' value='".CHATBOX_L5."' />";
";
if($pref['cb_emote'] && $pref['smiley_activate']){
// $texta .= "<input class='btn button' type='reset' name='reset' value='".CHATBOX_L5."' />"; // How often do we see these lately? ;-)
if($pref['cb_emote'] && $pref['smiley_activate'])
{
$texta .= "
<input class='btn button' type='button' style='cursor:pointer' size='30' value='".CHATBOX_L14."' onclick=\"expandit('emote')\" />
<div style='display:none' id='emote'>".r_emote()."
@@ -185,61 +290,55 @@ if(!$text = $e107cache->retrieve("nq_chatbox"))
LEFT JOIN #user AS u ON SUBSTRING_INDEX(c.cb_nick,'.',1) = u.user_id
ORDER BY c.cb_datestamp DESC LIMIT 0, ".intval($chatbox_posts);
if($sql -> db_Select_gen($qry))
global $CHATBOXSTYLE;
if($CHATBOXSTYLE)
{
$obj2 = new convert;
$cbpost = $sql -> db_getList();
$CHATBOX_TEMPLATE['start'] = "";
$CHATBOX_TEMPLATE['item'] = $CHATBOXSTYLE;
$CHATBOX_TEMPLATE['end'] = "";
}
else // default chatbox style
{
$tp->parseTemplate("{SETIMAGE: w=40}",true); // set thumbnail size.
$CHATBOX_TEMPLATE['start'] = "<ul class='unstyled'>";
$CHATBOX_TEMPLATE['item'] = "<li>
{AVATAR} <b>{USERNAME}</b>&nbsp;
<small class='muted smalltext'>{TIMEDATE}</small><br />
<p style='margin-left:50px'>{MESSAGE}</p>
</li>\n";
$CHATBOX_TEMPLATE['end'] = "</ul>";
}
$sc = e107::getScBatch('chatbox');
if($sql->gen($qry))
{
$cbpost = $sql->db_getList();
$text .= "<div id='chatbox-posts-block'>\n";
$text .= $tp->parseTemplate($CHATBOX_TEMPLATE['start'], true, $sc);
foreach($cbpost as $cb)
{
// get available vars
list($cb_uid, $cb_nick) = explode(".", $cb['cb_nick'], 2);
if($cb['user_name'])
{
$cb_nick = "<a href='".e_HTTP."user.php?id.{$cb_uid}'>{$cb['user_name']}</a>";
}
else
{
$cb_nick = $tp -> toHTML($cb_nick,FALSE,'USER_TITLE, emotes_off, no_make_clickable');
$cb_nick = str_replace("Anonymous", LAN_ANONYMOUS, $cb_nick);
$sc->setVars($cb);
$text .= $tp->parseTemplate($CHATBOX_TEMPLATE['item'], false, $sc);
}
$datestamp = $obj2->convert_date($cb['cb_datestamp'], "short");
$emotes_active = $pref['cb_emote'] ? 'USER_BODY, emotes_on' : 'USER_BODY, emotes_off';
$text .= $tp->parseTemplate($CHATBOX_TEMPLATE['end'], true, $sc);
$cb_message = $tp -> toHTML($cb['cb_message'], FALSE, $emotes_active, $cb_uid, $pref['menu_wordwrap']);
$replace[0] = "["; $replace[1] = "]";
$search[0] = "&lsqb;"; $search[1] = "&rsqb;";
$cb_message = str_replace($search, $replace, $cb_message);
global $CHATBOXSTYLE;
if( ! $CHATBOXSTYLE)
{
$bullet = '';
if(defined('BULLET'))
{
$bullet = '<img src="'.THEME_ABS.'images/'.BULLET.'" alt="" class="icon" />';
}
elseif(file_exists(THEME.'images/bullet2.gif'))
{
$bullet = '<img src="'.THEME_ABS.'images/bullet2.gif" alt="" class="icon" />';
}
// default chatbox style
$CHATBOXSTYLE = "<!-- chatbox -->\n<div class='spacer'>
$bullet <b>{USERNAME}</b><br /><span class='smalltext'>{TIMEDATE}</span><br /><div class='smallblacktext'>{MESSAGE}</div></div><br />\n";
}
$search = array('{USERNAME}', '{TIMEDATE}', '{MESSAGE}');
$replace = array($cb_nick,$datestamp,($cb['cb_blocked'] ? CHATBOX_L6 : $cb_message));
$text .= str_replace($search,$replace,$CHATBOXSTYLE);
}
$text .= "</div>";
}
else
{
$text .= "<span class='mediumtext'>".CHATBOX_L11."</span>";
}
$total_chats = $sql -> db_Count("chatbox");
$total_chats = $sql->count("chatbox");
if($total_chats > $chatbox_posts || CB_MOD)
{
$text .= "<br /><div style='text-align:center'><a href='".e_PLUGIN_ABS."chatbox_menu/chat.php'>".(CB_MOD ? CHATBOX_L13 : CHATBOX_L12)."</a> (".$total_chats.")</div>";
@@ -247,6 +346,9 @@ if(!$text = $e107cache->retrieve("nq_chatbox"))
$e107cache->set("nq_chatbox", $text);
}
$caption = (file_exists(THEME."images/chatbox_menu.png") ? "<img src='".THEME_ABS."images/chatbox_menu.png' alt='' /> ".CHATBOX_L2 : CHATBOX_L2);
if($pref['cb_layer'] == 1)
@@ -254,7 +356,7 @@ if($pref['cb_layer'] == 1)
$text = $texta."<div style='border : 0; padding : 4px; width : auto; height : ".$pref['cb_layer_height']."px; overflow : auto; '>".$text."</div>";
$ns -> tablerender($caption, $text, 'chatbox');
}
elseif($pref['cb_layer'] == 2 && isset($_POST['chat_submit']))
elseif($pref['cb_layer'] == 2 && e_AJAX_REQUEST)
{
$text = $texta.$text;
$text = str_replace(e_IMAGE, e_IMAGE_ABS, $text);
@@ -274,4 +376,5 @@ else
//if(ADMIN && getperms("C")){$text .= "<br /><div style='text-align: center'>[ <a href='".e_PLUGIN."chatbox_menu/admin_chatbox.php'>".CHATBOX_L13."</a> ]</div>";}
//$ns -> tablerender($caption, $text, 'chatbox');
?>

View File

@@ -17,7 +17,7 @@
define("CHATBOX_L1", "Unable to accept post as that username is registered - if it is your username please login to post.");
define("CHATBOX_L2", "Chatbox");
define("CHATBOX_L3", "You must be logged in to post comments on this site - please either log in or if you are not registered click <a href='".e_SIGNUP."'>here</a> to signup");
define("CHATBOX_L4", "Submit");
define("CHATBOX_L4", "Post new message");
define("CHATBOX_L5", "Reset");
define("CHATBOX_L6", "[blocked by admin]");
define("CHATBOX_L7", "Unblock");
@@ -49,4 +49,6 @@ define("NT_LAN_CB_4", "IP Address");
define("NT_LAN_CB_5", "Message");
define("NT_LAN_CB_6", "Chatbox Message Posted");
define("LAN_CHATBOX_100", "Type in your message");
?>

View File

@@ -620,6 +620,12 @@ $(document).ready(function()
})
@@ -1025,3 +1031,36 @@ function preview_image(src_val,img_path, not_found)
return;
}
// BC Ajax function
function sendInfo(handler, container, form)
{
var data = $(form).serialize();
$.ajax({
type: 'post',
url: handler,
data: data,
success: function(data)
{
// console.log(data);
$("#"+container).html(data).hide().show("slow");;
}
});
return false;
//$(container).load(handler,function() {
// alert(src);
//$(this).hide();
// $(this).fadeIn();
// });
//if(form)
// $(form).submitForm(container, null, handler);
//else
// new e107Ajax.Updater(container, handler);
}