Example #1
0
<?php

/** 
 * Copyright: dtbaker 2012
 * Licence: Please check CodeCanyon.net for licence details. 
 * More licence clarification available here:  http://codecanyon.net/wiki/support/legal-terms/licensing-terms/ 
 * Deploy: 9809 f200f46c2a19bb98d112f2d32a8de0c4
 * Envato: 4ffca17e-861e-4921-86c3-8931978c40ca
 * Package Date: 2015-11-25 02:55:20 
 * IP Address: 67.79.165.254
 */
if (_DEMO_MODE) {
    ?>
	<p>Demo Mode Notice: <strong>This is a public demo. Please only use TEST accounts here as others will see them.</strong></p>
	<?php 
}
if (isset($_REQUEST['social_facebook_id']) && !empty($_REQUEST['social_facebook_id'])) {
    $social_facebook_id = (int) $_REQUEST['social_facebook_id'];
    $social_facebook = module_social_facebook::get($social_facebook_id);
    include 'facebook_account_edit.php';
} else {
    include 'facebook_account_list.php';
}
?>
</th>-->
    </tr>
    </thead>
    <tbody>
    <?php 
$c = 0;
foreach ($facebook_accounts as $facebook_account) {
    ?>
        <tr class="<?php 
    echo $c++ % 2 ? "odd" : "even";
    ?>
">
            <td class="row_action">
                <?php 
    echo module_social_facebook::link_open($facebook_account['social_facebook_id'], true, $facebook_account);
    ?>
            </td>
            <td>
                <?php 
    echo print_date($facebook_account['last_checked'], true);
    ?>
            </td>
            <!--<td>
                <?php 
    /*
     */
    ?>
            </td>-->
        </tr>
    <?php 
        });
        $table_manager->set_columns($columns);
        $table_manager->row_callback = function ($message) use(&$facebook, &$table_manager) {
            $facebook_message = new ucm_facebook_message($facebook, $message['page'], $message['social_facebook_message_id']);
            $table_manager->row_class = 'facebook_message_row' . (!isset($message['read_time']) || !$message['read_time'] ? ' message_row_unread' : '');
            $table_manager->row_attributes = array('data-id' => (int) $message['social_facebook_message_id']);
            return array('facebook_message' => $facebook_message, 'comments' => $facebook_message->get_comments());
        };
        $table_manager->set_rows($all_messages);
        $table_manager->pagination = true;
        $table_manager->print_table();
        ?>
	    </form>
	    <script type="text/javascript">
		    $(function () {
			    ucm.social.init();
			    ucm.social.facebook.api_url = '<?php 
        echo module_social_facebook::link_social_ajax_functions($social_facebook_id);
        ?>
';
			    ucm.social.facebook.init();
		    });
	    </script>

		<div id="social_modal_popup" title="">
		    <div class="modal_inner" style="height:100%;"></div>
		</div>

    <?php 
    }
}
Example #4
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;
                    }
                }
            }
        }
    }
				            </li>
			            </ul>
		            <?php 
})), array('title' => _l('Account Name'), 'field' => array('type' => 'text', 'name' => 'facebook_name', 'value' => $facebook->get('facebook_name'), 'help' => 'Choose a name for this account. This name will be shown here in the system.')), array('title' => _l('Facebook App ID'), 'field' => array('type' => 'text', 'name' => 'facebook_app_id', 'value' => $facebook->get('facebook_app_id'), 'help' => 'The App ID (see instructions above). Leave blank to use defaults.')), array('title' => _l('Facebook App Secret'), 'field' => array('type' => 'text', 'name' => 'facebook_app_secret', 'value' => $facebook->get('facebook_app_secret'), 'help' => 'The App Secret (see instructions above). Leave blank to use defaults.'))));
// check if this is active, if not prmopt the user to re-connect.
if ($facebook->is_active()) {
    $fieldset_data['elements'][] = array('title' => _l('Last Checked'), 'fields' => array(print_date($facebook->get('last_checked'), true)));
    $pages = array('title' => _l('Available Pages'), 'fields' => array('<input type="hidden" name="save_facebook_pages" value="yep">'));
    $data = @json_decode($facebook->get('facebook_data'), true);
    if ($data && isset($data['pages']) && is_array($data['pages']) && count($data['pages']) > 0) {
        $pages['fields'][] = '<strong>Choose which Facebook Pages you would like to manage:</strong><br>';
        foreach ($data['pages'] as $page_id => $page_data) {
            $pages['fields'][] = '<div>';
            $pages['fields'][] = array('type' => 'check', 'name' => 'facebook_page[' . $page_id . ']', 'value' => 1, 'label' => $page_data['name'], 'checked' => $facebook->is_page_active($page_id));
            if ($facebook->is_page_active($page_id)) {
                $pages['fields'][] = '(<a href="' . module_social_facebook::link_open_facebook_page_refresh($social_facebook_id, $page_id, false, false) . '" target="_blank">manually re-load page data</a>)';
            }
            $pages['fields'][] = '</div>';
        }
    } else {
        $pages['fields'][] = 'No Facebook Pages Found to Manage';
    }
    $fieldset_data['elements'][] = $pages;
} else {
}
echo module_form::generate_fieldset($fieldset_data);
$form_actions = array('class' => 'action_bar action_bar_center', 'elements' => array());
echo module_form::generate_form_actions($form_actions);
if (!$facebook->is_active()) {
    // show a 'save' and button as normal
    $form_actions['elements'][] = array('type' => 'save_button', 'name' => 'butt_save_connect', 'value' => _l('Save & Connect to Facebook'));
Example #6
0
 public function link_new_message()
 {
     return module_social_facebook::link_open_facebook_message($this->get('social_facebook_id'), false);
 }
			    });
			    $('.facebook-type-'+currenttype).each(function(){
				    $(this).parents('tr').first().show();
			    });

		    }
		    $(function(){
			    $('[name=post_type]').change(change_post_type);
			    $('#message_link_url').change(function(){
				    $('#facebook_link_loading_message').html('<?php 
        _e('Loading URL information...');
        ?>
');
				    $.ajax({
					    url: '<?php 
        echo module_social_facebook::link_open_message_view($social_facebook_id);
        ?>
',
					    data: {_process:'ajax_facebook_url_info', url: $(this).val()},
					    dataType: 'json',
					    success: function(res){
						    $('.facebook-type-link').each(function(){
							    var elm = $(this).parent().find('input');
							    if(res && typeof res[elm.attr('name')] != 'undefined'){
								    elm.val(res[elm.attr('name')]);
							    }
						    });
					    },
					    complete: function(){
						    $('#facebook_link_loading_message').html('');
					    }
				};
				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>
			<a href="#" id="facebook-login-button"><img
					src="<?php 
                echo full_link('/includes/plugin_social_facebook/inc/connect.jpg');
                ?>
" width="90"
					height="25" title="Connect to Facebook" border="0"></a>

		<?php 
            }
        } else {
            // no app / secret defined, use the default UCM ones.
            ?>
		<iframe src="http://ultimateclientmanager.com/api/facebook/login.php?return=<?php 
            echo urlencode(module_social_facebook::link_open($social_facebook_id, false, false, 'facebook_account_connect'));
            ?>
&codes=<?php 
            echo urlencode(htmlspecialchars(module_config::c('_installation_code')));
            ?>
" frameborder="0" style="width:100%; height:600px; background: transparent" ALLOWTRANSPARENCY="true"></iframe>
	<?php 
        }
    }
}
        ?>
">
				<td class="row_action">
					<img src="<?php 
        echo _BASE_HREF;
        ?>
includes/plugin_social_facebook/images/facebook.png"
					     class="facebook_icon">
					<?php 
        echo htmlspecialchars($facebook_account->get('facebook_name'));
        ?>
					<br/>
				</td>
				<td>
					<a href="<?php 
        echo module_social_facebook::link_open_facebook_message($account['social_facebook_id'], false);
        ?>
" class="socialfacebook_message_open social_modal btn btn-success btn-sm" data-modal-title="<?php 
        _e('Compose Post');
        ?>
"><?php 
        _e('Compose Post');
        ?>
</a>
				</td>
			</tr>
		<?php 
    }
}
if (module_social::can_i('create', 'Twitter Comments', 'Social', 'social')) {
    $accounts = module_social_twitter::get_accounts();