Skip to content

Commit

Permalink
MDL-16500 Removed the old Jabber class from the module and moved to a…
Browse files Browse the repository at this point in the history
… new one called xmpphp in core libraries

           Also cleaned up some notices in message/edit.php
  • Loading branch information
moodler committed Sep 15, 2008
1 parent fa7bec7 commit 838a8eb
Show file tree
Hide file tree
Showing 17 changed files with 1,378 additions and 3,391 deletions.
39 changes: 39 additions & 0 deletions lib/jabber/XMPP/Exception.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* XMPPHP: The PHP XMPP Library
* Copyright (C) 2008 Nathanael C. Fritz
* This file is part of SleekXMPP.
*
* XMPPHP is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* XMPPHP is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XMPPHP; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category xmpphp
* @package XMPPHP
* @author Nathanael C. Fritz <JID: [email protected]>
* @author Stephan Wentz <JID: [email protected]>
* @copyright 2008 Nathanael C. Fritz
*/

/**
* XMPPHP Exception
*
* @category xmpphp
* @package XMPPHP
* @author Nathanael C. Fritz <JID: [email protected]>
* @author Stephan Wentz <JID: [email protected]>
* @copyright 2008 Nathanael C. Fritz
* @version $Id$
*/
class XMPPHP_Exception extends Exception {
}
116 changes: 116 additions & 0 deletions lib/jabber/XMPP/Log.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php
/**
* XMPPHP: The PHP XMPP Library
* Copyright (C) 2008 Nathanael C. Fritz
* This file is part of SleekXMPP.
*
* XMPPHP is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* XMPPHP is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XMPPHP; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category xmpphp
* @package XMPPHP
* @author Nathanael C. Fritz <JID: [email protected]>
* @author Stephan Wentz <JID: [email protected]>
* @copyright 2008 Nathanael C. Fritz
*/

/**
* XMPPHP Log
*
* @package XMPPHP
* @author Nathanael C. Fritz <JID: [email protected]>
* @author Stephan Wentz <JID: [email protected]>
* @copyright 2008 Nathanael C. Fritz
* @version $Id$
*/
class XMPPHP_Log {

const LEVEL_ERROR = 0;
const LEVEL_WARNING = 1;
const LEVEL_INFO = 2;
const LEVEL_DEBUG = 3;
const LEVEL_VERBOSE = 4;

/**
* @var array
*/
protected $data = array();

/**
* @var array
*/
protected $names = array('ERROR', 'WARNING', 'INFO', 'DEBUG', 'VERBOSE');

/**
* @var integer
*/
protected $runlevel;

/**
* @var boolean
*/
protected $printout;

/**
* Constructor
*
* @param boolean $printout
* @param string $runlevel
*/
public function __construct($printout = false, $runlevel = self::LEVEL_INFO) {
$this->printout = (boolean)$printout;
$this->runlevel = (int)$runlevel;
}

/**
* Add a message to the log data array
* If printout in this instance is set to true, directly output the message
*
* @param string $msg
* @param integer $runlevel
*/
public function log($msg, $runlevel = self::LEVEL_INFO) {
$time = time();
$this->data[] = array($this->runlevel, $msg, $time);
if($this->printout and $runlevel <= $this->runlevel) {
$this->writeLine($msg, $runlevel, $time);
}
}

/**
* Output the complete log.
* Log will be cleared if $clear = true
*
* @param boolean $clear
* @param integer $runlevel
*/
public function printout($clear = true, $runlevel = null) {
if($runlevel === null) {
$runlevel = $this->runlevel;
}
foreach($this->data as $data) {
if($runlevel <= $data[0]) {
$this->writeLine($data[1], $runlevel, $data[2]);
}
}
if($clear) {
$this->data = array();
}
}

protected function writeLine($msg, $runlevel, $time) {
//echo date('Y-m-d H:i:s', $time)." [".$this->names[$runlevel]."]: ".$msg."\n";
echo $time." [".$this->names[$runlevel]."]: ".$msg."\n";
}
}
155 changes: 155 additions & 0 deletions lib/jabber/XMPP/XMLObj.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<?php
/**
* XMPPHP: The PHP XMPP Library
* Copyright (C) 2008 Nathanael C. Fritz
* This file is part of SleekXMPP.
*
* XMPPHP is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* XMPPHP is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XMPPHP; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category xmpphp
* @package XMPPHP
* @author Nathanael C. Fritz <JID: [email protected]>
* @author Stephan Wentz <JID: [email protected]>
* @copyright 2008 Nathanael C. Fritz
*/

/**
* XMPPHP XML Object
*
* @category xmpphp
* @package XMPPHP
* @author Nathanael C. Fritz <JID: [email protected]>
* @author Stephan Wentz <JID: [email protected]>
* @copyright 2008 Nathanael C. Fritz
* @version $Id$
*/
class XMPPHP_XMLObj {
/**
* Tag name
*
* @var string
*/
public $name;

/**
* Namespace
*
* @var string
*/
public $ns;

/**
* Attributes
*
* @var array
*/
public $attrs = array();

/**
* Subs?
*
* @var array
*/
public $subs = array();

/**
* Node data
*
* @var string
*/
public $data = '';

/**
* Constructor
*
* @param string $name
* @param string $ns
* @param array $attrs
* @param string $data
*/
public function __construct($name, $ns = '', $attrs = array(), $data = '') {
$this->name = strtolower($name);
$this->ns = $ns;
if(is_array($attrs) && count($attrs)) {
foreach($attrs as $key => $value) {
$this->attrs[strtolower($key)] = $value;
}
}
$this->data = $data;
}

/**
* Dump this XML Object to output.
*
* @param integer $depth
*/
public function printObj($depth = 0) {
print str_repeat("\t", $depth) . $this->name . " " . $this->ns . ' ' . $this->data;
print "\n";
foreach($this->subs as $sub) {
$sub->printObj($depth + 1);
}
}

/**
* Return this XML Object in xml notation
*
* @param string $str
*/
public function toString($str = '') {
$str .= "<{$this->name} xmlns='{$this->ns}' ";
foreach($this->attrs as $key => $value) {
if($key != 'xmlns') {
$value = htmlspecialchars($value);
$str .= "$key='$value' ";
}
}
$str .= ">";
foreach($this->subs as $sub) {
$str .= $sub->toString();
}
$body = htmlspecialchars($this->data);
$str .= "$body</{$this->name}>";
return $str;
}

/**
* Has this XML Object the given sub?
*
* @param string $name
* @return boolean
*/
public function hasSub($name) {
foreach($this->subs as $sub) {
if($sub->name == $name) return true;
}
return false;
}

/**
* Return a sub
*
* @param string $name
* @param string $attrs
* @param string $ns
*/
public function sub($name, $attrs = null, $ns = null) {
foreach($this->subs as $sub) {
if($sub->name == $name) {
return $sub;
}
}
}
}
Loading

0 comments on commit 838a8eb

Please sign in to comment.