Example #1
0
 /**
  * Validate project quota offset param used for display formatting.
  *
  * @param HTTPRequest $request HTTP request
  *
  * @return Integer
  */
 private function validateOffset(HTTPRequest $request)
 {
     $valid = new Valid('offset');
     $valid->setErrorMessage('Invalid offset submitted. Force it to 0 (zero).');
     $valid->addRule(new Rule_Int());
     $valid->addRule(new Rule_GreaterOrEqual(0));
     if ($request->valid($valid)) {
         $offset = $request->get('offset');
     } else {
         $offset = 0;
     }
     return $offset;
 }
Example #2
0
 private function _login()
 {
     $array = $this->request->post('login');
     $array = Validation::factory($array)->label('username', 'Username')->label('password', 'Password')->label('email', 'Email')->rules('username', array(array('not_empty')))->rules('password', array(array('not_empty')));
     $fieldname = Valid::email(Arr::get($array, 'username')) ? Auth::EMAIL : Auth::USERNAME;
     // Get the remember login option
     $remember = isset($array['remember']);
     Observer::notify('admin_login_validation', $array);
     if ($array->check()) {
         Observer::notify('admin_login_before', $array);
         if (Auth::instance()->login($array['username'], $array['password'], $remember)) {
             Observer::notify('admin_login_success', $array['username']);
             Session::instance()->delete('install_data');
             Kohana::$log->add(Log::INFO, ':user login')->write();
             if ($next_url = Flash::get('redirect')) {
                 $this->go($next_url);
             }
             // $this->go to defaut controller and action
             $this->go_backend();
         } else {
             Observer::notify('admin_login_failed', $array);
             Messages::errors(__('Login failed. Please check your login data and try again.'));
             $array->error($fieldname, 'incorrect');
             Kohana::$log->add(Log::ALERT, 'Try to login with :field: :value. Incorrect data', array(':field' => $fieldname, ':value' => $array['username']))->write();
         }
     } else {
         Messages::errors($array->errors('validation'));
     }
     $this->go(Route::get('user')->uri(array('action' => 'login')));
 }
Example #3
0
 public function __construct($loggly_input_key)
 {
     if (!Valid::exact_length($loggly_input_key, self::LOGGLY_KEY_LENGTH)) {
         throw new Kohana_Exception('Loggly input key must be exactly :length characters long.', [':length' => self::LOGGLY_KEY_LENGTH]);
     }
     $this->_loggly_input_key = $loggly_input_key;
 }
Example #4
0
File: Util.php Project: Konro1/pms
 public static function download($url, $directory, $filename = NULL)
 {
     $url = str_replace(' ', '%20', $url);
     if (!Valid::url($url)) {
         return FALSE;
     }
     $curl = curl_init($url);
     $file = Upload_Util::combine($directory, uniqid());
     $handle = fopen($file, 'w');
     $headers = new HTTP_Header();
     curl_setopt($curl, CURLOPT_FILE, $handle);
     curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
     curl_setopt($curl, CURLOPT_HEADERFUNCTION, array($headers, 'parse_header_string'));
     if (curl_exec($curl) === FALSE or curl_getinfo($curl, CURLINFO_HTTP_CODE) !== 200) {
         fclose($handle);
         unlink($file);
         throw new Kohana_Exception('Curl: Download Error: :error, status :status on url :url', array(':url' => $url, ':status' => curl_getinfo($curl, CURLINFO_HTTP_CODE), ':error' => curl_error($curl)));
     }
     fclose($handle);
     if ($filename === NULL) {
         if (!isset($headers['content-disposition']) or !($filename = Upload_Util::filename_from_content_disposition($headers['content-disposition']))) {
             $mime_type = curl_getinfo($curl, CURLINFO_CONTENT_TYPE);
             $url = urldecode(curl_getinfo($curl, CURLINFO_EFFECTIVE_URL));
             $filename = Upload_Util::filename_from_url($url, $mime_type);
         }
     }
     $filename = substr(pathinfo($filename, PATHINFO_FILENAME), 0, 60) . '.' . pathinfo($filename, PATHINFO_EXTENSION);
     $result_file = Upload_Util::combine($directory, $filename);
     rename($file, $result_file);
     return is_file($result_file) ? $filename : FALSE;
 }
Example #5
0
 /**
  * Parse a remote feed into an array.
  *
  * @param   string   $feed   Remote feed URL
  * @param   integer  $limit  Item limit to fetch [Optional]
  *
  * @return  array
  *
  * @uses    Valid::url
  */
 public function parse($feed, $limit = 0)
 {
     // Make limit an integer
     $limit = (int) $limit;
     // Disable error reporting while opening the feed
     $error_level = error_reporting(0);
     // Allow loading by filename or raw XML string
     $load = (is_file($feed) or Valid::url($feed)) ? 'simplexml_load_file' : 'simplexml_load_string';
     // Load the feed
     $feed = $load($feed, 'SimpleXMLElement', LIBXML_NOCDATA);
     // Restore error reporting
     error_reporting($error_level);
     // Feed could not be loaded
     if (!$feed) {
         return array();
     }
     $namespaces = $feed->getNamespaces(TRUE);
     // This only for RSS 1.0/2.0 are supported
     $feed = $feed->xpath('//item');
     $i = 0;
     $items = array();
     foreach ($feed as $item) {
         if ($limit > 0 and $i++ === $limit) {
             break;
         }
         $item_fields = (array) $item;
         // get namespaced tags
         foreach ($namespaces as $ns) {
             $item_fields += (array) $item->children($ns);
         }
         $items[] = $item_fields;
     }
     return $items;
 }
Example #6
0
 /**
  * Render content.
  *
  * @return  string
  */
 public function content()
 {
     ob_start();
     // Stamp
     echo HTML::time(Date('l ', $this->event->stamp_begin) . Date::format('DDMMYYYY', $this->event->stamp_begin), $this->event->stamp_begin, true);
     // Location
     if ($this->event->venue) {
         echo ' @ ', HTML::anchor(Route::model($this->event->venue), HTML::chars($this->event->venue->name)), ', ', HTML::chars($this->event->venue->city_name);
     } elseif ($this->event->venue_name) {
         echo ' @ ', $this->event->venue_url ? HTML::anchor($this->event->venue_url, $this->event->venue_name) : HTML::chars($this->event->venue_name), $this->event->city_name ? ', ' . HTML::chars($this->event->city_name) : '';
     } elseif ($this->event->city_name) {
         echo ' @ ', HTML::chars($this->event->city_name);
     }
     // Flyer
     if ($this->event->flyer_front) {
         echo '<figure>', HTML::image($this->event->flyer_front->get_url(Model_Image::SIZE_THUMBNAIL)), '</figure>';
     } elseif ($this->event->flyer_back) {
         echo '<figure>', HTML::image($this->event->flyer_back->get_url(Model_Image::SIZE_THUMBNAIL)), '</figure>';
     } elseif (Valid::url($this->event->flyer_front_url)) {
         echo '<br /><figure>', HTML::image($this->event->flyer_front_url, array('width' => 160)), '</figure>';
     }
     // Favorites
     if ($this->event->favorite_count) {
         echo '<span class="stats"><i class="icon-heart"></i> ' . $this->event->favorite_count . '</span>';
     }
     return ob_get_clean();
 }
Example #7
0
 /**
  * CRUD controller: UPDATE
  */
 public function action_update()
 {
     $this->template->title = __('Update') . ' ' . __($this->_orm_model) . ' ' . $this->request->param('id');
     $form = new FormOrm($this->_orm_model, $this->request->param('id'));
     if ($this->request->post()) {
         if ($success = $form->submit()) {
             if (Valid::email($form->object->email, TRUE)) {
                 //check we have this email in the DB
                 $user = new Model_User();
                 $user = $user->where('email', '=', Kohana::$_POST_ORIG['formorm']['email'])->where('id_user', '!=', $this->request->param('id'))->limit(1)->find();
                 if ($user->loaded()) {
                     Alert::set(Alert::ERROR, __('A user with the email you specified already exists'));
                 } else {
                     $form->save_object();
                     Alert::set(Alert::SUCCESS, __('Item updated') . '. ' . __('Please to see the changes delete the cache') . '<br><a class="btn btn-primary btn-mini ajax-load" href="' . Route::url('oc-panel', array('controller' => 'tools', 'action' => 'cache')) . '?force=1" title="' . __('Delete cache') . '">' . __('Delete cache') . '</a>');
                     $this->redirect(Route::get($this->_route_name)->uri(array('controller' => Request::current()->controller())));
                 }
             } else {
                 Alert::set(Alert::ERROR, __('Invalid Email'));
             }
         } else {
             Alert::set(Alert::ERROR, __('Check form for errors'));
         }
     }
     return $this->render('oc-panel/pages/user/update', array('form' => $form));
 }
Example #8
0
 public function set_values(array $data)
 {
     if (!Valid::url($data['next_url'])) {
         $data['next_url'] = NULL;
     }
     $data['fields'] = array();
     if (!empty($data['field']) and is_array($data['field'])) {
         foreach ($data['field'] as $key => $values) {
             foreach ($values as $index => $value) {
                 if ($index == 0) {
                     continue;
                 }
                 if ($key == 'source') {
                     $value = URL::title($value, '_');
                 }
                 $data['fields'][$index][$key] = $value;
             }
         }
         $data['field'] = NULL;
     }
     $email_type_fields = array();
     foreach ($data['fields'] as $field) {
         $email_type_fields['key'][] = $field['id'];
         $email_type_fields['value'][] = !empty($field['name']) ? $field['name'] : Inflector::humanize($field['id']);
     }
     $this->create_email_type($email_type_fields);
     return parent::set_values($data);
 }
Example #9
0
File: info.php Project: anqh/anqh
 /**
  * Render content.
  *
  * @return  string
  */
 public function content()
 {
     ob_start();
     // Cover
     if (Valid::url($this->track->cover)) {
         echo HTML::image($this->track->cover, array('class' => 'cover img-responsive', 'alt' => __('Cover')));
     }
     // Time
     if ($this->track->size_time) {
         echo '<i class="fa fa-fw fa-clock-o"></i> ' . $this->track->size_time . '<br />';
     }
     // Listen count
     if ($this->track->listen_count > 1) {
         echo '<i class="fa fa-fw fa-play"></i> ' . ($this->track->listen_count == 1 ? __(':count play', array(':count' => $this->track->listen_count)) : __(':count plays', array(':count' => $this->track->listen_count))) . '<br />';
     }
     // Tags
     if ($tags = $this->track->tags()) {
         echo '<i class="fa fa-fw fa-music"></i> ' . implode(', ', $tags) . '<br />';
     } elseif (!empty($this->track->music)) {
         echo '<i class="fa fa-fw fa-music"></i> ' . $this->track->music . '<br />';
     }
     // Meta
     echo '<footer class="meta text-muted">';
     echo __('Added :date', array(':date' => HTML::time(Date::format(Date::DMY_SHORT, $this->track->created), $this->track->created)));
     echo '</footer>';
     return ob_get_clean();
 }
Example #10
0
 public function set_rss_url($url)
 {
     if (!Valid::url($url)) {
         return NULL;
     }
     return $url;
 }
Example #11
0
 /**
  * @return	void
  */
 public function action_index()
 {
     $this->template->content->active = "options";
     $session = Session::instance();
     // Check for post
     if ($this->request->method() === "POST") {
         $bucket_name = trim($this->request->post('bucket_name'));
         // Check for updates to the bucket name
         if (Valid::not_empty($bucket_name) and strcmp($bucket_name, $this->bucket['name']) !== 0) {
             $bucket_id = $this->bucket['id'];
             $parameters = array('name' => $bucket_name, 'public' => (bool) $this->request->post('bucket_publish'));
             //
             if (($bucket = $this->bucket_service->modify_bucket($bucket_id, $parameters, $this->user)) != FALSE) {
                 $session->set('message', __("Bucket settings successfully saved"));
                 // Reload the settings page using the updated bucket name
                 $this->redirect($bucket['url'] . '/settings', 302);
             } else {
                 $session->set('error', __("The bucket settings could not be updated"));
             }
         }
     }
     // Set the messages and/or error messages
     $this->template->content->set('message', $session->get('message'))->set('error', $session->get('error'));
     $this->settings_content = View::factory('pages/bucket/settings/display')->bind('bucket', $this->bucket)->bind('collaborators_view', $collaborators_view);
     // Collaboraotors view
     $collaborators_view = View::factory('/template/collaborators')->bind('fetch_url', $fetch_url)->bind('collaborator_list', $collaborators);
     $fetch_url = $this->bucket_base_url . '/collaborators';
     $collaborators = json_encode($this->bucket_service->get_collaborators($this->bucket['id']));
     $session->delete('message');
     $session->delete('error');
 }
Example #12
0
 /**
  * Send x copies of the registered item to a user.
  *
  * @param integer|Model_User $user
  * @param integer            $amount
  * @param string             $location
  *
  * @throws Item_Exception
  */
 public function to_user($user, $origin = "app", $amount = 1, $location = 'inventory')
 {
     if (!Valid::digit($amount)) {
         throw new Item_Exception('The supplied amount should be a number.');
     }
     if (Valid::digit($user)) {
         $user = ORM::factory('User', $user);
     } elseif (!is_a($user, 'Model_User')) {
         throw new Item_Exception('The supplied user does not come from a model.');
     }
     if (!$user->loaded()) {
         throw new Item_Exception('The supplied user does not exist.');
     } else {
         $user_item = ORM::factory('User_Item')->where('user_id', '=', $user->id)->where('item_id', '=', $this->_item->id)->where('location', '=', $location)->find();
         $action = $amount > 0 ? '+' : '-';
         if ($user_item->loaded()) {
             // update item amount
             $user_item->amount($action, $amount);
         } elseif ($action == '+') {
             $id = $this->_item->id;
             // create new copy
             $user_item = ORM::factory('User_Item')->values(array('user_id' => $user->id, 'item_id' => $id, 'location' => $location, 'amount' => $amount))->save();
         }
         return Journal::log('item.in.' . $origin, 'item', 'Player received :amount :item_name @ :origin', array(':amount' => $amount, ':item_name' => $user_item->item->name($amount, FALSE), ':origin' => str_replace('.', ' ', $origin)));
     }
 }
Example #13
0
 public function on_page_load()
 {
     $email_ctx_id = $this->get('email_id_ctx', 'email');
     $email = $this->_ctx->get($email_ctx_id);
     $referrer_page = Request::current()->referrer();
     $next_page = $this->get('next_url', Request::current()->referrer());
     if (!Valid::email($email)) {
         Messages::errors(__('Use a valid e-mail address.'));
         HTTP::redirect($referrer_page);
     }
     $user = ORM::factory('user', array('email' => $email));
     if (!$user->loaded()) {
         Messages::errors(__('No user found!'));
         HTTP::redirect($referrer_page);
     }
     $reflink = ORM::factory('user_reflink')->generate($user, 'forgot', array('next_url' => URL::site($this->next_url, TRUE)));
     if (!$reflink) {
         Messages::errors(__('Reflink generate error'));
         HTTP::redirect($referrer_page);
     }
     Observer::notify('admin_login_forgot_before', $user);
     try {
         Email_Type::get('user_request_password')->send(array('username' => $user->username, 'email' => $user->email, 'reflink' => Route::url('reflink', array('code' => $reflink)), 'code' => $reflink));
         Messages::success(__('Email with reflink send to address set in your profile'));
     } catch (Exception $e) {
         Messages::error(__('Something went wrong'));
     }
     HTTP::redirect($next_page);
 }
Example #14
0
 /**
  *  获取校验结果
  * @return type
  */
 public static function getVerifyResult()
 {
     $context = new Context();
     $typhoon = new Typhoon();
     if ($typhoon->isValid()) {
         $ssid = $typhoon->_ssid;
         $name = $typhoon->_name;
         $value = $context->get($name, '');
         if ($value != '') {
             if ($typhoon->_request_type == 1) {
                 $ret = Valid::sendVerifyRemoteRequest($ssid, $value, $typhoon->_diff_time);
             } else {
                 $ret = Valid::sendVerifyLocalRequest($ssid, $value);
             }
             self::$_result = Valid::getResult();
             self::$_code = Valid::getCode();
             self::$_details = Valid::getDetails();
         } else {
             self::$_result = 0;
             self::$_code = 'E_VALUEEMPTY_001';
             self::$_details = '验证码不可以为空';
         }
     } else {
         self::$_result = 0;
         self::$_code = 'E_PARAM_001';
         self::$_details = '重要参数传递错误';
     }
     return self::$_result === 1 ? TRUE : FALSE;
 }
Example #15
0
 public function isValid($Validation_data)
 {
     $errors = [];
     foreach ($Validation_data as $name => $value) {
         if (isset($_REQUEST[$name])) {
             $exploded = explode(':', $value);
             switch ($exploded[0]) {
                 case 'min':
                     $min = $exploded[1];
                     if (Valid::string()->length(3)->validate($_REQUEST[$name]) == false) {
                         $errors[] = "{$name} must be {$min} caracters long";
                     }
                     break;
                 case 'email':
                     if (Valid::email()->validate($_REQUEST[$name]) == false) {
                         $errors[] = $name . ' is not a valid email';
                     }
                     break;
                 case 'equalsTo':
                     $field = $exploded[1];
                     if (!Valid::equals($name)->validate($field)) {
                         $errors[] = $name . " must be equal to " . $field;
                     }
                     break;
             }
         }
     }
     return $errors;
 }
Example #16
0
 /**
  * [action_form] generates the form to pay at paypal
  */
 public function action_pay()
 {
     $this->auto_render = FALSE;
     $order_id = $this->request->param('id');
     $order = new Model_Order();
     $order->where('id_order', '=', $order_id)->where('status', '=', Model_Order::STATUS_CREATED)->limit(1)->find();
     if ($order->loaded()) {
         // case when selling advert
         if ($order->id_product == Model_Order::PRODUCT_AD_SELL) {
             $paypal_account = $order->ad->paypal_account();
             $currency = i18n::get_intl_currency_symbol();
             if (isset($order->ad->cf_shipping) and Valid::numeric($order->ad->cf_shipping) and $order->ad->cf_shipping > 0) {
                 $order->amount = $order->amount + $order->ad->cf_shipping;
             }
         } else {
             $paypal_account = core::config('payment.paypal_account');
             $currency = core::config('payment.paypal_currency');
         }
         $paypal_url = Core::config('payment.sandbox') ? Paypal::url_sandbox_gateway : Paypal::url_gateway;
         $paypal_data = array('order_id' => $order_id, 'amount' => number_format($order->amount, 2, '.', ''), 'site_name' => core::config('general.site_name'), 'site_url' => URL::base(TRUE), 'paypal_url' => $paypal_url, 'paypal_account' => $paypal_account, 'paypal_currency' => $currency, 'item_name' => $order->description);
         $this->template = View::factory('paypal', $paypal_data);
         $this->response->body($this->template->render());
     } else {
         Alert::set(Alert::INFO, __('Order could not be loaded'));
         $this->redirect(Route::url('default'));
     }
 }
Example #17
0
 public function action_index()
 {
     $code = $this->request->param('code');
     if ($code === NULL) {
         Model_Page_Front::not_found();
     }
     $reflink_model = ORM::factory('user_reflink', $code);
     if (!$reflink_model->loaded()) {
         Messages::errors(__('Reflink not found'));
         $this->go_home();
     }
     $next_url = Arr::get($reflink_model->data, 'next_url');
     try {
         Database::instance()->begin();
         Reflink::factory($reflink_model)->confirm();
         $reflink_model->delete();
         Database::instance()->commit();
     } catch (Kohana_Exception $e) {
         Database::instance()->rollback();
         Messages::errors($e->getMessage());
     }
     if (Valid::url($next_url)) {
         $this->go($next_url);
     }
     $this->go_home();
 }
Example #18
0
 public function action_stats()
 {
     $data = array();
     $errors = array();
     $filter = Session::instance()->get('statFilter', array());
     if ($this->isPressed('btnFilter')) {
         $filter['FIO'] = Arr::get($_POST, 'FIO');
         $filter['dateFrom'] = Arr::get($_POST, 'dateFrom');
         $filter['dateTo'] = Arr::get($_POST, 'dateTo');
         Session::instance()->set('statFilter', $filter);
         if ($filter['dateFrom'] != '' && !Valid::mydate($filter['dateFrom'])) {
             $errors['dateFrom'] = 'Дата должна быть в формате dd.mm.yyyy';
         }
         if ($filter['dateTo'] != '' && !Valid::mydate($filter['dateTo'])) {
             $errors['dateTo'] = 'Дата должна быть в формате dd.mm.yyyy';
         }
     }
     $material_id = $this->request->param('id', NULL);
     $material = ORM::factory('material', $material_id);
     $data['materialName'] = $material->materialName;
     $data['stats'] = $material->getStats($material_id, $filter);
     $data['count'] = count($data['stats']);
     $data['filter'] = $filter;
     $data['errors'] = $errors;
     $this->tpl->content = View::factory('materials/stats', $data);
 }
Example #19
0
 public function action_create()
 {
     try {
         if (!Valid::email(core::request('email'))) {
             $this->_error(__('Invalid email'), 501);
         } elseif (!is_numeric(core::request('id_product'))) {
             $this->_error(__('Invalid product'), 501);
         } else {
             $product = new Model_Product(core::request('id_product'));
             if ($product->loaded()) {
                 $user = Model_User::create_email(core::request('email'), core::request('name'));
                 $order = Model_Order::new_order($user, $product);
                 $order->confirm_payment(core::request('paymethod', 'API'), core::request('txn_id'), core::request('pay_date'), core::request('amount'), core::request('currency'), core::request('fee'));
                 //adding the notes
                 $order->notes = core::request('notes');
                 $order->save();
                 $this->rest_output(array('order' => self::get_order_array($order)));
             } else {
                 $this->_error(__('Something went wrong'), 501);
             }
         }
     } catch (Kohana_HTTP_Exception $khe) {
         $this->_error($khe);
     }
 }
Example #20
0
 /**
  * Handles setting of columns
  * Overriding this method to handle WKT Geometry value
  *
  * @param  string $column Column name
  * @param  mixed  $value  Column value
  * @throws Kohana_Exception
  * @return ORM
  */
 public function set($column, $value)
 {
     // Convert to WKT Point
     if ($column == 'value' and is_array($value) and array_key_exists('lat', $value) and Valid::numeric($value['lat']) and array_key_exists('lon', $value) and Valid::numeric($value['lon'])) {
         $value = strtr("POINT(lon lat)", $value);
     }
     return parent::set($column, $value);
 }
Example #21
0
 /**
  * Returns LogReader static url.
  * 
  * @return  string
  * @uses    URL::base()
  */
 public static function static_base()
 {
     if (Valid::url(static::$config->get_static_route())) {
         return static::$config->get_static_route() . '/';
     } else {
         return URL::base(Request::current()) . static::$config->get_static_route() . '/';
     }
 }
Example #22
0
 /**
  * return string
  */
 public function default_value()
 {
     if (Valid::date($this->default)) {
         return date($this->_format, strtotime($this->default));
     } else {
         return FALSE;
     }
 }
Example #23
0
 public static function check_link($link)
 {
     if (strpos($link, '//') !== FALSE) {
         return Valid::url($link);
     } elseif (strpos($link, '/') === 0) {
         return TRUE;
     }
 }
Example #24
0
 public function action_user_contact()
 {
     $ad = new Model_Ad($this->request->param('id'));
     //message to user
     if ($ad->loaded() and $this->request->post()) {
         $user = new Model_User($ad->id_user);
         //require login to contact
         if ((core::config('advertisement.login_to_contact') == TRUE or core::config('general.messaging') == TRUE) and !Auth::instance()->logged_in()) {
             Alert::set(Alert::INFO, __('Please, login before contacting'));
             HTTP::redirect(Route::url('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle)));
         }
         if (captcha::check('contact')) {
             //check if user is loged in
             if (Auth::instance()->logged_in()) {
                 $email_from = $this->user->email;
                 $name_from = $this->user->name;
             } else {
                 $email_from = core::post('email');
                 $name_from = core::post('name');
             }
             //akismet spam filter
             if (!core::akismet($name_from, $email_from, core::post('message'))) {
                 if (core::config('general.messaging')) {
                     //price?
                     $price = (core::post('price') !== NULL and is_numeric(core::post('price'))) ? core::post('price') : NULL;
                     $ret = Model_Message::send_ad(core::post('message'), $this->user, $ad->id_ad, $price);
                 } else {
                     if (isset($_FILES['file'])) {
                         $file = $_FILES['file'];
                     } else {
                         $file = NULL;
                     }
                     //contact email is set use that one
                     if (isset($ad->cf_contactemail) and Valid::email($ad->cf_contactemail)) {
                         $to = $ad->cf_contactemail;
                     } else {
                         $to = NULL;
                     }
                     $ret = $user->email('user-contact', array('[EMAIL.BODY]' => core::post('message'), '[AD.NAME]' => $ad->title, '[EMAIL.SENDER]' => $name_from, '[EMAIL.FROM]' => $email_from, '[URL.AD]' => Route::url('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle))), $email_from, $name_from, $file, $to);
                 }
                 //if succesfully sent
                 if ($ret) {
                     Alert::set(Alert::SUCCESS, __('Your message has been sent'));
                     // we are updating field of visit table (contact)
                     Model_Visit::contact_ad($ad->id_ad);
                 } else {
                     Alert::set(Alert::ERROR, __('Message not sent'));
                 }
                 HTTP::redirect(Route::url('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle)));
             } else {
                 Alert::set(Alert::SUCCESS, __('This email has been considered as spam! We are sorry but we can not send this email.'));
             }
         } else {
             Alert::set(Alert::ERROR, __('Captcha is not correct'));
             HTTP::redirect(Route::url('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle)));
         }
     }
 }
Example #25
0
 protected function validate($value)
 {
     if (!is_scalar($value)) {
         return 'scalar';
     }
     if (!Valid::max_length($value, 255)) {
         return 'max_length';
     }
 }
Example #26
0
 protected function validate($value)
 {
     if (!Valid::digit($value)) {
         return 'digit';
     }
     if (!$this->repo->exists($value)) {
         return 'exists';
     }
 }
Example #27
0
 public function check_code($value)
 {
     $_site_type = empty($this->_original_values['type']) ? $this->_object['type'] : $this->_original_values['type'];
     if ($_site_type === 'master') {
         return !Valid::not_empty($value);
     } else {
         return Valid::not_empty($value);
     }
 }
Example #28
0
 /**
  * Check an email address for correct format.
  *
  * @param   string   email address
  * @param   boolean  strict RFC compatibility and valid domain with MX
  * @return  boolean
  */
 public static function email($email, $strict = FALSE)
 {
     //strict validation
     if ($strict === TRUE) {
         //check the RFC compatibility and MX
         return parent::email($email, TRUE) ? Valid::email_domain($email) : FALSE;
     } else {
         return parent::email($email);
     }
 }
Example #29
0
 public static function validate_material_amounts($validation, $materials, $amount_key = 'amount', $name_key = 'name')
 {
     $status = TRUE;
     foreach ($materials as $material) {
         if (!Valid::digit($material[$amount_key])) {
             $status = $false;
             $validation->error('materials', $material[$name_key] . '\'s amount should be a number.');
         }
     }
     return $status;
 }
Example #30
0
 /**
  * Parses a remote feed into an array.
  *
  * @param   string  $feed   remote feed URL
  * @param   integer $limit  item limit to fetch
  * @param   integer $cache_expire_time in seconds when cache expires
  * @return  array
  */
 public static function parse($feed, $limit = 0, $cache_expire_time = NULL)
 {
     //in case theres no expire time set to 24h
     if ($cache_expire_time === NULL) {
         $cache_expire_time = 24 * 60 * 60;
     }
     // Check if SimpleXML is installed
     if (!function_exists('simplexml_load_file')) {
         throw new Kohana_Exception('SimpleXML must be installed!');
     }
     // Make limit an integer
     $limit = (int) $limit;
     // Disable error reporting while opening the feed
     $error_level = error_reporting(0);
     // Allow loading by filename or raw XML string
     if (Valid::url($feed)) {
         //mod! force usage of curl with timeout and cached!
         $feed_result = Core::cache($feed, NULL, $cache_expire_time);
         //not cached :(
         if ($feed_result === NULL) {
             $feed_result = Core::curl_get_contents($feed, 5);
             Core::cache($feed, $feed_result, $cache_expire_time);
         }
         $feed = $feed_result;
     } elseif (is_file($feed)) {
         // Get file contents
         $feed = file_get_contents($feed);
     }
     // Load the feed
     $feed = simplexml_load_string($feed, 'SimpleXMLElement', LIBXML_NOCDATA);
     // Restore error reporting
     error_reporting($error_level);
     // Feed could not be loaded
     if ($feed === FALSE) {
         return array();
     }
     $namespaces = $feed->getNamespaces(TRUE);
     // Detect the feed type. RSS 1.0/2.0 and Atom 1.0 are supported.
     $feed = isset($feed->channel) ? $feed->xpath('//item') : $feed->entry;
     $i = 0;
     $items = array();
     foreach ($feed as $item) {
         if ($limit > 0 and $i++ === $limit) {
             break;
         }
         $item_fields = (array) $item;
         // get namespaced tags
         foreach ($namespaces as $ns) {
             $item_fields += (array) $item->children($ns);
         }
         $items[] = $item_fields;
     }
     return $items;
 }