3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2012 The Nucleus Group
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 * (see nucleus/documentation/index.html#license for more info)
13 * This script allows adding items to Nucleus through bookmarklets. The member must be logged in
14 * in order to use this.
16 * @license http://nucleuscms.org/license.txt GNU General Public License
17 * @copyright Copyright (C) 2002-2012 The Nucleus Group
18 * @version $Id: bookmarklet.php 1624 2012-01-09 11:36:20Z sakamocchi $
21 // bookmarklet is part of admin area (might need XML-RPC)
23 $CONF['UsingAdminArea'] = 1;
25 // include all classes and config data
26 include('../config.php');
31 $skinid = $member->bookmarklet;
32 if ( !Skin::existsID($skinid) )
34 $skinid = $CONF['BookmarkletSkin'];
35 if ( !Skin::existsID($skinid) )
37 sendContentType('text/html');
42 $skin =& $manager->getSkin($skinid, 'AdminActions', 'AdminSkin');
44 >>>>>>> skinnable-master
45 // check logged-in or pass through
46 $action = requestVar('action');
47 if ( !$member->isLoggedIn() )
50 bm_loginAndPassThrough($action);
52 bm_loginAndPassThrough($skin, $action);
53 >>>>>>> skinnable-master
56 else if ( $action == 'login')
58 $action = requestVar('nextaction');
61 $action = strtolower($action);
63 if ( $action == 'contextmenucode' )
65 bm_doContextMenuCode();
68 else if ( $action == '' )
74 // send HTTP 1.1 message header for Content-Type
75 sendContentType('text/html', 'bookmarklet-' . $action);
78 >>>>>>> skinnable-master
80 $aActionsNotToCheck = array('login', 'add', 'edit');
81 if ( !in_array($action, $aActionsNotToCheck) )
83 if ( !$manager->checkTicket() )
85 bm_doError($skin, _ERROR_BADTICKET);
89 // find out what to do
92 // adds the item for real
97 // shows the edit item form
102 // edits the item for real
104 bm_doEditItem($skin);
107 // on login, 'action' gets changed to 'nextaction'
109 bm_doError($skin, 'Something went wrong');
112 // shows the fill in form
115 bm_doShowForm($skin);
119 function bm_doAddItem($skin)
121 global $member, $manager, $CONF;
123 $manager->loadClass('ITEM');
124 $result = Item::createFromRequest();
126 if ( $result['status'] == 'error' )
128 bm_doError($skin, $result['message']);
131 $blogid = getBlogIDFromItemID($result['itemid']);
132 $blog =& $manager->getBlog($blogid);
134 if ( $result['status'] == 'newcategory' )
136 $message = 'Item was added, and a new category was created. <a href="index.php?action=categoryedit&blogid=' . $blogid . '&catid=' . $result['catid'] . '" onclick="if (event && 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>';
141 $message = _ITEM_ADDED;
146 bm_message(_ITEM_ADDED, _ITEM_ADDED, $message,$extrahead);
148 bm_message($skin, _ITEM_ADDED, $message,$extrahead);
149 >>>>>>> skinnable-master
154 function bm_doEditItem($skin)
156 global $member, $manager, $CONF;
158 $itemid = intRequestVar('itemid');
159 $catid = postVar('catid');
161 // only allow if user is allowed to alter item
162 if ( !$member->canUpdateItem($itemid, $catid) )
164 bm_doError($skin, _ERROR_DISALLOWED);
167 $body = postVar('body');
168 $title = postVar('title');
169 $more = postVar('more');
170 $closed = intPostVar('closed');
171 $actiontype = postVar('actiontype');
172 $draftid = intPostVar('draftid');
174 // redirect to admin area on delete (has delete confirmation)
175 if ( $actiontype == 'delete' )
177 redirect('index.php?action=itemdelete&itemid=' . $itemid);
181 // create new category if needed (only on edit/changedate)
182 if ( i18n::strpos($catid,'newcat') === 0 )
185 list($blogid) = sscanf($catid, "newcat-%d");
188 $blog =& $manager->getBlog($blogid);
189 $catid = $blog->createNewCategory();
191 // show error when sth goes wrong
194 bm_doError($skin, 'Could not create new category');
198 // only edit action is allowed for bookmarklet edit
199 switch ( $actiontype )
204 $timestamp = mktime(intPostVar('hour'), intPostVar('minutes'), 0, intPostVar('month'), intPostVar('day'), intPostVar('year') );
217 bm_doError($skin, 'Something went wrong');
220 // update item for real
221 Item::update($itemid, $catid, $title, $body, $more, $closed, $wasdraft, $publish, $timestamp);
225 Item::delete($draftid);
228 if ( $result['status'] == 'newcategory' )
230 $href = "index.php?action=categoryedit&blogid={$blogid}&catid={$result['catid']}";
231 $onclick = 'if (event && event.preventDefault) event.preventDefault(); window.open(this.href); return false;';
232 $title = _BOOKMARKLET_NEW_WINDOW;
233 $aTag = " <a href=\"{$href}\" onclick=\"{$onclick}\" title=\"{$title}\">";
234 $message = _BOOKMARKLET_NEW_CATEGORY . $aTag . _BOOKMARKLET_NEW_CATEGORY_EDIT . '</a>';
238 $message = _ITEM_ADDED;
245 function bm_loginAndPassThrough($action='add')
247 // show success message
248 bm_message($skin, _ITEM_ADDED, $message, '');
252 function bm_loginAndPassThrough($skin, $action='add')
253 >>>>>>> skinnable-master
257 $blogid = intRequestVar('blogid');
258 $itemid = intRequestVar('itemid');
259 $log_text = requestVar('logtext');
260 $log_link = requestVar('loglink');
261 $log_linktitle = requestVar('loglinktitle');
264 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
265 echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n";
267 echo "<title>Nucleus CMS Bookmarklet</title>\n";
273 echo '<h1>' . _LOGIN_PLEASE . "</h1>\n";
274 echo "<form method=\"post\" action=\"bookmarklet.php\">\n";
276 echo _LOGINFORM_NAME . "<input type=\"text\" name=\"login\" value=\"\" /><br />\n";
277 echo _LOGINFORM_PWD . "<input type=\"password\" name=\"password\" value=\"\" /><br />\n";
279 >>>>>>> skinnable-master
280 echo '<input type="hidden" name="blogid" value="' . Entity::hsc($blogid). '" />' . "\n";
281 echo '<input type="hidden" name="itemid" value="' . Entity::hsc($itemid). '" />' . "\n";
282 echo '<input type="hidden" name="logtext" value="' . Entity::hsc($log_text) . '" />' . "\n";
283 echo '<input type="hidden" name="loglink" value="' . Entity::hsc($log_link) . '" />' . "\n";
284 echo '<input type="hidden" name="loglinktitle" value="' . Entity::hsc($log_linktitle) . '" />' . "\n";
285 echo "<input type=\"hidden\" name=\"nextaction\" value=\"{$action}\" />\n";
287 echo '<button type="submit" name="action" value="login">' . _LOGIN . "</button>\n";
290 echo '<p><a href="bookmarklet.php" onclick="window.close();">' . _POPUP_CLOSE . "</a></p>\n";
296 $skin->parse('showlogin');
297 >>>>>>> skinnable-master
302 function bm_doShowForm($skin)
304 global $manager, $member;
306 $blogid = intRequestVar('blogid');
307 $log_text = trim(requestVar('logtext'));
308 $log_link = requestVar('loglink');
309 $log_linktitle = requestVar('loglinktitle');
311 if ( !Blog::existsID($blogid) )
313 bm_doError($skin, _ERROR_NOSUCHBLOG);
318 $blog =& $manager->getBlog($blogid);
321 if ( !$member->isTeamMember($blogid) )
323 else if ( !$member->isTeamMember($blogid) )
324 >>>>>>> skinnable-master
326 bm_doError($skin, _ERROR_NOTONTEAM);
329 $blog =& $manager->getBlog($blogid);
335 $logje .= '<blockquote><div>"' . Entity::hsc($log_text) . '"</div></blockquote>' . "\n";
338 if ( !$log_linktitle )
340 $log_linktitle = $log_link;
345 $logje .= '<a href="' . Entity::hsc($log_link) . '">' . Entity::hsc($log_linktitle) . '</a>';
349 $variables = array();
350 $variables['body'] = $logje;
351 $variables['title'] = Entity::hsc($log_linktitle);
353 $handler = new PageFactory($blog);
354 $handler->setVariables($variables);
356 $contents = $handler->getTemplateFor('bookmarklet', 'add');
357 $manager->notify('PreAddItemForm', array('contents' => &$contents, 'blog' => &$blog));
359 $parser = new Parser($handler);
360 $parser->parse($contents);
364 $item['body'] = $logje;
365 $item['title'] = Entity::hsc($log_linktitle);
372 $manager->notify('PreAddItemForm', $data);
374 if ( $blog->convertBreaks() )
376 $item['body'] = removeBreaks($item['body']);
379 Admin::$blog = &$blog;
380 Admin::$contents = &$item;
382 Admin::$action = 'createitem';
383 $skin->parse('createitem');
385 >>>>>>> skinnable-master
389 function bm_doEditForm($skin)
391 global $member, $manager;
393 $itemid = intRequestVar('itemid');
395 if ( !$manager->existsItem($itemid, 0, 0) )
397 bm_doError($skin, _ERROR_NOSUCHITEM);
399 else if ( !$member->canAlterItem($itemid) )
401 bm_doError($skin, _ERROR_DISALLOWED);
405 $variables =& $manager->getItem($itemid, 1, 1);
407 >>>>>>> skinnable-master
408 $blog =& $manager->getBlog(getBlogIDFromItemID($itemid) );
409 $item =& $manager->getItem($itemid, 1, 1);
412 $manager->notify('PrepareItemForEdit', array('item' => &$variables) );
418 $manager->notify('PrepareItemForEdit', $data);
419 >>>>>>> skinnable-master
421 if ( $blog->convertBreaks() )
423 $variables['body'] = removeBreaks($variables['body']);
424 $variables['more'] = removeBreaks($variables['more']);
428 $handler = new PageFactory($blog);
429 $handler->setVariables($variables);
431 $contents = $handler->getTemplateFor('bookmarklet', 'edit');
433 $parser = new Parser($handler);
434 $parser->parse($contents);
439 Admin::$blog = &$blog;
440 Admin::$contents = &$item;
442 Admin::$action = 'itemedit';
443 $skin->parse('itemedit');
446 >>>>>>> skinnable-master
448 function bm_doError($skin, $msg)
450 bm_message($skin, _ERRORMSG, $msg);
454 function bm_message($skin, $title, $msg, $extrahead = '')
457 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
458 echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n";
460 echo "<title>{$title}</title>\n";
464 echo $extrahead . "\n";
467 echo "<h1>{$head}</h1>\n";
468 echo "<p>{$msg}</p>\n";
469 echo '<p><a href="bookmarklet.php" onclick="window.close();window.opener.location.reload();">' . _POPUP_CLOSE . "</a></p>\n";
473 Admin::$extrahead = $extrahead;
474 Admin::$headMess = $msg;
475 $skin->parse('adminerrorpage');
476 >>>>>>> skinnable-master
481 function bm_doContextMenuCode($width=600, $height=500)
484 echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"styles/bookmarklet.css\" />\n";
485 echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"styles/addedit.css\" />\n";
489 function bm_doContextMenuCode($width=600, $height=500)
495 >>>>>>> skinnable-master
496 $blogid = (integer) intGetVar('blogid');
498 echo "<script type=\"text/javascript\" defer=\"defer\">\n";
500 echo " doc = external.menuArguments.document;\n";
501 echo " lt = encodeURIComponent(doc.selection.createRange().text);\n";
502 echo " loglink = encodeURIComponent(external.menuArguments.location.href);\n";
503 echo " loglinktitle = encodeURIComponent(doc.title);\n";
504 echo " wingm = window.open('{$CONF['AdminURL']}bookmarklet.php?blogid={$blogid}&logtext=' + lt + '&loglink=' + loglink + '&loglinktitle=' + loglinktitle, 'nucleusbm', 'scrollbars=yes,width={$width},height={$height},left=10,top=10,status=yes,resizable=yes')\n";
505 echo " wingm.focus()\n";