function tbxSiteTemplateSearchReplace() { Privileges::Check(Privileges::TEMPLATES); $output = array(); $v = Validator::Create(); $v->Register(count(Request::Get('templates')), Validator_Type::GREATER, 'You must select at least one template for this action', 0); $v->Register(Request::Get('search'), Validator_Type::NOT_EMPTY, 'The Search For field is required'); foreach (Request::Get('templates') as $template) { $template = File::Sanitize($template); $filename = TEMPLATES_DIR . '/' . $template; $v->Register(is_writeable($filename), Validator_Type::NOT_FALSE, "The template file {$template} has incorrect permissions; change to 666 then try again"); } if (!$v->Validate()) { $output['message'] = 'Search and replace could not be executed; please fix the following items'; $output['errors'] = $v->GetErrors(); JSON::Failure($output); } else { $search = String::FormatNewlines(Request::Get('search'), String::NEWLINE_UNIX); $replace = String::FormatNewlines(Request::Get('replace'), String::NEWLINE_UNIX); $total_replacements = 0; foreach (Request::Get('templates') as $template) { $template = File::Sanitize($template); $filename = TEMPLATES_DIR . "/{$template}"; $template_code = file_get_contents($filename); $template_code = str_replace($search, $replace, $template_code, $replacements); // Changes have been made if ($replacements > 0 && ($code = Template_Compiler::Compile($template_code)) !== false) { file_put_contents($filename, $template_code); file_put_contents(TEMPLATE_COMPILE_DIR . "/{$template}", $code); @chmod($compiled, 0666); $total_replacements += $replacements; } } $output['message'] = 'Search and replace has been completed. Replacements made: ' . NumberFormatInteger($total_replacements); JSON::Success($output); } }
public function Parse($template) { $compiled_code = Template_Compiler::Compile($template); ob_start(); eval('?>' . $compiled_code); $generated = ob_get_clean(); return $this->nocache ? eval('?>' . $generated) : $generated; }