Пример #1
0
 public function __construct()
 {
     global $_GET, $_POST, $_COOKIE, $_FILES, $_SERVER;
     $this->properties = [];
     $this->server = $_SERVER;
     if (self::$handlers == null) {
         self::$handlers = [];
     }
     if (isset($_POST) && array_count($_POST) > 0) {
         foreach ($_POST as $key => $val) {
             $this->properties['POST'][$this->_clean_key($key)] = $this->_clean_val($val);
         }
     }
     if (isset($_GET) && array_count($_GET) > 0) {
         foreach ($_GET as $key => $val) {
             $this->properties['GET'][$this->_clean_key($key)] = $this->_clean_val($val);
         }
     }
     if (isset($_COOKIE) && array_count($_COOKIE) > 0) {
         foreach ($_COOKIE as $key => $val) {
             $this->properties['COOKIE'][$this->_clean_key($key)] = $this->_clean_val($val);
         }
     }
     if (isset($_FILES) && array_count($_FILES) > 0) {
         foreach ($_FILES as $key => $val) {
             $this->properties['FILES'][$this->_clean_key($key)] = $this->_clean_val($val);
         }
     }
     class_alias('\\Wasp\\Input', '\\Input');
 }
Пример #2
0
 public function __construct()
 {
     parent::__construct();
     if (self::$_saved === null) {
         self::$_saved = false;
     }
     if (self::$_need_save === null) {
         self::$_need_save = false;
     }
     $tmp = input()->cookie();
     if (array_count($tmp) > 0) {
         if (array_key_isset('PHPSESSID', $tmp)) {
             unset($tmp['PHPSESSID']);
         }
         if (array_count($tmp) > 0) {
             foreach ($tmp as $key => $val) {
                 if (is_varible_name($key)) {
                     if ($val != '') {
                         $this->_properties[$key] = unserialize(@gzuncompress(base64_decode($val)));
                     } else {
                         $this->_properties[$key] = '';
                     }
                 }
             }
         }
     }
     unset($tmp);
 }
Пример #3
0
 /**
  * Получение адреса по GPS координатам
  *
  * @param float $latitude
  * @param float $longitude
  * @param string $lang
  */
 public function getByCoords($latitude, $longitude, $lang = 'ru')
 {
     //            $url    = 'https://maps.googleapis.com/maps/api/geocode/json?key=' . self::API_KEY . '&latlng=' . $latitude . ',' . $longitude . '&sensor=false&language=' . $lang;
     $url = "http://maps.googleapis.com/maps/api/geocode/json?latlng={$latitude},{$longitude}&sensor=false&language={$lang}";
     $addr = null;
     $curDate = date('Ymd');
     $_ = $this->getFromBase($latitude, $longitude, $lang);
     if (empty($_)) {
         if (is_file(TEMP_DIR . DIR_SEP . "{$curDate}.txt")) {
             if (filemtime(TEMP_DIR . DIR_SEP . "{$curDate}.txt") > time() - 10800) {
                 return false;
             }
             if (!@unlink(TEMP_DIR . DIR_SEP . "{$curDate}.txt")) {
                 return false;
             }
         }
         $_ = $this->_curl->get($url);
     } else {
         return $_;
     }
     if (!empty($_)) {
         $result = json_decode($_, true);
         if (!empty($result['status']) && $result['status'] == 'OVER_QUERY_LIMIT' || $result['status'] == 'REQUEST_DENIED') {
             file_put_contents(TEMP_DIR . DIR_SEP . "{$curDate}.txt", $result['status']);
         }
         if (array_count($result['results']) > 0) {
             foreach ($result['results'] as $key => $val) {
                 if (!empty($val['formatted_address']) && !empty($val['geometry']['location'])) {
                     $this->setToBase($val['geometry']['location']['lat'], $val['geometry']['location']['lng'], $lang, $val['formatted_address']);
                 }
             }
         }
         if (!empty($result['results'])) {
             $addr = array_get_first($result['results']);
             if (!empty($addr['formatted_address'])) {
                 $this->setToBase($latitude, $longitude, $lang, $addr['formatted_address']);
             }
         }
     }
     unset($result, $_);
     return $addr['formatted_address'];
 }
Пример #4
0
 public function get($key, array $values = [])
 {
     if ($this->has($key)) {
         $_ = $this->strings->{$key};
         if (array_count($values) > 0) {
             foreach ($values as $key => $val) {
                 if (is_scalar($val)) {
                     $_ = str_replace(":{$key}", $val, $_);
                 }
             }
         }
         return $_;
     }
     return "::{$key}::";
 }
Пример #5
0
 /**
  * Получение ключа последнего элемента масива
  * 
  * @param array $_array
  */
 function array_get_last_key($_array)
 {
     if (array_count($_array) <= 0) {
         return false;
     }
     end($_array);
     $k = key($_array);
     unset($_array);
     return $k;
 }
Пример #6
0
echo form_error('fields[' . $index . '][required]');
echo form_dropdown($fld_name . '[type]', $types, set_value($fld_name . '[type]'), 'id="type' . $index . '" class="type_select"');
?>
	
	<?php 
echo form_checkbox($fld_name . '[required]', 'true', set_value($fld_name . '[required]'), 'id="required' . $index . '"');
echo form_label('This field is required', 'required' . $index);
?>
	
	<?php 
echo form_error('fields[' . $index . '][options][]');
?>
	<ul class="options">
		<span class="field_help">Press 'Enter' after each option to add more.</span>
		<?php 
$optionNum = max(array_count($fld_name . '[options][]'), 1);
?>
		<?php 
for ($i = 0; $i < $optionNum; $i++) {
    ?>
		<li>
			<span class="dummy"></span>
			<?php 
    echo form_input($fld_name . '[options][]', set_value($fld_name . '[options][]'), 'class="val_opts" size="50"');
    ?>
			<a class="delete_btn" href="#">X</a>
		</li>
		<?php 
}
?>
		<a class="add_btn add_option" href="#">Add Option</a>
Пример #7
0
 public function anyAdd()
 {
     $confirm = $this->input->post('confirm');
     $form = $this->input->post('form');
     $errors = [];
     if (!empty($confirm) && $confirm == 'ok') {
         $validator = new \Wasp\Validator($form, $this->validation);
         if (!$validator->checkAll()) {
             $errors = $validator->getMessages();
         }
         $check_user = $this->users->getByEmail($form['email']);
         $user_data = [];
         if (!empty($check_user->id)) {
             if (!isset($errors['email']) || !is_array($errors['email'])) {
                 $errors['email'] = [];
             }
             $errors['email'][] = 'Такой пользователь уже есть';
         }
         if (!is_alphanum($form['passwd1']) || !is_alphanum($form['passwd2']) || wasp_strlen($form['passwd1']) > 16 || wasp_strlen($form['passwd1']) < 6 || wasp_strlen($form['passwd2']) > 16 || wasp_strlen($form['passwd2']) < 6 || $form['passwd1'] != $form['passwd2']) {
             if (!isset($errors['passwd1']) || !is_array($errors['passwd1'])) {
                 $errors['passwd1'] = [];
             }
             $errors['passwd1'][] = 'Неверное указан пароль';
         }
         if (array_count($errors) == 0) {
             $current_user = $this->auth->getAuthUser();
             $group_level = $this->users->getGroupLevel($form['group_id']);
             $passwd = password_crypt($form['passwd1']);
             $user_data['email'] = $form['email'];
             $user_data['password'] = $passwd;
             if ($this->users->groupIdExists($form['group_id']) && ($group_level < $current_user->group->level || $this->auth->isRoot())) {
                 $user_data['group_id'] = intval($form['group_id']);
                 $user_data['blocked'] = intval($form['blocked']);
             }
             if ($this->auth->isAdmin()) {
                 foreach ($form as $key => $val) {
                     if (!array_key_isset($key, $user_data)) {
                         $user_data[$key] = $val;
                     }
                 }
             }
             $id = $this->users->create($user_data);
             redirect(['controller' => 'users', 'method' => 'edit', 'id' => $id, 'message' => 'Пользователь успешно добавлен в систему.']);
         }
     }
     $this->layout->useThemeCss('datepicker.css')->useThemeJs('bootstrap-datepicker.js', false);
     return $this->ui->assign('errors', $errors)->assign('form', $form)->assign('groups', $this->users->getGroups())->fetch('users/add');
 }
Пример #8
0
 public function display($content)
 {
     if (!$this->render) {
         if (!headers_sent() && array_count($this->_headers) > 0) {
             foreach ($this->_headers as $key => $val) {
                 header($val);
             }
         }
         http_cache_off();
         if (!Cookie::isSaved()) {
             cookie()->save();
         }
         if (wasp_strlen($content) > 102400) {
             @ini_set('zlib.output_compression', 1);
         }
         echo $this->getDebugInfo($content);
         return;
     }
     $templater = new \Smarty();
     $templater->enableSecurity('Wasp_Smarty_Security');
     $templater->setTemplateDir($this->getThemePath() . DIR_SEP);
     $temp_dir = TEMP_DIR . DIR_SEP . 'smarty' . DIR_SEP . $this->getThemeName();
     if (!is_dir($temp_dir)) {
         wasp_mkdir($temp_dir);
     }
     $templater->setCompileDir($temp_dir . DIR_SEP);
     if (array_count($this->_assigns) > 0) {
         foreach ($this->_assigns as $key => $val) {
             $templater->assign($key, $val);
         }
     }
     $templater->assign('content', $content);
     if (function_exists('memory_get_peak_usage')) {
         $templater->assign('max_mem_use', get_mem_use(true));
     } else {
         $templater->assign('max_mem_use', '-//-');
     }
     $out = $templater->fetch($this->_layout);
     if (!headers_sent() && array_count($this->_headers) > 0) {
         foreach ($this->_headers as $key => $val) {
             header($val);
         }
     }
     if (!Cookie::isSaved()) {
         cookie()->save();
     }
     if (wasp_strlen($out) > 102400) {
         ini_set('zlib.output_compression', 1);
     }
     unset($templater);
     memory_clear();
     /**
      * Add CSS
      */
     if (array_count($this->_css_list) > 0) {
         $_ = "\n\t\t<!-- DYNAMIC CSS -->\n";
         foreach ($this->_css_list as $key => $val) {
             if (preg_match('/^http/is', $val)) {
                 $_ .= "\t\t<link href=\"{$val}\" rel=\"stylesheet\" type=\"text/css\" />\n";
             } else {
                 $url = $this->getThemeUrl() . '/css/' . $val;
                 $_ .= "\t\t<link href=\"{$url}\" rel=\"stylesheet\" type=\"text/css\" />\n";
             }
         }
         $out = preg_replace('#\\<\\/head\\>#is', $_ . "</head>\n", $out);
         unset($_, $key, $val, $url);
     }
     /**
      * Add JS
      */
     if (array_count($this->_js_list) > 0) {
         $info = "\n\t\t<!-- :position DYNAMIC JS -->\n";
         foreach ($this->_js_list as $pos => $item) {
             $_ = str_replace(':position', wasp_strtoupper($pos), "\n\t\t<!-- :position DYNAMIC JS -->\n");
             if (array_count($item) > 0) {
                 foreach ($item as $key => $val) {
                     if (preg_match('/^http/is', $val)) {
                         $_ .= "\t\t<script type=\"text/javascript\" src=\"{$val}\"></script>\n";
                     } else {
                         $url = $this->getThemeUrl() . '/js/' . $val;
                         $_ .= "\t\t<script type=\"text/javascript\" src=\"{$url}\"></script>\n";
                     }
                 }
                 $out = preg_replace("#\\<\\/{$pos}\\>#is", $_ . "</{$pos}>\n", $out);
                 unset($_, $key, $val, $url);
             }
         }
         unset($pos, $item);
     }
     echo $this->getDebugInfo($out);
 }
Пример #9
0
 private function _execute_services()
 {
     if (is_dir(SERVICES_DIR)) {
         $services = get_files_list(SERVICES_DIR, ['php']);
         if (array_count($services) > 0) {
             ksort($services);
             foreach ($services as $key => $val) {
                 $service_name = str_replace('.php', '', $key);
                 $service_class = '\\App\\Services\\' . studly_case($service_name);
                 try {
                     $tmp = new $service_class();
                 } catch (AppException $e) {
                     wasp_error($e->getMessage());
                 }
                 if ($tmp instanceof Service) {
                     $tmp->execute();
                 } else {
                     wasp_error('Incorrect instance of service class ' . $tmp->className());
                 }
                 unset($tmp);
             }
         }
     }
 }
Пример #10
0
 private function _set_get_params($_array = [])
 {
     global $_GET;
     if (array_count($_array) > 0 && is_even(count($_array))) {
         $_array_count = floor(count($_array) / 2);
         for ($i = 0; $i / 2 < $_array_count; $i += 2) {
             $_GET[$_array[$i]] = !empty($_array[$i + 1]) ? $_array[$i + 1] : '';
         }
     }
 }
Пример #11
0
function mysql_add_records($connect_id, $table, $fields_array, $records_per_query = 100, $extra = array())
{
    if (!array_count($fields_array)) {
        return false;
    }
    if ($extra['insert_old']) {
        return mysql_add_records_old($connect_id, $table, $fields_array);
    }
    $base_sql_statement = "INSERT INTO {$table} ";
    if ($extra['insert_options']) {
        $extra['insert_options'] = strtoupper($extra['insert_options']);
        if ($extra['insert_options'] == "IGNORE") {
            $base_sql_statement = "INSERT IGNORE INTO {$table} ";
        } else {
            if ($extra['insert_options'] == "REPLACE") {
                $base_sql_statement = "REPLACE INTO {$table} ";
            }
        }
    }
    reset($fields_array);
    $first_record = current($fields_array);
    if (is_array($first_record)) {
        $field_names = array_keys($first_record);
    } else {
        $field_names = array_keys($table);
        $fields_array = array(0 => $fields_array);
    }
    # check if each record in the array has all the same fields and in the same order
    foreach ($fields_array as $key => $array) {
        if ($field_names != array_keys($array)) {
            $record_fields_error++;
            $record_fields_error_records[$key] = $array;
        }
    }
    # add the non-bulk records one by one (as its possibly they all have different lengths) and then add the bulk ones
    if ($record_fields_error) {
        mysql_add_records_old($connect_id, $table, $record_fields_error_records);
        foreach ($record_fields_error_records as $key => $array) {
            unset($fields_array[$key]);
        }
    }
    $base_sql_statement .= "( `" . join("`, `", $field_names) . "` ) VALUES ";
    foreach ($fields_array as $fields) {
        $x++;
        foreach ($fields as $key => $value) {
            if (is_null($value)) {
                $field_value = "NULL";
            } else {
                if (is_integer($value) or is_float($value)) {
                    $field_value = "{$value}";
                } else {
                    $field_value = "'" . mysql_real_escape_string($value) . "'";
                    if ($field_value == "''") {
                        $field_value = "NULL";
                    }
                }
            }
            $fields[$key] = $field_value;
        }
        $add_records[] = "( " . join(", ", $fields) . " )";
        if ($x == $records_per_query) {
            $sql_statement = $base_sql_statement . join(", ", $add_records);
            $return_value = mysql_execute_sql_quick($connect_id, $sql_statement);
            $x = 0;
            $add_records = array();
        }
    }
    if ($add_records) {
        $sql_statement = $base_sql_statement . join(", ", $add_records);
        $return_value = mysql_execute_sql_quick($connect_id, $sql_statement);
    }
    return $return_value;
}