C:\$Recycle.Bin\S-1-5-21-3967099092-2644009230-141905953-500\$R83TZYV\nucleus\bookmarklet.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
<?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)
 */
/**
  * This script allows adding items to Nucleus through bookmarklets. The member must be logged in
  * in order to use this.
  *
 * @license http://nucleuscms.org/license.txt GNU General Public License
 * @copyright Copyright (C) 2002-2005 The Nucleus Group
 * @version $Id: bookmarklet.php,v 1.16.2.1 2005/08/15 10:51:08 dekarma Exp $
  */

// bookmarklet is part of admin area (might need XML-RPC)
$CONF = array();
$CONF['UsingAdminArea'] = 1;

// include all classes and config data 
include('../config.php');

$action requestVar('action');

if (
$action == 'contextmenucode') {
    
bm_doContextMenuCode();
    exit;
}

if (!
$member->isLoggedIn()) {
    
bm_loginAndPassThrough();
    exit;
}

// on successfull login
if (($action == 'login') && ($member->isLoggedIn()))
    
$action requestVar('nextaction');
if (
$action == '')
    
$action 'add';
    
sendContentType('application/xhtml+xml''bookmarklet-'.$action);    

// check ticket
$action strtolower($action);
$aActionsNotToCheck = array('login''add''edit');
if (!
in_array($action$aActionsNotToCheck))
{
    if (!
$manager->checkTicket())
        
bm_doError(_ERROR_BADTICKET);



// find out what to do
switch ($action) {
    case 
'additem':
        
bm_doAddItem();        // adds the item for real
        
break;
    case 
'edit':
        
bm_doEditForm();    // shows the edit item form
        
break;
    case 
'edititem':        // edits the item for real
        
bm_doEditItem();
        break;
    case 
'login':            // on login, 'action' gets changed to 'nextaction'
        
bm_doError('Something went wrong');
        break;
    case 
'add':
    default:
        
bm_doShowForm();    // shows the fill in form
        
break;
}
    
function 
bm_doAddItem() {
    global 
$member$manager$CONF;
    
    
$manager->loadClass('ITEM');
    
$result ITEM::createFromRequest();
    
    if (
$result['status'] == 'error')
        
bm_doError($result['message']);

    
$blogid getBlogIDFromItemID($result['itemid']);
    
$blog =& $manager->getBlog($blogid);
    
    if (
$result['status'] == 'newcategory') {
        
$message 'Item was added, and a new category was created. <a href="index.php?action=categoryedit&amp;blogid='.$blogid.'&amp;catid='.$result['catid'].'" onclick="if (event &amp;&amp; event.preventDefault) event.preventDefault(); window.open(this.href); return false;" title="Opens in new window">Click here to edit the name and description of the category.</a>';
        
$extrahead '';
    } elseif ((
postVar('actiontype') == 'addnow') && $blog->pingUserland()) {
        
$message 'Item was added successfully. Now pinging weblogs.com. Please hold on... (can take a while)';
        
$pingUrl $manager->addTicketToUrl($CONF['AdminURL'] . 'index.php?action=sendping&blogid=' intval($blogid));
        
$extrahead '<meta http-equiv="refresh" content="1; url=' htmlspecialchars($pingUrl). '" />';
    } else {
        
$message _ITEM_ADDED;
        
$extrahead '';
    }
    
    
bm_message(_ITEM_ADDED_ITEM_ADDED$message,$extrahead);
}

function 
bm_doEditItem() {
    global 
$member$manager$CONF;
    
    
$itemid     intRequestVar('itemid');
    
$catid         postVar('catid');
    
    
// only allow if user is allowed to alter item
    
if (!$member->canUpdateItem($itemid$catid))
        
bm_doError(_ERROR_DISALLOWED);

    
$body         postVar('body');
    
$title         postVar('title');
    
$more         postVar('more');
    
$closed     intPostVar('closed');
    
$actiontype postVar('actiontype');
    
    
// redirect to admin area on delete (has delete confirmation)
    
if ($actiontype == 'delete') {
        
redirect('index.php?action=itemdelete&itemid='.$itemid);
        exit;    
    }
    
    
// create new category if needed (only on edit/changedate)
    
if (strstr($catid,'newcat')) {
        
// get blogid 
        
list($blogid) = sscanf($catid,"newcat-%d");

        
// create
        
$blog =& $manager->getBlog($blogid);
        
$catid $blog->createNewCategory();

        
// show error when sth goes wrong
        
if (!$catid
            
bm_doError('Could not create new category');
    } 

    
// only edit action is allowed for bookmarklet edit
    
switch ($actiontype) {
        case 
'changedate':
            
$publish 1;
            
$wasdraft 0;
            
$timestamp mktime(postVar('hour'), postVar('minutes'), 0postVar('month'), postVar('day'), postVar('year'));
            break;
        case 
'edit':
            
$publish 1;
            
$wasdraft 0;
            
$timestamp 0;
            break;
        default:
            
bm_doError('Something went wrong');
    }
    
    
// update item for real
    
ITEM::update($itemid$catid$title$body$more$closed$wasdraft$publish$timestamp);
    
    
// show success message
    
if ($catid != intPostVar('catid'))
        
bm_message(_ITEM_UPDATED_ITEM_UPDATED'Item was added, and a new category was created. <a href="index.php?action=categoryedit&amp;blogid='.$blog->getID().'&amp;catid='.$catid.'" onclick="if (event &amp;&amp; event.preventDefault) event.preventDefault(); window.open(this.href); return false;" title="Opens in new window">Click here to edit the name and description of the category.</a>''');
    else
        
bm_message(_ITEM_UPDATED_ITEM_UPDATED_ITEM_UPDATED'');
}

function 
bm_loginAndPassThrough() {

    
$blogid intRequestVar('blogid');
    
$log_text requestVar('logtext');
    
$log_link requestVar('loglink');
    
$log_linktitle requestVar('loglinktitle');
    
    
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Nucleus</title>
        <?php bm_style(); ?>
    </head>
    <body>
    <h1><?php echo _LOGIN_PLEASE?></h1>
    
    <form method="post" action="bookmarklet.php">
    <p>
        <input name="action" value="login" type="hidden" />
        <input name="blogid" value="<?php echo  htmlspecialchars($blogid?>" type="hidden" />
        <input name="logtext" value="<?php echo  htmlspecialchars($log_text?>" type="hidden" />
        <input name="loglink" value="<?php echo  htmlspecialchars($log_link?>" type="hidden" />
        <input name="loglinktitle" value="<?php echo  htmlspecialchars($log_linktitle?>" type="hidden" />
        <?php echo _LOGINFORM_NAME?>:
        <br /><input name="login" />
        <br /><?php echo _LOGINFORM_PWD?>:
        <br /><input name="password" type="password" />
        <br /><br />
        <br /><input type="submit" value="<?php echo _LOGIN?>" />
    </p>
    </form>
    <p><a href="bookmarklet.php" onclick="window.close();"><?php echo _POPUP_CLOSE?></a></p>
    </body>
    </html>
    <?php
}

function 
bm_doShowForm() {
    global 
$member;
    
    
$blogid intRequestVar('blogid');
    
$log_text trim(requestVar('logtext'));
    
$log_link requestVar('loglink');
    
$log_linktitle requestVar('loglinktitle');
    
    if (!
BLOG::existsID($blogid))
        
bm_doError(_ERROR_NOSUCHBLOG);

    if (!
$member->isTeamMember($blogid))
        
bm_doError(_ERROR_NOTONTEAM);
    
    
$logje '';
    if (
$log_text)
        
$logje .= '<blockquote><div>"' htmlspecialchars($log_text) .'"</div></blockquote>' "\n";
    if (!
$log_linktitle)
        
$log_linktitle $log_link;
    if (
$log_link
        
$logje .= '<a href="'htmlspecialchars($log_link) . '">'htmlspecialchars($log_linktitle).'</a>';
        

    
$item['body'] = $logje;
    
$item['title'] = htmlspecialchars($log_linktitle);

    
$factory = new PAGEFACTORY($blogid);
    
$factory->createAddForm('bookmarklet',$item);
}

function 
bm_doEditForm() {
    global 
$member$manager;
    
    
$itemid intRequestVar('itemid');
    
    if (!
$manager->existsItem($itemid00)) 
        
bm_doError(_ERROR_NOSUCHITEM);
        
    if (!
$member->canAlterItem($itemid))
        
bm_doError(_ERROR_DISALLOWED);
        
    
$item =& $manager->getItem($itemid,1,1);
    
$blog =& $manager->getBlog(getBlogIDFromItemID($itemid));
    
    
$manager->notify('PrepareItemForEdit', array('item' => &$item));

    if (
$blog->convertBreaks()) {
        
$item['body'] = removeBreaks($item['body']);
        
$item['more'] = removeBreaks($item['more']);
    }

    
$formfactory = new PAGEFACTORY($blog->getID());
    
$formfactory->createEditForm('bookmarklet',$item);        

}

function 
bm_doError($msg) {
    
bm_message(_ERROR,_ERRORMSG,$msg);
    die;
}

function 
bm_message($title$head$msg$extrahead '') {
    
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title><?php echo  $title ?></title>
        <?php bm_style(); ?>
        <?php echo $extrahead?>
    </head>
    <body>
    <h1><?php echo  $head ?></h1>
    <p><?php echo  $msg ?></p>
    <p><a href="bookmarklet.php" onclick="window.close();"><?php echo _POPUP_CLOSE?></a></p>
    </body>
    </html>
    
    <?php }

function 
bm_style() {
    echo 
'<link rel="stylesheet" type="text/css" href="styles/bookmarklet.css" />';
    echo 
'<link rel="stylesheet" type="text/css" href="styles/addedit.css" />';    
}

function 
bm_doContextMenuCode() {
    global 
$CONF;
    
?>
<script type="text/javascript" defer="defer">
doc=external.menuArguments.document;
lt=escape(doc.selection.createRange().text);
loglink=escape(external.menuArguments.location.href);
loglinktitle=escape(doc.title);
wingm=window.open('<?php echo $CONF['AdminURL']?>bookmarklet.php?blogid=<?php echo intGetVar('blogid')?>&logtext='+lt+'&loglink='+loglink+'&loglinktitle='+loglinktitle,'nucleusbm','scrollbars=yes,width=600,height=500,left=10,top=10,status=yes,resizable=yes');
wingm.focus();
</script>    
    <?php
}

?>