C:\$Recycle.Bin\S-1-5-21-3967099092-2644009230-141905953-500\$R83TZYV\nucleus\libs\PAGEFACTORY.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
<?php
/*
  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) 
  * Copyright (C) 2002-2005 The Nucleus Group
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
  * of the License, or (at your option) any later version.
  * (see nucleus/documentation/index.html#license for more info)
 */
/**
 * @license http://nucleuscms.org/license.txt GNU General Public License
 * @copyright Copyright (C) 2002-2005 The Nucleus Group
 * @version $Id: PAGEFACTORY.php,v 1.20.2.1 2005/08/15 10:50:12 dekarma Exp $
  */

/**
 * The formfactory class can be used to insert add/edit item forms into 
 * admin area, bookmarklet, skins or any other places where such a form
 * might be needed
 */
class PAGEFACTORY extends BaseActions {

    
// ref to the blog object for which an add:edit form is created
    
var $blog;
    
    
// allowed actions (for parser)
    
var $actions;
    
    
// allowed types of forms (bookmarklet/admin)
    
var $allowedTypes;
    var 
$type;        // one of the types in $allowedTypes
    
    // 'add' or 'edit'
    
var $method;
    
    
// info to fill out in the form (e.g. catid, itemid, ...)
    
var $variables;

    
/**
     * creates a new PAGEFACTORY object
     */
    
function PAGEFACTORY($blogid) {
        
// call constructor of superclass first
        
$this->BaseActions();            
        
        global 
$manager;
        
$this->blog =& $manager->getBlog($blogid);
        
        
// TODO: move the definition of actions to the createXForm 
        // methods
        
$this->actions = Array(
            
'actionurl'
            
'title',
            
'body',
            
'more',
            
'blogid',
            
'bloglink',
            
'blogname',
            
'authorname',
            
'checkedonval',
            
'helplink',
            
'currenttime',
            
'itemtime',
            
'init',
            
'text',
            
'jsinput',
            
'jsbuttonbar',
            
'categories',
            
'contents',
            
'ifblogsetting',
            
'ifitemproperty',
            
'else',
            
'endif',
            
'pluginextras',
            
'itemoptions',
            
'extrahead',
            
'ticket'
        
);
        
        
// TODO: maybe add 'skin' later on?
        // TODO: maybe add other pages from admin area
        
$this->allowedTypes = Array('bookmarklet','admin');    
    }

    
/**
     * creates a "add item" form for a given type of page
     *
     * @param type
     *        'admin' or 'bookmarklet' 
     */
    
function createAddForm($type$contents = array()) {
        if (!
in_array($type$this->allowedTypes))
            return;
        
$this->type $type;
        
$this->method 'add';
        
        global 
$manager;
        
$manager->notify('PreAddItemForm', array('contents' => &$contents'blog' => &$this->blog));
        
        
$this->createForm($contents);
    }
    
    
/**
     * creates a "add item" form for a given type of page
     *
     * @param type
     *        'admin' or 'bookmarklet' 
     * @param contents
     *        An associative array
     *            'author' => author
     *            '' => 
     */
    
function createEditForm($type$contents) {
        if (!
in_array($type$this->allowedTypes))
            return;
        
$this->type $type;
        
$this->method 'edit';
        
$this->createForm($contents);
    }
    
    
/**
     * (private) creates a form for a given type of page
     */
    
function createForm($contents) {
        
// save contents
        
$this->variables $contents;
        
        
// get template to use
        
$template $this->getTemplateFor($this->type);
        
        
// use the PARSER engine to parse that template
        
$parser =& new PARSER($this->actions$this);
        
$parser->parse($template);
    }
    
    
/**
     * returns an appropriate template
     */
    
function getTemplateFor($type) {
        global 
$DIR_LIBS;
        
        
$filename $DIR_LIBS 'include/' $this->type '-' $this->method '.template';
        
        if (!
file_exists($filename)) 
            return 
'';

        
$fsize filesize($filename);
        if (
$fsize <= 0)
            return 
'';
            
        
// read file and return it
        
$fd fopen ($filename'r');
        
$contents fread ($fd$fsize);
        
fclose ($fd);
        
        return 
$contents;
        
    }
    
    
// create category dropdown box
    
function parse_categories($startidx 0) {
            if (
$this->variables['catid']) 
                
$catid $this->variables['catid'];                // on edit item
            
else
                
$catid $this->blog->getDefaultCategory();        // on add item
            
            
ADMIN::selectBlogCategory('catid',$catid,$startidx,1,$this->blog->getID());
    }
    
    function 
parse_blogid() {
        echo 
$this->blog->getID();
    }
    
    function 
parse_blogname() {
        echo 
$this->blog->getName();
    }
    
    function 
parse_bloglink() {
        echo 
'<a href="'.htmlspecialchars($this->blog->getURL()).'">'.$this->blog->getName().'</a>';
    }
    
    function 
parse_authorname() {
        
// don't use on add item?
        
global $member;
        echo 
$member->getDisplayName();
    }

    function 
parse_title() {
        echo 
$this->contents['title'];
    }

    
/**
     * Indicates the start of a conditional block of data. It will be added to
     * the output only if the blogsetting with the given name equals the 
     * given value (default for value = 1 = true)
     *
     * the name of the blogsetting is the column name in the nucleus_blog table
     *
     * the conditional block ends with an <endif> var
     */
    
function parse_ifblogsetting($name,$value=1) {
        
$this->_addIfCondition(($this->blog->getSetting($name) == $value));
    }
    
    function 
parse_ifitemproperty($name,$value=1) {
        
$this->_addIfCondition(($this->variables[$name] == $value));
    }
    
    function 
parse_helplink($topic) {
        
help($topic);
    }
    
    
// for future items
    
function parse_currenttime($what) {
        
$nu getdate($this->blog->getCorrectTime());
        echo 
$nu[$what];
    }
    
    
// date change on edit item
    
function parse_itemtime($what) {
        
$itemtime getdate($this->variables['timestamp']);
        echo 
$itemtime[$what];
    }
    
    
// some init stuff for all forms
    
function parse_init() {
        
$authorid = ($this->method == 'edit') ? $this->variables['authorid'] : '';
        
$this->blog->insertJavaScriptInfo($authorid);        
    }
    
    
// on bookmarklets only: insert extra html header information (by plugins)
    
function parse_extrahead() {
        global 
$manager;
        
        
$extrahead '';
        
        
$manager->notify(
            
'BookmarkletExtraHead',
            array(
                
'extrahead' => &$extrahead
            
)
        );
        
        echo 
$extrahead;
    }
    
    
// inserts some localized text
    
function parse_text($which) {
        
// constant($which) only available from 4.0.4 :(
        
if (defined($which)) {     
            eval(
"echo $which;");
        } else {
            echo 
$which;    // this way we see where definitions are missing
        
}
        
    }
    
    function 
parse_contents($which) {
        echo 
htmlspecialchars($this->variables[$which]);
    }
    
    function 
parse_checkedonval($value$name) {
        if (
$this->variables[$name] == $value)
            echo 
"checked='checked'";
    }
    
    
// extra javascript for input and textarea fields
    
function parse_jsinput($which) {
        global 
$CONF;
    
?>
            name="<?php echo $which?>
            id="input<?php echo $which?>
    <?php
        
if ($CONF['DisableJsTools'] != 1) {
    
?>
            onkeyup="storeCaret(this); updPreview('<?php echo $which?>');"
            onclick="storeCaret(this);"
            onselect="storeCaret(this);" 

    <?php        
        

        
        if (
$CONF['DisableJsTools'] == 0) {
    
?>
              onkeypress="shortCuts();"            
    <?php        }
    }
    
    
// shows the javascript button bar
    
function parse_jsbuttonbar($extrabuttons "") {
        global 
$CONF;
        switch(
$CONF['DisableJsTools'])    {

            case 
"0":    
                echo 
'<div class="jsbuttonbar">';

                    
$this->_jsbutton('cut','cutThis()',_ADD_CUT_TT " (Ctrl + X)");
                    
$this->_jsbutton('copy','copyThis()',_ADD_COPY_TT " (Ctrl + C)");
                    
$this->_jsbutton('paste','pasteThis()',_ADD_PASTE_TT " (Ctrl + V)");
                    
$this->_jsbuttonspacer();
                    
$this->_jsbutton('bold',"boldThis()",_ADD_BOLD_TT ." (Ctrl + Shift + B)");
                    
$this->_jsbutton('italic',"italicThis()",_ADD_ITALIC_TT ." (Ctrl + Shift + I)");
                    
$this->_jsbutton('link',"ahrefThis()",_ADD_HREF_TT ." (Ctrl + Shift + A)");
                    
$this->_jsbuttonspacer();                    
                    
$this->_jsbutton('alignleft',"alignleftThis()",_ADD_ALIGNLEFT_TT);
                    
$this->_jsbutton('alignright',"alignrightThis()",_ADD_ALIGNRIGHT_TT);
                    
$this->_jsbutton('aligncenter',"aligncenterThis()",_ADD_ALIGNCENTER_TT);
                    
$this->_jsbuttonspacer();                    
                    
$this->_jsbutton('left',"leftThis()",_ADD_LEFT_TT);
                    
$this->_jsbutton('right',"rightThis()",_ADD_RIGHT_TT);

                
                    if (
$extrabuttons) {
                        
$btns explode('+',$extrabuttons);
                        
$this->_jsbuttonspacer();
                        foreach (
$btns as $button) {
                            switch(
$button) {
                                case 
"media":
                                    
$this->_jsbutton('media',"addMedia()",_ADD_MEDIA_TT .    " (Ctrl + Shift + M)");                            
                                    break;
                                case 
"preview":
                                    
$this->_jsbutton('preview',"showedit()",_ADD_PREVIEW_TT);
                                    break;
                            }
                        }
                    } 
                    
                echo 
'</div>';
                
                break;
            case 
"2":
                echo 
'<div class="jsbuttonbar">';

                    
$this->_jsbutton('bold',"boldThis()",'');
                    
$this->_jsbutton('italic',"italicThis()",'');
                    
$this->_jsbutton('link',"ahrefThis()",'');
                    
$this->_jsbuttonspacer();                                        
                    
$this->_jsbutton('alignleft',"alignleftThis()",_ADD_ALIGNLEFT_TT);
                    
$this->_jsbutton('alignright',"alignrightThis()",_ADD_ALIGNRIGHT_TT);
                    
$this->_jsbutton('aligncenter',"aligncenterThis()",_ADD_ALIGNCENTER_TT);
                    
$this->_jsbuttonspacer();                    
                    
$this->_jsbutton('left',"leftThis()",_ADD_LEFT_TT);
                    
$this->_jsbutton('right',"rightThis()",_ADD_RIGHT_TT);
                    

                    if (
$extrabuttons) {
                        
$btns explode('+',$extrabuttons);
                        
$this->_jsbuttonspacer();
                        foreach (
$btns as $button) {
                            switch(
$button) {
                                case 
"media":
                                    
$this->_jsbutton('media',"addMedia()",'');                            
                                    break;
                            }
                        }
                    } 
                    
                echo 
'</div>';
                
                break;            
        }
    }
    
    
/**
     * Allows plugins to add their own custom fields
     */
    
function parse_pluginextras() {
        global 
$manager;
            
        switch (
$this->method) {
            case 
'add':
                
$manager->notify('AddItemFormExtras'
                        array(
                            
'blog' => &$this->blog
                        
)
                );
                break;
            case 
'edit':
                
$manager->notify('EditItemFormExtras'
                        array(
                            
'variables' => $this->variables,
                            
'blog' => &$this->blog,
                            
'itemid' => $this->variables['itemid']
                        )
                );
                break;
        }
    }
    
    
/**
     * Adds the itemOptions of a plugin to a page
     * @author TeRanEX
     */
    
function parse_itemoptions() {
        global 
$itemid;
        
ADMIN::_insertPluginOptions('item'$itemid);
    }
    
    function 
parse_ticket() {
        global 
$manager;
        
$manager->addTicketHidden();
    }
    
    
/**
     * convenience method
     */
    
function _jsbutton($type$code ,$tooltip) {
    
?>
            <span class="jsbutton"
                onmouseover="BtnHighlight(this);" 
                onmouseout="BtnNormal(this);" 
                onclick="<?php echo $code?>" >            
                <img src="images/button-<?php echo $type?>.gif" alt="<?php echo $tooltip?>" width="16" height="16"/>
            </span>                
    <?php    }
    
    function 
_jsbuttonspacer() {
        echo 
'<span class="jsbuttonspacer"></span>';
    }
    
}
 
 
?>