username = trim( avia_get_option( 'updates_username' ) );
$this->apikey = trim( avia_get_option( 'updates_api_key' ) );
$this->author = "Kriesi";
$this->personal_token = trim( avia_get_option( 'updates_envato_token' ) );
$this->envato_token_state = trim( avia_get_option( 'updates_envato_token_state' ) );
$this->themename = self::get_themename();
$this->includes();
$this->hooks();
}
/**
* @since < 4.4.3
*/
protected function hooks()
{
add_action( 'update_bulk_theme_complete_actions', array( $this, 'update_complete' ), 10, 2 );
add_action( 'upgrader_process_complete', array( $this,'re_insert_custom_css' ) );
add_action( 'load-update.php', array( $this, 'temp_save_custom_css' ), 20 );
$this->temp_save_custom_css();
}
/**
* Include classes. We stay backwards compatible with the old API but request users to enter the personal token
*
* @since < 4.4.3
*/
protected function includes()
{
require_once( 'class-avia-theme-updater.php' );
$args = array(
'authors' => $this->author,
'personal_token' => ! empty( $this->envato_token_state ) ? $this->personal_token : '',
);
AviaThemeUpdater( $args );
if( empty( $this->personal_token ) && ! empty( $this->username ) && ! empty( $this->apikey ) )
{
/**
* backwards comp. for old API - can be removed in some future
* support for new API added in 4.4.3
*/
require_once( "class-pixelentity-theme-update.php" );
PixelentityThemeUpdate::init( $this->username , $this->apikey, $this->author );
}
}
/**
*
* @since < 4.4.3
* @param array $updates
* @param WP_Theme $info
* @return array
*/
public function update_complete( $updates, $info )
{
if(strtolower( $info->get('Name') ) == strtolower( $this->themename ) )
{
$updates = array('theme_updates' => 'Go Back to '.THEMENAME.' Theme Panel');
}
return $updates;
}
/**
*
* @since < 4.4.3
*/
public function re_insert_custom_css()
{
if(isset($this->custom_css_md5) && $this->custom_css_md5 == "1877fc72c3a2a4e3f1299ccdb16d0513") return;
if(isset($this->custom_css))
{
$self_update = "Attention: We detected some custom styling rules in your custom.css file but could not restore it. Please open the file yourself and add the following content:
";
if (is_writeable($this->custom_css))
{
$handle = @fopen( $this->custom_css, 'w' );
if ($handle && fwrite($handle, $this->custom_css_content)) {
echo "Attention: We detected some custom styling rules in your custom.css file and restored it ;)";
}
else
{
echo $self_update;
}
}
else
{
echo $self_update;
}
}
}
/**
*
* @since < 4.4.3
*/
public function temp_save_custom_css()
{
if(empty($_GET['themes']) || $_GET['themes'] != strtolower( $this->themename ) ) return;
$css_path = AVIA_BASE.'css/custom.css';
if(file_exists($css_path) && is_readable($css_path))
{
$size = filesize($css_path);
if($size > 0)
{
$handle = @fopen( $css_path, 'r' );
if ($handle)
{
$this->custom_css_content = fread($handle, $size);
$this->custom_css_md5 = md5($this->custom_css_content);
$this->custom_css = $css_path;
fclose($handle);
}
}
}
}
/**
*
* @since < 4.4.3
* @param array $avia_pages
* @return array
*/
public static function add_updates_tab( $avia_pages )
{
$title = __("Theme Update",'avia_framework');
if( false !== self::check_for_theme_update() )
{
$title .= "1";
add_filter('avia_filter_backend_menu_title', array('avia_auto_updates','sidebar_menu_title'));
}
$avia_pages[] = apply_filters('avf_update_theme_tab', array( 'slug' => 'update', 'parent'=>'avia', 'icon'=>"update.png", 'title' => $title ));
return $avia_pages;
}
/**
*
* @param string $title
* @return string
*/
public static function sidebar_menu_title( $title )
{
$title .= '1';
return $title;
}
/**
*
* @since < 4.4.3
* @return array|false
*/
public static function check_for_theme_update()
{
$updates = get_site_transient('update_themes');
$version = self::get_version();
if( ! empty( $updates ) && ! empty( $updates->response ) )
{
$theme = wp_get_theme();
$name = $theme->get_template();
if( array_key_exists( $name, $updates->response ) )
{
if( version_compare( $updates->response[ $name ]['new_version'], $version, '!=' ) )
{
return $updates->response[ $name ];
}
}
}
return false;
}
/**
*
* @since < 4.4.3
* @param array $avia_elements
* @return array
*/
public static function option_page_data( $avia_elements )
{
$desc = __( "If you want to get update notifications for your theme and if you want to be able to update your theme from your WordPress backend you need to enter your Envato Private Token below.", 'avia_framework' );
$desc .= '
';
$desc .= sprintf( __( 'A detailed description for generating this token can be found %s here %s', 'avia_framework' ), '', '' );
$avia_elements[] = array(
"name" => __( "Update your Theme from the WordPress Dashboard", 'avia_framework' ),
"desc" => $desc,
"std" => "",
"slug" => "update",
"type" => "heading",
"nodescription" => true
);
$avia_elements[] = array(
"slug" => "update",
"name" => __( "Enter a valid Envato private token", 'avia_framework' ),
"desc" => "",
"id" => "updates_envato_token",
"type" => "verification_field",
"ajax" => "av_envato_token_check",
"class" => "av_full_description",
"button-label" => __( 'Check the private token', 'avia_framework' ),
"button-relabel" => __( 'Revalidate or remove the token', 'avia_framework' ),
"std" => '',
'force_callback' => true
);
$avia_elements[] = array(
"slug" => "update",
"std" => "",
"name" => __( "Last verify state - hidden - used for internal use only", 'avia_framework' ),
"desc" => '',
"id" => "updates_envato_token_state",
"type" => "hidden",
// 'readonly' => true
);
/**
* deprecated - can be removed in future releases
*/
$avia_elements[] = array(
"slug" => "update",
"std" => "",
"name" => __( "Your Themeforest User Name (will be deprecated and removed in future) - hidden", 'avia_framework' ),
"desc" => '',
"id" => "updates_username",
"type" => "hidden",
// 'readonly' => true
);
/**
* deprecated - can be removed in future releases
*/
$avia_elements[] = array(
"slug" => "update",
"std" => "",
"name" => __( "Your Themeforest API Key (will be deprecated and removed in future) - hidden", 'avia_framework' ),
// "desc" => "Enter the API Key of your Account here.
You can find your API Key here",
"desc" => '',
"id" => "updates_api_key",
"type" => "hidden",
// 'readonly' => true
);
$avia_elements[] = array(
"slug" => "update",
"std" => "",
"name" => __( "Envato Reply - hidden - used for internal use only", 'avia_framework' ),
"desc" => '',
"id" => "updates_envato_info",
"type" => "hidden",
// 'readonly' => true
);
$avia_elements[] = array(
"slug" => "update",
"std" => "",
"name" => "",
"desc" => false,
"id" => "update_notification",
"use_function" => true,
"type" => "avia_backend_display_update_notification"
);
return $avia_elements;
}
/**
* @since < 4.4.3
* @return string
*/
public static function backend_html()
{
/**
* will be deprecated in future
*/
$username = trim(avia_get_option('updates_username'));
$apikey = trim(avia_get_option('updates_api_key'));
$old_keys_valid = ! empty( $username ) && ! empty( $apikey );
$updates_envato_token = trim( avia_get_option( 'updates_envato_token' ) );
$updates_envato_token_state = trim( avia_get_option( 'updates_envato_token_state' ) );
$keys_valid = ! empty( $updates_envato_token ) && ! empty( $updates_envato_token_state );
$output = '';
$version = self::get_version();
$themename = self::get_themename();
$parent_string = is_child_theme() ? "Parent Theme (". ucfirst( $themename ).")" : ucfirst( $themename )." Theme";
$update = self::check_for_theme_update();
if( ( ! $keys_valid ) && ( ! $old_keys_valid ) )
{
$output .= "