コード例 #1
0
ファイル: facebook.class.php プロジェクト: sgh1986915/php-crm
 public function handle_process($process, $options = array())
 {
     switch ($process) {
         case 'send_social_message':
             check_admin_referer('social_send-message');
             $message_count = 0;
             if (isset($options['social_message_id']) && (int) $options['social_message_id'] > 0 && isset($_POST['facebook_message']) && !empty($_POST['facebook_message'])) {
                 // we have a social message id, ready to send!
                 // which facebook accounts are we sending too?
                 $facebook_accounts = isset($_POST['compose_facebook_id']) && is_array($_POST['compose_facebook_id']) ? $_POST['compose_facebook_id'] : array();
                 foreach ($facebook_accounts as $facebook_account_id => $send_pages) {
                     $facebook_account = new ucm_facebook_account($facebook_account_id);
                     if ($facebook_account->get('social_facebook_id') == $facebook_account_id) {
                         /* @var $available_pages ucm_facebook_page[] */
                         $available_pages = $facebook_account->get('pages');
                         if ($send_pages) {
                             foreach ($send_pages as $facebook_page_id => $tf) {
                                 if (!$tf) {
                                     continue;
                                 }
                                 // shouldnt happen
                                 // see if this is an available page.
                                 if (isset($available_pages[$facebook_page_id])) {
                                     // push to db! then send.
                                     $facebook_message = new ucm_facebook_message($facebook_account, $available_pages[$facebook_page_id], false);
                                     $facebook_message->create_new();
                                     $facebook_message->update('social_facebook_page_id', $available_pages[$facebook_page_id]->get('social_facebook_page_id'));
                                     $facebook_message->update('social_message_id', $options['social_message_id']);
                                     $facebook_message->update('social_facebook_id', $facebook_account->get('social_facebook_id'));
                                     $facebook_message->update('summary', isset($_POST['facebook_message']) ? $_POST['facebook_message'] : '');
                                     if (isset($_POST['track_links']) && $_POST['track_links']) {
                                         $facebook_message->parse_links();
                                     }
                                     $facebook_message->update('type', 'pending');
                                     $facebook_message->update('link', isset($_POST['link']) ? $_POST['link'] : '');
                                     $facebook_message->update('data', json_encode($_POST));
                                     $facebook_message->update('user_id', get_current_user_id());
                                     // do we send this one now? or schedule it later.
                                     $facebook_message->update('status', _SOCIAL_MESSAGE_STATUS_PENDINGSEND);
                                     if (isset($options['send_time']) && !empty($options['send_time'])) {
                                         // schedule for sending at a different time (now or in the past)
                                         $facebook_message->update('last_active', $options['send_time']);
                                     } else {
                                         // send it now.
                                         $facebook_message->update('last_active', 0);
                                     }
                                     if (isset($_FILES['picture']['tmp_name']) && is_uploaded_file($_FILES['picture']['tmp_name'])) {
                                         $facebook_message->add_attachment($_FILES['picture']['tmp_name']);
                                     }
                                     $now = time();
                                     if (!$facebook_message->get('last_active') || $facebook_message->get('last_active') <= $now) {
                                         // send now! otherwise we wait for cron job..
                                         if ($facebook_message->send_queued(isset($_POST['debug']) && $_POST['debug'])) {
                                             $message_count++;
                                         }
                                     } else {
                                         $message_count++;
                                         if (isset($_POST['debug']) && $_POST['debug']) {
                                             echo "Message will be sent in cron job after " . print_date($facebook_message->get('last_active'), true);
                                         }
                                     }
                                 } else {
                                     // log error?
                                 }
                             }
                         }
                     }
                 }
             }
             return $message_count;
             break;
         case 'save_facebook':
             $social_facebook_id = isset($_REQUEST['social_facebook_id']) ? (int) $_REQUEST['social_facebook_id'] : 0;
             check_admin_referer('save-facebook' . $social_facebook_id);
             $facebook = new ucm_facebook_account($social_facebook_id);
             if (isset($_POST['butt_delete'])) {
                 $facebook->delete();
                 $redirect = 'admin.php?page=simple_social_inbox_facebook_settings';
             } else {
                 $facebook->save_data($_POST);
                 $social_facebook_id = $facebook->get('social_facebook_id');
                 if (isset($_POST['butt_save_reconnect'])) {
                     $redirect = $facebook->link_connect();
                 } else {
                     $redirect = $facebook->link_edit();
                 }
             }
             header("Location: {$redirect}");
             exit;
             break;
     }
 }
コード例 #2
0
									alert('Login failed. Please try again.');
								}
							},
							{scope: "manage_pages,read_page_mailboxes,publish_actions"} //, auth_type: 'reauthenticate'
						);
					},
					loggedin: function (response) {
						console.log(response);
						if (typeof response.authResponse != 'undefined' && typeof response.authResponse.accessToken != 'undefined') {
							// valid token! push this to UCM server so we can get an extended access token for use on our client side.
							/*amble.api('/facebook_token',{token: response.authResponse.accessToken}, function(data){
							 amble.log('Result from facebook token: ');
							 amble.log(data);
							 })*/
							window.location = '<?php 
                echo $facebook->link_connect();
                ?>
&login_completed=' + response.authResponse.accessToken;
						}
						FB.api('/me', function (response) {
							console.log(response);
						});
					}
				};
				if (typeof FB == 'undefined') {
					jQuery.getScript('//connect.facebook.net/en_US/all.js', ucmfacebook.loaded);
				} else {
					ucmfacebook.loaded();
				}
			</script>
			<p>Please click the button below to connect your Facebook account:</p>