source: temp/test-xoops.ec-cube.net/html/header.php @ 405

Revision 405, 15.3 KB checked in by root, 20 years ago (diff)
Line 
1<?php
2// $Id: header.php,v 1.7 2006/07/27 00:17:17 onokazu Exp $
3//  ------------------------------------------------------------------------ //
4//                XOOPS - PHP Content Management System                      //
5//                    Copyright (c) 2000 XOOPS.org                           //
6//                       <http://www.xoops.org/>                             //
7//  ------------------------------------------------------------------------ //
8//  This program is free software; you can redistribute it and/or modify     //
9//  it under the terms of the GNU General Public License as published by     //
10//  the Free Software Foundation; either version 2 of the License, or        //
11//  (at your option) any later version.                                      //
12//                                                                           //
13//  You may not change or alter any portion of this comment or credits       //
14//  of supporting developers from this source code or any supporting         //
15//  source code which is considered copyrighted (c) material of the          //
16//  original comment or credit authors.                                      //
17//                                                                           //
18//  This program is distributed in the hope that it will be useful,          //
19//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
20//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
21//  GNU General Public License for more details.                             //
22//                                                                           //
23//  You should have received a copy of the GNU General Public License        //
24//  along with this program; if not, write to the Free Software              //
25//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
26//  ------------------------------------------------------------------------ //
27
28if (!defined('XOOPS_ROOT_PATH')) {
29    exit();
30}
31include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php';
32if ($xoopsConfig['theme_set'] != 'default' && file_exists(XOOPS_THEME_PATH.'/'.$xoopsConfig['theme_set'].'/theme.php')) {
33    //
34    // Fall back on simple protector of common.php by checking the constant that
35    // is defined in common.php
36    //
37    if (!defined("XOOPS_CACHE_PATH")) {
38        die();
39    }
40
41    // the old way..
42    $xoopsOption['theme_use_smarty'] = 0;
43    if (file_exists(XOOPS_THEME_PATH.'/'.$xoopsConfig['theme_set'].'/language/lang-'.$xoopsConfig['language'].'.php')) {
44        include XOOPS_THEME_PATH.'/'.$xoopsConfig['theme_set'].'/language/lang-'.$xoopsConfig['language'].'.php';
45    } elseif (file_exists(XOOPS_THEME_PATH.'/'.$xoopsConfig['theme_set'].'/language/lang-english.php')) {
46        include XOOPS_THEME_PATH.'/'.$xoopsConfig['theme_set'].'/language/lang-english.php';
47    }
48    $config_handler =& xoops_gethandler('config');
49    $xoopsConfigMetaFooter =& $config_handler->getConfigsByCat(XOOPS_CONF_METAFOOTER);
50    xoops_header(false);
51    include XOOPS_THEME_PATH.'/'.$xoopsConfig['theme_set'].'/theme.php';
52    $xoopsOption['show_rblock'] = (!empty($xoopsOption['show_rblock'])) ? $xoopsOption['show_rblock'] : 0;
53    // include Smarty template engine and initialize it
54    require_once XOOPS_ROOT_PATH.'/class/template.php';
55    $xoopsTpl = new XoopsTpl();
56    if ($xoopsConfig['debug_mode'] == 3) {
57        $xoopsTpl->xoops_setDebugging(true);
58    }
59    if ($xoopsUser != '') {
60        $xoopsTpl->assign(array('xoops_isuser' => true, 'xoops_userid' => $xoopsUser->getVar('uid'), 'xoops_uname' => $xoopsUser->getVar('uname'), 'xoops_isadmin' => $xoopsUserIsAdmin));
61    }
62    $xoopsTpl->assign('xoops_requesturi', htmlspecialchars($GLOBALS['xoopsRequestUri'], ENT_QUOTES));
63    include XOOPS_ROOT_PATH.'/include/old_functions.php';
64
65    if ($xoopsOption['show_cblock'] || (!empty($xoopsModule) && preg_match("/index\.php$/i", xoops_getenv('PHP_SELF')) && $xoopsConfig['startpage'] == $xoopsModule->getVar('dirname'))) {
66        $xoopsOption['show_rblock'] = $xoopsOption['show_cblock'] = 1;
67    }
68    themeheader($xoopsOption['show_rblock']);
69    if ($xoopsOption['show_cblock']) make_cblock();  //create center block
70} else {
71    $xoopsOption['theme_use_smarty'] = 1;
72    // include Smarty template engine and initialize it
73    require_once XOOPS_ROOT_PATH.'/class/template.php';
74    $xoopsTpl = new XoopsTpl();
75    $xoopsTpl->xoops_setCaching(2);
76    if ($xoopsConfig['debug_mode'] == 3) {
77        $xoopsTpl->xoops_setDebugging(true);
78    }
79    $xoopsTpl->assign(array('xoops_theme' => $xoopsConfig['theme_set'], 'xoops_imageurl' => XOOPS_THEME_URL.'/'.$xoopsConfig['theme_set'].'/', 'xoops_themecss'=> xoops_getcss($xoopsConfig['theme_set']), 'xoops_requesturi' => htmlspecialchars($GLOBALS['xoopsRequestUri'], ENT_QUOTES), 'xoops_sitename' => htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES), 'xoops_slogan' => htmlspecialchars($xoopsConfig['slogan'], ENT_QUOTES)));
80    // Meta tags
81    $config_handler =& xoops_gethandler('config');
82    $criteria = new CriteriaCompo(new Criteria('conf_modid', 0));
83    $criteria->add(new Criteria('conf_catid', XOOPS_CONF_METAFOOTER));
84    $config =& $config_handler->getConfigs($criteria, true);
85    foreach (array_keys($config) as $i) {
86        // prefix each tag with 'xoops_'
87        $xoopsTpl->assign('xoops_'.$config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput());
88    }
89    //unset($config);
90    // show banner?
91    if ($xoopsConfig['banners'] == 1) {
92        $xoopsTpl->assign('xoops_banner', xoops_getbanner());
93    } else {
94        $xoopsTpl->assign('xoops_banner', '&nbsp;');
95    }
96    // Weird, but need extra <script> tags for 2.0.x themes
97    $xoopsTpl->assign('xoops_js', '//--></script><script type="text/javascript" src="'.XOOPS_URL.'/include/xoops.js"></script><script type="text/javascript"><!--');
98    // get all blocks and assign to smarty
99    $xoopsblock = new XoopsBlock();
100    $block_arr = array();
101    if (is_object($xoopsUser)) {
102        $xoopsTpl->assign(array('xoops_isuser' => true, 'xoops_userid' => $xoopsUser->getVar('uid'), 'xoops_uname' => $xoopsUser->getVar('uname'), 'xoops_isadmin' => $xoopsUserIsAdmin));
103        if (!empty($xoopsModule)) {
104            // set page title
105            $xoopsTpl->assign(array('xoops_pagetitle' => $xoopsModule->getVar('name'), 'xoops_modulename' => $xoopsModule->getVar('name'), 'xoops_dirname' => $xoopsModule->getVar('dirname')));
106            if (preg_match("/index\.php$/i", xoops_getenv('PHP_SELF')) && $xoopsConfig['startpage'] == $xoopsModule->getVar('dirname')) {
107                $block_arr =& $xoopsblock->getAllByGroupModule($xoopsUser->getGroups(), $xoopsModule->getVar('mid'), true, XOOPS_BLOCK_VISIBLE);
108            } else {
109                $block_arr =& $xoopsblock->getAllByGroupModule($xoopsUser->getGroups(), $xoopsModule->getVar('mid'), false, XOOPS_BLOCK_VISIBLE);
110            }
111        } else {
112            $xoopsTpl->assign('xoops_pagetitle', htmlspecialchars($xoopsConfig['slogan'], ENT_QUOTES));
113            if (!empty($xoopsOption['show_cblock'])) {
114                $block_arr =& $xoopsblock->getAllByGroupModule($xoopsUser->getGroups(), 0, true, XOOPS_BLOCK_VISIBLE);
115            } else {
116                $block_arr =& $xoopsblock->getAllByGroupModule($xoopsUser->getGroups(), 0, false, XOOPS_BLOCK_VISIBLE);
117            }
118        }
119    } else {
120        $xoopsTpl->assign(array('xoops_isuser' => false, 'xoops_isadmin' => false));
121        if (!empty($xoopsModule)) {
122            // set page title
123            $xoopsTpl->assign(array('xoops_pagetitle' => $xoopsModule->getVar('name'), 'xoops_modulename' => $xoopsModule->getVar('name'), 'xoops_dirname' => $xoopsModule->getVar('dirname')));
124            if (preg_match("/index\.php$/i", xoops_getenv('PHP_SELF')) && $xoopsConfig['startpage'] == $xoopsModule->getVar('dirname')) {
125                $block_arr =& $xoopsblock->getAllByGroupModule(XOOPS_GROUP_ANONYMOUS, $xoopsModule->getVar('mid'), true, XOOPS_BLOCK_VISIBLE);
126            } else {
127                $block_arr =& $xoopsblock->getAllByGroupModule(XOOPS_GROUP_ANONYMOUS, $xoopsModule->getVar('mid'), false, XOOPS_BLOCK_VISIBLE);
128            }
129        } else {
130            $xoopsTpl->assign('xoops_pagetitle', htmlspecialchars($xoopsConfig['slogan'], ENT_QUOTES));
131            if (!empty($xoopsOption['show_cblock'])) {
132                $block_arr =& $xoopsblock->getAllByGroupModule(XOOPS_GROUP_ANONYMOUS, 0, true, XOOPS_BLOCK_VISIBLE);
133            } else {
134                $block_arr =& $xoopsblock->getAllByGroupModule(XOOPS_GROUP_ANONYMOUS, 0, false, XOOPS_BLOCK_VISIBLE);
135            }
136        }
137    }
138    foreach (array_keys($block_arr) as $i) {
139        $bcachetime = $block_arr[$i]->getVar('bcachetime');
140        if (empty($bcachetime)) {
141            $xoopsTpl->xoops_setCaching(0);
142        } else {
143            $xoopsTpl->xoops_setCaching(2);
144            $xoopsTpl->xoops_setCacheTime($bcachetime);
145        }
146        $btpl = $block_arr[$i]->getVar('template');
147        if ($btpl != '') {
148            if (empty($bcachetime) || !$xoopsTpl->is_cached('db:'.$btpl, 'blk_'.$block_arr[$i]->getVar('bid'))) {
149                $xoopsLogger->addBlock($block_arr[$i]->getVar('name'));
150                $bresult =& $block_arr[$i]->buildBlock();
151                if (!$bresult) {
152                    continue;
153                }
154                $xoopsTpl->assign_by_ref('block', $bresult);
155                $bcontent = $xoopsTpl->fetch('db:'.$btpl, 'blk_'.$block_arr[$i]->getVar('bid'));
156                $xoopsTpl->clear_assign('block');
157            } else {
158                $xoopsLogger->addBlock($block_arr[$i]->getVar('name'), true, $bcachetime);
159                $bcontent = $xoopsTpl->fetch('db:'.$btpl, 'blk_'.$block_arr[$i]->getVar('bid'));
160            }
161        } else {
162            $bid = $block_arr[$i]->getVar('bid');
163            if (empty($bcachetime) || !$xoopsTpl->is_cached('db:system_dummy.html', 'blk_'.$bid)) {
164                $xoopsLogger->addBlock($block_arr[$i]->getVar('name'));
165                $bresult =& $block_arr[$i]->buildBlock();
166                if (!$bresult) {
167                    continue;
168                }
169                $xoopsTpl->assign_by_ref('dummy_content', $bresult['content']);
170                $bcontent = $xoopsTpl->fetch('db:system_dummy.html', 'blk_'.$bid);
171                $xoopsTpl->clear_assign('block');
172            } else {
173                $xoopsLogger->addBlock($block_arr[$i]->getVar('name'), true, $bcachetime);
174                $bcontent = $xoopsTpl->fetch('db:system_dummy.html', 'blk_'.$bid);
175            }
176        }
177        switch ($block_arr[$i]->getVar('side')) {
178        case XOOPS_SIDEBLOCK_LEFT:
179            if (!isset($show_lblock)) {
180                $xoopsTpl->assign('xoops_showlblock', 1);
181                $show_lblock = 1;
182            }
183            $xoopsTpl->append('xoops_lblocks', array('title' => $block_arr[$i]->getVar('title'), 'content' => $bcontent, 'weight' => $block_arr[$i]->getVar('weight')));
184            break;
185        case XOOPS_CENTERBLOCK_LEFT:
186            if (!isset($show_cblock)) {
187                $xoopsTpl->assign('xoops_showcblock', 1);
188                $show_cblock = 1;
189            }
190            $xoopsTpl->append('xoops_clblocks', array('title' => $block_arr[$i]->getVar('title'), 'content' => $bcontent, 'weight' => $block_arr[$i]->getVar('weight')));
191            break;
192        case XOOPS_CENTERBLOCK_RIGHT:
193            if (!isset($show_cblock)) {
194                $xoopsTpl->assign('xoops_showcblock', 1);
195                $show_cblock = 1;
196            }
197            $xoopsTpl->append('xoops_crblocks', array('title' => $block_arr[$i]->getVar('title'), 'content' => $bcontent, 'weight' => $block_arr[$i]->getVar('weight')));
198            break;
199        case XOOPS_CENTERBLOCK_CENTER:
200            if (!isset($show_cblock)) {
201                $xoopsTpl->assign('xoops_showcblock', 1);
202                $show_cblock = 1;
203            }
204            $xoopsTpl->append('xoops_ccblocks', array('title' => $block_arr[$i]->getVar('title'), 'content' => $bcontent, 'weight' => $block_arr[$i]->getVar('weight')));
205            break;
206        case XOOPS_SIDEBLOCK_RIGHT:
207            if (!isset($show_rblock)) {
208                $xoopsTpl->assign('xoops_showrblock', 1);
209                $show_rblock = 1;
210            }
211            $xoopsTpl->append('xoops_rblocks', array('title' => $block_arr[$i]->getVar('title'), 'content' => $bcontent, 'weight' => $block_arr[$i]->getVar('weight')));
212            break;
213        }
214        unset($bcontent);
215    }
216    //unset($block_arr);
217    if (!isset($show_lblock)) {
218        $xoopsTpl->assign('xoops_showlblock', 0);
219    }
220    if (!isset($show_rblock)) {
221        $xoopsTpl->assign('xoops_showrblock', 0);
222    }
223    if (!isset($show_cblock)) {
224        $xoopsTpl->assign('xoops_showcblock', 0);
225    }
226    if (xoops_getenv('REQUEST_METHOD') != 'POST' && !empty($xoopsModule) && !empty($xoopsConfig['module_cache'][$xoopsModule->getVar('mid')])) {
227        $xoopsTpl->xoops_setCaching(2);
228        $xoopsTpl->xoops_setCacheTime($xoopsConfig['module_cache'][$xoopsModule->getVar('mid')]);
229        if (!isset($xoopsOption['template_main'])) {
230            $xoopsCachedTemplate = 'db:system_dummy.html';
231        } else {
232            $xoopsCachedTemplate = 'db:'.$xoopsOption['template_main'];
233        }
234        // generate safe cache Id
235        $xoopsCachedTemplateId = 'mod_'.$xoopsModule->getVar('dirname').'|'.md5(str_replace(XOOPS_URL, '', $GLOBALS['xoopsRequestUri']));
236        if ($xoopsTpl->is_cached($xoopsCachedTemplate, $xoopsCachedTemplateId)) {
237            $xoopsLogger->addExtra($xoopsCachedTemplate, $xoopsConfig['module_cache'][$xoopsModule->getVar('mid')]);
238            $xoopsTpl->assign('xoops_contents', $xoopsTpl->fetch($xoopsCachedTemplate, $xoopsCachedTemplateId));
239            $xoopsTpl->xoops_setCaching(0);
240            if (!headers_sent()) {
241                header ('Content-Type:text/html; charset='._CHARSET);
242            }
243            $xoopsTpl->display($xoopsConfig['theme_set'].'/theme.html');
244            if ($xoopsConfig['debug_mode'] == 2 && $xoopsUserIsAdmin) {
245                echo '<script type="text/javascript">
246                <!--//
247                debug_window = openWithSelfMain("", "xoops_debug", 680, 600, true);
248                ';
249                $content = '<html><head><meta http-equiv="content-type" content="text/html; charset='._CHARSET.'" /><meta http-equiv="content-language" content="'._LANGCODE.'" /><title>'.htmlspecialchars($xoopsConfig['sitename']).'</title><link rel="stylesheet" type="text/css" media="all" href="'.getcss($xoopsConfig['theme_set']).'" /></head><body>'.$xoopsLogger->dumpAll().'<div style="text-align:center;"><input class="formButton" value="'._CLOSE.'" type="button" onclick="javascript:window.close();" /></div></body></html>';
250                $lines = preg_split("/(\r\n|\r|\n)( *)/", $content);
251                foreach ($lines as $line) {
252                    echo 'debug_window.document.writeln("'.str_replace('"', '\"', $line).'");';
253                }
254                echo '
255                debug_window.document.close();
256                //-->
257                </script>';
258            }
259            exit();
260        }
261    } else {
262        $xoopsTpl->xoops_setCaching(0);
263    }
264    if (!isset($xoopsOption['template_main'])) {
265        // new themes using Smarty does not have old functions that are required in old modules, so include them now
266        include XOOPS_ROOT_PATH.'/include/old_theme_functions.php';
267        // need this also
268        $xoopsTheme['thename'] = $xoopsConfig['theme_set'];
269        ob_start();
270    }
271}
272?>
Note: See TracBrowser for help on using the repository browser.