2 include_once (PARENT_DIR . '/admin/data_management/update.php');
4 @define('PARENT_NAME', 'CherryFramework');
6 $framework_version = get_theme_info(PARENT_NAME, 'Version');
7 function get_theme_info($theme_name, $data_type=''){
8 if ( function_exists('wp_get_theme') ) {
9 $theme = wp_get_theme($theme_name);
10 $return_info = $data_type ? $theme -> $data_type : $theme ;
12 $theme = get_theme_data(get_theme_root() . '/' . $theme_name . '/style.css');
13 $return_info = $data_type ? $theme[$data_type] : $theme ;
18 function get_file_date($theme_name){
19 $get_date_backup = get_option($theme_name."_date_backup");
20 $get_version_backup = get_option($theme_name."_version_backup");
21 $theme = new stdClass();
23 if($get_date_backup!=''){
24 $theme->date = $get_date_backup;
26 $theme->date = theme_locals("no_backup");
28 if($get_version_backup!=''){
29 $theme->backup_version = $get_version_backup;
31 $theme->backup_version = theme_locals("no_backup");
36 function add_radio_button($theme_name, $input_name, $checked=false){
37 $input_radio = '<input ';
38 $input_radio .= 'class="theme_name ';
39 if(get_option($theme_name."_date_backup")==""){
40 $input_radio .= 'no_backup';
42 $input_radio .= '" type="radio" value="'.$theme_name.'"';
44 $input_radio .= ' name="'.$input_name.'" ';
47 $input_radio .= 'checked ';
53 function check_update(){
54 global $wp_version, $framework_version, $framework_update;
55 $theme_base = get_theme_info(PARENT_NAME, 'Template');
56 $response["new_version"] = $framework_version;
57 $request = array('slug' => $theme_base, 'version' => $framework_version);
58 $send_for_check = array( 'body' => array('action' => 'theme_update', 'request' => serialize($request), 'api-key' => md5(get_bloginfo('url'))), 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url'));
59 $raw_response = wp_remote_post(API_URL, $send_for_check);
60 if (!is_wp_error($raw_response) && ($raw_response['response']['code'] == 200)){
61 $response= unserialize($raw_response['body']);
63 if(!isset($response)){
64 if($response["new_version"]==""){
65 $response["new_version"] = $framework_version;
68 return $response["new_version"];
72 if ( ! function_exists( 'admin_data_management' ) ) {
73 function admin_data_management () {
74 global $framework_version;
76 <div id="optionsframework-metabox" class="metabox-holder">
77 <div id="optionsframework" class="postbox store-holder">
79 <h3><?php echo theme_locals("data_management"); ?></h3>
80 <div class="data_management">
81 <p><?php echo theme_locals("info_box_1"); ?></p>
82 <div class="theme_box">
83 <h4><?php echo theme_locals('cherry_framework'); ?></h4>
84 <?php if(FILE_WRITEABLE){ ?>
85 <div class="error"><p><?php echo theme_locals("info_box_2"); ?></p></div>
87 <div class="controls framework_info">
88 <span class="data_label"><?php echo theme_locals("name"); ?>:</span><span class="data_val"><?php echo get_theme_info(PARENT_NAME, 'Name'); ?></span><br>
89 <span class="data_label"><?php echo theme_locals("author"); ?>:</span><span class="data_val"><?php echo get_theme_info(PARENT_NAME, 'Author'); ?></span><br>
90 <span class="data_label"><?php echo theme_locals("your_version"); ?>:</span><span id="your_version_<?php echo PARENT_NAME; ?>" class="data_val"><?php echo $framework_version; ?></span><br>
91 <span class="data_label"><?php echo theme_locals("update_version"); ?>:</span><span id="update_version" class="data_val"><?php echo check_update(); ?></span><br>
92 <span class="data_label"><?php echo theme_locals("backup_version"); ?>:</span><span id="version_<?php echo PARENT_NAME; ?>" class="data_val"><?php echo get_file_date(PARENT_NAME)->backup_version ?></span><br>
93 <span class="data_label"><?php echo theme_locals("backup_date"); ?>:</span><span id="date_<?php echo PARENT_NAME; ?>" class="data_val"><?php echo get_file_date(PARENT_NAME)->date ?></span><br>
94 <span class="data_label"><?php echo theme_locals("description"); ?>:</span><span class="data_val"><?php echo get_theme_info(PARENT_NAME, 'Description'); ?></span><br>
95 <?php add_radio_button(get_theme_info(PARENT_NAME, 'Template'), "", true); ?>
97 <?php if ( FILE_WRITEABLE ) { ?>
98 <div class="buttons_controls">
99 <div class="button_wrapper">
101 $update_url = wp_nonce_url('update.php?action=upgrade-theme&theme=' . urlencode(PARENT_NAME), 'upgrade-theme_'.urlencode(PARENT_NAME));
104 if($framework_version>=check_update()){
105 $cap = '<span class="cap"></span>';
106 $disable_class = "disable_button";
108 echo "<a id=\"update_framework\" class=\"button-primary ".$disable_class."\" href=\"".$update_url."\" onclick=\"if ( confirm('Updating this theme will lose any customizations you have made. \'Cancel\' to stop, \'OK\' to update.') ) {return true;}return false;\">".theme_locals("update")."</a>".$cap;
112 <div class="button_wrapper">
113 <a class="button-primary backup_theme" href="<?php echo PARENT_NAME; ?>" title="<?php echo theme_locals('backup'); ?>"><?php echo theme_locals("backup"); ?></a>
115 <div class="button_wrapper">
116 <a class="button-primary restore_theme " href="<?php echo PARENT_NAME; ?>" title="<?php echo theme_locals('restore'); ?>"><?php echo theme_locals("restore"); ?></a>
118 <div class="button_wrapper">
119 <a class="button-primary download_backup" href="<?php echo PARENT_NAME; ?>" title="<?php echo theme_locals('download_backup'); ?>"><?php echo theme_locals("download_backup"); ?></a>
123 printf('<p><em>'.theme_locals('warning_notice_1').' '.theme_locals('warning_notice_3').'</em></p>');
127 $themes_dir = get_theme_root();
128 $themes = scandir($themes_dir);
129 $themes_array = array();
130 foreach ($themes as $theme) {
131 if(is_dir("$themes_dir/$theme")){
132 if(strtolower(get_theme_info($theme, 'Template')) == 'cherryframework' && strtolower($theme) != 'cherryframework'){
133 array_push($themes_array, $theme);
137 if(count($themes_array)!=0){
140 <div class="theme_box">
141 <h4><?php echo theme_locals("child_theme"); ?></h4>
142 <div class="controls child_theme">
143 <div class="child_theme_title">
144 <span class="select"> </span>
145 <span class="child_preview"><?php echo theme_locals("preview"); ?></span>
146 <span class="name"><?php echo theme_locals("name"); ?></span>
147 <span class="date"><?php echo theme_locals("backup_date"); ?></span>
149 <div class="child_theme_list">
151 $input_checked = true;
152 foreach ($themes_array as $theme) {
154 echo '<span class="select">';
155 add_radio_button($theme, "theme_name", $input_checked);
157 $input_checked = false;
160 echo '<span class="child_preview">';
161 if(file_exists($themes_dir."/$theme/screenshot.png")){
162 echo '<img src="'.get_theme_root_uri()."/$theme/screenshot.png".'" alt="'.$theme.'">';
165 echo '<span class="name">'.$theme.'</span>';
166 echo '<span id="date_'.$theme.'" class="date">'.get_file_date($theme)->date.'</span>';
168 $not_child_theme = false;
173 <?php if (FILE_WRITEABLE) { ?>
174 <div class="buttons_controls">
175 <div class="button_wrapper">
176 <a class="button-primary backup_theme" href="CherryFramework" title="<?php echo theme_locals('backup'); ?>"><?php echo theme_locals("backup"); ?></a>
178 <div class="button_wrapper">
179 <a class="button-primary restore_theme" href="CherryFramework" title="<?php echo theme_locals('restore'); ?>"><?php echo theme_locals("restore"); ?></a>
181 <div class="button_wrapper">
182 <a class="button-primary download_backup" href="CherryFramework" title="<?php echo theme_locals('download_backup'); ?>"><?php echo theme_locals("download_backup"); ?></a>
186 printf('<p><em>'.theme_locals('warning_notice_1').' '.theme_locals('warning_notice_3').'</em></p>');