function activate()
 {
     if (!Config::isLive() && file_exists($this->bypass)) {
         Debugger::log("<span style='color: #939393'>Follow {$this->type} Redirect to:</span> <br><a href='{$this->url}' style='color: white;'>{$this->url}</a> ");
         exit;
     } else {
         header("Location: {$this->url}", true, $this->type);
         exit;
     }
     return;
 }
 private function email_alert()
 {
     if ($this->error_recently_sent()) {
         //return;	//error already emailed recently
     }
     if (!Config::isLive()) {
         error_log("Email alert would have been sent for this error.");
         global $argv;
         if (isset($argv[1])) {
             $this->alert_emails = array($argv[1]);
         } else {
             return;
             //do not send emails for testing
         }
     }
     $error_level = $this->exception->getSeverity();
     $subject = "PHP Error[" . $error_level . "] : " . $this->exception->getFile();
     $body = "";
     $body .= "\n Error sent from /utility/ErrorHandler.class";
     $body .= "\n PHP Error #: " . $error_level;
     $body .= "\n Error Message: " . $this->exception->getMessage();
     $body .= "\n File: " . $this->exception->getFile();
     $body .= "\n Line: " . $this->exception->getLine();
     $body .= "\n DateTime: " . date("Y-m-d H:i:s");
     if (isset($_SERVER['REMOTE_ADDR'])) {
         $body .= "\n Remote Address: " . $_SERVER['REMOTE_ADDR'];
     }
     if (isset($_SERVER['SERVER_ADDR'])) {
         $body .= "\n Server Address: " . $_SERVER['SERVER_ADDR'];
     }
     if (isset($_SERVER['SERVER_NAME'])) {
         $body .= "\n Server Name: " . $_SERVER['SERVER_NAME'];
     }
     $body .= "\n Trace: " . $this->exception->getTraceAsString();
     Loader::load('utility', "email/Email");
     $email = new Email();
     $email->setBody($body);
     $email->setSubject($subject);
     $email->setFromAddress("Error Alert", "");
     $email->addToAddress("Debugging", "*****@*****.**");
     $email->sendAsPlainText();
     $email->send();
 }
 function write($keyspace, $key, $column_family, $data, $consistency)
 {
     try {
         Loader::load("vendor", "phpcassa/columnfamily.php");
         $columnFamily = new columnFamily($this->connection($keyspace), $column_family);
         //echo "use phpcassa!\n";
         //exit;
         if (Config::isLive() || Config::isStaging()) {
             return $columnFamily->insert($key, $data, null, null, $consistency);
         }
         $time = $this->microsecond_timestamp();
         $cassandra_mutations = array();
         foreach ($data as $key => $value) {
             $cassandra_mutations[$key][$column_family][] = new cassandra_Mutation(array("column_or_supercolumn" => new cassandra_ColumnOrSuperColumn(array("column" => new cassandra_Column(array("name" => $key, "value" => $value, "timestamp" => $time))))));
         }
         //Debugger::log("set keyspace $keyspace");
         $this->set_keyspace($keyspace);
         $start = microtime(true);
         $this->get_client()->batch_mutate($cassandra_mutations, $this->consistency());
         $end = microtime(true);
         if (json_encode($cassandra_mutations) == null) {
             print_r($cassandra_mutations);
             exit;
         }
         //error_log("Thrift::batch_mutate(".json_encode($cassandra_mutations).") " . "(".$this->host .":".$this->settings["port"].")");
         Debugger::query("Thrift::batch_mutate(" . json_encode($cassandra_mutations) . ")", $end - $start, $keyspace . "(" . $this->settings["ip"] . ":" . $this->settings["port"] . ")");
         return true;
     } catch (Exception $e) {
         $info = isset($e->why) ? $e->why : get_class($e);
         throw new Exception("Database connection is not available: {$info} {$this->host}");
         return false;
     }
 }
Example #4
0
function displayPqp($output, $config)
{
    $cssUrl = '/css/pqp.css';
    $css = file_get_contents(Config::get('DocRoot') . '/vendor/pqp/pqp.css');
    echo <<<STYLES
<style>
{$css}
</style>
STYLES;
    echo <<<JAVASCRIPT
<!-- JavaScript -->
<script type="text/javascript">
\tvar PQP_DETAILS = false;
\tvar PQP_HEIGHT = "tall";
\t
\t//addEvent(window, 'load', loadCSS);
\t
\tvar PQP_INPUT = {
\t\ttimer: null,
\t\tclear: function(){
\t\t\tPQP_INPUT.input = '';
\t\t\tclearTimeout(PQP_INPUT.timer);
\t\t},
\t\tinput: '',
\t\tpattern: {
\t\t\tshow:'3838',
\t\t\thide:'4040'
\t\t}
\t};
\t
\taddEvent(window.document, 'keydown', function(e){
\t\tPQP_INPUT.input += e ? e.keyCode : event.keyCode;
\t\tPQP_INPUT.timer = setTimeout(PQP_INPUT.clear, 300);
\t\t
\t\tif (PQP_INPUT.input == PQP_INPUT.pattern.show)
\t\t{
\t\t\tPQP_INPUT.clear();
\t\t\tdocument.getElementById('pqp-container').style.display = "block";
\t\t}
\t\telse if (PQP_INPUT.input == PQP_INPUT.pattern.hide)
\t\t{
\t\t\tPQP_INPUT.clear();
\t\t\tdocument.getElementById('pqp-container').style.display = "none";
\t\t}
\t\t
\t});

\tfunction changeTab(tab) {
\t\tvar pQp = document.getElementById('pQp');
\t\thideAllTabs();
\t\taddClassName(pQp, tab, true);
\t}
\t
\tfunction hideAllTabs() {
\t\tvar pQp = document.getElementById('pQp');
\t\tremoveClassName(pQp, 'console');
\t\tremoveClassName(pQp, 'speed');
\t\tremoveClassName(pQp, 'queries');
\t\tremoveClassName(pQp, 'memory');
\t\tremoveClassName(pQp, 'files');
\t}
\t
\tfunction toggleDetails(){
\t\tvar container = document.getElementById('pqp-container');
\t\t
\t\tif(PQP_DETAILS){
\t\t\taddClassName(container, 'hideDetails', true);
\t\t\tPQP_DETAILS = false;
\t\t}
\t\telse{
\t\t\tremoveClassName(container, 'hideDetails');
\t\t\tPQP_DETAILS = true;
\t\t}
\t}
\tfunction toggleHeight(){
\t\tvar container = document.getElementById('pqp-container');
\t\t
\t\tif(PQP_HEIGHT == "short"){
\t\t\taddClassName(container, 'tallDetails', true);
\t\t\tPQP_HEIGHT = "tall";
\t\t}
\t\telse{
\t\t\tremoveClassName(container, 'tallDetails');
\t\t\tPQP_HEIGHT = "short";
\t\t}
\t}
\t
\tfunction loadCSS() {
\t\tvar sheet = document.createElement("link");
\t\tsheet.setAttribute("rel", "stylesheet");
\t\tsheet.setAttribute("type", "text/css");
\t\tsheet.setAttribute("href", "{$cssUrl}");
\t\tdocument.getElementsByTagName("head")[0].appendChild(sheet);
\t\tsetTimeout(function(){document.getElementById("pqp-container").style.display = "block"}, 10);
\t}
\t
\t
\t//http://www.bigbold.com/snippets/posts/show/2630
\tfunction addClassName(objElement, strClass, blnMayAlreadyExist){
\t   if ( objElement.className ){
\t      var arrList = objElement.className.split(' ');
\t      if ( blnMayAlreadyExist ){
\t         var strClassUpper = strClass.toUpperCase();
\t         for ( var i = 0; i < arrList.length; i++ ){
\t            if ( arrList[i].toUpperCase() == strClassUpper ){
\t               arrList.splice(i, 1);
\t               i--;
\t             }
\t           }
\t      }
\t      arrList[arrList.length] = strClass;
\t      objElement.className = arrList.join(' ');
\t   }
\t   else{  
\t      objElement.className = strClass;
\t      }
\t}

\t//http://www.bigbold.com/snippets/posts/show/2630
\tfunction removeClassName(objElement, strClass){
\t   if ( objElement.className ){
\t      var arrList = objElement.className.split(' ');
\t      var strClassUpper = strClass.toUpperCase();
\t      for ( var i = 0; i < arrList.length; i++ ){
\t         if ( arrList[i].toUpperCase() == strClassUpper ){
\t            arrList.splice(i, 1);
\t            i--;
\t         }
\t      }
\t      objElement.className = arrList.join(' ');
\t   }
\t}

\t//http://ejohn.org/projects/flexible-javascript-events/
\tfunction addEvent( obj, type, fn ) {
\t  if ( obj.attachEvent ) {
\t    obj["e"+type+fn] = fn;
\t    obj[type+fn] = function() { obj["e"+type+fn]( window.event ) };
\t    obj.attachEvent( "on"+type, obj[type+fn] );
\t  } 
\t  else{
\t    obj.addEventListener( type, fn, false );\t
\t  }
\t}
</script>
JAVASCRIPT;
    $hide = Config::isLive() ? ' style="display:none"' : '';
    echo "<div id=\"pqp-container\" class=\"pQp tallDetails hideDetails\"{$hide}>";
    $logCount = count($output['logs']['console']);
    $fileCount = count($output['files']);
    $memoryUsed = $output['memoryTotals']['used'];
    $queryCount = $output['queryTotals']['count'];
    $speedTotal = $output['speedTotals']['total'];
    echo <<<PQPTABS
<div id="pQp" class="console">
<table id="pqp-metrics" cellspacing="0">
<tr>
\t<td class="green" onclick="changeTab('console');">
\t\t<var>{$logCount}</var>
\t\t<h4>Console</h4>
\t</td>
\t<td class="blue" onclick="changeTab('speed');">
\t\t<var>{$speedTotal}</var>
\t\t<h4>Load Time</h4>
\t</td>
\t<td class="purple" onclick="changeTab('queries');">
\t\t<var>{$queryCount} Queries</var>
\t\t<h4>Database</h4>
\t</td>
\t<td class="orange" onclick="changeTab('memory');">
\t\t<var>{$memoryUsed}</var>
\t\t<h4>Memory Used</h4>
\t</td>
\t<td class="red" onclick="changeTab('files');">
\t\t<var>{$fileCount} Files</var>
\t\t<h4>Included</h4>
\t</td>
</tr>
</table>
PQPTABS;
    echo '<div id="pqp-console" class="pqp-box">';
    if ($logCount == 0) {
        echo '<h3>This panel has no log items.</h3>';
    } else {
        echo '<table class="side" cellspacing="0">
		<tr>
			<td class="alt1"><var>' . $output['logs']['logCount'] . '</var><h4>Logs</h4></td>
			<td class="alt2"><var>' . $output['logs']['errorCount'] . '</var> <h4>Errors</h4></td>
		</tr>
		<tr>
			<td class="alt3"><var>' . $output['logs']['memoryCount'] . '</var> <h4>Memory</h4></td>
			<td class="alt4"><var>' . $output['logs']['speedCount'] . '</var> <h4>Speed</h4></td>
		</tr>
		</table>
		<table class="main" cellspacing="0">';
        $class = '';
        foreach ($output['logs']['console'] as $log) {
            echo '<tr class="log-' . $log['type'] . '">
				<td class="type">' . $log['type'] . '</td>
				<td class="' . $class . '">';
            if ($log['type'] == 'log') {
                echo '<div><pre>' . $log['data'] . '</pre></div>';
            } elseif ($log['type'] == 'memory') {
                echo '<div><pre>' . $log['data'] . '</pre> <em>' . $log['dataType'] . '</em>: ' . $log['name'] . ' </div>';
            } elseif ($log['type'] == 'speed') {
                echo '<div><pre>' . $log['data'] . '</pre> <em>' . $log['name'] . '</em></div>';
            } elseif ($log['type'] == 'error') {
                echo '<div><em>Line ' . $log['line'] . '</em> : ' . $log['data'] . ' <pre>' . $log['file'] . '</pre></div>';
            }
            echo '</td></tr>';
            if ($class == '') {
                $class = 'alt';
            } else {
                $class = '';
            }
        }
        echo '</table>';
    }
    echo '</div>';
    echo '<div id="pqp-speed" class="pqp-box">';
    if ($output['logs']['speedCount'] == 0) {
        echo '<h3>This panel has no log items.</h3>';
    } else {
        echo '<table class="side" cellspacing="0">
		  <tr><td><var>' . $output['speedTotals']['total'] . '</var><h4>Load Time</h4></td></tr>
		  <tr><td class="alt"><var>' . $output['speedTotals']['allowed'] . '</var> <h4>Max Execution Time</h4></td></tr>
		 </table>
		<table class="main" cellspacing="0">';
        $class = '';
        foreach ($output['logs']['console'] as $log) {
            if ($log['type'] == 'speed') {
                echo '<tr class="log-' . $log['type'] . '">
				<td class="' . $class . '">';
                echo '<div><pre>' . $log['data'] . '</pre> <em>' . $log['name'] . '</em></div>';
                echo '</td></tr>';
                if ($class == '') {
                    $class = 'alt';
                } else {
                    $class = '';
                }
            }
        }
        echo '</table>';
    }
    echo '</div>';
    echo '<div id="pqp-queries" class="pqp-box">';
    if ($output['queryTotals']['count'] == 0) {
        echo '<h3>This panel has no log items.</h3>';
    } else {
        echo '<table class="side" cellspacing="0">
		  <tr><td><var>' . $output['queryTotals']['count'] . '</var><h4>Total Queries</h4></td></tr>
		  <tr><td class="alt"><var>' . $output['queryTotals']['time'] . '</var> <h4>Total Time</h4></td></tr>
		  <tr><td><var>0</var> <h4>Duplicates</h4></td></tr>
		 </table>
		<table class="main" cellspacing="0">';
        $class = '';
        foreach ($output['queries'] as $query) {
            echo '<tr>
				<td class="' . $class . '">' . $query['sql'];
            if ($query['explain']) {
                echo '<em>
					Possible keys: <b>' . $query['explain']['possible_keys'] . '</b> &middot; 
					Key Used: <b>' . $query['explain']['key'] . '</b> &middot; 
					Type: <b>' . $query['explain']['type'] . '</b> &middot; 
					Rows: <b>' . $query['explain']['rows'] . '</b> &middot; 
					Speed: <b>' . $query['time'] . '</b> &middot;
					Database: <b>' . $query['database'] . '</b>
				</em>';
            } else {
                if ($query['raw_time'] > 1000) {
                    $speed_class = "pqp-slowquery-high";
                } elseif ($query['raw_time'] > 100) {
                    $speed_class = "pqp-slowquery-mid";
                } else {
                    $speed_class = "pqp-slowquery-low";
                }
                echo '<em>
					Speed: <b><span class="' . $speed_class . '">' . $query['time'] . '</span></b> &middot;
					Database: <b>' . $query['database'] . '</b>
				      </em>';
            }
            echo '</td></tr>';
            if ($class == '') {
                $class = 'alt';
            } else {
                $class = '';
            }
        }
        echo '</table>';
    }
    echo '</div>';
    echo '<div id="pqp-memory" class="pqp-box">';
    if ($output['logs']['memoryCount'] == 0) {
        echo '<h3>This panel has no log items.</h3>';
    } else {
        echo '<table class="side" cellspacing="0">
		  <tr><td><var>' . $output['memoryTotals']['used'] . '</var><h4>Used Memory</h4></td></tr>
		  <tr><td class="alt"><var>' . $output['memoryTotals']['total'] . '</var> <h4>Total Available</h4></td></tr>
		 </table>
		<table class="main" cellspacing="0">';
        $class = '';
        foreach ($output['logs']['console'] as $log) {
            if ($log['type'] == 'memory') {
                echo '<tr class="log-' . $log['type'] . '">';
                echo '<td class="' . $class . '"><b>' . $log['data'] . '</b> <em>' . $log['dataType'] . '</em>: ' . $log['name'] . '</td>';
                echo '</tr>';
                if ($class == '') {
                    $class = 'alt';
                } else {
                    $class = '';
                }
            }
        }
        echo '</table>';
    }
    echo '</div>';
    echo '<div id="pqp-files" class="pqp-box">';
    if ($output['fileTotals']['count'] == 0) {
        echo '<h3>This panel has no log items.</h3>';
    } else {
        echo '<table class="side" cellspacing="0">
		  	<tr><td><var>' . $output['fileTotals']['count'] . '</var><h4>Total Files</h4></td></tr>
			<tr><td class="alt"><var>' . $output['fileTotals']['size'] . '</var> <h4>Total Size</h4></td></tr>
			<tr><td><var>' . $output['fileTotals']['largest'] . '</var> <h4>Largest</h4></td></tr>
		 </table>
		<table class="main" cellspacing="0">';
        $class = '';
        foreach ($output['files'] as $file) {
            echo '<tr><td class="' . $class . '"><b>' . $file['size'] . '</b> ' . $file['name'] . '</td></tr>';
            if ($class == '') {
                $class = 'alt';
            } else {
                $class = '';
            }
        }
        echo '</table>';
    }
    echo '</div>';
    echo <<<FOOTER
\t<table id="pqp-footer" cellspacing="0">
\t\t<tr>
\t\t\t<td class="credit">
\t\t\t\t<a href="http://particletree.com" target="_blank">
\t\t\t\t<strong>PHP</strong> 
\t\t\t\t<b class="green">Q</b><b class="blue">u</b><b class="purple">i</b><b class="orange">c</b><b class="red">k</b>
\t\t\t\tProfiler</a></td>
\t\t\t<td class="actions">
\t\t\t\t<a href="#" onclick="toggleDetails();return false;">+/-</a>
\t\t\t</td>
\t\t</tr>
\t</table>
FOOTER;
    echo '</div></div>';
}
	}

	//http://ejohn.org/projects/flexible-javascript-events/
	function addEvent( obj, type, fn ) {
	  if ( obj.attachEvent ) {
	    obj["e"+type+fn] = fn;
	    obj[type+fn] = function() { obj["e"+type+fn]( window.event ) };
	    obj.attachEvent( "on"+type, obj[type+fn] );
	  } 
	  else{
	    obj.addEventListener( type, fn, false );	
	  }
	}
</script>

<?$hide = (Config::isLive()) ? ' style="display:none"' : '';?>

<div id="pqp-container" class="pQp tallDetails hideDetails"<?php 
echo $hide;
?>
>
<?
$logCount = count($output['logs']['console']);
$fileCount = count($output['files']);
$memoryUsed = $output['memoryTotals']['used'];
$queryCount = $output['queryTotals']['count'];
$speedTotal = $output['speedTotals']['total'];
?>

<div id="pQp" class="console">
<table id="pqp-metrics" cellspacing="0">
 function send($html_mode = false)
 {
     if (Config::isLive() || Config::isStaging()) {
         $mail = $this->getEmailer();
         if ($this->send_as_html) {
             //many mail servers break 8bit encoding by adding newlines, QP prevents that for ASCII-only emails (like this)
             $mail->Encoding = "quoted-printable";
             $mail->isHTML(true);
         }
         $mail->Subject = $this->getSubjectWithReplacements();
         $mail->Body = $this->getBodyWithReplacements();
         if (!$mail->Send()) {
             error_log("ERROR: mail not sent: {$mail->ErrorInfo}");
             return false;
         } else {
             if ($this->recordMember) {
                 Loader::load('model', 'com/htmlgraphic/history/Transaction');
                 DBObject::mutator('Transaction', 'RecordContactEmailSentAction', array($this, $this->recordMember))->activate();
             }
         }
         return true;
     } else {
         //this is so you can see if you would have sent an email on a dev box
         if ($this->recordMember) {
             Loader::load('model', 'com/htmlgraphic/history/Transaction');
             DBObject::mutator('Transaction', 'RecordContactEmailSentAction', array($this, $this->recordMember))->activate();
         }
         //error_log(print_r($this->recordMember,true));
         Debugger::log("<span style='color: #fff;'>Subject:</span> " . $this->getSubjectWithReplacements() . "<br><br><span style='color: #fff;'>-----Body-----</span><br>" . $this->getBodyWithReplacements() . "<br><span style='color: #fff;'>-----Body-----</span>");
         return true;
     }
 }
 public static function consoleLog($data)
 {
     if (!Config::isLive()) {
         error_log("Debugger::consoleLog: " . self::format_data($data));
     }
 }