| Commit | Line | Data |
|---|---|---|
| 647a600b TW |
1 | <?php |
| 2 | // $Id$ | |
| 3 | ||
| 4 | /** | |
| 5 | * gallery.module : gallery_report.inc | |
| 6 | * Bug report assistance (system info) | |
| 7 | */ | |
| 8 | ||
| 73fe857f TW |
9 | /** |
| 10 | * Function _gallery_report(). | |
| 11 | */ | |
| 1512ba98 | 12 | function _gallery_report($download = FALSE, $report = array(), $cache = FALSE) { |
| 647a600b TW |
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 | //Drupal | |
| 33 | $report['Drupal']['Version'] = VERSION; | |
| 34 | ||
| 35 | // Module | |
| 36 | $modules = drupal_system_listing('\.module$', 'modules', 'name', 0); | |
| 37 | system_get_files_database($modules, 'module'); | |
| 38 | foreach ($modules as $name => $module) { | |
| 39 | if (in_array($name, array('gallery', 'gallery_menu', 'gallery_content'))) { | |
| 40 | $info = _module_parse_info_file(dirname($module->filename) .'/'. $module->name .'.info'); | |
| 41 | $report['Module']['Version'][$info['name']] = array( | |
| 42 | 'Version' => $info['version'] ? $info['version'] : 'unknown', | |
| 43 | 'Schema Version' => $module->schema_version, | |
| 44 | 'Location' => dirname($module->filename), | |
| 45 | 'Status' => $module->status | |
| 46 | ); | |
| 47 | // extract detailed version info from cvsid | |
| 48 | $files = file_scan_directory(dirname($module->filename), '.*\.(inc|module)$', array('.', '..', 'CVS'), 0, FALSE); | |
| 49 | foreach ($files as $file) { | |
| 6758036d | 50 | if (preg_match('/\x24Id: '. $file->basename .',v ([^\\$]+) Exp \x24/i', file_get_contents($file->filename), $cvsid)) { |
| 588dcdb8 | 51 | $report['Module']['Version'][$info['name']]['Files'][$file->basename] = 'Rev. '. $cvsid[1]; |
| 647a600b TW |
52 | } |
| 53 | } | |
| 54 | } | |
| 55 | } | |
| b304c130 | 56 | // Fetch module-related variables |
| 647a600b TW |
57 | $result = db_query('SELECT * FROM {variable} WHERE name LIKE \'gallery_%\''); |
| 58 | while ($var = db_fetch_object($result)) { | |
| 59 | $report['Module']['Variables'][$var->name] = unserialize($var->value); | |
| 60 | } | |
| 61 | $status = gallery_get_status(); | |
| 62 | unset($status['version'], $status['gallery_valid']); | |
| 63 | $report['Module']['Variables']['gallery_status'] = array($status); | |
| 64 | ||
| 65 | // Gallery | |
| 588dcdb8 TW |
66 | if (variable_get('gallery_valid', 0) && _gallery_init(FALSE, NULL, FALSE)) { |
| 67 | $version = gallery_version(); | |
| 68 | $report['Gallery 2']['Version'] = array( | |
| 69 | 'Core API' => $version['core']['major'] .'.'. $version['core']['minor'], | |
| 70 | 'Embed API' => $version['embed']['major'] .'.'. $version['embed']['minor'], | |
| 71 | ); | |
| 09dd84ab TW |
72 | list($ret, $rewrite_api) = GalleryCoreApi::newFactoryInstance('RewriteApi'); |
| 73 | if (!$ret && $rewrite_api) { | |
| 74 | list($ret, $rewrite_params) = $rewrite_api->fetchEmbedConfig(); | |
| 588dcdb8 TW |
75 | $report['Gallery 2']['URL Rewrite'] = $rewrite_params; |
| 76 | } | |
| b304c130 | 77 | // Get some basic information about G2 plugins |
| 588dcdb8 TW |
78 | list($ret, $plugins) = GalleryCoreApi::fetchPluginStatus('module'); |
| 79 | foreach ($plugins as $name => $info) { | |
| 80 | $report['Gallery 2']['Active Plugins'][drupal_ucfirst($name)]['Version'] = $info['active'] ? $info['version'] : 'inactive'; | |
| 81 | } | |
| 647a600b | 82 | } |
| 588dcdb8 TW |
83 | else { |
| 84 | $report['Gallery 2'] = 'Gallery2 not available'; | |
| 647a600b TW |
85 | } |
| 86 | ||
| 87 | $content = theme('gallery_report', $report); | |
| 88 | ||
| 89 | if ($cache) { | |
| 36e63db1 TW |
90 | if ($cache_content = cache_get('gallery_report_'. session_id())) { |
| 91 | $content .= $cache_content->data; | |
| 92 | } | |
| 647a600b TW |
93 | cache_set('gallery_report_'. session_id(), 'cache', $content, time()+600); |
| 94 | } | |
| 95 | if ($download) { | |
| 96 | _gallery_report_download($content); | |
| 97 | } | |
| 98 | ||
| 99 | return $content; | |
| 100 | } | |
| 101 | ||
| 73fe857f TW |
102 | /** |
| 103 | * Function _gallery_report_download(). | |
| 104 | */ | |
| 647a600b TW |
105 | function _gallery_report_download($content) { |
| 106 | header("Content-Type: application/octet-stream"); | |
| 107 | header("Content-Disposition: attachment; filename=gallery_report.html"); | |
| 108 | print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; | |
| 109 | print "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"; | |
| 110 | print " <head>\n <title>". t('Gallery module : Report Generator') ."</title>\n </head>\n"; | |
| 111 | print " <body>\n ". $content ."\n</body>\n"; | |
| 112 | print "</html>"; | |
| 113 | exit(); | |
| 114 | } | |
| 115 | ||
| 73fe857f TW |
116 | /** |
| 117 | * Theme function : theme_gallery_report(). | |
| 118 | */ | |
| 647a600b TW |
119 | function theme_gallery_report($report) { |
| 120 | return ' <div><table border=1 style=\'empty-cells:hide;\'>'. _gallery_report_walk($report) ."\n".' </table></div>'; | |
| 121 | } | |
| 122 | ||
| 73fe857f TW |
123 | /** |
| 124 | * Function _gallery_report_walk(). | |
| 125 | */ | |
| 647a600b TW |
126 | function _gallery_report_walk($element, $level = 1, $sub = FALSE) { |
| 127 | $html = ''; | |
| b304c130 | 128 | $element = is_object($element) ? get_object_vars($element) : $element; |
| 647a600b TW |
129 | if (is_array($element)) { |
| 130 | foreach ($element as $key => $value) { | |
| b304c130 | 131 | if (is_array($value) || is_object($value)) { |
| 647a600b TW |
132 | $html .= "\n".' <tr>'; |
| 133 | $html .= implode('<td></td>', array_fill(0, $level, '')); | |
| 134 | $html .= '<td>'. $key .'</td>'; | |
| 135 | $html .= _gallery_report_walk($value, $level+1, TRUE); | |
| 136 | } | |
| 137 | else { | |
| 138 | $html .= $sub ? '' : "\n".' <tr>'. implode('<td></td>', array_fill(0, $level, '')); | |
| 139 | $html .= '<td>'. $key .'</td><td>'. $value .'</td>'; | |
| 140 | $html .= '</tr>'; | |
| 141 | $sub = FALSE; | |
| 142 | } | |
| 143 | } | |
| 144 | } | |
| 145 | ||
| 146 | return $html; | |
| 147 | } |