-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
60 lines (46 loc) · 1.38 KB
/
functions.php
File metadata and controls
60 lines (46 loc) · 1.38 KB
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
<?php
function build_command($options, $url, $path) {
$command = $options['executable'];
foreach($options as $key => $value) {
if ($key != 'executable') {
$command .= ' --' . $key . ' ' . $value;
}
}
return $command . ' "' . $url . '" ' . $path;
}
function generate_path($output_dir, $filename = null) {
if(empty($filename) || !preg_match('/^\w+$/', $filename)) {
return build_path($output_dir, uniqid(rand(), true));
}
$counter = 0;
$name = $filename;
$path = build_path($output_dir, $name);
while (file_exists($path)) {
$name = $filename . '_' . ++$counter;
$path = build_path($output_dir, $name);
}
return $path;
}
function build_path($output_dir, $filename) {
return $output_dir . DIRECTORY_SEPARATOR . $filename . '.' . get_format_options()['extension'];
}
function extract_options() {
$options = array();
$options['executable'] = get_format_options()['executable'];
if (!empty($_GET['wait']) && is_numeric($_GET['wait'])) {
$options['javascript-delay'] = $_GET['wait'];
}
return $options;
}
function get_format_options() {
$options = array();
if (isset($_GET['format']) && $_GET['format'] == 'image') {
$options['executable'] = 'wkhtmltoimage';
$options['extension'] = 'jpeg';
} else {
$options['executable'] = 'wkhtmltopdf';
$options['extension'] = 'pdf';
}
return $options;
}
?>