[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/gallery/ -> gallery_report.inc (source)

   1  <?php
   2  // $Id: gallery_report.inc,v 1.3.2.6 2008/06/14 20:16:17 profix898 Exp $
   3  
   4  /**
   5   * gallery.module : gallery_report.inc
   6   * Bug report assistance (system info)
   7   */
   8  
   9  /**
  10   * Function _gallery_report().
  11   */
  12  function _gallery_report($download = FALSE, $report = array(), $cache = FALSE) {
  13    // provide download of the cached report
  14    if ($download && ($content = cache_get('gallery:report_'. session_id()))) {
  15      _gallery_report_download($content->data);
  16    }
  17    
  18    //System
  19    global $db_url;
  20    $report['System']['PHP']['Version'] = phpversion();
  21    $report['System']['PHP']['Memory limit'] = ini_get('memory_limit');
  22    $report['System']['PHP']['Safe mode'] = ini_get('safe_mode') ? 'On' : 'Off';  
  23    $database = is_array($db_url) ? $db_url : array('default' => $db_url);
  24    foreach ($database as $key => $value) {
  25      db_set_active($key);
  26      $db_info = parse_url($value);
  27      $report['System']['Database'][drupal_ucfirst($key)]['Type'] =  urldecode(strtoupper($db_info['scheme']));
  28      $report['System']['Database'][drupal_ucfirst($key)]['Version'] = db_version();
  29    }
  30    db_set_active('default');
  31    
  32    //Request
  33    $report['Request']['URI'] = request_uri();
  34    $report['Request']['Query'] = isset($_GET['q']) ? $_GET['q'] : '';
  35    $report['Request']['G2Path'] = isset($_GET['g2_path']) ? $_GET['g2_path'] : '';
  36    $report['Request']['Referer'] = referer_uri();
  37    
  38    //Drupal
  39    $report['Drupal']['Version'] = VERSION;
  40    
  41    // Module
  42    $modules = drupal_system_listing('\.module$', 'modules', 'name', 0);
  43    system_get_files_database($modules, 'module');
  44    foreach ($modules as $name => $module) {
  45      if (preg_match('/^gallery$|^gallery_/', $name)) {
  46        $info = drupal_parse_info_file(dirname($module->filename) .'/'. $module->name .'.info');
  47        $report['Module']['Version'][$info['name']] = array(
  48          'Version' => isset($info['version']) ? $info['version'] : 'unknown',
  49          'Schema Version' => $module->schema_version,
  50          'Location' => dirname($module->filename),
  51          'Status' => $module->status
  52        );
  53        // extract detailed version info from cvsid
  54        $files = file_scan_directory(dirname($module->filename), '.*\.(inc|module)$', array('.', '..', 'CVS'), 0, FALSE);
  55        foreach ($files as $file) {
  56          if (preg_match('/\x24Id: '. $file->basename .',v ([^\\$]+) Exp \x24/i', file_get_contents($file->filename), $cvsid)) {
  57            $report['Module']['Version'][$info['name']]['Files'][$file->basename] = 'Rev. '. $cvsid[1];
  58          }
  59        }
  60      }
  61    }
  62    // Fetch module-related variables
  63    $result = db_query('SELECT * FROM {variable} WHERE name LIKE \'gallery_%\'');
  64    while ($var = db_fetch_object($result)) {
  65      $report['Module']['Variables'][$var->name] = unserialize($var->value);
  66    }
  67    $status = gallery_get_status();
  68    unset($status['version'], $status['gallery_valid']);
  69    $report['Module']['Variables']['gallery_status'] = array($status);
  70    
  71    // Gallery
  72    if (variable_get('gallery_valid', 0) && _gallery_init(FALSE, NULL, FALSE)) {
  73      $version = gallery_version();
  74      $report['Gallery 2']['Version'] = array(
  75        'Core API' => $version['core']['major'] .'.'. $version['core']['minor'],
  76        'Embed API' => $version['embed']['major'] .'.'. $version['embed']['minor'],
  77      );
  78      list($ret, $rewrite_api) = GalleryCoreApi::newFactoryInstance('RewriteApi');
  79      if (!$ret && $rewrite_api) {
  80        list($ret, $rewrite_params) = $rewrite_api->fetchEmbedConfig();
  81        $report['Gallery 2']['URL Rewrite'] = $rewrite_params;
  82      }
  83      // Get some basic information about G2 plugins
  84      list($ret, $plugins) = GalleryCoreApi::fetchPluginStatus('module');
  85      foreach ($plugins as $name => $info) {
  86        $report['Gallery 2']['Active Plugins'][drupal_ucfirst($name)]['Version'] = isset($info['active']) ? $info['version'] : 'inactive';
  87      }
  88      // Debug Logs
  89      if ($GLOBALS['gallery']->_debug == 'buffered' && !empty($GLOBALS['gallery']->_debugBuffer)) {
  90        $report['Gallery 2']['DebugBuffer'] = $GLOBALS['gallery']->_debugBuffer;
  91      }
  92      else if (!empty($GLOBALS['gallery']->_debugSnippet)) {
  93        $report['Gallery 2']['DebugSnippet'] = $GLOBALS['gallery']->_debugSnippet;
  94      }
  95    }
  96    else {
  97      $report['Gallery 2'] = 'Gallery2 not available';
  98    }
  99    
 100    $content = theme('gallery_report', $report);
 101    
 102    if ($cache) {
 103      if ($cache_content = cache_get('gallery:report_'. session_id())) {
 104        $content .= $cache_content->data;
 105      }
 106      cache_set('gallery:report_'. session_id(), $content, 'cache', time()+600);
 107    }
 108    if ($download) {
 109      _gallery_report_download($content);
 110    }
 111    
 112    return $content;
 113  }
 114  
 115  /**
 116   * Function _gallery_report_download().
 117   */
 118  function _gallery_report_download($content) {
 119    header("Content-Type: application/octet-stream");
 120    header("Content-Disposition: attachment; filename=gallery_report.html");
 121    print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
 122    print "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n";
 123    print " <head>\n  <title>". t('Gallery module : Report Generator') ."</title>\n </head>\n";
 124    print " <body>\n ". $content ."\n</body>\n";
 125    print "</html>";
 126    exit();
 127  }
 128  
 129  /**
 130   * Theme function : theme_gallery_report().
 131   */
 132  function theme_gallery_report($report) {
 133    return '  <div><table border=1 style=\'empty-cells:hide;\'>'. _gallery_report_walk($report) ."\n".'  </table></div>';
 134  }
 135  
 136  /**
 137   * Function _gallery_report_walk().
 138   */
 139  function _gallery_report_walk($element, $level = 1, $sub = FALSE) {
 140    $html = '';
 141    $element = is_object($element) ? get_object_vars($element) : $element;
 142    if (is_array($element)) {
 143      foreach ($element as $key => $value) {
 144        if (is_array($value) || is_object($value)) {
 145          $html .= "\n".'    <tr>';
 146          $html .= implode('<td></td>', array_fill(0, $level, ''));
 147          $html .= '<td>'. $key .'</td>';
 148          $html .= _gallery_report_walk($value, $level+1, TRUE);
 149        }
 150        else {
 151          $html .= $sub ? '' : "\n".'    <tr>'. implode('<td></td>', array_fill(0, $level, ''));
 152          $html .= '<td>'. $key .'</td><td>'. $value .'</td>'; 
 153          $html .= '</tr>';
 154          $sub = FALSE;
 155        }
 156      }
 157    }  
 158    
 159    return $html;
 160  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7