function handler_email_layout($handler) { $handler_email_layout = handler_templates_dir($handler) . "email/layout.txt"; if (!empty($handler_email_layout) and template_file_exists($handler_email_layout)) { return $handler_email_layout; } else { return handler_templates_dir('') . "email/layout.html"; } }
function template_render($template, $template_vars = array(), $template_dir = NULL) { if ($template_file = template_file_exists($template, $template_dir)) { if (!empty($template_vars) and is_array($template_vars)) { extract($template_vars); } ob_start(); require $template_file; $buffer = ob_get_contents(); ob_end_clean(); return $buffer; } else { trigger_error("Required template ({$template}) not found.", E_USER_ERROR); } return false; }
function glue_response($req, $response) { $template_vars = is_array($response) ? array_merge($req, $response) : array_merge($req, array('content' => $response)); $headers = array_merge(array('content-type' => 'text/html'), response_headers($response)); if (isset($template_vars['template'])) { list($handler, $template) = template_resolver($template_vars['template']); unset($template_vars['template']); //TODO: feels liks a ugly hack to assume func from template but works well for handler-less (template-only) routes if (!isset($template_vars['handler'])) { $template_vars['handler'] = $handler; } if (!isset($template_vars['func'])) { $template_vars['func'] = $template; } if (template_file_exists(handler_template($handler, $template))) { if (isset($template_vars['layout'])) { $layout = $template_vars['layout']; unset($template_vars['layout']); if (is_equal(false, $layout)) { return response_(response_status_code($template_vars), $headers, template_render(handler_template($handler, $template), $template_vars)); } else { list($layout_handler, $layout_template) = template_resolver($layout); return response_(response_status_code($template_vars), $headers, template_compose(handler_template($handler, $template), $template_vars, handler_template($layout_handler, $layout_template), $template_vars)); } } else { return response_(response_status_code($template_vars), $headers, template_compose(handler_template($handler, $template), $template_vars, handler_layout($handler), $template_vars)); } } } return _200_plain(print_r($response, true)); }