<?php

/**
 * include some common code (like we did in the 90s)
 * People still do this? ;)
 */
$rep = $_REQUEST['rep'];
include_once dirname(__FILE__).'/'.$rep.'/config.php';
// configuration
include 'common.php';
 // objet actuel
$baseurl = URL_ROOT;

$div_height = 640;
if($translate->_('config__div_height') != 'config__div_height') {
    $div_height = $translate->_('config__div_height');
}
$tweet_explain_background = URL_ROOT.'images/tweetExplainBgd.gif';
if(file_exists(dirname(__FILE__)."/$rep/images/tweetExplainBgd.gif")) {
    $tweet_explain_background = URL_ROOT.$rep.'/images/tweetExplainBgd.gif';
}

$head_logo = URL_ROOT."$rep/images/head_logo.gif";
if($translate->_('config__head_logo') != 'config__head_logo' && $translate->_('config__head_logo') != null ) {
    $head_logo = URL_ROOT."$rep/".$translate->_('config__head_logo');
}

$url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];

$protocol_level = (
    isset($_REQUEST['protocol_level'])
    ? $_REQUEST['protocol_level']
    : (
        isset($config['protocol_level'])
        ? $config['protocol_level']
        : 3
    )
);

$protocol_level = min(3,max(0, $protocol_level));

$use_protocol = (isset($_REQUEST['protocol_level']) || isset($config['protocol_level']));

if ($use_protocol && !isset($_SESSION['answered_events'])) {
    $_SESSION['answered_events'] = array();
}

$show_splash = ( $use_protocol && !in_array($rep, $_SESSION['answered_events']) );

if ($show_splash) {
    array_push($_SESSION['answered_events'], $rep);
}

$annotation_protocol_version = isset($config['annotation_protocol_version'])?$config['annotation_protocol_version']:"1";
$annotations = get_default_annotations_config($config, $translate);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="<?php echo($actual); ?>">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Polemic tweet &mdash; <?php echo($translate->_('config__title')); ?></title>
    <meta name="keywords" content="<?php echo($translate->_('config__keywords')); ?>"><!-- add timestampedmetadata -->
    <!--<meta name="description" content="PoelmicTweet.fr : debate mapping, opinion, conference, video">-->
    <meta name="description" content="<?php echo(strip_tags($translate->_('config__description'))); ?>">
    <meta name="robots" content="index, follow">

    <!-- ICI : <?php echo($_SERVER['DOCUMENT_ROOT']); ?> -->
    <!-- JAVASCRIPT -->
    <script type="text/javascript" src="<?php echo(registry_url('json-js','js'));?>"></script>
    <script type="text/javascript" src="<?php echo(registry_url('metadataplayer','js'));?>"></script>
    <script type="text/javascript" src="<?php echo(registry_url('jquery','js'));?>"></script>
    <script type="text/javascript" src="<?php echo(registry_url('fancybox','js'));?>"></script>
    <script type="text/javascript" src="<?php echo(registry_url('jquery-url','js'));?>"></script>

    <!-- Framework CSS -->
    <link rel="stylesheet" href="<?php echo(registry_url('tweetcast','css'));?>" type="text/css" media="screen, projection"/>
    <link rel="stylesheet" href="<?php echo(registry_url('fancybox','css'));?>" media="screen"/>

    <!-- FONT -->
    <link href='<?php echo(registry_url('PT-Sans_Narrow','font'));?>' rel='stylesheet' type='text/css'/>
    <link href='<?php echo(registry_url('PT-Sans','font'));?>' rel='stylesheet' type='text/css'/>

    <link rel="stylesheet" href="<?php echo(registry_url('metadataplayer','css'));?>" media="screen"/>

    <link href='<?php echo(URL_ROOT); ?>res/css/common.css' rel='stylesheet' type='text/css'/>


    <script type="text/javascript">
          // Configuration Polemical Timeline
    if (typeof jQuery == "undefined") {
        jQuery = window.$;
    }
    <?php
          if(is_array($translate->_('config__metadata'))):
            $metadataurls = array_map("get_metadata_json_url",$translate->_('config__metadata'));
            reset($metadataurls);
            $first_key = key($metadataurls);
    ?>
    var metadatas = jQuery.parseJSON('<?php echo(json_encode($metadataurls)); ?>');
    var url = jQuery.url();
    var metadata_key = url.fparam('metadata');
    if(typeof metadata_key === "undefined" || metadata_key.length === 0) {
        metadata_key = "<?php echo($first_key);?>";
    }
    <?php else: ?>
    var metadatas = { metadata: {url: "<?php echo(get_metadata_url($translate->_('config__metadata')));?>"} };
    var metadata_key = "metadata";
    <?php endif;?>
    var _protocol_level = _protocol_level,
        _cookiematches = document.cookie.match(/PHPSESSID=([A-Za-z0-9]+)/),
        _cookie = (_cookiematches && _cookiematches.length > 1 ? _cookiematches[1] : undefined);

    IriSP.libFiles.defaultDir = "<?php echo(registry_url('libdir','js'));?>";
    IriSP.widgetsDir = "<?php echo(registry_url('ldtwidgets','js'));?>";
    IriSP.libFiles.locations.jwPlayerSWF = "<?php echo(URL_ROOT); ?>res/mediaplayer/player.swf";
    IriSP.language = "<?php echo($actual) ?>";

    var _metadata = {
        url: metadatas[metadata_key].url,
        format: 'ldt'
    };
    var _config = {
        width: 600,
        height: 800,
        container: 'LdtPlayer',
        default_options: {
            metadata: _metadata
        },
        css:'<?php echo(registry_url('metadataplayer','css'));?>',
        widgets: [
            {
                type: "AutoPlayer",
                height: 360,
                width: 600,
                dailymotionPlayerId: "x10ckq"
            },
            { type: "Slider" },
            {
                type: "Controller",
                disable_annotate_btn: true
            },
<?php if ($protocol_level > 1): ?>
            {
                type: "Polemic",
                max_elements: 60,
                default_version: "1",
<?php if (isset($annotations)): ?>
                polemics : { "<?php echo($annotation_protocol_version)?>":[
<?php foreach ($annotations as $annot_key => $annot_def): ?>
    <?php 
    $hVal = (isset($annot_def['colors'])&&isset($annot_def['colors']['h']))?floatval($annot_def['colors']['h']):0.17;
    $hVal = ($hVal<1)?floor($hVal*360.0):$hVal;
    $sVal = (isset($annot_def['colors'])&&isset($annot_def['colors']['s']))?floatval($annot_def['colors']['s']):1.0;

    $polemicColor = isset($annot_def['polemic_color'])?$annot_def['polemic_color']:rgb2hex(hsl2Rgb($hVal, $sVal, 0.5));

    if($annot_key == 'default') { continue; } ?>
                    {
                        "name" : "<?php echo $annot_def['polemic_cat']; ?>",
                        "keywords" : <?php echo json_encode($annot_def['polemic_keywords']); ?>,
                        "color" : "<?php echo $polemicColor; ?>"
                    },
<?php endforeach; ?>
                ]}
<?php endif; ?>
            },
<?php endif; ?>
<?php if ($protocol_level > 1): ?>
            {
                type: "Polemic",
                max_elements: 60,
                default_version: "1",
                annotation_type: ["chat"],
                defaultcolor: "#9b8864",
<?php if (isset($annotations)): ?>
                polemics : { "<?php echo($annotation_protocol_version)?>":[
<?php foreach ($annotations as $annot_key => $annot_def): ?>
    <?php 
    $hVal = (isset($annot_def['colors'])&&isset($annot_def['colors']['h']))?floatval($annot_def['colors']['h']):0.17;
    $hVal = ($hVal<1)?floor($hVal*360.0):$hVal;
    $sVal = (isset($annot_def['colors'])&&isset($annot_def['colors']['s']))?floatval($annot_def['colors']['s']):1.0;

    $polemicColor = isset($annot_def['polemic_color'])?$annot_def['polemic_color']:rgb2hex(hsl2Rgb($hVal, $sVal, 0.5));

    if($annot_key == 'default') { continue; } ?>
                    {
                        "name" : "<?php echo $annot_def['polemic_cat']; ?>",
                        "keywords" : <?php echo json_encode($annot_def['polemic_keywords']); ?>,
                        "color" : "<?php echo $polemicColor; ?>"
                    },
<?php endforeach; ?>
                ]}
<?php endif; ?>
            },
<?php endif; ?>
<?php if ($protocol_level > 1 || isset($annotations)): ?>
            {
                type: "MultiSegments",
                //annotation_type: "chap"
            },
            {
                type: "Annotation",
                annotation_type: "découpage"
            },
            { type: "Tweet" },
            {
                type: "Tagcloud",
                container: "TagcloudContainer",
                exclude_pattern: /^@/,
                custom_stopwords: <?php echo json_encode(array($translate->_('config__hashtag'))) ?>
            },
            {
                type: "AnnotationsList",
                //ajax_url : "<?php echo(LDT_PLATFORM); ?>ldtplatform/api/ldt/segments/{{media}}/{{begin}}/{{end}}?callback=?",
                //foreign_url : "<?php echo(LDT_PLATFORM); ?>ldtplatform/ldt/front/player/{{media}}/{{project}}/{{annotationType}}#id={{annotation}}",
                container: "AnnotationsListContainer"
            },
            // {
            //     type: "CreateAnnotation",
            //     api_endpoint_template: "<?php echo(LDT_PLATFORM); ?>ldtplatform/api/ldt/1.0/annotations/",
            //     api_method: 'POST',
            //     after_send_timeout: 8000,
            //     show_mic_record: false,
            //     close_after_send: false,
            //     slice_annotation_type: ["chap","découpage"],
            //     creator_avatar: "<?php echo(URL_ROOT); ?>images/avatar.png"
            // },
<?php endif; ?>
            { type: "Mediafragment"},
        ]
    };

    jQuery(document).ready(function() {
<?php if ($show_splash): ?>
        jQuery.fancybox(
            jQuery("#splash").html(),
            {
                width: 500,
                modal: true,
                closeBtn: false
            });

        jQuery("#fancybox-content form").submit(function() {
            jQuery.fancybox.close();
            var _checkboxes = [];
            jQuery("#fancybox-content .checkbox:checked").each(function() { _checkboxes.push(this.value) });
            var _data = {
                    eventLink: _checkboxes,
                    eMail: jQuery("#fancybox-content .eMail").val(),
                    twitterHandle: jQuery("#fancybox-content .twitterHandle").val(),
                    cookie: _cookie,
                    protocol_level: _protocol_level
                };
            return false;
        });
<?php endif; ?>

        jQuery("#mdselect_"+metadata_key).attr("selected","selected");
        jQuery("#mdselect").change(function() {
            var metadata_key = this.options[this.selectedIndex].value;
            window.location.hash = "#metadata="+metadata_key;
            window.location.href = window.location.href;
            window.location.reload(true);
            jQuery(".embedbutton").attr('href','<?php echo(URL_ROOT.$rep);?>/embed_form.php?metadata='+metadata_key);
        });
        if(metadata_key !== "metadata") {
            jQuery(".embedbutton").attr('href','<?php echo(URL_ROOT.$rep);?>/embed_form.php?metadata='+metadata_key);
        }
        jQuery(".embedbutton").fancybox({
            'width'                : 360,
            'height'            : 360,
            'autoDimensions'    : false,
            'transitionIn'        : 'none',
            'transitionOut'        : 'none',
            'type'                : 'iframe'
        });
        jQuery("#Program").fancybox({
            type: "iframe",
            width: 840,
            height: 640,
            transitionIn: "none",
            transitionOut: "none"
        });
        jQuery(".acctitre").click(function() {
            var _nx = jQuery(this).next();
            if (_nx.is(":hidden")) {
                jQuery(".acctexte").slideUp();
                _nx.slideDown();
            }
        })

    });
    </script>
  </head>
  <body>
  <!--div id="sendUsFeedBack"><a href="<?php echo($C_feedback_form_url); ?>" target="_blank"><img src="<?php echo(URL_ROOT); ?>images/sendusfeedback.png"></a></div-->

  <!-- tooltip -->
  </div>
    <div id="splash" style="display:none;">
        <div class="splash">
            <h1><?php echo $translate->_("Protocol_Head").$translate->_('config__title'); ?></h1>
            <p><?php echo $translate->_("Protocol_Subtitle"); ?></p>
            <?php echo $translate->_("Protocol_Explain_Level_".$protocol_level); ?>
            <hr />
            <h2><?php echo $translate->_("Protocol_Questions_Head"); ?></h2>
            <form target="_blank">
                <h3><?php echo $translate->_("Protocol_Questions_Part_1_prefix").$translate->_('config__title').$translate->_("Protocol_Questions_Part_1_suffix"); ?></h3>
                <ul>
                    <li><input class="checkbox" type="checkbox" value="wasThere"/><?php echo $translate->_("Protocol_Answer_WasThere"); ?></li>
                    <li><input class="checkbox" type="checkbox" value="watchedStream"/><?php echo $translate->_("Protocol_Answer_WatchedStream"); ?></li>
                    <li><input class="checkbox" type="checkbox" value="liveTweeted"/><?php echo $translate->_("Protocol_Answer_liveTweeted"); ?></li>
                    <li><input class="checkbox" type="checkbox" value="none"/><?php echo $translate->_("Protocol_Answer_none"); ?></li>
                </ul>
                <h3><?php echo $translate->_("Protocol_Questions_Part_2"); ?></h3>
                <ul>
                    <li><label><?php echo $translate->_("Protocol_Answer_Mail"); ?></label><input class="eMail" name="eMail" /></li>
                    <li><label><?php echo $translate->_("Protocol_Answer_Twitter"); ?></label><input class="twitterHandle" name="twitterHandle" /></li>
                </ul>
                <input type="submit" value="<?php echo $translate->_("Protocol_Submit_Label"); ?>" class="submit" />
            </form>
        </div>
    </div>
    <div id="container">
        <div class="barre">
            <img id="headlogo" src="<?php echo($head_logo); ?>" width="171" height="63" />
            <div id="minilogo"></div>
            <ul class="menu">
                <li>
                    <a href="<?php echo(URL_ROOT); ?>" class="menuLink">
                        <?php print $translate->_("Accueil"); ?>
                    </a>
                </li>
                <li>
                    <a href="<?php echo($translate->_('config__link')); ?>" class="menuLink" target="_blank" id='Program'>
                        <?php print $translate->_("Programme"); ?>
                    </a>
                </li>
                <li>
                    <a href="../about.php" class="menuLink" >
                        <?php print $translate->_("A propos"); ?>
                    </a>
                </li>
            </ul>
            <ul class="menu">
                <li>
                    <a href="<?php URL_ROOT ?>polemicaltimeline.php?lang=ja_JP" class="menuLink" >
                        <img src='<?php echo(URL_ROOT); ?>images/flag_jp.gif'<?php if($actual!="ja_JP"){echo("style='opacity: .5;'"); } ?> />
                        <?php print $translate->_("Japonais"); ?>
                    </a></li>
                <li>
                    <a href="<?php URL_ROOT ?>polemicaltimeline.php?lang=fr" class="menuLink">
                        <img src='<?php echo(URL_ROOT); ?>images/flag_fr.gif' <?php if($actual!="fr"){echo("style='opacity: .5;'"); } ?> />
                        <?php print $translate->_("Français"); ?>
                    </a>
                </li>
                <li>
                    <a href="<?php URL_ROOT ?>polemicaltimeline.php?lang=en" class="menuLink">
                        <img src='<?php echo(URL_ROOT); ?>images/flag_en.gif' <?php if($actual!="en"){echo("style='opacity: .5;'"); } ?> />
                        <?php print $translate->_("Anglais"); ?>
                    </a>
                </li>
            </ul>

    <?php if(is_array($translate->_('config__metadata'))): ?>
    <ul id="content_select_ul" class="menu mdselect">
        <span><?php print $translate->_("changer de contenu"); ?></span><br/>
        <select id="mdselect">
            <?php foreach ($translate->_('config__metadata') as $key => $value):?>
            <option value="<?php echo($key); ?>" id="mdselect_<?php echo($key); ?>" ><?php echo($value['display']); ?></option>
            <?php endforeach;?>
        </select>
    </ul>
    <?php endif;?>
            <div class="embedbar">
                <a class="embedbutton" href="<?php echo(URL_ROOT.$rep)?>/embed_form.php">Intégrer</a>
                <?php
                    $share_title = "Polemic Tweet - ".$translate->_('config__title');
                    $share_url = rtrim(URL_ROOT,"/").$rep;
                    $share_description = strip_tags(preg_replace('/<\s?br\s*\\?>/i', "\n", str_replace("&nbsp;", " ", $translate->_('config__abstract'))));
                ?>
                <!-- cf. https://sharingbuttons.io/ -->
                <div class="share_toolbox">
                    <!-- Sharingbutton Twitter -->
                    <a class="resp-sharing-button__link" href="https://twitter.com/intent/tweet/?text=<?php echo urlencode("$share_title - $share_url"); ?>&amp;url=<?php echo rawurlencode($share_url); ?>" target="_blank" rel="noopener" aria-label="">
                      <div class="resp-sharing-button resp-sharing-button--twitter resp-sharing-button--small"><div aria-hidden="true" class="resp-sharing-button__icon resp-sharing-button__icon--solid">
                        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M23.44 4.83c-.8.37-1.5.38-2.22.02.93-.56.98-.96 1.32-2.02-.88.52-1.86.9-2.9 1.1-.82-.88-2-1.43-3.3-1.43-2.5 0-4.55 2.04-4.55 4.54 0 .36.03.7.1 1.04-3.77-.2-7.12-2-9.36-4.75-.4.67-.6 1.45-.6 2.3 0 1.56.8 2.95 2 3.77-.74-.03-1.44-.23-2.05-.57v.06c0 2.2 1.56 4.03 3.64 4.44-.67.2-1.37.2-2.06.08.58 1.8 2.26 3.12 4.25 3.16C5.78 18.1 3.37 18.74 1 18.46c2 1.3 4.4 2.04 6.97 2.04 8.35 0 12.92-6.92 12.92-12.93 0-.2 0-.4-.02-.6.9-.63 1.96-1.22 2.56-2.14z"/></svg>
                        </div>
                      </div>
                    </a>
                    <!-- Sharingbutton Facebook -->
                    <a class="resp-sharing-button__link" href="https://facebook.com/sharer/sharer.php?t=<?php echo rawurlencode($share_title); ?>&amp;u=<?php echo rawurlencode($share_url); ?>" target="_blank" rel="noopener" aria-label="">
                      <div class="resp-sharing-button resp-sharing-button--facebook resp-sharing-button--small"><div aria-hidden="true" class="resp-sharing-button__icon resp-sharing-button__icon--solid">
                        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M18.77 7.46H14.5v-1.9c0-.9.6-1.1 1-1.1h3V.5h-4.33C10.24.5 9.5 3.44 9.5 5.32v2.15h-3v4h3v12h5v-12h3.85l.42-4z"/></svg>
                        </div>
                      </div>
                    </a>
                    <!-- Sharingbutton Telegram -->
                    <a class="resp-sharing-button__link" href="https://telegram.me/share/url?text=<?php echo rawurlencode("$share_description"); ?>&amp;url=<?php echo rawurlencode($share_url); ?>" target="_blank" rel="noopener" aria-label="">
                      <div class="resp-sharing-button resp-sharing-button--telegram resp-sharing-button--small"><div aria-hidden="true" class="resp-sharing-button__icon resp-sharing-button__icon--solid">
                          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M.707 8.475C.275 8.64 0 9.508 0 9.508s.284.867.718 1.03l5.09 1.897 1.986 6.38a1.102 1.102 0 0 0 1.75.527l2.96-2.41a.405.405 0 0 1 .494-.013l5.34 3.87a1.1 1.1 0 0 0 1.046.135 1.1 1.1 0 0 0 .682-.803l3.91-18.795A1.102 1.102 0 0 0 22.5.075L.706 8.475z"/></svg>
                        </div>
                      </div>
                    </a>
                    <!-- Sharingbutton E-Mail -->
                    <a class="resp-sharing-button__link" href="mailto:?subject=<?php echo rawurlencode($share_title); ?>&amp;body=<?php echo rawurlencode("$share_description - $share_url"); ?>" target="_self" rel="noopener" aria-label="">
                      <div class="resp-sharing-button resp-sharing-button--email resp-sharing-button--small"><div aria-hidden="true" class="resp-sharing-button__icon resp-sharing-button__icon--solid">
                        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M22 4H2C.9 4 0 4.9 0 6v12c0 1.1.9 2 2 2h20c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zM7.25 14.43l-3.5 2c-.08.05-.17.07-.25.07-.17 0-.34-.1-.43-.25-.14-.24-.06-.55.18-.68l3.5-2c.24-.14.55-.06.68.18.14.24.06.55-.18.68zm4.75.07c-.1 0-.2-.03-.27-.08l-8.5-5.5c-.23-.15-.3-.46-.15-.7.15-.22.46-.3.7-.14L12 13.4l8.23-5.32c.23-.15.54-.08.7.15.14.23.07.54-.16.7l-8.5 5.5c-.08.04-.17.07-.27.07zm8.93 1.75c-.1.16-.26.25-.43.25-.08 0-.17-.02-.25-.07l-3.5-2c-.24-.13-.32-.44-.18-.68s.44-.32.68-.18l3.5 2c.24.13.32.44.18.68z"/></svg>
                        </div>
                      </div>
                    </a>
                </div>
            </div>
        </div>

    <!-- EXPLICATION  -->
    <div id="mdpgauche">
        <ul class="accordeon">
            <div id="Slideshare"></div>
            <li class="acctitre">
                <h3><?php echo($translate->_('config__title')); ?></h3>
            </li>
            <li class="acctexte mdpacclimited">
                <p><?php echo($translate->_('config__description')); ?></p>
            </li>

<?php if (!$use_protocol): ?>
            <li class="acctitre">
                <h3>Liste des Annotations</h3>
            </li>
            <li class="acctexte mdpacclimited" style="display: none;">
                <div id="AnnotationsListContainer"></div>
            </li>
            <li class="acctitre">
                <h3>Mots-clés</h3>
            </li>
            <li class="acctexte mdpacclimited" style="display: none;">
                <div id="TagcloudContainer"></div>
            </li>
<?php endif; ?>
        </ul>

      </div>




      <div id="mdpdroite" >
        <div id="LdtPlayer"></div>
      </div>
<script type="text/javascript">
    var _myPlayer = new IriSP.Metadataplayer(_config);
</script>
  </div>

      <div class="footer">

        <hr>
            <?php echo($translate->_('config__partenaires')); ?><br>
      </div>

    </div>

  </body>
</html>
