Repository navigation
Expand file tree
/
Copy pathPvcCore.module
More file actions
662 lines (590 loc) · 23 KB
/
Copy pathPvcCore.module
File metadata and controls
662 lines (590 loc) · 23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
<?php
/**
* Pvc Core Module Class V. 0.9.1
* Part of Pvc, a module for ProcessWire 2.3+
*
* by Oliver Wehn
* https://github.com/oliverwehn
*
*
* Core class takes care of routing requests to their
* associated controllers and actions
*
*/
class PvcCore extends WireData implements Module, ConfigurableModule {
const PERMISSION_NAME = 'pvc-admin';
const MODULE_NAME = 'PvcCore';
const DEFAULT_LAYOUT = 'default';
const DEFAULT_RENDERER = 'Native';
private $_renderer = null;
private static
$defaults = array(
'baseControllerPath' => 'site/templates/',
'layoutsPath' => 'site/templates/layouts/',
'controllersPath' => 'site/templates/controllers/',
'viewsPath' => 'site/templates/views/',
'snippetsPath' => 'site/templates/snippets/',
'assetsPath' => 'site/templates/assets/',
'scriptsMarkup' => '<script src="%s"></script>',
'stylesMarkup' => '<link rel="stylesheet" href="%s">',
'rendererName' => self::DEFAULT_RENDERER
);
public static function getModuleInfo(){
return array(
'title' => 'Pvc Core',
'summary' => __('PVC stands for Page-View-Controller and brings MVCish templating to ProcessWire.'),
'autoload' => true,
'version' => 100,
'author' => 'Oliver Wehn',
'href' => 'https://github.com/oliverwehn/Pvc',
'singular' => true,
'installs' => ['PvcRendererNative']
);
}
public function __construct() {
}
public function init() {
// set global pvc var
Wire::setFuel('pvc', $this);
// manipulate render event
$this->addHookBefore('Page::viewable', $this, 'stubTemplate');
$this->addHookBefore('PageRender::renderPage', $this, 'renderView');
$this->addHookAfter('PageRender::renderPage', $this, 'cacheOutput');
// set up renderer
if(!$this->cfgRendererName) {
$this->cfgRendererName = self::DEFAULT_RENDERER;
}
// set relative template dir
$this->templatesRelPath = str_replace($this->config->paths->root, '', $this->config->paths->templates);
// set up default paths from config
$pvcPaths = new Paths($this->config->paths->get('root'));
$pvcUrls = new Paths($this->config->urls->templates);
$pvcPaths->set('views', $this->_getDefaultPath('views'));
$pvcPaths->set('controllers', $this->_getDefaultPath('controllers'));
$pvcPaths->set('layouts', $this->_getDefaultPath('layouts'));
$pvcPaths->set('snippets', $this->_getDefaultPath('snippets'));
$pvcPaths->set('assets', $this->_getDefaultPath('assets'));
$pvcUrls->set('assets', $this->getRelPath($pvcPaths->get('assets'), $this->config->urls->templates));
$pvcPaths->set('styles', $this->validateDir($pvcPaths->get('assets') . 'styles/'));
$pvcUrls->set('styles', $this->getRelPath($pvcPaths->get('styles'), $this->config->urls->templates));
$pvcPaths->set('scripts', $this->validateDir($pvcPaths->get('assets') . 'scripts/'));
$pvcUrls->set('scripts', $this->getRelPath($pvcPaths->get('scripts'), $this->config->urls->templates));
$pvcPaths->set('images', $this->validateDir($pvcPaths->get('assets') . 'images/'));
$pvcUrls->set('images', $this->getRelPath($pvcPaths->get('images'), $this->config->urls->templates));
$this->set('paths', $pvcPaths);
$this->set('urls', $pvcUrls);
// register class autoloader
spl_autoload_register(array(&$this, 'autoloadClass'));
// set up app controller
$baseControllerClass = $this->getClassName('base', 'controller', false);
if(!class_exists($baseControllerClass)) {
$baseControllerPath = $this->paths->controllers . $this->getFilenameFromClass($baseControllerClass, false);
if(!file_exists($baseControllerPath)) {
$path = dirname(__FILE__) . '/install/' . $this->getFilenameFromClass($baseControllerClass, false);
if(file_exists($path)) {
copy($path, $baseControllerPath);
}
}
// include BaseController class
require_once($baseControllerPath);
}
}
/**
* Auto-loads or generates PVC classes
* @method autoloadClass
* @param $className String
* @return true/false Boolean
*/
public function autoloadClass($className) {
$matched = preg_match('#^(([A-Z][a-z0-9]+)+)(View|Controller)$#', $className, $match);
if($matched && $match[1] !== 'Pvc') {
$classId = $match[1];
$classType = strtolower($match[3]);
$classFilename = PvcCore::getConfigValue('cfg' . ucfirst($classType) .'sPath') . PvcCore::getFilenameFromClass($className, false);
// save working dir
$saveDir = getcwd();
chdir(dirname(getenv('SCRIPT_FILENAME')));
if(file_exists($classFilename)) require_once($classFilename);
// restore working dir
chdir($saveDir);
if(!class_exists($className)) {
if($classId !== 'Base') {
// look up base class for type
$baseClass = PvcCore::getClassName('Base', $classType);
$extendBaseClass = class_exists($baseClass) ? true : $this->autoloadClass($baseClass);
}
if($extendBaseClass)
$extended = call_user_func($baseClass . '::extend', $className);
else
$extended = call_user_func('Pvc' . ucfirst($classType) . '::extend', $className);
}
return true;
}
else {
$classFilename = dirname(__FILE__) . '/' . $className . '.php';
if(file_exists($classFilename)) {
require_once($classFilename);
}
return class_exists($className);
}
}
/**
* Replaces method renderPage in PageRender module
* @method renderPage
* @param $event Event Object
* @return null
*/
public function renderView($event) {
if($this->page->rootParent->id !== $this->config->adminRootPageID) {
$oEvent = $event->arguments[0];
$module = $event->object;
$page = $oEvent->object;
$_page = $this->wire('page');
// update options with route info
$optionsIndex = 0;
if($page->template == 'admin') return;
if(!is_array($oEvent->arguments($optionsIndex))) {
if(is_string($oEvent->arguments($optionsIndex))) {
$optionsIndex = 1;
}
}
if(!is_array($oEvent->arguments($optionsIndex)))
$options = array();
else
$options = $oEvent->arguments($optionsIndex);
$options = array_merge(array(
'allowCache' => true,
'forceBuildCache' => false
), $options, $this->_getActionRoute($options));
// get cache and return if allowed
// $pageRender = $this->modules->get('PageRender');
$pageRender = $event->object;
if($options['allowCache']) {
$cacheAllowed = $options['allowCache'] && $pageRender->isCacheAllowed($page);
$cacheFile = null;
if($cacheAllowed) {
$cacheFile = $pageRender->getCacheFile($page, $options);
if(!$options['forceBuildCache'] && ($data = $cacheFile->get()) !== false) {
$event->replace = true;
// extract header from cache data
if(preg_match('#^\[(Content-type: ?([^\]]+))\]\n#i', $data, $match)) {
$data = implode("\n", array_slice(explode("\n", $data, 2), 1));
$contentType = $match[1];
header($contentType);
}
$oEvent->return = $data;
if($_page) $this->wire('page', $_page);
return;
}
else {
$options['allowCache'] = false;
$options['forceBuildCache'] = true;
}
}
}
if($optionsIndex == 1) {
$options['filename'] = $oEvent->arguments(0);
$oEvent->arguments($optionsIndex, null);
$optionsIndex = 0;
}
$oEvent->arguments($optionsIndex, $options);
// get/create proxy and inject into render process
if(($proxy = $this->get('proxy')) && ($proxy->id == $page->id)) {
$oEvent->object = $proxy;
}
else {
$oEvent->object = new PvcPageProxy($page);
}
$event = $oEvent;
}
}
public function cacheOutput($event) {
$oEvent = $event->arguments[0];
$page = $oEvent->object->get('page');
$options = $oEvent->arguments[0];
if(!$options['allowCache'] && $options['forceBuildCache']) {
$options['allowCache'] = true;
$options['forceBuildCache'] = false;
$data = $oEvent->return;
// extract content-type header
$headers = headers_list();
$header = false;
for($i=count($headers)-1; $i>=0; $i--) {
if(preg_match('#^Content\-type:#i', $headers[$i])) {
$header = $headers[$i];
break;
}
}
// store content-type header
if($header)
$data = "[{$header}]\n" . $data;
// save output data to cache file
$pageRender = $event->object;
$cacheFile = $pageRender->getCacheFile($page, $options);
$cacheFile->save($data);
}
}
public function stubTemplate($event) {
$page = $event->object;
if($page->rootParent->id !== $this->config->adminRootPageID) {
$proxy = new PvcPageProxy($page);
$this->set('proxy', $proxy);
$event->return = true;
}
}
/**
* Get action route
*/
private function _getActionRoute(Array &$options) {
if((!array_key_exists('pageStack', $options)) || (count($options['pageStack']) == 0)) {
if(!array_key_exists('route', $options)) {
$urlSegments = array();
if($this->input->urlSegments) {
for($i=0, $cnt=count($this->input->urlSegments); $i<=$cnt; $i++) {
if($segment = $this->input->urlSegments[$i])
$urlSegments[] = $segment;
}
}
$options['route'] = '/' . (count($urlSegments) > 0 ? implode('/', $urlSegments) . '/' : '');
}
}
return $options;
}
/**
* Handling renderer
*/
// set up renderer
private function initRenderer($rendererName = NULL) {
$class = 'PvcRenderer';
if(!is_string($rendererName)) $rendererName = $this->cfgRendererName;
$instanceOf = $class;
$class .= $this->camelcase($rendererName);
if(!class_exists($class)) {
$rendererPath = $this->cleanPath(dirname(__FILE__));
require_once($rendererPath . $class . '.php');
}
$renderer = new $class;
if(!($renderer instanceof $instanceOf)) {
throw new WireException(sprintf($this->_('Renderer "%s" can’t be initialized.'), $class));
}
return $renderer;
}
// returns current template engine
public function &getRenderer($rendererName = NULL) {
if(is_string($rendererName)) {
$renderer = &$this->initRenderer($rendererName);
}
else {
if(!$this->_renderer) {
$this->_renderer = $this->initRenderer();
}
$renderer = &$this->_renderer;
}
return $renderer;
}
/**
* Handling files and paths
*/
// Set default dir after checking it’s existence. Create if not existing
private function _getDefaultPath($key) {
if(!$relPath = $this->get('cfg' . $this->camelcase($key) . 'Path')) {
$relPath = self::$defaults[$key . 'Path'];
}
$path = $this->cleanPath($this->config->paths->root . $relPath);
return $this->validateDir($path, false);
}
// Check if dir is valid. If it doesn’t exist, create it.
public static function validateDir($path, $clean=true) {
if($clean) $path = self::cleanPath($path);
if((!is_dir($path)) && (!mkdir($path))) {
throw new WireException(sprintf(__("Directory '%s' wasn’t found and coundn’t be created."), $path));
}
return $path;
}
// beautify path string
public static function cleanPath($path) {
$path = isset($this)?$this->config->paths->normalizeSeparators($path):wire('config')->paths->normalizeSeparators($path);
return str_replace("//", "/", rtrim($path, "/") . "/");
}
// get paths relative to template directory
public static function getRelPath($path, $relTo=null, $prepSlash=false) {
if(isset($this)) {
// in object context
$config = &$this->config;
} else {
// in static context
$config = wire('config');
}
if(!$relTo) $rel_to = $config->paths->root;
if(preg_match("#^".preg_quote($config->paths->templates)."(.*)$#", $path, $match)) {
return ($prepSlash?"/":"") . rtrim($match[1]);
} else {
return false;
}
}
// Check, if dir is empty
public static function isDirEmpty($path) {
if (!is_readable($path)) return NULL;
$handle = opendir($path);
while ($f = readdir($handle)) {
if ($f != "." && $f != "..") {
return false;
}
}
return true;
}
/**
* Helpers for files, filenames
*/
// Get file extension
public static function ext($type, $renderer=null) {
$rendererClass = wire('pvc')->renderer;
$type = rtrim($type, 's') . 's';
if(!$rendererClass) $rendererClass = 'PvcRenderer' . ucfirst(strtolower(self::DEFAULT_RENDERER));
$exts = array(
'models' => '.model.php',
'controllers' => '.controller.php',
'layouts' => '.layout.php',
'views' => '.view.php',
'templates' => '.tmpl.php',
'snippets' => '.snippet.php'
);
return $exts[$type];
// return $rendererClass::ext($type);
}
// Sanitize controller name
public static function getControllerName($templateName) {
return self::getClassName($templateName, 'controller');
}
// Sanitize controller name
public static function getClassName($templateName, $type='', $protectBase=true) {
if(($protectBase) && ($templateName == 'base')) $templateName .= '1';
$type = is_string($type) ? self::camelcase($type) : '';
$className = self::camelcase($templateName) . $type;
return $className;
}
// Camelcase it
public static function camelcase($str) {
$str = preg_replace("#[-_]#", "-", $str);
$parts = explode('-', $str);
array_walk($parts, create_function('&$val', '$val = ucfirst(strtolower($val));'));
$camelcase = implode('', $parts);
if(preg_match("#^([A-Z][a-z0-9]+)+$#", $camelcase)) return $camelcase;
else throw new \WireException(sprintf(_('Wasn’t able to camel case template name. Resulted in "%s".'), $camelcase));
}
// Sanitize filename
public static function sanitizeFilename($className) {
if(preg_match_all("#([A-Z][^A-Z$]+)#", $className, $matches)) {
if(in_array($matches[1][count($matches[1]) - 1], array('View', 'Controller')))
array_pop($matches[1]);
$filename = strtolower(implode('_', $matches[1]));
} else {
$filename = strtolower($className);
}
if(preg_match("#^[a-z0-9_]+$#", $filename)) {
return $filename;
}
else {
return false;
}
}
// Get filename from classname
public static function getFilenameFromClass($className, $protectBase=true) {
if(!preg_match('#^(([A-Z][a-z0-9]+)+)([A-Z][a-z]+)$#', $className, $match))
return false;
$name = $match[1];
$type = strtolower($match[3]);
return self::getFilename($name, $type, $protectBase);
}
public static function getFilename($name, $type, $protectBase=true) {
if(($protectBase) && (strtolower($name) == 'base'))
$name .= '1';
$filename = self::sanitizeFilename($name);
return $filename ? $filename . self::ext($type) : false;
}
// Sanitize controller name
public static function sanitizeControllerName($name, $class=false) {
if(preg_match("#[/\\\]#", $name)) {
// May be a path. Deal with it.
$name = basename($name, self::ext('controllers'));
}
$name = preg_replace("#[-_]#", "-", $name);
$parts = explode('-', $name);
array_walk($parts, create_function('&$val', '$val = ucfirst(strtolower($val));'));
$controllerName = implode('', $parts);
if(!preg_match("#^([A-Z][a-z0-9]+)+$#", $controllerName)) return false;
return $controllerName . ($class ? 'Controller' : '');
}
// Get controller class name with or without namespace
public static function getControllerClassName($name) {
if(is_object($name)) return $this->getClass($name);
$class_name = self::sanitizeControllerName($name) . 'Controller';
return $class_name;
}
// Get class name for object with or without namespace
public static function getClass($controller) {
return get_class($controller);
}
// Get array of controller actions
public static function getControllerActions($class) {
if(!class_exists($class)) {
if(isset($this))
$controllerPath = $this->paths->controllers . getFilenameFromClass($class);
else
$controllerPath = self::getConfigValue('cfgControllersPath') . self::getFilenameFromClass($class);
$saveDir = getcwd();
chdir(dirname(getenv('SCRIPT_FILENAME')));
if((!@require_once($controllerPath)) || (!class_exists($class))) {
chdir($saveDir);
return false;
}
else {
chdir($saveDir);
}
}
$actions = array();
do {
$reflection = new ReflectionClass($class);
foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
if ($method->class == $reflection->getName() && $method->name !== 'init') {
$actions[] = $method->name;
}
}
$class = get_parent_class($class);
} while($class !== 'BaseController' && $class !== 'PvcController');
return $actions;
}
/**
* Configuration
*/
// Module configuration form
/**
* Configuration
*/
static public function getModuleConfigInputfields(array $data) {
$pvc = wire('pvc');
$form = new InputfieldForm();
$form->attr('id', 'pvc-config');
$wrapper = new InputfieldWrapper();
$wrapper->label = __("General Configuration");
// config
$config = wire('config');
// relative template dir
$templatesRelPath = str_replace($config->paths->root, '', $config->paths->templates);
// field for name of default layout file
$fieldValue = isset($data['cfgDefaultLayout']) ? $data['cfgDefaultLayout'] : self::DEFAULT_LAYOUT;
$cfgDefaultLayout = $fieldValue . self::ext('layouts');
$field = new InputfieldText();
$field->label = 'Default layout file (php file in your layouts folder)';
$field->attr('name+id', 'cfgDefaultLayout');
$field->description = file_exists(wire('config')->paths->root . $fieldValue . $cfgDefaultLayout)?sprintf(__("Layout file '%s' was found."), $cfgDefaultLayout):sprintf(__("Please provide a layout file '%s' in your layout directory '%s'."), $cfgDefaultLayout, $fieldValue);
$field->value = $fieldValue;
$wrapper->append($field);
// field for switching template engine
$field = new InputfieldSelect();
$field->label = 'Default Template Renderer';
$field->attr('name+id', 'cfgRendererName');
$modules = wire('modules');
if(!array_key_exists('cfgRendererName', $data)) $data['cfgRendererName'] = self::DEFAULT_RENDERER;
// $renderers = $modules->find('class^=PvcRenderer');
foreach($modules as $module) {
if(preg_match('#^PvcRenderer([A-Z].+)$#', $module, $match)) {
$name = $match[1];
$field->addOption($name, null, $data['cfgRendererName'] === $name ? array('selected'=>'selected'):null);
}
}
$field->removeOption('');
$wrapper->append($field);
$form->append($wrapper);
// paths
$wrapper = new InputfieldWrapper();
$wrapper->label = __("Configure file locations");
// field for layouts path
$field = new InputfieldText();
$field->label = "Layouts path";
$field->attr('name+id', 'cfgLayoutsPath');
if(isset($data['cfgLayoutsPath']) ? $field->value = self::cleanPath($data['cfgLayoutsPath']) : $field->value = self::$defaults['layoutsPath']);
$wrapper->append($field);
// field for app controller path
$field = new InputfieldText();
$field->label = 'App Controller folder, where is the App Controller located';
$field->attr('name+id', 'cfgBaseControllerPath');
if(isset($data['cfgBaseControllerPath']) ? $field->value = self::cleanPath($data['cfgBaseControllerPath']) : $field->value = self::$defaults['baseControllerPath']);
$wrapper->append($field);
$form->append($wrapper);
// field for controllers path
$field = new InputfieldText();
$field->label = "Controllers path";
$field->attr('name+id', 'cfgControllersPath');
if(isset($data['cfgControllersPath']) ? $field->value = self::cleanPath($data['cfgControllersPath']) : $field->value = self::$defaults['controllersPath']);
$wrapper->append($field);
// field for snippets path
$field = new InputfieldText();
$field->label = "Snippets path";
$field->attr('name+id', 'cfgSnippetsPath');
if(isset($data['cfgSnippetsPath']) ? $field->value = self::cleanPath($data['cfgSnippetsPath']) : $field->value = self::$defaults['snippetsPath']);
$wrapper->append($field);
// field for views path
$field = new InputfieldText();
$field->label = "Views path";
$field->attr('name+id', 'cfgViewsPath');
if(isset($data['cfgViewsPath']) ? $field->value = self::cleanPath($data['cfgViewsPath']) : $field->value = self::$defaults['viewsPath']);
$wrapper->append($field);
$form->append($wrapper);
// field for assets path
$field = new InputfieldText();
$field->label = "Assets path";
$field->attr('name+id', 'cfgAssetsPath');
if(isset($data['cfgAssetsPath']) ? $field->value = self::cleanPath($data['cfgAssetsPath']) : $field->value = self::$defaults['assetsPath']);
$wrapper->append($field);
$form->append($wrapper);
// paths
$wrapper = new InputfieldWrapper();
$wrapper->label = __("Markup Templates");
// field for styles markup
$field = new InputfieldText();
$field->label = "Styles";
$field->attr('name+id', 'cfgStylesMarkup');
if(isset($data['cfgStylesMarkup']) ? $field->value = $data['cfgStylesMarkup'] : $field->value = self::$defaults['stylesMarkup']);
$wrapper->append($field);
// field for scripts markup
$field = new InputfieldText();
$field->label = "Scripts";
$field->attr('name+id', 'cfgScriptsMarkup');
if(isset($data['cfgScriptsMarkup']) ? $field->value = $data['cfgScriptsMarkup'] : $field->value = self::$defaults['scriptsMarkup']);
$wrapper->append($field);
$form->append($wrapper);
// copy BaseController
$modulePath = dirname(__FILE__) . '/install/';
$basePath = dirname(getenv('SCRIPT_FILENAME')) . '/';
$files = array(
'base.view.php' => 'site/templates/views/',
'home.controller.php' => 'site/templates/controllers/',
'index.tmpl.php' => 'site/templates/views/home/',
'default.tmpl.php' => 'site/templates/layouts/',
);
foreach($files as $f => $dest) {
$dest = $basePath . $dest;
self::validateDir($dest);
$src = $modulePath . $f;
$dest = $dest . $f;
if(file_exists($src) && !file_exists($dest)) copy($src, $dest);
}
return $form;
}
// Returns config values of module
public static function getConfigValue($key) {
if(isset($this)) {
if($this->$key) return $this->key;
} else {
$modules = wire('modules');
$moduleConfig = $modules->getModuleConfigData(__CLASS__);
return array_key_exists($key, $moduleConfig) ? $moduleConfig[$key] : self::$defaults[lcfirst(preg_replace("#^cfg#", "", $key))];
}
return false;
}
public function ___install() {
}
public function ___uninstall() {
}
}