diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2014-03-15 14:42:42 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2014-03-15 14:42:42 -0300 |
commit | 551497ef94f6239b109316d8fab32f0909b13f73 (patch) | |
tree | 236615e9881988ce05f40583ff891bf0fcef2c14 /start.php | |
download | elgg-551497ef94f6239b109316d8fab32f0909b13f73.tar.gz elgg-551497ef94f6239b109316d8fab32f0909b13f73.tar.bz2 |
Squashed 'mod/less/' content from commit 380edad
git-subtree-dir: mod/less
git-subtree-split: 380edadb3a5e524a8e6ef6df063b678f2f00516f
Diffstat (limited to 'start.php')
-rw-r--r-- | start.php | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/start.php b/start.php new file mode 100644 index 000000000..476ad5104 --- /dev/null +++ b/start.php @@ -0,0 +1,104 @@ +<?php +/** + * Elgg LESS compiler + * + * @package ElggLESS + */ + +elgg_register_event_handler('init', 'system', 'less_init'); + +function less_init() { + + less_override_css(); + + //make sure this runs after everyone else is done + elgg_register_plugin_hook_handler('view', 'all', 'less_views', 999); +} + +function less_views($hook, $type, $content, $params) { + $view = $params['view']; + $vars = $params['vars']; + + if (preg_match("/^css\//", $view) && !$vars['less_flag']) { + global $CONFIG; + if ($CONFIG->less->view[$view]) { + $vars['less_flag'] = true; + $content = elgg_view($CONFIG->less->view[$view], $vars); + } + } + + if (preg_match("/^less\//", $view) && $vars['less_flag']) { + if (include_once(elgg_get_plugins_path() . 'less/vendors/lessphp/lessc.inc.php')) { + $parser = new lessc(); + return $parser->parse($content); + } + } + return $content; +} + +function less_override_css() { + $plugins = elgg_get_plugins('active'); + if ($plugins) { + foreach ($plugins as $plugin) { + $view_dir = elgg_get_plugins_path() . $plugin->getID() . "/views/"; + + if (!is_dir($view_dir) || FALSE === ($handle = opendir($view_dir))) { + continue; + } + + while (FALSE !== ($view_type = readdir($handle))) { + $view_type_dir = $view_dir . $view_type; + + if ('.' !== substr($view_type, 0, 1) && is_dir($view_type_dir)) { + less_autoregister_views('', $view_type_dir, $view_dir, $view_type); + } + } + } + } +} + +function less_autoregister_views($view_base, $folder, $base_location_path, $viewtype) { + if (!empty($view_base)) { + $view_base_new = $view_base . "/"; + } else { + $view_base_new = ""; + } + + if ($handle = opendir($folder)) { + while ($view = readdir($handle)) { + if (!in_array($view, array('.', '..', '.svn', 'CVS')) && !is_dir($folder . "/" . $view)) { + if (substr_count($view, ".php") > 0) { + less_update_view($view_base_new . str_replace('.php', '', $view)); + } + } else if (!in_array($view, array('.', '..', '.svn', 'CVS')) && is_dir($folder . "/" . $view)) { + if ($view == 'css' || $view == 'less') { + less_autoregister_views($view_base_new . $view, $folder . "/" . $view, + $base_location_path, $viewtype); + } + } + } + return TRUE; + } + return FALSE; +} + +function less_update_view($view) { + global $CONFIG; + + if (substr($view, 0, 5) == "less/") { + $css_view = substr($view, 5); + } else { + $css_view = $view; + } + + if (!isset($CONFIG->less)) { + $CONFIG->less = new stdClass; + } + + if (!isset($CONFIG->less->view)) { + $CONFIG->less->view = array($css_view => $view); + + } else { + $CONFIG->less->view[$css_view] = $view; + } +} |