Esempio n. 1
0
 function __get($key)
 {
     if (arr::has($this->_properties, $key)) {
         return $this->_properties[$key];
     }
     return null;
 }
Esempio n. 2
0
 public function index()
 {
     // Create new session
     $this->session->create();
     $this->template->header->this_page = 'alerts';
     $this->template->content = new View('alerts');
     // Display news feeds?
     $this->template->content->allow_feed = Kohana::config('settings.allow_feed');
     // Retrieve default country, latitude, longitude
     $default_country = Kohana::config('settings.default_country');
     // Retrieve Country Cities
     $this->template->content->cities = $this->_get_cities($default_country);
     // Setup and initialize form field names
     $form = array('alert_mobile' => '', 'alert_mobile_yes' => '', 'alert_email' => '', 'alert_email_yes' => '', 'alert_lat' => '', 'alert_lon' => '', 'alert_radius' => '');
     // Copy the form as errors, so the errors will be stored with keys
     // corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $form_saved = FALSE;
     // If there is a post and $_POST is not empty
     if ($post = $this->input->post()) {
         // Create a new alert
         $alert = ORM::factory('alert');
         // Test to see if things passed the rule checks
         if ($alert->validate($post)) {
             // Yes! everything is valid
             // Save alert and send out confirmation code
             if (!empty($post->alert_mobile)) {
                 $this->_send_mobile_alert($post->alert_mobile, $post->alert_lon, $post->alert_lat, $post->alert_radius);
             }
             if (!empty($post->alert_email)) {
                 $this->_send_email_alert($post->alert_email, $post->alert_lon, $post->alert_lat, $post->alert_radius);
             }
             $this->session->set('alert_mobile', $post->alert_mobile);
             $this->session->set('alert_email', $post->alert_email);
             url::redirect('alerts/confirm');
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('alerts'));
             $form_error = TRUE;
         }
     } else {
         $form['alert_lat'] = Kohana::config('settings.default_lat');
         $form['alert_lon'] = Kohana::config('settings.default_lon');
         $form['alert_radius'] = 20;
     }
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     // Javascript Header
     $this->template->header->map_enabled = TRUE;
     $this->template->header->js = new View('alerts_js');
     $this->template->header->js->default_map = Kohana::config('settings.default_map');
     $this->template->header->js->default_zoom = Kohana::config('settings.default_zoom');
     $this->template->header->js->latitude = $form['alert_lat'];
     $this->template->header->js->longitude = $form['alert_lon'];
 }
Esempio n. 3
0
 /**
  * Show latest PER_PAGE news on page
  * @return void
  */
 public function index($module = NULL, $page = 1)
 {
     $this->set_title(Kohana::lang('search.search'));
     if ($page == 1) {
         $this->add_breadcrumb(Kohana::lang('search.the_best_results'), url::current());
     } else {
         $this->add_breadcrumb(Kohana::lang('search.page_no') . ' ' . $page, url::current());
     }
     // Default values
     $form = array('value' => '');
     $errors = array();
     if ($_POST) {
         $post = new Validation($_POST);
         // Some filters
         $post->pre_filter('trim', TRUE);
         // Rules
         $post->add_rules('value', 'required');
         if ($post->validate()) {
             $form = arr::overwrite($form, $post->as_array());
         } else {
             // Repopulate form with error and original values
             $form = arr::overwrite($form, $post->as_array());
             $errors = $post->errors('search_errors');
         }
     }
     $this->template->content = new View('search');
     $data = $this->products->search($post['value']);
     $data2 = $this->page->search($post['value']);
     $data3 = $this->news->search($post['value']);
     $this->template->content->data = $data;
     $this->template->content->data2 = $data2;
     $this->template->content->data3 = $data3;
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
 }
Esempio n. 4
0
 public function __construct($options = array())
 {
     $default = array("width" => "100", "height" => "100", "images" => array(), "class" => "square_thumb", "view" => null, "thickbox" => true);
     $config = Kohana::config_load('zest');
     $config = arr::overwrite($default, $config['gallery']);
     $this->config = arr::overwrite($config, $options);
 }
Esempio n. 5
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');
     }
 }
Esempio n. 6
0
 private function _get_valid_accinfo($old_pass)
 {
     $form = array('txt_old_pass' => '', 'txt_new_pass' => '', 'txt_cf_new_pass' => '', 'txt_email' => '');
     $errors = $form;
     if ($_POST) {
         $post = new Validation($_POST);
         $post->pre_filter('trim', TRUE);
         if (!empty($old_pass)) {
             $post->add_rules('txt_new_pass', 'required', 'length[6,50]');
             $post->add_rules('txt_cf_new_pass', 'matches[txt_new_pass]');
             $post->add_callbacks('txt_old_pass', array($this, '_check_old_pass'));
         }
         $post->add_rules('txt_email', 'required', 'email');
         $post->add_callbacks('txt_email', array($this, '_check_email'));
         if ($post->validate()) {
             $form = arr::overwrite($form, $post->as_array());
             return $form;
         } else {
             $form = arr::overwrite($form, $post->as_array());
             $this->session->set_flash('input_data', $form);
             $errors = arr::overwrite($errors, $post->errors('account_validation'));
             $str_error = '';
             foreach ($errors as $id => $name) {
                 if ($name) {
                     $str_error .= $name . '<br>';
                 }
             }
             $this->session->set_flash('error_msg', $str_error);
             url::redirect($this->uri->segment(1));
             die;
         }
     }
 }
Esempio n. 7
0
 public function add()
 {
     $form = array('building_id' => '', 'name' => '', 'index' => '', 'img_uri' => '', 'active' => '');
     $errors = $form;
     if ($_POST) {
         $post = new Validation($_POST);
         $post->pre_filter('trim', true);
         $post->add_rules('buildings_id', 'required', 'digit');
         $post->add_rules('name', 'required');
         $post->add_rules('index', 'required');
         $post->add_rules('img_uri', 'required');
         $post->add_rules('active', 'required');
         if ($post->validate()) {
             // check for invilid
             $form = arr::overwrite($form, $post->as_array());
             $people = new Person_Model();
             $result = $people->save($this->input->get('person'), $person_id);
         } else {
             $form = arr::overwrite($form, $post->as_array());
             client::validation_results(arr::overwrite($errors, $post->errors('hiring_employee_form_validations')));
             client::messageSend("There were errors in some fields", E_USER_WARNING);
         }
     }
     $building = new Building_Model();
     $buildings_list = $building->select_list();
     $this->template->title = 'Seating::Spaces::Add';
     $this->template->content = new View('pages/spaces_add');
     $this->template->content->form = $form;
     $this->template->content->buildings_list = $buildings_list;
 }
Esempio n. 8
0
 public function login()
 {
     $form = $errors = array("user" => "", "password" => "");
     $post = new Validation($_POST);
     $post->add_rules("user", "required");
     $post->add_rules("password", "required");
     if ($valid = $post->validate()) {
         try {
             $token = G3Remote::instance()->get_access_token($post["user"], $post["password"]);
             Session::instance()->set("g3_client_access_token", $token);
             $response = G3Remote::instance()->get_resource("gallery");
             $valid = true;
             $content = $this->_get_main_view($response->resource);
         } catch (Exception $e) {
             Kohana_Log::add("error", Kohana_Exception::text($e));
             $valid = false;
         }
     }
     if (!$valid) {
         $content = new View('login.html');
         $content->form = arr::overwrite($form, $post->as_array());
         $content->errors = arr::overwrite($errors, $post->errors());
     }
     $this->auto_render = false;
     print json_encode(array("status" => $valid ? "ok" : "error", "content" => (string) $content));
 }
Esempio n. 9
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);
 }
Esempio n. 10
0
 public static function ignoreLogLevels($ignore)
 {
     if (!is_array($ignore)) {
         $ignore = array($ignore);
     }
     self::$ignore = arr::merge(self::$ignore, $ignore);
 }
Esempio n. 11
0
 public function __construct($config = array())
 {
     // Set the config
     $this->config = $config;
     // Set a filename, if we don't have one
     if (str::e($this->config['filename'])) {
         $this->config['filename'] = date("Y-m-d_g-ia");
     }
     // Build driver class
     $driver = "Export_Driver_" . trim(strtoupper($config['driver']));
     // Load the driver
     if (!Eight::auto_load($driver)) {
         throw new Export_Exception('export.driver_not_supported', $config['driver']);
     }
     // Initialize the driver
     $this->driver = new $driver($this->config);
     // Validate the driver
     if (!$this->driver instanceof Export_Driver) {
         throw new Export_Exception('export.driver_not_supported', 'Export drivers must use the Export_Driver interface.');
     }
     // Set the columns
     if (!arr::e($this->config['columns'])) {
         $this->driver->set_columns($this->config['columns']);
     }
 }
Esempio n. 12
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
     $data += array('nullOption' => 'Account Default');
     $data = arr::update($data, 'class', ' callid_dropdown');
     // see if the module wants to allow null selections
     if (!empty($data['nullOption'])) {
         $options = array('0' => $data['nullOption']);
     } else {
         $options = array();
     }
     unset($data['nullOption']);
     // build an array of netlists sutable for the dropdown helper
     $numbers = Doctrine_Query::create()->from('Number n')->Where('LENGTH(n.number) >= 10 ')->execute(array(), Doctrine::HYDRATE_ARRAY);
     foreach ($numbers as $number) {
         $matches = array();
         preg_match('/^\\+?1?([2-9][0-8][0-9])([2-9][0-9][0-9])([0-9]{4})$/', $number['number'], $matches);
         if (count($matches) == 4) {
             $options[$number['number_id']] = '( ' . $matches[1] . ' ) ' . $matches[2] . ' - ' . $matches[3];
         } else {
             $options[$number['number_id']] = $number['number'];
         }
     }
     return form::dropdown($data, $options, $selected, $extra);
 }
Esempio n. 13
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;
 }
Esempio n. 14
0
 public static function dropdownUserType($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
     $data += array('nullOption' => FALSE);
     // append or insert the class
     $data = arr::update($data, 'class', 'user_type_dropdown');
     // render a null option if its been set in data
     if (!empty($data['nullOption'])) {
         $options = array(0 => $data['nullOption']);
     } else {
         $options = array();
     }
     unset($data['nullOption']);
     $userTypes = self::getUserTypes();
     foreach ($userTypes as $userType => $displayName) {
         if ($userType <= users::getAttr('user_type')) {
             $options[$userType] = $displayName;
         }
     }
     // use kohana helper to generate the markup
     return form::dropdown($data, $options, $selected, $extra);
 }
Esempio n. 15
0
 /**
  * @brief Constructor
  *
  * @param String $algo The algorithm
  */
 public function __construct($algo)
 {
     $algo = strtolower($algo);
     // Check for support
     if (extension_loaded('hash')) {
         // We got the hashing support, so let's check if the algorithm is
         // supported.
         if (arr::hasValue(hash_algos(), $algo)) {
             $this->module = self::MOD_HASH;
             $this->algo = $algo;
             return;
         }
     }
     if (extension_loaded('mhash')) {
         // No hash support but mhash support, can it handle the algorithm?
         $num = mhash_count();
         for ($i = 0; $i <= $num; $i++) {
             if (mhash_get_hash_name($i) == $algo) {
                 $this->module = self::MOD_MHASH;
                 $this->algo = $algo;
                 return;
             }
         }
     }
     // Fall back on legacy spport here, is the algorithm one of the
     // by php supported ones?
     if (arr::hasValue(array('md5', 'sha1', 'crc32'), $algo)) {
         $this->module = self::MOD_PHP;
         $this->algo = $algo;
         return;
     }
     // No support, throw exception
     throw new SecurityException("Request for unsupported hash algorithm");
 }
Esempio n. 16
0
 /**
  * Pops back to previous directory
  */
 public static function pop_dir()
 {
     if (!arr::e(self::$dir_stack)) {
         $dir = array_pop(self::$dir_stack);
         chdir($dir);
     }
 }
Esempio n. 17
0
 private function _get_frm_valid()
 {
     $rdo_type = 'image';
     $file_ext = 'jpg,jpeg,gif,png';
     $form = array('hd_id' => '', 'attach_image' => '', 'txt_width' => '', 'txt_height' => '', 'sel_status' => '');
     $errors = $form;
     if ($_POST) {
         $post = new Validation(array_merge($_FILES, $_POST));
         $post->add_rules('attach_' . $rdo_type, 'upload::type[' . $file_ext . ']', 'upload::size[10M]');
         $post->add_rules('txt_width', 'digit');
         $post->add_rules('txt_height', 'digit');
         if ($post->validate()) {
             $form = arr::overwrite($form, $post->as_array());
             return $form;
         } else {
             $errors = $post->errors('banner_validation');
             $str_error = '';
             foreach ($errors as $id => $name) {
                 if ($name) {
                     $str_error .= $name . '<br>';
                 }
             }
             $this->session->set_flash('error_msg', $str_error);
             url::redirect($this->site['history']['current']);
             die;
         }
     }
 }
Esempio n. 18
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);
     }
 }
Esempio n. 19
0
 private function _get_frm_valid()
 {
     $hd_id = $this->input->post('hd_id');
     $form = $this->data_template_model->get_frm();
     $errors = $form;
     if ($_POST) {
         $post = new Validation($_POST);
         $post->pre_filter('trim', TRUE);
         $post->add_rules('txt_name', 'required', 'length[1,200]');
         $post->add_rules('txt_content', 'required');
         if ($post->validate()) {
             $form = arr::overwrite($form, $post->as_array());
             return $form;
         } else {
             $form = arr::overwrite($form, $post->as_array());
             $errors = arr::overwrite($errors, $post->errors('account_validation'));
             $str_error = '';
             foreach ($errors as $id => $name) {
                 if ($name) {
                     $str_error .= $name . '<br>';
                 }
             }
             $this->session->set_flash('error_msg', $str_error);
             if ($hd_id) {
                 url::redirect('admin_emailtemplate/edit/' . $hd_id);
             }
             die;
         }
     }
 }
Esempio n. 20
0
 public function actionSelect($field = '', $dir = '')
 {
     $dir = empty($dir) ? zotop::get('dir') : $dir;
     $dir = trim(url::decode($dir), '/');
     $path = site::template();
     $path = $path . DS . str_replace('/', DS, $dir);
     $path = path::clean($path);
     $folders = folder::folders($path);
     $files = folder::files($path);
     $position = '<a href="' . zotop::url('system/template/select') . '">' . zotop::t('根目录') . '</a><em> : //</em> ';
     if (!empty($dir)) {
         $dirs = arr::dirpath($dir, '/');
         foreach ($dirs as $d) {
             $position .= '<a href="' . zotop::url('system/template/select', array('dir' => rawurlencode($d[1]))) . '">' . $d[0] . '</a> <em>/</em>';
         }
     }
     $page = new dialog();
     $page->title = zotop::t('模板管理');
     $page->set('field', $field);
     $page->set('dir', $dir);
     $page->set('position', $position);
     $page->set('folders', $folders);
     $page->set('files', $files);
     $page->display();
 }
Esempio n. 21
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)));
 }
Esempio n. 22
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));
 }
Esempio n. 23
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);
 }
Esempio n. 24
0
 static function all($keys)
 {
     $keys = arr::explode($keys);
     $data = array();
     foreach ($keys as $k) {
         $key = substr($k, 1);
         switch ($k[0]) {
             case '+':
                 $data[$key] = self::int($key);
                 break;
             case '~':
                 $data[$key] = self::val($key);
                 break;
             case '*':
                 $data[$key] = self::txt($key);
                 break;
             case '@':
                 $data[$key] = self::time($key);
                 break;
             case '#':
                 $data[$key] = self::arr($key);
                 break;
             default:
                 $data[$k] = self::str($k);
         }
     }
     return $data;
 }
Esempio n. 25
0
 /**
  * Returns the formatted html
  *
  * html example
  * e.g <h1>{TITLE}</h1><h2>{DATE}</h2><h3>by {AUTHOR}</h3>{IMAGE}{TEXT}<div class="spacer">&nbsp;</div>
  *
  * @param   array	$options	Options for the rendering array('count', 'date_format','image' = array($width,$height), 'word_count', 'html')
  * @return	string	$html		Formatted HTML
  */
 public function render_summary($options = null, $feedpost_options = null)
 {
     $array = array('per_page' => 5, 'pagination' => 'classic', 'template' => 'feed', 'html' => '{FEEDPOSTS}{PAGINATION}');
     if (!$options) {
         $config = Kohana::config_load('zest');
         $options = $config['feed.summary'];
     }
     $array = arr::overwrite($array, $options);
     $uri = uri::instance();
     $page = $uri->segment('page', 1);
     $feedposts = "";
     $posts = $this->get_posts($array['per_page'], ($page - 1) * $array['per_page']);
     foreach ($posts as $post) {
         $feedposts .= $post->render_summary($feedpost_options);
     }
     $pagination = new Pagination(array('uri_segment' => 'page', 'total_items' => count($this->get_posts()), 'items_per_page' => $array['per_page'], 'style' => $array['pagination']));
     if ($array['template'] != '') {
         $html = zest::template_to_html('snippets/' . $array['template']);
     } else {
         $html = $array['html'];
     }
     $html = str_replace("{RSS_LINK}", $this->get_rss(), $html);
     $html = str_replace("{FEEDPOSTS}", $feedposts, $html);
     $html = str_replace("{PAGINATION}", $pagination, $html);
     $html = str_replace("{FEED_LINK}", $this->get_url(), $html);
     return $html;
 }
Esempio n. 26
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();
     }
 }
Esempio n. 27
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);
 }
Esempio n. 28
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;
 }
Esempio n. 29
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);
         }
     }
 }
Esempio n. 30
0
 public function html_element()
 {
     // Import base data
     $data = $this->data;
     // Get the options and default selection
     $time = $this->time_array(arr::remove('value', $data));
     // No labels or values
     unset($data['label']);
     $input = '';
     foreach ($this->parts as $type => $val) {
         if (is_int($type)) {
             // Just add the separators
             $input .= $val;
             continue;
         }
         // Set this input name
         $data['name'] = $this->data['name'] . '[' . $type . ']';
         // Set the selected option
         $selected = $time[$type];
         if ($type == 'am_pm') {
             // Options are static
             $options = array('AM' => 'AM', 'PM' => 'PM');
         } else {
             // minute(s), hour(s), etc
             $type .= 's';
             // Use the date helper to generate the options
             $options = empty($val) ? date::$type() : call_user_func_array(array('date', $type), $val);
         }
         $input .= form::dropdown($data, $options, $selected);
     }
     return $input;
 }