PDA

View Full Version : Order of info possible?


Boofo
01-11-2012, 11:25 AM
Is there a way to set the order in a setting for info added to an option like the following?

$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?

$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:

$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:
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.

$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:

$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 1326297407 at 1326297407 ---------------

//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:

$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
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.

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. ;)