language::load PHP Method

load() private static method

private static load ( $file )
    private static function load($file)
    {
        if (is_readable($lang = static::path($file))) {
            static::$lines[$file] = (require $lang);
        }
    }

Usage Example

Exemplo n.º 1
0
function nvweb_contact($vars = array())
{
    global $website;
    global $DB;
    global $current;
    global $webgets;
    global $dictionary;
    global $webuser;
    global $theme;
    global $events;
    $webget = 'contact';
    if (!isset($webgets[$webget])) {
        $webgets[$webget] = array();
        global $lang;
        if (empty($lang)) {
            $lang = new language();
            $lang->load($current['lang']);
        }
        // default translations
        $webgets[$webget]['translations'] = array('name' => t(159, 'Name'), 'email' => t(44, 'E-Mail'), 'message' => t(380, 'Message'), 'fields_blank' => t(444, 'You left some required fields blank.'), 'contact_request_sent' => t(445, 'Your contact request has been sent. We will contact you shortly.'), 'contact_request_failed' => t(446, 'We\'re sorry. Your contact request could not be sent. Please try again or find another way to contact us.'), 'receipt_confirmation' => t(650, 'Receipt confirmation'));
        // theme translations
        // if the web theme has custom translations for this string subtypes, use it (for the user selected language)
        /* just add the following translations to your json theme dictionary:
        
        			"name": "Name",
        			"email": "E-Mail",
        			"message": "Message",
        		    "fields_blank": "You left some required fields blank.",
        		    "contact_request_sent": "Your contact request has been sent. We will contact you shortly.",
        		    "contact_request_failed": "We're sorry. Your contact request could not be sent. Please try again or find another way to contact us.",
        		    "receipt_confirmation": "Receipt confirmation"
        
        		*/
        if (!empty($website->theme) && method_exists($theme, 't')) {
            foreach ($webgets[$webget]['translations'] as $code => $text) {
                $theme_translation = $theme->t($code);
                if (!empty($theme_translation) && $code != $theme_translation) {
                    $webgets[$webget]['translations'][$code] = $theme_translation;
                }
            }
        }
    }
    if (empty($vars['notify'])) {
        $vars['notify'] = 'alert';
    }
    $out = '';
    switch (@$vars['mode']) {
        case 'send':
            if (!empty($_POST)) {
                // a page may have several forms, which one do we have to check?
                if (!empty($vars['form'])) {
                    list($field_name, $field_value) = explode('=', $vars['form']);
                    $field_name = trim($field_name);
                    $field_value = trim($field_value);
                    if ($_POST[$field_name] != $field_value) {
                        return;
                    }
                }
                // try to check if this send request really comes from the website and not from a spambot
                if (parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST) != $website->subdomain . '.' . $website->domain && parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST) != $website->domain) {
                    return;
                }
                // prepare fields and labels
                $fields = explode(',', @$vars['fields']);
                $labels = explode(',', @$vars['labels']);
                if (empty($labels)) {
                    $labels = $fields;
                }
                $labels = array_map(function ($key) {
                    global $webgets;
                    global $theme;
                    $key = trim($key);
                    $tmp = $theme->t($key);
                    if (!empty($tmp)) {
                        return $tmp;
                    } else {
                        return $webgets['contact']['translations'][$key];
                    }
                }, $labels);
                $fields = array_combine($fields, $labels);
                // $fields = array( 'field_name' => 'field_label', ... )
                // check required fields
                $errors = array();
                $required = array();
                if (!empty($vars['required'])) {
                    $required = explode(',', $vars['required']);
                }
                if (!empty($required)) {
                    foreach ($required as $field) {
                        $field = trim($field);
                        $value = trim($_POST[$field]);
                        if (empty($value)) {
                            $errors[] = $fields[$field];
                        }
                    }
                    if (!empty($errors)) {
                        return nvweb_contact_notify($vars, true, $webgets[$webget]['translations']['fields_blank'] . ' (' . implode(", ", $errors) . ')');
                    }
                }
                // create e-mail message and send it
                $message = nvweb_contact_generate($fields);
                // prepare any attachment to be sent
                $attachments = array();
                foreach ($fields as $field => $label) {
                    if (isset($_FILES[$field]) && $_FILES[$field]['error'] == 0) {
                        $attachments[] = array('file' => $_FILES[$field]['tmp_name'], 'name' => $_FILES[$field]['name']);
                    }
                }
                $subject = $vars['subject'];
                if (!empty($subject)) {
                    $subject = ' | ' . $theme->t($subject);
                }
                $subject = $website->name . $subject;
                $sent = nvweb_send_email($subject, $message, $website->contact_emails, $attachments);
                if ($sent) {
                    if (!empty($vars['receipt_confirmation_email'])) {
                        $confirmation_email = '';
                        if ($vars['receipt_confirmation_email'] == 'webuser') {
                            $confirmation_email = $webuser->email;
                        } else {
                            $confirmation_email = $_POST[$vars['receipt_confirmation_email']];
                        }
                        if (!empty($confirmation_email)) {
                            nvweb_send_email($subject . ' (' . $webgets[$webget]['translations']['receipt_confirmation'] . ')', $message, $confirmation_email, $attachments);
                        }
                    }
                    $events->trigger('contact', 'sent', array('subject' => $subject, 'message' => $message, 'form' => @$vars['form'], 'emails' => $website->contact_emails));
                    $out = nvweb_contact_notify($vars, false, $webgets[$webget]['translations']['contact_request_sent']);
                } else {
                    $out = nvweb_contact_notify($vars, true, $webgets[$webget]['translations']['contact_request_failed']);
                }
            }
    }
    return $out;
}
All Usage Examples Of language::load