Project

General

Profile

« Previous | Next » 

Revision 2112

Added by darkviper almost 10 years ago

! module/show_menu2/ Changed global Constants into class constants

View differences:

branches/2.8.x/CHANGELOG
11 11
! = Update/Change
12 12
===============================================================================
13 13

  
14
25 Nov-2014 Build 2112 Manuela v.d.Decken(DarkViper)
15
! module/show_menu2/  Changed global Constants into class constants
16
25 Nov-2014 Build 2111 Manuela v.d.Decken(DarkViper)
17
# SqlImport fixed a Typo in Search-Replace of placeholders
14 18
25 Nov-2014 Build 2110 Manuela v.d.Decken(DarkViper)
15 19
# SqlImport fixed a Typo in Search-Replace of placeholders
16 20
25 Nov-2014 Build 2110 Manuela v.d.Decken(DarkViper)
branches/2.8.x/wb/admin/interface/version.php
51 51

  
52 52
// check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled)
53 53
if(!defined('VERSION')) define('VERSION', '2.8.4');
54
if(!defined('REVISION')) define('REVISION', '2111');
54
if(!defined('REVISION')) define('REVISION', '2112');
55 55
if(!defined('SP')) define('SP', '');
branches/2.8.x/wb/modules/show_menu2/include.php
19 19
// Must include code to stop this file being access directly
20 20
if(defined('WB_PATH') == false) { die("Cannot access this file directly"); }
21 21

  
22
define('SM2_ROOT',          -1000);
23
define('SM2_CURR',          -2000);
24
define('SM2_ALLMENU',          -1);
25
define('SM2_START',          1000);
26
define('SM2_MAX',            2000);
27
define('SM2_ALL',          0x0001); // bit 0 (group 1) (Note: also used for max level!)
28
define('SM2_TRIM',         0x0002); // bit 1 (group 1)
29
define('SM2_CRUMB',        0x0004); // bit 2 (group 1)
30
define('SM2_SIBLING',      0x0008); // bit 3 (group 1)
31
define('SM2_NUMCLASS',     0x0010); // bit 4
32
define('SM2_ALLINFO',      0x0020); // bit 5
33
define('SM2_NOCACHE',      0x0040); // bit 6
34
define('SM2_PRETTY',       0x0080); // bit 7
35
define('SM2_ESCAPE',       0x0100); // bit 8
36
define('SM2_NOESCAPE',          0); // NOOP, unnecessary with WB 2.6.7+
37
define('SM2_BUFFER',       0x0200); // bit 9
38
define('SM2_CURRTREE',     0x0400); // bit 10
39
define('SM2_SHOWHIDDEN',   0x0800); // bit 11
40
define('SM2_XHTML_STRICT', 0x1000); // bit 12
41
define('SM2_NO_TITLE',     0x1001); // bit 13
22
/**
23
 * future replacement for the function show_menu2()
24
 */
25
class SM2
26
{
27
    const ROOT =          -1000;
28
    const CURR =          -2000;
29
    const ALLMENU =          -1;
30
    const START =          1000;
31
    const MAX =            2000;
32
    const ALL =          0x0001; // bit 0 (group 1) (Note: also used for max level!)
33
    const TRIM =         0x0002; // bit 1 (group 1)
34
    const CRUMB =        0x0004; // bit 2 (group 1)
35
    const SIBLING =      0x0008; // bit 3 (group 1)
36
    const NUMCLASS =     0x0010; // bit 4
37
    const ALLINFO =      0x0020; // bit 5
38
    const NOCACHE =      0x0040; // bit 6
39
    const PRETTY =       0x0080; // bit 7
40
    const ESCAPE =       0x0100; // bit 8
41
    const NOESCAPE =          0; // NOOP, unnecessary with WB 2.6.7+
42
    const BUFFER =       0x0200; // bit 9
43
    const CURRTREE =     0x0400; // bit 10
44
    const SHOWHIDDEN =   0x0800; // bit 11
45
    const XHTML_STRICT = 0x1000; // bit 12
46
    const NO_TITLE =     0x2000; // bit 13
47
    const _GROUP_1 =     0x000F; // exactly one flag from group 1 is required
48
    const CONDITIONAL =  'if\s*\(([^\)]+)\)\s*{([^}]*)}\s*(?:else\s*{([^}]*)}\s*)?';
49
    const COND_TERM =    '\s*(\w+)\s*(<|<=|==|=|=>|>|!=)\s*([\w\-]+)\s*';
50
}
42 51

  
43
define('_SM2_GROUP_1',  0x000F); // exactly one flag from group 1 is required
44

  
45

  
46 52
// Implement support for page_menu and show_menu using show_menu2. If you remove
47 53
// the comments characters from the beginning of the following include, all menu
48 54
// functions in Website Baker will be implemented using show_menu2. While it is
49 55
// commented out, the original WB functions will be used.
50 56
//include('legacy.php');
51 57

  
52
// This class is the default menu formatter for sm2. If desired, you can 
53
// create your own formatter class and pass the object into show_menu2 
58
// This class is the default menu formatter for sm2. If desired, you can
59
// create your own formatter class and pass the object into show_menu2
54 60
// as $aItemFormat.
55
define('SM2_CONDITIONAL','if\s*\(([^\)]+)\)\s*{([^}]*)}\s*(?:else\s*{([^}]*)}\s*)?');
56
define('SM2_COND_TERM','\s*(\w+)\s*(<|<=|==|=|=>|>|!=)\s*([\w\-]+)\s*');
61

  
62

  
57 63
class SM2_Formatter
58 64
{
59 65
    var $output;
......
64 70
    var $menuClose;
65 71
    var $topItemOpen;
66 72
    var $topMenuOpen;
67
    
73

  
68 74
    var $isFirst;
69 75
    var $page;
70 76
    var $url;
......
75 81

  
76 82
    // output the data
77 83
    function output($aString) {
78
        if ($this->flags & SM2_BUFFER) {
84
        if ($this->flags & SM2::BUFFER) {
79 85
            $this->output .= $aString;
80 86
        }
81 87
        else {
82 88
            echo $aString;
83 89
        }
84 90
    }
85
    
91

  
86 92
    // set the default values for all of our formatting items
87 93
    function set($aFlags, $aItemOpen, $aItemClose, $aMenuOpen, $aMenuClose, $aTopItemOpen, $aTopMenuOpen) {
88 94
        $this->flags        = $aFlags;
......
98 104
    function initialize() {
99 105
        $this->output = '';
100 106
        $this->prettyLevel = 0;
101
        if ($this->flags & SM2_PRETTY) {
107
        if ($this->flags & SM2::PRETTY) {
102 108
            $this->output("\n<!-- show_menu2 -->");
103 109
        }
104 110
    }
105 111

  
106
    // start a menu     
112
    // start a menu
107 113
    function startList(&$aPage, &$aUrl) {
108 114
        $currClass = '';
109 115
        $currItem = $this->menuOpen;
110
        
116

  
111 117
        // use the top level menu open if this is the first menu
112 118
        if ($this->topMenuOpen) {
113 119
            $currItem = $this->topMenuOpen;
114 120
            $currClass .= ' menu-top';
115 121
            $this->topMenuOpen = false;
116 122
        }
117
        
123

  
118 124
        // add the numbered menu class only if requested
119
        if (($this->flags & SM2_NUMCLASS) == SM2_NUMCLASS) {
125
        if (($this->flags & SM2::NUMCLASS) == SM2::NUMCLASS) {
120 126
            $currClass .= ' menu-'.$aPage['level'];
121 127
        }
122
        
128

  
123 129
        $this->prettyLevel += 1;
124
        
130

  
125 131
        // replace all keywords in the output
126
        if ($this->flags & SM2_PRETTY) {
132
        if ($this->flags & SM2::PRETTY) {
127 133
            $this->output("\n".str_repeat(' ',$this->prettyLevel).
128 134
                $this->format($aPage, $aUrl, $currItem, $currClass));
129 135
        }
130 136
        else {
131 137
            $this->output($this->format($aPage, $aUrl, $currItem, $currClass));
132 138
        }
133
        
139

  
134 140
        $this->prettyLevel += 3;
135 141
    }
136
    
142

  
137 143
    // start an item within the menu
138 144
    function startItem(&$aPage, &$aUrl, $aCurrSib, $aSibCount) {
139 145
        // generate our class list
140 146
        $currClass = '';
141
        if (($this->flags & SM2_NUMCLASS) == SM2_NUMCLASS) {
147
        if (($this->flags & SM2::NUMCLASS) == SM2::NUMCLASS) {
142 148
            $currClass .= ' menu-'.$aPage['level'];
143 149
        }
144 150
        if (array_key_exists('sm2_has_child', $aPage)) {
145 151
            // not set if false, so existence = true
146 152
            $currClass .= ' menu-expand';
147 153
        }
148
        if (array_key_exists('sm2_is_curr', $aPage)) { 
154
        if (array_key_exists('sm2_is_curr', $aPage)) {
149 155
            $currClass .= ' menu-current';
150 156
        }
151
        elseif (array_key_exists('sm2_is_parent', $aPage)) { 
157
        elseif (array_key_exists('sm2_is_parent', $aPage)) {
152 158
            // not set if false, so existence = true
153 159
            $currClass .= ' menu-parent';
154 160
        }
......
159 165
        elseif (array_key_exists('sm2_child_level',$aPage)) {
160 166
            // not set if not a child
161 167
            $currClass .= ' menu-child';
162
            if (($this->flags & SM2_NUMCLASS) == SM2_NUMCLASS) {
168
            if (($this->flags & SM2::NUMCLASS) == SM2::NUMCLASS) {
163 169
                $currClass .= ' menu-child-'.($aPage['sm2_child_level']-1);
164 170
            }
165 171
        }
......
178 184
        }
179 185

  
180 186
        // replace all keywords in the output
181
        if ($this->flags & SM2_PRETTY) {
187
        if ($this->flags & SM2::PRETTY) {
182 188
            $this->output("\n".str_repeat(' ',$this->prettyLevel));
183 189
        }
184 190
        $this->output($this->format($aPage, $aUrl, $currItem, $currClass, $aCurrSib, $aSibCount));
185 191
    }
186
    
192

  
187 193
    // find and replace all keywords, setting the state variables first
188
    function format(&$aPage, &$aUrl, &$aCurrItem, &$aCurrClass, 
189
        $aCurrSib = 0, $aSibCount = 0) 
194
    function format(&$aPage, &$aUrl, &$aCurrItem, &$aCurrClass,
195
        $aCurrSib = 0, $aSibCount = 0)
190 196
    {
191 197
        $this->page      = &$aPage;
192 198
        $this->url       = &$aUrl;
193 199
        $this->currClass = trim($aCurrClass);
194 200
        $this->currSib   = $aCurrSib;
195 201
        $this->sibCount  = $aSibCount;
196
        
202

  
197 203
        $item = $this->format2($aCurrItem);
198
        
204

  
199 205
        unset($this->page);
200 206
        unset($this->url);
201 207
        unset($this->currClass);
202
        
208

  
203 209
        return $item;
204 210
    }
205
    
211

  
206 212
    // find and replace all keywords
207 213
    function format2(&$aCurrItem) {
208 214
        if (!is_string($aCurrItem)) return '';
209 215
        return preg_replace_callback(
210 216
            '@\[('.
211 217
                'a|ac|/a|li|/li|ul|/ul|menu_title|menu_icon_0|menu_icon_1|'.
212
		        'page_title|page_icon|url|target|page_id|tooltip|'.
218
                'page_title|page_icon|url|target|page_id|tooltip|'.
213 219
                'parent|level|sib|sibCount|class|description|keywords|'.
214
                SM2_CONDITIONAL.
220
                SM2::CONDITIONAL.
215 221
            ')\]@',
216 222
            array($this, 'replace'),
217 223
            $aCurrItem);
218 224
    }
219
    
225

  
220 226
    // replace the keywords
221 227
    function replace($aMatches) {
222 228
        $aMatch = $aMatches[1];
......
224 230
        switch ($aMatch) {
225 231
        case 'a':
226 232
            $retval = '<a href="'.$this->url.'"';
227
			// break; // ignore 'break' to add the rest of <a>-tag
228
		case 'ac':
229
			if( substr($retval, 0, 2) != '<a'){
230
				$retval = '<a href="'.$this->url.'" class="'.$this->currClass.'"';
231
			}
232
			if(($this->flags & SM2_NO_TITLE)) {
233
				$retval .= ' title="'.$this->page['tooltip'].'"';
234
			}
235
			if(!($this->flags & SM2_XHTML_STRICT)) {
236
				$retval .= ' target="'.$this->page['target'].'"';
237
			}
238
			$retval .= '>';
239
			break;
233
            // break; // ignore 'break' to add the rest of <a>-tag
234
        case 'ac':
235
            if( substr($retval, 0, 2) != '<a'){
236
                $retval = '<a href="'.$this->url.'" class="'.$this->currClass.'"';
237
            }
238
            if(($this->flags & SM2::NO_TITLE)) {
239
                $retval .= ' title="'.$this->page['tooltip'].'"';
240
            }
241
            if(!($this->flags & SM2::XHTML_STRICT)) {
242
                $retval .= ' target="'.$this->page['target'].'"';
243
            }
244
            $retval .= '>';
245
            break;
240 246
        case '/a':
241 247
            $retval = '</a>'; break;
242 248
        case 'li':
......
257 263
            $retval = $this->currClass; break;
258 264
        default:
259 265
            if (array_key_exists($aMatch, $this->page)) {
260
                if ($this->flags & SM2_ESCAPE) {
266
                if ($this->flags & SM2::ESCAPE) {
261 267
                    $retval = htmlspecialchars($this->page[$aMatch], ENT_QUOTES);
262 268
                }
263 269
                else {
264 270
                    $retval = $this->page[$aMatch];
265 271
                }
266 272
            }
267
            if (preg_match('/'.SM2_CONDITIONAL.'/', $aMatch, $rgMatches)) {
273
            if (preg_match('/'.SM2::CONDITIONAL.'/', $aMatch, $rgMatches)) {
268 274
                $retval = $this->replaceIf($rgMatches[1], $rgMatches[2], $rgMatches[3]);
269 275
            }
270 276
        }
271 277
        return $retval;
272 278
    }
273
    
279

  
274 280
    // conditional replacement
275 281
    function replaceIf(&$aExpression, &$aIfValue, &$aElseValue) {
276 282
        // evaluate all of the tests in the conditional (we don't do short-circuit
277 283
        // evaluation) and replace the string test with the boolean result
278 284
        $rgTests = preg_split('/(\|\||\&\&)/', $aExpression, -1, PREG_SPLIT_DELIM_CAPTURE);
279 285
        for ($n = 0; $n < count($rgTests); $n += 2) {
280
            if (preg_match('/'.SM2_COND_TERM.'/', $rgTests[$n], $rgMatches)) {
286
            if (preg_match('/'.SM2::COND_TERM.'/', $rgTests[$n], $rgMatches)) {
281 287
                $rgTests[$n] = $this->ifTest($rgMatches[1], $rgMatches[2], $rgMatches[3]);
282 288
            }
283 289
            else {
......
296 302
                $ok = $ok && $rgTests[$n+1];
297 303
            }
298 304
        }
299
        
305

  
300 306
        // return the formatted expression if the test succeeded
301 307
        return $ok ? $this->format2($aIfValue) : $this->format2($aElseValue);
302 308
    }
......
304 310
    // conditional test
305 311
    function ifTest(&$aKey, &$aOperator, &$aValue) {
306 312
        global $wb;
307
        
313

  
308 314
        // find the correct operand
309 315
        $operand = false;
310 316
        switch($aKey) {
......
312 318
            // we need to wrap the class names in spaces so we can test for a unique
313 319
            // class name that will not match prefixes or suffixes. Same must be done
314 320
            // for the value we are testing.
315
            $operand = " $this->currClass "; 
321
            $operand = " $this->currClass ";
316 322
            break;
317
		case 'target':
318
			$operand = $this->page['target'];
319
			break;
323
        case 'target':
324
            $operand = $this->page['target'];
325
            break;
320 326
        case 'sib':
321 327
            $operand = $this->currSib;
322 328
            if ($aValue == 'sibCount') {
......
348 354
            return '';
349 355
        }
350 356

  
351
        // do the test        
357
        // do the test
352 358
        $ok = false;
353
        switch ($aOperator) { 
359
        switch ($aOperator) {
354 360
        case '<':
355
            $ok = ($operand < $aValue); 
361
            $ok = ($operand < $aValue);
356 362
            break;
357 363
        case '<=':
358
            $ok = ($operand <= $aValue); 
364
            $ok = ($operand <= $aValue);
359 365
            break;
360 366
        case '=':
361 367
        case '==':
......
364 370
                $ok = strstr($operand, " $aValue ") !== FALSE;
365 371
            }
366 372
            else {
367
                $ok = ($operand == $aValue); 
373
                $ok = ($operand == $aValue);
368 374
            }
369 375
            if ($aOperator == '!=') {
370 376
                $ok = !$ok;
371 377
            }
372 378
            break;
373 379
        case '>=':
374
            $ok = ($operand >= $aValue); 
380
            $ok = ($operand >= $aValue);
375 381
        case '>':
376
            $ok = ($operand > $aValue); 
382
            $ok = ($operand > $aValue);
377 383
        }
378
        
384

  
379 385
        return $ok;
380 386
    }
381
    
387

  
382 388
    // finish the current menu item
383 389
    function finishItem() {
384
        if ($this->flags & SM2_PRETTY) {
390
        if ($this->flags & SM2::PRETTY) {
385 391
            $this->output(str_repeat(' ',$this->prettyLevel).$this->itemClose);
386 392
        }
387 393
        else {
......
392 398
    // finish the current menu
393 399
    function finishList() {
394 400
        $this->prettyLevel -= 3;
395
        
396
        if ($this->flags & SM2_PRETTY) {
401

  
402
        if ($this->flags & SM2::PRETTY) {
397 403
            $this->output("\n".str_repeat(' ',$this->prettyLevel).$this->menuClose."\n");
398 404
        }
399 405
        else {
400 406
            $this->output($this->menuClose);
401 407
        }
402
        
408

  
403 409
        $this->prettyLevel -= 1;
404 410
    }
405
    
411

  
406 412
    // cleanup the state of the formatter after everything has been output
407 413
    function finalize() {
408
        if ($this->flags & SM2_PRETTY) {
414
        if ($this->flags & SM2::PRETTY) {
409 415
            $this->output("\n");
410 416
        }
411 417
    }
......
432 438

  
433 439
function show_menu2(
434 440
    $aMenu          = 0,
435
    $aStart         = SM2_ROOT,
436
    $aMaxLevel      = -1999, // SM2_CURR+1
437
    $aOptions       = SM2_TRIM,
441
    $aStart         = SM2::ROOT,
442
    $aMaxLevel      = -1999, // SM2::CURR+1
443
    $aOptions       = SM2::TRIM,
438 444
    $aItemOpen      = false,
439 445
    $aItemClose     = false,
440 446
    $aMenuOpen      = false,
......
445 451
{
446 452
    global $wb;
447 453
    $database = WbDatabase::getInstance();
448
	$iQueryStart = $database->getQueryCount;
454
    $iQueryStart = $database->getQueryCount;
449 455
    // extract the flags and set $aOptions to an array
450 456
    $flags = 0;
451 457
    if (is_int($aOptions)) {
......
456 462
        $flags = $aOptions['flags'];
457 463
    }
458 464
    else {
459
        $flags = SM2_TRIM;
465
        $flags = SM2::TRIM;
460 466
        $aOptions = array();
461 467
        @error_logs('show_menu2 error: $aOptions is invalid. No flags supplied!');
462 468
    }
463
    
469

  
464 470
    // ensure we have our group 1 flag, we don't check for the "exactly 1" part, but
465 471
    // we do ensure that they provide at least one.
466
    if (0 == ($flags & _SM2_GROUP_1)) {
472
    if (0 == ($flags & SM2::_GROUP_1)) {
467 473
        @error_logs('show_menu2 error: $aOptions is invalid. No flags from group 1 supplied!');
468
        $flags |= SM2_TRIM; // default to TRIM
474
        $flags |= SM2::TRIM; // default to TRIM
469 475
    }
470
    
471
    // search page results don't have any of the page data loaded by WB, so we load it 
476

  
477
    // search page results don't have any of the page data loaded by WB, so we load it
472 478
    // ourselves using the referrer ID as the current page
473 479
    $CURR_PAGE_ID = defined('REFERRER_ID') ? REFERRER_ID : PAGE_ID;
474 480
    if (count($wb->page) == 0 && defined('REFERRER_ID') && REFERRER_ID > 0) {
......
480 486
        }
481 487
        unset($result);
482 488
    }
483
    
489

  
484 490
    // fix up the menu number to default to the menu number
485 491
    // of the current page if no menu has been supplied
486 492
    if ($aMenu == 0) {
487 493
        $aMenu = $wb->page['menu'] == '' ? 1 : $wb->page['menu'];
488
    } 
494
    }
489 495

  
490 496
    // Set some of the $wb->page[] settings to defaults if not set
491 497
    $pageLevel  = $wb->page['level']  == '' ? 0 : $wb->page['level'];
492 498
    $pageParent = $wb->page['parent'] == '' ? 0 : $wb->page['parent'];
493
    
499

  
494 500
    // adjust the start level and start page ID as necessary to
495 501
    // handle the special values that can be passed in as $aStart
496 502
    $aStartLevel = 0;
497
    if ($aStart < SM2_ROOT) {   // SM2_CURR+N
498
        if ($aStart == SM2_CURR) {
503
    if ($aStart < SM2::ROOT) {   // SM2::CURR+N
504
        if ($aStart == SM2::CURR) {
499 505
            $aStartLevel = $pageLevel;
500 506
            $aStart = $pageParent;
501 507
        }
502 508
        else {
503
            $aStartLevel = $pageLevel + $aStart - SM2_CURR;
504
            $aStart = $CURR_PAGE_ID; 
509
            $aStartLevel = $pageLevel + $aStart - SM2::CURR;
510
            $aStart = $CURR_PAGE_ID;
505 511
        }
506 512
    }
507
    elseif ($aStart < 0) {   // SM2_ROOT+N
508
        $aStartLevel = $aStart - SM2_ROOT;
513
    elseif ($aStart < 0) {   // SM2::ROOT+N
514
        $aStartLevel = $aStart - SM2::ROOT;
509 515
        $aStart = 0;
510 516
    }
511 517

  
512
    // we get the menu data once and store it in a global variable. This allows 
513
    // multiple calls to show_menu2 in a single page with only a single call to 
518
    // we get the menu data once and store it in a global variable. This allows
519
    // multiple calls to show_menu2 in a single page with only a single call to
514 520
    // the database. If this variable exists, then we have already retrieved all
515 521
    // of the information and processed it, so we don't need to do it again.
516
    if (($flags & SM2_NOCACHE) != 0
522
    if (($flags & SM2::NOCACHE) != 0
517 523
        || !array_key_exists('show_menu2_data', $GLOBALS)
518
        || !array_key_exists($aMenu, $GLOBALS['show_menu2_data'])) 
524
        || !array_key_exists($aMenu, $GLOBALS['show_menu2_data']))
519 525
    {
520 526
        global $database;
521 527

  
......
528 534
        // if the caller wants all menus gathered together (e.g. for a sitemap)
529 535
        // then we don't limit our SQL query
530 536
        $menuLimitSql = ' AND `menu`='.$aMenu;
531
        if ($aMenu == SM2_ALLMENU) {
537
        if ($aMenu == SM2::ALLMENU) {
532 538
            $menuLimitSql = '';
533 539
        }
534 540

  
......
538 544
        // is called (i.e. where the database is loaded) then the info won't
539 545
        // exist anyhow.
540 546
        $fields  = '`parent`,`page_id`,`menu_title`,`page_title`,`link`,`target`,';
541
		$fields .= '`level`,`visibility`,`viewing_groups`,`viewing_users`,';
542
		$fields .= '`menu_icon_0`,`menu_icon_1`,`page_icon`,`tooltip`';
543
        if ($flags & SM2_ALLINFO) {
547
        $fields .= '`level`,`visibility`,`viewing_groups`,`viewing_users`,';
548
        $fields .= '`menu_icon_0`,`menu_icon_1`,`page_icon`,`tooltip`';
549
        if ($flags & SM2::ALLINFO) {
544 550
            $fields = '*';
545 551
        }
546 552

  
547 553
        // we request all matching rows from the database for the menu that we
548 554
        // are about to create it is cheaper for us to get everything we need
549
        // from the database once and create the menu from memory then make 
550
        // multiple calls to the database. 
555
        // from the database once and create the menu from memory then make
556
        // multiple calls to the database.
551 557
        $sql  = 'SELECT '.$fields.' FROM `'.TABLE_PREFIX.'pages` ';
552
		$sql .= 'WHERE '.$wb->extra_where_sql.' '.$menuLimitSql.' ';
553
		$sql .= 'ORDER BY `level` ASC, `position` ASC';
558
        $sql .= 'WHERE '.$wb->extra_where_sql.' '.$menuLimitSql.' ';
559
        $sql .= 'ORDER BY `level` ASC, `position` ASC';
554 560
        $sql = str_replace('hidden', 'IGNOREME', $sql); // we want the hidden pages
555 561
        $oRowset = $database->query($sql);
556 562
        if (is_object($oRowset) && $oRowset->numRows() > 0) {
557
            // create an in memory array of the database data based on the item's parent. 
563
            // create an in memory array of the database data based on the item's parent.
558 564
            // The array stores all elements in the correct display order.
559 565
            while ($page = $oRowset->fetchRow()) {
560 566
                // ignore all pages that the current user is not permitted to view
......
563 569
                    if ($page['visibility'] == 'hidden') {
564 570
                        $page['sm2_hide'] = true;
565 571
                    }
566
                    
572

  
567 573
                    // 2. all pages with no active sections (unless it is the top page) are ignored
568 574
                    else if (!$wb->page_is_active($page) && $page['link'] != $wb->default_link && !INTRO_PAGE) {
569 575
                        continue;
......
574 580
                        continue;
575 581
                    }
576 582
                }
577
				if(isset($page['page_icon']) && $page['page_icon'] != '') {
578
					$page['page_icon'] = WB_URL.$page['page_icon'];
579
				}
580
				if(isset($page['menu_icon_0']) && $page['menu_icon_0'] != '') {
581
					$page['menu_icon_0'] = WB_URL.$page['menu_icon_0'];
582
				}
583
				if(isset($page['menu_icon_1']) && $page['menu_icon_1'] != '') {
584
					$page['menu_icon_1'] = WB_URL.$page['menu_icon_1'];
585
				}
583
                if(isset($page['page_icon']) && $page['page_icon'] != '') {
584
                    $page['page_icon'] = WB_URL.$page['page_icon'];
585
                }
586
                if(isset($page['menu_icon_0']) && $page['menu_icon_0'] != '') {
587
                    $page['menu_icon_0'] = WB_URL.$page['menu_icon_0'];
588
                }
589
                if(isset($page['menu_icon_1']) && $page['menu_icon_1'] != '') {
590
                    $page['menu_icon_1'] = WB_URL.$page['menu_icon_1'];
591
                }
586 592

  
587
				if(!isset($page['tooltip'])) { $page['tooltip'] = $page['page_title']; }
593
                if(!isset($page['tooltip'])) { $page['tooltip'] = $page['page_title']; }
588 594
                // ensure that we have an array entry in the table to add this to
589 595
                $idx = $page['parent'];
590 596
                if (!array_key_exists($idx, $rgParent)) {
......
595 601
                if ($page['page_id'] == $CURR_PAGE_ID) {
596 602
                    $page['sm2_is_curr'] = true;
597 603
                    $page['sm2_on_curr_path'] = true;
598
                    if ($flags & SM2_SHOWHIDDEN) 
599
					{ 
604
                    if ($flags & SM2::SHOWHIDDEN)
605
                    {
600 606
                        // show hidden pages if active and SHOWHIDDEN flag supplied
601
                        unset($page['sm2_hide']); 
607
                        unset($page['sm2_hide']);
602 608
                    }
603 609
                }
604 610

  
......
606 612
                if (in_array($page['page_id'], $rgCurrParents)) {
607 613
                    $page['sm2_is_parent'] = true;
608 614
                    $page['sm2_on_curr_path'] = true;
609
                    if ($flags & SM2_SHOWHIDDEN) 
610
					{
615
                    if ($flags & SM2::SHOWHIDDEN)
616
                    {
611 617
                        // show hidden pages if active and SHOWHIDDEN flag supplied
612
						unset($page['sm2_hide']); // don't hide a parent page                
618
                        unset($page['sm2_hide']); // don't hide a parent page
613 619
                    }
614 620
                }
615
                
616
                // add the entry to the array                
621

  
622
                // add the entry to the array
617 623
                $rgParent[$idx][] = $page;
618 624
            }
619
        }    
625
        }
620 626
        unset($oRowset);
621 627

  
622 628
        // mark all elements that are siblings of any element on the current path
......
646 652
            }
647 653
            unset($childSet);
648 654
        }
649
        
650
        // mark all children of the current page. We don't do this when 
651
        // $CURR_PAGE_ID is 0, as 0 is the parent of everything. 
655

  
656
        // mark all children of the current page. We don't do this when
657
        // $CURR_PAGE_ID is 0, as 0 is the parent of everything.
652 658
        // $CURR_PAGE_ID == 0 occurs on special pages like search results
653 659
        // when no referrer is available.s
654 660
        if ($CURR_PAGE_ID != 0) {
655 661
            sm2_mark_children($rgParent, $CURR_PAGE_ID, 1);
656 662
        }
657
        
658
        // store the complete processed menu data as a global. We don't 
659
        // need to read this from the database anymore regardless of how 
663

  
664
        // store the complete processed menu data as a global. We don't
665
        // need to read this from the database anymore regardless of how
660 666
        // many menus are displayed on the same page.
661 667
        if (!array_key_exists('show_menu2_data', $GLOBALS)) {
662 668
            $GLOBALS['show_menu2_data'] = array();
......
665 671
        unset($rgParent);
666 672
    }
667 673

  
668
    // adjust $aMaxLevel to the level number of the final level that 
674
    // adjust $aMaxLevel to the level number of the final level that
669 675
    // will be displayed. That is, we display all levels <= aMaxLevel.
670
    if ($aMaxLevel == SM2_ALL) {
676
    if ($aMaxLevel == SM2::ALL) {
671 677
        $aMaxLevel = 1000;
672 678
    }
673
    elseif ($aMaxLevel < 0) {   // SM2_CURR+N
674
        $aMaxLevel += $pageLevel - SM2_CURR;
679
    elseif ($aMaxLevel < 0) {   // SM2::CURR+N
680
        $aMaxLevel += $pageLevel - SM2::CURR;
675 681
    }
676
    elseif ($aMaxLevel >= SM2_MAX) { // SM2_MAX+N
677
        $aMaxLevel += $aStartLevel - SM2_MAX;
682
    elseif ($aMaxLevel >= SM2::MAX) { // SM2::MAX+N
683
        $aMaxLevel += $aStartLevel - SM2::MAX;
678 684
        if ($aMaxLevel > $pageLevel) {
679 685
            $aMaxLevel = $pageLevel;
680 686
        }
681 687
    }
682
    else {  // SM2_START+N
683
        $aMaxLevel += $aStartLevel - SM2_START;
688
    else {  // SM2::START+N
689
        $aMaxLevel += $aStartLevel - SM2::START;
684 690
    }
685 691

  
686 692
    // generate the menu
......
693 699
                $sm2formatter = new SM2_Formatter;
694 700
            }
695 701
            $formatter = $sm2formatter;
696
            $formatter->set($flags, $aItemOpen, $aItemClose, 
702
            $formatter->set($flags, $aItemOpen, $aItemClose,
697 703
                $aMenuOpen, $aMenuClose, $aTopItemOpen, $aTopMenuOpen);
698 704
        }
699
        
705

  
700 706
        // adjust the level until we show everything and ignore the SM2_TRIM flag.
701 707
        // Usually this will be less than the start level to disable it.
702 708
        $showAllLevel = $aStartLevel - 1;
703 709
        if (isset($aOptions['notrim'])) {
704 710
            $showAllLevel = $aStartLevel + $aOptions['notrim'];
705 711
        }
706
        
712

  
707 713
        // display the menu
708 714
        $formatter->initialize();
709 715
        sm2_recurse(
710 716
            $GLOBALS['show_menu2_data'][$aMenu],
711 717
            $aStart,    // parent id to start displaying sub-menus
712
            $aStartLevel, $showAllLevel, $aMaxLevel, $flags, 
718
            $aStartLevel, $showAllLevel, $aMaxLevel, $flags,
713 719
            $formatter);
714 720
        $formatter->finalize();
715
        
721

  
716 722
        // if we are returning something, get the data
717
        if (($flags & SM2_BUFFER) != 0) {
723
        if (($flags & SM2::BUFFER) != 0) {
718 724
            $retval = $formatter->getOutput();
719 725
        }
720 726
    }
721 727

  
722 728
    // clear the data if we aren't caching it
723
    if (($flags & SM2_NOCACHE) != 0) {
729
    if (($flags & SM2::NOCACHE) != 0) {
724 730
        unset($GLOBALS['show_menu2_data'][$aMenu]);
725 731
    }
726
	if(defined('DEBUG') && (DEBUG)) {
727
	    $iQueriesDone = $database->getQueryCount - $iQueryStart;
728
	    return $retval."\n".'<!-- Queries: '.$iQueriesDone.' -->'."\n";
729
	}
732
    if(defined('DEBUG') && (DEBUG)) {
733
        $iQueriesDone = $database->getQueryCount - $iQueryStart;
734
        return $retval."\n".'<!-- Queries: '.$iQueriesDone.' -->'."\n";
735
    }
730 736
    return $retval;
731 737
}
732 738

  
......
743 749
}
744 750

  
745 751
function sm2_recurse(
746
    &$rgParent, $aStart, 
747
    $aStartLevel, $aShowAllLevel, $aMaxLevel, $aFlags, 
752
    &$rgParent, $aStart,
753
    $aStartLevel, $aShowAllLevel, $aMaxLevel, $aFlags,
748 754
    &$aFormatter
749 755
    )
750 756
{
751 757
    global $wb;
752 758

  
753
    // on entry to this function we know that there are entries for this 
754
    // parent and all entries for that parent are being displayed. We also 
759
    // on entry to this function we know that there are entries for this
760
    // parent and all entries for that parent are being displayed. We also
755 761
    // need to check if any of the children need to be displayed too.
756 762
    $isListOpen = false;
757 763
    $currentLevel = $wb->page['level'] == '' ? 0 : $wb->page['level'];
758 764

  
759
    // get the number of siblings skipping the hidden pages so we can pass 
765
    // get the number of siblings skipping the hidden pages so we can pass
760 766
    // this in and check if the item is first or last
761 767
    $sibCount = 0;
762 768
    foreach ($rgParent[$aStart] as $page) {
763 769
        if (!array_key_exists('sm2_hide', $page)) $sibCount++;
764 770
    }
765
    
771

  
766 772
    $currSib = 0;
767 773
    foreach ($rgParent[$aStart] as $page) {
768
        // skip all hidden pages 
774
        // skip all hidden pages
769 775
        if (array_key_exists('sm2_hide', $page)) { // not set if false, so existence = true
770 776
            continue;
771 777
        }
772
        
778

  
773 779
        $currSib++;
774 780

  
775 781
        // skip any elements that are lower than the maximum level
......
777 783
        if ($pageLevel > $aMaxLevel) {
778 784
            continue;
779 785
        }
780
        
786

  
781 787
        // this affects ONLY the top level
782
        if ($aStart == 0 && ($aFlags & SM2_CURRTREE)) {
788
        if ($aStart == 0 && ($aFlags & SM2::CURRTREE)) {
783 789
            if (!array_key_exists('sm2_on_curr_path', $page)) { // not set if false, so existence = true
784 790
                continue;
785 791
            }
786 792
            $sibCount = 1;
787 793
        }
788
        
794

  
789 795
        // trim the tree as appropriate
790
        if ($aFlags & SM2_SIBLING) {
796
        if ($aFlags & SM2::SIBLING) {
791 797
            // parents, and siblings and children of current only
792 798
            if (!array_key_exists('sm2_on_curr_path', $page)      // not set if false, so existence = true
793 799
                && !array_key_exists('sm2_is_sibling', $page)     // not set if false, so existence = true
......
795 801
                continue;
796 802
            }
797 803
        }
798
        else if ($aFlags & SM2_TRIM) {
804
        else if ($aFlags & SM2::TRIM) {
799 805
            // parents and siblings of parents
800 806
            if ($pageLevel > $aShowAllLevel  // permit all levels to be shown
801 807
                && !array_key_exists('sm2_on_curr_path', $page)    // not set if false, so existence = true
......
803 809
                continue;
804 810
            }
805 811
        }
806
        elseif ($aFlags & SM2_CRUMB) {
812
        elseif ($aFlags & SM2::CRUMB) {
807 813
            // parents only
808 814
            if (!array_key_exists('sm2_on_curr_path', $page)    // not set if false, so existence = true
809 815
                || array_key_exists('sm2_child_level', $page)) {  // not set if false, so existence = true
......
823 829
            else {
824 830
                $url = $wb->page_link($page['link']);
825 831
            }
826
                    
832

  
827 833
            // we open the list only when we absolutely need to
828 834
            if (!$isListOpen) {
829 835
                $aFormatter->startList($page, $url);
......
832 838

  
833 839
            $aFormatter->startItem($page, $url, $currSib, $sibCount);
834 840
        }
835
        
841

  
836 842
        // display children as appropriate
837
        if ($pageLevel + 1 <= $aMaxLevel 
843
        if ($pageLevel + 1 <= $aMaxLevel
838 844
            && array_key_exists('sm2_has_child', $page)) {  // not set if false, so existence = true
839 845
            sm2_recurse(
840 846
                $rgParent, $nextParent, // parent id to start displaying sub-menus
841
                $aStartLevel, $aShowAllLevel, $aMaxLevel, $aFlags, 
847
                $aStartLevel, $aShowAllLevel, $aMaxLevel, $aFlags,
842 848
                $aFormatter);
843 849
        }
844
        
850

  
845 851
        // close the current element if appropriate
846 852
        if ($pageLevel >= $aStartLevel) {
847 853
            $aFormatter->finishItem($pageLevel, $page);
......
852 858
    if ($isListOpen) {
853 859
        $aFormatter->finishList();
854 860
    }
855
}
861
}
branches/2.8.x/wb/modules/show_menu2/legacy.php
79 79
    var $currentClass;
80 80
    
81 81
    function output($aString) {
82
        if ($this->flags & SM2_BUFFER) {
82
        if ($this->flags & SM2::BUFFER) {
83 83
            $this->output .= $aString;
84 84
        }
85 85
        else {
......
149 149
    $formatter->defaultClass  = $aDefaultClass;
150 150
    $formatter->currentClass  = $aCurrentClass;
151 151
    
152
    $start = SM2_ROOT + $aStartLevel;
152
    $start = SM2::ROOT + $aStartLevel;
153 153
    if ($aParent != 0) {
154 154
        $start = $aParent;
155 155
    }
......
159 159
        return;
160 160
    }
161 161
    if ($aRecurse < 0) {
162
        $maxLevel = SM2_ALL;
162
        $maxLevel = SM2::ALL;
163 163
    }
164 164
    else {
165
        $maxLevel = SM2_START + $aRecurse - 1;
165
        $maxLevel = SM2::START + $aRecurse - 1;
166 166
    }
167 167
    
168
    $flags = $aCollapse ? SM2_TRIM : SM2_ALL;
168
    $flags = $aCollapse ? SM2::TRIM : SM2::ALL;
169 169
    
170 170
    // special case for default case
171 171
    if ($aStartLevel == 0 && $aRecurse == -1 && $aCollapse) {
172
        $maxLevel = SM2_CURR + 1;
172
        $maxLevel = SM2::CURR + 1;
173 173
    }
174 174

  
175 175
    show_menu2($aMenu, $start, $maxLevel, $flags, $formatter);

Also available in: Unified diff