includeFile() public static method

Include a file with as little context as possible
public static includeFile ( string $file ) : mixed
$file string File to include
return mixed
Ejemplo n.º 1
0
 /**
  * Registers the plugin's views
  *
  * @throws PluginException
  * @return void
  */
 protected function registerViews()
 {
     $views = _elgg_services()->views;
     // Declared views first
     $file = "{$this->path}/views.php";
     if (is_file($file)) {
         $spec = Includer::includeFile($file);
         if (is_array($spec)) {
             $views->mergeViewsSpec($spec);
         }
     }
     $spec = $this->getStaticConfig('views');
     if ($spec) {
         $views->mergeViewsSpec($spec);
     }
     // Allow /views directory files to override
     if (!$views->registerPluginViews($this->path, $failed_dir)) {
         $key = 'ElggPlugin:Exception:CannotRegisterViews';
         $args = [$this->getID(), $this->guid, $failed_dir];
         $msg = _elgg_services()->translator->translate($key, $args);
         throw new \PluginException($msg);
     }
 }
Ejemplo n.º 2
0
 /**
  * Executes an action
  * If called from action() redirect will be issued by the response factory
  * If called as /action page handler response will be handled by \Elgg\Router
  * 
  * @param string $action    Action name
  * @param string $forwarder URL to forward to after completion
  * @return ResponseBuilder|null
  * @see action
  * @access private
  */
 public function execute($action, $forwarder = "")
 {
     $action = rtrim($action, '/');
     $this->currentAction = $action;
     // @todo REMOVE THESE ONCE #1509 IS IN PLACE.
     // Allow users to disable plugins without a token in order to
     // remove plugins that are incompatible.
     // Login and logout are for convenience.
     // file/download (see #2010)
     $exceptions = array('admin/plugins/disable', 'logout', 'file/download');
     if (!in_array($action, $exceptions)) {
         // All actions require a token.
         $pass = $this->gatekeeper($action);
         if (!$pass) {
             return;
         }
     }
     $forwarder = str_replace($this->config->getSiteUrl(), "", $forwarder);
     $forwarder = str_replace("http://", "", $forwarder);
     $forwarder = str_replace("@", "", $forwarder);
     if (substr($forwarder, 0, 1) == "/") {
         $forwarder = substr($forwarder, 1);
     }
     $ob_started = false;
     /**
      * Prepare action response
      *
      * @param string $error_key   Error message key
      * @param int    $status_code HTTP status code
      * @return ResponseBuilder
      */
     $forward = function ($error_key = '', $status_code = ELGG_HTTP_OK) use($action, $forwarder, &$ob_started) {
         if ($error_key) {
             if ($ob_started) {
                 ob_end_clean();
             }
             $msg = _elgg_services()->translator->translate($error_key, [$action]);
             _elgg_services()->systemMessages->addErrorMessage($msg);
             $response = new \Elgg\Http\ErrorResponse($msg, $status_code);
         } else {
             $content = ob_get_clean();
             $response = new \Elgg\Http\OkResponse($content, $status_code);
         }
         $forwarder = empty($forwarder) ? REFERER : $forwarder;
         $response->setForwardURL($forwarder);
         return $response;
     };
     if (!isset($this->actions[$action])) {
         return $forward('actionundefined', ELGG_HTTP_NOT_IMPLEMENTED);
     }
     $user = $this->session->getLoggedInUser();
     // access checks
     switch ($this->actions[$action]['access']) {
         case 'public':
             break;
         case 'logged_in':
             if (!$user) {
                 return $forward('actionloggedout', ELGG_HTTP_FORBIDDEN);
             }
             break;
         default:
             // admin or misspelling
             if (!$user || !$user->isAdmin()) {
                 return $forward('actionunauthorized', ELGG_HTTP_FORBIDDEN);
             }
     }
     ob_start();
     // To quietly cancel the file, return a falsey value in the "action" hook.
     if (!_elgg_services()->hooks->trigger('action', $action, null, true)) {
         return $forward('', ELGG_HTTP_OK);
     }
     $file = $this->actions[$action]['file'];
     if (!is_file($file) || !is_readable($file)) {
         return $forward('actionnotfound', ELGG_HTTP_NOT_IMPLEMENTED);
     }
     $result = Includer::includeFile($file);
     if ($result instanceof ResponseBuilder) {
         ob_end_clean();
         return $result;
     }
     return $forward('', ELGG_HTTP_OK);
 }
Ejemplo n.º 3
0
Archivo: views.php Proyecto: elgg/elgg
/**
 * Initialize viewtypes on system boot event
 * This ensures simplecache is cleared during upgrades. See #2252
 *
 * @return void
 * @access private
 * @elgg_event_handler boot system
 */
function elgg_views_boot()
{
    global $CONFIG;
    if (!elgg_get_config('system_cache_loaded')) {
        // Core view files in /views
        _elgg_services()->views->registerPluginViews(realpath(__DIR__ . '/../../'));
        // Core view definitions in /engine/views.php
        $file = dirname(__DIR__) . '/views.php';
        if (is_file($file)) {
            $spec = Includer::includeFile($file);
            if (is_array($spec)) {
                _elgg_services()->views->mergeViewsSpec($spec);
            }
        }
    }
    // on every page
    // jQuery and UI must come before require. See #9024
    elgg_register_js('jquery', elgg_get_simplecache_url('jquery.js'), 'head');
    elgg_load_js('jquery');
    elgg_register_js('jquery-ui', elgg_get_simplecache_url('jquery-ui.js'), 'head');
    elgg_load_js('jquery-ui');
    elgg_register_js('elgg.require_config', elgg_get_simplecache_url('elgg/require_config.js'), 'head');
    elgg_load_js('elgg.require_config');
    elgg_register_js('require', elgg_get_simplecache_url('require.js'), 'head');
    elgg_load_js('require');
    elgg_register_js('elgg', elgg_get_simplecache_url('elgg.js'), 'head');
    elgg_load_js('elgg');
    elgg_register_css('font-awesome', elgg_get_simplecache_url('font-awesome/css/font-awesome.css'));
    elgg_load_css('font-awesome');
    elgg_register_css('elgg', elgg_get_simplecache_url('elgg.css'));
    elgg_load_css('elgg');
    elgg_register_simplecache_view('elgg/init.js');
    elgg_register_css('lightbox', elgg_get_simplecache_url('lightbox/elgg-colorbox-theme/colorbox.css'));
    elgg_load_css('lightbox');
    elgg_define_js('jquery.ui.autocomplete.html', ['deps' => ['jquery-ui']]);
    elgg_register_js('elgg.friendspicker', elgg_get_simplecache_url('elgg/ui.friends_picker.js'));
    elgg_register_js('elgg.avatar_cropper', elgg_get_simplecache_url('elgg/ui.avatar_cropper.js'));
    // @deprecated 2.2
    elgg_register_js('elgg.ui.river', elgg_get_simplecache_url('elgg/ui.river.js'));
    elgg_register_js('jquery.imgareaselect', elgg_get_simplecache_url('jquery.imgareaselect.js'));
    elgg_register_css('jquery.imgareaselect', elgg_get_simplecache_url('jquery.imgareaselect.css'));
    elgg_register_ajax_view('languages.js');
    elgg_register_plugin_hook_handler('simplecache:generate', 'js', '_elgg_views_amd');
    elgg_register_plugin_hook_handler('simplecache:generate', 'css', '_elgg_views_minify');
    elgg_register_plugin_hook_handler('simplecache:generate', 'js', '_elgg_views_minify');
    elgg_register_plugin_hook_handler('output:before', 'page', '_elgg_views_send_header_x_frame_options');
    // registered with high priority for BC
    // prior to 2.2 registration used to take place in _elgg_views_prepare_head() before the hook was triggered
    elgg_register_plugin_hook_handler('head', 'page', '_elgg_views_prepare_favicon_links', 1);
    // @todo the cache is loaded in load_plugins() but we need to know viewtypes earlier
    $view_path = _elgg_services()->views->view_path;
    $viewtype_dirs = scandir($view_path);
    foreach ($viewtype_dirs as $viewtype) {
        if (_elgg_is_valid_viewtype($viewtype) && is_dir($view_path . $viewtype)) {
            elgg_register_viewtype($viewtype);
        }
    }
    // set default icon sizes - can be overridden in settings.php or with plugin
    if (!isset($CONFIG->icon_sizes)) {
        $icon_sizes = array('topbar' => array('w' => 16, 'h' => 16, 'square' => true, 'upscale' => true), 'tiny' => array('w' => 25, 'h' => 25, 'square' => true, 'upscale' => true), 'small' => array('w' => 40, 'h' => 40, 'square' => true, 'upscale' => true), 'medium' => array('w' => 100, 'h' => 100, 'square' => true, 'upscale' => true), 'large' => array('w' => 200, 'h' => 200, 'square' => false, 'upscale' => false), 'master' => array('w' => 550, 'h' => 550, 'square' => false, 'upscale' => false));
        elgg_set_config('icon_sizes', $icon_sizes);
    }
    // Patches and features that were included between major releases
    // sometimes require additional styling, but adding them to core CSS files
    // is not always feasible, because those can be replaced by themes.
    // @todo Remove in 3.0
    elgg_extend_view('elgg.css', 'elements/pathces.css');
    elgg_extend_view('admin.css', 'elements/pathces.css');
}