Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

new debug and helper classes

git-svn-id: http://svn.php.net/repository/pear/packages/HTML_AJAX/trunk@199136 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
commit c0a9db13a936b4a576abd0f6ed845f0b95559713 1 parent 979fbd5
Joshua Eichorn authored
Showing with 253 additions and 0 deletions.
  1. +140 −0 AJAX/Debug.php
  2. +113 −0 AJAX/Helper.php
View
140 AJAX/Debug.php
@@ -0,0 +1,140 @@
+<?php
+define ("NEWLINE", "\n");
+// {{{ class HTML_AJAX_Debug
+/**
+ * AJAX Debugging implementation
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @category HTML
+ * @package AJAX
+ * @author David Coallier <davidc@php.net>
+ * @copyright 2005 David Coallier
+ * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
+ * @version Release: @package_version@
+ */
+class HTML_AJAX_Debug {
+ // {{{ properties
+ /**
+ * This is the error message.
+ *
+ * @access private
+ */
+ var $errorMsg;
+
+ /**
+ * The line where the error occured.
+ *
+ * @access private
+ */
+ var $errorLine;
+
+ /**
+ * The error code.
+ *
+ * @access private
+ */
+ var $errorCode;
+
+ /**
+ * The file where the error occured.
+ *
+ * @access private
+ */
+ var $errorFile;
+
+ /**
+ * Time the error occured
+ *
+ * @access private
+ */
+ var $_timeOccured;
+
+ /**
+ * The whole error itself
+ *
+ * @access private
+ * @see errorMsg
+ * @see errorLine
+ * @see errorFile
+ * @see errorCode
+ */
+ var $error;
+
+ /**
+ * The file to save the error to.
+ *
+ * @access private
+ * @default ajaxErrLog.xml
+ */
+ var $file = 'ajaxErrLog.xml';
+ // }}}
+ // {{{ constructor
+ /**
+ * The constructor.
+ *
+ * @param string $errorMsg The error message.
+ * @param string $errLine The line where error occured.
+ * @param string $errCode The error Code.
+ * @param string $errFile The file where error occured.
+ */
+ function HTML_AJAX_Debug($errMsg, $errLine, $errCode, $errFile)
+ {
+ $this->errorMsg = $errMsg;
+ $this->errorLine = $errLine;
+ $this->errorCode = $errCode;
+ $this->errorFile = $errFile;
+ $this->_timeOccured = date("Y-m-d H:i:s", time());
+ $this->xmlError();
+ }
+ // }}}
+ // {{{ xmlError
+ /**
+ * This functions formats the error to xml format then we can save it.
+ *
+ * @access protected
+ * @return $this->error the main error.
+ */
+ function xmlError()
+ {
+ $error = " <when>{$this->_timeOccured}</when>" . NEWLINE;
+ $error .= " <msg>{$this->errorMsg}</msg>" . NEWLINE;
+ $error .= " <code>{$this->errorCode}</code>" . NEWLINE;
+ $error .= " <line>{$this->errorLine}</line>" . NEWLINE;
+ $error .= " <file>{$this->errorFile}</file>" . NEWLINE . NEWLINE;
+ return $this->error = $error;
+ }
+ // }}}
+ // {{{ sessionError
+ /**
+ * This function pushes the array $_SESSION['html_ajax_debug']['time'][]
+ * with the values inside of $this->error
+ *
+ * @access public
+ */
+ function sessionError()
+ {
+ $_SESSION['html_ajax_debug']['time'][] = $this->error;
+ }
+ // }}}
+ // {{{ _saveError
+ /**
+ * This function saves the error to a file
+ * appending to this file.
+ *
+ * @access private.
+ */
+ function _saveError()
+ {
+ if ($handle = fopen($this->file, 'a')) {
+ fwrite($handle, $this->error);
+ }
+ }
+ // }}}
+}
+// }}}
+?>
View
113 AJAX/Helper.php
@@ -0,0 +1,113 @@
+<?php
+/**
+ * HTML/JavaScript Generation Helper
+ *
+ * @category HTML
+ * @package AJAX
+ * @author Joshua Eichorn <josh@bluga.net>
+ * @copyright 2005 Joshua Eichorn
+ * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
+ * @version Release: @package_version@
+ */
+
+/**
+ * HTML/JavaScript Generation Helper
+ *
+ * @category HTML
+ * @package AJAX
+ * @author Joshua Eichorn <josh@bluga.net>
+ * @copyright 2005 Joshua Eichorn
+ * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
+ * @version Release: @package_version@
+ * @link http://pear.php.net/package/HTML_AJAX
+ */
+class HTML_AJAX_Helper
+{
+ /**
+ * URL where an HTML_AJAX_Server instance is serving up clients and taking ajax requests
+ */
+ var $serverUrl = 'server.php';
+
+ /**
+ * JS libraries to include
+ *
+ * @var array
+ */
+ var $jsLibraries = array('Util','Main','Request','HttpClient','Dispatcher','Behavior','Loading');
+
+ /**
+ * Include all needed libraries, stubs, and set defaultServer
+ *
+ * @return string
+ */
+ function setupAJAX()
+ {
+ $libs = implode(',',$this->jsLibraries);
+ $ret = "<script type='text/javascript' src='{$this->serverUrl}?client={$libs}'></script>\n";
+ $ret .= $this->encloseInScript('HTML_AJAX.defaultServerUrl = '.$this->escape($this->serverUrl));
+ return $ret;
+ }
+
+ /**
+ * Create a custom Loading message
+ *
+ * @param string $body HTML body of the loading div
+ * @param string $class CSS class of the div
+ * @param string $style style tag of the loading div
+ */
+ function loadingMessage($body, $class = 'HTML_AJAX_Loading',
+ $style = 'position: absolute; top: 0; right: 0; backgroundColor: red; width: 80px; padding: 4px; display: none')
+ {
+ return "<div id='HTML_AJAX_LOADING' class='{$class}' style=\"{$style}\">{$body}</div>\n";
+ }
+
+ /**
+ * Update the contents of an element using ajax
+ *
+ * @param string $id id of the element to update
+ * @param string|array $update Either a url to update with or a array like array('class','method')
+ * @param string $type replace or append
+ * @param boolean $enclose
+ */
+ function updateElement($id, $update, $type, $enclose = false) {
+ if (is_array($update)) {
+ $updateStr = "";
+ $comma = '';
+ foreach($update as $item) {
+ $updateStr .= $comma.$this->escape($item);
+ $comma = ',';
+ }
+ }
+ else {
+ $updateStr = $this->escape($update);
+ }
+
+ $ret = "HTML_AJAX.{$type}(".$this->escape($id).",{$updateStr});\n";
+ if ($enclose) {
+ $ret = $this->encloseInScript($ret);
+ }
+ return $ret;
+ }
+
+ /**
+ * Escape a string and add quotes allowing it to be a javascript paramater
+ *
+ * @param string $input
+ * @return string
+ * @todo do something here besides a quick hack
+ */
+ function escape($input) {
+ return "'".addslashes($input)."'";
+ }
+
+ /**
+ * Enclose a string in a script block
+ *
+ * @param string $input
+ * @return string
+ */
+ function encloseInScript($input) {
+ return '<script type="text/javascript">'.$input."</script>\n";
+ }
+}
+?>
Please sign in to comment.
Something went wrong with that request. Please try again.