-
Notifications
You must be signed in to change notification settings - Fork 0
/
export.php
76 lines (59 loc) · 2 KB
/
export.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
<?php
/*
Template Name: Export fiche
*/
if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
require __DIR__ . '/vendor/autoload.php';
}
use Spiritix\Html2Pdf\Converter;
use Spiritix\Html2Pdf\Input\UrlInput;
use Spiritix\Html2Pdf\Output\DownloadOutput;
// category slug
$category_name = 'bdtfxcache';
$securise = (isset($_SERVER['HTTPS'])) ? "https://" : "http://";
if (empty($_GET['p'])) {
$the_query = new WP_Query( [
'category_name' => $category_name,
'post_status' => 'publish',
/*'posts_per_page' => 5 */
] );
$string = '<ul class="postslist">';
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
$name = get_post_field( 'post_name', get_post() );
$string .= '<li><a href="export/?p=' . $name .'" rel="bookmark">' . get_the_title() .'</a></li>';
}
} else {
$string .= '<li>Pas de fiche trouvée dans la categorie '.$category_name.'</li>';
}
$string .= '</ul>';
/* Restore original Post Data */
wp_reset_postdata();
echo $string;
} else {
$posts = query_posts([
'title' => $_GET['p'],
'post_type' => 'post',
'post_status' => array('publish', 'pending', 'draft'),
'showposts' => 1
]);
if (have_posts()) {
the_post();
// header('Content-Type: application/pdf');
// header('Content-Disposition: attachment; filename="'.$_GET['p'].'.pdf"');
$input = new UrlInput();
$input->setUrl($securise.$_SERVER['HTTP_HOST'].'/fiche/?p='.$_GET['p']);
$converter = new Converter($input, new DownloadOutput());
$converter->setOptions([
'printBackground' => true,
'displayHeaderFooter' => true,
'format' => 'A4',
'disable-pdf-compression' => true,
'scale' => 1.2,
'dpi' => 300,
]);
$output = $converter->convert();
$output->download($_GET['p'].'.pdf');
}
}