$max)
{ if(isset($legende))
{ $navig .=
$legende." ".($current + 1)." à "
.(($current + $max) > $total ? $total : $current + $max)
." sur ".$total." - aller à la ";
}
$get_params = array();
if(($q = strpos($base_url, "?")) !== false)
{ $v_query = explode("&", substr($base_url, $q + 1));
$base_url = substr($base_url, 0, $q);
foreach($v_query as $query)
{ if($query)
{ $v = explode("=", $query);
$get_params[$v[0]] = $v[1];
}
}
}
if(isset($get_params[$start_param])) unset($get_params[$start_param]);
$base_url .= "?";
foreach($get_params as $key => $value) $base_url .= $key."=".$value."&";
$nb_pages = ceil($total / $max);
$navig .=
"page : "
."\n";
if($current >= $max)
{ $navig .=
" <<\n";
}
if($current < $total - $max)
{ $navig .=
" >>\n";
}
}
return $navig;
}
function order_link($env, $text, $order_by, $base_url)
{ $get_params = array();
if(($q = strpos($base_url, "?")) !== false)
{ $v_query = explode("&", substr($base_url, $q + 1));
$base_url = substr($base_url, 0, $q);
foreach($v_query as $query)
{ if($query)
{ $v = explode("=", $query);
$get_params[$v[0]] = $v[1];
}
}
}
if(isset($get_params[$env->param("order_by")])) unset($get_params[$env->param("order_by")]);
if(isset($get_params[$env->param("order")])) unset($get_params[$env->param("order")]);
$base_url .= "?";
foreach($get_params as $key => $value) $base_url .= $key."=".$value."&";
if(substr($base_url, -1) === "&") $base_url = substr($base_url, 0, -1);
$order_params = "";
$order_img = "";
if($order_by === $env->order_by)
{ if($env->order === "ASC")
{ $order_params = $env->param("order_by")."=".$order_by."&".$env->param("order")."=DESC";
$order_img = "";
}
elseif($env->order === "DESC")
{ $order_img = "";
}
}
else
{ $order_params = $env->param("order_by")."=".$order_by."&".$env->param("order")."=ASC";
}
return "".$text." ".$order_img;
}
function is_date($date)
{ return ereg("^[0-9][0-9][0-9][0-9]-[0-9]{1,2}-[0-9]{1,2}$", $date);
}
function is_num($num)
{ $num = str_replace(array(",", " "), array(".", ""), $num);
$v_num = explode(".", $num);
if(count($v_num) > 2) return false;
$OK = true;
for($n = 0; $n < count($v_num) && $OK; $n++) $OK = ereg("^[0-9]+$", $v_num[$n]);
return $OK ? $num : false;
}
function date_texte($moment)
{ $moment = explode("-", $moment);
return jour_semaine($moment[0], $moment[1], $moment[2])." ".(0 + $moment[0])." ".mois(0 + $moment[1])." ".$moment[2];
}
function jour_semaine($jour, $mois, $annee)
{ switch(date("N", mktime(1, 0, 0, 0 + $mois, 0 + $jour, 0 + $annee)))
{ case 1: return "lundi";
case 2: return "mardi";
case 3: return "mercredi";
case 4: return "jeudi";
case 5: return "vendredi";
case 6: return "samedi";
case 7: return "dimanche";
}
}
function mois($mois)
{ switch($mois)
{ case 1: return "janvier";
case 2: return "fevrier";
case 3: return "mars";
case 4: return "avril";
case 5: return "mai";
case 6: return "juin";
case 7: return "juillet";
case 8: return "août";
case 9: return "septembre";
case 10: return "octobre";
case 11: return "novembre";
case 12: return "decembre";
}
return "?";
}
function resume($content, $n)
{ if($n)
{ $v_content = explode(" ", $content);
if(count($v_content) > $n)
{ $_content = "";
for($i = 0; $i <= $n; $i++) $_content .= $v_content[$i]." ";
return $_content." (...)";
}
}
return $content;
}
function js_str($content)
{ return str_replace
( array("\"", "\r", "\n"),
array("\\\"", "\\r", "\\n"),
$content
);
}
function js_str_nocrlf($content)
{ return str_replace
( array("\"", "\r", "\n"),
array("\\\"", " ", " "),
$content
);
}
function img_size($file, $max_width, $max_height)
{ $img_infos = @getimagesize($file);
$img_size = array();
if($img_infos)
{ if($img_infos[0] > $max_width || $img_infos[1] > $max_height)
{ $r = $max_width / $img_infos[0];
if($r * $img_infos[1] > $max_height) $r = $max_height / $img_infos[1];
return array
( "width" => floor($r * $img_infos[0]),
"height" => floor($r * $img_infos[1])
);
}
return array
( "width" => $img_infos[0],
"height" => $img_infos[1]
);
}
return false;
}
?>