C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\netspot\includes\mamboxml.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
<?php
/**
* @version $Id: mamboxml.php,v 1.8 2005/01/06 01:13:29 eddieajau Exp $
* @package Mambo
* @copyright (C) 2000 - 2005 Miro International Pty Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* Mambo is Free Software
*/

// ensure this file is being included by a parent file
defined'_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

/**
* Parameters handler
* @package Mambo
*/
class mosParameters {
    
/** @var object */
    
var $_params null;
    
/** @var string The raw params string */
    
var $_raw null;
    
/** @var string Path to the xml setup file */
    
var $_path null;
    
/** @var string The type of setup file */
    
var $_type null;
    
/** @var object The xml params element */
    
var $_xmlElem null;
/**
* Constructor
* @param string The raw parms text
* @param string Path to the xml setup file
* @var string The type of setup file
*/
    
function mosParameters$text$path=''$type='component' ) {
        
$this->_params $this->parse$text );
        
$this->_raw $text;
        
$this->_path $path;
        
$this->_type $type;
    }
/**
* @param string The name of the param
* @param string The value of the parameter
* @return string The set value
*/
    
function set$key$value='' ) {
        
$this->_params->$key $value;
        return 
$value;
    }
/**
* Sets a default value if not alreay assigned
* @param string The name of the param
* @param string The value of the parameter
* @return string The set value
*/
    
function def$key$value='' ) {
        return 
$this->set$key$this->get$key$value ) );
    }
/**
* @param string The name of the param
* @param mixed The default value if not found
* @return string
*/
    
function get$key$default='' ) {
        if (isset( 
$this->_params->$key )) {
            return 
$this->_params->$key === '' $default $this->_params->$key;
        } else {
            return 
$default;
        }
    }
/**
* Parse an .ini string, based on phpDocumentor phpDocumentor_parse_ini_file function
* @param mixed The ini string or array of lines
* @param boolean add an associative index for each section [in brackets]
* @return object
*/
    
function parse$txt$process_sections false ) {
        if (
is_string$txt )) {
            
$lines explode"\n"$txt );
        } else if (
is_array$txt )) {
            
$lines $txt;
        } else {
            
$lines = array();
        }
        
$obj = new stdClass();

        
$sec_name '';
        
$unparsed 0;
        if (!
$lines) {
            return 
$obj;
        }
        foreach (
$lines as $line) {
            
// ignore comments
            
if ($line && $line[0] == ';') {
                continue;
            }
            
$line trim$line );

            if (
$line == '') {
                continue;
            }
            if (
$line && $line[0] == '[' && $line[strlen($line) - 1] == ']') {
                
$sec_name substr$line1strlen($line) - );
                if (
$process_sections) {
                    
$obj->$sec_name = new stdClass();
                }
            } else {
                if (
$pos strpos$line'=' )) {
                    
$property trimsubstr$line0$pos ) );

                    if (
substr($property01) == '"' && substr($property, -1) == '"') {
                        
$property stripcslashes(substr($property,1,count($property) - 2));
                    }
                    
$value trimsubstr$line$pos ) );
                    if (
$value == 'false') {
                        
$value false;
                    }
                    if (
$value == 'true') {
                        
$value true;
                    }
                    if (
substr$value0) == '"' && substr$value, -) == '"') {
                        
$value stripcslashessubstr$value1count$value ) - ) );
                    }

                    if (
$process_sections) {
                        if (
$sec_name != '') {
                              
$obj->$sec_name->$property $value;
                          } else {
                            
$obj->$property $value;
                        }
                    } else {
                        
$obj->$property $value;
                    }
                } else {
                    if (
$line && trim($line[0]) == ';') {
                        continue;
                    }
                    if (
$process_sections) {
                        
$property '__invalid' $unparsed++ . '__';
                        if (
$process_sections) {
                            if (
$sec_name != '') {
                                  
$obj->$sec_name->$property trim($line);
                              } else {
                                
$obj->$property trim($line);
                            }
                        } else {
                            
$obj->$property trim($line);
                        }
                    }
                }
            }
        }
        return 
$obj;
    }
/**
* @param string The name of the control, or the default text area if a setup file is not found
* @return string HTML
*/
    
function render$name='params' ) {
        global 
$mosConfig_absolute_path;

        if (
$this->_path) {
            if (!
is_object$this->_xmlElem )) {
                require_once( 
$mosConfig_absolute_path '/includes/domit/xml_domit_lite_include.php' );

                
$xmlDoc =& new DOMIT_Lite_Document();
                
$xmlDoc->resolveErrorstrue );
                if (
$xmlDoc->loadXML$this->_pathfalsetrue )) {
                    
$element =& $xmlDoc->documentElement;

                    if (
$element->getTagName() == 'mosinstall' && $element->getAttribute"type" ) == $this->_type) {
                        if (
$element = &$xmlDoc->getElementsByPath'params')) {
                            
$this->_xmlElem =& $element;
                        }
                    }
                }
            }
        }

        if (
is_object$this->_xmlElem )) {
            
$html = array();
            
$html[] = '<table class="paramlist">';

            
$element =& $this->_xmlElem;

            if (
$description $element->getAttribute'description' )) {
                
// add the params description to the display
                
$html[] = '<tr><td colspan="3">' $description '</td></tr>';
            }

            
//$params = mosParseParams( $row->params );
            
$this->_methods get_class_methodsget_class$this ) );

            foreach (
$element->childNodes as $param) {
                
$result $this->renderParam$param$name );
                
$html[] = '<tr>';

                
$html[] = '<td width="35%" align="right" valign="top">' $result[0] . '</td>';
                
$html[] = '<td>' $result[1] . '</td>';
                
$html[] = '<td width="10%" align="left" valign="top">' $result[2] . "</td>";

                
$html[] = '</tr>';
            }
            
$html[] = '</table>';

            if (
count$element->childNodes ) < 1) {
                
$html[] = "<tr><td colspan=\"2\"><i>" _NO_PARAMS "</i></td></tr>";
            }
            return 
implode"\n"$html );
        } else {
            return 
"<textarea name=\"$name\" cols=\"40\" rows=\"10\" class=\"text_area\">$this->_raw</textarea>";
        }
    }
/**
* @param object A param tag node
    * @param string The control name
* @return array Any array of the label, the form element and the tooltip
*/
    
function renderParam( &$param$control_name='params' ) {
        
$result = array();

        
$name $param->getAttribute'name' );
        
$label $param->getAttribute'label' );

        
$value $this->get$name$param->getAttribute'default' ) );
        
$description $param->getAttribute'description' );

        
$result[0] = $label $label $name;
        if ( 
$result[0] == '@spacer' ) {
            
$result[0] = '<hr/>';
        } else if ( 
$result[0] ) {
            
$result[0] .= ':';
        }

        
$type $param->getAttribute'type' );

        if (
in_array'_form_' $type$this->_methods )) {
            
$result[1] = call_user_func( array( &$this'_form_' $type ), $name$value$param$control_name );
        } else {
            
$result[1] = _HANDLER ' = ' $type;
        }

        if ( 
$description ) {
            
$result[2] = mosToolTip$description$name );
        } else {
            
$result[2] = '';
        }

        return 
$result;
    }
    
/**
    * @param string The name of the form element
    * @param string The value of the element
    * @param object The xml element for the parameter
    * @param string The control name
    * @return string The html for the element
    */
    
function _form_text$name$value, &$node$control_name ) {
        
$size $node->getAttribute'size' );

        return 
'<input type="text" name="'$control_name .'['$name .']" value="'$value .'" class="text_area" size="'$size .'"/>';
    }
    
/**
    * @param string The name of the form element
    * @param string The value of the element
    * @param object The xml element for the parameter
    * @param string The control name
    * @return string The html for the element
    */
    
function _form_list$name$value, &$node$control_name ) {
        
$size $node->getAttribute'size' );

        
$options = array();
        foreach (
$node->childNodes as $option) {
            
$val $option->getAttribute'value' );
            
$text $option->gettext();
            
$options[] = mosHTML::makeOption$val$text );
        }

        return 
mosHTML::selectList$options''$control_name .'['$name .']''class="inputbox"''value''text'$value );
    }
    
/**
    * @param string The name of the form element
    * @param string The value of the element
    * @param object The xml element for the parameter
    * @param string The control name
    * @return string The html for the element
    */
    
function _form_radio$name$value, &$node$control_name ) {
        
$options = array();
        foreach (
$node->childNodes as $option) {
            
$val $option->getAttribute'value' );
            
$text $option->gettext();
            
$options[] = mosHTML::makeOption$val$texttrue );
        }

        return 
mosHTML::radioList$options''$control_name .'['$name .']'''$value );
    }
    
/**
    * @param string The name of the form element
    * @param string The value of the element
    * @param object The xml element for the parameter
    * @param string The control name
    * @return string The html for the element
    */
    
function _form_mos_section$name$value, &$node$control_name ) {
        global 
$database;

        
$query "SELECT id AS value, title AS text"
        
"\n FROM #__sections"
        
"\n WHERE published='1' AND scope='content'"
        
"\n ORDER BY title"
        
;
        
$database->setQuery$query );
        
$options $database->loadObjectList();
        
array_unshift$optionsmosHTML::makeOption'0''- Select Content Section -' ) );

        return 
mosHTML::selectList$options''$control_name .'['$name .']''class="inputbox"''value''text'$value );
    }
    
/**
    * @param string The name of the form element
    * @param string The value of the element
    * @param object The xml element for the parameter
    * @param string The control name
    * @return string The html for the element
    */
    
function _form_mos_category$name$value, &$node$control_name ) {
        global 
$database;

        
$query     "SELECT c.id AS value, CONCAT_WS( '/',s.title, c.title ) AS text"
        
"\n FROM #__categories AS c"
        
"\n LEFT JOIN #__sections AS s ON s.id=c.section"
        
"\n WHERE c.published='1' AND s.scope='content'"
        
"\n ORDER BY c.title"
        
;
        
$database->setQuery$query );
        
$options $database->loadObjectList();
        
array_unshift$optionsmosHTML::makeOption'0''- Select Content Category -' ) );

        return 
mosHTML::selectList$options''$control_name .'['$name .']''class="inputbox"''value''text'$value );
    }
    
/**
    * @param string The name of the form element
    * @param string The value of the element
    * @param object The xml element for the parameter
    * @param string The control name
    * @return string The html for the element
    */
    
function _form_mos_menu$name$value, &$node$control_name ) {
        global 
$database;

        
$menuTypes mosAdminMenus::menutypes();
        
        foreach(
$menuTypes as $menutype ) {
            
$options[] = mosHTML::makeOption$menutype$menutype );
        }
        
array_unshift$optionsmosHTML::makeOption'''- Select Menu -' ) );

        return 
mosHTML::selectList$options''$control_name .'['$name .']''class="inputbox"''value''text'$value );
    }
    
/**
    * @param string The name of the form element
    * @param string The value of the element
    * @param object The xml element for the parameter
    * @param string The control name
    * @return string The html for the element
    */
    
function _form_imagelist$name$value, &$node$control_name ) {
        global 
$mosConfig_absolute_path;

        
// path to images directory
        
$path $mosConfig_absolute_path $node->getAttribute'directory' );
        
$files mosReadDirectory$path'\.png$|\.gif$|\.jpg$|\.bmp$|\.ico$' );

        
$options = array();
        foreach (
$files as $file) {
            
$options[] = mosHTML::makeOption$file$file );
        }
        if ( !
$node->getAttribute'hide_none' ) ) {
            
array_unshift$optionsmosHTML::makeOption'-1''- Do not use an image -' ) );
        }
        if ( !
$node->getAttribute'hide_default' ) ) {
            
array_unshift$optionsmosHTML::makeOption'''- Use Default image -' ) );
        }

        return 
mosHTML::selectList$options''$control_name .'['$name .']''class="inputbox"''value''text'$value );
    }

    
/**
    * @param string The name of the form element
    * @param string The value of the element
    * @param object The xml element for the parameter
    * @param string The control name
    * @return string The html for the element
    */
    
function _form_textarea$name$value, &$node$control_name ) {
         
$rows     $node->getAttribute'rows' );
         
$cols     $node->getAttribute'cols' );
         
// convert <br /> tags so they are not visible when editing
         
$value     str_replace'<br />'"\n"$value );

         return 
'<textarea name="params['$name .']" cols="'$cols .'" rows="'$rows .'" class="text_area">'$value .'</textarea>';
    }

    
/**
    * @param string The name of the form element
    * @param string The value of the element
    * @param object The xml element for the parameter
    * @param string The control name
    * @return string The html for the element
    */
    
function _form_spacer$name$value, &$node$control_name ) {
        if ( 
$value ) {
            return 
$value;
        } else {
            return 
'<hr />';
        }
    }

    
/**
    * special handling for textarea param
    */
    
function textareaHandling( &$txt ) {
        
$total count$txt );
        for( 
$i=0$i $total$i++ ) {
            if ( 
strstr$txt[$i], "\n" ) ) {
                
$txt[$i] = str_replace"\n"'<br />'$txt[$i] );
            }
        }
        
$txt implode"\n"$txt );

        return 
$txt;
    }
}

/**
* @param string
* @return string
*/
function mosParseParams$txt ) {
    return 
mosParameters::parse$txt );
}

function 
walkNodesAndReturnMosNodeList(&$nodeList, &$contextNode) {
    
//STEP 1: DO SOME ERROR CHECKING (this can be omitted if you want to optimize, but isn't as safe)
    //ensure that node is not null
    
if (!isset( $contextNode )) {
        return;
    }

    
//ensure that node is a DOMIT element
    
if (strtolowerget_class$contextNode ) ) != 'domit_element') {
        
//if contextNode is a DOMIT Document, grab the documentElement
        
if (strtolowerget_class$contextNode ) ) == 'domit_document') {
            
$contextNode =& $contextNode->documentElement;
            if (!isset( 
$contextNode )) {
                return;
            }
        } else {
            return;
        }
    }

    
//STEP 2: EVALUATE THE CONTEXT NODE BASED ON SOME CRITERIA
    //determine whether the context node should be added to the master nodeList
    
if ((strlen$contextNode->nodeName ) > 3) && (substr$contextNode->nodeName0) == "mos:")) {
        
$nodeList->appendNode($contextNode);
    }

    
//STEP 3: ITERATE THROUGH THE CONTEXT NODE CHILDREN AND
    //RECURSIVELY CALL THIS FUNCTION WITH THE CHILD AS THE CONTEXT NODE
    
$total $contextNode->childCount;

    for (
$i 0$i $total$i++) {
        
walkNodesAndReturnMosNodeList($nodeList$contextNode->childNodes[$i]);
    }
//walkNodesAndReturnMosNodeList

/*
    You'd call the function like this:

    $myNodeList =& new DOMIT_NodeList();
    walkNodesAndReturnMosNodeList($myNodeList, $someXMLDoc);
*/

class mosEmpty {
    function 
def$key$value='' ) {
        return 
1;
    }
    function 
get$key$default='' ) {
        return 
1;
    }
}
?>