Skip to content

Commit

Permalink
Update Dompdf, code cleanup, and makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
creecros committed Feb 16, 2023
1 parent 3351ada commit 5f7c04a
Show file tree
Hide file tree
Showing 81 changed files with 1,964 additions and 43,895 deletions.
100 changes: 48 additions & 52 deletions Controller/PrintTaskController.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Locale/pt_BR/translations.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
'Do Not Embed Files when creating a PDF for all Open Tasks in a Project' => 'Não incorpore arquivos ao criar um PDF para todas as tarefas abertas em um projeto',
'Show PDF inline Browser' => 'Mostrar pdf no navegador',
'Download pdf' => 'Baixar pdf'
);
);
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extract = $(shell grep -A2 $(1) Plugin.php | tail -n1 | tr -d " ;'" | sed "s/return//")

plugin = $(call extract, getPluginName)
version = $(call extract, getPluginVersion)

all:
@echo "Build archive for plugin ${plugin} version=${version}"
@git archive HEAD --prefix=${plugin}/ --format=zip -o ${plugin}-${version}.zip
64 changes: 31 additions & 33 deletions Model/PrintModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,54 @@
use Kanboard\Core\ObjectStorage\ObjectStorageException;
use DOMDocument;


/**
* @plugin Task2pdf
*
* @package Model
* @author creecros
*/

class PrintModel extends Base {


public function preparePrint($toFix)
class PrintModel extends Base
{
public function preparePrint($toFix)
{
$toFix = str_replace('```', '`', $toFix);
$toFix = str_replace('~~~', '`', $toFix);
if (file_exists('plugins/MarkdownPlus')){
if (file_exists('plugins/MarkdownPlus')) {
$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);
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');
}

// 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;

return $toFix;
}
}

75 changes: 38 additions & 37 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,51 @@
use Kanboard\Core\Translator;

class Plugin extends Base

{
public function initialize()
{
$this->template->hook->attach('template:task:sidebar:information', 'task2pdf:print');
$this->template->hook->attach('template:project:dropdown', 'task2pdf:project_header/print_project');
$this->template->hook->attach('template:config:application', 'task2pdf:config/font_toggle');
}

public function getClasses() {
public function initialize()
{
$this->template->hook->attach('template:task:sidebar:information', 'task2pdf:print');
$this->template->hook->attach('template:project:dropdown', 'task2pdf:project_header/print_project');
$this->template->hook->attach('template:config:application', 'task2pdf:config/font_toggle');
}

public function getClasses()
{
return array(
'Plugin\Task2pdf\Model' => array(
'PrintModel',
)
);
}
}

// Translation
public function onStartup() {
// Translation
public function onStartup()
{
Translator::load($this->languageModel->getCurrentLanguage(), __DIR__.'/Locale');
}
public function getPluginName()
{
return 'Task2pdf';
}

public function getPluginAuthor()
{
return 'Craig Crosby';
}

public function getPluginVersion()
{
return '1.7.0';
}

public function getPluginDescription()
{
return 'Create a printer friendly PDF of a task.';
}

public function getPluginHomepage()
{
return 'https://github.com/creecros/Task2pdf';
}

public function getPluginName()
{
return 'Task2pdf';
}

public function getPluginAuthor()
{
return 'Craig Crosby';
}

public function getPluginVersion()
{
return '1.8.0';
}

public function getPluginDescription()
{
return 'Create a printer friendly PDF of a task.';
}

public function getPluginHomepage()
{
return 'https://github.com/creecros/Task2pdf';
}
}
16 changes: 8 additions & 8 deletions Template/config/font_toggle.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<div class="panel"><h1>Task2PDF Options</h1>
<br>
<h2><?= t('Font Options') ?>:</h2>
<?= $this->form->radio('task2pdf_cjk', t('Normal Font set when creating PDFs') , 1, isset($values['task2pdf_cjk'])&& $values['task2pdf_cjk']==1) ?>
<?= $this->form->radio('task2pdf_cjk', t('CJK Font set when creating PDFs') , 2, isset($values['task2pdf_cjk'])&& $values['task2pdf_cjk']==2) ?>
<?= $this->form->radio('task2pdf_cjk', t('Normal Font set when creating PDFs'), 1, isset($values['task2pdf_cjk'])&& $values['task2pdf_cjk']==1) ?>
<?= $this->form->radio('task2pdf_cjk', t('CJK Font set when creating PDFs'), 2, isset($values['task2pdf_cjk'])&& $values['task2pdf_cjk']==2) ?>
<br>
<h2><?= t('Embed Task Files Options') ?>:</h2>
<?= $this->form->radio('task2pdf_embed_task', t('Embed Files when creating a PDF for a Task') , 1, isset($values['task2pdf_embed_task'])&& $values['task2pdf_embed_task']==1) ?>
<?= $this->form->radio('task2pdf_embed_task', t('Do not embed Files when creating a PDF for a Task') , 2, isset($values['task2pdf_embed_task'])&& $values['task2pdf_embed_task']==2) ?>
<?= $this->form->radio('task2pdf_embed_projects', t('Embed Files when creating a PDF for all Open Tasks in a Project') , 1, isset($values['task2pdf_embed_projects'])&& $values['task2pdf_embed_projects']==1) ?>
<?= $this->form->radio('task2pdf_embed_projects', t('Do Not Embed Files when creating a PDF for all Open Tasks in a Project') , 2, isset($values['task2pdf_embed_projects'])&& $values['task2pdf_embed_projects']==2) ?>
<?= $this->form->radio('task2pdf_embed_task', t('Embed Files when creating a PDF for a Task'), 1, isset($values['task2pdf_embed_task'])&& $values['task2pdf_embed_task']==1) ?>
<?= $this->form->radio('task2pdf_embed_task', t('Do not embed Files when creating a PDF for a Task'), 2, isset($values['task2pdf_embed_task'])&& $values['task2pdf_embed_task']==2) ?>
<?= $this->form->radio('task2pdf_embed_projects', t('Embed Files when creating a PDF for all Open Tasks in a Project'), 1, isset($values['task2pdf_embed_projects'])&& $values['task2pdf_embed_projects']==1) ?>
<?= $this->form->radio('task2pdf_embed_projects', t('Do Not Embed Files when creating a PDF for all Open Tasks in a Project'), 2, isset($values['task2pdf_embed_projects'])&& $values['task2pdf_embed_projects']==2) ?>
<br>
<h2><?= t('PDF Download or Inline') ?>:</h2>
<?= $this->form->radio('task2pdf_attachment', t('Show PDF inline Browser') , 1, isset($values['task2pdf_attachment'])&& $values['task2pdf_attachment']==1) ?>
<?= $this->form->radio('task2pdf_attachment', t('Download pdf') , 2, isset($values['task2pdf_attachment'])&& $values['task2pdf_attachment']==2) ?>
<?= $this->form->radio('task2pdf_attachment', t('Show PDF inline Browser'), 1, isset($values['task2pdf_attachment'])&& $values['task2pdf_attachment']==1) ?>
<?= $this->form->radio('task2pdf_attachment', t('Download pdf'), 2, isset($values['task2pdf_attachment'])&& $values['task2pdf_attachment']==2) ?>
</div>
24 changes: 10 additions & 14 deletions Template/project_header/print_project.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
<?= $this->url->icon('file-pdf-o', t('Print Closed Tasks'), 'PrintTaskController', 'printProjectClosed', ['plugin' => 'task2pdf', 'project_id' => $project['id']]) ?>
</li>
<?php endif ?>
<?php
if ($this->user->hasProjectAccess('ExportController', 'tasks', $project['id']))
{
<?php
if ($this->user->hasProjectAccess('ExportController', 'tasks', $project['id'])) {
$search = $this->helper->projectHeader->getSearchQuery($project);
if($search=="" || $search=="status:open" || !isset($search))
{
?>
if($search=="" || $search=="status:open" || !isset($search)) {
?>
<li>
<?= $this->url->icon('file-pdf-o', t('Print All Tasks for This User'), 'PrintTaskController', 'printProjectPerUser', ['plugin' => 'task2pdf', 'project_id' => $project['id']]) ?>
</li>
Expand All @@ -25,14 +23,12 @@
<li>
<?= $this->url->icon('file-pdf-o', t('Print Closed Tasks for This User'), 'PrintTaskController', 'printProjectPerUserClosed', ['plugin' => 'task2pdf', 'project_id' => $project['id']]) ?>
</li>
<?php }
else
{
?>
<?php } else {
?>
<li>
<?= $this->url->icon('file-pdf-o', t('Print Filtered Tasks'), 'PrintTaskController', 'printProjectByFilter', ['plugin' => 'task2pdf', 'project_id' => $project['id'], 'search' => $search]) ?>
</li>
<?php
}
}
?>
<?php
}
}
?>
40 changes: 20 additions & 20 deletions composer.lock

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

17 changes: 15 additions & 2 deletions vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,21 @@
// 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);
if (!headers_sent()) {
header('HTTP/1.1 500 Internal Server Error');
}
$err = '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;
if (!ini_get('display_errors')) {
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
fwrite(STDERR, $err);
} elseif (!headers_sent()) {
echo $err;
}
}
trigger_error(
$err,
E_USER_ERROR
);
}

require_once __DIR__ . '/composer/autoload_real.php';
Expand Down
Loading

0 comments on commit 5f7c04a

Please sign in to comment.