Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/sitepres.../lib
File: icl_api.php
<?php
[0] Fix | Delete
class ICanLocalizeQuery{
[1] Fix | Delete
[2] Fix | Delete
private $site_id;
[3] Fix | Delete
private $access_key;
[4] Fix | Delete
private $error = null;
[5] Fix | Delete
private $sitepress;
[6] Fix | Delete
private $wpml_icl_client;
[7] Fix | Delete
[8] Fix | Delete
function __construct( $site_id = null, $access_key = null, SitePress $sitepress = null, $wpml_icl_client = null ) {
[9] Fix | Delete
$this->site_id = $site_id;
[10] Fix | Delete
$this->access_key = $access_key;
[11] Fix | Delete
if ( null === $sitepress ) {
[12] Fix | Delete
global $sitepress;
[13] Fix | Delete
}
[14] Fix | Delete
$this->sitepress = $sitepress;
[15] Fix | Delete
if ( null === $wpml_icl_client ) {
[16] Fix | Delete
$wpml_icl_client = new WPML_ICL_Client( new WP_Http(), new WPML_WP_API() );
[17] Fix | Delete
}
[18] Fix | Delete
$this->wpml_icl_client = $wpml_icl_client;
[19] Fix | Delete
}
[20] Fix | Delete
[21] Fix | Delete
public function setting($setting){
[22] Fix | Delete
return $this->$setting;
[23] Fix | Delete
}
[24] Fix | Delete
[25] Fix | Delete
public function error(){
[26] Fix | Delete
return $this->error;
[27] Fix | Delete
}
[28] Fix | Delete
[29] Fix | Delete
function updateAccount($data){
[30] Fix | Delete
$request = ICL_API_ENDPOINT . '/websites/'.$data['site_id'].'/update_by_cms.xml';
[31] Fix | Delete
unset($data['site_id']);
[32] Fix | Delete
$response = $this->request($request, 'POST', $data);
[33] Fix | Delete
if(!$response){
[34] Fix | Delete
return $this->error;
[35] Fix | Delete
}else{
[36] Fix | Delete
return 0;
[37] Fix | Delete
}
[38] Fix | Delete
}
[39] Fix | Delete
[40] Fix | Delete
/**
[41] Fix | Delete
* @param bool $force
[42] Fix | Delete
*
[43] Fix | Delete
* @return array of website details returned from a direct API call to ICL
[44] Fix | Delete
*/
[45] Fix | Delete
function get_website_details( $force = false ) {
[46] Fix | Delete
$res = $this->sitepress->get_wp_api()->get_transient( WEBSITE_DETAILS_TRANSIENT_KEY );
[47] Fix | Delete
[48] Fix | Delete
if ( ! $res || $force ) {
[49] Fix | Delete
$website_details_cache_index = '_last_valid_icl_website_details';
[50] Fix | Delete
$request_url = ICL_API_ENDPOINT . '/websites/' . $this->site_id . '.xml?accesskey=' . $this->access_key;
[51] Fix | Delete
$res = $this->request( $request_url );
[52] Fix | Delete
if ( isset( $res['info']['website'] ) ) {
[53] Fix | Delete
$res = $res['info']['website'];
[54] Fix | Delete
$this->sitepress->set_setting( $website_details_cache_index, $res, true );
[55] Fix | Delete
} else {
[56] Fix | Delete
$res = $this->sitepress->get_setting( $website_details_cache_index, array() );
[57] Fix | Delete
}
[58] Fix | Delete
$this->sitepress->get_wp_api()->set_transient( WEBSITE_DETAILS_TRANSIENT_KEY, $res, DAY_IN_SECONDS );
[59] Fix | Delete
}
[60] Fix | Delete
return $res;
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
private function request( $request, $method = 'GET', $formvars = null ) {
[64] Fix | Delete
$this->wpml_icl_client->set_method( $method );
[65] Fix | Delete
$this->wpml_icl_client->set_post_data( $formvars );
[66] Fix | Delete
[67] Fix | Delete
return $this->wpml_icl_client->request( $request );
[68] Fix | Delete
}
[69] Fix | Delete
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
/**
[73] Fix | Delete
* gzdecode implementation
[74] Fix | Delete
*
[75] Fix | Delete
* @see http://hu.php.net/manual/en/function.gzencode.php#44470
[76] Fix | Delete
*
[77] Fix | Delete
* @param string $data
[78] Fix | Delete
* @param string $filename
[79] Fix | Delete
* @param string $error
[80] Fix | Delete
* @param int $maxlength
[81] Fix | Delete
* @return string
[82] Fix | Delete
*/
[83] Fix | Delete
function icl_gzdecode($data, &$filename = '', &$error = '', $maxlength = null) {
[84] Fix | Delete
$len = strlen ( $data );
[85] Fix | Delete
if ($len < 18 || strcmp ( substr ( $data, 0, 2 ), "\x1f\x8b" )) {
[86] Fix | Delete
$error = "Not in GZIP format.";
[87] Fix | Delete
return null; // Not GZIP format (See RFC 1952)
[88] Fix | Delete
}
[89] Fix | Delete
$method = ord ( substr ( $data, 2, 1 ) ); // Compression method
[90] Fix | Delete
$flags = ord ( substr ( $data, 3, 1 ) ); // Flags
[91] Fix | Delete
if ($flags & 31 != $flags) {
[92] Fix | Delete
$error = "Reserved bits not allowed.";
[93] Fix | Delete
return null;
[94] Fix | Delete
}
[95] Fix | Delete
$headerlen = 10;
[96] Fix | Delete
if ($flags & 4) {
[97] Fix | Delete
// 2-byte length prefixed EXTRA data in header
[98] Fix | Delete
if ($len - $headerlen - 2 < 8) {
[99] Fix | Delete
return false; // invalid
[100] Fix | Delete
}
[101] Fix | Delete
$extralen = unpack ( "v", substr ( $data, 8, 2 ) );
[102] Fix | Delete
$extralen = $extralen [1];
[103] Fix | Delete
if ($len - $headerlen - 2 - $extralen < 8) {
[104] Fix | Delete
return false; // invalid
[105] Fix | Delete
}
[106] Fix | Delete
$headerlen += 2 + $extralen;
[107] Fix | Delete
}
[108] Fix | Delete
$filename = "";
[109] Fix | Delete
if ($flags & 8) {
[110] Fix | Delete
// C-style string
[111] Fix | Delete
if ($len - $headerlen - 1 < 8) {
[112] Fix | Delete
return false; // invalid
[113] Fix | Delete
}
[114] Fix | Delete
$filenamelen = strpos ( substr ( $data, $headerlen ), chr ( 0 ) );
[115] Fix | Delete
if ($filenamelen === false || $len - $headerlen - $filenamelen - 1 < 8) {
[116] Fix | Delete
return false; // invalid
[117] Fix | Delete
}
[118] Fix | Delete
$filename = substr ( $data, $headerlen, $filenamelen );
[119] Fix | Delete
$headerlen += $filenamelen + 1;
[120] Fix | Delete
}
[121] Fix | Delete
if ($flags & 16) {
[122] Fix | Delete
// C-style string COMMENT data in header
[123] Fix | Delete
if ($len - $headerlen - 1 < 8) {
[124] Fix | Delete
return false; // invalid
[125] Fix | Delete
}
[126] Fix | Delete
$commentlen = strpos ( substr ( $data, $headerlen ), chr ( 0 ) );
[127] Fix | Delete
if ($commentlen === false || $len - $headerlen - $commentlen - 1 < 8) {
[128] Fix | Delete
return false; // Invalid header format
[129] Fix | Delete
}
[130] Fix | Delete
$headerlen += $commentlen + 1;
[131] Fix | Delete
}
[132] Fix | Delete
if ($flags & 2) {
[133] Fix | Delete
// 2-bytes (lowest order) of CRC32 on header present
[134] Fix | Delete
if ($len - $headerlen - 2 < 8) {
[135] Fix | Delete
return false; // invalid
[136] Fix | Delete
}
[137] Fix | Delete
$calccrc = crc32 ( substr ( $data, 0, $headerlen ) ) & 0xffff;
[138] Fix | Delete
$headercrc = unpack ( "v", substr ( $data, $headerlen, 2 ) );
[139] Fix | Delete
$headercrc = $headercrc [1];
[140] Fix | Delete
if ($headercrc != $calccrc) {
[141] Fix | Delete
$error = "Header checksum failed.";
[142] Fix | Delete
return false; // Bad header CRC
[143] Fix | Delete
}
[144] Fix | Delete
$headerlen += 2;
[145] Fix | Delete
}
[146] Fix | Delete
// GZIP FOOTER
[147] Fix | Delete
$datacrc = unpack ( "V", substr ( $data, - 8, 4 ) );
[148] Fix | Delete
$datacrc = sprintf ( '%u', $datacrc [1] & 0xFFFFFFFF );
[149] Fix | Delete
$isize = unpack ( "V", substr ( $data, - 4 ) );
[150] Fix | Delete
$isize = $isize [1];
[151] Fix | Delete
// decompression:
[152] Fix | Delete
$bodylen = $len - $headerlen - 8;
[153] Fix | Delete
if ($bodylen < 1) {
[154] Fix | Delete
// IMPLEMENTATION BUG!
[155] Fix | Delete
return null;
[156] Fix | Delete
}
[157] Fix | Delete
$body = substr ( $data, $headerlen, $bodylen );
[158] Fix | Delete
$data = "";
[159] Fix | Delete
if ($bodylen > 0) {
[160] Fix | Delete
switch ($method) {
[161] Fix | Delete
case 8 :
[162] Fix | Delete
// Currently the only supported compression method:
[163] Fix | Delete
$data = gzinflate ( $body, $maxlength );
[164] Fix | Delete
break;
[165] Fix | Delete
default :
[166] Fix | Delete
$error = "Unknown compression method.";
[167] Fix | Delete
return false;
[168] Fix | Delete
}
[169] Fix | Delete
} // zero-byte body content is allowed
[170] Fix | Delete
// Verifiy CRC32
[171] Fix | Delete
$crc = sprintf ( "%u", crc32 ( $data ) );
[172] Fix | Delete
$crcOK = $crc == $datacrc;
[173] Fix | Delete
$lenOK = $isize == strlen ( $data );
[174] Fix | Delete
if (! $lenOK || ! $crcOK) {
[175] Fix | Delete
$error = ($lenOK ? '' : 'Length check FAILED. ') . ($crcOK ? '' : 'Checksum FAILED.');
[176] Fix | Delete
return false;
[177] Fix | Delete
}
[178] Fix | Delete
return $data;
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function