getEnabled() ) { HookRegistry::register('TemplateManager::display', array(&$this, 'templateManagerCallback')); } return true; } return false; } function templateManagerCallback($hookName, $args) { $templateMgr =& $args[0]; //TemplateManager::getManager(); $baseUrl = $templateMgr->get_template_vars('baseUrl'); $roundedCornerCssUrl = $baseUrl . '/plugins/generic/roundedCorners/roundedcorners.css'; $templateMgr->addStyleSheet($roundedCornerCssUrl); $templateMgr->register_outputfilter(array('RoundedCornersPlugin', 'roundOutputFilter')); } /** * Do the work of adding in the blocks */ function roundOutputFilter($output, &$smarty) { $top = '
'; $bottom = '
'; $newOutput = $output; $matches = RoundedCornersPlugin::_getDivs($newOutput, 'block'); if (count($matches) > 0) { foreach ($matches as $match) { if (preg_match('/]+class\=\"block\"[^>]*>(\s*)(<\/div>[^<]*)$/', $match) > 0 ) continue; $newBlock = preg_replace('/(]+class\=\"block)(\"[^>]*>)/is', "\\1 alreadyRounded\\2$top", $match, PREG_OFFSET_CAPTURE); $newBlock = preg_replace('/([^>]*)(<\/div>[^<]*)$/', "\\1$bottom\\2", $newBlock); $newOutput = str_replace($match, $newBlock, $newOutput); } } return $newOutput; } /** * look for the opening and closing divs with a particular $class in the $subject * Have to count opening and closing divs since regexes are not so good matching opening and closing tags */ function _getDivs($subject, $class) { preg_match_all("/]+class\=\"$class\"[^>]*>/is", $subject, $matches, PREG_OFFSET_CAPTURE); $matches = $matches[0]; for ($i=0; $i]*>/is", $subject, $divPosition, PREG_OFFSET_CAPTURE, $matches[$i][1]); $divPosition = $divPosition[0]; for ($i2=0; $i2 $openDivs-1) { $divClosePosition = $divPosition[$i2][1]; $divLength = $divClosePosition+6 - $matches[$i][1]; $divs[$i] = substr($subject, $matches[$i][1], $divLength); break; } } } return $divs; } } ?>