View Full Version : RESOLVED: Vbulletin Variable / Array names in Javascript?
vaskies
12-06-2009, 05:34 PM
*warning* javascript/php noob here. I'm in the process of learning, but would *HIGHLY* appreciate some help on this. The bolded code is what I'm editing:
(note I'm using wz_tooltip.js, a javascript tooltip (http://www.walterzorn.com/tooltip/tooltip_e.htm) and the how to display active threads on forum home (http://www.vbulletin.com/forum/showthread.php?158887-HowTo-Display-Latest-Active-Threads-on-Forumhome)
<script type="text/javascript" src="/js/tooltips/wz_tooltip.js"></script>
<if condition="$vbulletin->options['externaljs']">
<!-- show latest active threads -->
<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%"
align="center">
<tbody>
<tr>
<td class="thead" colspan="2">
<a style="float:$stylevar[right]" href="#top" onclick="return toggle_collapse('forumhome_external')"><img
id="collapseimg_forumhome_external"
src="$stylevar[imgdir_button]/collapse_thead$vbcollapse[collapseimg_forumhome_external].gif" alt="" border="0" /></a>
<a href="search.php?$session[sessionurl]do=getnew">Latest Active Threads</a>
</td>
</tr>
</tbody>
<tbody id="collapseobj_forumhome_external" style="$vbcollapse[collapseobj_forumhome_external]">
<tr>
<td class="alt1" width="100%">
<div class="smallfont">
<script type="text/javascript" src="external.php?type=js"></script>
<script language="" type="text/javascript">
<!--
for (var x in threads)
{
document.writeln("<img class=\"inlineimg\" src=\"$stylevar[imgdir_button]/lastpost.gif\" alt=\"\" border=\"0\" />
<a onmouseover=\"Tip('<b>Thread Title:</b> $threadinfo[title]<br/>
<b>Last Post Time:</b> $gnpdate<br/>
<b>Username of Last Poster:</b>$threadinfo[musername]<br/>
<b>Preview of Thread:</b>$threadinfo[preview]')\" onmouseout=\"UnTip()\" href=\"showthread.php?t="+threads[x].threadid+"\">"+threads[x].title+"</a><br />");
}
//-->
</script></div>
</td>
</tr>
</tbody>
<!-- show latest active threads -->
</table>
<br />
</if>
As it is, nothing shows up in the tooltip. What's wrong with my variables? Thank you very much in advance! :)
Wow, *there's* a cool puzzle. :) Anyway, too cool for me maybe because I don't see anything wrong. I can't remember, if you view the HTML source will you see the part that comes from a document.write? The only other thing I can think of is to simplify it, just put in <a onmouseover="Tip('foo')" ... and then add stuff back in gradually.
vaskies
12-07-2009, 12:29 AM
Viewing source with ('Some Text') as the mouseover:
<!--
for (var x in threads)
{
document.writeln("<img class=\"inlineimg\" src=\"images/buttons/lastpost.gif\" alt=\"\" border=\"0\" /> <a onmouseover=\"Tip('Some text')\" onmouseout=\"UnTip()\" href=\"showthread.php?t="+threads[x].threadid+"\">"+threads[x].title+"</a><br />");
}
//-->
</script>
When replacing Some Text with say, $gnpdate, this is what view source outputs:
<!--
for (var x in threads)
{
document.writeln("<img class=\"inlineimg\" src=\"images/buttons/lastpost.gif\" alt=\"\" border=\"0\" /> <a onmouseover=\"Tip('')\" onmouseout=\"UnTip()\" href=\"showthread.php?t="+threads[x].threadid+"\">"+threads[x].title+"</a><br />");
}
//-->
Where the variable was placed, nothing shows up at all. And on the mouse over, it is blank as well.
:confused:
I think that could only happen if $gnpdate had no value.
vaskies
12-07-2009, 01:19 AM
What's interesting to note is that a variable like $bbuserinfo[musername] works!
None of the variables directly related to the individual thread though are working.
Is there a way I could go about assigning them proper values?
I don't know what $gnpdate is supposed to be. Is it set in the same php file that the template is eval'd in?
vaskies
12-07-2009, 02:10 AM
Oops, I got confused there for a second. I've been trying various plugins throughout the day and I thought that was a default vbulletin variable. :p
I'm trying to display the date of the last post of a thread. So when you mouse over the thread link, it will display "Last Post: 10 minutes ago".
How would I go about defining that?
Just the date, or those other thread fields? Anyway, if you look in forumdisplay.php you'll see how the thread info is read from the database, then I think includes/functions_forumdisplay.php has functions for formatting that data. If you search in there for 'dateline' you'll find where it uses the function vbdate() to do the formatting.
It depends on which .php file you're displaying, but it looks like in general $threadinfo is set by global.php if the url has a threadid. In forumdisplay it's displaying many threads in a loop, and it looks like within that loop it's using $thread. So if your stuff is being call from there you might find that $thread[postdate] and $thread[posttime] are already set.
vaskies
12-08-2009, 12:02 AM
Both $thread[postdate] and $thread[posttime] show up as nothing. There seems to be no association with those variables and the thread link itself. Maybe I have to read it from the database? (I have no idea how I'd do that :p)
Well, where are you getting the thread titles? What's the url of the page you are working on (not the domain name, but everything after that)?
vaskies
12-09-2009, 11:37 PM
I'm getting the thread titles from that "latest threads on forum home" template modification I linked in my first post.
The URL of the page I'm working on is vb3/index.php. It's on a local setup, so the full URL is http://localhost/vb3/index.php.
If I could get the forumdisplay.php variables to work on index.php, I should be all set, yeah?
Cause as it is, the forumdisplay.php variables show up as undefined when used on index.php.
Sorry for the late response by the way, been busy last couple days. Things have settled down a bit now though. :)
OK, my fault - I totally missed the "how to display active threads on forum home" link in the first post. I can understand your confusion.
It looks like what's going on is the thread info is being loaded in to the page as javascript. So you can't use any php variable replacement in the templates to add info (because the thread variables aren't set), you have to just use whatever is passed in the javascript. I don't see it documented anywhere (big surprise, really), so I just got the javascript and looked at it. It looks like you have 5 things you can use: threadid, title, poster, threaddate, threadtime. And you would use them like you see them being used there, threads[x].threaddate for instance.
You could of course get more info by getting it from the database, but then there is probably no point in using the external data provider thing.
ETA: actually, I thought of something else you could do - change external.php. If you search for
if ($vbulletin->GPC['type'] == 'JS')
{ // javascript output
you will see how it constructs the javascript. There it has the $thread variable available, so you could add any fields you wanted in addition to the 5 that are already there.
vaskies
12-10-2009, 05:20 AM
Long post up ahead! :p I'll split this into two parts. The first part shows what I've tried. The second part is what I think might be a good idea to try next. This will make more sense once you read it. Stay with me. :)
What I've Tried:
I found the function you were referring to inside external.php. Unfortunately, I'm having some trouble using the values inside the javascript mouseover.
For example, I tried threaddate below: (this code snippet is from the forum home template mod)
for (var x in threads)
{
document.writeln("<a onmouseover=\"Tip('threads[x].threaddate')\" onmouseout=\"UnTip()\" href=\"showthread.php?t="+threads[x].threadid+"\">"+threads[x].title+"</a> <span class=\"time\">($vbphrase[posted_by]: "+threads[x].poster+")</span><br />");
}
Instead of showing the actual date of the thread's creation, it prints out the actual text threads[x].threaddate and treats it like any other string.
I tried variations too such as +threads[x].threaddate+ without any luck.
Bad news is, I have no clue why it's not parsing that value. Good news is, I think I may have found (possibly) a better approach to my needs. I'll need some help though if I'm going to get the values I need inside of it. :) I think it should be much simpler and to the point because it's not dealing with javascript. What I'm referring to is this plugin (https://vborg.vbsupport.ru/showthread.php?t=106726&highlight=active+threads).
Quick and to the point:
Here's the plugins php main code: (I bolded what looks relevant)
global $db, $vbulletin;
switch ($vbulletin->options['devel_lastx_ord'])
{
case 0: $ord = 'dateline'; break;
case 1: $ord = 'lastpost'; break;
}
$forumdevel1 = $vbulletin->options['lastxforumid1'];
$forumnamedevel1 = $vbulletin->options['forumnamedevel1'];
$limitdevel1 = $vbulletin->options['lastxlimit1'];
if ($vbulletin->options['endislastx'])
if ($vbulletin->options['endislastx1'])
$lastxdevels1 = $db->query_read("
SELECT threadid, title, postusername, replycount, lastposter, views, attach
FROM " . TABLE_PREFIX . "thread
WHERE forumid IN ($forumdevel1)
AND visible = 1
order by $ord DESC
LIMIT $limitdevel1
");
while ($lastxdevel1 = $db->fetch_array($lastxdevels1))
{
if(strlen($lastxdevel1['title']) > $vbulletin->options['lastxmax'])
{
$lastxdevel1['title'] = substr($lastxdevel1['title'], 0, $vbulletin->options['lastxmax']) . ' ...';
}
$lastxdevelt1.="<div class='smallfont'><font size='2'><a onmouseover=\"Tip('Some Text')\" onmouseout=\"UnTip()\" href='showthread.php?t=$lastxdevel1[threadid]'><span style='width:200px;text-overflow:hidden;'>$lastxdevel1[title]</span></a></font></div>";
}
$forumdevel2 = $vbulletin->options['lastxforumid2'];
$forumnamedevel2 = $vbulletin->options['forumnamedevel2'];
$limitdevel2 = $vbulletin->options['lastxlimit2'];
if ($vbulletin->options['endislastx'])
if ($vbulletin->options['endislastx2'])
$lastxdevels2 = $db->query_read("
SELECT threadid, title, postusername, replycount, lastposter, views, attach
FROM " . TABLE_PREFIX . "thread
WHERE forumid IN ($forumdevel2)
AND visible = 1
order by $ord DESC
LIMIT $limitdevel2
");
while ($lastxdevel2 = $db->fetch_array($lastxdevels2))
{
if(strlen($lastxdevel2['title']) > $vbulletin->options['lastxmax'])
{
$lastxdevel2['title'] = substr($lastxdevel2['title'], 0, $vbulletin->options['lastxmax']) . ' ...';
}
$lastxdevelt2.="<div class='smallfont'><img border='0' src='$stylevar/lastpost.png'> <font size='2'><a title='$vbphrase[pobydevel]$lastxdevel2[postusername] | $vbphrase[lasdevel]$lastxdevel2[lastposter] | $vbphrase[redevel]$lastxdevel2[replycount] | $vbphrase[viewdevel]$lastxdevel2[views] | $vbphrase[attcodevel]$lastxdevel2[attach]' href='showthread.php?t=$lastxdevel2[threadid]'>$lastxdevel2[title]</a></font></div>";
}
$forumdevel3 = $vbulletin->options['lastxforumid3'];
$forumnamedevel3 = $vbulletin->options['forumnamedevel3'];
$limitdevel3 = $vbulletin->options['lastxlimit3'];
if ($vbulletin->options['endislastx'])
if ($vbulletin->options['endislastx3'])
$lastxdevels3 = $db->query_read("
SELECT threadid, title, postusername, replycount, lastposter, views, attach
FROM " . TABLE_PREFIX . "thread
WHERE forumid IN ($forumdevel3)
AND visible = 1
order by $ord DESC
LIMIT $limitdevel3
");
while ($lastxdevel3 = $db->fetch_array($lastxdevels3))
{
if(strlen($lastxdevel3['title']) > $vbulletin->options['lastxmax'])
{
$lastxdevel3['title'] = substr($lastxdevel3['title'], 0, $vbulletin->options['lastxmax']) . ' ...';
}
$lastxdevelt3.="<div class='smallfont'><img border='0' src='$stylevar[imgdir_button]/lastpost.png'> <font size='2'><a title='$vbphrase[pobydevel]$lastxdevel3[postusername] | $vbphrase[lasdevel]$lastxdevel3[lastposter] | $vbphrase[redevel]$lastxdevel3[replycount] | $vbphrase[viewdevel]$lastxdevel3[views] | $vbphrase[attcodevel]$lastxdevel3[attach]' href='showthread.php?t=$lastxdevel3[threadid]'>$lastxdevel3[title]</a></font></div>";
}
Keep in mind, that the code for outputting the latest threads is repeated three times because this plugin allows for three columns, all from different forumIDs. Once we can figure out how to get the values into one column, it would be a matter of copy and pasting for the other two.
As a reminder, the 4 values I need are:
$thread[title]
$thread[lastposter]
$thread[preview]
$thread[lastpost]
As you can see in the above bolded code, the first two values,title and lastposter are already read from the table and actually work! :) And after a couple days of learning PHP, I managed to get $thread[lastpost] to work in the correct time format too! The last value however, thread[preview] causes the error:
Invalid SQL:
SELECT threadid, title, preview, postusername, replycount, lastposter, lastpost, views, attach
FROM thread
WHERE forumid IN (2)
AND visible = 1
order by lastpost DESC
LIMIT 10;
MySQL Error : Unknown column 'preview' in 'field list'
[I]To make a long story short: where is $thread[preview] located?
One Last Thing:
In addition to getting this plugin to work, I'm really trying to further my knowledge on vbulletin's syntax. I'm currently learning PHP (I just finished up learning functions) but I'm finding a lot of vbulletin's documentation to be pretty inconsistent. Aside from the vbulletin manual, are there any resources available that really explain vbulletin's structure? In particular, I would like to know all the values for $thread array but have no idea where to look. $thread is an array correct? Since the syntax is $thread[value].
Take your time replying to this one haha :p I tried to be concise as possible, but I really wanted to convey that I've been working to improve and learn more, as opposed to seem like I'm simply leeching off more knowledgable people such as yourself. :p You've been invaluable and thank you for your help and patience with me. :)
First, I think what might have worked is :
for (var x in threads)
{
document.writeln("<a onmouseover=\"Tip(threads[x].threaddate)\" onmouseout=\"UnTip()\" href=\"showthread.php?t="+threads[x].threadid+"\">"+threads[x].title+"</a> <span class=\"time\">($vbphrase[posted_by]: "+threads[x].poster+")</span><br />");
}
with no quotes (although I'm not sure without trying it). It's complicated, you have HTML with javascript that writes out HTML with a javascript call in it. But at some point it's just a string you're trying to send to the browser, and in this case I don't think you need any quotes or anything.
As for preview, you're right, it's not a database field. If you look in forumdisplay you'll see that it starts out as the pagetext field, because there's:
if ($vbulletin->options['threadpreview'] > 0)
{
$previewfield = "post.pagetext AS preview,";
which gets included in the query and puts the pagetext field (the entire text for the post) in the trhead array as preview. Then later the query results are retrieved one at a time as a $thread array, and the function "process_thread_array" is called to do more processing on it (that's in includes/functions_forumdisplay.php). So if you look at that you'll see how it further processes the preview.
Don't worry, you're obviously trying to figure stuff out yourself, and anyway I try to answer the questions I'm interested in and I don't care if someone *is* being a "leech". I've been a programmer for many years but until last Aug. I didn't know any php and I had never heard of vbulletin. So really I'm not that far ahead, but I guess I've had the luxury of a lot of time to look at it over the past months. But I guess I'll pretty much be starting all over with version 4.0.
vaskies
12-11-2009, 11:54 AM
I thought I would remedy the situation by modifying the plugin's code. I tried a zillion things, but only two of them are really worth mentioning. :p Here's the original snippet:
$forumdevel1 = $vbulletin->options['lastxforumid1'];
$forumnamedevel1 = $vbulletin->options['forumnamedevel1'];
$limitdevel1 = $vbulletin->options['lastxlimit1'];
if ($vbulletin->options['endislastx'])
if ($vbulletin->options['endislastx1'])
$lastxdevels1 = $db->query_read("
SELECT threadid, title, postusername, replycount, lastposter, lastpost, views, attach
FROM " . TABLE_PREFIX . "thread
WHERE forumid IN ($forumdevel1)
AND visible = 1
order by $ord DESC
LIMIT $limitdevel1
");
while ($lastxdevel1 = $db->fetch_array($lastxdevels1))
{
if(strlen($lastxdevel1['title']) > $vbulletin->options['lastxmax'])
{
$lastxdevel1['title'] = substr($lastxdevel1['title'], 0, $vbulletin->options['lastxmax']) . ' ...';
}
$agdate1 = vbdate($vbulletin->options['dateformat'], $lastxdevel1[lastpost], true);
$agtime1 = vbdate($vbulletin->options['timeformat'], $lastxdevel1[lastpost]);
$lastxdevelt1.="<div class='smallfont'><font size='2'><a onmouseover=\"Tip('<b>Title:</b> $lastxdevel1[title]<br/><b>User:</b> $lastxdevel1[lastposter]<br /><b>Last Post:</b>$agdate1<br/><b>Preview:</b>will go here... <br/>')\" onmouseout=\"UnTip()\" href='showthread.php?t=$lastxdevel1[threadid]'>$lastxdevel1[title]</a></font></div>";
}
And here's what I added:
$forumdevel1 = $vbulletin->options['lastxforumid1'];
$forumnamedevel1 = $vbulletin->options['forumnamedevel1'];
$limitdevel1 = $vbulletin->options['lastxlimit1'];
if ($vbulletin->options['endislastx'])
if ($vbulletin->options['endislastx1'])
$lastxdevels1 = $db->query_read("
SELECT threadid, title, postusername, replycount, lastposter, lastpost, views, attach
FROM " . TABLE_PREFIX . "thread
WHERE forumid IN ($forumdevel1)
AND visible = 1
order by $ord DESC
LIMIT $limitdevel1
");
$threadPreviewThings = $db->query_read("
SELECT pagetext
FROM " . TABLE_PREFIX . "post
WHERE threadid IN ($forumdevel1)
AND visible = 1
LIMIT $limitdevel1
");
$threadPreviewThing = $db->fetch_array($threadPreviewThings);
while ($lastxdevel1 = $db->fetch_array($lastxdevels1))
{
if(strlen($lastxdevel1['title']) > $vbulletin->options['lastxmax'])
{
$lastxdevel1['title'] = substr($lastxdevel1['title'], 0, $vbulletin->options['lastxmax']) . ' ...';
}
$agdate1 = vbdate($vbulletin->options['dateformat'], $lastxdevel1[lastpost], true);
$agtime1 = vbdate($vbulletin->options['timeformat'], $lastxdevel1[lastpost]);
$lastxdevelt1.="<div class='smallfont'><font size='2'><a onmouseover=\"Tip('<b>Title:</b> $lastxdevel1[title]<br/><b>User:</b> $lastxdevel1[lastposter]<br /><b>Last Post:</b>$agdate1<br/><b>Preview:</b>$threadPreviewThing[pagetext] <br/>')\" onmouseout=\"UnTip()\" href='showthread.php?t=$lastxdevel1[threadid]'>$lastxdevel1[title]</a></font></div>";
}
Which caused the mouseover to not show up at all (i.e. breaking it). I obviously am approaching this from the wrong angle. So I did a google search of how to read from two tables at once and many sites said it was impossible. But as you see in the code, that variable $lastxdlevels1 has to be assigned to a query_read. But the 4 values I need are in two different tables, yeah? This is problematic.
So I decided, why not try assigning what table I'm using into an array of two different values.
$dbTables = array(thread, post);
$forumdevel1 = $vbulletin->options['lastxforumid1'];
$forumnamedevel1 = $vbulletin->options['forumnamedevel1'];
$limitdevel1 = $vbulletin->options['lastxlimit1'];
if ($vbulletin->options['endislastx'])
if ($vbulletin->options['endislastx1'])
$lastxdevels1 = $db->query_read("
SELECT threadid, title, postusername, replycount, lastposter, lastpost, views, attach, pagetext
FROM " . TABLE_PREFIX . "{$dbTables}
WHERE forumid IN ($forumdevel1)
AND visible = 1
order by $ord DESC
LIMIT $limitdevel1
");
while ($lastxdevel1 = $db->fetch_array($lastxdevels1))
{
if(strlen($lastxdevel1['title']) > $vbulletin->options['lastxmax'])
{
$lastxdevel1['title'] = substr($lastxdevel1['title'], 0, $vbulletin->options['lastxmax']) . ' ...';
}
$agdate1 = vbdate($vbulletin->options['dateformat'], $lastxdevel1[lastpost], true);
$agtime1 = vbdate($vbulletin->options['timeformat'], $lastxdevel1[lastpost]);
$lastxdevelt1.="<div class='smallfont'><font size='2'><a onmouseover=\"Tip('<b>Title:</b> $lastxdevel1[title]<br/><b>User:</b> $lastxdevel1[lastposter]<br /><b>Last Post:</b>$agdate1<br/><b>Preview:</b>$lastxdevel1[pagetext] <br/>')\" onmouseout=\"UnTip()\" href='showthread.php?t=$lastxdevel1[threadid]'>$lastxdevel1[title]</a></font></div>";
}
Which turned out this error:
MySQL Error : Table 'vb3.array' doesn't exist
Error Number : 1146
Hindsight that was a stupid idea, since $dbTables simply outputs "Array". In summation, I tried splitting the code up into two separate query reads with no luck. And then I tried consolidating them via an array which probably never would have worked anyway, because even if I could display the values, they would not translate with the SQL syntax!
If I'm ever going to figure this out, one thing is for sure: I'm going to need to improve my knowledge on vbulletin's database structure as well as my understanding of SQL syntax. Which is exactly what I'm going to attempt today. I just learned I could view the database tables in phpMyAdmin which has been expontentially helpful...
And by the way, you were right! Taking out the single quotes worked. :( I still need the thread preview, though, so using the external data provider thing, as you said, wouldn't be the best approach.
I'm not a SQL expert, but look at the "JOIN" statement. While I guess you can't techinically read from two tables at a time, you can use JOIN and sort of think of it as a single virtual table with all the fields you need. You can find examples of that in a lot of places in the vbulletin code.
showthread.php has (as part of a larger query):
"LEFT JOIN " . TABLE_PREFIX . "post AS post ON (post.postid = thread.firstpostid)"
http://dev.mysql.com/doc/refman/5.4/en/join.html
vaskies
12-11-2009, 01:48 PM
Quick syntax question. 10 pages of google turned up nada.
if ($vbulletin->options['threadpreview'] > 0)
{
$previewfield = "post.pagetext AS preview,";
I understand this code except for one part: "AS preview,"
Here's my understanding:
If threadpreview is enabled in vbulletin's options,
statement: assigning $previewfield the value of field pagetest in the post table
What language is AS from? It's a PHP if statement so I assume php, but it wasn't covered at all in the tutorials so far. I need to know, because I'm going to need to recreate how vbulletin defined $threadinfo[preview] inside of the plugin.
Edit: It would also help me better understand your post better too. I also see an "ON" in there. :o
Google to the rescue :0 http://www.tizag.com/sqlTutorial/sqlas.php
Back to work...
I looked at that link, I didn't realize that was a way to use "AS". Anyway, you probably figured out already that it's there (I think) to avoid having to put TABLE_PREFIX in everywhere the table name is used.
Of course this is a reference and not a tutorial, but in case you missed the link I added above, you might find this useful: http://dev.mysql.com/doc/refman/5.4/en/sql-syntax.html
vaskies
12-12-2009, 01:47 PM
Good news! JOIN clause worked marvelously! Well, sort of. The first posts of each thread are properly linked to their thread, which was the hardest part.
$lastxdevels1 = $db->query_read("
SELECT thread.threadid, thread.title, thread.postusername, thread.replycount, thread.lastposter, thread.lastpost, thread.views, thread.attach, post.pagetext
FROM " . TABLE_PREFIX . "thread
LEFT JOIN post AS post ON(post.postid = thread.firstpostid)
WHERE forumid IN ($forumdevel1)
AND thread.visible = 1
order by thread.lastpost DESC
LIMIT $limitdevel1
");
Bad news, Javascript does not like thread titles or posts with apostrophes or quotes. If any are present, it breaks the javascript mouseover entirely (it simply doesn't show up). This is a huge problem because it's very common to have at least one apostrophe in a thread title, let alone an entire first post.
Taking a look back at the mouseover code itself:
$lastxdevelt1.="<div class='smallfont'><a onmouseover=\"Tip('<b>Title:</b> $lastxdevel1[title]<br/><b>User:</b> $lastxdevel1[lastposter]<br /><b>Last Post:</b>$agdate1<br/><b>Preview:</b>$lastxdevel1[pagetext] <br/>')\" onmouseout=\"UnTip()\" href='showthread.php?t=$lastxdevel1[threadid]'>$lastxdevel1[title]</a></div>";
I backslashed all the quotes for the code to work. But with something dynamic like $lastxdevel1[pagetext], I'm not sure how to remedy that.
So two things are left. I'm going to try and create a conditional statement that if lastxdevel1[thread.title] or lastxdevel1[pagetext] contain a certain string (quote or apostrophe), they get replaced with a . And second, I need to find a way to set up ellipses for the lastxdlevel[thread] and lastxdlevel[pagetext]. They way they are now, thread titles that are too long cause misalignment, and if the first post of a thread is long, the mouseover preview takes up the whole page. :p Made some huge progress today thanks to you!
If you look at functions_forumdisplay.php where the preview is processed:
// format thread preview if there is one
if ($ignore["$thread[postuserid]"])
{
$thread['preview'] = '';
}
else if (isset($thread['preview']) AND $vbulletin->options['threadpreview'] > 0)
{
$thread['preview'] = strip_quotes($thread['preview']);
$thread['preview'] = htmlspecialchars_uni(fetch_censored_text(fetch_tri mmed_title(
strip_bbcode($thread['preview'], false, true),
$vbulletin->options['threadpreview']
)));
}
Some of that may be useful, looks like it handles quotes and other special characters, possible BBCode, and trimming it down to length.
vaskies
12-12-2009, 04:38 PM
strip_quotes();
htmlspecialchars_uni();
fetch_censored_text();
strip_bbcode();
Those are all vbulletin functions, yeah? For simple testing, I tried using just the strip_quotes function on its own:
$lastxdevel1[pagetext] = strip_quotes($lastxdevel1[pagetext]);
That line of code has no effect on how the javascript mouseover handles $lastxdevel1[pagetext]. As if the function weren't doing anything at all. To test this, I'm using a thread that has all normal characters in the title, but a single quote at the beginning of the post.
Does strip_quotes(); need to be redefined from within the plugin?
Well to be honest I don't know the details of what any of those functions do, just thought since (I believe) it's doing something like what you're trying, maybe something would be useful.
As it turns out, it looks like "strip_quotes" (which is in functions.php) strips [quote] tags out of the text. So I guess it had nothing to do with your quote problem, sorry about that.
Maybe you can use the php str_replace function to replace ' with \' (put a backslash in front of it)? I'm afraid I'm not much help at this point - maybe worse than none if I lead you astray. :)
vaskies
12-15-2009, 01:01 PM
-Phew- First of all, thanks for pointing me to functions.php. It's really helping me to begin understanding how vbulletin works.
After a lot of learning (particularly noteworthy is the php str_replace) as well as furthering my understanding of vbulletin's functions, I've managed to create a working concept. Any character I throw at it it replaces with a javascript-friendly version.
I set up a live example here (http://htreplays.com/vb3).
You'll see though in the example that the thread on the right doesn't show the tooltip. This is because the post preview (pagetext) has a line break in it. To remedy this problem, I did the following:
$placeholders = array("'", "<br />");
$fixup = array("\'", " ");
$saPreview2 = str_replace($placeholders, $fixup, $lastxdevel2['pagetext']);
What's odd is, if you view the source you will indeed see that the <br /> has been properly replaced with a space. Yet there is still a line break, and more importantly, the tooltip still does not work.
So my question is, why would a line break in pagetext cause the tooltip to cease functioning? Is there something about how vbulletin handles line breaks in pagetext that I'm unaware of? Or is this a javascript syntax conflict? I know that javascript ignores whitespace so I'm leaning towards the possibility this is more a vbulletin issue than a javascript one...
Hmm...I think what you have is an actual newline character in the string which I don't think is allowed in a javascript string constant. Maybe try replacing "\n" with "\\n" (which will hopefully put "\n" in the javascript string instead of the actual newline).
vaskies
12-15-2009, 01:57 PM
:D Aweeesome. I was not aware of this newline character. Interesting.
Well, it took over a week but we did it! Thanks so much for your time and help. You have no idea. :)
Thankfully the rest of the site's development will involve mostly CSS and HTML, which I'm much more adept at. After I get a solid handling of PHP functions and loops though, I plan to learn javascript as well as other programming languages. My feeling is, once I get a firm grasp of one, the rest will be much easier to learn as I've become accustomed to typical programming language syntax.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.