Elgg  Version 1.11
elgglib.php
Go to the documentation of this file.
1 <?php
21 function elgg_register_library($name, $location) {
22  $config = _elgg_services()->config;
23 
24  $libraries = $config->get('libraries');
25  if ($libraries === null) {
26  $libraries = array();
27  }
28  $libraries[$name] = $location;
29  $config->set('libraries', $libraries);
30 }
31 
44  static $loaded_libraries = array();
45 
46  if (in_array($name, $loaded_libraries)) {
47  return;
48  }
49 
50  $libraries = _elgg_services()->config->get('libraries');
51 
52  if (!isset($libraries[$name])) {
53  $error = "$name is not a registered library";
54  throw new \InvalidParameterException($error);
55  }
56 
57  if (!include_once($libraries[$name])) {
58  $error = "Could not load the $name library from {$libraries[$name]}";
59  throw new \InvalidParameterException($error);
60  }
61 
62  $loaded_libraries[] = $name;
63 }
64 
80 function forward($location = "", $reason = 'system') {
81  if (!headers_sent($file, $line)) {
82  if ($location === REFERER) {
83  $location = _elgg_services()->request->headers->get('Referer');
84  }
85 
86  $location = elgg_normalize_url($location);
87 
88  // return new forward location or false to stop the forward or empty string to exit
90  $params = array('current_url' => $current_page, 'forward_url' => $location);
91  $location = elgg_trigger_plugin_hook('forward', $reason, $params, $location);
92 
93  if ($location) {
94  header("Location: {$location}");
95  }
96  exit;
97  } else {
98  throw new \SecurityException("Redirect could not be issued due to headers already being sent. Halting execution for security. "
99  . "Output started in file $file at line $line. Search http://learn.elgg.org/ for more information.");
100  }
101 }
102 
127 function elgg_register_js($name, $url, $location = 'head', $priority = null) {
128  return elgg_register_external_file('js', $name, $url, $location, $priority);
129 }
130 
152 function elgg_define_js($name, $config) {
153  $src = elgg_extract('src', $config);
154 
155  if ($src) {
157  _elgg_services()->amdConfig->addPath($name, $url);
158  }
159 
160  // shimmed module
161  if (isset($config['deps']) || isset($config['exports'])) {
162  _elgg_services()->amdConfig->addShim($name, $config);
163  }
164 }
165 
175  return elgg_unregister_external_file('js', $name);
176 }
177 
189 function elgg_load_js($name) {
191 }
192 
193 
202  _elgg_services()->amdConfig->addDependency($name);
203 }
204 
205 
214 function elgg_get_loaded_js($location = 'head') {
215  return elgg_get_loaded_external_files('js', $location);
216 }
217 
228 function elgg_register_css($name, $url, $priority = null) {
229  return elgg_register_external_file('css', $name, $url, 'head', $priority);
230 }
231 
241  return elgg_unregister_external_file('css', $name);
242 }
243 
255 function elgg_load_css($name) {
257 }
258 
266  return elgg_get_loaded_external_files('css', 'head');
267 }
268 
281 function elgg_register_external_file($type, $name, $url, $location, $priority = 500) {
282  return _elgg_services()->externalFiles->register($type, $name, $url, $location, $priority);
283 }
284 
295  return _elgg_services()->externalFiles->unregister($type, $name);
296 }
297 
308  return _elgg_services()->externalFiles->load($type, $name);
309 }
310 
320 function elgg_get_loaded_external_files($type, $location) {
321  return _elgg_services()->externalFiles->getLoadedFiles($type, $location);
322 }
323 
336 function elgg_get_file_list($directory, $exceptions = array(), $list = array(),
337 $extensions = null) {
338 
339  $directory = sanitise_filepath($directory);
340  if ($handle = opendir($directory)) {
341  while (($file = readdir($handle)) !== false) {
342  if (!is_file($directory . $file) || in_array($file, $exceptions)) {
343  continue;
344  }
345 
346  if (is_array($extensions)) {
347  if (in_array(strrchr($file, '.'), $extensions)) {
348  $list[] = $directory . $file;
349  }
350  } else {
351  $list[] = $directory . $file;
352  }
353  }
354  closedir($handle);
355  }
356 
357  return $list;
358 }
359 
368 function sanitise_filepath($path, $append_slash = true) {
369  // Convert to correct UNIX paths
370  $path = str_replace('\\', '/', $path);
371  $path = str_replace('../', '/', $path);
372  // replace // with / except when preceeded by :
373  $path = preg_replace("/([^:])\/\//", "$1/", $path);
374 
375  // Sort trailing slash
376  $path = trim($path);
377  // rtrim defaults plus /
378  $path = rtrim($path, " \n\t\0\x0B/");
379 
380  if ($append_slash) {
381  $path = $path . '/';
382  }
383 
384  return $path;
385 }
386 
412 function system_messages($message = null, $register = "success", $count = false) {
413  if ($count) {
414  return _elgg_services()->systemMessages->count($register);
415  }
416  if ($message === null) {
417  return _elgg_services()->systemMessages->dumpRegister($register);
418  }
419  return _elgg_services()->systemMessages->addMessageToRegister($message, $register);
420 }
421 
429 function count_messages($register = "") {
430  return _elgg_services()->systemMessages->count($register);
431 }
432 
443  return _elgg_services()->systemMessages->addSuccessMessage($message);
444 }
445 
456  return _elgg_services()->systemMessages->addErrorMessage($error);
457 }
458 
519 function elgg_register_event_handler($event, $object_type, $callback, $priority = 500) {
520  return _elgg_services()->events->registerHandler($event, $object_type, $callback, $priority);
521 }
522 
533 function elgg_unregister_event_handler($event, $object_type, $callback) {
534  return _elgg_services()->events->unregisterHandler($event, $object_type, $callback);
535 }
536 
570 function elgg_trigger_event($event, $object_type, $object = null) {
571  return _elgg_services()->events->trigger($event, $object_type, $object);
572 }
573 
591 function elgg_trigger_before_event($event, $object_type, $object = null) {
592  return _elgg_services()->events->trigger("$event:before", $object_type, $object);
593 }
594 
610 function elgg_trigger_after_event($event, $object_type, $object = null) {
611  $options = array(
612  \Elgg\EventsService::OPTION_STOPPABLE => false,
613  );
614  return _elgg_services()->events->trigger("$event:after", $object_type, $object, $options);
615 }
616 
630 function elgg_trigger_deprecated_event($event, $object_type, $object = null, $message, $version) {
631  $options = array(
632  \Elgg\EventsService::OPTION_DEPRECATION_MESSAGE => $message,
633  \Elgg\EventsService::OPTION_DEPRECATION_VERSION => $version,
634  );
635  return _elgg_services()->events->trigger($event, $object_type, $object, $options);
636 }
637 
703 function elgg_register_plugin_hook_handler($hook, $type, $callback, $priority = 500) {
704  return _elgg_services()->hooks->registerHandler($hook, $type, $callback, $priority);
705 }
706 
717 function elgg_unregister_plugin_hook_handler($hook, $entity_type, $callback) {
718  _elgg_services()->hooks->unregisterHandler($hook, $entity_type, $callback);
719 }
720 
775 function elgg_trigger_plugin_hook($hook, $type, $params = null, $returnvalue = null) {
776  return _elgg_services()->hooks->trigger($hook, $type, $params, $returnvalue);
777 }
778 
797  $timestamp = time();
798  error_log("Exception #$timestamp: $exception");
799 
800  // Wipe any existing output buffer
801  ob_end_clean();
802 
803  // make sure the error isn't cached
804  header("Cache-Control: no-cache, must-revalidate", true);
805  header('Expires: Fri, 05 Feb 1982 00:00:00 -0500', true);
806  // @note Do not send a 500 header because it is not a server error
807 
808  // we don't want the 'pagesetup', 'system' event to fire
809  global $CONFIG;
810  $CONFIG->pagesetupdone = true;
811 
812  try {
813  // allow custom scripts to trigger on exception
814  // $CONFIG->exception_include can be set locally in settings.php
815  // value should be a system path to a file to include
816  if (!empty($CONFIG->exception_include) && is_file($CONFIG->exception_include)) {
817  ob_start();
818  include $CONFIG->exception_include;
819  $exception_output = ob_get_clean();
820 
821  // if content is returned from the custom handler we will output
822  // that instead of our default failsafe view
823  if (!empty($exception_output)) {
824  echo $exception_output;
825  exit;
826  }
827  }
828 
829  elgg_set_viewtype('failsafe');
830 
831  if (elgg_is_admin_logged_in()) {
832  if (!elgg_view_exists("messages/exceptions/admin_exception")) {
833  elgg_set_viewtype('failsafe');
834  }
835 
836  $body = elgg_view("messages/exceptions/admin_exception", array(
837  'object' => $exception,
838  'ts' => $timestamp
839  ));
840  } else {
841  if (!elgg_view_exists("messages/exceptions/exception")) {
842  elgg_set_viewtype('failsafe');
843  }
844 
845  $body = elgg_view("messages/exceptions/exception", array(
846  'object' => $exception,
847  'ts' => $timestamp
848  ));
849  }
850  echo elgg_view_page(elgg_echo('exception:title'), $body);
851  } catch (Exception $e) {
852  $timestamp = time();
853  $message = $e->getMessage();
854  echo "Fatal error in exception handler. Check log for Exception #$timestamp";
855  error_log("Exception #$timestamp : fatal error in exception handler : $message");
856  }
857 }
858 
883 function _elgg_php_error_handler($errno, $errmsg, $filename, $linenum, $vars) {
884  $error = date("Y-m-d H:i:s (T)") . ": \"$errmsg\" in file $filename (line $linenum)";
885 
886  switch ($errno) {
887  case E_USER_ERROR:
888  error_log("PHP ERROR: $error");
889  register_error("ERROR: $error");
890 
891  // Since this is a fatal error, we want to stop any further execution but do so gracefully.
892  throw new \Exception($error);
893  break;
894 
895  case E_WARNING :
896  case E_USER_WARNING :
897  case E_RECOVERABLE_ERROR: // (e.g. type hint violation)
898 
899  // check if the error wasn't suppressed by the error control operator (@)
900  if (error_reporting()) {
901  error_log("PHP WARNING: $error");
902  }
903  break;
904 
905  default:
906  global $CONFIG;
907  if (isset($CONFIG->debug) && $CONFIG->debug === 'NOTICE') {
908  error_log("PHP NOTICE: $error");
909  }
910  }
911 
912  return true;
913 }
914 
915 
933 function elgg_log($message, $level = 'NOTICE') {
934  static $levels = array(
935  'INFO' => 200,
936  'NOTICE' => 250,
937  'WARNING' => 300,
938  'DEBUG' => 300,
939  'ERROR' => 400,
940  );
941 
942  if ($level == 'DEBUG') {
943  elgg_deprecated_notice("The 'DEBUG' level for logging has been deprecated.", 1.9);
944  }
945 
946  $level = $levels[$level];
947  return _elgg_services()->logger->log($message, $level);
948 }
949 
964 function elgg_dump($value, $to_screen = true) {
965  _elgg_services()->logger->dump($value, $to_screen);
966 }
967 
976 function elgg_get_version($human_readable = false) {
977  global $CONFIG;
978 
979  static $version, $release;
980 
981  if (isset($CONFIG->path)) {
982  if (!isset($version) || !isset($release)) {
983  if (!include($CONFIG->path . "version.php")) {
984  return false;
985  }
986  }
987  return $human_readable ? $release : $version;
988  }
989 
990  return false;
991 }
992 
1006 function elgg_deprecated_notice($msg, $dep_version, $backtrace_level = 1) {
1007  $backtrace_level += 1;
1008  return _elgg_services()->deprecation->sendNotice($msg, $dep_version, $backtrace_level);
1009 }
1010 
1024 function elgg_http_build_url(array $parts, $html_encode = true) {
1025  // build only what's given to us.
1026  $scheme = isset($parts['scheme']) ? "{$parts['scheme']}://" : '';
1027  $host = isset($parts['host']) ? "{$parts['host']}" : '';
1028  $port = isset($parts['port']) ? ":{$parts['port']}" : '';
1029  $path = isset($parts['path']) ? "{$parts['path']}" : '';
1030  $query = isset($parts['query']) ? "?{$parts['query']}" : '';
1031  $fragment = isset($parts['fragment']) ? "#{$parts['fragment']}" : '';
1032 
1033  $string = $scheme . $host . $port . $path . $query . $fragment;
1034 
1035  if ($html_encode) {
1036  return elgg_format_url($string);
1037  } else {
1038  return $string;
1039  }
1040 }
1041 
1059 function elgg_add_action_tokens_to_url($url, $html_encode = false) {
1061  $components = parse_url($url);
1062 
1063  if (isset($components['query'])) {
1064  $query = elgg_parse_str($components['query']);
1065  } else {
1066  $query = array();
1067  }
1068 
1069  if (isset($query['__elgg_ts']) && isset($query['__elgg_token'])) {
1070  return $url;
1071  }
1072 
1073  // append action tokens to the existing query
1074  $query['__elgg_ts'] = time();
1075  $query['__elgg_token'] = generate_action_token($query['__elgg_ts']);
1076  $components['query'] = http_build_query($query);
1077 
1078  // rebuild the full url
1079  return elgg_http_build_url($components, $html_encode);
1080 }
1081 
1094  return elgg_http_add_url_query_elements($url, array($element => null));
1095 }
1096 
1107 function elgg_http_add_url_query_elements($url, array $elements) {
1108  $url_array = parse_url($url);
1109 
1110  if (isset($url_array['query'])) {
1111  $query = elgg_parse_str($url_array['query']);
1112  } else {
1113  $query = array();
1114  }
1115 
1116  foreach ($elements as $k => $v) {
1117  if ($v === null) {
1118  unset($query[$k]);
1119  } else {
1120  $query[$k] = $v;
1121  }
1122  }
1123 
1124  // why check path? A: if no path, this may be a relative URL like "?foo=1". In this case,
1125  // the output "" would be interpreted the current URL, so in this case we *must* set
1126  // a query to make sure elements are removed.
1127  if ($query || empty($url_array['path'])) {
1128  $url_array['query'] = http_build_query($query);
1129  } else {
1130  unset($url_array['query']);
1131  }
1132  $string = elgg_http_build_url($url_array, false);
1133 
1134  return $string;
1135 }
1136 
1151 function elgg_http_url_is_identical($url1, $url2, $ignore_params = array('offset', 'limit')) {
1152  $url1 = elgg_normalize_url($url1);
1153  $url2 = elgg_normalize_url($url2);
1154 
1155  // @todo - should probably do something with relative URLs
1156 
1157  if ($url1 == $url2) {
1158  return true;
1159  }
1160 
1161  $url1_info = parse_url($url1);
1162  $url2_info = parse_url($url2);
1163 
1164  if (isset($url1_info['path'])) {
1165  $url1_info['path'] = trim($url1_info['path'], '/');
1166  }
1167  if (isset($url2_info['path'])) {
1168  $url2_info['path'] = trim($url2_info['path'], '/');
1169  }
1170 
1171  // compare basic bits
1172  $parts = array('scheme', 'host', 'path');
1173 
1174  foreach ($parts as $part) {
1175  if ((isset($url1_info[$part]) && isset($url2_info[$part]))
1176  && $url1_info[$part] != $url2_info[$part]) {
1177  return false;
1178  } elseif (isset($url1_info[$part]) && !isset($url2_info[$part])) {
1179  return false;
1180  } elseif (!isset($url1_info[$part]) && isset($url2_info[$part])) {
1181  return false;
1182  }
1183  }
1184 
1185  // quick compare of get params
1186  if (isset($url1_info['query']) && isset($url2_info['query'])
1187  && $url1_info['query'] == $url2_info['query']) {
1188  return true;
1189  }
1190 
1191  // compare get params that might be out of order
1192  $url1_params = array();
1193  $url2_params = array();
1194 
1195  if (isset($url1_info['query'])) {
1196  if ($url1_info['query'] = html_entity_decode($url1_info['query'])) {
1197  $url1_params = elgg_parse_str($url1_info['query']);
1198  }
1199  }
1200 
1201  if (isset($url2_info['query'])) {
1202  if ($url2_info['query'] = html_entity_decode($url2_info['query'])) {
1203  $url2_params = elgg_parse_str($url2_info['query']);
1204  }
1205  }
1206 
1207  // drop ignored params
1208  foreach ($ignore_params as $param) {
1209  if (isset($url1_params[$param])) {
1210  unset($url1_params[$param]);
1211  }
1212  if (isset($url2_params[$param])) {
1213  unset($url2_params[$param]);
1214  }
1215  }
1216 
1217  // array_diff_assoc only returns the items in arr1 that aren't in arrN
1218  // but not the items that ARE in arrN but NOT in arr1
1219  // if arr1 is an empty array, this function will return 0 no matter what.
1220  // since we only care if they're different and not how different,
1221  // add the results together to get a non-zero (ie, different) result
1222  $diff_count = count(array_diff_assoc($url1_params, $url2_params));
1223  $diff_count += count(array_diff_assoc($url2_params, $url1_params));
1224  if ($diff_count > 0) {
1225  return false;
1226  }
1227 
1228  return true;
1229 }
1230 
1246 function elgg_extract($key, array $array, $default = null, $strict = true) {
1247  if (!is_array($array)) {
1248  return $default;
1249  }
1250 
1251  if ($strict) {
1252  return (isset($array[$key])) ? $array[$key] : $default;
1253  } else {
1254  return (isset($array[$key]) && !empty($array[$key])) ? $array[$key] : $default;
1255  }
1256 }
1257 
1278 function elgg_sort_3d_array_by_value(&$array, $element, $sort_order = SORT_ASC,
1279 $sort_type = SORT_LOCALE_STRING) {
1280 
1281  $sort = array();
1282 
1283  foreach ($array as $v) {
1284  if (isset($v[$element])) {
1285  $sort[] = strtolower($v[$element]);
1286  } else {
1287  $sort[] = null;
1288  }
1289  };
1290 
1291  return array_multisort($sort, $sort_order, $sort_type, $array);
1292 }
1293 
1304 function ini_get_bool($ini_get_arg) {
1305  $temp = strtolower(ini_get($ini_get_arg));
1306 
1307  if ($temp == '1' || $temp == 'on' || $temp == 'true') {
1308  return true;
1309  }
1310  return false;
1311 }
1312 
1324 function elgg_get_ini_setting_in_bytes($setting) {
1325  // retrieve INI setting
1326  $val = ini_get($setting);
1327 
1328  // convert INI setting when shorthand notation is used
1329  $last = strtolower($val[strlen($val) - 1]);
1330  switch($last) {
1331  case 'g':
1332  $val *= 1024;
1333  // fallthrough intentional
1334  case 'm':
1335  $val *= 1024;
1336  // fallthrough intentional
1337  case 'k':
1338  $val *= 1024;
1339  }
1340 
1341  // return byte value
1342  return $val;
1343 }
1344 
1356  if (($string === '') || ($string === false) || ($string === null)) {
1357  return false;
1358  }
1359 
1360  return true;
1361 }
1362 
1377  foreach ($singulars as $singular) {
1378  $plural = $singular . 's';
1379 
1380  if (array_key_exists($singular, $options)) {
1381  if ($options[$singular] === ELGG_ENTITIES_ANY_VALUE) {
1382  $options[$plural] = $options[$singular];
1383  } else {
1384  // Test for array refs #2641
1385  if (!is_array($options[$singular])) {
1386  $options[$plural] = array($options[$singular]);
1387  } else {
1388  $options[$plural] = $options[$singular];
1389  }
1390  }
1391  }
1392 
1393  unset($options[$singular]);
1394  }
1395 
1396  return $options;
1397 }
1398 
1416 
1417  try {
1418  elgg_trigger_event('shutdown', 'system');
1419 
1420  $time = (float)(microtime(true) - $START_MICROTIME);
1421  $uri = _elgg_services()->request->server->get('REQUEST_URI', 'CLI');
1422  // demoted to NOTICE from DEBUG so javascript is not corrupted
1423  elgg_log("Page {$uri} generated in $time seconds", 'INFO');
1424  } catch (Exception $e) {
1425  $message = 'Error: ' . get_class($e) . ' thrown within the shutdown handler. ';
1426  $message .= "Message: '{$e->getMessage()}' in file {$e->getFile()} (line {$e->getLine()})";
1427  error_log($message);
1428  error_log("Exception trace stack: {$e->getTraceAsString()}");
1429  }
1430 
1431  // Prevent an APC session bug: https://bugs.php.net/bug.php?id=60657
1432  session_write_close();
1433 }
1434 
1447 function _elgg_js_page_handler($page) {
1448  return _elgg_cacheable_view_page_handler($page, 'js');
1449 }
1450 
1463 function _elgg_ajax_page_handler($page) {
1464  // the ajax page handler should only be called from an xhr
1465  if (!elgg_is_xhr()) {
1466  register_error(_elgg_services()->translator->translate('ajax:not_is_xhr'));
1467  forward(null, '400');
1468  }
1469 
1470  if (is_array($page) && sizeof($page)) {
1471  // throw away 'view' and form the view name
1472  unset($page[0]);
1473  $view = implode('/', $page);
1474 
1475  $allowed_views = elgg_get_config('allowed_ajax_views');
1476  if (!array_key_exists($view, $allowed_views)) {
1477  header('HTTP/1.1 403 Forbidden');
1478  exit;
1479  }
1480 
1481  // pull out GET parameters through filter
1482  $vars = array();
1483  foreach (_elgg_services()->request->query->keys() as $name) {
1484  $vars[$name] = get_input($name);
1485  }
1486 
1487  if (isset($vars['guid'])) {
1488  $vars['entity'] = get_entity($vars['guid']);
1489  }
1490 
1491  // Try to guess the mime-type
1492  switch ($page[1]) {
1493  case "js":
1494  header("Content-Type: text/javascript");
1495  break;
1496  case "css":
1497  header("Content-Type: text/css");
1498  break;
1499  }
1500 
1502  return true;
1503  }
1504  return false;
1505 }
1506 
1518 function _elgg_css_page_handler($page) {
1519  if (!isset($page[0])) {
1520  // default css
1521  $page[0] = 'elgg';
1522  }
1523 
1524  return _elgg_cacheable_view_page_handler($page, 'css');
1525 }
1526 
1535 function _elgg_favicon_page_handler($segments) {
1536  header("HTTP/1.1 404 Not Found", true, 404);
1537 
1538  header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+1 week")), true);
1539  header("Pragma: public", true);
1540  header("Cache-Control: public", true);
1541 
1542  // TODO in next 1.x send our default icon
1543  //header('Content-Type: image/vnd.microsoft.icon');
1544  //readfile(elgg_get_root_path() . '_graphics/favicon.ico');
1545 
1546  return true;
1547 }
1548 
1561 
1562  switch ($type) {
1563  case 'js':
1564  $content_type = 'text/javascript';
1565  break;
1566 
1567  case 'css':
1568  $content_type = 'text/css';
1569  break;
1570 
1571  default:
1572  return false;
1573  break;
1574  }
1575 
1576  if ($page) {
1577  // the view file names can have multiple dots
1578  // eg: views/default/js/calendars/jquery.fullcalendar.min.php
1579  // translates to the url /js/<ts>/calendars/jquery.fullcalendar.min.js
1580  // and the view js/calendars/jquery.fullcalendar.min
1581  // we ignore the last two dots for the ts and the ext.
1582  // Additionally, the timestamp is optional.
1583  $page = implode('/', $page);
1584  $regex = '|(.+?)\.\w+$|';
1585  if (!preg_match($regex, $page, $matches)) {
1586  return false;
1587  }
1588  $view = "$type/{$matches[1]}";
1589  if (!elgg_view_exists($view)) {
1590  return false;
1591  }
1592  $return = elgg_view($view);
1593 
1594  header("Content-type: $content_type");
1595 
1596  // @todo should js be cached when simple cache turned off
1597  //header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+10 days")), true);
1598  //header("Pragma: public");
1599  //header("Cache-Control: public");
1600  //header("Content-Length: " . strlen($return));
1601 
1602  echo $return;
1603  return true;
1604  }
1605  return false;
1606 }
1607 
1620  $order_by = strtolower($order_by);
1621 
1622  if (strpos($order_by, ' asc') !== false) {
1623  $return = str_replace(' asc', ' desc', $order_by);
1624  } elseif (strpos($order_by, ' desc') !== false) {
1625  $return = str_replace(' desc', ' asc', $order_by);
1626  } else {
1627  // no order specified, so default to desc since mysql defaults to asc
1628  $return = $order_by . ' desc';
1629  }
1630 
1631  return $return;
1632 }
1633 
1646  // our db functions return the number of rows affected...
1647  return $object->enable() ? true : false;
1648 }
1649 
1660  // our db functions return the number of rows affected...
1661  return $object->disable() ? true : false;
1662 }
1663 
1674  // our db functions return the number of rows affected...
1675  return $object->delete() ? true : false;
1676 }
1677 
1688  if (!$options || !is_array($options)) {
1689  return false;
1690  }
1691 
1692  // at least one of these is required.
1693  $required = array(
1694  // generic restraints
1695  'guid', 'guids'
1696  );
1697 
1698  switch ($type) {
1699  case 'metadata':
1700  $metadata_required = array(
1701  'metadata_owner_guid', 'metadata_owner_guids',
1702  'metadata_name', 'metadata_names',
1703  'metadata_value', 'metadata_values'
1704  );
1705 
1706  $required = array_merge($required, $metadata_required);
1707  break;
1708 
1709  case 'annotations':
1710  case 'annotation':
1711  $annotations_required = array(
1712  'annotation_owner_guid', 'annotation_owner_guids',
1713  'annotation_name', 'annotation_names',
1714  'annotation_value', 'annotation_values'
1715  );
1716 
1717  $required = array_merge($required, $annotations_required);
1718  break;
1719 
1720  default:
1721  return false;
1722  }
1723 
1724  foreach ($required as $key) {
1725  // check that it exists and is something.
1726  if (isset($options[$key]) && $options[$key]) {
1727  return true;
1728  }
1729  }
1730 
1731  return false;
1732 }
1733 
1741 
1742  elgg_load_css('elgg.walled_garden');
1743  elgg_load_js('elgg.walled_garden');
1744 
1745  $content = elgg_view('core/walled_garden/login');
1746 
1747  $params = array(
1748  'content' => $content,
1749  'class' => 'elgg-walledgarden-double',
1750  'id' => 'elgg-walledgarden-login',
1751  );
1752  $body = elgg_view_layout('walled_garden', $params);
1753  echo elgg_view_page('', $body, 'walled_garden');
1754 
1755  return true;
1756 }
1757 
1758 
1767  $view = $page[0];
1768  $params = array(
1769  'content' => elgg_view("core/walled_garden/$view"),
1770  'class' => 'elgg-walledgarden-single hidden',
1771  'id' => str_replace('_', '-', "elgg-walledgarden-$view"),
1772  );
1773  echo elgg_view_layout('walled_garden', $params);
1774  return true;
1775 }
1776 
1791  global $CONFIG;
1792 
1793  elgg_register_css('elgg.walled_garden', elgg_get_simplecache_url('css', 'walled_garden'));
1794  elgg_register_js('elgg.walled_garden', elgg_get_simplecache_url('js', 'walled_garden'));
1795 
1796  elgg_register_page_handler('walled_garden', '_elgg_walled_garden_ajax_handler');
1797 
1798  // check for external page view
1799  if (isset($CONFIG->site) && $CONFIG->site instanceof \ElggSite) {
1800  $CONFIG->site->checkWalledGarden();
1801  }
1802 }
1803 
1814  if (isset($accesses[ACCESS_PUBLIC])) {
1815  unset($accesses[ACCESS_PUBLIC]);
1816  }
1817  return $accesses;
1818 }
1819 
1833 function _elgg_engine_boot() {
1834  // Register the error handlers
1835  set_error_handler('_elgg_php_error_handler');
1836  set_exception_handler('_elgg_php_exception_handler');
1837 
1838  _elgg_services()->db->setupConnections();
1839 
1840  _elgg_services()->db->assertInstalled();
1841 
1843 
1845 
1847 
1849 
1850  _elgg_services()->systemCache->loadAll();
1851 
1852  _elgg_services()->translator->loadTranslations();
1853 }
1854 
1864 function _elgg_init() {
1865  global $CONFIG;
1866 
1867  elgg_register_action('comment/save');
1868  elgg_register_action('comment/delete');
1869 
1870  elgg_register_page_handler('js', '_elgg_js_page_handler');
1871  elgg_register_page_handler('css', '_elgg_css_page_handler');
1872  elgg_register_page_handler('ajax', '_elgg_ajax_page_handler');
1873  elgg_register_page_handler('favicon.ico', '_elgg_favicon_page_handler');
1874 
1875  elgg_register_page_handler('manifest.json', function() {
1877  $resource = new \Elgg\Http\WebAppManifestResource($site);
1878  header('Content-Type: application/json');
1879  echo json_encode($resource->get());
1880  return true;
1881  });
1882 
1883  elgg_register_plugin_hook_handler('head', 'page', function($hook, $type, array $result) {
1884  $result['links']['manifest'] = [
1885  'rel' => 'manifest',
1886  'href' => elgg_normalize_url('/manifest.json'),
1887  ];
1888 
1889  return $result;
1890  });
1891 
1892  elgg_register_js('elgg.autocomplete', 'js/lib/ui.autocomplete.js');
1893  elgg_register_js('jquery.ui.autocomplete.html', 'vendors/jquery/jquery.ui.autocomplete.html.js');
1894 
1895  elgg_define_js('jquery.ui.autocomplete.html', array(
1896  'src' => '/vendors/jquery/jquery.ui.autocomplete.html.js',
1897  'deps' => array('jquery.ui')
1898  ));
1899 
1900  elgg_register_external_view('js/elgg/UserPicker.js', true);
1901 
1902  elgg_register_js('elgg.friendspicker', 'js/lib/ui.friends_picker.js');
1903  elgg_register_js('elgg.avatar_cropper', 'js/lib/ui.avatar_cropper.js');
1904  elgg_register_js('jquery.imgareaselect', 'vendors/jquery/jquery.imgareaselect/scripts/jquery.imgareaselect.min.js');
1905  elgg_register_js('elgg.ui.river', 'js/lib/ui.river.js');
1906 
1907  elgg_register_css('jquery.imgareaselect', 'vendors/jquery/jquery.imgareaselect/css/imgareaselect-deprecated.css');
1908 
1909  // Trigger the shutdown:system event upon PHP shutdown.
1910  register_shutdown_function('_elgg_shutdown_hook');
1911 
1912  // Sets a blacklist of words in the current language.
1913  // This is a comma separated list in word:blacklist.
1914  // @todo possibly deprecate
1915  $CONFIG->wordblacklist = array();
1916  $list = explode(',', elgg_echo('word:blacklist'));
1917  if ($list) {
1918  foreach ($list as $l) {
1919  $CONFIG->wordblacklist[] = trim($l);
1920  }
1921  }
1922 }
1923 
1936 function _elgg_api_test($hook, $type, $value, $params) {
1937  global $CONFIG;
1938  $value[] = $CONFIG->path . 'engine/tests/ElggTravisInstallTest.php';
1939  $value[] = $CONFIG->path . 'engine/tests/ElggCoreHelpersTest.php';
1940  $value[] = $CONFIG->path . 'engine/tests/ElggCoreRegressionBugsTest.php';
1941  $value[] = $CONFIG->path . 'engine/tests/ElggBatchTest.php';
1942  return $value;
1943 }
1944 
1953 define('ACCESS_DEFAULT', -1);
1954 define('ACCESS_PRIVATE', 0);
1955 define('ACCESS_LOGGED_IN', 1);
1956 define('ACCESS_PUBLIC', 2);
1957 define('ACCESS_FRIENDS', -2);
1967 define('ELGG_ENTITIES_ANY_VALUE', null);
1968 
1976 define('ELGG_ENTITIES_NO_VALUE', 0);
1977 
1985 define('REFERRER', -1);
1986 
1995 define('REFERER', -1);
1996 
1997 return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) {
1998  $events->registerHandler('init', 'system', '_elgg_init');
1999  $events->registerHandler('boot', 'system', '_elgg_engine_boot', 1);
2000  $hooks->registerHandler('unit_test', 'system', '_elgg_api_test');
2001 
2002  $events->registerHandler('init', 'system', '_elgg_walled_garden_init', 1000);
2003 };
_elgg_load_autoload_cache()
Load cached data into the autoload system.
Definition: autoloader.php:49
elgg_http_add_url_query_elements($url, array $elements)
Sets elements in a URL&#39;s query string.
Definition: elgglib.php:1107
elgg_parse_str($str)
Parses a string using mb_parse_str() if available.
Definition: mb_wrapper.php:19
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
$view
Definition: crop.php:68
elgg_get_loaded_css()
Get the loaded CSS URLs.
Definition: elgglib.php:265
elgg_get_site_entity($site_guid=0)
Get an entity (default is current site)
Definition: sites.php:18
if(!$owner||!($owner instanceof ElggUser)||!$owner->canEdit()) $error
Definition: upload.php:14
elgg_is_xhr()
Checks whether the request was requested via ajax.
Definition: actions.php:227
elgg_unregister_plugin_hook_handler($hook, $entity_type, $callback)
Unregister a callback as a plugin hook.
Definition: elgglib.php:717
get_input($variable, $default=null, $filter_result=true)
Get some input from variables passed submitted through GET or POST.
Definition: input.php:27
elgg_add_action_tokens_to_url($url, $html_encode=false)
Adds action tokens to URL.
Definition: elgglib.php:1059
_elgg_css_page_handler($page)
Serve CSS.
Definition: elgglib.php:1518
_elgg_is_valid_options_for_batch_operation($options, $type)
Checks if there are some constraints on the options array for potentially dangerous operations...
Definition: elgglib.php:1687
elgg_register_external_file($type, $name, $url, $location, $priority=500)
Core registration function for external files.
Definition: elgglib.php:281
elgg_is_admin_logged_in()
Returns whether or not the viewer is currently logged in and an admin user.
Definition: sessions.php:60
elgg_normalize_url($url)
Definition: output.php:311
$current_page
Definition: pagination.php:50
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
elgg_define_js($name, $config)
Defines a JS lib as an AMD module.
Definition: elgglib.php:152
current_page_url()
Returns the current page&#39;s complete URL.
Definition: input.php:65
elgg_sort_3d_array_by_value(&$array, $element, $sort_order=SORT_ASC, $sort_type=SORT_LOCALE_STRING)
Sorts a 3d array by specific element.
Definition: elgglib.php:1278
$e
Definition: metadata.php:12
$object
Definition: upgrade.php:12
$extensions
elgg_http_url_is_identical($url1, $url2, $ignore_params=array('offset', 'limit'))
Test if two URLs are functionally identical.
Definition: elgglib.php:1151
elgg_unregister_external_file($type, $name)
Unregister an external file.
Definition: elgglib.php:294
sanitise_filepath($path, $append_slash=true)
Sanitise file paths ensuring that they begin and end with slashes etc.
Definition: elgglib.php:368
$value
Definition: longtext.php:26
elgg_register_external_view($view, $cacheable=false)
Registers a view as being available externally (i.e.
Definition: views.php:231
elgg_view_exists($view, $viewtype= '', $recurse=true)
Returns whether the specified view exists.
Definition: views.php:318
elgg_register_css($name, $url, $priority=null)
Register a CSS file for inclusion in the HTML head.
Definition: elgglib.php:228
elgg_load_library($name)
Load a PHP library.
Definition: elgglib.php:43
$return
Definition: opendd.php:15
_elgg_favicon_page_handler($segments)
Handle requests for /favicon.ico.
Definition: elgglib.php:1535
$default
Definition: checkbox.php:34
$src
Definition: iframe.php:18
exit
Definition: reorder.php:12
elgg parse_url
Parse a URL into its parts.
Definition: elgglib.js:432
elgg_extract($key, array $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:1246
_elgg_load_site_config()
Loads configuration related to this site.
elgg_register_plugin_hook_handler($hook, $type, $callback, $priority=500)
Definition: elgglib.php:703
$timestamp
Definition: date.php:35
_elgg_sql_reverse_order_by_clause($order_by)
Reverses the ordering in an ORDER BY clause.
Definition: elgglib.php:1619
_elgg_ajax_page_handler($page)
Serve individual views for Ajax.
Definition: elgglib.php:1463
elgg_trigger_before_event($event, $object_type, $object=null)
Trigger a "Before event" indicating a process is about to begin.
Definition: elgglib.php:591
$url
Definition: exceptions.php:24
_elgg_shutdown_hook()
Emits a shutdown:system event upon PHP shutdown, but before database connections are dropped...
Definition: elgglib.php:1414
_elgg_php_exception_handler($exception)
Intercepts, logs, and displays uncaught exceptions.
Definition: elgglib.php:796
register_error($error)
Display an error on next page load.
Definition: elgglib.php:455
$string
elgg_get_loaded_external_files($type, $location)
Get external resource descriptors.
Definition: elgglib.php:320
$params
Definition: login.php:72
is_not_null($string)
Returns true is string is not empty, false, or null.
Definition: elgglib.php:1355
$options
Definition: index.php:14
elgg_batch_delete_callback($object)
Delete objects with a delete() method.
Definition: elgglib.php:1673
_elgg_js_page_handler($page)
Serve javascript pages.
Definition: elgglib.php:1447
$exception
elgg_unregister_css($name)
Unregister a CSS file.
Definition: elgglib.php:240
elgg_require_js($name)
Request that Elgg load an AMD module onto the page.
Definition: elgglib.php:201
elgg_get_file_list($directory, $exceptions=array(), $list=array(), $extensions=null)
Returns a list of files in $directory.
Definition: elgglib.php:336
elgg_get_ini_setting_in_bytes($setting)
Returns a PHP INI setting in bytes.
Definition: elgglib.php:1324
Save menu items.
_elgg_api_test($hook, $type, $value, $params)
Adds unit tests for the general API.
Definition: elgglib.php:1936
elgg_load_css($name)
Load a CSS file for this page.
Definition: elgglib.php:255
elgg_register_js($name, $url, $location= 'head', $priority=null)
Register a JavaScript file for inclusion.
Definition: elgglib.php:127
generate_action_token($timestamp)
Generate an action token.
Definition: actions.php:167
elgg_set_viewtype($viewtype="")
Manually set the viewtype.
Definition: views.php:70
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
elgg_get_simplecache_url($type, $view)
Definition: cache.php:117
elgg_http_remove_url_query_element($url, $element)
Removes an element from a URL&#39;s query string.
Definition: elgglib.php:1093
$key
Definition: summary.php:34
elgg_trigger_deprecated_event($event, $object_type, $object=null, $message, $version)
Trigger an event normally, but send a notice about deprecated use if any handlers are registered...
Definition: elgglib.php:630
const REFERER
Definition: elgglib.php:1995
_elgg_services()
Definition: autoloader.php:14
elgg_load_external_file($type, $name)
Load an external resource for use on this page.
Definition: elgglib.php:307
_elgg_engine_boot()
Boots the engine.
Definition: elgglib.php:1833
_elgg_walled_garden_index()
Intercepts the index page when Walled Garden mode is enabled.
Definition: elgglib.php:1740
global $CONFIG
_elgg_cacheable_view_page_handler($page, $type)
Serves a JS or CSS view with headers for caching.
Definition: elgglib.php:1560
ini_get_bool($ini_get_arg)
Return the state of a php.ini setting as a bool.
Definition: elgglib.php:1304
elgg_dump($value, $to_screen=true)
Logs or displays $value.
Definition: elgglib.php:964
const ELGG_ENTITIES_ANY_VALUE
Definition: elgglib.php:1967
elgg echo
Translates a string.
Definition: languages.js:43
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Definition: elgglib.php:775
elgg_register_page_handler($identifier, $function)
Registers a page handler for a particular identifier.
Definition: pagehandler.php:34
_elgg_walled_garden_ajax_handler($page)
Serve walled garden sections.
Definition: elgglib.php:1766
global $START_MICROTIME
The time with microseconds when the Elgg engine was started.
Definition: start.php:24
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:1006
elgg global
Pointer to the global context.
Definition: elgglib.js:12
$type
Definition: add.php:8
elgg_register_library($name, $location)
Register a PHP file as a library.
Definition: elgglib.php:21
elgg_view($view, $vars=array(), $bypass=false, $ignored=false, $viewtype= '')
Return a parsed view.
Definition: views.php:354
system_messages($message=null, $register="success", $count=false)
Queues a message to be displayed.
Definition: elgglib.php:412
elgg_view_layout($layout_name, $vars=array())
Displays a layout with optional parameters.
Definition: views.php:622
elgg_register_event_handler($event, $object_type, $callback, $priority=500)
Definition: elgglib.php:519
elgg_log($message, $level= 'NOTICE')
Display or log a message.
Definition: elgglib.php:933
_elgg_walled_garden_remove_public_access($hook, $type, $accesses)
Remove public access for walled gardens.
Definition: elgglib.php:1813
const ACCESS_PUBLIC
Definition: elgglib.php:1956
forward($location="", $reason= 'system')
Forward to $location.
Definition: elgglib.php:80
elgg_get_version($human_readable=false)
Get the current Elgg version information.
Definition: elgglib.php:976
elgg_load_js($name)
Load a JavaScript resource on this page.
Definition: elgglib.php:189
elgg_http_build_url(array $parts, $html_encode=true)
Builds a URL from the a parts array like one returned by parse_url().
Definition: elgglib.php:1024
$content
Set robots.txt action.
Definition: set_robots.php:6
$sort
Definition: plugins.php:19
elgg_batch_disable_callback($object)
Disable objects with a disable() method.
Definition: elgglib.php:1659
elgg_format_url($url)
Handles formatting of ampersands in urls.
Definition: output.php:105
if(elgg_in_context('widget')) $count
Definition: pagination.php:20
elgg_trigger_after_event($event, $object_type, $object=null)
Trigger an "After event" indicating a process has finished.
Definition: elgglib.php:610
_elgg_init()
Elgg&#39;s main init.
Definition: elgglib.php:1864
$filename
Definition: crop.php:23
elgg_view_page($title, $body, $page_shell= 'default', $vars=array())
Assembles and outputs a full page.
Definition: views.php:437
clearfix elgg elgg elgg elgg page header
Definition: admin.php:127
elgg_register_action($action, $filename="", $access= 'logged_in')
Registers an action.
Definition: actions.php:85
_elgg_session_boot()
Initializes the session and checks for the remember me cookie.
Definition: sessions.php:408
_elgg_normalize_plural_options_array($options, $singulars)
Normalise the singular keys in an options array to plural keys.
Definition: elgglib.php:1376
elgg_trigger_event($event, $object_type, $object=null)
Definition: elgglib.php:570
_elgg_walled_garden_init()
Checks the status of the Walled Garden and forwards to a login page if required.
Definition: elgglib.php:1790
_elgg_php_error_handler($errno, $errmsg, $filename, $linenum, $vars)
Intercepts catchable PHP errors.
Definition: elgglib.php:883
$version
Definition: version.php:14
_elgg_load_application_config()
Loads configuration related to Elgg as an application.
$path
Definition: invalid.php:17
system_message($message)
Display a system message on next page load.
Definition: elgglib.php:442
elgg_get_loaded_js($location= 'head')
Get the JavaScript URLs that are loaded.
Definition: elgglib.php:214
elgg_batch_enable_callback($object)
Enable objects with an enable() method.
Definition: elgglib.php:1645
elgg_unregister_event_handler($event, $object_type, $callback)
Unregisters a callback for an event.
Definition: elgglib.php:533
define(function(require){var $=require('jquery');var active=false;var SHOW_DELAY=20;$('body').append('< div class="elgg-spinner">< div class="elgg-ajax-loader"></div ></div >');return{start:function(){active=true;setTimeout(function(){if(active){$('body').addClass('elgg-spinner-active');}}, SHOW_DELAY);}, stop:function(){active=false;$('body').removeClass('elgg-spinner-active');}};})
$priority
elgg_unregister_js($name)
Unregister a JavaScript file.
Definition: elgglib.php:174
count_messages($register="")
Counts the number of messages, either globally or in a particular register.
Definition: elgglib.php:429
if($composer===null) if(!isset($composer->version)) $release
Definition: version.php:30
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:382
if(file_exists($welcome)) $vars
Definition: upgrade.php:93