<?php
namespace wcf\action;
use wcf\system\clipboard\ClipboardHandler;
-use wcf\system\exception\AJAXException;
+use wcf\system\exception\UserInputException;
use wcf\system\WCF;
use wcf\util\ArrayUtil;
use wcf\util\JSON;
* @subpackage action
* @category Community Framework
*/
-class ClipboardAction extends AbstractSecureAction {
+class ClipboardAction extends AJAXInvokeAction {
/**
* clipboard action
* @var string
*/
protected $objectTypeID = 0;
- /**
- * @see wcf\action\IAction::__run()
- */
- public function __run() {
- try {
- parent::__run();
- }
- catch (\Exception $e) {
- if ($e instanceof AJAXException) {
- throw $e;
- }
- else {
- throw new AJAXException($e->getMessage());
- }
- }
- }
-
/**
* @see wcf\action\Action::readParameters()
*/
public function readParameters() {
- parent::readParameters();
+ AbstractSecureAction::readParameters();
if (isset($_POST['action'])) $this->action = StringUtil::trim($_POST['action']);
if (isset($_POST['containerData']) && is_array($_POST['containerData'])) $this->containerData = $_POST['containerData'];
* @see wcf\action\Action::execute()
*/
public function execute() {
- parent::execute();
+ AbstractSecureAction::execute();
// execute clipboard action
$this->executeAction();
*/
protected function validate() {
if (empty($this->objectIDs)) {
- throw new AJAXException("Invalid object ids given.");
+ throw new UserInputException('objectIDs');
}
if (empty($this->pageClassName)) {
- throw new AJAXException("page not given");
+ throw new UserInputException('pageClassName');
}
if ($this->action != 'mark' && $this->action != 'unmark') {
- throw new AJAXException("Clipboard action '".$this->action."' is invalid.");
+ throw new UserInputException('action');
}
$this->objectTypeID = (!empty($this->type)) ? ClipboardHandler::getInstance()->getObjectTypeID($this->type) : null;
if ($this->objectTypeID === null) {
- throw new AJAXException("object type '".$this->type."' is invalid.");
+ throw new UserInputException('type');
}
}
}
return null;
}
+ /**
+ * Returns object type by object type name.
+ *
+ * @param string $objectType
+ * @return integer
+ */
+ public function getObjectTypeByName($objectType) {
+ foreach ($this->cache['objectTypes'] as $objectTypeID => $objectTypeObj) {
+ if ($objectTypeObj->objectType == $objectType) {
+ return $objectTypeID;
+ }
+ }
+
+ return null;
+ }
+
/**
* Loads a list of marked items grouped by type name.
*
$objectList->readObjects();
$this->markedItems[$objectType] = $objectList->getObjects();
+
+ // validate object ids against loaded items (check for zombie object ids)
+ $indexName = $objectList->getDatabaseTableIndexName();
+ foreach ($this->markedItems[$objectType] as $object) {
+ $index = array_search($object->$indexName, $objectData['objectIDs']);
+ unset($objectData['objectIDs'][$index]);
+ }
+
+ if (!empty($objectData['objectIDs'])) {
+ $conditions = new PreparedStatementConditionBuilder();
+ $conditions->add("objectTypeID = ?", array($this->getObjectTypeByName($objectType)));
+ $conditions->add("userID = ?", array(WCF::getUser()->userID));
+ $conditions->add("objectID IN (?)", array($objectData['objectIDs']));
+
+ $sql = "DELETE FROM wcf".WCF_N."_clipboard_item
+ ".$conditions;
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute($conditions->getParameters());
+ }
}
}
foreach ($actions as $actionData) {
// get accepted objects
$typeName = $actionData['object']->getTypeName();
- if (!isset($this->markedItems[$typeName])) continue;
+ if (!isset($this->markedItems[$typeName]) || empty($this->markedItems[$typeName])) continue;
$editorData[$typeName] = array(
'label' => $actionData['object']->getEditorLabel($this->markedItems[$typeName]),