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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
<?php
/**
* This file is part of BibORB
*
* Copyright (C) 2003-2008 Guillaume Gardey <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
*
* File: functions.php
*
* Description:
*
* Some generic functions
*/
/**
* load variables and functions
*/
/**
* Upload a file.
* If successful, return the name of the file, otherwise null.
* Overwrite if the file is already present.
*
* @param $bibname The name of the bibliography
* @param $type The ID of the file uploaded.
* @param $id The BibTeX id of the paper.
*
* @return The name of the file uploaded on success. Null otherwise.
*
* @author G. Gardey
*/
function upload_file($bibname,$type,$id)
{
$res = null;
$infofile = pathinfo($_FILES[$type]['name']);
$extension = $infofile['extension'];
$file = $id.'.'.FileToolKit::getAllExtensions($infofile['basename']);
$path = "./bibs/".$bibname."/papers/".$file;
// If file already exists, delete it
if(file_exists($path)){
unlink($path);
}
// upload the file
$is_uploaded = move_uploaded_file($_FILES[$type]["tmp_name"],$path);
// change it to be readable/writable to the owner and readable for others
if($is_uploaded){
chmod($path, 0777 - UMASK );
$res = $file;
}
return $res;
}
/**
* Create the main panel in the BibORB HTML interface.
*
* @author G. Gardey
*/
function main($title,$content,$error = null,$message = null)
{
$html = "<div id='main'>";
if (is_array($error))
{
print_r($error);
if($title != null){$html .= "<h2 id='main_title'>$title</h2>";}
if($error[0] == 0){$html .= "<div id='error'>".$error[1]['error']."</div>";}
if($error[0] == 1){$html .= "<div id='message'>".$error[1]['message']."</div>";}
if($content != null) {$html .= "<div id='content'>$content</div>";}
$html .= "</div>";
}
else
{
print_r($error);
if($title != null){$html .= "<h2 id='main_title'>$title</h2>";}
if($error){$html .= "<div id='error'>$error</div>";}
if($message){$html .= "<div id='message'>$message</div>";}
if($content != null) {$html .= "<div id='content'>$content</div>";}
$html .= "</div>";
}
return '';
// return $html;
}
/**
* Recursively delete a directory.
* @param $dir The name of the directory.
* @author G. Gardey
*/
function deldir($dir) {
$current_dir = opendir($dir);
while($entryname = readdir($current_dir)){
if(is_dir("$dir/$entryname") and ($entryname != "." and $entryname!="..")){
deldir("${dir}/${entryname}");
}
elseif($entryname != "." and $entryname!=".."){
unlink("${dir}/${entryname}");
}
}
closedir($current_dir);
rmdir($dir);
}
/**
* Remove accents of a string.
*/
function remove_accents($string){
return strtr($string,
"¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ",
"YuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy");
}
/**
* Generate the add all to basket div section for the BibORB html interface.
* @param $ids The ids to add in the basket.
* @param $mode The current display mode of BibORB.
* @param $extraparam Some extraparam.
* @author G. Gardey
*/
function add_all_to_basket_div($ids,$mode,$extraparam=null){
$title = msg("Add all entries to the basket.");
$html = "<div class='addtobasket' title='$title'>";
$addalllink = "bibindex.php?mode=$mode&action=add_to_basket&id=";
foreach($ids as $id){
$addalllink .= "$id*";
}
if($extraparam){$addalllink .= "&$extraparam";}
$html .= "<a href='".$addalllink."'>";
$html .= "<img src='./data/images/add.png' alt='add' />";
$html .= "</a>";
$html .= "</div>";
return $html;
}
/**
* Generate a XHTML div containing sort functions.
* @param $selected_sort The sort selected.
* @param $selected_order The sort order selected.
* @param $mode The Biborb current display mode.
* @param $misc An array containing additional values for the form.
*/
function sort_div($iSelectedSort, $iSelectedOrder, $iMode, $iMisc)
{
$aHtml = HtmlToolKit::startTag('div', array('class'=>'sort'));
$aHtml .= msg('Sort by:').' ';
$aHtml .= HtmlToolKit::startTag('form', array('method' => 'get',
'action' => 'bibindex.php'));
$aHtml .= HtmlToolKit::startTag('fieldset');
$aHtml .= HtmlToolKit::selectTag(array('name'=>'sort','size' => 1),
array_combine($_SESSION['bibdb']->getSortMethodValues(),
$_SESSION['bibdb']->getSortMethodValues()),
$iSelectedSort);
$aHtml .= HtmlToolKit::tagNoData('input', array('type' => 'hidden',
'name' => 'mode',
'value' => $iMode));
if ($iMisc)
{
foreach ($iMisc as $aKey => $aVal)
{
$aHtml .= HtmlToolKit::tagNoData('input', array('type' => 'hidden',
'name' => $aKey,
'value'=> $aVal));
}
}
$aHtml .= HtmlToolKit::selectTag( array('name' => 'sort_order'),
array_combine($_SESSION['bibdb']->getSortOrderValues(),
$_SESSION['bibdb']->getSortOrderValues()),
$iSelectedOrder);
$aHtml .= HtmlToolKit::tagNoData('input', array('type' => 'submit',
'value' => msg('Sort')));
$aHtml .= HtmlToolKit::closeTag('fieldset');
$aHtml .= HtmlToolKit::closeTag('form');
$aHtml .= HtmlToolKit::closeTag('div');
return $aHtml;
}
/**
* Analyze a .dot aux file and return an array of bibtex ids
* @param $auxfile A .aux LaTeX file.
* @return An array of BibTeX keys.
*/
function bibtex_keys_from_aux($auxfile){
$lines = file_get_contents($auxfile);
preg_match_all("/citation{(.*)}/i",$lines,$res);
return $res[1];
}
/*
Create the nav bar
*/
function create_nav_bar($current_page,$max_page,$mode,$extraparam=null){
$html = "";
if($max_page>1){
$html .= "<div id='nav_bar'>";
if($extraparam != null){
$extraparam = "&".$extraparam;
}
// left arrows to display if this isn't the first page
if($current_page != 0){
$html .= "<a href='bibindex.php?mode=$mode$extraparam&page=0'><img src='data/images/stock_first-16.png' alt='First' title='First'/></a>";
$html .= "<a href='bibindex.php?mode=$mode$extraparam&page=".($current_page-1)."'><img src='data/images/stock_left-16.png' alt='Previous' title='Previous'/></a>";
}
// computes which index to display
$nb = 10;
if($current_page-$nb<0){
$start_index = 0;
}
else if($current_page==$max_page-1){
$start_index = max($max_page-2*$nb ,0);
}
else{
$start_index = max($current_page - $nb-1,0);
}
// if $start_index is not 0 display dots
if($start_index != 0){
$html .= " ... ";
}
// output the numbered navigation bar
for($i=$start_index;$i<$max_page && $i<$start_index+2*$nb ;$i++){
if($current_page==$i){
$html .= "<a id='current_page' href='bibindex.php?mode=$mode$extraparam&page=$i'>".($i+1)."</a>";
}
else{
$html .= "<a class='num_page' href='bibindex.php?mode=$mode$extraparam&page=$i'>".($i+1)."</a>";
}
}
// if the last page number is not displayed, output dots.
if($i != $max_page){
$html .= " ... ";
}
// right arrows to display if this isn't the last page
if($current_page != $max_page-1){
$html .= "<a href='bibindex.php?mode=$mode$extraparam&page=".($current_page+1)."'><img src='data/images/stock_right-16.png' alt='Next' title='Next'/></a>";
$html .= "<a href='bibindex.php?mode=$mode$extraparam&page=".($max_page-1)."'><img src='data/images/stock_last-16.png' alt='Last' title='Last'/></a>";
}
$html .= "</div>";
}
return $html;
}
?>
|