1<?php
2/**
3 * System help page
4 *
5 * You may not change or alter any portion of this comment or credits
6 * of supporting developers from this source code or any supporting source code
7 * which is considered copyrighted (c) material of the original comment or credit authors.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
13 * @license             GNU GPL 2 (http://www.gnu.org/licenses/gpl-2.0.html)
14 * @author              Andricq Nicolas (AKA MusS)
15 */
16/* @var XoopsModule $module */
17
18// Include header
19include __DIR__ . '/header.php';
20
21$page = system_CleanVars($_REQUEST, 'page', '', 'string');
22$mid  = system_CleanVars($_REQUEST, 'mid', 0, 'int');
23
24// Define main template
25$GLOBALS['xoopsOption']['template_main'] = 'system_help.tpl';
26xoops_cp_header();
27// Define Stylesheet
28$xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/admin.css');
29$xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/help.css');
30// Define Breadcrumb and tips
31$xoBreadCrumb->addLink(_AM_SYSTEM_HELP, 'help.php');
32
33// If $mid > 0, we're in a module's help section.
34if ($mid > 0) {
35    /* @var XoopsModuleHandler $module_handler */
36    $module_handler = xoops_getHandler('module');
37    /* @var XoopsModule $module */
38    $module         = $module_handler->get($mid);
39
40    $xoBreadCrumb->addLink($module->getVar('name'), 'help.php?mid=' . $module->getVar('mid', 's'));
41    $xoBreadCrumb->addLink(system_adminVersion($page, 'name'));
42    $xoBreadCrumb->render();
43
44    // Special handling for the System Module
45    if ($module->getVar('dirname', 'e') === 'system') {
46        xoops_load('xoopslists');
47        $admin_dir = XOOPS_ROOT_PATH . '/modules/system/admin';
48        $dirlist   = XoopsLists::getDirListAsArray($admin_dir);
49        foreach ($dirlist as $directory) {
50            if (file_exists($admin_dir . '/' . $directory . '/xoops_version.php')) {
51                require $admin_dir . '/' . $directory . '/xoops_version.php';
52                if ($modversion['help']) {
53                    $help['name'] = system_adminVersion($directory, 'name');
54                    $help['link'] = 'help.php?mid=' . $mid . '&amp;' . system_adminVersion($directory, 'help');
55                    $xoopsTpl->append_by_ref('help', $help);
56                    unset($help);
57                }
58                unset($modversion);
59            }
60        }
61        unset($dirlist);
62
63        // Handling for all other modules.
64    } else {
65        $list_help      = array();
66        $listed_mods[0] = $module->toArray();
67        $helplist       = $module->getInfo('helpsection');
68        $j              = 0;
69        if (is_array($helplist)) {
70            foreach ($helplist as $helpitem) {
71                if (($helpitem['name'] !== '') && ($helpitem['link'] !== '')) {
72                    $list_help[$j]['name'] = $helpitem['name'];
73                    $list_help[$j]['link'] = 'help.php?mid=' . $mid . '&amp;' . $helpitem['link'];
74                    ++$j;
75                }
76            }
77            $listed_mods[0]['help_page'] = $list_help;
78            $xoopsTpl->assign('list_mods', $listed_mods);
79        }
80        unset($helplist);
81        if (($module->getInfo('help') !== '') && ($j == 0)) {
82            $help['name'] = $module->getInfo('name');
83            $help['link'] = 'help.php?mid=' . $mid . '&amp;' . $module->getInfo('help');
84            $xoopsTpl->append_by_ref('help', $help);
85        }
86        unset($help);
87    }
88
89    $xoopsTpl->assign('modname', $module->getVar('name'));
90
91    if ($page !== '') {
92        // Call template
93        if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'e') . '/language/' . $xoopsConfig['language'] . '/help/' . $page . '.html')) {
94            $helpcontent = $xoopsTpl->fetch(XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'e') . '/language/' . $xoopsConfig['language'] . '/help/' . $page . '.html');
95        } elseif (file_exists(XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'e') . '/language/' . $xoopsConfig['language'] . '/help/' . $page . '.tpl')) {
96            $helpcontent = $xoopsTpl->fetch(XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'e') . '/language/' . $xoopsConfig['language'] . '/help/' . $page . '.tpl');
97        } elseif (file_exists(XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'e') . '/language/english/help/' . $page . '.html')) {
98            $helpcontent = $xoopsTpl->fetch(XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'e') . '/language/english/help/' . $page . '.html');
99        } elseif (file_exists(XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'e') . '/language/english/help/' . $page . '.tpl')) {
100            $helpcontent = $xoopsTpl->fetch(XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'e') . '/language/english/help/' . $page . '.tpl');
101        } else {
102            $xoopsTpl->assign('load_error', 1);
103        }
104        $xoopsTpl->assign('helpcontent', $helpcontent);
105    } else {
106        if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'e') . '/language/' . $xoopsConfig['language'] . '/help/module_index.html')) {
107            $helpcontent = $xoopsTpl->fetch(XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'e') . '/language/' . $xoopsConfig['language'] . '/help/module_index.html');
108        } else {
109            $helpcontent = $module->getInfo('description');
110            $helpcontent = '<div id="non-modhelp">' . $helpcontent . '</div>';
111        }
112        $xoopsTpl->assign('helpcontent', $helpcontent);
113    }
114
115    // This section is called if we're in the general help area.
116} else {
117    $xoBreadCrumb->render();
118
119    // Get Module Handler
120    /* @var XoopsModuleHandler $module_handler */
121    $module_handler = xoops_getHandler('module');
122    $criteria       = new CriteriaCompo();
123    $criteria->setOrder('weight');
124
125    // Get all installed modules
126    $installed_mods = $module_handler->getObjects($criteria);
127    $listed_mods    = array();
128    $i              = 0;
129    $j              = 0;
130    foreach ($installed_mods as $module) {
131        $list_help                      = array();
132        $listed_mods[$i]                = $module->toArray();
133        $listed_mods[$i]['image']       = $module->getInfo('image');
134        $listed_mods[$i]['adminindex']  = $module->getInfo('adminindex');
135        $listed_mods[$i]['version']     = round($module->getVar('version') / 100, 2);
136        $listed_mods[$i]['last_update'] = formatTimestamp($module->getVar('last_update'), 'm');
137        $listed_mods[$i]['author']      = $module->getInfo('author');
138        $listed_mods[$i]['credits']     = $module->getInfo('credits');
139        $listed_mods[$i]['license']     = $module->getInfo('license');
140        $listed_mods[$i]['description'] = $module->getInfo('description');
141
142        // Special handling for the System module
143        if ($module->getVar('dirname', 'e') === 'system') {
144            xoops_load('xoopslists');
145            $admin_dir = XOOPS_ROOT_PATH . '/modules/system/admin';
146            $dirlist   = XoopsLists::getDirListAsArray($admin_dir);
147            foreach ($dirlist as $directory) {
148                if (file_exists($admin_dir . '/' . $directory . '/xoops_version.php')) {
149                    require $admin_dir . '/' . $directory . '/xoops_version.php';
150                    if ($modversion['help']) {
151                        $list_help[$j]['name'] = system_adminVersion($directory, 'name');
152                        $list_help[$j]['link'] = 'help.php?mid=' . $module->getVar('mid', 'e') . '&amp;' . system_adminVersion($directory, 'help');
153                    }
154                    unset($modversion);
155                    ++$j;
156                }
157            }
158            unset($dirlist);
159
160            // Handling for all other modules
161        } else {
162            $helplist = $module->getInfo('helpsection');
163            $k        = 0;
164
165            // Only build the list if one has been defined.
166            if (is_array($helplist)) {
167                foreach ($helplist as $helpitem) {
168                    if (($helpitem['name'] !== '') && ($helpitem['link'] !== '')) {
169                        $list_help[$j]['name'] = $helpitem['name'];
170                        $list_help[$j]['link'] = 'help.php?mid=' . $module->getVar('mid', 'e') . '&amp;' . $helpitem['link'];
171                        ++$j;
172                        ++$k;
173                    }
174                }
175            }
176            unset($helplist);
177
178            // If there is no help section ($k=0), and a lone help parameter has been defined.
179            if (($module->getInfo('help') !== '') && ($k == 0)) {
180                $list_help[$j]['name'] = $module->getInfo('name');
181                $list_help[$j]['link'] = 'help.php?mid=' . $module->getVar('mid', 'e') . '&amp;' . $module->getInfo('help');
182            }
183        }
184
185        $listed_mods[$i]['help_page'] = $list_help;
186        if ($module->getInfo('help') === '') {
187            unset($listed_mods[$i]);
188        }
189        unset($list_help, $module);
190        ++$i;
191        ++$j;
192    }
193    $xoopsTpl->assign('list_mods', $listed_mods);
194
195    if (file_exists(XOOPS_ROOT_PATH . '/modules/system/language/' . $xoopsConfig['language'] . '/help/help_center.html')) {
196        $helpcontent = $xoopsTpl->fetch(XOOPS_ROOT_PATH . '/modules/system/language/' . $xoopsConfig['language'] . '/help/help_center.html');
197    } else {
198        $helpcontent = '<div id="non-modhelp">' . _MD_CPANEL_HELPCENTER . '</div>';
199    }
200
201    $xoopsTpl->assign('helpcontent', $helpcontent);
202}
203
204xoops_cp_footer();
205