Skip to content

Commit

Permalink
Merge pull request #25 from creecros/WIPbranch
Browse files Browse the repository at this point in the history
WIPbranch Internal Image support
  • Loading branch information
creecros authored Nov 7, 2022
2 parents cf6ac32 + 2c23cb5 commit 0f71c80
Show file tree
Hide file tree
Showing 185 changed files with 56,304 additions and 34,398 deletions.
8 changes: 5 additions & 3 deletions Controller/PrintTaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ public function printTask()
$options->set('defaultFont', 'DejaVu Sans');
$options->set('fontHeightRatio', '.9');
$options->set('isJavascriptEnabled', 'true');
set_time_limit(600);
$dompdf = new Dompdf($options);
$dompdf->setBasePath('/var/www/app/');
$dompdf->setBasePath('/var/www/app/data/');

if ($this->configModel->get('task2pdf_cjk', 1) == 1) { $layout = 'Task2pdf:printlayout/printlayout_n'; } else { $layout = 'Task2pdf:printlayout/printlayout_cjk'; }

$task = $this->getTask();
Expand Down Expand Up @@ -95,8 +96,9 @@ public function printProject()
$options->set('defaultFont', 'DejaVu Sans');
$options->set('fontHeightRatio', '.9');
$options->set('isJavascriptEnabled', 'true');
set_time_limit(600);
$dompdf = new Dompdf($options);
$dompdf->setBasePath('/var/www/app/');
$dompdf->setBasePath('/var/www/app/data/');

if ($this->configModel->get('task2pdf_cjk', 1) == 1) {
$html_all = '<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><style>.task-board.color-yellow, .task-summary-container.color-yellow, .color-picker-square.color-yellow, .task-board-category.color-yellow, .table-list-category.color-yellow, .task-tag.color-yellow {background-color: rgb(245, 247, 196);border-color: rgb(223, 227, 45)}td.color-yellow { background-color: rgb(245, 247, 196)}.table-list-row.color-yellow {border-left: 5px solid rgb(223, 227, 45)}.task-board.color-blue, .task-summary-container.color-blue, .color-picker-square.color-blue, .task-board-category.color-blue, .table-list-category.color-blue, .task-tag.color-blue {background-color: rgb(219, 235, 255);border-color: rgb(168, 207, 255)}td.color-blue { background-color: rgb(219, 235, 255)}.table-list-row.color-blue {border-left: 5px solid rgb(168, 207, 255)}.task-board.color-green, .task-summary-container.color-green, .color-picker-square.color-green, .task-board-category.color-green, .table-list-category.color-green, .task-tag.color-green {background-color: rgb(189, 244, 203);border-color: rgb(74, 227, 113)}td.color-green { background-color: rgb(189, 244, 203)}.table-list-row.color-green {border-left: 5px solid rgb(74, 227, 113)}.task-board.color-purple, .task-summary-container.color-purple, .color-picker-square.color-purple, .task-board-category.color-purple, .table-list-category.color-purple, .task-tag.color-purple {background-color: rgb(223, 176, 255);border-color: rgb(205, 133, 254)}td.color-purple { background-color: rgb(223, 176, 255)}.table-list-row.color-purple {border-left: 5px solid rgb(205, 133, 254)}.task-board.color-red, .task-summary-container.color-red, .color-picker-square.color-red, .task-board-category.color-red, .table-list-category.color-red, .task-tag.color-red {background-color: rgb(255, 187, 187);border-color: rgb(255, 151, 151)}td.color-red { background-color: rgb(255, 187, 187)}.table-list-row.color-red {border-left: 5px solid rgb(255, 151, 151)}.task-board.color-orange, .task-summary-container.color-orange, .color-picker-square.color-orange, .task-board-category.color-orange, .table-list-category.color-orange, .task-tag.color-orange {background-color: rgb(255, 215, 179);border-color: rgb(255, 172, 98)}td.color-orange { background-color: rgb(255, 215, 179)}.table-list-row.color-orange {border-left: 5px solid rgb(255, 172, 98)}.task-board.color-grey, .task-summary-container.color-grey, .color-picker-square.color-grey, .task-board-category.color-grey, .table-list-category.color-grey, .task-tag.color-grey {background-color: rgb(238, 238, 238);border-color: rgb(204, 204, 204)}td.color-grey { background-color: rgb(238, 238, 238)}.table-list-row.color-grey {border-left: 5px solid rgb(204, 204, 204)}.task-board.color-brown, .task-summary-container.color-brown, .color-picker-square.color-brown, .task-board-category.color-brown, .table-list-category.color-brown, .task-tag.color-brown {background-color: #d7ccc8;border-color: #4e342e}td.color-brown { background-color: #d7ccc8}.table-list-row.color-brown {border-left: 5px solid #4e342e}.task-board.color-deep_orange, .task-summary-container.color-deep_orange, .color-picker-square.color-deep_orange, .task-board-category.color-deep_orange, .table-list-category.color-deep_orange, .task-tag.color-deep_orange {background-color: #ffab91;border-color: #e64a19}td.color-deep_orange { background-color: #ffab91}.table-list-row.color-deep_orange {border-left: 5px solid #e64a19}.task-board.color-dark_grey, .task-summary-container.color-dark_grey, .color-picker-square.color-dark_grey, .task-board-category.color-dark_grey, .table-list-category.color-dark_grey, .task-tag.color-dark_grey {background-color: #cfd8dc;border-color: #455a64}td.color-dark_grey { background-color: #cfd8dc}.table-list-row.color-dark_grey {border-left: 5px solid #455a64}.task-board.color-pink, .task-summary-container.color-pink, .color-picker-square.color-pink, .task-board-category.color-pink, .table-list-category.color-pink, .task-tag.color-pink {background-color: #f48fb1;border-color: #d81b60}td.color-pink { background-color: #f48fb1}.table-list-row.color-pink {border-left: 5px solid #d81b60}.task-board.color-teal, .task-summary-container.color-teal, .color-picker-square.color-teal, .task-board-category.color-teal, .table-list-category.color-teal, .task-tag.color-teal {background-color: #80cbc4;border-color: #00695c}td.color-teal { background-color: #80cbc4}.table-list-row.color-teal {border-left: 5px solid #00695c}.task-board.color-cyan, .task-summary-container.color-cyan, .color-picker-square.color-cyan, .task-board-category.color-cyan, .table-list-category.color-cyan, .task-tag.color-cyan {background-color: #b2ebf2;border-color: #00bcd4}td.color-cyan { background-color: #b2ebf2}.table-list-row.color-cyan {border-left: 5px solid #00bcd4}.task-board.color-lime, .task-summary-container.color-lime, .color-picker-square.color-lime, .task-board-category.color-lime, .table-list-category.color-lime, .task-tag.color-lime {background-color: #e6ee9c;border-color: #afb42b}td.color-lime { background-color: #e6ee9c}.table-list-row.color-lime {border-left: 5px solid #afb42b}.task-board.color-light_green, .task-summary-container.color-light_green, .color-picker-square.color-light_green, .task-board-category.color-light_green, .table-list-category.color-light_green, .task-tag.color-light_green {background-color: #dcedc8;border-color: #689f38}td.color-light_green { background-color: #dcedc8}.table-list-row.color-light_green {border-left: 5px solid #689f38}.task-board.color-amber, .task-summary-container.color-amber, .color-picker-square.color-amber, .task-board-category.color-amber, .table-list-category.color-amber, .task-tag.color-amber {background-color: #ffe082;border-color: #ffa000}td.color-amber { background-color: #ffe082}.table-list-row.color-amber {border-left: 5px solid #ffa000}</style></head><body>';
Expand Down
45 changes: 40 additions & 5 deletions Model/PrintModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
namespace Kanboard\Plugin\Task2pdf\Model;

use Kanboard\Core\Base;
use Kanboard\Model\TaskFileModel;
use Kanboard\Core\ObjectStorage\ObjectStorageException;
use DOMDocument;


/**
* @plugin Task2pdf
Expand All @@ -12,12 +16,43 @@
*/

class PrintModel extends Base {



public function codeblockFix($toFix)
{
$toFix = str_replace('```', '`', $toFix);
$toFix = str_replace('~~~', '`', $toFix);
return $toFix;
$dom = new DOMDocument('1.0');

// Loading HTML content in $dom
@$dom->loadHTML($toFix);

// Selecting all image i.e. img tag object
$anchors = $dom -> getElementsByTagName('img');
// Extracting attribute from each object
foreach ($anchors as $element) {
// Extracting value of src attribute of
// the current image object
$src = $element -> getAttribute('src');
if (str_contains($src, 'FileViewerController')) {
$file_id = substr($src, strpos($src, 'file_id=')+8);
$file_id = intval($file_id);

$file = $this->taskFileModel->getById($file_id);
if(!is_null($file)) $file_data = base64_encode(file_get_contents(FILES_DIR.DIRECTORY_SEPARATOR.$file['path']));
if(!is_null($file)) $toFix = str_replace($src, 'data:image/png;base64,'.$file_data, $toFix);
}

// Extracting value of height attribute
// of the current image object
$height = $element -> getAttribute('height');

// Extracting value of width attribute of
// the current image object
$width = $element -> getAttribute('width');


}
return $toFix;

}

}

2 changes: 1 addition & 1 deletion Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function getPluginAuthor()

public function getPluginVersion()
{
return '1.5.0';
return '1.6.0';
}

public function getPluginDescription()
Expand Down
19 changes: 19 additions & 0 deletions Template/printlayout/description.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
<style type="text/css">
img.enlargable {
max-width: 300px;
max-height: 300px;
cursor: zoom-in;
margin: 20px 10px 7px 10px;
/*display: inline-block !important;*/
}
.markdown p {
margin-bottom: 60px;
}
.accordion-content {
margin-top: 0px;
margin-bottom: 0px;
}
.accordion-title h3 {
margin-bottom: 0;
}
</style>
<section class="accordion-section <?= empty($task['description']) ? 'accordion-collapsed' : '' ?>">
<div class="accordion-title">
<h3><a href="#" class="fa accordion-toggle"></a> <?= t('Description') ?></h3>
Expand Down
46 changes: 26 additions & 20 deletions Template/printlayout/file_table.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php if (! empty($files) || ! empty($images)): ?>
<table style="border:1px solid #eee;border-collapse:collapse;width:100%;">
<tr style="background-color: #eee;">
<th><?= t('Filename') ?></th>
<th><?= t('Creator') ?></th>
<th><?= t('Date') ?></th>
<th><?= t('Size') ?></th>
<table style="width:100%; position: relative; table-layout: fixed;">
<tr style="border:1px solid #eee; background-color: #eee; margin-top: 6px; margin-bottom: 6px; position: relative;">
<th style="text-align:left; padding: 4px;"><?= t('Filename') ?></th>
<th style="text-align:left; padding: 4px;"><?= t('Creator') ?></th>
<th style="text-align:left; padding: 4px;"><?= t('Date') ?></th>
<th style="text-align:left; padding: 4px;"><?= t('Size') ?></th>
</tr>
<?php foreach ($files as $file): ?>
<tr style="background-color: #fff;">
Expand All @@ -22,21 +22,27 @@
</td>
</tr>
<?php endforeach ?>
</table>
<br>
<table style="width:100%; position: relative; table-layout: fixed;">
<tr style="background-color: #fff;">
<?php $c = 0; ?>
<?php foreach ($images as $image): ?>
<tr style="background-color: #fff;">
<td>
<?= $this->text->e($image['name']) ?>
</td>
<td>
<?= $this->text->e($image['user_name'] ?: $image['username']) ?>
</td>
<td>
<?= $this->dt->date($image['date']) ?>
</td>
<td>
<?= $this->text->bytes($image['size']) ?>
</td>
</tr>
<?php $c = $c + 1; ?>
<?php if ($c == 6): ?>
<?php $c = 0; ?>
</tr>
<tr style="background-color: #fff;">
<?php endif ?>
<td>
<br><img src="data:image/png;base64,<?= base64_encode(file_get_contents(FILES_DIR.DIRECTORY_SEPARATOR.$image['path'])); ?>"
style="width: 100px; border:1px solid #000; border-radius:3px; margin-bottom:10px; box-shadow:4px 2px 10px -6px rgb(0 0 0 / 55%); margin: 0 15px 0 0; /*max-height:100px;*/"></br>
<br><?= $this->text->e($image['name'] ?: $image['name']) ?></br>
<br><?= $this->dt->date($image['date']) ?></br>
<br><?= $this->text->bytes($image['size']) ?></br>
</td>

<?php endforeach ?>
</tr>
</table>
<?php endif ?>
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"require": {
"dompdf/dompdf": "^2.0.1"
"dompdf/dompdf": "^2.0.0"
}
}
30 changes: 15 additions & 15 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

// autoload.php @generated by Composer

if (PHP_VERSION_ID < 50600) {
echo 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
exit(1);
}

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit443d77403e4dafb9f0628f8dcbc4aeee::getLoader();
Loading

0 comments on commit 0f71c80

Please sign in to comment.