Add function to generate strong URL

This commit is contained in:
Némunaire 2013-11-29 03:10:12 +01:00
parent 7bd2e3eecf
commit 9cc1110717
9 changed files with 90 additions and 20 deletions

View File

@ -6,6 +6,7 @@ define("SALT_USER", "connected");
define("SALT_ADMIN", "admin");
//On active le débogage si l'on est sur le domaine de debug
if ($_SERVER["SERVER_NAME"] == "localhost" || $_SERVER["SERVER_NAME"] == "fic" || $_SERVER["SERVER_NAME"] == "fic.nemunai.re" || $_SERVER["SERVER_NAME"] == "atlantis.chen.li")
define("DEBUG", true);
@ -15,7 +16,14 @@ require_once("common.php");
$template->assign("SALT_USER",SALT_USER);
$template->assign("SALT_ADMIN",SALT_ADMIN);
$n = preg_match_all("#[^/]+#", strtolower(gpc("p")), $out);
// Convert hidden URL to raw one
$urls = Cache::read("urls");
$p = strtolower(gpc("p"));
if (!empty($urls["/".$p]))
$p = $urls["/".$p];
$n = preg_match_all("#[^/]+#", $p, $out);
$p = $out[0];
// Admin part

View File

@ -13,7 +13,7 @@ if (isset($VAR['submission_dir']))
if ($n >= 6 && $p[5] == "werr")
{
$template->assign("ERRcolor", "danger");
if (DEBUG)
if (defined("DEBUG") && DEBUG)
$template->assign("ERRmessage", "DEBUG ERROR: le répertoire submission n'est pas accessible en écriture.");
else
$template->assign("ERRmessage", "Une erreur s'est produite durant la soumission. Veuillez réessayer dans quelques instants.");
@ -23,15 +23,15 @@ if (isset($VAR['submission_dir']))
$template->assign("ERRcolor", "success");
$template->assign("ERRmessage", "Votre réponse a bien été prise en compte et sera évaluée dans quelques instants...");
}
if (!empty($_POST["solution"]))
{
if (is_writable("$submission_dir/"))
{
$file = $submission_dir.'/'.$p[1].'-'.$p[2].'-'.$p[3];
file_put_contents($file, $_POST['solution'], LOCK_EX);
header("Location: /".implode("/", $p));
exit;
}
@ -45,7 +45,7 @@ if (isset($VAR['submission_dir']))
}
else
{
if (DEBUG)
if (defined("DEBUG") && DEBUG)
erreur("Merci d'ajouter la variable submission_dir dans root.xml");
else
erreur("Une erreur s'est produite. Veuillez réessayer dans quelques instants.");

View File

@ -0,0 +1,61 @@
<?php
function smarty_function_link($params, $template)
{
if (!isset($params['href']))
{
trigger_error("link: missing 'href' parameter", E_USER_WARNING);
return;
}
else
$href = $params['href'];
if (!empty($params['href_prefix']))
$href = $params['href_prefix'] . $href;
if (!empty($params['href_suffix']))
$href = $href . $params['href_suffix'];
if (empty($params['label']))
$label = $href;
else
$label = $params['label'];
if (!defined("DEBUG"))
{
$href_de = $href;
if (!empty($params['href']))
{
$href = hash('whirlpool', $href);
if (!empty($params['href_prefix']))
$href = $params['href_prefix'] . $href;
if (!empty($params['href_suffix']))
$href = $href . $params['href_suffix'];
}
$urls = Cache::read("urls");
if (empty($urls[$href]) || $urls[$href] != $href_de)
{
$urls[$href] = $href_de;
Cache::set("urls", $urls);
}
unset($urls);
}
$more = "";
if (!empty($params['class']))
$more .= ' class="' . $params['class'] . '"';
if (!empty($params['data-toggle']))
$more .= ' data-toggle="' . $params['data-toggle'] . '"';
if (!empty($params['role']))
$more .= ' role="' . $params['role'] . '"';
if (!isset($params['notag']))
return '<a href="' . $href . '"' . $more . '>' . $label . '</a>';
else
return $href;
}

View File

@ -25,19 +25,19 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/{$SALT_ADMIN}/">FIC</a>
{link class="navbar-brand" href_prefix="/{$SALT_ADMIN}/" href="" label="FIC"}
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li{if $menu_where == "teams"} class="active"{/if}><a href="/{$SALT_ADMIN}/teams">Équipes</a></li>
<li{if $menu_where == "themes"} class="active"{/if}><a href="/{$SALT_ADMIN}/themes">Thèmes</a></li>
<li{if $menu_where == "teams"} class="active"{/if}>{link href_prefix="/{$SALT_ADMIN}/" href="teams" label="Équipes"}</li>
<li{if $menu_where == "themes"} class="active"{/if}>{link href_prefix="/{$SALT_ADMIN}/" href="themes" label="Thèmes"}</li>
{foreach from=$themes item=t}
<li class="dropdown{if $menu_where == $t->get_name()} active{/if}">
<a href="/{$SALT_ADMIN}/ex/{$t->get_id()}-{$t->get_name()}" class="dropdown-toggle" data-toggle="dropdown">{$t->get_name()} <b class="caret"></b></a>
{link href_prefix="/{$SALT_ADMIN}/" href="ex/{$t->get_id()}-{$t->get_name()}" class="dropdown-toggle" data-toggle="dropdown" label="{$t->get_name()} <b class=\"caret\"></b>"}
<ul class="dropdown-menu">
{foreach from=$t->get_exercices_ordered() item=e}
<li><a href="/{$SALT_ADMIN}/ex/{$t->get_id()}-{$t->get_name()}/{$e->get_id()}">{$e->get_name()}</a></li>
{foreach from=$t->get_exercices_ordered() item=e}
<li>{link href_prefix="/{$SALT_ADMIN}/" href="ex/{$t->get_id()}-{$t->get_name()}/{$e->get_id()}" label="{$e->get_name()}"}</li>
{/foreach}
</ul>
</li>

View File

@ -1,6 +1,8 @@
<div class="clock">
<div id="ficlogo">
<a href="/">
<img src="/img/challenge.jpg" alt="Forum International de la Cybersécurité">
</a>
</div>
<div id="epitalogo">
<img src="/img/epita.png" alt="Epita">

View File

@ -21,7 +21,7 @@
<h3>Top 10</h3>
<div class="list-group">
{foreach from=$top item=t key=k}
<div class="list-group-item">{$k+1}. <a href="/{$t->id}-{$t->get_name()}">{$t->get_name()}</a></div>
<div class="list-group-item">{$k+1}. {link href="{$t->id}-{$t->get_name()}" href_prefix="/" label=$t->get_name()}</div>
{/foreach}
</div>
</div>

View File

@ -39,11 +39,11 @@ $(document).ready(function() {
<aside class="panel panel-default">
<div class="panel-body">
<p>
<span style="font-weight: bolder;">{$my_team->get_name()}<a class="badge pull-right" href="/{$SALT_USER}/{$my_team->get_id()}/me">Info</a></span>
<span style="font-weight: bolder;">{$my_team->get_name()}{link class="badge pull-right" href_prefix="/{$SALT_USER}/{$my_team->get_id()}/" href="me" label="Info"}</span>
<em>{$my_team->get_slogan()}</em>
</p>
<p>
{$my_team->get_pts()} points<a class="badge pull-right" href="/{$SALT_USER}/{$my_team->get_id()}/summary">Synthèse</a><br>
{$my_team->get_pts()} points{link class="badge pull-right" href_prefix="/{$SALT_USER}/{$my_team->get_id()}/" href="summary" label="Synthèse"}<br>
{$my_team->get_rank()}<sup>e</sup> sur {Team::get_nb_teams()}
</p>
</div>
@ -51,7 +51,7 @@ $(document).ready(function() {
<div class="list-group">
{foreach from=$themes item=t key=k}
<a class="list-group-item" href="/{$SALT_USER}/{$my_team->get_id()}/{$t->get_id()}-{$t->get_name()}">
<a class="list-group-item" href="{link notag=1 href_prefix="/{$SALT_USER}/{$my_team->get_id()}/" href="{$t->get_id()}-{$t->get_name()}"}">
<span class="badge">{$my_team->get_nb_res_exercises_by_theme($t->get_id())}/{$t->get_nb_exercices()}</span>
{$t->get_name()}
</a>

View File

@ -3,7 +3,7 @@
<h3>Choisissez la team que vous voulez représenter :</h3>
{foreach from=$teams item=i}
<ul>
<li><a href="/{$SALT_USER}/{$i->id}/">{$i->team_name}</a></li>
<li>{link href_prefix="/{$SALT_USER}/{$i->id}/" href="" label="{$i->team_name}"}</li>
</ul>
{/foreach}
{/block}

View File

@ -6,10 +6,9 @@
<p>
{foreach from=$cur_theme->get_exercices_ordered() item=exercice}
{if $exercice->has_solved($my_team)}
<a class="btn btn-success" role="button" href="/{$SALT_USER}/{$my_team->get_id()}/{$cur_theme->get_id()}-{$cur_theme->get_name()}/{$exercice->get_id()}">{$exercice->get_name()}</a>
{link class="btn btn-success" role="button" href_prefix="/{$SALT_USER}/{$my_team->get_id()}/" href="{$cur_theme->get_id()}-{$cur_theme->get_name()}/{$exercice->get_id()}" label="{$exercice->get_name()}"}
{elseif $exercice->is_unlocked($my_team)}
<a class="btn btn-primary" role="button" href="/{$SALT_USER}/{$my_team->get_id()}/{$cur_theme->get_id()}-{$cur_theme->get_name()}/{$exercice->get_id()}">{$exercice->get_name()}</a>
{link class="btn btn-primary" role="button" href_prefix="/{$SALT_USER}/{$my_team->get_id()}/" href="{$cur_theme->get_id()}-{$cur_theme->get_name()}/{$exercice->get_id()}" label="{$exercice->get_name()}"}
{else}
<a class="btn btn-danger" disabled="disabled">{$exercice->get_name()}</a>
{/if}