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

Reply
 
Thread Tools Display Modes
  #1  
Old 02-06-2013, 02:53 AM
LifesGreatestGift's Avatar
LifesGreatestGift LifesGreatestGift is offline
 
Join Date: Jul 2009
Location: Louisville, KY USA
Posts: 885
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default find replace issue

Any idea why this isn't working?

Using parse_templates (also tried forumdisplay_complete)

Code:
$find = 'Post New Thread'; 
$replace = 'Create a Listing';  

$vbulletin->templatecache['FORUMDISPLAY'] = str_replace($find, $replace, $vbulletin->templatecache['FORUMDISPLAY']);
Reply With Quote
  #2  
Old 02-06-2013, 02:55 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Normally the text is in a phrase, so maybe what you want is to enter a translation for the phrase instead of doing a str_replace on the template?

ETA: Or if you had some reason for wanting to do a str_replace instead, then you'd have to do it after the template was rendered instead of doing it on the template cache.
Reply With Quote
  #3  
Old 02-06-2013, 02:59 AM
LifesGreatestGift's Avatar
LifesGreatestGift LifesGreatestGift is offline
 
Join Date: Jul 2009
Location: Louisville, KY USA
Posts: 885
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I just need it changed in certain forums (have code with forum id array).

I tried forumdisplay_complete and it did nothing as well... :\

--------------- Added [DATE]1360123229[/DATE] at [TIME]1360123229[/TIME] ---------------

so would i use

Code:
$vbulletin->template['FORUMDISPLAY']
?

--------------- Added [DATE]1360123422[/DATE] at [TIME]1360123422[/TIME] ---------------

or do i need to figure out how to use the template parser?
Reply With Quote
  #4  
Old 02-06-2013, 03:09 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yeah, the problem is that it calls print_output with the result of the render call, so there's no place to do the replace. Well, there might be but I think I have what might be a better idea: create a new phrase (Phrase Type "Forum Display") for "Create a Listing", then do the str_replace on the cache using the phrase varnames, like:

Code:
$find = 'post_new_thread'; 
$replace = 'create_a_listing';  

$vbulletin->templatecache['FORUMDISPLAY'] = str_replace($find, $replace, $vbulletin->templatecache['FORUMDISPLAY']);


Edit: There's also a global_complete hook location where the output is in $output, so another way would be to try doing your str_replace that way, like:

Code:
$find = 'Post New Thread'; 
$replace = 'Create a Listing';  

$output = str_replace($find, $replace, $output);

... but I guess then you'd have to somehow make sure that it was being done only on the FORUMDISPLAY page. Hmm...maybe it won't work after all.
Reply With Quote
  #5  
Old 02-06-2013, 03:19 AM
LifesGreatestGift's Avatar
LifesGreatestGift LifesGreatestGift is offline
 
Join Date: Jul 2009
Location: Louisville, KY USA
Posts: 885
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

awesome that worked

now i need to wrap it with if(THIS_SCRIPT for FORUMDISPLAY so its not running on every page
Reply With Quote
  #6  
Old 02-06-2013, 12:25 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by LifesGreatestGift View Post
awesome that worked

now i need to wrap it with if(THIS_SCRIPT for FORUMDISPLAY so its not running on every page
Oh right, that does work for forumdisplay. I was thinking that some scripts have more than one function so they output more than one possible page.
Reply With Quote
  #7  
Old 02-06-2013, 12:39 PM
nhawk nhawk is offline
 
Join Date: Jan 2011
Posts: 1,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think you're complicating things by using str_replace.

If all you're doing is replacing the 'Post New Thread' text for the buttons, this is easier...

Use the forumdisplay_complete hook...
Code:
if ($foruminfo['forumid'] == Your_ForumID)
{
	$vbphrase['post_new_thread'] = 'Create Listing';
}
Reply With Quote
2 благодарности(ей) от:
kh99, Lynne
  #8  
Old 02-06-2013, 08:51 PM
LifesGreatestGift's Avatar
LifesGreatestGift LifesGreatestGift is offline
 
Join Date: Jul 2009
Location: Louisville, KY USA
Posts: 885
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Here is my completed plugin. Please let me know if it can be 'condensed'.

here is the scenario, i have 51 'top level' forums that will always be, and never change or have any forums added to. But of those 51 forums, I may add/remove multiple sub-forums and don't want to keep adding COUNTLESS id's to the plugin. (there are hundreds of subforums).

Code:
if (is_member_of($vbulletin->userinfo, 6)) {
/* These are the main top-category forums aka states */
$main_forums = array(18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68);

/*get all ids of all sub-forums aka cities of top-level states */
foreach ($main_forums AS $state => $forumid) {
  $s[] = $vbulletin->db->query_first('SELECT `childlist` FROM ' . TABLE_PREFIX . 'forum WHERE `forumid` IN (' . $forumid . ')'); 
}

/* convert multi-arrays into single string */
$imploded = array();
foreach($s as $ss) {
	$imploded[] = implode('~', $ss);
}
$sub_forums = implode(",", $imploded);

/* remove the stupid '-1,' and ',-1' id's */
$sub_forums = str_replace("-1,", "", $sub_forums);
$sub_forums = str_replace(",-1", "", $sub_forums);

/* convert back to array :) */
$main_all_array = explode( ',', $sub_forums );

#print_r($main_all_array);

GLOBAL $foruminfo;

if (THIS_SCRIPT == "forumdisplay") {
  if (in_array($foruminfo['forumid'], $main_all_array)) {
    $find = 'Post New Thread'; 
    $replace = 'Create a Listing';  
    $output = str_replace($find, $replace, $output);
  }
}

} #END ADMIN GROUP
i have is wrapped in "admin" so guests don't see it while im testing

--------------- Added [DATE]1360187715[/DATE] at [TIME]1360187715[/TIME] ---------------

i may be overcomplicating it a bit, but i am not a professional with php. as is, it works.
Reply With Quote
  #9  
Old 02-07-2013, 11:18 AM
nhawk nhawk is offline
 
Join Date: Jan 2011
Posts: 1,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

While it may work, again you've over complicated what you want to do by adding 51 unneeded additional database queries each time forumdisplay is accessed.

Using the forumdisplay_complete hook...

Code:
if ($foruminfo['parentid'] >= 18 AND $foruminfo['parentid'] <= 68)
{
	$vbphrase['post_new_thread'] = 'Create a Listing';
}

The only thing that might complicate things is if your sub-forums have sub-forums. Then that's a different story.
Reply With Quote
Благодарность от:
Lynne
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 03:05 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06995 seconds
  • Memory Usage 2,256KB
  • Queries Executed 13 (?)
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
  • (7)bbcode_code
  • (1)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
  • (3)post_thanks_box_bit
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit
  • (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_postinfo_query
  • fetch_postinfo
  • 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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete