1 |
2
|
Manuela
|
<?php
|
2 |
|
|
/*
|
3 |
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
4 |
|
|
*
|
5 |
|
|
* This program is free software: you can redistribute it and/or modify
|
6 |
|
|
* it under the terms of the GNU General Public License as published by
|
7 |
|
|
* the Free Software Foundation, either version 3 of the License, or
|
8 |
|
|
* (at your option) any later version.
|
9 |
|
|
*
|
10 |
|
|
* This program is distributed in the hope that it will be useful,
|
11 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
|
|
* GNU General Public License for more details.
|
14 |
|
|
*
|
15 |
|
|
* You should have received a copy of the GNU General Public License
|
16 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17 |
|
|
*/
|
18 |
|
|
|
19 |
|
|
/**
|
20 |
|
|
* SimpleCommandDispatcher.inc
|
21 |
|
|
*
|
22 |
|
|
* @category Addons
|
23 |
|
|
* @package Addons_Dispatcher
|
24 |
|
|
* @copyright Manuela v.d.Decken <manuela@isteam.de>
|
25 |
|
|
* @author Manuela v.d.Decken <manuela@isteam.de>
|
26 |
|
|
* @license http://www.gnu.org/licenses/gpl.html GPL License
|
27 |
|
|
* @version 3.0.1
|
28 |
|
|
* @lastmodified $Date$
|
29 |
|
|
* @since File available since 17.12.2015
|
30 |
|
|
* @description xyz
|
31 |
|
|
*/
|
32 |
|
|
|
33 |
|
|
require (__DIR__.'/SimpleRegister.php');
|
34 |
|
|
|
35 |
|
|
// detect if system running backend or frontend is already set by SimpleRegister
|
36 |
|
|
// $oApp = (isset($GLOBALS['admin']) ? $GLOBALS['admin'] : $GLOBALS['wb']);
|
37 |
|
|
$bIsBackend = ($oApp instanceof admin);
|
38 |
|
|
// set addon depending path / url
|
39 |
|
|
$sAddonPath = $oReg->AppPath.'modules/'.$sAddonName;
|
40 |
|
|
$sAddonUrl = $oReg->AppUrl.'modules/'.$sAddonName;
|
41 |
|
|
$sAddonRel = '/modules/'.basename(__DIR__);
|
42 |
|
|
$sAddonThemeRel ='/themes/default';
|
43 |
|
|
// define the theme to use -----------------------------------------------------------
|
44 |
|
|
if (is_readable($sAddonPath.'/themes/default')) {
|
45 |
|
|
// first set fallback to system default theme
|
46 |
|
|
$sAddonThemePath = $sAddonPath.'/themes/default';
|
47 |
|
|
$sAddonThemeUrl = $sAddonUrl.'/themes/default';
|
48 |
|
|
}
|
49 |
|
|
if (is_readable($sAddonPath.'/themes/'.$oReg->DefaultTheme)) {
|
50 |
|
|
// overload with the selected theme if accessible
|
51 |
|
|
$sAddonThemePath = $sAddonPath.'/themes/'.$oReg->DefaultTheme;
|
52 |
|
|
$sAddonThemeUrl = $sAddonUrl.'/themes/'.$oReg->DefaultTheme;
|
53 |
|
|
}
|
54 |
|
|
// define the template to use --------------------------------------------------------
|
55 |
|
|
if (is_readable($sAddonPath.'/templates/default')) {
|
56 |
|
|
// first set fallback to system default template
|
57 |
|
|
$sAddonTemplatePath = $sAddonPath.'/templates/default';
|
58 |
|
|
$sAddonTemplateUrl = $sAddonUrl.'/templates/default';
|
59 |
|
|
}
|
60 |
|
|
if (is_readable($sAddonPath.'/templates/'.$oReg->DefaultTemplate)) {
|
61 |
|
|
// try setting to the template of global settings
|
62 |
|
|
$sAddonTemplatePath = $sAddonPath.'/templates/'.$oReg->DefaultTemplate;
|
63 |
|
|
$sAddonTemplateUrl = $sAddonUrl.'/templates/'.$oReg->DefaultTemplate;
|
64 |
|
|
}
|
65 |
|
|
if (!$bIsBackend && is_readable($sAddonPath.'/templates/'.$oReg->Template)) {
|
66 |
|
|
// try setting to the template of page depending settings
|
67 |
|
|
$sAddonTemplatePath = $sAddonPath.'/templates/'.$oReg->Template;
|
68 |
|
|
$sAddonTemplateUrl = $sAddonUrl.'/templates/'.$oReg->Template;
|
69 |
|
|
}
|
70 |
|
|
// load addon depending language file ------------------------------------------------
|
71 |
|
|
if (is_readable($sAddonPath.'/languages/EN.php')) {
|
72 |
|
|
// first load fallback to system default language (EN)
|
73 |
|
|
include $sAddonPath.'/languages/EN.php';
|
74 |
|
|
}
|
75 |
|
|
if (is_readable($sAddonPath.'/languages/'.$oReg->DefaultLanguage.'.php')) {
|
76 |
|
|
// try loading language of global settings
|
77 |
|
|
include $sAddonPath.'/languages/'.$oReg->DefaultLanguage.'.php';
|
78 |
|
|
}
|
79 |
|
|
if (is_readable($sAddonPath.'/languages/'.$oReg->Language.'.php')) {
|
80 |
|
|
// try loading language of user (backend) or page (frontend) defined settings
|
81 |
|
|
include $sAddonPath.'/languages/'.$oReg->Language.'.php';
|
82 |
|
|
}
|
83 |
|
|
// load addon Theme/Template depending language file ---------------------------------
|
84 |
|
|
$sTmp = ($bIsBackend ? $sAddonThemePath : $sAddonTemplatePath).'/languages/';
|
85 |
|
|
if (is_readable($sTmp.'EN.php')) {
|
86 |
|
|
// first load fallback to system default language (EN)
|
87 |
|
|
include $sTmp.'EN.php';
|
88 |
|
|
}
|
89 |
|
|
if (is_readable($sTmp.$oReg->DefaultLanguage.'.php')) {
|
90 |
|
|
// try loading language of global settings
|
91 |
|
|
include $sTmp.$oReg->DefaultLanguage.'.php';
|
92 |
|
|
}
|
93 |
|
|
if (is_readable($sTmp.$oReg->Language.'.php')) {
|
94 |
|
|
// try loading language of user (backend) or page (frontend) defined settings
|
95 |
|
|
include $sTmp.$oReg->Language.'.php';
|
96 |
|
|
}
|
97 |
|
|
// Simple Command Dispatcher ---------------------------------------------------------
|
98 |
|
|
// Include the ordering class
|
99 |
|
|
if (!class_exists('order')) {
|
100 |
|
|
include $oReg->AppPath.'framework/class.order.php';
|
101 |
|
|
}
|
102 |
|
|
if (!class_exists('admin')) {
|
103 |
|
|
include $oReg->AppPath.'framework/class.admin.php';
|
104 |
|
|
}
|
105 |
|
|
if (!class_exists('Translate')) {
|
106 |
|
|
include $oReg->AppPath.'framework/Translate.php';
|
107 |
|
|
}
|
108 |
|
|
Translate::getInstance ()->enableAddon ('modules\\'.$sAddonName);
|
109 |
|
|
// sanitize command from compatibility file
|
110 |
|
|
$sCommand = (isset($sCommand) ? strtolower($sCommand) : '');
|
111 |
|
|
// sanitize/validate request var 'cmd'
|
112 |
|
|
$sCmd = preg_replace(
|
113 |
|
|
'/[^a-z\/0-1]/siu',
|
114 |
|
|
'',
|
115 |
|
|
(isset($_REQUEST['cmd']) ? strtolower($_REQUEST['cmd']) : '')
|
116 |
|
|
);
|
117 |
|
|
// build valid sCommand string
|
118 |
|
|
if (($sCommand && $sCmd)) {
|
119 |
|
|
if (!preg_match('/^'.$sCommand.'/si', $sCmd)) {
|
120 |
|
|
// concate both arguments if needed
|
121 |
|
|
$sCommand .= '/'.$sCmd;
|
122 |
|
|
} else {
|
123 |
|
|
$sCommand = $sCmd;
|
124 |
|
|
}
|
125 |
|
|
|
126 |
|
|
$sCmd = '';
|
127 |
|
|
}
|
128 |
|
|
$sCommand = 'cmd'.str_replace( // remove spaces and add prefix 'cmd'
|
129 |
|
|
' ', '',
|
130 |
|
|
ucfirst( // make first char of every word to uppercase
|
131 |
|
|
str_replace( // change '/' to space
|
132 |
|
|
'/', ' ',
|
133 |
|
|
preg_replace( // change leading 'add/' to 'modify/'
|
134 |
|
|
'/^add\//s',
|
135 |
|
|
'modify/',
|
136 |
|
|
trim(($sCommand ?: $sCmd), '/') // remove leading and trailing slashes
|
137 |
|
|
)
|
138 |
|
|
)
|
139 |
|
|
)
|
140 |
|
|
);
|
141 |
|
|
// execute command -------------------------------------------------------------------
|
142 |
|
|
if (is_readable($sAddonPath.'/cmd/'.$sCommand.'.inc') ) {
|
143 |
|
|
include($sAddonPath.'/cmd/'.$sCommand.'.inc');
|
144 |
|
|
} else {
|
145 |
|
|
throw new Exception('call of invalid command ['.$sCommand.'] for [modules/'.$sAddonName.'] failed!');
|
146 |
|
|
}
|
147 |
|
|
|
148 |
|
|
// end of file
|