vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Order of info possible? (https://vborg.vbsupport.ru/showthread.php?t=276793)

Boofo 01-11-2012 11:25 AM

Order of info possible?
 
Is there a way to set the order in a setting for info added to an option like the following?

PHP Code:

$vbulletin->options['boofo_sucks'] .= Some info here;
$vbulletin->options['boofo_sucks'] .= Slam Boofo here;
$vbulletin->options['boofo_sucks'] .= Hit him again;
$vbulletin->options['boofo_sucks'] .= Bounce him off the floor;
$vbulletin->options['boofo_sucks'] .= Push him out the door


Now, if I want to change the order that those things get added to the option, is there a way to do that in PHP? I know switch will allow me to choose one of them but I want to be able to set the order somehow.

Disasterpiece 01-11-2012 12:12 PM

Which order? You're concatenating strings... if you want to change the order, well, change the order of the lines.

Boofo 01-11-2012 12:31 PM

I understand that. I was just wanting to know i it was possible to do it automatically with setting.

Disasterpiece 01-11-2012 12:35 PM

Can you elaborate a bit more detailed? I'm not quite sure I get what you want to accomplish.

Maybe use arrays instead of appends?

PHP Code:

$vbulletin->options['boofo_sucks'][] = Some info here;
$vbulletin->options['boofo_sucks'][] = Slam Boofo here;
$vbulletin->options['boofo_sucks'][] = Hit him again;
$vbulletin->options['boofo_sucks'][] = Bounce him off the floor;
$vbulletin->options['boofo_sucks'][] = Push him out the door

This way you could 'switch' 2 array fields:

PHP Code:

$tmp $vbulletin->options['boofo_sucks'][1];
$vbulletin->options['boofo_sucks'][1] = $vbulletin->options['boofo_sucks'][3];
$vbulletin->options['boofo_sucks'][3] = $tmp

And afterward append them all together:
PHP Code:

echo implode($vbulletin->options['boofo_sucks']); 


Boofo 01-11-2012 12:51 PM

Thank you for responding to this. ;)

What I want to be able to do is set it so that they can be listed/added in any order the user wants. Like 1,2,3,4,5, or 4,1,3,2,5 and so on. This is going in the footer and there are only 2 hooks there that are of no use for something like this, so this is the way I have to do it for now. Since the copyright text is anchored right below the "time is now", that is a good area to be able to add things to. Does that make any sense? I'm not very good at explaining things at times.

Disasterpiece 01-11-2012 02:30 PM

ok now I get it.

Sadly, no there is absolutely no way to accomplish this. It's not the best method to start with, but the vb template system has always been a bit clunky imho.

If you want to make sure a certain text appears at a certain position, use extra templatehooks or guide the user how he/she can change the order by themselves.

The only thing you can force is the to be inserted text appear at the beginning or the end.

PHP Code:

$sometext .= 'this comes at the end';
$sometext 'this comes before' $sometext

obviously.

//e:

Another method would be, if you know there is already text in the template var inserted and you want to put your text at a certain position, you can split the string, place yours and convert it to a string again:

PHP Code:

$lines explode("\n"$text);
$newlines = array();
$insert_at 4;
$new_line 'my new line';
for (
$i=0$i count($lines); $i++) {
    if (
$i == $insert_at) {
        
$newlines[$i] = $new_line;
        
$i++;
    } else {
        
$newlines[$i] = $lines[$i];
    }
}
$text implode($newlines); 


Boofo 01-11-2012 02:37 PM

Yes, I agree. There isn't much you can do with it the way it is. I don't like doing it this way but there really is no other choice if I want to make it as automatic as possible. They will just have to live with the order I put them in unless they want to edit the plugin, I guess. Since this was mainly for my own site, I set it up to how I use it.

Thanks for verifying what I suspected, though. ;)

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

Quote:

Originally Posted by Disasterpiece (Post 2286539)
//e:

Another method would be, if you know there is already text in the template var inserted and you want to put your text at a certain position, you can split the string, place yours and convert it to a string again:

PHP Code:

$lines explode("\n"$text);
$newlines = array();
$insert_at 4;
$new_line 'my new line';
for (
$i=0$i count($lines); $i++) {
    if (
$i == $insert_at) {
        
$newlines[$i] = $new_line;
        
$i++;
    } else {
        
$newlines[$i] = $lines[$i];
    }
}
$text implode($newlines); 


But to add this to a mod for users to use wouldn't really work, would it? Since I'm adding the text to the line, I can add it in any order I want to when making the mod. But for the end user to do it, they will have to edit the plugin manually. But you mentioned earlier about adding some hooks to the template. How hard would that be to do? I've never added hooks for a mod before. Or, being it is the footer template, maybe it would be more hassle than it is worth?

nhawk 01-11-2012 06:01 PM

Assuming you have each item stored in a table, why not add an 'order_by' column to the table and give the user the option to number them in the order they want?

Then query the table with order by order_by and display.

Disasterpiece 01-11-2012 06:25 PM

After all it's better to let the user modify the template on their own, not with template hooks but with html, just as they want it to look like.

Boofo 01-11-2012 08:45 PM

Quote:

Originally Posted by nhawk (Post 2286628)
Assuming you have each item stored in a table, why not add an 'order_by' column to the table and give the user the option to number them in the order they want?

Then query the table with order by order_by and display.

Their not stored in a table. I thought of doing it that way but really didn't want to be adding a query to every page load.

Quote:

Originally Posted by Disasterpiece (Post 2286636)
After all it's better to let the user modify the template on their own, not with template hooks but with html, just as they want it to look like.

I suppose I could throw it all in a template and then just hook into the copyrighttext one time instead of adding to it for each item. Thanks for the advice, sir. ;)


All times are GMT. The time now is 09:34 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
  • Page Generation 0.03657 seconds
  • Memory Usage 1,774KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (7)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete