web/common.php
changeset 988 954019f62866
parent 985 374aacd1eb0d
child 989 e4e219f7b12c
--- a/web/common.php	Wed Nov 13 17:55:34 2013 +0100
+++ b/web/common.php	Sun Nov 24 03:13:33 2013 +0100
@@ -13,12 +13,15 @@
 /**
 * Base configuration
 */
+date_default_timezone_set('UTC');
 
 $ldt_platform = 'http://ldt.iri.centrepompidou.fr/';
 $project_url_base = 'ldtplatform/ldt/cljson/id/';
 
 $C_default_rep = 'attention-1314-01-notion-attention';
 $C_feedback_form_url = 'https://spreadsheets.google.com/spreadsheet/viewform?hl=en_US&formkey=dDZILVdXVHRzd0xhWGVZXzkweHN2RGc6MQ#gid=0';
+$C_event_props = __DIR__ . "/event_props";
+$C_event_users = array('polemictweet' => 'polemictweet'.date('Y/m/d'));
 
 $archives_list = array(
     "rsln", "rsln-opendata", "rsln-mercedes-bunz",
@@ -57,7 +60,10 @@
 	$req_rep = $config['rep'];
 }
 
-include_once dirname(__FILE__).'/traduction.php';
+foreach (glob(dirname(__FILE__).'/traductions/*.php') as $trad_filename)
+{
+	include_once $trad_filename;
+}
 if(file_exists(dirname(__FILE__)."/$req_rep/traduction.php")) {
 	include_once dirname(__FILE__)."/$req_rep/traduction.php";
 }
@@ -153,9 +159,9 @@
 $translate = new Zend_Translate('array', $init, 'fr');
 
 
-$translate->addTranslation($english, 'en');
-$translate->addTranslation($japan, 'ja_JP');
-$translate->addTranslation($french, 'fr');
+$translate->addTranslation($traduction_en, 'en');
+$translate->addTranslation($traduction_ja, 'ja_JP');
+$translate->addTranslation($traduction_fr, 'fr');
 
 if(isset($config)) {
     
@@ -194,16 +200,16 @@
 $js_registry = array(
 	'local' => array(
 	    'libdir'        => URL_ROOT.'res/js/',
-	    'jquery' 		=> URL_ROOT.'res/js/jquery-1.4.3.min.js',
+	    'jquery' 		=> URL_ROOT.'res/js/jquery-1.10.2.min.js',
 	    'raphael' 		=> URL_ROOT.'res/js/raphael-min.js',
-	    'jquery-ui' 	=> URL_ROOT.'res/js/jquery-ui-1.8.13.min.js',
+	    'jquery-ui' 	=> URL_ROOT.'res/js/jquery-ui.min.js',
 	    'niceforms' 	=> URL_ROOT.'res/js/niceforms.js',
 	    'jquery-url' 	=> URL_ROOT.'res/js/jquery.url.js',
 	    'ldtplayer' 	=> URL_ROOT.'res/metadataplayer/src/js/LdtPlayer.js',
-		'fancybox' 		=> URL_ROOT.'res/js/fancybox/jquery.fancybox-1.3.4.pack.js',
+		'fancybox' 		=> URL_ROOT.'res/js/fancybox/jquery.fancybox.pack.js',
 		'jquery-tools' 	=> URL_ROOT.'res/js/jquery.tools.min.js',
 		'tw-widget' 	=> URL_ROOT.'res/js/tw_widget.js',
-		'jquery-mousewheel' => URL_ROOT.'res/js/jquery.mousewheel-3.0.4.pack.js',
+		'jquery-mousewheel' => URL_ROOT.'res/js/jquery.mousewheel.js',
 		'swfobject' 	=> URL_ROOT.'res/js/swfobject.js',
 		'json-js' 		=> URL_ROOT.'res/js/json2.js',
 		'underscore'    => URL_ROOT.'res/js/underscore-min.js' ,
@@ -213,20 +219,21 @@
         'metadataplayer'=> URL_ROOT.'res/metadataplayer/LdtPlayer-core.js' ,
         'ldtwidgets'    => URL_ROOT.'res/metadataplayer/' ,
         'tracemanager'  => URL_ROOT.'res/js/tracemanager.js' ,
-        'jwplayer-js'   => URL_ROOT.'res/js/jwplayer.js'
+        'jwplayer-js'   => URL_ROOT.'res/js/jwplayer.js',
+		'jquery-te'     => URL_ROOT.'res/js/jquery-te-1.4.0.min.js',
 	),
 	'cdn' => array(
         'libdir'        => URL_ROOT.'res/js/',
-	    'jquery' 		=> 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js',
+	    'jquery' 		=> 'http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js',
 		'raphael' 		=> URL_ROOT.'res/js/raphael-min.js',
-		'jquery-ui' 	=> 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js',
+		'jquery-ui' 	=> 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js',
 		'niceforms' 	=> URL_ROOT.'res/js/niceforms.js',
 		'jquery-url' 	=> URL_ROOT.'res/js/jquery.url.js',
 		'ldtplayer' 	=> URL_ROOT.'res/metadataplayer/src/js/LdtPlayer.js',
-		'fancybox' 		=> URL_ROOT.'res/js/fancybox/jquery.fancybox-1.3.4.pack.js',
+		'fancybox' 		=> URL_ROOT.'res/js/fancybox/jquery.fancybox.pack.js',
 		'jquery-tools' 	=> 'http://cdn.jquerytools.org/1.2.4/all/jquery.tools.min.js',
 		'tw-widget' 	=> 'http://widgets.twimg.com/j/2/widget.js',
-        'jquery-mousewheel' => URL_ROOT.'res/js/jquery.mousewheel-3.0.4.pack.js',
+        'jquery-mousewheel' => URL_ROOT.'res/js/jquery.mousewheel.js',
 		'swfobject' 	=> 'http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js',
         'json-js'       => URL_ROOT.'res/js/json2.js',
         'underscore'    => URL_ROOT.'res/js/underscore-min.js' ,
@@ -236,7 +243,8 @@
         'metadataplayer'=> URL_ROOT.'res/metadataplayer/LdtPlayer-core.js' ,
         'ldtwidgets'    => URL_ROOT.'res/metadataplayer/' ,
         'tracemanager'  => URL_ROOT.'res/js/tracemanager.js' ,
-        'jwplayer-js'   => URL_ROOT.'res/js/jwplayer.js'
+        'jwplayer-js'   => URL_ROOT.'res/js/jwplayer.js',
+		'jquery-te'     => URL_ROOT.'res/js/jquery-te-1.4.0.min.js',
 	)
 );
 
@@ -259,13 +267,14 @@
 		'blueprint-ie' => URL_ROOT.'res/css/blueprint-ie.css',
 		'blueprint-plugins-fancy-type' => URL_ROOT.'res/css/blueprint-plugins/fancy-type/screen.css',
 		'custom' => URL_ROOT.'res/css/custom.css',
-		'fancybox' => URL_ROOT.'res/js/fancybox/jquery.fancybox-1.3.4.css',
+		'fancybox' => URL_ROOT.'res/js/fancybox/jquery.fancybox.css',
 		'jquery-ui' => URL_ROOT.'res/metadataplayer/res/css/jq-css/themes/base/jquery-ui.css',
 		'tabs-slideshow' => URL_ROOT.'res/css/tabs-slideshow.css',
 		'tweetcast' => URL_ROOT.'res/css/tweetcast.css',
 		'semanticboard' =>  URL_ROOT.'res/css/semanticboard.css',
         'archives-iframe' => URL_ROOT.'res/css/archives-iframe.css',
         'metadataplayer' => URL_ROOT.'res/metadataplayer/LdtPlayer-core.css',
+		'jquery-te' => URL_ROOT.'res/css/jquery-te.css',
 	),
 	'cdn' => array(
 		'blueprint-screen' => URL_ROOT.'res/css/blueprint-screen.css',
@@ -273,13 +282,14 @@
 		'blueprint-ie' => URL_ROOT.'res/css/blueprint-ie.css',
 		'blueprint-plugins-fancy-type' => URL_ROOT.'res/css/blueprint-plugins/fancy-type/screen.css',
 		'custom' => URL_ROOT.'res/css/custom.css',
-		'fancybox' => URL_ROOT.'res/js/fancybox/jquery.fancybox-1.3.4.css',
+		'fancybox' => URL_ROOT.'res/js/fancybox/jquery.fancybox.css',
 		'jquery-ui' => "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/themes/base/jquery-ui.css",
 		'tabs-slideshow' => URL_ROOT.'res/css/tabs-slideshow.css',
         'tweetcast' => URL_ROOT.'res/css/tweetcast.css',
         'semanticboard' =>  URL_ROOT.'res/css/semanticboard.css',
         'archives-iframe' => URL_ROOT.'res/css/archives-iframe.css',
         'metadataplayer' => URL_ROOT.'res/metadataplayer/LdtPlayer-core.css',
+		'jquery-te' => URL_ROOT.'res/css/jquery-te.css',
 	)
 );
 
@@ -389,3 +399,70 @@
         return get_metadata_url($metadata);
     }
 }
+
+
+$realm = 'Polemictweet restricted area';
+
+function authenticate($users, $translate) {
+
+	global $realm;
+	
+	if (empty($_SERVER['PHP_AUTH_DIGEST'])) {
+		$_SESSION['http_digest_nonce'] = uniqid();
+		header('HTTP/1.1 401 Unauthorized');
+		header('WWW-Authenticate: Digest realm="'.$realm.
+		'",qop="auth",nonce="'.$_SESSION['http_digest_nonce'].'",opaque="'.md5($realm).'"');
+
+		return array('error' => $translate->_('This area is restricted, please authenticate'));
+	}
+
+
+	//analyze the PHP_AUTH_DIGEST variable
+	if (!($data = http_digest_parse($_SERVER['PHP_AUTH_DIGEST'])) ||
+		!isset($users[$data['username']])) {
+		$_SERVER['PHP_AUTH_DIGEST'] = '';
+		return array('error' => $translate->_('Wrong Credentials!'));
+	}
+
+
+	//generate the valid response
+	$A1 = md5($data['username'] . ':' . $realm . ':' . $users[$data['username']]);
+	$A2 = md5($_SERVER['REQUEST_METHOD'].':'.$data['uri']);
+	$valid_response = md5($A1.':'.$data['nonce'].':'.$data['nc'].':'.$data['cnonce'].':'.$data['qop'].':'.$A2);
+
+	if ($data['response'] != $valid_response) {
+		$_SERVER['PHP_AUTH_DIGEST'] = '';
+		return array('error' => $translate->_('Wrong Credentials!'));
+	}
+
+	// ok, valid username & password
+	$_SESSION['auth'] = $data;
+	return $data;
+}
+
+function logout() {
+	global $realm;
+	
+	$_SESSION['auth'] = null;
+	header('HTTP/1.1 401 Unauthorized');
+	header('WWW-Authenticate: Digest realm="'.$realm.'",qop="auth",nonce="'.$_SESSION['http_digest_nonce'].'",opaque="'.md5($realm).'"');
+}
+
+
+//function to parse the http auth header
+function http_digest_parse($txt)
+{
+	// protect against missing data
+	$needed_parts = array('nonce'=>1, 'nc'=>1, 'cnonce'=>1, 'qop'=>1, 'username'=>1, 'uri'=>1, 'response'=>1);
+	$data = array();
+	$keys = implode('|', array_keys($needed_parts));
+
+	preg_match_all('@(' . $keys . ')=(?:([\'"])([^\2]+?)\2|([^\s,]+))@', $txt, $matches, PREG_SET_ORDER);
+
+	foreach ($matches as $m) {
+		$data[$m[1]] = $m[3] ? $m[3] : $m[4];
+		unset($needed_parts[$m[1]]);
+	}
+
+	return $needed_parts ? false : $data;
+}