TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,973
  • Latest: NonStop
Stats
  • Total Posts: 196,242
  • Total Topics: 21,353
  • Online today: 192
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 1
  • Guests: 482
  • Total: 483
  • lurkalot

TPShout/Div

Started by Tanyril, January 25, 2010, 07:00:53 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Tanyril

Hi, I'd like to make a new block in which TPShout is loaded, but contained within a DIV so that I can have my Ajax script update the shoutbox every so often. Any suggestions? I tried having the div load TPShout.php but it's just coming up blank (possibly being detected as a hacking attempt?)

Link to my site: http://www.boundbybrotherhood.org
SMF version: 1.1.11
TP version: 1.04 B
Theme name and version: WoW-DK
Browser Name and Version: IE 8
Mods installed: Several, doesn't really apply
Related Error messages: No message.

IchBin

Where are you loading your ajax from? Why not just have it call the id of the block? Each block has an id set to it when displaying.

As for the ajax, make sure when you send the parameters in the request that you are sending the same exact info that TP is sending. For example, if you don't send the session id you'll likely get the hacking attempt message.

If you get it working, feel free to share your code. I know others have wanted this for quite some time.

Tanyril

Brilliant idea. I'll look into it.

Tanyril

Would one get the sessionid from SSI? What all variables need to be passed to TPShout in order to function?

Tanyril

&$context['session_id'] ... Anyone know the correct syntax to use this from SMF?

IchBin

In order to get the session id all you have to do is grab the $context global. If you include context in your scope you have access to the session_id.

You'll need to look at the form that is used for the shoutbox when you click the submit button. Look at all the hidden inputs etc. Here's the output of this shoutbox here when it's loaded. The shoutbox is looking for each of those inputs when you submit the form.

<form  accept-charset="UTF-8" class="smalltext" style="padding: 0; margin: 8px 0 8px 0; text-align: center;" name="tp_shoutbox"  id="tp_shoutbox" action="http://www.tinyportal.net/index.php?action=tpmod;shout=save" method="post" >
<textarea class="editor" name="tp_shout" id="tp_shout" onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);" onchange="storeCaret(this);" style="width: 80%;margin-top: 1ex; height: 50px;"  tabindex="1"></textarea><br />
<input style="margin-top: 4px;" class="smalltext" type="submit" name="shout_send" value="Shout!" />
<input type="hidden" name="tp-shout-name" value="IchBinâ„¢" />
<br /><a href="http://www.tinyportal.net/index.php?action=tpmod;shout=show50">Show 50 latest</a>
<input name="tp-shout-url" type="hidden" value="topic=31759.msg254267;topicseen" />
<input type="hidden" name="sc" value="12s3ads43f4asd3f34asf3" />
</form>

Tanyril

#6
Sessioning is beyond me apparently... I no longer get a blank box... just "Hacking attempt..." :D

Using this in my block:

echo $context['session_id'];

echo'
<script src="../tp-files/tp-modules/TPShout/Sources/shtbxupdate.js"></script>
<script type="text/javascript"><!--
refreshdiv();
// --></script>
<div id="shoutbox"></div>
';



In shtbxupdate.js here's the URL that's being passed:

../tp-files/tp-modules/TPShout/Sources/TPShout.php?sc=$context['session_id']&memID=$context['user']['id']
All i'm getting is the session ID from where I echo it and then a blank line in the div...
Am i calling the wrong PHP file or something? This would be much easier if i could see the block code for tpshout :D

Also- I tried just refreshing the block ID, but the script i'm using apparently has to have a URL supplied... FYI- very little of the stuff i'm using is my own code.

IchBin

When you do ajax and you need to pass parameters with $_POST or $_GET, you have to pass those parameters to the ajax call. You don't do it by calling the TPShout.php file. You do it by submitting the form the same way it is submitted through TP. Look at the method="" attribute of the form I posted above. I'd suggest on reading up on some ajax tutorials if you don't know how it all works.

Tanyril

All of the Ajax stuff is later in the js file. I'll post it if you like. I'll let you know what i figure out. Thanks for the tips!

Tanyril

Hey, so, I think i'm pretty close, i have one problem though. I need to have the Ajax code run the tpshout_fetch() function instead of just calling the TPShout.php. By calling that function within a block it actually passes all the variables for me.

here's the javascript (full)

// Customise those settings

var shoutboxseconds = 5;
var shoutboxdivid = "customshoutbox";
var shoutboxurl = "../tp-files/tp-modules/TPShout/Sources/TPShout.php";

function refreshshoutbox(){

// The XMLHttpRequest object

var xmlHttpshoutbox;
try{
xmlHttpshoutbox=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
}
catch (e){
try{
xmlHttpshoutbox=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
}
catch (e){
try{
xmlHttpshoutbox=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
alert("Your browser does not support AJAX.");
return false;
}
}
}

// Timestamp for preventing IE caching the GET request

fetch_unix_timestamp = function()
{
return parseInt(new Date().getTime().toString().substring(0, 10))
}

var shoutboxtimestamp = fetch_unix_timestamp();
var shoutboxnocacheurl = shoutboxurl+"?t="+shoutboxtimestamp;

// The code...

xmlHttpshoutbox.onreadystatechange=function(){
if(xmlHttpshoutbox.readyState==4){
document.getElementById(shoutboxdivid).innerHTML=xmlHttpshoutbox.responseText;
setTimeout('refreshshoutbox()',shoutboxseconds*1000);
}
}
xmlHttpshoutbox.open("GET",shoutboxnocacheurl,true);
xmlHttpshoutbox.send(null);
}

// Start the refreshing process

var shoutboxseconds;
window.onload = function startshoutboxrefresh(){
setTimeout('refreshshoutbox()',shoutboxseconds*1000);
}


i had read somewhere that instead of:
document.getElementById(shoutboxdivid).innerHTML=xmlHttpshoutbox.responseText;

i could do:
document.getElementById(shoutboxdivid).innerHTML="<?php tpshout_fetch() ?>";

but that didn't work. Any pearls of wisdom?

This website is proudly hosted on Crocweb Cloud Website Hosting.