Skip to content

Commit

Permalink
update to upstream 4.5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Server committed Mar 15, 2022
1 parent bae69d1 commit 6521c31
Show file tree
Hide file tree
Showing 49 changed files with 2,135 additions and 1,950 deletions.
103 changes: 4 additions & 99 deletions includes/api/class-api-v3-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ class NL4WP_API_v3_Client {
*/
private $api_key;

/**
* @var string Non necessario
*/
private $api_url = 'https://api.newsletter.com/3.0/';

/**
* @var array
*/
Expand All @@ -24,12 +19,6 @@ class NL4WP_API_v3_Client {
*/
public function __construct( $api_key ) {
$this->api_key = $api_key;

$dash_position = strpos( $api_key, '-' );
if( $dash_position !== false ) {
$this->api_url = str_replace( '//api.', '//' . substr( $api_key, $dash_position + 1 ) . ".api.", $this->api_url );
}

}


Expand Down Expand Up @@ -90,40 +79,16 @@ public function delete( $resource ) {
* NEWSLETTER unica funzione da cambiare.
*/
private function request( $method, $resource, array $data = array() ) {
global $wp_version;
$this->reset();

// don't bother if no API key was given.
if( empty( $this->api_key ) ) {
throw new NL4WP_API_Exception( "Missing API key", 001 );
}

$GLOBALS['service_wrapper_uaprefix'] = 'newsletter-for-wp/'.NL4WP_VERSION.' ';
$GLOBALS['service_wrapper_uaprefix'] = 'nl4wp/' . NL4WP_VERSION . '; wp/' . $wp_version . '; ' . home_url() . '; '; // get_bloginfo( 'url' )
service_init($this->api_key); // inizializzazione API service
/* commentato
$url = $this->api_url . ltrim( $resource, '/' );
$args = array(
'method' => $method,
'headers' => $this->get_headers(),
'timeout' => 10,
'sslverify' => apply_filters( 'nl4wp_use_sslverify', true ),
);*/
//$this->get_log()->info( sprintf( "Richiesta: %s", $resource ) );
//$this->get_log()->info( sprintf( "Parametri richiesta: %s", print_r($data,true) ) );

// attach arguments (in body or URL)
/* commentato
if( $method === 'GET' ) {
$url = add_query_arg( $data, $url );
} else {
$args['body'] = json_encode( $data );
}
*/
// perform request
//$response = wp_remote_request( $url, $args );
//$this->last_response = $response;

// parse response
//$data = $this->parse_response( $response );

// gestione ad hoc della richiesta di check utente
if (preg_match ( '/(\/lists\/1\/members)\/(.*)/', $resource,$matches))
Expand Down Expand Up @@ -305,73 +270,13 @@ private function request( $method, $resource, array $data = array() ) {
break;
}
break;
default:
throw new NL4WP_API_Exception( "Unsupported call: " . $resource, 002 );
}

return (object) $data;
}

/**
* @return array
*/
private function get_headers() {
global $wp_version;

$headers = array();
$headers['Authorization'] = 'Basic ' . base64_encode( 'nl4wp:' . $this->api_key );
$headers['Accept'] = 'application/json';
$headers['Content-Type'] = 'application/json';
$headers['User-Agent'] = 'nl4wp/' . NL4WP_VERSION . '; WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' );

// Copy Accept-Language from browser headers
if( ! empty( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ) {
$headers['Accept-Language'] = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
}

return $headers;
}

/**
* @param array|WP_Error $response
*
* @return mixed
*
* @throws NL4WP_API_Exception
*/
private function parse_response( $response ) {

if( $response instanceof WP_Error ) {
throw new NL4WP_API_Connection_Exception( $response->get_error_message(), (int) $response->get_error_code() );
}

// decode response body
$code = (int) wp_remote_retrieve_response_code( $response );
$message = wp_remote_retrieve_response_message( $response );
$body = wp_remote_retrieve_body( $response );

// set body to "true" in case Newsletter returned No Content
if( $code < 300 && empty( $body ) ) {
$body = "true";
}

$data = json_decode( $body );
if( $code >= 400 ) {
if( $code === 404 ) {
throw new NL4WP_API_Resource_Not_Found_Exception( $message, $code, $response, $data );
}

throw new NL4WP_API_Exception( $message, $code, $response, $data );
}

if( ! is_null( $data ) ) {
return $data;
}

// unable to decode response
$message = service_errormessage();
$code = (int) service_errorcode();
throw new NL4WP_API_Exception( $message, $code, $response );
}

/**
* Empties all data from previous response
*/
Expand Down
4 changes: 2 additions & 2 deletions plugin-update-checker/Puc/v4/Factory.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
if ( !class_exists('Puc_v4_Factory', false) ):

class Puc_v4_Factory extends Puc_v4p5_Factory { }
class Puc_v4_Factory extends Puc_v4p8_Factory { }

endif;
endif;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

if ( !class_exists('Puc_v4p5_Autoloader', false) ):
if ( !class_exists('Puc_v4p8_Autoloader', false) ):

class Puc_v4p5_Autoloader {
class Puc_v4p8_Autoloader {
private $prefix = '';
private $rootDir = '';
private $libraryDir = '';
Expand All @@ -16,12 +16,10 @@ public function __construct() {

$this->libraryDir = realpath($this->rootDir . '../..') . '/';
$this->staticMap = array(
'PucReadmeParser' => 'vendor/readme-parser.php',
'Parsedown' => 'vendor/ParsedownLegacy.php',
'PucReadmeParser' => 'vendor/PucReadmeParser.php',
'Parsedown' => 'vendor/Parsedown.php',
'Puc_v4_Factory' => 'Puc/v4/Factory.php',
);
if ( version_compare(PHP_VERSION, '5.3.0', '>=') ) {
$this->staticMap['Parsedown'] = 'vendor/Parsedown.php';
}

spl_autoload_register(array($this, 'autoload'));
}
Expand All @@ -46,4 +44,4 @@ public function autoload($className) {
}
}

endif;
endif;
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
if ( !class_exists('Puc_v4p5_DebugBar_Extension', false) ):
if ( !class_exists('Puc_v4p8_DebugBar_Extension', false) ):

class Puc_v4p5_DebugBar_Extension {
class Puc_v4p8_DebugBar_Extension {
const RESPONSE_BODY_LENGTH_LIMIT = 4000;

/** @var Puc_v4p5_UpdateChecker */
/** @var Puc_v4p8_UpdateChecker */
protected $updateChecker;
protected $panelClass = 'Puc_v4p5_DebugBar_Panel';
protected $panelClass = 'Puc_v4p8_DebugBar_Panel';

public function __construct($updateChecker, $panelClass = null) {
$this->updateChecker = $updateChecker;
Expand Down Expand Up @@ -150,11 +150,11 @@ private function getLibraryUrl($filePath) {
$absolutePath = realpath(dirname(__FILE__) . '/../../../' . ltrim($filePath, '/'));

//Where is the library located inside the WordPress directory structure?
$absolutePath = Puc_v4p5_Factory::normalizePath($absolutePath);
$absolutePath = Puc_v4p8_Factory::normalizePath($absolutePath);

$pluginDir = Puc_v4p5_Factory::normalizePath(WP_PLUGIN_DIR);
$muPluginDir = Puc_v4p5_Factory::normalizePath(WPMU_PLUGIN_DIR);
$themeDir = Puc_v4p5_Factory::normalizePath(get_theme_root());
$pluginDir = Puc_v4p8_Factory::normalizePath(WP_PLUGIN_DIR);
$muPluginDir = Puc_v4p8_Factory::normalizePath(WPMU_PLUGIN_DIR);
$themeDir = Puc_v4p8_Factory::normalizePath(get_theme_root());

if ( (strpos($absolutePath, $pluginDir) === 0) || (strpos($absolutePath, $muPluginDir) === 0) ) {
//It's part of a plugin.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

if ( !class_exists('Puc_v4p5_DebugBar_Panel', false) && class_exists('Debug_Bar_Panel', false) ):
if ( !class_exists('Puc_v4p8_DebugBar_Panel', false) && class_exists('Debug_Bar_Panel', false) ):

class Puc_v4p5_DebugBar_Panel extends Debug_Bar_Panel {
/** @var Puc_v4p5_UpdateChecker */
class Puc_v4p8_DebugBar_Panel extends Debug_Bar_Panel {
/** @var Puc_v4p8_UpdateChecker */
protected $updateChecker;

private $responseBox = '<div class="puc-ajax-response" style="display: none;"></div>';
Expand Down Expand Up @@ -162,4 +162,4 @@ public function row($name, $value) {
}
}

endif;
endif;
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
if ( !class_exists('Puc_v4p5_DebugBar_PluginExtension', false) ):
if ( !class_exists('Puc_v4p8_DebugBar_PluginExtension', false) ):

class Puc_v4p5_DebugBar_PluginExtension extends Puc_v4p5_DebugBar_Extension {
/** @var Puc_v4p5_Plugin_UpdateChecker */
class Puc_v4p8_DebugBar_PluginExtension extends Puc_v4p8_DebugBar_Extension {
/** @var Puc_v4p8_Plugin_UpdateChecker */
protected $updateChecker;

public function __construct($updateChecker) {
parent::__construct($updateChecker, 'Puc_v4p5_DebugBar_PluginPanel');
parent::__construct($updateChecker, 'Puc_v4p8_DebugBar_PluginPanel');

add_action('wp_ajax_puc_v4_debug_request_info', array($this, 'ajaxRequestInfo'));
}
Expand All @@ -30,4 +30,4 @@ public function ajaxRequestInfo() {
}
}

endif;
endif;
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

if ( !class_exists('Puc_v4p5_DebugBar_PluginPanel', false) ):
if ( !class_exists('Puc_v4p8_DebugBar_PluginPanel', false) ):

class Puc_v4p5_DebugBar_PluginPanel extends Puc_v4p5_DebugBar_Panel {
class Puc_v4p8_DebugBar_PluginPanel extends Puc_v4p8_DebugBar_Panel {
/**
* @var Puc_v4p5_Plugin_UpdateChecker
* @var Puc_v4p8_Plugin_UpdateChecker
*/
protected $updateChecker;

Expand Down Expand Up @@ -35,4 +35,4 @@ protected function getUpdateFields() {
}
}

endif;
endif;
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

if ( !class_exists('Puc_v4p5_DebugBar_ThemePanel', false) ):
if ( !class_exists('Puc_v4p8_DebugBar_ThemePanel', false) ):

class Puc_v4p5_DebugBar_ThemePanel extends Puc_v4p5_DebugBar_Panel {
class Puc_v4p8_DebugBar_ThemePanel extends Puc_v4p8_DebugBar_Panel {
/**
* @var Puc_v4p5_Theme_UpdateChecker
* @var Puc_v4p8_Theme_UpdateChecker
*/
protected $updateChecker;

Expand All @@ -18,4 +18,4 @@ protected function getUpdateFields() {
}
}

endif;
endif;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
if ( !class_exists('Puc_v4p5_Factory', false) ):
if ( !class_exists('Puc_v4p8_Factory', false) ):

/**
* A factory that builds update checker instances.
Expand All @@ -11,7 +11,7 @@
* At the moment it can only build instances of the UpdateChecker class. Other classes are
* intended mainly for internal use and refer directly to specific implementations.
*/
class Puc_v4p5_Factory {
class Puc_v4p8_Factory {
protected static $classVersions = array();
protected static $sorted = false;

Expand All @@ -24,15 +24,15 @@ class Puc_v4p5_Factory {
* This method automatically detects if you're using it for a plugin or a theme and chooses
* the appropriate implementation for your update source (JSON file, GitHub, BitBucket, etc).
*
* @see Puc_v4p5_UpdateChecker::__construct
* @see Puc_v4p8_UpdateChecker::__construct
*
* @param string $metadataUrl The URL of the metadata file, a GitHub repository, or another supported update source.
* @param string $fullPath Full path to the main plugin file or to the theme directory.
* @param string $slug Custom slug. Defaults to the name of the main plugin file or the theme directory.
* @param int $checkPeriod How often to check for updates (in hours).
* @param string $optionName Where to store book-keeping info about update checks.
* @param string $muPluginFile The plugin filename relative to the mu-plugins directory.
* @return Puc_v4p5_Plugin_UpdateChecker|Puc_v4p5_Theme_UpdateChecker|Puc_v4p5_Vcs_BaseChecker
* @return Puc_v4p8_Plugin_UpdateChecker|Puc_v4p8_Theme_UpdateChecker|Puc_v4p8_Vcs_BaseChecker
*/
public static function buildUpdateChecker($metadataUrl, $fullPath, $slug = '', $checkPeriod = 12, $optionName = '', $muPluginFile = '') {
$fullPath = self::normalizePath($fullPath);
Expand Down Expand Up @@ -80,7 +80,7 @@ public static function buildUpdateChecker($metadataUrl, $fullPath, $slug = '', $
);
return null;
}

if ( !isset($apiClass) ) {
//Plain old update checker.
return new $checkerClass($metadataUrl, $id, $slug, $checkPeriod, $optionName, $muPluginFile);
Expand Down Expand Up @@ -127,7 +127,7 @@ public static function normalizePath($path) {
}
return $path;
}

/**
* Check if the path points to a plugin file.
*
Expand Down Expand Up @@ -188,8 +188,8 @@ private static function getVcsService($metadataUrl) {
$service = null;

//Which hosting service does the URL point to?
$host = @parse_url($metadataUrl, PHP_URL_HOST);
$path = @parse_url($metadataUrl, PHP_URL_PATH);
$host = parse_url($metadataUrl, PHP_URL_HOST);
$path = parse_url($metadataUrl, PHP_URL_PATH);

//Check if the path looks like "/user-name/repository".
//For GitLab.com it can also be "/user/group1/group2/.../repository".
Expand All @@ -207,8 +207,8 @@ private static function getVcsService($metadataUrl) {
$service = $knownServices[$host];
}
}
return $service;

return apply_filters('puc_get_vcs_service', $service, $host, $path, $metadataUrl);
}

/**
Expand Down Expand Up @@ -294,4 +294,4 @@ public static function addVersion($generalClass, $versionedClass, $version) {
}
}

endif;
endif;
Loading

0 comments on commit 6521c31

Please sign in to comment.