Esempio n. 1
0
function handler_sendmail($handler, $email, $resource)
{
    require_once handler_email_file($handler, php_self_dir());
    $args = func_get_args();
    $handler_email_func_args = array_slice($args, 2);
    $handler_email_func = "{$handler}_{$email}_email";
    $params = call_user_func_array($handler_email_func, $handler_email_func_args);
    // TODO: is this all I need to send to the email template?
    $template_vars = array('resource' => $resource, 'params' => $params);
    if (isset($params['message'])) {
        $message = $params['message'];
    } else {
        $message = template_compose(handler_email_template($handler, $email), $template_vars, handler_email_layout($handler), $template_vars);
    }
    return emailmodule_sendmail($params['from'], $params['to'], $params['subject'], $message);
}
Esempio n. 2
0
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));
}