The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
How to register new plugin/variable?
I'm wanting to make a change in the template -- specifically the page title shown in the <title></title> tags.
$thread[title] is part of the title. What I'm attempting to do is capitalize each word using ucwords(), but adding PHP into the <title> doesn't work. I thought adding a quick plugin would solve this, and I could instead call up the alternate variable ($captitle) in the <title>. Before adding ucwords(), I thought I'd try a simple swap, using a new plugin with this code: Code:
$captitle = $thread['title']; I tried it on both the global_start and showthread_start -- no effect. I asked this question in an existing (unanswered) thread at vBulletin.com, but this was the response: Quote:
Quote:
So ... what am I missing here? :erm: |
#2
|
|||
|
|||
The response about registering was meant for vb version 4. The fetch_template() code isn't something you need in this case. My guess is that the place where you set $captitle is inside a function so it's not a global, and not in scope when the template is rendered. Which template are you trying to change, and which hook location did you use for your plugin?
If my guess is right, you could try this: Code:
global $captitle; $captitle = $thread['title']; Edit: another thing that should work (although it's cheating, a bit): Code:
$thread['captitle'] = ucwords($thread['title']); |
#3
|
||||
|
||||
Thanks for replying.
To start with, it would probably be fine to just alter the <title> in the <head> of SHOWTHREAD. There's a few things in your post that I don't quite understand... Quote:
I was going to Add New Plugin, and creating a new plugin named "Capitalize Thread HTML Titles", adding it to showthread_start (or global_start if needed?), and making the body of the plugin .... ... and that's where I'm apparently stumped. This doesn't seem to work: Code:
$thread['captitle'] = ucwords($thread['title']); There's not really a comprehensible (with examples) how-to manual on this, and vB3 has become so buried under vB4 that even advanced Google searching of vB.org or vB.com doesn't help find anything. I learn by example -- need to see code in action. |
#4
|
|||
|
|||
Sorry, I see now that you did say in your first post which hooks you tried. Those aren't inside functions so my guess was wrong. It seems to me like the code you posted above should have worked. I'll try it myself.
Edit: wait - I think maybe the problem with that code is that $thread['title'] hasn't been set yet at that hook location. Try showthread_complete instead. Quote:
I should have also mentioned that you'd then use $thread['captitle'] in the template. Edit: ...but as I added above, I think your original code works if you change to showthread_complete. Quote:
I understand the frustration. I believe that, unfortunately, the only way to really figure this stuff out is to read the vb code. |
#5
|
||||
|
||||
Ah-ha, now that works (showthread_complete, using $thread[captitle] in SHOWTHREAD, and the aforementioned plugin).
But there's still one more step I'd like to take now, if possible... I use this plugin for new posts, to run ucwords() on all but specific stop words in an array: Code:
$smallwords = array( 'of','a','the','and','an','or', 'nor','but','is','if','then','else','when', 'at','from', 'by','on','for','in','to','into','with' ); $words = explode(' ', $vbulletin->GPC['subject']); foreach ($words as $key => $word) { if (!$key or !in_array($word, $smallwords)) $words[$key] = ucwords(strtolower($word)); } It works great and all, but it does nothing for old posts. Right now, I have text-transform:capitalize; CSS in some of the templates, to "fix" terrible capitalization by members. But it caps everything, including stop words (a, and, the, or, etc). It also did nothing for the HTML page titles, hence the need for this plugin. I want to adjust the plugin now so that it doesn't capitalize stop words like the CSS does. The new post plugin above does what it should, but I'm thinking there's a way to copy some of that functionality (with new variables, of course) and merge it with $thread[captitle] But I'm not entirely clear on what should be removed/replaced. Any ideas? Again, I really appreciate your replies thus far. |
#6
|
|||
|
|||
So you want to perform your capitalization function on the post text? In that case you could use the postbit_display_complete hook and work on $post['message']. You could set a new variable then edit the appropriate templates and change where it's using $post[message] (postbit or postbit_legacy), or you could just change $post[message].
Edit: oh, I realized after posting that that you probably want to do it to the post titles and not the entire post text? In that case I believe it's $post[title] you want to change. |
#7
|
||||
|
||||
Just the thread titles -- and right now just the thread titles within the <title> HTML code in the <head> of the SHOWTHREAD template. I don't want to complicate anything.
The code you helped me figure out was to use ucwords() to force all words to be capitalized. What I'd like to do now is make it act more like the plugin that is used for new posts -- the ability to exclude using ucwords() on stop words (a, an, the, or, and, etc). I may have confused you by discussing the CSS. I was just giving an example of "bad capitalization" in addition to using pure ucwords(). The best capitalization is content-aware, and excludes stop words. |
#8
|
|||
|
|||
Oh I see. OK, then I think you just want this:
Code:
$smallwords = array( 'of','a','the','and','an','or', 'nor','but','is','if','then','else','when', 'at','from', 'by','on','for','in','to','into','with' ); $words = explode(' ', $thread['title']); foreach ($words as $key => $word) { if (!$key or !in_array($word, $smallwords)) $words[$key] = ucwords(strtolower($word)); } and I don't know what follows, I guess an implode? |
#9
|
||||
|
||||
Yes, I seem to have left the last line off my last post.
Code:
$vbulletin->GPC['subject'] = implode(' ' , $words); Code:
$smallwords = array( 'of','a','the','and','an','am','or','is','if','at','by','on','in','to' ); $words = explode(' ', $thread['title']); foreach ($words as $key => $word) { if (!$key or !in_array($word, $smallwords)) $words[$key] = ucwords(strtolower($word)); } $thread['title'] = implode(' ' , $words); $thread['captitle'] = $thread['title']; It would be awesome if I could dump the text-transform:capitalize; CSS in use now in specific places -- for example, on the forum display -- so that the list of threads in a forum also obeyed the above ucwords()+exclusions plugin. While the plugin we just finished could be expanded to globals (right?), it may be better to just add another plugin that only works on the page with threads listed out. I was mostly worried about two locations: 1. The HTML page title -- which is now fixed. (Yay!) - DONE! 2. The title as it appears in the listing of threads. I'll probably leave the CSS in everywhere else (related threads, the breadcrumbs, etc), as it's not as important. Again, your help is most appreciated. While I can read, experiment, etc -- sometimes it's good to get outside advice. I don't write PHP (or vB-specific PHP) daily, so it can be hazy when trying something new. --- In case it's not obvious, these are my questions: 1. What would the syntax be to create a similar plugin that works on the thread list when viewing a subforum? 2. What hook location should it use? -- I'm thinking threadbit_display ? 3. Do you remember offhand which template needs editing? I think it's threadbit, and specifically the $thread[title_editable] variable about 20% into the template. |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|