Example #1
0
 public static function translate($key)
 {
     if (self::$lang == null) {
         $language = '';
         if (isset($_SESSION['language'])) {
             $language = strtolower($_SESSION['language']);
         } else {
             $q = mysql_query("SELECT language FROM tblclients WHERE id = " . $_SESSION['uid']);
             $row = mysql_fetch_assoc($q);
             if ($row['language']) {
                 $language = $row['language'];
             }
         }
         if (!$language) {
             $q = mysql_query("SELECT value FROM tblconfiguration WHERE setting = 'language' LIMIT 1");
             $row = mysql_fetch_assoc($q);
             $language = $row['language'];
         }
         if (!$language) {
             $language = 'english';
         }
         if (file_exists(ADDON_DIR . '/lang/' . $language . '.php')) {
             include ADDON_DIR . '/lang/' . $language . '.php';
         }
         if (isset($LANG)) {
             self::$lang = $LANG;
         }
     }
     if (isset(self::$lang[$key])) {
         return self::$lang[$key];
     }
     return $key;
 }
 public static function run($input)
 {
     if (!$input) {
         $input = $_REQUEST;
     }
     if (!count($input)) {
         return false;
     }
     self::$input = $input;
     //die(print_r(self::$data));
     $passed = true;
     foreach (self::$data as $fieldName => &$field) {
         foreach ($field['rules'] as &$rule) {
             $func = $rule['rule'];
             if (method_exists(__CLASS__, $func)) {
                 if (isset($rule['vars'])) {
                     $rule['passed'] = (int) call_user_func(array('MG_Validation', $func), $fieldName, $rule['vars']);
                 } else {
                     $rule['passed'] = (int) call_user_func(array('MG_Validation', $func), $fieldName);
                 }
             } else {
                 $rule['passed'] = (int) call_user_func($func, self::$input[$fieldName]);
             }
             if (!$rule['passed']) {
                 addError(str_replace("%", $field['friendlyName'], MG_Lang::translate('validation_' . $rule['rule'])));
                 $passed = 0;
                 $field['passed'] = 0;
             }
         }
     }
     return $passed;
 }