Read Below.
Printable View
Read Below.
Right just to clarify you want to add if statements to you parser? What does your template look like?
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,
then im sorry if i gave the wrong idea.Quote:
PHP Code:so if user isnt logged in {MembersTable.Email} == "Logged"
ELSE {MembersTable.Email} == user@domain.tld
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.
ANDPHP 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;
}
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
}
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.
Bump T_t Cry
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.
Well Sure.
Using This Script....
And this as my template filePHP 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;
}
}
?>
I am trying to loop content blocks.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 -->
the errors i get are from two functions... get_block and assign_block_vars
The errors are:
It repeats the lines two times because i have two entries.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
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.
And using this as my template file.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();
?>
which would outputPHP Code:<!-- START Members -->
USERNAME :: {Members.UserName} IP :: {Members.IP}
<!-- END Members -->
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.
I am still really confused. All that code is going over my head.
If we go with this example
What problem are you having processing that?PHP Code:<!-- START Members -->
USERNAME :: {Members.UserName} IP :: {Members.IP}
<!-- END Members -->
Explain, don't hit me with mountains of code. I'm tired :p
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
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.Quote:
I am trying to loop content blocks.
the errors i get are from two functions... get_block and assign_block_vars
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.
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
Ohh my its zee bumpinator.
Enough. No more bumps.