]> git.mxchange.org Git - friendica-addons.git/blob - jappixmini/jappix/php/functions-get.php
GContact moved to src
[friendica-addons.git] / jappixmini / jappix / php / functions-get.php
1 <?php
2
3 /*
4
5 Jappix - An open social platform
6 These are the PHP functions for Jappix Get API
7
8 -------------------------------------------------
9
10 License: AGPL
11 Authors: Vanaryon, Mathieui, olivierm
12 Last revision: 26/08/11
13
14 */
15
16 // The function to get the cached content
17 function readCache($hash) {
18         return file_get_contents(JAPPIX_BASE.'/store/cache/'.$hash.'.cache');
19 }
20
21 // The function to generate a cached file
22 function genCache($string, $mode, $cache) {
23         if(!$mode) {
24                 $cache_dir = JAPPIX_BASE.'/store/cache';
25                 $file_put = $cache_dir.'/'.$cache.'.cache';
26                 
27                 // Cache not yet wrote
28                 if(is_dir($cache_dir) && !file_exists($file_put))
29                         file_put_contents($file_put, $string);
30         }
31 }
32
33 // The function to remove the BOM from a string
34 function rmBOM($string) { 
35         if(substr($string, 0, 3) == pack('CCC', 0xef, 0xbb, 0xbf))
36                 $string = substr($string, 3);
37         
38         return $string; 
39 }
40
41 // The function to compress the CSS
42 function compressCSS($buffer) {
43         // We remove the comments
44         $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
45         
46         // We remove the useless spaces
47         $buffer = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ', '    '), '', $buffer);
48         
49         // We remove the last useless spaces
50         $buffer = str_replace(array(' { ',' {','{ '), '{', $buffer);
51         $buffer = str_replace(array(' } ',' }','} '), '}', $buffer);
52         $buffer = str_replace(array(' : ',' :',': '), ':', $buffer);
53         
54         return $buffer;
55 }
56
57 // The function to replace classical path to get.php paths
58 function setPath($string, $hash, $host, $type, $locale) {
59         // Initialize the static server path
60         $static = '.';
61         
62         // Replace the JS strings
63         if($type == 'js') {
64                 // Static host defined
65                 if($host && ($host != '.'))
66                         $static = $host;
67                 
68                 // Links to JS (must have a lang parameter)
69                 $string = preg_replace('/((\")|(\'))(\.\/)(js)(\/)(\S+)(js)((\")|(\'))/', '$1'.$static.'/php/get.php?h='.$hash.'&l='.$locale.'&t=$5&f=$7$8$9', $string);
70                 
71                 // Other "normal" links (no lang parameter)
72                 $string = preg_replace('/((\")|(\'))(\.\/)(css|img|store|snd)(\/)(\S+)(css|png|jpg|jpeg|gif|bmp|ogg|oga)((\")|(\'))/', '$1'.$static.'/php/get.php?h='.$hash.'&t=$5&f=$7$8$9', $string);
73         }
74         
75         // Replace the CSS strings
76         else if($type == 'css') {
77                 // Static host defined
78                 if($host && ($host != '.'))
79                         $static = $host.'/php';
80                 
81                 $string = preg_replace('/(\(\.\.\/)(css|js|img|store|snd)(\/)(\S+)(css|js|png|jpg|jpeg|gif|bmp|ogg|oga)(\))/', '('.$static.'/get.php?h='.$hash.'&t=$2&f=$4$5)', $string);
82         }
83         
84         return $string;
85 }
86
87 // The function to set the good translation to a JS file
88 function setTranslation($string) {
89         return preg_replace('/_e\("([^\"\"]+)"\)/e', "'_e(\"'.addslashes(T_gettext(stripslashes('$1'))).'\")'", $string);
90 }
91
92 // The function to set the good locales
93 function setLocales($string, $locale) {
94         // Generate the two JS array list
95         $available_list = availableLocales($locale);
96         $available_id = '';
97         $available_names = '';
98         
99         // Add the values to the arrays
100         foreach($available_list as $current_id => $current_name) {
101                 $available_id .= '\''.$current_id.'\', ';
102                 $available_names .= '\''.addslashes($current_name).'\', ';
103         }
104         
105         // Remove the last comma
106         $regex = '/(.+), $/';
107         $available_id = preg_replace($regex, '$1', $available_id);
108         $available_names = preg_replace($regex, '$1', $available_names);
109         
110         // Locales array
111         $array = array(
112                         'LOCALES_AVAILABLE_ID' => $available_id,
113                         'LOCALES_AVAILABLE_NAMES' => $available_names
114                       );
115         
116         // Apply it!
117         foreach($array as $array_key => $array_value)
118                 $string = preg_replace('/(var '.$array_key.'(( )?=( )?)new Array\()(\);)/', '$1'.$array_value.'$5', $string);
119         
120         return $string;
121 }
122
123 // The function to set the good configuration to a JS file
124 function setConfiguration($string, $locale, $version, $max_upload) {
125         // Special BOSH URL if BOSH proxy enabled
126         if(BOSHProxy())
127                 $bosh_special = staticLocation().'php/bosh.php';
128         else
129                 $bosh_special = HOST_BOSH;
130         
131         // Configuration array
132         $array = array(
133                         // xml:lang
134                         'XML_LANG'              => $locale,
135                         
136                         // Jappix parameters
137                         'JAPPIX_STATIC'         => staticLocation(),
138                         'JAPPIX_VERSION'        => $version,
139                         'JAPPIX_MAX_FILE_SIZE'  => $max_upload,
140                         'JAPPIX_MAX_UPLOAD'     => formatBytes($max_upload),
141                         
142                         // Main configuration
143                         'SERVICE_NAME'          => SERVICE_NAME,
144                         'SERVICE_DESC'          => SERVICE_DESC,
145                         'JAPPIX_RESOURCE'       => JAPPIX_RESOURCE,
146                         'LOCK_HOST'             => LOCK_HOST,
147                         'ANONYMOUS'             => ANONYMOUS,
148                         'REGISTRATION'          => REGISTRATION,
149                         'BOSH_PROXY'            => BOSH_PROXY,
150                         'MANAGER_LINK'          => MANAGER_LINK,
151                         'GROUPCHATS_JOIN'       => GROUPCHATS_JOIN,
152                         'ENCRYPTION'            => ENCRYPTION,
153                         'HTTPS_STORAGE'         => HTTPS_STORAGE,
154                         'HTTPS_FORCE'           => HTTPS_FORCE,
155                         'COMPRESSION'           => COMPRESSION,
156                         'MULTI_FILES'           => MULTI_FILES,
157                         'DEVELOPER'             => DEVELOPER,
158                         
159                         // Hosts configuration
160                         'HOST_MAIN'             => HOST_MAIN,
161                         'HOST_MUC'              => HOST_MUC,
162                         'HOST_PUBSUB'           => HOST_PUBSUB,
163                         'HOST_VJUD'             => HOST_VJUD,
164                         'HOST_ANONYMOUS'        => HOST_ANONYMOUS,
165                         'HOST_BOSH'             => $bosh_special,
166                         'HOST_BOSH_MAIN'        => HOST_BOSH_MAIN,
167                         'HOST_BOSH_MINI'        => HOST_BOSH_MINI,
168                         'HOST_STATIC'           => HOST_STATIC,
169                         'HOST_UPLOAD'           => HOST_UPLOAD
170                       );
171         
172         // Apply it!
173         foreach($array as $array_key => $array_value)
174                 $string = preg_replace('/var '.$array_key.'(( )?=( )?)null;/', 'var '.$array_key.'$1\''.addslashes($array_value).'\';', $string);
175         
176         return $string;
177 }
178
179 // The function to set the logos
180 function setLogos($string, $files) {
181         // Jappix Desktop home logo?
182         if(in_array('home.css', $files) && file_exists(JAPPIX_BASE.'/store/logos/desktop_home.png')) {
183                 $string .=
184 '#home .left .logo {
185         background-image: url(../store/logos/desktop_home.png) !important;
186         background-position: center center !important;
187 }';
188         }
189         
190         // Jappix Desktop app logo?
191         if(in_array('tools.css', $files) && file_exists(JAPPIX_BASE.'/store/logos/desktop_app.png')) {
192                 $string .=
193 '#top-content .tools-logo {
194         background-image: url(../store/logos/desktop_app.png) !important;
195         background-position: center center !important;
196 }';
197         }
198         
199         // Jappix Mobile logo?
200         if(in_array('mobile.css', $files) && file_exists(JAPPIX_BASE.'/store/logos/mobile.png')) {
201                 $string .=
202 '.header div {
203         background-image: url(../store/logos/mobile.png) !important;
204         background-position: center center !important;
205 }';
206         }
207         
208         // Jappix Mini logo?
209         if(in_array('mini.css', $files) && file_exists(JAPPIX_BASE.'/store/logos/mini.png')) {
210                 $string .=
211 '#jappix_mini div.jm_actions a.jm_logo {
212         background-image: url(../store/logos/mini.png) !important;
213         background-position: center center !important;
214 }';
215         }       
216         
217         return $string;
218 }
219
220 // The function to set the background
221 function setBackground($string) {
222         // Get the default values
223         $array = defaultBackground();
224         
225         // Read the background configuration
226         $xml = readXML('conf', 'background');
227         
228         if($xml) {
229                 $read = new SimpleXMLElement($xml);
230                 
231                 foreach($read->children() as $child) {
232                         // Any value?
233                         if($child)
234                                 $array[$child->getName()] = $child;
235                 }
236         }
237         
238         $css = '';
239         
240         // Generate the CSS code
241         switch($array['type']) {
242                 // Image
243                 case 'image':
244                         $css .= 
245         "\n".'  background-image: url(../store/backgrounds/'.urlencode($array['image_file']).');
246         background-repeat: '.$array['image_repeat'].';
247         background-position: '.$array['image_horizontal'].' '.$array['image_vertical'].';
248         background-color: '.$array['image_color'].';'
249                         ;
250                         
251                         // Add CSS code to adapt the image?
252                         if($array['image_adapt'] == 'on')
253                                 $css .= 
254         '       background-attachment: fixed;
255         background-size: cover;
256         -moz-background-size: cover;
257         -webkit-background-size: cover;';
258                         
259                         $css .= "\n";
260                         
261                         break;
262                 
263                 // Color
264                 case 'color':
265                         $css .= "\n".'  background-color: '.$array['color_color'].';'."\n";
266                         
267                         break;
268                 
269                 // Default: use the filtering regex
270                 default:
271                         $css .= '$3';
272                         
273                         break;
274         }
275         
276         // Apply the replacement!
277         return preg_replace('/(\.body-images( )?\{)([^\{\}]+)(\})/i', '$1'.$css.'$4', $string);
278 }
279
280 ?>