Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-16371

patch: support for firePHP debuging aid tool in firefox

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Won't Fix
    • Affects Version/s: 1.9.2
    • Fix Version/s: None
    • Component/s: Libraries
    • Labels:
    • Environment:
      apache 2 , php 5 , mysql 5 , moodle 1.9.2
    • Database:
      MySQL
    • Affected Branches:
      MOODLE_19_STABLE

      Description

      i have added php debugging support into moodle that uses the firePHP (firebug) extension

      it needs review because it has very basic functionality. and it only implemented for debugging()

      first you have to be using firefox then download firebug and then add firephp.
      see instructions: http://www.firephp.org/Wiki/Main/QuickStart

      i have downloaded the "FirePHP Core Library" from http://www.firephp.org/ and placed it under moodle/lib
      in the folder /moodle/lib/FirePHPCore (three files : fb.php , FirePHP.class.php , LICENSE )

      i added a new "echo" to firePHP function in /moodle/lib/weblib.php called echo_fb() and changed debugging() a little bit
      to echo its output to firePHP as well.

      here is the echo_fb:

      /**

      • echo some firePHP debug info plus internal system variables
      • @param string $msg - some text message to output
      • @param string $var - variable array we wish to see in firebug php
      • @param integer $level - warrning level (as used in FirePHP presets
        */
        function echo_fb($msg, $var=NULL, $level=0) {
        global $CFG;
        require_once($CFG->libdir.'/FirePHPCore/FirePHP.class.php');
        ob_start();

      $firephp = FirePHP::getInstance(true);

      if ($level == 0)

      { $level = FirePHP::WARN; }

      $firephp->fb($msg,array($var),$level);
      ob_end_clean();
      }

      and here is a patched debugging() function:
      function debugging($message='', $level=DEBUG_NORMAL) {

      global $CFG, $USER;

      if (empty($CFG->debug))

      { return false; }

      //nadavkav
      //echo 'debugging for admin user = '.$USER->id == 2 ONLY;
      if ($CFG->debug >= $level && $USER->id == 2) {
      if ($message) {
      $callers = debug_backtrace();
      $from = '<ul style="direction: ltr; text-align: left">';
      foreach ($callers as $caller) {
      $fb_log = '';
      $fb_log_ct = '';
      if (!isset($caller['line']))

      { $caller['line'] = '?'; // probably call_user_func() }

      if (!isset($caller['file']))

      { $caller['file'] = $CFG->dirroot.'/unknownfile'; // probably call_user_func() }

      $from .= '<li>line ' . $caller['line'] . ' of ' . substr($caller['file'], strlen($CFG->dirroot) + 1);
      if (isset($caller['function'])) {
      $from .= ': call to ';
      if (isset($caller['class']))

      { $from .= $caller['class'] . $caller['type']; $fb_log_ct = $caller['class'] . $caller['type']; }

      $from .= $caller['function'] . '()';
      }
      $from .= '</li>';
      $fb_log = 'line[' . $caller['line'] . '] file[' . $caller['file'] . '] func[' . $fb_log_ct . $caller['function'] . ']';
      }
      $from .= '</ul>';
      if (!isset($CFG->debugdisplay))

      { $CFG->debugdisplay = ini_get_bool('display_errors'); }

      if ($CFG->debugdisplay) {
      if (!defined('DEBUGGING_PRINTED'))

      { define('DEBUGGING_PRINTED', 1); // indicates we have printed something }

      notify($message . $from, 'notifytiny');
      echo_fb($fb_log,array($callers));
      } else

      { trigger_error($message . $from, E_USER_NOTICE); }

      }
      return true;
      }
      return false;
      }

      you can notice i have debugging displayed only for Admin (userid == 2)
      if you do not like this, please ignore it and remove it
      (many teachers complained that they see the warnings when i "work" on the moodle code,
      so i set it this way so only i can see them)

      i am attaching a capture screen to show how useful it is to display the contents of php variables
      i just put the variable in the echo_fb msg (as an arry()) and it is visible to the firephp

      hope you like too

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Votes:
                4 Vote for this issue
                Watchers:
                14 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: