sites.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. * Get an \ElggSite entity (default is current site)
  11. *
  12. * @param int $site_guid Optional. Site GUID.
  13. *
  14. * @return \ElggSite
  15. * @since 1.8.0
  16. */
  17. function elgg_get_site_entity($site_guid = 0) {
  18. global $CONFIG;
  19. $result = false;
  20. if ($site_guid == 0) {
  21. $site = $CONFIG->site;
  22. } else {
  23. $site = get_entity($site_guid);
  24. }
  25. if ($site instanceof \ElggSite) {
  26. $result = $site;
  27. }
  28. return $result;
  29. }
  30. /**
  31. * Return the site specific details of a site by a row.
  32. *
  33. * @param int $guid The site GUID
  34. *
  35. * @return mixed
  36. * @access private
  37. */
  38. function get_site_entity_as_row($guid) {
  39. global $CONFIG;
  40. $guid = (int)$guid;
  41. return get_data_row("SELECT * FROM {$CONFIG->dbprefix}sites_entity WHERE guid = $guid");
  42. }
  43. /**
  44. * Return the site via a url.
  45. *
  46. * @param string $url The URL of a site
  47. *
  48. * @return mixed
  49. */
  50. function get_site_by_url($url) {
  51. global $CONFIG;
  52. $url = sanitise_string($url);
  53. $row = get_data_row("SELECT * from {$CONFIG->dbprefix}sites_entity where url='$url'");
  54. if ($row) {
  55. return get_entity($row->guid);
  56. }
  57. return false;
  58. }
  59. /**
  60. * Unit tests for sites
  61. *
  62. * @param string $hook unit_test
  63. * @param string $type system
  64. * @param mixed $value Array of tests
  65. * @param mixed $params Params
  66. *
  67. * @return array
  68. * @access private
  69. */
  70. function _elgg_sites_test($hook, $type, $value, $params) {
  71. global $CONFIG;
  72. $value[] = "{$CONFIG->path}engine/tests/ElggSiteTest.php";
  73. return $value;
  74. }
  75. return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) {
  76. $hooks->registerHandler('unit_test', 'system', '_elgg_sites_test');
  77. };