/** * @param string $pluginFile Extension plugin file to verify * @param string $key The child-key * @param int $groupid The id of the group you wish to retrieve * @param bool $for_manager * * @return array|bool An array of arrays, the inner-array contains the id/name/array of site ids for the supplied groupid/all groups. False when something goes wrong. */ public static function hookGetGroups($pluginFile, $key, $groupid, $for_manager = false) { if (!self::hookVerify($pluginFile, $key)) { return false; } if ($for_manager && (!defined('MWP_TEAMCONTROL_PLUGIN_SLUG') || !mainwp_current_user_can('extension', dirname(MWP_TEAMCONTROL_PLUGIN_SLUG)))) { return false; } if (isset($groupid)) { $group = MainWP_DB::Instance()->getGroupById($groupid); if (!MainWP_Utility::can_edit_group($group)) { return false; } $websites = MainWP_DB::Instance()->getWebsitesByGroupId($group->id); $websitesOut = array(); foreach ($websites as $website) { $websitesOut[] = $website->id; } return array(array('id' => $groupid, 'name' => $group->name, 'websites' => $websitesOut)); } $groups = MainWP_DB::Instance()->getGroupsAndCount(null, $for_manager); $output = array(); foreach ($groups as $group) { $websites = MainWP_DB::Instance()->getWebsitesByGroupId($group->id); $websitesOut = array(); foreach ($websites as $website) { if (in_array($website->id, $websitesOut)) { continue; } $websitesOut[] = $website->id; } $output[] = array('id' => $group->id, 'name' => $group->name, 'websites' => $websitesOut); } return $output; }
public static function updateGroup() { if (isset($_POST['groupId']) && MainWP_Utility::ctype_digit($_POST['groupId'])) { $group = MainWP_DB::Instance()->getGroupById($_POST['groupId']); if (MainWP_Utility::can_edit_group($group)) { MainWP_DB::Instance()->clearGroup($group->id); if (isset($_POST['websiteIds'])) { foreach ($_POST['websiteIds'] as $websiteId) { $website = MainWP_DB::Instance()->getWebsiteById($websiteId); if (MainWP_Utility::can_edit_website($website)) { MainWP_DB::Instance()->updateGroupSite($group->id, $website->id); } } } die(json_encode(array('result' => true))); } } die(json_encode(array('result' => false))); }