3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2004 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)
12 * This script allows adding items to Nucleus through bookmarklets. The member must be logged in
13 * in order to use this.
15 * $Id: bookmarklet.php,v 1.1.1.1 2005-02-28 07:14:31 kimitake Exp $
18 // bookmarklet is part of admin area (might need XML-RPC)
20 $CONF['UsingAdminArea'] = 1;
22 // include all classes and config data
23 include('../config.php');
25 $action = requestVar('action');
27 if ($action == 'contextmenucode') {
28 bm_doContextMenuCode();
32 if (!$member->isLoggedIn()) {
33 bm_loginAndPassThrough();
37 // on successfull login
38 if (($action == 'login') && ($member->isLoggedIn()))
39 $action = requestVar('nextaction');
43 sendContentType('application/xhtml+xml', 'bookmarklet-'.$action);
46 $action = strtolower($action);
47 $aActionsNotToCheck = array('login', 'add', 'edit');
48 if (!in_array($action, $aActionsNotToCheck))
50 if (!$manager->checkTicket())
51 bm_doError(_ERROR_BADTICKET);
55 // find out what to do
58 bm_doAddItem(); // adds the item for real
61 bm_doEditForm(); // shows the edit item form
63 case 'edititem': // edits the item for real
66 case 'login': // on login, 'action' gets changed to 'nextaction'
67 bm_doError('Something went wrong');
71 bm_doShowForm(); // shows the fill in form
75 function bm_doAddItem() {
76 global $member, $manager;
78 $manager->loadClass('ITEM');
79 $result = ITEM::createFromRequest();
81 if ($result['status'] == 'error')
82 bm_doError($result['message']);
84 $blogid = getBlogIDFromItemID($result['itemid']);
85 $blog =& $manager->getBlog($blogid);
87 if ($result['status'] == 'newcategory') {
88 $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>';
90 } elseif ((postVar('actiontype') == 'addnow') && $blog->pingUserland()) {
91 $message = 'アイテムの追加に成功しました。現在weblogs.comにpingを送っています。しばらくの間お待ちください...';
92 $extrahead = '<meta http-equiv="refresh" content="1; url=index.php?action=sendping&blogid=' . $blogid . '" />';
94 $message = _ITEM_ADDED;
98 bm_message(_ITEM_ADDED, _ITEM_ADDED, $message,$extrahead);
101 function bm_doEditItem() {
102 global $member, $manager, $CONF;
104 $itemid = intRequestVar('itemid');
105 $catid = postVar('catid');
107 // only allow if user is allowed to alter item
108 if (!$member->canUpdateItem($itemid, $catid))
109 bm_doError(_ERROR_DISALLOWED);
111 $body = postVar('body');
112 $title = postVar('title');
113 $more = postVar('more');
114 $closed = intPostVar('closed');
115 $actiontype = postVar('actiontype');
117 // redirect to admin area on delete (has delete confirmation)
118 if ($actiontype == 'delete') {
119 redirect('index.php?action=itemdelete&itemid='.$itemid);
123 // create new category if needed (only on edit/changedate)
124 if (strstr($catid,'newcat')) {
126 list($blogid) = sscanf($catid,"newcat-%d");
129 $blog =& $manager->getBlog($blogid);
130 $catid = $blog->createNewCategory();
132 // show error when sth goes wrong
134 bm_doError('Could not create new category');
137 // only edit action is allowed for bookmarklet edit
138 switch ($actiontype) {
142 $timestamp = mktime(postVar('hour'), postVar('minutes'), 0, postVar('month'), postVar('day'), postVar('year'));
150 bm_doError('Something went wrong');
153 // update item for real
154 ITEM::update($itemid, $catid, $title, $body, $more, $closed, $wasdraft, $publish, $timestamp);
156 // show success message
157 if ($catid != intPostVar('catid'))
158 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>', '');
160 bm_message(_ITEM_UPDATED, _ITEM_UPDATED, _ITEM_UPDATED, '');
163 function bm_loginAndPassThrough() {
165 $blogid = intRequestVar('blogid');
166 $log_text = requestVar('logtext');
167 $log_link = requestVar('loglink');
168 $log_linktitle = requestVar('loglinktitle');
171 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
172 <html xmlns="http://www.w3.org/1999/xhtml">
174 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
175 <title>Nucleus</title>
179 <h1><?php echo _LOGIN_PLEASE?></h1>
181 <form method="post" action="bookmarklet.php">
183 <input name="action" value="login" type="hidden" />
184 <input name="blogid" value="<?php echo htmlspecialchars($blogid) ?>" type="hidden" />
185 <input name="logtext" value="<?php echo htmlspecialchars($log_text) ?>" type="hidden" />
186 <input name="loglink" value="<?php echo htmlspecialchars($log_link) ?>" type="hidden" />
187 <input name="loglinktitle" value="<?php echo htmlspecialchars($log_linktitle) ?>" type="hidden" />
188 <?php echo _LOGINFORM_NAME?>:
189 <br /><input name="login" />
190 <br /><?php echo _LOGINFORM_PWD?>:
191 <br /><input name="password" type="password" />
193 <br /><input type="submit" value="<?php echo _LOGIN?>" />
196 <p><a href="bookmarklet.php" onclick="window.close();"><?php echo _POPUP_CLOSE?></a></p>
202 function bm_doShowForm() {
205 $blogid = intRequestVar('blogid');
206 $log_text = trim(requestVar('logtext'));
207 $log_link = requestVar('loglink');
208 $log_linktitle = requestVar('loglinktitle');
210 $log_text = uniDecode($log_text,_CHARSET);
211 $log_linktitle = uniDecode($log_linktitle,_CHARSET);
213 if (!BLOG::existsID($blogid))
214 bm_doError(_ERROR_NOSUCHBLOG);
216 if (!$member->isTeamMember($blogid))
217 bm_doError(_ERROR_NOTONTEAM);
221 $logje .= '<blockquote><div>"' . htmlspecialchars($log_text) .'"</div></blockquote>' . "\n";
223 $log_linktitle = $log_link;
225 $logje .= '<a href="'. htmlspecialchars($log_link) . '">'. htmlspecialchars($log_linktitle).'</a>';
228 $item['body'] = $logje;
229 $item['title'] = htmlspecialchars($log_linktitle);
231 $factory = new PAGEFACTORY($blogid);
232 $factory->createAddForm('bookmarklet',$item);
235 function bm_doEditForm() {
236 global $member, $manager;
238 $itemid = intRequestVar('itemid');
240 if (!$manager->existsItem($itemid, 0, 0))
241 bm_doError(_ERROR_NOSUCHITEM);
243 if (!$member->canAlterItem($itemid))
244 bm_doError(_ERROR_DISALLOWED);
246 $item =& $manager->getItem($itemid,1,1);
247 $blog =& $manager->getBlog(getBlogIDFromItemID($itemid));
249 $manager->notify('PrepareItemForEdit', array('item' => &$item));
251 if ($blog->convertBreaks()) {
252 $item['body'] = removeBreaks($item['body']);
253 $item['more'] = removeBreaks($item['more']);
256 $formfactory = new PAGEFACTORY($blog->getID());
257 $formfactory->createEditForm('bookmarklet',$item);
261 function bm_doError($msg) {
262 bm_message(_ERROR,_ERRORMSG,$msg);
266 function bm_message($title, $head, $msg, $extrahead = '') {
268 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
269 <html xmlns="http://www.w3.org/1999/xhtml">
271 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
272 <title><?php echo $title ?></title>
274 <?php echo $extrahead?>
277 <h1><?php echo $head ?></h1>
278 <p><?php echo $msg ?></p>
279 <p><a href="bookmarklet.php" onclick="window.close();"><?php echo _POPUP_CLOSE?></a></p>
285 function bm_style() {
286 echo '<link rel="stylesheet" type="text/css" href="styles/bookmarklet.css" />';
287 echo '<link rel="stylesheet" type="text/css" href="styles/addedit.css" />';
290 function bm_doContextMenuCode() {
293 <script type="text/javascript" defer="defer">
294 doc=external.menuArguments.document;
295 lt=escape(doc.selection.createRange().text);
296 loglink=escape(external.menuArguments.location.href);
297 loglinktitle=escape(doc.title);
298 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');
304 function uniDecode($str,$charcode){
305 $text = preg_replace_callback("/%u[0-9A-Za-z]{4}/",toUtf8,$str);
306 return mb_convert_encoding($text, $charcode, 'utf-8');
308 function toUtf8($ar){
309 foreach($ar as $val){
310 $val = intval(substr($val,2),16);
311 if($val < 0x7F){ // 0000-007F
313 }elseif($val < 0x800) { // 0080-0800
314 $c .= chr(0xC0 | ($val / 64));
315 $c .= chr(0x80 | ($val % 64));
317 $c .= chr(0xE0 | (($val / 64) / 64));
318 $c .= chr(0x80 | (($val / 64) % 64));
319 $c .= chr(0x80 | ($val % 64));