XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
HelpAction.class.php
1<?php
14
15 if (!defined('XOOPS_ROOT_PATH')) {
16 exit();
17 }
18
19/***
20 * @internal
21 *
22 * The subclass of Smarty for the Help viewer, allows using Smarty in html help files.
23 * This class extends Smarty to avoid filename collisions in compiled filenames.
24 * Smarty custom modifiers supported in Help view :
25 * 'helpurl' - modify a relative URL to the dynamic page link.
26 * 'helpimage' - modify an image URL.
27 * Since XCL 2.3
28 * Usage : <{$help}>=module_dirname
29 * Example
30 * Module : <a href="<{$help}>=legacy">System</a>
31 * File : <a href="<{$help}>=legacy&amp;file=block.html">Block</a>
32 * These modifiers take into account the existence of language files.
33 */
34class Legacy_HelpSmarty extends Smarty
35{
39 public $mDirname = null;
40
44 public $mModuleObject = null;
45
49 public $mFilename = null;
50
54 private $_canUpdateFromFile = true;
55
56 public function __construct()
57 {
58 parent::Smarty();
59
60 $this->compile_id = null;
61 $this->compile_check = true;
62 $this->compile_dir = XOOPS_COMPILE_PATH;
63 $this->left_delimiter = '<{';
64 $this->right_delimiter = '}>';
65
66 $this->force_compile = true;
67
68 $this->register_modifier('helpurl', 'Legacy_modifier_helpurl');
69 $this->register_modifier('helpimage', 'Legacy_modifier_helpimage');
70 }
71
72 public function setDirname($dirname)
73 {
74 $this->mDirname = $dirname;
75 }
76
83 public function _get_auto_filename($autoBase, $autoSource = null, $autoId = null)
84 {
85 $autoSource = $this->mDirname . '_help_' . $autoSource;
86 return parent::_get_auto_filename($autoBase, $autoSource, $autoId);
87 }
88}
89
95function Legacy_modifier_helpurl($file, $dirname = null)
96{
97 $root =& XCube_Root::getSingleton();
98
99 $language = $root->mContext->getXoopsConfig('language');
100 $dirname = $root->mContext->getAttribute('legacy_help_dirname');
101
102 if (null === $dirname) {
103 $moduleObject =& $root->mContext->mXoopsModule;
104 $dirname = $moduleObject->get('dirname');
105 }
106
107 //
108 // TODO We should check file_exists -> line 201
109 //
110
111 return XOOPS_MODULE_URL . "/legacy/admin/index.php?action=Help&amp;dirname={$dirname}&amp;file={$file}";
112}
113
118function Legacy_modifier_helpimage($file)
119{
120 $root =& XCube_Root::getSingleton();
121
122 $language = $root->mContext->getXoopsConfig('language');
123 $dirname = $root->mContext->getAttribute('legacy_help_dirname');
124
125 $path = "/{$dirname}/language/{$language}/help/images/{$file}";
126 if (!file_exists(XOOPS_MODULE_PATH . $path) && 'english' !== $language) {
127 $path = "/{$dirname}/language/english/help/images/{$file}";
128 }
129
130 return XOOPS_MODULE_URL . $path;
131}
132
133/***
134 * @internal
135 * This action will show the information of a module specified to user.
136 */
137class Legacy_HelpAction extends Legacy_Action
138{
139 public $mModuleObject = null;
140 public $mContents = null;
141
142 public $mErrorMessage = null;
143
147 public $_mDirname = null;
148
152 public $mCreateHelpSmarty = null;
153
154 public function __construct($flag)
155 {
156 parent::__construct($flag);
157
158 $this->mCreateHelpSmarty =new XCube_Delegate();
159 $this->mCreateHelpSmarty->add([&$this, '_createHelpSmarty']);
160 $this->mCreateHelpSmarty->register('Legacy_HelpAction.CreateHelpSmarty');
161 }
162
163 public function prepare(&$controller, &$xoopsUser)
164 {
165 parent::prepare($controller, $xoopsUser);
166 $this->_mDirname = xoops_getrequest('dirname');
167 }
168
169 public function hasPermission(&$controller, &$xoopsUser)
170 {
171 $dirname = xoops_getrequest('dirname');
172 $controller->mRoot->mRoleManager->loadRolesByDirname($this->_mDirname);
173 return $controller->mRoot->mContext->mUser->isInRole('Module.' . $dirname . '.Admin');
174 }
175
176 public function getDefaultView(&$controller, &$xoopsUser)
177 {
178 $moduleHandler =& xoops_gethandler('module');
179 $this->mModuleObject =& $moduleHandler->getByDirname($this->_mDirname);
180 $language = $controller->mRoot->mContext->getXoopsConfig('language');
181
182 //
183 // TODO We must change the following lines to ActionForm.
184 //
185 $helpfile = xoops_getrequest('file') ?: $this->mModuleObject->getHelp();
186
187 //
188 // Smarty
189 //
190 $smarty = null;
191 $this->mCreateHelpSmarty->call(new XCube_Ref($smarty));
192 $smarty->setDirname($this->_mDirname);
193
194 //
195 // file check
196 //
197 // TODO We should not access files in language directory directly.
198 //
199 $template_dir = XOOPS_MODULE_PATH . '/' . $this->_mDirname . "/language/{$language}/help";
200
201
202/* if (!file_exists($template_dir . '/' . $helpfile)) {
203 $template_dir = XOOPS_MODULE_PATH . '/' . $this->_mDirname . '/language/english/help';
204 if (!file_exists($template_dir . '/' . $helpfile)) {
205 $this->mErrorMessage = _AD_LEGACY_ERROR_NO_HELP_FILE;
206 return LEGACY_FRAME_VIEW_ERROR;
207 }
208 } */
209
210 if (!file_exists($template_dir . '/' . $helpfile)) {
211 // Try XOOPS_TRUST_PATH for D3 modules
212 $trust_dir = XOOPS_TRUST_PATH . '/modules/' . $this->_mDirname . '/language/english/help';
213 if (!file_exists($trust_dir . '/' . $helpfile)) {
214 $this->mErrorMessage = _AD_LEGACY_ERROR_NO_HELP_FILE;
215 return LEGACY_FRAME_VIEW_ERROR;
216 }
217 $template_dir = $trust_dir;
218 }
219
220 $controller->mRoot->mContext->setAttribute('legacy_help_dirname', $this->_mDirname);
221 // Since XCL 2.3
222 // Usage : <{$help}>=module_dirname
223 // Example
224 // Module : <a href="<{$help}>=legacy">System</a>
225 // File : <a href="<{$help}>=legacy&amp;file=block.html">Block</a>
226 $mHelp = XOOPS_MODULE_URL . "/legacy/admin/index.php?action=Help&amp;dirname";
227 $smarty->assign('help',$mHelp);
228 $smarty->template_dir = $template_dir;
229 $this->mContents = $smarty->fetch('file:' . $helpfile);
230
231 return LEGACY_FRAME_VIEW_SUCCESS;
232 }
233
234
235 public function _createHelpSmarty(&$smarty)
236 {
237 if (!is_object($smarty)) {
238 $smarty = new Legacy_HelpSmarty();
239 }
240 }
241
242 public function executeViewSuccess(&$controller, &$xoopsUser, &$renderer)
243 {
244 $renderer->setTemplateName('help.html');
245
246 $module =& Legacy_Utils::createModule($this->mModuleObject);
247
248 $renderer->setAttribute('module', $module);
249 $renderer->setAttribute('contents', $this->mContents);
250 }
251
252 public function executeViewError(&$controller, &$xoopsUser, &$renderer)
253 {
254 $controller->executeRedirect('./index.php?action=ModuleList', 1, $this->mErrorMessage);
255 }
256}
_get_auto_filename($autoBase, $autoSource=null, $autoId=null)
[Final] Used for the simple mechanism for common delegation in XCube.