Sources for file plugins/class/debug.php in version 4.0 Beta 1



Click on a comment to hide it. Click here to show all comments.

/**
 * Project:     Xnyo 4: Bubbles
 * File:        plugins/class/debug.php
 *
 * Version:     4.0-dev
 * SVN Id:      $Id: debug.php 5 2007-05-18 03:49:07Z bok $
 * SVN URL:     $HeadURL:
http://svn.syd.wholesalebroadband.com.au/xnyo/trunk/plugins/class/debug.php $
 * Authors:     Robert Amos <bok[at]odynia.org>
 *
 * Copyright (c) 2001-2007 Robert Amos <bok[at]odynia.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/

/**
 * This file contains the basic information used when displaying the debug console
**/

class XnyoDebug implements XnyoClassPlugin
{
    
// Plugin Information
    
public $_plugin_info = array
    (
        
'name' => 'Xnyo Debug Plugin',
        
'description' => 'This plugin displays the debug console',
        
'action' => XNYO_PLUGIN_ACTION_STORAGE,
        
'varname' => 'debug'
    
);

    
/**
     * Constructor
    **/
    
private $xnyo;
    public function 
__construct ()
    {
        
$this->xnyo $GLOBALS['xnyo_parent'];
    }

    public function 
build ()
    {
        global 
$smarty;
        
        try
        {
            
// we need to load up the template file
            
if (!file_exists($this->xnyo->debug->template) || !is_readable($this->xnyo->debug->template))
                return 
$this->button(sprintf('Unable to load debug template <b>%s</b>. Could not be found or
read.'
$this->xnyo->debug->template));
        
            
// load the template
            
$tpl file_get_contents($this->xnyo->debug->template);
        
            
// empty? bugger..
            
if (empty($tpl))
                return 
$this->button(sprintf('Debug console template <b>%s</b> is empty.',
$this->xnyo->debug->template));

            
// Get assigned smarty variables before we add to it
            
$smarty->assign('smarty_assigned', (array)$smarty->get_template_vars());

            
// Get error/debug messages
            
$smarty->assign('errors'$this->xnyo->storage->error->get());

            
$d $this->xnyo->storage->error->get(DEBUG);
            
// the total script execution time.. roughly
            
$smarty->assign('time'array_sum(explode(' 'microtime())));
            
$smarty->assign('exec_time'round(array_sum(explode(' 'microtime())) - $d[0]->getTimestamp(),
6));

        
            
/**
             * ADD MORE STUFF IN HERE
            **/

            // Evaluate the template
            
$smarty->_compile_source('evaluated_template'$tpl$comp_tpl);
            
$smarty->_eval('?>'.$comp_tpl);
            
$buf ob_get_contents();
        
            
// pull the template from the garbage thats littered in the buffer!
            
if (!preg_match('/<xnyo::debug::console::template>(.*?)<\/xnyo::debug::console::template>/is',
$buf$m))
                return 
$this->button('Unable to get debug console output, could not find
xnyo::debug::console::template tags.'
);
        
            
// throw it into the session
            
$_SESSION['_xnyo_debug_console'] = $m[1];
            
//return $m[1];
            // return the button so it goes on the end of the page.
            
return $this->button();
        } catch (
Exception $e)
        {
            return (string)
$e;
        }
    }
    
    public function 
button ($text=null)
    {
        if (
$text == null)
            
$text 'Open Debug Console';
        
$html '<button name="Debug Console" value="'.$text.'"
onclick="window.open(\'
?'.XNYO_DEBUG_VAR.'=console\', \'xnyo_debug_console\')"
style="position: fixed !important; position: absolute; top: 5px; right: 5px; border: 2px solid
#6c0a05; color: #FFFFFF; background-color: #7f0c06; z-index: 1000;"
>'.$text.'</button>';
        return $html;
    }

}

Website is Copyright © Odynia.org 2000-2005 - Xnyo is released under a BSD license.