Esempio n. 1
0
 /**
  * Clone Nodes and their children deeply into a new parent Node.
  *
  * @param array $nodeids Source nodeIDs
  * @param string|int $to_parent Parent node id. If to_parent is a string, it should be a route path to the node
  * @param string $newtitle If parent is a channel, the oldest post will be promoted to a Thread with the new title.
  * @return mixed array of origional nodeids as keys, cloned nodeids as values
  */
 public function cloneNodes($nodeids, $to_parent, $newtitle = '')
 {
     $userContext = vB::getUserContext();
     if ($userContext->isModerator()) {
         $this->inlinemodAuthCheck();
     }
     $to_parent = $this->assertNodeidStr($to_parent);
     // check permissions
     // * if the user has the moderator permission 'canmassmove' on the source and target
     // nodes, they can do the move/copy.
     // * if this node belongs to the user and they have 'canmove' on the source node and
     // they have create permission on the target node, they can do the move/copy.
     $canMassMoveAtTarget = $userContext->getChannelPermission('moderatorpermissions', 'canmassmove', $to_parent);
     $createPermissionsAtTarget = $userContext->getCanCreate($to_parent);
     foreach ($nodeids as $nodeid) {
         if (!$canMassMoveAtTarget or !$userContext->getChannelPermission('moderatorpermissions', 'canmassmove', $nodeid)) {
             $node = $this->library->getNode($nodeid);
             $contentTypeClass = vB_Types::instance()->getContentTypeClasses($node['contenttypeid']);
             $contentTypeClass = strtolower($contentTypeClass[$node['contenttypeid']]);
             $canCreateAtTarget = !empty($createPermissionsAtTarget[$contentTypeClass]);
             if ($node['userid'] != vB::getCurrentSession()->get('userid') or !$canCreateAtTarget or !$userContext->getChannelPermission('forumpermissions', 'canmove', $nodeid)) {
                 throw new vB_Exception_Api('no_permission');
             }
         }
     }
     return $this->library->cloneNodes($nodeids, $to_parent, $newtitle);
 }