bookmarklet.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
00004  * Copyright (C) 2002-2007 The Nucleus Group
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  * (see nucleus/documentation/index.html#license for more info)
00011  */
00022 // bookmarklet is part of admin area (might need XML-RPC)
00023 $CONF = array();
00024 $CONF['UsingAdminArea'] = 1;
00025 
00026 // include all classes and config data
00027 include('../config.php');
00028 
00029 $action = requestVar('action');
00030 
00031 if ($action == 'contextmenucode') {
00032         bm_doContextMenuCode();
00033         exit;
00034 }
00035 
00036 if (!$member->isLoggedIn() ) {
00037         bm_loginAndPassThrough();
00038         exit;
00039 }
00040 
00041 // on successfull login
00042 if ( ($action == 'login') && ($member->isLoggedIn() ) ) {
00043         $action = requestVar('nextaction');
00044 }
00045 
00046 if ($action == '') {
00047         $action = 'add';
00048 }
00049 
00050 sendContentType('application/xhtml+xml', 'bookmarklet-' . $action);
00051 
00052 // check ticket
00053 $action = strtolower($action);
00054 $aActionsNotToCheck = array('login', 'add', 'edit');
00055 
00056 if (!in_array($action, $aActionsNotToCheck) ) {
00057 
00058         if (!$manager->checkTicket() ) {
00059                 bm_doError(_ERROR_BADTICKET);
00060         }
00061 
00062 }
00063 
00064 // find out what to do
00065 switch ($action) {
00066         // adds the item for real
00067         case 'additem':
00068                 bm_doAddItem();
00069                 break;
00070 
00071         // shows the edit item form
00072         case 'edit':
00073                 bm_doEditForm();
00074                 break;
00075 
00076         // edits the item for real
00077         case 'edititem':
00078                 bm_doEditItem();
00079                 break;
00080 
00081         // on login, 'action' gets changed to 'nextaction'
00082         case 'login':
00083                 bm_doError('Something went wrong');
00084                 break;
00085 
00086         // shows the fill in form
00087         case 'add':
00088         default:
00089                 bm_doShowForm();
00090                 break;
00091 }
00092 
00093 function bm_doAddItem() {
00094         global $member, $manager, $CONF;
00095 
00096         $manager->loadClass('ITEM');
00097         $result = ITEM::createFromRequest();
00098 
00099         if ($result['status'] == 'error') {
00100                 bm_doError($result['message']);
00101         }
00102 
00103         $blogid = getBlogIDFromItemID($result['itemid']);
00104         $blog =& $manager->getBlog($blogid);
00105 
00106         if ($result['status'] == 'newcategory') {
00107                 $message = 'アイテムã¯è¿½åŠ ã•ã‚Œã€æ–°ã—ã„カテゴリーãŒä½œæˆã•ã‚Œã¾ã—ãŸã€‚ <a href="index.php?action=categoryedit&amp;blogid='.$blogid.'&amp;catid='.$result['catid'].'" onclick="if (event &amp;&amp; event.preventDefault) event.preventDefault(); window.open(this.href); return false;" title="Opens in new window">ã“ã“をクリックã—ã¦ã‚«ãƒ†ã‚´ãƒªãƒ¼ã®åå‰ã¨èª¬æ˜Žã‚’編集ã—ã¦ãã ã•ã„。</a>';
00108                 $extrahead = '';
00109         } elseif ( (postVar('actiontype') == 'addnow') && $blog->sendPing() ) {
00110                 $message = 'アイテムã®è¿½åŠ ã«æˆåŠŸã—ã¾ã—ãŸã€‚ç¾åœ¨weblogs.comã«pingã‚’é€ã£ã¦ã„ã¾ã™ã€‚ã—ã°ã‚‰ãã®é–“ãŠå¾…ã¡ãã ã•ã„...';
00111                 $pingUrl = $manager->addTicketToUrl($CONF['AdminURL'] . 'index.php?action=sendping&blogid=' . intval($blogid) );
00112                 $extrahead = '<meta http-equiv="refresh" content="1; url=' . htmlspecialchars($pingUrl) . '" />';
00113         } else {
00114                 $message = _ITEM_ADDED;
00115                 $extrahead = '';
00116         }
00117 
00118         bm_message(_ITEM_ADDED, _ITEM_ADDED, $message,$extrahead);
00119 }
00120 
00121 function bm_doEditItem() {
00122         global $member, $manager, $CONF;
00123 
00124         $itemid = intRequestVar('itemid');
00125         $catid = postVar('catid');
00126 
00127         // only allow if user is allowed to alter item
00128         if (!$member->canUpdateItem($itemid, $catid) ) {
00129                 bm_doError(_ERROR_DISALLOWED);
00130         }
00131 
00132         $body = postVar('body');
00133         $title = postVar('title');
00134         $more = postVar('more');
00135         $closed = intPostVar('closed');
00136         $actiontype = postVar('actiontype');
00137         $draftid = intPostVar('draftid');
00138 
00139         // redirect to admin area on delete (has delete confirmation)
00140         if ($actiontype == 'delete') {
00141                 redirect('index.php?action=itemdelete&itemid=' . $itemid);
00142                 exit;
00143         }
00144 
00145         // create new category if needed (only on edit/changedate)
00146         if (strstr($catid,'newcat') ) {
00147                 // get blogid
00148                 list($blogid) = sscanf($catid, "newcat-%d");
00149 
00150                 // create
00151                 $blog =& $manager->getBlog($blogid);
00152                 $catid = $blog->createNewCategory();
00153 
00154                 // show error when sth goes wrong
00155                 if (!$catid) {
00156                         bm_doError('Could not create new category');
00157                 }
00158         }
00159 
00160         // only edit action is allowed for bookmarklet edit
00161         switch ($actiontype) {
00162                 case 'changedate':
00163                         $publish = 1;
00164                         $wasdraft = 0;
00165                         $timestamp = mktime(postVar('hour'), postVar('minutes'), 0, postVar('month'), postVar('day'), postVar('year') );
00166                         break;
00167                 case 'edit':
00168                         $publish = 1;
00169                         $wasdraft = 0;
00170                         $timestamp = 0;
00171                         break;
00172                 default:
00173                         bm_doError('Something went wrong');
00174         }
00175 
00176         // update item for real
00177         ITEM::update($itemid, $catid, $title, $body, $more, $closed, $wasdraft, $publish, $timestamp);
00178 
00179         if ($draftid > 0) {
00180                 ITEM::delete($draftid);
00181         }
00182 
00183         // show success message
00184         if ($catid != intPostVar('catid') ) {
00185                 bm_message(_ITEM_UPDATED, _ITEM_UPDATED, 'アイテムã¯è¿½åŠ ã•ã‚Œã€æ–°ã—ã„カテゴリーãŒä½œæˆã•ã‚Œã¾ã—ãŸã€‚<a href="index.php?action=categoryedit&amp;blogid='.$blog->getID().'&amp;catid='.$catid.'" onclick="if (event &amp;&amp; event.preventDefault) event.preventDefault(); window.open(this.href); return false;" title="Opens in new window">ã“ã“をクリックã—ã¦ã‚«ãƒ†ã‚´ãƒªãƒ¼ã®åå‰ã¨èª¬æ˜Žã‚’編集ã—ã¦ãã ã•ã„。</a>', '');
00186         } else {
00187                 bm_message(_ITEM_UPDATED, _ITEM_UPDATED, _ITEM_UPDATED, '');
00188         }
00189 }
00190 
00191 function bm_loginAndPassThrough() {
00192 
00193         $blogid = intRequestVar('blogid');
00194         $log_text = requestVar('logtext');
00195         $log_link = requestVar('loglink');
00196         $log_linktitle = requestVar('loglinktitle');
00197 
00198         ?>
00199 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
00200         <html xmlns="http://www.w3.org/1999/xhtml">
00201         <head>
00202                 <meta http-equiv="Content-Type" content="text/html; charset=<?php echo _CHARSET ?>" />
00203                 <title>Nucleus</title>
00204                 <?php bm_style(); ?>
00205         </head>
00206         <body>
00207         <h1><?php echo _LOGIN_PLEASE ?></h1>
00208 
00209         <form method="post" action="bookmarklet.php">
00210         <p>
00211                 <input name="action" value="login" type="hidden" />
00212                 <input name="blogid" value="<?php echo htmlspecialchars($blogid); ?>" type="hidden" />
00213                 <input name="logtext" value="<?php echo htmlspecialchars($log_text); ?>" type="hidden" />
00214                 <input name="loglink" value="<?php echo htmlspecialchars($log_link); ?>" type="hidden" />
00215                 <input name="loglinktitle" value="<?php echo htmlspecialchars($log_linktitle); ?>" type="hidden" />
00216                 <?php echo _LOGINFORM_NAME ?>:
00217                 <br /><input name="login" />
00218                 <br /><?php echo _LOGINFORM_PWD ?>:
00219                 <br /><input name="password" type="password" />
00220                 <br /><br />
00221                 <br /><input type="submit" value="<?php echo _LOGIN ?>" />
00222         </p>
00223         </form>
00224         <p><a href="bookmarklet.php" onclick="window.close();"><?php echo _POPUP_CLOSE ?></a></p>
00225         </body>
00226         </html>
00227         <?php
00228 }
00229 
00230 function bm_doShowForm() {
00231         global $member;
00232 
00233         $blogid = intRequestVar('blogid');
00234         $log_text = trim(requestVar('logtext'));
00235         $log_link = requestVar('loglink');
00236         $log_linktitle = requestVar('loglinktitle');
00237 
00238         $log_text = uniDecode($log_text,_CHARSET);
00239         $log_linktitle = uniDecode($log_linktitle,_CHARSET);
00240         
00241         if (!BLOG::existsID($blogid) ) {
00242                 bm_doError(_ERROR_NOSUCHBLOG);
00243         }
00244 
00245         if (!$member->isTeamMember($blogid) ) {
00246                 bm_doError(_ERROR_NOTONTEAM);
00247         }
00248 
00249         $logje = '';
00250 
00251         if ($log_text) {
00252                 $logje .= '<blockquote><div>"' . htmlspecialchars($log_text) . '"</div></blockquote>' . "\n";
00253         }
00254 
00255         if (!$log_linktitle) {
00256                 $log_linktitle = $log_link;
00257         }
00258 
00259         if ($log_link) {
00260                 $logje .= '<a href="' . htmlspecialchars($log_link) . '">' . htmlspecialchars($log_linktitle) . '</a>';
00261         }
00262 
00263         $item['body'] = $logje;
00264         $item['title'] = htmlspecialchars($log_linktitle);
00265 
00266         $factory = new PAGEFACTORY($blogid);
00267         $factory->createAddForm('bookmarklet', $item);
00268 }
00269 
00270 function bm_doEditForm() {
00271         global $member, $manager;
00272 
00273         $itemid = intRequestVar('itemid');
00274 
00275         if (!$manager->existsItem($itemid, 0, 0) ) {
00276                 bm_doError(_ERROR_NOSUCHITEM);
00277         }
00278 
00279         if (!$member->canAlterItem($itemid) ) {
00280                 bm_doError(_ERROR_DISALLOWED);
00281         }
00282 
00283         $item =& $manager->getItem($itemid, 1, 1);
00284         $blog =& $manager->getBlog(getBlogIDFromItemID($itemid) );
00285 
00286         $manager->notify('PrepareItemForEdit', array('item' => &$item) );
00287 
00288         if ($blog->convertBreaks() ) {
00289                 $item['body'] = removeBreaks($item['body']);
00290                 $item['more'] = removeBreaks($item['more']);
00291         }
00292 
00293         $formfactory = new PAGEFACTORY($blog->getID() );
00294         $formfactory->createEditForm('bookmarklet', $item);
00295 }
00296 
00297 function bm_doError($msg) {
00298         bm_message(_ERROR, _ERRORMSG, $msg);
00299         die;
00300 }
00301 
00302 function bm_message($title, $head, $msg, $extrahead = '') {
00303         ?>
00304 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
00305         <html xmlns="http://www.w3.org/1999/xhtml">
00306         <head>
00307                 <meta http-equiv="Content-Type" content="text/html; charset=<?php echo _CHARSET ?>" />
00308                 <title><?php echo $title ?></title>
00309                 <?php bm_style(); ?>
00310                 <?php echo $extrahead; ?>
00311         </head>
00312         <body>
00313         <h1><?php echo $head; ?></h1>
00314         <p><?php echo $msg; ?></p>
00315         <p><a href="bookmarklet.php" onclick="window.close();"><?php echo _POPUP_CLOSE ?></a></p>
00316         </body>
00317         </html>
00318 
00319         <?php
00320 }
00321 
00322 function bm_style() {
00323         echo '<link rel="stylesheet" type="text/css" href="styles/bookmarklet.css" />';
00324         echo '<link rel="stylesheet" type="text/css" href="styles/addedit.css" />';
00325 }
00326 
00327 function bm_doContextMenuCode() {
00328         global $CONF;
00329         ?>
00330 <script type="text/javascript" defer="defer">
00331 doc = external.menuArguments.document;
00332 lt = escape(doc.selection.createRange().text);
00333 loglink = escape(external.menuArguments.location.href);
00334 loglinktitle = escape(doc.title);
00335 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');
00336 wingm.focus();
00337 </script>
00338         <?php
00339 }
00340 
00341 function uniDecode($str,$charcode){
00342   $text = preg_replace_callback("/%u[0-9A-Za-z]{4}/",toUtf8,$str);
00343   return mb_convert_encoding($text, $charcode, 'UTF-8');
00344 }
00345 function toUtf8($ar){
00346   foreach($ar as $val){
00347     $val = intval(substr($val,2),16);
00348     if($val < 0x7F){        // 0000-007F
00349         $c .= chr($val);
00350     }elseif($val < 0x800) { // 0080-0800
00351         $c .= chr(0xC0 | ($val / 64));
00352         $c .= chr(0x80 | ($val % 64));
00353     }else{                // 0800-FFFF
00354         $c .= chr(0xE0 | (($val / 64) / 64));
00355         $c .= chr(0x80 | (($val / 64) % 64));
00356         $c .= chr(0x80 | ($val % 64));
00357     }
00358   }
00359   return $c;
00360 }
00361 
00362 ?>



Generated on Wed Jun 25 17:25:58 2008 by  doxygen 1.5.5