/** * Generate a HTML code using a template and replacing all the pseudo-variables * by the dynamic variables provided by the developer through one of the parameters * of the function. * * @param string $template Filename of the template that will be used to generate the page. * @param array $params Key-value array with pseudo-variables shared with the template. * @param boolean $type Template type; either page, section or snippet. * @return string Formatted HTML code after pseudo-variables replacement. */ public static function getTemplate($template = '', $params = array(), $type = 'page') { if (!is_array($params)) { $params = array(); } if ($type == 'page' || $type == 'section') { $fpath_pattern = '%s/%s/inc/tpl/%s.html.tpl'; } elseif ($type == 'snippet') { $fpath_pattern = '%s/%s/inc/tpl/%s.snippet.tpl'; } else { $fpath_pattern = null; } if ($fpath_pattern !== null) { $output = ''; $fpath = sprintf($fpath_pattern, WP_PLUGIN_DIR, SUCURISCAN_PLUGIN_FOLDER, $template); if (file_exists($fpath) && is_readable($fpath)) { $output = @file_get_contents($fpath); $params['SucuriURL'] = SUCURISCAN_URL; // Detect the current page URL. if ($_page = self::get('page', '_page')) { $params['CurrentURL'] = SucuriScan::admin_url('admin.php?page=' . $_page); } else { $params['CurrentURL'] = SucuriScan::admin_url(); } // Replace the global pseudo-variables in the section/snippets templates. if ($template == 'base' && array_key_exists('PageContent', $params) && @preg_match('/%%SUCURI\\.(.+)%%/', $params['PageContent'])) { $params['PageContent'] = self::replacePseudoVars($params['PageContent'], $params); } $output = self::replacePseudoVars($output, $params); } if ($template == 'base' || $type != 'page') { return $output; } return self::getBaseTemplate($output, $params); } return ''; }