| 1 | <?php |
||||||
| 2 | |||||||
| 3 | class action_plugin_pwaoffline extends DokuWiki_Action_Plugin |
||||||
|
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. Loading history...
|
|||||||
| 4 | { |
||||||
| 5 | |||||||
| 6 | /** |
||||||
| 7 | * Registers a callback function for a given event |
||||||
| 8 | * |
||||||
| 9 | * @param Doku_Event_Handler $controller DokuWiki's event controller object |
||||||
| 10 | * |
||||||
| 11 | * @return void |
||||||
| 12 | */ |
||||||
| 13 | public function register(Doku_Event_Handler $controller) |
||||||
|
0 ignored issues
–
show
The type
Doku_Event_Handler was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||||
| 14 | { |
||||||
| 15 | $controller->register_hook('MANIFEST_SEND', 'BEFORE', $this, 'add144pxImageToManifest'); |
||||||
| 16 | $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'collectPagesToCache'); |
||||||
| 17 | $controller->register_hook('DOKUWIKI_STARTED', 'BEFORE', $this, 'writeConfigToJSINFO'); |
||||||
| 18 | |||||||
| 19 | } |
||||||
| 20 | |||||||
| 21 | /** |
||||||
| 22 | * [Custom event handler which performs action] |
||||||
| 23 | * |
||||||
| 24 | * Event: MANIFEST_SEND |
||||||
| 25 | * |
||||||
| 26 | * @param Doku_Event $event event object by reference |
||||||
| 27 | * @param mixed $param [the parameters passed as fifth argument to register_hook() when this |
||||||
| 28 | * handler was registered] |
||||||
| 29 | * |
||||||
| 30 | * @return void |
||||||
| 31 | */ |
||||||
| 32 | public function add144pxImageToManifest(Doku_Event $event, $param) |
||||||
|
0 ignored issues
–
show
The type
Doku_Event was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||||
| 33 | { |
||||||
| 34 | $event->data['icons'][] = [ |
||||||
| 35 | 'src' => DOKU_BASE . 'lib/plugins/pwaoffline/144.png', |
||||||
|
0 ignored issues
–
show
|
|||||||
| 36 | 'sizes' => '144x144', |
||||||
| 37 | ]; |
||||||
| 38 | } |
||||||
| 39 | |||||||
| 40 | /** |
||||||
| 41 | * Event: AJAX_CALL_UNKNOWN |
||||||
| 42 | * |
||||||
| 43 | * @param Doku_Event $event |
||||||
| 44 | * @param $param |
||||||
| 45 | */ |
||||||
| 46 | public function collectPagesToCache(Doku_Event $event, $param) |
||||||
| 47 | { |
||||||
| 48 | if ($event->data !== 'plugin_pwaoffline') { |
||||||
| 49 | return; |
||||||
| 50 | } |
||||||
| 51 | |||||||
| 52 | global $conf, $INPUT; |
||||||
|
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
Loading history...
|
|||||||
| 53 | |||||||
| 54 | // fixme do a full resync if the config was saved? |
||||||
| 55 | $ts = $INPUT->has('ts') ? $INPUT->int('ts') : 0; |
||||||
| 56 | |||||||
| 57 | search($pages, $conf['datadir'], 'search_allpages', ['skipacl' => false]); |
||||||
|
0 ignored issues
–
show
The function
search was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
Comprehensibility
Best Practice
introduced
by
|
|||||||
| 58 | |||||||
| 59 | $pagesToCache = []; |
||||||
| 60 | foreach ($pages as $pageData) { |
||||||
| 61 | if ($pageData['mtime'] < $ts) { |
||||||
| 62 | continue; |
||||||
| 63 | } |
||||||
| 64 | $pagesToCache[] = [ |
||||||
| 65 | 'link' => wl($pageData['id']), |
||||||
|
0 ignored issues
–
show
The function
wl was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 66 | 'lastmod' => $pageData['mtime'], |
||||||
| 67 | ]; |
||||||
| 68 | } |
||||||
| 69 | |||||||
| 70 | header('Content-Type:application/json'); |
||||||
| 71 | echo json_encode($pagesToCache); |
||||||
| 72 | |||||||
| 73 | $event->preventDefault(); |
||||||
| 74 | $event->stopPropagation(); |
||||||
| 75 | } |
||||||
| 76 | |||||||
| 77 | /** |
||||||
| 78 | * Event: DOKUWIKI_STARTED |
||||||
| 79 | * |
||||||
| 80 | * @param Doku_Event $event |
||||||
| 81 | * @param $param |
||||||
| 82 | */ |
||||||
| 83 | public function writeConfigToJSINFO(Doku_Event $event, $param) |
||||||
| 84 | { |
||||||
| 85 | global $ACT; |
||||||
|
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
Loading history...
|
|||||||
| 86 | if (act_clean($ACT) === 'pwaoffline_serviceworker') { |
||||||
|
0 ignored issues
–
show
The function
act_clean was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 87 | header('Content-Type:application/javascript'); |
||||||
| 88 | $swjs = file_get_contents(__DIR__ . '/sw.js'); |
||||||
| 89 | echo $swjs; |
||||||
| 90 | echo "const swHashVersion = '" . md5($swjs) . "';\n"; |
||||||
| 91 | $idbKeyVal = file_get_contents(__DIR__ . '/node_modules/idb-keyval/dist/idb-keyval-iife.min.js'); |
||||||
| 92 | echo $idbKeyVal; |
||||||
| 93 | exit(); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 94 | } |
||||||
| 95 | |||||||
| 96 | global $JSINFO; |
||||||
|
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
Loading history...
|
|||||||
| 97 | header('X-DWPLUGIN-PWAOFFLINE-ACT:' . act_clean($ACT)); |
||||||
| 98 | if (empty($JSINFO['plugins'])) { |
||||||
| 99 | $JSINFO['plugins'] = []; |
||||||
| 100 | } |
||||||
| 101 | |||||||
| 102 | $JSINFO['plugins']['pwaoffline'] = [ |
||||||
| 103 | 'ts' => time(), |
||||||
| 104 | 'swHashVersion' => md5(file_get_contents(__DIR__ . '/sw.js')), |
||||||
| 105 | ]; |
||||||
| 106 | } |
||||||
| 107 | |||||||
| 108 | } |
||||||
| 109 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths