|
-
Mar 22nd, 2006, 01:58 AM
#1
Thread Starter
Hyperactive Member
Last edited by PlaGuE; Apr 20th, 2006 at 12:42 AM.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Mar 22nd, 2006, 09:27 AM
#2
<?="Moderator"?>
Re: TPL PARSER REALLY REALLY Help!!BEEN TRYING FOR 2 WEEKS
Right just to clarify you want to add if statements to you parser? What does your template look like?
-
Mar 22nd, 2006, 07:58 PM
#3
Thread Starter
Hyperactive Member
Re: TPL PARSER REALLY REALLY Help!!BEEN TRYING FOR 2 WEEKS
no. i dont want ot add an if statement to my parser.
What im tryingto do is "loop" an arry. with the assign_block_vars("blockname", $tag_array());
so taht
in between blocks like
<!-- START blocname -->
{blockname.tag}
<!-- END blockname -->
The template will ONLY hold the design.
if you thought i was assing an IF statement because of,
PHP Code:
so if user isnt logged in {MembersTable.Email} == "Logged"
ELSE {MembersTable.Email} == user@domain.tld
then im sorry if i gave the wrong idea.
the assign_block_vars should turn into an array and list many rows.But because of the fact that its returning Undefinded Offset 0 on the get_block and assign block vars. I've had to kee it static. So i have it only returns one row until i can fix it.
The errors occur in these to functions.
PHP Code:
function get_block($block){
preg_match ('#<!-- START '. $block . ' -->([^.]+)<!-- END '. $block . ' -->#',$this->page,$this->return);
$code = str_replace ('<!-- START '. $block . ' -->', "", $this->return[0]); //ERROR HERE
$code = str_replace ('<!-- END ' . $block . ' -->', "", $code);
return $code;
}
AND
PHP Code:
function assign_block_vars($blockname, $data)
{
$blockCode = $this->get_block($blockname);
foreach ($data as $key => $value) {
$blockCode = str_replace ("{".$blockname.".".$key."}", $value, $blockCode);
}
$this->page = str_replace ($blockCode.$this->return[0], $this->return[0], $this->page);//Error Here
}
Last edited by PlaGuE; Apr 9th, 2006 at 02:55 AM.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Apr 9th, 2006, 02:56 AM
#4
Thread Starter
Hyperactive Member
Re: TPL PARSER REALLY REALLY Help!!BEEN TRYING FOR 2 WEEKS
Bumping it cuz i still cant figure it out... if you need me to clarify it more on what i am tryign to accomplish.. just say so.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Apr 16th, 2006, 03:34 AM
#5
Thread Starter
Hyperactive Member
Re: Template Parser Help.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Apr 16th, 2006, 03:57 AM
#6
Re: Template Parser Help.
Can you try and really simplify this down to the concept of what you want to do? Because I really don't have a clue.
-
Apr 16th, 2006, 04:18 AM
#7
Thread Starter
Hyperactive Member
Re: Template Parser Help.
Well Sure.
Using This Script....
PHP Code:
<?php
/**
* ************************************************\
* Template Paser
*
* \************************************************
*/
class Page {
var $page;
function connect($host, $user, $pass, $db, $dbtype = 'mysql')
{
switch ($dbtype):
case 'mysql':
mysql_connect($host, $user, $pass);
mysql_select_db($db);
break;
case 'mssql':
mssql_connect($host, $user, $pass);
mssql_select_db($db);
break;
case 'msql':
msql_connect($host, $user, $pass);
msql_select_db($db);
break;
case 'odbc':
odbc_connect($host, $user, $pass);
break;
endswitch;
}
function setvars($type, $data)
{
switch ($type):
case 'title':
print('<title>' . ':: ' . $data . '</title>');
break;
case 'error_reporting':
error_reporting($data);
break;
endswitch;
}
// --------------
// Page($template)
// --------------
function Page($template = "templates/template.tpl")
{
if (is_file($template))
$this->page = implode("", file($template));
else
die("Template file $template not found.");
}
// --------------
// Parse($file)
// --------------
function parse($file)
{
ob_start();
include($file);
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
}
// --------------
// Message_Die
// --------------
function Message_Die($data)
{
error_reporting(E_ALL ^ E_WARNING);
$message = '<textarea style=" color:#FFFFFF; width:100%; height:40px; border:1px solid #000000; background:none;">';
$message .= htmlentities($data);
$message .= '</textarea>';
print($message);
}
// --------------
// get_header
// --------------
function get_header()
{
$file = explode("<!-- TEMPLATE -->", $this->page);
$header = $file["0"];
$header = explode("<!-- HEADER -->", $header);
$this->_header = $header[1];
print $this->_header;
}
// --------------
// get_footer
// --------------
function get_footer()
{
$file = explode("<!-- TEMPLATE -->", $this->page);
$footer = $file["0"];
$footer = explode("<!-- FOOTER -->", $footer);
$this->_footer = $footer[1];
print $this->_footer;
}
// --------------
// Replace Tags
// --------------
function replace_tags($tags = array())
{
if (sizeof($tags) > 0)
foreach ($tags as $tag => $data) {
$this->page = str_replace("{" . $tag . "}", $data, $this->page);
}
}
// --------------
// Get Block
// --------------
function get_block($block)
{
preg_match ('#<!-- START ' . $block . ' -->([^.]+)<!-- END ' . $block . ' -->#', $this->page, $this->return);
$code = str_replace ('<!-- START ' . $block . ' -->', "", $this->return[0]); //Error Here <- line 111
$code = str_replace ('<!-- END ' . $block . ' -->', "", $code);
return $code;
}
// --------------
// Remove Block
// --------------
function removeBlock($blockName)
{
// search a match for the expression
preg_match ('#<!-- START ' . $blockName . ' -->([^*]+)<!-- END ' . $blockName . ' -->#', $this->page, $resultCode);
// replace the match with an empty string
@$this->page = str_replace($resultCode[0], '', $this->page);
}
// *
// --------------
// Assign Block Vars
// --------------
function assign_block_vars($blockname, $data)
{
$blockCode = $this->get_block($blockname);
foreach ($data as $key => $value) {
$blockCode = str_replace ("{" . $blockname . "." . $key . "}", $value, $blockCode);
}
$this->page = str_replace ($this->return[0], $blockCode . $this->return[0], $this->page); //Error Here <- line 152
}
// */
// --------------
// Output
// --------------
function output()
{
print $this->page;
}
}
?>
And this as my template file
PHP Code:
<!-- START Announcements -->
<br />
<table width="95%" height="19" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#000000">
<tr>
<td colspan="2" bgcolor="#1D5292"><div align="center" class="Header" id="Author">{Announcements.Content_Header}</div></td>
</tr>
<tr>
<td width="15%" bgcolor="#2F5B93"><span class="username_member" id="Author"><a href="{Announcements.L_UserName}">{Announcements.UserName}</a></span><br />
<span class="username_member" id="Author">{Announcements.UserTitle}</span><br />
<span class="username_member" id="Author">{Announcements.PostTitle}</span><br />
<span class="username_member" id="Author">{Announcements.Posts}</span><br />
<span id="Author">{Announcements.Avatar}</span><br />
<span class="username_member" id="Author">{Announcements.Location}</span><br />
<span class="username_member" id="Author">{Announcements.Reputation}</span><br />
<span id="Author">{Announcements.WarningBar}</span></td>
<td width="85%" bgcolor="#4880C4" valign="top"><div align="left" id="news_posted">
<div align="left"><span class="titlebar"id="Post">Title:{Announcements.Content_Header} Posted on:{Announcements.Content_Date}</span></div>
</div>
<div align="left" class="Body" id="Post">{Announcements.Content_Body}</div></td>
</tr>
<tr>
<td colspan="2" bgcolor="#1D5292"><div align="right"><span class="titlebar"id="Post">
{Announcements.EDIT_BUTTON}
{Announcements.FASTEDIT_BUTTON}
{Announcements.QUOTE*_BUTTON}
{Announcements.QUOTE_BUTTON}
{Announcements.REPLY_BUTTON}
{Announcements.FASTREPLY_BUTTON}
{Announcements.DELETE_BUTTON}</span></div></td>
</tr>
</table>
<!-- END Announcements -->
I am trying to loop content blocks.
the errors i get are from two functions... get_block and assign_block_vars
The errors are:
Code:
Notice: Undefined offset: 0 in C:\Program Files\Apache Group\Apache2\htdocs\cdstplcls\lib\parser.php on line 111
Notice: Undefined offset: 0 in C:\Program Files\Apache Group\Apache2\htdocs\cdstplcls\lib\parser.php on line 137
Notice: Undefined offset: 0 in C:\Program Files\Apache Group\Apache2\htdocs\cdstplcls\lib\parser.php on line 137
Notice: Undefined offset: 0 in C:\Program Files\Apache Group\Apache2\htdocs\cdstplcls\lib\parser.php on line 111
Notice: Undefined offset: 0 in C:\Program Files\Apache Group\Apache2\htdocs\cdstplcls\lib\parser.php on line 137
Notice: Undefined offset: 0 in C:\Program Files\Apache Group\Apache2\htdocs\cdstplcls\lib\parser.php on line 137
It repeats the lines two times because i have two entries.
If i had one entry. The Errors would only show once.
My goal is quite simple.
Here's a sample of how the file with the replace variables.
Not exactly as above.. but easiest to use for an example of wanted outcome.
PHP Code:
<?php
include "parser.php";
$template = new Page("template.tpl");
$sql = "SELECT * FROM members";
$result = mysql_query($sql) or die('Could Not Do a SELECT Query for MEMBERS.');
while ($row = mysql_fetch_array($result)):
$template->assign_block_vars("Members", array("IP" => ($_SESSION['user_id'] != $row['id'] ? $row['ip']:'logged'),
"UserName" => $row['username']));
endwhile;
$template->output();
?>
And using this as my template file.
PHP Code:
<!-- START Members -->
USERNAME :: {Members.UserName} IP :: {Members.IP}
<!-- END Members -->
which would output
if logged in:
USERNAME :: PlaGuE IP :: 68.150.14.124
if not logged in:
USERNAME :: PlaGuE IP :: Logged
Hopefully with that example you get the picture.
Again I apperciate ANY help. As this problem is a big one for me...But you could probably see that already as i have been bumping this topic.
if you need more information just ask.
Last edited by PlaGuE; Apr 21st, 2006 at 03:54 AM.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Apr 19th, 2006, 06:50 AM
#8
Re: Template Parser Help.
I am still really confused. All that code is going over my head.
If we go with this example
PHP Code:
<!-- START Members -->
USERNAME :: {Members.UserName} IP :: {Members.IP}
<!-- END Members -->
What problem are you having processing that?
Explain, don't hit me with mountains of code. I'm tired
-
Apr 19th, 2006, 05:50 PM
#9
Thread Starter
Hyperactive Member
Re: Template Parser Help.
Okay, well if you were to test out the whole script/parser. you'de see it.
Here's an example of the script.
http://plague.chaoticdesignz.net/cdstplcls/
Btw sorry if all the codes going over yer head.
I just posted the complete parser file. the template file in which its being used. An example of how its being used....
also
I am trying to loop content blocks.
the errors i get are from two functions... get_block and assign_block_vars
This quote here is from a post above. What its saying is that the errors occur in both the get_block() and assign_block_vars() functions. HOWEVER it is really only erroring within the assign_block_vars() function due to it not "looping" the content. What its supposed to do is quite simple. However right now i cannot explain it due to the fact that, well idk how to explain it without getting you more confused aswell as confusing myself in the process.
The main problem is... its not looping. its just giving an error. because its not looping the variables. Once {Members.IP} becomes 68.xx.xxx.xx it stays that way. Which it shouldnt.it should go back to {Members.IP}
Hopefully that'll help.... since thats all i could muster outa me wee brain.
Again if you need more explaination. I'd be happy to. Seeing as how this has still eluded me.
I'd suggest testing out the provided code and looking at the errors.
Last edited by PlaGuE; Apr 19th, 2006 at 07:48 PM.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Apr 21st, 2006, 03:49 AM
#10
Thread Starter
Hyperactive Member
Re: Template Parser Help.
UPDATE: Beautified my parser script to look nice. So Now VisualAd and Pengate. YELP ME.lol...btw bump.
PS. I only bump after a certain ammount of time has passed
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Apr 29th, 2006, 03:53 AM
#11
Thread Starter
Hyperactive Member
Re: Template Parser Help.
Ohh my its zee bumpinator.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Apr 29th, 2006, 04:12 AM
#12
Re: Template Parser Help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|