Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New test workflow, Style fixes #494

Merged
merged 3 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/dokuwiki.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: DokuWiki Default Tasks
on:
push:
pull_request:
schedule:
- cron: '22 12 25 * *'


jobs:
all:
uses: dokuwiki/github-action/.github/workflows/all.yml@main
52 changes: 0 additions & 52 deletions .github/workflows/phpTestLinux.yml

This file was deleted.

57 changes: 33 additions & 24 deletions DokuImageProcessorDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace dokuwiki\plugin\dw2pdf;

require_once __DIR__ . '/vendor/autoload.php';

class DokuImageProcessorDecorator extends \Mpdf\Image\ImageProcessor {
use Mpdf\Image\ImageProcessor;

class DokuImageProcessorDecorator extends ImageProcessor
{
/**
* Override the mpdf _getImage function
*
Expand All @@ -14,57 +14,66 @@ class DokuImageProcessorDecorator extends \Mpdf\Image\ImageProcessor {
* making sure that only cached file paths are passed to mpdf. It also
* takes care of checking image ACls.
*/
public function getImage (&$file, $firsttime = true, $allowvector = true, $orig_srcpath = false, $interpolation = false) {
list($file, $orig_srcpath) = self::adjustGetImageLinks($file, $orig_srcpath);
public function getImage(
&$file,
$firsttime = true,
$allowvector = true,
$orig_srcpath = false,
$interpolation = false
) {
[$file, $orig_srcpath] = self::adjustGetImageLinks($file, $orig_srcpath);

return parent::getImage($file, $firsttime, $allowvector, $orig_srcpath, $interpolation);
}


public static function adjustGetImageLinks($file, $orig_srcpath) {
public static function adjustGetImageLinks($file, $orig_srcpath)
{
global $conf;

// build regex to parse URL back to media info
$re = preg_quote(ml('xxx123yyy', '', true, '&', true), '/');
$re = str_replace('xxx123yyy', '([^&\?]*)', $re);

// extract the real media from a fetch.php uri and determine mime
if(preg_match("/^$re/", $file, $m) ||
if (
preg_match("/^$re/", $file, $m) ||
preg_match('/[&?]media=([^&?]*)/', $file, $m)
) {
$media = rawurldecode($m[1]);
list($ext, $mime) = mimetype($media);
[$ext, $mime] = mimetype($media);
} else {
list($ext, $mime) = mimetype($file);
[$ext, $mime] = mimetype($file);
}

// local files
$local = '';
if(substr($file, 0, 9) == 'dw2pdf://') {
if (substr($file, 0, 9) == 'dw2pdf://') {
// support local files passed from plugins
$local = substr($file, 9);
} elseif(!preg_match('/(\.php|\?)/', $file)) {
} elseif (!preg_match('/(\.php|\?)/', $file)) {
$re = preg_quote(DOKU_URL, '/');
// directly access local files instead of using HTTP, skip dynamic content
$local = preg_replace("/^$re/i", DOKU_INC, $file);
}

if(substr($mime, 0, 6) == 'image/') {
if(!empty($media)) {
if (substr($mime, 0, 6) == 'image/') {
if (!empty($media)) {
// any size restrictions?
$w = $h = 0;
$w = 0;
$h = 0;
$rev = '';
if(preg_match('/[?&]w=(\d+)/', $file, $m)) $w = $m[1];
if(preg_match('/[?&]h=(\d+)/', $file, $m)) $h = $m[1];
if(preg_match('/[&?]rev=(\d+)/', $file, $m)) $rev = $m[1];
if (preg_match('/[?&]w=(\d+)/', $file, $m)) $w = $m[1];
if (preg_match('/[?&]h=(\d+)/', $file, $m)) $h = $m[1];
if (preg_match('/[&?]rev=(\d+)/', $file, $m)) $rev = $m[1];

if(media_isexternal($media)) {
if (media_isexternal($media)) {
$local = media_get_from_URL($media, $ext, -1);
if(!$local) $local = $media; // let mpdf try again
if (!$local) $local = $media; // let mpdf try again
} else {
$media = cleanID($media);
//check permissions (namespace only)
if(auth_quickaclcheck(getNS($media) . ':X') < AUTH_READ) {
if (auth_quickaclcheck(getNS($media) . ':X') < AUTH_READ) {
$file = '';
$local = '';
} else {
Expand All @@ -73,18 +82,18 @@ public static function adjustGetImageLinks($file, $orig_srcpath) {
}

//handle image resizing/cropping
if($w && file_exists($local)) {
if($h) {
if ($w && file_exists($local)) {
if ($h) {
$local = media_crop_image($local, $ext, $w, $h);
} else {
$local = media_resize_image($local, $ext, $w, $h);
}
}
} elseif(!file_exists($local) && media_isexternal($file)) { // fixed external URLs
} elseif (!file_exists($local) && media_isexternal($file)) { // fixed external URLs
$local = media_get_from_URL($file, $ext, $conf['cachetime']);
}

if($local) {
if ($local) {
$file = $local;
$orig_srcpath = $local;
}
Expand Down
33 changes: 15 additions & 18 deletions DokuPDF.class.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<?php

// phpcs:disable: PSR1.Methods.CamelCapsMethodName.NotCamelCaps

use Mpdf\Mpdf;
use dokuwiki\plugin\dw2pdf\DokuImageProcessorDecorator;

/**
* Wrapper around the mpdf library class
*
Expand All @@ -7,31 +13,25 @@
*
* @author Andreas Gohr <[email protected]>
*/

use dokuwiki\plugin\dw2pdf\DokuImageProcessorDecorator;

require_once __DIR__ . '/vendor/autoload.php';

/**
* Class DokuPDF
* Some DokuWiki specific extentions
*/
class DokuPDF extends \Mpdf\Mpdf
class DokuPDF extends Mpdf
{

/**
* DokuPDF constructor.
*
* @param string $pagesize
* @param string $orientation
* @param int $fontsize
*/
function __construct($pagesize = 'A4', $orientation = 'portrait', $fontsize = 11, $docLang = 'en')
public function __construct($pagesize = 'A4', $orientation = 'portrait', $fontsize = 11, $docLang = 'en')
{
global $conf;
global $lang;

if (!defined('_MPDF_TEMP_PATH')) define('_MPDF_TEMP_PATH', $conf['tmpdir'] . '/dwpdf/' . rand(1, 1000) . '/');
require_once __DIR__ . '/vendor/autoload.php';

if (!defined('_MPDF_TEMP_PATH')) {
define('_MPDF_TEMP_PATH', $conf['tmpdir'] . '/dwpdf/' . random_int(1, 1000) . '/');
}
io_mkdir_p(_MPDF_TEMP_PATH);

$format = $pagesize;
Expand All @@ -48,7 +48,6 @@ function __construct($pagesize = 'A4', $orientation = 'portrait', $fontsize = 11
break;
default:
$mode = 'UTF-8-s';

}

parent::__construct([
Expand Down Expand Up @@ -76,7 +75,7 @@ function __construct($pagesize = 'A4', $orientation = 'portrait', $fontsize = 11
/**
* Cleanup temp dir
*/
function __destruct()
public function __destruct()
{
io_rmdir(_MPDF_TEMP_PATH, true);
}
Expand All @@ -87,11 +86,9 @@ function __destruct()
* @param string $path
* @param string $basepath
*/
function GetFullPath(&$path, $basepath = '')
public function GetFullPath(&$path, $basepath = '')
{
$path = htmlspecialchars_decode($path);
parent::GetFullPath($path, $basepath);
}


}
14 changes: 8 additions & 6 deletions MenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
*
* @package dokuwiki\plugin\dw2pdf
*/
class MenuItem extends AbstractItem {

class MenuItem extends AbstractItem
{
/** @var string do action for this plugin */
protected $type = 'export_pdf';

Expand All @@ -22,13 +22,14 @@ class MenuItem extends AbstractItem {
/**
* MenuItem constructor.
*/
public function __construct() {
public function __construct()
{
parent::__construct();
global $REV, $DATE_AT;

if($DATE_AT) {
if ($DATE_AT) {
$this->params['at'] = $DATE_AT;
} elseif($REV) {
} elseif ($REV) {
$this->params['rev'] = $REV;
}
}
Expand All @@ -38,7 +39,8 @@ public function __construct() {
*
* @return string
*/
public function getLabel() {
public function getLabel()
{
$hlp = plugin_load('action', 'dw2pdf');
return $hlp->getLang('export_pdf_button');
}
Expand Down
6 changes: 3 additions & 3 deletions _test/ActionPagenameSortTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public function testDirectPagenameSort()
{
$action = new \action_plugin_dw2pdf();

$this->assertLessThan(0, $action->_pagenamesort(['id' => 'bar'], ['id' => 'bar:start']));
$this->assertGreaterThan(0, $action->_pagenamesort(['id' => 'bar:bar'], ['id' => 'bar:start']));
$this->assertLessThan(0, $action->cbPagenameSort(['id' => 'bar'], ['id' => 'bar:start']));
$this->assertGreaterThan(0, $action->cbPagenameSort(['id' => 'bar:bar'], ['id' => 'bar:start']));
}

/**
Expand Down Expand Up @@ -96,7 +96,7 @@ public function testPagenameSort($comment, $expected)

// run sort
$action = new \action_plugin_dw2pdf();
usort($input, [$action, '_pagenamesort']);
usort($input, [$action, 'cbPagenameSort']);

$this->assertSame($prepared, $input);
}
Expand Down
6 changes: 6 additions & 0 deletions _test/DokuImageProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
*/
class DokuImageProcessorTest extends DokuWikiTest
{
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
require_once __DIR__ . '/../vendor/autoload.php';
}


/**
* @return array the Testdata
Expand Down
Loading