web/common.php
changeset 1558 761ba7426984
parent 1557 7c67caaafdeb
child 1571 4a1e6952afe5
equal deleted inserted replaced
1557:7c67caaafdeb 1558:761ba7426984
     2 
     2 
     3 // composer autoload files
     3 // composer autoload files
     4 require __DIR__ . '/vendor/autoload.php';
     4 require __DIR__ . '/vendor/autoload.php';
     5 
     5 
     6 use Abraham\TwitterOAuth\TwitterOAuth;
     6 use Abraham\TwitterOAuth\TwitterOAuth;
     7 use Fundevogel\Mastodon\Api;
     7 use GuzzleHttp\Client;
       
     8 use GuzzleHttp\Psr7\URI;
     8 
     9 
     9 /**
    10 /**
    10 * Base configuration
    11  * Base configuration
    11 */
    12  */
    12 date_default_timezone_set('UTC');
    13 date_default_timezone_set('UTC');
       
    14 
       
    15 $MASTODON_DEFAULT_GROUP_DOMAIN = 'a.gup.pe';
    13 
    16 
    14 $project_url_base = 'ldtplatform/ldt/cljson/id/';
    17 $project_url_base = 'ldtplatform/ldt/cljson/id/';
    15 
    18 
    16 $C_default_rep = 'enmi21';
    19 $C_default_rep = 'enmi21';
    17 $C_feedback_form_url = 'https://spreadsheets.google.com/spreadsheet/viewform?hl=en_US&formkey=dDZILVdXVHRzd0xhWGVZXzkweHN2RGc6MQ#gid=0';
    20 $C_feedback_form_url = 'https://spreadsheets.google.com/spreadsheet/viewform?hl=en_US&formkey=dDZILVdXVHRzd0xhWGVZXzkweHN2RGc6MQ#gid=0';
    18 $C_event_props = __DIR__ . "/event_props";
    21 $C_event_props = __DIR__ . "/event_props";
    19 $C_event_users = array('polemictweet' => 'polemictweet'.date('Y/m/d'));
    22 $C_event_users = array('polemictweet' => 'polemictweet' . date('Y/m/d'));
    20 
    23 
    21 $C_openssl_cipher_iv_length = 16; //openssl_cipher_iv_length('aes256')
    24 $C_openssl_cipher_iv_length = 16; //openssl_cipher_iv_length('aes256')
    22 
    25 
    23 $archives_list = array(
    26 $archives_list = array(
    24     "rsln", "rsln-opendata", "rsln-mercedes-bunz",
    27     "rsln", "rsln-opendata", "rsln-mercedes-bunz",
    25     "enmi2011-technologie-confiance", "CPV", array("fens_FabLab_Design_Metadata","fablab"),
    28     "enmi2011-technologie-confiance", "CPV", array("fens_FabLab_Design_Metadata", "fablab"),
    26 array("fens_FabLab_Design_Metadata","designmd"), array("mashup","conference"), array("mashup","tableronde"),
    29     array("fens_FabLab_Design_Metadata", "designmd"), array("mashup", "conference"), array("mashup", "tableronde"),
    27     "sig-chi-paris-2011", "rwd-meetup-patrimoine", "2011-2012-museo-ouverture"/*, "JaneMcGonigal-gameDesign"*/,
    30     "sig-chi-paris-2011", "rwd-meetup-patrimoine", "2011-2012-museo-ouverture"/*, "JaneMcGonigal-gameDesign"*/,
    28     "iii-catastrophe", "edito-inaugurale", "enmi2011", "2011-2012-museo-structured-data",
    31     "iii-catastrophe", "edito-inaugurale", "enmi2011", "2011-2012-museo-structured-data",
    29     "edito-webdoc","edito-intelligence", "2011-2012-museo-contribution",
    32     "edito-webdoc", "edito-intelligence", "2011-2012-museo-contribution",
    30     "2011-2012-museo-ingenierie", "edito-serious-games", "enmi2012-seminaire-1", "2011-2012-museo-audiovisuel", "edito-reseaux-sociaux",
    33     "2011-2012-museo-ingenierie", "edito-serious-games", "enmi2012-seminaire-1", "2011-2012-museo-audiovisuel", "edito-reseaux-sociaux",
    31     "edito-arts-numeriques",
    34     "edito-arts-numeriques",
    32     'fens2012-gamestudies',
    35     'fens2012-gamestudies',
    33     'fens2012-designmetadata',
    36     'fens2012-designmetadata',
    34     'fens2012-museo-culture-opendata',
    37     'fens2012-museo-culture-opendata',
    47     'mediapartlive-comment-combattre-le-fn',
    50     'mediapartlive-comment-combattre-le-fn',
    48     'attention-1314-01-notion-attention',
    51     'attention-1314-01-notion-attention',
    49     'attention-1314-02-syndrome-saturation-cognitive',
    52     'attention-1314-02-syndrome-saturation-cognitive',
    50     'edito-1314-01-quest-ce-quun-support',
    53     'edito-1314-01-quest-ce-quun-support',
    51     'enmi13', 'museo-1314-03-cognition-apprentissage', 'attention-1314-03-nouvelle-valeur-economique',
    54     'enmi13', 'museo-1314-03-cognition-apprentissage', 'attention-1314-03-nouvelle-valeur-economique',
    52     'edito-1314-02-lannotation-le-savoir-dans-la-marge', 'museo-1314-04-lecture-active' , 'edito-1314-03-traduction', 'attention-1314-04-pathologies-attention-memoire', 'edito-1314-04-environnement-support', 'attention-1314-05-marche-attention-avenement-publicite','museo-1314-05-nouvelles-editions', 'edito-1314-05-algorithme',
    55     'edito-1314-02-lannotation-le-savoir-dans-la-marge', 'museo-1314-04-lecture-active', 'edito-1314-03-traduction', 'attention-1314-04-pathologies-attention-memoire', 'edito-1314-04-environnement-support', 'attention-1314-05-marche-attention-avenement-publicite', 'museo-1314-05-nouvelles-editions', 'edito-1314-05-algorithme',
    53     'fens2014-design-metadata','fens2014-museo','fens2014-transmediamix','fens2014-edito','fens2014-attention',
    56     'fens2014-design-metadata', 'fens2014-museo', 'fens2014-transmediamix', 'fens2014-edito', 'fens2014-attention',
    54     'pour-la-transition-une-conomie-du-partage-de-la-connaissance-et-des-biens-communs','spel-01-gout-archivage', 'edito-1415-01-hybridation-pratiques-recherche',
    57     'pour-la-transition-une-conomie-du-partage-de-la-connaissance-et-des-biens-communs', 'spel-01-gout-archivage', 'edito-1415-01-hybridation-pratiques-recherche',
    55     'museo-1415-01-inaugurale', 'museo-1415-02-controverses', 'attention-1415-01-attention-automatisee',
    58     'museo-1415-01-inaugurale', 'museo-1415-02-controverses', 'attention-1415-01-attention-automatisee',
    56     'museo-1415-03-pedagogies', 'museo-1415-04-reseaux-sociaux-hermeneutiques','edito-1415-02-ressources-documentation-recherche', 'enmi14',
    59     'museo-1415-03-pedagogies', 'museo-1415-04-reseaux-sociaux-hermeneutiques', 'edito-1415-02-ressources-documentation-recherche', 'enmi14',
    57     'attention-1415-02-recherche-algo-attention-hermeneutique', 'edito-1415-04-elargissement-communautes-scientifiques', /*'museo-1415-05-interfaces-design',*/
    60     'attention-1415-02-recherche-algo-attention-hermeneutique', 'edito-1415-04-elargissement-communautes-scientifiques', /*'museo-1415-05-interfaces-design',*/
    58     'museo-1415-06-multilinguisme', 'museo-1415-07-traduction', 'attention-1415-05-reseaux-sociaux-valorisation',
    61     'museo-1415-06-multilinguisme', 'museo-1415-07-traduction', 'attention-1415-05-reseaux-sociaux-valorisation',
    59     'attention-1415-06-game-design', 'edito-1415-05-faire-oeuvre-epoque-numerique', 'museo-1415-08-histoire-critique',
    62     'attention-1415-06-game-design', 'edito-1415-05-faire-oeuvre-epoque-numerique', 'museo-1415-08-histoire-critique',
    60     'attention-1415-07-design-pluralisation', 'edito-1516-01-profil-collectif', 'edito-1516-02-corps-profil', 'enmi15', 'edito-1516-03-editorialisation-universitaire',
    63     'attention-1415-07-design-pluralisation', 'edito-1516-01-profil-collectif', 'edito-1516-02-corps-profil', 'enmi15', 'edito-1516-03-editorialisation-universitaire',
    61     'edito-1516-04-detournements-creation', 'edito-1516-05-production-reel', 'edito-1516-06-confession-confiscation-de-soi',
    64     'edito-1516-04-detournements-creation', 'edito-1516-05-production-reel', 'edito-1516-06-confession-confiscation-de-soi',
    62     'edito-1516-07-architecture-savoir', 'edito-1516-08-desir-profilage', 'edito-1516-09-cloture', 'journee-omnsh-2016-10-patrimoine-numerique', 'enmi16',
    65     'edito-1516-07-architecture-savoir', 'edito-1516-08-desir-profilage', 'edito-1516-09-cloture', 'journee-omnsh-2016-10-patrimoine-numerique', 'enmi16',
    63     'cnsad-ateliers-2017', 'crypto-party-camp-rouxteur-10-2017', 'cnsad-seminaire-telepresence-11-2017', 'enmi17', /*'enmi18-preparatoire',*/'marathon-serpentine-2018', 'enmi18', 'enmi19-preparatoire', 'enmi19',
    66     'cnsad-ateliers-2017', 'crypto-party-camp-rouxteur-10-2017', 'cnsad-seminaire-telepresence-11-2017', 'enmi17', /*'enmi18-preparatoire',*/ 'marathon-serpentine-2018', 'enmi18', 'enmi19-preparatoire', 'enmi19',
    64     'enmi20', 'enmi21',
    67     'enmi20', 'enmi21',
    65 );
    68 );
    66 
    69 
    67 
       
    68 $req_rep = $C_default_rep;
    70 $req_rep = $C_default_rep;
    69 if(isset($config) && isset($config['rep'])) {
    71 if (isset($config) && isset($config['rep'])) {
    70     $req_rep = $config['rep'];
    72     $req_rep = $config['rep'];
    71 }
    73 }
    72 
    74 
    73 foreach (glob(dirname(__FILE__).'/traductions/*.php') as $trad_filename)
    75 foreach (glob(dirname(__FILE__) . '/traductions/*.php') as $trad_filename) {
    74 {
       
    75     include_once $trad_filename;
    76     include_once $trad_filename;
    76 }
    77 }
    77 if(file_exists(dirname(__FILE__)."/$req_rep/traduction.php")) {
    78 if (file_exists(dirname(__FILE__) . "/$req_rep/traduction.php")) {
    78     include_once dirname(__FILE__)."/$req_rep/traduction.php";
    79     include_once dirname(__FILE__) . "/$req_rep/traduction.php";
    79 }
    80 }
    80 
    81 
    81 $appCacheHandle = new SQLite3(dirname(__FILE__)."/data/app_cache.db");
    82 $appCacheHandle = new SQLite3(dirname(__FILE__) . "/data/app_cache.db");
    82 $appCacheHandle->query("CREATE TABLE IF NOT EXISTS apps (id INTEGER PRIMARY KEY, domain TEXT UNIQUE NOT NULL, app_key TEXT UNIQUE NOT NULL, app_secret TEXT NOT NULL)");
    83 $appCacheHandle->query("CREATE TABLE IF NOT EXISTS apps (id INTEGER PRIMARY KEY, domain TEXT NOT NULL, event TEXT NOT NULL, client_id TEXT UNIQUE NOT NULL, client_secret TEXT NOT NULL, UNIQUE(domain, event))");
       
    84 
    83 
    85 
    84 
    86 
    85 
    87 
    86 /**
    88 /**
    87  * Start up the ol' session engine
    89  * Start up the ol' session engine
    89 session_start();
    91 session_start();
    90 
    92 
    91 /**
    93 /**
    92  * Include the configuration data for our OAuth Client (array $configuration)
    94  * Include the configuration data for our OAuth Client (array $configuration)
    93  */
    95  */
    94 include_once dirname(__FILE__).'/config.php';
    96 include_once dirname(__FILE__) . '/config.php';
    95 
    97 
    96 
    98 function get_cached_app_ids($login_domain, $req_rep, $appCacheHandle) {
    97 $get_social_request_token = function ($loginDomain, $config) use ($req_rep, $appCacheHandle) {
    99 
       
   100     $statement = $appCacheHandle->prepare('SELECT * FROM apps WHERE domain = :domain and event = :event;');
       
   101     $statement->bindValue(':domain', $login_domain);
       
   102     $statement->bindValue(':event', $req_rep);
       
   103 
       
   104     $result = $statement->execute();
       
   105     $client_id = false;
       
   106     $client_secret = false;
       
   107     if ($row = $result->fetchArray()) {
       
   108         $client_id = $row["client_id"];
       
   109         $client_secret = $row["client_secret"];
       
   110     }
       
   111 
       
   112     return [ "client_id" => $client_id, "client_secret" => $client_secret];
       
   113 }
       
   114 
       
   115 $get_social_request_token = function ($login_domain, $config) use ($req_rep, $appCacheHandle) {
    98 
   116 
    99     $socialNetwork = $config['social_network'];
   117     $socialNetwork = $config['social_network'];
   100 
   118 
   101     if($socialNetwork == "Twitter") {
   119     if ($socialNetwork == "Twitter") {
   102 
   120 
   103         $twitterClient = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
   121         $twitterClient = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
   104         $token = $twitterClient->oauth('oauth/request_token', array('oauth_callback' => URL_ROOT."callback.php?rep=$req_rep"));
   122         $token = $twitterClient->oauth('oauth/request_token', array('oauth_callback' => URL_ROOT . "callback.php?rep=$req_rep"));
   105 
   123 
   106         $_SESSION['TWITTER_REQUEST_TOKEN'] = serialize($token);
   124         $_SESSION['TWITTER_REQUEST_TOKEN'] = serialize($token);
   107 
   125 
   108         /**
   126         /**
   109         * Now redirect user to Twitter site so they can log in and
   127          * Now redirect user to Twitter site so they can log in and
   110         * approve our access
   128          * approve our access
   111         */
   129          */
   112 
   130 
   113         $url = $twitterClient->url('oauth/authorize', array('oauth_token' => $token['oauth_token']));
   131         $url = $twitterClient->url('oauth/authorize', array('oauth_token' => $token['oauth_token']));
   114         header("Location: ".$url);
   132     } else if ($socialNetwork == "Mastodon") {
   115         die();
   133 
   116     } else if($socialNetwork == "Mastodon") {
   134         $_SESSION['SOCIAL_LOGIN_DOMAIN'] = $login_domain;
   117         $mastodonApi = new Api($loginDomain);
   135 
   118 
   136         $base_uri = "https://$login_domain";
   119         $cachedApp = $appCacheHandle->querySingle("");
   137         $client = new Client([
   120         $statement = $cachedApp->prepare('SELECT * FROM apps WHERE domain = :domain;');
   138             'base_uri' => $base_uri,
   121         $statement->bindValue(':domain', $loginDomain);
   139             'timeout'  => 2.0,
   122 
   140         ]);
   123 $result = $statement->execute();
   141 
       
   142         $client_ids = get_cached_app_ids($login_domain, $req_rep, $appCacheHandle);
       
   143         $client_id = $client_ids["client_id"];
       
   144         $client_secret = $client_ids["client_secret"];
       
   145 
       
   146         if(!$client_id || !$client_secret) {
   124             // Create app
   147             // Create app
   125         $appsDef = $mastodonApi->apps()->create("PolemicToot", URL_ROOT."callback.php?rep=$req_rep", 'read write push');
   148             $resp = $client->post('/api/v1/apps', ['form_params' => [
   126         var_dump($appsDef);
   149                 "client_name" => "PolemicToot-$req_rep",
   127         //$mastodonApi->logIn();
   150                 "redirect_uris" => URL_ROOT . "callback.php?rep=$req_rep",
   128     }
   151                 "scopes" => 'read write push'
       
   152             ]]);
       
   153             $appsDef = json_decode($resp->getBody());
       
   154             //var_dump($appsDef);
       
   155             $client_id = $appsDef->client_id;
       
   156             $client_secret = $appsDef->client_secret;
       
   157             $appCacheHandle->exec("INSERT INTO apps (domain, event, client_id, client_secret) VALUES ('$login_domain', '$req_rep', '$client_id', '$client_secret')");
       
   158         }
       
   159 
       
   160         $state = bin2hex(random_bytes(12));
       
   161 
       
   162         $_SESSION['SOCIAL_AUTH_STATE'] = $state;
       
   163 
       
   164         $uri = URI::withQueryValues(URI::fromParts([
       
   165             'scheme' => 'https',
       
   166             'host' => $login_domain,
       
   167             'path' => '/oauth/authorize'
       
   168         ]), [
       
   169             "response_type" => "code",
       
   170             "client_id" => "$client_id",
       
   171             "redirect_uri" => URL_ROOT . "callback.php?rep=$req_rep",
       
   172             "scope" => 'read write push',
       
   173             "state" => $state
       
   174         ]);
       
   175 
       
   176         $url = (string)$uri;
       
   177     }
       
   178     header("Location: " . $url);
       
   179     die();
   129 };
   180 };
       
   181 
       
   182 function setGroupMastodon($config, $default_domain) {
       
   183     if(strtolower(($config['social_network'] ?? 'Twitter')) === "twitter" ) {
       
   184         return $config;
       
   185     }
       
   186     $group = '@'. ltrim($config['group'] ?? $config['hashtag'], '@');
       
   187 
       
   188     if(!preg_match("/.+@.+$/", $group)) {
       
   189         $group = $group . "@" . $default_domain;
       
   190     }
       
   191 
       
   192     $res = $config;
       
   193     $res['group'] = $group;
       
   194 
       
   195     return $res;
       
   196 }
       
   197 
       
   198 
   130 
   199 
   131 /**
   200 /**
   132  * TRADUCTION
   201  * TRADUCTION
   133 **/
   202  **/
   134 function get_config_translations($config) {
   203 function get_config_translations($config)
       
   204 {
   135 
   205 
   136     $fr = array();
   206     $fr = array();
   137     $en = array();
   207     $en = array();
   138     $jp = array();
   208     $jp = array();
   139 
   209 
   140     $array_loop = array("fr"=>&$fr,"en"=>&$en,"jp"=>&$jp);
   210     $array_loop = array("fr" => &$fr, "en" => &$en, "jp" => &$jp);
   141     /**
   211     /**
   142      * add all config key as translation.
   212      * add all config key as translation.
   143      * translation key is "config__<config_key>"
   213      * translation key is "config__<config_key>"
   144      */
   214      */
   145     foreach ($config as $key => $value) {
   215     foreach ($config as $key => $value) {
   146         $translation_key = "config__$key";
   216         $translation_key = "config__$key";
   147 
   217 
   148         foreach ($array_loop as $lang => &$lang_array) {
   218         foreach ($array_loop as $lang => &$lang_array) {
   149             if(is_array($value) && count(array_intersect_key($value,$array_loop)) > 0 ) {
   219             if (is_array($value) && count(array_intersect_key($value, $array_loop)) > 0) {
   150                 if (array_key_exists($lang, $value)) {
   220                 if (array_key_exists($lang, $value)) {
   151                     $lang_array[$translation_key] = $value[$lang];
   221                     $lang_array[$translation_key] = $value[$lang];
   152                 }
   222                 } elseif (array_key_exists('fr', $value)) {
   153                 elseif (array_key_exists('fr', $value)) {
       
   154                     $lang_array[$translation_key] = $value['fr'];
   223                     $lang_array[$translation_key] = $value['fr'];
   155                 }
   224                 }
   156             }
   225             } else {
   157             else {
       
   158                 $lang_array[$translation_key] = $value;
   226                 $lang_array[$translation_key] = $value;
   159             }
   227             }
   160         }
   228         }
   161     }
   229     }
   162 
   230 
   163     return $array_loop;
   231     return $array_loop;
   164 
   232 }
   165 }
   233 
   166 
   234 function set_config_translations(&$config, &$translate)
   167 function set_config_translations(&$config, &$translate) {
   235 {
   168 
   236 
   169     $config_translations = get_config_translations($config);
   237     $config_translations = get_config_translations($config);
   170 
   238 
   171     // save the locale because it gets changed when adding translations
   239     // save the locale because it gets changed when adding translations
   172     $locale = $translate->getLocale();
   240     $locale = $translate->getLocale();
   187 
   255 
   188 $translate->addTranslation($traduction_en, 'en');
   256 $translate->addTranslation($traduction_en, 'en');
   189 $translate->addTranslation($traduction_ja, 'ja_JP');
   257 $translate->addTranslation($traduction_ja, 'ja_JP');
   190 $translate->addTranslation($traduction_fr, 'fr');
   258 $translate->addTranslation($traduction_fr, 'fr');
   191 
   259 
   192 if(isset($config)) {
   260 if (isset($config)) {
   193     set_config_translations($config, $translate);
   261     set_config_translations($config, $translate);
       
   262     $config = setGroupMastodon($config, $MASTODON_DEFAULT_GROUP_DOMAIN);
   194 }
   263 }
   195 
   264 
   196 $actual = $translate->getLocale();
   265 $actual = $translate->getLocale();
   197 
   266 
   198 
   267 
   199 if(isset($_GET['lang'])==false and isset($_SESSION['lang'])==false){
   268 if (isset($_GET['lang']) == false and isset($_SESSION['lang']) == false) {
   200 
   269 
   201     if($actual!='fr' and $actual!='en' and $actual!='ja_JP'){
   270     if ($actual != 'fr' and $actual != 'en' and $actual != 'ja_JP') {
   202         $translate->setLocale("fr");
   271         $translate->setLocale("fr");
   203          $_SESSION['lang']="fr";
   272         $_SESSION['lang'] = "fr";
   204     }
   273     }
   205 
   274 } else if (isset($_GET['lang']) == true) {
   206 } else if (isset($_GET['lang'])==true){
       
   207     $translate->setLocale($_GET['lang']);
   275     $translate->setLocale($_GET['lang']);
   208     $_SESSION['lang'] = $_GET['lang'];
   276     $_SESSION['lang'] = $_GET['lang'];
   209     $actual = $_SESSION['lang'];
   277     $actual = $_SESSION['lang'];
   210 
   278 } else if (isset($_SESSION['lang']) == true) {
   211 } else if (isset($_SESSION['lang'])==true){
   279     $translate->setLocale($_SESSION['lang']);
   212     $translate->setLocale( $_SESSION['lang']);
       
   213     $actual = $_SESSION['lang'];
   280     $actual = $_SESSION['lang'];
   214 
       
   215 }
   281 }
   216 
   282 
   217 $js_registry = array(
   283 $js_registry = array(
   218     'local' => array(
   284     'local' => array(
   219         'libdir'        => URL_ROOT.'res/js/',
   285         'libdir'        => URL_ROOT . 'res/js/',
   220         'jquery' 		=> URL_ROOT.'res/js/jquery-1.10.2.min.js',
   286         'jquery'         => URL_ROOT . 'res/js/jquery.min.js',
   221         'raphael' 		=> URL_ROOT.'res/js/raphael-min.js',
   287         'raphael'         => URL_ROOT . 'res/js/raphael-min.js',
   222         'jquery-ui' 	=> URL_ROOT.'res/js/jquery-ui.min.js',
   288         'jquery-ui'     => URL_ROOT . 'res/js/jquery-ui.min.js',
   223         'niceforms' 	=> URL_ROOT.'res/js/niceforms.js',
   289         'niceforms'     => URL_ROOT . 'res/js/niceforms.js',
   224         'jquery-url' 	=> URL_ROOT.'res/js/jquery.url.js',
   290         'jquery-url'     => URL_ROOT . 'res/js/jquery.url.js',
   225         'ldtplayer' 	=> URL_ROOT.'res/metadataplayer/src/js/LdtPlayer.js',
   291         'ldtplayer'     => URL_ROOT . 'res/metadataplayer/src/js/LdtPlayer.js',
   226         'fancybox' 		=> URL_ROOT.'res/js/fancybox/jquery.fancybox.pack.js',
   292         'fancybox'         => URL_ROOT . 'res/js/fancybox/jquery.fancybox.pack.js',
   227         'jquery-tools' 	=> URL_ROOT.'res/js/jquery.tools.min.js',
   293         'jquery-tools'     => URL_ROOT . 'res/js/jquery.tools.min.js',
   228         'jquery-migrate' => URL_ROOT.'res/js/jquery-migrate-1.4.1.min.js',
   294         'jquery-migrate' => URL_ROOT . 'res/js/jquery-migrate-1.4.1.min.js',
   229         'tw-widget' 	=> URL_ROOT.'res/js/tw_widget.js',
   295         'tw-widget'     => URL_ROOT . 'res/js/tw_widget.js',
   230         'jquery-mousewheel' => URL_ROOT.'res/js/jquery.mousewheel.js',
   296         'jquery-mousewheel' => URL_ROOT . 'res/js/jquery.mousewheel.js',
   231         'swfobject' 	=> URL_ROOT.'res/js/swfobject.js',
   297         'swfobject'     => URL_ROOT . 'res/js/swfobject.js',
   232         'json-js' 		=> URL_ROOT.'res/js/json2.js',
   298         'json-js'         => URL_ROOT . 'res/js/json2.js',
   233         'underscore'    => URL_ROOT.'res/js/underscore-min.js' ,
   299         'underscore'    => URL_ROOT . 'res/js/underscore-min.js',
   234         'jquery-scrollto'=>URL_ROOT.'res/js/jquery.scrollTo-2.1.2-min.js' ,
   300         'jquery-scrollto' => URL_ROOT . 'res/js/jquery.scrollTo-2.1.2-min.js',
   235         'twcx-main'     => URL_ROOT.'res/js/live-polemic.js' ,
   301         'twcx-main'     => URL_ROOT . 'res/js/live-polemic.js',
   236         'semanticboard' => URL_ROOT.'res/js/semanticboard.js' ,
   302         'semanticboard' => URL_ROOT . 'res/js/semanticboard.js',
   237         'metadataplayer'=> URL_ROOT.'res/metadataplayer/LdtPlayer-core.js' ,
   303         'metadataplayer' => URL_ROOT . 'res/metadataplayer/LdtPlayer-core.js',
   238         'ldtwidgets'    => URL_ROOT.'res/metadataplayer/' ,
   304         'ldtwidgets'    => URL_ROOT . 'res/metadataplayer/',
   239         'tracemanager'  => URL_ROOT.'res/js/tracemanager.js' ,
   305         'tracemanager'  => URL_ROOT . 'res/js/tracemanager.js',
   240         'jwplayer-js'   => URL_ROOT.'res/js/jwplayer.js',
   306         'jwplayer-js'   => URL_ROOT . 'res/js/jwplayer.js',
   241         'jquery-tinymce' => URL_ROOT.'res/js/tinymce/jquery.tinymce.min.js',
   307         'jquery-tinymce' => URL_ROOT . 'res/js/tinymce/jquery.tinymce.min.js',
   242         'tinymce'        => URL_ROOT.'res/js/tinymce/tinymce.min.js',
   308         'tinymce'        => URL_ROOT . 'res/js/tinymce/tinymce.min.js',
   243         'dashjs'         => URL_ROOT.'res/js/dashjs/dash.min.js',
   309         'dashjs'         => URL_ROOT . 'res/js/dashjs/dash.min.js',
   244         'videojs-dash'   => URL_ROOT.'res/js/dashjs/videojs-dash.min.js',
   310         'videojs-dash'   => URL_ROOT . 'res/js/dashjs/videojs-dash.min.js',
   245         'videojs'        => URL_ROOT.'res/js/videojs/video.min.js',
   311         'videojs'        => URL_ROOT . 'res/js/videojs/video.min.js',
   246         'twitter-text'   => URL_ROOT.'res/js/twitter-text-3.0.1.min.js',
   312         'twitter-text'   => URL_ROOT . 'res/js/twitter-text-3.0.1.min.js',
   247     ),
   313     ),
   248     'cdn' => array(
   314     'cdn' => array(
   249         'libdir'        => URL_ROOT.'res/js/',
   315         'libdir'        => URL_ROOT . 'res/js/',
   250         'jquery' 		=> 'http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js',
   316         'jquery'         => 'http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js',
   251         'raphael' 		=> URL_ROOT.'res/js/raphael-min.js',
   317         'raphael'         => URL_ROOT . 'res/js/raphael-min.js',
   252         'jquery-ui' 	=> 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js',
   318         'jquery-ui'     => 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js',
   253         'niceforms' 	=> URL_ROOT.'res/js/niceforms.js',
   319         'niceforms'     => URL_ROOT . 'res/js/niceforms.js',
   254         'jquery-url' 	=> URL_ROOT.'res/js/jquery.url.js',
   320         'jquery-url'     => URL_ROOT . 'res/js/jquery.url.js',
   255         'ldtplayer' 	=> URL_ROOT.'res/metadataplayer/src/js/LdtPlayer.js',
   321         'ldtplayer'     => URL_ROOT . 'res/metadataplayer/src/js/LdtPlayer.js',
   256         'fancybox' 		=> URL_ROOT.'res/js/fancybox/jquery.fancybox.pack.js',
   322         'fancybox'         => URL_ROOT . 'res/js/fancybox/jquery.fancybox.pack.js',
   257         'jquery-tools' 	=> 'http://cdn.jquerytools.org/1.2.7/all/jquery.tools.min.js',
   323         'jquery-tools'     => 'http://cdn.jquerytools.org/1.2.7/all/jquery.tools.min.js',
   258         'jquery-migrate' => 'http://code.jquery.com/jquery-migrate-1.4.1.min.js',
   324         'jquery-migrate' => 'http://code.jquery.com/jquery-migrate-1.4.1.min.js',
   259         'tw-widget' 	=> 'http://widgets.twimg.com/j/2/widget.js',
   325         'tw-widget'     => 'http://widgets.twimg.com/j/2/widget.js',
   260         'jquery-mousewheel' => URL_ROOT.'res/js/jquery.mousewheel.js',
   326         'jquery-mousewheel' => URL_ROOT . 'res/js/jquery.mousewheel.js',
   261         'swfobject' 	=> 'http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js',
   327         'swfobject'     => 'http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js',
   262         'json-js'       => URL_ROOT.'res/js/json2.js',
   328         'json-js'       => URL_ROOT . 'res/js/json2.js',
   263         'underscore'    => URL_ROOT.'res/js/underscore-min.js' ,
   329         'underscore'    => URL_ROOT . 'res/js/underscore-min.js',
   264         'jquery-scrollto'=>URL_ROOT.'res/js/jquery.scrollTo-2.1.2-min.js' ,
   330         'jquery-scrollto' => URL_ROOT . 'res/js/jquery.scrollTo-2.1.2-min.js',
   265         'twcx-main'     => URL_ROOT.'res/js/live-polemic.js' ,
   331         'twcx-main'     => URL_ROOT . 'res/js/live-polemic.js',
   266         'semanticboard' => URL_ROOT.'res/js/semanticboard.js' ,
   332         'semanticboard' => URL_ROOT . 'res/js/semanticboard.js',
   267         'metadataplayer'=> URL_ROOT.'res/metadataplayer/LdtPlayer-core.js' ,
   333         'metadataplayer' => URL_ROOT . 'res/metadataplayer/LdtPlayer-core.js',
   268         'ldtwidgets'    => URL_ROOT.'res/metadataplayer/' ,
   334         'ldtwidgets'    => URL_ROOT . 'res/metadataplayer/',
   269         'tracemanager'  => URL_ROOT.'res/js/tracemanager.js' ,
   335         'tracemanager'  => URL_ROOT . 'res/js/tracemanager.js',
   270         'jwplayer-js'   => URL_ROOT.'res/js/jwplayer.js',
   336         'jwplayer-js'   => URL_ROOT . 'res/js/jwplayer.js',
   271         'jquery-tinymce' => URL_ROOT.'res/js/tinymce/jquery.tinymce.min.js',
   337         'jquery-tinymce' => URL_ROOT . 'res/js/tinymce/jquery.tinymce.min.js',
   272         'tinymce'        => URL_ROOT.'res/js/tinymce/tinymce.min.js',
   338         'tinymce'        => URL_ROOT . 'res/js/tinymce/tinymce.min.js',
   273         'dashjs'         => "http://cdn.dashjs.org/latest/dash.all.min.js",
   339         'dashjs'         => "http://cdn.dashjs.org/latest/dash.all.min.js",
   274         'videojs-dash'   => 'https://cdnjs.cloudflare.com/ajax/libs/videojs-contrib-dash/2.5.2/videojs-dash.min.js',
   340         'videojs-dash'   => 'https://cdnjs.cloudflare.com/ajax/libs/videojs-contrib-dash/2.5.2/videojs-dash.min.js',
   275         'videojs'        => 'http://vjs.zencdn.net/5.12.6/video.js',
   341         'videojs'        => 'http://vjs.zencdn.net/5.12.6/video.js',
   276         'twitter-text'   => URL_ROOT.'res/js/twitter-text-3.0.1.min.js',
   342         'twitter-text'   => URL_ROOT . 'res/js/twitter-text-3.0.1.min.js',
   277     )
   343     )
   278 );
   344 );
   279 
   345 
   280 $font_registry = array(
   346 $font_registry = array(
   281     'local' => array(
   347     'local' => array(
   282         'PT-Sans_Narrow' => URL_ROOT.'res/fonts/PTSansNarrow.css',
   348         'PT-Sans_Narrow' => URL_ROOT . 'res/fonts/PTSansNarrow.css',
   283         'PT-Sans' 		 => URL_ROOT.'res/fonts/PTSans.css'
   349         'PT-Sans'          => URL_ROOT . 'res/fonts/PTSans.css'
   284     ),
   350     ),
   285     'cdn' => array(
   351     'cdn' => array(
   286         'PT-Sans_Narrow' => 'http://fonts.googleapis.com/css?family=PT+Sans+Narrow&subset=latin',
   352         'PT-Sans_Narrow' => 'http://fonts.googleapis.com/css?family=PT+Sans+Narrow&subset=latin',
   287         'PT-Sans' 		 => 'http://fonts.googleapis.com/css?family=PT+Sans&subset=latin'
   353         'PT-Sans'          => 'http://fonts.googleapis.com/css?family=PT+Sans&subset=latin'
   288     )
   354     )
   289 );
   355 );
   290 
   356 
   291 
   357 
   292 $css_registry = array(
   358 $css_registry = array(
   293     'local' => array(
   359     'local' => array(
   294        	'blueprint-screen' => URL_ROOT.'res/css/blueprint-screen.css',
   360         'blueprint-screen' => URL_ROOT . 'res/css/blueprint-screen.css',
   295         'blueprint-print' => URL_ROOT.'res/css/blueprint-print.css',
   361         'blueprint-print' => URL_ROOT . 'res/css/blueprint-print.css',
   296         'blueprint-ie' => URL_ROOT.'res/css/blueprint-ie.css',
   362         'blueprint-ie' => URL_ROOT . 'res/css/blueprint-ie.css',
   297         'blueprint-plugins-fancy-type' => URL_ROOT.'res/css/blueprint-plugins/fancy-type/screen.css',
   363         'blueprint-plugins-fancy-type' => URL_ROOT . 'res/css/blueprint-plugins/fancy-type/screen.css',
   298         'custom' => URL_ROOT.'res/css/custom.css',
   364         'custom' => URL_ROOT . 'res/css/custom.css',
   299         'fancybox' => URL_ROOT.'res/js/fancybox/jquery.fancybox.css',
   365         'fancybox' => URL_ROOT . 'res/js/fancybox/jquery.fancybox.css',
   300         'jquery-ui' => URL_ROOT.'res/metadataplayer/res/css/jq-css/themes/base/jquery-ui.css',
   366         'jquery-ui' => URL_ROOT . 'res/metadataplayer/res/css/jq-css/themes/base/jquery-ui.css',
   301         'tabs-slideshow' => URL_ROOT.'res/css/tabs-slideshow.css',
   367         'tabs-slideshow' => URL_ROOT . 'res/css/tabs-slideshow.css',
   302         'tweetcast' => URL_ROOT.'res/css/tweetcast.css',
   368         'tweetcast' => URL_ROOT . 'res/css/tweetcast.css',
   303         'semanticboard' =>  URL_ROOT.'res/css/semanticboard.css',
   369         'semanticboard' =>  URL_ROOT . 'res/css/semanticboard.css',
   304         'archives-iframe' => URL_ROOT.'res/css/archives-iframe.css',
   370         'archives-iframe' => URL_ROOT . 'res/css/archives-iframe.css',
   305         'metadataplayer' => URL_ROOT.'res/metadataplayer/LdtPlayer-core.css',
   371         'metadataplayer' => URL_ROOT . 'res/metadataplayer/LdtPlayer-core.css',
   306         'jquery-te' => URL_ROOT.'res/css/jquery-te.css',
   372         'jquery-te' => URL_ROOT . 'res/css/jquery-te.css',
   307         'videojs' => URL_ROOT.'res/js/videojs/video-js.min.css',
   373         'videojs' => URL_ROOT . 'res/js/videojs/video-js.min.css',
       
   374         'ldtplayer'     => URL_ROOT . 'res/metadataplayer/src/js/LdtPlayer.css',
   308     ),
   375     ),
   309     'cdn' => array(
   376     'cdn' => array(
   310         'blueprint-screen' => URL_ROOT.'res/css/blueprint-screen.css',
   377         'blueprint-screen' => URL_ROOT . 'res/css/blueprint-screen.css',
   311         'blueprint-print' => URL_ROOT.'res/css/blueprint-print.css',
   378         'blueprint-print' => URL_ROOT . 'res/css/blueprint-print.css',
   312         'blueprint-ie' => URL_ROOT.'res/css/blueprint-ie.css',
   379         'blueprint-ie' => URL_ROOT . 'res/css/blueprint-ie.css',
   313         'blueprint-plugins-fancy-type' => URL_ROOT.'res/css/blueprint-plugins/fancy-type/screen.css',
   380         'blueprint-plugins-fancy-type' => URL_ROOT . 'res/css/blueprint-plugins/fancy-type/screen.css',
   314         'custom' => URL_ROOT.'res/css/custom.css',
   381         'custom' => URL_ROOT . 'res/css/custom.css',
   315         'fancybox' => URL_ROOT.'res/js/fancybox/jquery.fancybox.css',
   382         'fancybox' => URL_ROOT . 'res/js/fancybox/jquery.fancybox.css',
   316         'jquery-ui' => "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/themes/base/jquery-ui.css",
   383         'jquery-ui' => "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/themes/base/jquery-ui.css",
   317         'tabs-slideshow' => URL_ROOT.'res/css/tabs-slideshow.css',
   384         'tabs-slideshow' => URL_ROOT . 'res/css/tabs-slideshow.css',
   318         'tweetcast' => URL_ROOT.'res/css/tweetcast.css',
   385         'tweetcast' => URL_ROOT . 'res/css/tweetcast.css',
   319         'semanticboard' =>  URL_ROOT.'res/css/semanticboard.css',
   386         'semanticboard' =>  URL_ROOT . 'res/css/semanticboard.css',
   320         'archives-iframe' => URL_ROOT.'res/css/archives-iframe.css',
   387         'archives-iframe' => URL_ROOT . 'res/css/archives-iframe.css',
   321         'metadataplayer' => URL_ROOT.'res/metadataplayer/LdtPlayer-core.css',
   388         'metadataplayer' => URL_ROOT . 'res/metadataplayer/LdtPlayer-core.css',
   322         'jquery-te' => URL_ROOT.'res/css/jquery-te.css',
   389         'jquery-te' => URL_ROOT . 'res/css/jquery-te.css',
   323         'videojs' => "http://vjs.zencdn.net/5.12.6/video-js.css"
   390         'videojs' => "http://vjs.zencdn.net/5.12.6/video-js.css"
   324     )
   391     )
   325 );
   392 );
   326 
   393 
   327 
   394 
   328 function registry_url($key, $type, $registry_def=null) {
   395 function registry_url($key, $type, $registry_def = null)
       
   396 {
   329 
   397 
   330     global $js_registry, $font_registry, $css_registry, $C_default_registry;
   398     global $js_registry, $font_registry, $css_registry, $C_default_registry;
   331 
   399 
   332     if($registry_def != null) {
   400     if ($registry_def != null) {
   333         $registry = $registry_def;
   401         $registry = $registry_def;
   334     }
   402     } elseif (isset($C_default_registry)) {
   335     elseif(isset($C_default_registry)) {
       
   336         $registry = $C_default_registry;
   403         $registry = $C_default_registry;
   337     }
   404     } else {
   338     else {
       
   339         $registry = 'local';
   405         $registry = 'local';
   340     }
   406     }
   341     $registry_name = $type."_registry";
   407     $registry_name = $type . "_registry";
   342     return ${
   408     return ${$registry_name}[$registry][$key];
   343         $registry_name}[$registry][$key];
   409 }
   344 
   410 
   345 }
   411 function get_default_annotations_config($config, $translate)
   346 
   412 {
   347 function get_default_annotations_config($config, $translate) {
       
   348 
   413 
   349     $default_protocol_annotations = array(
   414     $default_protocol_annotations = array(
   350         "1" => array(
   415         "1" => array(
   351             "default" => array(
   416             "default" => array(
   352                 "colors" => array(
   417                 "colors" => array(
   385                     "h" => .16,
   450                     "h" => .16,
   386                     "s" => .8
   451                     "s" => .8
   387                 ),
   452                 ),
   388                 "colors_class" => "twbYellow",
   453                 "colors_class" => "twbYellow",
   389                 "polemic_cat" => 'REF',
   454                 "polemic_cat" => 'REF',
   390                 "polemic_keywords" => array("==","http://"),
   455                 "polemic_keywords" => array("==", "http://"),
   391                 "polemic_color" => "#C5A62D"
   456                 "polemic_color" => "#C5A62D"
   392             ),
   457             ),
   393             "question" => array(
   458             "question" => array(
   394                 "display_name" => "?? | Question",
   459                 "display_name" => "?? | Question",
   395                 "keywords" => "\\?\\?",
   460                 "keywords" => "\\?\\?",
   397                     "h" => .6,
   462                     "h" => .6,
   398                     "s" => .8
   463                     "s" => .8
   399                 ),
   464                 ),
   400                 "colors_class" => "twbBlue",
   465                 "colors_class" => "twbBlue",
   401                 "polemic_cat" => 'Q',
   466                 "polemic_cat" => 'Q',
   402                 "polemic_keywords" => array("?","??"),
   467                 "polemic_keywords" => array("?", "??"),
   403                 "polemic_color" => "#036AAE"
   468                 "polemic_color" => "#036AAE"
   404             )
   469             )
   405         ),
   470         ),
   406         "2" => array(
   471         "2" => array(
   407             "default" => array(
   472             "default" => array(
   441                     "h" => .16,
   506                     "h" => .16,
   442                     "s" => .8
   507                     "s" => .8
   443                 ),
   508                 ),
   444                 "colors_class" => "twbYellow",
   509                 "colors_class" => "twbYellow",
   445                 "polemic_cat" => 'REF',
   510                 "polemic_cat" => 'REF',
   446                 "polemic_keywords" => array("==","http://"),
   511                 "polemic_keywords" => array("==", "http://"),
   447                 "polemic_color" => "#C5A62D"
   512                 "polemic_color" => "#C5A62D"
   448             ),
   513             ),
   449             "question" => array(
   514             "question" => array(
   450                 "display_name" => "?? | Question",
   515                 "display_name" => "?? | Question",
   451                 "keywords" => "\\?\\?",
   516                 "keywords" => "\\?\\?",
   453                     "h" => .6,
   518                     "h" => .6,
   454                     "s" => .8
   519                     "s" => .8
   455                 ),
   520                 ),
   456                 "colors_class" => "twbBlue",
   521                 "colors_class" => "twbBlue",
   457                 "polemic_cat" => 'Q',
   522                 "polemic_cat" => 'Q',
   458                 "polemic_keywords" => array("?","??"),
   523                 "polemic_keywords" => array("?", "??"),
   459                 "polemic_color" => "#036AAE"
   524                 "polemic_color" => "#036AAE"
   460             )
   525             )
   461         ),
   526         ),
   462         "3" => array(
   527         "3" => array(
   463             "default" => array(
   528             "default" => array(
   476                 "polemic_cat" => 'OK',
   541                 "polemic_cat" => 'OK',
   477                 "polemic_keywords" => array("++"),
   542                 "polemic_keywords" => array("++"),
   478                 "polemic_color" => "#196be6"
   543                 "polemic_color" => "#196be6"
   479             ),
   544             ),
   480             "trouble" => array( // orange
   545             "trouble" => array( // orange
   481                 "display_name" => "?? | Trouble", 
   546                 "display_name" => "?? | Trouble",
   482                 "keywords" => "\\?\\?",
   547                 "keywords" => "\\?\\?",
   483                 "colors" => array(
   548                 "colors" => array(
   484                     "h" => .13,
   549                     "h" => .13,
   485                     "s" => .8
   550                     "s" => .8
   486                 ),
   551                 ),
   494                 "colors" => array(
   559                 "colors" => array(
   495                     "h" => .83,
   560                     "h" => .83,
   496                     "s" => .8
   561                     "s" => .8
   497                 ),
   562                 ),
   498                 "polemic_cat" => 'REF',
   563                 "polemic_cat" => 'REF',
   499                 "polemic_keywords" => array("**","http://"),
   564                 "polemic_keywords" => array("**", "http://"),
   500                 "polemic_color" => "#e619e6"
   565                 "polemic_color" => "#e619e6"
   501             ),
   566             ),
   502             "comments" => array( // green
   567             "comments" => array( // green
   503                 "display_name" => "== | Comment",
   568                 "display_name" => "== | Comment",
   504                 "keywords" => "\\=\\=",
   569                 "keywords" => "\\=\\=",
   511                 "polemic_color" => "#42e619"
   576                 "polemic_color" => "#42e619"
   512             )
   577             )
   513         )
   578         )
   514     );
   579     );
   515 
   580 
   516     $annotation_protocol_version = isset($config['annotation_protocol_version'])?$config['annotation_protocol_version']:"1";
   581     $annotation_protocol_version = isset($config['annotation_protocol_version']) ? $config['annotation_protocol_version'] : "1";
   517 
   582 
   518     $annotations_def = (isset($config['annotations']) && !empty($config['annotations']))?$config['annotations']:$default_protocol_annotations[$annotation_protocol_version];
   583     $annotations_def = (isset($config['annotations']) && !empty($config['annotations'])) ? $config['annotations'] : $default_protocol_annotations[$annotation_protocol_version];
   519 
   584 
   520     $annotations = array();
   585     $annotations = array();
   521 
   586 
   522     foreach ($annotations_def as $annot_cat => $annot_def) {
   587     foreach ($annotations_def as $annot_cat => $annot_def) {
   523         if(isset($annot_def['display_name'])) {
   588         if (isset($annot_def['display_name'])) {
   524             $disp_parts = array_map('trim',explode("|",$annot_def['display_name']));
   589             $disp_parts = array_map('trim', explode("|", $annot_def['display_name']));
   525             if(count($disp_parts) > 1) {
   590             if (count($disp_parts) > 1) {
   526                 $disp_parts[1] = $translate->_($disp_parts[1]);
   591                 $disp_parts[1] = $translate->_($disp_parts[1]);
   527             }
   592             }
   528             $annot_def['display_name'] = implode(" | ", $disp_parts);
   593             $annot_def['display_name'] = implode(" | ", $disp_parts);
   529         }
   594         }
   530         $annotations[$annot_cat] = $annot_def;
   595         $annotations[$annot_cat] = $annot_def;
   531     }
   596     }
   532     return $annotations;
   597     return $annotations;
   533 }
   598 }
   534 
   599 
   535 
   600 
   536 function get_archive_box($rep, $metadata, $url_root, $basepath, &$translate) {
   601 function get_archive_box($rep, $metadata, $url_root, $basepath, &$translate)
       
   602 {
   537 
   603 
   538     include("$basepath$rep/config.php");
   604     include("$basepath$rep/config.php");
   539 
   605 
   540     set_config_translations($config, $translate);
   606     set_config_translations($config, $translate);
   541 
   607 
   542     $id = "abox_$rep".(($metadata!=null)?"_$metadata":"");
   608     $id = "abox_$rep" . (($metadata != null) ? "_$metadata" : "");
   543     $hash = ($metadata!=null)?"#metadata=$metadata":"";
   609     $hash = ($metadata != null) ? "#metadata=$metadata" : "";
   544     $tail_img = $translate->_('config__archive_img');
   610     $tail_img = $translate->_('config__archive_img');
   545     if(is_array($tail_img)) {
   611     if (is_array($tail_img)) {
   546         $tail_img = $tail_img[$metadata];
   612         $tail_img = $tail_img[$metadata];
   547     }
   613     }
   548     $archive_title = $translate->_('config__archive_title');
   614     $archive_title = $translate->_('config__archive_title');
   549     if(is_array($archive_title)) {
   615     if (is_array($archive_title)) {
   550         $archive_title = $archive_title[$metadata];
   616         $archive_title = $archive_title[$metadata];
   551     }
   617     }
   552     $archive_description = $translate->_('config__archive_description');
   618     $archive_description = $translate->_('config__archive_description');
   553     if(is_array($archive_description)) {
   619     if (is_array($archive_description)) {
   554         $archive_description = $archive_description[$metadata];
   620         $archive_description = $archive_description[$metadata];
   555     }
   621     }
   556 
   622 
   557 
   623 
   558     $res  = "<div id=\"$id\" class=\"archivesVideoBox\">\n";
   624     $res  = "<div id=\"$id\" class=\"archivesVideoBox\">\n";
   564     $res .= "        $archive_description\n";
   630     $res .= "        $archive_description\n";
   565     $res .= "    </div>\n";
   631     $res .= "    </div>\n";
   566     $res .= "</div>\n";
   632     $res .= "</div>\n";
   567 
   633 
   568     return $res;
   634     return $res;
   569 
   635 }
   570 }
   636 
   571 
   637 function display_archives_list($archives_list, $box_class, $url_root, $basepath, &$translate)
   572 function display_archives_list($archives_list, $box_class, $url_root, $basepath, &$translate) {
   638 {
   573 
   639 
   574 
   640 
   575     for($i=0;$i<count($archives_list);$i++) {
   641     for ($i = 0; $i < count($archives_list); $i++) {
   576         if(($i % 3)==0) {
   642         if (($i % 3) == 0) {
   577             print("			    <div class=\"$box_class\">\n");
   643             print("			    <div class=\"$box_class\">\n");
   578         }
   644         }
   579         $archive_ref = $archives_list[$i];
   645         $archive_ref = $archives_list[$i];
   580 
   646 
   581         $archive_name = $archive_ref;
   647         $archive_name = $archive_ref;
   582         $metadata = null;
   648         $metadata = null;
   583         if(is_array($archive_ref)) {
   649         if (is_array($archive_ref)) {
   584             $archive_name = $archive_ref[0];
   650             $archive_name = $archive_ref[0];
   585             $metadata = $archive_ref[1];
   651             $metadata = $archive_ref[1];
   586         }
   652         }
   587         print(get_archive_box($archive_name,$metadata, $url_root, $basepath, $translate));
   653         print(get_archive_box($archive_name, $metadata, $url_root, $basepath, $translate));
   588         if(($i % 3)==2 || $i == (count($archives_list)-1)) {
   654         if (($i % 3) == 2 || $i == (count($archives_list) - 1)) {
   589             print("			    </div>\n");
   655             print("			    </div>\n");
   590         }
   656         }
   591     }
   657     }
   592 }
   658 }
   593 
   659 
   594 function get_metadata_url($metadata) {
   660 function get_metadata_url($metadata)
       
   661 {
   595     global $project_url_base;
   662     global $project_url_base;
   596     if (preg_match('/^https?:\/\//', $metadata)) {
   663     if (preg_match('/^https?:\/\//', $metadata)) {
   597         return $metadata;
   664         return $metadata;
   598     } else {
   665     } else {
   599         return LDT_PLATFORM.$project_url_base.$metadata;
   666         return LDT_PLATFORM . $project_url_base . $metadata;
   600     }
   667     }
   601 }
   668 }
   602 
   669 
   603 function get_metadata_json_url($metadata) {
   670 function get_metadata_json_url($metadata)
       
   671 {
   604     if (is_array($metadata)) {
   672     if (is_array($metadata)) {
   605         $metadata["url"] = get_metadata_url($metadata["url"]);
   673         $metadata["url"] = get_metadata_url($metadata["url"]);
   606         return $metadata;
   674         return $metadata;
   607     } else {
   675     } else {
   608         return get_metadata_url($metadata);
   676         return get_metadata_url($metadata);
   611 
   679 
   612 
   680 
   613 $realm = 'Polemictweet restricted area';
   681 $realm = 'Polemictweet restricted area';
   614 
   682 
   615 
   683 
   616 function authenticate($users, $translate) {
   684 function authenticate($users, $translate)
       
   685 {
   617 
   686 
   618     global $realm;
   687     global $realm;
   619 
   688 
   620     $_SESSION['auth'] = 'polemictweet';
   689     $_SESSION['auth'] = 'polemictweet';
   621     return array('username'=>'polemictweet');
   690     return array('username' => 'polemictweet');
   622 
   691 
   623     if (empty($_SERVER['PHP_AUTH_DIGEST']) || !isset($_SESSION['http_digest_nonce'])) {
   692     if (empty($_SERVER['PHP_AUTH_DIGEST']) || !isset($_SESSION['http_digest_nonce'])) {
   624         $_SESSION['http_digest_nonce'] = uniqid();
   693         $_SESSION['http_digest_nonce'] = uniqid();
   625         header('HTTP/1.1 401 Unauthorized');
   694         header('HTTP/1.1 401 Unauthorized');
   626         header('WWW-Authenticate: Digest realm="'.$realm.
   695         header('WWW-Authenticate: Digest realm="' . $realm .
   627         '",qop="auth",nonce="'.$_SESSION['http_digest_nonce'].'",opaque="'.md5($realm).'"');
   696             '",qop="auth",nonce="' . $_SESSION['http_digest_nonce'] . '",opaque="' . md5($realm) . '"');
   628         return array('error' => $translate->_('This area is restricted, please authenticate'));
   697         return array('error' => $translate->_('This area is restricted, please authenticate'));
   629     }
   698     }
   630 
   699 
   631 
   700 
   632     //analyze the PHP_AUTH_DIGEST variable
   701     //analyze the PHP_AUTH_DIGEST variable
   633     if (!($data = http_digest_parse($_SERVER['PHP_AUTH_DIGEST'])) ||
   702     if (
   634         !isset($users[$data['username']])) {
   703         !($data = http_digest_parse($_SERVER['PHP_AUTH_DIGEST'])) ||
       
   704         !isset($users[$data['username']])
       
   705     ) {
   635         $_SERVER['PHP_AUTH_DIGEST'] = '';
   706         $_SERVER['PHP_AUTH_DIGEST'] = '';
   636         unset($_SESSION['auth']);
   707         unset($_SESSION['auth']);
   637         unset($_SESSION['http_digest_nonce']);
   708         unset($_SESSION['http_digest_nonce']);
   638         return array('error' => $translate->_('Wrong Credentials!'));
   709         return array('error' => $translate->_('Wrong Credentials!'));
   639     }
   710     }
   640 
   711 
   641 
   712 
   642     //generate the valid response
   713     //generate the valid response
   643     $A1 = md5($data['username'] . ':' . $realm . ':' . $users[$data['username']]);
   714     $A1 = md5($data['username'] . ':' . $realm . ':' . $users[$data['username']]);
   644     $A2 = md5($_SERVER['REQUEST_METHOD'].':'.$data['uri']);
   715     $A2 = md5($_SERVER['REQUEST_METHOD'] . ':' . $data['uri']);
   645     $valid_response = md5($A1.':'.$data['nonce'].':'.$data['nc'].':'.$data['cnonce'].':'.$data['qop'].':'.$A2);
   716     $valid_response = md5($A1 . ':' . $data['nonce'] . ':' . $data['nc'] . ':' . $data['cnonce'] . ':' . $data['qop'] . ':' . $A2);
   646 
   717 
   647     if ($data['response'] != $valid_response) {
   718     if ($data['response'] != $valid_response) {
   648         $_SERVER['PHP_AUTH_DIGEST'] = '';
   719         $_SERVER['PHP_AUTH_DIGEST'] = '';
   649         unset($_SESSION['http_digest_nonce']);
   720         unset($_SESSION['http_digest_nonce']);
   650         unset($_SESSION['auth']);
   721         unset($_SESSION['auth']);
   654     // ok, valid username & password
   725     // ok, valid username & password
   655     $_SESSION['auth'] = $data['username'];
   726     $_SESSION['auth'] = $data['username'];
   656     return $data;
   727     return $data;
   657 }
   728 }
   658 
   729 
   659 function logout() {
   730 function logout()
   660     global $realm;
   731 {
   661 
   732     global $_SESSION;
   662     unset($_SESSION['auth']);
   733 
   663     unset($_SESSION['http_digest_nonce']);
   734     $_SESSION = [];
   664 }
   735 }
   665 
   736 
   666 
   737 
   667 //function to parse the http auth header
   738 //function to parse the http auth header
   668 function http_digest_parse($txt)
   739 function http_digest_parse($txt)
   669 {
   740 {
   670     // protect against missing data
   741     // protect against missing data
   671     $needed_parts = array('nonce'=>1, 'nc'=>1, 'cnonce'=>1, 'qop'=>1, 'username'=>1, 'uri'=>1, 'response'=>1);
   742     $needed_parts = array('nonce' => 1, 'nc' => 1, 'cnonce' => 1, 'qop' => 1, 'username' => 1, 'uri' => 1, 'response' => 1);
   672     $data = array();
   743     $data = array();
   673     $keys = implode('|', array_keys($needed_parts));
   744     $keys = implode('|', array_keys($needed_parts));
   674 
   745 
   675     preg_match_all('@(' . $keys . ')=(?:([\'"])([^\2]+?)\2|([^\s,]+))@', $txt, $matches, PREG_SET_ORDER);
   746     preg_match_all('@(' . $keys . ')=(?:([\'"])([^\2]+?)\2|([^\s,]+))@', $txt, $matches, PREG_SET_ORDER);
   676 
   747 
   702     $text = strtolower($text);
   773     $text = strtolower($text);
   703 
   774 
   704     // remove unwanted characters
   775     // remove unwanted characters
   705     $text = preg_replace('~[^-\w]+~', '', $text);
   776     $text = preg_replace('~[^-\w]+~', '', $text);
   706 
   777 
   707     if (empty($text))
   778     if (empty($text)) {
   708     {
       
   709         return 'n-a';
   779         return 'n-a';
   710     }
   780     }
   711 
   781 
   712     return $text;
   782     return $text;
   713 }
   783 }
   714 
   784 
   715 
   785 
   716 // from http://www.house6.com/blog/?p=83
   786 // from http://www.house6.com/blog/?p=83
   717 function sanitize_filename($f) {
   787 function sanitize_filename($f)
       
   788 {
   718     // a combination of various methods
   789     // a combination of various methods
   719     // we don't want to convert html entities, or do any url encoding
   790     // we don't want to convert html entities, or do any url encoding
   720     // we want to retain the "essence" of the original file name, if possible
   791     // we want to retain the "essence" of the original file name, if possible
   721     // char replace table found at:
   792     // char replace table found at:
   722     // http://www.php.net/manual/en/function.strtr.php#98669
   793     // http://www.php.net/manual/en/function.strtr.php#98669
   723     $replace_chars = array(
   794     $replace_chars = array(
   724             'Š'=>'S', 'š'=>'s', 'Ð'=>'Dj','Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A',
   795         'Š' => 'S', 'š' => 's', 'Ð' => 'Dj', 'Ž' => 'Z', 'ž' => 'z', 'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A',
   725             'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I',
   796         'Å' => 'A', 'Æ' => 'A', 'Ç' => 'C', 'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I',
   726             'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U',
   797         'Ï' => 'I', 'Ñ' => 'N', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'O', 'Ø' => 'O', 'Ù' => 'U', 'Ú' => 'U',
   727             'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss','à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a',
   798         'Û' => 'U', 'Ü' => 'U', 'Ý' => 'Y', 'Þ' => 'B', 'ß' => 'Ss', 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'a',
   728             'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i',
   799         'å' => 'a', 'æ' => 'a', 'ç' => 'c', 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', 'ì' => 'i', 'í' => 'i', 'î' => 'i',
   729             'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u',
   800         'ï' => 'i', 'ð' => 'o', 'ñ' => 'n', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ø' => 'o', 'ù' => 'u',
   730             'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y', 'ƒ'=>'f'
   801         'ú' => 'u', 'û' => 'u', 'ý' => 'y', 'ý' => 'y', 'þ' => 'b', 'ÿ' => 'y', 'ƒ' => 'f'
   731     );
   802     );
   732     $f = strtr($f, $replace_chars);
   803     $f = strtr($f, $replace_chars);
   733     // convert & to "and", @ to "at", and # to "number"
   804     // convert & to "and", @ to "at", and # to "number"
   734     $f = preg_replace(array('/[\&]/', '/[\@]/', '/[\#]/'), array('-and-', '-at-', '-number-'), $f);
   805     $f = preg_replace(array('/[\&]/', '/[\@]/', '/[\#]/'), array('-and-', '-at-', '-number-'), $f);
   735     $f = preg_replace('/[^(\x20-\x7F)]*/','', $f); // removes any special chars we missed
   806     $f = preg_replace('/[^(\x20-\x7F)]*/', '', $f); // removes any special chars we missed
   736     $f = str_replace(' ', '-', $f); // convert space to hyphen
   807     $f = str_replace(' ', '-', $f); // convert space to hyphen
   737     $f = str_replace('\'', '', $f); // removes apostrophes
   808     $f = str_replace('\'', '', $f); // removes apostrophes
   738     $f = preg_replace('/[^\w\-\.]+/', '', $f); // remove non-word chars (leaving hyphens and periods)
   809     $f = preg_replace('/[^\w\-\.]+/', '', $f); // remove non-word chars (leaving hyphens and periods)
   739     $f = preg_replace('/[\-]+/', '-', $f); // converts groups of hyphens into one
   810     $f = preg_replace('/[\-]+/', '-', $f); // converts groups of hyphens into one
   740     if (function_exists('iconv'))
   811     if (function_exists('iconv')) {
   741     {
       
   742         $f = iconv('utf-8', 'us-ascii//TRANSLIT', $f);
   812         $f = iconv('utf-8', 'us-ascii//TRANSLIT', $f);
   743     }
   813     }
   744 
   814 
   745     return strtolower($f);
   815     return strtolower($f);
   746 }
   816 }
   747 
   817 
   748 function rgb2hex($rgb) {
   818 function rgb2hex($rgb)
   749    $hex = "#";
   819 {
   750    $hex .= str_pad(dechex($rgb[0]), 2, "0", STR_PAD_LEFT);
   820     $hex = "#";
   751    $hex .= str_pad(dechex($rgb[1]), 2, "0", STR_PAD_LEFT);
   821     $hex .= str_pad(dechex($rgb[0]), 2, "0", STR_PAD_LEFT);
   752    $hex .= str_pad(dechex($rgb[2]), 2, "0", STR_PAD_LEFT);
   822     $hex .= str_pad(dechex($rgb[1]), 2, "0", STR_PAD_LEFT);
   753 
   823     $hex .= str_pad(dechex($rgb[2]), 2, "0", STR_PAD_LEFT);
   754    return $hex; // returns the hex value including the number sign (#)
   824 
   755 }
   825     return $hex; // returns the hex value including the number sign (#)
   756 
   826 }
   757 function hsl2Rgb( $h, $s, $l ){
   827 
   758     $r;
   828 function hsl2Rgb($h, $s, $l)
   759     $g;
   829 {
   760     $b;
   830     $r = -1;
   761 	$c = ( 1 - abs( 2 * $l - 1 ) ) * $s;
   831     $g = -1;
   762 	$x = $c * ( 1 - abs( fmod( ( $h / 60 ), 2 ) - 1 ) );
   832     $b = -1;
   763 	$m = $l - ( $c / 2 );
   833     $c = (1 - abs(2 * $l - 1)) * $s;
   764 	if ( $h < 60 ) {
   834     $x = $c * (1 - abs(fmod(($h / 60), 2) - 1));
   765 		$r = $c;
   835     $m = $l - ($c / 2);
   766 		$g = $x;
   836     if ($h < 60) {
   767 		$b = 0;
   837         $r = $c;
   768 	} else if ( $h < 120 ) {
   838         $g = $x;
   769 		$r = $x;
   839         $b = 0;
   770 		$g = $c;
   840     } else if ($h < 120) {
   771 		$b = 0;
   841         $r = $x;
   772 	} else if ( $h < 180 ) {
   842         $g = $c;
   773 		$r = 0;
   843         $b = 0;
   774 		$g = $c;
   844     } else if ($h < 180) {
   775 		$b = $x;
   845         $r = 0;
   776 	} else if ( $h < 240 ) {
   846         $g = $c;
   777 		$r = 0;
   847         $b = $x;
   778 		$g = $x;
   848     } else if ($h < 240) {
   779 		$b = $c;
   849         $r = 0;
   780 	} else if ( $h < 300 ) {
   850         $g = $x;
   781 		$r = $x;
   851         $b = $c;
   782 		$g = 0;
   852     } else if ($h < 300) {
   783 		$b = $c;
   853         $r = $x;
   784 	} else {
   854         $g = 0;
   785 		$r = $c;
   855         $b = $c;
   786 		$g = 0;
   856     } else {
   787 		$b = $x;
   857         $r = $c;
   788 	}
   858         $g = 0;
   789 	$r = ( $r + $m ) * 255;
   859         $b = $x;
   790 	$g = ( $g + $m ) * 255;
   860     }
   791 	$b = ( $b + $m  ) * 255;
   861     $r = ($r + $m) * 255;
   792     return array( floor( $r ), floor( $g ), floor( $b ) );
   862     $g = ($g + $m) * 255;
   793 }
   863     $b = ($b + $m) * 255;
       
   864     return array(floor($r), floor($g), floor($b));
       
   865 }