/** * @param bool $id * @return bool * @throws Kohana_Exception * * insert or update book */ public function insBook($id = false) { $_POST = Arr::map('trim', $_POST); $post = Validation::factory($_POST); $post->rule('name', 'not_empty')->rule('name', 'alpha_numeric', array(':value', false))->rule('name', 'min_length', array(':value', 2))->rule('name', 'max_length', array(':value', 20))->rule('email', 'email')->rule('body', 'not_empty')->rule('body', 'max_length', array(':value', 1024)); if ($post->check()) { if ($id) { $book = ORM::factory('Guestbook', $id); } else { $book = ORM::factory('Guestbook'); } $book->name = Security::encode_php_tags(HTML::chars($_POST['name'])); $book->email = Security::encode_php_tags(HTML::chars($_POST['email'])); $book->body = Security::encode_php_tags(HTML::chars($_POST['body'])); try { if ($id) { $book->update(); } else { $book->create(); } return true; } catch (ORM_Validation_Exception $e) { return false; } } else { //$errors = $post -> errors('validation'); return false; } }
public function action_index() { $config = Kohana::$config->load('huia/email'); $values = Arr::map('strip_tags', $this->request->post()); $view = View::factory('huia/email/' . $values['view']); $view->set($values); $result = Email::factory($values['subject'], $view->render(), 'text/html')->to($values['to_email'])->from($config->from_email, $config->from_name)->send(); $this->response->body(@json_encode(array('success' => $result))); }
public function action_edit() { $view = View::factory('exercise/form')->bind('form', $form)->bind('questions', $questions)->bind('selected_questions', $selected_questions)->bind('exercise_questions', $exercise_questions)->bind('error_notif', $error_notif); $submitted = false; $course = ORM::factory('course', Session::instance()->get('course_id')); $error_notif = array(); $exercise_id = (int) $this->request->param('id'); $exercise = ORM::factory('exercise', $exercise_id); if ($this->request->method() === 'POST' && $this->request->post()) { $submitted = true; $safepost = Arr::map('Security::xss_clean', $this->request->post()); $validator = $exercise->validator($safepost); if ($validator->check() && $this->validate_form($safepost)) { $exercise->values(array_merge($safepost, array('course_id' => $course->id, 'slug' => Text::limit_chars(Inflector::underscore($safepost['title'])), 'modified_at' => date('Y-m-d H:i:s', time())))); $exercise->save(); $zip_ques = Arr::zip($safepost['selected'], $safepost['marks']); $exercise->delete_questions()->add_questions($zip_ques); if ($safepost['pub_status'] == '1') { $exist = ORM::factory('feed'); $exist->where('type', ' = ', 'exercise'); $exist->where('action', ' = ', 'add'); $exist->where('respective_id', ' = ', $exercise->id); $exist->where('course_id', ' = ', Session::instance()->get('course_id')); $exists = $exist->find_all(); if (count($exists) == 0) { $feed = new Feed_Exercise(); $feed->set_action('add'); $feed->set_course_id(Session::instance()->get('course_id')); $feed->set_respective_id($exercise->id); $feed->set_actor_id(Auth::instance()->get_user()->id); $feed->streams(array('course_id' => (int) Session::instance()->get('course_id'))); $feed->save(); } } Session::instance()->set('success', 'Exercise edited successfully.'); Request::current()->redirect('exercise'); exit; } else { $this->_errors = array_merge($this->_errors, $validator->errors('exercise')); $error_notif = Arr::get($this->_errors, 'questions', ''); } } $exercise_questions = $exercise->questions()->as_array('question_id', 'marks'); $selected_questions = array_keys($exercise_questions); $saved_data = $exercise->as_array(); $form = $this->form('exercise/edit/id/' . $exercise->id, $submitted, $saved_data); Breadcrumbs::add(array('Edit', '')); // set content $questions = Model_Question::get_questions(array('course_id' => $course->id)); $this->content = $view; }
public function __construct($preset = 'default') { Arr::map('Security::xss_clean', $_POST); $settings = Kohana::$config->load('fbuilder.' . $preset); $this->view = View::factory($settings['view']); $this->defaults = $settings['params_default']; $this->theme = $settings['theme']; if ($post = $_POST) { $dta = $this->flatten_array($post); } if (isset($dta) and !empty($dta)) { $this->post = Arr::merge($this->post, $dta); } }
/** * Form with mentions keywords list */ public function index() { $keywords = User_search_keyword::inst()->get_user_keywords($this->c_user->id, $this->profile->id); $new_keywords = array(); $errors = array(); $saved_ids = array(0); // '0' to prevent datamapper error caused by empty array $delete = true; if ($post = $this->input->post()) { unset($post['submit']); $grouped = Arr::collect($post); foreach ($grouped as $id => $data) { if (strpos($id, 'new_') === 0) { $keyword = User_search_keyword::inst()->fill_from_array($data, $this->c_user->id, $this->profile->id); $new_keywords[$id] = $keyword; } else { $keyword = User_search_keyword::inst()->fill_from_array($data, $this->c_user->id, $this->profile->id, $id); if ($keyword->id !== $id) { $new_keywords[$id] = $keyword; } } if ($keyword->save()) { $saved_ids[] = $keyword->id; } else { $errors[$id] = $keyword->error->string; } } if (empty($errors)) { if ($delete) { User_search_keyword::inst()->set_deleted($this->c_user->id, $this->profile->id, $saved_ids); } $this->addFlash(lang('keywords_saved_success'), 'success'); redirect('settings/user_search_keywords'); } else { $this->addFlash(implode('<br>', Arr::map('strip_tags', $errors))); } } CssJs::getInst()->c_js('settings/user_search_keywords', 'index'); $configs = Available_config::getByKeysAsArray(array('auto_follow_users_by_search', 'max_daily_auto_follow_users_by_search'), $this->c_user, $this->profile->id); $outp_keywords = array(); foreach ($keywords as $keyword) { $outp_keywords[$keyword->id] = $keyword; } $outp_keywords = array_merge($outp_keywords, $new_keywords); $this->template->set('keywords', $outp_keywords); $this->template->set('errors', $errors); $this->template->set('configs', $configs); $this->template->render(); }
/** * Прослойка поиска * @param array $data * @return array */ private function _search(array $data) { $result = NULL; $validation = Validation::factory($data)->rule('str', 'not_empty')->rule('str', 'min_length', array(':value', 4)); if ($validation->check()) { // Обработка строки $search_str = trim(preg_replace('/ +/ ', ' ', preg_replace('/[^A-ZА-ЯЁ0-9]+/ui', ' ', mb_strtolower($validation['str'])))); // Выпиливание стоп-слов, слов короче 3 букв, не больше 7 слов $original_words = array_slice(array_diff(Arr::map('Controller_Search::clear_short_words', explode(' ', $search_str)), Kohana::$config->load('settings.search_stop_words')), 0, 7); // Поиск леммы $words = Arr::map('Controller_Search::stemm', $original_words); if (!empty($words)) { // ORM object $company = ORM::factory('service')->search($words, $original_words); $news = ORM::factory('news')->search($words, $original_words); $stocks = ORM::factory('stock')->search($words, $original_words); $vacancies = ORM::factory('vacancy')->search($words, $original_words); $types = array(); if (count($company->services) > 0) { $types['services'] = __('site_search_services'); } if (count($company->shops) > 0) { $types['shops'] = __('site_search_shops'); } if (count($news->companies) > 0) { $types['companies-news'] = __('services_news'); } if (count($news->world) > 0) { $types['news-world'] = __('world_news'); } if (count($news->portal) > 0) { $types['news-association'] = __('association_news'); } if (count($stocks) > 0) { $types['stocks'] = __('cb_stocks'); } if (count($vacancies) > 0) { $types['vacancies'] = __('cb_vacancies'); } $result = View::factory('frontend/search/result')->set('types', $types)->set('company', $company->company)->set('services', $company->services)->set('shops', $company->shops)->set('stocks', $stocks)->set('news', $news)->set('vacancies', $vacancies); } else { $this->errors[] = 'Ошибка поиска, возможно введены недопустимые слова'; } } else { $this->errors = $validation->errors('search_on_site'); } $this->values = $data; return $result; }
public function action_index() { $installation_status = Kohana::$config->load('install.status'); switch ($installation_status) { case NOT_INSTALLED: if (!$this->check_installation_parameters()) { //$data['title']=__('Installation: something wrong'); // $this->data=Arr::merge($this->data, Helper::get_db_settings()); $this->data = Arr::merge($this->data, get_object_vars($this->install_config)); $res = View::factory('install_form', $this->data)->render(); //Model::factory('model_name')->model_method( $data ); } else { $_post = Arr::map('trim', $_POST); $post = new Validation($_post); $post->rule('db_path', 'not_empty')->rule('db_name', 'not_empty')->rule('db_login', 'not_empty')->rule('installer_login', 'not_empty')->rule('installer_password', 'not_empty'); if ($post->check()) { Helper::save_install_settings($post); if (!Model::factory('install')->install($err_list)) { Helper::set_installation_status(NOT_INSTALLED); foreach ($err_list as $e) { $this->data['errors'][] = $e['error']; } $res = View::factory('installing', $this->data)->render(); } else { $res = View::factory('installing_ok', $this->data)->render(); } } else { // Кажется что-то случилось //$data['title']=__('Installation: something wrong'); $this->data['errors'] = $post->errors('validation'); $res = View::factory('install_form', $this->data)->render(); } } break; case INSTALLING: $res = View::factory('installing')->render(); break; case INSTALLED: // $res = View::factory('/')->render(); $this->redirect('/'); break; default: // $res = View::factory('/')->render(); $this->redirect('/'); break; } // Save result / Сохраняем результат $this->_result = $res; }
/** * Initializing method: Removes slashes from GPC. * * @return Recipe_Request_Adapter */ protected function init() { if ($this->hasMagicQuotes()) { if (is_array($_GET) && count($_GET) > 0) { $_GET = Arr::map("stripslashes", $_GET); } if (is_array($_POST) && count($_POST) > 0) { $_POST = Arr::map("stripslashes", $_POST); } if (is_array($_COOKIE) && count($_COOKIE) > 0) { $_COOKIE = Arr::map("stripslashes", $_COOKIE); } } return $this; }
function action_third() { $reg_status = $this->session->get('reg_status', NULL); if (empty($reg_status) and $reg_status['step'] != 3 and !isset($reg_status['service_id'])) { $this->request->redirect('/'); } $service = ORM::factory('service', $reg_status['service_id']); if ($service->user->id != $this->user->id or !$service->loaded()) { $this->request->redirect('/'); } $work_category = ORM::factory('workcategory'); $cars = ORM::factory('car_brand')->get_cars_as_array(); $discounts = ORM::factory('discount')->get_all_as_array(); if ($_POST) { $post = Arr::map('trim', $_POST); if (isset($post['skip'])) { Message::set(Message::SUCCESS, 'Вы успешно зарегистрировались, но не указали дополнительную информацию для фирмы. Вы можете сделать это в ' . HTML::anchor('cabinet', 'личном кабинете') . '.'); $this->session->delete('reg_status'); $this->request->redirect('cabinet'); } try { $service->values($post, array('about', 'work_times', 'discount_id', 'coupon_text')); $cars_input = Arr::get($_POST, 'model', array()); foreach ($cars_input as $c) { $service->add('cars', $c); } if ($service->type == 1) { $works_input = Arr::get($_POST, 'work', array()); foreach ($works_input as $w) { $service->add('works', $w); } } $service->update(); Message::set(Message::SUCCESS, 'Вы успешно зарегистрировались.'); $this->session->delete('reg_status'); $this->request->redirect('cabinet'); //throw ORM_Validation_Exception::text('') } catch (ORM_Validation_Exception $e) { $this->values = $post; $this->errors = $e->errors('models'); } } $reg_step_view = View::factory('frontend/auth/register/steps')->set('step', 3); $this->view = View::factory('frontend/auth/register/third')->set('type', $service->type)->set('discounts', $discounts)->set('work_category', $work_category)->set('auto_models', $cars)->set('values', $this->values)->set('errors', $this->errors)->set('reg_steps', $reg_step_view); $this->template->title = $this->site_name . __('s_reg_3_step'); $this->template->bc['#'] = 'Регистрация'; $this->template->content .= $this->view; }
public function action_edit() { $submitted = false; $id = $this->request->param('id'); if (!$id) { Request::current()->redirect('batch'); } $batch = ORM::factory('batch', $id); if ($this->request->method() === 'POST' && $this->request->post()) { if (Arr::get($this->request->post(), 'save') !== null) { $submitted = true; $safepost = Arr::map('Security::xss_clean', $this->request->post()); $validator = $batch->validator($safepost); if ($validator->check()) { $batch->name = Arr::get($safepost, 'name'); $batch->description = Arr::get($safepost, 'description'); $batch->save(); Session::instance()->set('success', 'Batch edited successfully.'); Request::current()->redirect('batch'); exit; } else { $this->_errors = $validator->errors('batch'); } } } Breadcrumbs::add(array('Batches', Url::site('batch'))); Breadcrumbs::add(array('Edit', Url::site('batch/edit/id/' . $id))); $this->form('batch/edit/id/' . $id, $submitted, array('name' => $batch->name, 'description' => $batch->description)); }
function action_login() { $this->view = View::factory('frontend/auth/login')->bind('values', $this->values)->bind('errors', $this->errors); if ($_POST) { $post = Arr::map('trim', $_POST); if ($this->auth->login($post['username'], $post['password'])) { $user = $this->auth->get_user(); // проверяем настройки доступа человека - не просрочен ли его аккаунт if ($user->user_type == 'unconfirmed') { $this->auth->logout(); Message::set(Message::NOTICE, 'Вы должны активировать ваш аккаунт'); $this->request->redirect('/auth/confirm_email'); } Message::set(Message::SUCCESS, 'Добро пожаловать!'); Logger::write(Logger::ACTION, 'Пользователь авторизовался', $user); $this->request->redirect('cabinet'); } else { Message::set(Message::ERROR, 'Неправильное имя пользователя или пароль'); } } $this->template->content = $this->view; }
public function action_edit() { $submitted = false; $id = $this->request->param('id'); if (!$id) { Request::current()->redirect('flashcard'); } $flashcard = ORM::factory('flashcard', $id); if ($this->request->method() === 'POST' && $this->request->post()) { if (Arr::get($this->request->post(), 'save') !== null) { $submitted = true; $safepost = Arr::map('Security::xss_clean', $this->request->post()); $validator = $flashcard->validator($safepost); if ($validator->check()) { $flashcard->title = Arr::get($safepost, 'title'); $flashcard->description = Arr::get($safepost, 'description'); $flashcard->course_id = Session::instance()->get('course_id'); $flashcard->save(); if (Arr::get($safepost, 'question_selected')) { Model_Flashcard::insert_flashcard_question($flashcard->id, Arr::get($safepost, 'question_selected')); } Session::instance()->set('success', 'Flashcard edited successfully.'); Request::current()->redirect('flashcard'); exit; } else { $this->_errors = $validator->errors('flashcard'); } } } Breadcrumbs::add(array('Edit', Url::site('flashcard/edit/id/' . $id))); $this->form('flashcard/edit/id/' . $id, $submitted, array('title' => $flashcard->title, 'description' => $flashcard->description)); }
/** * @param mixed $value * @return mixed */ public function escape($value) { if (is_array($value)) { return Arr::map(array($this, "escape"), $value); } return substr($this->pdo->quote($value), 1, -1); }
public function action_edit() { $submitted = false; $id = $this->request->param('id'); if (!$id) { Request::current()->redirect('examgroup'); } $examgroup = ORM::factory('examgroup', $id); if ($this->request->method() === 'POST' && $this->request->post()) { if (Arr::get($this->request->post(), 'save') !== null) { $submitted = true; $safepost = Arr::map('Security::xss_clean', $this->request->post()); $validator = $examgroup->validator($safepost); if ($validator->check()) { $examgroup->name = Arr::get($safepost, 'name'); $examgroup->save(); Session::instance()->set('success', 'Grading Period edited successfully.'); Request::current()->redirect('examgroup'); exit; } else { $this->_errors = $validator->errors('examgroup'); } } } $form = $this->form('examgroup/edit/id/' . $id, $submitted, array('name' => $examgroup->name)); $links = array('cancel' => Html::anchor('/examgroup/', 'or cancel')); $view = View::factory('examgroup/form')->bind('links', $links)->bind('form', $form); $this->content = $view; Breadcrumbs::add(array('Exams', Url::site('exam'))); Breadcrumbs::add(array('Grading Period', Url::site('examgroup'))); Breadcrumbs::add(array('Edit', Url::site('examgroup/edit/id/' . $id))); }
/** * Recursive version of [array_map](http://php.net/array_map), applies the * same callback to all elements in an array, including sub-arrays. * * // Apply "strip_tags" to every element in the array * $array = Arr::map('strip_tags', $array); * * [!!] Unlike `array_map`, this method requires a callback and will only map * a single array. * * @param mixed callback applied to every element in the array * @param array array to map * @return array */ public static function map($callback, $array) { foreach ($array as $key => $val) { if (is_array($val)) { $array[$key] = Arr::map($callback, $val); } else { $array[$key] = call_user_func($callback, $val); } } return $array; }
/** * * @test * @dataProvider provider_map */ public function test_map($method, $source, $expected) { $this->assertSame($expected, Arr::map($method, $source)); }
/** * @param mixed $value * @return mixed */ public function escape($value) { if (is_array($value)) { return Arr::map(array($this, "escape"), $value); } return $this->mysqli->real_escape_string($value); }
/** * Form with mentions keywords list */ public function index() { $this->load->config('site_config', TRUE); $keywords_config = $this->config->item('mention_keywords', 'site_config'); $config_count = isset($keywords_config['count']) && $keywords_config['count'] ? $keywords_config['count'] : 10; $availableKeywordsCount = $this->getAAC()->getPlanFeatureValue('brand_reputation_monitoring'); if ($availableKeywordsCount) { $config_count = $availableKeywordsCount; } $keywords = Mention_keyword::inst()->get_user_keywords($this->c_user->id, $this->profile->id); $new_keywords = array(); $errors = array(); $saved_ids = array(0); // '0' to prevent datamapper error caused by empty array $delete = true; if ($post = $this->input->post()) { unset($post['submit']); $grouped = Arr::collect($post); if ($availableKeywordsCount && count($grouped) > $config_count) { $planError = lang('keywords_count_error', [$config_count]); $errors[] = $planError; $delete = false; } else { foreach ($grouped as $id => $data) { if (empty($data['keyword'])) { continue; } if (strpos($id, 'new_') === 0) { $keyword = Mention_keyword::inst()->fill_from_array($data, $this->c_user->id, $this->profile->id); $new_keywords[$id] = $keyword; } else { $keyword = Mention_keyword::inst()->fill_from_array($data, $this->c_user->id, $this->profile->id, $id); if ($keyword->id !== $id) { $new_keywords[$id] = $keyword; } } if ($keyword->save()) { $saved_ids[] = $keyword->id; } else { $errors[$id] = $keyword->error->string; } } } if (empty($errors)) { if ($delete) { Mention_keyword::inst()->set_deleted($this->c_user->id, $this->profile->id, $saved_ids); } $this->addFlash(lang('keywords_saved_success'), 'success'); redirect('settings/mention_keywords'); } else { $this->addFlash(implode('<br>', Arr::map('strip_tags', $errors))); } } JsSettings::instance()->add(array('max_keywords' => $config_count)); CssJs::getInst()->c_js(); $outp_keywords = array(); foreach ($keywords as $keyword) { $outp_keywords[$keyword->id] = $keyword; } $outp_keywords = array_merge($outp_keywords, $new_keywords); $this->template->set('keywords', $outp_keywords); $this->template->set('errors', $errors); $this->template->set('config_count', $config_count); $this->template->render(); }
public function action_edit() { $submitted = false; $id = $this->request->param('id'); if (!$id) { Request::current()->redirect('link'); } $link = ORM::factory('link', $id); if ($this->request->method() === 'POST' && $this->request->post()) { if (Arr::get($this->request->post(), 'save') !== null) { $submitted = true; $safepost = Arr::map('Security::xss_clean', $this->request->post()); $validator = $link->validator($safepost); if ($validator->check()) { $link->title = Arr::get($safepost, 'title'); $link->description = Arr::get($safepost, 'description'); $link->image = Arr::get($safepost, 'image'); $link->url = Arr::get($safepost, 'url'); $link->course_id = Session::instance()->get('course_id'); $link->save(); Session::instance()->set('success', 'Link edited successfully.'); Request::current()->redirect('link'); exit; } else { $this->_errors = $validator->errors('link'); } } } Breadcrumbs::add(array('Edit', Url::site('link/edit/id/' . $id))); $this->form('link/edit/id/' . $id, $submitted, array('title' => $link->title, 'description' => $link->description, 'url' => $link->url, 'image' => $link->image), $link->image); }
public function action_post() { $text_message_error = false; // Берем новость $post = ORM::factory('blog')->where('url', '=', $this->request->param('path'))->find(); // Если пришло сообщение if ($_POST) { // Получаем сообщение $text_message = Arr::get($_POST, 'text_message'); // Получаем то, что запостили и убираем пробелы $validator = Validation::factory(Arr::map('trim', $_POST)); $validator->rule('text_message', 'not_empty'); // Если данные корректные if ($validator->check()) { // Добавляем сообщение на стену ORM::factory('message')->set('post_id', $post->id)->set('username', $this->user->username)->set('date', DB::expr('now()'))->set('text', $text_message)->save(); // Редиректим HTTP::redirect(Request::current()->uri()); } else { $text_message_error = true; //$content->errors = $post->errors('text_message'); } } if ($post->id) { // Получаем все сообщения по данной новости $messages = ORM::factory('message')->where('post_id', '=', $post->id)->order_by('id', 'DESC')->find_all(); $this->template->title = $post->name; $content = View::factory('post')->bind('messages', $messages)->bind('text_message_error', $text_message_error)->bind('post', $post); } $this->template->content = $content; }
/** * Recursive version of [array_map](http://php.net/array_map), applies the * same callback to all elements in an array, including sub-arrays. * * // Apply "strip_tags" to every element in the array * $array = Arr::map_recursive('strip_tags', $array); * * [!!] Unlike `array_map`, this method requires a callback and will only map * a single array. * * @param mixed callback applied to every element in the array * @param array array to map * @param array array of keys to apply to * @return array */ public static function map_recursive($callback, $array, $keys = NULL) { foreach ($array as $key => $val) { if (self::is_array($val)) { $array[$key] = Arr::map($callback, $array[$key]); } elseif (!is_array($keys) or in_array($key, $keys)) { //Removed kohana array of callback support, its stupid... use closures $array[$key] = call_user_func($callback, $array[$key]); } } return $array; }
public function install(&$err_list, $script_file_name = '') { $err_list = array(); if ($script_file_name == '') { $script_file_name = Kohana::$config->load('install.install_sql_script_name'); } Helper::set_installation_status(INSTALLING); $a = Helper::get_install_settings(); $link = @mysqli_connect($a['db_path'], $a['db_login'], $a['db_password'], $a['db_name']); if (!$link) { //throw new Exception($message, $code, $previous) $err_list[0]['error'] = __('Error connecting to MySQL') . ' №' . mysqli_connect_errno() . ': ' . mysqli_connect_error() . '.'; return false; } else { // mysqli_query($link,'SET NAMES utf8'); $i = 0; $a = file($script_file_name); $a = Arr::map('trim', $a); foreach ($a as $n => $l) { if (substr($l, 0, 2) == '--' or $l == '') { unset($a[$n]); } } $a = explode(";\n", implode("\n", $a)); //unset($a[count($a)-1]); foreach ($a as $n => $q) { if ($q) { if (!mysqli_query($link, $q)) { $err_list[$i]['errno'] = mysqli_errno($link); $err_list[$i]['sqlstate'] = mysqli_sqlstate($link); $err_list[$i]['error'] = mysqli_error($link); $i++; } } } $q = 'INSERT INTO `roles` (`id`, `name`, `description`) VALUES' . '(1, \'login\', \'Login privileges, granted after account confirmation\'),' . '(2, \'admin\', \'Administrative user, has access to everything.\');'; if (!mysqli_query($link, $q)) { $err_list[$i]['errno'] = mysqli_errno($link); $err_list[$i]['sqlstate'] = mysqli_sqlstate($link); $err_list[$i]['error'] = mysqli_error($link); $i++; } $install = Helper::get_install_settings(); $q = 'INSERT INTO users (id,username, password) VALUES (1,"' . $install['installer_login'] . '","' . Auth::instance()->hash($install['installer_password']) . '")'; if (!mysqli_query($link, $q)) { $err_list[$i]['errno'] = mysqli_errno($link); $err_list[$i]['sqlstate'] = mysqli_sqlstate($link); $err_list[$i]['error'] = mysqli_error($link); $i++; } $q = 'INSERT INTO `roles_users` (`user_id`, `role_id`) VALUES (1, 1),(1, 2);'; if (!mysqli_query($link, $q)) { $err_list[$i]['errno'] = mysqli_errno($link); $err_list[$i]['sqlstate'] = mysqli_sqlstate($link); $err_list[$i]['error'] = mysqli_error($link); $i++; } // @mysqli_multi_query($link,$c); // // while (mysqli_more_results($link)) { // $result = mysqli_next_result($link); // $discard = mysqli_store_result($link); // //if (!$result){ // if (mysqli_errno($link)){ // $err_list[$i]['errno']=mysqli_errno($link); // $err_list[$i]['sqlstate']=mysqli_sqlstate($link); // $err_list[$i]['error']=mysqli_error($link); // $i++; // } // } if ($i == 0) { Helper::set_installation_status(INSTALLED); } return $i == 0 ? true : false; } }
/** * Recursive version of [array_map](http://php.net/array_map), applies one or more * callbacks to all elements in an array, including sub-arrays. * * // Apply "strip_tags" to every element in the array * $array = Arr::map('strip_tags', $array); * * // Apply $this->filter to every element in the array * $array = Arr::map(array(array($this,'filter')), $array); * * // Apply strip_tags and $this->filter to every element * $array = Arr::map(array('strip_tags',array($this,'filter')), $array); * * [!!] Because you can pass an array of callbacks, if you wish to use an array-form callback * you must nest it in an additional array as above. Calling Arr::map(array($this,'filter'), $array) * will cause an error. * [!!] Unlike `array_map`, this method requires a callback and will only map * a single array. * * @param mixed $callbacks array of callbacks to apply to every element in the array * @param array $array array to map * @param array $keys array of keys to apply to * @return array */ public static function map($callbacks, $array, $keys = NULL) { foreach ($array as $key => $val) { if (is_array($val)) { $array[$key] = Arr::map($callbacks, $array[$key]); } elseif (!is_array($keys) or in_array($key, $keys)) { if (is_array($callbacks)) { foreach ($callbacks as $cb) { $array[$key] = call_user_func($cb, $array[$key]); } } else { $array[$key] = call_user_func($callbacks, $array[$key]); } } } return $array; }
$e = new Arr(); // print_r(Arr::mixins()); // print_r(Arr::methods()); $e[] = 'ing'; $e[] = 'cool'; $e[] = 'wow'; echo $e[99]; $e->default = 'TEST DEFAULT'; echo $e[99] . "\n"; foreach ($e as $k => $v) { echo $k . ' => ' . $v . "\n"; } echo "***COLLECT***\n"; print_r($e->collect('$key;')->array); echo "***ALIAS METHOD MAP***\n"; print_r($e->map('$key;')->array); if ($e->any('$key == 1;')) { echo "true\n"; } if ($e->any('$key == 4;')) { echo "true\n"; } echo "***INJECT***\n"; print_r($e->inject(array(), '$object["injected_$key"] = $value;$object;')); $e = new Hash(); $e['short'] = 4; $e['this is a longer one'] = 12; $e['this is long'] = 2; echo "***ARRAY***\n"; print_r($e->array); echo "***SORT***\n";