OSDN Git Service

Merge branch 'skinnable-master'
[nucleus-jp/nucleus-next.git] / nucleus / bookmarklet.php
index f9251dd..836b920 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
- * Copyright (C) 2002-2009 The Nucleus Group
+ * Copyright (C) 2002-2012 The Nucleus Group
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -14,7 +14,7 @@
  * in order to use this.
  *
  * @license http://nucleuscms.org/license.txt GNU General Public License
- * @copyright Copyright (C) 2002-2009 The Nucleus Group
+ * @copyright Copyright (C) 2002-2012 The Nucleus Group
  * @version $Id: bookmarklet.php 1624 2012-01-09 11:36:20Z sakamocchi $
  */
 
@@ -25,135 +25,179 @@ $CONF['UsingAdminArea'] = 1;
 // include all classes and config data
 include('../config.php');
 
-$action = requestVar('action');
-
-if ($action == 'contextmenucode') {
-       bm_doContextMenuCode();
-       exit;
+<<<<<<< HEAD
+=======
+// get skin object
+$skinid = $member->bookmarklet;
+if ( !Skin::existsID($skinid) )
+{
+       $skinid = $CONF['BookmarkletSkin'];
+       if ( !Skin::existsID($skinid) )
+       {
+               sendContentType('text/html');
+               echo _ERROR_SKIN;
+               exit;
+       }
 }
+$skin =& $manager->getSkin($skinid, 'AdminActions', 'AdminSkin');
 
-if (!$member->isLoggedIn() ) {
-       bm_loginAndPassThrough();
+>>>>>>> skinnable-master
+// check logged-in or pass through
+$action = requestVar('action');
+if ( !$member->isLoggedIn() )
+{
+<<<<<<< HEAD
+       bm_loginAndPassThrough($action);
+=======
+       bm_loginAndPassThrough($skin, $action);
+>>>>>>> skinnable-master
        exit;
 }
-
-// on successfull login
-if ( ($action == 'login') && ($member->isLoggedIn() ) ) {
+else if ( $action == 'login')
+{
        $action = requestVar('nextaction');
 }
 
-if ($action == '') {
+$action = strtolower($action);
+
+if ( $action == 'contextmenucode' )
+{
+       bm_doContextMenuCode();
+       exit;
+}
+else if ( $action == '' )
+{
        $action = 'add';
 }
 
+<<<<<<< HEAD
+// send HTTP 1.1 message header for Content-Type
 sendContentType('text/html', 'bookmarklet-' . $action);
 
+=======
+>>>>>>> skinnable-master
 // check ticket
-$action = strtolower($action);
 $aActionsNotToCheck = array('login', 'add', 'edit');
-
-if (!in_array($action, $aActionsNotToCheck) ) {
-
-       if (!$manager->checkTicket() ) {
-               bm_doError(_ERROR_BADTICKET);
+if ( !in_array($action, $aActionsNotToCheck) )
+{
+       if ( !$manager->checkTicket() )
+       {
+               bm_doError($skin, _ERROR_BADTICKET);
        }
-
 }
 
 // find out what to do
-switch ($action) {
+switch ( $action )
+{
        // adds the item for real
        case 'additem':
-               bm_doAddItem();
+               bm_doAddItem($skin);
                break;
-
+       
        // shows the edit item form
        case 'edit':
-               bm_doEditForm();
+               bm_doEditForm($skin);
                break;
-
+       
        // edits the item for real
        case 'edititem':
-               bm_doEditItem();
+               bm_doEditItem($skin);
                break;
-
+       
        // on login, 'action' gets changed to 'nextaction'
        case 'login':
-               bm_doError('Something went wrong');
+               bm_doError($skin, 'Something went wrong');
                break;
-
+       
        // shows the fill in form
        case 'add':
        default:
-               bm_doShowForm();
+               bm_doShowForm($skin);
                break;
 }
 
-function bm_doAddItem() {
+function bm_doAddItem($skin)
+{
        global $member, $manager, $CONF;
-
+       
        $manager->loadClass('ITEM');
-       $result = ITEM::createFromRequest();
-
-       if ($result['status'] == 'error') {
-               bm_doError($result['message']);
+       $result = Item::createFromRequest();
+       
+       if ( $result['status'] == 'error' )
+       {
+               bm_doError($skin, $result['message']);
        }
-
+       
        $blogid = getBlogIDFromItemID($result['itemid']);
        $blog =& $manager->getBlog($blogid);
-
-       if ($result['status'] == 'newcategory') {
+       
+       if ( $result['status'] == 'newcategory' )
+       {
                $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>';
                $extrahead = '';
-       } else {
+       }
+       else
+       {
                $message = _ITEM_ADDED;
                $extrahead = '';
        }
-
+       
+<<<<<<< HEAD
        bm_message(_ITEM_ADDED, _ITEM_ADDED, $message,$extrahead);
+=======
+       bm_message($skin, _ITEM_ADDED, $message,$extrahead);
+>>>>>>> skinnable-master
+       
+       return;
 }
 
-function bm_doEditItem() {
+function bm_doEditItem($skin)
+{
        global $member, $manager, $CONF;
-
+       
        $itemid = intRequestVar('itemid');
        $catid = postVar('catid');
-
+       
        // only allow if user is allowed to alter item
-       if (!$member->canUpdateItem($itemid, $catid) ) {
-               bm_doError(_ERROR_DISALLOWED);
+       if ( !$member->canUpdateItem($itemid, $catid) )
+       {
+               bm_doError($skin, _ERROR_DISALLOWED);
        }
-
+       
        $body = postVar('body');
        $title = postVar('title');
        $more = postVar('more');
        $closed = intPostVar('closed');
        $actiontype = postVar('actiontype');
        $draftid = intPostVar('draftid');
-
+       
        // redirect to admin area on delete (has delete confirmation)
-       if ($actiontype == 'delete') {
+       if ( $actiontype == 'delete' )
+       {
                redirect('index.php?action=itemdelete&itemid=' . $itemid);
                exit;
        }
-
+       
        // create new category if needed (only on edit/changedate)
-       if (strstr($catid,'newcat') ) {
+       if ( i18n::strpos($catid,'newcat') === 0 )
+       {
                // get blogid
                list($blogid) = sscanf($catid, "newcat-%d");
-
+               
                // create
                $blog =& $manager->getBlog($blogid);
                $catid = $blog->createNewCategory();
-
+               
                // show error when sth goes wrong
-               if (!$catid) {
-                       bm_doError('Could not create new category');
+               if ( !$catid )
+               {
+                       bm_doError($skin, 'Could not create new category');
                }
        }
-
+       
        // only edit action is allowed for bookmarklet edit
-       switch ($actiontype) {
+       switch ( $actiontype )
+       {
                case 'changedate':
                        $publish = 1;
                        $wasdraft = 0;
@@ -170,167 +214,295 @@ function bm_doEditItem() {
                        $timestamp = 0;
                        break;
                default:
-                       bm_doError('Something went wrong');
+                       bm_doError($skin, 'Something went wrong');
        }
-
+       
        // update item for real
-       ITEM::update($itemid, $catid, $title, $body, $more, $closed, $wasdraft, $publish, $timestamp);
-
-       if ($draftid > 0) {
-               ITEM::delete($draftid);
+       Item::update($itemid, $catid, $title, $body, $more, $closed, $wasdraft, $publish, $timestamp);
+       
+       if ( $draftid > 0 )
+       {
+               Item::delete($draftid);
        }
-
-       // show success message
-       if ($catid != intPostVar('catid') ) {
-               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>', '');
-       } else {
-               bm_message(_ITEM_UPDATED, _ITEM_UPDATED, _ITEM_UPDATED, '');
+       
+       if ( $result['status'] == 'newcategory' )
+       {
+               $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          = _BOOKMARKLET_NEW_WINDOW;
+               $aTag           = " <a href=\"{$href}\" onclick=\"{$onclick}\" title=\"{$title}\">";
+               $message        = _BOOKMARKLET_NEW_CATEGORY . $aTag . _BOOKMARKLET_NEW_CATEGORY_EDIT . '</a>';
        }
+       else
+       {
+               $message = _ITEM_ADDED;
+       }
+       
+<<<<<<< HEAD
+       return;
 }
 
-function bm_loginAndPassThrough() {
+function bm_loginAndPassThrough($action='add')
+=======
+       // show success message
+       bm_message($skin, _ITEM_ADDED, $message, '');
+       return;
+}
 
+function bm_loginAndPassThrough($skin, $action='add')
+>>>>>>> skinnable-master
+{
+       /*
+        * TODO: これを出力させる
        $blogid = intRequestVar('blogid');
+       $itemid = intRequestVar('itemid');
        $log_text = requestVar('logtext');
        $log_link = requestVar('loglink');
        $log_linktitle = requestVar('loglinktitle');
-
-       ?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-       <html xmlns="http://www.w3.org/1999/xhtml">
-       <head>
-               <title>Nucleus</title>
-               <?php bm_style(); ?>
-       </head>
-       <body>
-       <h1><?php echo _LOGIN_PLEASE ?></h1>
-
-       <form method="post" action="bookmarklet.php">
-       <p>
-               <input name="action" value="login" type="hidden" />
-               <input name="blogid" value="<?php echo i18n::hsc($blogid); ?>" type="hidden" />
-               <input name="logtext" value="<?php echo i18n::hsc($log_text); ?>" type="hidden" />
-               <input name="loglink" value="<?php echo i18n::hsc($log_link); ?>" type="hidden" />
-               <input name="loglinktitle" value="<?php echo i18n::hsc($log_linktitle); ?>" type="hidden" />
-               <?php echo _LOGINFORM_NAME ?>:
-               <br /><input name="login" />
-               <br /><?php echo _LOGINFORM_PWD ?>:
-               <br /><input name="password" type="password" />
-               <br /><br />
-               <br /><input type="submit" value="<?php echo _LOGIN ?>" />
-       </p>
-       </form>
-       <p><a href="bookmarklet.php" onclick="window.close();"><?php echo _POPUP_CLOSE ?></a></p>
-       </body>
-       </html>
-       <?php
+       
+<<<<<<< HEAD
+       echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
+       echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n";
+       echo "<head>\n";
+       echo "<title>Nucleus CMS Bookmarklet</title>\n";
+       
+       bm_style();
+       
+       echo "</head>\n";
+       echo "<body>\n";
+       echo '<h1>' . _LOGIN_PLEASE . "</h1>\n";
+       echo "<form method=\"post\" action=\"bookmarklet.php\">\n";
+       echo "<p>\n";
+       echo _LOGINFORM_NAME . "<input type=\"text\" name=\"login\" value=\"\" /><br />\n";
+       echo _LOGINFORM_PWD . "<input type=\"password\" name=\"password\" value=\"\" /><br />\n";
+=======
+>>>>>>> skinnable-master
+       echo '<input type="hidden" name="blogid" value="' . Entity::hsc($blogid). '" />' . "\n";
+       echo '<input type="hidden" name="itemid" value="' . Entity::hsc($itemid). '" />' . "\n";
+       echo '<input type="hidden" name="logtext" value="' . Entity::hsc($log_text) . '" />' . "\n";
+       echo '<input type="hidden" name="loglink" value="' . Entity::hsc($log_link) . '" />' . "\n";
+       echo '<input type="hidden" name="loglinktitle" value="' . Entity::hsc($log_linktitle) . '" />' . "\n";
+       echo "<input type=\"hidden\" name=\"nextaction\" value=\"{$action}\" />\n";
+<<<<<<< HEAD
+       echo '<button type="submit" name="action" value="login">' . _LOGIN . "</button>\n";
+       echo "</p>\n";
+       echo "</form>\n";
+       echo '<p><a href="bookmarklet.php" onclick="window.close();">' . _POPUP_CLOSE . "</a></p>\n";
+       echo "</body>\n";
+       echo "</html>\n";
+=======
+       */
+       
+       $skin->parse('showlogin');
+>>>>>>> skinnable-master
+       
+       return;
 }
 
-function bm_doShowForm() {
-       global $member;
-
-       $blogid = intRequestVar('blogid');
-       $log_text = trim(requestVar('logtext'));
-       $log_link = requestVar('loglink');
-       $log_linktitle = requestVar('loglinktitle');
-
-       if (!BLOG::existsID($blogid) ) {
-               bm_doError(_ERROR_NOSUCHBLOG);
+function bm_doShowForm($skin)
+{
+       global $manager, $member;
+       
+       $blogid                 = intRequestVar('blogid');
+       $log_text               = trim(requestVar('logtext'));
+       $log_link               = requestVar('loglink');
+       $log_linktitle  = requestVar('loglinktitle');
+       
+       if ( !Blog::existsID($blogid) )
+       {
+               bm_doError($skin, _ERROR_NOSUCHBLOG);
        }
-
-       if (!$member->isTeamMember($blogid) ) {
-               bm_doError(_ERROR_NOTONTEAM);
+<<<<<<< HEAD
+       else
+       {
+               $blog =& $manager->getBlog($blogid);
        }
-
+       
+       if ( !$member->isTeamMember($blogid) )
+=======
+       else if ( !$member->isTeamMember($blogid) )
+>>>>>>> skinnable-master
+       {
+               bm_doError($skin, _ERROR_NOTONTEAM);
+       }
+       
+       $blog =& $manager->getBlog($blogid);
+       
        $logje = '';
-
-       if ($log_text) {
-               $logje .= '<blockquote><div>"' . i18n::hsc($log_text) . '"</div></blockquote>' . "\n";
+       
+       if ( $log_text )
+       {
+               $logje .= '<blockquote><div>"' . Entity::hsc($log_text) . '"</div></blockquote>' . "\n";
        }
-
-       if (!$log_linktitle) {
+       
+       if ( !$log_linktitle )
+       {
                $log_linktitle = $log_link;
        }
-
-       if ($log_link) {
-               $logje .= '<a href="' . i18n::hsc($log_link) . '">' . i18n::hsc($log_linktitle) . '</a>';
+       
+       if ( $log_link )
+       {
+               $logje .= '<a href="' . Entity::hsc($log_link) . '">' . Entity::hsc($log_linktitle) . '</a>';
        }
-
+       
+<<<<<<< HEAD
+       $variables = array();
+       $variables['body'] = $logje;
+       $variables['title'] = Entity::hsc($log_linktitle);
+       
+       $handler = new PageFactory($blog);
+       $handler->setVariables($variables);
+       
+       $contents = $handler->getTemplateFor('bookmarklet', 'add');
+       $manager->notify('PreAddItemForm', array('contents' => &$contents, 'blog' => &$blog));
+       
+       $parser = new Parser($handler);
+       $parser->parse($contents);
+       
+=======
+       $item = array();
        $item['body'] = $logje;
-       $item['title'] = i18n::hsc($log_linktitle);
-
-       $factory = new PAGEFACTORY($blogid);
-       $factory->createAddForm('bookmarklet', $item);
+       $item['title'] = Entity::hsc($log_linktitle);
+       
+       $data = array(
+               'blog'          => &$blog,
+               'item'          => &$item,
+               'contents'      => &$item
+       );
+       $manager->notify('PreAddItemForm', $data);
+       
+       if ( $blog->convertBreaks() )
+       {
+               $item['body'] = removeBreaks($item['body']);
+       }
+       
+       Admin::$blog = &$blog;
+       Admin::$contents = &$item;
+       
+       Admin::$action = 'createitem';
+       $skin->parse('createitem');
+       
+>>>>>>> skinnable-master
+       return;
 }
 
-function bm_doEditForm() {
+function bm_doEditForm($skin)
+{
        global $member, $manager;
-
+       
        $itemid = intRequestVar('itemid');
-
-       if (!$manager->existsItem($itemid, 0, 0) ) {
-               bm_doError(_ERROR_NOSUCHITEM);
+       
+       if ( !$manager->existsItem($itemid, 0, 0) )
+       {
+               bm_doError($skin, _ERROR_NOSUCHITEM);
        }
-
-       if (!$member->canAlterItem($itemid) ) {
-               bm_doError(_ERROR_DISALLOWED);
+       else if ( !$member->canAlterItem($itemid) )
+       {
+               bm_doError($skin, _ERROR_DISALLOWED);
        }
-
-       $item =& $manager->getItem($itemid, 1, 1);
+       
+<<<<<<< HEAD
+       $variables =& $manager->getItem($itemid, 1, 1);
+=======
+>>>>>>> skinnable-master
        $blog =& $manager->getBlog(getBlogIDFromItemID($itemid) );
-
-       $manager->notify('PrepareItemForEdit', array('item' => &$item) );
-
-       if ($blog->convertBreaks() ) {
-               $item['body'] = removeBreaks($item['body']);
-               $item['more'] = removeBreaks($item['more']);
+       $item =& $manager->getItem($itemid, 1, 1);
+       
+<<<<<<< HEAD
+       $manager->notify('PrepareItemForEdit', array('item' => &$variables) );
+=======
+       $data = array(
+               'blog' => &$blog,
+               'item' => &$item
+       );
+       $manager->notify('PrepareItemForEdit', $data);
+>>>>>>> skinnable-master
+       
+       if ( $blog->convertBreaks() )
+       {
+               $variables['body'] = removeBreaks($variables['body']);
+               $variables['more'] = removeBreaks($variables['more']);
        }
-
-       $formfactory = new PAGEFACTORY($blog->getID() );
-       $formfactory->createEditForm('bookmarklet', $item);
+       
+<<<<<<< HEAD
+       $handler = new PageFactory($blog);
+       $handler->setVariables($variables);
+       
+       $contents = $handler->getTemplateFor('bookmarklet', 'edit');
+       
+       $parser = new Parser($handler);
+       $parser->parse($contents);
+       
+       return;
 }
-
-function bm_doError($msg) {
-       bm_message(_ERROR, _ERRORMSG, $msg);
+=======
+       Admin::$blog = &$blog;
+       Admin::$contents = &$item;
+       
+       Admin::$action = 'itemedit';
+       $skin->parse('itemedit');
+       
+       return;}
+>>>>>>> skinnable-master
+
+function bm_doError($skin, $msg)
+{
+       bm_message($skin, _ERRORMSG, $msg);
        die;
 }
 
-function bm_message($title, $head, $msg, $extrahead = '') {
-       ?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-       <html xmlns="http://www.w3.org/1999/xhtml">
-       <head>
-               <title><?php echo $title ?></title>
-               <?php bm_style(); ?>
-               <?php echo $extrahead; ?>
-       </head>
-       <body>
-       <h1><?php echo $head; ?></h1>
-       <p><?php echo $msg; ?></p>
-       <p><a href="bookmarklet.php" onclick="window.close();window.opener.location.reload();"><?php echo _POPUP_CLOSE ?></a></p>
-       </body>
-       </html>
-
-       <?php
+function bm_message($skin, $title, $msg, $extrahead = '')
+{
+<<<<<<< HEAD
+       echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
+       echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n";
+       echo "<head>\n";
+       echo "<title>{$title}</title>\n";
+       
+       bm_style();
+       
+       echo $extrahead . "\n";
+       echo "</head>\n";
+       echo "<body>\n";
+       echo "<h1>{$head}</h1>\n";
+       echo "<p>{$msg}</p>\n";
+       echo '<p><a href="bookmarklet.php" onclick="window.close();window.opener.location.reload();">' . _POPUP_CLOSE . "</a></p>\n";
+       echo "</body>\n";
+       echo "</html>\n";
+=======
+       Admin::$extrahead = $extrahead;
+       Admin::$headMess = $msg;
+       $skin->parse('adminerrorpage');
+>>>>>>> skinnable-master
+       
+       return;
 }
 
-function bm_style() {
-       echo '<link rel="stylesheet" type="text/css" href="styles/bookmarklet.css" />';
-       echo '<link rel="stylesheet" type="text/css" href="styles/addedit.css" />';
+function bm_doContextMenuCode($width=600, $height=500)
+{
+<<<<<<< HEAD
+       echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"styles/bookmarklet.css\" />\n";
+       echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"styles/addedit.css\" />\n";
+       return;
 }
 
-function bm_doContextMenuCode() {
+function bm_doContextMenuCode($width=600, $height=500)
+{
        global $CONF;
-       ?>
-<script type="text/javascript" defer="defer">
-doc = external.menuArguments.document;
-lt = escape(doc.selection.createRange().text);
-loglink = escape(external.menuArguments.location.href);
-loglinktitle = escape(doc.title);
-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');
-wingm.focus();
-</script>
-       <?php
-}
-
-?>
+       
+=======
+       global $CONF;   
+>>>>>>> skinnable-master
+       $blogid = (integer) intGetVar('blogid');
+       
+       echo "<script type=\"text/javascript\" defer=\"defer\">\n";
+       echo "<![CDATA[\n";
+       echo " doc = external.menuArguments.document;\n";
+       echo " lt = encodeURIComponent(doc.selection.createRange().text);\n";
+       echo " loglink = encodeURIComponent(external.menuArguments.location.href);\n";
+       echo " loglinktitle = encodeURIComponent(doc.title);\n";
+       echo " wingm = window.open('{$CONF['AdminURL']}bookmarklet.php?blogid={$blogid}&logtext=' + lt + '&loglink=' + loglink + '&loglinktitle=' + loglinktitle, 'nucleusbm', 'scrollbars=yes,width={$width},height={$height},left=10,top=10,status=yes,resizable=yes')\n";
+       echo " wingm.focus()\n";
+       echo "]]>\n";
+       echo "</script>\n";
+}
\ No newline at end of file