5 Jappix - An open social platform
6 These are the PHP functions for Jappix Get API
8 -------------------------------------------------
11 Authors: Vanaryon, Mathieui, olivierm
12 Last revision: 26/08/11
16 // The function to get the cached content
17 function readCache($hash) {
18 return file_get_contents(JAPPIX_BASE.'/store/cache/'.$hash.'.cache');
21 // The function to generate a cached file
22 function genCache($string, $mode, $cache) {
24 $cache_dir = JAPPIX_BASE.'/store/cache';
25 $file_put = $cache_dir.'/'.$cache.'.cache';
27 // Cache not yet wrote
28 if(is_dir($cache_dir) && !file_exists($file_put))
29 file_put_contents($file_put, $string);
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);
41 // The function to compress the CSS
42 function compressCSS($buffer) {
43 // We remove the comments
44 $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
46 // We remove the useless spaces
47 $buffer = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer);
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);
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
62 // Replace the JS strings
64 // Static host defined
65 if($host && ($host != '.'))
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);
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);
75 // Replace the CSS strings
76 else if($type == 'css') {
77 // Static host defined
78 if($host && ($host != '.'))
79 $static = $host.'/php';
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);
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);
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);
97 $available_names = '';
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).'\', ';
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);
112 'LOCALES_AVAILABLE_ID' => $available_id,
113 'LOCALES_AVAILABLE_NAMES' => $available_names
117 foreach($array as $array_key => $array_value)
118 $string = preg_replace('/(var '.$array_key.'(( )?=( )?)new Array\()(\);)/', '$1'.$array_value.'$5', $string);
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
127 $bosh_special = staticLocation().'php/bosh.php';
129 $bosh_special = HOST_BOSH;
131 // Configuration array
134 'XML_LANG' => $locale,
137 'JAPPIX_STATIC' => staticLocation(),
138 'JAPPIX_VERSION' => $version,
139 'JAPPIX_MAX_FILE_SIZE' => $max_upload,
140 'JAPPIX_MAX_UPLOAD' => formatBytes($max_upload),
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,
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
173 foreach($array as $array_key => $array_value)
174 $string = preg_replace('/var '.$array_key.'(( )?=( )?)null;/', 'var '.$array_key.'$1\''.addslashes($array_value).'\';', $string);
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')) {
185 background-image: url(../store/logos/desktop_home.png) !important;
186 background-position: center center !important;
190 // Jappix Desktop app logo?
191 if(in_array('tools.css', $files) && file_exists(JAPPIX_BASE.'/store/logos/desktop_app.png')) {
193 '#top-content .tools-logo {
194 background-image: url(../store/logos/desktop_app.png) !important;
195 background-position: center center !important;
199 // Jappix Mobile logo?
200 if(in_array('mobile.css', $files) && file_exists(JAPPIX_BASE.'/store/logos/mobile.png')) {
203 background-image: url(../store/logos/mobile.png) !important;
204 background-position: center center !important;
209 if(in_array('mini.css', $files) && file_exists(JAPPIX_BASE.'/store/logos/mini.png')) {
211 '#jappix_mini div.jm_actions a.jm_logo {
212 background-image: url(../store/logos/mini.png) !important;
213 background-position: center center !important;
220 // The function to set the background
221 function setBackground($string) {
222 // Get the default values
223 $array = defaultBackground();
225 // Read the background configuration
226 $xml = readXML('conf', 'background');
229 $read = new SimpleXMLElement($xml);
231 foreach($read->children() as $child) {
234 $array[$child->getName()] = $child;
240 // Generate the CSS code
241 switch($array['type']) {
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'].';'
251 // Add CSS code to adapt the image?
252 if($array['image_adapt'] == 'on')
254 ' background-attachment: fixed;
255 background-size: cover;
256 -moz-background-size: cover;
257 -webkit-background-size: cover;';
265 $css .= "\n".' background-color: '.$array['color_color'].';'."\n";
269 // Default: use the filtering regex
276 // Apply the replacement!
277 return preg_replace('/(\.body-images( )?\{)([^\{\}]+)(\})/i', '$1'.$css.'$4', $string);