/** * Deletes one item and returns error if something goes wrong * @param int $itemid */ function deleteOneItem($itemid) { global $member, $manager; // only allow if user is allowed to alter item (also checks if itemid exists) if (!$member->canAlterItem($itemid)) { return _ERROR_DISALLOWED; } // need to get blogid before the item is deleted $blogid = getBlogIDFromItemId($itemid); $manager->loadClass('ITEM'); ITEM::delete($itemid); // update blog's futureposted $this->updateFuturePosted($blogid); }
/** * Tries to create an item from the data in the current request (comes from * bookmarklet or admin area * * Returns an array with status info: * status = 'added', 'error', 'newcategory' * * @static */ function createFromRequest() { global $member, $manager; $i_author = $member->getID(); $i_body = postVar('body'); $i_title = postVar('title'); $i_more = postVar('more'); $i_actiontype = postVar('actiontype'); $i_closed = intPostVar('closed'); $i_hour = intPostVar('hour'); $i_minutes = intPostVar('minutes'); $i_month = intPostVar('month'); $i_day = intPostVar('day'); $i_year = intPostVar('year'); $i_catid = postVar('catid'); $i_draftid = intPostVar('draftid'); if (!$member->canAddItem($i_catid)) { return array('status' => 'error', 'message' => _ERROR_DISALLOWED); } if (!$i_actiontype) { $i_actiontype = 'addnow'; } switch ($i_actiontype) { case 'adddraft': $i_draft = 1; break; case 'addfuture': case 'addnow': default: $i_draft = 0; } if (!trim($i_body)) { return array('status' => 'error', 'message' => _ERROR_NOEMPTYITEMS); } // create new category if needed if (strstr($i_catid, 'newcat')) { // get blogid list($i_blogid) = sscanf($i_catid, "newcat-%d"); // create $blog =& $manager->getBlog($i_blogid); $i_catid = $blog->createNewCategory(); // show error when sth goes wrong if (!$i_catid) { return array('status' => 'error', 'message' => 'Could not create new category'); } } else { // force blogid (must be same as category id) $i_blogid = getBlogIDFromCatID($i_catid); $blog =& $manager->getBlog($i_blogid); } if ($i_actiontype == 'addfuture') { $posttime = mktime($i_hour, $i_minutes, 0, $i_month, $i_day, $i_year); // make sure the date is in the future, unless we allow past dates if (!$blog->allowPastPosting() && $posttime < $blog->getCorrectTime()) { $posttime = $blog->getCorrectTime(); } } else { // time with offset, or 0 for drafts $posttime = $i_draft ? 0 : $blog->getCorrectTime(); } if ($posttime > $blog->getCorrectTime()) { $posted = 0; $blog->setFuturePost(); } else { $posted = 1; } $itemid = $blog->additem($i_catid, $i_title, $i_body, $i_more, $i_blogid, $i_author, $posttime, $i_closed, $i_draft, $posted); //Setting the itemOptions $aOptions = requestArray('plugoption'); NucleusPlugin::_applyPluginOptions($aOptions, $itemid); $manager->notify('PostPluginOptionsUpdate', array('context' => 'item', 'itemid' => $itemid, 'item' => array('title' => $i_title, 'body' => $i_body, 'more' => $i_more, 'closed' => $i_closed, 'catid' => $i_catid))); if ($i_draftid > 0) { // delete permission is checked inside ITEM::delete() ITEM::delete($i_draftid); } // success if ($i_catid != intRequestVar('catid')) { return array('status' => 'newcategory', 'itemid' => $itemid, 'catid' => $i_catid); } else { return array('status' => 'added', 'itemid' => $itemid); } }
/** * deletes an item */ function _deleteItem($itemid, $username, $password) { global $manager; // 1. login $mem = new MEMBER(); if (!$mem->login($username, $password)) { return _error(1, "Could not log in"); } // 2. check if allowed if (!$manager->existsItem($itemid, 1, 1)) { return _error(6, "No such item ({$itemid})"); } $blogid = getBlogIDFromItemID($itemid); if (!$mem->teamRights($blogid)) { return _error(3, "Not a team member"); } // delete the item ITEM::delete($itemid); return new xmlrpcresp(new xmlrpcval(1, "boolean")); }
function bm_doEditItem() { 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); } $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') { redirect('index.php?action=itemdelete&itemid=' . $itemid); exit; } // create new category if needed (only on edit/changedate) if (strstr($catid, 'newcat')) { // 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(_BOOKMARKLET_ERROR_COULDNTNEWCAT); } } // only edit action is allowed for bookmarklet edit switch ($actiontype) { case 'changedate': $publish = 1; $wasdraft = 0; $timestamp = mktime(intPostVar('hour'), intPostVar('minutes'), 0, intPostVar('month'), intPostVar('day'), intPostVar('year')); break; case 'edit': $publish = 1; $wasdraft = 0; $timestamp = 0; break; case 'backtodrafts': $publish = 0; $wasdraft = 0; $timestamp = 0; break; default: bm_doError(_BOOKMARKLET_ERROR_SOMETHINGWRONG); } // update item for real ITEM::update($itemid, $catid, $title, $body, $more, $closed, $wasdraft, $publish, $timestamp); if ($draftid > 0) { ITEM::delete($draftid); } // show success message if ($catid != intPostVar('catid')) { $href = 'index.php?action=categoryedit&blogid=' . $blog->getID() . '&catid=' . $catid; $onclick = 'if (event && 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>'; bm_message(_ITEM_UPDATED, _ITEM_UPDATED, _BOOKMARKLET_NEW_CATEGORY . $aTag . _BOOKMARKLET_NEW_CATEGORY_EDIT . '</a>', ''); } else { bm_message(_ITEM_UPDATED, _ITEM_UPDATED, _ITEM_UPDATED, ''); } }