]> _ Git - couzy.git/blob
d1cdca63af1ba9afc62ab8d105cbe628e1c51015
[couzy.git] /
1 <?php
2         include_once (PARENT_DIR . '/admin/data_management/update.php');
3
4         @define('PARENT_NAME', 'CherryFramework');
5
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 ;
11                 } else {
12                         $theme = get_theme_data(get_theme_root() . '/' . $theme_name . '/style.css');
13                         $return_info = $data_type ? $theme[$data_type] : $theme ;
14                 }
15                 return $return_info;
16         }
17
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();
22
23                 if($get_date_backup!=''){
24                         $theme->date = $get_date_backup;
25                 }else{
26                         $theme->date = theme_locals("no_backup");
27                 }
28                 if($get_version_backup!=''){
29                         $theme->backup_version = $get_version_backup;
30                 }else{
31                         $theme->backup_version = theme_locals("no_backup");
32                 }
33                 return $theme;
34         }
35
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';
41                 }
42                 $input_radio .= '" type="radio" value="'.$theme_name.'"';
43                 if($input_name!=""){
44                         $input_radio .= ' name="'.$input_name.'" ';
45                 }
46                 if($checked){
47                         $input_radio .= 'checked ';
48                 }
49                 $input_radio .= '>';
50                 echo $input_radio;
51         }
52
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']);
62                 }
63                 if(!isset($response)){
64                         if($response["new_version"]==""){
65                                 $response["new_version"] = $framework_version;
66                         }
67                 }
68                 return $response["new_version"];
69         }
70
71
72         if ( ! function_exists( 'admin_data_management' ) ) {
73                 function admin_data_management () {
74                         global $framework_version;
75                         ?>
76                         <div id="optionsframework-metabox" class="metabox-holder">
77                                 <div id="optionsframework" class="postbox store-holder">
78                                         <div class="wrap">
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>
86                                                                 <?php } ?>
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); ?>
96                                                                 </div>
97                                                                 <?php if ( FILE_WRITEABLE ) { ?>
98                                                                 <div class="buttons_controls">
99                                                                         <div class="button_wrapper">
100                                                                                 <?php 
101                                                                                         $update_url = wp_nonce_url('update.php?action=upgrade-theme&amp;theme=' . urlencode(PARENT_NAME), 'upgrade-theme_'.urlencode(PARENT_NAME));
102                                                                                         $disable_class= "";
103                                                                                         $cap= "";
104                                                                                         if($framework_version>=check_update()){
105                                                                                                 $cap = '<span class="cap"></span>';
106                                                                                                 $disable_class = "disable_button";
107                                                                                         }
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;
109                                                                                         
110                                                                                 ?>
111                                                                         </div>
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>
114                                                                         </div>
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>
117                                                                         </div>
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>
120                                                                         </div>
121                                                                 </div>
122                                                                 <?php }else{
123                                                                         printf('<p><em>'.theme_locals('warning_notice_1').' '.theme_locals('warning_notice_3').'</em></p>');
124                                                                 }?>
125                                                         </div>
126                                                         <?php
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);
134                                                                                 }
135                                                                         }
136                                                                 }
137                                                                 if(count($themes_array)!=0){
138                                                         ?>
139
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>
148                                                                         </div>
149                                                                         <div class="child_theme_list">
150                                                                                 <?php
151                                                                                         $input_checked = true;
152                                                                                         foreach ($themes_array as $theme) {
153                                                                                                 echo '<label>';
154                                                                                                 echo '<span class="select">';
155                                                                                                 add_radio_button($theme, "theme_name", $input_checked);
156                                                                                                 if($input_checked){
157                                                                                                         $input_checked = false;
158                                                                                                 }
159                                                                                                 echo '</span>';
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.'">';
163                                                                                                 }
164                                                                                                 echo '</span>';
165                                                                                                 echo '<span class="name">'.$theme.'</span>';
166                                                                                                 echo '<span id="date_'.$theme.'" class="date">'.get_file_date($theme)->date.'</span>';
167                                                                                                 echo '</label>';
168                                                                                                 $not_child_theme = false;
169                                                                                         }
170                                                                                 ?>
171                                                                         </div>
172                                                                 </div>
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>
177                                                                         </div>
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>
180                                                                         </div>
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>
183                                                                         </div>
184                                                                 </div>
185                                                                 <?php }else{
186                                                                         printf('<p><em>'.theme_locals('warning_notice_1').' '.theme_locals('warning_notice_3').'</em></p>');
187                                                                 }?>
188                                                         </div>
189                                                         <?php
190                                                                 }
191                                                         ?>
192                                                 </div>
193                                         </div>
194                                 </div>
195                         </div>
196                         <?php
197                 }
198         }
199 ?>