Пример #1
0
 /**
  * Handles scraper pages
  *
  * @param array $segments URL segments
  * @return bool
  */
 public static function serveScraperPages($segments)
 {
     $url = get_input('url');
     if (!elgg_is_logged_in()) {
         $m = get_input('m');
         if (!$m || !elgg_build_hmac($url)->matchesToken($m)) {
             return false;
         }
     }
     $viewtype = array_shift($segments);
     if (!$viewtype || !elgg_is_registered_viewtype($viewtype)) {
         $viewtype = 'default';
     }
     elgg_set_viewtype($viewtype);
     echo elgg_view_resource('scraper/card', ['href' => $url, 'iframe' => get_input('iframe', false)]);
     return true;
 }
Пример #2
0
 /**
  * Bootstrap the Elgg engine, loads plugins, and calls initial system events
  *
  * This method loads the full Elgg engine, checks the installation
  * state, and triggers a series of events to finish booting Elgg:
  * 	- {@elgg_event boot system}
  * 	- {@elgg_event init system}
  * 	- {@elgg_event ready system}
  *
  * If Elgg is not fully installed, the browser will be redirected to an installation page.
  *
  * @return void
  */
 public function bootCore()
 {
     $config = $this->services->config;
     if ($config->getVolatile('boot_complete')) {
         return;
     }
     $this->loadSettings();
     $config->set('boot_complete', false);
     // This will be overridden by the DB value but may be needed before the upgrade script can be run.
     $config->set('default_limit', 10);
     // in case not loaded already
     $this->loadCore();
     $events = $this->services->events;
     // Connect to database, load language files, load configuration, init session
     // Plugins can't use this event because they haven't been loaded yet.
     $events->trigger('boot', 'system');
     // Load the plugins that are active
     $this->services->plugins->load();
     if (Directory\Local::root()->getPath() != self::elggDir()->getPath()) {
         // Elgg is installed as a composer dep, so try to treat the root directory
         // as a custom plugin that is always loaded last and can't be disabled...
         if (!elgg_get_config('system_cache_loaded')) {
             $viewsFile = Directory\Local::root()->getFile('views.php');
             if ($viewsFile->exists()) {
                 $viewsSpec = $viewsFile->includeFile();
                 if (is_array($viewsSpec)) {
                     _elgg_services()->views->mergeViewsSpec($viewsSpec);
                 }
             }
             _elgg_services()->views->registerPluginViews(Directory\Local::root()->getPath());
         }
         if (!elgg_get_config('i18n_loaded_from_cache')) {
             _elgg_services()->translator->registerPluginTranslations(Directory\Local::root()->getPath());
         }
         // This is root directory start.php, not elgg/engine/start.php
         @(include_once Directory\Local::root()->getPath("start.php"));
     }
     // @todo move loading plugins into a single boot function that replaces 'boot', 'system' event
     // and then move this code in there.
     // This validates the view type - first opportunity to do it is after plugins load.
     $viewtype = elgg_get_viewtype();
     if (!elgg_is_registered_viewtype($viewtype)) {
         elgg_set_viewtype('default');
     }
     // @todo deprecate as plugins can use 'init', 'system' event
     $events->trigger('plugins_boot', 'system');
     // Complete the boot process for both engine and plugins
     $events->trigger('init', 'system');
     $config->set('boot_complete', true);
     // System loaded and ready
     $events->trigger('ready', 'system');
 }
Пример #3
0
if (!is_file("{$engine_dir}/settings.php")) {
    header("Location: install.php");
    exit;
}
if (!is_readable("{$engine_dir}/settings.php")) {
    echo "The Elgg settings file exists but the web server doesn't have read permission to it.";
    exit;
}
require_once "{$engine_dir}/settings.php";
// This will be overridden by the DB value but may be needed before the upgrade script can be run.
$CONFIG->default_limit = 10;
require_once "{$engine_dir}/load.php";
// Connect to database, load language files, load configuration, init session
// Plugins can't use this event because they haven't been loaded yet.
elgg_trigger_event('boot', 'system');
// Load the plugins that are active
_elgg_load_plugins();
// @todo move loading plugins into a single boot function that replaces 'boot', 'system' event
// and then move this code in there.
// This validates the view type - first opportunity to do it is after plugins load.
$viewtype = elgg_get_viewtype();
if (!elgg_is_registered_viewtype($viewtype)) {
    elgg_set_viewtype('default');
}
// @todo deprecate as plugins can use 'init', 'system' event
elgg_trigger_event('plugins_boot', 'system');
// Complete the boot process for both engine and plugins
elgg_trigger_event('init', 'system');
$CONFIG->boot_complete = true;
// System loaded and ready
elgg_trigger_event('ready', 'system');
Пример #4
0
/**
 * Services handler - turns request over to the registered handler
 * If no handler is found, this returns a 404 error
 *
 * @param string $handler Handler name
 * @param array  $request Request string
 *
 * @return void
 * @access private
 */
function service_handler($handler, $request)
{
    global $CONFIG;
    elgg_set_context('api');
    $request = explode('/', $request);
    // after the handler, the first identifier is response format
    // ex) http://example.org/services/api/rest/json/?method=test
    $response_format = array_shift($request);
    // Which view - xml, json, ...
    if ($response_format && elgg_is_registered_viewtype($response_format)) {
        elgg_set_viewtype($response_format);
    } else {
        // default to json
        elgg_set_viewtype("json");
    }
    if (!isset($CONFIG->servicehandler) || empty($handler)) {
        // no handlers set or bad url
        header("HTTP/1.0 404 Not Found");
        exit;
    } else {
        if (isset($CONFIG->servicehandler[$handler]) && is_callable($CONFIG->servicehandler[$handler])) {
            $function = $CONFIG->servicehandler[$handler];
            call_user_func($function, $request, $handler);
        } else {
            // no handler for this web service
            header("HTTP/1.0 404 Not Found");
            exit;
        }
    }
}
Пример #5
0
 /**
  * Handles graph requests
  *
  * /graph/<node>[/<edge>]
  *
  * @param array $segments URL segments
  * @return bool
  */
 public function pageHandler($segments)
 {
     elgg_register_plugin_hook_handler('debug', 'log', array($this->logger, 'debugLogHandler'));
     error_reporting(E_ALL);
     set_error_handler(array($this->logger, 'errorHandler'));
     set_exception_handler(array($this->logger, 'exceptionHandler'));
     try {
         if ($this->request->getUrlSegments()[0] == 'services') {
             elgg_trigger_plugin_hook('auth', 'graph');
         } else {
             // graph page handler is being accessed directly, and not routed to from services
             // check csrf tokens
             action_gatekeeper('');
             if ($this->request->getMethod() != HttpRequest::METHOD_GET) {
                 elgg_gatekeeper();
             }
         }
         elgg_set_context('services');
         elgg_push_context('api');
         elgg_push_context('graph');
         $viewtype = $this->mapViewtype();
         $endpoint = implode('/', $segments);
         if (!elgg_is_registered_viewtype($viewtype)) {
             $viewtype = 'json';
         }
         elgg_set_viewtype($viewtype);
         $result = $this->route($endpoint);
     } catch (Exception $ex) {
         $result = new ErrorResult($ex->getMessage(), $ex->getCode(), $ex);
     }
     $this->send($result);
     return true;
 }
Пример #6
0
 /**
  * Bootstrap the Elgg engine, loads plugins, and calls initial system events
  *
  * This method loads the full Elgg engine, checks the installation
  * state, and triggers a series of events to finish booting Elgg:
  * 	- {@elgg_event boot system}
  * 	- {@elgg_event init system}
  * 	- {@elgg_event ready system}
  *
  * If Elgg is not fully installed, the browser will be redirected to an installation page.
  *
  * @see install.php
  * @return void
  */
 public function bootCore()
 {
     $config = $this->services->config;
     if ($config->getVolatile('boot_complete')) {
         return;
     }
     $this->loadSettings();
     $config->set('boot_complete', false);
     // This will be overridden by the DB value but may be needed before the upgrade script can be run.
     $config->set('default_limit', 10);
     // in case not loaded already
     $this->loadCore();
     $events = $this->services->events;
     // Connect to database, load language files, load configuration, init session
     // Plugins can't use this event because they haven't been loaded yet.
     $events->trigger('boot', 'system');
     // Load the plugins that are active
     $this->services->plugins->load();
     // @todo move loading plugins into a single boot function that replaces 'boot', 'system' event
     // and then move this code in there.
     // This validates the view type - first opportunity to do it is after plugins load.
     $viewtype = elgg_get_viewtype();
     if (!elgg_is_registered_viewtype($viewtype)) {
         elgg_set_viewtype('default');
     }
     // @todo deprecate as plugins can use 'init', 'system' event
     $events->trigger('plugins_boot', 'system');
     // Complete the boot process for both engine and plugins
     $events->trigger('init', 'system');
     $config->set('boot_complete', true);
     // System loaded and ready
     $events->trigger('ready', 'system');
 }
Пример #7
0
 /**
  * Bootstrap the Elgg engine, loads plugins, and calls initial system events
  *
  * This method loads the full Elgg engine, checks the installation
  * state, and triggers a series of events to finish booting Elgg:
  * 	- {@elgg_event boot system}
  * 	- {@elgg_event init system}
  * 	- {@elgg_event ready system}
  *
  * If Elgg is not fully installed, the browser will be redirected to an installation page.
  *
  * @return void
  */
 public function bootCore()
 {
     $config = $this->services->config;
     if ($this->isTestingApplication()) {
         throw new \RuntimeException('Unit tests should not call ' . __METHOD__);
     }
     if ($config->getVolatile('boot_complete')) {
         return;
     }
     $this->loadSettings();
     $config->set('boot_complete', false);
     // This will be overridden by the DB value but may be needed before the upgrade script can be run.
     $config->set('default_limit', 10);
     // in case not loaded already
     $this->loadCore();
     $events = $this->services->events;
     // Connect to database, load language files, load configuration, init session
     // Plugins can't use this event because they haven't been loaded yet.
     $events->trigger('boot', 'system');
     // Load the plugins that are active
     $this->services->plugins->load();
     $root = Directory\Local::root();
     if ($root->getPath() != self::elggDir()->getPath()) {
         // Elgg is installed as a composer dep, so try to treat the root directory
         // as a custom plugin that is always loaded last and can't be disabled...
         if (!elgg_get_config('system_cache_loaded')) {
             // configure view locations for the custom plugin (not Elgg core)
             $viewsFile = $root->getFile('views.php');
             if ($viewsFile->exists()) {
                 $viewsSpec = $viewsFile->includeFile();
                 if (is_array($viewsSpec)) {
                     _elgg_services()->views->mergeViewsSpec($viewsSpec);
                 }
             }
             // find views for the custom plugin (not Elgg core)
             _elgg_services()->views->registerPluginViews($root->getPath());
         }
         if (!elgg_get_config('i18n_loaded_from_cache')) {
             _elgg_services()->translator->registerPluginTranslations($root->getPath());
         }
         // This is root directory start.php
         $root_start = $root->getPath("start.php");
         if (is_file($root_start)) {
             require $root_start;
         }
     }
     // @todo move loading plugins into a single boot function that replaces 'boot', 'system' event
     // and then move this code in there.
     // This validates the view type - first opportunity to do it is after plugins load.
     $viewtype = elgg_get_viewtype();
     if (!elgg_is_registered_viewtype($viewtype)) {
         elgg_set_viewtype('default');
     }
     $this->allowPathRewrite();
     // Allows registering handlers strictly before all init, system handlers
     $events->trigger('plugins_boot', 'system');
     // Complete the boot process for both engine and plugins
     $events->trigger('init', 'system');
     $config->set('boot_complete', true);
     // System loaded and ready
     $events->trigger('ready', 'system');
 }