1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Elgg sites |
4
|
|
|
* Functions to manage multiple or single sites in an Elgg install |
5
|
|
|
* |
6
|
|
|
* @package Elgg.Core |
7
|
|
|
* @subpackage DataModel.Site |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Get an \ElggSite entity (default is current site) |
12
|
|
|
* |
13
|
|
|
* @param int $site_guid Optional. Site GUID. |
14
|
|
|
* |
15
|
|
|
* @return \ElggSite |
16
|
|
|
* @since 1.8.0 |
17
|
|
|
*/ |
18
|
|
|
function elgg_get_site_entity($site_guid = 0) { |
19
|
|
|
global $CONFIG; |
20
|
|
|
|
21
|
|
|
$result = false; |
22
|
|
|
|
23
|
|
|
if ($site_guid == 0) { |
24
|
|
|
$site = $CONFIG->site; |
25
|
|
|
} else { |
26
|
|
|
$site = get_entity($site_guid); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
if ($site instanceof \ElggSite) { |
30
|
|
|
$result = $site; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
return $result; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Return the site specific details of a site by a row. |
38
|
|
|
* |
39
|
|
|
* @param int $guid The site GUID |
40
|
|
|
* |
41
|
|
|
* @return mixed |
42
|
|
|
* @access private |
43
|
|
|
*/ |
44
|
|
|
function get_site_entity_as_row($guid) { |
45
|
|
|
global $CONFIG; |
46
|
|
|
|
47
|
|
|
$guid = (int)$guid; |
48
|
|
|
return get_data_row("SELECT * FROM {$CONFIG->dbprefix}sites_entity WHERE guid = $guid"); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Return the site via a url. |
53
|
|
|
* |
54
|
|
|
* @param string $url The URL of a site |
55
|
|
|
* |
56
|
|
|
* @return mixed |
57
|
|
|
*/ |
58
|
|
View Code Duplication |
function get_site_by_url($url) { |
59
|
|
|
global $CONFIG; |
60
|
|
|
|
61
|
|
|
$url = sanitise_string($url); |
62
|
|
|
|
63
|
|
|
$row = get_data_row("SELECT * from {$CONFIG->dbprefix}sites_entity where url='$url'"); |
64
|
|
|
|
65
|
|
|
if ($row) { |
|
|
|
|
66
|
|
|
return get_entity($row->guid); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return false; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Unit tests for sites |
74
|
|
|
* |
75
|
|
|
* @param string $hook unit_test |
76
|
|
|
* @param string $type system |
77
|
|
|
* @param mixed $value Array of tests |
78
|
|
|
* @param mixed $params Params |
79
|
|
|
* |
80
|
|
|
* @return array |
81
|
|
|
* @access private |
82
|
|
|
*/ |
83
|
|
|
function _elgg_sites_test($hook, $type, $value, $params) { |
84
|
|
|
global $CONFIG; |
85
|
|
|
$value[] = "{$CONFIG->path}engine/tests/ElggSiteTest.php"; |
86
|
|
|
return $value; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) { |
90
|
|
|
$hooks->registerHandler('unit_test', 'system', '_elgg_sites_test'); |
91
|
|
|
}; |
92
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.