Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 04-13-2012, 12:27 AM
kpmedia's Avatar
kpmedia kpmedia is offline
 
Join Date: Jan 2008
Posts: 136
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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'];
The title ends up removed.
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:
If you want to use $captitle in the template, then you will need to first register the variable for use in the template. The best place to be asking for help with this is over on vbulletin.org, the modification site.
I read this post: https://vborg.vbsupport.ru/showthrea...74#post1524774
Quote:
Originally Posted by Opserty View Post
Create a Plugin (AdminCP > Plugins & Products > Add New Plugin) with the PHP code:
PHP Code:
 eval('$customvar = "'fetch_template('customtemplate') .'";'); 
Choose an appropriate hook location like global_start or something.
Then use $customvar where you want.
But not sure I understand what goes where.

So ... what am I missing here? :erm:
Reply With Quote
  #2  
Old 04-13-2012, 12:36 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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']);
Reply With Quote
  #3  
Old 04-13-2012, 12:51 AM
kpmedia's Avatar
kpmedia kpmedia is offline
 
Join Date: Jan 2008
Posts: 136
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:
the place where you set $captitle is inside a function so it's not a global
Where now?

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']);
I added that as the plugin syntax, and then inserted $captitle into the <title> on SHOWTHREAD.

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.
Reply With Quote
  #4  
Old 04-13-2012, 12:56 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kpmedia View Post
Where now?
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:
This doesn't seem to work:
Code:
$thread['captitle'] = ucwords($thread['title']);
I added that as the plugin syntax, and then inserted $captitle into the <title> on SHOWTHREAD.

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:
Originally Posted by kpmedia View Post
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.

I understand the frustration. I believe that, unfortunately, the only way to really figure this stuff out is to read the vb code.
Reply With Quote
  #5  
Old 04-13-2012, 01:26 AM
kpmedia's Avatar
kpmedia kpmedia is offline
 
Join Date: Jan 2008
Posts: 136
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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));
 }
at newthread_post_start

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.
Reply With Quote
  #6  
Old 04-13-2012, 01:44 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #7  
Old 04-13-2012, 02:07 AM
kpmedia's Avatar
kpmedia kpmedia is offline
 
Join Date: Jan 2008
Posts: 136
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #8  
Old 04-13-2012, 03:04 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #9  
Old 04-13-2012, 03:46 AM
kpmedia's Avatar
kpmedia kpmedia is offline
 
Join Date: Jan 2008
Posts: 136
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes, I seem to have left the last line off my last post.
Code:
$vbulletin->GPC['subject'] = implode(' ' , $words);
This works perfectly:
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'];
Now one last request.

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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:10 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04455 seconds
  • Memory Usage 2,263KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (9)bbcode_code
  • (1)bbcode_php
  • (6)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete