@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Calendar state container.
|
||||
*
|
||||
* @author Time.ly Network Inc.
|
||||
* @since 2.2
|
||||
*
|
||||
* @package AI1EC
|
||||
* @subpackage AI1EC.Lib.Calendar
|
||||
*/
|
||||
class Ai1ec_Calendar_State extends Ai1ec_Base {
|
||||
|
||||
/**
|
||||
* Whether calendar is initializing router or not.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $_is_routing_initializing = false;
|
||||
|
||||
/**
|
||||
* Whether Html render strategy should append content in the_content
|
||||
* filter hook.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $_append_content = true;
|
||||
|
||||
/**
|
||||
* Returns whether routing is during initialization phase or not.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_routing_initializing() {
|
||||
return $this->_is_routing_initializing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets state for routing initialization phase.
|
||||
*
|
||||
* @param bool $status State for initializing phase.
|
||||
*/
|
||||
public function set_routing_initialization( $status ) {
|
||||
$this->_is_routing_initializing = $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether html render strategy should append content in the_content
|
||||
* filter hook.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function append_content() {
|
||||
return $this->_append_content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets state for content appending in html renderer the_content hook.
|
||||
* See Ai1ec_Render_Strategy_Html::append_content()
|
||||
*
|
||||
* @param bool $status Whether to append content or not.
|
||||
*/
|
||||
public function set_append_content( $status ) {
|
||||
$this->_append_content = $status;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Calendar state container.
|
||||
*
|
||||
* @author Time.ly Network Inc.
|
||||
* @since 2.3
|
||||
*
|
||||
* @package AI1EC
|
||||
* @subpackage AI1EC.Lib.Calendar
|
||||
*/
|
||||
class Ai1ec_Calendar_Updates extends Ai1ec_Base {
|
||||
|
||||
/**
|
||||
* Primary update endpoint.
|
||||
*
|
||||
* @const string
|
||||
*/
|
||||
const PRIMARY_END_POINT = 'https://update.time.ly/update';
|
||||
|
||||
/**
|
||||
* Alternative update endpoint.
|
||||
*
|
||||
* @const string
|
||||
*/
|
||||
const SECONDARY_END_POINT = 'https://checkout.time.ly/update';
|
||||
|
||||
/**
|
||||
* Check updates and return additional info.
|
||||
*
|
||||
* @param mixed $transient_data Current transient data.
|
||||
*
|
||||
* @return mixed Modified transient data.
|
||||
*/
|
||||
public function check_updates( $transient_data ) {
|
||||
if ( empty( $transient_data ) ) {
|
||||
return $transient_data;
|
||||
}
|
||||
$updates = $this->_download_updates();
|
||||
if ( empty( $updates ) ) {
|
||||
return $transient_data;
|
||||
}
|
||||
$plugins = get_plugins();
|
||||
foreach ( $updates as $plugin => $update_data ) {
|
||||
/** @var $plugin_data array */
|
||||
$plugin_data = isset( $plugins[$plugin] ) ? $plugins[$plugin] : null;
|
||||
if (
|
||||
empty( $plugin_data['Version'] ) ||
|
||||
version_compare( $plugin_data['Version'], $update_data['new_version'], '>=' )
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
$transient_data->response[$plugin] = (object) $update_data;
|
||||
}
|
||||
|
||||
return $transient_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get plugin data from retrieved and cached data.
|
||||
*
|
||||
* @param array $data Current data.
|
||||
* @param string $action Action name.
|
||||
* @param array|null $args Query arguments.
|
||||
*
|
||||
* @return mixed Plugin data.
|
||||
*/
|
||||
public function plugins_api_filter( $data, $action = '', $args = null ) {
|
||||
/*
|
||||
if (
|
||||
'plugin_information' !== $action ||
|
||||
empty( $args->slug ) ||
|
||||
'all-in-one-event-calendar' !== substr( $args->slug, 0, 25 )
|
||||
) {
|
||||
return $data;
|
||||
}
|
||||
$update_data = get_site_transient( 'update_plugins' );
|
||||
$plugin_identifier = $args->slug . '/' . $args->slug . '.php';
|
||||
if ( empty( $update_data->response[$plugin_identifier] ) ) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
return $update_data->response[$plugin_identifier];
|
||||
*/
|
||||
$updates = $this->_download_updates();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear updates related transients.
|
||||
*
|
||||
* @return void Method does not return.
|
||||
*/
|
||||
public function clear_transients() {
|
||||
delete_site_transient( 'ai1ec_update_plugins' );
|
||||
delete_site_transient( 'update_plugins' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Download update info. Check local transient for cached data.
|
||||
*
|
||||
* @return array|mixed|null|object Update data.
|
||||
*/
|
||||
protected function _download_updates() {
|
||||
$cached_updates = get_site_transient( 'ai1ec_update_plugins' );
|
||||
if ( $cached_updates ) {
|
||||
return $cached_updates;
|
||||
}
|
||||
// try first endpoint
|
||||
$response = $this->_get_data_from_endpoint( self::PRIMARY_END_POINT );
|
||||
if ( is_wp_error( $response ) ) {
|
||||
$response = $this->_get_data_from_endpoint( self::SECONDARY_END_POINT );
|
||||
}
|
||||
if ( is_wp_error( $response ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$data = json_decode( wp_remote_retrieve_body( $response ), true );
|
||||
set_site_transient( 'ai1ec_update_plugins', $data, 30 * MINUTE_IN_SECONDS );
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get update data from given endpoint.
|
||||
*
|
||||
* @param string $endpoint Endpoint URI.
|
||||
*
|
||||
* @return array|WP_Error Request result.
|
||||
*/
|
||||
protected function _get_data_from_endpoint( $endpoint ) {
|
||||
|
||||
// Use ticketing token to check for subscriptions
|
||||
$token = $this->_registry->get( 'model.api.api-registration' )->get_timely_token();
|
||||
if ( null === $token ) {
|
||||
$token = '';
|
||||
}
|
||||
|
||||
$request = array(
|
||||
'method' => 'GET',
|
||||
'timeout' => 15,
|
||||
'sslverify' => false
|
||||
);
|
||||
|
||||
return wp_remote_request( $endpoint . '/' . $token, $request );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user