2012-11-01, 12:46 AM
Hi all,
Working on the CMS plugin and having some trouble with the blocks.
I am using [ba]block_area_name[/b] in the template, this then triggers a function that looks for any blocks that are assigned to that block area.
I was hoping that I could then simply replace the [ba]block_area_name[/b] with the ordered includes of the block index files.
This kind of works, however instead of replacing in place, it is replacing at the start of the page.
I am guessing that pre_output_page is precisely that, output before the page content.
Here is my code, can anyone offer any suggestions?
UPDATE: seems it is with the include, for some reason it wont do an include replace in place.
UPDATE 2: using file_get_contents() seems to be the best solution
Working on the CMS plugin and having some trouble with the blocks.
I am using [ba]block_area_name[/b] in the template, this then triggers a function that looks for any blocks that are assigned to that block area.
I was hoping that I could then simply replace the [ba]block_area_name[/b] with the ordered includes of the block index files.
This kind of works, however instead of replacing in place, it is replacing at the start of the page.
I am guessing that pre_output_page is precisely that, output before the page content.
Here is my code, can anyone offer any suggestions?
function cms_block_caller(&$page) {
global $db, $config;
$pattern= "/\[ba\](.*?)\[\/ba\]/is";
//the variable for the replace
preg_match_all($pattern, $page, $matches);
foreach($matches[1] as $match) {
//We need to get the ID of the block area for later use. We could do this with a join, but the performance value isn't there as it should be an inexpensive query
$query = $db->query("Select ID from ".TABLE_PREFIX."brookie_cms_general_data where type='blockarea' and title='".$match."'");
$block_area_id = $db->fetch_field($query, "ID");
if($block_area_id) {
//get all of the blocks for the block are, in order and replace them.
$block_query = $db->query("select block_title, block_folder from ".TABLE_PREFIX."brookie_cms_blocks where area=".$block_area_id);
while($result=$db->fetch_array($block_query)) {
$page = str_replace('[ba]'.$match.'[/ba]', include("cms/blocks/".$result["block_folder"]."/index.php"), $page);
}
}
}
UPDATE: seems it is with the include, for some reason it wont do an include replace in place.
UPDATE 2: using file_get_contents() seems to be the best solution