[ Index ]

PHP Cross Reference of Nucleus CMS 3.32

title

Body

[close]

/nucleus/ -> bookmarklet.php (source)

   1  <?php
   2  /*
   3   * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
   4   * Copyright (C) 2002-2007 The Nucleus Group
   5   *
   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)
  11   */
  12  /**
  13   * This script allows adding items to Nucleus through bookmarklets. The member must be logged in
  14   * in order to use this.
  15   *
  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 1130 2007-03-13 14:42:38Z ehui $
  19   */
  20  
  21  // bookmarklet is part of admin area (might need XML-RPC)
  22  $CONF = array();
  23  $CONF['UsingAdminArea'] = 1;
  24  
  25  // include all classes and config data
  26  include ('../config.php');
  27  
  28  $action = requestVar('action');
  29  
  30  if ($action == 'contextmenucode') {
  31      bm_doContextMenuCode();
  32      exit;
  33  }
  34  
  35  if (!$member->isLoggedIn() ) {
  36      bm_loginAndPassThrough();
  37      exit;
  38  }
  39  
  40  // on successfull login
  41  if ( ($action == 'login') && ($member->isLoggedIn() ) ) {
  42      $action = requestVar('nextaction');
  43  }
  44  
  45  if ($action == '') {
  46      $action = 'add';
  47  }
  48  
  49  sendContentType('application/xhtml+xml', 'bookmarklet-' . $action);
  50  
  51  // check ticket
  52  $action = strtolower($action);
  53  $aActionsNotToCheck = array('login', 'add', 'edit');
  54  
  55  if (!in_array($action, $aActionsNotToCheck) ) {
  56  
  57      if (!$manager->checkTicket() ) {
  58          bm_doError(_ERROR_BADTICKET);
  59      }
  60  
  61  }
  62  
  63  // find out what to do
  64  switch ($action) {
  65      // adds the item for real
  66      case 'additem':
  67          bm_doAddItem();
  68          break;
  69  
  70      // shows the edit item form
  71      case 'edit':
  72          bm_doEditForm();
  73          break;
  74  
  75      // edits the item for real
  76      case 'edititem':
  77          bm_doEditItem();
  78          break;
  79  
  80      // on login, 'action' gets changed to 'nextaction'
  81      case 'login':
  82          bm_doError('Something went wrong');
  83          break;
  84  
  85      // shows the fill in form
  86      case 'add':
  87      default:
  88          bm_doShowForm();
  89          break;
  90  }
  91  
  92  function bm_doAddItem() {
  93      global $member, $manager, $CONF;
  94  
  95      $manager->loadClass('ITEM');
  96      $result = ITEM::createFromRequest();
  97  
  98      if ($result['status'] == 'error') {
  99          bm_doError($result['message']);
 100      }
 101  
 102      $blogid = getBlogIDFromItemID($result['itemid']);
 103      $blog =& $manager->getBlog($blogid);
 104  
 105      if ($result['status'] == 'newcategory') {
 106          $message = 'Item was added, and a new category was created. <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">Click here to edit the name and description of the category.</a>';
 107          $extrahead = '';
 108      } elseif ( (postVar('actiontype') == 'addnow') && $blog->sendPing() ) {
 109          $message = 'Item was added successfully. Now pinging weblogs.com. Please hold on... (can take a while)';
 110          $pingUrl = $manager->addTicketToUrl($CONF['AdminURL'] . 'index.php?action=sendping&blogid=' . intval($blogid) );
 111          $extrahead = '<meta http-equiv="refresh" content="1; url=' . htmlspecialchars($pingUrl) . '" />';
 112      } else {
 113          $message = _ITEM_ADDED;
 114          $extrahead = '';
 115      }
 116  
 117      bm_message(_ITEM_ADDED, _ITEM_ADDED, $message,$extrahead);
 118  }
 119  
 120  function bm_doEditItem() {
 121      global $member, $manager, $CONF;
 122  
 123      $itemid = intRequestVar('itemid');
 124      $catid = postVar('catid');
 125  
 126      // only allow if user is allowed to alter item
 127      if (!$member->canUpdateItem($itemid, $catid) ) {
 128          bm_doError(_ERROR_DISALLOWED);
 129      }
 130  
 131      $body = postVar('body');
 132      $title = postVar('title');
 133      $more = postVar('more');
 134      $closed = intPostVar('closed');
 135      $actiontype = postVar('actiontype');
 136      $draftid = intPostVar('draftid');
 137  
 138      // redirect to admin area on delete (has delete confirmation)
 139      if ($actiontype == 'delete') {
 140          redirect('index.php?action=itemdelete&itemid=' . $itemid);
 141          exit;
 142      }
 143  
 144      // create new category if needed (only on edit/changedate)
 145      if (strstr($catid,'newcat') ) {
 146          // get blogid
 147          list($blogid) = sscanf($catid, "newcat-%d");
 148  
 149          // create
 150          $blog =& $manager->getBlog($blogid);
 151          $catid = $blog->createNewCategory();
 152  
 153          // show error when sth goes wrong
 154          if (!$catid) {
 155              bm_doError('Could not create new category');
 156          }
 157      }
 158  
 159      // only edit action is allowed for bookmarklet edit
 160      switch ($actiontype) {
 161          case 'changedate':
 162              $publish = 1;
 163              $wasdraft = 0;
 164              $timestamp = mktime(postVar('hour'), postVar('minutes'), 0, postVar('month'), postVar('day'), postVar('year') );
 165              break;
 166          case 'edit':
 167              $publish = 1;
 168              $wasdraft = 0;
 169              $timestamp = 0;
 170              break;
 171          default:
 172              bm_doError('Something went wrong');
 173      }
 174  
 175      // update item for real
 176      ITEM::update($itemid, $catid, $title, $body, $more, $closed, $wasdraft, $publish, $timestamp);
 177  
 178      if ($draftid > 0) {
 179          ITEM::delete($draftid);
 180      }
 181  
 182      // show success message
 183      if ($catid != intPostVar('catid') ) {
 184          bm_message(_ITEM_UPDATED, _ITEM_UPDATED, 'Item was added, and a new category was created. <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">Click here to edit the name and description of the category.</a>', '');
 185      } else {
 186          bm_message(_ITEM_UPDATED, _ITEM_UPDATED, _ITEM_UPDATED, '');
 187      }
 188  }
 189  
 190  function bm_loginAndPassThrough() {
 191  
 192      $blogid = intRequestVar('blogid');
 193      $log_text = requestVar('logtext');
 194      $log_link = requestVar('loglink');
 195      $log_linktitle = requestVar('loglinktitle');
 196  
 197      ?>
 198  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 199      <html xmlns="http://www.w3.org/1999/xhtml">
 200      <head>
 201          <title>Nucleus</title>
 202          <?php bm_style(); ?>
 203      </head>
 204      <body>
 205      <h1><?php echo _LOGIN_PLEASE ?></h1>
 206  
 207      <form method="post" action="bookmarklet.php">
 208      <p>
 209          <input name="action" value="login" type="hidden" />
 210          <input name="blogid" value="<?php echo htmlspecialchars($blogid); ?>" type="hidden" />
 211          <input name="logtext" value="<?php echo htmlspecialchars($log_text); ?>" type="hidden" />
 212          <input name="loglink" value="<?php echo htmlspecialchars($log_link); ?>" type="hidden" />
 213          <input name="loglinktitle" value="<?php echo htmlspecialchars($log_linktitle); ?>" type="hidden" />
 214          <?php echo _LOGINFORM_NAME ?>:
 215          <br /><input name="login" />
 216          <br /><?php echo _LOGINFORM_PWD ?>:
 217          <br /><input name="password" type="password" />
 218          <br /><br />
 219          <br /><input type="submit" value="<?php echo _LOGIN ?>" />
 220      </p>
 221      </form>
 222      <p><a href="bookmarklet.php" onclick="window.close();"><?php echo _POPUP_CLOSE ?></a></p>
 223      </body>
 224      </html>
 225      <?php
 226  }
 227  
 228  function bm_doShowForm() {
 229      global $member;
 230  
 231      $blogid = intRequestVar('blogid');
 232      $log_text = trim(requestVar('logtext'));
 233      $log_link = requestVar('loglink');
 234      $log_linktitle = requestVar('loglinktitle');
 235  
 236      if (!BLOG::existsID($blogid) ) {
 237          bm_doError(_ERROR_NOSUCHBLOG);
 238      }
 239  
 240      if (!$member->isTeamMember($blogid) ) {
 241          bm_doError(_ERROR_NOTONTEAM);
 242      }
 243  
 244      $logje = '';
 245  
 246      if ($log_text) {
 247          $logje .= '<blockquote><div>"' . htmlspecialchars($log_text) . '"</div></blockquote>' . "\n";
 248      }
 249  
 250      if (!$log_linktitle) {
 251          $log_linktitle = $log_link;
 252      }
 253  
 254      if ($log_link) {
 255          $logje .= '<a href="' . htmlspecialchars($log_link) . '">' . htmlspecialchars($log_linktitle) . '</a>';
 256      }
 257  
 258      $item['body'] = $logje;
 259      $item['title'] = htmlspecialchars($log_linktitle);
 260  
 261      $factory = new PAGEFACTORY($blogid);
 262      $factory->createAddForm('bookmarklet', $item);
 263  }
 264  
 265  function bm_doEditForm() {
 266      global $member, $manager;
 267  
 268      $itemid = intRequestVar('itemid');
 269  
 270      if (!$manager->existsItem($itemid, 0, 0) ) {
 271          bm_doError(_ERROR_NOSUCHITEM);
 272      }
 273  
 274      if (!$member->canAlterItem($itemid) ) {
 275          bm_doError(_ERROR_DISALLOWED);
 276      }
 277  
 278      $item =& $manager->getItem($itemid, 1, 1);
 279      $blog =& $manager->getBlog(getBlogIDFromItemID($itemid) );
 280  
 281      $manager->notify('PrepareItemForEdit', array('item' => &$item) );
 282  
 283      if ($blog->convertBreaks() ) {
 284          $item['body'] = removeBreaks($item['body']);
 285          $item['more'] = removeBreaks($item['more']);
 286      }
 287  
 288      $formfactory = new PAGEFACTORY($blog->getID() );
 289      $formfactory->createEditForm('bookmarklet', $item);
 290  }
 291  
 292  function bm_doError($msg) {
 293      bm_message(_ERROR, _ERRORMSG, $msg);
 294      die;
 295  }
 296  
 297  function bm_message($title, $head, $msg, $extrahead = '') {
 298      ?>
 299  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 300      <html xmlns="http://www.w3.org/1999/xhtml">
 301      <head>
 302          <title><?php echo $title ?></title>
 303          <?php bm_style(); ?>
 304          <?php echo $extrahead; ?>
 305      </head>
 306      <body>
 307      <h1><?php echo $head; ?></h1>
 308      <p><?php echo $msg; ?></p>
 309      <p><a href="bookmarklet.php" onclick="window.close();"><?php echo _POPUP_CLOSE ?></a></p>
 310      </body>
 311      </html>
 312  
 313      <?php
 314  }
 315  
 316  function bm_style() {
 317      echo '<link rel="stylesheet" type="text/css" href="styles/bookmarklet.css" />';
 318      echo '<link rel="stylesheet" type="text/css" href="styles/addedit.css" />';
 319  }
 320  
 321  function bm_doContextMenuCode() {
 322      global $CONF;
 323      ?>
 324  <script type="text/javascript" defer="defer">
 325  doc = external.menuArguments.document;
 326  lt = escape(doc.selection.createRange().text);
 327  loglink = escape(external.menuArguments.location.href);
 328  loglinktitle = escape(doc.title);
 329  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');
 330  wingm.focus();
 331  </script>
 332      <?php
 333  }
 334  
 335  ?>


Generated: Tue Feb 12 15:34:36 2008 Cross-referenced by PHPXref 0.7