Example #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);
         }
     }
 }
Example #2
0
 public function action_edit($id = null)
 {
     if (empty($id) || !Model_Base_Product::valid_field('id', $id)) {
         Response::redirect('/admin/product');
     }
     $this->data['category'] = Model_Base_Category::get_all();
     $this->data['product'] = Model_Base_Product::get_one($id);
     $this->data['product']['category'] = Model_Base_ProductCategory::get_by('category_id', 'product_id', $id);
     $this->data['product']['sub_photo'] = Model_Base_Product::get_sub_photo($id);
     $this->template->content = View::forge($this->layout . '/product/edit', $this->data);
 }