author = "Kriesi";
$this->username = trim(avia_get_option('updates_username'));
$this->apikey = trim(avia_get_option('updates_api_key'));
$this->themename = self::get_themename();
$this->includes();
$this->hooks();
}
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();
}
function includes()
{
if(!empty($this->username) && !empty($this->apikey))
{
require_once("class-pixelentity-theme-update.php");
PixelentityThemeUpdate::init($this->username ,$this->apikey,$this->author);
}
}
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;
}
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;
}
}
}
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);
}
}
}
}
public static function add_updates_tab($avia_pages)
{
$title = __("Theme Update",'avia_framework');
if(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;
}
public static function sidebar_menu_title($title)
{
$title .= '1';
return $title;
}
public static function check_for_theme_update()
{
$updates = get_site_transient('update_themes');
if(!empty($updates) && !empty($updates->response))
{
$theme = wp_get_theme();
if($key = array_key_exists($theme->get_template(), $updates->response))
{
return $updates->response[$theme->get_template()];
}
}
return false;
}
public static function option_page_data($avia_elements)
{
$avia_elements[] = array( "name" => "Update your Theme from the WordPress Dashboard",
"desc" => "If you want to get update notifications for your themes and if you want to be able to update your theme from your WordPress backend you need to enter your Themeforest account name as well as your Themeforest Secret API Key below:",
"std" => "",
"slug" => "update",
"type" => "heading",
"nodescription"=>true);
$avia_elements[] = array(
"slug" => "update",
"std" => "",
"name" => "Your Themeforest User Name",
"desc" => "Enter the Name of the User you used to purchase this theme",
"id" => "updates_username",
"type" => "text"
);
$avia_elements[] = array(
"slug" => "update",
"std" => "",
"name" => "Your Themeforest API Key",
"desc" => "Enter the API Key of your Account here.
You can find your API Key here",
"id" => "updates_api_key",
"type" => "text"
);
$avia_elements[] = array(
"slug" => "update",
"std" => "",
"name" => "",
"desc" => false,
"id" => "update_notification",
"use_function" => true,
"type" => "avia_backend_display_update_notification"
);
return $avia_elements;
}
public static function backend_html()
{
$username = trim(avia_get_option('updates_username'));
$apikey = trim(avia_get_option('updates_api_key'));
$output = "";
$version = self::get_version();
$themename = self::get_themename();
$parent_string = is_child_theme() ? "Parent Theme (". ucfirst( $themename ).")" : "Theme";
if(empty($username) || empty($apikey))
{
$output = "