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/content-.../inc/freemius/includes/sdk
File: FreemiusBase.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Copyright 2014 Freemius, Inc.
[2] Fix | Delete
*
[3] Fix | Delete
* Licensed under the GPL v2 (the "License"); you may
[4] Fix | Delete
* not use this file except in compliance with the License. You may obtain
[5] Fix | Delete
* a copy of the License at
[6] Fix | Delete
*
[7] Fix | Delete
* http://choosealicense.com/licenses/gpl-v2/
[8] Fix | Delete
*
[9] Fix | Delete
* Unless required by applicable law or agreed to in writing, software
[10] Fix | Delete
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
[11] Fix | Delete
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
[12] Fix | Delete
* License for the specific language governing permissions and limitations
[13] Fix | Delete
* under the License.
[14] Fix | Delete
*/
[15] Fix | Delete
[16] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[17] Fix | Delete
exit;
[18] Fix | Delete
}
[19] Fix | Delete
[20] Fix | Delete
if ( ! defined( 'FS_API__VERSION' ) ) {
[21] Fix | Delete
define( 'FS_API__VERSION', '1' );
[22] Fix | Delete
}
[23] Fix | Delete
if ( ! defined( 'FS_SDK__PATH' ) ) {
[24] Fix | Delete
define( 'FS_SDK__PATH', dirname( __FILE__ ) );
[25] Fix | Delete
}
[26] Fix | Delete
if ( ! defined( 'FS_SDK__EXCEPTIONS_PATH' ) ) {
[27] Fix | Delete
define( 'FS_SDK__EXCEPTIONS_PATH', FS_SDK__PATH . '/Exceptions/' );
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
if ( ! function_exists( 'json_decode' ) ) {
[31] Fix | Delete
throw new Exception( 'Freemius needs the JSON PHP extension.' );
[32] Fix | Delete
}
[33] Fix | Delete
[34] Fix | Delete
// Include all exception files.
[35] Fix | Delete
$exceptions = array(
[36] Fix | Delete
'Exception',
[37] Fix | Delete
'InvalidArgumentException',
[38] Fix | Delete
'ArgumentNotExistException',
[39] Fix | Delete
'EmptyArgumentException',
[40] Fix | Delete
'OAuthException'
[41] Fix | Delete
);
[42] Fix | Delete
[43] Fix | Delete
foreach ( $exceptions as $e ) {
[44] Fix | Delete
require_once FS_SDK__EXCEPTIONS_PATH . $e . '.php';
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
if ( ! class_exists( 'Freemius_Api_Base' ) ) {
[48] Fix | Delete
abstract class Freemius_Api_Base {
[49] Fix | Delete
const VERSION = '1.0.4';
[50] Fix | Delete
const FORMAT = 'json';
[51] Fix | Delete
[52] Fix | Delete
protected $_id;
[53] Fix | Delete
protected $_public;
[54] Fix | Delete
protected $_secret;
[55] Fix | Delete
protected $_scope;
[56] Fix | Delete
protected $_isSandbox;
[57] Fix | Delete
[58] Fix | Delete
/**
[59] Fix | Delete
* @param string $pScope 'app', 'developer', 'plugin', 'user' or 'install'.
[60] Fix | Delete
* @param number $pID Element's id.
[61] Fix | Delete
* @param string $pPublic Public key.
[62] Fix | Delete
* @param string $pSecret Element's secret key.
[63] Fix | Delete
* @param bool $pIsSandbox Whether or not to run API in sandbox mode.
[64] Fix | Delete
*/
[65] Fix | Delete
public function Init( $pScope, $pID, $pPublic, $pSecret, $pIsSandbox = false ) {
[66] Fix | Delete
$this->_id = $pID;
[67] Fix | Delete
$this->_public = $pPublic;
[68] Fix | Delete
$this->_secret = $pSecret;
[69] Fix | Delete
$this->_scope = $pScope;
[70] Fix | Delete
$this->_isSandbox = $pIsSandbox;
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
public function IsSandbox() {
[74] Fix | Delete
return $this->_isSandbox;
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
function CanonizePath( $pPath ) {
[78] Fix | Delete
$pPath = trim( $pPath, '/' );
[79] Fix | Delete
$query_pos = strpos( $pPath, '?' );
[80] Fix | Delete
$query = '';
[81] Fix | Delete
[82] Fix | Delete
if ( false !== $query_pos ) {
[83] Fix | Delete
$query = substr( $pPath, $query_pos );
[84] Fix | Delete
$pPath = substr( $pPath, 0, $query_pos );
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
// Trim '.json' suffix.
[88] Fix | Delete
$format_length = strlen( '.' . self::FORMAT );
[89] Fix | Delete
$start = $format_length * ( - 1 ); //negative
[90] Fix | Delete
if ( substr( strtolower( $pPath ), $start ) === ( '.' . self::FORMAT ) ) {
[91] Fix | Delete
$pPath = substr( $pPath, 0, strlen( $pPath ) - $format_length );
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
switch ( $this->_scope ) {
[95] Fix | Delete
case 'app':
[96] Fix | Delete
$base = '/apps/' . $this->_id;
[97] Fix | Delete
break;
[98] Fix | Delete
case 'developer':
[99] Fix | Delete
$base = '/developers/' . $this->_id;
[100] Fix | Delete
break;
[101] Fix | Delete
case 'user':
[102] Fix | Delete
$base = '/users/' . $this->_id;
[103] Fix | Delete
break;
[104] Fix | Delete
case 'plugin':
[105] Fix | Delete
$base = '/plugins/' . $this->_id;
[106] Fix | Delete
break;
[107] Fix | Delete
case 'install':
[108] Fix | Delete
$base = '/installs/' . $this->_id;
[109] Fix | Delete
break;
[110] Fix | Delete
default:
[111] Fix | Delete
throw new Freemius_Exception( 'Scope not implemented.' );
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
return '/v' . FS_API__VERSION . $base .
[115] Fix | Delete
( ! empty( $pPath ) ? '/' : '' ) . $pPath .
[116] Fix | Delete
( ( false === strpos( $pPath, '.' ) ) ? '.' . self::FORMAT : '' ) . $query;
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
abstract function MakeRequest( $pCanonizedPath, $pMethod = 'GET', $pParams = array() );
[120] Fix | Delete
[121] Fix | Delete
/**
[122] Fix | Delete
* @param string $pPath
[123] Fix | Delete
* @param string $pMethod
[124] Fix | Delete
* @param array $pParams
[125] Fix | Delete
*
[126] Fix | Delete
* @return object[]|object|null
[127] Fix | Delete
*/
[128] Fix | Delete
private function _Api( $pPath, $pMethod = 'GET', $pParams = array() ) {
[129] Fix | Delete
$pMethod = strtoupper( $pMethod );
[130] Fix | Delete
[131] Fix | Delete
try {
[132] Fix | Delete
$result = $this->MakeRequest( $pPath, $pMethod, $pParams );
[133] Fix | Delete
} catch ( Freemius_Exception $e ) {
[134] Fix | Delete
// Map to error object.
[135] Fix | Delete
$result = (object) $e->getResult();
[136] Fix | Delete
} catch ( Exception $e ) {
[137] Fix | Delete
// Map to error object.
[138] Fix | Delete
$result = (object) array(
[139] Fix | Delete
'error' => (object) array(
[140] Fix | Delete
'type' => 'Unknown',
[141] Fix | Delete
'message' => $e->getMessage() . ' (' . $e->getFile() . ': ' . $e->getLine() . ')',
[142] Fix | Delete
'code' => 'unknown',
[143] Fix | Delete
'http' => 402
[144] Fix | Delete
)
[145] Fix | Delete
);
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
return $result;
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
public function Api( $pPath, $pMethod = 'GET', $pParams = array() ) {
[152] Fix | Delete
return $this->_Api( $this->CanonizePath( $pPath ), $pMethod, $pParams );
[153] Fix | Delete
}
[154] Fix | Delete
[155] Fix | Delete
/**
[156] Fix | Delete
* Base64 decoding that does not need to be urldecode()-ed.
[157] Fix | Delete
*
[158] Fix | Delete
* Exactly the same as PHP base64 encode except it uses
[159] Fix | Delete
* `-` instead of `+`
[160] Fix | Delete
* `_` instead of `/`
[161] Fix | Delete
* No padded =
[162] Fix | Delete
*
[163] Fix | Delete
* @param string $input Base64UrlEncoded() string
[164] Fix | Delete
*
[165] Fix | Delete
* @return string
[166] Fix | Delete
*/
[167] Fix | Delete
protected static function Base64UrlDecode( $input ) {
[168] Fix | Delete
/**
[169] Fix | Delete
* IMPORTANT NOTE:
[170] Fix | Delete
* This is a hack suggested by @otto42 and @greenshady from
[171] Fix | Delete
* the theme's review team. The usage of base64 for API
[172] Fix | Delete
* signature encoding was approved in a Slack meeting
[173] Fix | Delete
* held on Tue (10/25 2016).
[174] Fix | Delete
*
[175] Fix | Delete
* @todo Remove this hack once the base64 error is removed from the Theme Check.
[176] Fix | Delete
*
[177] Fix | Delete
* @since 1.2.2
[178] Fix | Delete
* @author Vova Feldman (@svovaf)
[179] Fix | Delete
*/
[180] Fix | Delete
$fn = 'base64' . '_decode';
[181] Fix | Delete
return $fn( strtr( $input, '-_', '+/' ) );
[182] Fix | Delete
}
[183] Fix | Delete
[184] Fix | Delete
/**
[185] Fix | Delete
* Base64 encoding that does not need to be urlencode()ed.
[186] Fix | Delete
*
[187] Fix | Delete
* Exactly the same as base64 encode except it uses
[188] Fix | Delete
* `-` instead of `+
[189] Fix | Delete
* `_` instead of `/`
[190] Fix | Delete
*
[191] Fix | Delete
* @param string $input string
[192] Fix | Delete
*
[193] Fix | Delete
* @return string Base64 encoded string
[194] Fix | Delete
*/
[195] Fix | Delete
protected static function Base64UrlEncode( $input ) {
[196] Fix | Delete
/**
[197] Fix | Delete
* IMPORTANT NOTE:
[198] Fix | Delete
* This is a hack suggested by @otto42 and @greenshady from
[199] Fix | Delete
* the theme's review team. The usage of base64 for API
[200] Fix | Delete
* signature encoding was approved in a Slack meeting
[201] Fix | Delete
* held on Tue (10/25 2016).
[202] Fix | Delete
*
[203] Fix | Delete
* @todo Remove this hack once the base64 error is removed from the Theme Check.
[204] Fix | Delete
*
[205] Fix | Delete
* @since 1.2.2
[206] Fix | Delete
* @author Vova Feldman (@svovaf)
[207] Fix | Delete
*/
[208] Fix | Delete
$fn = 'base64' . '_encode';
[209] Fix | Delete
$str = strtr( $fn( $input ), '+/', '-_' );
[210] Fix | Delete
$str = str_replace( '=', '', $str );
[211] Fix | Delete
[212] Fix | Delete
return $str;
[213] Fix | Delete
}
[214] Fix | Delete
}
[215] Fix | Delete
}
[216] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function