function subsite_manager_siteid_hook($hook, $type, $return, $params) { global $SUBSITE_MANAGER_CUSTOM_DOMAIN; $result = false; elgg_register_classes(dirname(__FILE__) . "/classes/"); if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "") { $protocol = "https"; } else { $protocol = "http"; } if (strpos($_SERVER["HTTP_HOST"], "www.") === 0) { $alt_host = str_replace("www.", "", $_SERVER["HTTP_HOST"]); } else { $alt_host = "www." . $_SERVER["HTTP_HOST"]; } $url = $protocol . "://" . $_SERVER["HTTP_HOST"] . "/"; $alt_url = $protocol . "://" . $alt_host . "/"; if ($site = get_site_by_url($url)) { $result = $site->getGUID(); } elseif ($site = get_site_by_url($alt_url)) { $result = $site->getGUID(); } else { // no site found, forward to main site $default_site_guid = (int) datalist_get("default_site"); $default_site = get_entity($default_site_guid); forward($default_site->url); } return $result; }
/** * Create a new \ElggSite. * * Plugin developers should only use the constructor to create a new entity. * To retrieve entities, use get_entity() and the elgg_get_entities* functions. * * @param \stdClass $row Database row result. Default is null to create a new site. * * @throws IOException If cannot load remaining data from db * @throws InvalidParameterException If not passed a db result */ public function __construct($row = null) { $this->initializeAttributes(); if (!empty($row)) { // Is $row is a DB entity table row if ($row instanceof \stdClass) { // Load the rest if (!$this->load($row)) { $msg = "Failed to load new " . get_class() . " for GUID:" . $row->guid; throw new \IOException($msg); } } else { if (strpos($row, "http") !== false) { // url so retrieve by url elgg_deprecated_notice("Passing URL to constructor is deprecated. Use get_site_by_url()", 1.9); $row = get_site_by_url($row); foreach ($row->attributes as $key => $value) { $this->attributes[$key] = $value; } } else { if (is_numeric($row)) { // $row is a GUID so load elgg_deprecated_notice('Passing a GUID to constructor is deprecated. Use get_entity()', 1.9); if (!$this->load($row)) { throw new \IOException("Failed to load new " . get_class() . " from GUID:" . $row); } } else { throw new \InvalidParameterException("Unrecognized value passed to constuctor."); } } } } }
/** * Create a new ElggSite. * * Plugin developers should only use the constructor to create a new entity. * To retrieve entities, use get_entity() and the elgg_get_entities* functions. * * @param stdClass $row Database row result. Default is null to create a new site. * * @throws IOException If cannot load remaining data from db * @throws InvalidParameterException If not passed a db result */ public function __construct($row = null) { $this->initializeAttributes(); // compatibility for 1.7 api. $this->initialise_attributes(false); if (!empty($row)) { // Is $row is a DB entity table row if ($row instanceof stdClass) { // Load the rest if (!$this->load($row)) { $msg = "Failed to load new " . get_class() . " for GUID:" . $row->guid; throw new IOException($msg); } } else { if ($row instanceof ElggSite) { // $row is an ElggSite so this is a copy constructor elgg_deprecated_notice('This type of usage of the ElggSite constructor was deprecated. Please use the clone method.', 1.7); foreach ($row->attributes as $key => $value) { $this->attributes[$key] = $value; } } else { if (strpos($row, "http") !== false) { // url so retrieve by url elgg_deprecated_notice("Passing URL to constructor is deprecated. Use get_site_by_url()", 1.9); $row = get_site_by_url($row); foreach ($row->attributes as $key => $value) { $this->attributes[$key] = $value; } } else { if (is_numeric($row)) { // $row is a GUID so load elgg_deprecated_notice('Passing a GUID to constructor is deprecated. Use get_entity()', 1.9); if (!$this->load($row)) { throw new IOException("Failed to load new " . get_class() . " from GUID:" . $row); } } else { throw new InvalidParameterException("Unrecognized value passed to constuctor."); } } } } } }
/** * Construct a new site object, optionally from a given id value. * * @param mixed $guid If an int, load that GUID. * If a db row then will attempt to load the rest of the data. * @throws Exception if there was a problem creating the site. */ function __construct($guid = null) { $this->initialise_attributes(); if (!empty($guid)) { // Is $guid is a DB row - either a entity row, or a site table row. if ($guid instanceof stdClass) { // Load the rest if (!$this->load($guid->guid)) { throw new IOException(sprintf(elgg_echo('IOException:FailedToLoadGUID'), get_class(), $guid->guid)); } } else { if ($guid instanceof ElggSite) { elgg_deprecated_notice('This type of usage of the ElggSite constructor was deprecated. Please use the clone method.', 1.7); foreach ($guid->attributes as $key => $value) { $this->attributes[$key] = $value; } } else { if ($guid instanceof ElggEntity) { throw new InvalidParameterException(elgg_echo('InvalidParameterException:NonElggSite')); } else { if (strpos($guid, "http") !== false) { $guid = get_site_by_url($guid); foreach ($guid->attributes as $key => $value) { $this->attributes[$key] = $value; } } else { if (is_numeric($guid)) { if (!$this->load($guid)) { throw new IOException(sprintf(elgg_echo('IOException:FailedToLoadGUID'), get_class(), $guid)); } } else { throw new InvalidParameterException(elgg_echo('InvalidParameterException:UnrecognisedValue')); } } } } } } }
/** * Load or create a new ElggSite. * * If no arguments are passed, create a new entity. * * If an argument is passed attempt to load a full Site entity. Arguments * can be: * - The GUID of a site entity. * - A URL as stored in ElggSite->url * - A DB result object with a guid property * * @param mixed $guid If an int, load that GUID. If a db row then will attempt * to load the rest of the data. * * @throws IOException If passed an incorrect guid * @throws InvalidParameterException If passed an Elgg* Entity that isn't an ElggSite */ function __construct($guid = null) { $this->initializeAttributes(); // compatibility for 1.7 api. $this->initialise_attributes(false); if (!empty($guid)) { // Is $guid is a DB row - either a entity row, or a site table row. if ($guid instanceof stdClass) { // Load the rest if (!$this->load($guid->guid)) { $msg = elgg_echo('IOException:FailedToLoadGUID', array(get_class(), $guid->guid)); throw new IOException($msg); } // Is $guid is an ElggSite? Use a copy constructor } else { if ($guid instanceof ElggSite) { elgg_deprecated_notice('This type of usage of the ElggSite constructor was deprecated. Please use the clone method.', 1.7); foreach ($guid->attributes as $key => $value) { $this->attributes[$key] = $value; } // Is this is an ElggEntity but not an ElggSite = ERROR! } else { if ($guid instanceof ElggEntity) { throw new InvalidParameterException(elgg_echo('InvalidParameterException:NonElggSite')); // See if this is a URL } else { if (strpos($guid, "http") !== false) { $guid = get_site_by_url($guid); foreach ($guid->attributes as $key => $value) { $this->attributes[$key] = $value; } // We assume if we have got this far, $guid is an int } else { if (is_numeric($guid)) { if (!$this->load($guid)) { throw new IOException(elgg_echo('IOException:FailedToLoadGUID', array(get_class(), $guid))); } } else { throw new InvalidParameterException(elgg_echo('InvalidParameterException:UnrecognisedValue')); } } } } } } }
// get input $name = get_input("name"); $description = get_input("description"); $url = rtrim(get_input("url", "", false), "/") . "/"; $category = get_input("category"); $membership = get_input("membership"); $visibility = get_input("visibility"); $domains = get_input("domains"); $has_public_acl = get_input("has_public_acl"); $admin = get_input("admin"); if (!empty($name) && !empty($url) && !empty($membership) && !empty($has_public_acl)) { $valid = true; if (!(stristr($url, "http://") || stristr($url, "https://")) || substr($url, -1) != "/") { $valid = false; register_error(elgg_echo("subsite_manager:action:subsites:new:error:validate:url:invalid")); } elseif (get_site_by_url($url)) { $valid = false; register_error(elgg_echo("subsite_manager:action:subsites:new:error:validate:url:duplicate")); } if ($valid) { $url = strtolower($url); $site = new Subsite(); $site->name = $name; $site->description = $description; $site->url = $url; if (!($guid = $site->save())) { register_error(elgg_echo("IOException:UnableToSaveNew", array(get_class($site)))); $site = null; } else { $site = get_entity($guid); $site->createACL();
/** * Load or create a new ElggSite. * * If no arguments are passed, create a new entity. * * If an argument is passed attempt to load a full Site entity. Arguments * can be: * - The GUID of a site entity. * - A URL as stored in ElggSite->url * - A DB result object with a guid property * * @param mixed $guid If an int, load that GUID. If a db row then will * load the rest of the data. * * @throws IOException If passed an incorrect guid * @throws InvalidParameterException If passed an Elgg* Entity that isn't an ElggSite */ function __construct($guid = null) { $this->initializeAttributes(); // compatibility for 1.7 api. $this->initialise_attributes(false); if (!empty($guid)) { // Is $guid is a DB entity table row if ($guid instanceof stdClass) { // Load the rest if (!$this->load($guid)) { $msg = elgg_echo('IOException:FailedToLoadGUID', array(get_class(), $guid->guid)); throw new IOException($msg); } } else { if ($guid instanceof ElggSite) { // $guid is an ElggSite so this is a copy constructor elgg_deprecated_notice('This type of usage of the ElggSite constructor was deprecated. Please use the clone method.', 1.7); foreach ($guid->attributes as $key => $value) { $this->attributes[$key] = $value; } } else { if ($guid instanceof ElggEntity) { // @todo remove and just use else clause throw new InvalidParameterException(elgg_echo('InvalidParameterException:NonElggSite')); } else { if (strpos($guid, "http") !== false) { // url so retrieve by url $guid = get_site_by_url($guid); foreach ($guid->attributes as $key => $value) { $this->attributes[$key] = $value; } } else { if (is_numeric($guid)) { // $guid is a GUID so load if (!$this->load($guid)) { throw new IOException(elgg_echo('IOException:FailedToLoadGUID', array(get_class(), $guid))); } } else { throw new InvalidParameterException(elgg_echo('InvalidParameterException:UnrecognisedValue')); } } } } } } }
$digischool_urls = array("https://groep1en2.pleio.nl/", "https://groep3en4.pleio.nl/", "https://groep5en6.pleio.nl/", "https://groep7en8.pleio.nl/", "https://interbegeleiders.pleio.nl/", "https://pabo.pleio.nl/", "https://rekenen.pleio.nl/", "https://taal.pleio.nl/", "https://voorschool.pleio.nl/", "https://aardrijkskunde.pleio.nl/", "https://arabisch.pleio.nl/", "https://beeldonderwijs.pleio.nl/", "https://biologie.pleio.nl/", "https://ckv.pleio.nl/", "https://drama.pleio.nl/", "https://duits.pleio.nl/", "https://economie.pleio.nl/", "https://engels.pleio.nl/", "https://filosofie.pleio.nl/", "https://frans.pleio.nl/", "https://geschiedenis.pleio.nl/", "https://grafimedia.pleio.nl/", "https://informatica.pleio.nl/", "https://levensbeschouwing.pleio.nl/", "https://klassieketalen.pleio.nl/", "https://ckv2kua.pleio.nl/", "https://lichamelijkeopvoeding.pleio.nl/", "https://maatschappijleer.pleio.nl/", "https://natuurlevenentechnologie.pleio.nl/", "https://muziek.pleio.nl/", "https://natuurkunde.pleio.nl/", "https://nederlands.pleio.nl/", "https://praktijkonderwijs.pleio.nl/", "https://scheikunde.pleio.nl/", "https://spaans.pleio.nl/", "https://systeembeheer.pleio.nl/", "https://techniekvo.pleio.nl/", "https://turks.pleio.nl/", "https://tweetaligonderwijs.pleio.nl/", "https://verzorging.pleio.nl/", "https://wiskunde.pleio.nl/", "https://digitaalleermateriaal.pleio.nl/", "https://professionalisering.pleio.nl/"); $digischool_admin_usernames = array("Luyben"); $count = 0; $digischool_admins = array(); echo "matching usernames to users<br />"; foreach ($digischool_admin_usernames as $username) { if ($user = get_user_by_username($username)) { $digischool_admins[] = $user; } else { echo "couldn't find " . $username . "<br />"; } } echo "proccessing site urls<br />"; foreach ($digischool_urls as $site_url) { echo "searching for " . $site_url . "<br />"; if ($subsite = get_site_by_url($site_url)) { echo "found " . $site->name . "<br />"; if (!empty($digischool_admins)) { echo "adding admins<br />"; foreach ($digischool_admins as $admin) { if (!$subsite->isUser($admin->getGUID())) { echo "adding user to site " . $admin->name . "<br />"; $subsite->addUser($admin->getGUID()); } if (!$subsite->isAdmin($admin->getGUID())) { echo "adding user as admin " . $admin->name . "<br />"; $subsite->makeAdmin($admin->getGUID()); } } echo "done with admins<br />"; }