Import legacy nurinda.co.id website
This commit is contained in:
1 parent
3f59bb9038
commit
6e21646ac4
13389 files changed
+3246690
No files matched your search
@@ -0,0 +1,229 @@
|
||||
<?php
|
||||
/*
|
||||
* Based on RollingCurlX https://github.com/marcushat/rollingcurlx
|
||||
*
|
||||
* Modified for Mashshare by René Hermenau to be compatible with php 5.3 and older versions
|
||||
*
|
||||
* @scince 2.2.7
|
||||
*/
|
||||
Class RollingCurlX {
|
||||
private $_maxConcurrent = 0; //max. number of simultaneous connections allowed
|
||||
private $_options = array(); //shared cURL options
|
||||
private $_headers = array(); //shared cURL request headers
|
||||
private $_callback = NULL; //default callback
|
||||
private $_timeout = 1; //timeout used for curl_multi_select() function in seconds. Lower this to zero increases total performance.
|
||||
private $requests = array(); //request_queue
|
||||
|
||||
function __construct($max_concurrent = 10) {
|
||||
$this->setMaxConcurrent($max_concurrent);
|
||||
}
|
||||
|
||||
public function setMaxConcurrent($max_requests) {
|
||||
if($max_requests > 0) {
|
||||
$this->_maxConcurrent = $max_requests;
|
||||
}
|
||||
}
|
||||
|
||||
public function setOptions(array $options) {
|
||||
$this->_options = $options;
|
||||
}
|
||||
|
||||
public function setHeaders(array $headers) {
|
||||
if(is_array($headers) && count($headers)) {
|
||||
$this->_headers = $headers;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//public function setCallback(callable $callback) {
|
||||
public function setCallback($callback) {
|
||||
$this->_callback = $callback;
|
||||
}
|
||||
|
||||
/* Bug on php 5.3 Do not use this
|
||||
|
||||
*/
|
||||
/*public function setTimeout($timeout) { //in milliseconds
|
||||
if($timeout > 0) {
|
||||
$this->_timeout = $timeout/1000; //to seconds
|
||||
}
|
||||
}*/
|
||||
|
||||
//Add a request to the request queue
|
||||
public function addRequest(
|
||||
$url,
|
||||
array $post_data = NULL,
|
||||
array $callback = NULL,
|
||||
$user_data = NULL,
|
||||
array $options = NULL, //individual cURL options
|
||||
array $headers = NULL //individual cURL request headers
|
||||
) { //Add to request queue
|
||||
$this->requests[] = array(
|
||||
'url' => $url,
|
||||
'post_data' => ($post_data) ? $post_data : NULL,
|
||||
'callback' => ($callback) ? $callback : $this->_callback,
|
||||
'user_data' => ($user_data) ? $user_data : NULL,
|
||||
'options' => ($options) ? $options : NULL,
|
||||
'headers' => ($headers) ? $headers : NULL
|
||||
);
|
||||
return count($this->requests) - 1; //return request number/index
|
||||
}
|
||||
|
||||
//Reset request queue
|
||||
public function reset() {
|
||||
$this->requests = array();
|
||||
}
|
||||
|
||||
//Execute the request queue
|
||||
public function execute() {
|
||||
if(count($this->requests) < $this->_maxConcurrent) {
|
||||
$this->_maxConcurrent = count($this->requests);
|
||||
}
|
||||
//the request map that maps the request queue to request curl handles
|
||||
$requests_map = array();
|
||||
$multi_handle = curl_multi_init();
|
||||
//start processing the initial request queue
|
||||
for($i = 0; $i < $this->_maxConcurrent; $i++) {
|
||||
$ch = curl_init();
|
||||
|
||||
$request =& $this->requests[$i];
|
||||
$this->addTimer($request);
|
||||
|
||||
curl_setopt_array($ch, $this->buildOptions($request));
|
||||
curl_multi_add_handle($multi_handle, $ch);
|
||||
|
||||
|
||||
//add curl handle of a request to the request map
|
||||
// PHP 8: On success, this function returns a CurlMultiHandle instance now; previously on PHP 7.X and lower, a resource was returned.
|
||||
if(is_resource($ch)) {
|
||||
$key = (string) $ch;
|
||||
} else {
|
||||
$key = spl_object_hash($ch);
|
||||
}
|
||||
$requests_map[$key] = $i;
|
||||
}
|
||||
do{
|
||||
while(($mh_status = curl_multi_exec($multi_handle, $active)) == CURLM_CALL_MULTI_PERFORM);
|
||||
if($mh_status != CURLM_OK) {
|
||||
break;
|
||||
}
|
||||
|
||||
//a request is just completed, find out which one
|
||||
while($completed = curl_multi_info_read($multi_handle)) {
|
||||
$ch = $completed['handle'];
|
||||
$request_info = curl_getinfo($ch);
|
||||
if(curl_errno($ch) !== 0 || intval($request_info['http_code']) !== 200) { //if server responded with http error
|
||||
$response = json_encode(array('error'=>curl_multi_getcontent($ch)));
|
||||
} else { //sucessful response
|
||||
$response = curl_multi_getcontent($ch);
|
||||
}
|
||||
|
||||
//get request info
|
||||
if(is_resource($ch)) {
|
||||
$key = (string) $ch;
|
||||
} else {
|
||||
$key = spl_object_hash($ch);
|
||||
}
|
||||
$request =& $this->requests[$requests_map[$key]]; //map handler to request index to get request info
|
||||
$url = $request['url'];
|
||||
$callback = $request['callback'];
|
||||
$user_data = $request['user_data'];
|
||||
$options = $request['options'];
|
||||
$this->stopTimer($request); //record request time
|
||||
$time = $request['time'];
|
||||
|
||||
if($response && (isset($this->_options[CURLOPT_HEADER]) || isset($options[CURLOPT_HEADER]))) {
|
||||
$k = intval($request_info['header_size']);
|
||||
$request_info['response_header'] = substr($response, 0, $k);
|
||||
$response = substr($response, $k);
|
||||
}
|
||||
|
||||
//remove completed request and its curl handle
|
||||
unset($requests_map[$key]);
|
||||
curl_multi_remove_handle($multi_handle, $ch);
|
||||
|
||||
//call the callback function and pass request info and user data to it
|
||||
if($callback) {
|
||||
call_user_func($callback, $response, $url, $request_info, $user_data, $time);
|
||||
}
|
||||
$request = NULL; //free up memory now just incase response was large
|
||||
|
||||
//add/start a new request to the request queue
|
||||
if($i < count($this->requests) && isset($this->requests[$i])) { //if requests left
|
||||
$ch = curl_init();
|
||||
|
||||
$request =& $this->requests[$i];
|
||||
$this->addTimer($request);
|
||||
|
||||
curl_setopt_array($ch, $this->buildOptions($request));
|
||||
curl_multi_add_handle($multi_handle, $ch);
|
||||
|
||||
//add curl handle of a new request to the request map
|
||||
if(is_resource($ch)) {
|
||||
$key = (string) $ch;
|
||||
} else {
|
||||
$key = spl_object_hash($ch);
|
||||
}
|
||||
$requests_map[$key] = $i;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
if($active) {
|
||||
if(curl_multi_select($multi_handle, $this->_timeout) === -1) { //wait for activity on any connection
|
||||
usleep(5);
|
||||
}
|
||||
|
||||
}
|
||||
} while ($active || count($requests_map)); //End do-while
|
||||
|
||||
$this->reset();
|
||||
curl_multi_close($multi_handle);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Build individual cURL options for a request
|
||||
private function buildOptions(array $request) {
|
||||
$url = $request['url'];
|
||||
$post_data = $request['post_data'];
|
||||
$individual_opts = $request['options'];
|
||||
$individual_headers = $request['headers'];
|
||||
|
||||
$options = ($individual_opts) ? $individual_opts + $this->_options : $this->_options; //merge shared and individual request options
|
||||
$headers = ($individual_headers) ? $individual_headers + $this->_headers : $this->_headers; //merge shared and individual request headers
|
||||
|
||||
//the below will overide the corresponding default or individual options
|
||||
$options[CURLOPT_RETURNTRANSFER] = true;
|
||||
//$options[CURLOPT_TIMEOUT] = $this->_timeout; //timeout in ms. bug in php 5.3
|
||||
$options[CURLOPT_TIMEOUT] = 5; //timeout in seconds;
|
||||
if($url) {
|
||||
$options[CURLOPT_URL] = $url;
|
||||
}
|
||||
|
||||
if($headers) {
|
||||
$options[CURLOPT_HTTPHEADER] = $headers;
|
||||
}
|
||||
|
||||
// enable POST method and set POST parameters
|
||||
if($post_data) {
|
||||
$options[CURLOPT_POST] = 1;
|
||||
$options[CURLOPT_POSTFIELDS] = is_array($post_data)? http_build_query($post_data) : $post_data;
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function addTimer(array &$request) { //adds timer object to request
|
||||
$request['timer'] = microtime(true);
|
||||
$request['time'] = false; //default if not overridden by time later
|
||||
}
|
||||
|
||||
private function stopTimer(array &$request) {
|
||||
$start_time = $request['timer'];
|
||||
$end_time = microtime(true);
|
||||
$elapsed_time = rtrim(sprintf('%.20F', ($end_time - $start_time)), '0'); //convert float to string
|
||||
$request['time'] = $elapsed_time*1000; //
|
||||
unset($request['timer']);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,227 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Simple PHP class for interacting with the v3 bit.ly api (only deals with
|
||||
* JSON format, but supports new OAuth endpoints).
|
||||
* REQUIREMENTS: PHP, Curl, JSON
|
||||
*
|
||||
* @link https://github.com/Falicon/BitlyPHP
|
||||
* @author Kevin Marshall <info@falicon.com>
|
||||
* @author René Hermenau <info@mashshare.net>
|
||||
*/
|
||||
class mashsb_bitly_shorturl {
|
||||
|
||||
// The URI of the bitly OAuth endpoints.
|
||||
private $bitly_oauth_api;
|
||||
|
||||
// The URI for OAuth access token requests.
|
||||
private $bitly_oauth_access_token;
|
||||
|
||||
public function __construct() {
|
||||
|
||||
$this->bitly_oauth_api = 'https://api-ssl.bit.ly/v3/';
|
||||
$this->bitly_oauth_access_token = 'https://api-ssl.bit.ly/oauth/';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an OAuth access token as well as API users for a given code.
|
||||
*
|
||||
* @param $code
|
||||
* The OAuth verification code acquired via OAuth’s web authentication
|
||||
* protocol.
|
||||
* @param $redirect
|
||||
* The page to which a user was redirected upon successfully authenticating.
|
||||
* @param $client_id
|
||||
* The client_id assigned to your OAuth app. (http://bit.ly/a/account)
|
||||
* @param $client_secret
|
||||
* The client_secret assigned to your OAuth app. (http://bit.ly/a/account)
|
||||
*
|
||||
* @return
|
||||
* An associative array containing:
|
||||
* - login: The corresponding bit.ly users username.
|
||||
* - api_key: The corresponding bit.ly users API key.
|
||||
* - access_token: The OAuth access token for specified user.
|
||||
*
|
||||
* @see http://code.google.com/p/bitly-api/wiki/ApiDocumentation#/oauth/access_token
|
||||
*/
|
||||
public function bitly_oauth_access_token($code, $redirect, $client_id, $client_secret) {
|
||||
$results = array();
|
||||
$url = $this->bitly_oauth_access_token() . "access_token";
|
||||
$params = array();
|
||||
$params['client_id'] = $client_id;
|
||||
$params['client_secret'] = $client_secret;
|
||||
$params['code'] = $code;
|
||||
$params['redirect_uri'] = $redirect;
|
||||
$output = bitly_post_curl($url, $params);
|
||||
$parts = explode('&', $output);
|
||||
foreach ($parts as $part) {
|
||||
$bits = explode('=', $part);
|
||||
$results[$bits[0]] = $bits[1];
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an OAuth access token via the user's bit.ly login Username and Password
|
||||
*
|
||||
* @param $username
|
||||
* The user's Bitly username
|
||||
* @param $password
|
||||
* The user's Bitly password
|
||||
* @param $client_id
|
||||
* The client_id assigned to your OAuth app. (http://bit.ly/a/account)
|
||||
* @param $client_secret
|
||||
* The client_secret assigned to your OAuth app. (http://bit.ly/a/account)
|
||||
*
|
||||
* @return
|
||||
* An associative array containing:
|
||||
* - access_token: The OAuth access token for specified user.
|
||||
*
|
||||
*/
|
||||
public function bitly_oauth_access_token_via_password($username, $password, $client_id, $client_secret) {
|
||||
$results = array();
|
||||
$url = bitly_oauth_access_token . "access_token";
|
||||
|
||||
$headers = array();
|
||||
$headers[] = 'Authorization: Basic ' . base64_encode($client_id . ":" . $client_secret);
|
||||
|
||||
$params = array();
|
||||
$params['grant_type'] = "password";
|
||||
$params['username'] = $username;
|
||||
$params['password'] = $password;
|
||||
|
||||
$output = bitly_post_curl($url, $params, $headers);
|
||||
|
||||
$decoded_output = json_decode($output, 1);
|
||||
|
||||
$results = array(
|
||||
"access_token" => $decoded_output['access_token']
|
||||
);
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a GET call to the bit.ly API.
|
||||
*
|
||||
* @param $endpoint
|
||||
* bit.ly API endpoint to call.
|
||||
* @param $params
|
||||
* associative array of params related to this call.
|
||||
* @param $complex
|
||||
* set to true if params includes associative arrays itself (or using <php5)
|
||||
*
|
||||
* @return
|
||||
* associative array of bit.ly response
|
||||
*
|
||||
* @see http://code.google.com/p/bitly-api/wiki/ApiDocumentation#/v3/validate
|
||||
*/
|
||||
public function bitly_get($endpoint, $params, $complex = false) {
|
||||
|
||||
$result = array();
|
||||
if ($complex) {
|
||||
$url_params = "";
|
||||
foreach ($params as $key => $val) {
|
||||
if (is_array($val)) {
|
||||
// we need to flatten this into one proper command
|
||||
$recs = array();
|
||||
foreach ($val as $rec) {
|
||||
$tmp = explode('/', $rec);
|
||||
$tmp = array_reverse($tmp);
|
||||
array_push($recs, $tmp[0]);
|
||||
}
|
||||
$val = implode('&' . $key . '=', $recs);
|
||||
}
|
||||
$url_params .= '&' . $key . "=" . $val;
|
||||
}
|
||||
$url = $this->bitly_oauth_api . $endpoint . "?" . substr($url_params, 1);
|
||||
} else {
|
||||
$url = $this->bitly_oauth_api . $endpoint . "?" . http_build_query($params);
|
||||
}
|
||||
|
||||
//echo $url . "\n";
|
||||
|
||||
$result = json_decode($this->bitly_get_curl($url), true);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a POST call to the bit.ly API.
|
||||
*
|
||||
* @param $uri
|
||||
* URI to call.
|
||||
* @param $fields
|
||||
* Array of fields to send.
|
||||
*/
|
||||
function bitly_post($endpoint, $params) {
|
||||
$result = array();
|
||||
$url = bitly_oauth_api . $api_endpoint;
|
||||
$output = json_decode(bitly_post_curl($url, $params), true);
|
||||
$result = $output['data'][str_replace('/', '_', $api_endpoint)];
|
||||
$result['status_code'] = $output['status_code'];
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a GET call to the bit.ly API.
|
||||
*
|
||||
* @param $uri
|
||||
* URI to call.
|
||||
*/
|
||||
private function bitly_get_curl($uri) {
|
||||
$output = "";
|
||||
try {
|
||||
$ch = curl_init($uri);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
$output = curl_exec($ch);
|
||||
} catch (Exception $e) {
|
||||
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a POST call to the bit.ly API.
|
||||
*
|
||||
* @param $uri
|
||||
* URI to call.
|
||||
* @param $fields
|
||||
* Array of fields to send.
|
||||
*/
|
||||
private function bitly_post_curl($uri, $fields, $header_array = array()) {
|
||||
$output = "";
|
||||
$fields_string = "";
|
||||
foreach ($fields as $key => $value) {
|
||||
$fields_string .= $key . '=' . urlencode($value) . '&';
|
||||
}
|
||||
rtrim($fields_string, '&');
|
||||
try {
|
||||
$ch = curl_init($uri);
|
||||
|
||||
if (is_array($header_array) && !empty($header_array)) {
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $header_array);
|
||||
}
|
||||
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_POST, count($fields));
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 2);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
$output = curl_exec($ch);
|
||||
} catch (Exception $e) {
|
||||
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of googl-php
|
||||
*
|
||||
* https://github.com/sebi/googl-php
|
||||
*
|
||||
* googl-php is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
class mashsb_google_shorturl
|
||||
{
|
||||
public $extended;
|
||||
private $target;
|
||||
private $apiKey;
|
||||
private $ch;
|
||||
|
||||
private static $buffer = array();
|
||||
|
||||
function __construct($apiKey = null) {
|
||||
|
||||
# Extended output mode
|
||||
$extended = false;
|
||||
|
||||
# Set Google Shortener API target
|
||||
$this->target = 'https://www.googleapis.com/urlshortener/v1/url?';
|
||||
|
||||
# Set API key if available
|
||||
if ( $apiKey != null ) {
|
||||
$this->apiKey = $apiKey;
|
||||
$this->target .= 'key='.$apiKey.'&';
|
||||
}
|
||||
|
||||
# Initialize cURL
|
||||
$this->ch = curl_init();
|
||||
# Set our default target URL
|
||||
curl_setopt($this->ch, CURLOPT_URL, $this->target);
|
||||
# We don't want the return data to be directly outputted, so set RETURNTRANSFER to true
|
||||
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
|
||||
}
|
||||
|
||||
public function shorten($url, $extended = false) {
|
||||
|
||||
# Check buffer
|
||||
if ( !$extended && !$this->extended && !empty(self::$buffer[$url]) ) {
|
||||
return self::$buffer[$url];
|
||||
}
|
||||
|
||||
# Payload
|
||||
$data = array( 'longUrl' => $url );
|
||||
$data_string = '{ "longUrl": "'.$url.'" }';
|
||||
|
||||
# Set cURL options
|
||||
curl_setopt($this->ch, CURLOPT_POST, count($data));
|
||||
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $data_string);
|
||||
curl_setopt($this->ch, CURLOPT_HTTPHEADER, Array('Content-Type: application/json'));
|
||||
|
||||
if ( $extended || $this->extended) {
|
||||
return json_decode(curl_exec($this->ch));
|
||||
} else {
|
||||
|
||||
if (isset(json_decode(curl_exec($this->ch))->id)){
|
||||
$ret = json_decode(curl_exec($this->ch))->id;
|
||||
self::$buffer[$url] = $ret;
|
||||
return $ret;
|
||||
}
|
||||
return '';
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function expand($url, $extended = false) {
|
||||
# Set cURL options
|
||||
curl_setopt($this->ch, CURLOPT_HTTPGET, true);
|
||||
curl_setopt($this->ch, CURLOPT_URL, $this->target.'shortUrl='.$url);
|
||||
|
||||
if ( $extended || $this->extended ) {
|
||||
return json_decode(curl_exec($this->ch));
|
||||
} else {
|
||||
return json_decode(curl_exec($this->ch))->longUrl;
|
||||
}
|
||||
}
|
||||
|
||||
public function checkApiKey($url, $extended = true) {
|
||||
|
||||
# Check buffer
|
||||
if ( !$extended && !$this->extended && !empty(self::$buffer[$url]) ) {
|
||||
return self::$buffer[$url];
|
||||
}
|
||||
|
||||
# Payload
|
||||
$data = array( 'longUrl' => $url );
|
||||
$data_string = '{ "longUrl": "'.$url.'" }';
|
||||
|
||||
# Set cURL options
|
||||
curl_setopt($this->ch, CURLOPT_POST, count($data));
|
||||
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $data_string);
|
||||
curl_setopt($this->ch, CURLOPT_HTTPHEADER, Array('Content-Type: application/json'));
|
||||
|
||||
if ( $extended || $this->extended) {
|
||||
return json_decode(curl_exec($this->ch), true);
|
||||
} else {
|
||||
$ret = json_decode(curl_exec($this->ch))->id;
|
||||
self::$buffer[$url] = $ret;
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
function __destruct() {
|
||||
# Close the curl handle
|
||||
curl_close($this->ch);
|
||||
# Nulling the curl handle
|
||||
$this->ch = null;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in new issue
Block a user