Permalink
Browse files

feature(views): Allow specifying exact view paths via views.php

We use this feature to bring vendor(s) files into the views system.
This also loads jQuery UI completely asynchronously.

Fixes #6844
Fixes #8515
Fixes #8527
  • Loading branch information...
mrclay authored and ewinslow committed Jun 17, 2015
1 parent f546352 commit f3881cf400765cbd91db67afdb59b610fa5d3e84
Showing with 655 additions and 516 deletions.
  1. +13 −0 docs/conf.py
  2. +11 −1 docs/guides/upgrading.rst
  3. +233 −82 docs/guides/views.rst
  4. +2 −28 docs/info/config.php
  5. +2 −11 engine/classes/Elgg/Cache/SimpleCache.php
  6. +6 −11 engine/classes/Elgg/Cache/SystemCache.php
  7. +0 −4 engine/classes/Elgg/Database/ConfigTable.php
  8. +18 −49 engine/classes/Elgg/Debug/Inspector.php
  9. +2 −57 engine/classes/Elgg/Debug/Inspector/ViewComponent.php
  10. +211 −160 engine/classes/Elgg/ViewsService.php
  11. +1 −1 engine/classes/ElggInstaller.php
  12. +13 −1 engine/classes/ElggPlugin.php
  13. +0 −1 engine/lib/configuration.php
  14. +0 −18 engine/lib/deprecated-1.12.php
  15. +2 −2 engine/lib/deprecated-1.8.php
  16. +1 −1 engine/lib/deprecated-1.9.php
  17. +0 −14 engine/lib/elgglib.php
  18. +7 −0 engine/lib/pagehandler.php
  19. +46 −26 engine/lib/views.php
  20. +21 −4 engine/tests/phpunit/Elgg/ViewsServiceTest.php
  21. +2 −0 engine/tests/phpunit/bootstrap.php
  22. +1 −0 engine/tests/phpunit/test_files/views2/default/static.css
  23. +37 −0 engine/views.php
  24. +3 −3 mod/developers/classes/ElggInspector.php
  25. +1 −1 mod/developers/views/default/admin/develop_tools/inspect/views.php
  26. BIN vendors/elgg-colorbox-theme/{images → colorbox-images}/border1.png
  27. BIN vendors/elgg-colorbox-theme/{images → colorbox-images}/border2.png
  28. BIN vendors/elgg-colorbox-theme/{images → colorbox-images}/loading.gif
  29. +9 −9 vendors/elgg-colorbox-theme/colorbox.css
  30. +1 −1 views/default/js/elgg.php
  31. +0 −2 views/default/js/jquery-migrate.js.php
  32. +12 −0 views/default/js/jquery-ui.js.php
  33. +0 −2 views/default/js/jquery.form.js.php
  34. +0 −2 views/default/js/jquery.imgareaselect.css.php
  35. +0 −3 views/default/js/jquery.imgareaselect.js.php
  36. +0 −2 views/default/js/jquery.jeditable.js.php
  37. +0 −2 views/default/js/jquery.js.php
  38. +0 −2 views/default/js/jquery.min.map.php
  39. +0 −10 views/default/js/jquery.ui.js.php
  40. +0 −2 views/default/js/require.js.php
  41. +0 −2 views/default/js/sprintf.js.php
  42. +0 −2 views/default/js/text.js.php
View
@@ -23,6 +23,9 @@
# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
from sphinx.highlighting import lexers
from pygments.lexers.web import PhpLexer
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = []
@@ -90,6 +93,16 @@
#keep_warnings = False
# -- Elgg customizations -------------------------------------------------------
# Support parsing PHP out of <?php ?> by default
lexers['php'] = PhpLexer(startinline=True)
lexers['php-annotations'] = PhpLexer(startinline=True)
lexers['php-standalone'] = PhpLexer(startinline=True)
# use PHP as the primary domain
primary_domain = 'php'
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
View
@@ -221,11 +221,21 @@ Removed Classes
- ``FilePluginFile``: replace with ``ElggFile`` (or load with ``get_entity()``)
Removed keys available via ``elgg_get_config()``
------------------------------------------------
- ``views``
- ``viewtype``
- ``viewpath``
Also note that plugins should not be accessing the global ``$CONFIG`` variable except for in ``settings.php``.
Removed Functions
-----------------
- ``get_db_error()``
- ``elgg_get_view_location()``
- ``execute_delayed_query()``
- ``get_db_error()``
- ``get_db_link()``
- ``load_plugins()``
- ``mysql_*()``: Elgg :ref:`no longer uses ext/mysql<migrated-to-pdo>`
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -68,9 +68,9 @@
/**
* The full path for core views.
*
* @global string $CONFIG->viewpath
* @global string $CONFIG->view_path
*/
$CONFIG->viewpath;
$CONFIG->view_path;
/**
* The full path where plugins are stored.
@@ -235,32 +235,6 @@
*/
$CONFIG->menu_items_custom_items;
/**
* Holds information about views.
*
* @global object $CONFIG->views
*/
$CONFIG->views;
/**
* A list of views to cache in the simple cache.
*
* @global object $CONFIG->views->simplecache
*/
$CONFIG->views->simplecache;
/**
* A list of views and the top level views directory to search for the view in.
*
* @note Views are stored as the key and the top level view location is stored as the value.
* The current viewtype {@link $CONFIG->view} is used to determin which directory under the entry
* in $CONFIG->views->location to search. View names are automatically appened a '.php' extension.
*
* @global object $CONFIG->views->locations
*/
$CONFIG->views->locations;
/**
* A list of valid view types as discovered.
*
@@ -85,11 +85,10 @@ function getUrl($view, $subview = '') {
// handle `getUrl('js', 'blog/save_draft.js')`
if (!empty($subview)) {
$view = "$view/$subview";
$subview = '';
}
// should be normalized to canonical form by now: `getUrl('js/blog/save_draft.js')`
elgg_register_simplecache_view($view);
$this->registerView($view);
return $this->getRoot() . $view;
}
@@ -129,7 +128,7 @@ function isEnabled() {
function enable() {
_elgg_services()->datalist->set('simplecache_enabled', 1);
_elgg_services()->config->set('simplecache_enabled', 1);
elgg_invalidate_simplecache();
$this->invalidate();
}
/**
@@ -157,12 +156,6 @@ function disable() {
* @return bool
*/
function invalidate() {
if (!isset($this->CONFIG->views->simplecache) || !is_array($this->CONFIG->views->simplecache)) {
return false;
}
_elgg_rmdir("{$this->CONFIG->dataroot}views_simplecache");
mkdir("{$this->CONFIG->dataroot}views_simplecache");
@@ -179,8 +172,6 @@ function invalidate() {
* @return void
*/
function init() {
if (!defined('UPGRADING') && empty($this->CONFIG->lastcache)) {
$this->CONFIG->lastcache = (int)_elgg_services()->datalist->get('simplecache_lastupdate');
}
@@ -134,17 +134,12 @@ function disable() {
* @access private
*/
function loadAll() {
$this->CONFIG->system_cache_loaded = false;
$this->CONFIG->views = new \stdClass();
$data = $this->load('view_locations');
if (!is_string($data)) {
if (!_elgg_services()->views->configureFromCache($this)) {
return;
}
$this->CONFIG->views->locations = unserialize($data);
$data = $this->load('view_types');
if (!is_string($data)) {
return;
@@ -169,15 +164,15 @@ function init() {
// cache system data if enabled and not loaded
if (!$this->CONFIG->system_cache_loaded) {
$this->save('view_locations', serialize($this->CONFIG->views->locations));
$this->save('view_types', serialize($this->CONFIG->view_types));
// this is saved just for the inspector and is not loaded in loadAll()
$this->save('view_overrides', serialize(_elgg_services()->views->getOverriddenLocations()));
_elgg_services()->views->cacheConfiguration($this);
}
if (!$this->CONFIG->i18n_loaded_from_cache) {
_elgg_services()->translator->reloadAllTranslations();
foreach ($this->CONFIG->translations as $lang => $map) {
$this->save("$lang.lang", serialize($map));
}
@@ -132,10 +132,6 @@ function get($name, $site_guid = 0) {
// @todo might be a better spot to define this?
$new_name = false;
switch($name) {
case 'viewpath':
$new_name = 'view_path';
break;
case 'pluginspath':
$new_name = 'plugins_path';
break;
@@ -37,9 +37,7 @@ public function getPluginHooks() {
* @return string[]
*/
public function getViewtypes() {
global $CONFIG;
return array_keys($CONFIG->views->locations);
return array_keys($this->getViewsData()['locations']);
}
/**
@@ -52,38 +50,22 @@ public function getViewtypes() {
public function getViews($viewtype = 'default') {
global $CONFIG;
$overrides = null;
if ($CONFIG->system_cache_enabled) {
$data = _elgg_services()->systemCache->load('view_overrides');
if ($data) {
$overrides = unserialize($data);
}
} else {
$overrides = _elgg_services()->views->getOverriddenLocations();
}
$view_data = $this->getViewsData();
// maps view name to array of ViewComponent[] with priority as keys
$views = array();
$location = "{$CONFIG->viewpath}{$viewtype}/";
$core_file_list = $this->recurseFileTree($location);
// setup views array before adding extensions and plugin views
foreach ($core_file_list as $path) {
$component = ViewComponent::fromPaths($path, $location);
$views[$component->view] = array(500 => $component);
}
// add plugins and handle overrides
foreach ($CONFIG->views->locations[$viewtype] as $view => $location) {
foreach ($view_data['locations'][$viewtype] as $view => $location) {
$component = new ViewComponent();
$component->view = $view;
$component->location = "{$location}{$viewtype}/";
$views[$view] = array(500 => $component);
$component->file = $location;
$views[$view] = [500 => $component];
}
// now extensions
foreach ($CONFIG->views->extensions as $view => $extensions) {
foreach ($view_data['extensions'] as $view => $extensions) {
$view_list = array();
foreach ($extensions as $priority => $ext_view) {
if (isset($views[$ext_view])) {
@@ -99,13 +81,14 @@ public function getViews($viewtype = 'default') {
// now overrides
foreach ($views as $view => $view_list) {
if (!empty($overrides[$viewtype][$view])) {
if (!empty($view_data['overrides'][$viewtype][$view])) {
$overrides_list = array();
foreach ($overrides[$viewtype][$view] as $i => $location) {
foreach ($view_data['overrides'][$viewtype][$view] as $i => $location) {
$component = new ViewComponent();
$component->overridden = true;
$component->view = $view;
$component->location = "{$location}{$viewtype}/";
$component->file = $location;
$overrides_list["o:$i"] = $component;
}
$views[$view] = $overrides_list + $view_list;
@@ -376,29 +359,15 @@ protected function buildHandlerTree($all_handlers) {
}
/**
* Create array of all php files in directory and subdirectories
* Get data from the Views service
*
* @param string $dir full path to directory to begin search
* @return array of every php file in $dir or below in file tree
* @return array
*/
protected function recurseFileTree($dir) {
$view_list = array();
$handle = opendir($dir);
while ($file = readdir($handle)) {
if ($file[0] == '.') {
} else if (is_dir($dir . $file)) {
$view_list = array_merge($view_list, $this->recurseFileTree($dir . $file . "/"));
} else {
$extension = strrchr(trim($file, "/"), '.');
if ($extension === ".php") {
$view_list[] = $dir . $file;
}
}
private function getViewsData() {
static $data;
if ($data === null) {
$data = _elgg_services()->views->getInspectorData();
}
closedir($handle);
return $view_list;
return $data;
}
}
@@ -12,11 +12,6 @@
*/
class ViewComponent {
/**
* @var string View location. E.g. "/path/to/views/default/"
*/
public $location;
/**
* @var string View name. E.g. "css/elgg"
*/
@@ -33,57 +28,7 @@ class ViewComponent {
public $overridden = false;
/**
* @return string Return the component as a file path
* @var string Full file path, if available
*/
public function getFile() {
$ext = pathinfo($this->view, PATHINFO_EXTENSION);
if ($ext) {
// view is filename
return "{$this->location}{$this->view}";
}
$str = "{$this->location}{$this->view}.{$this->extension}";
if ($this->extension === null) {
// try to guess from filesystem
$files = glob("{$this->location}{$this->view}.*");
if (count($files) === 1) {
$str = $files[0];
} else {
$str = "{$this->location}{$this->view}.?";
}
}
return $str;
}
/**
* Get a component from the path and location
*
* @param string $path Full file path
* @param string $location Base location of view
*
* @return ViewComponent
*/
public static function fromPaths($path, $location) {
$component = new self();
$component->location = $location;
// cut location off
$file = substr($path, strlen($location));
$component->file = $file;
$basename = basename($file);
$period = strpos($basename, '.');
if ($period === false) {
// file with no extension? shouldn't happen
$component->view = $file;
$component->extension = '';
} else {
$cut_off_end = strlen($basename) - $period;
$component->view = substr($file, 0, -$cut_off_end);
$component->extension = substr($basename, $period + 1);
}
return $component;
}
public $file = '';
}
Oops, something went wrong.

0 comments on commit f3881cf

Please sign in to comment.