3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2007 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-2007 The Nucleus Group
18 * @version $Id: bookmarklet.php,v 1.9 2007-02-04 06:28:45 kimitake Exp $
19 * $NucleusJP: bookmarklet.php,v 1.8 2007/02/03 05:41:29 kimitake Exp $
22 // bookmarklet is part of admin area (might need XML-RPC)
24 $CONF['UsingAdminArea'] = 1;
26 // include all classes and config data
27 include('../config.php');
29 $action = requestVar('action');
31 if ($action == 'contextmenucode') {
32 bm_doContextMenuCode();
36 if (!$member->isLoggedIn() ) {
37 bm_loginAndPassThrough();
41 // on successfull login
42 if ( ($action == 'login') && ($member->isLoggedIn() ) ) {
43 $action = requestVar('nextaction');
50 sendContentType('application/xhtml+xml', 'bookmarklet-' . $action);
53 $action = strtolower($action);
54 $aActionsNotToCheck = array('login', 'add', 'edit');
56 if (!in_array($action, $aActionsNotToCheck) ) {
58 if (!$manager->checkTicket() ) {
59 bm_doError(_ERROR_BADTICKET);
64 // find out what to do
66 // adds the item for real
71 // shows the edit item form
76 // edits the item for real
81 // on login, 'action' gets changed to 'nextaction'
83 bm_doError('Something went wrong');
86 // shows the fill in form
93 function bm_doAddItem() {
94 global $member, $manager, $CONF;
96 $manager->loadClass('ITEM');
97 $result = ITEM::createFromRequest();
99 if ($result['status'] == 'error') {
100 bm_doError($result['message']);
103 $blogid = getBlogIDFromItemID($result['itemid']);
104 $blog =& $manager->getBlog($blogid);
106 if ($result['status'] == 'newcategory') {
107 $message = 'アイテムは追加され、新しいカテゴリーが作成されました。 <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">ここをクリックしてカテゴリーの名前と説明を編集してください。</a>';
109 } elseif ((postVar('actiontype') == 'addnow') && $blog->pingUserland()) {
110 $message = 'アイテムの追加に成功しました。現在weblogs.comにpingを送っています。しばらくの間お待ちください...';
111 $pingUrl = $manager->addTicketToUrl($CONF['AdminURL'] . 'index.php?action=sendping&blogid=' . intval($blogid));
112 $extrahead = '<meta http-equiv="refresh" content="1; url=' . htmlspecialchars($pingUrl). '" />';
114 $message = _ITEM_ADDED;
118 bm_message(_ITEM_ADDED, _ITEM_ADDED, $message,$extrahead);
121 function bm_doEditItem() {
122 global $member, $manager, $CONF;
124 $itemid = intRequestVar('itemid');
125 $catid = postVar('catid');
127 // only allow if user is allowed to alter item
128 if (!$member->canUpdateItem($itemid, $catid) ) {
129 bm_doError(_ERROR_DISALLOWED);
132 $body = postVar('body');
133 $title = postVar('title');
134 $more = postVar('more');
135 $closed = intPostVar('closed');
136 $actiontype = postVar('actiontype');
137 $draftid = intPostVar('draftid');
139 // redirect to admin area on delete (has delete confirmation)
140 if ($actiontype == 'delete') {
141 redirect('index.php?action=itemdelete&itemid=' . $itemid);
145 // create new category if needed (only on edit/changedate)
146 if (strstr($catid,'newcat') ) {
148 list($blogid) = sscanf($catid, "newcat-%d");
151 $blog =& $manager->getBlog($blogid);
152 $catid = $blog->createNewCategory();
154 // show error when sth goes wrong
156 bm_doError('Could not create new category');
160 // only edit action is allowed for bookmarklet edit
161 switch ($actiontype) {
165 $timestamp = mktime(postVar('hour'), postVar('minutes'), 0, postVar('month'), postVar('day'), postVar('year') );
173 bm_doError('Something went wrong');
176 // update item for real
177 ITEM::update($itemid, $catid, $title, $body, $more, $closed, $wasdraft, $publish, $timestamp);
180 ITEM::delete($draftid);
183 // show success message
184 if ($catid != intPostVar('catid') ) {
185 bm_message(_ITEM_UPDATED, _ITEM_UPDATED, 'アイテムは追加され、新しいカテゴリーが作成されました。<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">ここをクリックしてカテゴリーの名前と説明を編集してください。</a>', '');
187 bm_message(_ITEM_UPDATED, _ITEM_UPDATED, _ITEM_UPDATED, '');
191 function bm_loginAndPassThrough() {
193 $blogid = intRequestVar('blogid');
194 $log_text = requestVar('logtext');
195 $log_link = requestVar('loglink');
196 $log_linktitle = requestVar('loglinktitle');
199 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
200 <html xmlns="http://www.w3.org/1999/xhtml">
202 <meta http-equiv="Content-Type" content="text/html; charset=<?php echo _CHARSET ?>" />
203 <title>Nucleus</title>
207 <h1><?php echo _LOGIN_PLEASE ?></h1>
209 <form method="post" action="bookmarklet.php">
211 <input name="action" value="login" type="hidden" />
212 <input name="blogid" value="<?php echo htmlspecialchars($blogid); ?>" type="hidden" />
213 <input name="logtext" value="<?php echo htmlspecialchars($log_text); ?>" type="hidden" />
214 <input name="loglink" value="<?php echo htmlspecialchars($log_link); ?>" type="hidden" />
215 <input name="loglinktitle" value="<?php echo htmlspecialchars($log_linktitle); ?>" type="hidden" />
216 <?php echo _LOGINFORM_NAME ?>:
217 <br /><input name="login" />
218 <br /><?php echo _LOGINFORM_PWD ?>:
219 <br /><input name="password" type="password" />
221 <br /><input type="submit" value="<?php echo _LOGIN ?>" />
224 <p><a href="bookmarklet.php" onclick="window.close();"><?php echo _POPUP_CLOSE ?></a></p>
230 function bm_doShowForm() {
233 $blogid = intRequestVar('blogid');
234 $log_text = trim(requestVar('logtext'));
235 $log_link = requestVar('loglink');
236 $log_linktitle = requestVar('loglinktitle');
238 $log_text = uniDecode($log_text,_CHARSET);
239 $log_linktitle = uniDecode($log_linktitle,_CHARSET);
241 if (!BLOG::existsID($blogid))
242 bm_doError(_ERROR_NOSUCHBLOG);
244 if (!$member->isTeamMember($blogid) ) {
245 bm_doError(_ERROR_NOTONTEAM);
251 $logje .= '<blockquote><div>"' . htmlspecialchars($log_text) . '"</div></blockquote>' . "\n";
254 if (!$log_linktitle) {
255 $log_linktitle = $log_link;
259 $logje .= '<a href="' . htmlspecialchars($log_link) . '">' . htmlspecialchars($log_linktitle) . '</a>';
262 $item['body'] = $logje;
263 $item['title'] = htmlspecialchars($log_linktitle);
265 $factory = new PAGEFACTORY($blogid);
266 $factory->createAddForm('bookmarklet', $item);
269 function bm_doEditForm() {
270 global $member, $manager;
272 $itemid = intRequestVar('itemid');
274 if (!$manager->existsItem($itemid, 0, 0) ) {
275 bm_doError(_ERROR_NOSUCHITEM);
278 if (!$member->canAlterItem($itemid) ) {
279 bm_doError(_ERROR_DISALLOWED);
282 $item =& $manager->getItem($itemid, 1, 1);
283 $blog =& $manager->getBlog(getBlogIDFromItemID($itemid) );
285 $manager->notify('PrepareItemForEdit', array('item' => &$item) );
287 if ($blog->convertBreaks() ) {
288 $item['body'] = removeBreaks($item['body']);
289 $item['more'] = removeBreaks($item['more']);
292 $formfactory = new PAGEFACTORY($blog->getID() );
293 $formfactory->createEditForm('bookmarklet', $item);
296 function bm_doError($msg) {
297 bm_message(_ERROR, _ERRORMSG, $msg);
301 function bm_message($title, $head, $msg, $extrahead = '') {
303 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
304 <html xmlns="http://www.w3.org/1999/xhtml">
306 <meta http-equiv="Content-Type" content="text/html; charset=<?php echo _CHARSET ?>" />
307 <title><?php echo $title ?></title>
309 <?php echo $extrahead; ?>
312 <h1><?php echo $head; ?></h1>
313 <p><?php echo $msg; ?></p>
314 <p><a href="bookmarklet.php" onclick="window.close();"><?php echo _POPUP_CLOSE ?></a></p>
321 function bm_style() {
322 echo '<link rel="stylesheet" type="text/css" href="styles/bookmarklet.css" />';
323 echo '<link rel="stylesheet" type="text/css" href="styles/addedit.css" />';
326 function bm_doContextMenuCode() {
329 <script type="text/javascript" defer="defer">
330 doc = external.menuArguments.document;
331 lt = escape(doc.selection.createRange().text);
332 loglink = escape(external.menuArguments.location.href);
333 loglinktitle = escape(doc.title);
334 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');
340 function uniDecode($str,$charcode){
341 $text = preg_replace_callback("/%u[0-9A-Za-z]{4}/",toUtf8,$str);
342 return mb_convert_encoding($text, $charcode, 'UTF-8');
344 function toUtf8($ar){
345 foreach($ar as $val){
346 $val = intval(substr($val,2),16);
347 if($val < 0x7F){ // 0000-007F
349 }elseif($val < 0x800) { // 0080-0800
350 $c .= chr(0xC0 | ($val / 64));
351 $c .= chr(0x80 | ($val % 64));
353 $c .= chr(0xE0 | (($val / 64) / 64));
354 $c .= chr(0x80 | (($val / 64) % 64));
355 $c .= chr(0x80 | ($val % 64));