/** * Adds one or more attachments * * @param int * @param mixed array of attachment info * * @return int an attachid * **/ public function addAttachment($nodeid, $data) { /* data must include a filedataid, and possibly any combination of visible,counter,posthash,filename,caption, reportthreadid, settings */ if (empty($nodeid) or empty($data['filedataid'])) { throw new Exception('incorrect_attach_data'); } //we need the current node data. $node = $this->getNode($nodeid); if (empty($node)) { throw new Exception('incorrect_attach_data'); } $maxattachments = vB::getUserContext()->getChannelLimitPermission('forumpermissions', 'maxattachments', $nodeid); //check the permission. $canAdd = false; if ($node['userid'] == vB::getCurrentSession()->get('userid') and vB::getUserContext()->getChannelPermission('forumpermissions', 'canpostattachment', $nodeid)) { $canAdd = true; } if (!$canAdd and vB::getUserContext()->getChannelPermission('moderatorpermissions', 'canmoderateattachments', $nodeid)) { $canAdd = true; } if (!$canAdd) { throw new Exception('no_permission'); } if (isset($node['attachments']) and $maxattachments > 0 and count($node['attachments']) >= $maxattachments) { throw new Exception('max_attachments_reached'); } $attachApi = vB_Api::InstanceInternal('content_attach'); $data['parentid'] = $nodeid; $attachid = $attachApi->add($data); //updating the refcount in filedata happens in attach library's add() now. return is_array($attachid) ? $attachid[0] : $attachid; }