Zdrojový kód skriptu seznam předložek
Písmo:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-language" content="cs"> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <meta name="keywords" content="seznam předložek, předložka, předložky, zpracování předložek"> <meta name="description" content="Jak sami jistě dobře víte, dle pravidel českého pravopisu předložky nemají co dělat na konci řádku. Nikde v internetu jsem nenašel jejich seznam, a proto jsem si vytvořil vlastní, který využívám ve skriptu, tak aby se měkké mezery za předložkami nahradily tvrdými. Předložka se tak připojí k následujícímu slovu."> <title>Seznam předložek</title> <link rel="stylesheet" href="mainstyle.css" type="text/css"> <style> .stick_preps {border: solid #CCCC99 2px; color: #FFAA00; font-weight: bold} .stick_preps td {border-bottom: solid #CCCC99 2px} </style> </head> <body> <h1>Seznam předložek</h1> <p class="maintext"> Jak sami jistě dobře víte, dle pravidel českého pravopisu předložky nemají co dělat na konci řádku. Nikde v internetu jsem nenašel jejich seznam, a proto jsem si vytvořil vlastní, který využívám ve skriptu, tak aby se měkké mezery za předložkami nahradily tvrdými. Předložka se tak připojí k následujícímu slovu. </p><?php $tab = " " ; function write_text ( $file , $pref = "" , $postf = "" , $row_pref = "" , $row_postf = "" ) { if ( file_exists ( $file )) { if (( $fp = @ fopen ( $file , "r" )) && filesize ( $file )) { echo $pref ; while(! feof ( $fp )) { $row = chop ( fgets ( $fp , filesize ( $file ))); echo $row_pref . $row . $row_postf ; } echo $postf ; return true ; } else return false ; } else return false ; } if (! write_text ( "seznam_predlozek.txt" , "$tab<h4>Základní předložky</h4>\n$tab<p class=\"bold maintext\" style=\"position: relative; left:1em; top: -0.5em;\">\n" , "$tab</p>\n" , "$tab <span style=\"white-space: nowrap\">" , ",</span>\n" )) { echo "<font color=\"red\">Nepodařilo se načíst soubor základních předložek.</font><br>" ; } if ( file_exists ( "pridane_predlozky.txt" ) && ! write_text ( "pridane_predlozky.txt" , "$tab<h4>Přidané předložky</h4>\n$tab<p class=\"bold maintext\" style=\"position: relative; left:1em; top: -0.5em;\">\n" , "$tab</p>\n" , "$tab <span style=\"white-space: nowrap\">" , ",</span>\n" )) { echo "<font color=\"red\">Nepodařilo se načíst soubor základních předložek.</font><br>" ; } if( $_POST [ "prep_post" ] == "Přidej předložku" ) { if( $_POST [ "prep" ]) { if(( $ffpp = fopen ( "./pridane_predlozky.txt" , "a+" )) && ( $ffps = fopen ( "./seznam_predlozek.txt" , "r" ))) { if(! preg_match ( "/\s" . $_POST [ "prep" ]. "\s/iUm" , fread ( $ffps , 102400 ))) { if(! preg_match ( "/\s" . $_POST [ "prep" ]. "\s/iUm" , fread ( $ffpp , 102400 ))) { fwrite ( $ffpp , "\n" . $_POST [ "prep" ]); fclose ( $ffpp ); echo "<font color=\"lime\">Předložka uložena.</font><br>" ; } else { echo "<font color=\"red\">Předložka už existuje v přidaných předložkách !</font><br>" ; } } else { echo "<font color=\"red\">Předložka už existuje v základních předložkách !</font><br>" ; } } else { echo "<font color=\"red\">Nelze otevřít soubor s předložkalmi !</font><br>" ; } } else { echo "<font color=\"red\">Napište prosím předložku, kterou máte v úmyslu přidat.</font><br>" ; } } ?> <script language="javascript" type="text/javascript"> <!-- function validate_forum() { var note = ""; if (forum.forumname.value == "") note = note + " jméno"; if (forum.forumsubject.value == "") note = note + ", předmět"; if (forum.forumtext.value == "") note = note + ", text příspěvku"; if (note) { window.alert("Vyplňte prosím:"+note+"."); return false; } else { window.location.href='/index.php?forum=simpleforum&level=0&ref=1#form'; } } function validate_add_prep() { if (add_prep.prep.value == "") { window.alert("Napište prosím předložku"); return false; } else { window.location.href='/index.php?forum=simpleforum&level=0&ref=1#form'; } } function validate_stick_preps() { if (stick_preps.format_filelocation.value == "") { window.alert("Chybí soubor k formátování"); return false; } else { window.location.href='/index.php?forum=simpleforum&level=0&ref=1#form'; } } --> </script> <form name="add_prep" action="<?php echo $_SERVER [ "REQUEST_URI" ]; ?> " method="post" onSubmit="return validate_add_prep();"> <input type="text" size="25" name="prep"> <input type="submit" name="prep_post" value="Přidej předložku" style="font-weight: bold; margin-top: 5px"> </form> <hr> <h3>Formátování souboru</h3> <style type="text/css"> .nkmex_lime {color: lime;} </style><?php function get_rows ( $file ) { if( file_exists ( $file )) { if( $fp = @ fopen ( $file , "r" )) { if( feof ( $fp ) || ! filesize ( $file )) { $rows [] = chop ( fgets ( $fp , filesize ( $file ))); if(! $rows [ 0 ]) return false ; //Prázdný soubor } else $rows [] = chop ( fgets ( $fp , filesize ( $file ))); while (! feof ( $fp )) { $rows [] = chop ( fgets ( $fp , filesize ( $file ))); } return $rows ; } else return false ; } else return false ; } function get_text ( $file ) { if( file_exists ( $file )) { if( $fp = @ fopen ( $file , "r" )) { if( $text = fread ( $fp , filesize ( $file ))) return $text ; else return false ; } else return false ; } else return false ; } function convert_to_utf_czech ( $str , $encoding ) { $conv_utf = Array( "ě" , "š" , "č" , "ř" , "ť" , "ž" , "ň" , "ď" , "ý" , "á" , "í" , "é" , "ú" , "ů" , "ó" , "Ě" , "Š" , "Č" , "Ř" , "Ž" , "Ť" , "Ň" , "Ď" , "Ý" , "Á" , "Í" , "É" , "Ú" , "Ó" ); if ( $encoding == "windows-1250" ) { return str_replace ( get_rows ( "windows-1250.txt" ), $conv_utf , $str ); //Neznám lepší způsob } elseif ( $encoding == "iso-8859-2" ) { $conv_utf [ 11 ] = "é" ; return str_replace ( get_rows ( "iso-8859-2.txt" ), $conv_utf , $str ); } else { return $str ; } } function convert_all_to_utf_czech ( $str_array , $encoding ) { if ( is_array ( $str_array )) { foreach ( $str_array as $str ) { $new_array [] = convert_to_utf_czech ( $str , $encoding ); } return $new_array ; } else { return convert_to_utf_czech ( $str_array , $encoding ); } } function preg_char ( $str ) { $search = array( "?" , "*" , "+" , "," , "{" , "}" , "[" , "]" , "(" , ")" , "/" ); $replace = array( "\?" , "\*" , "\+" , "\," , "\{" , "\}" , "\[" , "\]" , "\(" , "\)" , "\/" ); return str_replace ( $search , $replace , $str ); } function preg_test_all ( $pattern , $str ) { if( is_array ( $pattern ) && ! is_array ( $str )) { foreach( $pattern as $p ) if( preg_match ( $p , $str )) return true ; } else echo "<font color=\"red\">Fce preg_test_all() ma chybne parametry!</font>" ; return false ; } function format_text ( $text , $preps , $glue , $ignoreHTML = 0 ) { global $highlight_1 ; global $highlight_2 ; if ( $_POST [ "output" ] == "formated_text" ) { $highlight_1 = "<span class=\"nkmex_lime\">" ; $highlight_2 = "</span>" ; } if( is_array ( $preps )) { foreach( $preps as $prep ) { if(! $prep ) continue; $pattern [] = "/(\s+)" . preg_char ( $prep ). "\s+/" ; $pattern [] = "/" . preg_char ( $highlight_1 . $glue . $highlight_2 . $prep ). "\s+/" ; $replace [] = "\\1" . $prep . $highlight_1 . $glue . $highlight_2 ; $replace [] = $highlight_1 . $glue . $highlight_2 . $prep . $highlight_1 . $glue . $highlight_2 ; } } else return 0 ; $text = " " . $text ; //Optimalizace if( $ignoreHTML ) { $non_text_tags = array( "/^script/" , "/^style/" ); if( substr_count ( $text , "<" ) != substr_count ( $text , ">" )) $text = "<font color=\"red\">(x)HTML dokument není validní, formátování proto nemusí být správné</font>\n" . $text ; $tok = strtok ( $text , "<" ); $text = "" ; while ( $tok ) { $ftok = explode ( ">" , $tok ); if( preg_test_all ( $non_text_tags , $ftok [ 0 ])) { $text .= "<" . $tok ; $tok = strtok ( "<" ); continue; } if( $ftok [ 1 ]) { $text .= "<" . $ftok [ 0 ]. ">" ; $ftok [ 1 ] = preg_replace ( $pattern , $replace , " " . $ftok [ 1 ]); $text .= substr ( $ftok [ 1 ], 1 , strlen ( $ftok [ 1 ])); } elseif( strpos ( $tok , ">" ) === false ) { $ftok [ 1 ] = preg_replace ( $pattern , $replace , " " . $tok ); $text .= substr ( $ftok [ 1 ], 1 , strlen ( $ftok [ 1 ])); } else $text .= "<" . $tok ; $tok = strtok ( "<" ); } } else $text = preg_replace ( $pattern , $replace , $text ); return substr ( $text , 1 , strlen ( $text )); } function load_preps ( $encoding ) { if (! $_FILES [ "altpreps_filelocation" ][ "name" ]) { if (! $preps = convert_all_to_utf_czech ( get_rows ( "seznam_predlozek.txt" ), $_POST [ "charset" ])) { echo "<font color=\"#FF0000\"><b> Nepovedlo se přečíst soubor se základními předložkami</b></font><br>" ; } } else { if (! $preps = convert_all_to_utf_czech ( get_rows ( $_FILES [ "altpreps_filelocation" ][ "tmp_name" ]), $_POST [ "charset" ])) { echo "<font color=\"#FF0000\"><b> Nepovedlo se přečíst soubor s alternativními předložkami</b></font><br>" ; } } if ( $_POST [ "added_preps" ]) { if (! $add_preps = convert_all_to_utf_czech ( get_rows ( "pridane_predlozky.txt" ), $_POST [ "charset" ])) { echo "<font color=\"#FF0000\"><b> Nepovedlo se přečíst soubor s přidanými předložkami</b></font><br>" ; } elseif ( $preps [ 0 ]) { foreach ( $add_preps as $prep ) { $preps [] = $prep ; } } else { $preps = $add_preps ; } } if ( $preps [ 0 ]) { $i = 0 ; foreach ( $preps as $prep ) { $preps [] = ucfirst ( $preps [ $i ]); $i ++; } return $preps ; } else { return false ; } } function decode_misc ( $misc ) { if ( $misc == "&nbsp;" ) return " " ; else return $misc ; } if ( $_POST [ "format" ] == "Formatuj" ) { if (( $text = convert_all_to_utf_czech ( get_text ( $_FILES [ "format_filelocation" ][ "tmp_name" ]), $_POST [ "charset" ])) && ( $preps = load_preps ( $_POST [ "charset" ]))) { if ( $_POST [ "ignore_html" ]) { $text = format_text ( $text , $preps , decode_misc ( $_POST [ "glue" ]), 1 ); $formated_file = $text . "\n" ; } else { $text = format_text ( $text , $preps , decode_misc ( $_POST [ "glue" ]), 0 ); $formated_file = $text . "\n" ; } } else { echo "<font color=\"#FF0000\"><b> Nepovedlo se přečíst soubor nebo nahrát předložky</b></font><br>" ; } } ?> <form name="stick_preps" action="<?php echo $_SERVER [ "REQUEST_URI" ]; ?> " method="post" onSubmit="return validate_stick_preps();" enctype="multipart/form-data"> <table class="bold"> <tr> <td align="right">Cesta k souboru: </td> <td> <input type="file" name="format_filelocation"></td> </tr> <tr> <td align="right">Znak za předložkou: </td> <td> <input type="text" size="25" name="glue" value="<?php if ( $_POST [ "glue" ]) echo str_replace ( "&" , "&" , $_POST [ "glue" ]); else echo "&nbsp;" ; ?> "></td> </tr> <tr> <td align="right">Znaková sada: </td> <td> <select name="charset" size="1"> <option value="iso-8859-2">iso-8859-2</option> <option value="windows-1250" <?php if ( $_POST [ "charset" ] == "windows-1250" ) echo "selected" ; ?> >windows-1250</option> <option value="utf-8" <?php if ( $_POST [ "charset" ] == "utf-8" ) echo "selected" ; ?> >utf-8</option> </select> </td> </tr> <tr> <td align="right">Alternativní soubor s předložkami: </td> <td style="white-space: nowrap"> <input type="file" name="altpreps_filelocation"> (1 řádka = 1 předložka)</td> </tr> <tr> <td align="right">Zahrnout přidané předložky: </td> <td> <input type="checkbox" name="added_preps" value="add" <?php if ( $_POST [ "added_preps" ]) echo "checked" ; ?> ></td> </tr> <tr> <td align="right">Ignorovat HTML tagy: </td> <td> <input type="checkbox" name="ignore_html" value="ignore" <?php if ( $_POST [ "ignore_html" ]) echo "checked" ; ?> > (Tagy se nesmí zalamovat)</td> </tr> <tr> <td align="right">Výstup: </td> <td><input type="radio" name="output" value="formated_text" <?php if (!( $_POST [ "output" ] == "textarea" ) ) echo "checked" ; ?> >Zvýrazněný text <input type="radio" name="output" value="textarea" <?php if ( $_POST [ "output" ] == "textarea" ) echo "checked" ; ?> >Textové pole</td> </tr> <tr> <td></td> <td> <input type="submit" name="format" value="Formatuj"> Zformátovámy text se zobrazí pod formulářem</td> </tr> </table> </form><?php function html_ent ( $string ) { return str_replace ( "<" , "<" , str_replace ( ">" , ">" , str_replace ( "&" , "&" , $string ))); } if ( $formated_file ) { if ( $_POST [ "output" ] == "formated_text" ) { $search [] = "&#269;" ; $search [] = "&eacute;" ; $search [] = " " ; $search [] = "\t" ; $search [] = "\r\n" ; $search [] = "\n" ; $search [] = "\r" ; $search [] = "<br>" ; $search [] = str_replace ( " " , " " , html_ent ( $highlight_1 . decode_misc ( $_POST [ "glue" ]). $highlight_2 )); $replace [] = "č" ; $replace [] = "é" ; $replace [] = " " ; $replace [] = " " ; $replace [] = "<br>" ; $replace [] = "<br>" ; $replace [] = "<br>" ; $replace [] = "<br>\n" ; $replace [] = $highlight_1 . html_ent ( decode_misc ( $_POST [ "glue" ])). $highlight_2 ; $formated_file = str_replace ( $search , $replace , html_ent ( $formated_file )); echo "<p class=\"maintext\">\n" . $formated_file . "\n</p>" ; } else { echo "<textarea style=\"width: 99.5%; height: 200px; font-size: 90%; font-weight: bold;\">\n" . html_ent ( $formated_file ). "\n</textarea>\n" ; } } ?> <p class="maintext"> <a href="zdroj_stick_prep.php" target="_blank">Vizte zdrojový kód skriptu</a> </p> <hr><?php if ( $_GET [ "level" ]) { $re = "RE: " . $_GET [ "subject" ]; } if ( $_POST [ "spam" ] == "no" ) { if ( $_POST [ "forumname" ] && $_POST [ "forumsubject" ] && $_POST [ "forumtext" ]) { $forumgetdate = getdate (); $forumdate = $forumgetdate [ "mday" ]. "." . $forumgetdate [ "mon" ]. "." . $forumgetdate [ "year" ]; $level = $_GET [ "level" ]+ 1 ; if ( $_GET [ "level" ] > 5 ) { $level = $_GET [ "level" ]; } $forumtemplate = "<div class=\"forum level$level\">\n" ; $forumtemplate .= " <div class=\"forumhead\">\n" ; $forumtemplate .= " <span class=\"bold\">Od:</span> " . $_POST [ "forumname" ]. "<br>\n" ; $forumtemplate .= " <span class=\"bold\">Datum:</span> " . $forumdate . "<br>\n" ; $forumtemplate .= " <span class=\"bold\">Předmět:</span> " . $_POST [ "forumsubject" ]. "\n" ; $forumtemplate .= " </div>\n" ; $forumtemplate .= " <div class=\"forumtext\">\n" ; $forumtemplate .= " " . html_ent ( str_replace ( "\\" , "" , $_POST [ "forumtext" ])). "\n" ; $forumtemplate .= " <br><div align=\"right\"><a href=\"seznam_predlozek.php?forum=simpleforum&level=$level&subject=" . $_POST [ "forumsubject" ]. "#form\">Odpovědět</a></div>\n" ; $forumtemplate .= " </div>\n" ; $forumtemplate .= "</div>\n" ; if ( $ffp = fopen ( "./forum_predlozky.html" , "a" )) { fwrite ( $ffp , $forumtemplate ); fclose ( $ffp ); } } else { echo "<font color=\"red\">Prosím vyplňte všechna pole.</font><br>" ; } } if (! write_text ( "forum_predlozky.html" , "$tab<div class=\"maintext\">" , "$tab</div>\n" , "$tab" , "\n" )) { echo "<font color=\"red\">Nepodařilo se načíst soubor s komentáři</font><br>" ; } ?> <form name="forum" action="<?php echo $_SERVER [ "REQUEST_URI" ]; ?> " method="post" onSubmit="return testvalues();"> <a name="form"></a> <table class="bold" style="margin-top: 15px"> <tr> <td><h3>Vlož komentář</h3><br></td> </tr> <tr> <td>Jméno:</td> <td><input type="text" size="25" name="forumname"></td> </tr> <tr> <td>Předmět:</td> <td><input type="text" size="25" name="forumsubject" value="<?php echo $re ; ?> "></td> </tr> </table> <textarea rows="30" name="forumtext" id="text" style="width: 99.5%; height: 200px"></textarea> <div align="right"> <input type="submit" name="forumpost" value="Odeslat" style="font-weight: bold; margin-top: 5px"> <input type="hidden" name="spam" value="yes"> </div> </form> <script language="javascript" type="text/javascript"> <!-- document.forum.spam.value = "no"; function testvalues() { var note = ""; if (forum.forumname.value == "") note = note + " jméno"; if (forum.forumsubject.value == "") note = note + ", předmět"; if (forum.forumtext.value == "") note = note + ", text příspěvku"; if (note) { window.alert("Vyplňte prosím:"+note+"."); return false; } else { window.location.href='/index.php?forum=simpleforum&level=0&ref=1#form'; } } --> </script> <a href="http://www.toplist.cz/" target="_top"> <img src="http://toplist.cz/count.asp?id=201140" alt="TOPlist" border="0" style="display: none"></a> <p class="maintext"> <a href="/">Zpět na hlavní stránku</a> </p> </body> </html>
Zpět na skript