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 = $CONF['BookmarkletSkin'];
30 if ( !Skin::existsID($skinid) )
35 $skin = new Skin($skinid, 'AdminActions', 'AdminSkin');
37 // check logged-in or pass through
38 $action = requestVar('action');
39 if ( !$member->isLoggedIn() )
41 bm_loginAndPassThrough($skin, $action);
44 else if ( $action == 'login')
46 $action = requestVar('nextaction');
49 $action = strtolower($action);
51 if ( $action == 'contextmenucode' )
53 bm_doContextMenuCode();
56 else if ( $action == '' )
62 $aActionsNotToCheck = array('login', 'add', 'edit');
63 if ( !in_array($action, $aActionsNotToCheck) )
65 if ( !$manager->checkTicket() )
67 bm_doError(_ERROR_BADTICKET);
71 // find out what to do
74 // adds the item for real
79 // shows the edit item form
84 // edits the item for real
89 // on login, 'action' gets changed to 'nextaction'
91 bm_doError($skin, 'Something went wrong');
94 // shows the fill in form
101 function bm_doAddItem($skin)
103 global $member, $manager, $CONF;
105 $manager->loadClass('ITEM');
106 $result = Item::createFromRequest();
108 if ( $result['status'] == 'error' )
110 bm_doError($result['message']);
113 $blogid = getBlogIDFromItemID($result['itemid']);
114 $blog =& $manager->getBlog($blogid);
116 if ( $result['status'] == 'newcategory' )
118 $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>';
123 $message = _ITEM_ADDED;
127 bm_message($skin, _ITEM_ADDED, _ITEM_ADDED, $message,$extrahead);
134 function bm_doEditItem($skin)
136 global $member, $manager, $CONF;
138 $itemid = intRequestVar('itemid');
139 $catid = postVar('catid');
141 // only allow if user is allowed to alter item
142 if ( !$member->canUpdateItem($itemid, $catid) )
144 bm_doError(_ERROR_DISALLOWED);
147 $body = postVar('body');
148 $title = postVar('title');
149 $more = postVar('more');
150 $closed = intPostVar('closed');
151 $actiontype = postVar('actiontype');
152 $draftid = intPostVar('draftid');
154 // redirect to admin area on delete (has delete confirmation)
155 if ( $actiontype == 'delete' )
157 redirect('index.php?action=itemdelete&itemid=' . $itemid);
161 // create new category if needed (only on edit/changedate)
162 if ( i18n::strpos($catid,'newcat') === 0 )
165 list($blogid) = sscanf($catid, "newcat-%d");
168 $blog =& $manager->getBlog($blogid);
169 $catid = $blog->createNewCategory();
171 // show error when sth goes wrong
174 bm_doError('Could not create new category');
178 // only edit action is allowed for bookmarklet edit
179 switch ( $actiontype )
184 $timestamp = mktime(intPostVar('hour'), intPostVar('minutes'), 0, intPostVar('month'), intPostVar('day'), intPostVar('year') );
197 bm_doError('Something went wrong');
200 // update item for real
201 Item::update($itemid, $catid, $title, $body, $more, $closed, $wasdraft, $publish, $timestamp);
205 Item::delete($draftid);
208 // show success message
209 if ( $catid != intPostVar('catid') )
211 bm_message($skin, _ITEM_UPDATED, _ITEM_UPDATED, 'Item was added, and a new category was created. <a href="index.php?action=categoryedit&blogid=' . $blog->getID() . '&catid=' . $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>', '');
215 bm_message($skin, _ITEM_UPDATED, _ITEM_UPDATED, _ITEM_UPDATED, '');
221 function bm_loginAndPassThrough($skin, $action='add')
225 $blogid = intRequestVar('blogid');
226 $itemid = intRequestVar('itemid');
227 $log_text = requestVar('logtext');
228 $log_link = requestVar('loglink');
229 $log_linktitle = requestVar('loglinktitle');
231 echo '<input type="hidden" name="blogid" value="' . Entity::hsc($blogid). '" />' . "\n";
232 echo '<input type="hidden" name="itemid" value="' . Entity::hsc($itemid). '" />' . "\n";
233 echo '<input type="hidden" name="logtext" value="' . Entity::hsc($log_text) . '" />' . "\n";
234 echo '<input type="hidden" name="loglink" value="' . Entity::hsc($log_link) . '" />' . "\n";
235 echo '<input type="hidden" name="loglinktitle" value="' . Entity::hsc($log_linktitle) . '" />' . "\n";
236 echo "<input type=\"hidden\" name=\"nextaction\" value=\"{$action}\" />\n";
239 $skin->parse('pagehead');
240 $skin->parse('showlogin');
241 $skin->parse('pagefoot');
247 function bm_doShowForm($skin)
249 global $manager, $member;
251 $blogid = intRequestVar('blogid');
252 $log_text = trim(requestVar('logtext'));
253 $log_link = requestVar('loglink');
254 $log_linktitle = requestVar('loglinktitle');
256 if ( !Blog::existsID($blogid) )
258 bm_doError(_ERROR_NOSUCHBLOG);
262 $blog =& $manager->getBlog($blogid);
265 if ( !$member->isTeamMember($blogid) )
267 bm_doError(_ERROR_NOTONTEAM);
274 $logje .= '<blockquote><div>"' . Entity::hsc($log_text) . '"</div></blockquote>' . "\n";
277 if ( !$log_linktitle )
279 $log_linktitle = $log_link;
284 $logje .= '<a href="' . Entity::hsc($log_link) . '">' . Entity::hsc($log_linktitle) . '</a>';
287 $variables = array();
288 $variables['body'] = $logje;
289 $variables['title'] = Entity::hsc($log_linktitle);
292 $skin->parse('pagehead');
293 $skin->parse('itemedit');
294 $skin->parse('pagefoot');
299 function bm_doEditForm($skin)
301 global $member, $manager;
303 $itemid = intRequestVar('itemid');
305 if ( !$manager->existsItem($itemid, 0, 0) )
307 bm_doError(_ERROR_NOSUCHITEM);
310 if ( !$member->canAlterItem($itemid) )
312 bm_doError(_ERROR_DISALLOWED);
315 $variables =& $manager->getItem($itemid, 1, 1);
316 $blog =& $manager->getBlog(getBlogIDFromItemID($itemid) );
318 $manager->notify('PrepareItemForEdit', array('item' => &$variables) );
320 if ( $blog->convertBreaks() )
322 $variables['body'] = removeBreaks($variables['body']);
323 $variables['more'] = removeBreaks($variables['more']);
327 $skin->parse('pagehead');
328 $skin->parse('createitem');
329 $skin->parse('pagefoot');
333 function bm_doError($skin, $msg)
335 bm_message($skin, _ERROR, _ERRORMSG, $msg);
339 function bm_message($skin, $title, $head, $msg, $extrahead = '')
341 /* TODO: $title, $head, $msg, $extraheadを渡す */
342 $skin->parse('pagehead');
343 $skin->parse('adminerrorpage');
344 $skin->parse('pagefoot');
350 function bm_doContextMenuCode($width=600, $height=500)
353 $blogid = (integer) intGetVar('blogid');
355 echo "<script type=\"text/javascript\" defer=\"defer\">\n";
357 echo " doc = external.menuArguments.document;\n";
358 echo " lt = encodeURIComponent(doc.selection.createRange().text);\n";
359 echo " loglink = encodeURIComponent(external.menuArguments.location.href);\n";
360 echo " loglinktitle = encodeURIComponent(doc.title);\n";
361 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";
362 echo " wingm.focus()\n";