Example #1
0
 /**
  * creates a user from email if exists doesn't...
  * @param  string $email 
  * @param  string $name  
  * @param  string $password
  * @return Model_User        
  */
 public static function create_email($email, $name = NULL, $password = NULL)
 {
     $user = new self();
     $user->where('email', '=', $email)->limit(1)->find();
     if (!$user->loaded()) {
         if ($password === NULL) {
             $password = Text::random('alnum', 8);
         }
         $user->email = $email;
         $user->name = ($name === NULL or !isset($name)) ? substr($email, 0, strpos($email, '@')) : $name;
         $user->status = self::STATUS_ACTIVE;
         $user->id_role = Model_Role::ROLE_USER;
         $user->seoname = $user->gen_seo_title($user->name);
         $user->password = $password;
         $user->subscriber = 1;
         $user->last_ip = ip2long(Request::$client_ip);
         $user->country = euvat::country_code();
         //geo info EU
         try {
             $user->save();
             //send welcome email
             $url = $user->ql('oc-panel', array('controller' => 'profile', 'action' => 'edit'), TRUE);
             $user->email('auth-register', array('[USER.PWD]' => $password, '[URL.QL]' => $url));
         } catch (ORM_Validation_Exception $e) {
             throw HTTP_Exception::factory(500, $e->getMessage());
         }
     }
     return $user;
 }
 /**
  * creates a category by name
  * @param  string  $name               
  * @param  integer $id_category_parent 
  * @param  string  $description        
  * @return Model_Category                      
  */
 public static function create_name($name, $order = 0, $id_category_parent = 1, $parent_deep = 0, $price = 0, $description = NULL)
 {
     $cat = new self();
     $cat->where('name', '=', $name)->limit(1)->find();
     //if doesnt exists create
     if (!$cat->loaded()) {
         $cat->name = $name;
         $cat->seoname = $cat->gen_seoname($name);
         $cat->id_category_parent = $id_category_parent;
         $cat->order = $order;
         $cat->parent_deep = $parent_deep;
         $cat->price = $price;
         $cat->description = $description;
         try {
             $cat->save();
         } catch (ORM_Validation_Exception $e) {
             throw HTTP_Exception::factory(500, $e->getMessage());
         }
     }
     return $cat;
 }
Example #3
0
 /**
  * save_image upload images with given path
  * 
  * @param  [array]  $image      [image $_FILE-s ]
  * @param  [string] $seotitle   [unique id, and folder name]
  * @return [bool]               [return true if 1 or more images uploaded, false otherwise]
  */
 public function save_image($image)
 {
     if (core::config('image.aws_s3_active')) {
         require_once Kohana::find_file('vendor', 'amazon-s3-php-class/S3', 'php');
         $s3 = new S3(core::config('image.aws_access_key'), core::config('image.aws_secret_key'));
     }
     if (!Upload::valid($image) or !Upload::not_empty($image) or !Upload::type($image, explode(',', core::config('image.allowed_formats'))) or !Upload::size($image, core::config('image.max_image_size') . 'M')) {
         if (Upload::not_empty($image) && !Upload::type($image, explode(',', core::config('image.allowed_formats')))) {
             return Alert::set(Alert::ALERT, $image['name'] . ': ' . sprintf(__('This uploaded image is not of a valid format. Please use one of these formats: %s'), core::config('image.allowed_formats')));
         }
         if (!Upload::size($image, core::config('image.max_image_size') . 'M')) {
             return Alert::set(Alert::ALERT, $image['name'] . ': ' . sprintf(__("This uploaded image exceeds the allowable limit. Uploaded images cannot be larger than %s MB per image"), core::config('image.max_image_size')));
         }
     }
     if ($image !== NULL) {
         $id = $this->id_product;
         $seotitle = $this->seotitle;
         $obj_product = new self($id);
         if ($obj_product->loaded()) {
             $created = $obj_product->created;
         } else {
             $created = NULL;
         }
         $path = $this->image_path($id, $created);
         $docroot = DOCROOT;
         $directory = $docroot . $path;
         $image_quality = core::config('image.quality');
         $width = core::config('image.width');
         $width_thumb = core::config('image.width_thumb');
         $height_thumb = core::config('image.height_thumb');
         $height = core::config('image.height');
         if (!is_numeric($height)) {
             // when installing this field is empty, to avoid crash we check here
             $height = NULL;
         }
         if (!is_numeric($height_thumb)) {
             $height_thumb = NULL;
         }
         // how many files are saved
         $counter = $this->has_images > 0 ? $this->has_images + 1 : 1;
         if ($file = Upload::save($image, NULL, $directory)) {
             $filename_thumb = 'thumb_' . $seotitle . '_' . $counter . '.jpg';
             $filename_original = $seotitle . '_' . $counter . '.jpg';
             //if original image is bigger that our constants we resize
             $image_size_orig = getimagesize($file);
             if ($image_size_orig[0] > $width || $image_size_orig[1] > $height) {
                 Image::factory($file)->orientate()->resize($width, $height, Image::AUTO)->save($directory . $filename_original, $image_quality);
             } else {
                 Image::factory($file)->orientate()->save($directory . $filename_original, $image_quality);
             }
             //creating the thumb and resizing using the the biggest side INVERSE
             Image::factory($directory . $filename_original)->resize($width_thumb, $height_thumb, Image::INVERSE)->save($directory . $filename_thumb, $image_quality);
             //check if the height or width of the thumb is bigger than default then crop
             if ($height_thumb !== NULL) {
                 $image_size_orig = getimagesize($directory . $filename_thumb);
                 if ($image_size_orig[1] > $height_thumb || $image_size_orig[0] > $width_thumb) {
                     Image::factory($directory . $filename_thumb)->crop($width_thumb, $height_thumb)->save($directory . $filename_thumb);
                 }
             }
             if (core::config('image.aws_s3_active')) {
                 // put image to Amazon S3
                 $s3->putObject($s3->inputFile($directory . $filename_original), core::config('image.aws_s3_bucket'), $path . $filename_original, S3::ACL_PUBLIC_READ);
                 // put thumb to Amazon S3
                 $s3->putObject($s3->inputFile($directory . $filename_thumb), core::config('image.aws_s3_bucket'), $path . $filename_thumb, S3::ACL_PUBLIC_READ);
             }
             // Delete the temporary file
             @unlink($file);
             return TRUE;
         }
     }
 }
Example #4
0
 /**
  * has this category siblings?
  * @return boolean             [description]
  */
 public function has_siblings($categories = NULL)
 {
     if ($this->loaded()) {
         if ($categories === NULL) {
             $category = new self();
             $category->where('id_category_parent', '=', $this->id_category)->where('id_category', '!=', $this->id_category)->limit(1)->cached()->find();
             return $category->loaded();
         } else {
             //d($categories);
             foreach ($categories as $category) {
                 //d($category);
                 if ($category['id_category_parent'] == $this->id_category and $category['id_category'] != $this->id_category) {
                     return TRUE;
                 }
             }
         }
     }
     return FALSE;
 }
Example #5
0
 /**
  * is used to create configs if they dont exist
  * @param array
  * @return boolean 
  */
 public static function config_array($configs)
 {
     $return = FALSE;
     foreach ($configs as $c => $value) {
         // get config from DB
         $confp = new self();
         $confp->where('config_key', '=', $value['config_key'])->where('group_name', '=', $value['group_name'])->limit(1)->find();
         // if do not exist (not loaded) create them, else do nothing
         if (!$confp->loaded()) {
             $confp->config_key = $value['config_key'];
             $confp->group_name = $value['group_name'];
             $confp->config_value = $value['config_value'];
             $confp->save();
             $return = TRUE;
         }
     }
     return $return;
 }
Example #6
0
 /**
  * creates a user from email if exists doesn't...
  * @param  string $email 
  * @param  string $name  
  * @param  string $password
  * @return Model_User        
  */
 public static function create_user($email, $name = NULL, $password = NULL)
 {
     $user = new self();
     $user->where('email', '=', $email)->limit(1)->find();
     if (!$user->loaded()) {
         if ($password === NULL) {
             $password = Text::random('alnum', 8);
         }
         $user->email = $email;
         $user->name = ($name === NULL or !isset($name)) ? substr($email, 0, strpos($email, '@')) : $name;
         $user->status = self::STATUS_ACTIVE;
         $user->id_role = Model_Role::ROLE_USER;
         $user->seoname = $user->gen_seo_title($user->name);
         $user->password = $password;
         $user->subscriber = 1;
         try {
             $user->save();
         } catch (ORM_Validation_Exception $e) {
             throw HTTP_Exception::factory(500, $e->getMessage());
         }
     }
     return $user;
 }
Example #7
0
 /**
  * sets the value for 1 key
  * @param [type] $group_name [description]
  * @param [type] $config_key [description]
  * @param [type] $value      [description]
  */
 public static function set_value($group_name, $config_key, $value)
 {
     $confp = new self();
     $confp->where('config_key', '=', $config_key)->where('group_name', '=', $group_name)->limit(1)->find();
     // if do not exist (not loaded) create
     if (!$confp->loaded()) {
         $confp->config_key = $config_key;
         $confp->group_name = $group_name;
     }
     $confp->config_value = $value;
     $confp->save();
 }
Example #8
0
 /**
  * @param  MPTT|int|array $target 实例或者主键ID
  * @param  bool|int       $leftColumn
  * @param  bool|int       $leftOffset
  * @param  bool|int       $levelOffset
  * @param  bool|int       $allowRootTarget
  * @return $this|bool
  * @throws \Doctrine\DBAL\DBALException
  */
 protected function move($target, $leftColumn, $leftOffset, $levelOffset, $allowRootTarget)
 {
     if (!$this->loaded()) {
         return false;
     }
     // store the changed parent id before reload
     $parentID = $this->{$this->_parentColumn};
     // 保证数据是最新的
     $this->reload();
     if (!$target instanceof $this) {
         $target = new self($target);
         if (!$target->loaded()) {
             return false;
         }
     } else {
         $target->reload();
     }
     // Stop $this being moved into a descendant or itself or disallow if target is root
     if ($target->isDescendant($this) || $this->pk() === $target->pk() || $allowRootTarget === false && $target->isRoot()) {
         return false;
     }
     if ($levelOffset > 0) {
         // We're moving to a child node so add 1 to left offset.
         $leftOffset = $leftColumn === true ? $target->left() + 1 : $target->right() + $leftOffset;
     } else {
         $leftOffset = $leftColumn === true ? $target->left() : $target->right() + $leftOffset;
     }
     $levelOffset = $target->level() - $this->level() + $levelOffset;
     $size = $this->size();
     $this->createSpace($leftOffset, $size);
     $this->reload();
     $offset = $leftOffset - $this->left();
     $this->db()->createQueryBuilder()->update($this->_tableName)->set($this->_leftColumn, $this->_leftColumn . '+' . $offset)->set($this->_rightColumn, $this->_rightColumn . '+' . $offset)->set($this->_levelColumn, $this->_levelColumn . '+' . $levelOffset)->set($this->_scopeColumn, $target->scope())->where($this->_leftColumn . '>=' . $this->left())->andWhere($this->_rightColumn . '<=' . $this->right())->andWhere($this->_scopeColumn . '=' . $this->scope())->execute();
     $this->deleteSpace($this->left(), $size);
     // all went well so save the parent_id if changed
     if ($parentID != $this->{$this->_parentColumn}) {
         $this->{$this->_parentColumn} = $parentID;
         $this->save();
     }
     $this->reload();
     return $this;
 }
Example #9
0
 /**
  * has this location siblings?
  * @return boolean             [description]
  */
 public function has_siblings($locations = NULL)
 {
     if ($this->loaded()) {
         if ($locations === NULL) {
             $location = new self();
             $location->where('id_location_parent', '=', $this->id_location)->where('id_location', '!=', $this->id_location)->limit(1)->cached()->find();
             return $location->loaded();
         } else {
             foreach ($locations as $key => $location) {
                 //d($location);
                 if ($location['id_location_parent'] == $this->id_location and $key != $this->id_location) {
                     return TRUE;
                 }
             }
         }
     }
     return FALSE;
 }
Example #10
0
 /**
  * is used to create contets if they dont exist
  * @param array
  * @return boolean 
  */
 public static function content_array($contents)
 {
     $return = FALSE;
     foreach ($contents as $c => $value) {
         // get config from DB
         $cont = new self();
         $cont->where('seotitle', '=', $value['seotitle'])->limit(1)->find();
         // if do not exist (not loaded) create them, else do nothing
         if (!$cont->loaded()) {
             $cont->order = $value['order'];
             $cont->title = $value['title'];
             $cont->seotitle = $value['seotitle'];
             $cont->description = $value['description'];
             $cont->from_email = $value['from_email'];
             $cont->type = $value['type'];
             $cont->status = $value['status'];
             $cont->save();
             $return = TRUE;
         }
     }
     return $return;
 }
Example #11
0
 /**
  * creates a User from social data
  * @param  string $email      
  * @param  string $name       
  * @param  string $provider   
  * @param  mixed $identifier 
  * @return Model_User             
  */
 public static function create_social($email, $name = NULL, $provider, $identifier)
 {
     $user = new self();
     $user->where('email', '=', $email)->limit(1)->find();
     //doesnt exists
     if (!$user->loaded()) {
         $user->email = $email;
         $user->name = $name;
         $user->status = self::STATUS_ACTIVE;
         $user->id_role = 1;
         $user->seoname = $user->gen_seo_title($user->name);
         $user->password = Text::random('alnum', 8);
     }
     //always we set this values even if user existed
     $user->hybridauth_provider_name = $provider;
     $user->hybridauth_provider_uid = $identifier;
     try {
         $user->save();
     } catch (ORM_Validation_Exception $e) {
         d($e->errors(''));
     }
     return $user;
 }
Example #12
0
 /**
  * confirm payment for order
  *
  * @param string    $id_order [unique indentifier of order]
  * @param int       $id_user  [unique indentifier of user] 
  */
 public function confirm_payment($id_order, $moderation)
 {
     $orders = new self();
     $orders->where('id_order', '=', $id_order)->where('status', '=', 0)->limit(1)->find();
     $id_ad = $orders->id_ad;
     $product_find = new Model_Ad();
     $product_find = $product_find->where('id_ad', '=', $id_ad)->limit(1)->find();
     $categ = new Model_Category($product_find->id_category);
     $user = new Model_User($orders->id_user);
     // update orders
     if ($orders->loaded()) {
         $orders->status = 1;
         $orders->pay_date = Date::unix2mysql(time());
         try {
             $orders->save();
         } catch (Exception $e) {
             echo $e;
         }
     }
     // update product
     if ($orders->id_product == Paypal::category_product) {
         if ($moderation == Model_Ad::PAYMENT_ON) {
             $product_find->published = Date::unix2mysql(time());
             $product_find->status = 1;
             try {
                 $product_find->save();
                 //we get the QL, and force the regen of token for security
                 $url_cont = $user->ql('contact', array(), TRUE);
                 $url_ad = $user->ql('ad', array('category' => $product_find->id_category, 'seotitle' => $product_find->seotitle), TRUE);
                 $ret = $user->email('ads.user_check', array('[URL.CONTACT]' => $url_cont, '[URL.AD]' => $url_ad, '[AD.NAME]' => $product_find->title));
             } catch (Exception $e) {
                 echo $e;
             }
         } else {
             if ($moderation == Model_Ad::PAYMENT_MODERATION) {
                 $product_find->published = Date::unix2mysql(time());
                 try {
                     $product_find->save();
                     $edit_url = core::config('general.base_url') . 'oc-panel/profile/update/' . $product_find->id_ad;
                     $delete_url = core::config('general.base_url') . 'oc-panel/ad/delete/' . $product_find->id_ad;
                     //we get the QL, and force the regen of token for security
                     $url_ql = $user->ql('oc-panel', array('controller' => 'profile', 'action' => 'update', 'id' => $orders->id_ad), TRUE);
                     $ret = $user->email('ads.notify', array('[URL.QL]' => $url_ql, '[AD.NAME]' => $product_find->title, '[URL.EDITAD]' => $edit_url, '[URL.DELETEAD]' => $delete_url));
                 } catch (Exception $e) {
                 }
             }
         }
     } elseif ($orders->id_product == Paypal::to_top) {
         $product_find->published = Date::unix2mysql(time());
         try {
             $product_find->save();
         } catch (Exception $e) {
             echo $e;
         }
     } elseif ($orders->id_product == Paypal::to_featured) {
         $product_find->featured = Date::unix2mysql(time() + core::config('payment.featured_days') * 24 * 60 * 60);
         try {
             $product_find->save();
         } catch (Exception $e) {
             echo $e;
         }
     }
 }