Got a spare half hour to play with this. First, you will need to create a new EE template, have PHP on Input, and put this in it:
<?php /* PHP on Input */ global $SESS, $DB; $query = $DB->query("SELECT private_messages FROM exp_members WHERE member_id = '".$DB->escape_str($SESS->userdata['member_id'])."'"); exit($query->row['private_messages']); ?>
My template was in the ‘site’ template group and I called the template ‘anything’. Next, find the forum template for the Private Message box. Replace its HTML with this new stuff:
<script type="text/javascript">
var XMLHttp=false; var checkTime = 15; // 15 seconds
function checkPM() {
var serverPage = '/ExpressionEngine140/index.php/site/anything/';
if (window.XMLHttpRequest) { XMLHttp = new XMLHttpRequest(); XMLHttp.onreadystatechange = processResult XMLHttp.open("GET", serverPage); XMLHttp.send(null); // branch for IE/Windows ActiveX version } else if (window.ActiveXObject) { try { XMLHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch(g){ var unSupported = 'y'; }
You will see the javascript up there. I currently have it set to check every 15 seconds. Make sure to see the relative path for your template created above in the checkPM javascript function and you should be good.
You’d either need to put backslashes before your single quotes- or just drop out of php entirely- which is probably what I’d do. Make sense? If not, post what you were trying to use that was throwing errors.
Would it be possible to alter this in such a way that instead of refreshing the PM display, the code takes a look at an xml file on the server and updates the information located there?
I’m trying to think of a way to improve the Koru Production’s Now Playing plugin.
Rob1 pointed me to this thread as a possible start to the solution.
Well, the iTunes visualizer plugin uploads an xml file to the server, and the Now Playing plugin then reads the file and posts the song currently playing in iTunes. I was wondering if it could somehow read that xml file and automatically update the information in that plugin without refreshing the entire screen, only the Now Playing song.
That plugin is not updated, it merely displays the updated XML file. So, what you want is possible with this. You would probably put the plugin in its own, dedicate template and then have the AJAX code above simply call that template and display the results on your page.
Nope, remember how the data that needs to be loads is that which is created by the plugin? So, that GET url should be the URL to your page/template with only the plugin in it.
I’m not sure I’m going to get this, Paul. I just don’t know enough. Anything, really, other than how to ask questions, it seems.
In the line:
var serverPage = '/ExpressionEngine140/index.php/site/anything/';
am I putting in
http://www.scrine.com/templategroup/template
And I don’t have a clue how I’m supposed to change the whole PM business in that code. Do I just perform the function part at the top half, and then get rid of the function result part, letting the plugin template that’s been called for do that work?
Or do I just try to bribe you with money or something to make it work?
Hm. The above AJAX stuff is very specific to the PM info displaying, so perhaps we should try a different approach and get you working on a library? I suggest the Moo.fx one as it is really light weight and has AJAX easily available. You will want to download the files and then load them in your page’s headers:
I downloaded the four moo.fx scripts and place them in my header, along with
</script> </script> </script> </s
In my template, I then put the function you’ve provided, looking like this:
var checkTime = 15; // 15 seconds
function load_itunes() { new ajax ('http://scrine.com/scrine/now-playing/', { update: $('iTunesDiv') } );
setTimeout("load_itunes()", checkTime * 1000); }
setTimeout("load_itunes()", checkTime * 1000);
</script>
Isn’t the starting script tag missing? What do I use exactly?
I’m not sure what the iTunesDiv means. Is that just the div where the results will show, defined in the CSS?
Thank you for your patience, Paul. I know you have better things to be doing than helping me figure this out. I do think other people will want to utilize this setup, though, once it’s beat into my hard head.
The XSS_Clean function in EE is removing the tags from your forum posts, but yes they should be there. The ‘iTunesDiv’ is the id for the <div> that will contain your results:
I really feel like an idiot here. What’s going in the iTunesDiv? Isn’t this where the results of the Now Playing plugin go? I just don’t know how to make the results show.