]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #3152 adds wrapping of views with comments
authorcash <cash.costello@gmail.com>
Sat, 2 Jul 2011 23:51:22 +0000 (19:51 -0400)
committercash <cash.costello@gmail.com>
Sat, 2 Jul 2011 23:51:22 +0000 (19:51 -0400)
mod/developers/actions/developers/settings.php
mod/developers/languages/en.php
mod/developers/start.php
mod/developers/views/default/admin/developers/settings.php

index 5a7f97cd3163b1f0b53942314efba4a0f1d9187c..f7caf859db5c70e689c1c54ab812e39e92326897 100644 (file)
@@ -24,7 +24,7 @@ if ($debug) {
        unset_config('debug', $site->getGUID());
 }
 
-$simple_settings = array('display_errors', 'screen_log', 'show_strings');
+$simple_settings = array('display_errors', 'screen_log', 'show_strings', 'wrap_views');
 foreach ($simple_settings as $setting) {
        elgg_set_plugin_setting($setting, get_input($setting), 'developers');
 }
index 827eb6ba3dafaada70a6c3fd09ef3a798cefcfec..a20241effb4610e9fab1c85e6315160bffcd1f2e 100644 (file)
@@ -25,6 +25,8 @@ $english = array(
        'developers:help:screen_log' => "This displays elgg_log() and elgg_dump() output on the web page.",
        'developers:label:show_strings' => "Show raw translation strings",
        'developers:help:show_strings' => "This displays the translation strings used by elgg_echo().",
+       'developers:label:wrap_views' => "Wrap views",
+       'developers:help:wrap_views' => "This wraps almost every view with HTML comments. Useful for finding the view creating particular HTML.",
 
        'developers:debug:off' => 'Off',
        'developers:debug:error' => 'Error',
index b864bca1e1a2286cb3d9dc543a500e4eff33bd88..27a14b336f0bdde8037106ef1eb647b2284cfc9c 100644 (file)
@@ -43,8 +43,12 @@ function developers_process_settings() {
 
        if (elgg_get_plugin_setting('show_strings', 'developers') == 1) {
                // first and last in case a plugin registers a translation in an init method
-               register_elgg_event_handler('init', 'system', 'developers_clear_strings', 1000);
-               register_elgg_event_handler('init', 'system', 'developers_clear_strings', 1);
+               elgg_register_event_handler('init', 'system', 'developers_clear_strings', 1000);
+               elgg_register_event_handler('init', 'system', 'developers_clear_strings', 1);
+       }
+
+       if (elgg_get_plugin_setting('wrap_views', 'developers') == 1) {
+               register_plugin_hook('view', 'all', 'developers_wrap_views');
        }
 }
 
@@ -67,6 +71,40 @@ function developers_clear_strings() {
        $CONFIG->translations['en'] = array();
 }
 
+/**
+ * Post-process a view to add wrapper comments to it
+ */
+function developers_wrap_views($hook, $type, $result, $params) {
+       if (elgg_get_viewtype() != "default") {
+               return;
+       }
+
+       $excluded_bases = array('css', 'js', 'input', 'output', 'embed', 'icon',);
+
+       $excluded_views = array(
+               'page/default',
+               'page/admin',
+               'page/elements/head',
+       );
+
+       $view = $params['view'];
+
+       $view_hierarchy = explode('/',$view);
+       if (in_array($view_hierarchy[0], $excluded_bases)) {
+               return;
+       }
+
+       if (in_array($view, $excluded_views)) {
+               return;
+       }
+
+       if ($result) {
+               $result = "<!-- developers:begin $view -->$result<!-- developers:end $view -->";
+       }
+
+       return $result;
+}
+
 /**
  * Serve the theme preview pages
  *
index a1ae6c1866f01be35c90246e20f39c9c22b0b06d..d463955b6523d2ecb7d3d1d211b212ef2dd848e9 100644 (file)
@@ -44,6 +44,12 @@ $data = array(
                'value' => 1,
                'checked' => elgg_get_plugin_setting('show_strings', 'developers') == 1,
        ),
+
+       'wrap_views' => array(
+               'type' => 'checkbox',
+               'value' => 1,
+               'checked' => elgg_get_plugin_setting('wrap_views', 'developers') == 1,
+       ),
 );
 
 $form_vars = array('id' => 'developer-settings-form');