-
Notifications
You must be signed in to change notification settings - Fork 1
/
reverse_ottoman_cyrillic.php
112 lines (89 loc) · 3.38 KB
/
reverse_ottoman_cyrillic.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
include("functions.php");
//load the rules text file
//this functin define in functions.php
$rules = get_the_rules("ottoman_cyrillic_rules.txt");
//get metadata information from the $_POST
$title = $_POST['title'];
if(!$title) $htitle = "untitled"; else $htitle = $title;
$author = $_POST['author'];
$date = $_POST['date'];
$responsibility = $_POST['responsibility'];
//check and see if a file was uploaded
if ($_FILES["file"]["error"] > 0) {
$file = false;
} else {
$file = $_FILES["file"]["tmp_name"];
}
//if a file was uploaded, append it to the text area content
if($file != false) {
$input = $_POST['area'] . file_get_contents($file);
} else {
$input = $_POST['area'];
}
//insert a leadind space
$input = " " . $input;
//count the number of tags like <stuff> and store them for later
preg_match_all('/<(.*?)>/', $input, $matches);
//replace all tags with a numbered tag like <1>
for($i = 0; $i < sizeof($matches[0]); $i++) {
#$input = preg_replace('/<(.*?)>/', "<>", $input);
$input = str_replace($matches[0][$i], "<".$i.">", $input);
}
//count the entity references and store them for later
preg_match_all('/&#(.*?);/', $input, $matches2);
//replace the entity references with bracketed number like [1]
for($i = 0; $i < sizeof($matches2[0]); $i++) {
$input = str_replace($matches2[0][$i], "[".$i."]", $input);
}
//remove extraneous space
$input = preg_replace('([[:space:]]+)', " ", $input);
//retrieve the keys from the rules file
$keys = array_keys($rules);
//iterate over the rules and apply them
foreach ($keys as $key) {
$input = str_replace($key, $rules[$key], $input);
}
//get the font size
$size = $_POST['size'];
//the markers for line group breaks and line breaks
$pbreak = strpos($input, "**");
$lbreak = strpos($input, "*");
//if there are both lines and line groups, put <p> around the line <div>
if($pbreak !== false && $lbreak !== false) {
$input = str_replace("**", "</div>\n</p>\n<p>\n<div style=\"font-size:".$size."px\">", $input);
}
//if just lines, put the line in a <div>
if($lbreak !== false) {
$input = str_replace("*", "</div>\n<div style=\"font-size:".$size."px\">", $input);
}
//replace the + with &# to correct the entity references
$input = str_replace("+", "&#", $input);
//put the stored tags back into place
for($i = 0; $i < sizeof($matches[0]); $i++) {
$input = str_replace("<".$i.">", $matches[0][$i], $input);
}
//put the stored entity references back into place
for($i = 0; $i < sizeof($matches2[0]); $i++) {
$input = str_replace("[".$i."]", $matches2[0][$i], $input);
}
//html stuff
echo "<html>\n<head>\n<title>$htitle</title>\n";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"style_cyrillic.css\" />\n";
echo "</head>\n<body>\n";
//use the font size
echo "<div style=\"width:720px;font-size:".$size."px\">\n";
echo "<p>$title<br/>$author<br/>$date<br/>$responsibility</p></br/>\n";
//take care of the various possibilities of line or line group
if($pbreak !== false) { echo "<p>\n"; }
if($lbreak !== false && $pbreak === false) { echo "<p>\n"; }
if($lbreak === false && $pbreak === false) { echo "<p>"; }
if($lbreak !== false) { echo "<div style=\"font-size:".$size."px\">"; }
echo $input;
if($lbreak !== false) { echo "</div>\n"; }
if($lbreak !== false && $pbreak === false) { echo "</p>\n"; }
if($lbreak === false && $pbreak === false) { echo "</p>\n"; }
if($pbreak !== false) { echo "</p>\n"; }
//close up
echo "</div>\n</body>\n</html>";
?>