function scrape_libe($search_term, $d, $m, $y)
{
    //finds the day after
    $next_day = getDayAfter($d, $m, $y);
    $d_next = $next_day[0];
    $m_next = $next_day[1];
    $y_next = $next_day[2];
    //splits the different keywords, if there are several
    $search_term = urldecode($search_term);
    $keywords = explode(", ", $search_term);
    $num_articles = 0;
    foreach ($keywords as $term) {
        $term = urlencode(trim($term));
        $url = "http://recherche.liberation.fr/recherche/?q={$term}&period=custom&period_start_day={$d}&period_start_month={$m}&period_start_year={$y}&period_end_day={$d_next}&period_end_month={$m_next}&period_end_year={$y_next}&editorial_source=&paper_channel=&sort=-publication_date_time";
        $html = utf8_decode(run_curl($url));
        $pattern = "/<p>(\\d*) r.sultat/s";
        $preg = preg_match($pattern, $html, $matches, PREG_OFFSET_CAPTURE);
        if ($preg) {
            $num_articles += $matches[1][0];
        } else {
            $num_articles = 0;
        }
    }
    echo $num_articles;
}
Example #2
0
function refreshToken($refresh_token)
{
    //construct POST object required for refresh token fetch
    $postvals = array('grant_type' => 'refresh_token', 'client_id' => KEY, 'client_secret' => SECRET, 'refresh_token' => $refresh_token);
    //return JSON refreshed access token object
    return json_decode(run_curl(ACCESS_TOKEN_ENDPOINT, 'POST', $postvals));
}
function get_pco_data($url,$method = "GET",$content = Null){
	global $pco_key, $pco_secret, $user_access_token, $user_access_token_secret;

	$test_consumer  = new OAuthConsumer($pco_key, $pco_secret, NULL);
	$access_consumer = new OAuthConsumer($user_access_token, $user_access_token_secret, NULL);

	// build and sign request
	$request = OAuthRequest::from_consumer_and_token($test_consumer,
	  $access_consumer, 
	  $method,
	  $url, 
	  NULL);
	$request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(),
	  $test_consumer, 
	  $access_consumer
	);
	
	if (isset($content)){
		//define request headers
		$headers = array("Accept: application/xml");
		$headers[] = $request->to_header();
		$headers[] = "Content-type: application/xml";
		$response = run_curl($url, $method, $headers, $content);
	}
	else {
		// make GET request
		$response = run_curl($request, $method);
	}
	
	return $response;

}
Example #4
0
function refreshToken($key, $secret, $refresh_token)
{
    //set URL to be used for refresh access token request
    $url = "https://api.gowalla.com/api/oauth/token";
    //construct POST object required for refresh token fetch
    $postvals = array('grant_type' => 'refresh_token', 'client_id' => $key, 'client_secret' => $secret, 'refresh_token' => $refresh_token);
    //return JSON refreshed access token object
    return json_decode(run_curl($url, 'POST', null, $postvals));
}
function check_connected_to_pco($id=0){
	global $user_access_token, $user_access_token_secret, $pco_key, $pco_secret, $request_token_endpoint, $callback_url, $authorize_endpoint;
	$needs_pco_attach = 0;
	
	if ($id > 0){
		if ((isset($user_access_token)) && ($user_access_token != "")){ //if the access token has been previously set and stored, then make sure it works.
			$url = sprintf("https://www.planningcenteronline.com/organization.xml");
			$test_consumer  = new OAuthConsumer($pco_key, $pco_secret, NULL);
			$access_consumer = new OAuthConsumer($user_access_token, $user_access_token_secret, NULL);
			
			// build and sign request
			$request = OAuthRequest::from_consumer_and_token($test_consumer,
			  $access_consumer, 
			  'GET',
			  $url, 
			  NULL);
			$request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(),
			  $test_consumer, 
			  $access_consumer
			);

			// make request
			$response = run_curl($request, 'GET');
			if ($response == "API call not authorized."){
				$needs_pco_attach = 1;
			}
		}
		else{ //if not, the user needs attaching to a planning center account, so flag this:
			$needs_pco_attach = 1;
		}
	
		if ($needs_pco_attach == 1){
			//grab the calling url:
			$calling_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
			$_SESSION['calling_url'] = $calling_url;
			
			//initialize consumer
			$consumer = new OAuthConsumer($pco_key, $pco_secret, NULL);

			//prepare to get request token
			$sig_method = new OAuthSignatureMethod_HMAC_SHA1();
			$parsed = parse_url($request_token_endpoint);
			$params = array('oauth_callback' => $callback_url);

			//sign request and get request token
			$req_req = OAuthRequest::from_consumer_and_token($consumer, NULL, "GET", $request_token_endpoint, $params);
			$req_req->sign_request($sig_method, $consumer, NULL);
			$req_token = run_curl($req_req->to_url(), 'GET');

			//if fetching request token was successful we should have oauth_token and oauth_token_secret
			parse_str($req_token, $tokens);
			$oauth_token = $tokens['oauth_token'];
			$oauth_token_secret = $tokens['oauth_token_secret'];

			//store pco_key and token details in cookie to pass to complete stage
			setcookie("requestToken", "key=$pco_key&token=$oauth_token&token_secret=$oauth_token_secret");
				   
			//build authentication url following sign-in and redirect user
			$auth_url = $authorize_endpoint . "?oauth_token=$oauth_token";
			header("Location: $auth_url");	
		
		}
	
	}
}
Example #6
0
<?php

require_once "oauth_config.php";
require_once "helpers.php";
require_once "oauth.php";
$consumer = new OAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET, NULL);
$access_token = new OAuthConsumer($_COOKIE['oauth_token'], $_COOKIE['oauth_token_secret'], NULL);
$url = "https://services.planningcenteronline.com/me.json";
$request = OAuthRequest::from_consumer_and_token($consumer, $access_token, "GET", $url, NULL);
$request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, $access_token);
$response = run_curl($request, "GET");
$me = json_decode($response);
printf("Hello " . $me->first_name);
Example #7
0
<?php

require_once "common.php";
//capture code from auth
$code = $_GET["code"];
//construct POST object for access token fetch request
$postvals = array('grant_type' => 'authorization_code', 'client_id' => $key, 'client_secret' => $secret, 'code' => $code, 'redirect_uri' => $callback_url);
//get JSON access token object (with refresh_token parameter)
$token = json_decode(run_curl($access_token_endpoint, 'POST', null, $postvals));
echo "<h1>TOKEN</h1>";
var_dump($token);
echo "<br /><br />";
//set request headers for signed OAuth request
$headers = array("Accept: application/json");
//construct URI to fetch profile information for current user
$profile_url = "https://api.gowalla.com/users/me?oauth_token=" . $token->access_token;
//fetch profile of current user
$profile = run_curl($profile_url, 'GET', $headers);
var_dump($profile);
echo "<h1>REFRESHING TOKEN</h1>";
var_dump(refreshToken($key, $secret, $token->refresh_token));
$token_secret   = $request_token_array["token_secret"];
$oauth_verifier = $_GET['oauth_verifier'];

//create required consumer variables
$test_consumer  = new OAuthConsumer($key, $secret, NULL);
$req_token      = new OAuthConsumer($token, $token_secret, NULL);
$sig_method     = new OAuthSignatureMethod_HMAC_SHA1();
//echo "<p>============================================</p>";
//echo $req_token;
//echo "<p>============================================</p>";

//exchange authenticated request token for access token
$params         = array('oauth_verifier' => $oauth_verifier);
$acc_req        = OAuthRequest::from_consumer_and_token($test_consumer, $req_token, "GET", $oauth_access_token_endpoint, $params);
$acc_req->sign_request($sig_method, $test_consumer, $req_token);
$access_ret     = run_curl($acc_req->to_url(), 'GET');

// //if access token fetch succeeded, we should have oauth_token and oauth_token_secret parse and generate access consumer from values
parse_str($access_ret, $access_token);
// echo "<p>============================================</p>";
// echo print_r($access_token);
// echo "<p>============================================</p>";

$access_consumer = new OAuthConsumer($access_token['oauth_token'], $access_token['oauth_token_secret'], NULL);

// =========== NOTE: Important =======================
// The $access_token array here is what you want to save to your db for your application. 
// That way you can repull out the oauth_token and oauth_token_secret any time you wish
// and re-initiate the consumer without going back to the oauth authorize page.
// 
// The Array looks something like this:
Example #9
0
<?php

require_once "oauth_config.php";
require_once "helpers.php";
require_once "oauth.php";
$consumer = new OAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET, NULL);
$request_token = new OAuthConsumer($_COOKIE["oauth_token"], $_COOKIE["oauth_token_secret"], NULL);
$params = array("oauth_verifier" => $_GET['oauth_verifier']);
$access_token_request = OAuthRequest::from_consumer_and_token($consumer, $request_token, "GET", "https://services.planningcenteronline.com/oauth/access_token", $params);
$access_token_request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, $request_token);
$access_token_response = run_curl($access_token_request->to_url(), "GET");
parse_str($access_token_response, $access_token_request);
setcookie("oauth_token", $access_token_request['oauth_token']);
setcookie("oauth_token_secret", $access_token_request['oauth_token_secret']);
header("Location: /me.php");
Example #10
0
<?php

require_once "OAuth.php";
//oauth library
require_once "common.php";
//common functions and variables
//initialize consumer
$consumer = new OAuthConsumer($key, $secret, NULL);
//prepare to get request token
$sig_method = new OAuthSignatureMethod_HMAC_SHA1();
$parsed = parse_url($request_token_endpoint);
$params = array('oauth_callback' => $base_url);
//sign request and get request token
$req_req = OAuthRequest::from_consumer_and_token($consumer, NULL, "GET", $request_token_endpoint, $params);
$req_req->sign_request($sig_method, $consumer, NULL);
$req_token = run_curl($req_req->to_url(), 'GET');
//if fetching request token was successful we should have oauth_token and oauth_token_secret
parse_str($req_token, $tokens);
$oauth_token = $tokens['oauth_token'];
$oauth_token_secret = $tokens['oauth_token_secret'];
//store key and token details in cookie to pass to complete stage
setcookie("requestToken", "key={$key}&token={$oauth_token}&token_secret={$oauth_token_secret}");
//build authentication url following sign-in and redirect user
$auth_url = $authorize_endpoint . "?oauth_token={$oauth_token}";
header("Location: {$auth_url}");
Example #11
0
//build update PUT request payload
$guid = $access_token['xoauth_yahoo_guid'];
$title = 'New update';
//arbitrary title
$description = 'The time is now ' . date("g:i a");
//arbitrary desc
$link = 'http://en.wikipedia.org/wiki/Haiku#Examples';
//arbitrary link
$source = 'APP.' . $appid;
//note: 'APP.' syntax
$date = time();
$suid = 'uniquestring' . time();
//arbitrary, unique string
$body = array("updates" => array(array("collectionID" => $guid, "collectionType" => "guid", "class" => "app", "source" => $source, "type" => 'appActivity', "suid" => $suid, "title" => $title, "description" => $description, "link" => $link, "pubDate" => (string) $date)));
//build update PUT request URL
$url = sprintf("http://%s/v1/user/%s/updates/%s/%s", 'social.yahooapis.com', $guid, $source, urlencode($suid));
//build and sign request
$request = OAuthRequest::from_consumer_and_token($test_consumer, $access_consumer, 'PUT', $url, array());
$request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $test_consumer, $access_consumer);
//define request headers
$headers = array("Accept: application/json");
$headers[] = $request->to_header();
$headers[] = "Content-type: application/json";
//json encode request payload and make PUT request
$content = json_encode($body);
$resp = run_curl($url, 'PUT', $headers, $content);
//if debug mode, dump signatures & headers
if ($debug) {
    $debug_out = array('Access token' => $access_token, 'PUT URL' => $url, 'PUT headers' => $headers, 'PUT content' => $content, 'PUT response' => $resp);
    print_r($debug_out);
}
Example #12
0
<?php

require_once "oauth.php";
require_once "helpers.php";
require_once "oauth_config.php";
$consumer = new OAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET, NULL);
$params = array("oauth_callback" => CALLBACK_URL);
$request_token_request = OAuthRequest::from_consumer_and_token($consumer, NULL, "GET", "https://services.planningcenteronline.com/oauth/request_token", $params);
$request_token_request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, NULL);
$request_token_response = run_curl($request_token_request->to_url(), "GET");
parse_str($request_token_response, $request_token);
setcookie("oauth_token", $request_token["oauth_token"]);
setcookie("oauth_token_secret", $request_token["oauth_token_secret"]);
$authorization_url = "https://services.planningcenteronline.com/oauth/authorize?oauth_token=" . $request_token["oauth_token"];
header("Location: {$authorization_url}");
             $info_data = mysql_get_rows('messages', array('where' => "payment_id='{$payment_data['id']}' AND msg_type='1'"), 1);
             $return_data['dd'] = 'Before ' . date('Y-m-d H:i:s', strtotime($payment_data['order_start_date']) + $info_data['days'] * 86400);
         } elseif ($job_type == 5 && in_array($payment_data['job_status'], array(3))) {
             updateDB("job_status = 5", "WHERE id = '{$pi}'", 'payments');
         } elseif ($job_type == 6) {
             updateDB("job_status = 6", "WHERE id = '{$pi}'", 'payments');
             $return_data['dd'] = '-';
         }
         if (in_array($job_type, array(2, 4, 5, 6)) && !is_null($payment_data['bkid']) && $payment_data['bkid'] !== '') {
             $user_data = mysql_get_rows('users', array('where' => "id='{$user_id}'"), 1);
             $curl_pay_data = $payment_data;
             unlink($curl_pay_data['post_data']);
             $curl_data = array('job_type' => $job_type, 'time' => $time, 'bkid' => $payment_data['bkid'], 'email' => $user_data['email'], 'payment_data' => $curl_pay_data, 'access' => md5('dmexpert-to-basekit-api'));
             $extra_data = array(CURLOPT_REFERER => 'http://www.dmexpert.net');
             $url = BK_URL . 'agent/dashboard/updatemessage';
             run_curl($url, $curl_data, $extra_data);
         }
     }
     ob_start();
     include "msg_display.php";
     $html = ob_get_contents();
     ob_end_clean();
     $return_data['html'] = $html;
     $return_data['rtype'] = $rtype;
     $return_data['status'] = 1;
     $return_data['message'] = 'Message sent successfully';
 } else {
     $messages = '';
     foreach ($v->errors() as $k => $msgs) {
         foreach ($msgs as $msg) {
             $messages .= $msg . "<br>";
Example #14
0
<?php

require_once "common.php";
//capture code from auth
$code = $_GET["code"];
//build access token request URI
$token_url = $access_token_endpoint . "?client_id={$key}&" . "redirect_uri=" . urlencode($callback_url) . "&" . "client_secret={$secret}&" . "code={$code}";
//get access token & expiration - parse individual params
$token_obj = explode('&', run_curl($token_url, 'GET'));
$token = explode('=', $token_obj[0]);
$token = $token[1];
//display token
echo "<h1>ACCESS TOKEN</h1>";
var_dump($token);
echo "<br /><br />";
//construct URI to fetch profile information for current user
$friends_uri = "https://graph.facebook.com/me/friends?access_token=" . $token;
//fetch profile of current user and decode
$friends = json_decode(run_curl($friends_uri, 'GET'));
//print profile
echo "<h1>CURRENT USER FRIENDS</h1>";
var_dump($friends);
                    } else {
                        $log_msg .= date('Y-m-d H:i:s') . " " . $pid . " MODS datastream failed\r\n";
                        echo "Failed to create MODS datastream for " . $pid . " ... exit the script!<br>\r\n";
                        exit;
                    }
                }
                if (strtolower($file->getExtension()) == 'jpg' || strtolower($file->getExtension()) == 'png') {
                    $mime = strtolower($file->getExtension()) == 'jpg' ? 'image/jpeg' : 'image/png';
                    $url = $base_url . '/fedora/objects/' . $pid . '/datastreams/TN?controlGroup=M&dsLabel=TN&mimeType=' . $mime;
                    if (function_exists('curl_file_create')) {
                        // PHP 5.5+
                        $request = array('file' => curl_file_create($file->getPathname(), 'image/jpeg', $file->getFilename()));
                    } else {
                        $request = array('file' => '@' . $file->getPathname());
                    }
                    $response = run_curl($url, $username, $pass, NULL, $request);
                    if ($response['httpcode'] == 201) {
                        $log_msg .= date('Y-m-d H:i:s') . " " . $pid . " TN datastream is created and ingested successfully\r\n";
                        $pid = $resXML->pid;
                    } else {
                        $log_msg .= date('Y-m-d H:i:s') . " " . $pid . " TN datastream failed\r\n";
                        echo "Failed to create TN datastream for " . $pid . " ... exit the script!<br>\r\n";
                        exit;
                    }
                }
            }
            // End Process each file based on their extension or filename
        }
    }
}
// Log message
Example #16
0
function submit_job($job)
{
    if (!is_string($job)) {
        $job = json_encode($job);
    }
    return run_curl("jobs", $_SERVER['QUERY_STRING'], function ($ch) use($job) {
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $job);
    });
}
Example #17
0
    }
    curl_close($ch);
    return $response;
}
if ($action == 'complete') {
    //capture code from auth
    $code = $_GET["code"];
    //construct POST object for access token fetch request
    $postvals = array('grant_type' => 'authorization_code', 'client_id' => KEY, 'client_secret' => SECRET, 'code' => $code, 'redirect_uri' => CALLBACK_URL);
    //get JSON access token object (with refresh_token parameter)
    $sReturn = run_curl(ACCESS_TOKEN_ENDPOINT, 'POST', $postvals);
    $token = json_decode($sReturn);
    //construct URI to fetch profile for current user
    $profile_url = "https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=" . $token->access_token;
    //fetch profile of current user
    $oProfile = json_decode(run_curl($profile_url, 'GET'));
    $sSocialId = 'google:' . $oProfile->id;
    $sStart = date("Y-m-d h:i:s");
    if (file_exists('../../model/users.json')) {
        $oUsers = json_decode(file_get_contents('../../model/users.json'));
        $sOldSession = $oUsers->{$sSocialId}->session;
        if (isset($oUsers->{$sOldSession})) {
            unset($oUsers->{$sOldSession});
        }
    } else {
        if (!is_dir('../../model')) {
            mkdir('../../model');
        }
        $oUsers = new stdClass();
        $oUsers->{$sSocialId}->badmin = 1;
    }
                $sig_method = new OAuthSignatureMethod_HMAC_SHA1();
                //manually generate request token object
                $req_token = new stdclass();
                $req_token->key = $attributes['openid_oauth_request_token'];
                $req_token->secret = '';
                //generate access token object
                $acc_req = OAuthRequest::from_consumer_and_token($consumer, $req_token, "GET", $oauth_access_token_endpoint, array());
                $acc_req->sign_request($sig_method, $consumer, $req_token);
                $access_ret = run_curl($acc_req->to_url(), 'GET');
                //if access token fetch succeeded, we should have oauth_token and oauth_token_secret
                //parse and generate access consumer from values
                $access_token = array();
                parse_str($access_ret, $access_token);
                $access_consumer = new OAuthConsumer($access_token['oauth_token'], $access_token['oauth_token_secret'], NULL);
                //build profile GET request URL
                $guid = $access_token['xoauth_yahoo_guid'];
                $url = sprintf("http://%s/v1/user/%s/profile", 'social.yahooapis.com', $guid);
                //build and sign request
                $request = OAuthRequest::from_consumer_and_token($consumer, $access_consumer, 'GET', $url, array());
                $request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, $access_consumer);
                //make GET request
                $resp = run_curl($request->to_url(), 'GET');
                //if debug mode, dump signatures & headers from OpenID / OAuth process
                if ($debug) {
                    $debug_out = array('OpenID Response' => $response_state, 'Access token' => $access_token, 'GET URL' => $url, 'GET response' => htmlentities($resp));
                    print_r($debug_out);
                }
            }
        }
    }
}
Example #19
0
<?php

require_once "common.php";
//capture code from auth
$code = $_GET["code"];
//construct POST object for access token fetch request
$postvals = sprintf("client_id=%s&client_secret=%s&grant_type=authorization_code&code=%s&redirect_uri=%s", KEY, SECRET, $code, urlencode(CALLBACK_URL));
//get JSON access token object (with refresh_token parameter)
$token = json_decode(run_curl(ACCESS_TOKEN_ENDPOINT, 'POST', $postvals));
//construct URI to fetch profile information for current user
$profile_url = sprintf("%s?oauth_token=%s", PROFILE_ENDPOINT, $token->access_token);
//fetch profile of current user
$profile = run_curl($profile_url);
var_dump($profile);
Example #20
0
<?php

require_once "common.php";
//capture code from auth
$code = $_GET["code"];
//construct POST object for access token fetch request
$postvals = array('grant_type' => 'authorization_code', 'client_id' => KEY, 'client_secret' => SECRET, 'code' => $code, 'redirect_uri' => CALLBACK_URL);
//get JSON access token object (with refresh_token parameter)
$token = json_decode(run_curl(ACCESS_TOKEN_ENDPOINT, 'POST', $postvals));
//set request headers for signed OAuth request
$headers = array("Accept: application/json");
//construct URI to fetch contact information for current user
$contact_url = "https://www.google.com/m8/feeds/contacts/default/full?oauth_token=" . $token->access_token;
//fetch profile of current user
$contacts = run_curl($contact_url, 'GET', $headers);
var_dump($contacts);
echo "<h1>REFRESHING TOKEN</h1>";
var_dump(refreshToken($token->refresh_token));