/** Validates permission and sets a node to unpublished status * * @param mixed nodeid- integer or array of integers * **/ public function unPublish($nodes, $permanent = false) { if (!is_array($nodes)) { $nodes = array($nodes); } $approved = array(); foreach ($nodes as $nodeid) { if (vB::getUserContext()->getChannelPermission('moderatorpermissions', 'canmoderateposts', $nodeid, false) or vB::getUserContext()->getChannelPermission('forumpermissions2', 'canpublish', $nodeid)) { $approved[] = $nodeid; } } if ($permanent) { $publishdate = -1; } else { $publishdate = 0; } $approvedNodes = vB_Library::instance('node')->getNodes($approved); $parents = $starters = array(); $events = array(); foreach ($approvedNodes as $approvedNode) { if (empty($approvedNode['starter']) or !empty($starters[$approvedNode['starter']])) { continue; } $starters[$approvedNode['starter']] = 1; $events[] = "nodeChg_" . $approvedNode['starter']; } if (!empty($starters)) { $starterNodes = vB_Library::instance('node')->getNodes(array_keys($starters)); foreach ($starterNodes as $starterNode) { if (empty($starterNode['parentid']) or !empty($parents[$starterNode['parentid']])) { continue; } $parents[$starterNode['parentid']] = 1; $events[] = "nodeChg_" . $starterNode['parentid']; } } vB_Cache::instance()->allCacheEvent($events); foreach ($approved as $nodeid) { $this->library->setUnPublished($nodeid); } vB_Api::instance('Search')->purgeCacheForCurrentUser(); }