3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2009 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-2009 The Nucleus Group
19 * $NucleusJP: bookmarklet.php,v 1.9.2.1 2007/09/07 07:16:39 kimitake Exp $
22 // bookmarklet is part of admin area (might need XML-RPC)
\r
24 $CONF['UsingAdminArea'] = 1;
\r
26 // include all classes and config data
\r
27 include('../config.php');
\r
29 $action = requestVar('action');
\r
31 if ($action == 'contextmenucode') {
\r
32 bm_doContextMenuCode();
\r
36 if (!$member->isLoggedIn() ) {
\r
37 bm_loginAndPassThrough();
\r
41 // on successfull login
\r
42 if ( ($action == 'login') && ($member->isLoggedIn() ) ) {
\r
43 $action = requestVar('nextaction');
\r
46 if ($action == '') {
\r
50 sendContentType('text/html', 'bookmarklet-' . $action);
\r
53 $action = strtolower($action);
\r
54 $aActionsNotToCheck = array('login', 'add', 'edit');
\r
56 if (!in_array($action, $aActionsNotToCheck) ) {
\r
58 if (!$manager->checkTicket() ) {
\r
59 bm_doError(_ERROR_BADTICKET);
\r
64 // find out what to do
\r
66 // adds the item for real
\r
71 // shows the edit item form
\r
76 // edits the item for real
\r
81 // on login, 'action' gets changed to 'nextaction'
\r
83 bm_doError('Something went wrong');
\r
86 // shows the fill in form
\r
93 function bm_doAddItem() {
\r
94 global $member, $manager, $CONF;
\r
96 $manager->loadClass('ITEM');
\r
97 $result = ITEM::createFromRequest();
\r
99 if ($result['status'] == 'error') {
\r
100 bm_doError($result['message']);
\r
103 $blogid = getBlogIDFromItemID($result['itemid']);
\r
104 $blog =& $manager->getBlog($blogid);
\r
106 if ($result['status'] == 'newcategory') {
\r
107 $href = 'index.php?action=categoryedit&blogid=' . $blogid . '&catid=' . $result['catid'];
\r
108 $onclick = 'if (event && event.preventDefault) event.preventDefault(); window.open(this.href); return false;';
\r
109 $title = _BOOKMARKLET_NEW_WINDOW;
\r
110 $aTag = ' <a href="' . $href . '" onclick="' . $onclick . '" title="' . $title . '">';
\r
111 $message = _BOOKMARKLET_NEW_CATEGORY . $aTag . _BOOKMARKLET_NEW_CATEGORY_EDIT . '</a>';
\r
113 } elseif ( (postVar('actiontype') == 'addnow') && $blog->sendPing() ) {
\r
114 $message = _BOOKMARKLET_SEND_PING;
\r
115 $pingUrl = $manager->addTicketToUrl($CONF['AdminURL'] . 'index.php?action=sendping&blogid=' . intval($blogid) );
\r
116 $extrahead = '<meta http-equiv="refresh" content="1; url=' . htmlspecialchars($pingUrl) . '" />';
\r
118 $message = _ITEM_ADDED;
\r
122 bm_message(_ITEM_ADDED, _ITEM_ADDED, $message,$extrahead);
\r
125 function bm_doEditItem() {
\r
126 global $member, $manager, $CONF;
\r
128 $itemid = intRequestVar('itemid');
\r
129 $catid = postVar('catid');
\r
131 // only allow if user is allowed to alter item
\r
132 if (!$member->canUpdateItem($itemid, $catid) ) {
\r
133 bm_doError(_ERROR_DISALLOWED);
\r
136 $body = postVar('body');
\r
137 $title = postVar('title');
\r
138 $more = postVar('more');
\r
139 $closed = intPostVar('closed');
\r
140 $actiontype = postVar('actiontype');
\r
141 $draftid = intPostVar('draftid');
\r
143 // redirect to admin area on delete (has delete confirmation)
\r
144 if ($actiontype == 'delete') {
\r
145 redirect('index.php?action=itemdelete&itemid=' . $itemid);
\r
149 // create new category if needed (only on edit/changedate)
\r
150 if (strstr($catid,'newcat') ) {
\r
152 list($blogid) = sscanf($catid, "newcat-%d");
\r
155 $blog =& $manager->getBlog($blogid);
\r
156 $catid = $blog->createNewCategory();
\r
158 // show error when sth goes wrong
\r
160 bm_doError('Could not create new category');
\r
164 // only edit action is allowed for bookmarklet edit
\r
165 switch ($actiontype) {
\r
169 $timestamp = mktime(intPostVar('hour'), intPostVar('minutes'), 0, intPostVar('month'), intPostVar('day'), intPostVar('year') );
\r
176 case 'backtodrafts':
\r
182 bm_doError('Something went wrong');
\r
185 // update item for real
\r
186 ITEM::update($itemid, $catid, $title, $body, $more, $closed, $wasdraft, $publish, $timestamp);
\r
188 if ($draftid > 0) {
\r
189 ITEM::delete($draftid);
\r
192 // show success message
\r
193 if ($catid != intPostVar('catid') ) {
\r
194 $href = 'index.php?action=categoryedit&blogid=' . $blog->getID() . '&catid=' . $catid;
\r
195 $onclick = 'if (event && event.preventDefault) event.preventDefault(); window.open(this.href); return false;';
\r
196 $title = _BOOKMARKLET_NEW_WINDOW;
\r
197 $aTag = ' <a href="' . $href . '" onclick="' . $onclick . '" title="' . $title . '">';
\r
198 $message = _BOOKMARKLET_NEW_CATEGORY . $aTag . _BOOKMARKLET_NEW_CATEGORY_EDIT . '</a>';
\r
199 bm_message(_ITEM_UPDATED, _ITEM_UPDATED, _BOOKMARKLET_NEW_CATEGORY . $aTag . _BOOKMARKLET_NEW_CATEGORY_EDIT . '</a>', '');
\r
201 bm_message(_ITEM_UPDATED, _ITEM_UPDATED, _ITEM_UPDATED, '');
\r
205 function bm_loginAndPassThrough() {
\r
207 $blogid = intRequestVar('blogid');
\r
208 $log_text = requestVar('logtext');
\r
209 $log_link = requestVar('loglink');
\r
210 $log_linktitle = requestVar('loglinktitle');
\r
213 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
\r
214 <html <?php echo _HTML_XML_NAME_SPACE_AND_LANG_CODE; ?>>
\r
216 <meta http-equiv="Content-Type" content="text/html; charset=<?php echo _CHARSET ?>" />
\r
217 <title>Nucleus</title>
\r
218 <?php bm_style(); ?>
\r
221 <h1><?php echo _LOGIN_PLEASE ?></h1>
\r
223 <form method="post" action="bookmarklet.php">
\r
225 <input name="action" value="login" type="hidden" />
\r
226 <input name="blogid" value="<?php echo htmlspecialchars($blogid); ?>" type="hidden" />
\r
227 <input name="logtext" value="<?php echo htmlspecialchars($log_text); ?>" type="hidden" />
\r
228 <input name="loglink" value="<?php echo htmlspecialchars($log_link); ?>" type="hidden" />
\r
229 <input name="loglinktitle" value="<?php echo htmlspecialchars($log_linktitle); ?>" type="hidden" />
\r
230 <?php echo _LOGINFORM_NAME ?>:
\r
231 <br /><input name="login" />
\r
232 <br /><?php echo _LOGINFORM_PWD ?>:
\r
233 <br /><input name="password" type="password" />
\r
235 <br /><input type="submit" value="<?php echo _LOGIN ?>" />
\r
238 <p><a href="bookmarklet.php" onclick="window.close();"><?php echo _POPUP_CLOSE ?></a></p>
\r
244 function bm_doShowForm() {
\r
247 $blogid = intRequestVar('blogid');
\r
248 $log_text = trim(requestVar('logtext'));
\r
249 $log_link = requestVar('loglink');
\r
250 $log_linktitle = requestVar('loglinktitle');
\r
252 $log_text = uniDecode($log_text,_CHARSET);
\r
253 $log_linktitle = uniDecode($log_linktitle,_CHARSET);
\r
255 if (!BLOG::existsID($blogid) ) {
\r
256 bm_doError(_ERROR_NOSUCHBLOG);
\r
259 if (!$member->isTeamMember($blogid) ) {
\r
260 bm_doError(_ERROR_NOTONTEAM);
\r
266 $logje .= '<blockquote><div>"' . htmlspecialchars($log_text) . '"</div></blockquote>' . "\n";
\r
269 if (!$log_linktitle) {
\r
270 $log_linktitle = $log_link;
\r
274 $logje .= '<a href="' . htmlspecialchars($log_link) . '">' . htmlspecialchars($log_linktitle) . '</a>';
\r
277 $item['body'] = $logje;
\r
278 $item['title'] = htmlspecialchars($log_linktitle);
\r
280 $factory = new PAGEFACTORY($blogid);
\r
281 $factory->createAddForm('bookmarklet', $item);
\r
284 function bm_doEditForm() {
\r
285 global $member, $manager;
\r
287 $itemid = intRequestVar('itemid');
\r
289 if (!$manager->existsItem($itemid, 0, 0) ) {
\r
290 bm_doError(_ERROR_NOSUCHITEM);
\r
293 if (!$member->canAlterItem($itemid) ) {
\r
294 bm_doError(_ERROR_DISALLOWED);
\r
297 $item =& $manager->getItem($itemid, 1, 1);
\r
298 $blog =& $manager->getBlog(getBlogIDFromItemID($itemid) );
\r
300 $manager->notify('PrepareItemForEdit', array('item' => &$item) );
\r
302 if ($blog->convertBreaks() ) {
\r
303 $item['body'] = removeBreaks($item['body']);
\r
304 $item['more'] = removeBreaks($item['more']);
\r
307 $formfactory = new PAGEFACTORY($blog->getID() );
\r
308 $formfactory->createEditForm('bookmarklet', $item);
\r
311 function bm_doError($msg) {
\r
312 bm_message(_ERROR, _ERRORMSG, $msg);
\r
316 function bm_message($title, $head, $msg, $extrahead = '') {
\r
318 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
\r
319 <html <?php echo _HTML_XML_NAME_SPACE_AND_LANG_CODE; ?>>
\r
321 <meta http-equiv="Content-Type" content="text/html; charset=<?php echo _CHARSET ?>" />
\r
322 <title><?php echo $title ?></title>
\r
323 <?php bm_style(); ?>
\r
324 <?php echo $extrahead; ?>
\r
327 <h1><?php echo $head; ?></h1>
\r
328 <p><?php echo $msg; ?></p>
\r
329 <p><a href="bookmarklet.php" onclick="window.close();window.opener.location.reload();"><?php echo _POPUP_CLOSE ?></a></p>
\r
336 function bm_style() {
\r
337 echo '<link rel="stylesheet" type="text/css" href="styles/bookmarklet.css" />';
\r
338 echo '<link rel="stylesheet" type="text/css" href="styles/addedit.css" />';
\r
341 function bm_doContextMenuCode() {
\r
344 <script type="text/javascript" defer="defer">
\r
345 doc = external.menuArguments.document;
\r
346 lt = escape(doc.selection.createRange().text);
\r
347 loglink = escape(external.menuArguments.location.href);
\r
348 loglinktitle = escape(doc.title);
\r
349 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');
\r
355 function uniDecode($str,$charcode){
\r
356 $text = preg_replace_callback("/%u[0-9A-Za-z]{4}/",toUtf8,$str);
\r
357 return mb_convert_encoding($text, $charcode, 'UTF-8');
\r
359 function toUtf8($ar){
\r
360 foreach($ar as $val){
\r
361 $val = intval(substr($val,2),16);
\r
362 if($val < 0x7F){ // 0000-007F
\r
364 }elseif($val < 0x800) { // 0080-0800
\r
365 $c .= chr(0xC0 | ($val / 64));
\r
366 $c .= chr(0x80 | ($val % 64));
\r
367 }else{ // 0800-FFFF
\r
368 $c .= chr(0xE0 | (($val / 64) / 64));
\r
369 $c .= chr(0x80 | (($val / 64) % 64));
\r
370 $c .= chr(0x80 | ($val % 64));
\r