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');
29 $skinid = $member->bookmarklet;
30 if ( !Skin::existsID($skinid) )
32 $skinid = $CONF['BookmarkletSkin'];
33 if ( !Skin::existsID($skinid) )
35 sendContentType('text/html');
40 $skin =& $manager->getSkin($skinid, 'AdminActions', 'AdminSkin');
42 // check logged-in or pass through
43 $action = requestVar('action');
44 if ( !$member->isLoggedIn() )
46 bm_loginAndPassThrough($skin, $action);
49 else if ( $action == 'login')
51 $action = requestVar('nextaction');
54 $action = strtolower($action);
56 if ( $action == 'contextmenucode' )
58 bm_doContextMenuCode();
61 else if ( $action == '' )
67 $aActionsNotToCheck = array('login', 'add', 'edit');
68 if ( !in_array($action, $aActionsNotToCheck) )
70 if ( !$manager->checkTicket() )
72 bm_doError($skin, _ERROR_BADTICKET);
76 // find out what to do
79 // adds the item for real
84 // shows the edit item form
89 // edits the item for real
94 // on login, 'action' gets changed to 'nextaction'
96 bm_doError($skin, 'Something went wrong');
99 // shows the fill in form
102 bm_doShowForm($skin);
106 function bm_doAddItem($skin)
108 global $member, $manager, $CONF;
110 $manager->loadClass('ITEM');
111 $result = Item::createFromRequest();
113 if ( $result['status'] == 'error' )
115 bm_doError($skin, $result['message']);
118 $blogid = getBlogIDFromItemID($result['itemid']);
119 $blog =& $manager->getBlog($blogid);
121 if ( $result['status'] == 'newcategory' )
123 $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>';
128 $message = _ITEM_ADDED;
132 bm_message($skin, _ITEM_ADDED, $message,$extrahead);
137 function bm_doEditItem($skin)
139 global $member, $manager, $CONF;
141 $itemid = intRequestVar('itemid');
142 $catid = postVar('catid');
144 // only allow if user is allowed to alter item
145 if ( !$member->canUpdateItem($itemid, $catid) )
147 bm_doError($skin, _ERROR_DISALLOWED);
150 $body = postVar('body');
151 $title = postVar('title');
152 $more = postVar('more');
153 $closed = intPostVar('closed');
154 $actiontype = postVar('actiontype');
155 $draftid = intPostVar('draftid');
157 // redirect to admin area on delete (has delete confirmation)
158 if ( $actiontype == 'delete' )
160 redirect('index.php?action=itemdelete&itemid=' . $itemid);
164 // create new category if needed (only on edit/changedate)
165 if ( i18n::strpos($catid,'newcat') === 0 )
168 list($blogid) = sscanf($catid, "newcat-%d");
171 $blog =& $manager->getBlog($blogid);
172 $catid = $blog->createNewCategory();
174 // show error when sth goes wrong
177 bm_doError($skin, 'Could not create new category');
181 // only edit action is allowed for bookmarklet edit
182 switch ( $actiontype )
187 $timestamp = mktime(intPostVar('hour'), intPostVar('minutes'), 0, intPostVar('month'), intPostVar('day'), intPostVar('year') );
200 bm_doError($skin, 'Something went wrong');
203 // update item for real
204 Item::update($itemid, $catid, $title, $body, $more, $closed, $wasdraft, $publish, $timestamp);
208 Item::delete($draftid);
211 if ( $result['status'] == 'newcategory' )
213 $href = "index.php?action=categoryedit&blogid={$blogid}&catid={$result['catid']}";
214 $onclick = 'if (event && event.preventDefault) event.preventDefault(); window.open(this.href); return false;';
215 $title = _BOOKMARKLET_NEW_WINDOW;
216 $aTag = " <a href=\"{$href}\" onclick=\"{$onclick}\" title=\"{$title}\">";
217 $message = _BOOKMARKLET_NEW_CATEGORY . $aTag . _BOOKMARKLET_NEW_CATEGORY_EDIT . '</a>';
221 $message = _ITEM_ADDED;
224 // show success message
225 bm_message($skin, _ITEM_ADDED, $message, '');
229 function bm_loginAndPassThrough($skin, $action='add')
233 $blogid = intRequestVar('blogid');
234 $itemid = intRequestVar('itemid');
235 $log_text = requestVar('logtext');
236 $log_link = requestVar('loglink');
237 $log_linktitle = requestVar('loglinktitle');
239 echo '<input type="hidden" name="blogid" value="' . Entity::hsc($blogid). '" />' . "\n";
240 echo '<input type="hidden" name="itemid" value="' . Entity::hsc($itemid). '" />' . "\n";
241 echo '<input type="hidden" name="logtext" value="' . Entity::hsc($log_text) . '" />' . "\n";
242 echo '<input type="hidden" name="loglink" value="' . Entity::hsc($log_link) . '" />' . "\n";
243 echo '<input type="hidden" name="loglinktitle" value="' . Entity::hsc($log_linktitle) . '" />' . "\n";
244 echo "<input type=\"hidden\" name=\"nextaction\" value=\"{$action}\" />\n";
247 $skin->parse('showlogin');
252 function bm_doShowForm($skin)
254 global $manager, $member;
256 $blogid = intRequestVar('blogid');
257 $log_text = trim(requestVar('logtext'));
258 $log_link = requestVar('loglink');
259 $log_linktitle = requestVar('loglinktitle');
261 if ( !Blog::existsID($blogid) )
263 bm_doError($skin, _ERROR_NOSUCHBLOG);
265 else if ( !$member->isTeamMember($blogid) )
267 bm_doError($skin, _ERROR_NOTONTEAM);
270 $blog =& $manager->getBlog($blogid);
276 $logje .= '<blockquote><div>"' . Entity::hsc($log_text) . '"</div></blockquote>' . "\n";
279 if ( !$log_linktitle )
281 $log_linktitle = $log_link;
286 $logje .= '<a href="' . Entity::hsc($log_link) . '">' . Entity::hsc($log_linktitle) . '</a>';
290 $item['body'] = $logje;
291 $item['title'] = Entity::hsc($log_linktitle);
298 $manager->notify('PreAddItemForm', $data);
300 if ( $blog->convertBreaks() )
302 $item['body'] = removeBreaks($item['body']);
305 Admin::$blog = &$blog;
306 Admin::$contents = &$item;
308 Admin::$action = 'createitem';
309 $skin->parse('createitem');
314 function bm_doEditForm($skin)
316 global $member, $manager;
318 $itemid = intRequestVar('itemid');
320 if ( !$manager->existsItem($itemid, 0, 0) )
322 bm_doError($skin, _ERROR_NOSUCHITEM);
324 else if ( !$member->canAlterItem($itemid) )
326 bm_doError($skin, _ERROR_DISALLOWED);
329 $blog =& $manager->getBlog(getBlogIDFromItemID($itemid) );
330 $item =& $manager->getItem($itemid, 1, 1);
336 $manager->notify('PrepareItemForEdit', $data);
338 if ( $blog->convertBreaks() )
340 $item['body'] = removeBreaks($item['body']);
341 $item['more'] = removeBreaks($item['more']);
344 Admin::$blog = &$blog;
345 Admin::$contents = &$item;
347 Admin::$action = 'itemedit';
348 $skin->parse('itemedit');
352 function bm_doError($skin, $msg)
354 bm_message($skin, _ERRORMSG, $msg);
358 function bm_message($skin, $title, $msg, $extrahead = '')
360 Admin::$extrahead = $extrahead;
361 Admin::$headMess = $msg;
362 $skin->parse('adminerrorpage');
367 function bm_doContextMenuCode($width=600, $height=500)
370 $blogid = (integer) intGetVar('blogid');
372 echo "<script type=\"text/javascript\" defer=\"defer\">\n";
374 echo " doc = external.menuArguments.document;\n";
375 echo " lt = encodeURIComponent(doc.selection.createRange().text);\n";
376 echo " loglink = encodeURIComponent(external.menuArguments.location.href);\n";
377 echo " loglinktitle = encodeURIComponent(doc.title);\n";
378 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";
379 echo " wingm.focus()\n";