IPB

ISO Image Creator

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Template System...., Any ideas?
Mackins
post Dec 28 2005, 01:03 PM
Post #1


Themer
Group Icon

Group: Members
Posts: 120
Joined: 17-March 05
From: England
Member No.: 29,841
 United Kingdom


Ok, as I've been trying to rewrite my entire system using OOP. I need a more complex layout and template system because at the moment I've just put html within my php code.

If I were to have templates, would I use preg and str replace or just build up variables (eg. $output .= 'Hello')? This is difficult...

Come on Brandon, you work for IPS, you give me some ideas biggrin.gif

It needs to be a bit more complex than normal, and I want a challenge happy.gif. I know IPB has a very complex sort of thing, and something like that, but maybe a little easier tongue.gif

Just give me ideas and I'll try my best. w00t.gif

Thanks all wink.gif

-Mackins cool.gif
Go to the top of the page
 
+Quote Post
mflintjer
post Dec 31 2005, 02:59 AM
Post #2


Back; Down you Hooligans! :P
Group Icon

Group: Members
Posts: 1,012
Joined: 2-November 04
From: Rochester, MN
Member No.: 23,596
 United States


you could try using SDK MOD over at invisionize to possibly make something wink.gif
Go to the top of the page
 
+Quote Post
bfarber
post Dec 31 2005, 08:29 AM
Post #3


Administrator
Group Icon

Group: Admin
Posts: 10,302
Joined: 9-February 03
From: Jacksonville, FL
Member No.: 1
 United States


The way IPB does it, is all skin bits are stored in the skin files as functions. When I need to display something, I call that function (passing it variables if I need to, and the function returns the html I need).

This is all passed to a function in the output/display class which just appends the html to it's existing html.

Finally the html is output. smile.gif
Go to the top of the page
 
+Quote Post
Mackins
post Dec 31 2005, 10:09 AM
Post #4


Themer
Group Icon

Group: Members
Posts: 120
Joined: 17-March 05
From: England
Member No.: 29,841
 United Kingdom


So, do you think I should have a go with making that or will I get screwed over with copyright? hmm.gif

Anyway, I've started it but I'm not too sure on how to actually output it as I've put it all into variables. How about this:
CODE
<?php

// This function makes a new class in the 'templates' variable in the class
// The line will create $skin->templates['global'];
$skin->load_template('global');

// I was thinking about making this: btw $func is my main misc function class
$func->output($skin->templates['global']->template_bit();

// Or should I put it all in a variable:
$func->output .= $skin->templates['global']->template_bit();

?>

But then, when shall I output the output variable? at the end of the index page?
And another thing is that I'm not too sure on how to get the page title to change, but I figure the only way to do it is to load up the page into a variable before you ouput anything, which means the pages that have been loaded have the opportunity to change the title if they want.
A little help would be fine, cheers biggrin.gif
-Mackins

This post has been edited by Mackins: Dec 31 2005, 09:13 PM
Go to the top of the page
 
+Quote Post
Mackins
post Jan 6 2006, 04:58 PM
Post #5


Themer
Group Icon

Group: Members
Posts: 120
Joined: 17-March 05
From: England
Member No.: 29,841
 United Kingdom


I've finished the system biggrin.gif and things are really beginning to take shape (well, a better one than before). Now all I need to do is find out how that I can let the admin edit them. Any ideas?

The structure of each template is basically just like IPBs.
CODE
<?php
class template_name {

var $mackins; // the class that contains everthing  :)

function template_bit_name(data_needed) {
return <<<E0F // is it zero or o ??
template_html
E0F;
}

}
?>
Is there a way to select the function and rewrite over it? Or will I have to save the old version to a variable and then str_replace it?

I need to know how to stop sessions being created by web bots such as google. smile.gif Or just add them as a session like in ipb.

One more thing. What does the @ do when put before a function eg. @mysql_db_select(db);

-Mackins

This post has been edited by Mackins: Jan 6 2006, 05:25 PM
Go to the top of the page
 
+Quote Post
bfarber
post Jan 7 2006, 07:21 AM
Post #6


Administrator
Group Icon

Group: Admin
Posts: 10,302
Joined: 9-February 03
From: Jacksonville, FL
Member No.: 1
 United States


Sorry it took so long to reply, but here are the answers to your questions. smile.gif

You should output everything after all script execution is done. Not during shutdown (if you are using register_shutdown_func for anything) of course, but after everything else in your script is done.

Best bet I've found is to do this at the end of each of your source files like IPB. This allows you to process anything you need to process in your source files and then output it, or not output anything in the case of a redirection. You could put the output call in your index file if you wanted though, as it would essentially work the same.

QUOTE
is it zero or o ??
Great thing is, it doesn't matter. As long as the name you set with
<<<NAME

is the same one you use with the

NAME;

call, it's fine. You can put anything you want, those two lines just have to match. The traditional usage though, is the letter o (stands for End of Function).

QUOTE
Is there a way to select the function and rewrite over it? Or will I have to save the old version to a variable and then str_replace it?


I'm not entirely sure what you mean, but if you mean pull content from one function, then overwrite that content rather than append it, what you should do is when this *could* happen, save the content of your output to a different variable temporarily, and then when you have decided you don't need to overwrite it, THEN assign it to your main output variable. Like this

$temp_output = $skin->templates['global']->whatever_func();

//you've decided to overwrite it here

$temp_output = $skin->templates['global']->diff_func();

// No more need to overwrite it

$func->output .= $temp_output;

QUOTE
I need to know how to stop sessions being created by web bots such as google.
You need to sniff for them to do this (for either solution). You have to match the user-agent against the ones bots use, and there are litterally like millions. Of course you could just limit this to the commone ones (like google, msn, slurp, yahoo, etc.).

QUOTE
What does the @ do when put before a function eg. @mysql_db_select(db);


All the @ symbol does is repress warnings. It doesn't repress fatal errors or anything like that, but it will stop a warning from displaying on the screen. smile.gif
Go to the top of the page
 
+Quote Post
Mackins
post Jan 7 2006, 10:42 AM
Post #7


Themer
Group Icon

Group: Members
Posts: 120
Joined: 17-March 05
From: England
Member No.: 29,841
 United Kingdom


QUOTE
I'm not entirely sure what you mean
You're right, I didn't word it too well. hmm.gif

Say the admin wanted to change the layout of a certain skin, which means the template file would have to be edited. The editing of it would be pretty easy as you would just use a textarea but then how would you rewrite the template file with the data of the edited function (plus everything else in the file)?
CODE
<?php
$data_to_replace = $skin->template['global']->global_header();
$safe_data = $mackins->safe_string($data_to_replace); // convert ascii thingies
// just skip form data to textarea because i can't be bothered to write the rest at the mo
$mackins->output = <<<EOF
<textarea cols="70" rows="25" name="data">$safe_data</textarea>
EOF;
?>

After that, I'm not too sure what to do. I know how to write to files and everything, but how would I replace that data? str_replace(), should work with the $data_to_replace, but there must be a more advanced way of doing it.

And as an initial installation of the system I'm thinking about using xml to hold data so I can parse it and insert it into the database so I can have master skin sets, like ipb does. So I'll be researching on xml for the next year sad.gif sad.gif

One more thing. The same question about the @ (thanks by the way) but this time with an & after = and before variables. Thanks big B. lol w00t.gif

-Mackins sad.gif

This post has been edited by Mackins: Jan 8 2006, 02:51 PM
Go to the top of the page
 
+Quote Post
bfarber
post Jan 10 2006, 07:30 AM
Post #8


Administrator
Group Icon

Group: Admin
Posts: 10,302
Joined: 9-February 03
From: Jacksonville, FL
Member No.: 1
 United States


Writing the template files you wouldn't want to do str_replace. What you'd do is store the new data in the db (since it sounds like you are using that method) and then pull all the functions for one skin file and write them to the flat file at once.

You wouldn't really be replacing a function in the skin file, but rather just generating a new file with the most up to date content.

XML with PHP is trickier than I thought originally, but once you get the hang of it it's not too bad. smile.gif

The & symbol forces a reference of a variable, array, or object rather than copying it.

If you do

$test = $somevar;

then $somevar is copied over to test. This means changes to either one do not affect the other. If you do this instead

$test =& $somevar;
(or $test = &$somevar; - the & can be against the = sign or the variable or have a space between either)

then you are making $test a reference of $somevar. This uses less memory, however if you edit $test, it edits $somevar as well. This can be desirable at times. You want to use references when possible because it uses a LOT less memory to make a reference to something than to actually copy it over to a new variable. This is especially true for objects.
Go to the top of the page
 
+Quote Post
Mackins
post Jan 10 2006, 03:00 PM
Post #9


Themer
Group Icon

Group: Members
Posts: 120
Joined: 17-March 05
From: England
Member No.: 29,841
 United Kingdom


Haha, I just had an idea biggrin.gif Now that I've merged my $func $skin and $info objects into one, and have converted everything using OOP, i can use this:
CODE
<?php
// my new $mackins class loaded here- everything merged (easier for me to get at)
// another class loaded into $run (as in $run = new mr_class)
$run->mackins =& $mackins;
?>
Would that work for the class? As there is a variable inside the class being loaded into $run:
CODE
var $mackins

Will it be loaded into it and everything work OK?

Good idea about pulling stuff from the database. Appreciate it smile.gif .
But its the tricky bit of getting xml to work first.
Any tips on writing my XML class will be greatly appreciated. I know the basics now and stuff about character data, I just need to know what kind of array my xml class should create.

Oooooooooooh, I hate difficult stuff sad.gif

-Mackins wacko.gif

This post has been edited by Mackins: Jan 10 2006, 03:01 PM
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 24th May 2012 - 04:29 AM

  Page top

Webber Enhanced skin created by Im4eversmart of RuneHQ.

  Privacy Policy 1 2 3 4 5

IPS Driver Error

IPS Driver Error

There appears to be an error with the database.
You can try to refresh the page by clicking here