X-Git-Url: http://git.jankratochvil.net/?a=blobdiff_plain;f=common.php;h=d66927fbaa3ccd1f1e5240f7a2ff07086cd46f2c;hb=b6706dbfce855578ede6abdc3a810f17c81d61f7;hp=449c87badcee8208ded289c8f2686f10fcd5ab7e;hpb=9d53c04df0bcadbe77e0711f4eff06d5ff29b572;p=www.energie.vellum.cz.git diff --git a/common.php b/common.php index 449c87b..d66927f 100644 --- a/common.php +++ b/common.php @@ -10,7 +10,7 @@ $cvs_id_split=split(" ",$cvs_id); if (count($cvs_id_split)==8) { $cvs_id_split[1]="".$cvs_id_split[1].""; - $cvs_id_split[5]="".$cvs_id_split[5].""; + $cvs_id_split[5]="".$cvs_id_split[5].""; } $cvs_id_html=join(" ",$cvs_id_split); @@ -19,12 +19,15 @@ if (isset($detect_js) && !$have_js) $head.=''."\n"; - $user_agent=$HTTP_SERVER_VARS["HTTP_USER_AGENT"]; + $user_agent=(!isset($HTTP_SERVER_VARS["HTTP_USER_AGENT"]) ? "" : $HTTP_SERVER_VARS["HTTP_USER_AGENT"]); if (ereg("[[:<:]]MSIE ([0-9]+)\\.",$user_agent,$msie_major_a)) $msie_major=$msie_major_a[1]; else if (ereg("[[:<:]]Mozilla/([0-9]+)\\.",$user_agent,$mozilla_major_a)) $mozilla_major=$mozilla_major_a[1]; + $have_style=!isset($mozilla_major) || $mozilla_major!=4; + $have_css=true; // doesn't hurt anybody AFAIK + function addpercents($url) { $r=$c=""; @@ -40,7 +43,7 @@ function fatal($msg="UNKNOWN") { global $admin_mail; - print("\n

Nastala chyba pøi zpracování: $msg!

\n" + print("\n

 
 


Nastala chyba pøi zpracování: $msg!

\n" ."

Mù¾ete tento problém nahlásit správci tohoto webu.

\n"); footer(); } @@ -102,31 +105,63 @@ function db_row($query) return($r); } +function db_array($query) +{ + $q=db_query($query); + $r=mysql_fetch_array($q); + mysql_free_result($q); + return($r); +} + function db_item($query) { $row=db_row($query); return($row[0]); } -function month_a($year,$month,$month_last=0) +function num2greg($num) { - global $tb_obsah; + $r=""; + $vals=array(1=>"I",5=>"V",10=>"X",50=>"L",100=>"C",500=>"D",1000=>"M"); + krsort($vals,SORT_NUMERIC); + foreach($vals as $val=>$sym) { + while ($num<0 && $num+$val<-$num) { + $r=substr($r,0,-1).$sym.substr($r,-1,1); + $num+=$val; + } + while (10*$num>=8*$val+(substr($val,0,1)=="1")) { + $r=$r.$sym; + $num-=$val; + } + } + return($r); +} + +function month_a($year,$month,$month_last=0,$sequential=0) +{ + global $tb_obsah,$obsah_year_base; - if (!$month_last) - $month_last=db_item("select month_last from $tb_obsah where year='$year' and month='$month'"); + if (!$month_last || !$sequential) + list($month_last,$sequential)=db_row("select month_last,sequential from $tb_obsah where year='$year' and month='$month'"); $month_full=sprintf("%02d".($month==$month_last ? "" : "-%02d"),$month,$month_last); $r=array("year"=>$year,"month"=>$month,"month_last"=>$month_last,"month_full"=>$month_full, - "name"=>"$month".($month==$month_last ? "" : "-$month_last")."/$year", + "name"=>"$month" .($month==$month_last ? "" : "-$month_last")."/$year", "img" =>"img/eap-$year-${month_full}.jpeg", "icon"=>"img/eap-$year-${month_full}s.jpeg", ); + $r["name_full"]=$r["name"] + ." ($sequential".($month==$month_last ? "" : "-".($sequential+$month_last-$month)).")" + ." - ".num2greg($year-$obsah_year_base+1).". roèník"; return($r); } function img_size($width,$height) { - return("style=\"border:0;width:${width}px;height:${height}px\" width=\"$width\" height=\"$height\""); + global $have_style; + + return(($have_style ? "style=\"border:0;width:${width}px;height:${height}px\"" : "border=\"0\"") + ." width=\"$width\" height=\"$height\""); } function img($file,$alt,$attrs="") @@ -161,7 +196,7 @@ function title_name($year,$month) { if (isset($year) && isset($month)) { $month_a=month_a($year,$month); - return("Èíslo ".$month_a["name"]); + return("Èíslo ".$month_a["name_full"]); } else if (isset($year)) return("Roèník $year"); @@ -181,13 +216,16 @@ function title_month($year,$month) ); } -function title_icons_table_month($year,$month,$month_last) +function title_icons_table_month($year,$month,$month_last,$sequential) { - $month_a=month_a($year,$month,$month_last); + global $tb_clanek; + + $month_a=month_a($year,$month,$month_last,$sequential); print("" - .img($month_a["icon"],"titulní stránka ".$month_a["name"])."
" - ."obsah ".$month_a["name"]."" - ); + .img($month_a["icon"],"titulní stránka ".$month_a["name_full"])."
" + ."obsah ".$month_a["name"].""); + if (db_item("select count(*) from $tb_clanek where year=$year and month=$month")) + print("
ukázka èlánkù"); } function title_icons($year,$month) @@ -195,12 +233,12 @@ function title_icons($year,$month) global $tb_obsah; print("

" - .(isset($year) ? "" : "") + .(isset($year) ? "" : "") .title_name(&$year,&$month) .(isset($year) ? "" : "") ."

\n"); - $result=db_query("select year,month,month_last from $tb_obsah" + $result=db_query("select year,month,month_last,sequential from $tb_obsah" .(isset($year) || isset($month) ? " where" : "") .(isset($year ) ? " year=$year" : "") .(isset($year) && isset($month) ? " and" : "") @@ -224,7 +262,7 @@ function title_icons($year,$month) $year=$row["year"]; print("" - .(!isset($wanted_year) ? "

 

" : "") + .(!isset($wanted_year) ? "

 

" : "") ."
\n" ."\n" ); @@ -243,10 +281,10 @@ function title_icons($year,$month) print(""); $month++; } - print("\n"); $month=$row["month_last"]; } @@ -266,6 +304,8 @@ function image_supported($mime) { global $HTTP_SERVER_VARS; + if (!isset($HTTP_SERVER_VARS["HTTP_ACCEPT"])) + return(false); $exp=explode(",",$HTTP_SERVER_VARS["HTTP_ACCEPT"]); while (($s=array_shift($exp))) { $s=trim(ereg_replace(";.*","",$s)); @@ -275,7 +315,31 @@ function image_supported($mime) return(false); } -function footer() +// PHP dirname() is broken: ("/1/2/3"=>"/1/2", "/1"->"/") +function dirnameslashed($filename) +{ + $r=dirname($filename); + if (substr($r,-1)!="/") + $r.="/"; + return($r); +} + +function usersize($size) +{ + $suffix_a=array("","k","M","G","T"); + while ($size>=1000 && sizeof($suffix_a)>=2) { + $size/=1000; + array_shift($suffix_a); + } + return(round($size)." ".$suffix_a[0]."B"); +} + +function data_href($filename,$text) +{ + return("$text (".usersize(filesize($filename)).")"); +} + +function footer($delimit=true) { // deadlock prevention: global $footer_passed; @@ -284,20 +348,22 @@ function footer() $footer_passed=true; global $cvs_id_html,$viewcvs,$viewcvs,$HTTP_SERVER_VARS; + if ($delimit) + print("

 

\n"); + $uri="uri=".addpercents("http://".$HTTP_SERVER_VARS["HTTP_HOST"].$HTTP_SERVER_VARS["REQUEST_URI"]); ?> -

 


Roèník $year (obsahy èísel)
"); - title_icons_table_month($year,$row["month"]+1,$row["month_last"]+1); + title_icons_table_month($year,$row["month"]+1,$row["month_last"]+1,$row["sequential"]); print("
alt="Valid XHTML 1.0!" />"> alt="Valid XHTML 1.1!" /> alt="Valid CSS!" />
- =4) - print(''."\n"); + print(''."\n"); ?> - - + + Energie & peníze<?php if (isset($title_tail)) - print(": $title_tail"); -?> -\n"); + if (isset($head_css)) + print(trim($head_css)."\n"); + print("-->\n"); + } if (isset($head)) print($head); print("\n"); + if ($title) + print("

" + .img("img/eap-title.".(image_supported("image/png") ? "png" : "gif"),"Energie & Peníze") + ."

\n"); } ?>