Project

General

Profile

wb-2_10_x / branches / main / framework / frontend.functions.php @ 10

1
<?php
2
/**
3
 *
4
 * @category        framework
5
 * @package         frontend.functions
6
 * @author          WebsiteBaker Project
7
 * @copyright       Ryan Djurovich
8
 * @copyright       WebsiteBaker Org. e.V.
9
 * @link            http://websitebaker.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.3
12
 * @requirements    PHP 5.3.6 and higher
13
 * @version         $Id: frontend.functions.php 2 2017-07-02 15:14:29Z Manuela $
14
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb/2.10.x/branches/main/framework/frontend.functions.php $
15
 * @lastmodified    $Date: 2017-07-02 17:14:29 +0200 (Sun, 02 Jul 2017) $
16
 *
17
 */
18
/* -------------------------------------------------------- */
19
// Must include code to stop this file being accessed directly
20
if(!defined('WB_PATH')) {
21
    require_once(dirname(__FILE__).'/globalExceptionHandler.php');
22
    throw new IllegalFileException();
23
}
24
/* -------------------------------------------------------- */
25

    
26
    $include_head_link_css = '';
27
    $include_head_links    = '';
28
    $include_body_links    = '';
29

    
30
    $aAlllowedModules = array();
31
    $aModules = glob (WB_PATH.'/modules/*', GLOB_ONLYDIR|GLOB_NOSORT);
32
    foreach ($aModules as $sPath){
33
        if (is_readable($sPath.'/include.php')){$aAlllowedModules[] = basename($sPath);}
34
    }
35
    $sAllowedModules   = implode(', ',
36
                         array_map(function(&$item) use ($database){
37
                                       return '\''.$database->escapeString($item) .'\'';
38
                                   },$aAlllowedModules));
39

    
40
// workout to included frontend.css, fronten.js and frontend_body.js in snippets and tools
41
    $sql  = 'SELECT `directory`,`function` FROM `'.TABLE_PREFIX.'addons` '
42
          . 'WHERE `type`=\'module\' '
43
          .   'AND `function` IN (\'snippet\', \'tool\') '
44
          .   'AND `directory` IN('.$sAllowedModules.')'
45
          . '';
46
    if(($oSnippets = $database->query($sql)))
47
    {
48
        while($aSnippet = $oSnippets->fetchRow( MYSQLI_ASSOC))
49
        {
50
            $module_dir = $aSnippet['directory'];
51
            if (is_readable(WB_PATH.'/modules/'.$module_dir.'/include.php'))
52
            {
53
                include(WB_PATH.'/modules/'.$module_dir.'/include.php');
54
            // check if frontend.css file needs to be included into the <head></head> of index.php
55
                if( is_readable(WB_PATH .'/modules/'.$module_dir.'/frontend.css')) {
56
                    $include_head_link_css .= "\t".'<link rel="stylesheet" type="text/css" href="'.WB_URL.'/modules/'.$module_dir.'/frontend.css" media="screen" />'."\n";
57
                    $include_head_file = 'frontend.css';
58
                }
59
            // check if frontend.js file needs to be included into the <body></body> of index.php
60
                if(is_readable(WB_PATH .'/modules/'.$module_dir.'/frontend.js')) {
61
                    $include_head_links .= "\t".'<script src="'.WB_URL.'/modules/'.$module_dir.'/frontend.js" type="text/javascript" ></script>';
62
                    $include_head_file = 'frontend.js';
63
                }
64
            // check if frontend_body.js file needs to be included into the <body></body> of index.php
65
                if(is_readable(WB_PATH .'/modules/'.$module_dir.'/frontend_body.js')) {
66
                    $include_body_links .= "\t".'<script src="'.WB_URL.'/modules/'.$module_dir.'/frontend_body.js" type="text/javascript" ></script>'."\n";
67
                    $include_body_file   = 'frontend_body.js';
68
                }
69
            }
70
        }
71
    }
72
/* ------------------------------------------------------------------------------------------------ */
73

    
74
// Frontend functions
75
if(!function_exists('page_link')) {
76
    /**
77
     * generate full qualified URL from relative link based on pages_dir
78
     * @param string $link
79
     * @return string
80
     */
81
    function page_link($link) {
82
        return $GLOBALS['wb']->page_link($link);
83
    }
84
}
85

    
86
if (!function_exists('get_page_link')) {
87
    /**
88
     * get relative link from database based on pages_dir
89
     * @global <type> $database
90
     * @param <type> $id
91
     * @return <type>
92
     */
93
    function get_page_link( $id )
94
    {
95
        global $database;
96
        $sql = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.intval($id);
97
        $link = $database->get_one( $sql );
98
        return $link;
99
    }
100
}
101

    
102
//function to highlight search results
103
if(!function_exists('search_highlight')) {
104
    /**
105
     *
106
     * @staticvar boolean $string_ul_umlaut
107
     * @staticvar boolean $string_ul_regex
108
     * @param string $foo
109
     * @param array $arr_string
110
     * @return string
111
     */
112
    function search_highlight($foo='', $arr_string=array()) {
113
        require_once(WB_PATH.'/framework/functions.php');
114
        static $string_ul_umlaut = FALSE;
115
        static $string_ul_regex = FALSE;
116
        if($string_ul_umlaut === FALSE || $string_ul_regex === FALSE) {
117
            require(WB_PATH.'/search/search_convert.php');
118
        }
119
        $foo = entities_to_umlauts($foo, 'UTF-8');
120
        array_walk($arr_string, create_function('&$v,$k','$v = preg_quote($v, \'~\');'));
121
        $search_string = implode("|", $arr_string);
122
        $string = str_replace($string_ul_umlaut, $string_ul_regex, $search_string);
123
        // the highlighting
124
        // match $string, but not inside <style>...</style>, <script>...</script>, <!--...--> or HTML-Tags
125
        // Also droplet tags are now excluded from highlighting.
126
        // split $string into pieces - "cut away" styles, scripts, comments, HTML-tags and eMail-addresses
127
        // we have to cut <pre> and <code> as well.
128
        // for HTML-Tags use <(?:[^<]|<.*>)*> which will match strings like <input ... value="<b>value</b>" >
129
        $matches = preg_split("~(\[\[.*\]\]|<style.*</style>|<script.*</script>|<pre.*</pre>|<code.*</code>|<!--.*-->|<(?:[^<]|<.*>)*>|\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,8}\b)~iUs",$foo,-1,(PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY));
130
        if(is_array($matches) && $matches != array()) {
131
            $foo = "";
132
            foreach($matches as $match) {
133
                if($match{0}!="<" && !preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,8}$/i', $match) && !preg_match('~\[\[.*\]\]~', $match)) {
134
                    $match = str_replace(array('&lt;', '&gt;', '&amp;', '&quot;', '&#039;', '&nbsp;'), array('<', '>', '&', '"', '\'', "\xC2\xA0"), $match);
135
                    $match = preg_replace('~('.$string.')~ui', '_span class=_highlight__$1_/span_',$match);
136
                    $match = str_replace(array('&', '<', '>', '"', '\'', "\xC2\xA0"), array('&amp;', '&lt;', '&gt;', '&quot;', '&#039;', '&nbsp;'), $match);
137
                    $match = str_replace(array('_span class=_highlight__', '_/span_'), array('<span class="highlight">', '</span>'), $match);
138
                }
139
                $foo .= $match;
140
            }
141
        }
142

    
143
        if(DEFAULT_CHARSET != 'utf-8') {
144
            $foo = umlauts_to_entities($foo, 'UTF-8');
145
        }
146
        return $foo;
147
    }
148
}
149

    
150
if (!function_exists('page_menu')) {
151
    /**
152
     * Old menu generator
153
     * @deprecated from WB 2.8.x and up
154
     * @global <type> $wb
155
     * @param <type> $parent
156
     * @param <type> $menu_number
157
     * @param <type> $item_template
158
     * @param <type> $menu_header
159
     * @param <type> $menu_footer
160
     * @param <type> $default_class
161
     * @param <type> $current_class
162
     * @param <type> $recurse
163
     */
164
    function page_menu($parent = 0, $menu_number = 1, $item_template = '<li[class]>[a] [menu_title] [/a]</li>', $menu_header = '<ul>', $menu_footer = '</ul>', $default_class = ' class="menu_default"', $current_class = ' class="menu_current"', $recurse = LEVEL) {
165
        global $wb;
166
        $wb->menu_number=$menu_number;
167
        $wb->menu_item_template=$item_template;
168
        $wb->menu_item_footer='';
169
        $wb->menu_parent = $parent;
170
        $wb->menu_header = $menu_header;
171
        $wb->menu_footer = $menu_footer;
172
        $wb->menu_default_class = $default_class;
173
        $wb->menu_current_class = $current_class;
174
        $wb->menu_recurse = $recurse+2;
175
        $wb->menu();
176
        unset($wb->menu_parent);
177
        unset($wb->menu_number);
178
        unset($wb->menu_item_template);
179
        unset($wb->menu_item_footer);
180
        unset($wb->menu_header);
181
        unset($wb->menu_footer);
182
        unset($wb->menu_default_class);
183
        unset($wb->menu_current_class);
184
        unset($wb->menu_start_level);
185
        unset($wb->menu_collapse);
186
        unset($wb->menu_recurse);
187
    }
188
}
189

    
190
if (!function_exists('show_menu')) {
191
    /**
192
     * Old menu generator
193
     * @deprecated from WB 2.8.x and up
194
     * @global  $wb
195
     * @param <type> $menu_number
196
     * @param <type> $start_level
197
     * @param <type> $recurse
198
     * @param <type> $collapse
199
     * @param <type> $item_template
200
     * @param <type> $item_footer
201
     * @param <type> $menu_header
202
     * @param <type> $menu_footer
203
     * @param <type> $default_class
204
     * @param <type> $current_class
205
     * @param <type> $parent
206
     */
207
    function show_menu($menu_number = NULL, $start_level=NULL, $recurse = NULL, $collapse = NULL, $item_template = NULL, $item_footer = NULL, $menu_header = NULL, $menu_footer = NULL, $default_class = NULL, $current_class = NULL, $parent = NULL) {
208
        global $wb;
209
        if (isset($menu_number))
210
            $wb->menu_number=$menu_number;
211
        if (isset($start_level))
212
            $wb->menu_start_level=$start_level;
213
        if (isset($recurse))
214
            $wb->menu_recurse=$recurse;
215
        if (isset($collapse))
216
            $wb->menu_collapse=$collapse;
217
        if (isset($item_template))
218
            $wb->menu_item_template=$item_template;
219
        if (isset($item_footer))
220
            $wb->menu_item_footer=$item_footer;
221
        if (isset($menu_header))
222
            $wb->menu_header=$menu_header;
223
        if (isset($menu_footer))
224
            $wb->menu_footer=$menu_footer;
225
        if (isset($default_class))
226
            $wb->menu_default_class=$default_class;
227
        if (isset($current_class))
228
            $wb->menu_current_class=$current_class;
229
        if (isset($parent))
230
            $wb->menu_parent=$parent;
231
        $wb->menu();
232
        unset($wb->menu_recurse);
233
        unset($wb->menu_parent);
234
        unset($wb->menu_start_level);
235
    }
236
}
237

    
238
if (!function_exists('page_content')) {
239
    /**
240
     *
241
     * @global array $TEXT
242
     * @global array $MENU
243
     * @global array $HEADING
244
     * @global array $MESSAGE
245
     * @global array $globals several global vars
246
     * @global datadase $database
247
     * @global wb $wb
248
     * @global string $global_name
249
     * @param int $block
250
     * @return void
251
     */
252
    function page_content($block = 1) {
253
        // Get outside objects
254
        global $TEXT,$MENU,$HEADING,$MESSAGE;
255
        global $globals;
256
        global $database;
257
        global $wb;
258
        $admin = $wb;
259

    
260
        if ($wb->page_access_denied==true) {
261
            echo $MESSAGE['FRONTEND_SORRY_NO_VIEWING_PERMISSIONS'];
262
            return;
263
        }
264
        if ($wb->page_no_active_sections==true) {
265
            echo $MESSAGE['FRONTEND_SORRY_NO_ACTIVE_SECTIONS'];
266
            return;
267
        }
268
        if(isset($globals) AND is_array($globals)) {
269
            foreach($globals AS $global_name) {
270
                global $$global_name;
271
            }
272
        }
273
        // Make sure block is numeric
274
        if (($block = intval($block)) == 0 ) { $block = 1;}
275
        // Include page content
276
        if (!defined('PAGE_CONTENT') OR $block!=1)
277
        {
278
            $page_id = intval($wb->page_id);
279
            if (($wb instanceof frontend) && !$wb->page_is_visible($wb->page)) { // SOLVED dw2015
280
             return ;
281
            }
282
        // First get all sections for this page
283
            $sql  = 'SELECT `section_id`, `module`, `publ_start`, `publ_end` ';
284
            $sql .= 'FROM `'.TABLE_PREFIX.'sections` ';
285
            $sql .= 'WHERE `page_id`='.$page_id.' AND `block`='.$block.' ';
286
            $sql .= 'ORDER BY `position`';
287
            if( !($query_sections = $database->query($sql)) ) { return; }
288
        // If none were found, check if default content is supposed to be shown
289
            if($query_sections->numRows() == 0) {
290
                if($wb->default_block_content == 'none') { return; }
291
                if (is_numeric($wb->default_block_content)) {
292
                    $page_id = $wb->default_block_content;
293
                } else {
294
                    $page_id = $wb->default_page_id;
295
                }
296
                $sql  = 'SELECT `section_id`, `module`, `publ_start`, `publ_end` ';
297
                $sql .= 'FROM `'.TABLE_PREFIX.'sections` ';
298
                $sql .= 'WHERE `page_id`='.$page_id.' AND `block`='.$block.' ';
299
                $sql .= 'ORDER BY `position`';
300
                if( !($query_sections = $database->query($sql)) ) { return; }
301
                // Still no cotent found? Give it up, there's just nothing to show!
302
                if($query_sections->numRows() == 0) { return; }
303
            }
304
            // Loop through them and include their module file
305
            while($section = $query_sections->fetchRow(MYSQLI_ASSOC)) {
306
                // skip this section if it is out of publication-date
307
                $now = time();
308
                if( !(($now<=$section['publ_end'] || $section['publ_end']==0) && ($now>=$section['publ_start'] || $section['publ_start']==0)) ) {
309
                    continue;
310
                }
311
                $section_id = $section['section_id'] ;
312
                $module = $section['module'] ;
313
                // check if module exists - feature: write in errorlog
314
                if(is_readable(WB_PATH.'/modules/'.$module.'/view.php')) {
315
                 // fetch content -- this is where to place possible output-filters (before highlighting)
316
                 ob_start() ; // fetch original content<div id="Sec103" class="section  m_modulename user-defined-class" >
317
                 $sSectionIdPrefix = (defined('SEC_ANCHOR') && SEC_ANCHOR != '') ? SEC_ANCHOR : 'Sec' ;
318
                 require (WB_PATH.'/modules/'.$module.'/view.php') ;
319
                 $content = ob_get_clean() ;
320
                 if($content != '') {
321
                   $sBeforeContent = ($sSectionIdPrefix == 'none') ? '' : "\n".'<div id="'.$sSectionIdPrefix.$section_id.'" class="section m_'.$module.'" >'."\n" ;
322
                   $sAfterContent = ($sSectionIdPrefix == 'none') ? '' : "\n".'</div><!-- '.$module.$section_id.' -->'."\n" ;
323
                   $content = $sBeforeContent.$content.$sAfterContent ;
324
                 }
325
                } else {
326
                    continue;
327
                }
328
                // highlights searchresults
329
                if (isset($_GET['searchresult']) && is_numeric($_GET['searchresult'])
330
                          && !isset($_GET['nohighlight'])
331
                          && isset($_GET['sstring'])
332
                          && !empty($_GET['sstring'])
333
                          ) {
334
                    $arr_string = explode(" ", $_GET['sstring']);
335
                    if($_GET['searchresult']==2) { // exact match
336
                        $arr_string[0] = str_replace("_", " ", $arr_string[0]);
337
                    }
338
                    echo search_highlight($content, $arr_string);
339
                } else {
340
                    echo $content;
341
                }
342
            }
343
        } else {   // Searchresults! But also some special pages,
344
         // e.g. guestbook (add entry), news (add comment) uses this
345
            ob_start(); // fetch original content
346
            require(PAGE_CONTENT);
347
            $content = ob_get_clean();
348
            // Apply Filters
349
            if(function_exists('OutputFilterApi')) {
350
                $content = OutputFilterApi('OpF?arg=special', $content);
351
            }
352
            echo $content;
353
        }
354
    }
355
}
356

    
357
if (!function_exists('show_content')) {
358
    function show_content($block=1) {
359
        page_content($block);
360
    }
361
}
362

    
363
if (!function_exists('show_breadcrumbs'))
364
{
365
    function show_breadcrumbs($sep = ' &raquo; ',$level = 0, $links = true, $depth = -1, $title = '', $print=true)
366
    {
367
        global $wb,$database,$MENU;
368
        $retVal = '';
369
        $page_id = $wb->page_id;
370
        $title = (trim($title) == '') ? $MENU['BREADCRUMB'] : $title;
371
        if ($page_id != 0)
372
        {
373
            $counter = 0;
374
            // get links as array
375
            $bread_crumbs = $wb->page_trail;
376
            $count = sizeof($bread_crumbs);
377
            // level can't be greater than sum of links
378
            $level = ($count <= $level ) ? $count-1 : $level;
379
            // set level from which to show, delete indexes in array
380
            $crumbs = array_slice($bread_crumbs, $level );
381
            $depth = ($depth <= 0) ? sizeof($crumbs) : $depth;
382
            // if empty array, set orginal links
383
            $crumbs = (!empty($crumbs)) ?  $crumbs : $wb->page_trail;
384
            $total_crumbs = ( ($depth <= 0) || ($depth > sizeof($crumbs)) ) ? sizeof($crumbs) : $depth;
385
            $retVal .= '<div class="breadcrumb">'.PHP_EOL.'<span class="title">'.$title.'</span>'.PHP_EOL;
386
          //  print_r($crumbs);
387
            foreach ($crumbs as $temp)
388
            {
389
                if($counter == $depth) { break; }
390
                // set links and separator
391
                    $sql  = 'SELECT * FROM `'.TABLE_PREFIX.'pages` WHERE `page_id`='.(int)$temp;
392
                    $query_menu = $database->query($sql);
393
                    $page = $query_menu->fetchRow();
394
                    $show_crumb = (($links == true) && ($temp != $page_id))
395
                            ? '<a href="'.page_link($page['link']).'" class="link">'.$page['menu_title'].'</a>'.PHP_EOL
396
                            : '<span class="crumb">'.$page['menu_title'].'</span>'.PHP_EOL;
397
                    // Permission
398
                    switch ($page['visibility'])
399
                    {
400
                        case 'none' :
401
                        case 'hidden' :
402
                        // if show, you know there is an error in a hidden page
403
                            $retVal .= $show_crumb.'&nbsp;';
404
                            break;
405
                        default :
406
                            $retVal .= $show_crumb;
407
                            break;
408
                    }
409
                    if ( ( $counter <> $total_crumbs-1 ) )
410
                    {
411
                        $retVal .= '<span class="separator">'.$sep.'</span>'.PHP_EOL;
412
                    }
413
                $counter++;
414
            }
415
            $retVal .=  "</div>".PHP_EOL;
416
            if ($print) { print $retVal;} else {return $retVal;}
417
        }
418
    }
419
}
420

    
421
// Function for page title
422
if (!function_exists('page_title')) {
423
    function page_title($spacer = ' - ', $template = '[WEBSITE_TITLE][SPACER][PAGE_TITLE]') {
424
        $vars = array('[WEBSITE_TITLE]', '[PAGE_TITLE]', '[MENU_TITLE]', '[SPACER]');
425
        $values = array(WEBSITE_TITLE, PAGE_TITLE, MENU_TITLE, $spacer);
426
        echo str_replace($vars, $values, $template);
427
    }
428
}
429

    
430
// Function for page description
431
if (!function_exists('page_description')) {
432
    function page_description() {
433
        global $wb;
434
        if ($wb->page_description!='') {
435
            echo $wb->page_description;
436
        } else {
437
            echo WEBSITE_DESCRIPTION;
438
        }
439
    }
440
}
441

    
442
// Function for page keywords
443
if (!function_exists('page_keywords')) {
444
    function page_keywords() {
445
        global $wb;
446
        if ($wb->page_keywords!='') {
447
            echo $wb->page_keywords;
448
        } else {
449
            echo WEBSITE_KEYWORDS;
450
        }
451
    }
452
}
453

    
454
// Function for page header
455
if (!function_exists('page_header')) {
456
    function page_header($date_format = 'Y') {
457
        echo WEBSITE_HEADER;
458
    }
459
}
460

    
461
// Function for page footer
462
if (!function_exists('page_footer')) {
463
    function page_footer($date_format = 'Y') {
464
        global $starttime;
465
        $vars = array('[YEAR]', '[PROCESS_TIME]');
466
        $processtime=array_sum(explode(" ",microtime()))-$starttime;
467
        $values = array(gmdate($date_format),$processtime);
468
        echo str_replace($vars, $values, WEBSITE_FOOTER);
469
    }
470
}
471
/* ------------------------------------------------------------------------------------------------ */
472
//  begin register_frontend_files
473
/* ------------------------------------------------------------------------------------------------ */
474

    
475
    function register_frontend_LoadOnFly ($bInsert=true)
476
    {
477
        static $bSriptLoaded=false;
478
        $sLoadOnFly = '';
479
        if ($bInsert&&!$bSriptLoaded){
480
            $sLoadOnFly .= "\t".'<script src="'.WB_URL.'/include/jquery/domReady.js" type="text/javascript"></script>'."\n";
481
            $sLoadOnFly .= "\t".'<script src="'.WB_URL.'/include/jquery/LoadOnFly.js" type="text/javascript"></script>'."\n";
482
            $bSriptLoaded = true;
483
        }
484
        return $sLoadOnFly;
485
    }
486
    function register_frontend_ScriptVars ($bInsert=true)
487
    {
488
        static $bSriptLoaded=false;
489
        $sScriptVars = '';
490
        if ($bInsert&&!$bSriptLoaded){
491
            $sScriptVars .= "\t"."<script type=\"text/javascript\">\n"
492
                ."\t\t".'/* inserted by register_frontend_modfiles */'."\n"
493
                ."\t\t"."var URL = '".WB_URL."';\n"
494
                ."\t\t"."var WB_URL = '".WB_URL."';\n"
495
                ."\t\t"."var THEME_URL = '".THEME_URL."';\n"
496
                ."\t\t"."var TEMPLATE_DIR = '".TEMPLATE_DIR."';\n"
497
                ."\t\t"."var TEMPLATE = '".TEMPLATE."';\n"
498
                ."\t\t"."var EDITOR = '".WYSIWYG_EDITOR."';\n"
499
                ."\t"."</script>\n";
500
            $bSriptLoaded = true;
501
            }
502
        return $sScriptVars;
503
    }
504

    
505
function bind_jquery ($file_id='jquery')
506
{
507
    $jquery_links = '';
508
    /* include the Javascript jquery api  */
509
    if( $file_id == 'jquery' && file_exists(WB_PATH .'/include/jquery/jquery-min.js'))
510
    {
511
        $jquery_links .= "\t".'<script src="'.WB_URL.'/include/jquery/jquery-min.js" type="text/javascript"></script>'."\n";
512
        $jquery_links .= "\t".'<script src="'.WB_URL.'/include/jquery/jquery-insert.js" type="text/javascript"></script>'."\n";
513
        $jquery_links .= "\t".'<script src="'.WB_URL.'/include/jquery/jquery-include.js" type="text/javascript"></script>'."\n";
514
        /* workout to insert ui.css and theme */
515
        $jquery_theme =  WB_PATH.'/modules/jquery/jquery_theme.js';
516
        $jquery_links .=  (file_exists($jquery_theme)
517
            ? "\t".'<script src="'.WB_URL.'/modules/jquery/jquery_theme.js" type="text/javascript"></script>'."\n"
518
            : "\t".'<script src="'.WB_URL.'/include/jquery/jquery_theme.js" type="text/javascript"></script>'."\n");
519
        /* workout to insert plugins functions, set in templatedir */
520
        $jquery_frontend_file = TEMPLATE_DIR.'/jquery_frontend.js';
521
        $jquery_links .= (file_exists(str_replace( WB_URL, WB_PATH, $jquery_frontend_file))
522
            ? "\t".'<script src="'.$jquery_frontend_file.'" type="text/javascript"></script>'
523
            : '');
524
    }
525
    return $jquery_links;
526
}
527

    
528
// Function to add optional module Javascript or CSS stylesheets into the <head> section of the frontend
529
if(!function_exists('register_frontend_modfiles'))
530
{
531
    function register_frontend_modfiles($file_id="css", $bOutput=true)
532
    {
533
        global $wb, $database, $include_head_link_css, $include_head_links, $page_id;
534
        $page_id = (@$page_id?:$wb->page_id);
535
        $aFilterSettings = getOutputFilterSettings();
536
        // sanity check of parameter passed to the function
537
        $file_id = strtolower($file_id);
538
        $aAllowedAction = array( 'css', 'script', 'js', 'jquery', 'javascript' );
539
        if (!in_array($file_id, $aAllowedAction)) { return false; }
540
        // define default baselink and filename for optional module javascript and stylesheet files
541
        $head_links = "";
542
        $base_file  = '';
543
        $base_link  = '';
544
        switch ($file_id)
545
        {
546
            case 'css':
547
                $base_link = "\t".'<link rel="stylesheet" type="text/css" href="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend.css" media="screen" />'."\n";
548
                $base_file = "frontend.css";
549
                if(!empty($include_head_link_css))
550
                {
551
                  $head_links .=  !strpos($head_links, $include_head_link_css) ? $include_head_link_css : '';
552
                  $include_head_link_css = '';
553
                }
554
                break;
555
            case 'jquery':
556
/*----------------------------------------------------------------------------------------------*/
557
                $key = preg_replace('=^.*?filter([^\.\/\\\\]+)(\.[^\.]+)?$=is', '\1', 'filterScriptVars.php');
558
                $bLoadScriptVars = (isset($aFilterSettings[$key])&&$aFilterSettings[$key] ?false:true);
559
                $base_link .= register_frontend_ScriptVars($bLoadScriptVars);
560
/*----------------------------------------------------------------------------------------------*/
561
                $key = preg_replace('=^.*?filter([^\.\/\\\\]+)(\.[^\.]+)?$=is', '\1', 'filterLoadOnFly.php');
562
                $bLoadOnFly = (isset($aFilterSettings[$key])&&$aFilterSettings[$key] ?false:true);
563
                $base_link .= register_frontend_LoadOnFly($bLoadOnFly);
564
/*----------------------------------------------------------------------------------------------*/
565
                $key = preg_replace('=^.*?filter([^\.\/\\\\]+)(\.[^\.]+)?$=is', '\1', 'filterJquery.php');
566
                $bLoadJquery = (isset($aFilterSettings[$key])&&$aFilterSettings[$key] ?false:true);
567
                if ($bLoadJquery) {
568
                    $base_link .= bind_jquery($file_id);
569
                }
570
                break;
571
            case 'js':
572
                $base_file = "frontend.js";
573
                $key = preg_replace('=^.*?filter([^\.\/\\\\]+)(\.[^\.]+)?$=is', '\1', 'filterFrontendJs.php');
574
                $bLoadFrontendJs = (isset($aFilterSettings[$key])&&$aFilterSettings[$key] ?false:true);
575
                if ($bLoadFrontendJs) {
576
                    $base_link .= "\t".'<script src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend.js" type="text/javascript"></script>';
577
                    if (!empty($include_head_links))
578
                    {
579
                      $head_links .= !strpos($head_links, $include_head_links) ? $include_head_links."\n" : '';
580
                      $include_head_links = '';
581
                    }
582
                }
583
                break;
584
            case 'script_old':
585
                break;
586
            default:
587
                break;
588
        }
589
        if( $file_id != 'jquery_old')
590
        {
591
            // gather information for all models embedded on actual page
592
            $sql  = 'SELECT `module` FROM `'.TABLE_PREFIX.'sections` '
593
                  . 'WHERE `page_id` = '.(int)$page_id;
594
            if( ($oModules = $database->query($sql)) )
595
            {
596
                while($row = $oModules->fetchRow( MYSQLI_ASSOC ))
597
                {
598
                    // check if page module directory contains a frontend.js or frontend.css file
599
                    if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file"))
600
                    {
601
                    // create link with frontend.js or frontend.css source for the current module
602
                        $tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link);
603
                        // define constant indicating that the register_frontent_files was invoked
604
                        if($file_id == 'css')
605
                        {
606
                            if(!defined('MOD_FRONTEND_CSS_REGISTERED')) define('MOD_FRONTEND_CSS_REGISTERED', true);
607
                        } else {
608
                            if(!defined('MOD_FRONTEND_JAVASCRIPT_REGISTERED')) define('MOD_FRONTEND_JAVASCRIPT_REGISTERED', true);
609
                        }
610
                        // ensure that frontend.js or frontend.css is only added once per module type
611
                        if( $tmp_link && strpos($head_links, $tmp_link) === false)
612
                        {
613
                            $head_links .= $tmp_link;
614
                        }
615
                    };
616
                }
617
            }
618
        }
619
        if ($bOutput) { print $head_links."\n";} else {return $head_links."\n";}
620
    }
621
}
622

    
623
// Function to add optional module Javascript into the <body> section of the frontend
624
if(!function_exists('register_frontend_modfiles_body'))
625
{
626
    function register_frontend_modfiles_body($file_id="js", $print=true)
627
    {
628
        // sanity check of parameter passed to the function
629
        $file_id = strtolower($file_id);
630
        $aAllowedAction = array( 'css', 'js', 'jquery', 'javascript' );
631
        if(!in_array($file_id, $aAllowedAction)) { return false; }
632

    
633
       // define constant indicating that the register_frontent_files was invoked
634
       if(!defined('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED')) define('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED', true);
635
        global $wb, $database, $include_body_links;
636
        // define default baselink and filename for optional module javascript files
637
        $body_links = "";
638

    
639
        /* include the Javascript jquery api  */
640
        $body_links .= bind_jquery($file_id);
641

    
642
        if($file_id !== "css" && $file_id == "js" && $file_id !== "jquery")
643
        {
644
            $base_link = "\t".'<script src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend_body.js" type="text/javascript"></script>';
645
            $base_file = "frontend_body.js";
646
            // ensure that frontend_body.js is only added once per module type
647
            if(!empty($include_body_links))
648
            {
649
                if(strpos($body_links, $include_body_links) === false)
650
                {
651
                    $body_links .= $include_body_links;
652
                }
653
                $include_body_links = '';
654
            }
655
            // gather information for all models embedded on actual page
656
            $page_id = $wb->page_id;
657
            $sql = 'SELECT `module` FROM `'.TABLE_PREFIX.'sections` ';
658
            $sql .= 'WHERE `page_id` = '.(int)$page_id.' AND `module`<>\'wysiwyg\'';
659
            if( ($query_modules = $database->query($sql)) )
660
            {
661
                while($row = $query_modules->fetchRow(MYSQLI_ASSOC))
662
                {
663
                    // check if page module directory contains a frontend_body.js file
664
                    if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file"))
665
                    {
666
                    // create link with frontend_body.js source for the current module
667
                        $tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link);
668
                        // define constant indicating that the register_frontent_files_body was invoked
669
                            if(!defined('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED')) { define('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED', true);}
670
                        // ensure that frontend_body.js is only added once per module type
671
                        if(strpos($body_links, $tmp_link) === false)
672
                        {
673
                            $body_links .= $tmp_link;
674
                        }
675
                    }
676
                }
677
            }
678
        }
679
        if ($print) { print $body_links."\n";} else {return $body_links."\n";}
680
//        print $body_links."\n"; ;
681
    }
682
}
683

    
684
    function moveCssToHead($content) {
685
       return OutputFilterApi('CssToHead', $sContent);
686
    }