mirror of
https://github.com/e107inc/e107.git
synced 2025-07-29 10:50:25 +02:00
CURL init cleanup.
This commit is contained in:
47
class2.php
47
class2.php
@@ -407,14 +407,14 @@ e107::getSingleton('e107_traffic'); // We start traffic counting ASAP
|
|||||||
$sql = e107::getDb(); //TODO - find & replace $sql, $e107->sql
|
$sql = e107::getDb(); //TODO - find & replace $sql, $e107->sql
|
||||||
$sql->db_SetErrorReporting(FALSE);
|
$sql->db_SetErrorReporting(FALSE);
|
||||||
|
|
||||||
$sql->db_Mark_Time('Start: SQL Connect');
|
$sql->db_Mark_Time('SQL Connect');
|
||||||
$merror=$sql->db_Connect($mySQLserver, $mySQLuser, $mySQLpassword, $mySQLdefaultdb);
|
$merror=$sql->db_Connect($mySQLserver, $mySQLuser, $mySQLpassword, $mySQLdefaultdb);
|
||||||
|
|
||||||
// create after the initial connection.
|
// create after the initial connection.
|
||||||
//DEPRECATED, BC, call the method only when needed
|
//DEPRECATED, BC, call the method only when needed
|
||||||
$sql2 = e107::getDb('sql2'); //TODO find & replace all $sql2 calls
|
$sql2 = e107::getDb('sql2'); //TODO find & replace all $sql2 calls
|
||||||
|
|
||||||
$sql->db_Mark_Time('Start: Prefs, misc tables');
|
$sql->db_Mark_Time('Prefs, misc tables');
|
||||||
|
|
||||||
//DEPRECATED, BC, call the method only when needed, $e107->admin_log caught by __get()
|
//DEPRECATED, BC, call the method only when needed, $e107->admin_log caught by __get()
|
||||||
$admin_log = e107::getAdminLog(); //TODO - find & replace $admin_log, $e107->admin_log
|
$admin_log = e107::getAdminLog(); //TODO - find & replace $admin_log, $e107->admin_log
|
||||||
@@ -440,7 +440,7 @@ e107_require_once(e_HANDLER.'php_compatibility_handler.php');
|
|||||||
//
|
//
|
||||||
// L: Extract core prefs from the database
|
// L: Extract core prefs from the database
|
||||||
//
|
//
|
||||||
$sql->db_Mark_Time('Start: Extract Core Prefs');
|
$sql->db_Mark_Time('Extract Core Prefs');
|
||||||
|
|
||||||
// TODO - remove it from here, auto-loaded when required
|
// TODO - remove it from here, auto-loaded when required
|
||||||
e107_require_once(e_HANDLER.'cache_handler.php');
|
e107_require_once(e_HANDLER.'cache_handler.php');
|
||||||
@@ -527,7 +527,7 @@ if(e107::getPref('ssl_enabled') && !deftrue('e_SSL_DISABLE'))
|
|||||||
|
|
||||||
// $sql->db_Mark_Time('(Extracting Core Prefs Done)');
|
// $sql->db_Mark_Time('(Extracting Core Prefs Done)');
|
||||||
|
|
||||||
$sql->db_Mark_Time('Start: Init Language and detect changes');
|
$sql->db_Mark_Time('Init Language and detect changes');
|
||||||
$lng = e107::getLanguage(); // required for v1.0 BC.
|
$lng = e107::getLanguage(); // required for v1.0 BC.
|
||||||
$lng->detect();
|
$lng->detect();
|
||||||
|
|
||||||
@@ -622,7 +622,7 @@ if(!empty($pref['redirectsiteurl']) && !empty($pref['siteurl'])) {
|
|||||||
// to avoid multi-language 'access-denied' issues.
|
// to avoid multi-language 'access-denied' issues.
|
||||||
//session_start(); see e107::getSession() above
|
//session_start(); see e107::getSession() above
|
||||||
e107::getSession(); //init core _SESSION - actually here for reference only, it's done by language handler set() method
|
e107::getSession(); //init core _SESSION - actually here for reference only, it's done by language handler set() method
|
||||||
$sql->db_Mark_Time('Start: Set User Language Session');
|
$sql->db_Mark_Time('Set User Language Session');
|
||||||
e107::getLanguage()->set(); // set e_LANGUAGE, USERLAN, Language Session / Cookies etc. requires $pref;
|
e107::getLanguage()->set(); // set e_LANGUAGE, USERLAN, Language Session / Cookies etc. requires $pref;
|
||||||
|
|
||||||
if(varset($pref['multilanguage']) && (e_LANGUAGE != $pref['sitelanguage']))
|
if(varset($pref['multilanguage']) && (e_LANGUAGE != $pref['sitelanguage']))
|
||||||
@@ -635,7 +635,7 @@ if(varset($pref['multilanguage']) && (e_LANGUAGE != $pref['sitelanguage']))
|
|||||||
// e107_include_once(e_LANGUAGEDIR.e_LANGUAGE.'/'.e_LANGUAGE.'.php');
|
// e107_include_once(e_LANGUAGEDIR.e_LANGUAGE.'/'.e_LANGUAGE.'.php');
|
||||||
// e107_include_once(e_LANGUAGEDIR.e_LANGUAGE.'/'.e_LANGUAGE.'_custom.php');
|
// e107_include_once(e_LANGUAGEDIR.e_LANGUAGE.'/'.e_LANGUAGE.'_custom.php');
|
||||||
// v1 Custom language File Path.
|
// v1 Custom language File Path.
|
||||||
$sql->db_Mark_Time('Start: Include Global Core Language Files');
|
$sql->db_Mark_Time('Include Global Core Language Files');
|
||||||
if((e_ADMIN_AREA === true) && !empty($pref['adminlanguage']))
|
if((e_ADMIN_AREA === true) && !empty($pref['adminlanguage']))
|
||||||
{
|
{
|
||||||
include(e_LANGUAGEDIR.$pref['adminlanguage'].'/'.$pref['adminlanguage'].'.php');
|
include(e_LANGUAGEDIR.$pref['adminlanguage'].'/'.$pref['adminlanguage'].'.php');
|
||||||
@@ -662,7 +662,7 @@ unset($customLan, $customLan2);
|
|||||||
|
|
||||||
$lng->bcDefs(); // defined v1.x definitions for old templates.
|
$lng->bcDefs(); // defined v1.x definitions for old templates.
|
||||||
|
|
||||||
$sql->db_Mark_Time('Start: Include Global Plugin Language Files');
|
$sql->db_Mark_Time('Include Global Plugin Language Files');
|
||||||
if(isset($pref['lan_global_list']))
|
if(isset($pref['lan_global_list']))
|
||||||
{
|
{
|
||||||
foreach($pref['lan_global_list'] as $path)
|
foreach($pref['lan_global_list'] as $path)
|
||||||
@@ -673,7 +673,7 @@ if(isset($pref['lan_global_list']))
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
$sql->db_Mark_Time('Start: CHAP challenge');
|
$sql->db_Mark_Time('CHAP challenge');
|
||||||
|
|
||||||
$die = (e_AJAX_REQUEST == true) ? false : true;
|
$die = (e_AJAX_REQUEST == true) ? false : true;
|
||||||
e107::getSession()
|
e107::getSession()
|
||||||
@@ -684,7 +684,7 @@ unset($die);
|
|||||||
//
|
//
|
||||||
// N: misc setups: online user tracking, cache
|
// N: misc setups: online user tracking, cache
|
||||||
//
|
//
|
||||||
$sql->db_Mark_Time('Start: Misc resources. Online user tracking, cache');
|
$sql->db_Mark_Time('Misc resources. Online user tracking, cache');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -698,15 +698,15 @@ $override = e107::getSingleton('override', true); //TODO - find & replace $overr
|
|||||||
//DEPRECATED, BC, call the method only when needed, $e107->user_class caught by __get()
|
//DEPRECATED, BC, call the method only when needed, $e107->user_class caught by __get()
|
||||||
$e_userclass = e107::getUserClass(); //TODO - find & replace $e_userclass, $e107->user_class
|
$e_userclass = e107::getUserClass(); //TODO - find & replace $e_userclass, $e107->user_class
|
||||||
|
|
||||||
$sql->db_Mark_Time('Start: Init Event Handler');
|
$sql->db_Mark_Time('Init Event Handler');
|
||||||
e107::getEvent()->init();
|
e107::getEvent()->init();
|
||||||
$sql->db_Mark_Time('Start: Register Core Events');
|
$sql->db_Mark_Time('Register Core Events');
|
||||||
e107::getNotify()->registerEvents();
|
e107::getNotify()->registerEvents();
|
||||||
|
|
||||||
//
|
//
|
||||||
// O: Start user session
|
// O: Start user session
|
||||||
//
|
//
|
||||||
$sql -> db_Mark_Time('Start: User session');
|
$sql -> db_Mark_Time('User session');
|
||||||
init_session(); // Set up a lot of the user-related constants
|
init_session(); // Set up a lot of the user-related constants
|
||||||
|
|
||||||
|
|
||||||
@@ -781,7 +781,7 @@ if (isset($pref['modules']) && $pref['modules']) {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sql->db_Mark_Time('Start: Load Plugin Modules');
|
$sql->db_Mark_Time('Load Plugin Modules');
|
||||||
|
|
||||||
$js_body_onload = array(); // Initialise this array in case a module wants to add to it
|
$js_body_onload = array(); // Initialise this array in case a module wants to add to it
|
||||||
|
|
||||||
@@ -803,7 +803,7 @@ if(isset($pref['e_module_list']) && $pref['e_module_list'])
|
|||||||
// P: THEME LOADING
|
// P: THEME LOADING
|
||||||
//
|
//
|
||||||
|
|
||||||
$sql->db_Mark_Time('Start: Load Theme');
|
$sql->db_Mark_Time('Load Theme');
|
||||||
|
|
||||||
//########### Module redefinable functions ###############
|
//########### Module redefinable functions ###############
|
||||||
if (!function_exists('checkvalidtheme'))
|
if (!function_exists('checkvalidtheme'))
|
||||||
@@ -886,7 +886,7 @@ if (!function_exists('checkvalidtheme'))
|
|||||||
//
|
//
|
||||||
// Q: ALL OTHER SETUP CODE
|
// Q: ALL OTHER SETUP CODE
|
||||||
//
|
//
|
||||||
$sql->db_Mark_Time('Start: Misc Setup');
|
$sql->db_Mark_Time('Misc Setup');
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------------------------------------------------//
|
//------------------------------------------------------------------------------------------------------------------------------------//
|
||||||
if (!class_exists('e107table', false))
|
if (!class_exists('e107table', false))
|
||||||
@@ -1017,7 +1017,7 @@ $ns = e107::getRender(); //TODO - find & replace $ns, $e107->ns
|
|||||||
|
|
||||||
// EONE-134 - bad e_module could destroy e107 instance
|
// EONE-134 - bad e_module could destroy e107 instance
|
||||||
$e107 = e107::getInstance(); // Is this needed now?
|
$e107 = e107::getInstance(); // Is this needed now?
|
||||||
$sql->db_Mark_Time('Start: IP Handler and Ban Check');
|
$sql->db_Mark_Time('IP Handler and Ban Check');
|
||||||
e107::getIPHandler()->ban();
|
e107::getIPHandler()->ban();
|
||||||
|
|
||||||
if(varset($pref['force_userupdate']) && USER && !isset($_E107['no_forceuserupdate']) && $_SERVER['QUERY_STRING'] !== 'logout')
|
if(varset($pref['force_userupdate']) && USER && !isset($_E107['no_forceuserupdate']) && $_SERVER['QUERY_STRING'] !== 'logout')
|
||||||
@@ -1029,7 +1029,7 @@ if(varset($pref['force_userupdate']) && USER && !isset($_E107['no_forceuserupdat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql->db_Mark_Time('Start: Signup/splash/admin');
|
$sql->db_Mark_Time('Signup/splash/admin');
|
||||||
|
|
||||||
|
|
||||||
if(($pref['membersonly_enabled'] && !isset($_E107['allow_guest'])) || ($pref['maintainance_flag'] && empty($_E107['cli']) && empty($_E107['no_maintenance'])))
|
if(($pref['membersonly_enabled'] && !isset($_E107['allow_guest'])) || ($pref['maintainance_flag'] && empty($_E107['cli']) && empty($_E107['no_maintenance'])))
|
||||||
@@ -1047,7 +1047,7 @@ if(!isset($_E107['no_prunetmp']))
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$sql->db_Mark_Time('Start: Login/logout/ban/tz');
|
$sql->db_Mark_Time('Login/logout/ban/tz');
|
||||||
|
|
||||||
|
|
||||||
if (isset($_POST['userlogin']) || isset($_POST['userlogin_x']))
|
if (isset($_POST['userlogin']) || isset($_POST['userlogin_x']))
|
||||||
@@ -1139,7 +1139,7 @@ define('TIMEOFFSET', $e_deltaTime);
|
|||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
$sql->db_Mark_Time('Start: Find/Load Theme');
|
$sql->db_Mark_Time('Find/Load Theme');
|
||||||
|
|
||||||
if(e_ADMIN_AREA) // Load admin phrases ASAP
|
if(e_ADMIN_AREA) // Load admin phrases ASAP
|
||||||
{
|
{
|
||||||
@@ -1175,7 +1175,7 @@ if(!defined('THEME'))
|
|||||||
|
|
||||||
$theme_pref = varset($pref['sitetheme_pref']);
|
$theme_pref = varset($pref['sitetheme_pref']);
|
||||||
// --------------------------------------------------------------
|
// --------------------------------------------------------------
|
||||||
$sql->db_Mark_Time('Start: Find/Load Theme-Layout'); // needs to run after checkvalidtheme() (for theme previewing).
|
$sql->db_Mark_Time('Find/Load Theme-Layout'); // needs to run after checkvalidtheme() (for theme previewing).
|
||||||
|
|
||||||
if(!defined("THEME_LAYOUT"))
|
if(!defined("THEME_LAYOUT"))
|
||||||
{
|
{
|
||||||
@@ -1258,15 +1258,17 @@ if(!defined("THEME_LAYOUT"))
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
|
||||||
$sql->db_Mark_Time('Start: Get menus');
|
|
||||||
if(!isset($_E107['no_menus']))
|
if(!isset($_E107['no_menus']))
|
||||||
{
|
{
|
||||||
|
$sql->db_Mark_Time('Init Menus');
|
||||||
e107::getMenu()->init();
|
e107::getMenu()->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
// here we USE the theme
|
// here we USE the theme
|
||||||
if(e_ADMIN_AREA)
|
if(e_ADMIN_AREA)
|
||||||
{
|
{
|
||||||
|
$sql->db_Mark_Time('Loading Admin Theme');
|
||||||
if(file_exists(THEME.'admin_theme.php')&&(strpos(e_SELF.'?'.e_QUERY, $ADMIN_DIRECTORY.'menus.php?configure')===FALSE)) // no admin theme when previewing.
|
if(file_exists(THEME.'admin_theme.php')&&(strpos(e_SELF.'?'.e_QUERY, $ADMIN_DIRECTORY.'menus.php?configure')===FALSE)) // no admin theme when previewing.
|
||||||
{
|
{
|
||||||
require_once (THEME.'admin_theme.php');
|
require_once (THEME.'admin_theme.php');
|
||||||
@@ -1278,6 +1280,7 @@ if(e_ADMIN_AREA)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
$sql->db_Mark_Time('Loading Site Theme');
|
||||||
require_once (THEME.'theme.php');
|
require_once (THEME.'theme.php');
|
||||||
if(isset($SC_WRAPPER))
|
if(isset($SC_WRAPPER))
|
||||||
{
|
{
|
||||||
@@ -1835,7 +1838,7 @@ function init_session()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$sql->db_Mark_Time('Start: Go online');
|
$sql->db_Mark_Time('Go online');
|
||||||
if(!isset($_E107['no_online']) && varset($pref['track_online']))
|
if(!isset($_E107['no_online']) && varset($pref['track_online']))
|
||||||
{
|
{
|
||||||
e107::getOnline()->goOnline($pref['track_online'], $pref['flood_protect']);
|
e107::getOnline()->goOnline($pref['track_online'], $pref['flood_protect']);
|
||||||
|
@@ -393,7 +393,9 @@ abstract class e_marketplace_adapter_abstract
|
|||||||
$fp = fopen($path.$local_file, 'w'); // media-directory is the root.
|
$fp = fopen($path.$local_file, 'w'); // media-directory is the root.
|
||||||
//$fp1 = fopen(e_TEMP.'/curllog.txt', 'w');
|
//$fp1 = fopen(e_TEMP.'/curllog.txt', 'w');
|
||||||
|
|
||||||
$cp = curl_init($remote_url);
|
|
||||||
|
$cp = e107::getFile()->initCurl($remote_url);
|
||||||
|
/* $cp = curl_init($remote_url);
|
||||||
curl_setopt($cp, CURLOPT_FILE, $fp);
|
curl_setopt($cp, CURLOPT_FILE, $fp);
|
||||||
|
|
||||||
//curl_setopt($ch, CURLOPT_VERBOSE, 1);
|
//curl_setopt($ch, CURLOPT_VERBOSE, 1);
|
||||||
@@ -402,7 +404,7 @@ abstract class e_marketplace_adapter_abstract
|
|||||||
curl_setopt($cp, CURLOPT_REFERER, e_REQUEST_HTTP);
|
curl_setopt($cp, CURLOPT_REFERER, e_REQUEST_HTTP);
|
||||||
curl_setopt($cp, CURLOPT_HEADER, 0);
|
curl_setopt($cp, CURLOPT_HEADER, 0);
|
||||||
curl_setopt($cp, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
|
curl_setopt($cp, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
|
||||||
curl_setopt($cp, CURLOPT_COOKIEFILE, e_SYSTEM.'cookies.txt');
|
curl_setopt($cp, CURLOPT_COOKIEFILE, e_SYSTEM.'cookies.txt');*/
|
||||||
|
|
||||||
$buffer = curl_exec($cp);
|
$buffer = curl_exec($cp);
|
||||||
|
|
||||||
|
@@ -438,6 +438,9 @@ class e_file
|
|||||||
|
|
||||||
$fp = fopen($path.$local_file, 'w'); // media-directory is the root.
|
$fp = fopen($path.$local_file, 'w'); // media-directory is the root.
|
||||||
|
|
||||||
|
$cp = $this->initCurl($remote_url);
|
||||||
|
|
||||||
|
/*
|
||||||
$cp = curl_init($remote_url);
|
$cp = curl_init($remote_url);
|
||||||
curl_setopt($cp, CURLOPT_FILE, $fp);
|
curl_setopt($cp, CURLOPT_FILE, $fp);
|
||||||
curl_setopt($cp, CURLOPT_REFERER, e_REQUEST_HTTP);
|
curl_setopt($cp, CURLOPT_REFERER, e_REQUEST_HTTP);
|
||||||
@@ -445,6 +448,7 @@ class e_file
|
|||||||
curl_setopt($cp, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
|
curl_setopt($cp, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
|
||||||
curl_setopt($cp, CURLOPT_COOKIEFILE, e_SYSTEM.'cookies.txt');
|
curl_setopt($cp, CURLOPT_COOKIEFILE, e_SYSTEM.'cookies.txt');
|
||||||
curl_setopt($cp, CURLOPT_SSL_VERIFYPEER, FALSE);
|
curl_setopt($cp, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||||
|
*/
|
||||||
|
|
||||||
$buffer = curl_exec($cp);
|
$buffer = curl_exec($cp);
|
||||||
|
|
||||||
@@ -455,34 +459,16 @@ class e_file
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FIXME add POST support
|
|
||||||
* Get Remote contents
|
|
||||||
* $options array:
|
|
||||||
* - 'timeout' (integer): timeout in seconds
|
|
||||||
* - 'post' (array|urlencoded string): POST data
|
|
||||||
* - 'header' (array) headers, example: array('Content-Type: text/xml', 'X-Custom-Header: SomeValue');
|
|
||||||
* @param string $address
|
* @param string $address
|
||||||
* @param array $options [optional]
|
* @param array|null $options
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
function getRemoteContent($address, $options = array())
|
function initCurl($address, $options =null)
|
||||||
{
|
{
|
||||||
// Could do something like: if ($timeout <= 0) $timeout = $pref['get_remote_timeout']; here
|
$cu = curl_init();
|
||||||
$postData = varset($options['post'], null);
|
|
||||||
$timeout = (integer) vartrue($options['timeout'], 10);
|
$timeout = (integer) vartrue($options['timeout'], 10);
|
||||||
$timeout = min($timeout, 120);
|
$timeout = min($timeout, 120);
|
||||||
$timeout = max($timeout, 3);
|
$timeout = max($timeout, 3);
|
||||||
$fileContents = '';
|
|
||||||
$this->error = '';
|
|
||||||
$this->errornum = null;
|
|
||||||
|
|
||||||
$mes = e107::getMessage();
|
|
||||||
|
|
||||||
$address = str_replace(array("\r", "\n", "\t"), '', $address); // May be paranoia, but streaky thought it might be a good idea
|
|
||||||
// ... and there shouldn't be unprintable characters in the URL anyway
|
|
||||||
$requireCurl = false;
|
|
||||||
|
|
||||||
if(vartrue($options['decode'], false)) $address = urldecode($address);
|
|
||||||
|
|
||||||
$urlData = parse_url($address);
|
$urlData = parse_url($address);
|
||||||
$referer = $urlData['scheme']."://".$urlData['host'];
|
$referer = $urlData['scheme']."://".$urlData['host'];
|
||||||
@@ -492,17 +478,12 @@ class e_file
|
|||||||
$referer = e_REQUEST_HTTP;
|
$referer = e_REQUEST_HTTP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Keep this in first position.
|
|
||||||
if (function_exists("curl_init")) // Preferred.
|
|
||||||
{
|
|
||||||
$cu = curl_init();
|
|
||||||
curl_setopt($cu, CURLOPT_URL, $address);
|
curl_setopt($cu, CURLOPT_URL, $address);
|
||||||
|
curl_setopt($cu, CURLOPT_TIMEOUT, $timeout);
|
||||||
curl_setopt($cu, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($cu, CURLOPT_RETURNTRANSFER, true);
|
||||||
curl_setopt($cu, CURLOPT_HEADER, 0);
|
curl_setopt($cu, CURLOPT_HEADER, 0);
|
||||||
curl_setopt($cu, CURLOPT_TIMEOUT, $timeout);
|
|
||||||
curl_setopt($cu, CURLOPT_SSL_VERIFYPEER, FALSE);
|
|
||||||
curl_setopt($cu, CURLOPT_REFERER, $referer);
|
curl_setopt($cu, CURLOPT_REFERER, $referer);
|
||||||
|
curl_setopt($cu, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||||
curl_setopt($cu, CURLOPT_FOLLOWLOCATION, 0);
|
curl_setopt($cu, CURLOPT_FOLLOWLOCATION, 0);
|
||||||
curl_setopt($cu, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
|
curl_setopt($cu, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
|
||||||
curl_setopt($cu, CURLOPT_COOKIEFILE, e_SYSTEM.'cookies.txt');
|
curl_setopt($cu, CURLOPT_COOKIEFILE, e_SYSTEM.'cookies.txt');
|
||||||
@@ -523,17 +504,16 @@ class e_file
|
|||||||
curl_setopt($cu, CURLOPT_PROXYTYPE, e_CURL_PROXYTYPE); // If expected to cal
|
curl_setopt($cu, CURLOPT_PROXYTYPE, e_CURL_PROXYTYPE); // If expected to cal
|
||||||
}
|
}
|
||||||
|
|
||||||
if($postData !== null)
|
if(!empty($options['post']))
|
||||||
{
|
{
|
||||||
curl_setopt($cu, CURLOPT_POST, true);
|
curl_setopt($cu, CURLOPT_POST, true);
|
||||||
// if array -> will encode the data as multipart/form-data, if URL-encoded string - application/x-www-form-urlencoded
|
// if array -> will encode the data as multipart/form-data, if URL-encoded string - application/x-www-form-urlencoded
|
||||||
curl_setopt($cu, CURLOPT_POSTFIELDS, $postData);
|
curl_setopt($cu, CURLOPT_POSTFIELDS, $options['post']);
|
||||||
$requireCurl = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($options['header']) && is_array($options['header']))
|
if(isset($options['header']) && is_array($options['header']))
|
||||||
{
|
{
|
||||||
curl_setopt($cu, CURLOPT_HTTPHEADER, $options['header']);
|
curl_setopt($cu, CURLOPT_HTTPHEADER, $options['header']);
|
||||||
$requireCurl = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!file_exists(e_SYSTEM.'cookies.txt'))
|
if(!file_exists(e_SYSTEM.'cookies.txt'))
|
||||||
@@ -541,6 +521,45 @@ class e_file
|
|||||||
file_put_contents(e_SYSTEM.'cookies.txt','');
|
file_put_contents(e_SYSTEM.'cookies.txt','');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $cu;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FIXME add POST support
|
||||||
|
* Get Remote contents
|
||||||
|
* $options array:
|
||||||
|
* - 'timeout' (integer): timeout in seconds
|
||||||
|
* - 'post' (array|urlencoded string): POST data
|
||||||
|
* - 'header' (array) headers, example: array('Content-Type: text/xml', 'X-Custom-Header: SomeValue');
|
||||||
|
* @param string $address
|
||||||
|
* @param array $options [optional]
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function getRemoteContent($address, $options = array())
|
||||||
|
{
|
||||||
|
// Could do something like: if ($timeout <= 0) $timeout = $pref['get_remote_timeout']; here
|
||||||
|
|
||||||
|
$fileContents = '';
|
||||||
|
$this->error = '';
|
||||||
|
$this->errornum = null;
|
||||||
|
|
||||||
|
$mes = e107::getMessage();
|
||||||
|
|
||||||
|
$address = str_replace(array("\r", "\n", "\t"), '', $address); // May be paranoia, but streaky thought it might be a good idea
|
||||||
|
// ... and there shouldn't be unprintable characters in the URL anyway
|
||||||
|
$requireCurl = false;
|
||||||
|
|
||||||
|
if(vartrue($options['decode'], false)) $address = urldecode($address);
|
||||||
|
|
||||||
|
// Keep this in first position.
|
||||||
|
if (function_exists("curl_init")) // Preferred.
|
||||||
|
{
|
||||||
|
|
||||||
|
$cu = $this->initCurl($address, $options);
|
||||||
|
|
||||||
$fileContents = curl_exec($cu);
|
$fileContents = curl_exec($cu);
|
||||||
if (curl_error($cu))
|
if (curl_error($cu))
|
||||||
{
|
{
|
||||||
@@ -555,6 +574,8 @@ class e_file
|
|||||||
// CURL is required, abort...
|
// CURL is required, abort...
|
||||||
if($requireCurl == true) return false;
|
if($requireCurl == true) return false;
|
||||||
|
|
||||||
|
$timeout = 5;
|
||||||
|
|
||||||
if (function_exists('file_get_contents') && ini_get('allow_url_fopen'))
|
if (function_exists('file_get_contents') && ini_get('allow_url_fopen'))
|
||||||
{
|
{
|
||||||
$old_timeout = e107_ini_set('default_socket_timeout', $timeout);
|
$old_timeout = e107_ini_set('default_socket_timeout', $timeout);
|
||||||
|
@@ -435,128 +435,10 @@ class xmlClass
|
|||||||
{
|
{
|
||||||
$_file = e107::getFile();
|
$_file = e107::getFile();
|
||||||
$this->xmlFileContents = $_file->getRemoteContent($address, array('timeout' => $timeout, 'post' => $postData));
|
$this->xmlFileContents = $_file->getRemoteContent($address, array('timeout' => $timeout, 'post' => $postData));
|
||||||
$this->error = $_file->error;
|
$this->error = $_file->getErrorMessage();
|
||||||
|
|
||||||
return $this->xmlFileContents;
|
return $this->xmlFileContents;
|
||||||
|
|
||||||
// ------ MOVED TO FILE HANDLER ------ //
|
|
||||||
// Could do something like: if ($timeout <= 0) $timeout = $pref['get_remote_timeout']; here
|
|
||||||
$timeout = min($timeout, 120);
|
|
||||||
$timeout = max($timeout, 3);
|
|
||||||
$this->xmlFileContents = '';
|
|
||||||
|
|
||||||
$mes = e107::getMessage();
|
|
||||||
|
|
||||||
if($this->_feedUrl) // override option for use when part of the address needs to be encoded.
|
|
||||||
{
|
|
||||||
$mes->addDebug("getting Remote File: ".$this->_feedUrl);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$address = str_replace(array("\r", "\n", "\t"), '', $address); // May be paranoia, but streaky thought it might be a good idea
|
|
||||||
// ... and there shouldn't be unprintable characters in the URL anyway
|
|
||||||
}
|
|
||||||
|
|
||||||
if($this->urlPrefix !== false)
|
|
||||||
{
|
|
||||||
$address = $this->urlPrefix.$address;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ... and there shouldn't be unprintable characters in the URL anyway
|
|
||||||
|
|
||||||
|
|
||||||
// Keep this in first position.
|
|
||||||
if (function_exists("curl_init")) // Preferred.
|
|
||||||
{
|
|
||||||
$cu = curl_init();
|
|
||||||
curl_setopt($cu, CURLOPT_URL, $address);
|
|
||||||
curl_setopt($cu, CURLOPT_RETURNTRANSFER, true);
|
|
||||||
curl_setopt($cu, CURLOPT_HEADER, 0);
|
|
||||||
curl_setopt($cu, CURLOPT_TIMEOUT, $timeout);
|
|
||||||
curl_setopt($cu, CURLOPT_SSL_VERIFYPEER, FALSE);
|
|
||||||
curl_setopt($cu, CURLOPT_REFERER, e_REQUEST_HTTP);
|
|
||||||
curl_setopt($cu, CURLOPT_FOLLOWLOCATION, 0);
|
|
||||||
curl_setopt($cu, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
|
|
||||||
curl_setopt($cu, CURLOPT_COOKIEFILE, e_SYSTEM.'cookies.txt');
|
|
||||||
curl_setopt($cu, CURLOPT_COOKIEJAR, e_SYSTEM.'cookies.txt');
|
|
||||||
|
|
||||||
if(!file_exists(e_SYSTEM.'cookies.txt'))
|
|
||||||
{
|
|
||||||
file_put_contents(e_SYSTEM.'cookies.txt','');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->xmlFileContents = curl_exec($cu);
|
|
||||||
if (curl_error($cu))
|
|
||||||
{
|
|
||||||
$this->error = "Curl error: ".curl_errno($cu).", ".curl_error($cu);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
curl_close($cu);
|
|
||||||
return $this->xmlFileContents;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (function_exists('file_get_contents') && ini_get('allow_url_fopen'))
|
|
||||||
{
|
|
||||||
$old_timeout = e107_ini_set('default_socket_timeout', $timeout);
|
|
||||||
$address = ($this->_feedUrl) ? $this->_feedUrl : urldecode($address);
|
|
||||||
|
|
||||||
$data = file_get_contents($address);
|
|
||||||
|
|
||||||
// $data = file_get_contents(htmlspecialchars($address)); // buggy - sometimes fails.
|
|
||||||
if ($old_timeout !== FALSE)
|
|
||||||
{
|
|
||||||
e107_ini_set('default_socket_timeout', $old_timeout);
|
|
||||||
}
|
|
||||||
if ($data !== FALSE)
|
|
||||||
{
|
|
||||||
$this->xmlFileContents = $data;
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
$this->error = "File_get_contents(XML) error"; // Fill in more info later
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ini_get("allow_url_fopen"))
|
|
||||||
{
|
|
||||||
$old_timeout = e107_ini_set('default_socket_timeout', $timeout);
|
|
||||||
$remote = @fopen($address, "r");
|
|
||||||
if (!$remote)
|
|
||||||
{
|
|
||||||
$this->error = "fopen: Unable to open remote XML file: ".$address;
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$old_timeout = $timeout;
|
|
||||||
$tmp = parse_url($address);
|
|
||||||
if (!$remote = fsockopen($tmp['host'], 80, $errno, $errstr, $timeout))
|
|
||||||
{
|
|
||||||
$this->error = "Sockets: Unable to open remote XML file: ".$address;
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
socket_set_timeout($remote, $timeout);
|
|
||||||
fputs($remote, "GET ".urlencode($address)." HTTP/1.0\r\n\r\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$this->xmlFileContents = "";
|
|
||||||
while (!feof($remote))
|
|
||||||
{
|
|
||||||
$this->xmlFileContents .= fgets($remote, 4096);
|
|
||||||
}
|
|
||||||
fclose($remote);
|
|
||||||
if ($old_timeout != $timeout)
|
|
||||||
{
|
|
||||||
if ($old_timeout !== FALSE)
|
|
||||||
{
|
|
||||||
e107_ini_set('default_socket_timeout', $old_timeout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $this->xmlFileContents;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user