Example #1
8
 public static function dialplan($number)
 {
     $xml = Telephony::getDriver()->xml;
     $destination = $number['Destination'];
     if ($id = arr::get($destination, 'queue_id')) {
         $xml->update('/action[@application="callcenter"]{@data="queue_' . $id . '"}');
     }
 }
Example #2
0
File: oauth.php Project: rafi/oauth
 /**
  * Returns the output of a remote URL. Any [curl option](http://php.net/curl_setopt)
  * may be used.
  *
  *     // Do a simple GET request
  *     $data = Remote::get($url);
  *
  *     // Do a POST request
  *     $data = Remote::get($url, array(
  *         CURLOPT_POST       => TRUE,
  *         CURLOPT_POSTFIELDS => http_build_query($array),
  *     ));
  *
  * @param   string   remote URL
  * @param   array    curl options
  * @return  string
  * @throws  Kohana_Exception
  */
 public static function remote($url, array $options = NULL)
 {
     // The transfer must always be returned
     $options[CURLOPT_RETURNTRANSFER] = TRUE;
     // Open a new remote connection
     $remote = curl_init($url);
     // Set connection options
     if (!curl_setopt_array($remote, $options)) {
         throw new Kohana_Exception('Failed to set CURL options, check CURL documentation: :url', array(':url' => 'http://php.net/curl_setopt_array'));
     }
     // Get the response
     $response = curl_exec($remote);
     // @TODO: Find a better way to do this
     if (curl_errno($remote) == 60) {
         curl_setopt($remote, CURLOPT_CAINFO, arr::get(Kohana::find_file('config', 'ca-bundle', 'crt'), 0, ''));
         $response = curl_exec($remote);
     }
     // Get the response information
     $code = curl_getinfo($remote, CURLINFO_HTTP_CODE);
     if ($code and $code < 200 or $code > 299) {
         $error = $response;
     } elseif ($response === FALSE) {
         $error = curl_error($remote);
     }
     // Close the connection
     curl_close($remote);
     if (isset($error)) {
         throw new Kohana_OAuth_Exception('Error fetching remote :url [ status :code ] :error', array(':url' => $url, ':code' => $code, ':error' => $error));
     }
     return $response;
 }
Example #3
0
 public function action_index()
 {
     $code = $this->request->param('code');
     $message = arr::get(Response::$messages, $code);
     $this->template->title = sprintf('Error %s: %s', $code, $message);
     $this->response->status($code);
 }
Example #4
0
 public function action_login()
 {
     if ((bool) arr::get($_GET, 'return', false)) {
         site::set_last_url($this->request->referrer());
     }
     $error = false;
     if ($_POST) {
         $email = arr::get($_POST, 'email', '');
         $password = arr::get($_POST, 'password', '');
         $remember = arr::get($_POST, 'remember', '') == 'yes';
         if (user::login($email, $password, $remember)) {
             $user = user::get();
             notes::success('You have been logged in. Welcome back!');
             $lasturl = site::get_last_url();
             if ($lasturl) {
                 site::redirect($lasturl);
             }
             site::redirect('write');
         } else {
             //notes::error('Wrong username or password. Please try again.');
             $error = true;
         }
     }
     $this->bind('error', $error);
 }
Example #5
0
 public static function dropdown($data, $selected = NULL, $extra = '')
 {
     // standardize the $data as an array, strings default to the class_type
     if (!is_array($data)) {
         $data = array('name' => $data);
     }
     // add in all the defaults if they are not provided
     $defaults = array('null_option' => FALSE, 'default_first' => TRUE, 'unauth_before_auth' => FALSE);
     $data = arr::merge($defaults, $data);
     $options = array();
     $sipinterfaces = Doctrine::getTable('SipInterface')->findAll();
     foreach ($sipinterfaces as $sipinterface) {
         if (!($id = arr::get($sipinterface, 'sipinterface_id')) or !($name = arr::get($sipinterface, 'name'))) {
             continue;
         }
         if ($data['unauth_before_auth'] and !$sipinterface['auth'] or !$data['unauth_before_auth'] and $sipinterface['auth']) {
             arr::unshift_assoc($options, $id, $name);
             continue;
         }
         $options[$id] = $name;
     }
     if ($data['default_first'] and $default_sipinterface = SipInterface::get_default()) {
         unset($options[$default_sipinterface['sipinterface_id']]);
         arr::unshift_assoc($options, $default_sipinterface['sipinterface_id'], $default_sipinterface['name']);
     }
     if ($data['null_option']) {
         arr::unshift_assoc($options, 0, $data['null_option']);
     }
     $data = array_diff($data, $defaults);
     // use kohana helper to generate the markup
     return form::dropdown($data, $options, $selected, $extra);
 }
Example #6
0
 public function action_result()
 {
     $data = array();
     if ($_POST) {
         $id_brand = arr::get($_POST, 'id_brand');
         $id_model = arr::get($_POST, 'id_model');
         $id_series = arr::get($_POST, 'series');
         $year = arr::get($_POST, 'year');
         $to_number = arr::get($_POST, 'to_number');
         $millage_val = arr::get($_POST, 'millage_val');
         //$brands = ORM::factory('labor')->find_all();
         $brand = ORM::factory('brand', $id_brand)->name;
         $model = ORM::factory('model', $id_model)->name;
         $series = ORM::factory('series', $id_series)->as_array();
         $price = ORM::factory('price');
         $modification = new Model_Modification();
         $result = $modification->getModification($year, $id_series, $to_number);
         $labors = new Model_Labor();
         foreach ($result as $mod) {
             $labors_val[$mod['id']] = $labors->getLabors($mod['id'], $to_number)->as_array();
         }
         $calc_view = View::factory('forms/form.calculator')->set('id_brand', $id_brand)->set('id_model', $id_model)->set('id_series', $id_series)->set('year', $year)->set('millage_val', $millage_val)->set('modification', $result)->set('test', $modification)->set('to_number', $to_number);
         $this->template->content = View::factory('calculator.result')->set('brand', $brand)->set('model', $model)->set('year', $year)->set('series', $series)->set('millage_val', $millage_val)->set('modification', $result)->set('to_number', $to_number)->set('labors', $labors_val)->set('price', $price)->set('calculator_form', $calc_view->render());
     } else {
         HTTP::redirect('calculator');
     }
 }
Example #7
0
 protected function do_login()
 {
     if ($this->request->is_ajax() && $_POST) {
         $this->do_auth();
     }
     $this->template->set_layout('layout/admin/login');
     $this->template->email = '';
     $this->template->remember = false;
     $this->template->error = '';
     $this->template->return = arr::get($_GET, 'return', arr::get($_POST, 'return', FALSE));
     if (isset($_POST['login'])) {
         $email = $_POST['email'];
         $password = $_POST['password'];
         $remember = $_POST['remember'];
         $this->template->email = $email;
         $this->template->remember = $remember;
         if (Auth::instance()->login($email, $password, (bool) $remember)) {
             if ($this->template->return) {
                 HTTP::redirect($this->template->return);
             } else {
                 return TRUE;
             }
         }
         if (Auth::instance()->is_banned()) {
             $banned_to = Auth::instance()->get_banned_to();
             $this->template->error = 'Аккаунт заблокирован до ' . date('Y-m-d H:i', $banned_to) . ' (до разблокировки ' . ceil(($banned_to - time()) / 3600) . ' ч ' . date('i мин', $banned_to - time()) . ')';
         } else {
             $this->template->error = 'Неверные e-mail или пароль';
         }
         return FALSE;
     }
 }
Example #8
0
 protected static function tiers_POST($id, $envelope)
 {
     if (is_null($id)) {
         self::throwErrorAndDie('Invalid request', array($id), 410);
     }
     $data = self::requireData($envelope);
     $tier_agents = array();
     if ($agents = arr::get($data, 'agents')) {
         foreach ($agents as $agent) {
             if ($tier_agent_id = arr::get($agent, 'tier_agent_id')) {
                 $tier_agent = Doctrine::getTable('TierAgent')->findOneBy('tier_agent_id', $tier_agent_id);
             } else {
                 $tier_agent = new TierAgent();
             }
             try {
                 $tier_agent->synchronizeWithArray($agent);
                 $tier_agent->save();
                 $tier_agents[] = $tier_agent->toArray();
             } catch (Exception $e) {
                 self::throwErrorAndDie('Invalid data', Bluebox_Controller::$validation->errors(), 400);
             }
         }
         arr::remove('agents', $data);
         arr::merge($envelope['data'], $data);
     }
     $response = self::generalAPI_POST($id, 'tier_id', 'Tier', $envelope);
     $response['agents'] = $tier_agents;
     return $response;
 }
Example #9
0
 /**
  * Processes incoming text
  */
 public function action_index()
 {
     $this->request->headers['Content-type'] = 'image/png';
     // Grab text and styles
     $text = arr::get($_GET, 'text');
     $styles = $_GET;
     $hover = FALSE;
     try {
         // Create image
         $img = new PNGText($text, $styles);
         foreach ($styles as $key => $value) {
             if (substr($key, 0, 6) == 'hover-') {
                 // Grab hover associated styles and override existing styles
                 $hover = TRUE;
                 $styles[substr($key, 6)] = $value;
             }
         }
         if ($hover) {
             // Create new hover image and stack it
             $hover = new PNGText($text, $styles);
             $img->stack($hover);
         }
         echo $img->draw();
     } catch (Exception $e) {
         if (Kohana::config('pngtext.debug')) {
             // Dump error message in an image form
             $img = imagecreatetruecolor(strlen($e->getMessage()) * 6, 16);
             imagefill($img, 0, 0, imagecolorallocate($img, 255, 255, 255));
             imagestring($img, 2, 0, 0, $e->getMessage(), imagecolorallocate($img, 0, 0, 0));
             echo imagepng($img);
         }
     }
 }
Example #10
0
 public function validate(CM_Form_Abstract $form)
 {
     if ($this->_extra_validation) {
         $values = array();
         foreach ($form->get_values() as $name => $value) {
             $values[$name] = $value->get_raw();
             $this->_extra_validation->label($name, $form->get_field($name)->get_label());
         }
         // Validation только read-only, поэтому создаем новый объект
         $this->_extra_validation = $this->_extra_validation->copy($values);
     }
     try {
         $this->get_model()->check($this->_extra_validation);
     } catch (ORM_Validation_Exception $e) {
         $errors = $e->errors('validation');
         if ($external = arr::get($errors, '_external')) {
             $errors = arr::merge($errors, $external);
             unset($errors['_external']);
         }
         foreach ($errors as $name => $error) {
             $form->get_field($name)->set_error($error);
         }
         return FALSE;
     }
     return TRUE;
 }
Example #11
0
 public static function echo_test()
 {
     $featureCode = new FeatureCode();
     $featureCode['name'] = 'Echo Test';
     $featureCode['registry'] = array('feature' => 'echo');
     $featureCode->save();
     try {
         $location = Doctrine::getTable('Location')->findAll();
         if (!$location->count()) {
             throw Exception('Could not find location id');
         }
         $location_id = arr::get($location, 0, 'location_id');
         $number = new Number();
         $number['user_id'] = users::getAttr('user_id');
         $number['number'] = '9999';
         $number['location_id'] = $location_id;
         $number['registry'] = array('ignoreFWD' => '0', 'ringtype' => 'ringing', 'timeout' => 20);
         $dialplan = array('terminate' => array('transfer' => 0, 'voicemail' => 0, 'action' => 'hangup'));
         $number['dialplan'] = $dialplan;
         $number['class_type'] = 'FeatureCodeNumber';
         $number['foreign_id'] = $featureCode['feature_code_id'];
         $context = Doctrine::getTable('Context')->findOneByName('Outbound Routes');
         $number['NumberContext']->fromArray(array(0 => array('context_id' => $context['context_id'])));
         $numberType = Doctrine::getTable('NumberType')->findOneByClass('FeatureCodeNumber');
         if (empty($numberType['number_type_id'])) {
             return FALSE;
         }
         $number['NumberPool']->fromArray(array(0 => array('number_type_id' => $numberType['number_type_id'])));
         $number->save();
         return $number['number_id'];
     } catch (Exception $e) {
         kohana::log('error', 'Unable to initialize device number: ' . $e->getMessage());
         throw $e;
     }
 }
Example #12
0
 public function get_submitted_value()
 {
     $source = $this->get_value_source();
     $values = array();
     foreach ($source as $field_name => $field_value) {
         if (strpos($field_name, $this->get_name() . '_') === 0) {
             $num = str_replace($this->get_name() . '_', '', $field_name);
             // Нашли поле, отвечающее за имя
             if (preg_match('#^[0-9]+$#', $num)) {
                 $namefield = new CM_Field_String();
                 $namefield->set_name($field_name);
                 $namefield->set_value_source($this->get_value_source());
                 $name = $namefield->get_submitted_value()->get_raw();
                 $valuefield = clone $this->get_value_field();
                 $value = arr::get(array_values($this->get_value()->get_values()), $num);
                 if ($value) {
                     $value = $value->get_raw();
                 }
                 $valuefield->set_raw_value($value);
                 $valuefield->set_name($field_name . '_value');
                 $valuefield->set_value_source($this->get_value_source());
                 $values[$name] = $valuefield->get_submitted_value()->get_raw();
             }
         }
     }
     return $this->create_raw_value(serialize($values));
 }
Example #13
0
 public function action_files()
 {
     $files = array();
     $limit = arr::get($_GET, 'limit', 10);
     $offset = arr::get($_GET, 'offset', 0);
     $query = ORM::factory('File');
     if (arr::get($_GET, 'tags', false)) {
         $tags = arr::get($_GET, 'tags');
         if (arr::get($_GET, 'matchAll', false) == "true") {
             $tagsquery = DB::select('files_tags.file_id')->from('files_tags')->where('files_tags.tag_id', 'IN', $tags)->group_by('files_tags.file_id')->having(DB::expr('COUNT(files_tags.file_id)'), '=', count($tags))->execute();
             //die(var_dump($tagsquery));
         } else {
             $tagsquery = DB::select('files_tags.file_id')->distinct(true)->from('files_tags')->where('files_tags.tag_id', 'IN', $tags)->execute();
             //die(var_dump($tagsquery));
         }
         if ((bool) $tagsquery->count()) {
             $ids = array();
             foreach ($tagsquery as $q) {
                 $ids[] = arr::get($q, 'file_id');
                 //$files[] = ORM::factory('File', arr::get($q, 'file_id'))->info();
             }
             $query = $query->where('id', 'IN', $ids);
         } else {
             // Empty resultset
             ajax::success('ok', array('files' => array()));
         }
     }
     $query = $query->order_by('created', 'DESC')->limit($limit)->offset($offset)->find_all();
     if ((bool) $query->count()) {
         foreach ($query as $file) {
             $files[] = $file->info();
         }
     }
     ajax::success('ok', array('files' => $files));
 }
Example #14
0
 public function action_edit()
 {
     $file = ORM::factory('file', $this->request->param('id'));
     if (!$file->loaded()) {
         notes::add('error', 'Filen blev ikke fundet!');
         cms::redirect('files');
     }
     if ($_POST) {
         $filename = arr::get($_POST, 'filename', '');
         if (empty($filename)) {
             $filename = $file->filename;
         }
         if ($filename != $file->filename) {
             $filename = files::fixname($filename);
             $filename = files::get_available_filename('files/', $filename, $file->ext);
             rename('files/' . $file->filename(), 'files/' . $filename . '.' . $file->ext);
             $versions = $file->versions->find_all();
             if ((bool) $versions->count()) {
                 foreach ($versions as $version) {
                     $version->delete();
                 }
             }
         }
         $file->filename = $filename;
         $file->alt = arr::get($_POST, 'alt', '');
         $file->description = arr::get($_POST, 'description', '');
         try {
             $file->save();
             cms::redirect('files/edit/' . $file->id);
         } catch (exception $e) {
             notes::add('error', 'Filen kunne ikke gemmes! Siden sagde: ' . $e->getMessage());
         }
     }
     $this->bind('file', $file);
 }
Example #15
0
 public function human_readable_created($segments = 2)
 {
     $when = Date::span($this->created);
     $years = arr::get($when, 'years', 0);
     $months = arr::get($when, 'months', 0);
     $weeks = arr::get($when, 'weeks', 0);
     $days = arr::get($when, 'days', 0);
     $hours = arr::get($when, 'hours', 0);
     $minutes = arr::get($when, 'minutes', 0);
     $seconds = arr::get($when, 'seconds', 0);
     $str = array();
     if ($years > 0) {
         $str[] = $years . ' ' . ($years == 1 ? __('year') : __('years'));
     }
     if ($months > 0) {
         $str[] = $months . ' ' . ($months == 1 ? __('month') : __('months'));
     }
     if ($weeks > 0) {
         $str[] = $weeks . ' ' . ($weeks == 1 ? __('week') : __('weeks'));
     }
     if ($days > 0) {
         $str[] = $days . ' ' . ($days == 1 ? __('day') : __('days'));
     }
     if ($hours > 0) {
         $str[] = $hours . ' ' . ($hours == 1 ? __('hour') : __('hours'));
     }
     if ($minutes > 0) {
         $str[] = $minutes . ' ' . ($minutes == 1 ? __('minute') : __('minutes'));
     }
     if ($seconds > 0) {
         $str[] = $seconds . ' ' . ($seconds == 1 ? __('second') : __('secondss'));
     }
     $str = array_slice($str, 0, $segments);
     return implode(', ', $str);
 }
Example #16
0
 /**
  * Sets fields to the current object
  *
  * @param Array $fields
  */
 public function set_fields($fields)
 {
     $this->title = arr::get($fields, 'title');
     $this->description = arr::get($fields, 'description');
     $this->budget = arr::get($fields, 'budget');
     $this->category_id = arr::get($fields, 'category_id');
     $this->jobtype_id = arr::get($fields, 'jobtype_id');
     $this->contact = arr::get($fields, 'contact');
     $this->telecommute = arr::get($fields, 'telecommute', 0);
     $this->location = arr::get($fields, 'location', 'Anywhere');
     $this->highlight = arr::get($fields, 'highlight', 0);
     $this->company_logo = arr::get($fields, 'company_logo');
     $this->email = arr::get($fields, 'email');
     $this->discount_code = arr::get($fields, 'discount_code');
     $this->created_at = arr::get($fields, 'created_at');
     $this->jobboard_id = arr::get($fields, 'jobboard_id', 1);
     $this->active = 0;
     if (arr::get($fields, 'private_company') == 1) {
         $this->company_name = '';
         $this->company_url = '';
         $this->company_address = '';
     } else {
         $this->company_name = arr::get($fields, 'company_name');
         $this->company_url = arr::get($fields, 'company_url');
         $this->company_address = arr::get($fields, 'company_address');
     }
 }
Example #17
0
 public static function delete($trunk)
 {
     if ($interfaceId = arr::get($trunk, 'plugins', 'sipinterface', 'sipinterface_id')) {
         $xml = FreeSwitch::setSection('gateway', 'sipinterface_' . $interfaceId, 'trunk_' . $trunk['trunk_id']);
         $xml->deleteNode();
     }
 }
Example #18
0
 public function action_rid()
 {
     if (!user::logged()) {
         ajax::error('You must be logged in to see this.', array('problem' => 'auth'));
     }
     $user = user::get();
     $langs = array(1 => 'english', 17 => 'french', 19 => 'german', 22 => 'hungarian', 34 => 'portugese');
     $userlang = $user->option('language');
     if (!key_exists($userlang, $langs)) {
         ajax::error('We currently only have RID data available for English, French, German, Hungarian and Portugese.', array('problem' => 'data'));
     }
     $page = ORM::factory('Page', arr::get($_POST, 'id', ''));
     if (!$page->loaded() || !$page->user_id == $user->id) {
         ajax::error('That page wasn\'t found!');
     }
     if ($page->rid == '') {
         require Kohana::find_file('vendor/rid', 'rid');
         $rid = new RID();
         $rid->load_dictionary(Kohana::find_file('vendor/rid', $langs[$userlang], 'cat'));
         $data = $rid->analyze($page->content());
         $vals = array();
         $colors = array('#B0BF1A', '#7CB9E8', '#C9FFE5', '#B284BE', '#5D8AA8', '#00308F', '#00308F', '#AF002A', '#F0F8FF', '#E32636', '#C46210', '#EFDECD', '#E52B50', '#AB274F', '#F19CBB', '#3B7A57', '#FFBF00', '#FF7E00', '#FF033E', '#9966CC', '#A4C639', '#CD9575', '#665D1E', '#915C83', '#841B2D', '#FAEBD7', '#008000', '#8DB600', '#FBCEB1', '#00FFFF', '#7FFFD4', '#4B5320', '#3B444B', '#8F9779', '#E9D66B', '#B2BEB5', '#87A96B', '#FF9966', '#A52A2A', '#FDEE00', '#6E7F80', '#568203', '#007FFF');
         $i = 0;
         foreach ($data->category_percentage as $key => $val) {
             $vals[] = array('value' => $val, 'label' => $key, 'color' => $colors[$i]);
             $i++;
         }
         $page->rid = serialize($vals);
         $page->save();
     }
     ajax::success('ok', array('data' => unserialize($page->rid)));
 }
Example #19
0
 public static function pagination($numresults, $url, $limit = 20)
 {
     $page = (int) arr::get($_GET, 'p', 1);
     $page = $page - 1;
     if ($page < 0) {
         $page = 0;
     }
     $numpages = ceil($numresults / $limit);
     if ($page > $numpages) {
         $page = $numpages;
     }
     $offset = $limit * $page;
     $pagination = '';
     if ($numpages > 1) {
         $pagination .= '<ul class="pagination">';
         if (strpos($url, '?')) {
             $url .= '&p=';
         } else {
             $url .= '?p=';
         }
         for ($i = 1; $i <= $numpages; $i++) {
             $pagination .= '<li class="' . ($page + 1 == $i ? 'active' : '') . '"><a href="' . $url . $i . '">' . $i . '</a></li>';
         }
         $pagination .= '<ul>';
     }
     return $pagination;
 }
Example #20
0
 public function action_index()
 {
     $view = View::factory('kadldap/index');
     $this->template->content = $view;
     $this->template->title = 'Kadldap';
     $this->template->menu = NULL;
     $this->template->breadcrumb = array(Route::get('docs/guide')->uri() => __('User Guide'), Route::get('docs/guide')->uri() . '/kadldap.about' => $this->template->title, 'Configuration Test');
     $view->message = FALSE;
     if (isset($_POST['login'])) {
         $post = Validate::factory($_POST)->filter(TRUE, 'trim')->rule('username', 'not_empty')->rule('username', 'min_length', array(1))->rule('password', 'not_empty');
         if ($post->check()) {
             $username = $post['username'];
             $password = arr::get($post, 'password', '');
             try {
                 if (Auth::instance()->login($username, $password)) {
                     $view->message = 'Successful login.';
                 } else {
                     $view->message = 'Login failed.';
                 }
             } catch (adLDAPException $e) {
                 $view->message = $e->getMessage();
             }
         } else {
             $view->message = 'You must enter both your username and password.';
         }
     }
     if (Auth::instance()->logged_in()) {
         $username = Auth::instance()->get_user();
         $password = Auth::instance()->password($username);
         $view->kadldap = Kadldap::instance();
         $view->kadldap->authenticate($username, $password);
     }
 }
Example #21
0
 public function action_ajax_add_feedback()
 {
     if ($_POST) {
         $errors = array('name' => 'false', 'text' => 'false', 'email' => 'false', 'check' => 'false', 'phone' => 'false');
         if (Validation::factory($_POST)->rule('email', 'email')->rule('email', 'not_empty')->check()) {
             $errors['email'] = 'true';
         }
         if (Validation::factory($_POST)->rule('phone', 'not_empty')->check()) {
             $errors['phone'] = 'true';
         }
         if (Validation::factory($_POST)->rule('name', 'not_empty')->check()) {
             $errors['name'] = 'true';
         }
         if (Validation::factory($_POST)->rule('text', 'not_empty')->check()) {
             $errors['text'] = 'true';
         }
         $check = arr::get($_POST, 'check');
         if (!$check) {
             $errors['check'] = 'true';
         }
         if ($errors['name'] == 'true' && $errors['email'] == 'true' && $errors['phone'] == 'true' && $errors['text'] == 'true' && $errors['check'] == 'true') {
             $feedback = ORM::factory('Feedback');
             $feedback->name = arr::get($_POST, 'name');
             $feedback->phone = arr::get($_POST, 'phone');
             $feedback->email = arr::get($_POST, 'email');
             $feedback->text = arr::get($_POST, 'text');
             $feedback->save();
             Email::send('*****@*****.**', array('*****@*****.**', 'Trip-Shop'), 'Новый отзыв', 'Имя - ' . arr::get($_POST, 'name') . '<br/>' . 'Email - ' . arr::get($_POST, 'email') . '<br/>' . 'Телефон - ' . arr::get($_POST, 'phone') . '<br/>' . arr::get($_POST, 'text'), true);
         }
         echo json_encode($errors);
     } else {
         $this->forward_404();
     }
 }
Example #22
0
 private function get_file_info($file)
 {
     $filesize = 0;
     $fileParts = parse_url($file);
     $path = arr::get($fileParts, 'path');
     $path = substr_replace($path, '', 0, 1);
     $path = urldecode($path);
     $pathParts = explode('/', $path);
     $name = end($pathParts);
     if (is_file(PUBLIC_ROOT . $path)) {
         $filesize = filesize(PUBLIC_ROOT . $path) / 1000;
     }
     $mbSize = $filesize / 1000;
     $type = 'KB';
     if ($mbSize > 1) {
         $filesize = $mbSize;
         $type = 'MB';
     }
     $fileType = 'file';
     try {
         $exifImageType = @exif_imagetype(PUBLIC_ROOT . $path);
         if ($exifImageType > 0 && $exifImageType < 18) {
             $fileType = 'image';
         }
     } catch (Exception $e) {
     }
     return array('type' => $type, 'size' => round($filesize, 2, PHP_ROUND_HALF_UP), 'name' => $name, 'file_type' => $fileType);
 }
 public function action_index()
 {
     if ($_POST) {
         $message = html::chars((string) arr::get($_POST, 'message', ''));
         if ($message) {
             // Append user information
             if ($user = $this->auth->get_user()) {
                 $message .= '<h2>Användarinfo</h2>';
                 $message .= '<dl>';
                 foreach (array('id', 'username', 'email') as $field) {
                     $message .= sprintf('<dt>%s</dt><dd>%s</dd>', $field, html::chars($user->{$field}));
                 }
                 $message .= '</dl>';
             }
             $from = arr::extract($_POST, array('e-mail', 'name'));
             if (!Validate::email($from['e-mail'])) {
                 $from['name'] .= " ({$from['e-mail']})";
                 $from['e-mail'] = '*****@*****.**';
             }
             $sent = Email::send('*****@*****.**', array($from['e-mail'], $from['name']), '[Änglarna Stockholm] Meddelande från kontaktsidan', $message, TRUE);
             if ($sent >= 1) {
                 $this->message_add('Ditt meddelande har skickats till ' . html::mailto('*****@*****.**') . '!');
             } else {
                 $this->message_add('Något blev fel. Försök igen eller skicka ett vanligt mail till ' . html::mailto('*****@*****.**') . ' istället.', 'error');
             }
         } else {
             $this->message_add('Du måste ange ett meddelande.', 'error');
         }
         $this->request->reload();
     }
     $this->template->title = 'Kontakta Änglarna Stockholm';
     $this->template->content = View::factory('kontakt/index');
 }
Example #24
0
 /**
  *
  * Returns the locale.
  * If $ext is true, the UTF8 extension gets returned as well, otherwise, just the language code.
  * Defaults to true.
  *
  * @return 							The locale
  * @param boolean $ext[optional]	Get the Extension?
  */
 public static function get_locale($ext = true)
 {
     if ($ext) {
         return I18n::$locale;
     } else {
         return arr::get(explode('.', I18n::$locale), 0);
     }
 }
Example #25
0
 public function render_value()
 {
     $options = $this->get_options();
     if (isset($options[''])) {
         unset($options['']);
     }
     return arr::get($options, (string) $this->get_value());
 }
Example #26
0
 public function get_roles_rendered()
 {
     $roles_rendered = array();
     foreach ($this->get_roles_list() as $role) {
         $roles_rendered[] = arr::get(Kohana::$config->load('auth')->roles_labels, $role, $role);
     }
     return implode(', ', $roles_rendered);
 }
Example #27
0
 public function __construct($status = 404, $message = NULL, array $values = NULL, $code = 0)
 {
     $this->_status = $status;
     if (!$message) {
         $message = arr::get(Request::$messages, $status);
     }
     parent::__construct($message, $values, $code);
 }
Example #28
0
 public static function create($data)
 {
     $user = ORM::factory('User');
     $user->create_user($data, array('username', 'password', 'email'));
     $user->add_role('login');
     $mail = mail::create('usercreated')->to($user->email)->tokenize(array('username' => $user->username))->send();
     user::login(arr::get($data, 'email', ''), arr::get($data, 'password', ''));
 }
Example #29
0
 public function action_index()
 {
     $url = $this->param('url');
     if (preg_match('|.html|', arr::get($_SERVER, 'REQUEST_URI'))) {
         $url .= '.html';
     }
     $this->set_metatags_and_content($url);
 }
Example #30
0
 public function construct_form(CM_Form_Abstract $form, $params)
 {
     $this->set_model($params);
     foreach ($form->get_field_names() as $name) {
         if ($label = arr::get($this->get_model()->labels(), $name)) {
             $form->get_field($name)->set_label($label);
         }
     }
 }