public static function processArguments()
 {
     if (self::$_provided_arguments == null) {
         self::$_provided_arguments = array();
         foreach ($GLOBALS['argv'] as $cc => $argument) {
             self::$_provided_arguments[$cc] = $argument;
             $argument_parts = explode('=', $argument, 2);
             if (count($argument_parts) == 2) {
                 $key = substr($argument_parts[0], 2);
                 self::$_provided_arguments[$key] = $argument_parts[1];
                 if (!is_numeric($key)) {
                     self::$_named_arguments[$key] = $argument_parts[1];
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Log a message to the logger
  *
  * @param string $message The message to log
  * @param string $category[optional] The message category (default "main")
  * @param integer $level[optional] The loglevel
  */
 public static function log($message, $category = 'main', $level = 1)
 {
     if (!self::$_logging_enabled) {
         return false;
     }
     if (self::$_loglevel > $level) {
         return false;
     }
     if (self::$_cli_log_to_screen_in_debug_mode && TBGContext::isCLI() && TBGContext::isDebugMode() && class_exists('TBGCliCommand')) {
         TBGCliCommand::cli_echo(mb_strtoupper(self::getLevelName($level)), 'white', 'bold');
         TBGCliCommand::cli_echo(" [{$category}] ", 'green', 'bold');
         TBGCliCommand::cli_echo("{$message}\n");
     }
     if (self::$_logonajaxcalls || TBGContext::getRequest()->isAjaxCall()) {
         if (self::$_logfile !== null) {
             file_put_contents(self::$_logfile, mb_strtoupper(self::getLevelName($level)) . " [{$category}] {$message}\n", FILE_APPEND);
         }
         $time_msg = TBGContext::isDebugMode() ? ($load_time = TBGContext::getLoadtime()) >= 1 ? round($load_time, 2) . ' seconds' : round($load_time * 1000, 3) . ' ms' : '';
         self::$_entries[] = array('category' => $category, 'time' => $time_msg, 'message' => $message, 'level' => $level);
         self::$_categorized_entries[$category][] = array('time' => $time_msg, 'message' => $message, 'level' => $level);
     }
 }
Ejemplo n.º 3
0
 /**
  * Log a message to the logger
  *
  * @param string $message The message to log
  * @param string $category[optional] The message category (default "main")
  * @param integer $level[optional] The loglevel
  */
 public static function log($message, $category = 'main', $level = 1)
 {
     Caspar::ping();
     if (!self::$_logging_enabled) {
         return false;
     }
     if (self::$_loglevel > $level) {
         return false;
     }
     if (self::$_cli_log_to_screen_in_debug_mode && Caspar::isCLI() && Caspar::isDebugMode() && class_exists('TBGCliCommand')) {
         TBGCliCommand::cli_echo(mb_strtoupper(self::getLevelName($level)), 'white', 'bold');
         TBGCliCommand::cli_echo(" [{$category}] ", 'green', 'bold');
         TBGCliCommand::cli_echo("{$message}\n");
     }
     if (self::$_logonajaxcalls || !(isset($_SERVER["HTTP_X_REQUESTED_WITH"]) || isset($_SERVER["HTTP_X_REQUESTED_WITH"]) && $_SERVER["HTTP_X_REQUESTED_WITH"] == '')) {
         if (self::$_logfile !== null) {
             file_put_contents(self::$_logfile, mb_strtoupper(self::getLevelName($level)) . " [{$category}] {$message}\n", FILE_APPEND);
         }
         $time_msg = ($load_time = Caspar::getLoadtime()) >= 1 ? round($load_time, 2) . ' seconds' : round($load_time * 1000, 3) . ' ms';
         self::$_entries[] = array('category' => $category, 'time' => $time_msg, 'message' => $message, 'level' => $level);
         self::$_categorized_entries[$category][] = array('time' => $time_msg, 'message' => $message, 'level' => $level);
     }
 }
Ejemplo n.º 4
0
 public function loadArticles($namespace = '', $overwrite = true, $scope = null)
 {
     $scope = TBGContext::getScope()->getID();
     $namespace = strtolower($namespace);
     $_path_handle = opendir(THEBUGGENIE_MODULES_PATH . 'publish' . DS . 'fixtures' . DS);
     while ($original_article_name = readdir($_path_handle)) {
         if (strpos($original_article_name, '.') === false) {
             $article_name = strtolower($original_article_name);
             $imported = false;
             $import = false;
             if ($namespace) {
                 if (strpos(urldecode($article_name), "{$namespace}:") === 0 || strpos(urldecode($article_name), "category:") === 0 && strpos(urldecode($article_name), "{$namespace}:") === 9) {
                     $import = true;
                 }
             } else {
                 if (strpos(urldecode($article_name), "category:help:") === 0) {
                     $name_test = substr(urldecode($article_name), 14);
                 } elseif (strpos(urldecode($article_name), "category:") === 0) {
                     $name_test = substr(urldecode($article_name), 9);
                 } else {
                     $name_test = urldecode($article_name);
                 }
                 if (strpos($name_test, ':') === false) {
                     $import = true;
                 }
             }
             if ($import) {
                 if (TBGContext::isCLI()) {
                     TBGCliCommand::cli_echo('Saving ' . urldecode($original_article_name) . "\n");
                 }
                 if ($overwrite) {
                     TBGArticlesTable::getTable()->deleteArticleByName(urldecode($original_article_name));
                 }
                 if (TBGArticlesTable::getTable()->getArticleByName(urldecode($original_article_name)) === null) {
                     $content = file_get_contents(THEBUGGENIE_MODULES_PATH . 'publish' . DS . 'fixtures' . DS . $original_article_name);
                     TBGWikiArticle::createNew(urldecode($original_article_name), $content, true, $scope, array('overwrite' => $overwrite, 'noauthor' => true));
                     $imported = true;
                 }
                 TBGEvent::createNew('publish', 'fixture_article_loaded', urldecode($original_article_name), array('imported' => $imported))->trigger();
             }
         }
     }
 }
Ejemplo n.º 5
0
 public function do_execute()
 {
     $this->cliEcho("The Bug Genie CLI help\n", 'white', 'bold');
     if ($this->hasProvidedArgument(2)) {
         $module_command = explode(':', $this->getProvidedArgument(2));
         $module_name = count($module_command) == 2 ? $module_command[0] : 'main';
         $command = count($module_command) == 2 ? $module_command[1] : $module_command[0];
         $commands = self::getAvailableCommands();
         if (array_key_exists($module_name, $commands) && array_key_exists($command, $commands[$module_name])) {
             $this->cliEcho("\n");
             $class = $commands[$module_name][$command];
             $this->cliEcho("Usage: ", 'white', 'bold');
             $this->cliEcho(TBGCliCommand::getCommandLineName() . " ");
             if ($module_name != 'main') {
                 $this->cliEcho($module_name . ':', 'green', 'bold');
             }
             $this->cliEcho($class->getCommandName() . " ", 'green', 'bold');
             $hasArguments = false;
             foreach ($class->getRequiredArguments() as $argument => $description) {
                 $this->cliEcho($argument . ' ', 'magenta', 'bold');
                 $hasArguments = true;
             }
             foreach ($class->getOptionalArguments() as $argument => $description) {
                 $this->cliEcho('[' . $argument . '] ', 'magenta');
                 $hasArguments = true;
             }
             $this->cliEcho("\n");
             $this->cliEcho($class->getDescription(), 'white', 'bold');
             $this->cliEcho("\n\n");
             if ($hasArguments) {
                 $this->cliEcho("Argument descriptions:\n", 'white', 'bold');
                 foreach ($class->getRequiredArguments() as $argument => $description) {
                     $this->cliEcho("  {$argument}", 'magenta', 'bold');
                     if ($description != '') {
                         $this->cliEcho(" - {$description}");
                     } else {
                         $this->cliEcho(" - No description provided");
                     }
                     $this->cliEcho("\n");
                 }
                 foreach ($class->getOptionalArguments() as $argument => $description) {
                     $this->cliEcho("  [{$argument}]", 'magenta');
                     if ($description != '') {
                         $this->cliEcho(" - {$description}");
                     } else {
                         $this->cliEcho(" - No description provided");
                     }
                     $this->cliEcho("\n");
                 }
                 $this->cliEcho("\n");
                 $this->cliEcho("Parameters must be passed either in the order described above\nor in the following format:\n");
                 $this->cliEcho("--parameter_name=value", 'magenta');
                 $this->cliEcho("\n\n");
             }
         } else {
             $this->cliEcho("\n");
             $this->cliEcho("Unknown command\n", 'red', 'bold');
             $this->cliEcho("Type " . TBGCliCommand::getCommandLineName() . ' ', 'white', 'bold');
             $this->cliEcho('help', 'green', 'bold');
             $this->cliEcho(" for more information about the cli tool.\n\n");
         }
     } else {
         $this->cliEcho("Below is a list of available commands:\n");
         $this->cliEcho("Type ");
         $this->cliEcho(TBGCliCommand::getCommandLineName() . ' ', 'white', 'bold');
         $this->cliEcho('help', 'green', 'bold');
         $this->cliEcho(' command', 'magenta');
         $this->cliEcho(" for more information about a specific command.\n\n");
         $commands = $this->getAvailableCommands();
         foreach ($commands as $module_name => $module_commands) {
             if ($module_name != 'main' && count($module_commands) > 0) {
                 $this->cliEcho("\n{$module_name}:\n", 'green', 'bold');
             }
             ksort($module_commands, SORT_STRING);
             foreach ($module_commands as $command_name => $command) {
                 if ($module_name != 'main') {
                     $this->cliEcho("  ");
                 }
                 $this->cliEcho("{$command_name}", 'green', 'bold');
                 $this->cliEcho(" - {$command->getDescription()}\n");
             }
             if (count($commands) > 1 && $module_name == 'remote') {
                 $this->cliEcho("\nModule commands, use ");
                 $this->cliEcho("module_name:command_name", 'green');
                 $this->cliEcho(" to run:");
             }
         }
         $this->cliEcho("\n");
     }
 }
Ejemplo n.º 6
0
 protected function _setup()
 {
     $this->_command_name = 'list_scopes';
     $this->_description = "List available scopes";
     parent::_setup();
 }
Ejemplo n.º 7
0
/**
 * Displays a nicely formatted exception message
 *  
 * @param string $title
 * @param Exception $exception
 */
function tbg_exception($title, $exception)
{
    if (TBGContext::getRequest() instanceof TBGRequest && TBGContext::getRequest()->isAjaxCall()) {
        TBGContext::getResponse()->ajaxResponseText(404, $title);
    }
    $ob_status = ob_get_status();
    if (!empty($ob_status) && $ob_status['status'] != PHP_OUTPUT_HANDLER_END) {
        ob_end_clean();
    }
    if (TBGContext::isCLI()) {
        $trace_elements = null;
        if ($exception instanceof Exception) {
            if ($exception instanceof TBGActionNotFoundException) {
                TBGCliCommand::cli_echo("Could not find the specified action\n", 'white', 'bold');
            } elseif ($exception instanceof TBGTemplateNotFoundException) {
                TBGCliCommand::cli_echo("Could not find the template file for the specified action\n", 'white', 'bold');
            } elseif ($exception instanceof B2DBException) {
                TBGCliCommand::cli_echo("An exception was thrown in the B2DB framework\n", 'white', 'bold');
            } else {
                TBGCliCommand::cli_echo("An unhandled exception occurred:\n", 'white', 'bold');
            }
            echo TBGCliCommand::cli_echo($exception->getMessage(), 'red', 'bold') . "\n";
            echo "\n";
            TBGCliCommand::cli_echo('Stack trace') . ":\n";
            $trace_elements = $exception->getTrace();
        } else {
            if ($exception['code'] == 8) {
                TBGCliCommand::cli_echo('The following notice has stopped further execution:', 'white', 'bold');
            } else {
                TBGCliCommand::cli_echo('The following error occured:', 'white', 'bold');
            }
            echo "\n";
            echo "\n";
            TBGCliCommand::cli_echo($title, 'red', 'bold');
            echo "\n";
            TBGCliCommand::cli_echo("occured in\n");
            TBGCliCommand::cli_echo($exception['file'] . ', line ' . $exception['line'], 'blue', 'bold');
            echo "\n";
            echo "\n";
            TBGCliCommand::cli_echo("Backtrace:\n", 'white', 'bold');
            $trace_elements = debug_backtrace();
        }
        foreach ($trace_elements as $trace_element) {
            if (array_key_exists('class', $trace_element)) {
                TBGCliCommand::cli_echo($trace_element['class'] . $trace_element['type'] . $trace_element['function'] . '()');
            } elseif (array_key_exists('function', $trace_element)) {
                if (in_array($trace_element['function'], array('tbg_error_handler', 'tbg_exception'))) {
                    continue;
                }
                TBGCliCommand::cli_echo($trace_element['function'] . '()');
            } else {
                TBGCliCommand::cli_echo('unknown function');
            }
            echo "\n";
            if (array_key_exists('file', $trace_element)) {
                TBGCliCommand::cli_echo($trace_element['file'] . ', line ' . $trace_element['line'], 'blue', 'bold');
            } else {
                TBGCliCommand::cli_echo('unknown file', 'red', 'bold');
            }
            echo "\n";
        }
        if (class_exists('B2DB')) {
            echo "\n";
            TBGCliCommand::cli_echo("SQL queries:\n", 'white', 'bold');
            try {
                $cc = 1;
                foreach (B2DB::getSQLHits() as $details) {
                    TBGCliCommand::cli_echo("(" . $cc++ . ") [");
                    $str = $details['time'] >= 1 ? round($details['time'], 2) . ' seconds' : round($details['time'] * 1000, 1) . 'ms';
                    TBGCliCommand::cli_echo($str);
                    TBGCliCommand::cli_echo("] from ");
                    TBGCliCommand::cli_echo($details['filename'], 'blue');
                    TBGCliCommand::cli_echo(", line ");
                    TBGCliCommand::cli_echo($details['line'], 'white', 'bold');
                    TBGCliCommand::cli_echo(":\n");
                    TBGCliCommand::cli_echo("{$details['sql']}\n");
                }
                echo "\n";
            } catch (Exception $e) {
                TBGCliCommand::cli_echo("Could not generate query list (there may be no database connection)", "red", "bold");
            }
        }
        echo "\n";
        die;
    }
    echo "\n\t\t<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n\t\t<html>\n\t\t<head>\n\t\t<style>\n\t\tbody { background-color: #DFDFDF; font-family: \"Droid Sans\", \"Trebuchet MS\", \"Liberation Sans\", \"Nimbus Sans L\", \"Luxi Sans\", Verdana, sans-serif; font-size: 13px; }\n\t\th1 { margin: 5px 0 0 0; font-size: 19px; }\n\t\th2 { margin: 0 0 15px 0; font-size: 16px; }\n\t\th3 { margin: 15px 0 0 0; font-size: 14px; }\n\t\tinput[type=\"text\"], input[type=\"password\"] { float: left; margin-right: 15px; }\n\t\tlabel { float: left; font-weight: bold; margin-right: 5px; display: block; width: 150px; }\n\t\tlabel span { font-weight: normal; color: #888; }\n\t\t.rounded_box {background: transparent; margin:0px;}\n\t\t.rounded_box h4 { margin-bottom: 0px; margin-top: 7px; font-size: 14px; }\n\t\t.xtop, .xbottom {display:block; background:transparent; font-size:1px;}\n\t\t.xb1, .xb2, .xb3, .xb4 {display:block; overflow:hidden;}\n\t\t.xb1, .xb2, .xb3 {height:1px;}\n\t\t.xb2, .xb3, .xb4 {background:#F9F9F9; border-left:1px solid #CCC; border-right:1px solid #CCC;}\n\t\t.xb1 {margin:0 5px; background:#CCC;}\n\t\t.xb2 {margin:0 3px; border-width:0 2px;}\n\t\t.xb3 {margin:0 2px;}\n\t\t.xb4 {height:2px; margin:0 1px;}\n\t\t.xboxcontent {display:block; background:#F9F9F9; border:0 solid #CCC; border-width:0 1px; padding: 0 5px 0 5px;}\n\t\t.xboxcontent table td.description { padding: 3px 3px 3px 0;}\n\t\t.white .xb2, .white .xb3, .white .xb4 { background: #FFF; border-color: #CCC; }\n\t\t.white .xb1 { background: #CCC; }\n\t\t.white .xboxcontent { background: #FFF; border-color: #CCC; }\n\t\tpre { overflow: scroll; padding: 5px; }\n\t\t</style>\n\t\t<!--[if IE]>\n\t\t<style>\n\t\tbody { background-color: #DFDFDF; font-family: sans-serif; font-size: 13px; }\n\t\t</style>\n\t\t<![endif]-->\n\t\t</head>\n\t\t<body>\n\t\t<div class=\"rounded_box white\" style=\"margin: 30px auto 0 auto; width: 700px;\">\n\t\t\t<b class=\"xtop\"><b class=\"xb1\"></b><b class=\"xb2\"></b><b class=\"xb3\"></b><b class=\"xb4\"></b></b>\n\t\t\t<div class=\"xboxcontent\" style=\"vertical-align: middle; padding: 10px 10px 10px 15px;\">\n\t\t\t<img style=\"float: left; margin-right: 10px;\" src=\"" . TBGContext::getTBGPath() . "header.png\"><h1>An error occured in The Bug Genie</h1>";
    echo "<h2>{$title}</h2>";
    $report_description = null;
    if ($exception instanceof Exception) {
        if ($exception instanceof TBGActionNotFoundException) {
            echo "<h3>Could not find the specified action</h3>";
            $report_description = "Could not find the specified action";
        } elseif ($exception instanceof TBGTemplateNotFoundException) {
            echo "<h3>Could not find the template file for the specified action</h3>";
            $report_description = "Could not find the template file for the specified action";
        } elseif ($exception instanceof B2DBException) {
            echo "<h3>An exception was thrown in the B2DB framework</h3>";
            $report_description = "An exception was thrown in the B2DB framework";
        } else {
            echo "<h3>An unhandled exception occurred:</h3>";
            $report_description = "An unhandled exception occurred";
        }
        $report_description .= "\n" . $exception->getMessage();
        echo "<i>" . $exception->getMessage() . "</i><br>";
        if (class_exists("TBGContext") && TBGContext::isDebugMode()) {
            echo "<h3>Stack trace:</h3>\n\t\t\t\t\t<ul>";
            //echo '<pre>';var_dump($exception->getTrace());die();
            foreach ($exception->getTrace() as $trace_element) {
                echo '<li>';
                if (array_key_exists('class', $trace_element)) {
                    echo '<strong>' . $trace_element['class'] . $trace_element['type'] . $trace_element['function'] . '()</strong><br>';
                } elseif (array_key_exists('function', $trace_element)) {
                    if (!in_array($trace_element['function'], array('tbg_error_handler', 'tbg_exception'))) {
                        echo '<strong>' . $trace_element['function'] . '()</strong><br>';
                    }
                } else {
                    echo '<strong>unknown function</strong><br>';
                }
                if (array_key_exists('file', $trace_element)) {
                    echo '<span style="color: #55F;">' . $trace_element['file'] . '</span>, line ' . $trace_element['line'];
                } else {
                    echo '<span style="color: #C95;">unknown file</span>';
                }
                echo '</li>';
            }
            echo "</ul>";
        }
    } else {
        echo '<h3>';
        if ($exception['code'] == 8) {
            echo 'The following notice has stopped further execution:';
            $report_description = 'The following notice has stopped further execution: ';
        } else {
            echo 'The following error occured:';
            $report_description = 'The following error occured: ';
        }
        echo '</h3>';
        $report_description .= $title;
        echo "{$title}</i><br>\n\t\t\t\t<h3>Error information:</h3>\n\t\t\t\t<ul>\n\t\t\t\t\t<li>";
        echo '<span style="color: #55F;">' . $exception['file'] . '</span>, line ' . $exception['line'];
        echo "</li>\n\t\t\t\t</ul>";
        if (class_exists("TBGContext") && TBGContext::isDebugMode()) {
            echo "<h3>Backtrace:</h3>\n\t\t\t\t\t<ol>";
            foreach (debug_backtrace() as $trace_element) {
                echo '<li>';
                if (array_key_exists('class', $trace_element)) {
                    echo '<strong>' . $trace_element['class'] . $trace_element['type'] . $trace_element['function'] . '()</strong><br>';
                } elseif (array_key_exists('function', $trace_element)) {
                    if (in_array($trace_element['function'], array('tbg_error_handler', 'tbg_exception'))) {
                        continue;
                    }
                    echo '<strong>' . $trace_element['function'] . '()</strong><br>';
                } else {
                    echo '<strong>unknown function</strong><br>';
                }
                if (array_key_exists('file', $trace_element)) {
                    echo '<span style="color: #55F;">' . $trace_element['file'] . '</span>, line ' . $trace_element['line'];
                } else {
                    echo '<span style="color: #C95;">unknown file</span>';
                }
                echo '</li>';
            }
            echo "</ol>";
        }
    }
    if (class_exists("TBGContext") && TBGContext::isDebugMode()) {
        echo "<h3>Log messages:</h3>";
        foreach (TBGLogging::getEntries() as $entry) {
            $color = TBGLogging::getCategoryColor($entry['category']);
            $lname = TBGLogging::getLevelName($entry['level']);
            echo "<div class=\"log_{$entry['category']}\"><strong>{$lname}</strong> <strong style=\"color: #{$color}\">[{$entry['category']}]</strong> <span style=\"color: #555; font-size: 10px; font-style: italic;\">{$entry['time']}</span>&nbsp;&nbsp;{$entry['message']}</div>";
        }
    }
    if (class_exists("B2DB") && TBGContext::isDebugMode()) {
        echo "<h3>SQL queries:</h3>";
        try {
            echo "<ol>";
            foreach (B2DB::getSQLHits() as $details) {
                echo "<li>\n\t\t\t\t\t\t\t<b>\n\t\t\t\t\t\t\t<span class=\"faded_out dark small\">[";
                echo $details['time'] >= 1 ? round($details['time'], 2) . ' seconds' : round($details['time'] * 1000, 1) . 'ms';
                echo "]</span> </b> from <b>{$details['filename']}, line {$details['line']}</b>:<br>\n\t\t\t\t\t\t\t<span style=\"font-size: 12px;\">{$details['sql']}</span>\n\t\t\t\t\t\t</li>";
            }
            echo "</ol>";
        } catch (Exception $e) {
            echo '<span style="color: red;">Could not generate query list (there may be no database connection)</span>';
        }
    }
    echo "</div>\n\t\t\t<b class=\"xbottom\"><b class=\"xb4\"></b><b class=\"xb3\"></b><b class=\"xb2\"></b><b class=\"xb1\"></b></b>\n\t\t</div>";
    if (class_exists("TBGContext") && !TBGContext::isDebugMode()) {
        echo "<div style=\"text-align: left; margin: 35px auto 0 auto; width: 700px; font-size: 13px;\">\n\t\t\t\t<div class=\"rounded_box white\" style=\"margin-bottom: 10px; text-align: right; color: #111;\">\n\t\t\t\t\t<b class=\"xtop\"><b class=\"xb1\"></b><b class=\"xb2\"></b><b class=\"xb3\"></b><b class=\"xb4\"></b></b>\n\t\t\t\t\t<div class=\"xboxcontent\">\n\t\t\t\t\t\t<div style=\"text-align: left;\">\n\t\t\t\t\t\t\t<h2 style=\"padding-top: 10px; margin-bottom: 5px;\">Reporting this issue</h2>\n\t\t\t\t\t\t\tPlease report this error in the bug tracker by pressing the button below. This will file an automatic bug report and open it in a new window.<br><br>\n\t\t\t\t\t\t\tNo login is required - but if you have a username and password entering it below will post the issue with your username, allowing you to follow its progress.\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<br>\n\t\t\t\t\t\t<form action=\"http://thebuggenie.com/thebuggenie/thebuggenie/issues/new/bugreport\" target=\"_new\" method=\"post\">\n\t\t\t\t\t\t\t<label for=\"username\">Username <span>(optional)</span></label>\n\t\t\t\t\t\t\t<input type=\"text\" name=\"tbg3_username\" id=\"username\">\n\t\t\t\t\t\t\t<br style=\"clear: both;\">\n\t\t\t\t\t\t\t<label for=\"password\">Password <span>(optional)</span></label>\n\t\t\t\t\t\t\t<input type=\"password\" name=\"tbg3_password\" id=\"password\">\n\t\t\t\t\t\t\t<br>\n\t\t\t\t\t\t\t<input type=\"hidden\" name=\"category_id\" value=\"34\">\n\t\t\t\t\t\t\t<input type=\"hidden\" name=\"title\" value=\"" . htmlentities($title) . "\">\n\t\t\t\t\t\t\t<input type=\"hidden\" name=\"description\" value=\"" . htmlentities($report_description) . "\n\n\">";
        echo "<input type=\"hidden\" name=\"reproduction_steps\" value=\"PHP_SAPI: " . PHP_SAPI . "<br>PHP_VERSION: " . PHP_VERSION . "\n\n'''Backtrace''':<br>";
        if ($exception instanceof TBGException) {
            foreach ($exception->getTrace() as $trace_element) {
                if (array_key_exists('class', $trace_element)) {
                    echo "'''{$trace_element['class']}{$trace_element['type']}{$trace_element['function']}()'''\n";
                } elseif (array_key_exists('function', $trace_element)) {
                    if (in_array($trace_element['function'], array('tbg_error_handler', 'tbg_exception'))) {
                        continue;
                    }
                    echo "'''{$trace_element['function']}()'''\n";
                } else {
                    echo "'''unknown function'''\n";
                }
                if (array_key_exists('file', $trace_element)) {
                    echo 'in ' . str_replace(THEBUGGENIE_PATH, '<installpath>/', $trace_element['file']) . ', line ' . $trace_element['line'];
                } else {
                    echo 'in an unknown file';
                }
                echo "<br>";
            }
        } else {
            foreach (debug_backtrace() as $trace_element) {
                if (array_key_exists('class', $trace_element)) {
                    echo "'''{$trace_element['class']}{$trace_element['type']}{$trace_element['function']}()'''\n";
                } elseif (array_key_exists('function', $trace_element)) {
                    if (in_array($trace_element['function'], array('tbg_error_handler', 'tbg_exception'))) {
                        continue;
                    }
                    echo "'''{$trace_element['function']}()'''\n";
                } else {
                    echo "'''unknown function'''\n";
                }
                if (array_key_exists('file', $trace_element)) {
                    echo 'in ' . str_replace(THEBUGGENIE_PATH, '<installpath>/', $trace_element['file']) . ', line ' . $trace_element['line'];
                } else {
                    echo 'in an unknown file';
                }
                echo "<br>";
            }
        }
        echo "\n\n\">";
        echo "\t\t\t\t\t\n\t\t\t\t\t\t\t\t<input type=\"submit\" value=\"Submit details for reporting\" style=\"font-size: 16px; font-weight: normal; padding: 5px; margin: 10px 0;\">\n\t\t\t\t\t\t\t\t<div style=\"font-size: 15px; font-weight: bold; padding: 0 5px 10px 0;\">Thank you for helping us improve The Bug Genie!</div>\n\t\t\t\t\t\t\t</form>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<b class=\"xbottom\"><b class=\"xb4\"></b><b class=\"xb3\"></b><b class=\"xb2\"></b><b class=\"xb1\"></b></b>\n\t\t\t\t\t</div>";
        if (TBGLogging::isEnabled()) {
            echo "<h3 style=\"margin-top: 50px;\">Log messages (may contain useful information, but will not be submitted):</h3>";
            foreach (TBGLogging::getEntries() as $entry) {
                $color = TBGLogging::getCategoryColor($entry['category']);
                $lname = TBGLogging::getLevelName($entry['level']);
                echo "<div class=\"log_{$entry['category']}\"><strong>{$lname}</strong> <strong style=\"color: #{$color}\">[{$entry['category']}]</strong> <span style=\"color: #555; font-size: 10px; font-style: italic;\">{$entry['time']}</span>&nbsp;&nbsp;{$entry['message']}</div>";
            }
        }
    }
    echo "\n\t\t\t</div>\n\t\t</body>\n\t\t</html>\n\t\t";
    die;
}
Ejemplo n.º 8
0
 protected static function cliError($title, $exception)
 {
     $trace_elements = null;
     if ($exception instanceof Exception) {
         if ($exception instanceof TBGActionNotFoundException) {
             TBGCliCommand::cli_echo("Could not find the specified action\n", 'white', 'bold');
         } elseif ($exception instanceof TBGTemplateNotFoundException) {
             TBGCliCommand::cli_echo("Could not find the template file for the specified action\n", 'white', 'bold');
         } elseif ($exception instanceof \b2db\Exception) {
             TBGCliCommand::cli_echo("An exception was thrown in the B2DB framework\n", 'white', 'bold');
         } else {
             TBGCliCommand::cli_echo("An unhandled exception occurred:\n", 'white', 'bold');
         }
         echo TBGCliCommand::cli_echo($exception->getMessage(), 'red', 'bold') . "\n";
         echo "\n";
         TBGCliCommand::cli_echo('Stack trace') . ":\n";
         $trace_elements = $exception->getTrace();
     } else {
         if ($exception['code'] == 8) {
             TBGCliCommand::cli_echo('The following notice has stopped further execution:', 'white', 'bold');
         } else {
             TBGCliCommand::cli_echo('The following error occured:', 'white', 'bold');
         }
         echo "\n";
         echo "\n";
         TBGCliCommand::cli_echo($title, 'red', 'bold');
         echo "\n";
         TBGCliCommand::cli_echo("occured in\n");
         TBGCliCommand::cli_echo($exception['file'] . ', line ' . $exception['line'], 'blue', 'bold');
         echo "\n";
         echo "\n";
         TBGCliCommand::cli_echo("Backtrace:\n", 'white', 'bold');
         $trace_elements = debug_backtrace();
     }
     foreach ($trace_elements as $trace_element) {
         if (array_key_exists('class', $trace_element)) {
             if (array_key_exists('class', $trace_element) && $trace_element['class'] == 'TBGContext' && array_key_exists('function', $trace_element) && in_array($trace_element['function'], array('errorHandler', 'cliError'))) {
                 continue;
             }
             TBGCliCommand::cli_echo($trace_element['class'] . $trace_element['type'] . $trace_element['function'] . '()');
         } elseif (array_key_exists('function', $trace_element)) {
             TBGCliCommand::cli_echo($trace_element['function'] . '()');
         } else {
             TBGCliCommand::cli_echo('unknown function');
         }
         echo "\n";
         if (array_key_exists('file', $trace_element)) {
             TBGCliCommand::cli_echo($trace_element['file'] . ', line ' . $trace_element['line'], 'blue', 'bold');
         } else {
             TBGCliCommand::cli_echo('unknown file', 'red', 'bold');
         }
         echo "\n";
     }
     if (class_exists('\\b2db\\Core')) {
         echo "\n";
         $sqlhits = \b2db\Core::getSQLHits();
         if (count($sqlhits)) {
             TBGCliCommand::cli_echo("SQL queries:\n", 'white', 'bold');
             try {
                 $cc = 1;
                 foreach ($sqlhits as $details) {
                     TBGCliCommand::cli_echo("(" . $cc++ . ") [");
                     $str = $details['time'] >= 1 ? round($details['time'], 2) . ' seconds' : round($details['time'] * 1000, 1) . 'ms';
                     TBGCliCommand::cli_echo($str);
                     TBGCliCommand::cli_echo("] from ");
                     TBGCliCommand::cli_echo($details['filename'], 'blue');
                     TBGCliCommand::cli_echo(", line ");
                     TBGCliCommand::cli_echo($details['line'], 'white', 'bold');
                     TBGCliCommand::cli_echo(":\n");
                     TBGCliCommand::cli_echo("{$details['sql']}\n");
                 }
                 echo "\n";
             } catch (Exception $e) {
                 TBGCliCommand::cli_echo("Could not generate query list (there may be no database connection)", "red", "bold");
             }
         }
     }
     echo "\n";
 }