/** * Iterator * Get all the blocks and attach the content within the view called * @param array $blocks * @param string $side */ private function Iterator($blocks, $side) { $ns = new Zend_Session_Namespace('Admin'); $languageID = Languages::get_language_id($ns->lang); if (!empty($blocks['side'])) { if ($blocks['side'] == $side) { $blocks = $blocks['block']; if (count($blocks) > 1) { foreach ($blocks as $block) { $block = CmsBlocks::findbyvar($block['name'], $languageID); if (!empty($block[0]['body'])) { echo $block[0]['body']; } } } else { $block = CmsBlocks::findbyvar($blocks['name'], $languageID); if (!empty($block[0]['body'])) { echo $block[0]['body']; } else { echo $blocks['name'] . " block not found."; } } } } }
/** * chkCmsBlocks * Replace all the blocks with the cms blocks found * * In the cms page you have to write in this way within the text body * {block name="homepage"} * * @param string $text * @return string */ public static function chkCmsBlocks($text, $locale = "en") { $languageID = Languages::get_language_id($locale); // Get all the blocks in the whole text $blocks = self::getAllBlocks($text); if (!empty($blocks[0])) { // For each block do ... foreach ($blocks[0] as $block) { // Get the information from the block preg_match_all('(([a-zA-Z0-9]+)=\\"(.+)\\")Ui', $block, $matches); // If the information are correct we get the name of the cms block to load if (!empty($matches[2][0])) { // This is the name of the cms block to load from the db $blockname = str_replace("\"", "", $matches[2][0]); // Get the block information $rsblock = CmsBlocks::findbyvar($blockname, $languageID); // Replace the block placeholder with the cmsblock body if (!empty($rsblock[0])) { $text = str_replace($block, $rsblock[0]['body'], $text); } else { $text = str_replace($block, "[ERROR Cms block: {$blockname} doesn't exist.]", $text); } } } } return $text; }