180 |
180 |
181 //$translate->setLocale("en"); |
181 //$translate->setLocale("en"); |
182 // $acceptCookie = $this->_request->getCookie('acceptCookie',0); |
182 // $acceptCookie = $this->_request->getCookie('acceptCookie',0); |
183 |
183 |
184 if(isset($_GET['lang'])==false and isset($_SESSION['lang'])==false){ |
184 if(isset($_GET['lang'])==false and isset($_SESSION['lang'])==false){ |
185 |
185 |
186 if($actual!='fr' and $actual!='en' and $actual!='ja_JP'){ |
186 if($actual!='fr' and $actual!='en' and $actual!='ja_JP'){ |
187 $translate->setLocale("fr"); |
187 $translate->setLocale("fr"); |
188 $_SESSION['lang']="fr"; |
188 $_SESSION['lang']="fr"; |
189 } |
189 } |
190 |
190 |
191 } else if (isset($_GET['lang'])==true){ |
191 } else if (isset($_GET['lang'])==true){ |
192 $translate->setLocale($_GET['lang']); |
192 $translate->setLocale($_GET['lang']); |
193 $_SESSION['lang'] = $_GET['lang']; |
193 $_SESSION['lang'] = $_GET['lang']; |
194 $actual = $_SESSION['lang']; |
194 $actual = $_SESSION['lang']; |
195 |
195 |
196 } else if (isset($_SESSION['lang'])==true){ |
196 } else if (isset($_SESSION['lang'])==true){ |
197 $translate->setLocale( $_SESSION['lang']); |
197 $translate->setLocale( $_SESSION['lang']); |
198 $actual = $_SESSION['lang']; |
198 $actual = $_SESSION['lang']; |
199 |
199 |
200 } |
200 } |
201 |
201 |
202 $js_registry = array( |
202 $js_registry = array( |
203 'local' => array( |
203 'local' => array( |
204 'libdir' => URL_ROOT.'res/js/', |
204 'libdir' => URL_ROOT.'res/js/', |
205 'jquery' => URL_ROOT.'res/js/jquery-1.10.2.min.js', |
205 'jquery' => URL_ROOT.'res/js/jquery-1.10.2.min.js', |
206 'raphael' => URL_ROOT.'res/js/raphael-min.js', |
206 'raphael' => URL_ROOT.'res/js/raphael-min.js', |
207 'jquery-ui' => URL_ROOT.'res/js/jquery-ui.min.js', |
207 'jquery-ui' => URL_ROOT.'res/js/jquery-ui.min.js', |
208 'niceforms' => URL_ROOT.'res/js/niceforms.js', |
208 'niceforms' => URL_ROOT.'res/js/niceforms.js', |
209 'jquery-url' => URL_ROOT.'res/js/jquery.url.js', |
209 'jquery-url' => URL_ROOT.'res/js/jquery.url.js', |
210 'ldtplayer' => URL_ROOT.'res/metadataplayer/src/js/LdtPlayer.js', |
210 'ldtplayer' => URL_ROOT.'res/metadataplayer/src/js/LdtPlayer.js', |
211 'fancybox' => URL_ROOT.'res/js/fancybox/jquery.fancybox.pack.js', |
211 'fancybox' => URL_ROOT.'res/js/fancybox/jquery.fancybox.pack.js', |
212 'jquery-tools' => URL_ROOT.'res/js/jquery.tools.min.js', |
212 'jquery-tools' => URL_ROOT.'res/js/jquery.tools.min.js', |
213 'jquery-migrate' => URL_ROOT.'res/js/jquery-migrate-1.2.1.min.js', |
213 'jquery-migrate' => URL_ROOT.'res/js/jquery-migrate-1.2.1.min.js', |
214 'tw-widget' => URL_ROOT.'res/js/tw_widget.js', |
214 'tw-widget' => URL_ROOT.'res/js/tw_widget.js', |
215 'jquery-mousewheel' => URL_ROOT.'res/js/jquery.mousewheel.js', |
215 'jquery-mousewheel' => URL_ROOT.'res/js/jquery.mousewheel.js', |
216 'swfobject' => URL_ROOT.'res/js/swfobject.js', |
216 'swfobject' => URL_ROOT.'res/js/swfobject.js', |
217 'json-js' => URL_ROOT.'res/js/json2.js', |
217 'json-js' => URL_ROOT.'res/js/json2.js', |
218 'underscore' => URL_ROOT.'res/js/underscore-min.js' , |
218 'underscore' => URL_ROOT.'res/js/underscore-min.js' , |
219 'jquery-scrollto'=>URL_ROOT.'res/js/jquery.scrollTo-1.4.2-min.js' , |
219 'jquery-scrollto'=>URL_ROOT.'res/js/jquery.scrollTo-1.4.2-min.js' , |
220 'twcx-main' => URL_ROOT.'res/js/live-polemic.js' , |
220 'twcx-main' => URL_ROOT.'res/js/live-polemic.js' , |
221 'semanticboard' => URL_ROOT.'res/js/semanticboard.js' , |
221 'semanticboard' => URL_ROOT.'res/js/semanticboard.js' , |
222 'metadataplayer'=> URL_ROOT.'res/metadataplayer/LdtPlayer-core.js' , |
222 'metadataplayer'=> URL_ROOT.'res/metadataplayer/LdtPlayer-core.js' , |
223 'ldtwidgets' => URL_ROOT.'res/metadataplayer/' , |
223 'ldtwidgets' => URL_ROOT.'res/metadataplayer/' , |
224 'tracemanager' => URL_ROOT.'res/js/tracemanager.js' , |
224 'tracemanager' => URL_ROOT.'res/js/tracemanager.js' , |
225 'jwplayer-js' => URL_ROOT.'res/js/jwplayer.js', |
225 'jwplayer-js' => URL_ROOT.'res/js/jwplayer.js', |
226 'jquery-te' => URL_ROOT.'res/js/jquery-te-1.4.0.min.js', |
226 'jquery-tinymce' => URL_ROOT.'res/js/tinymce/jquery.tinymce.min.js', |
227 ), |
227 'tinymce' => URL_ROOT.'res/js/tinymce/tinymce.min.js', |
228 'cdn' => array( |
228 ), |
|
229 'cdn' => array( |
229 'libdir' => URL_ROOT.'res/js/', |
230 'libdir' => URL_ROOT.'res/js/', |
230 'jquery' => 'http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js', |
231 'jquery' => 'http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js', |
231 'raphael' => URL_ROOT.'res/js/raphael-min.js', |
232 'raphael' => URL_ROOT.'res/js/raphael-min.js', |
232 'jquery-ui' => 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js', |
233 'jquery-ui' => 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js', |
233 'niceforms' => URL_ROOT.'res/js/niceforms.js', |
234 'niceforms' => URL_ROOT.'res/js/niceforms.js', |
234 'jquery-url' => URL_ROOT.'res/js/jquery.url.js', |
235 'jquery-url' => URL_ROOT.'res/js/jquery.url.js', |
235 'ldtplayer' => URL_ROOT.'res/metadataplayer/src/js/LdtPlayer.js', |
236 'ldtplayer' => URL_ROOT.'res/metadataplayer/src/js/LdtPlayer.js', |
236 'fancybox' => URL_ROOT.'res/js/fancybox/jquery.fancybox.pack.js', |
237 'fancybox' => URL_ROOT.'res/js/fancybox/jquery.fancybox.pack.js', |
237 'jquery-tools' => 'http://cdn.jquerytools.org/1.2.7/all/jquery.tools.min.js', |
238 'jquery-tools' => 'http://cdn.jquerytools.org/1.2.7/all/jquery.tools.min.js', |
238 'jquery-migrate' => 'http://code.jquery.com/jquery-migrate-1.2.1.min.js', |
239 'jquery-migrate' => 'http://code.jquery.com/jquery-migrate-1.2.1.min.js', |
239 'tw-widget' => 'http://widgets.twimg.com/j/2/widget.js', |
240 'tw-widget' => 'http://widgets.twimg.com/j/2/widget.js', |
240 'jquery-mousewheel' => URL_ROOT.'res/js/jquery.mousewheel.js', |
241 'jquery-mousewheel' => URL_ROOT.'res/js/jquery.mousewheel.js', |
241 'swfobject' => 'http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js', |
242 'swfobject' => 'http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js', |
242 'json-js' => URL_ROOT.'res/js/json2.js', |
243 'json-js' => URL_ROOT.'res/js/json2.js', |
243 'underscore' => URL_ROOT.'res/js/underscore-min.js' , |
244 'underscore' => URL_ROOT.'res/js/underscore-min.js' , |
244 'jquery-scrollto'=>URL_ROOT.'res/js/jquery.scrollTo-1.4.2-min.js' , |
245 'jquery-scrollto'=>URL_ROOT.'res/js/jquery.scrollTo-1.4.2-min.js' , |
245 'twcx-main' => URL_ROOT.'res/js/live-polemic.js' , |
246 'twcx-main' => URL_ROOT.'res/js/live-polemic.js' , |
246 'semanticboard' => URL_ROOT.'res/js/semanticboard.js' , |
247 'semanticboard' => URL_ROOT.'res/js/semanticboard.js' , |
247 'metadataplayer'=> URL_ROOT.'res/metadataplayer/LdtPlayer-core.js' , |
248 'metadataplayer'=> URL_ROOT.'res/metadataplayer/LdtPlayer-core.js' , |
248 'ldtwidgets' => URL_ROOT.'res/metadataplayer/' , |
249 'ldtwidgets' => URL_ROOT.'res/metadataplayer/' , |
249 'tracemanager' => URL_ROOT.'res/js/tracemanager.js' , |
250 'tracemanager' => URL_ROOT.'res/js/tracemanager.js' , |
250 'jwplayer-js' => URL_ROOT.'res/js/jwplayer.js', |
251 'jwplayer-js' => URL_ROOT.'res/js/jwplayer.js', |
251 'jquery-te' => URL_ROOT.'res/js/jquery-te-1.4.0.min.js', |
252 'jquery-tinymce' => URL_ROOT.'res/js/tinymce/jquery.tinymce.min.js', |
252 ) |
253 'tinymce' => URL_ROOT.'res/js/tinymce/tinymce.min.js', |
|
254 ) |
253 ); |
255 ); |
254 |
256 |
255 $font_registry = array( |
257 $font_registry = array( |
256 'local' => array( |
258 'local' => array( |
257 'PT-Sans_Narrow' => URL_ROOT.'res/fonts/PTSansNarrow.css', |
259 'PT-Sans_Narrow' => URL_ROOT.'res/fonts/PTSansNarrow.css', |
258 'PT-Sans' => URL_ROOT.'res/fonts/PTSans.css' |
260 'PT-Sans' => URL_ROOT.'res/fonts/PTSans.css' |
259 ), |
261 ), |
260 'cdn' => array( |
262 'cdn' => array( |
261 'PT-Sans_Narrow' => 'http://fonts.googleapis.com/css?family=PT+Sans+Narrow&subset=latin', |
263 'PT-Sans_Narrow' => 'http://fonts.googleapis.com/css?family=PT+Sans+Narrow&subset=latin', |
262 'PT-Sans' => 'http://fonts.googleapis.com/css?family=PT+Sans&subset=latin' |
264 'PT-Sans' => 'http://fonts.googleapis.com/css?family=PT+Sans&subset=latin' |
263 ) |
265 ) |
264 ); |
266 ); |
265 |
267 |
266 |
268 |
267 $css_registry = array( |
269 $css_registry = array( |
268 'local' => array( |
270 'local' => array( |
269 'blueprint-screen' => URL_ROOT.'res/css/blueprint-screen.css', |
271 'blueprint-screen' => URL_ROOT.'res/css/blueprint-screen.css', |
270 'blueprint-print' => URL_ROOT.'res/css/blueprint-print.css', |
272 'blueprint-print' => URL_ROOT.'res/css/blueprint-print.css', |
271 'blueprint-ie' => URL_ROOT.'res/css/blueprint-ie.css', |
273 'blueprint-ie' => URL_ROOT.'res/css/blueprint-ie.css', |
272 'blueprint-plugins-fancy-type' => URL_ROOT.'res/css/blueprint-plugins/fancy-type/screen.css', |
274 'blueprint-plugins-fancy-type' => URL_ROOT.'res/css/blueprint-plugins/fancy-type/screen.css', |
273 'custom' => URL_ROOT.'res/css/custom.css', |
275 'custom' => URL_ROOT.'res/css/custom.css', |
274 'fancybox' => URL_ROOT.'res/js/fancybox/jquery.fancybox.css', |
276 'fancybox' => URL_ROOT.'res/js/fancybox/jquery.fancybox.css', |
275 'jquery-ui' => URL_ROOT.'res/metadataplayer/res/css/jq-css/themes/base/jquery-ui.css', |
277 'jquery-ui' => URL_ROOT.'res/metadataplayer/res/css/jq-css/themes/base/jquery-ui.css', |
276 'tabs-slideshow' => URL_ROOT.'res/css/tabs-slideshow.css', |
278 'tabs-slideshow' => URL_ROOT.'res/css/tabs-slideshow.css', |
277 'tweetcast' => URL_ROOT.'res/css/tweetcast.css', |
|
278 'semanticboard' => URL_ROOT.'res/css/semanticboard.css', |
|
279 'archives-iframe' => URL_ROOT.'res/css/archives-iframe.css', |
|
280 'metadataplayer' => URL_ROOT.'res/metadataplayer/LdtPlayer-core.css', |
|
281 'jquery-te' => URL_ROOT.'res/css/jquery-te.css', |
|
282 ), |
|
283 'cdn' => array( |
|
284 'blueprint-screen' => URL_ROOT.'res/css/blueprint-screen.css', |
|
285 'blueprint-print' => URL_ROOT.'res/css/blueprint-print.css', |
|
286 'blueprint-ie' => URL_ROOT.'res/css/blueprint-ie.css', |
|
287 'blueprint-plugins-fancy-type' => URL_ROOT.'res/css/blueprint-plugins/fancy-type/screen.css', |
|
288 'custom' => URL_ROOT.'res/css/custom.css', |
|
289 'fancybox' => URL_ROOT.'res/js/fancybox/jquery.fancybox.css', |
|
290 'jquery-ui' => "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/themes/base/jquery-ui.css", |
|
291 'tabs-slideshow' => URL_ROOT.'res/css/tabs-slideshow.css', |
|
292 'tweetcast' => URL_ROOT.'res/css/tweetcast.css', |
279 'tweetcast' => URL_ROOT.'res/css/tweetcast.css', |
293 'semanticboard' => URL_ROOT.'res/css/semanticboard.css', |
280 'semanticboard' => URL_ROOT.'res/css/semanticboard.css', |
294 'archives-iframe' => URL_ROOT.'res/css/archives-iframe.css', |
281 'archives-iframe' => URL_ROOT.'res/css/archives-iframe.css', |
295 'metadataplayer' => URL_ROOT.'res/metadataplayer/LdtPlayer-core.css', |
282 'metadataplayer' => URL_ROOT.'res/metadataplayer/LdtPlayer-core.css', |
296 'jquery-te' => URL_ROOT.'res/css/jquery-te.css', |
283 'jquery-te' => URL_ROOT.'res/css/jquery-te.css', |
297 ) |
284 ), |
|
285 'cdn' => array( |
|
286 'blueprint-screen' => URL_ROOT.'res/css/blueprint-screen.css', |
|
287 'blueprint-print' => URL_ROOT.'res/css/blueprint-print.css', |
|
288 'blueprint-ie' => URL_ROOT.'res/css/blueprint-ie.css', |
|
289 'blueprint-plugins-fancy-type' => URL_ROOT.'res/css/blueprint-plugins/fancy-type/screen.css', |
|
290 'custom' => URL_ROOT.'res/css/custom.css', |
|
291 'fancybox' => URL_ROOT.'res/js/fancybox/jquery.fancybox.css', |
|
292 'jquery-ui' => "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/themes/base/jquery-ui.css", |
|
293 'tabs-slideshow' => URL_ROOT.'res/css/tabs-slideshow.css', |
|
294 'tweetcast' => URL_ROOT.'res/css/tweetcast.css', |
|
295 'semanticboard' => URL_ROOT.'res/css/semanticboard.css', |
|
296 'archives-iframe' => URL_ROOT.'res/css/archives-iframe.css', |
|
297 'metadataplayer' => URL_ROOT.'res/metadataplayer/LdtPlayer-core.css', |
|
298 'jquery-te' => URL_ROOT.'res/css/jquery-te.css', |
|
299 ) |
298 ); |
300 ); |
299 |
301 |
300 |
302 |
301 function registry_url($key, $type, $registry_def=null) { |
303 function registry_url($key, $type, $registry_def=null) { |
302 |
304 |
303 global $js_registry, $font_registry, $css_registry, $C_default_registry; |
305 global $js_registry, $font_registry, $css_registry, $C_default_registry; |
304 |
306 |
305 if($registry_def != null) { |
307 if($registry_def != null) { |
306 $registry = $registry_def; |
308 $registry = $registry_def; |
307 } |
309 } |
308 elseif(isset($C_default_registry)) { |
310 elseif(isset($C_default_registry)) { |
309 $registry = $C_default_registry; |
311 $registry = $C_default_registry; |
310 } |
312 } |
311 else { |
313 else { |
312 $registry = 'local'; |
314 $registry = 'local'; |
313 } |
315 } |
314 $registry_name = $type."_registry"; |
316 $registry_name = $type."_registry"; |
315 return ${ |
317 return ${ |
316 $registry_name}[$registry][$key]; |
318 $registry_name}[$registry][$key]; |
317 |
319 |
318 } |
320 } |
319 |
321 |
320 function get_archive_box($rep, $metadata, $url_root, $basepath, &$translate) { |
322 function get_archive_box($rep, $metadata, $url_root, $basepath, &$translate) { |
321 |
323 |
322 include("$basepath$rep/config.php"); |
324 include("$basepath$rep/config.php"); |
323 |
325 |
324 set_config_translations($config, $translate); |
326 set_config_translations($config, $translate); |
325 /* $config_translations = get_config_translations($config); |
327 /* $config_translations = get_config_translations($config); |
326 |
328 |
327 // save the locale because it gets changed when adding translations |
329 // save the locale because it gets changed when adding translations |
328 $locale = $translate->getLocale(); |
330 $locale = $translate->getLocale(); |
329 |
331 |
330 $translate->addTranslation($config_translations['en'], 'en'); |
332 $translate->addTranslation($config_translations['en'], 'en'); |
331 $translate->addTranslation($config_translations['jp'], 'ja_JP'); |
333 $translate->addTranslation($config_translations['jp'], 'ja_JP'); |
332 $translate->addTranslation($config_translations['fr'], 'fr'); |
334 $translate->addTranslation($config_translations['fr'], 'fr'); |
333 |
335 |
334 // set the locale back |
336 // set the locale back |
335 $translate->setLocale($locale); |
337 $translate->setLocale($locale); |
336 */ |
338 */ |
337 $id = "abox_$rep".(($metadata!=null)?"_$metadata":""); |
339 $id = "abox_$rep".(($metadata!=null)?"_$metadata":""); |
338 $hash = ($metadata!=null)?"#metadata=$metadata":""; |
340 $hash = ($metadata!=null)?"#metadata=$metadata":""; |
339 $tail_img = $translate->_('config__archive_img'); |
341 $tail_img = $translate->_('config__archive_img'); |
340 if(is_array($tail_img)) { |
342 if(is_array($tail_img)) { |
341 $tail_img = $tail_img[$metadata]; |
343 $tail_img = $tail_img[$metadata]; |
342 } |
344 } |
343 $archive_title = $translate->_('config__archive_title'); |
345 $archive_title = $translate->_('config__archive_title'); |
344 if(is_array($archive_title)) { |
346 if(is_array($archive_title)) { |
345 $archive_title = $archive_title[$metadata]; |
347 $archive_title = $archive_title[$metadata]; |
346 } |
348 } |
347 $archive_description = $translate->_('config__archive_description'); |
349 $archive_description = $translate->_('config__archive_description'); |
348 if(is_array($archive_description)) { |
350 if(is_array($archive_description)) { |
349 $archive_description = $archive_description[$metadata]; |
351 $archive_description = $archive_description[$metadata]; |
350 } |
352 } |
351 |
353 |
352 |
354 |
353 $res = "<div id=\"$id\" class=\"archivesVideoBox\">\n"; |
355 $res = "<div id=\"$id\" class=\"archivesVideoBox\">\n"; |
354 $res .= " <a href=\"$rep/polemicaltimeline.php$hash\">\n"; |
356 $res .= " <a href=\"$rep/polemicaltimeline.php$hash\">\n"; |
355 $res .= " <img src=\"$url_root$rep/$tail_img\" width=\"270\" height=\"150\" class=\"AVBimg\" />"; |
357 $res .= " <img src=\"$url_root$rep/$tail_img\" width=\"270\" height=\"150\" class=\"AVBimg\" />"; |
356 $res .= " </a>"; |
358 $res .= " </a>"; |
357 $res .= " <div class=\"AVBtitle\">$archive_title</div>\n"; |
359 $res .= " <div class=\"AVBtitle\">$archive_title</div>\n"; |
358 $res .= " <div class=\"AVBtext\">\n"; |
360 $res .= " <div class=\"AVBtext\">\n"; |
359 $res .= " $archive_description\n"; |
361 $res .= " $archive_description\n"; |
360 $res .= " </div>\n"; |
362 $res .= " </div>\n"; |
361 $res .= "</div>\n"; |
363 $res .= "</div>\n"; |
362 |
364 |
363 return $res; |
365 return $res; |
364 |
366 |
365 } |
367 } |
366 |
368 |
367 function display_archives_list($archives_list, $box_class, $url_root, $basepath, &$translate) { |
369 function display_archives_list($archives_list, $box_class, $url_root, $basepath, &$translate) { |
368 |
370 |
369 |
371 |
370 for($i=0;$i<count($archives_list);$i++) { |
372 for($i=0;$i<count($archives_list);$i++) { |
371 if(($i % 3)==0) { |
373 if(($i % 3)==0) { |
372 print(" <div class=\"$box_class\">\n"); |
374 print(" <div class=\"$box_class\">\n"); |
373 } |
375 } |
374 $archive_ref = $archives_list[$i]; |
376 $archive_ref = $archives_list[$i]; |
375 |
377 |
376 $archive_name = $archive_ref; |
378 $archive_name = $archive_ref; |
377 $metadata = null; |
379 $metadata = null; |
378 if(is_array($archive_ref)) { |
380 if(is_array($archive_ref)) { |
379 $archive_name = $archive_ref[0]; |
381 $archive_name = $archive_ref[0]; |
380 $metadata = $archive_ref[1]; |
382 $metadata = $archive_ref[1]; |
381 } |
383 } |
382 print(get_archive_box($archive_name,$metadata, $url_root, $basepath, $translate)); |
384 print(get_archive_box($archive_name,$metadata, $url_root, $basepath, $translate)); |
383 if(($i % 3)==2 || $i == (count($archives_list)-1)) { |
385 if(($i % 3)==2 || $i == (count($archives_list)-1)) { |
384 print(" </div>\n"); |
386 print(" </div>\n"); |
385 } |
387 } |
386 } |
388 } |
387 } |
389 } |
388 |
390 |
389 function get_metadata_url($metadata) { |
391 function get_metadata_url($metadata) { |
390 global $ldt_platform, $project_url_base; |
392 global $ldt_platform, $project_url_base; |
391 if (preg_match('/^https?:\/\//', $metadata)) { |
393 if (preg_match('/^https?:\/\//', $metadata)) { |
408 $realm = 'Polemictweet restricted area'; |
410 $realm = 'Polemictweet restricted area'; |
409 |
411 |
410 |
412 |
411 function authenticate($users, $translate) { |
413 function authenticate($users, $translate) { |
412 |
414 |
413 global $realm; |
415 global $realm; |
414 |
416 |
415 |
417 |
416 if (empty($_SERVER['PHP_AUTH_DIGEST']) || !isset($_SESSION['http_digest_nonce'])) { |
418 if (empty($_SERVER['PHP_AUTH_DIGEST']) || !isset($_SESSION['http_digest_nonce'])) { |
417 $_SESSION['http_digest_nonce'] = uniqid(); |
419 $_SESSION['http_digest_nonce'] = uniqid(); |
418 header('HTTP/1.1 401 Unauthorized'); |
420 header('HTTP/1.1 401 Unauthorized'); |
419 header('WWW-Authenticate: Digest realm="'.$realm. |
421 header('WWW-Authenticate: Digest realm="'.$realm. |
420 '",qop="auth",nonce="'.$_SESSION['http_digest_nonce'].'",opaque="'.md5($realm).'"'); |
422 '",qop="auth",nonce="'.$_SESSION['http_digest_nonce'].'",opaque="'.md5($realm).'"'); |
421 return array('error' => $translate->_('This area is restricted, please authenticate')); |
423 return array('error' => $translate->_('This area is restricted, please authenticate')); |
422 } |
424 } |
423 |
425 |
424 |
426 |
425 //analyze the PHP_AUTH_DIGEST variable |
427 //analyze the PHP_AUTH_DIGEST variable |
426 if (!($data = http_digest_parse($_SERVER['PHP_AUTH_DIGEST'])) || |
428 if (!($data = http_digest_parse($_SERVER['PHP_AUTH_DIGEST'])) || |
427 !isset($users[$data['username']])) { |
429 !isset($users[$data['username']])) { |
428 $_SERVER['PHP_AUTH_DIGEST'] = ''; |
430 $_SERVER['PHP_AUTH_DIGEST'] = ''; |
429 unset($_SESSION['auth']); |
431 unset($_SESSION['auth']); |
430 unset($_SESSION['http_digest_nonce']); |
432 unset($_SESSION['http_digest_nonce']); |
431 return array('error' => $translate->_('Wrong Credentials!')); |
433 return array('error' => $translate->_('Wrong Credentials!')); |
432 } |
434 } |
433 |
435 |
434 |
436 |
435 //generate the valid response |
437 //generate the valid response |
436 $A1 = md5($data['username'] . ':' . $realm . ':' . $users[$data['username']]); |
438 $A1 = md5($data['username'] . ':' . $realm . ':' . $users[$data['username']]); |
437 $A2 = md5($_SERVER['REQUEST_METHOD'].':'.$data['uri']); |
439 $A2 = md5($_SERVER['REQUEST_METHOD'].':'.$data['uri']); |
438 $valid_response = md5($A1.':'.$data['nonce'].':'.$data['nc'].':'.$data['cnonce'].':'.$data['qop'].':'.$A2); |
440 $valid_response = md5($A1.':'.$data['nonce'].':'.$data['nc'].':'.$data['cnonce'].':'.$data['qop'].':'.$A2); |
439 |
441 |
440 if ($data['response'] != $valid_response) { |
442 if ($data['response'] != $valid_response) { |
441 $_SERVER['PHP_AUTH_DIGEST'] = ''; |
443 $_SERVER['PHP_AUTH_DIGEST'] = ''; |
442 unset($_SESSION['http_digest_nonce']); |
444 unset($_SESSION['http_digest_nonce']); |
443 unset($_SESSION['auth']); |
445 unset($_SESSION['auth']); |
444 return array('error' => $translate->_('Wrong Credentials!')); |
446 return array('error' => $translate->_('Wrong Credentials!')); |
445 } |
447 } |
446 |
448 |
447 // ok, valid username & password |
449 // ok, valid username & password |
448 $_SESSION['auth'] = $data['username']; |
450 $_SESSION['auth'] = $data['username']; |
449 return $data; |
451 return $data; |
450 } |
452 } |
451 |
453 |
452 function logout() { |
454 function logout() { |
453 global $realm; |
455 global $realm; |
454 |
456 |
455 unset($_SESSION['auth']); |
457 unset($_SESSION['auth']); |
456 unset($_SESSION['http_digest_nonce']); |
458 unset($_SESSION['http_digest_nonce']); |
457 } |
459 } |
458 |
460 |
459 |
461 |
460 //function to parse the http auth header |
462 //function to parse the http auth header |
461 function http_digest_parse($txt) |
463 function http_digest_parse($txt) |
462 { |
464 { |
463 // protect against missing data |
465 // protect against missing data |
464 $needed_parts = array('nonce'=>1, 'nc'=>1, 'cnonce'=>1, 'qop'=>1, 'username'=>1, 'uri'=>1, 'response'=>1); |
466 $needed_parts = array('nonce'=>1, 'nc'=>1, 'cnonce'=>1, 'qop'=>1, 'username'=>1, 'uri'=>1, 'response'=>1); |
465 $data = array(); |
467 $data = array(); |
466 $keys = implode('|', array_keys($needed_parts)); |
468 $keys = implode('|', array_keys($needed_parts)); |
467 |
469 |
468 preg_match_all('@(' . $keys . ')=(?:([\'"])([^\2]+?)\2|([^\s,]+))@', $txt, $matches, PREG_SET_ORDER); |
470 preg_match_all('@(' . $keys . ')=(?:([\'"])([^\2]+?)\2|([^\s,]+))@', $txt, $matches, PREG_SET_ORDER); |
469 |
471 |
470 foreach ($matches as $m) { |
472 foreach ($matches as $m) { |
471 $data[$m[1]] = $m[3] ? $m[3] : $m[4]; |
473 $data[$m[1]] = $m[3] ? $m[3] : $m[4]; |
472 unset($needed_parts[$m[1]]); |
474 unset($needed_parts[$m[1]]); |
473 } |
475 } |
474 |
476 |
475 return $needed_parts ? false : $data; |
477 return $needed_parts ? false : $data; |
476 } |
478 } |
477 |
479 |
478 /** |
480 /** |
479 * Modifies a string to remove all non ASCII characters and spaces. |
481 * Modifies a string to remove all non ASCII characters and spaces. |
480 */ |
482 */ |
481 function slugify($text) |
483 function slugify($text) |
482 { |
484 { |
483 // replace non letter or digits by - |
485 // replace non letter or digits by - |
484 $text = preg_replace('~[^\\pL\d]+~u', '-', $text); |
486 $text = preg_replace('~[^\\pL\d]+~u', '-', $text); |
485 |
487 |
486 // trim |
488 // trim |
487 $text = trim($text, '-'); |
489 $text = trim($text, '-'); |
488 |
490 |
489 // transliterate |
491 // transliterate |
490 if (function_exists('iconv')) |
492 if (function_exists('iconv')) |
491 { |
493 { |
492 $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text); |
494 $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text); |
493 } |
495 } |
494 |
496 |
495 // lowercase |
497 // lowercase |
496 $text = strtolower($text); |
498 $text = strtolower($text); |
497 |
499 |
498 // remove unwanted characters |
500 // remove unwanted characters |
499 $text = preg_replace('~[^-\w]+~', '', $text); |
501 $text = preg_replace('~[^-\w]+~', '', $text); |
500 |
502 |
501 if (empty($text)) |
503 if (empty($text)) |
502 { |
504 { |
503 return 'n-a'; |
505 return 'n-a'; |
504 } |
506 } |
505 |
507 |
506 return $text; |
508 return $text; |
507 } |
509 } |
508 |
510 |
509 |
511 |
510 // from http://www.house6.com/blog/?p=83 |
512 // from http://www.house6.com/blog/?p=83 |
511 function sanitize_filename($f) { |
513 function sanitize_filename($f) { |
512 // a combination of various methods |
514 // a combination of various methods |
513 // we don't want to convert html entities, or do any url encoding |
515 // we don't want to convert html entities, or do any url encoding |
514 // we want to retain the "essence" of the original file name, if possible |
516 // we want to retain the "essence" of the original file name, if possible |
515 // char replace table found at: |
517 // char replace table found at: |
516 // http://www.php.net/manual/en/function.strtr.php#98669 |
518 // http://www.php.net/manual/en/function.strtr.php#98669 |
517 $replace_chars = array( |
519 $replace_chars = array( |
518 'Š'=>'S', 'š'=>'s', 'Ð'=>'Dj','Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', |
520 'Š'=>'S', 'š'=>'s', 'Ð'=>'Dj','Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', |
519 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', |
521 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', |
520 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U', |
522 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U', |
521 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss','à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', |
523 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss','à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', |
522 'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', |
524 'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', |
523 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u', |
525 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u', |
524 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y', 'ƒ'=>'f' |
526 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y', 'ƒ'=>'f' |
525 ); |
527 ); |
526 $f = strtr($f, $replace_chars); |
528 $f = strtr($f, $replace_chars); |
527 // convert & to "and", @ to "at", and # to "number" |
529 // convert & to "and", @ to "at", and # to "number" |
528 $f = preg_replace(array('/[\&]/', '/[\@]/', '/[\#]/'), array('-and-', '-at-', '-number-'), $f); |
530 $f = preg_replace(array('/[\&]/', '/[\@]/', '/[\#]/'), array('-and-', '-at-', '-number-'), $f); |
529 $f = preg_replace('/[^(\x20-\x7F)]*/','', $f); // removes any special chars we missed |
531 $f = preg_replace('/[^(\x20-\x7F)]*/','', $f); // removes any special chars we missed |
530 $f = str_replace(' ', '-', $f); // convert space to hyphen |
532 $f = str_replace(' ', '-', $f); // convert space to hyphen |
531 $f = str_replace('\'', '', $f); // removes apostrophes |
533 $f = str_replace('\'', '', $f); // removes apostrophes |
532 $f = preg_replace('/[^\w\-\.]+/', '', $f); // remove non-word chars (leaving hyphens and periods) |
534 $f = preg_replace('/[^\w\-\.]+/', '', $f); // remove non-word chars (leaving hyphens and periods) |
533 $f = preg_replace('/[\-]+/', '-', $f); // converts groups of hyphens into one |
535 $f = preg_replace('/[\-]+/', '-', $f); // converts groups of hyphens into one |
534 if (function_exists('iconv')) |
536 if (function_exists('iconv')) |
535 { |
537 { |
536 $f = iconv('utf-8', 'us-ascii//TRANSLIT', $f); |
538 $f = iconv('utf-8', 'us-ascii//TRANSLIT', $f); |
537 } |
539 } |
538 |
540 |
539 return strtolower($f); |
541 return strtolower($f); |
540 } |
542 } |