Exemplo n.º 1
0
    public function process()
    {
        if ("save_facebook" == $_REQUEST['_process']) {
            $social_facebook_id = isset($_REQUEST['social_facebook_id']) ? (int) $_REQUEST['social_facebook_id'] : 0;
            $facebook = new ucm_facebook_account($social_facebook_id);
            if (isset($_POST['butt_del']) && module_social::can_i('delete', 'Facebook', 'Social', 'social')) {
                if (module_form::confirm_delete('social_facebook_id', "Really delete this Facebook account from the system? All messages will be lost.", self::link_open($_REQUEST['social_facebook_id']))) {
                    $facebook->delete();
                    set_message("Facebook account deleted successfully");
                    redirect_browser(self::link_open(false));
                }
            }
            $facebook->save_data($_POST);
            $social_facebook_id = $facebook->get('social_facebook_id');
            if (isset($_POST['butt_save_connect'])) {
                $redirect = $this->link_open($social_facebook_id, false, false, 'facebook_account_connect');
            } else {
                set_message('Facebook account saved successfully');
                $redirect = $this->link_open($social_facebook_id);
            }
            redirect_browser($redirect);
            exit;
        } else {
            if ("send_facebook_message" == $_REQUEST['_process']) {
                if (module_form::check_secure_key()) {
                    $social_facebook_id = isset($_REQUEST['social_facebook_id']) ? (int) $_REQUEST['social_facebook_id'] : 0;
                    $facebook = new ucm_facebook_account($social_facebook_id);
                    if ($social_facebook_id && $facebook->get('social_facebook_id') == $social_facebook_id) {
                        // queue the message into the facebook_message table
                        // if there's a scheduled date in the past we send it in the past, no date we send straight away, date in the future we leave it in the db table for the cron job to pick up.
                        //print_r($_POST);exit;
                        $send_time = false;
                        // default: now
                        if (isset($_POST['schedule_date']) && isset($_POST['schedule_time']) && !empty($_POST['schedule_date']) && !empty($_POST['schedule_time'])) {
                            $date = $_POST['schedule_date'];
                            $time_hack = $_POST['schedule_time'];
                            $time_hack = str_ireplace('am', '', $time_hack);
                            $time_hack = str_ireplace('pm', '', $time_hack);
                            $bits = explode(':', $time_hack);
                            if (strpos($_POST['schedule_time'], 'pm')) {
                                $bits[0] += 12;
                            }
                            // add the time if it exists
                            $date .= ' ' . implode(':', $bits) . ':00';
                            $send_time = strtotime(input_date($date, true));
                        } else {
                            if (isset($_POST['schedule_date']) && !empty($_POST['schedule_date'])) {
                                $send_time = strtotime(input_date($_POST['schedule_date'], true));
                            }
                        }
                        //echo print_date($send_time,true);
                        //echo '<br>';
                        //echo date('c',$send_time);
                        //exit;
                        /* @var $available_pages ucm_facebook_page[] */
                        $available_pages = $facebook->get('pages');
                        $send_pages = isset($_POST['compose_page_id']) && is_array($_POST['compose_page_id']) ? $_POST['compose_page_id'] : array();
                        $page_count = 0;
                        if ($send_pages) {
                            foreach ($send_pages as $facebook_page_id => $tf) {
                                if (!$tf) {
                                    continue;
                                }
                                // 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, $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_facebook_id', $facebook->get('social_facebook_id'));
                                    $facebook_message->update('summary', isset($_POST['message']) ? $_POST['message'] : '');
                                    $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', module_security::get_loggedin_id());
                                    // do we send this one now? or schedule it later.
                                    $facebook_message->update('status', _SOCIAL_MESSAGE_STATUS_PENDINGSEND);
                                    if ($send_time) {
                                        // schedule for sending at a different time (now or in the past)
                                        $facebook_message->update('last_active', $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']);
                                    }
                                    $facebook_message->send_queued(isset($_POST['debug']));
                                    $page_count++;
                                } else {
                                    // log error?
                                }
                            }
                        }
                        set_message(_l('Message delivered successfully to %s Facebook pages', $page_count));
                        $redirect = $this->link_open_message_view($social_facebook_id);
                        redirect_browser($redirect);
                    }
                }
            } else {
                if ("ajax_facebook_url_info" == $_REQUEST['_process']) {
                    header('Content-type: text/javascript');
                    $url = isset($_REQUEST['url']) ? $_REQUEST['url'] : false;
                    if (strlen($url) > 4 && preg_match('#https?://#', $url)) {
                        // pass this into graph api debugger to get some information back about the URL
                        $facebook = new ucm_facebook();
                        $data = $facebook->get_url_info($url);
                        // return the data formatted in json ready to be added into the relevant input boxes.
                        $data['link_picture'] = isset($data['image'][0]['url']) ? $data['image'][0]['url'] : '';
                        $data['link_name'] = isset($data['title']) ? $data['title'] : '';
                        $data['link_caption'] = isset($data['caption']) ? $data['caption'] : '';
                        $data['link_description'] = isset($data['description']) ? $data['description'] : '';
                        echo json_encode($data);
                    }
                    exit;
                } else {
                    if ("ajax_social_facebook" == $_REQUEST['_process']) {
                        // ajax functions from wdsocial. copied from the datafeed.php sample files.
                        header('Content-type: text/javascript');
                        if (module_form::check_secure_key()) {
                            // todo: check user has access to this message.
                            $social_facebook_id = isset($_REQUEST['social_facebook_id']) ? (int) $_REQUEST['social_facebook_id'] : 0;
                            //$facebook = new ucm_facebook_account($social_facebook_id);
                            //if($social_facebook_id && $facebook->get('social_facebook_id') == $social_facebook_id){
                            $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : false;
                            $message_id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
                            $facebook_message = new ucm_facebook_message();
                            $facebook_message->load($message_id);
                            //if($facebook_message->get('social_facebook_id') == $social_facebook_id){
                            switch ($action) {
                                case "send-message-reply":
                                    if (module_social::can_i('create', 'Facebook Comments', 'Social', 'social')) {
                                        $return = array();
                                        $message = isset($_POST['message']) && $_POST['message'] ? $_POST['message'] : '';
                                        $facebook_id = isset($_POST['facebook_id']) && $_POST['facebook_id'] ? $_POST['facebook_id'] : false;
                                        $debug = isset($_POST['debug']) && $_POST['debug'] ? $_POST['debug'] : false;
                                        if ($message) {
                                            if ($debug) {
                                                ob_start();
                                            }
                                            $facebook_message->send_reply($facebook_id, $message, $debug);
                                            if ($debug) {
                                                $return['message'] = ob_get_clean();
                                            } else {
                                                // todo - option to ask the user if they want to archive a message during the send.
                                                set_message(_l('Message sent and conversation archived.'));
                                                if ($social_facebook_id) {
                                                    $return['redirect'] = module_social_facebook::link_open_message_view($social_facebook_id);
                                                } else {
                                                    // return to the 'combined' view:
                                                }
                                            }
                                        }
                                        echo json_encode($return);
                                    }
                                    break;
                                case "set-answered":
                                    if (module_social::can_i('edit', 'Facebook Comments', 'Social', 'social')) {
                                        $facebook_message->update('status', _SOCIAL_MESSAGE_STATUS_ANSWERED);
                                        ?>

									$('.facebook_message_row[data-id=<?php 
                                        echo $message_id;
                                        ?>
]').hide();
									<?php 
                                    }
                                    break;
                                case "set-unanswered":
                                    if (module_social::can_i('edit', 'Facebook Comments', 'Social', 'social')) {
                                        $facebook_message->update('status', _SOCIAL_MESSAGE_STATUS_UNANSWERED);
                                        ?>

					                $('.facebook_message_row[data-id=<?php 
                                        echo $message_id;
                                        ?>
]').hide();
					                <?php 
                                    }
                                    break;
                            }
                            //echo 'The status is '.$facebook_message->get('status');
                            //}
                        }
                        // }
                        exit;
                    }
                }
            }
        }
    }
Exemplo n.º 2
0
    public function handle_ajax($action, $simple_social_inbox_wp)
    {
        switch ($action) {
            case 'fb_url_info':
                if (!headers_sent()) {
                    header('Content-type: text/javascript');
                }
                $url = isset($_REQUEST['url']) ? $_REQUEST['url'] : false;
                if (strlen($url) > 4 && preg_match('#https?://#', $url)) {
                    // pass this into graph api debugger to get some information back about the URL
                    $facebook = new ucm_facebook();
                    $data = $facebook->get_url_info($url);
                    // return the data formatted in json ready to be added into the relevant input boxes.
                    $data['link_picture'] = isset($data['image'][0]['url']) ? $data['image'][0]['url'] : '';
                    $data['link_name'] = isset($data['title']) ? $data['title'] : '';
                    $data['link_caption'] = isset($data['caption']) ? $data['caption'] : '';
                    $data['link_description'] = isset($data['description']) ? $data['description'] : '';
                    echo json_encode($data);
                }
                exit;
                break;
            case 'send-message-reply':
                if (!headers_sent()) {
                    header('Content-type: text/javascript');
                }
                if (isset($_REQUEST['facebook_id']) && !empty($_REQUEST['facebook_id']) && isset($_REQUEST['id']) && (int) $_REQUEST['id'] > 0) {
                    $ucm_facebook_message = new ucm_facebook_message(false, false, $_REQUEST['id']);
                    if ($ucm_facebook_message->get('social_facebook_message_id') == $_REQUEST['id']) {
                        $return = array();
                        $message = isset($_POST['message']) && $_POST['message'] ? $_POST['message'] : '';
                        $facebook_id = isset($_REQUEST['facebook_id']) && $_REQUEST['facebook_id'] ? $_REQUEST['facebook_id'] : false;
                        $debug = isset($_POST['debug']) && $_POST['debug'] ? $_POST['debug'] : false;
                        if ($message) {
                            if ($debug) {
                                ob_start();
                            }
                            $ucm_facebook_message->send_reply($facebook_id, $message, $debug);
                            if ($debug) {
                                $return['message'] = ob_get_clean();
                            } else {
                                //set_message( _l( 'Message sent and conversation archived.' ) );
                                $return['redirect'] = 'admin.php?page=simple_social_inbox_main';
                            }
                        }
                        echo json_encode($return);
                    }
                }
                break;
            case 'modal':
                if (isset($_REQUEST['socialfacebookmessageid']) && (int) $_REQUEST['socialfacebookmessageid'] > 0) {
                    $ucm_facebook_message = new ucm_facebook_message(false, false, $_REQUEST['socialfacebookmessageid']);
                    if ($ucm_facebook_message->get('social_facebook_message_id') == $_REQUEST['socialfacebookmessageid']) {
                        $social_facebook_id = $ucm_facebook_message->get('facebook_account')->get('social_facebook_id');
                        $social_facebook_message_id = $ucm_facebook_message->get('social_facebook_message_id');
                        include trailingslashit($simple_social_inbox_wp->dir) . 'pages/facebook_message.php';
                    }
                }
                break;
            case 'set-answered':
                if (!headers_sent()) {
                    header('Content-type: text/javascript');
                }
                if (isset($_REQUEST['social_facebook_message_id']) && (int) $_REQUEST['social_facebook_message_id'] > 0) {
                    $ucm_facebook_message = new ucm_facebook_message(false, false, $_REQUEST['social_facebook_message_id']);
                    if ($ucm_facebook_message->get('social_facebook_message_id') == $_REQUEST['social_facebook_message_id']) {
                        $ucm_facebook_message->update('status', _SOCIAL_MESSAGE_STATUS_ANSWERED);
                        ?>
						jQuery('.socialfacebook_message_action[data-id=<?php 
                        echo (int) $ucm_facebook_message->get('social_facebook_message_id');
                        ?>
]').parents('tr').first().hide();
						<?php 
                    }
                }
                break;
            case 'set-unanswered':
                if (!headers_sent()) {
                    header('Content-type: text/javascript');
                }
                if (isset($_REQUEST['social_facebook_message_id']) && (int) $_REQUEST['social_facebook_message_id'] > 0) {
                    $ucm_facebook_message = new ucm_facebook_message(false, false, $_REQUEST['social_facebook_message_id']);
                    if ($ucm_facebook_message->get('social_facebook_message_id') == $_REQUEST['social_facebook_message_id']) {
                        $ucm_facebook_message->update('status', _SOCIAL_MESSAGE_STATUS_UNANSWERED);
                        ?>
						jQuery('.socialfacebook_message_action[data-id=<?php 
                        echo (int) $ucm_facebook_message->get('social_facebook_message_id');
                        ?>
]').parents('tr').first().hide();
						<?php 
                    }
                }
                break;
        }
        return false;
    }