1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: if (!defined('XOOPS_ROOT_PATH')) exit();
12:
13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26: class Legacy_HelpSmarty extends Smarty
27: {
28: 29: 30:
31: var $mDirname = null;
32:
33: 34: 35:
36: var $mModuleObject = null;
37:
38: 39: 40:
41: var $mFilename = null;
42:
43: function Legacy_HelpSmarty()
44: {
45: parent::Smarty();
46:
47: $this->compile_id = null;
48: $this->_canUpdateFromFile = true;
49: $this->compile_check = true;
50: $this->compile_dir = XOOPS_COMPILE_PATH;
51: $this->left_delimiter = "<{";
52: $this->right_delimiter = "}>";
53:
54: $this->force_compile = true;
55:
56: $this->register_modifier("helpurl", "Legacy_modifier_helpurl");
57: $this->register_modifier("helpimage", "Legacy_modifier_helpimage");
58: }
59:
60: function setDirname($dirname)
61: {
62: $this->mDirname = $dirname;
63: }
64:
65: function _get_auto_filename($autoBase, $autoSource = null, $auotId = null)
66: {
67: $autoSource = $this->mDirname . "_help_" . $autoSource;
68: return parent::_get_auto_filename($autoBase, $autoSource, $auotId);
69: }
70: }
71:
72: function Legacy_modifier_helpurl($file, $dirname = null )
73: {
74: $root =& XCube_Root::getSingleton();
75:
76: $language = $root->mContext->getXoopsConfig('language');
77: $dirname = $root->mContext->getAttribute('legacy_help_dirname');
78:
79: if ( $dirname == null ) {
80: $moduleObject =& $root->mContext->mXoopsModule;
81: $dirname = $moduleObject->get('dirname');
82: }
83:
84:
85:
86:
87:
88: $url = XOOPS_MODULE_URL . "/legacy/admin/index.php?action=Help&dirname=${dirname}&file=${file}";
89:
90: return $url;
91: }
92:
93: function Legacy_modifier_helpimage($file)
94: {
95: $root =& XCube_Root::getSingleton();
96:
97: $language = $root->mContext->getXoopsConfig('language');
98: $dirname = $root->mContext->getAttribute('legacy_help_dirname');
99:
100: $path = "/${dirname}/language/${language}/help/images/${file}";
101: if (!file_exists(XOOPS_MODULE_PATH . $path) && $language != "english") {
102: $path = "/${dirname}/language/english/help/images/${file}";
103: }
104:
105: return XOOPS_MODULE_URL . $path;
106: }
107:
108: 109: 110: 111:
112: class Legacy_HelpAction extends Legacy_Action
113: {
114: var $mModuleObject = null;
115: var $mContents = null;
116:
117: var $mErrorMessage = null;
118:
119: 120: 121:
122: var $_mDirname = null;
123:
124: 125: 126:
127: var $mCreateHelpSmarty = null;
128:
129: function Legacy_HelpAction($flag)
130: {
131: parent::Legacy_Action($flag);
132:
133: $this->mCreateHelpSmarty =new XCube_Delegate();
134: $this->mCreateHelpSmarty->add(array(&$this, '_createHelpSmarty'));
135: $this->mCreateHelpSmarty->register('Legacy_HelpAction.CreateHelpSmarty');
136: }
137:
138: function prepare(&$controller, &$xoopsUser)
139: {
140: parent::prepare($controller, $xoopsUser);
141: $this->_mDirname = xoops_getrequest('dirname');
142: }
143:
144: function hasPermission(&$controller, &$xoopsUser)
145: {
146: $dirname = xoops_getrequest('dirname');
147: $controller->mRoot->mRoleManager->loadRolesByDirname($this->_mDirname);
148: return $controller->mRoot->mContext->mUser->isInRole('Module.' . $dirname . '.Admin');
149: }
150:
151: function getDefaultView(&$controller, &$xoopsUser)
152: {
153: $moduleHandler =& xoops_gethandler('module');
154: $this->mModuleObject =& $moduleHandler->getByDirname($this->_mDirname);
155:
156: $language = $controller->mRoot->mContext->getXoopsConfig('language');
157:
158:
159:
160:
161: $helpfile = xoops_getrequest('file') ? xoops_getrequest('file') : $this->mModuleObject->getHelp();
162:
163:
164:
165:
166: $smarty = null;
167: $this->mCreateHelpSmarty->call(new XCube_Ref($smarty));
168: $smarty->setDirname($this->_mDirname);
169:
170:
171:
172:
173:
174:
175: $template_dir = XOOPS_MODULE_PATH . "/" . $this->_mDirname . "/language/${language}/help";
176: if (!file_exists($template_dir . "/" . $helpfile)) {
177: $template_dir = XOOPS_MODULE_PATH . "/" . $this->_mDirname . "/language/english/help";
178: if (!file_exists($template_dir . "/" . $helpfile)) {
179: $this->mErrorMessage = _AD_LEGACY_ERROR_NO_HELP_FILE;
180: return LEGACY_FRAME_VIEW_ERROR;
181: }
182: }
183:
184: $controller->mRoot->mContext->setAttribute('legacy_help_dirname', $this->_mDirname);
185:
186: $smarty->template_dir = $template_dir;
187: $this->mContents = $smarty->fetch("file:" . $helpfile);
188:
189: return LEGACY_FRAME_VIEW_SUCCESS;
190: }
191:
192: function _createHelpSmarty(&$smarty)
193: {
194: if (!is_object($smarty)) {
195: $smarty = new Legacy_HelpSmarty();
196: }
197: }
198:
199: function executeViewSuccess(&$controller, &$xoopsUser, &$renderer)
200: {
201: $renderer->setTemplateName("help.html");
202:
203: $module =& Legacy_Utils::createModule($this->mModuleObject);
204:
205: $renderer->setAttribute('module', $module);
206: $renderer->setAttribute('contents', $this->mContents);
207: }
208:
209: function executeViewError(&$controller, &$xoopsUser, &$renderer)
210: {
211: $controller->executeRedirect('./index.php?action=ModuleList', 1, $this->mErrorMessage);
212: }
213: }
214:
215: ?>
216: