]> git.mxchange.org Git - friendica-addons.git/blob - jappixmini/jappix/php/post-design.php
Merge branch '3.6-release'
[friendica-addons.git] / jappixmini / jappix / php / post-design.php
1 <?php
2
3 /*
4
5 Jappix - An open social platform
6 This is the design configuration POST handler (manager)
7
8 -------------------------------------------------
9
10 License: AGPL
11 Author: Vanaryon
12 Last revision: 25/08/11
13
14 */
15
16 // Someone is trying to hack us?
17 if(!defined('JAPPIX_BASE'))
18         exit;
19
20 // Handle the remove GET
21 if(isset($_GET['k']) && !empty($_GET['k'])) {
22         $kill_logo = JAPPIX_BASE.'/store/logos/'.$_GET['k'].'.png';
23         
24         if(isSafe($kill_logo) && file_exists($kill_logo)) {
25                 unlink($kill_logo);
26                 
27                 echo('<p class="info smallspace success">'.T_("The selected elements have been removed.").'</p>');
28         }
29 }
30
31 // Handle the remove POST
32 else if(isset($_POST['remove']))
33         removeElements();
34
35 // Handle the logo upload POST
36 else if(isset($_POST['logo_upload'])) {
37         // Avoid errors
38         $logos_arr_1_name = $logos_arr_1_tmp = $logos_arr_2_name = $logos_arr_2_tmp = $logos_arr_3_name = $logos_arr_3_tmp = $logos_arr_4_name = $logos_arr_4_tmp = '';
39         
40         if(isset($_FILES['logo_own_1_location'])) {
41                 $logos_arr_1_name = $_FILES['logo_own_1_location']['name'];
42                 $logos_arr_1_tmp = $_FILES['logo_own_1_location']['tmp_name'];
43         }
44         
45         if(isset($_FILES['logo_own_2_location'])) {
46                 $logos_arr_2_name = $_FILES['logo_own_2_location']['name'];
47                 $logos_arr_2_tmp = $_FILES['logo_own_2_location']['tmp_name'];
48         }
49         
50         if(isset($_FILES['logo_own_3_location'])) {
51                 $logos_arr_3_name = $_FILES['logo_own_3_location']['name'];
52                 $logos_arr_3_tmp = $_FILES['logo_own_3_location']['tmp_name'];
53         }
54         
55         if(isset($_FILES['logo_own_4_location'])) {
56                 $logos_arr_4_name = $_FILES['logo_own_4_location']['name'];
57                 $logos_arr_4_tmp = $_FILES['logo_own_4_location']['tmp_name'];
58         }
59         
60         // File infos array
61         $logos = array(
62                 array($logos_arr_1_name, $logos_arr_1_tmp, JAPPIX_BASE.'/store/logos/desktop_home.png'),
63                 array($logos_arr_2_name, $logos_arr_2_tmp, JAPPIX_BASE.'/store/logos/desktop_app.png'),
64                 array($logos_arr_3_name, $logos_arr_3_tmp, JAPPIX_BASE.'/store/logos/mobile.png'),
65                 array($logos_arr_4_name, $logos_arr_4_tmp, JAPPIX_BASE.'/store/logos/mini.png')
66         );
67         
68         // Check for errors
69         $logo_error = false;
70         $logo_not_png = false;
71         $logo_anything = false;
72         
73         foreach($logos as $sub_array) {
74                 // Nothing?
75                 if(!$sub_array[0] || !$sub_array[1])
76                         continue;
77                 
78                 // Not an image?
79                 if(getFileExt($sub_array[0]) != 'png') {
80                         $logo_not_png = true;
81                         
82                         continue;
83                 }
84                 
85                 // Upload error?
86                 if(!move_uploaded_file($sub_array[1], $sub_array[2])) {
87                         $logo_error = true;
88                         
89                         continue;
90                 }
91                 
92                 $logo_anything = true;
93         }
94         
95         // Not an image?
96         if($logo_not_png) { ?>
97                 <p class="info smallspace fail"><?php _e("This is not a valid image, please use the PNG format!"); ?></p>
98         <?php }
99         
100         // Upload error?
101         else if($logo_error || !$logo_anything) { ?>
102                 <p class="info smallspace fail"><?php _e("The image could not be received, would you mind retry?"); ?></p>
103         <?php }
104         
105         // Everything went fine
106         else { ?>
107                 <p class="info smallspace success"><?php _e("Your service logo has been successfully changed!"); ?></p>
108         <?php }
109 }
110
111 // Handle the background upload POST
112 else if(isset($_POST['background_upload'])) {
113         // Get the file path
114         $name_background_image = $_FILES['background_image_upload']['name'];
115         $temp_background_image = $_FILES['background_image_upload']['tmp_name'];
116         $path_background_image = JAPPIX_BASE.'/store/backgrounds/'.$name_background_image;
117         
118         // An error occured?
119         if(!isSafe($name_background_image) || $_FILES['background_image_upload']['error'] || !move_uploaded_file($temp_background_image, $path_background_image)) { ?>
120         
121                 <p class="info smallspace fail"><?php _e("The image could not be received, would you mind retry?"); ?></p>
122         
123         <?php }
124         
125         // Bad extension?
126         else if(!isImage($name_background_image)) {
127                 // Remove the image file
128                 if(file_exists($path_background_image))
129                         unlink($path_background_image); 
130         ?>
131         
132                 <p class="info smallspace fail"><?php _e("This is not a valid image, please use PNG, GIF or JPG!"); ?></p>
133         
134         <?php }
135         
136         // The file has been sent
137         else { ?>
138         
139                 <p class="info smallspace success"><?php _e("Your image was added to the list!"); ?></p>
140         
141         <?php }
142 }
143
144 // Handle the save POST
145 else if(isset($_POST['save'])) {
146         // Marker
147         $save_marker = true;
148         
149         // Handle it for background
150         $background = array();
151         
152         if(isset($_POST['background_type']))
153                 $background['type'] = $_POST['background_type'];
154         
155         if(isset($_POST['background_image_file']))
156                 $background['image_file'] = $_POST['background_image_file'];
157
158         if(isset($_POST['background_image_repeat']))
159                 $background['image_repeat'] = $_POST['background_image_repeat'];
160         
161         if(isset($_POST['background_image_horizontal']))
162                 $background['image_horizontal'] = $_POST['background_image_horizontal'];
163         
164         if(isset($_POST['background_image_vertical']))
165                 $background['image_vertical'] = $_POST['background_image_vertical'];
166         
167         if(isset($_POST['background_image_adapt']))
168                 $background['image_adapt'] = 'on';
169         
170         if(isset($_POST['background_image_color']))
171                 $background['image_color'] = $_POST['background_image_color'];
172         
173         if(isset($_POST['background_color_color']))
174                 $background['color_color'] = $_POST['background_color_color'];
175         
176         // Write the configuration file
177         writeBackground($background);
178         
179         // Handle it for notice
180         if(isset($_POST['notice_type']))
181                 $notice_type = $_POST['notice_type'];
182         else
183                 $notice_type = 'none';
184         
185         $notice_text = '';
186         
187         if(isset($_POST['notice_text']))
188                 $notice_text = $_POST['notice_text'];
189         
190         // Check our values
191         if(!$notice_text && ($notice_type != 'none'))
192                 $save_marker = false;
193         
194         // All is okay
195         if($save_marker) {
196                 // Write the notice configuration
197                 writeNotice($notice_type, $notice_text);
198                 
199                 // Show a success notice
200                 ?>
201                 
202                         <p class="info smallspace success"><?php _e("Your design preferences have been saved!"); ?></p>
203                 
204                 <?php }
205                 
206                 // Something went wrong
207                 else { ?>
208                 
209                         <p class="info smallspace fail"><?php _e("Please check your inputs: something is missing!"); ?></p>
210                 
211                 <?php
212         }
213 }
214
215 ?>