Exemplo n.º 1
0
 public static function feed_fb($token, $data)
 {
     $data = json_decode(base64_decode($data));
     if (!empty($data->id)) {
         if (!defined('_PATH_PRODUCT_')) {
             define('_PATH_PRODUCT_', Config::get('base_url') . Config::get('app.path.product'));
         }
         $product = \Model_Base_Product::get_one($data->id);
         $tmp = "\r\n\r\n--------------------------------------------------\r\n\r\n";
         $message = $product['product_name'] . $tmp . $product['product_description'] . $tmp . $product['product_info'];
         $groups = \Model_Base_GroupFb::get_all();
         foreach ($groups as $group) {
             try {
                 \OpauthStrategy::serverPost('https://graph.facebook.com/v2.5/' . $group['group_id'] . '/feed', array('access_token' => $token, 'message' => strip_tags(html_entity_decode($message, ENT_QUOTES)), 'link' => Uri::create('/product/' . $product['code']), 'caption' => 'WJ-SHOP', 'name' => html_entity_decode($product['product_name'], ENT_QUOTES), 'description' => html_entity_decode($product['product_description'], ENT_QUOTES), 'picture' => _PATH_PRODUCT_ . $product['product_photo']), null, $headers);
             } catch (\Exception $e) {
                 Log::error($e->getMessage());
             }
             sleep(5);
         }
     } elseif (!empty($data->message) && !empty($data->link)) {
         $groups = \Model_Base_GroupFb::get_all();
         foreach ($groups as $group) {
             try {
                 \OpauthStrategy::serverPost('https://graph.facebook.com/v2.5/' . $group['group_id'] . '/feed', array('access_token' => $token, 'message' => html_entity_decode($data->message, ENT_QUOTES), 'link' => $data->link), null, $headers);
             } catch (\Exception $e) {
                 Log::error($e->getMessage());
             }
             sleep(5);
         }
     }
 }
Exemplo n.º 2
0
 public static function _validation_valid_product($val)
 {
     if (self::_empty($val)) {
         return true;
     }
     return Model_Base_Product::valid_field('id', $val);
 }
Exemplo n.º 3
0
 public function action_home()
 {
     $this->data['highlight_product'] = Model_Base_Product::get_by(array('where' => array(array('highlight', '=', 1), array('status', '=', 1)), 'limit' => 5));
     $this->data['new_product'] = Model_Base_Product::get_by(array('where' => array(array('status', '=', 1)), 'limit' => 8));
     $this->data['product_category'] = Model_Base_Category::get_all(array('where' => array(array('parent_category_id', '=', 0), array('status', '=', 1))));
     foreach ($this->data['product_category'] as $key => $value) {
         $this->data['product_category'][$key]['product'] = Model_Base_Product::get_by_category($value['id'], 0, 4);
     }
     $this->template->title = 'Home Page';
     $this->template->content = View::forge($this->layout . '/home/home', $this->data);
 }
Exemplo n.º 4
0
 public function post_list()
 {
     $page = (int) Input::post('page') !== 0 ? (int) Input::post('page') : 1;
     $code = Input::post('code');
     $category_id = Model_Base_Category::get_id_by_code($code);
     $total = Model_Base_Product::count_by_category($category_id);
     $limit = _DEFAULT_LIMIT_;
     $offset = $page * $limit - $limit < $total ? $page * $limit - $limit : _DEFAULT_OFFSET_;
     $this->data['products'] = Model_Base_Product::get_by_category($category_id, $offset, $limit);
     $this->data['success'] = true;
     return $this->response($this->data);
 }
Exemplo n.º 5
0
 public function action_detail($code = null)
 {
     $this->data['product'] = Model_Base_Product::get_by_code($code, array('where' => array(array('status', '=', 1))));
     if (empty($this->data['product']['id'])) {
         Response::redirect('/');
     }
     $this->data['product']['sub_photo'] = Model_Base_Product::get_sub_photo($this->data['product']['id']);
     $category_ids = Model_Base_ProductCategory::get_by('category_id', 'product_id', $this->data['product']['id']);
     if (!empty($category_ids)) {
         $this->data['products'] = Model_Base_Product::get_by_category_ids($category_ids, 0, 5);
     }
     View::set_global('product', $this->data['product']);
     $this->template->title = 'Product List';
     $this->template->content = View::forge($this->layout . '/product/detail', $this->data);
 }
Exemplo n.º 6
0
 public static function run($type = null, $options = array())
 {
     $data = array();
     $photo_name = array();
     try {
         Upload::process();
     } catch (Exception $e) {
         $data['error'] = Lang::get('notice.upload.no_file');
         return $data;
     }
     if (Upload::is_valid()) {
         Upload::save();
     }
     foreach (Upload::get_errors() as $file) {
         $data['error'] = $file['errors']['0']['message'];
         return $data;
     }
     foreach (Upload::get_files() as $file) {
         $resize = self::resize_photo($file['saved_to'], $file['saved_as'], $type);
         $photo_name[] = $file['saved_as'];
     }
     if ($resize) {
         switch ($type) {
             case 'icon':
                 if (Model_Base_User::update($options['user_id'], array('user_photo' => $photo_name[0]))) {
                     $old_photo = $file['saved_to'] . $type . '/' . $options['user_photo'];
                     if (File::exists($old_photo)) {
                         File::delete($old_photo);
                     }
                     $data['photo_name'] = _PATH_ICON_ . $photo_name[0];
                 } else {
                     $data['error'] = Lang::get('notice.upload.save_icon_error');
                 }
                 break;
             case 'category':
                 $old_photo = $options['type'] === 'new' ?: $file['saved_to'] . $type . '/' . Model_Category::find($options['category_id'])->category_photo;
                 if (Model_Base_Category::update($options['category_id'], array('category_photo' => $photo_name[0]))) {
                     if (File::exists($old_photo)) {
                         File::delete($old_photo);
                     }
                     $data['photo_name'] = _PATH_CATEGORY_ . $photo_name[0];
                 } else {
                     $data['error'] = Lang::get('notice.upload.save_category_error');
                 }
                 break;
             case 'product':
                 $old_photo = $file['saved_to'] . $type . '/' . Model_Product::find($options['product_id'])->product_photo;
                 if (Model_Base_Product::update($options['product_id'], array('product_photo' => $photo_name[0]))) {
                     if (File::exists($old_photo)) {
                         File::delete($old_photo);
                     }
                     $data['photo_name'] = _PATH_PRODUCT_ . $photo_name[0];
                 } else {
                     $data['error'] = Lang::get('notice.upload.save_product_error');
                 }
                 break;
             case 'photo':
                 if ($options['type'] === 'sub_product_photo') {
                     $photo_props = array('product_id' => $options['product_id'], 'photo_name' => $photo_name[0]);
                     if ($photo_id = Model_Base_Photo::insert($photo_props)) {
                         $data['photo_id'] = $photo_id;
                         $data['photo_name'] = _PATH_PHOTO_ . $photo_name[0];
                     } else {
                         $data['error'] = Lang::get('notice.upload.save_photo_error');
                     }
                 }
                 break;
             default:
                 $data['error'] = Lang::get('system_error');
                 break;
         }
     } else {
         $data['error'] = Lang::get('system_error');
     }
     return $data;
 }
Exemplo n.º 7
0
 public function post_highlight()
 {
     $val = Validation::forge();
     $val->add_callable('MyRules');
     $val->add_field('highlight', Lang::get('label.highlight'), 'required|valid_product_highlight');
     $val->add_field('product_id', Lang::get('label.product'), 'required|valid_product');
     if ($val->run()) {
         Model_Base_Product::update($val->validated('product_id'), array('highlight' => $val->validated('highlight')));
         $this->data['success'] = true;
     } else {
         $this->data['errors'] = $val->error_message();
     }
     return $this->response($this->data);
 }