![]() |
RESOLVED: Vbulletin Variable / Array names in Javascript?
*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 and the how to display active threads on forum home Code:
<script type="text/javascript" src="/js/tooltips/wz_tooltip.js"></script> |
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.
|
Viewing source with ('Some Text') as the mouseover:
Code:
<!-- Code:
<!-- :confused: |
I think that could only happen if $gnpdate had no value.
|
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?
|
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. |
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)?
|
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 Code:
if ($vbulletin->GPC['type'] == 'JS') 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. |
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) Code:
for (var x in threads) 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. Quick and to the point: Here's the plugins php main code: (I bolded what looks relevant) Code:
global $db, $vbulletin; 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: Code:
Invalid SQL: 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 :
Code:
for (var x in threads) 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: Code:
if ($vbulletin->options['threadpreview'] > 0) 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. |
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:
Code:
$forumdevel1 = $vbulletin->options['lastxforumid1']; Code:
$forumdevel1 = $vbulletin->options['lastxforumid1']; 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. Code:
$dbTables = array(thread, post); 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): Code:
"LEFT JOIN " . TABLE_PREFIX . "post AS post ON (post.postid = thread.firstpostid)" http://dev.mysql.com/doc/refman/5.4/en/join.html |
[S]Quick syntax question. 10 pages of google turned up nada.
Code:
if ($vbulletin->options['threadpreview'] > 0) Here's my understanding: Code:
If threadpreview is enabled in vbulletin's options, Edit: It would also help me better understand your post better too. I also see an "ON" in there. :o[/S] 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 |
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.
Code:
$lastxdevels1 = $db->query_read(" Taking a look back at the mouseover code itself: Code:
$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>"; 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:
PHP Code:
Some of that may be useful, looks like it handles quotes and other special characters, possible BBCode, and trimming it down to length. |
PHP Code:
PHP Code:
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. :) |
-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. 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: PHP Code:
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).
|
: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. |
All times are GMT. The time now is 03:28 AM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|