Skip to content

Commit

Permalink
Display a sneak peak of a publication instead of its rendered HTML
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Parisot committed Sep 22, 2020
1 parent 229ede9 commit 5b3ed31
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 5 deletions.
2 changes: 1 addition & 1 deletion handlers/page/__show.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
global $wiki;

if ($this->HasAccess('write') && isset($this->page['metadatas']['publication-title'])) {
$wiki->AddCSSFile('tools/publication/presentation/styles/publication.css');
$wiki->page['body'] = '{{button link="'.$wiki->href('pdf', '').'" text="PDF" class="btn-primary pull-right space-left" icon="fas fa-book"}} {{button link="'.$wiki->href('preview', '').'" text="'._t('PUBLICATION_PREVIEW').'" class="btn-info pull-right" icon="fas fa-book-reader"}}""<div class="clearfix"></div>""'.$wiki->page['body'];
}
29 changes: 29 additions & 0 deletions handlers/page/show__.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
global $wiki;

if ($this->HasAccess('write') && isset($this->page['metadatas']['publication-title'])) {
include_once 'includes/squelettephp.class.php';

// user options
$options = array(
"publication-hide-links-url" => '1',
"publication-cover-page" => '0',
"publication-book-fold" => '0',
"publication-page-format" => 'A4',
"publication-page-orientation" => 'portrait',
"publication-pagination" => "bottom-center",
"publication-print-marks" => '0'
);

$metadata = array_merge($options, $wiki->page['metadatas']);
$template = new SquelettePhp('print-show.tpl.html', 'publication');

$output = $template->render(array(
'hasWriteAccess' => $wiki->HasAccess('write'),
'metadata' => $metadata,
'page' => $wiki->page,
'wiki' => $wiki,
));

$plugin_output_new = preg_replace('/<div class="page" >.+<hr class="hr_clear" \/>/siU', '<div class="page" >'. $output .'<hr class="hr_clear" />', $plugin_output_new);
}
6 changes: 4 additions & 2 deletions lang/publication_en.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@
'PUBLICATION_PREVIEW' => 'Preview',
'PUBLICATION_SEE_NEWSLETTER' => 'See newsletter',
'PUBLICATION_SEE_PAGE' => 'See page',
'PUBLICATION_SELECT_PAGE' => 'Select page',
'PUBLICATION_SELECT_PAGE' => 'Select page',
'PUBLICATION_SHOW_NOTICE' => 'Here is a sneak peak of a printable document. Feel free to print it, or share it!',
'PUBLICATION_SPAM_RISK' => 'In order to avoid the publication generator being considered as spam, you must activate javascript.',
'PUBLICATION_START_PAGE' => 'First page',
'PUBLICATION_YOUR' => 'Your',
'PUBLICATION_YOUR' => 'Your',
'PUBLICATION_VIEW_PDF' => 'Download PDF',
'PUBLICATION_EXPORT_PAGE_TO_PDF' => 'Export page to pdf',
'PUBLICATION_NO_GENERATED_PDF_FILE_FOUND' => 'No pdf file was found.<br />Please check access rights on the "cache" folder.',
'PUBLICATION_NO_EXECUTABLE_FILE_FOUND_ON_PATH' => 'No executable file found on path',
Expand Down
6 changes: 4 additions & 2 deletions lang/publication_fr.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@
'PUBLICATION_PREVIEW' => 'Aperçu',
'PUBLICATION_SEE_NEWSLETTER' => 'Voir la newsletter',
'PUBLICATION_SEE_PAGE' => 'Voir la page',
'PUBLICATION_SELECT_PAGE' => 'S&eacute;lectionner la page',
'PUBLICATION_SELECT_PAGE' => 'S&eacute;lectionner la page',
'PUBLICATION_SHOW_NOTICE' => 'Voici un aperçu d\'un document imprimable. Téléchargez-le, ou partagez-le avec des ami·es&nbsp;!',
'PUBLICATION_SPAM_RISK' => 'Il faut activer javascript pour ne pas &ecirc;tre consid&eacute;r&eacute; comme du spam.',
'PUBLICATION_START_PAGE' => 'Page d\'introduction',
'PUBLICATION_YOUR' => 'Votre',
'PUBLICATION_YOUR' => 'Votre',
'PUBLICATION_VIEW_PDF' => 'Télécharger le PDF',
'PUBLICATION_EXPORT_PAGE_TO_PDF' => 'Exporter la page au format pdf',
'PUBLICATION_NO_GENERATED_PDF_FILE_FOUND' => 'Le fichier pdf g&eacute;n&eacute;r&eacute; n\'a pas &eacute;t&eacute; trouv&eacute;.<br />V&eacute;rifier les permissions en &eacute;criture sur le dossier "cache" ou les permissions en droit d\'&eacute;x&eacute;cution du programme chromium.',
'PUBLICATION_NO_EXECUTABLE_FILE_FOUND_ON_PATH' => 'Pas de fichier exécutable trouvé pour',
Expand Down
6 changes: 6 additions & 0 deletions presentation/styles/publication.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
border: 1px solid #d9534f;
}

.yw-publication__show .img-cover {
object-fit: cover;
height: 250px;
width: 200px;
}

.export-table-form details > summary {
cursor: pointer;
display: revert; /* this is somewhat unset by Bootstrap, which we don't want in this case */
Expand Down
40 changes: 40 additions & 0 deletions presentation/templates/print-show.tpl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<div class="alert alert-info">
<p><?php echo _t('PUBLICATION_SHOW_NOTICE') ?></p>
</div>

<div class="row yw-publication__show">
<div class="col-sm-8">
<div class="thumbnail">
<div class="caption">
<?php if ($metadata['publication-cover-image']) { ?>
<img class="pull-right img-cover img-thumbnail" alt="" src="<?php echo $metadata['publication-cover-image'] ?>">
<?php } ?>

<h3><?php echo $metadata['publication-title'] ?></h3>

<p class="clearfix"><?php echo $metadata['publication-description'] ?></p>
</div>
</div>
</div>

<div class="col-sm-4">
<div class="btn-group-vertical" role="group" aria-label="">
<a href="<?php echo $wiki->href('pdf', '') ?>" download type="application/pdf" class="btn btn-primary">
<i class="fas fa-book"></i>
<?php echo _t('PUBLICATION_VIEW_PDF') ?>
</a>

<?php if ($hasWriteAccess) { ?>
<a href="<?php echo $wiki->href('preview', '') ?>" class="btn btn-default btn-secondary">
<i class="fas fa-book-reader"></i>
<?php echo _t('PUBLICATION_PREVIEW') ?>
</a>
<?php } ?>

<a href="<?php echo $wiki->href('share', '') ?>" class="btn btn-default btn-secondary">
<i class="fas fa-share-alt"></i>
<?php echo _t('TEMPLATE_SHARE') ?>
</a>
</div>
</div>
</div>

0 comments on commit 5b3ed31

Please sign in to comment.