123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- <?php
- define('TRIPAL_CRITICAL',2);
- define('TRIPAL_ERROR',3);
- define('TRIPAL_WARNING',4);
- define('TRIPAL_NOTICE',5);
- define('TRIPAL_INFO',6);
- define('TRIPAL_DEBUG',7);
- function tripal_report_error($type, $severity, $message, $variables = array(), $options = array()) {
-
- $severity_string = '';
- switch ($severity) {
- case TRIPAL_CRITICAL:
- $severity_string = 'CRITICAL';
- break;
- case TRIPAL_ERROR:
- $severity_string = 'ERROR';
- break;
- case TRIPAL_WARNING:
- $severity_string = 'WARNING';
- break;
- case TRIPAL_NOTICE:
- $severity_string = 'NOTICE';
- break;
- case TRIPAL_INFO:
- $severity_string = 'INFO';
- break;
- case TRIPAL_DEBUG:
- $severity_string = 'DEBUG';
- break;
- }
-
-
-
- if (getenv('TRIPAL_DEBUG') == 1) {
- $backtrace = debug_backtrace();
- $message .= "\nBacktrace:\n";
- $i = 1;
- for ($i = 1; $i < count($backtrace); $i++) {
- $function = $backtrace[$i];
- $message .= " $i) " . $function['function'] . "\n";
- }
- }
-
- try {
- watchdog($type, $message, $variables, $severity);
- }
- catch (Exception $e) {
- print "CRITICAL (TRIPAL_CORE): Unable to register error message with watchdog";
- $options['print'] = TRUE;
- }
-
- if (isset($options['print'])) {
- if (sizeof($variables) > 0) {
- $message = str_replace(array_keys($variables), $variables, $message);
- }
- print $severity_string . ' (' . strtoupper($type) . '): ' . $message . "\n";
- }
- }
- function tripal_set_message($message, $importance = TRIPAL_INFO, $options = array()) {
- global $user;
-
-
- if (!user_access('administer tripal')) {
- return '';
- }
-
- $options['return_html'] = (isset($options['return_html'])) ? $options['return_html'] : FALSE;
-
- $importance_string = '';
- switch ($importance) {
- case TRIPAL_CRITICAL:
- $importance_string = 'CRITICAL';
- break;
- case TRIPAL_ERROR:
- $importance_string = 'ERROR';
- break;
- case TRIPAL_WARNING:
- $importance_string = 'WARNING';
- break;
- case TRIPAL_NOTICE:
- $importance_string = 'NOTICE';
- break;
- case TRIPAL_INFO:
- $importance_string = 'INFO';
- break;
- case TRIPAL_DEBUG:
- $importance_string = 'DEBUG';
- break;
- }
-
- $full_message =
- '<div class="tripal-site-admin-message">'
- . '<span class="tripal-serverity-string ' . strtolower($importance_string) . '">' . $importance_string . ': </span>'
- . $message
- . '</div>';
-
-
- if ($options['return_html']) {
- return '<div class="messages tripal-site-admin-only">' . $full_message . '</div>';
- }
- else {
- drupal_set_message($full_message, 'tripal-site-admin-only');
- }
- }
|