Commit 83168467 authored by profix898's avatar profix898

- task: improved debug output (part ii)

parent 06e17c81
......@@ -104,7 +104,7 @@ function _gallery_init($full = FALSE, $vars = NULL, $report_error = TRUE) {
$params['fullInit'] = $full;
// Debug output of init parameters
gallery_debug($params, t('Gallery Init'));
gallery_debug($params, t('Init parameters'));
// Check for existence of 'embed.php'
if (!$gallery_valid || !is_readable($params['g2Dir'] .'embed.php')) {
......@@ -212,6 +212,16 @@ function gallery_handle_request() {
}
}
// Catch debug output from G2
if (($pos = strpos($result['bodyHtml'], '<div id="gpDebug">')) !== FALSE) {
list($result['bodyHtml'], $suffix) = explode('<div id="gpDebug">', $result['bodyHtml']);
if ($suffix) {
list($debug, $suffix) = explode('</div>', $suffix, 2);
$result['bodyHtml'] .= $suffix;
gallery_debug($debug, t('G2 Debug Buffer'), TRUE);
}
}
return $result;
}
......@@ -450,6 +460,8 @@ function gallery_set_head($html, $settitle = FALSE) {
function gallery_set_meta($meta) {
static $meta_memory = array();
// Debug output
gallery_debug($meta, t('Head [Meta]'));
// Drupal adds these item by default already
if (empty($meta_memory)) {
$meta_memory[] = md5('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>');
......@@ -471,6 +483,9 @@ function gallery_set_css($css) {
static $css_memory = array();
if (count($css)) {
// Debug output
gallery_debug($css, t('Head [CSS]'));
// Handle css styles and includes
$css = preg_replace('/<link(.*?)href="([^"]*)"(.*?)\/>/i', '${2}', $css);
foreach ($css as $include) {
if (!in_array(($md5 = md5($include)), $css_memory)) {
......@@ -508,6 +523,9 @@ function gallery_set_javascript($javascript) {
static $js_memory = array();
if (!empty($javascript)) {
// Debug output
gallery_debug($javascript, t('Head [Javascript]'));
// Handle inline javascript and includes
$files = preg_grep('/<script(.*?)src=/i', $javascript);
// Inline Javascript
$inline = array_diff($javascript, $files);
......@@ -708,14 +726,14 @@ function _gallery_report_error($report = array()) {
/**
* Function gallery_debug().
*/
function gallery_debug($array, $label = '') {
function gallery_debug($output, $label = '', $html = FALSE) {
if (variable_get('gallery_debug', 0) && user_access('administer site configuration')) {
// Output debug log into a collapsible fieldset
$fieldset = array(
'#title' => check_plain('Gallery Debug: '. $label),
'#title' => t('Gallery Debug: '). check_plain($label),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#value' => '<pre>'. print_r($array, TRUE) .'</pre>',
'#value' => '<pre>'. ($html ? $output : htmlspecialchars(print_r($output, TRUE))) .'</pre>',
);
drupal_set_content('content', theme('fieldset', $fieldset));
}
......
......@@ -179,18 +179,20 @@ function _gallery_settings_general() {
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$debug = variable_get('gallery_debug', 0);
$form['error']['debug']['gallery_debug'] = array(
'#type' => 'checkbox',
'#title' => t('Enable debug mode'),
'#default_value' => variable_get('gallery_debug', 0),
'#default_value' => $debug,
'#description' => t('Print out debug variables and verbose error messages. Only visible to users
with \'administer site configuration\' permission.')
);
$form['error']['debug']['gallery_g2debug'] = array(
'#type' => 'checkbox',
'#title' => t('Enable G2 debug output'),
'#default_value' => variable_get('gallery_g2debug', 0),
'#description' => t('Enables Gallery2\'s buffered debug output to be displayed.')
'#default_value' => $debug && variable_get('gallery_g2debug', 0),
'#description' => t('Enables Gallery2\'s buffered debug output to be displayed.'),
'#disabled' => !$debug
);
// Relevant links
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment