-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfonctions.php
190 lines (147 loc) · 6.03 KB
/
fonctions.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
/* functions for processing file content and data extraction */
// Text enhancing
function AppliquerStyle($rawText)
{
// echo $rawText.'<br /><hr /><hr />';
/* Application du Style */
//$rawText = stripslashes(nl2br($rawText));
// Check here for Line break issue !
preg_match('~\s*<br ?/?>\s*~',$rawText, $matches);
// echo count($matches).'<br />';
/*$rawText = preg_replace('~\s*<br ?/?>\s*~',"<br />",$rawText); */
// $rawText = nl2br($rawText);
// echo $rawText;
// ===== Publication handling =====
// Full bibliography
$rawText = preg_replace("#\[publicationList\](.+?)\[/publicationList\]#i", "", $rawText); /* Underlining */
// In text citations
$rawText = preg_replace("#\[startCitations file={(.+?)}]#i", "", $rawText); /* Citations */
// $rawText = preg_replace("#\[stopCitations]#i", "tata", $rawText); /* Citations */
// $rawText = preg_replace("#\[cite\](.+?)\[/cite\]#i", "$1", $rawText); /* Citations */
/* Style basique */
$rawText = preg_replace("#\[b\](.+?)\[/b\]#msi", "<strong>$1</strong>", $rawText); /* Bold */
$rawText = preg_replace("#\[i\](.+?)\[/i\]#msi", "<em>$1</em>", $rawText); /* Italic */
$rawText = preg_replace("#\[u\](.+?)\[/u\]#msi", "<u>$1</u>", $rawText); /* Underlining */
// DOes nothing !
$rawText = preg_replace("#\[center\](.+?)\[/center\]#msi", "<span class=\"centered\">$1</span>", $rawText); /* Underlining */
// Implement lists !
/* Balises d'inclusion d'éléments divers */
$rawText = preg_replace("#\[img\](.+?)\[/img\]#i", "<img src=\"$1\" class=\"standardimg\" />", $rawText); /* Remplacement des balises IMAGE */
$rawText = preg_replace("#\[imgmH\](.+?)\[/imgmH\]#i", "<img src=\"$1\" class=\"sizedimgH\" />", $rawText); /* Remplacement des balises IMAGE miniature */
$rawText = preg_replace("#\[imgmV\](.+?)\[/imgmV\]#i", "<img src=\"$1\" class=\"sizedimgV\" />", $rawText); /* Remplacement des balises IMAGE miniature */
$rawText = preg_replace("#\[miniature\](.+?)\[/miniature\]#i","", $rawText);/* Remplacement des balises MINIATURE */
$rawText = str_replace("[link={","<a href=\"",$rawText); /* ouverture de lien */
$rawText = str_replace("} text={","\">",$rawText); /* intermédiaire de lien */
$rawText = str_replace("} /link]","</a>",$rawText); /* fermeture de lien */
$rawText = str_replace("[line]","<hr />",$rawText);
/*--------------------------------------------------------------------------------------------------------------------*/
// echo $rawText;
return $rawText;
}
function extractMetaData($rawText)
{
$gluedText = implode('<br />',$rawText);
preg_match('`\[title\](.+?)\[\/title\]`ms',$gluedText,$titleresult);
preg_match('`\[subtitle](.+?)\[\/subtitle\]`ms',$gluedText,$subtitleresult);
preg_match('`\[menu\](.+?)\[\/menu\]`ms',$gluedText,$menuresult);
preg_match('`\[bottom\](.+?)\[\/bottom\]`ms',$gluedText,$bottomresult);
return array($titleresult[1], $subtitleresult[1], $menuresult[1], $bottomresult[1]);
}
function extractMenu($rawText)
{
preg_match_all('`\[item\](.+?)\[/item\]`msi', $rawText, $splittedmenu);
foreach($splittedmenu[1] as $item)
{
$menuline = explode(',',$item);
$menuline = str_replace(' ', ' ', $menuline);
// echo $menuline[1].'<br />';
$item = implode(',', $menuline);
}
/*foreach($splittedmenu[1] as $item)
{
echo $item.'<br />';
}*/
return $splittedmenu[1];
}
function extractContent($rawText)
{
// $gluedText2 = implode('<br />',$rawText);
/* foreach($rawText as $line)
{
echo 'line : '.$line.'<br />';
} */
$gluedText = implode('<br />',$rawText);
// echo "--".$gluedText."<br />";
// echo "--".$gluedText2."<br />";
preg_match('`\[pagetitle\](.+?)\[\/pagetitle\]`ms',$gluedText,$pagetitleresult);
preg_match('`\[content\](.+?)\[\/content\]`ms',$gluedText,$contentresult);
preg_match('`\[supplementary\](.+?)\[\/supplementary\]`ms',$gluedText,$pagesuppresult);
// echo "--".$pagetitleresult[1]."<br />".$contentresult[1]."<br />".$pagesuppresult[1]."--<br />";
// preg_match('\n', $contentresult[1], $matches);
// echo $matches.' '.count($matches);
return array($pagetitleresult[1],$contentresult[1],$pagesuppresult[1]);
}
function processPublications($rawText)
{
// echo $rawText.'<br /><hr /><hr />';
// Load Lib :
require_once('./phpBibLib/lib/lib_bibtex.inc.php');
// Get pub file :
if( preg_match('`\[publicationList\](.+?)\[\/publicationList\]`ms',$rawText, $publist) )
{
$bibfile = $publist[1];
// Create bib object :
$bib = new Bibtex($bibfile);
// Set Order and Style :
$bib->SetBibliographyOrder('year');
$bib->SetBibliographyStyle('natbib');
$bib->SelectAll();
$bib->PrintBibliography();
}
// echo $rawText;
return $rawText;
}
function processCitations($rawText)
{
// echo $rawText.'<br /><hr /><hr />';
// Load Lib :
require_once('./phpBibLib/lib/lib_bibtex.inc.php');
// Get pub file :
preg_match('`\[startCitations file={(.+?)}\]`ms',$rawText, $reffile);
$bibfile = $reffile[1];
//echo 'Used file = '.$bibfile.'<br />';
// Create bib object :
$bib = new Bibtex($bibfile);
// Set Order and Style :
//$bib->SetBibliographyStyle('natbib');
$bib->SetBibliographyStyle('numeric');
$bib->SetBibliographyOrder('usage');
preg_match_all('`\[cite\](.+?)\[\/cite\]`ms',$rawText, $citations);
$citationNb = 0;
foreach($citations[1] as $elem)
{
// echo $elem.'<br />';
ob_start();
cite($bib, $elem);
// Cheating with the lib : we get the output of the cite command to replace the [cite][/cite] with
$output[$citationNb] = ob_get_clean();
$citationNb++;
//cite($bib, $elem);
// $rawText = preg_replace('`\[cite\](.+?)\[\/cite\]`ms', cite($bib, $elem), $rawText);
}
for($cit = 0 ; $cit < count($output) ; $cit++)
{
// echo $citations[0][$cit].' : '.$output[$cit].'<br />';
$rawText = str_replace($citations[0][$cit], $output[$cit], $rawText);
// echo 'Count of rep : '. $count.'<br />';
}
ob_start();
$bib->PrintBibliography();
// Cheating with the lib : we get the output of the cite command to replace the [cite][/cite] with
$biblioCited = ob_get_clean();
$rawText = str_replace('[stopCitations]', $biblioCited, $rawText);
// echo $rawText;
return $rawText;
}
?>