Esempio n. 1
0
 public function networks()
 {
     $networks = Network::where('user_id', '=', Auth::user()->id)->get();
     $page_data = array('network_count' => count($networks), 'networks' => $networks);
     $this->layout->title = 'Networks';
     $this->layout->content = View::make('admin.networks', $page_data);
 }
 public function getProducts($id)
 {
     $category = Category::find($id);
     $network = Network::where('category_id', '=', $id)->get();
     $product = Product::where('category_id', '=', $id)->paginate(9);
     $phone = Product::where('category_id', '=', $id)->get();
     return View::make('products.index')->with('category', $category)->with('network', $network)->with('product', $product)->with('phone', $phone);
 }
Esempio n. 3
0
 public function settings()
 {
     $user_id = Auth::user()->id;
     $networks = Network::where('user_id', '=', $user_id)->get();
     $settings = Settings::where('user_id', '=', $user_id)->first();
     $schedules = Schedule::where('user_id', '=', $user_id)->get();
     $default_networks = json_decode($settings->default_networks);
     $page_data = array('networks' => $networks, 'default_networks' => $default_networks, 'default_schedule' => $settings->schedule_id, 'schedules' => $schedules, 'api_key' => $settings->api_key);
     $this->layout->title = 'Settings';
     $this->layout->content = View::make('admin.settings', $page_data);
 }
 public function getProduct($id)
 {
     $phones = Product::find($id);
     if ($id <= 9) {
         $countrys = Country::where('category_id', '=', '1')->get();
         $networks = Network::where('category_id', '=', '1')->get();
     } elseif ($id <= 12) {
         $countrys = Country::where('category_id', '=', '2')->get();
         $networks = Network::where('category_id', '=', '2')->get();
     } elseif ($id <= 15) {
         $countrys = Country::where('category_id', '=', '3')->get();
         $networks = Network::where('category_id', '=', '3')->get();
     }
     return View::make('products.product')->with('phones', $phones)->with('networks', $networks)->with('countrys', $countrys);
 }
Esempio n. 5
0
 public function connectFacebook()
 {
     $provider = new Facebook(Config::get('social.facebook'));
     try {
         $network_type = 'facebook';
         $token = $provider->getAccessToken('authorizationCode', array('code' => Input::get('code')));
         $access_token = $token->accessToken;
         $client = new GuzzleHttp\Client();
         $res = $client->get('https://graph.facebook.com/me', array('query' => array('access_token' => $access_token)));
         $response_body = $res->getBody();
         $response_body = json_decode($response_body, true);
         $id = $response_body['id'];
         $name = $response_body['name'];
         if (!Auth::check()) {
             $user = User::where('social_id', '=', $id)->where('type', '=', 'facebook')->first();
             if (empty($user)) {
                 $user['inputs'] = array('username' => $name, 'email' => '', 'type' => $network_type, 'social_id' => $id);
                 Event::fire('user.create', array($user));
             }
         }
         if (Auth::check()) {
             $res = $client->get('https://graph.facebook.com/oauth/access_token', array('query' => array('grant_type' => 'fb_exchange_token', 'client_id' => Config::get('social.facebook.clientId'), 'client_secret' => Config::get('social.facebook.clientSecret'), 'fb_exchange_token' => $access_token)));
             $extended_accesstoken_response_body = $res->getBody();
             $extended_accesstoken = str_replace('access_token=', '', $extended_accesstoken_response_body);
             $extended_accesstoken = preg_replace('/&expires\\=[0-9]*/', '', $extended_accesstoken);
             $user_id = Auth::user()->id;
             $network = Network::where('user_id', '=', $user_id)->where('network', '=', $network_type)->where('network_id', '=', $id)->first();
             if (!empty($network)) {
                 $network->user_token = $extended_accesstoken;
                 $network->save();
             } else {
                 $network = new Network();
                 $network->user_id = $user_id;
                 $network->network = $network_type;
                 $network->user_token = $extended_accesstoken;
                 $network->network_id = $id;
                 $network->username = $name;
                 $network->save();
             }
             //get pages
             $res = $client->get('https://graph.facebook.com/me/accounts', array('query' => array('access_token' => $extended_accesstoken)));
             $response_body = $res->getBody();
             $pages = json_decode($response_body, true);
             if (!empty($pages['data'])) {
                 foreach ($pages['data'] as $page) {
                     if (in_array('CREATE_CONTENT', $page['perms'])) {
                         $page_id = $page['id'];
                         $page_name = $page['name'];
                         $page_accesstoken = $page['access_token'];
                         $network = Network::where('user_id', '=', $user_id)->where('network', '=', $network_type)->where('network_id', '=', $page_id)->first();
                         if (!empty($network)) {
                             $network->user_token = $page_accesstoken;
                             $network->save();
                         } else {
                             $network = new Network();
                             $network->user_id = $user_id;
                             $network->network = $network_type;
                             $network->user_token = $page_accesstoken;
                             $network->network_id = $page_id;
                             $network->username = $page_name;
                             $network->save();
                         }
                     }
                 }
             }
             return Redirect::to('/networks')->with('message', array('type' => 'success', 'text' => 'You have successfully connected your Facebook account!'));
         }
     } catch (Exception $e) {
         return Redirect::to('/networks')->with('message', array('type' => 'danger', 'text' => 'Something went wrong while trying to connect to your Facebook account. Please try again.'));
     }
 }
Esempio n. 6
0
 public function viewPost($post_id)
 {
     $user_id = Auth::user()->id;
     $post = Post::where('user_id', '=', $user_id)->where('id', '=', $post_id)->first();
     $networks = Network::where('user_id', '=', $user_id)->get();
     $settings = Settings::where('user_id', '=', $user_id)->first();
     $selected_networks = PostNetwork::where('post_id', $post_id)->where('status', '=', 1)->lists('network_id');
     $response_data = array('post_id' => $post_id, 'post' => $post, 'networks' => $networks, 'selected_networks' => $selected_networks);
     return $response_data;
 }
Esempio n. 7
0
 public function fire($job, $data)
 {
     $post_id = $data['post_id'];
     $post = Post::find($post_id);
     if (!empty($post)) {
         $user_id = $post->user_id;
         $post_url = '';
         preg_match_all('#[-a-zA-Z0-9@:%_\\+.~\\#?&//=]{2,256}\\.[a-z]{2,4}\\b(\\/[-a-zA-Z0-9@:%_\\+.~\\#?&//=]*)?#si', $post->content, $url_matches);
         if (!empty($url_matches)) {
             $all_urls = $url_matches[0];
             $post_url = !empty($all_urls[0]) ? $all_urls[0] : '';
         }
         $network_ids = PostNetwork::where('post_id', '=', $post_id)->lists('network_id');
         $network = Network::where('user_id', '=', $user_id)->select('user_token', 'user_secret', 'network')->whereIn('id', $network_ids)->get();
         $client = new GuzzleHttp\Client();
         if (!empty($network)) {
             foreach ($network as $s) {
                 if ($s->network == 'twitter') {
                     try {
                         Twitter::setOAuthToken($s->user_token);
                         Twitter::setOAuthTokenSecret($s->user_secret);
                         $twitter_response = Twitter::statusesUpdate($post->content);
                     } catch (Exception $e) {
                     }
                 } else {
                     if ($s->network == 'linkedin') {
                         if (!empty($post_url)) {
                             try {
                                 $post_data = array('comment' => $post->content, 'content' => array('description' => $post->content), 'visibility' => array('code' => 'anyone'));
                                 $post_data['content']['submittedUrl'] = $post_url;
                                 $request_body = $post_data;
                                 $linkedin_resource = '/v1/people/~/shares';
                                 $request_format = 'json';
                                 $linkedin_params = array('oauth2_access_token' => $s->user_token, 'format' => $request_format);
                                 $linkedinurl_info = parse_url('https://api.linkedin.com' . $linkedin_resource);
                                 if (isset($linkedinurl_info['query'])) {
                                     $query = parse_str($linkedinurl_info['query']);
                                     $linkedin_params = array_merge($linkedin_params, $query);
                                 }
                                 $request_url = 'https://api.linkedin.com' . $linkedinurl_info['path'] . '?' . http_build_query($linkedin_params);
                                 $request_body = json_encode($request_body);
                                 $linkedin_response = CurlRequester::requestCURL('POST', $request_url, $request_body, $request_format);
                             } catch (Exception $e) {
                             }
                         }
                     } else {
                         if ($s->network == 'facebook') {
                             try {
                                 $post_data = array('access_token' => $s->user_token, 'message' => $post->content);
                                 if (!empty($post_url)) {
                                     $post_data['link'] = $post_url;
                                 }
                                 $res = $client->post('https://graph.facebook.com/me/feed', array('query' => $post_data));
                                 $response_body = $res->getBody();
                                 $response_body = json_decode($response_body, true);
                             } catch (Exception $e) {
                             }
                         }
                     }
                 }
             }
         }
     }
     $post->published = 1;
     $post->save();
     $job->delete();
 }