Example #1
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 #2
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 #3
0
File: api.php Project: anqh/anqh
 /**
  * Action: browse
  */
 public function action_browse()
 {
     $this->data['events'] = array();
     // Get start stamp
     $from = Arr::get($_REQUEST, 'from', 'today');
     $from = Valid::numeric($from) ? (int) $from : strtotime($from);
     // Get order
     $order = Arr::get($_REQUEST, 'order') == 'desc' ? 'desc' : 'asc';
     // Get limit, time span or 500 events max
     $limit = Arr::get($_REQUEST, 'limit', '1w');
     if (Valid::numeric($limit)) {
         // Limit given as event count
         $to = false;
         $limit = max(min((int) $limit, 500), 1);
     } else {
         if ($span = Date::parse_span($limit)) {
             // Limit given as timespan
             $to = strtotime(($order == 'asc' ? '+' : '-') . $span, $from);
             $limit = 500;
         } else {
             // No limit given
             $to = false;
             $limit = 500;
         }
     }
     // Get fields
     $field = explode(':', Arr::get($_REQUEST, 'field', 'id:name:city'));
     $fields = empty($field) || ($field[0] = 'all') ? self::$_fields : array_intersect($field, self::$_fields);
     $fields = empty($fields) ? array('id', 'name') : $fields;
     // Build query
     $event = new Model_Event();
     $events = DB::select_array($event->fields())->order_by('stamp_begin', $order);
     if ($order == 'asc') {
         // Upcoming events
         if ($to) {
             $events->where('stamp_begin', 'BETWEEN', array($from, $to));
         } else {
             $events->where('stamp_begin', '>=', $from);
         }
     } else {
         // Past events
         if ($to) {
             $events->where('stamp_begin', 'BETWEEN', array($to, $from));
         } else {
             $events->where('stamp_begin', '<=', $from);
         }
     }
     // Build data
     foreach ($event->load($events, $limit) as $event) {
         $this->data['events'][] = $this->_prepare_event($event, $fields);
     }
 }
Example #4
0
 /**
  * 
  * @return ORM
  */
 public function get_user()
 {
     if ($this->_user instanceof ORM) {
         return $this->_user;
     }
     $profile_id = $this->get_profile_id();
     if (is_string($profile_id) and Valid::numeric($profile_id)) {
         $this->_user = ORM::factory('User', $profile_id);
     } else {
         $this->_user = Auth::get_record(ORM::factory('User'));
         $this->_ctx->set($this->profile_id_ctx, $this->_user->id);
     }
     return $this->_user;
 }
Example #5
0
 /**
  *  Finds next execution time(stamp) parsin crontab syntax, 
  *  after given starting timestamp (or current time if ommited)
  * 
  *  @param string $cron_string:
  *
  *      0     1    2    3    4
  *      *     *    *    *    *  
  *      -     -    -    -    -
  *      |     |    |    |    |
  *      |     |    |    |    +----- day of week (0 - 6) (Sunday=0)
  *      |     |    |    +------- month (1 - 12)
  *      |     |    +--------- day of month (1 - 31)
  *      |     +----------- hour (0 - 23)
  *      +------------- min (0 - 59)
  *  @param int $after_timestamp timestamp [default=current timestamp]
  *  @return int unix timestamp - next execution time will be greater 
  *              than given timestamp (defaults to the current timestamp)
  *  @throws Kohana_Exception 
  */
 public static function parse($cron_string, $after_timestamp = NULL)
 {
     if (!Crontab::valid($cron_string)) {
         throw new Kohana_Exception('Invalid cron string: :string', array(':string' => $cron_string));
     }
     if ($after_timestamp !== NULL and !Valid::numeric($after_timestamp)) {
         throw new Kohana_Exception("\$after_timestamp must be a valid unix timestamp (:string given)", array(':string' => $after_timestamp));
     }
     $cron = preg_split("/[\\s]+/i", trim($cron_string));
     $start = empty($after_timestamp) ? time() : $after_timestamp;
     $date = array('minutes' => self::_parse_cron_numbers($cron[0], 0, 59), 'hours' => self::_parse_cron_numbers($cron[1], 0, 23), 'dom' => self::_parse_cron_numbers($cron[2], 1, 31), 'month' => self::_parse_cron_numbers($cron[3], 1, 12), 'dow' => self::_parse_cron_numbers($cron[4], 0, 6));
     // limited to time()+366 - no need to check more than 1year ahead
     for ($i = 0; $i <= 60 * 60 * 24 * 366; $i += 60) {
         if (in_array(intval(date('j', $start + $i)), $date['dom']) and in_array(intval(date('n', $start + $i)), $date['month']) and in_array(intval(date('w', $start + $i)), $date['dow']) and in_array(intval(date('G', $start + $i)), $date['hours']) and in_array(intval(date('i', $start + $i)), $date['minutes'])) {
             return $start + $i;
         }
     }
     return NULL;
 }
Example #6
0
 /**
  * 
  * @param integer|string $date
  * @param string $format
  * @return string
  */
 public static function format($date = NULL, $format = NULL)
 {
     if ($format === NULL) {
         $format = Config::get('site', 'date_format', 'Y-m-d H:I:s');
     }
     if (is_array($date)) {
         $string = '';
         if (!empty($date['year']) and !empty($date['month']) and !empty($date['day'])) {
             $string = $date['year'] . '-' . $date['month'] . '-' . $date['day'];
         }
         if ($date['hour'] and !empty($date['minute']) and !empty($date['second'])) {
             $string .= ' ' . $date['hour'] . ':' . $date['minute'] . ':' . $date['second'];
         }
         $date = strtotime($string);
     } else {
         if (!Valid::numeric($date)) {
             $date = strtotime($date);
         }
     }
     if (empty($date)) {
         return __('Never');
     }
     return strtr(date($format, $date), self::_translate_words());
 }
Example #7
0
        ?>
				                        <?php 
    }
    ?>
				                    </td>
				                <?php 
}
?>

								<tr>
									<td class="text-right"><h4><strong><?php 
echo __('Total');
?>
: </strong></h4></td>
									<?php 
if ($order->id_product == Model_Order::PRODUCT_AD_SELL and isset($order->ad->cf_shipping) and Valid::numeric($order->ad->cf_shipping) and $order->ad->cf_shipping > 0) {
    ?>
				                    	<td class="text-center text-danger"><h4><strong><?php 
    echo i18n::money_format($order->amount + $order->ad->cf_shipping, $order->currency);
    ?>
</strong></h4></td>
				                    <?php 
} else {
    ?>
				                    	<td class="text-center text-danger"><h4><strong><?php 
    echo $order->id_product == Model_Order::PRODUCT_AD_SELL ? i18n::money_format($order->amount, $order->currency) : i18n::format_currency($order->amount, $order->currency);
    ?>
</strong></h4></td>
				                    <?php 
}
?>
 /**
  * [action_buy] Pay for ad, and set new order 
  *
  */
 public function action_buy()
 {
     //check pay to featured top is enabled
     if (core::config('payment.paypal_seller') == FALSE) {
         throw HTTP_Exception::factory(404, __('Page not found'));
     }
     //getting the user that wants to buy now
     if (!Auth::instance()->logged_in()) {
         Alert::set(Alert::INFO, __('To buy this product you first need to register'));
         $this->redirect(Route::url('oc-panel'));
     }
     $id_product = Model_Order::PRODUCT_AD_SELL;
     //check ad exists
     $id_ad = $this->request->param('id');
     $ad = new Model_Ad($id_ad);
     //loaded published and with stock if we control the stock.
     if ($ad->loaded() and $ad->status == Model_Ad::STATUS_PUBLISHED and (core::config('payment.stock') == 0 or $ad->stock > 0 and core::config('payment.stock') == 1)) {
         $amount = $ad->price;
         $currency = core::config('payment.paypal_currency');
         if (isset($ad->cf_shipping) and Valid::numeric($ad->cf_shipping) and $ad->cf_shipping > 0) {
             $amount = $ad->price + $ad->cf_shipping;
         }
         $order = Model_Order::new_order($ad, $this->user, $id_product, $amount, $currency, __('Purchase') . ': ' . $ad->seotitle);
         $this->redirect(Route::url('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order)));
     } else {
         throw HTTP_Exception::factory(404, __('Page not found'));
     }
 }
Example #9
0
 public function get_doc_id()
 {
     if (Valid::numeric($this->_id)) {
         return $this->_id;
     }
     return $this->_ctx->get($this->doc_id_ctx);
 }
Example #10
0
 public function set_widget_id($widget_id)
 {
     return Valid::numeric($widget_id) ? $widget_id : NULL;
 }
Example #11
0
        <table class="table table-hover">
            <thead>
                <tr>
                    <th style="text-align: center">#</th>
                    <th><?php 
echo __('Product');
?>
</th>
                    <th class="text-center"><?php 
echo __('Price');
?>
</th>
                </tr>
            </thead>
            <tbody>
                <?if($order->id_product == Model_Order::PRODUCT_AD_SELL AND isset($order->ad->cf_shipping) AND Valid::numeric($order->ad->cf_shipping) AND $order->ad->cf_shipping > 0):?>
                    <tr>
                        <td class="col-md-1" style="text-align: center"><?php 
echo $order->id_product;
?>
</td>
                        <td class="col-md-9"><?php 
echo $order->description;
?>
 <em>(<?php 
echo Model_Order::product_desc($order->id_product);
?>
)</em></td>
                        <td class="col-md-2 text-center"><?php 
echo i18n::format_currency($order->amount - $order->ad->cf_shipping, $order->currency);
?>
Example #12
0
 protected function validate($value)
 {
     if (!Valid::numeric($value)) {
         return 'decimal';
     }
 }
Example #13
0
 /**
  * 
  * @param string $key
  * @return string
  */
 public function parse_meta($key, $value = NULL)
 {
     if ($value === NULL) {
         $value = strtr($this->{$key}, array('\'' => '\\\'', '\\' => '\\\\'));
     }
     $fields = array();
     $found = preg_match_all('/(?<!\\{)\\{(' . '((\\$|\\:)[A-Za-z0-9_\\-\\.\\/]+(\\|[\\w\\ ]*)?)' . '|[\\.]+' . ')\\}(?!\\})/u', $value, $fields);
     if ($found) {
         $fields = array_unique($fields[1]);
         $parts = array();
         foreach ($fields as $i => $field) {
             $patterns[] = '/(?<!\\{)\\{' . preg_quote($field, '/') . '\\}(?!\\})/u';
             switch ($field) {
                 case '.':
                     // Current page
                     if ($key == 'meta_title') {
                         $parts[] = $this->title();
                     }
                     break;
                 case '..':
                     // Parent page
                     if ($this->parent() instanceof Model_Page_Front) {
                         $parts[] = $this->parent()->{$key}();
                     }
                     break;
                 default:
                     // Level
                     if (Valid::numeric($field) and $this->level() != $field and $this->parent($field) instanceof Model_Page_Front) {
                         $parts[] = $this->parent($field)->{$key}();
                     }
                     break;
             }
             $param = NULL;
             $meta_param = NULL;
             $default = NULL;
             if (strpos($field, '|') !== FALSE) {
                 list($field, $default) = explode('|', $field, 2);
             }
             switch ($field[0]) {
                 case '$':
                     $param = substr($field, 1);
                     break;
                 case ':':
                     $meta_param = substr($field, 1);
                     break;
             }
             if ($param !== NULL) {
                 if (strpos($param, 'site.') !== FALSE) {
                     $parts[] = Config::get('site', substr($param, 5), $default);
                 } else {
                     if (strpos($param, 'ctx.') !== FALSE) {
                         $parts[] = Context::instance()->get(substr($param, 4));
                     } else {
                         if (strpos($param, 'parent.') !== FALSE and $this->parent() instanceof Model_Page_Front and method_exists($this->parent(), substr($param, 7))) {
                             $parts[] = $this->parent()->{substr($param, 7)}();
                         } else {
                             if (method_exists($this, $param)) {
                                 $parts[] = $this->{$param}();
                             }
                         }
                     }
                 }
             }
             if ($meta_param !== NULL) {
                 $parts[] = Arr::get($this->_meta_params, $meta_param, $default);
             }
         }
         $value = preg_replace($patterns, $parts, $value);
     }
     return $value;
 }
Example #14
0
 /**
  * Указание позиции поля
  * 
  * @param integer $position
  * @return \DataSource_Hybrid_Field
  */
 public function set_position($position)
 {
     if (!Valid::numeric($position)) {
         $position = DataSource_Hybrid_Field_Factory::get_last_position($this->ds_id) + 10;
     }
     $this->position = (int) $position;
     if ($this->position < 0) {
         $this->position = 0;
     }
     return $this;
 }
Example #15
0
 /**
  * 
  * @param integer|string $id
  * @param array $fields
  * @param string $id_field
  * @return null|array
  */
 public function get_document($id, array $fields = NULL, $id_field = NULL)
 {
     $query = $this->get_query_props($fields);
     $hybrid_fields = $this->get_fields();
     if (Valid::numeric($id_field) and isset($hybrid_fields[$id_field])) {
         $id_field = $hybrid_fields[$id_field]->name;
     }
     if ($id_field == 'id' or empty($id_field)) {
         $id_field = 'd.id';
     }
     $query = $query->where($id_field, '=', $id)->where('d.published', '=', 1)->group_by('d.id')->limit(1)->execute()->current();
     if (empty($query)) {
         return NULL;
     }
     return $query;
 }
Example #16
0
 /**
  * Tests Valid::numeric()
  *
  * @test
  * @dataProvider provider_numeric
  * @param string  $input     Input to test
  * @param boolean $expected  Whether or not $input is numeric
  */
 public function test_numeric($input, $expected)
 {
     $this->assertSame($expected, Valid::numeric($input));
 }
Example #17
0
 /**
  * Validation callback
  *
  * @param   string      $name        Validation name
  * @param   Validation  $validation  Validation object
  * @param   string      $field       Field name
  *
  * @uses    Valid::numeric
  * @uses    Config::get
  */
 public function is_valid($name, Validation $validation, $field)
 {
     // Make sure we have a valid term id set
     if ($name == 'category') {
         if (isset($this->categories) and is_array($this->categories)) {
             foreach ($this->categories as $id => $term) {
                 if ($term == 'last' or !Valid::numeric($term)) {
                     $validation->error('categories', 'invalid', array($validation[$field]));
                 }
             }
         }
     } elseif ($name == 'created') {
         if (!empty($this->author_date) and !($date = strtotime($this->author_date))) {
             $validation->error($field, 'invalid', array($this->author_date));
         } else {
             if (isset($date)) {
                 $this->created = $date;
             }
         }
     } elseif ($name == 'author') {
         if (!empty($this->author_name) and !($account = User::lookup_by_name($this->author_name))) {
             $validation->error($field, 'invalid', array($this->author_name));
         } else {
             if (isset($account)) {
                 $this->author = $account->id;
             }
         }
     } elseif ($name == 'pubdate') {
         if (!empty($this->author_pubdate) and !($date = strtotime($this->author_pubdate))) {
             $validation->error($field, 'invalid', array($validation[$field]));
         } else {
             if (isset($date)) {
                 $this->pubdate = $date;
             }
         }
     } elseif ($name == 'image') {
         if (isset($_FILES['image']['name']) and !empty($_FILES['image']['name'])) {
             $allowed_types = Config::get('media.supported_image_formats', array('jpg', 'png', 'gif'));
             $data = Validation::factory($_FILES)->rule('image', 'Upload::not_empty')->rule('image', 'Upload::valid')->rule('image', 'Upload::type', array(':value', $allowed_types));
             if (!$data->check()) {
                 $validation->error($field, 'invalid', array($validation[$field]));
             }
         }
     }
 }