예제 #1
0
 public function import_limit_reached($extension, $user_id, $username = null)
 {
     //different day ot no day set, set the day and the counter to 0;
     if (bebop_tables::get_user_meta_value($user_id, 'bebop_' . $extension . '_' . $username . '_counterdate') != date('dmy')) {
         bebop_tables::update_user_meta($user_id, $extension, 'bebop_' . $extension . '_' . $username . '_daycounter', '0');
         bebop_tables::update_user_meta($user_id, $extension, 'bebop_' . $extension . '_' . $username . '_counterdate', date('dmy'));
     }
     //max items per day * < should return false*
     $maximport_value = bebop_tables::get_option_value('bebop_' . $extension . '_maximport');
     if (empty($maximport_value) || $maximport_value === 0) {
         //its empty. no value is set (unlimited)
         return false;
     } else {
         if (is_numeric($maximport_value)) {
             //not empty but value is numeric
             if (bebop_tables::get_user_meta_value($user_id, 'bebop_' . $extension . '_' . $username . '_daycounter') < $maximport_value) {
                 return false;
             }
         }
     }
     //otherwise limit must be have been met.
     return true;
 }
예제 #2
0
function bebop_manage_provider()
{
    global $bp;
    if (bp_is_current_component('bebop') && bp_is_current_action('bebop-accounts')) {
        $query_string = bp_action_variables();
        if (!empty($query_string)) {
            $provider = $query_string[0];
        }
        if (!empty($provider)) {
            global $bp;
            $extension = bebop_extensions::bebop_get_extension_config_by_name(strtolower($provider));
            if (isset($_POST['submit'])) {
                check_admin_referer('bebop_' . $extension['name'] . '_user_settings');
                if (isset($_POST['bebop_' . $extension['name'] . '_active_for_user'])) {
                    bebop_tables::update_user_meta($bp->loggedin_user->id, $extension['name'], 'bebop_' . $extension['name'] . '_active_for_user', $_POST['bebop_' . $extension['name'] . '_active_for_user']);
                    bp_core_add_message(sprintf(__('Settings for %1$s have been saved.', 'bebop'), $extension['display_name']));
                }
                if (!empty($_POST['bebop_' . $extension['name'] . '_username'])) {
                    $new_name = stripslashes($_POST['bebop_' . $extension['name'] . '_username']);
                    if (bebop_tables::add_user_meta($bp->loggedin_user->id, $extension['name'], 'bebop_' . $extension['name'] . '_username', $new_name, $check_meta_value = true)) {
                        bebop_tables::add_to_first_importers_list($bp->loggedin_user->id, $extension['name'], 'bebop_' . $extension['name'] . '_' . $new_name . '_do_initial_import', $new_name);
                        bp_core_add_message(sprintf(__('%1$s has been added to the %2$s feed.', 'bebop'), $new_name, $extension['display_name']));
                    } else {
                        bp_core_add_message(sprintf(__('%1$s already exists in the %2$s feed; you cannot add it again.', 'bebop'), $new_name, $extension['display_name']), __('error', 'bebop'));
                    }
                }
                //Try and add a new RSS feed.
                if (!empty($_POST['bebop_' . $extension['name'] . '_newfeedname']) && !empty($_POST['bebop_' . $extension['name'] . '_newfeedurl'])) {
                    if (filter_var($_POST['bebop_' . $extension['name'] . '_newfeedurl'], FILTER_VALIDATE_URL)) {
                        $insert_url = $_POST['bebop_' . $extension['name'] . '_newfeedurl'];
                        $new_name = str_replace(' ', '_', stripslashes(strip_tags($_POST['bebop_' . $extension['name'] . '_newfeedname'])));
                        if (bebop_tables::add_user_meta($bp->loggedin_user->id, $extension['name'] . '_' . $new_name, $new_name, strip_tags($insert_url))) {
                            bebop_tables::add_to_first_importers_list($bp->loggedin_user->id, $extension['name'], 'bebop_' . $extension['name'] . '_' . $new_name . '_do_initial_import', $new_name);
                            bp_core_add_message(__('Feed successfully added.', 'bebop'));
                        } else {
                            bp_core_add_message(__('This feed already exists, you cannot add it again.', 'bebop'), __('error', 'bebop'));
                        }
                    } else {
                        bp_core_add_message(__('That feed cannot be added as it is not a valid URL.', 'bebop'), __('error', 'bebop'));
                    }
                }
                //
                //Extension authors: use this hook to add your own data saves.
                do_action('bebop_user_settings_pre_edit_save', $extension);
                bp_core_redirect($bp->loggedin_user->domain . bp_current_component() . '/' . bp_current_action());
            }
            //End if ( isset( $_POST['submit'] ) ) {
            //Twitter Oauth stuff
            if (isset($_GET['oauth_token'])) {
                //Handle the oAuth requests
                $OAuth = new bebop_oauth();
                $OAuth->set_request_token_url($extension['request_token_url']);
                $OAuth->set_access_token_url($extension['access_token_url']);
                $OAuth->set_authorize_url($extension['authorize_url']);
                $OAuth->set_parameters(array('oauth_verifier' => $_GET['oauth_verifier']));
                $OAuth->set_callback_url($bp->loggedin_user->domain . bp_current_component() . '/' . bp_current_action() . '/' . $extension['name']);
                $OAuth->set_consumer_key(bebop_tables::get_option_value('bebop_' . $extension['name'] . '_consumer_key'));
                $OAuth->set_consumer_secret(bebop_tables::get_option_value('bebop_' . $extension['name'] . '_consumer_secret'));
                $OAuth->set_request_token(bebop_tables::get_user_meta_value($bp->loggedin_user->id, 'bebop_' . $extension['name'] . '_oauth_token_temp'));
                $OAuth->set_request_token_secret(bebop_tables::get_user_meta_value($bp->loggedin_user->id, 'bebop_' . $extension['name'] . '_oauth_token_secret_temp'));
                $accessToken = $OAuth->access_token();
                bebop_tables::update_user_meta($bp->loggedin_user->id, $extension['name'], 'bebop_' . $extension['name'] . '_oauth_token', $accessToken['oauth_token']);
                bebop_tables::update_user_meta($bp->loggedin_user->id, $extension['name'], 'bebop_' . $extension['name'] . '_oauth_token_secret', $accessToken['oauth_token_secret']);
                bebop_tables::update_user_meta($bp->loggedin_user->id, $extension['name'], 'bebop_' . $extension['name'] . '_active_for_user', 1);
                bebop_tables::add_to_first_importers_list($bp->loggedin_user->id, $extension['name'], 'bebop_' . $extension['name'] . '_do_initial_import', 1);
                bp_core_add_message(sprintf(__('You have successfully authenticated your %1$s account.', 'bebop'), $extension['display_name']));
                bp_core_redirect($bp->loggedin_user->domain . bp_current_component() . '/' . bp_current_action());
            }
            //Facebook oAuth stuff.
            if (isset($_REQUEST['code'])) {
                $app_id = bebop_tables::get_option_value('bebop_' . $extension['name'] . '_consumer_key');
                $app_secret = bebop_tables::get_option_value('bebop_' . $extension['name'] . '_consumer_secret');
                $my_url = urlencode($bp->loggedin_user->domain . bp_current_component() . '/' . bp_current_action() . '/' . $extension['name'] . '?scope=read_stream');
                if ($_SESSION['facebook_state'] == $_GET['state']) {
                    $code = $_GET['code'];
                    $accessTokenUrl = str_replace('APP_ID', $app_id, $extension['access_token_url']);
                    $accessTokenUrl = str_replace('REDIRECT_URI', $my_url, $accessTokenUrl);
                    $accessTokenUrl = str_replace('APP_SECRET', $app_secret, $accessTokenUrl);
                    $accessTokenUrl = str_replace('CODE', $code, $accessTokenUrl);
                    $response = file_get_contents($accessTokenUrl);
                    parse_str($response, $params);
                    //extend access token
                    $extendedAccessTokenUrl = str_replace('APP_ID', $app_id, $extension['extend_access_token_url']);
                    $extendedAccessTokenUrl = str_replace('APP_SECRET', $app_secret, $extendedAccessTokenUrl);
                    $extendedAccessTokenUrl = str_replace('SHORT_TOKEN', $params['access_token'], $extendedAccessTokenUrl);
                    $response2 = file_get_contents($extendedAccessTokenUrl);
                    parse_str($response2, $params2);
                    //save the extended access token
                    if (isset($params['access_token'])) {
                        bebop_tables::update_user_meta($bp->loggedin_user->id, $extension['name'], 'bebop_' . $extension['name'] . '_oauth_token', $params2['access_token']);
                        bebop_tables::update_user_meta($bp->loggedin_user->id, $extension['name'], 'bebop_' . $extension['name'] . '_active_for_user', 1);
                        bebop_tables::add_to_first_importers_list($bp->loggedin_user->id, $extension['name'], 'bebop_' . $extension['name'] . '_do_initial_import', 1);
                        bp_core_add_message(sprintf(__('You have successfully authenticated your %1$s account.', 'bebop'), $extension['display_name']));
                        bp_core_redirect($bp->loggedin_user->domain . bp_current_component() . '/' . bp_current_action());
                        unset($_SESSION['facebook_state']);
                    }
                }
            }
            //delete a user's feed
            if (isset($_GET['delete_feed'])) {
                $feed_name = str_replace(' ', '_', stripslashes(urldecode($_GET['delete_feed'])));
                $check_feed = bebop_tables::get_user_meta_value($bp->loggedin_user->id, $feed_name);
                if (!empty($check_feed)) {
                    if (filter_var($check_feed, FILTER_VALIDATE_URL)) {
                        if (bebop_tables::remove_user_meta($bp->loggedin_user->id, $feed_name)) {
                            bebop_tables::delete_from_first_importers($bp->loggedin_user->id, $extension['name'], 'bebop_' . $extension['name'] . '_' . $feed_name . '_do_initial_import');
                            bp_core_add_message(__('Feed successfully deleted.', 'bebop'));
                            //bp_core_redirect( $bp->loggedin_user->domain  . bp_current_component() . '/' . bp_current_action() );
                        } else {
                            bp_core_add_message(__('We could not delete that feed.', 'bebop'), __('error', 'bebop'));
                            bp_core_redirect($bp->loggedin_user->domain . bp_current_component() . '/' . bp_current_action());
                        }
                    }
                }
            }
            //resets the user's data - twitter
            if (isset($_GET['reset'])) {
                bebop_tables::remove_user_meta($bp->loggedin_user->id, 'bebop_' . $extension['name'] . '_username');
            }
            //resets the user's data - other
            if (isset($_GET['remove_username'])) {
                $username = stripslashes($_GET['remove_username']);
                if (bebop_tables::remove_user_meta_value($bp->loggedin_user->id, $username)) {
                    bp_core_add_message(sprintf(__('%1$s has been removed from your %2$s feed.', 'bebop'), $username, $extension['display_name']));
                    bp_core_redirect($bp->loggedin_user->domain . bp_current_component() . '/' . bp_current_action());
                } else {
                    bp_core_add_message(__('We could not delete that feed.', 'bebop'), __('error', 'bebop'));
                    bp_core_redirect($bp->loggedin_user->domain . bp_current_component() . '/' . bp_current_action());
                }
            }
            //Extension authors: use this hook to add your own removal functionality.
            do_action('bebop_admin_settings_pre_remove', $extension);
        }
        //End if ( !empty( $provider ) ) {
    }
    //End if ( bp_is_current_component( 'bebop' ) && bp_is_current_action('bebop-accounts' ) ) {
}
예제 #3
0
function bebop_facebook_import($extension, $user_metas = null)
{
    global $wpdb, $bp;
    if (empty($extension)) {
        bebop_tables::log_general('Importer', 'The $extension parameter is empty.');
        return false;
    } else {
        if (!bebop_tables::check_option_exists('bebop_' . $extension . '_consumer_key')) {
            bebop_tables::log_general('Importer', 'No consumer key was found for ' . $extension);
            return false;
        } else {
            $this_extension = bebop_extensions::bebop_get_extension_config_by_name($extension);
        }
    }
    //item counter for in the logs
    $itemCounter = 0;
    //if no user_metas are supplied, serarch for them.
    if (!isset($user_metas)) {
        $user_metas = bebop_tables::get_user_ids_from_meta_name('bebop_' . $this_extension['name'] . '_oauth_token');
    }
    if (isset($user_metas)) {
        foreach ($user_metas as $user_meta) {
            $errors = null;
            $items = null;
            //Ensure the user is currently wanting to import items.
            if (bebop_tables::get_user_meta_value($user_meta->user_id, 'bebop_' . $this_extension['name'] . '_active_for_user') == 1) {
                //if it is the first import, update the flag.
                if (bebop_tables::check_for_first_import($user_meta->user_id, $this_extension['name'], 'bebop_' . $this_extension['name'] . '_do_initial_import')) {
                    bebop_tables::delete_from_first_importers($user_meta->user_id, $this_extension['name'], 'bebop_' . $this_extension['name'] . '_do_initial_import');
                }
                /* 
                 * ******************************************************************************************************************
                 * Depending on the data source, you will need to switch how the data is retrieved. If the feed is RSS, use the 	*
                 * SimplePie method, as shown in the youtube extension. If the feed is oAuth API based, use the oAuth implementation*
                 * as shown in the twitter extension. If the feed is an API without oAuth authentication, use SlideShare			*
                 * ******************************************************************************************************************
                 */
                $data_request = new bebop_data();
                $params = array('limit' => '30', 'access_token' => bebop_tables::get_user_meta_value($user_meta->user_id, 'bebop_' . $this_extension['name'] . '_oauth_token'));
                $data = $data_request->execute_request($this_extension['data_feed'], $params);
                $items = json_decode($data);
                /* 
                 * ******************************************************************************************************************
                 * We can get as far as loading the items, but you will need to adjust the values of the variables below to match 	*
                 * the values from the extension's API.																				*
                 * This is because each API return data under different parameter names, and the simplest way to get around this is *
                 * to quickly match the values. To find out what values you should be using, consult the provider's documentation.	*
                 * You can also contact us if you get stuck - details are in the 'support' section of the admin homepage.			*
                 * ******************************************************************************************************************
                 * 
                 * Values you will need to check and update are:
                 *		$errors 				- Must point to the error boolean value (true/false)
                 *		$username				- Must point to the value holding the username of the person.
                 *		$id						- Must be the ID of the item returned through the data API.
                 *		$item_content			- The actual content of the imported item.
                 *		$item_published			- The time the item was published.
                 *		$action_link			- This is where the link will point to - i.e. where the user can click to get more info.
                 */
                //Edit the following two variables to point to where the relevant content is being stored in the API:
                if (isset($items->error)) {
                    bebop_tables::log_error(sprintf(__('Importer - %1$s', 'bebop'), $this_extension['display_name']), sprintf(__('Feed Error: %1$s', 'bebop'), serialize($data->error)));
                } else {
                    if (!bebop_tables::check_user_meta_exists($user_meta->user_id, 'bebop_' . $this_extension['name'] . '_username')) {
                        $get_username = true;
                    } else {
                        $get_username = false;
                        $username = bebop_tables::get_user_meta_value($user_meta->user_id, 'bebop_' . $this_extension['name'] . '_username');
                    }
                    if ($items) {
                        foreach ($items->data as $item) {
                            //if its a story, break as we only want wall posts, not comments.
                            if (isset($item->message)) {
                                //if the username doesnt exist, add it.
                                if ($get_username == true) {
                                    $this_user_id = substr($item->id, 0, strpos($item->id, '_'));
                                    $user_query_data = $data_request->execute_request($this_extension['people_data'] . $this_user_id);
                                    $user = json_decode($user_query_data);
                                    $username = $user->name;
                                    bebop_tables::update_user_meta($user_meta->user_id, $this_extension['name'], 'bebop_' . $this_extension['name'] . '_username', $username);
                                    $get_username = false;
                                }
                                if (!bebop_filters::import_limit_reached($this_extension['name'], $user_meta->user_id, $username)) {
                                    //Edit the following three variables to point to where the relevant content is being stored:
                                    $id = $item->id;
                                    $item_content = $item->message;
                                    $item_published = gmdate('Y-m-d H:i:s', strtotime($item->created_time));
                                    if (isset($item->actions[0]->link)) {
                                        $action_link = $item->actions[0]->link;
                                    } else {
                                        if (isset($item->link)) {
                                            $action_link = $item->link;
                                        }
                                    }
                                    //Stop editing - you should be all done.
                                    //generate an $item_id
                                    $item_id = bebop_generate_secondary_id($user_meta->user_id, $id, $item_published);
                                    //if the id is not found, import the content.
                                    if (!bebop_tables::check_existing_content_id($user_meta->user_id, $this_extension['name'], $item_id)) {
                                        if (bebop_create_buffer_item(array('user_id' => $user_meta->user_id, 'extension' => $this_extension['name'], 'type' => $this_extension['content_type'], 'username' => $username, 'content' => $item_content, 'content_oembed' => $this_extension['content_oembed'], 'item_id' => $item_id, 'raw_date' => $item_published, 'actionlink' => $action_link))) {
                                            $itemCounter++;
                                        }
                                    }
                                }
                            }
                            //End if ( isset( $item->message ) ) {
                            unset($item);
                        }
                    }
                }
                //End else
                unset($user_meta);
            }
        }
    }
    //return the result
    return $itemCounter . ' ' . $this_extension['content_type'] . 's';
}
예제 #4
0
        echo '</form>';
    } else {
        echo '<h5>' . sprintf(__('%1$s Setup', 'bebop'), $extension['display_name']) . '</h5>
		<p>' . sprintf(__('You can setup %1$s integration here.', 'bebop'), $extension['display_name']) . '</p>
		</p>' . sprintf(__('Before you can begin using %1$s with this site you must authorise on %1$s by clicking the link below.', 'bebop'), $extension['display_name']) . '</p>';
        //oauth
        $OAuth = new bebop_oauth();
        $OAuth->set_request_token_url($extension['request_token_url']);
        $OAuth->set_access_token_url($extension['access_token_url']);
        $OAuth->set_authorize_url($extension['authorize_url']);
        $OAuth->set_callback_url($bp->loggedin_user->domain . bp_current_component() . '/' . bp_current_action() . '/' . $extension['name']);
        $OAuth->set_consumer_key(bebop_tables::get_option_value('bebop_' . $extension['name'] . '_consumer_key'));
        $OAuth->set_consumer_secret(bebop_tables::get_option_value('bebop_' . $extension['name'] . '_consumer_secret'));
        //get the oauth token
        $requestToken = $OAuth->request_token();
        $OAuth->set_request_token($requestToken['oauth_token']);
        $OAuth->set_request_token_secret($requestToken['oauth_token_secret']);
        bebop_tables::update_user_meta($bp->loggedin_user->id, $extension['name'], 'bebop_' . $extension['name'] . '_oauth_token_temp', '' . $requestToken['oauth_token'] . '');
        bebop_tables::update_user_meta($bp->loggedin_user->id, $extension['name'], 'bebop_' . $extension['name'] . '_oauth_token_secret_temp', '' . $requestToken['oauth_token_secret'] . '');
        //get the redirect url for the user
        $redirectUrl = $OAuth->get_redirect_url();
        if ($redirectUrl) {
            echo '<div class="button_container"><a class="button" href="' . $redirectUrl . '">' . __(' Start Authorisation', 'bebop') . '</a></div>';
            echo '<div class="clear_both"></div>';
        } else {
            _e('authentication is all broken :(', 'bebop');
        }
    }
} else {
    echo sprintf(__('%1$s has not yet been configured. Please contact the blog admin to make sure %1$s is configured properly.', 'bebop'), $extension['display_name']);
}