Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 350 lines (337 sloc) 14.018 kb
a7096dda » jakubvrana
2007-07-16 Separate editing functions
1 <?php
471ae2b2 » jakubvrana
2009-09-13 Move select function
2 /** Print select result
3 * @param Min_Result
4 * @param Min_DB connection to examine indexes
5 * @return null
6 */
64d616c0 » jakubvrana
2009-09-22 Rename get_dbh to connection
7 function select($result, $connection2 = null) {
782921b6 »
2010-05-27 Finish SQLite
8 $links = array(); // colno => orgtable - create links from these columns
9 $indexes = array(); // orgtable => array(column => colno) - primary keys
10 $columns = array(); // orgtable => array(column => ) - not selected columns in primary key
11 $blobs = array(); // colno => bool - display bytes for blobs
12 $types = array(); // colno => type - display char in <code>
13 odd(''); // reset odd for each result
14 for ($i=0; $row = $result->fetch_row(); $i++) {
15 if (!$i) {
16 echo "<table cellspacing='0' class='nowrap'>\n";
17 echo "<thead><tr>";
18 for ($j=0; $j < count($row); $j++) {
19 $field = $result->fetch_field();
20 $orgtable = $field->orgtable;
21 $orgname = $field->orgname;
22 if ($orgtable != "") {
23 if (!isset($indexes[$orgtable])) {
24 // find primary key in each table
25 $indexes[$orgtable] = array();
26 foreach (indexes($orgtable, $connection2) as $index) {
27 if ($index["type"] == "PRIMARY") {
28 $indexes[$orgtable] = array_flip($index["columns"]);
29 break;
471ae2b2 » jakubvrana
2009-09-13 Move select function
30 }
31 }
782921b6 »
2010-05-27 Finish SQLite
32 $columns[$orgtable] = $indexes[$orgtable];
471ae2b2 » jakubvrana
2009-09-13 Move select function
33 }
782921b6 »
2010-05-27 Finish SQLite
34 if (isset($columns[$orgtable][$orgname])) {
35 unset($columns[$orgtable][$orgname]);
36 $indexes[$orgtable][$orgname] = $j;
37 $links[$j] = $orgtable;
471ae2b2 » jakubvrana
2009-09-13 Move select function
38 }
39 }
782921b6 »
2010-05-27 Finish SQLite
40 if ($field->charsetnr == 63) { // 63 - binary
41 $blobs[$j] = true;
42 }
43 $types[$j] = $field->type;
44 echo "<th" . ($orgtable != "" || $field->name != $orgname ? " title='" . h(($orgtable != "" ? "$orgtable." : "") . $orgname) . "'" : "") . ">" . h($field->name);
471ae2b2 » jakubvrana
2009-09-13 Move select function
45 }
782921b6 »
2010-05-27 Finish SQLite
46 echo "</thead>\n";
47 }
48 echo "<tr" . odd() . ">";
49 foreach ($row as $key => $val) {
50 if (!isset($val)) {
51 $val = "<i>NULL</i>";
52 } else {
53 if ($blobs[$key] && !is_utf8($val)) {
54 $val = "<i>" . lang('%d byte(s)', strlen($val)) . "</i>"; //! link to download
55 } elseif (!strlen($val)) { // strlen - SQLite can return int
56 $val = "&nbsp;"; // some content to print a border
471ae2b2 » jakubvrana
2009-09-13 Move select function
57 } else {
782921b6 »
2010-05-27 Finish SQLite
58 $val = h($val);
59 if ($types[$key] == 254) { // 254 - char
60 $val = "<code>$val</code>";
471ae2b2 » jakubvrana
2009-09-13 Move select function
61 }
782921b6 »
2010-05-27 Finish SQLite
62 }
63 if (isset($links[$key]) && !$columns[$links[$key]]) {
64 $link = "edit=" . urlencode($links[$key]);
65 foreach ($indexes[$links[$key]] as $col => $j) {
66 $link .= "&where" . urlencode("[" . bracket_escape($col) . "]") . "=" . urlencode($row[$j]);
471ae2b2 » jakubvrana
2009-09-13 Move select function
67 }
782921b6 »
2010-05-27 Finish SQLite
68 $val = "<a href='" . h(ME . $link) . "'>$val</a>";
471ae2b2 » jakubvrana
2009-09-13 Move select function
69 }
70 }
782921b6 »
2010-05-27 Finish SQLite
71 echo "<td>$val";
471ae2b2 » jakubvrana
2009-09-13 Move select function
72 }
73 }
782921b6 »
2010-05-27 Finish SQLite
74 echo ($i ? "</table>" : "<p class='message'>" . lang('No rows.')) . "\n";
471ae2b2 » jakubvrana
2009-09-13 Move select function
75 }
76
1118566a » jakubvrana
2009-10-23 Documentation
77 /** Get referencable tables with single column primary key except self
78 * @param string
79 * @return array ($table_name => $field)
80 */
ced9de9d » jakubvrana
2009-07-02 Create single column foreign key in table structure
81 function referencable_primary($self) {
82 $return = array(); // table_name => field
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
83 foreach (table_status() as $table_name => $table) {
84 if ($table_name != $self && fk_support($table)) {
ced9de9d » jakubvrana
2009-07-02 Create single column foreign key in table structure
85 foreach (fields($table_name) as $field) {
86 if ($field["primary"]) {
87 if ($return[$table_name]) { // multi column primary key
88 unset($return[$table_name]);
89 break;
90 }
91 $return[$table_name] = $field;
92 }
93 }
94 }
95 }
96 return $return;
97 }
98
d6ac5f1a »
2010-07-13 Move textarea function to editing.*
99 /** Print SQL <textarea> tag
100 * @param string
101 * @param int
102 * @param int
103 * @param string
104 * @return null
105 */
106 function textarea($name, $value, $rows = 10, $cols = 80) {
644c355d »
2010-10-17 Send the form by Ctrl+Enter in all textareas
107 echo "<textarea name='$name' rows='$rows' cols='$cols' style='width: 98%;' spellcheck='false' onkeydown='return textareaKeydown(this, event, true);'>" . h($value) . "</textarea>"; // spellcheck - not valid before HTML5
d6ac5f1a »
2010-07-13 Move textarea function to editing.*
108 }
109
1118566a » jakubvrana
2009-10-23 Documentation
110 /** Print table columns for type edit
111 * @param string
112 * @param array
113 * @param array
114 * @param array returned by referencable_primary()
115 * @return null
116 */
ced9de9d » jakubvrana
2009-07-02 Create single column foreign key in table structure
117 function edit_type($key, $field, $collations, $foreign_keys = array()) {
b0d637b6 »
2010-10-13 Avoid fatal errors
118 global $structured_types, $types, $unsigned, $on_actions;
f2813b57 » jakubvrana
2008-03-20 Don't hide/show added/dropped columns (bug 1920167)
119 ?>
6e2a887f »
2010-05-27 Typos
120 <td><select name="<?php echo $key; ?>[type]" class="type" onfocus="lastType = selectValue(this);" onchange="editingTypeChange(this);"><?php echo optionlist((!$field["type"] || isset($types[$field["type"]]) ? array() : array($field["type"])) + $structured_types + ($foreign_keys ? array(lang('Foreign keys') => $foreign_keys) : array()), $field["type"]); ?></select>
3a76704f » jakubvrana
2010-02-19 Spaces
121 <td><input name="<?php echo $key; ?>[length]" value="<?php echo h($field["length"]); ?>" size="3" onfocus="editingLengthFocus(this);"><td><?php
5cac902d » jakubvrana
2009-10-06 Work with default values
122 echo "<select name='$key" . "[collation]'" . (ereg('(char|text|enum|set)$', $field["type"]) ? "" : " class='hidden'") . '><option value="">(' . lang('collation') . ')' . optionlist($collations, $field["collation"]) . '</select>';
dc4fc82d »
2010-05-20 ON DELETE action for foreign keys in Create table
123 echo ($unsigned ? "<select name='$key" . "[unsigned]'" . (!$field["type"] || ereg('(int|float|double|decimal)$', $field["type"]) ? "" : " class='hidden'") . '><option>' . optionlist($unsigned, $field["unsigned"]) . '</select>' : '');
124 echo ($foreign_keys ? "<select name='$key" . "[on_delete]'" . (ereg("`", $field["type"]) ? "" : " class='hidden'") . "><option value=''>(" . lang('ON DELETE') . ")" . optionlist($on_actions, $field["on_delete"]) . "</select> " : " "); // space for IE
a7096dda » jakubvrana
2007-07-16 Separate editing functions
125 }
126
1118566a » jakubvrana
2009-10-23 Documentation
127 /** Filter length value including enums
128 * @param string
129 * @return string
130 */
f93c84e4 » jakubvrana
2009-07-27 Function process_length used only in Adminer
131 function process_length($length) {
132 global $enum_length;
133 return (preg_match("~^\\s*(?:$enum_length)(?:\\s*,\\s*(?:$enum_length))*\\s*\$~", $length) && preg_match_all("~$enum_length~", $length, $matches) ? implode(",", $matches[0]) : preg_replace('~[^0-9,+-]~', '', $length));
134 }
135
1118566a » jakubvrana
2009-10-23 Documentation
136 /** Create SQL string from field type
137 * @param array
138 * @param string
139 * @return string
140 */
a3c969c0 » jakubvrana
2007-07-17 Routines uses CHARACTER SET
141 function process_type($field, $collate = "COLLATE") {
7e644b43 »
2010-10-13 Save bytes ($connection->quote shortcut)
142 global $unsigned;
9e1d1c35 »
2010-05-25 Respect unsupported types
143 return " $field[type]"
4780703d »
2010-05-21 Respect PostgreSQL custom types
144 . ($field["length"] != "" ? "(" . process_length($field["length"]) . ")" : "")
5abd943c » jakubvrana
2009-07-13 Change simple preg_match to ereg
145 . (ereg('int|float|double|decimal', $field["type"]) && in_array($field["unsigned"], $unsigned) ? " $field[unsigned]" : "")
7e644b43 »
2010-10-13 Save bytes ($connection->quote shortcut)
146 . (ereg('char|text|enum|set', $field["type"]) && $field["collation"] ? " $collate " . q($field["collation"]) : "")
a7096dda » jakubvrana
2007-07-16 Separate editing functions
147 ;
148 }
149
1118566a » jakubvrana
2009-10-23 Documentation
150 /** Create SQL string from field
151 * @param array basic field information
152 * @param array information about field type
9e1d1c35 »
2010-05-25 Respect unsupported types
153 * @return array array("field", "type", "NULL", "DEFAULT", "ON UPDATE", "COMMENT", "AUTO_INCREMENT")
1118566a » jakubvrana
2009-10-23 Documentation
154 */
2e680bc9 » jakubvrana
2009-09-09 Speedup of simple alter table
155 function process_field($field, $type_field) {
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
156 return array(
157 idf_escape($field["field"]),
158 process_type($type_field),
159 ($field["null"] ? " NULL" : " NOT NULL"), // NULL for timestamp
7e644b43 »
2010-10-13 Save bytes ($connection->quote shortcut)
160 (isset($field["default"]) ? " DEFAULT " . ($field["type"] == "timestamp" && eregi("^CURRENT_TIMESTAMP$", $field["default"]) ? $field["default"] : q($field["default"])) : ""),
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
161 ($field["on_update"] ? " ON UPDATE $field[on_update]" : ""),
7e644b43 »
2010-10-13 Save bytes ($connection->quote shortcut)
162 (support("comment") && $field["comment"] != "" ? " COMMENT " . q($field["comment"]) : ""),
736d6e43 »
2010-05-05 Fix alter table
163 ($field["auto_increment"] ? auto_increment() : null),
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
164 );
2e680bc9 » jakubvrana
2009-09-09 Speedup of simple alter table
165 }
166
1118566a » jakubvrana
2009-10-23 Documentation
167 /** Get type class to use in CSS
168 * @param string
169 * @return string class=''
170 */
3015aed7 » jakubvrana
2009-07-14 Separate type_class
171 function type_class($type) {
d144e9c3 » jakubvrana
2009-09-19 Save bytes
172 foreach (array(
173 'char' => 'text',
174 'date' => 'time|year',
175 'binary' => 'blob',
176 'enum' => 'set',
177 ) as $key => $val) {
c0c7ab3c » jakubvrana
2009-09-19 Typo
178 if (ereg("$key|$val", $type)) {
d144e9c3 » jakubvrana
2009-09-19 Save bytes
179 return " class='$key'";
180 }
3015aed7 » jakubvrana
2009-07-14 Separate type_class
181 }
182 }
183
1118566a » jakubvrana
2009-10-23 Documentation
184 /** Print table interior for fields editing
185 * @param array
186 * @param array
187 * @param string TABLE or PROCEDURE
188 * @param int number of fields allowed by Suhosin
189 * @param array returned by referencable_primary()
190 * @return bool column comments used
191 */
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
192 function edit_fields($fields, $collations, $type = "TABLE", $allowed = 0, $foreign_keys = array(), $comments = false) {
d31d4e9e » jakubvrana
2009-07-28 Emulate REQUEST_URI
193 global $inout;
540e2174 » jakubvrana
2009-05-29 Separate JavaScript
194 foreach ($fields as $field) {
7352c281 » jakubvrana
2010-01-09 Replace strlen() by != ""
195 if ($field["comment"] != "") {
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
196 $comments = true;
1118566a » jakubvrana
2009-10-23 Documentation
197 break;
540e2174 » jakubvrana
2009-05-29 Separate JavaScript
198 }
199 }
f2813b57 » jakubvrana
2008-03-20 Don't hide/show added/dropped columns (bug 1920167)
200 ?>
dfe25403 » jakubvrana
2010-01-28 Centralize nowrap
201 <thead><tr class="wrap">
b3496120 » jakubvrana
2009-08-25 Remove useless translations
202 <?php if ($type == "PROCEDURE") { ?><td>&nbsp;<?php } ?>
ace55ed1 » jakubvrana
2009-07-11 HTML instead of XHTML
203 <th><?php echo ($type == "TABLE" ? lang('Column name') : lang('Parameter name')); ?>
3a76704f » jakubvrana
2010-02-19 Spaces
204 <td><?php echo lang('Type'); ?><textarea id="enum-edit" rows="4" cols="12" wrap="off" style="display: none;" onblur="editingLengthBlur(this);"></textarea>
ace55ed1 » jakubvrana
2009-07-11 HTML instead of XHTML
205 <td><?php echo lang('Length'); ?>
206 <td><?php echo lang('Options'); ?>
a7096dda » jakubvrana
2007-07-16 Separate editing functions
207 <?php if ($type == "TABLE") { ?>
b3496120 » jakubvrana
2009-08-25 Remove useless translations
208 <td>NULL
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
209 <td><input type="radio" name="auto_increment_col" value=""><acronym title="<?php echo lang('Auto Increment'); ?>">AI</acronym>
4cead560 » jakubvrana
2009-08-21 Edit default values directly in table creation
210 <td class="hidden"><?php echo lang('Default values'); ?>
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
211 <?php echo (support("comment") ? "<td" . ($comments ? "" : " class='hidden'") . ">" . lang('Comment') : ""); ?>
a7096dda » jakubvrana
2007-07-16 Separate editing functions
212 <?php } ?>
da8a1b66 » jakubvrana
2010-05-05 Respect move and drop column support
213 <td><?php echo "<input type='image' name='add[" . (support("move_col") ? 0 : count($fields)) . "]' src='../adminer/static/plus.gif' alt='+' title='" . lang('Add next') . "'>"; ?><script type="text/javascript">row_count = <?php echo count($fields); ?>;</script>
ace55ed1 » jakubvrana
2009-07-11 HTML instead of XHTML
214 </thead>
a7096dda » jakubvrana
2007-07-16 Separate editing functions
215 <?php
93c27c95 » jakubvrana
2007-07-16 Separate type_change()
216 foreach ($fields as $i => $field) {
217 $i++;
da8a1b66 » jakubvrana
2010-05-05 Respect move and drop column support
218 $orig = $field[($_POST ? "orig" : "field")];
219 $display = (isset($_POST["add"][$i-1]) || (isset($field["field"]) && !$_POST["drop_col"][$i])) && (support("drop_col") || $orig == "");
93c27c95 » jakubvrana
2007-07-16 Separate type_change()
220 ?>
a76c555b » jakubvrana
2009-06-11 Remove odd() from create
221 <tr<?php echo ($display ? "" : " style='display: none;'"); ?>>
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
222 <?php echo ($type == "PROCEDURE" ? "<td>" . html_select("fields[$i][inout]", $inout, $field["inout"]) : ""); ?>
da8a1b66 » jakubvrana
2010-05-05 Respect move and drop column support
223 <th><?php if ($display) { ?><input name="fields[<?php echo $i; ?>][field]" value="<?php echo h($field["field"]); ?>" onchange="<?php echo ($field["field"] != "" || count($fields) > 1 ? "" : "editingAddRow(this, $allowed); "); ?>editingNameChange(this);" maxlength="64"><?php } ?><input type="hidden" name="fields[<?php echo $i; ?>][orig]" value="<?php echo h($orig); ?>">
ced9de9d » jakubvrana
2009-07-02 Create single column foreign key in table structure
224 <?php edit_type("fields[$i]", $field, $collations, $foreign_keys); ?>
a7096dda » jakubvrana
2007-07-16 Separate editing functions
225 <?php if ($type == "TABLE") { ?>
6b30cfa7 » jakubvrana
2009-09-25 Separate checkbox
226 <td><?php echo checkbox("fields[$i][null]", 1, $field["null"]); ?>
b79a28f6 »
2010-06-08 Link table names in SQL queries
227 <td><input type="radio" name="auto_increment_col" value="<?php echo $i; ?>"<?php if ($field["auto_increment"]) { ?> checked<?php } ?> onclick="var field = this.form['fields[' + this.value + '][field]']; if (!field.value) { field.value = 'id'; field.onchange(); }">
dfe25403 » jakubvrana
2010-01-28 Centralize nowrap
228 <td class="hidden"><?php echo checkbox("fields[$i][has_default]", 1, $field["has_default"]); ?><input name="fields[<?php echo $i; ?>][default]" value="<?php echo h($field["default"]); ?>" onchange="this.previousSibling.checked = true;">
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
229 <?php echo (support("comment") ? "<td" . ($comments ? "" : " class='hidden'") . "><input name='fields[$i][comment]' value='" . h($field["comment"]) . "' maxlength='255'>" : ""); ?>
a7096dda » jakubvrana
2007-07-16 Separate editing functions
230 <?php } ?>
231 <?php
da8a1b66 » jakubvrana
2010-05-05 Respect move and drop column support
232 echo "<td>";
233 echo (support("move_col") ?
234 "<input type='image' name='add[$i]' src='../adminer/static/plus.gif' alt='+' title='" . lang('Add next') . "' onclick='return !editingAddRow(this, $allowed, 1);'>&nbsp;"
235 . "<input type='image' name='up[$i]' src='../adminer/static/up.gif' alt='^' title='" . lang('Move up') . "'>&nbsp;"
236 . "<input type='image' name='down[$i]' src='../adminer/static/down.gif' alt='v' title='" . lang('Move down') . "'>&nbsp;"
237 : "");
238 echo ($orig == "" || support("drop_col") ? "<input type='image' name='drop_col[$i]' src='../adminer/static/cross.gif' alt='x' title='" . lang('Remove') . "' onclick='return !editingRemoveRow(this);'>" : "");
50881f89 » jakubvrana
2009-10-13 Move whitespace to CSS
239 echo "\n";
a7096dda » jakubvrana
2007-07-16 Separate editing functions
240 }
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
241 return $comments;
a7096dda » jakubvrana
2007-07-16 Separate editing functions
242 }
93c27c95 » jakubvrana
2007-07-16 Separate type_change()
243
1118566a » jakubvrana
2009-10-23 Documentation
244 /** Move fields up and down or add field
245 * @param array
246 * @return null
247 */
fd8948ff » jakubvrana
2008-05-07 Order of columns in table
248 function process_fields(&$fields) {
249 ksort($fields);
250 $offset = 0;
251 if ($_POST["up"]) {
252 $last = 0;
253 foreach ($fields as $key => $field) {
254 if (key($_POST["up"]) == $key) {
255 unset($fields[$key]);
256 array_splice($fields, $last, 0, array($field));
257 break;
258 }
259 if (isset($field["field"])) {
260 $last = $offset;
261 }
262 $offset++;
263 }
264 }
265 if ($_POST["down"]) {
266 $found = false;
267 foreach ($fields as $key => $field) {
268 if (isset($field["field"]) && $found) {
269 unset($fields[key($_POST["down"])]);
270 array_splice($fields, $offset, 0, array($found));
271 break;
272 }
273 if (key($_POST["down"]) == $key) {
274 $found = $field;
275 }
276 $offset++;
277 }
278 }
279 $fields = array_values($fields);
280 if ($_POST["add"]) {
281 array_splice($fields, key($_POST["add"]), 0, array(array()));
282 }
283 }
284
1118566a » jakubvrana
2009-10-23 Documentation
285 /** Callback used in routine()
286 * @param array
287 * @return string
288 */
8060c5bc » jakubvrana
2007-07-17 Routines
289 function normalize_enum($match) {
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
290 return "'" . str_replace("'", "''", addcslashes(stripcslashes(str_replace($match[0][0] . $match[0][0], $match[0][0], substr($match[0], 1, -1))), '\\')) . "'";
8060c5bc » jakubvrana
2007-07-17 Routines
291 }
292
1118566a » jakubvrana
2009-10-23 Documentation
293 /** Issue grant or revoke commands
294 * @param string GRANT or REVOKE
295 * @param array
296 * @param string
297 * @param string
298 * @return
299 */
464d84af » jakubvrana
2009-09-09 Define functions unconditionally
300 function grant($grant, $privileges, $columns, $on) {
301 if (!$privileges) {
302 return true;
303 }
304 if ($privileges == array("ALL PRIVILEGES", "GRANT OPTION")) {
305 // can't be granted or revoked together
306 return ($grant == "GRANT"
307 ? queries("$grant ALL PRIVILEGES$on WITH GRANT OPTION")
308 : queries("$grant ALL PRIVILEGES$on") && queries("$grant GRANT OPTION$on")
309 );
310 }
311 return queries("$grant " . preg_replace('~(GRANT OPTION)\\([^)]*\\)~', '\\1', implode("$columns, ", $privileges) . $columns) . $on);
312 }
32d5b9cc » jakubvrana
2009-10-13 Inform about dropped routine, trigger and view
313
1118566a » jakubvrana
2009-10-23 Documentation
314 /** Drop old object and create a new one
315 * @param string drop query
316 * @param string create query
317 * @param string
318 * @param string
319 * @param string
320 * @param string
321 * @param string
322 * @return bool dropped
323 */
32d5b9cc » jakubvrana
2009-10-13 Inform about dropped routine, trigger and view
324 function drop_create($drop, $create, $location, $message_drop, $message_alter, $message_create, $name) {
325 if ($_POST["drop"]) {
326 return query_redirect($drop, $location, $message_drop, true, !$_POST["dropped"]);
327 }
7352c281 » jakubvrana
2010-01-09 Replace strlen() by != ""
328 $dropped = $name != "" && ($_POST["dropped"] || queries($drop));
32d5b9cc » jakubvrana
2009-10-13 Inform about dropped routine, trigger and view
329 $created = queries($create);
7352c281 » jakubvrana
2010-01-09 Replace strlen() by != ""
330 if (!queries_redirect($location, ($name != "" ? $message_alter : $message_create), $created) && $dropped) {
be49e08b » jakubvrana
2009-11-03 Improve session restarting
331 restart_session();
32d5b9cc » jakubvrana
2009-10-13 Inform about dropped routine, trigger and view
332 $_SESSION["messages"][] = $message_drop;
333 }
334 return $dropped;
335 }
095d4723 »
2010-10-29 Customizable export
336
337 /** Get string to add a file in TAR
338 * @param string
339 * @param string
340 * @return string
341 */
342 function tar_file($filename, $contents) {
343 $return = pack("a100a8a8a8a12a12", $filename, 644, 0, 0, decoct(strlen($contents)), decoct(time()));
344 $checksum = 8*32; // space for checksum itself
345 for ($i=0; $i < strlen($return); $i++) {
346 $checksum += ord($return{$i});
347 }
348 $return .= sprintf("%06o", $checksum) . "\0 ";
349 return $return . str_repeat("\0", 512 - strlen($return)) . $contents . str_repeat("\0", 511 - (strlen($contents) + 511) % 512);
350 }
Something went wrong with that request. Please try again.