[pLog-svn] r2188 - in plugins/trunk: . moblog moblog/class
moblog/class/PEAR moblog/class/PEAR/Auth
moblog/class/PEAR/Auth/SASL moblog/class/PEAR/HTTP
moblog/class/PEAR/HTTP/Request moblog/class/PEAR/Net
moblog/class/action moblog/class/moblog moblog/class/security
moblog/class/view moblog/templates
mark at devel.plogworld.net
mark at devel.plogworld.net
Fri Jun 10 09:43:48 GMT 2005
Author: mark
Date: 2005-06-10 09:43:48 +0000 (Fri, 10 Jun 2005)
New Revision: 2188
Added:
plugins/trunk/moblog/class/PEAR/
plugins/trunk/moblog/class/PEAR/Auth/
plugins/trunk/moblog/class/PEAR/Auth/SASL.php
plugins/trunk/moblog/class/PEAR/Auth/SASL/
plugins/trunk/moblog/class/PEAR/Auth/SASL/Anonymous.php
plugins/trunk/moblog/class/PEAR/Auth/SASL/Common.php
plugins/trunk/moblog/class/PEAR/Auth/SASL/CramMD5.php
plugins/trunk/moblog/class/PEAR/Auth/SASL/DigestMD5.php
plugins/trunk/moblog/class/PEAR/Auth/SASL/Login.php
plugins/trunk/moblog/class/PEAR/Auth/SASL/Plain.php
plugins/trunk/moblog/class/PEAR/HTTP/
plugins/trunk/moblog/class/PEAR/HTTP/Request.php
plugins/trunk/moblog/class/PEAR/HTTP/Request/
plugins/trunk/moblog/class/PEAR/HTTP/Request/Listener.php
plugins/trunk/moblog/class/PEAR/Net/
plugins/trunk/moblog/class/PEAR/Net/POP3.php
plugins/trunk/moblog/class/PEAR/Net/Socket.php
plugins/trunk/moblog/class/PEAR/Net/URL.php
plugins/trunk/moblog/class/PEAR/PEAR.php
plugins/trunk/moblog/class/action/adminmoblogbatchpluginsettingsaction.class.php
plugins/trunk/moblog/class/action/adminmoblogbatchpluginupdatesettingsaction.class.php
plugins/trunk/moblog/class/security/
plugins/trunk/moblog/class/security/moblogbatchfilter.class.php
plugins/trunk/moblog/class/view/adminmoblogbatchpluginsettingsview.class.php
plugins/trunk/moblog/templates/moblogbatchsettings.template
plugins/trunk/moblogbatch.php
Modified:
plugins/trunk/moblog.php
plugins/trunk/moblog/class/moblog/moblogconstants.properties.php
plugins/trunk/moblog/class/moblog/moblogrequest.class.php
plugins/trunk/moblog/pluginmoblog.class.php
Log:
Update moblog plugins
1. Add pull modelto moblog plugin (wirh real/pseudi cron)
2. Fix file name encoding problem
3. Fix content encoding problem (with MOBLOG_FORCE_ENCODE_TO_UTF8 constant)
4. Add support for HTML format e-mail
Added: plugins/trunk/moblog/class/PEAR/Auth/SASL/Anonymous.php
===================================================================
--- plugins/trunk/moblog/class/PEAR/Auth/SASL/Anonymous.php 2005-06-10 09:00:01 UTC (rev 2187)
+++ plugins/trunk/moblog/class/PEAR/Auth/SASL/Anonymous.php 2005-06-10 09:43:48 UTC (rev 2188)
@@ -0,0 +1,71 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Copyright (c) 2002-2003 Richard Heyes |
+// | All rights reserved. |
+// | |
+// | Redistribution and use in source and binary forms, with or without |
+// | modification, are permitted provided that the following conditions |
+// | are met: |
+// | |
+// | o Redistributions of source code must retain the above copyright |
+// | notice, this list of conditions and the following disclaimer. |
+// | o Redistributions in binary form must reproduce the above copyright |
+// | notice, this list of conditions and the following disclaimer in the |
+// | documentation and/or other materials provided with the distribution.|
+// | o The names of the authors may not be used to endorse or promote |
+// | products derived from this software without specific prior written |
+// | permission. |
+// | |
+// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+// | |
+// +-----------------------------------------------------------------------+
+// | Author: Richard Heyes <richard at php.net> |
+// +-----------------------------------------------------------------------+
+//
+// $Id: Anonymous.php,v 1.4 2003/02/21 16:07:17 mj Exp $
+
+/**
+* Implmentation of ANONYMOUS SASL mechanism
+*
+* @author Richard Heyes <richard at php.net>
+* @access public
+* @version 1.0
+* @package Auth_SASL
+*/
+
+require_once('Auth/SASL/Common.php');
+
+class Auth_SASL_Anonymous extends Auth_SASL_Common
+{
+ /**
+ * Not much to do here except return the token supplied.
+ * No encoding, hashing or encryption takes place for this
+ * mechanism, simply one of:
+ * o An email address
+ * o An opaque string not containing "@" that can be interpreted
+ * by the sysadmin
+ * o Nothing
+ *
+ * We could have some logic here for the second option, but this
+ * would by no means create something interpretable.
+ *
+ * @param string $token Optional email address or string to provide
+ * as trace information.
+ * @return string The unaltered input token
+ */
+ function getResponse($token = '')
+ {
+ return $token;
+ }
+}
+?>
\ No newline at end of file
Added: plugins/trunk/moblog/class/PEAR/Auth/SASL/Common.php
===================================================================
--- plugins/trunk/moblog/class/PEAR/Auth/SASL/Common.php 2005-06-10 09:00:01 UTC (rev 2187)
+++ plugins/trunk/moblog/class/PEAR/Auth/SASL/Common.php 2005-06-10 09:43:48 UTC (rev 2188)
@@ -0,0 +1,74 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Copyright (c) 2002-2003 Richard Heyes |
+// | All rights reserved. |
+// | |
+// | Redistribution and use in source and binary forms, with or without |
+// | modification, are permitted provided that the following conditions |
+// | are met: |
+// | |
+// | o Redistributions of source code must retain the above copyright |
+// | notice, this list of conditions and the following disclaimer. |
+// | o Redistributions in binary form must reproduce the above copyright |
+// | notice, this list of conditions and the following disclaimer in the |
+// | documentation and/or other materials provided with the distribution.|
+// | o The names of the authors may not be used to endorse or promote |
+// | products derived from this software without specific prior written |
+// | permission. |
+// | |
+// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+// | |
+// +-----------------------------------------------------------------------+
+// | Author: Richard Heyes <richard at php.net> |
+// +-----------------------------------------------------------------------+
+//
+// $Id: Common.php,v 1.6 2003/02/21 16:07:17 mj Exp $
+
+/**
+* Common functionality to SASL mechanisms
+*
+* @author Richard Heyes <richard at php.net>
+* @access public
+* @version 1.0
+* @package Auth_SASL
+*/
+
+class Auth_SASL_Common
+{
+ /**
+ * Function which implements HMAC MD5 digest
+ *
+ * @param string $key The secret key
+ * @param string $data The data to protect
+ * @return string The HMAC MD5 digest
+ */
+ function _HMAC_MD5($key, $data)
+ {
+ if (strlen($key) > 64) {
+ $key = pack('H32', md5($key));
+ }
+
+ if (strlen($key) < 64) {
+ $key = str_pad($key, 64, chr(0));
+ }
+
+ $k_ipad = substr($key, 0, 64) ^ str_repeat(chr(0x36), 64);
+ $k_opad = substr($key, 0, 64) ^ str_repeat(chr(0x5C), 64);
+
+ $inner = pack('H32', md5($k_ipad . $data));
+ $digest = md5($k_opad . $inner);
+
+ return $digest;
+ }
+}
+?>
Added: plugins/trunk/moblog/class/PEAR/Auth/SASL/CramMD5.php
===================================================================
--- plugins/trunk/moblog/class/PEAR/Auth/SASL/CramMD5.php 2005-06-10 09:00:01 UTC (rev 2187)
+++ plugins/trunk/moblog/class/PEAR/Auth/SASL/CramMD5.php 2005-06-10 09:43:48 UTC (rev 2188)
@@ -0,0 +1,68 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Copyright (c) 2002-2003 Richard Heyes |
+// | All rights reserved. |
+// | |
+// | Redistribution and use in source and binary forms, with or without |
+// | modification, are permitted provided that the following conditions |
+// | are met: |
+// | |
+// | o Redistributions of source code must retain the above copyright |
+// | notice, this list of conditions and the following disclaimer. |
+// | o Redistributions in binary form must reproduce the above copyright |
+// | notice, this list of conditions and the following disclaimer in the |
+// | documentation and/or other materials provided with the distribution.|
+// | o The names of the authors may not be used to endorse or promote |
+// | products derived from this software without specific prior written |
+// | permission. |
+// | |
+// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+// | |
+// +-----------------------------------------------------------------------+
+// | Author: Richard Heyes <richard at php.net> |
+// +-----------------------------------------------------------------------+
+//
+// $Id: CramMD5.php,v 1.4 2003/02/21 16:07:17 mj Exp $
+
+/**
+* Implmentation of CRAM-MD5 SASL mechanism
+*
+* @author Richard Heyes <richard at php.net>
+* @access public
+* @version 1.0
+* @package Auth_SASL
+*/
+
+require_once('Auth/SASL/Common.php');
+
+class Auth_SASL_CramMD5 extends Auth_SASL_Common
+{
+ /**
+ * Implements the CRAM-MD5 SASL mechanism
+ * This DOES NOT base64 encode the return value,
+ * you will need to do that yourself.
+ *
+ * @param string $user Username
+ * @param string $pass Password
+ * @param string $challenge The challenge supplied by the server.
+ * this should be already base64_decoded.
+ *
+ * @return string The string to pass back to the server, of the form
+ * "<user> <digest>". This is NOT base64_encoded.
+ */
+ function getResponse($user, $pass, $challenge)
+ {
+ return $user . ' ' . $this->_HMAC_MD5($pass, $challenge);
+ }
+}
+?>
\ No newline at end of file
Added: plugins/trunk/moblog/class/PEAR/Auth/SASL/DigestMD5.php
===================================================================
--- plugins/trunk/moblog/class/PEAR/Auth/SASL/DigestMD5.php 2005-06-10 09:00:01 UTC (rev 2187)
+++ plugins/trunk/moblog/class/PEAR/Auth/SASL/DigestMD5.php 2005-06-10 09:43:48 UTC (rev 2188)
@@ -0,0 +1,194 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Copyright (c) 2002-2003 Richard Heyes |
+// | All rights reserved. |
+// | |
+// | Redistribution and use in source and binary forms, with or without |
+// | modification, are permitted provided that the following conditions |
+// | are met: |
+// | |
+// | o Redistributions of source code must retain the above copyright |
+// | notice, this list of conditions and the following disclaimer. |
+// | o Redistributions in binary form must reproduce the above copyright |
+// | notice, this list of conditions and the following disclaimer in the |
+// | documentation and/or other materials provided with the distribution.|
+// | o The names of the authors may not be used to endorse or promote |
+// | products derived from this software without specific prior written |
+// | permission. |
+// | |
+// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+// | |
+// +-----------------------------------------------------------------------+
+// | Author: Richard Heyes <richard at php.net> |
+// +-----------------------------------------------------------------------+
+//
+// $Id: DigestMD5.php,v 1.6 2003/02/21 16:07:17 mj Exp $
+
+/**
+* Implmentation of DIGEST-MD5 SASL mechanism
+*
+* @author Richard Heyes <richard at php.net>
+* @access public
+* @version 1.0
+* @package Auth_SASL
+*/
+
+require_once('Auth/SASL/Common.php');
+
+class Auth_SASL_DigestMD5 extends Auth_SASL_Common
+{
+ /**
+ * Provides the (main) client response for DIGEST-MD5
+ * requires a few extra parameters than the other
+ * mechanisms, which are unavoidable.
+ *
+ * @param string $authcid Authentication id (username)
+ * @param string $pass Password
+ * @param string $challenge The digest challenge sent by the server
+ * @param string $hostname The hostname of the machine you're connecting to
+ * @param string $service The servicename (eg. imap, pop, acap etc)
+ * @param string $authzid Authorization id (username to proxy as)
+ * @return string The digest response (NOT base64 encoded)
+ * @access public
+ */
+ function getResponse($authcid, $pass, $challenge, $hostname, $service, $authzid = '')
+ {
+ $challenge = $this->_parseChallenge($challenge);
+ $authzid_string = '';
+ if ($authzid != '') {
+ $authzid_string = ',authzid="' . $authzid . '"';
+ }
+
+ if (!empty($challenge)) {
+ $cnonce = $this->_getCnonce();
+ $digest_uri = sprintf('%s/%s', $service, $hostname);
+ $response_value = $this->_getResponseValue($authcid, $pass, $challenge['realm'], $challenge['nonce'], $cnonce, $digest_uri, $authzid);
+
+ return sprintf('username="%s",realm="%s"' . $authzid_string . ',nonce="%s",cnonce="%s",nc="00000001",qop=auth,digest-uri="%s",response=%s,%d', $authcid, $challenge['realm'], $challenge['nonce'], $cnonce, $digest_uri, $response_value, $challenge['maxbuf']);
+ } else {
+ return PEAR::raiseError('Invalid digest challenge');
+ }
+ }
+
+ /**
+ * Parses and verifies the digest challenge*
+ *
+ * @param string $challenge The digest challenge
+ * @return array The parsed challenge as an assoc
+ * array in the form "directive => value".
+ * @access private
+ */
+ function _parseChallenge($challenge)
+ {
+ $tokens = array();
+ while (preg_match('/^([a-z-]+)=("[^"]+(?<!\\\)"|[^,]+)/i', $challenge, $matches)) {
+
+ // Ignore these as per rfc2831
+ if ($matches[1] == 'opaque' OR $matches[1] == 'domain') {
+ $challenge = substr($challenge, strlen($matches[0]) + 1);
+ continue;
+ }
+
+ // Allowed multiple "realm" and "auth-param"
+ if (!empty($tokens[$matches[1]]) AND ($matches[1] == 'realm' OR $matches[1] == 'auth-param')) {
+ if (is_array($tokens[$matches[1]])) {
+ $tokens[$matches[1]][] = preg_replace('/^"(.*)"$/', '\\1', $matches[2]);
+ } else {
+ $tokens[$matches[1]] = array($tokens[$matches[1]], preg_replace('/^"(.*)"$/', '\\1', $matches[2]));
+ }
+
+ // Any other multiple instance = failure
+ } elseif (!empty($tokens[$matches[1]])) {
+ $tokens = array();
+ break;
+
+ } else {
+ $tokens[$matches[1]] = preg_replace('/^"(.*)"$/', '\\1', $matches[2]);
+ }
+
+ // Remove the just parsed directive from the challenge
+ $challenge = substr($challenge, strlen($matches[0]) + 1);
+ }
+
+ /**
+ * Defaults and required directives
+ */
+ // Realm
+ if (empty($tokens['realm'])) {
+ $uname = posix_uname();
+ $tokens['realm'] = $uname['nodename'];
+ }
+
+ // Maxbuf
+ if (empty($tokens['maxbuf'])) {
+ $tokens['maxbuf'] = 65536;
+ }
+
+ // Required: nonce, algorithm
+ if (empty($tokens['nonce']) OR empty($tokens['algorithm'])) {
+ return array();
+ }
+
+ return $tokens;
+ }
+
+ /**
+ * Creates the response= part of the digest response
+ *
+ * @param string $authcid Authentication id (username)
+ * @param string $pass Password
+ * @param string $realm Realm as provided by the server
+ * @param string $nonce Nonce as provided by the server
+ * @param string $cnonce Client nonce
+ * @param string $digest_uri The digest-uri= value part of the response
+ * @param string $authzid Authorization id
+ * @return string The response= part of the digest response
+ * @access private
+ */
+ function _getResponseValue($authcid, $pass, $realm, $nonce, $cnonce, $digest_uri, $authzid = '')
+ {
+ if ($authzid == '') {
+ $A1 = sprintf('%s:%s:%s', pack('H32', md5(sprintf('%s:%s:%s', $authcid, $realm, $pass))), $nonce, $cnonce);
+ } else {
+ $A1 = sprintf('%s:%s:%s:%s', pack('H32', md5(sprintf('%s:%s:%s', $authcid, $realm, $pass))), $nonce, $cnonce, $authzid);
+ }
+ $A2 = 'AUTHENTICATE:' . $digest_uri;
+ return md5(sprintf('%s:%s:00000001:%s:auth:%s', md5($A1), $nonce, $cnonce, md5($A2)));
+ }
+
+ /**
+ * Creates the client nonce for the response
+ *
+ * @return string The cnonce value
+ * @access private
+ */
+ function _getCnonce()
+ {
+ if (file_exists('/dev/urandom')) {
+ return base64_encode(fread(fopen('/dev/urandom', 'r'), 32));
+
+ } elseif (file_exists('/dev/random')) {
+ return base64_encode(fread(fopen('/dev/random', 'r'), 32));
+
+ } else {
+ $str = '';
+ mt_srand((double)microtime()*10000000);
+ for ($i=0; $i<32; $i++) {
+ $str .= chr(mt_rand(0, 255));
+ }
+
+ return base64_encode($str);
+ }
+ }
+}
+?>
Added: plugins/trunk/moblog/class/PEAR/Auth/SASL/Login.php
===================================================================
--- plugins/trunk/moblog/class/PEAR/Auth/SASL/Login.php 2005-06-10 09:00:01 UTC (rev 2187)
+++ plugins/trunk/moblog/class/PEAR/Auth/SASL/Login.php 2005-06-10 09:43:48 UTC (rev 2188)
@@ -0,0 +1,65 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Copyright (c) 2002-2003 Richard Heyes |
+// | All rights reserved. |
+// | |
+// | Redistribution and use in source and binary forms, with or without |
+// | modification, are permitted provided that the following conditions |
+// | are met: |
+// | |
+// | o Redistributions of source code must retain the above copyright |
+// | notice, this list of conditions and the following disclaimer. |
+// | o Redistributions in binary form must reproduce the above copyright |
+// | notice, this list of conditions and the following disclaimer in the |
+// | documentation and/or other materials provided with the distribution.|
+// | o The names of the authors may not be used to endorse or promote |
+// | products derived from this software without specific prior written |
+// | permission. |
+// | |
+// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+// | |
+// +-----------------------------------------------------------------------+
+// | Author: Richard Heyes <richard at php.net> |
+// +-----------------------------------------------------------------------+
+//
+// $Id: Login.php,v 1.4 2003/02/21 16:07:17 mj Exp $
+
+/**
+* This is technically not a SASL mechanism, however
+* it's used by Net_Sieve, Net_Cyrus and potentially
+* other protocols , so here is a good place to abstract
+* it.
+*
+* @author Richard Heyes <richard at php.net>
+* @access public
+* @version 1.0
+* @package Auth_SASL
+*/
+
+require_once('Auth/SASL/Common.php');
+
+class Auth_SASL_Login extends Auth_SASL_Common
+{
+ /**
+ * Pseudo SASL LOGIN mechanism
+ *
+ * @param string $user Username
+ * @param string $pass Password
+ * @return string LOGIN string
+ */
+ function getResponse($user, $pass)
+ {
+ return sprintf('LOGIN %s %s', $user, $pass);
+ }
+}
+?>
\ No newline at end of file
Added: plugins/trunk/moblog/class/PEAR/Auth/SASL/Plain.php
===================================================================
--- plugins/trunk/moblog/class/PEAR/Auth/SASL/Plain.php 2005-06-10 09:00:01 UTC (rev 2187)
+++ plugins/trunk/moblog/class/PEAR/Auth/SASL/Plain.php 2005-06-10 09:43:48 UTC (rev 2188)
@@ -0,0 +1,63 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Copyright (c) 2002-2003 Richard Heyes |
+// | All rights reserved. |
+// | |
+// | Redistribution and use in source and binary forms, with or without |
+// | modification, are permitted provided that the following conditions |
+// | are met: |
+// | |
+// | o Redistributions of source code must retain the above copyright |
+// | notice, this list of conditions and the following disclaimer. |
+// | o Redistributions in binary form must reproduce the above copyright |
+// | notice, this list of conditions and the following disclaimer in the |
+// | documentation and/or other materials provided with the distribution.|
+// | o The names of the authors may not be used to endorse or promote |
+// | products derived from this software without specific prior written |
+// | permission. |
+// | |
+// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+// | |
+// +-----------------------------------------------------------------------+
+// | Author: Richard Heyes <richard at php.net> |
+// +-----------------------------------------------------------------------+
+//
+// $Id: Plain.php,v 1.5 2003/02/21 16:07:17 mj Exp $
+
+/**
+* Implmentation of PLAIN SASL mechanism
+*
+* @author Richard Heyes <richard at php.net>
+* @access public
+* @version 1.0
+* @package Auth_SASL
+*/
+
+require_once('Auth/SASL/Common.php');
+
+class Auth_SASL_Plain extends Auth_SASL_Common
+{
+ /**
+ * Returns PLAIN response
+ *
+ * @param string $authcid Authentication id (username)
+ * @param string $pass Password
+ * @param string $authzid Autorization id
+ * @return string PLAIN Response
+ */
+ function getResponse($authcid, $pass, $authzid = '')
+ {
+ return $authzid . chr(0) . $authcid . chr(0) . $pass;
+ }
+}
+?>
Added: plugins/trunk/moblog/class/PEAR/Auth/SASL.php
===================================================================
--- plugins/trunk/moblog/class/PEAR/Auth/SASL.php 2005-06-10 09:00:01 UTC (rev 2187)
+++ plugins/trunk/moblog/class/PEAR/Auth/SASL.php 2005-06-10 09:43:48 UTC (rev 2188)
@@ -0,0 +1,98 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Copyright (c) 2002-2003 Richard Heyes |
+// | All rights reserved. |
+// | |
+// | Redistribution and use in source and binary forms, with or without |
+// | modification, are permitted provided that the following conditions |
+// | are met: |
+// | |
+// | o Redistributions of source code must retain the above copyright |
+// | notice, this list of conditions and the following disclaimer. |
+// | o Redistributions in binary form must reproduce the above copyright |
+// | notice, this list of conditions and the following disclaimer in the |
+// | documentation and/or other materials provided with the distribution.|
+// | o The names of the authors may not be used to endorse or promote |
+// | products derived from this software without specific prior written |
+// | permission. |
+// | |
+// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+// | |
+// +-----------------------------------------------------------------------+
+// | Author: Richard Heyes <richard at php.net> |
+// +-----------------------------------------------------------------------+
+//
+// $Id: SASL.php,v 1.4 2003/02/21 16:07:17 mj Exp $
+
+/**
+* Client implementation of various SASL mechanisms
+*
+* @author Richard Heyes <richard at php.net>
+* @access public
+* @version 1.0
+* @package Auth_SASL
+*/
+
+require_once (dirname(__FILE__).'/../PEAR.php');
+
+class Auth_SASL
+{
+ /**
+ * Factory class. Returns an object of the request
+ * type.
+ *
+ * @param string $type One of: Anonymous
+ * Plain
+ * CramMD5
+ * DigestMD5
+ * Types are not case sensitive
+ */
+ function &factory($type)
+ {
+ switch (strtolower($type)) {
+ case 'anonymous':
+ $filename = dirname(__FILE__).'/Auth/SASL/Anonymous.php';
+ $classname = 'Auth_SASL_Anonymous';
+ break;
+
+ case 'login':
+ $filename = dirname(__FILE__).'/Auth/SASL/Login.php';
+ $classname = 'Auth_SASL_Login';
+ break;
+
+ case 'plain':
+ $filename = dirname(__FILE__).'/Auth/SASL/Plain.php';
+ $classname = 'Auth_SASL_Plain';
+ break;
+
+ case 'crammd5':
+ $filename = dirname(__FILE__).'/Auth/SASL/CramMD5.php';
+ $classname = 'Auth_SASL_CramMD5';
+ break;
+
+ case 'digestmd5':
+ $filename = dirname(__FILE__).'/Auth/SASL/DigestMD5.php';
+ $classname = 'Auth_SASL_DigestMD5';
+ break;
+
+ default:
+ return PEAR::raiseError('Invalid SASL mechanism type');
+ break;
+ }
+
+ require_once($filename);
+ return new $classname();
+ }
+}
+
+?>
\ No newline at end of file
Added: plugins/trunk/moblog/class/PEAR/HTTP/Request/Listener.php
===================================================================
--- plugins/trunk/moblog/class/PEAR/HTTP/Request/Listener.php 2005-06-10 09:00:01 UTC (rev 2187)
+++ plugins/trunk/moblog/class/PEAR/HTTP/Request/Listener.php 2005-06-10 09:43:48 UTC (rev 2188)
@@ -0,0 +1,96 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Copyright (c) 2002-2003, Richard Heyes |
+// | All rights reserved. |
+// | |
+// | Redistribution and use in source and binary forms, with or without |
+// | modification, are permitted provided that the following conditions |
+// | are met: |
+// | |
+// | o Redistributions of source code must retain the above copyright |
+// | notice, this list of conditions and the following disclaimer. |
+// | o Redistributions in binary form must reproduce the above copyright |
+// | notice, this list of conditions and the following disclaimer in the |
+// | documentation and/or other materials provided with the distribution.|
+// | o The names of the authors may not be used to endorse or promote |
+// | products derived from this software without specific prior written |
+// | permission. |
+// | |
+// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+// | |
+// +-----------------------------------------------------------------------+
+// | Author: Alexey Borzov <avb at php.net> |
+// +-----------------------------------------------------------------------+
+//
+// $Id: Listener.php,v 1.2 2003/10/26 10:28:29 avb Exp $
+//
+
+/**
+ * This class implements the Observer part of a Subject-Observer
+ * design pattern. It listens to the events sent by a
+ * HTTP_Request or HTTP_Response instance.
+ *
+ * @package HTTP_Request
+ * @author Alexey Borzov <avb at php.net>
+ * @version $Revision: 1.2 $
+ */
+class HTTP_Request_Listener
+{
+ /**
+ * A listener's identifier
+ * @var string
+ */
+ var $_id;
+
+ /**
+ * Constructor, sets the object's identifier
+ *
+ * @access public
+ */
+ function HTTP_Request_Listener()
+ {
+ $this->_id = md5(uniqid('http_request_', 1));
+ }
+
+
+ /**
+ * Returns the listener's identifier
+ *
+ * @access public
+ * @return string
+ */
+ function getId()
+ {
+ return $this->_id;
+ }
+
+
+ /**
+ * This method is called when Listener is notified of an event
+ *
+ * @access public
+ * @param object an object the listener is attached to
+ * @param string Event name
+ * @param mixed Additional data
+ * @abstract
+ */
+ function update(&$subject, $event, $data = null)
+ {
+ echo "Notified of event: '$event'\n";
+ if (null !== $data) {
+ echo "Additional data: ";
+ var_dump($data);
+ }
+ }
+}
+?>
Added: plugins/trunk/moblog/class/PEAR/HTTP/Request.php
===================================================================
--- plugins/trunk/moblog/class/PEAR/HTTP/Request.php 2005-06-10 09:00:01 UTC (rev 2187)
+++ plugins/trunk/moblog/class/PEAR/HTTP/Request.php 2005-06-10 09:43:48 UTC (rev 2188)
@@ -0,0 +1,1143 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Copyright (c) 2002-2003, Richard Heyes |
+// | All rights reserved. |
+// | |
+// | Redistribution and use in source and binary forms, with or without |
+// | modification, are permitted provided that the following conditions |
+// | are met: |
+// | |
+// | o Redistributions of source code must retain the above copyright |
+// | notice, this list of conditions and the following disclaimer. |
+// | o Redistributions in binary form must reproduce the above copyright |
+// | notice, this list of conditions and the following disclaimer in the |
+// | documentation and/or other materials provided with the distribution.|
+// | o The names of the authors may not be used to endorse or promote |
+// | products derived from this software without specific prior written |
+// | permission. |
+// | |
+// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+// | |
+// +-----------------------------------------------------------------------+
+// | Author: Richard Heyes <richard at phpguru.org> |
+// +-----------------------------------------------------------------------+
+//
+// $Id: Request.php,v 1.41 2004/12/10 14:42:57 avb Exp $
+//
+// HTTP_Request Class
+//
+// Simple example, (Fetches yahoo.com and displays it):
+//
+// $a = &new HTTP_Request('http://www.yahoo.com/');
+// $a->sendRequest();
+// echo $a->getResponseBody();
+//
+
+require_once (dirname(__FILE__).'/../PEAR.php');
+require_once (dirname(__FILE__).'/../Net/Socket.php');
+require_once (dirname(__FILE__).'/../Net/URL.php');
+
+define('HTTP_REQUEST_METHOD_GET', 'GET', true);
+define('HTTP_REQUEST_METHOD_HEAD', 'HEAD', true);
+define('HTTP_REQUEST_METHOD_POST', 'POST', true);
+define('HTTP_REQUEST_METHOD_PUT', 'PUT', true);
+define('HTTP_REQUEST_METHOD_DELETE', 'DELETE', true);
+define('HTTP_REQUEST_METHOD_OPTIONS', 'OPTIONS', true);
+define('HTTP_REQUEST_METHOD_TRACE', 'TRACE', true);
+
+define('HTTP_REQUEST_HTTP_VER_1_0', '1.0', true);
+define('HTTP_REQUEST_HTTP_VER_1_1', '1.1', true);
+
+class HTTP_Request {
+
+ /**
+ * Instance of Net_URL
+ * @var object Net_URL
+ */
+ var $_url;
+
+ /**
+ * Type of request
+ * @var string
+ */
+ var $_method;
+
+ /**
+ * HTTP Version
+ * @var string
+ */
+ var $_http;
+
+ /**
+ * Request headers
+ * @var array
+ */
+ var $_requestHeaders;
+
+ /**
+ * Basic Auth Username
+ * @var string
+ */
+ var $_user;
+
+ /**
+ * Basic Auth Password
+ * @var string
+ */
+ var $_pass;
+
+ /**
+ * Socket object
+ * @var object Net_Socket
+ */
+ var $_sock;
+
+ /**
+ * Proxy server
+ * @var string
+ */
+ var $_proxy_host;
+
+ /**
+ * Proxy port
+ * @var integer
+ */
+ var $_proxy_port;
+
+ /**
+ * Proxy username
+ * @var string
+ */
+ var $_proxy_user;
+
+ /**
+ * Proxy password
+ * @var string
+ */
+ var $_proxy_pass;
+
+ /**
+ * Post data
+ * @var mixed
+ */
+ var $_postData;
+
+ /**
+ * Files to post
+ * @var array
+ */
+ var $_postFiles = array();
+
+ /**
+ * Connection timeout.
+ * @var float
+ */
+ var $_timeout;
+
+ /**
+ * HTTP_Response object
+ * @var object HTTP_Response
+ */
+ var $_response;
+
+ /**
+ * Whether to allow redirects
+ * @var boolean
+ */
+ var $_allowRedirects;
+
+ /**
+ * Maximum redirects allowed
+ * @var integer
+ */
+ var $_maxRedirects;
+
+ /**
+ * Current number of redirects
+ * @var integer
+ */
+ var $_redirects;
+
+ /**
+ * Whether to append brackets [] to array variables
+ * @var bool
+ */
+ var $_useBrackets = true;
+
+ /**
+ * Attached listeners
+ * @var array
+ */
+ var $_listeners = array();
+
+ /**
+ * Whether to save response body in response object property
+ * @var bool
+ */
+ var $_saveBody = true;
+
+ /**
+ * Timeout for reading from socket (array(seconds, microseconds))
+ * @var array
+ */
+ var $_readTimeout = null;
+
+ /**
+ * Options to pass to Net_Socket::connect. See stream_context_create
+ * @var array
+ */
+ var $_socketOptions = null;
+
+ /**
+ * Constructor
+ *
+ * Sets up the object
+ * @param string The url to fetch/access
+ * @param array Associative array of parameters which can have the following keys:
+ * <ul>
+ * <li>method - Method to use, GET, POST etc (string)</li>
+ * <li>http - HTTP Version to use, 1.0 or 1.1 (string)</li>
+ * <li>user - Basic Auth username (string)</li>
+ * <li>pass - Basic Auth password (string)</li>
+ * <li>proxy_host - Proxy server host (string)</li>
+ * <li>proxy_port - Proxy server port (integer)</li>
+ * <li>proxy_user - Proxy auth username (string)</li>
+ * <li>proxy_pass - Proxy auth password (string)</li>
+ * <li>timeout - Connection timeout in seconds (float)</li>
+ * <li>allowRedirects - Whether to follow redirects or not (bool)</li>
+ * <li>maxRedirects - Max number of redirects to follow (integer)</li>
+ * <li>useBrackets - Whether to append [] to array variable names (bool)</li>
+ * <li>saveBody - Whether to save response body in response object property (bool)</li>
+ * <li>readTimeout - Timeout for reading / writing data over the socket (array (seconds, microseconds))</li>
+ * <li>socketOptions - Options to pass to Net_Socket object (array)</li>
+ * </ul>
+ * @access public
+ */
+ function HTTP_Request($url = '', $params = array())
+ {
+ $this->_sock = &new Net_Socket();
+ $this->_method = HTTP_REQUEST_METHOD_GET;
+ $this->_http = HTTP_REQUEST_HTTP_VER_1_1;
+ $this->_requestHeaders = array();
+ $this->_postData = null;
+
+ $this->_user = null;
+ $this->_pass = null;
+
+ $this->_proxy_host = null;
+ $this->_proxy_port = null;
+ $this->_proxy_user = null;
+ $this->_proxy_pass = null;
+
+ $this->_allowRedirects = false;
+ $this->_maxRedirects = 3;
+ $this->_redirects = 0;
+
+ $this->_timeout = null;
+ $this->_response = null;
+
+ foreach ($params as $key => $value) {
+ $this->{'_' . $key} = $value;
+ }
+
+ if (!empty($url)) {
+ $this->setURL($url);
+ }
+
+ // Default useragent
+ $this->addHeader('User-Agent', 'PEAR HTTP_Request class ( http://pear.php.net/ )');
+
+ // Make sure keepalives dont knobble us
+ $this->addHeader('Connection', 'close');
+
+ // Basic authentication
+ if (!empty($this->_user)) {
+ $this->_requestHeaders['Authorization'] = 'Basic ' . base64_encode($this->_user . ':' . $this->_pass);
+ }
+
+ // Use gzip encoding if possible
+ // Avoid gzip encoding if using multibyte functions (see #1781)
+ if (HTTP_REQUEST_HTTP_VER_1_1 == $this->_http && extension_loaded('zlib') &&
+ 0 == (2 & ini_get('mbstring.func_overload'))) {
+
+ $this->addHeader('Accept-Encoding', 'gzip');
+ }
+ }
+
+ /**
+ * Generates a Host header for HTTP/1.1 requests
+ *
+ * @access private
+ * @return string
+ */
+ function _generateHostHeader()
+ {
+ if ($this->_url->port != 80 AND strcasecmp($this->_url->protocol, 'http') == 0) {
+ $host = $this->_url->host . ':' . $this->_url->port;
+
+ } elseif ($this->_url->port != 443 AND strcasecmp($this->_url->protocol, 'https') == 0) {
+ $host = $this->_url->host . ':' . $this->_url->port;
+
+ } elseif ($this->_url->port == 443 AND strcasecmp($this->_url->protocol, 'https') == 0 AND strpos($this->_url->url, ':443') !== false) {
+ $host = $this->_url->host . ':' . $this->_url->port;
+
+ } else {
+ $host = $this->_url->host;
+ }
+
+ return $host;
+ }
+
+ /**
+ * Resets the object to its initial state (DEPRECATED).
+ * Takes the same parameters as the constructor.
+ *
+ * @param string $url The url to be requested
+ * @param array $params Associative array of parameters
+ * (see constructor for details)
+ * @access public
+ * @deprecated deprecated since 1.2, call the constructor if this is necessary
+ */
+ function reset($url, $params = array())
+ {
+ $this->HTTP_Request($url, $params);
+ }
+
+ /**
+ * Sets the URL to be requested
+ *
+ * @param string The url to be requested
+ * @access public
+ */
+ function setURL($url)
+ {
+ $this->_url = &new Net_URL($url, $this->_useBrackets);
+
+ if (!empty($this->_url->user) || !empty($this->_url->pass)) {
+ $this->setBasicAuth($this->_url->user, $this->_url->pass);
+ }
+
+ if (HTTP_REQUEST_HTTP_VER_1_1 == $this->_http) {
+ $this->addHeader('Host', $this->_generateHostHeader());
+ }
+ }
+
+ /**
+ * Sets a proxy to be used
+ *
+ * @param string Proxy host
+ * @param int Proxy port
+ * @param string Proxy username
+ * @param string Proxy password
+ * @access public
+ */
+ function setProxy($host, $port = 8080, $user = null, $pass = null)
+ {
+ $this->_proxy_host = $host;
+ $this->_proxy_port = $port;
+ $this->_proxy_user = $user;
+ $this->_proxy_pass = $pass;
+
+ if (!empty($user)) {
+ $this->addHeader('Proxy-Authorization', 'Basic ' . base64_encode($user . ':' . $pass));
+ }
+ }
+
+ /**
+ * Sets basic authentication parameters
+ *
+ * @param string Username
+ * @param string Password
+ */
+ function setBasicAuth($user, $pass)
+ {
+ $this->_user = $user;
+ $this->_pass = $pass;
+
+ $this->addHeader('Authorization', 'Basic ' . base64_encode($user . ':' . $pass));
+ }
+
+ /**
+ * Sets the method to be used, GET, POST etc.
+ *
+ * @param string Method to use. Use the defined constants for this
+ * @access public
+ */
+ function setMethod($method)
+ {
+ $this->_method = $method;
+ }
+
+ /**
+ * Sets the HTTP version to use, 1.0 or 1.1
+ *
+ * @param string Version to use. Use the defined constants for this
+ * @access public
+ */
+ function setHttpVer($http)
+ {
+ $this->_http = $http;
+ }
+
+ /**
+ * Adds a request header
+ *
+ * @param string Header name
+ * @param string Header value
+ * @access public
+ */
+ function addHeader($name, $value)
+ {
+ $this->_requestHeaders[$name] = $value;
+ }
+
+ /**
+ * Removes a request header
+ *
+ * @param string Header name to remove
+ * @access public
+ */
+ function removeHeader($name)
+ {
+ if (isset($this->_requestHeaders[$name])) {
+ unset($this->_requestHeaders[$name]);
+ }
+ }
+
+ /**
+ * Adds a querystring parameter
+ *
+ * @param string Querystring parameter name
+ * @param string Querystring parameter value
+ * @param bool Whether the value is already urlencoded or not, default = not
+ * @access public
+ */
+ function addQueryString($name, $value, $preencoded = false)
+ {
+ $this->_url->addQueryString($name, $value, $preencoded);
+ }
+
+ /**
+ * Sets the querystring to literally what you supply
+ *
+ * @param string The querystring data. Should be of the format foo=bar&x=y etc
+ * @param bool Whether data is already urlencoded or not, default = already encoded
+ * @access public
+ */
+ function addRawQueryString($querystring, $preencoded = true)
+ {
+ $this->_url->addRawQueryString($querystring, $preencoded);
+ }
+
+ /**
+ * Adds postdata items
+ *
+ * @param string Post data name
+ * @param string Post data value
+ * @param bool Whether data is already urlencoded or not, default = not
+ * @access public
+ */
+ function addPostData($name, $value, $preencoded = false)
+ {
+ if ($preencoded) {
+ $this->_postData[$name] = $value;
+ } else {
+ $this->_postData[$name] = $this->_arrayMapRecursive('urlencode', $value);
+ }
+ }
+
+ /**
+ * Recursively applies the callback function to the value
+ *
+ * @param mixed Callback function
+ * @param mixed Value to process
+ * @access private
+ * @return mixed Processed value
+ */
+ function _arrayMapRecursive($callback, $value)
+ {
+ if (!is_array($value)) {
+ return call_user_func($callback, $value);
+ } else {
+ $map = array();
+ foreach ($value as $k => $v) {
+ $map[$k] = $this->_arrayMapRecursive($callback, $v);
+ }
+ return $map;
+ }
+ }
+
+ /**
+ * Adds a file to upload
+ *
+ * This also changes content-type to 'multipart/form-data' for proper upload
+ *
+ * @access public
+ * @param string name of file-upload field
+ * @param mixed file name(s)
+ * @param mixed content-type(s) of file(s) being uploaded
+ * @return bool true on success
+ * @throws PEAR_Error
+ */
+ function addFile($inputName, $fileName, $contentType = 'application/octet-stream')
+ {
+ if (!is_array($fileName) && !is_readable($fileName)) {
+ return PEAR::raiseError("File '{$fileName}' is not readable");
+ } elseif (is_array($fileName)) {
+ foreach ($fileName as $name) {
+ if (!is_readable($name)) {
+ return PEAR::raiseError("File '{$name}' is not readable");
+ }
+ }
+ }
+ $this->addHeader('Content-Type', 'multipart/form-data');
+ $this->_postFiles[$inputName] = array(
+ 'name' => $fileName,
+ 'type' => $contentType
+ );
+ return true;
+ }
+
+ /**
+ * Adds raw postdata
+ *
+ * @param string The data
+ * @param bool Whether data is preencoded or not, default = already encoded
+ * @access public
+ */
+ function addRawPostData($postdata, $preencoded = true)
+ {
+ $this->_postData = $preencoded ? $postdata : urlencode($postdata);
+ }
+
+ /**
+ * Clears any postdata that has been added (DEPRECATED).
+ *
+ * Useful for multiple request scenarios.
+ *
+ * @access public
+ * @deprecated deprecated since 1.2
+ */
+ function clearPostData()
+ {
+ $this->_postData = null;
+ }
+
+ /**
+ * Appends a cookie to "Cookie:" header
+ *
+ * @param string $name cookie name
+ * @param string $value cookie value
+ * @access public
+ */
+ function addCookie($name, $value)
+ {
+ $cookies = isset($this->_requestHeaders['Cookie']) ? $this->_requestHeaders['Cookie']. '; ' : '';
+ $this->addHeader('Cookie', $cookies . $name . '=' . $value);
+ }
+
+ /**
+ * Clears any cookies that have been added (DEPRECATED).
+ *
+ * Useful for multiple request scenarios
+ *
+ * @access public
+ * @deprecated deprecated since 1.2
+ */
+ function clearCookies()
+ {
+ $this->removeHeader('Cookie');
+ }
+
+ /**
+ * Sends the request
+ *
+ * @access public
+ * @param bool Whether to store response body in Response object property,
+ * set this to false if downloading a LARGE file and using a Listener
+ * @return mixed PEAR error on error, true otherwise
+ */
+ function sendRequest($saveBody = true)
+ {
+ if (!is_a($this->_url, 'Net_URL')) {
+ return PEAR::raiseError('No URL given.');
+ }
+
+ $host = isset($this->_proxy_host) ? $this->_proxy_host : $this->_url->host;
+ $port = isset($this->_proxy_port) ? $this->_proxy_port : $this->_url->port;
+
+ // 4.3.0 supports SSL connections using OpenSSL. The function test determines
+ // we running on at least 4.3.0
+ if (strcasecmp($this->_url->protocol, 'https') == 0 AND function_exists('file_get_contents') AND extension_loaded('openssl')) {
+ if (isset($this->_proxy_host)) {
+ return PEAR::raiseError('HTTPS proxies are not supported.');
+ }
+ $host = 'ssl://' . $host;
+ }
+
+ // If this is a second request, we may get away without
+ // re-connecting if they're on the same server
+ if (PEAR::isError($err = $this->_sock->connect($host, $port, null, $this->_timeout, $this->_socketOptions)) ||
+ PEAR::isError($err = $this->_sock->write($this->_buildRequest()))) {
+
+ return $err;
+ }
+ if (!empty($this->_readTimeout)) {
+ $this->_sock->setTimeout($this->_readTimeout[0], $this->_readTimeout[1]);
+ }
+
+ $this->_notify('sentRequest');
+
+ // Read the response
+ $this->_response = &new HTTP_Response($this->_sock, $this->_listeners);
+ if (PEAR::isError($err = $this->_response->process($this->_saveBody && $saveBody)) ) {
+ return $err;
+ }
+
+ // Check for redirection
+ // Bugfix (PEAR) bug #18, 6 oct 2003 by Dave Mertens (headers are also stored lowercase, so we're gonna use them here)
+ // some non RFC2616 compliant servers (scripts) are returning lowercase headers ('location: xxx')
+ if ( $this->_allowRedirects
+ AND $this->_redirects <= $this->_maxRedirects
+ AND $this->getResponseCode() > 300
+ AND $this->getResponseCode() < 399
+ AND !empty($this->_response->_headers['location'])) {
+
+
+ $redirect = $this->_response->_headers['location'];
+
+ // Absolute URL
+ if (preg_match('/^https?:\/\//i', $redirect)) {
+ $this->_url = &new Net_URL($redirect);
+ $this->addHeader('Host', $this->_generateHostHeader());
+ // Absolute path
+ } elseif ($redirect{0} == '/') {
+ $this->_url->path = $redirect;
+
+ // Relative path
+ } elseif (substr($redirect, 0, 3) == '../' OR substr($redirect, 0, 2) == './') {
+ if (substr($this->_url->path, -1) == '/') {
+ $redirect = $this->_url->path . $redirect;
+ } else {
+ $redirect = dirname($this->_url->path) . '/' . $redirect;
+ }
+ $redirect = Net_URL::resolvePath($redirect);
+ $this->_url->path = $redirect;
+
+ // Filename, no path
+ } else {
+ if (substr($this->_url->path, -1) == '/') {
+ $redirect = $this->_url->path . $redirect;
+ } else {
+ $redirect = dirname($this->_url->path) . '/' . $redirect;
+ }
+ $this->_url->path = $redirect;
+ }
+
+ $this->_redirects++;
+ return $this->sendRequest($saveBody);
+
+ // Too many redirects
+ } elseif ($this->_allowRedirects AND $this->_redirects > $this->_maxRedirects) {
+ return PEAR::raiseError('Too many redirects');
+ }
+
+ $this->_sock->disconnect();
+
+ return true;
+ }
+
+ /**
+ * Returns the response code
+ *
+ * @access public
+ * @return mixed Response code, false if not set
+ */
+ function getResponseCode()
+ {
+ return isset($this->_response->_code) ? $this->_response->_code : false;
+ }
+
+ /**
+ * Returns either the named header or all if no name given
+ *
+ * @access public
+ * @param string The header name to return, do not set to get all headers
+ * @return mixed either the value of $headername (false if header is not present)
+ * or an array of all headers
+ */
+ function getResponseHeader($headername = null)
+ {
+ if (!isset($headername)) {
+ return isset($this->_response->_headers)? $this->_response->_headers: array();
+ } else {
+ return isset($this->_response->_headers[$headername]) ? $this->_response->_headers[$headername] : false;
+ }
+ }
+
+ /**
+ * Returns the body of the response
+ *
+ * @access public
+ * @return mixed response body, false if not set
+ */
+ function getResponseBody()
+ {
+ return isset($this->_response->_body) ? $this->_response->_body : false;
+ }
+
+ /**
+ * Returns cookies set in response
+ *
+ * @access public
+ * @return mixed array of response cookies, false if none are present
+ */
+ function getResponseCookies()
+ {
+ return isset($this->_response->_cookies) ? $this->_response->_cookies : false;
+ }
+
+ /**
+ * Builds the request string
+ *
+ * @access private
+ * @return string The request string
+ */
+ function _buildRequest()
+ {
+ $separator = ini_get('arg_separator.output');
+ ini_set('arg_separator.output', '&');
+ $querystring = ($querystring = $this->_url->getQueryString()) ? '?' . $querystring : '';
+ ini_set('arg_separator.output', $separator);
+
+ $host = isset($this->_proxy_host) ? $this->_url->protocol . '://' . $this->_url->host : '';
+ $port = (isset($this->_proxy_host) AND $this->_url->port != 80) ? ':' . $this->_url->port : '';
+ $path = (empty($this->_url->path)? '/': $this->_url->path) . $querystring;
+ $url = $host . $port . $path;
+
+ $request = $this->_method . ' ' . $url . ' HTTP/' . $this->_http . "\r\n";
+
+ if (HTTP_REQUEST_METHOD_POST != $this->_method && HTTP_REQUEST_METHOD_PUT != $this->_method) {
+ $this->removeHeader('Content-Type');
+ } else {
+ if (empty($this->_requestHeaders['Content-Type'])) {
+ // Add default content-type
+ $this->addHeader('Content-Type', 'application/x-www-form-urlencoded');
+ } elseif ('multipart/form-data' == $this->_requestHeaders['Content-Type']) {
+ $boundary = 'HTTP_Request_' . md5(uniqid('request') . microtime());
+ $this->addHeader('Content-Type', 'multipart/form-data; boundary=' . $boundary);
+ }
+ }
+
+ // Request Headers
+ if (!empty($this->_requestHeaders)) {
+ foreach ($this->_requestHeaders as $name => $value) {
+ $request .= $name . ': ' . $value . "\r\n";
+ }
+ }
+
+ // No post data or wrong method, so simply add a final CRLF
+ if ((HTTP_REQUEST_METHOD_POST != $this->_method && HTTP_REQUEST_METHOD_PUT != $this->_method) ||
+ (empty($this->_postData) && empty($this->_postFiles))) {
+
+ $request .= "\r\n";
+ // Post data if it's an array
+ } elseif ((!empty($this->_postData) && is_array($this->_postData)) || !empty($this->_postFiles)) {
+ // "normal" POST request
+ if (!isset($boundary)) {
+ $postdata = implode('&', array_map(
+ create_function('$a', 'return $a[0] . \'=\' . $a[1];'),
+ $this->_flattenArray('', $this->_postData)
+ ));
+
+ // multipart request, probably with file uploads
+ } else {
+ $postdata = '';
+ if (!empty($this->_postData)) {
+ $flatData = $this->_flattenArray('', $this->_postData);
+ foreach ($flatData as $item) {
+ $postdata .= '--' . $boundary . "\r\n";
+ $postdata .= 'Content-Disposition: form-data; name="' . $item[0] . '"';
+ $postdata .= "\r\n\r\n" . urldecode($item[1]) . "\r\n";
+ }
+ }
+ foreach ($this->_postFiles as $name => $value) {
+ if (is_array($value['name'])) {
+ $varname = $name . ($this->_useBrackets? '[]': '');
+ } else {
+ $varname = $name;
+ $value['name'] = array($value['name']);
+ }
+ foreach ($value['name'] as $key => $filename) {
+ $fp = fopen($filename, 'r');
+ $data = fread($fp, filesize($filename));
+ fclose($fp);
+ $basename = basename($filename);
+ $type = is_array($value['type'])? @$value['type'][$key]: $value['type'];
+
+ $postdata .= '--' . $boundary . "\r\n";
+ $postdata .= 'Content-Disposition: form-data; name="' . $varname . '"; filename="' . $basename . '"';
+ $postdata .= "\r\nContent-Type: " . $type;
+ $postdata .= "\r\n\r\n" . $data . "\r\n";
+ }
+ }
+ $postdata .= '--' . $boundary . "\r\n";
+ }
+ $request .= 'Content-Length: ' . strlen($postdata) . "\r\n\r\n";
+ $request .= $postdata;
+
+ // Post data if it's raw
+ } elseif(!empty($this->_postData)) {
+ $request .= 'Content-Length: ' . strlen($this->_postData) . "\r\n\r\n";
+ $request .= $this->_postData;
+ }
+
+ return $request;
+ }
+
+ /**
+ * Helper function to change the (probably multidimensional) associative array
+ * into the simple one.
+ *
+ * @param string name for item
+ * @param mixed item's values
+ * @return array array with the following items: array('item name', 'item value');
+ */
+ function _flattenArray($name, $values)
+ {
+ if (!is_array($values)) {
+ return array(array($name, $values));
+ } else {
+ $ret = array();
+ foreach ($values as $k => $v) {
+ if (empty($name)) {
+ $newName = $k;
+ } elseif ($this->_useBrackets) {
+ $newName = $name . '[' . $k . ']';
+ } else {
+ $newName = $name;
+ }
+ $ret = array_merge($ret, $this->_flattenArray($newName, $v));
+ }
+ return $ret;
+ }
+ }
+
+
+ /**
+ * Adds a Listener to the list of listeners that are notified of
+ * the object's events
+ *
+ * @param object HTTP_Request_Listener instance to attach
+ * @return boolean whether the listener was successfully attached
+ * @access public
+ */
+ function attach(&$listener)
+ {
+ if (!is_a($listener, 'HTTP_Request_Listener')) {
+ return false;
+ }
+ $this->_listeners[$listener->getId()] =& $listener;
+ return true;
+ }
+
+
+ /**
+ * Removes a Listener from the list of listeners
+ *
+ * @param object HTTP_Request_Listener instance to detach
+ * @return boolean whether the listener was successfully detached
+ * @access public
+ */
+ function detach(&$listener)
+ {
+ if (!is_a($listener, 'HTTP_Request_Listener') ||
+ !isset($this->_listeners[$listener->getId()])) {
+ return false;
+ }
+ unset($this->_listeners[$listener->getId()]);
+ return true;
+ }
+
+
+ /**
+ * Notifies all registered listeners of an event.
+ *
+ * Events sent by HTTP_Request object
+ * 'sentRequest': after the request was sent
+ * Events sent by HTTP_Response object
+ * 'gotHeaders': after receiving response headers (headers are passed in $data)
+ * 'tick': on receiving a part of response body (the part is passed in $data)
+ * 'gzTick': on receiving a gzip-encoded part of response body (ditto)
+ * 'gotBody': after receiving the response body (passes the decoded body in $data if it was gzipped)
+ *
+ * @param string Event name
+ * @param mixed Additional data
+ * @access private
+ */
+ function _notify($event, $data = null)
+ {
+ foreach (array_keys($this->_listeners) as $id) {
+ $this->_listeners[$id]->update($this, $event, $data);
+ }
+ }
+}
+
+
+/**
+* Response class to complement the Request class
+*/
+class HTTP_Response
+{
+ /**
+ * Socket object
+ * @var object
+ */
+ var $_sock;
+
+ /**
+ * Protocol
+ * @var string
+ */
+ var $_protocol;
+
+ /**
+ * Return code
+ * @var string
+ */
+ var $_code;
+
+ /**
+ * Response headers
+ * @var array
+ */
+ var $_headers;
+
+ /**
+ * Cookies set in response
+ * @var array
+ */
+ var $_cookies;
+
+ /**
+ * Response body
+ * @var string
+ */
+ var $_body = '';
+
+ /**
+ * Used by _readChunked(): remaining length of the current chunk
+ * @var string
+ */
+ var $_chunkLength = 0;
+
+ /**
+ * Attached listeners
+ * @var array
+ */
+ var $_listeners = array();
+
+ /**
+ * Constructor
+ *
+ * @param object Net_Socket socket to read the response from
+ * @param array listeners attached to request
+ * @return mixed PEAR Error on error, true otherwise
+ */
+ function HTTP_Response(&$sock, &$listeners)
+ {
+ $this->_sock =& $sock;
+ $this->_listeners =& $listeners;
+ }
+
+
+ /**
+ * Processes a HTTP response
+ *
+ * This extracts response code, headers, cookies and decodes body if it
+ * was encoded in some way
+ *
+ * @access public
+ * @param bool Whether to store response body in object property, set
+ * this to false if downloading a LARGE file and using a Listener.
+ * This is assumed to be true if body is gzip-encoded.
+ * @throws PEAR_Error
+ * @return mixed true on success, PEAR_Error in case of malformed response
+ */
+ function process($saveBody = true)
+ {
+ do {
+ $line = $this->_sock->readLine();
+ if (sscanf($line, 'HTTP/%s %s', $http_version, $returncode) != 2) {
+ return PEAR::raiseError('Malformed response.');
+ } else {
+ $this->_protocol = 'HTTP/' . $http_version;
+ $this->_code = intval($returncode);
+ }
+ while ('' !== ($header = $this->_sock->readLine())) {
+ $this->_processHeader($header);
+ }
+ } while (100 == $this->_code);
+
+ $this->_notify('gotHeaders', $this->_headers);
+
+ // If response body is present, read it and decode
+ $chunked = isset($this->_headers['transfer-encoding']) && ('chunked' == $this->_headers['transfer-encoding']);
+ $gzipped = isset($this->_headers['content-encoding']) && ('gzip' == $this->_headers['content-encoding']);
+ $hasBody = false;
+ while (!$this->_sock->eof()) {
+ if ($chunked) {
+ $data = $this->_readChunked();
+ } else {
+ $data = $this->_sock->read(4096);
+ }
+ if ('' != $data) {
+ $hasBody = true;
+ if ($saveBody || $gzipped) {
+ $this->_body .= $data;
+ }
+ $this->_notify($gzipped? 'gzTick': 'tick', $data);
+ }
+ }
+ if ($hasBody) {
+ // Uncompress the body if needed
+ if ($gzipped) {
+ $this->_body = gzinflate(substr($this->_body, 10));
+ $this->_notify('gotBody', $this->_body);
+ } else {
+ $this->_notify('gotBody');
+ }
+ }
+ return true;
+ }
+
+
+ /**
+ * Processes the response header
+ *
+ * @access private
+ * @param string HTTP header
+ */
+ function _processHeader($header)
+ {
+ list($headername, $headervalue) = explode(':', $header, 2);
+ $headername_i = strtolower($headername);
+ $headervalue = ltrim($headervalue);
+
+ if ('set-cookie' != $headername_i) {
+ $this->_headers[$headername] = $headervalue;
+ $this->_headers[$headername_i] = $headervalue;
+ } else {
+ $this->_parseCookie($headervalue);
+ }
+ }
+
+
+ /**
+ * Parse a Set-Cookie header to fill $_cookies array
+ *
+ * @access private
+ * @param string value of Set-Cookie header
+ */
+ function _parseCookie($headervalue)
+ {
+ $cookie = array(
+ 'expires' => null,
+ 'domain' => null,
+ 'path' => null,
+ 'secure' => false
+ );
+
+ // Only a name=value pair
+ if (!strpos($headervalue, ';')) {
+ $pos = strpos($headervalue, '=');
+ $cookie['name'] = trim(substr($headervalue, 0, $pos));
+ $cookie['value'] = trim(substr($headervalue, $pos + 1));
+
+ // Some optional parameters are supplied
+ } else {
+ $elements = explode(';', $headervalue);
+ $pos = strpos($elements[0], '=');
+ $cookie['name'] = trim(substr($elements[0], 0, $pos));
+ $cookie['value'] = trim(substr($elements[0], $pos + 1));
+
+ for ($i = 1; $i < count($elements); $i++) {
+ if (false === strpos($elements[$i], '=')) {
+ $elName = trim($elements[$i]);
+ $elValue = null;
+ } else {
+ list ($elName, $elValue) = array_map('trim', explode('=', $elements[$i]));
+ }
+ $elName = strtolower($elName);
+ if ('secure' == $elName) {
+ $cookie['secure'] = true;
+ } elseif ('expires' == $elName) {
+ $cookie['expires'] = str_replace('"', '', $elValue);
+ } elseif ('path' == $elName || 'domain' == $elName) {
+ $cookie[$elName] = urldecode($elValue);
+ } else {
+ $cookie[$elName] = $elValue;
+ }
+ }
+ }
+ $this->_cookies[] = $cookie;
+ }
+
+
+ /**
+ * Read a part of response body encoded with chunked Transfer-Encoding
+ *
+ * @access private
+ * @return string
+ */
+ function _readChunked()
+ {
+ // at start of the next chunk?
+ if (0 == $this->_chunkLength) {
+ $line = $this->_sock->readLine();
+ if (preg_match('/^([0-9a-f]+)/i', $line, $matches)) {
+ $this->_chunkLength = hexdec($matches[1]);
+ // Chunk with zero length indicates the end
+ if (0 == $this->_chunkLength) {
+ $this->_sock->readAll(); // make this an eof()
+ return '';
+ }
+ } elseif ($this->_sock->eof()) {
+ return '';
+ }
+ }
+ $data = $this->_sock->read($this->_chunkLength);
+ $this->_chunkLength -= strlen($data);
+ if (0 == $this->_chunkLength) {
+ $this->_sock->readLine(); // Trailing CRLF
+ }
+ return $data;
+ }
+
+
+ /**
+ * Notifies all registered listeners of an event.
+ *
+ * @param string Event name
+ * @param mixed Additional data
+ * @access private
+ * @see HTTP_Request::_notify()
+ */
+ function _notify($event, $data = null)
+ {
+ foreach (array_keys($this->_listeners) as $id) {
+ $this->_listeners[$id]->update($this, $event, $data);
+ }
+ }
+} // End class HTTP_Response
+?>
Added: plugins/trunk/moblog/class/PEAR/Net/POP3.php
===================================================================
--- plugins/trunk/moblog/class/PEAR/Net/POP3.php 2005-06-10 09:00:01 UTC (rev 2187)
+++ plugins/trunk/moblog/class/PEAR/Net/POP3.php 2005-06-10 09:43:48 UTC (rev 2188)
@@ -0,0 +1,1224 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Copyright (c) 2002, Richard Heyes |
+// | All rights reserved. |
+// | |
+// | Redistribution and use in source and binary forms, with or without |
+// | modification, are permitted provided that the following conditions |
+// | are met: |
+// | |
+// | o Redistributions of source code must retain the above copyright |
+// | notice, this list of conditions and the following disclaimer. |
+// | o Redistributions in binary form must reproduce the above copyright |
+// | notice, this list of conditions and the following disclaimer in the |
+// | documentation and/or other materials provided with the distribution.|
+// | o The names of the authors may not be used to endorse or promote |
+// | products derived from this software without specific prior written |
+// | permission. |
+// | |
+// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+// | |
+// +-----------------------------------------------------------------------+
+// | Author: Richard Heyes <richard at phpguru.org> |
+// | Co-Author: Damian Fernandez Sosa <damlists at cnba.uba.ar> |
+// +-----------------------------------------------------------------------+
+//
+// $Id: POP3.php,v 1.2 2004/12/05 16:34:39 damian Exp $
+
+require_once (dirname(__FILE__).'/Socket.php');
+
+/**
+* +----------------------------- IMPORTANT ------------------------------+
+* | Usage of this class compared to native php extensions such as IMAP |
+* | is slow and may be feature deficient. If available you are STRONGLY |
+* | recommended to use the php extensions. |
+* +----------------------------------------------------------------------+
+*
+* POP3 Access Class
+*
+* For usage see the example script
+*/
+
+define('NET_POP3_STATE_DISCONNECTED', 1, true);
+define('NET_POP3_STATE_AUTHORISATION', 2, true);
+define('NET_POP3_STATE_TRANSACTION', 4, true);
+
+class Net_POP3 {
+
+ /*
+ * Some basic information about the mail drop
+ * garnered from the STAT command
+ *
+ * @var array
+ */
+ var $_maildrop;
+
+ /*
+ * Used for APOP to store the timestamp
+ *
+ * @var string
+ */
+ var $_timestamp;
+
+ /*
+ * Timeout that is passed to the socket object
+ *
+ * @var integer
+ */
+ var $_timeout;
+
+ /*
+ * Socket object
+ *
+ * @var object
+ */
+ var $_socket;
+
+ /*
+ * Current state of the connection. Used with the
+ * constants defined above.
+ *
+ * @var integer
+ */
+ var $_state;
+
+ /*
+ * Hostname to connect to
+ *
+ * @var string
+ */
+ var $_host;
+
+ /*
+ * Port to connect to
+ *
+ * @var integer
+ */
+ var $_port;
+
+ /**
+ * To allow class debuging
+ * @var boolean
+ */
+ var $_debug = false;
+
+
+ /**
+ * The auth methods this class support
+ * @var array
+ */
+ //var $supportedAuthMethods=array('DIGEST-MD5', 'CRAM-MD5', 'APOP' , 'PLAIN' , 'LOGIN', 'USER');
+ //Disabling DIGEST-MD5 for now
+ var $supportedAuthMethods=array( 'CRAM-MD5', 'APOP' , 'PLAIN' , 'LOGIN', 'USER');
+ //var $supportedAuthMethods=array( 'CRAM-MD5', 'PLAIN' , 'LOGIN');
+ //var $supportedAuthMethods=array( 'PLAIN' , 'LOGIN');
+
+
+ /**
+ * The auth methods this class support
+ * @var array
+ */
+ var $supportedSASLAuthMethods=array('DIGEST-MD5', 'CRAM-MD5');
+
+
+ /**
+ * The capability response
+ * @var array
+ */
+ var $_capability;
+
+ /*
+ * Constructor. Sets up the object variables, and instantiates
+ * the socket object.
+ *
+ */
+
+
+ function Net_POP3()
+ {
+ $this->_timestamp = ''; // Used for APOP
+ $this->_maildrop = array();
+ $this->_timeout = 3;
+ $this->_state = NET_POP3_STATE_DISCONNECTED;
+ $this->_socket =& new Net_Socket();
+ /*
+ * Include the Auth_SASL package. If the package is not available,
+ * we disable the authentication methods that depend upon it.
+ */
+ if ((@include_once dirname(__FILE__).'/../Auth/SASL.php') == false) {
+ if($this->_debug){
+ echo "AUTH_SASL NOT PRESENT!\n";
+ }
+ foreach($this->supportedSASLAuthMethods as $SASLMethod){
+ $pos = array_search( $SASLMethod, $this->supportedAuthMethods );
+ if($this->_debug){
+ echo "DISABLING METHOD $SASLMethod\n";
+ }
+ unset($this->supportedAuthMethods[$pos]);
+ }
+ }
+
+
+
+ }
+
+
+ /**
+ * Handles the errors the class can find
+ * on the server
+ *
+ * @access private
+ * @return PEAR_Error
+ */
+
+ function _raiseError($msg, $code =-1)
+ {
+ require_once (dirname(__FILE__).'/../PEAR.php');
+ return PEAR::raiseError($msg, $code);
+ }
+
+
+
+ /*
+ * Connects to the given host on the given port.
+ * Also looks for the timestamp in the greeting
+ * needed for APOP authentication
+ *
+ * @param string $host Hostname/IP address to connect to
+ * @param string $port Port to use to connect to on host
+ * @return bool Success/Failure
+ */
+ function connect($host = 'localhost', $port = 110)
+ {
+ $this->_host = $host;
+ $this->_port = $port;
+
+ $result = $this->_socket->connect($host, $port, false, $this->_timeout);
+ if ($result === true) {
+ $data = $this->_recvLn();
+
+ if( $this->_checkResponse($data) ){
+ // if the response begins with '+OK' ...
+// if (@substr(strtoupper($data), 0, 3) == '+OK') {
+ // Check for string matching apop timestamp
+ if (preg_match('/<.+ at .+>/U', $data, $matches)) {
+ $this->_timestamp = $matches[0];
+ }
+ $this->_maildrop = array();
+ $this->_state = NET_POP3_STATE_AUTHORISATION;
+
+ return true;
+ }
+ }
+
+ $this->_socket->disconnect();
+ return false;
+ }
+
+ /*
+ * Disconnect function. Sends the QUIT command
+ * and closes the socket.
+ *
+ * @return bool Success/Failure
+ */
+ function disconnect()
+ {
+ return $this->_cmdQuit();
+ }
+
+ /*
+ * Performs the login procedure. If there is a timestamp
+ * stored, APOP will be tried first, then basic USER/PASS.
+ *
+ * @param string $user Username to use
+ * @param string $pass Password to use
+ * @param mixed $apop Whether to try APOP first, if used as string you can select the auth methd to use ( $pop3->login('validlogin', 'validpass', "CRAM-MD5");
+ * Valid methods are: 'DIGEST-MD5','CRAM-MD5','LOGIN','PLAIN','APOP','USER'
+ * @return mixed true on Success/ PEAR_ERROR on error
+ */
+ function login($user, $pass, $apop = true)
+ {
+ if ($this->_state == NET_POP3_STATE_AUTHORISATION) {
+
+ if(PEAR::isError($ret= $this->_cmdAuthenticate($user , $pass , $apop ) ) ){
+ return $ret;
+ }
+ if( ! PEAR::isError($ret)){
+ $this->_state = NET_POP3_STATE_TRANSACTION;
+ return true;
+ }
+
+ }
+ return $this->_raiseError('Generic login error' , 1);
+ }
+
+
+
+ /**
+ * Parses the response from the capability command. Stores
+ * the result in $this->_capability
+ *
+ * @access private
+ */
+ function _parseCapability()
+ {
+
+ if(!PEAR::isError($data = $this->_sendCmd('CAPA'))){
+ $data = $this->_getMultiline();
+ }else {
+ // CAPA command not supported, reset data var
+ // to avoid Notice errors of preg_split on an object
+ $data = '';
+ }
+ $data = preg_split('/\r?\n/', $data, -1, PREG_SPLIT_NO_EMPTY);
+
+ for ($i = 0; $i < count($data); $i++) {
+
+ $capa='';
+ if (preg_match('/^([a-z,\-]+)( ((.*))|$)$/i', $data[$i], $matches)) {
+
+ $capa=strtolower($matches[1]);
+ switch ($capa) {
+ case 'implementation':
+ $this->_capability['implementation'] = $matches[3];
+ break;
+ case 'sasl':
+ $this->_capability['sasl'] = preg_split('/\s+/', $matches[3]);
+ break;
+ default :
+ $this->_capability[$capa] = $matches[2];
+ break;
+ }
+ }
+ }
+ }
+
+
+
+
+ /**
+ * Returns the name of the best authentication method that the server
+ * has advertised.
+ *
+ * @param string if !=null,authenticate with this method ($userMethod).
+ *
+ * @return mixed Returns a string containing the name of the best
+ * supported authentication method or a PEAR_Error object
+ * if a failure condition is encountered.
+ * @access private
+ * @since 1.0
+ */
+ function _getBestAuthMethod($userMethod = null)
+ {
+
+/*
+ return 'USER';
+ return 'APOP';
+ return 'DIGEST-MD5';
+ return 'CRAM-MD5';
+*/
+
+
+ $this->_parseCapability();
+
+ //unset($this->_capability['sasl']);
+
+ if( isset($this->_capability['sasl']) ){
+ $serverMethods=$this->_capability['sasl'];
+ }else{
+ $serverMethods=array('USER');
+ // Check for timestamp before attempting APOP
+ if ($this->_timestamp != null)
+ {
+ $serverMethods[] = 'APOP';
+ }
+ }
+
+ if($userMethod !== null && $userMethod !== true ){
+ $methods = array();
+ $methods[] = $userMethod;
+ return $userMethod;
+ }else{
+ $methods = $this->supportedAuthMethods;
+ }
+
+ if( ($methods != null) && ($serverMethods != null)){
+
+ foreach ( $methods as $method ) {
+
+ if ( in_array( $method , $serverMethods ) ) {
+ return $method;
+ }
+ }
+ $serverMethods=implode(',' , $serverMethods );
+ $myMethods=implode(',' ,$this->supportedAuthMethods);
+ return $this->_raiseError("$method NOT supported authentication method!. This server " .
+ "supports these methods: $serverMethods, but I support $myMethods");
+ }else{
+ return $this->_raiseError("This server don't support any Auth methods");
+ }
+ }
+
+
+
+
+
+
+ /* Handles the authentication using any known method
+ *
+ * @param string The userid to authenticate as.
+ * @param string The password to authenticate with.
+ * @param string The method to use ( if $usermethod == '' then the class chooses the best method (the stronger is the best ) )
+ *
+ * @return mixed string or PEAR_Error
+ *
+ * @access private
+ * @since 1.0
+ */
+ function _cmdAuthenticate($uid , $pwd , $userMethod = null )
+ {
+
+
+ if ( PEAR::isError( $method = $this->_getBestAuthMethod($userMethod) ) ) {
+ return $method;
+ }
+
+ switch ($method) {
+ case 'DIGEST-MD5':
+ $result = $this->_authDigest_MD5( $uid , $pwd );
+ break;
+ case 'CRAM-MD5':
+ $result = $this->_authCRAM_MD5( $uid , $pwd );
+ break;
+ case 'LOGIN':
+ $result = $this->_authLOGIN( $uid , $pwd );
+ break;
+ case 'PLAIN':
+ $result = $this->_authPLAIN( $uid , $pwd );
+ break;
+ case 'APOP':
+ $result = $this->_cmdApop( $uid , $pwd );
+ // if APOP fails fallback to USER auth
+ if( PEAR::isError( $result ) ){
+ //echo "APOP FAILED!!!\n";
+ $result=$this->_authUSER( $uid , $pwd );
+ }
+ break;
+ case 'USER':
+ $result = $this->_authUSER( $uid , $pwd );
+ break;
+
+
+ default :
+ $result = $this->_raiseError( "$method is not a supported authentication method" );
+ break;
+ }
+ return $result;
+ }
+
+
+
+
+ /* Authenticates the user using the USER-PASS method.
+ *
+ * @param string The userid to authenticate as.
+ * @param string The password to authenticate with.
+ *
+ * @return mixed true on success or PEAR_Error on failure
+ *
+ * @access private
+ * @since 1.0
+ */
+ function _authUSER($user, $pass )
+ {
+ if ( PEAR::isError($ret=$this->_cmdUser($user) ) ){
+ return $ret;
+ }
+ if ( PEAR::isError($ret=$this->_cmdPass($pass) ) ){
+ return $ret;
+ }
+ return true;
+ }
+
+
+
+
+
+
+
+
+ /* Authenticates the user using the PLAIN method.
+ *
+ * @param string The userid to authenticate as.
+ * @param string The password to authenticate with.
+ *
+ * @return array Returns an array containing the response
+ *
+ * @access private
+ * @since 1.0
+ */
+ function _authPLAIN($user, $pass )
+ {
+ $cmd=sprintf('AUTH PLAIN %s', base64_encode( chr(0) . $user . chr(0) . $pass ) );
+
+ if ( PEAR::isError( $ret = $this->_send($cmd) ) ) {
+ return $ret;
+ }
+ if ( PEAR::isError( $challenge = $this->_recvLn() ) ){
+ return $challenge;
+ }
+ if( PEAR::isError($ret=$this->_checkResponse($challenge) )){
+ return $ret;
+ }
+
+ return true;
+ }
+
+
+
+ /* Authenticates the user using the PLAIN method.
+ *
+ * @param string The userid to authenticate as.
+ * @param string The password to authenticate with.
+ *
+ * @return array Returns an array containing the response
+ *
+ * @access private
+ * @since 1.0
+ */
+ function _authLOGIN($user, $pass )
+ {
+ $this->_send('AUTH LOGIN');
+
+ if ( PEAR::isError( $challenge = $this->_recvLn() ) ) {
+ return $challenge;
+ }
+ if( PEAR::isError($ret=$this->_checkResponse($challenge) )){
+ return $ret;
+ }
+
+
+ if ( PEAR::isError( $ret = $this->_send(sprintf('%s', base64_encode($user))) ) ) {
+ return $ret;
+ }
+
+ if ( PEAR::isError( $challenge = $this->_recvLn() ) ) {
+ return $challenge;
+ }
+ if( PEAR::isError($ret=$this->_checkResponse($challenge) )){
+ return $ret;
+ }
+
+ if ( PEAR::isError( $ret = $this->_send(sprintf('%s', base64_encode($pass))) ) ) {
+ return $ret;
+ }
+
+ if ( PEAR::isError( $challenge = $this->_recvLn() ) ) {
+ return $challenge;
+ }
+ return $this->_checkResponse($challenge);
+ }
+
+
+
+
+
+ /* Authenticates the user using the CRAM-MD5 method.
+ *
+ * @param string The userid to authenticate as.
+ * @param string The password to authenticate with.
+ *
+ * @return array Returns an array containing the response
+ *
+ * @access private
+ * @since 1.0
+ */
+ function _authCRAM_MD5($uid, $pwd )
+ {
+ if ( PEAR::isError( $ret = $this->_send( 'AUTH CRAM-MD5' ) ) ) {
+ return $ret;
+ }
+
+ if ( PEAR::isError( $challenge = $this->_recvLn() ) ) {
+ return $challenge;
+ }
+ if( PEAR::isError($ret=$this->_checkResponse($challenge) )){
+ return $ret;
+ }
+
+ // remove '+ '
+
+ $challenge=substr($challenge,2);
+
+ $challenge = base64_decode( $challenge );
+
+ $cram = &Auth_SASL::factory('crammd5');
+ $auth_str = base64_encode( $cram->getResponse( $uid , $pwd , $challenge ) );
+
+
+ if ( PEAR::isError($error = $this->_send( $auth_str ) ) ) {
+ return $error;
+ }
+ if ( PEAR::isError( $ret = $this->_recvLn() ) ) {
+ return $ret;
+ }
+ //echo "RET:$ret\n";
+ return $this->_checkResponse($ret);
+ }
+
+
+
+ /* Authenticates the user using the DIGEST-MD5 method.
+ *
+ * @param string The userid to authenticate as.
+ * @param string The password to authenticate with.
+ * @param string The efective user
+ *
+ * @return array Returns an array containing the response
+ *
+ * @access private
+ * @since 1.0
+ */
+ function _authDigest_MD5($uid, $pwd)
+ {
+ if ( PEAR::isError( $ret = $this->_send( 'AUTH DIGEST-MD5' ) ) ) {
+ return $ret;
+ }
+
+ if ( PEAR::isError( $challenge = $this->_recvLn() ) ) {
+ return $challenge;
+ }
+ if( PEAR::isError($ret=$this->_checkResponse($challenge) )){
+ return $ret;
+ }
+
+ // remove '+ '
+ $challenge=substr($challenge,2);
+
+ $challenge = base64_decode( $challenge );
+ $digest = &Auth_SASL::factory('digestmd5');
+ $auth_str = base64_encode($digest->getResponse($uid, $pwd, $challenge, "localhost", "pop3" ));
+
+ if ( PEAR::isError($error = $this->_send( $auth_str ) ) ) {
+ return $error;
+ }
+
+ if ( PEAR::isError( $challenge = $this->_recvLn() ) ) {
+ return $challenge;
+ }
+ if( PEAR::isError($ret=$this->_checkResponse($challenge) )){
+ return $ret;
+ }
+ /*
+ * We don't use the protocol's third step because POP3 doesn't allow
+ * subsequent authentication, so we just silently ignore it.
+ */
+
+ if ( PEAR::isError( $challenge = $this->_send("\r\n") ) ) {
+ return $challenge ;
+ }
+
+ if ( PEAR::isError( $challenge = $this->_recvLn() ) ) {
+ return $challenge;
+ }
+
+ return $this->_checkResponse($challenge);
+
+
+ }
+
+
+
+
+
+
+
+
+
+
+ /*
+ * Sends the APOP command
+ *
+ * @param $user Username to send
+ * @param $pass Password to send
+ * @return bool Success/Failure
+ */
+ function _cmdApop($user, $pass)
+ {
+ if ($this->_state == NET_POP3_STATE_AUTHORISATION) {
+
+ if (!empty($this->_timestamp)) {
+ if(PEAR::isError($data = $this->_sendCmd('APOP ' . $user . ' ' . md5($this->_timestamp . $pass)) ) ){
+ return $data;
+ }
+ $this->_state = NET_POP3_STATE_TRANSACTION;
+ return true;
+ }
+ }
+ return $this->_raiseError('Not In NET_POP3_STATE_AUTHORISATION State1');
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ /*
+ * Returns the raw headers of the specified message.
+ *
+ * @param integer $msg_id Message number
+ * @return mixed Either raw headers or false on error
+ */
+ function getRawHeaders($msg_id)
+ {
+ if ($this->_state == NET_POP3_STATE_TRANSACTION) {
+ return $this->_cmdTop($msg_id, 0);
+ }
+
+ return false;
+ }
+
+ /*
+ * Returns the headers of the specified message in an
+ * associative array. Array keys are the header names, array
+ * values are the header values. In the case of multiple headers
+ * having the same names, eg Received:, the array value will be
+ * an indexed array of all the header values.
+ *
+ * @param integer $msg_id Message number
+ * @return mixed Either array of headers or false on error
+ */
+ function getParsedHeaders($msg_id)
+ {
+ if ($this->_state == NET_POP3_STATE_TRANSACTION) {
+
+ $raw_headers = rtrim($this->getRawHeaders($msg_id));
+
+ $raw_headers = preg_replace("/\r\n[ \t]+/", ' ', $raw_headers); // Unfold headers
+ $raw_headers = explode("\r\n", $raw_headers);
+ foreach ($raw_headers as $value) {
+ $name = substr($value, 0, $pos = strpos($value, ':'));
+ $value = ltrim(substr($value, $pos + 1));
+ if (isset($headers[$name]) AND is_array($headers[$name])) {
+ $headers[$name][] = $value;
+ } elseif (isset($headers[$name])) {
+ $headers[$name] = array($headers[$name], $value);
+ } else {
+ $headers[$name] = $value;
+ }
+ }
+
+ return $headers;
+ }
+
+ return false;
+ }
+
+ /*
+ * Returns the body of the message with given message number.
+ *
+ * @param integer $msg_id Message number
+ * @return mixed Either message body or false on error
+ */
+ function getBody($msg_id)
+ {
+ if ($this->_state == NET_POP3_STATE_TRANSACTION) {
+ $msg = $this->_cmdRetr($msg_id);
+ return substr($msg, strpos($msg, "\r\n\r\n")+4);
+ }
+
+ return false;
+ }
+
+ /*
+ * Returns the entire message with given message number.
+ *
+ * @param integer $msg_id Message number
+ * @return mixed Either entire message or false on error
+ */
+ function getMsg($msg_id)
+ {
+ if ($this->_state == NET_POP3_STATE_TRANSACTION) {
+ return $this->_cmdRetr($msg_id);
+ }
+
+ return false;
+ }
+
+ /*
+ * Returns the size of the maildrop
+ *
+ * @return mixed Either size of maildrop or false on error
+ */
+ function getSize()
+ {
+ if ($this->_state == NET_POP3_STATE_TRANSACTION) {
+ if (isset($this->_maildrop['size'])) {
+ return $this->_maildrop['size'];
+ } else {
+ list(, $size) = $this->_cmdStat();
+ return $size;
+ }
+ }
+
+ return false;
+ }
+
+ /*
+ * Returns number of messages in this maildrop
+ *
+ * @return mixed Either number of messages or false on error
+ */
+ function numMsg()
+ {
+ if ($this->_state == NET_POP3_STATE_TRANSACTION) {
+ if (isset($this->_maildrop['num_msg'])) {
+ return $this->_maildrop['num_msg'];
+ } else {
+ list($num_msg, ) = $this->_cmdStat();
+ return $num_msg;
+ }
+ }
+
+ return false;
+ }
+
+ /*
+ * Marks a message for deletion. Only will be deleted if the
+ * disconnect() method is called.
+ *
+ * @param integer $msg_id Message to delete
+ * @return bool Success/Failure
+ */
+ function deleteMsg($msg_id)
+ {
+ if ($this->_state == NET_POP3_STATE_TRANSACTION) {
+ return $this->_cmdDele($msg_id);
+ }
+
+ return false;
+ }
+
+ /*
+ * Combination of LIST/UIDL commands, returns an array
+ * of data
+ *
+ * @param integer $msg_id Optional message number
+ * @return mixed Array of data or false on error
+ */
+ function getListing($msg_id = null)
+ {
+
+ if ($this->_state == NET_POP3_STATE_TRANSACTION) {
+ if (!isset($msg_id)){
+
+ $list=array();
+ if ($list = $this->_cmdList()) {
+ if ($uidl = $this->_cmdUidl()) {
+ foreach ($uidl as $i => $value) {
+ $list[$i]['uidl'] = $value['uidl'];
+ }
+ }
+ return $list;
+ }else{
+ return array();
+ }
+ } else {
+ if ($list = $this->_cmdList($msg_id) AND $uidl = $this->_cmdUidl($msg_id)) {
+ return array_merge($list, $uidl);
+ }
+ }
+ }
+
+ return false;
+ }
+
+ /*
+ * Sends the USER command
+ *
+ * @param string $user Username to send
+ * @return bool Success/Failure
+ */
+ function _cmdUser($user)
+ {
+ if ($this->_state == NET_POP3_STATE_AUTHORISATION) {
+ return $this->_sendCmd('USER ' . $user);
+ }
+ return $this->_raiseError('Not In NET_POP3_STATE_AUTHORISATION State');
+ }
+
+
+ /*
+ * Sends the PASS command
+ *
+ * @param string $pass Password to send
+ * @return bool Success/Failure
+ */
+ function _cmdPass($pass)
+ {
+ if ($this->_state == NET_POP3_STATE_AUTHORISATION) {
+ return $this->_sendCmd('PASS ' . $pass);
+ }
+ return $this->_raiseError('Not In NET_POP3_STATE_AUTHORISATION State');
+ }
+
+
+ /*
+ * Sends the STAT command
+ *
+ * @return mixed Indexed array of number of messages and
+ * maildrop size, or false on error.
+ */
+ function _cmdStat()
+ {
+ if ($this->_state == NET_POP3_STATE_TRANSACTION) {
+ if(!PEAR::isError($data = $this->_sendCmd('STAT'))){
+ sscanf($data, '+OK %d %d', $msg_num, $size);
+ $this->_maildrop['num_msg'] = $msg_num;
+ $this->_maildrop['size'] = $size;
+
+ return array($msg_num, $size);
+ }
+ }
+ return false;
+ }
+
+
+ /*
+ * Sends the LIST command
+ *
+ * @param integer $msg_id Optional message number
+ * @return mixed Indexed array of msg_id/msg size or
+ * false on error
+ */
+ function _cmdList($msg_id = null)
+ {
+ $return=array();
+ if ($this->_state == NET_POP3_STATE_TRANSACTION) {
+ if (!isset($msg_id)) {
+ if(!PEAR::isError($data = $this->_sendCmd('LIST') )){
+ $data = $this->_getMultiline();
+ $data = explode("\r\n", $data);
+ foreach ($data as $line) {
+ if($line !=''){
+ sscanf($line, '%s %s', $msg_id, $size);
+ $return[] = array('msg_id' => $msg_id, 'size' => $size);
+ }
+ }
+ return $return;
+ }
+ } else {
+ if(!PEAR::isError($data = $this->_sendCmd('LIST ' . $msg_id))){
+ if($data!=''){
+ sscanf($data, '+OK %d %d', $msg_id, $size);
+ return array('msg_id' => $msg_id, 'size' => $size);
+ }
+ return array();
+ }
+ }
+ }
+
+
+ return false;
+ }
+
+
+ /*
+ * Sends the RETR command
+ *
+ * @param integer $msg_id The message number to retrieve
+ * @return mixed The message or false on error
+ */
+ function _cmdRetr($msg_id)
+ {
+ if ($this->_state == NET_POP3_STATE_TRANSACTION) {
+ if(!PEAR::isError($data = $this->_sendCmd('RETR ' . $msg_id) )){
+ $data = $this->_getMultiline();
+ return $data;
+ }
+ }
+
+ return false;
+ }
+
+
+ /*
+ * Sends the DELE command
+ *
+ * @param integer $msg_id Message number to mark as deleted
+ * @return bool Success/Failure
+ */
+ function _cmdDele($msg_id)
+ {
+ if ($this->_state == NET_POP3_STATE_TRANSACTION) {
+ return $this->_sendCmd('DELE ' . $msg_id);
+ }
+
+ return false;
+ }
+
+
+ /*
+ * Sends the NOOP command
+ *
+ * @return bool Success/Failure
+ */
+ function _cmdNoop()
+ {
+ if ($this->_state == NET_POP3_STATE_TRANSACTION) {
+ if(!PEAR::isError($data = $this->_sendCmd('NOOP'))){
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /*
+ * Sends the RSET command
+ *
+ * @return bool Success/Failure
+ */
+ function _cmdRset()
+ {
+ if ($this->_state == NET_POP3_STATE_TRANSACTION) {
+ if(!PEAR::isError($data = $this->_sendCmd('RSET'))){
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /*
+ * Sends the QUIT command
+ *
+ * @return bool Success/Failure
+ */
+ function _cmdQuit()
+ {
+ $data = $this->_sendCmd('QUIT');
+ $this->_state = NET_POP3_STATE_DISCONNECTED;
+ $this->_socket->disconnect();
+
+ return (bool)$data;
+ }
+
+
+ /*
+ * Sends the TOP command
+ *
+ * @param integer $msg_id Message number
+ * @param integer $num_lines Number of lines to retrieve
+ * @return mixed Message data or false on error
+ */
+ function _cmdTop($msg_id, $num_lines)
+ {
+ if ($this->_state == NET_POP3_STATE_TRANSACTION) {
+
+ if(!PEAR::isError($data = $this->_sendCmd('TOP ' . $msg_id . ' ' . $num_lines))){
+ return $this->_getMultiline();
+ }
+ }
+
+ return false;
+ }
+
+ /*
+ * Sends the UIDL command
+ *
+ * @param integer $msg_id Message number
+ * @return mixed indexed array of msg_id/uidl or false on error
+ */
+ function _cmdUidl($msg_id = null)
+ {
+ if ($this->_state == NET_POP3_STATE_TRANSACTION) {
+
+ if (!isset($msg_id)) {
+ if(!PEAR::isError($data = $this->_sendCmd('UIDL') )){
+ $data = $this->_getMultiline();
+ $data = explode("\r\n", $data);
+ foreach ($data as $line) {
+ sscanf($line, '%d %s', $msg_id, $uidl);
+ $return[] = array('msg_id' => $msg_id, 'uidl' => $uidl);
+ }
+
+ return $return;
+ }
+ } else {
+
+ $data = $this->_sendCmd('UIDL ' . $msg_id);
+ sscanf($data, '+OK %d %s', $msg_id, $uidl);
+ return array('msg_id' => $msg_id, 'uidl' => $uidl);
+ }
+ }
+
+ return false;
+ }
+
+
+
+
+
+
+
+
+
+ /*
+ * Sends a command, checks the reponse, and
+ * if good returns the reponse, other wise
+ * returns false.
+ *
+ * @param string $cmd Command to send (\r\n will be appended)
+ * @return mixed First line of response if successful, otherwise false
+ */
+ function _sendCmd($cmd)
+ {
+ if (PEAR::isError($result = $this->_send($cmd) )){
+ return $result ;
+ }
+
+ if (PEAR::isError($data = $this->_recvLn() )){
+ return $data;
+ }
+
+ if ( strtoupper(substr($data, 0, 3)) == '+OK') {
+ return $data;
+ }
+
+
+ return $this->_raiseError($data);
+ }
+
+ /*
+ * Reads a multiline reponse and returns the data
+ *
+ * @return string The reponse.
+ */
+ function _getMultiline()
+ {
+ $data = '';
+ while(!PEAR::isError($tmp = $this->_recvLn() ) ) {
+ if($tmp == '.'){
+ return substr($data, 0, -2);
+ }
+ if (substr($tmp, 0, 2) == '..') {
+ $tmp = substr($tmp, 1);
+ }
+ $data .= $tmp . "\r\n";
+ }
+ return substr($data, 0, -2);
+ }
+
+
+ /**
+ * Sets the bebug state
+ *
+ * @param bool $debug
+ * @access public
+ * @return void
+ */
+ function setDebug($debug=true)
+ {
+ $this->_debug=$debug;
+ }
+
+
+
+
+
+ /**
+ * Send the given string of data to the server.
+ *
+ * @param string $data The string of data to send.
+ *
+ * @return mixed True on success or a PEAR_Error object on failure.
+ *
+ * @access private
+ * @since 1.0
+ */
+ function _send($data)
+ {
+ if ($this->_debug) {
+ echo "C: $data\n";
+ }
+
+ if (PEAR::isError($error = $this->_socket->writeLine($data))) {
+ return $this->_raiseError('Failed to write to socket: ' . $error->getMessage());
+ }
+ return true;
+ }
+
+
+
+ /**
+ * Receive the given string of data from the server.
+ *
+ * @return mixed a line of response on success or a PEAR_Error object on failure.
+ *
+ * @access private
+ * @since 1.0
+ */
+ function _recvLn()
+ {
+ if (PEAR::isError( $lastline = $this->_socket->readLine( 8192 ) ) ) {
+ return $this->_raiseError('Failed to write to socket: ' . $this->lastline->getMessage() );
+ }
+ if($this->_debug){
+ // S: means this data was sent by the POP3 Server
+ echo "S:$lastline\n" ;
+ }
+ return $lastline;
+ }
+
+ /**
+ * Checks de server Response
+ *
+ * @param string $response the response
+ * @return mixed true on success or a PEAR_Error object on failure.
+ *
+ * @access private
+ * @since 1.3.3
+ */
+
+ function _checkResponse($response)
+ {
+ if (@substr(strtoupper($response), 0, 3) == '+OK') {
+ return true;
+ }else{
+ if (@substr(strtoupper($response), 0, 4) == '-ERR') {
+ return $this->_raiseError($response);
+ }else{
+ if (@substr(strtoupper($response), 0, 2) == '+ ') {
+ return true;
+ }
+ }
+
+ }
+ return $this->_raiseError("Unknown Response ($response)");
+ }
+
+
+
+}
+
+?>
Added: plugins/trunk/moblog/class/PEAR/Net/Socket.php
===================================================================
--- plugins/trunk/moblog/class/PEAR/Net/Socket.php 2005-06-10 09:00:01 UTC (rev 2187)
+++ plugins/trunk/moblog/class/PEAR/Net/Socket.php 2005-06-10 09:43:48 UTC (rev 2188)
@@ -0,0 +1,528 @@
+<?php
+//
+// +----------------------------------------------------------------------+
+// | PHP Version 4 |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 1997-2003 The PHP Group |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 2.0 of the PHP license, |
+// | that is bundled with this package in the file LICENSE, and is |
+// | available at through the world-wide-web at |
+// | http://www.php.net/license/2_02.txt. |
+// | If you did not receive a copy of the PHP license and are unable to |
+// | obtain it through the world-wide-web, please send a note to |
+// | license at php.net so we can mail you a copy immediately. |
+// +----------------------------------------------------------------------+
+// | Authors: Stig Bakken <ssb at php.net> |
+// | Chuck Hagenbuch <chuck at horde.org> |
+// +----------------------------------------------------------------------+
+//
+// $Id: Socket.php,v 1.24 2005/02/03 20:40:16 chagenbu Exp $
+
+require_once (dirname(__FILE__).'/../PEAR.php');
+
+define('NET_SOCKET_READ', 1);
+define('NET_SOCKET_WRITE', 2);
+define('NET_SOCKET_ERROR', 3);
+
+/**
+ * Generalized Socket class.
+ *
+ * @version 1.1
+ * @author Stig Bakken <ssb at php.net>
+ * @author Chuck Hagenbuch <chuck at horde.org>
+ */
+class Net_Socket extends PEAR {
+
+ /**
+ * Socket file pointer.
+ * @var resource $fp
+ */
+ var $fp = null;
+
+ /**
+ * Whether the socket is blocking. Defaults to true.
+ * @var boolean $blocking
+ */
+ var $blocking = true;
+
+ /**
+ * Whether the socket is persistent. Defaults to false.
+ * @var boolean $persistent
+ */
+ var $persistent = false;
+
+ /**
+ * The IP address to connect to.
+ * @var string $addr
+ */
+ var $addr = '';
+
+ /**
+ * The port number to connect to.
+ * @var integer $port
+ */
+ var $port = 0;
+
+ /**
+ * Number of seconds to wait on socket connections before assuming
+ * there's no more data. Defaults to no timeout.
+ * @var integer $timeout
+ */
+ var $timeout = false;
+
+ /**
+ * Number of bytes to read at a time in readLine() and
+ * readAll(). Defaults to 2048.
+ * @var integer $lineLength
+ */
+ var $lineLength = 2048;
+
+ /**
+ * Connect to the specified port. If called when the socket is
+ * already connected, it disconnects and connects again.
+ *
+ * @param string $addr IP address or host name.
+ * @param integer $port TCP port number.
+ * @param boolean $persistent (optional) Whether the connection is
+ * persistent (kept open between requests
+ * by the web server).
+ * @param integer $timeout (optional) How long to wait for data.
+ * @param array $options See options for stream_context_create.
+ *
+ * @access public
+ *
+ * @return boolean | PEAR_Error True on success or a PEAR_Error on failure.
+ */
+ function connect($addr, $port = 0, $persistent = null, $timeout = null, $options = null)
+ {
+ if (is_resource($this->fp)) {
+ @fclose($this->fp);
+ $this->fp = null;
+ }
+
+ if (!$addr) {
+ return $this->raiseError('$addr cannot be empty');
+ } elseif (strspn($addr, '.0123456789') == strlen($addr) ||
+ strstr($addr, '/') !== false) {
+ $this->addr = $addr;
+ } else {
+ $this->addr = @gethostbyname($addr);
+ }
+
+ $this->port = $port % 65536;
+
+ if ($persistent !== null) {
+ $this->persistent = $persistent;
+ }
+
+ if ($timeout !== null) {
+ $this->timeout = $timeout;
+ }
+
+ $openfunc = $this->persistent ? 'pfsockopen' : 'fsockopen';
+ $errno = 0;
+ $errstr = '';
+ if ($options && function_exists('stream_context_create')) {
+ if ($this->timeout) {
+ $timeout = $this->timeout;
+ } else {
+ $timeout = 0;
+ }
+ $context = stream_context_create($options);
+ $fp = @$openfunc($this->addr, $this->port, $errno, $errstr, $timeout, $context);
+ } else {
+ if ($this->timeout) {
+ $fp = @$openfunc($this->addr, $this->port, $errno, $errstr, $this->timeout);
+ } else {
+ $fp = @$openfunc($this->addr, $this->port, $errno, $errstr);
+ }
+ }
+
+ if (!$fp) {
+ return $this->raiseError($errstr, $errno);
+ }
+
+ $this->fp = $fp;
+
+ return $this->setBlocking($this->blocking);
+ }
+
+ /**
+ * Disconnects from the peer, closes the socket.
+ *
+ * @access public
+ * @return mixed true on success or an error object otherwise
+ */
+ function disconnect()
+ {
+ if (!is_resource($this->fp)) {
+ return $this->raiseError('not connected');
+ }
+
+ @fclose($this->fp);
+ $this->fp = null;
+ return true;
+ }
+
+ /**
+ * Find out if the socket is in blocking mode.
+ *
+ * @access public
+ * @return boolean The current blocking mode.
+ */
+ function isBlocking()
+ {
+ return $this->blocking;
+ }
+
+ /**
+ * Sets whether the socket connection should be blocking or
+ * not. A read call to a non-blocking socket will return immediately
+ * if there is no data available, whereas it will block until there
+ * is data for blocking sockets.
+ *
+ * @param boolean $mode True for blocking sockets, false for nonblocking.
+ * @access public
+ * @return mixed true on success or an error object otherwise
+ */
+ function setBlocking($mode)
+ {
+ if (!is_resource($this->fp)) {
+ return $this->raiseError('not connected');
+ }
+
+ $this->blocking = $mode;
+ socket_set_blocking($this->fp, $this->blocking);
+ return true;
+ }
+
+ /**
+ * Sets the timeout value on socket descriptor,
+ * expressed in the sum of seconds and microseconds
+ *
+ * @param integer $seconds Seconds.
+ * @param integer $microseconds Microseconds.
+ * @access public
+ * @return mixed true on success or an error object otherwise
+ */
+ function setTimeout($seconds, $microseconds)
+ {
+ if (!is_resource($this->fp)) {
+ return $this->raiseError('not connected');
+ }
+
+ return socket_set_timeout($this->fp, $seconds, $microseconds);
+ }
+
+ /**
+ * Returns information about an existing socket resource.
+ * Currently returns four entries in the result array:
+ *
+ * <p>
+ * timed_out (bool) - The socket timed out waiting for data<br>
+ * blocked (bool) - The socket was blocked<br>
+ * eof (bool) - Indicates EOF event<br>
+ * unread_bytes (int) - Number of bytes left in the socket buffer<br>
+ * </p>
+ *
+ * @access public
+ * @return mixed Array containing information about existing socket resource or an error object otherwise
+ */
+ function getStatus()
+ {
+ if (!is_resource($this->fp)) {
+ return $this->raiseError('not connected');
+ }
+
+ return socket_get_status($this->fp);
+ }
+
+ /**
+ * Get a specified line of data
+ *
+ * @access public
+ * @return $size bytes of data from the socket, or a PEAR_Error if
+ * not connected.
+ */
+ function gets($size)
+ {
+ if (!is_resource($this->fp)) {
+ return $this->raiseError('not connected');
+ }
+
+ return @fgets($this->fp, $size);
+ }
+
+ /**
+ * Read a specified amount of data. This is guaranteed to return,
+ * and has the added benefit of getting everything in one fread()
+ * chunk; if you know the size of the data you're getting
+ * beforehand, this is definitely the way to go.
+ *
+ * @param integer $size The number of bytes to read from the socket.
+ * @access public
+ * @return $size bytes of data from the socket, or a PEAR_Error if
+ * not connected.
+ */
+ function read($size)
+ {
+ if (!is_resource($this->fp)) {
+ return $this->raiseError('not connected');
+ }
+
+ return @fread($this->fp, $size);
+ }
+
+ /**
+ * Write a specified amount of data.
+ *
+ * @param string $data Data to write.
+ * @param integer $blocksize Amount of data to write at once.
+ * NULL means all at once.
+ *
+ * @access public
+ * @return mixed true on success or an error object otherwise
+ */
+ function write($data, $blocksize = null)
+ {
+ if (!is_resource($this->fp)) {
+ return $this->raiseError('not connected');
+ }
+
+ if (is_null($blocksize) && !OS_WINDOWS) {
+ return fwrite($this->fp, $data);
+ } else {
+ if (is_null($blocksize)) {
+ $blocksize = 1024;
+ }
+
+ $pos = 0;
+ $size = strlen($data);
+ while ($pos < $size) {
+ $written = @fwrite($this->fp, substr($data, $pos, $blocksize));
+ if ($written === false) {
+ return false;
+ }
+ $pos += $written;
+ }
+
+ return $pos;
+ }
+ }
+
+ /**
+ * Write a line of data to the socket, followed by a trailing "\r\n".
+ *
+ * @access public
+ * @return mixed fputs result, or an error
+ */
+ function writeLine($data)
+ {
+ if (!is_resource($this->fp)) {
+ return $this->raiseError('not connected');
+ }
+
+ return fwrite($this->fp, $data . "\r\n");
+ }
+
+ /**
+ * Tests for end-of-file on a socket descriptor.
+ *
+ * @access public
+ * @return bool
+ */
+ function eof()
+ {
+ return (is_resource($this->fp) && feof($this->fp));
+ }
+
+ /**
+ * Reads a byte of data
+ *
+ * @access public
+ * @return 1 byte of data from the socket, or a PEAR_Error if
+ * not connected.
+ */
+ function readByte()
+ {
+ if (!is_resource($this->fp)) {
+ return $this->raiseError('not connected');
+ }
+
+ return ord(@fread($this->fp, 1));
+ }
+
+ /**
+ * Reads a word of data
+ *
+ * @access public
+ * @return 1 word of data from the socket, or a PEAR_Error if
+ * not connected.
+ */
+ function readWord()
+ {
+ if (!is_resource($this->fp)) {
+ return $this->raiseError('not connected');
+ }
+
+ $buf = @fread($this->fp, 2);
+ return (ord($buf[0]) + (ord($buf[1]) << 8));
+ }
+
+ /**
+ * Reads an int of data
+ *
+ * @access public
+ * @return integer 1 int of data from the socket, or a PEAR_Error if
+ * not connected.
+ */
+ function readInt()
+ {
+ if (!is_resource($this->fp)) {
+ return $this->raiseError('not connected');
+ }
+
+ $buf = @fread($this->fp, 4);
+ return (ord($buf[0]) + (ord($buf[1]) << 8) +
+ (ord($buf[2]) << 16) + (ord($buf[3]) << 24));
+ }
+
+ /**
+ * Reads a zero-terminated string of data
+ *
+ * @access public
+ * @return string, or a PEAR_Error if
+ * not connected.
+ */
+ function readString()
+ {
+ if (!is_resource($this->fp)) {
+ return $this->raiseError('not connected');
+ }
+
+ $string = '';
+ while (($char = @fread($this->fp, 1)) != "\x00") {
+ $string .= $char;
+ }
+ return $string;
+ }
+
+ /**
+ * Reads an IP Address and returns it in a dot formated string
+ *
+ * @access public
+ * @return Dot formated string, or a PEAR_Error if
+ * not connected.
+ */
+ function readIPAddress()
+ {
+ if (!is_resource($this->fp)) {
+ return $this->raiseError('not connected');
+ }
+
+ $buf = @fread($this->fp, 4);
+ return sprintf("%s.%s.%s.%s", ord($buf[0]), ord($buf[1]),
+ ord($buf[2]), ord($buf[3]));
+ }
+
+ /**
+ * Read until either the end of the socket or a newline, whichever
+ * comes first. Strips the trailing newline from the returned data.
+ *
+ * @access public
+ * @return All available data up to a newline, without that
+ * newline, or until the end of the socket, or a PEAR_Error if
+ * not connected.
+ */
+ function readLine()
+ {
+ if (!is_resource($this->fp)) {
+ return $this->raiseError('not connected');
+ }
+
+ $line = '';
+ $timeout = time() + $this->timeout;
+ while (!feof($this->fp) && (!$this->timeout || time() < $timeout)) {
+ $line .= @fgets($this->fp, $this->lineLength);
+ if (substr($line, -1) == "\n") {
+ return rtrim($line, "\r\n");
+ }
+ }
+ return $line;
+ }
+
+ /**
+ * Read until the socket closes, or until there is no more data in
+ * the inner PHP buffer. If the inner buffer is empty, in blocking
+ * mode we wait for at least 1 byte of data. Therefore, in
+ * blocking mode, if there is no data at all to be read, this
+ * function will never exit (unless the socket is closed on the
+ * remote end).
+ *
+ * @access public
+ *
+ * @return string All data until the socket closes, or a PEAR_Error if
+ * not connected.
+ */
+ function readAll()
+ {
+ if (!is_resource($this->fp)) {
+ return $this->raiseError('not connected');
+ }
+
+ $data = '';
+ while (!feof($this->fp)) {
+ $data .= @fread($this->fp, $this->lineLength);
+ }
+ return $data;
+ }
+
+ /**
+ * Runs the equivalent of the select() system call on the socket
+ * with a timeout specified by tv_sec and tv_usec.
+ *
+ * @param integer $state Which of read/write/error to check for.
+ * @param integer $tv_sec Number of seconds for timeout.
+ * @param integer $tv_usec Number of microseconds for timeout.
+ *
+ * @access public
+ * @return False if select fails, integer describing which of read/write/error
+ * are ready, or PEAR_Error if not connected.
+ */
+ function select($state, $tv_sec, $tv_usec = 0)
+ {
+ if (!is_resource($this->fp)) {
+ return $this->raiseError('not connected');
+ }
+
+ $read = null;
+ $write = null;
+ $except = null;
+ if ($state & NET_SOCKET_READ) {
+ $read[] = $this->fp;
+ }
+ if ($state & NET_SOCKET_WRITE) {
+ $write[] = $this->fp;
+ }
+ if ($state & NET_SOCKET_ERROR) {
+ $except[] = $this->fp;
+ }
+ if (false === ($sr = stream_select($read, $write, $except, $tv_sec, $tv_usec))) {
+ return false;
+ }
+
+ $result = 0;
+ if (count($read)) {
+ $result |= NET_SOCKET_READ;
+ }
+ if (count($write)) {
+ $result |= NET_SOCKET_WRITE;
+ }
+ if (count($except)) {
+ $result |= NET_SOCKET_ERROR;
+ }
+ return $result;
+ }
+
+}
Added: plugins/trunk/moblog/class/PEAR/Net/URL.php
===================================================================
--- plugins/trunk/moblog/class/PEAR/Net/URL.php 2005-06-10 09:00:01 UTC (rev 2187)
+++ plugins/trunk/moblog/class/PEAR/Net/URL.php 2005-06-10 09:43:48 UTC (rev 2188)
@@ -0,0 +1,410 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Copyright (c) 2002-2004, Richard Heyes |
+// | All rights reserved. |
+// | |
+// | Redistribution and use in source and binary forms, with or without |
+// | modification, are permitted provided that the following conditions |
+// | are met: |
+// | |
+// | o Redistributions of source code must retain the above copyright |
+// | notice, this list of conditions and the following disclaimer. |
+// | o Redistributions in binary form must reproduce the above copyright |
+// | notice, this list of conditions and the following disclaimer in the |
+// | documentation and/or other materials provided with the distribution.|
+// | o The names of the authors may not be used to endorse or promote |
+// | products derived from this software without specific prior written |
+// | permission. |
+// | |
+// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+// | |
+// +-----------------------------------------------------------------------+
+// | Author: Richard Heyes <richard at php net> |
+// +-----------------------------------------------------------------------+
+//
+// $Id: URL.php,v 1.36 2004/06/19 18:58:50 richard Exp $
+//
+// Net_URL Class
+
+class Net_URL
+{
+ /**
+ * Full url
+ * @var string
+ */
+ var $url;
+
+ /**
+ * Protocol
+ * @var string
+ */
+ var $protocol;
+
+ /**
+ * Username
+ * @var string
+ */
+ var $username;
+
+ /**
+ * Password
+ * @var string
+ */
+ var $password;
+
+ /**
+ * Host
+ * @var string
+ */
+ var $host;
+
+ /**
+ * Port
+ * @var integer
+ */
+ var $port;
+
+ /**
+ * Path
+ * @var string
+ */
+ var $path;
+
+ /**
+ * Query string
+ * @var array
+ */
+ var $querystring;
+
+ /**
+ * Anchor
+ * @var string
+ */
+ var $anchor;
+
+ /**
+ * Whether to use []
+ * @var bool
+ */
+ var $useBrackets;
+
+ /**
+ * PHP4 Constructor
+ *
+ * @see __construct()
+ */
+ function Net_URL($url = null, $useBrackets = true)
+ {
+ $this->__construct($url, $useBrackets);
+ }
+
+ /**
+ * PHP5 Constructor
+ *
+ * Parses the given url and stores the various parts
+ * Defaults are used in certain cases
+ *
+ * @param string $url Optional URL
+ * @param bool $useBrackets Whether to use square brackets when
+ * multiple querystrings with the same name
+ * exist
+ */
+ function __construct($url = null, $useBrackets = true)
+ {
+ $HTTP_SERVER_VARS = !empty($_SERVER) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS'];
+
+ $this->useBrackets = $useBrackets;
+ $this->url = $url;
+ $this->user = '';
+ $this->pass = '';
+ $this->host = '';
+ $this->port = 80;
+ $this->path = '';
+ $this->querystring = array();
+ $this->anchor = '';
+
+ // Only use defaults if not an absolute URL given
+ if (!preg_match('/^[a-z0-9]+:\/\//i', $url)) {
+
+ $this->protocol = (@$HTTP_SERVER_VARS['HTTPS'] == 'on' ? 'https' : 'http');
+
+ /**
+ * Figure out host/port
+ */
+ if (!empty($HTTP_SERVER_VARS['HTTP_HOST']) AND preg_match('/^(.*)(:([0-9]+))?$/U', $HTTP_SERVER_VARS['HTTP_HOST'], $matches)) {
+ $host = $matches[1];
+ if (!empty($matches[3])) {
+ $port = $matches[3];
+ } else {
+ $port = $this->getStandardPort($this->protocol);
+ }
+ }
+
+ $this->user = '';
+ $this->pass = '';
+ $this->host = !empty($host) ? $host : (isset($HTTP_SERVER_VARS['SERVER_NAME']) ? $HTTP_SERVER_VARS['SERVER_NAME'] : 'localhost');
+ $this->port = !empty($port) ? $port : (isset($HTTP_SERVER_VARS['SERVER_PORT']) ? $HTTP_SERVER_VARS['SERVER_PORT'] : $this->getStandardPort($this->protocol));
+ $this->path = !empty($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : '/';
+ $this->querystring = isset($HTTP_SERVER_VARS['QUERY_STRING']) ? $this->_parseRawQuerystring($HTTP_SERVER_VARS['QUERY_STRING']) : null;
+ $this->anchor = '';
+ }
+
+ // Parse the url and store the various parts
+ if (!empty($url)) {
+ $urlinfo = parse_url($url);
+
+ // Default querystring
+ $this->querystring = array();
+
+ foreach ($urlinfo as $key => $value) {
+ switch ($key) {
+ case 'scheme':
+ $this->protocol = $value;
+ $this->port = $this->getStandardPort($value);
+ break;
+
+ case 'user':
+ case 'pass':
+ case 'host':
+ case 'port':
+ $this->$key = $value;
+ break;
+
+ case 'path':
+ if ($value{0} == '/') {
+ $this->path = $value;
+ } else {
+ $path = dirname($this->path) == DIRECTORY_SEPARATOR ? '' : dirname($this->path);
+ $this->path = sprintf('%s/%s', $path, $value);
+ }
+ break;
+
+ case 'query':
+ $this->querystring = $this->_parseRawQueryString($value);
+ break;
+
+ case 'fragment':
+ $this->anchor = $value;
+ break;
+ }
+ }
+ }
+ }
+
+ /**
+ * Returns full url
+ *
+ * @return string Full url
+ * @access public
+ */
+ function getURL()
+ {
+ $querystring = $this->getQueryString();
+
+ $this->url = $this->protocol . '://'
+ . $this->user . (!empty($this->pass) ? ':' : '')
+ . $this->pass . (!empty($this->user) ? '@' : '')
+ . $this->host . ($this->port == $this->getStandardPort($this->protocol) ? '' : ':' . $this->port)
+ . $this->path
+ . (!empty($querystring) ? '?' . $querystring : '')
+ . (!empty($this->anchor) ? '#' . $this->anchor : '');
+
+ return $this->url;
+ }
+
+ /**
+ * Adds a querystring item
+ *
+ * @param string $name Name of item
+ * @param string $value Value of item
+ * @param bool $preencoded Whether value is urlencoded or not, default = not
+ * @access public
+ */
+ function addQueryString($name, $value, $preencoded = false)
+ {
+ if ($preencoded) {
+ $this->querystring[$name] = $value;
+ } else {
+ $this->querystring[$name] = is_array($value) ? array_map('rawurlencode', $value): rawurlencode($value);
+ }
+ }
+
+ /**
+ * Removes a querystring item
+ *
+ * @param string $name Name of item
+ * @access public
+ */
+ function removeQueryString($name)
+ {
+ if (isset($this->querystring[$name])) {
+ unset($this->querystring[$name]);
+ }
+ }
+
+ /**
+ * Sets the querystring to literally what you supply
+ *
+ * @param string $querystring The querystring data. Should be of the format foo=bar&x=y etc
+ * @access public
+ */
+ function addRawQueryString($querystring)
+ {
+ $this->querystring = $this->_parseRawQueryString($querystring);
+ }
+
+ /**
+ * Returns flat querystring
+ *
+ * @return string Querystring
+ * @access public
+ */
+ function getQueryString()
+ {
+ if (!empty($this->querystring)) {
+ foreach ($this->querystring as $name => $value) {
+ if (is_array($value)) {
+ foreach ($value as $k => $v) {
+ $querystring[] = $this->useBrackets ? sprintf('%s[%s]=%s', $name, $k, $v) : ($name . '=' . $v);
+ }
+ } elseif (!is_null($value)) {
+ $querystring[] = $name . '=' . $value;
+ } else {
+ $querystring[] = $name;
+ }
+ }
+ $querystring = implode(ini_get('arg_separator.output'), $querystring);
+ } else {
+ $querystring = '';
+ }
+
+ return $querystring;
+ }
+
+ /**
+ * Parses raw querystring and returns an array of it
+ *
+ * @param string $querystring The querystring to parse
+ * @return array An array of the querystring data
+ * @access private
+ */
+ function _parseRawQuerystring($querystring)
+ {
+ $parts = preg_split('/[' . preg_quote(ini_get('arg_separator.input'), '/') . ']/', $querystring, -1, PREG_SPLIT_NO_EMPTY);
+ $return = array();
+
+ foreach ($parts as $part) {
+ if (strpos($part, '=') !== false) {
+ $value = substr($part, strpos($part, '=') + 1);
+ $key = substr($part, 0, strpos($part, '='));
+ } else {
+ $value = null;
+ $key = $part;
+ }
+ if (substr($key, -2) == '[]') {
+ $key = substr($key, 0, -2);
+ if (@!is_array($return[$key])) {
+ $return[$key] = array();
+ $return[$key][] = $value;
+ } else {
+ $return[$key][] = $value;
+ }
+ } elseif (!$this->useBrackets AND !empty($return[$key])) {
+ $return[$key] = (array)$return[$key];
+ $return[$key][] = $value;
+ } else {
+ $return[$key] = $value;
+ }
+ }
+
+ return $return;
+ }
+
+ /**
+ * Resolves //, ../ and ./ from a path and returns
+ * the result. Eg:
+ *
+ * /foo/bar/../boo.php => /foo/boo.php
+ * /foo/bar/../../boo.php => /boo.php
+ * /foo/bar/.././/boo.php => /foo/boo.php
+ *
+ * This method can also be called statically.
+ *
+ * @param string $url URL path to resolve
+ * @return string The result
+ */
+ function resolvePath($path)
+ {
+ $path = explode('/', str_replace('//', '/', $path));
+
+ for ($i=0; $i<count($path); $i++) {
+ if ($path[$i] == '.') {
+ unset($path[$i]);
+ $path = array_values($path);
+ $i--;
+
+ } elseif ($path[$i] == '..' AND ($i > 1 OR ($i == 1 AND $path[0] != '') ) ) {
+ unset($path[$i]);
+ unset($path[$i-1]);
+ $path = array_values($path);
+ $i -= 2;
+
+ } elseif ($path[$i] == '..' AND $i == 1 AND $path[0] == '') {
+ unset($path[$i]);
+ $path = array_values($path);
+ $i--;
+
+ } else {
+ continue;
+ }
+ }
+
+ return implode('/', $path);
+ }
+
+ /**
+ * Returns the standard port number for a protocol
+ *
+ * @param string $scheme The protocol to lookup
+ * @return integer Port number or NULL if no scheme matches
+ *
+ * @author Philippe Jausions <Philippe.Jausions at 11abacus.com>
+ */
+ function getStandardPort($scheme)
+ {
+ switch (strtolower($scheme)) {
+ case 'http': return 80;
+ case 'https': return 443;
+ case 'ftp': return 21;
+ case 'imap': return 143;
+ case 'imaps': return 993;
+ case 'pop3': return 110;
+ case 'pop3s': return 995;
+ default: return null;
+ }
+ }
+
+ /**
+ * Forces the URL to a particular protocol
+ *
+ * @param string $protocol Protocol to force the URL to
+ * @param integer $port Optional port (standard port is used by default)
+ */
+ function setProtocol($protocol, $port = null)
+ {
+ $this->protocol = $protocol;
+ $this->port = is_null($port) ? $this->getStandardPort() : $port;
+ }
+
+}
+?>
Added: plugins/trunk/moblog/class/PEAR/PEAR.php
===================================================================
--- plugins/trunk/moblog/class/PEAR/PEAR.php 2005-06-10 09:00:01 UTC (rev 2187)
+++ plugins/trunk/moblog/class/PEAR/PEAR.php 2005-06-10 09:43:48 UTC (rev 2188)
@@ -0,0 +1,1055 @@
+<?php
+//
+// +--------------------------------------------------------------------+
+// | PEAR, the PHP Extension and Application Repository |
+// +--------------------------------------------------------------------+
+// | Copyright (c) 1997-2004 The PHP Group |
+// +--------------------------------------------------------------------+
+// | This source file is subject to version 3.0 of the PHP license, |
+// | that is bundled with this package in the file LICENSE, and is |
+// | available through the world-wide-web at the following url: |
+// | 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 world-wide-web, please send a note to |
+// | license at php.net so we can mail you a copy immediately. |
+// +--------------------------------------------------------------------+
+// | Authors: Sterling Hughes <sterling at php.net> |
+// | Stig Bakken <ssb at php.net> |
+// | Tomas V.V.Cox <cox at idecnet.com> |
+// +--------------------------------------------------------------------+
+//
+// $Id: PEAR.php,v 1.82.2.6 2005/01/01 05:24:51 cellog Exp $
+//
+
+define('PEAR_ERROR_RETURN', 1);
+define('PEAR_ERROR_PRINT', 2);
+define('PEAR_ERROR_TRIGGER', 4);
+define('PEAR_ERROR_DIE', 8);
+define('PEAR_ERROR_CALLBACK', 16);
+/**
+ * WARNING: obsolete
+ * @deprecated
+ */
+define('PEAR_ERROR_EXCEPTION', 32);
+define('PEAR_ZE2', (function_exists('version_compare') &&
+ version_compare(zend_version(), "2-dev", "ge")));
+
+if (substr(PHP_OS, 0, 3) == 'WIN') {
+ define('OS_WINDOWS', true);
+ define('OS_UNIX', false);
+ define('PEAR_OS', 'Windows');
+} else {
+ define('OS_WINDOWS', false);
+ define('OS_UNIX', true);
+ define('PEAR_OS', 'Unix'); // blatant assumption
+}
+
+// instant backwards compatibility
+if (!defined('PATH_SEPARATOR')) {
+ if (OS_WINDOWS) {
+ define('PATH_SEPARATOR', ';');
+ } else {
+ define('PATH_SEPARATOR', ':');
+ }
+}
+
+$GLOBALS['_PEAR_default_error_mode'] = PEAR_ERROR_RETURN;
+$GLOBALS['_PEAR_default_error_options'] = E_USER_NOTICE;
+$GLOBALS['_PEAR_destructor_object_list'] = array();
+$GLOBALS['_PEAR_shutdown_funcs'] = array();
+$GLOBALS['_PEAR_error_handler_stack'] = array();
+
+ at ini_set('track_errors', true);
+
+/**
+ * Base class for other PEAR classes. Provides rudimentary
+ * emulation of destructors.
+ *
+ * If you want a destructor in your class, inherit PEAR and make a
+ * destructor method called _yourclassname (same name as the
+ * constructor, but with a "_" prefix). Also, in your constructor you
+ * have to call the PEAR constructor: $this->PEAR();.
+ * The destructor method will be called without parameters. Note that
+ * at in some SAPI implementations (such as Apache), any output during
+ * the request shutdown (in which destructors are called) seems to be
+ * discarded. If you need to get any debug information from your
+ * destructor, use error_log(), syslog() or something similar.
+ *
+ * IMPORTANT! To use the emulated destructors you need to create the
+ * objects by reference: $obj =& new PEAR_child;
+ *
+ * @since PHP 4.0.2
+ * @author Stig Bakken <ssb at php.net>
+ * @see http://pear.php.net/manual/
+ */
+class PEAR
+{
+ // {{{ properties
+
+ /**
+ * Whether to enable internal debug messages.
+ *
+ * @var bool
+ * @access private
+ */
+ var $_debug = false;
+
+ /**
+ * Default error mode for this object.
+ *
+ * @var int
+ * @access private
+ */
+ var $_default_error_mode = null;
+
+ /**
+ * Default error options used for this object when error mode
+ * is PEAR_ERROR_TRIGGER.
+ *
+ * @var int
+ * @access private
+ */
+ var $_default_error_options = null;
+
+ /**
+ * Default error handler (callback) for this object, if error mode is
+ * PEAR_ERROR_CALLBACK.
+ *
+ * @var string
+ * @access private
+ */
+ var $_default_error_handler = '';
+
+ /**
+ * Which class to use for error objects.
+ *
+ * @var string
+ * @access private
+ */
+ var $_error_class = 'PEAR_Error';
+
+ /**
+ * An array of expected errors.
+ *
+ * @var array
+ * @access private
+ */
+ var $_expected_errors = array();
+
+ // }}}
+
+ // {{{ constructor
+
+ /**
+ * Constructor. Registers this object in
+ * $_PEAR_destructor_object_list for destructor emulation if a
+ * destructor object exists.
+ *
+ * @param string $error_class (optional) which class to use for
+ * error objects, defaults to PEAR_Error.
+ * @access public
+ * @return void
+ */
+ function PEAR($error_class = null)
+ {
+ $classname = strtolower(get_class($this));
+ if ($this->_debug) {
+ print "PEAR constructor called, class=$classname\n";
+ }
+ if ($error_class !== null) {
+ $this->_error_class = $error_class;
+ }
+ while ($classname && strcasecmp($classname, "pear")) {
+ $destructor = "_$classname";
+ if (method_exists($this, $destructor)) {
+ global $_PEAR_destructor_object_list;
+ $_PEAR_destructor_object_list[] = &$this;
+ if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) {
+ register_shutdown_function("_PEAR_call_destructors");
+ $GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true;
+ }
+ break;
+ } else {
+ $classname = get_parent_class($classname);
+ }
+ }
+ }
+
+ // }}}
+ // {{{ destructor
+
+ /**
+ * Destructor (the emulated type of...). Does nothing right now,
+ * but is included for forward compatibility, so subclass
+ * destructors should always call it.
+ *
+ * See the note in the class desciption about output from
+ * destructors.
+ *
+ * @access public
+ * @return void
+ */
+ function _PEAR() {
+ if ($this->_debug) {
+ printf("PEAR destructor called, class=%s\n", strtolower(get_class($this)));
+ }
+ }
+
+ // }}}
+ // {{{ getStaticProperty()
+
+ /**
+ * If you have a class that's mostly/entirely static, and you need static
+ * properties, you can use this method to simulate them. Eg. in your method(s)
+ * do this: $myVar = &PEAR::getStaticProperty('myclass', 'myVar');
+ * You MUST use a reference, or they will not persist!
+ *
+ * @access public
+ * @param string $class The calling classname, to prevent clashes
+ * @param string $var The variable to retrieve.
+ * @return mixed A reference to the variable. If not set it will be
+ * auto initialised to NULL.
+ */
+ function &getStaticProperty($class, $var)
+ {
+ static $properties;
+ return $properties[$class][$var];
+ }
+
+ // }}}
+ // {{{ registerShutdownFunc()
+
+ /**
+ * Use this function to register a shutdown method for static
+ * classes.
+ *
+ * @access public
+ * @param mixed $func The function name (or array of class/method) to call
+ * @param mixed $args The arguments to pass to the function
+ * @return void
+ */
+ function registerShutdownFunc($func, $args = array())
+ {
+ $GLOBALS['_PEAR_shutdown_funcs'][] = array($func, $args);
+ }
+
+ // }}}
+ // {{{ isError()
+
+ /**
+ * Tell whether a value is a PEAR error.
+ *
+ * @param mixed $data the value to test
+ * @param int $code if $data is an error object, return true
+ * only if $code is a string and
+ * $obj->getMessage() == $code or
+ * $code is an integer and $obj->getCode() == $code
+ * @access public
+ * @return bool true if parameter is an error
+ */
+ function isError($data, $code = null)
+ {
+ if (is_a($data, 'PEAR_Error')) {
+ if (is_null($code)) {
+ return true;
+ } elseif (is_string($code)) {
+ return $data->getMessage() == $code;
+ } else {
+ return $data->getCode() == $code;
+ }
+ }
+ return false;
+ }
+
+ // }}}
+ // {{{ setErrorHandling()
+
+ /**
+ * Sets how errors generated by this object should be handled.
+ * Can be invoked both in objects and statically. If called
+ * statically, setErrorHandling sets the default behaviour for all
+ * PEAR objects. If called in an object, setErrorHandling sets
+ * the default behaviour for that object.
+ *
+ * @param int $mode
+ * One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
+ * PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE,
+ * PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION.
+ *
+ * @param mixed $options
+ * When $mode is PEAR_ERROR_TRIGGER, this is the error level (one
+ * of E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR).
+ *
+ * When $mode is PEAR_ERROR_CALLBACK, this parameter is expected
+ * to be the callback function or method. A callback
+ * function is a string with the name of the function, a
+ * callback method is an array of two elements: the element
+ * at index 0 is the object, and the element at index 1 is
+ * the name of the method to call in the object.
+ *
+ * When $mode is PEAR_ERROR_PRINT or PEAR_ERROR_DIE, this is
+ * a printf format string used when printing the error
+ * message.
+ *
+ * @access public
+ * @return void
+ * @see PEAR_ERROR_RETURN
+ * @see PEAR_ERROR_PRINT
+ * @see PEAR_ERROR_TRIGGER
+ * @see PEAR_ERROR_DIE
+ * @see PEAR_ERROR_CALLBACK
+ * @see PEAR_ERROR_EXCEPTION
+ *
+ * @since PHP 4.0.5
+ */
+
+ function setErrorHandling($mode = null, $options = null)
+ {
+ if (isset($this) && is_a($this, 'PEAR')) {
+ $setmode = &$this->_default_error_mode;
+ $setoptions = &$this->_default_error_options;
+ } else {
+ $setmode = &$GLOBALS['_PEAR_default_error_mode'];
+ $setoptions = &$GLOBALS['_PEAR_default_error_options'];
+ }
+
+ switch ($mode) {
+ case PEAR_ERROR_EXCEPTION:
+ case PEAR_ERROR_RETURN:
+ case PEAR_ERROR_PRINT:
+ case PEAR_ERROR_TRIGGER:
+ case PEAR_ERROR_DIE:
+ case null:
+ $setmode = $mode;
+ $setoptions = $options;
+ break;
+
+ case PEAR_ERROR_CALLBACK:
+ $setmode = $mode;
+ // class/object method callback
+ if (is_callable($options)) {
+ $setoptions = $options;
+ } else {
+ trigger_error("invalid error callback", E_USER_WARNING);
+ }
+ break;
+
+ default:
+ trigger_error("invalid error mode", E_USER_WARNING);
+ break;
+ }
+ }
+
+ // }}}
+ // {{{ expectError()
+
+ /**
+ * This method is used to tell which errors you expect to get.
+ * Expected errors are always returned with error mode
+ * PEAR_ERROR_RETURN. Expected error codes are stored in a stack,
+ * and this method pushes a new element onto it. The list of
+ * expected errors are in effect until they are popped off the
+ * stack with the popExpect() method.
+ *
+ * Note that this method can not be called statically
+ *
+ * @param mixed $code a single error code or an array of error codes to expect
+ *
+ * @return int the new depth of the "expected errors" stack
+ * @access public
+ */
+ function expectError($code = '*')
+ {
+ if (is_array($code)) {
+ array_push($this->_expected_errors, $code);
+ } else {
+ array_push($this->_expected_errors, array($code));
+ }
+ return sizeof($this->_expected_errors);
+ }
+
+ // }}}
+ // {{{ popExpect()
+
+ /**
+ * This method pops one element off the expected error codes
+ * stack.
+ *
+ * @return array the list of error codes that were popped
+ */
+ function popExpect()
+ {
+ return array_pop($this->_expected_errors);
+ }
+
+ // }}}
+ // {{{ _checkDelExpect()
+
+ /**
+ * This method checks unsets an error code if available
+ *
+ * @param mixed error code
+ * @return bool true if the error code was unset, false otherwise
+ * @access private
+ * @since PHP 4.3.0
+ */
+ function _checkDelExpect($error_code)
+ {
+ $deleted = false;
+
+ foreach ($this->_expected_errors AS $key => $error_array) {
+ if (in_array($error_code, $error_array)) {
+ unset($this->_expected_errors[$key][array_search($error_code, $error_array)]);
+ $deleted = true;
+ }
+
+ // clean up empty arrays
+ if (0 == count($this->_expected_errors[$key])) {
+ unset($this->_expected_errors[$key]);
+ }
+ }
+ return $deleted;
+ }
+
+ // }}}
+ // {{{ delExpect()
+
+ /**
+ * This method deletes all occurences of the specified element from
+ * the expected error codes stack.
+ *
+ * @param mixed $error_code error code that should be deleted
+ * @return mixed list of error codes that were deleted or error
+ * @access public
+ * @since PHP 4.3.0
+ */
+ function delExpect($error_code)
+ {
+ $deleted = false;
+
+ if ((is_array($error_code) && (0 != count($error_code)))) {
+ // $error_code is a non-empty array here;
+ // we walk through it trying to unset all
+ // values
+ foreach($error_code as $key => $error) {
+ if ($this->_checkDelExpect($error)) {
+ $deleted = true;
+ } else {
+ $deleted = false;
+ }
+ }
+ return $deleted ? true : PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
+ } elseif (!empty($error_code)) {
+ // $error_code comes alone, trying to unset it
+ if ($this->_checkDelExpect($error_code)) {
+ return true;
+ } else {
+ return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
+ }
+ } else {
+ // $error_code is empty
+ return PEAR::raiseError("The expected error you submitted is empty"); // IMPROVE ME
+ }
+ }
+
+ // }}}
+ // {{{ raiseError()
+
+ /**
+ * This method is a wrapper that returns an instance of the
+ * configured error class with this object's default error
+ * handling applied. If the $mode and $options parameters are not
+ * specified, the object's defaults are used.
+ *
+ * @param mixed $message a text error message or a PEAR error object
+ *
+ * @param int $code a numeric error code (it is up to your class
+ * to define these if you want to use codes)
+ *
+ * @param int $mode One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
+ * PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE,
+ * PEAR_ERROR_CALLBACK, PEAR_ERROR_EXCEPTION.
+ *
+ * @param mixed $options If $mode is PEAR_ERROR_TRIGGER, this parameter
+ * specifies the PHP-internal error level (one of
+ * E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR).
+ * If $mode is PEAR_ERROR_CALLBACK, this
+ * parameter specifies the callback function or
+ * method. In other error modes this parameter
+ * is ignored.
+ *
+ * @param string $userinfo If you need to pass along for example debug
+ * information, this parameter is meant for that.
+ *
+ * @param string $error_class The returned error object will be
+ * instantiated from this class, if specified.
+ *
+ * @param bool $skipmsg If true, raiseError will only pass error codes,
+ * the error message parameter will be dropped.
+ *
+ * @access public
+ * @return object a PEAR error object
+ * @see PEAR::setErrorHandling
+ * @since PHP 4.0.5
+ */
+ function raiseError($message = null,
+ $code = null,
+ $mode = null,
+ $options = null,
+ $userinfo = null,
+ $error_class = null,
+ $skipmsg = false)
+ {
+ // The error is yet a PEAR error object
+ if (is_object($message)) {
+ $code = $message->getCode();
+ $userinfo = $message->getUserInfo();
+ $error_class = $message->getType();
+ $message->error_message_prefix = '';
+ $message = $message->getMessage();
+ }
+
+ if (isset($this) && isset($this->_expected_errors) && sizeof($this->_expected_errors) > 0 && sizeof($exp = end($this->_expected_errors))) {
+ if ($exp[0] == "*" ||
+ (is_int(reset($exp)) && in_array($code, $exp)) ||
+ (is_string(reset($exp)) && in_array($message, $exp))) {
+ $mode = PEAR_ERROR_RETURN;
+ }
+ }
+ // No mode given, try global ones
+ if ($mode === null) {
+ // Class error handler
+ if (isset($this) && isset($this->_default_error_mode)) {
+ $mode = $this->_default_error_mode;
+ $options = $this->_default_error_options;
+ // Global error handler
+ } elseif (isset($GLOBALS['_PEAR_default_error_mode'])) {
+ $mode = $GLOBALS['_PEAR_default_error_mode'];
+ $options = $GLOBALS['_PEAR_default_error_options'];
+ }
+ }
+
+ if ($error_class !== null) {
+ $ec = $error_class;
+ } elseif (isset($this) && isset($this->_error_class)) {
+ $ec = $this->_error_class;
+ } else {
+ $ec = 'PEAR_Error';
+ }
+ if ($skipmsg) {
+ return new $ec($code, $mode, $options, $userinfo);
+ } else {
+ return new $ec($message, $code, $mode, $options, $userinfo);
+ }
+ }
+
+ // }}}
+ // {{{ throwError()
+
+ /**
+ * Simpler form of raiseError with fewer options. In most cases
+ * message, code and userinfo are enough.
+ *
+ * @param string $message
+ *
+ */
+ function throwError($message = null,
+ $code = null,
+ $userinfo = null)
+ {
+ if (isset($this) && is_a($this, 'PEAR')) {
+ return $this->raiseError($message, $code, null, null, $userinfo);
+ } else {
+ return PEAR::raiseError($message, $code, null, null, $userinfo);
+ }
+ }
+
+ // }}}
+ function staticPushErrorHandling($mode, $options = null)
+ {
+ $stack = &$GLOBALS['_PEAR_error_handler_stack'];
+ $def_mode = &$GLOBALS['_PEAR_default_error_mode'];
+ $def_options = &$GLOBALS['_PEAR_default_error_options'];
+ $stack[] = array($def_mode, $def_options);
+ switch ($mode) {
+ case PEAR_ERROR_EXCEPTION:
+ case PEAR_ERROR_RETURN:
+ case PEAR_ERROR_PRINT:
+ case PEAR_ERROR_TRIGGER:
+ case PEAR_ERROR_DIE:
+ case null:
+ $def_mode = $mode;
+ $def_options = $options;
+ break;
+
+ case PEAR_ERROR_CALLBACK:
+ $def_mode = $mode;
+ // class/object method callback
+ if (is_callable($options)) {
+ $def_options = $options;
+ } else {
+ trigger_error("invalid error callback", E_USER_WARNING);
+ }
+ break;
+
+ default:
+ trigger_error("invalid error mode", E_USER_WARNING);
+ break;
+ }
+ $stack[] = array($mode, $options);
+ return true;
+ }
+
+ function staticPopErrorHandling()
+ {
+ $stack = &$GLOBALS['_PEAR_error_handler_stack'];
+ $setmode = &$GLOBALS['_PEAR_default_error_mode'];
+ $setoptions = &$GLOBALS['_PEAR_default_error_options'];
+ array_pop($stack);
+ list($mode, $options) = $stack[sizeof($stack) - 1];
+ array_pop($stack);
+ switch ($mode) {
+ case PEAR_ERROR_EXCEPTION:
+ case PEAR_ERROR_RETURN:
+ case PEAR_ERROR_PRINT:
+ case PEAR_ERROR_TRIGGER:
+ case PEAR_ERROR_DIE:
+ case null:
+ $setmode = $mode;
+ $setoptions = $options;
+ break;
+
+ case PEAR_ERROR_CALLBACK:
+ $setmode = $mode;
+ // class/object method callback
+ if (is_callable($options)) {
+ $setoptions = $options;
+ } else {
+ trigger_error("invalid error callback", E_USER_WARNING);
+ }
+ break;
+
+ default:
+ trigger_error("invalid error mode", E_USER_WARNING);
+ break;
+ }
+ return true;
+ }
+
+ // {{{ pushErrorHandling()
+
+ /**
+ * Push a new error handler on top of the error handler options stack. With this
+ * you can easily override the actual error handler for some code and restore
+ * it later with popErrorHandling.
+ *
+ * @param mixed $mode (same as setErrorHandling)
+ * @param mixed $options (same as setErrorHandling)
+ *
+ * @return bool Always true
+ *
+ * @see PEAR::setErrorHandling
+ */
+ function pushErrorHandling($mode, $options = null)
+ {
+ $stack = &$GLOBALS['_PEAR_error_handler_stack'];
+ if (isset($this) && is_a($this, 'PEAR')) {
+ $def_mode = &$this->_default_error_mode;
+ $def_options = &$this->_default_error_options;
+ } else {
+ $def_mode = &$GLOBALS['_PEAR_default_error_mode'];
+ $def_options = &$GLOBALS['_PEAR_default_error_options'];
+ }
+ $stack[] = array($def_mode, $def_options);
+
+ if (isset($this) && is_a($this, 'PEAR')) {
+ $this->setErrorHandling($mode, $options);
+ } else {
+ PEAR::setErrorHandling($mode, $options);
+ }
+ $stack[] = array($mode, $options);
+ return true;
+ }
+
+ // }}}
+ // {{{ popErrorHandling()
+
+ /**
+ * Pop the last error handler used
+ *
+ * @return bool Always true
+ *
+ * @see PEAR::pushErrorHandling
+ */
+ function popErrorHandling()
+ {
+ $stack = &$GLOBALS['_PEAR_error_handler_stack'];
+ array_pop($stack);
+ list($mode, $options) = $stack[sizeof($stack) - 1];
+ array_pop($stack);
+ if (isset($this) && is_a($this, 'PEAR')) {
+ $this->setErrorHandling($mode, $options);
+ } else {
+ PEAR::setErrorHandling($mode, $options);
+ }
+ return true;
+ }
+
+ // }}}
+ // {{{ loadExtension()
+
+ /**
+ * OS independant PHP extension load. Remember to take care
+ * on the correct extension name for case sensitive OSes.
+ *
+ * @param string $ext The extension name
+ * @return bool Success or not on the dl() call
+ */
+ function loadExtension($ext)
+ {
+ if (!extension_loaded($ext)) {
+ // if either returns true dl() will produce a FATAL error, stop that
+ if ((ini_get('enable_dl') != 1) || (ini_get('safe_mode') == 1)) {
+ return false;
+ }
+ if (OS_WINDOWS) {
+ $suffix = '.dll';
+ } elseif (PHP_OS == 'HP-UX') {
+ $suffix = '.sl';
+ } elseif (PHP_OS == 'AIX') {
+ $suffix = '.a';
+ } elseif (PHP_OS == 'OSX') {
+ $suffix = '.bundle';
+ } else {
+ $suffix = '.so';
+ }
+ return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix);
+ }
+ return true;
+ }
+
+ // }}}
+}
+
+// {{{ _PEAR_call_destructors()
+
+function _PEAR_call_destructors()
+{
+ global $_PEAR_destructor_object_list;
+ if (is_array($_PEAR_destructor_object_list) &&
+ sizeof($_PEAR_destructor_object_list))
+ {
+ reset($_PEAR_destructor_object_list);
+ if (@PEAR::getStaticProperty('PEAR', 'destructlifo')) {
+ $_PEAR_destructor_object_list = array_reverse($_PEAR_destructor_object_list);
+ }
+ while (list($k, $objref) = each($_PEAR_destructor_object_list)) {
+ $classname = get_class($objref);
+ while ($classname) {
+ $destructor = "_$classname";
+ if (method_exists($objref, $destructor)) {
+ $objref->$destructor();
+ break;
+ } else {
+ $classname = get_parent_class($classname);
+ }
+ }
+ }
+ // Empty the object list to ensure that destructors are
+ // not called more than once.
+ $_PEAR_destructor_object_list = array();
+ }
+
+ // Now call the shutdown functions
+ if (is_array($GLOBALS['_PEAR_shutdown_funcs']) AND !empty($GLOBALS['_PEAR_shutdown_funcs'])) {
+ foreach ($GLOBALS['_PEAR_shutdown_funcs'] as $value) {
+ call_user_func_array($value[0], $value[1]);
+ }
+ }
+}
+
+// }}}
+
+class PEAR_Error
+{
+ // {{{ properties
+
+ var $error_message_prefix = '';
+ var $mode = PEAR_ERROR_RETURN;
+ var $level = E_USER_NOTICE;
+ var $code = -1;
+ var $message = '';
+ var $userinfo = '';
+ var $backtrace = null;
+
+ // }}}
+ // {{{ constructor
+
+ /**
+ * PEAR_Error constructor
+ *
+ * @param string $message message
+ *
+ * @param int $code (optional) error code
+ *
+ * @param int $mode (optional) error mode, one of: PEAR_ERROR_RETURN,
+ * PEAR_ERROR_PRINT, PEAR_ERROR_DIE, PEAR_ERROR_TRIGGER,
+ * PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION
+ *
+ * @param mixed $options (optional) error level, _OR_ in the case of
+ * PEAR_ERROR_CALLBACK, the callback function or object/method
+ * tuple.
+ *
+ * @param string $userinfo (optional) additional user/debug info
+ *
+ * @access public
+ *
+ */
+ function PEAR_Error($message = 'unknown error', $code = null,
+ $mode = null, $options = null, $userinfo = null)
+ {
+ if ($mode === null) {
+ $mode = PEAR_ERROR_RETURN;
+ }
+ $this->message = $message;
+ $this->code = $code;
+ $this->mode = $mode;
+ $this->userinfo = $userinfo;
+ if (function_exists("debug_backtrace")) {
+ if (@!PEAR::getStaticProperty('PEAR_Error', 'skiptrace')) {
+ $this->backtrace = debug_backtrace();
+ }
+ }
+ if ($mode & PEAR_ERROR_CALLBACK) {
+ $this->level = E_USER_NOTICE;
+ $this->callback = $options;
+ } else {
+ if ($options === null) {
+ $options = E_USER_NOTICE;
+ }
+ $this->level = $options;
+ $this->callback = null;
+ }
+ if ($this->mode & PEAR_ERROR_PRINT) {
+ if (is_null($options) || is_int($options)) {
+ $format = "%s";
+ } else {
+ $format = $options;
+ }
+ printf($format, $this->getMessage());
+ }
+ if ($this->mode & PEAR_ERROR_TRIGGER) {
+ trigger_error($this->getMessage(), $this->level);
+ }
+ if ($this->mode & PEAR_ERROR_DIE) {
+ $msg = $this->getMessage();
+ if (is_null($options) || is_int($options)) {
+ $format = "%s";
+ if (substr($msg, -1) != "\n") {
+ $msg .= "\n";
+ }
+ } else {
+ $format = $options;
+ }
+ die(sprintf($format, $msg));
+ }
+ if ($this->mode & PEAR_ERROR_CALLBACK) {
+ if (is_callable($this->callback)) {
+ call_user_func($this->callback, $this);
+ }
+ }
+ if ($this->mode & PEAR_ERROR_EXCEPTION) {
+ trigger_error("PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_ErrorStack for exceptions", E_USER_WARNING);
+ eval('$e = new Exception($this->message, $this->code);$e->PEAR_Error = $this;throw($e);');
+ }
+ }
+
+ // }}}
+ // {{{ getMode()
+
+ /**
+ * Get the error mode from an error object.
+ *
+ * @return int error mode
+ * @access public
+ */
+ function getMode() {
+ return $this->mode;
+ }
+
+ // }}}
+ // {{{ getCallback()
+
+ /**
+ * Get the callback function/method from an error object.
+ *
+ * @return mixed callback function or object/method array
+ * @access public
+ */
+ function getCallback() {
+ return $this->callback;
+ }
+
+ // }}}
+ // {{{ getMessage()
+
+
+ /**
+ * Get the error message from an error object.
+ *
+ * @return string full error message
+ * @access public
+ */
+ function getMessage()
+ {
+ return ($this->error_message_prefix . $this->message);
+ }
+
+
+ // }}}
+ // {{{ getCode()
+
+ /**
+ * Get error code from an error object
+ *
+ * @return int error code
+ * @access public
+ */
+ function getCode()
+ {
+ return $this->code;
+ }
+
+ // }}}
+ // {{{ getType()
+
+ /**
+ * Get the name of this error/exception.
+ *
+ * @return string error/exception name (type)
+ * @access public
+ */
+ function getType()
+ {
+ return get_class($this);
+ }
+
+ // }}}
+ // {{{ getUserInfo()
+
+ /**
+ * Get additional user-supplied information.
+ *
+ * @return string user-supplied information
+ * @access public
+ */
+ function getUserInfo()
+ {
+ return $this->userinfo;
+ }
+
+ // }}}
+ // {{{ getDebugInfo()
+
+ /**
+ * Get additional debug information supplied by the application.
+ *
+ * @return string debug information
+ * @access public
+ */
+ function getDebugInfo()
+ {
+ return $this->getUserInfo();
+ }
+
+ // }}}
+ // {{{ getBacktrace()
+
+ /**
+ * Get the call backtrace from where the error was generated.
+ * Supported with PHP 4.3.0 or newer.
+ *
+ * @param int $frame (optional) what frame to fetch
+ * @return array Backtrace, or NULL if not available.
+ * @access public
+ */
+ function getBacktrace($frame = null)
+ {
+ if ($frame === null) {
+ return $this->backtrace;
+ }
+ return $this->backtrace[$frame];
+ }
+
+ // }}}
+ // {{{ addUserInfo()
+
+ function addUserInfo($info)
+ {
+ if (empty($this->userinfo)) {
+ $this->userinfo = $info;
+ } else {
+ $this->userinfo .= " ** $info";
+ }
+ }
+
+ // }}}
+ // {{{ toString()
+
+ /**
+ * Make a string representation of this object.
+ *
+ * @return string a string with an object summary
+ * @access public
+ */
+ function toString() {
+ $modes = array();
+ $levels = array(E_USER_NOTICE => 'notice',
+ E_USER_WARNING => 'warning',
+ E_USER_ERROR => 'error');
+ if ($this->mode & PEAR_ERROR_CALLBACK) {
+ if (is_array($this->callback)) {
+ $callback = (is_object($this->callback[0]) ?
+ strtolower(get_class($this->callback[0])) :
+ $this->callback[0]) . '::' .
+ $this->callback[1];
+ } else {
+ $callback = $this->callback;
+ }
+ return sprintf('[%s: message="%s" code=%d mode=callback '.
+ 'callback=%s prefix="%s" info="%s"]',
+ strtolower(get_class($this)), $this->message, $this->code,
+ $callback, $this->error_message_prefix,
+ $this->userinfo);
+ }
+ if ($this->mode & PEAR_ERROR_PRINT) {
+ $modes[] = 'print';
+ }
+ if ($this->mode & PEAR_ERROR_TRIGGER) {
+ $modes[] = 'trigger';
+ }
+ if ($this->mode & PEAR_ERROR_DIE) {
+ $modes[] = 'die';
+ }
+ if ($this->mode & PEAR_ERROR_RETURN) {
+ $modes[] = 'return';
+ }
+ return sprintf('[%s: message="%s" code=%d mode=%s level=%s '.
+ 'prefix="%s" info="%s"]',
+ strtolower(get_class($this)), $this->message, $this->code,
+ implode("|", $modes), $levels[$this->level],
+ $this->error_message_prefix,
+ $this->userinfo);
+ }
+
+ // }}}
+}
+
+/*
+ * Local Variables:
+ * mode: php
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ */
+?>
Added: plugins/trunk/moblog/class/action/adminmoblogbatchpluginsettingsaction.class.php
===================================================================
--- plugins/trunk/moblog/class/action/adminmoblogbatchpluginsettingsaction.class.php 2005-06-10 09:00:01 UTC (rev 2187)
+++ plugins/trunk/moblog/class/action/adminmoblogbatchpluginsettingsaction.class.php 2005-06-10 09:43:48 UTC (rev 2188)
@@ -0,0 +1,24 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
+ include_once( PLOG_CLASS_PATH."plugins/moblog/class/view/adminmoblogbatchpluginsettingsview.class.php" );
+
+ /**
+ * doesn't do almost anything :))
+ */
+ class AdminMoblogBatchPluginSettingsAction extends SiteAdminAction
+ {
+ function AdminMoblogBatchPluginSettingsAction( $actionInfo, $request )
+ {
+ $this->SiteAdminAction( $actionInfo, $request );
+ }
+
+ function perform()
+ {
+ $this->_view = new AdminMoblogBatchPluginSettingsView( $this->_blogInfo, $this->_userInfo );
+ $this->setCommonData();
+
+ return true;
+ }
+ }
+?>
\ No newline at end of file
Added: plugins/trunk/moblog/class/action/adminmoblogbatchpluginupdatesettingsaction.class.php
===================================================================
--- plugins/trunk/moblog/class/action/adminmoblogbatchpluginupdatesettingsaction.class.php 2005-06-10 09:00:01 UTC (rev 2187)
+++ plugins/trunk/moblog/class/action/adminmoblogbatchpluginupdatesettingsaction.class.php 2005-06-10 09:43:48 UTC (rev 2188)
@@ -0,0 +1,59 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
+ include_once( PLOG_CLASS_PATH."plugins/moblog/class/view/adminmoblogbatchpluginsettingsview.class.php" );
+ include_once( PLOG_CLASS_PATH."plugins/moblog/class/moblog/moblogconstants.properties.php" );
+
+ class AdminMoblogBatchPluginUpdateSettingsAction extends SiteAdminAction
+ {
+
+ var $_pluginEnabled;
+
+ function AdminMoblogBatchPluginUpdateSettingsAction( $actionInfo, $request )
+ {
+ $this->SiteAdminAction( $actionInfo, $request );
+ }
+
+ function validate()
+ {
+ $this->_mailServer = $this->_request->getValue( "mailServer" );
+ $this->_port = $this->_request->getValue( "port" );
+ $this->_userName = $this->_request->getValue( "userName" );
+ $this->_password = $this->_request->getValue( "password" );
+ $this->_pseudoBatch = $this->_request->getValue( "pseudoBatch" );
+ return true;
+ }
+
+ function perform()
+ {
+ // update the plugin configurations to blog setting
+ $config =& Config::getConfig();
+ $config->setValue( "plugin_moblog_mailserver", $this->_mailServer );
+ $config->setValue( "plugin_moblog_port", $this->_port );
+ $config->setValue( "plugin_moblog_username", $this->_userName );
+ $config->setValue( "plugin_moblog_password", $this->_password );
+ $config->setValue( "plugin_moblog_pseudobatch", $this->_pseudoBatch );
+
+ if( !$config->save() ) {
+ $this->_view = new AdminMoblogBatchPluginSettingsView( $this->_blogInfo );
+ $this->_view->setErrorMessage( $this->_locale->tr("error_updating_settings"));
+ $this->setCommonData();
+
+ return false;
+ }
+
+ // if everything went ok...
+ $this->_session->setValue( "blogInfo", $this->_blogInfo );
+ $this->saveSession();
+
+ $this->_view = new AdminMoblogBatchPluginSettingsView( $this->_blogInfo );
+ $this->_view->setSuccessMessage( $this->_locale->tr("moblog_settings_saved_ok"));
+ $this->setCommonData();
+
+ // clear the cache
+ CacheControl::resetBlogCache( $this->_blogInfo->getId());
+
+ return true;
+ }
+ }
+?>
\ No newline at end of file
Modified: plugins/trunk/moblog/class/moblog/moblogconstants.properties.php
===================================================================
--- plugins/trunk/moblog/class/moblog/moblogconstants.properties.php 2005-06-10 09:00:01 UTC (rev 2187)
+++ plugins/trunk/moblog/class/moblog/moblogconstants.properties.php 2005-06-10 09:43:48 UTC (rev 2188)
@@ -13,4 +13,7 @@
// played
//
define( 'MOBLOG_IGNORE_SMIL_ATTACHMENTS', true );
+
+ // encode all incoming e-mail message to UTF-8
+ define( 'MOBLOG_FORCE_ENCODE_TO_UTF8', true );
?>
\ No newline at end of file
Modified: plugins/trunk/moblog/class/moblog/moblogrequest.class.php
===================================================================
--- plugins/trunk/moblog/class/moblog/moblogrequest.class.php 2005-06-10 09:00:01 UTC (rev 2187)
+++ plugins/trunk/moblog/class/moblog/moblogrequest.class.php 2005-06-10 09:43:48 UTC (rev 2188)
@@ -1,248 +1,294 @@
-<?php
-
- include_once( PLOG_CLASS_PATH."plugins/moblog/class/moblog/mimeDecode.class.php" );
- include_once( PLOG_CLASS_PATH."plugins/moblog/class/log/mobloglogger.class.php" );
- include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
-
- /**
- * contains all the parameters that came in the user's email.
- */
- class MoblogRequest extends Object
- {
- var $_message;
- var $_structure;
- var $_replyAddress;
- var $_body;
- var $_category;
- var $_topic;
- var $_user;
- var $_pass;
- var $_blogId;
- var $_blogName;
- var $_introduction;
- var $_host;
- var $_attachments;
- var $_help;
-
- function MoblogRequest( $request )
- {
- $this->Object();
-
- $this->_message = $request["message"];
- // it is possible to specify a default user id in the POSTed email message via
- // curl, so that the amount of stuff that we need to type in the email is reduced
- // to only the user password. This basically means that email addresses configured to be used
- // by a default user and blog id cannot be used as 'gateways'
- $this->_blogId = $request["blogId"];
- $this->_user = $request["user"];
-
- MoblogLogger::log( "From REQUEST: user = ".$this->_user." - blogId = ".$this->_blogId );
-
- // parse the mime message
+<?php
+
+ include_once( PLOG_CLASS_PATH."plugins/moblog/class/moblog/mimeDecode.class.php" );
+ include_once( PLOG_CLASS_PATH."plugins/moblog/class/moblog/moblogconstants.properties.php" );
+ include_once( PLOG_CLASS_PATH."plugins/moblog/class/log/mobloglogger.class.php" );
+ include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
+
+ /**
+ * contains all the parameters that came in the user's email.
+ */
+ class MoblogRequest extends Object
+ {
+ var $_message;
+ var $_structure;
+ var $_replyAddress;
+ var $_body;
+ var $_category;
+ var $_topic;
+ var $_user;
+ var $_pass;
+ var $_blogId;
+ var $_blogName;
+ var $_introduction;
+ var $_host;
+ var $_attachments;
+ var $_help;
+ var $_inputEncoding;
+
+ function MoblogRequest( $request )
+ {
+ $this->Object();
+
+ $this->_message = $request["message"];
+ // it is possible to specify a default user id in the POSTed email message via
+ // curl, so that the amount of stuff that we need to type in the email is reduced
+ // to only the user password. This basically means that email addresses configured to be used
+ // by a default user and blog id cannot be used as 'gateways'
+ $this->_blogId = $request["blogId"];
+ $this->_user = $request["user"];
+
+ MoblogLogger::log( "From REQUEST: user = ".$this->_user." - blogId = ".$this->_blogId );
+
+ // parse the mime message
$decode = new Mail_mimeDecode( $this->_message, "\r\n" );
- $structure = $decode->decode(Array(
- "include_bodies" => true,
- "decode_bodies" => true,
- "decode_headers" => false,
- ));
-
- // get the reply address, it might be in different headers
+ $structure = $decode->decode(Array(
+ "include_bodies" => true,
+ "decode_bodies" => true,
+ "decode_headers" => true,
+ ));
+
+ // get the reply address, it might be in different headers
if (isset($structure->headers['x-loop'])) {
$this->_replyAddress = "";
- }
+ }
else {
$replyTo1 = $structure->headers['from'];
$replyTo2 = $structure->headers['return-path'];
$this->_replyAddress = ($replyTo2 != "") ? $replyTo2 : $replyTo1;
- }
-
- // parse the body
- $this->parseBody( $structure->body );
-
- MoblogLogger::log( "There are ".count($structure->parts)." MIME parts available to parse" );
- $this->parseMimeParts( $structure->parts );
-
- // if there was no subject specified, then let's see if there was something in the
- // 'subject' line...
- if( $this->_topic == "" ) {
- $this->_topic = $structure->headers['subject'];
- if( $this->_topic == "" ) {
- // if there is still no subject, get the first 50 characters of the body
- $this->_topic = substr(strip_tags($this->_body), 0, 50 );
- }
- }
- MoblogLogger::Log("subject is = ".$this->_topic );
- }
-
- /**
- * Uses the mimeDecode class to parse the message and get the fields
- * that we need. This class is also capable of parsing attachments, mime
- * messages, etc.
- */
- function parseBody( $body )
- {
- $body = strip_tags($body, "<a><b><i><u><s>");
- //$body = strtr($body,"\xE2\x80\xA9","\n\n\n");
- $body = str_replace("\xE2\x80\xA9","\n",$body);
-
- //We try to find out where the line containing the title is at...
- if (preg_match("/^topic:(.*)/mi", $body, $title)) {
- //And put the title var in the proper place
- $this->_topic = trim($title[1]);
- }
-
- //We repeat the same trick as above... for all vars wanted
- if (preg_match("/^user:(.*)/mi", $body, $user)) {
- $this->_user = trim($user[1]);
- }
-
- // in case ppl are lazy and use pass instead of password
- if (preg_match("/^pass:(.*)/mi", $body, $pass)) {
- $this->_pass = trim($pass[1]);
- }
- else if (preg_match("/^password:(.*)/mi", $body, $password)) {
- $this->_pass = trim($password[1]);
- }
-
- // we can either specify a blog id...
- if (preg_match("/^blogid:(.*)/mi", $body, $blog)) {
- $this->_blogId = trim($blog[1]);
- }
-
- // ...or a blog name
- if (preg_match("/^blog:(.*)/mi", $body, $blogname)) {
- $this->_blogName = trim($blogname[1]);
- }
-
- //We strip out all the lines we already used, and use what's left as the body
- $body = str_replace($title[0], "", $body);
- $body = str_replace($user[0], "", $body);
- $body = str_replace($pass[0], "", $body);
- $body = str_replace($password[0], "", $body);
- $body = str_replace($cat[0], "", $body);
- $body = str_replace($publish[0], "", $body);
- $body = str_replace($category[0], "", $body);
- $body = str_replace($blog[0], "", $body );
- $body = str_replace($blogname[0], "", $body );
- $body = str_replace($host[0], "", $body );
-
- // strip off a standard .sig. Properly formed .sigs start with '-- ' on a new line.
- list($body, $sig) = explode("\n-- ", $body);
-
- MoblogLogger::log( "parseBody ---> body = $body" );
- $body = trim($body);
+ }
+
+ // parse the body
+ $this->parseBody( $structure->body );
+
+ MoblogLogger::log( "There are ".count($structure->parts)." MIME parts available to parse" );
+ $this->parseMimeParts( $structure->parts );
+
+ // if there was no subject specified, then let's see if there was something in the
+ // 'subject' line...
+ if( $this->_topic == "" ) {
+ $this->_topic = $structure->headers['subject'];
+ if( $this->_topic == "" || stristr( $this->_topic, "pass:" )) {
+ // if there is still no subject, get the first 50 characters of the body
+ $this->_topic = substr(strip_tags($this->_body), 0, 50 );
+ if ( $this->_topic == "" )
+ $this->_topic = "No Topic";
+ }
+ }
+ MoblogLogger::Log("subject is = ".$this->_topic );
+ }
+
+ /**
+ * Uses the mimeDecode class to parse the message and get the fields
+ * that we need. This class is also capable of parsing attachments, mime
+ * messages, etc.
+ */
+ function parseBody( $body )
+ {
+ $body = strip_tags($body, "<a><b><i><u><s>");
+ //$body = strtr($body,"\xE2\x80\xA9","\n\n\n");
+ $body = str_replace("\xE2\x80\xA9","\n",$body);
+
+ //We try to find out where the line containing the title is at...
+ if (preg_match("/^topic:(.*)/mi", $body, $title)) {
+ //And put the title var in the proper place
+ $this->_topic = trim($title[1]);
+ }
+
+ //We repeat the same trick as above... for all vars wanted
+ if (preg_match("/^user:(.*)/mi", $body, $user)) {
+ $this->_user = trim($user[1]);
+ }
+
+ // in case ppl are lazy and use pass instead of password
+ if (preg_match("/^pass:(.*)/mi", $body, $pass)) {
+ $this->_pass = trim($pass[1]);
+ }
+ else if (preg_match("/^password:(.*)/mi", $body, $password)) {
+ $this->_pass = trim($password[1]);
+ }
+
+ // we can either specify a blog id...
+ if (preg_match("/^blogid:(.*)/mi", $body, $blog)) {
+ $this->_blogId = trim($blog[1]);
+ }
+
+ // ...or a blog name
+ if (preg_match("/^blog:(.*)/mi", $body, $blogname)) {
+ $this->_blogName = trim($blogname[1]);
+ }
+
+ //We strip out all the lines we already used, and use what's left as the body
+ $body = str_replace($title[0], "", $body);
+ $body = str_replace($user[0], "", $body);
+ $body = str_replace($pass[0], "", $body);
+ $body = str_replace($password[0], "", $body);
+ $body = str_replace($cat[0], "", $body);
+ $body = str_replace($publish[0], "", $body);
+ $body = str_replace($category[0], "", $body);
+ $body = str_replace($blog[0], "", $body );
+ $body = str_replace($blogname[0], "", $body );
+ $body = str_replace($host[0], "", $body );
+
+ // strip off a standard .sig. Properly formed .sigs start with '-- ' on a new line.
+ list($body, $sig) = explode("\n-- ", $body);
+
+ MoblogLogger::log( "parseBody ---> body = $body" );
+ $body = trim($body);
$this->_body .= $body;
- }
-
- /**
- * checks if there are any mime parts, perhaps attachments or something like
- * that...
- */
- function parseMimeParts( $parts )
- {
- $this->_attachments = Array();
- foreach( $parts as $part ) {
- MoblogLogger::log( "attachment type = ".$part->ctype_primary."/".$part->ctype_secondary );
-
- if( strtolower($part->ctype_primary) == "text" ) {
- // if message is MIME, then this actually is the text of the message
- MoblogLogger::log( "Reparsing the body of the message!" );
- MoblogLogger::log( "text/plain part - contents = ".$part->body );
- $this->parseBody( $part->body );
- }
- elseif( strtolower($part->ctype_primary) == "multipart" ) {
- // ignore these 'multipart' attachments, since they usually
- // are html stuff that we don't care about...
- }
- else {
- // whatever comes as a part, we will take it and treat it as if it was
- // a normal resource as long as it's not an application/smil thingie...
-
- if( strtolower($part->ctype_secondary) != 'smil' && MOBLOG_IGNORE_SMIL_ATTACHMENTS ) {
- // GalleryResources::addResource only deals with uploaded files, so we'll
- // have to pretend that this is one of them!
- $config =& Config::getConfig();
- $tmpFolder = $config->getValue( "temp_folder" );
- $tmpFolderName = $tmpFolder."/".md5(microtime());
- File::createDir( $tmpFolderName );
- MoblogLogger::log( "Creating temp folder = $tmpFolderName" );
- $fileName = stripslashes($part->ctype_parameters["name"]);
- if( $fileName == "" )
- $fileName = stripslashes($part->d_parameters["filename"]);
-
- $fileName = str_replace( "\"", "", $fileName );
- $fileName = str_replace( "'", "", $fileName );
- $f = new File( $tmpFolderName."/".$fileName );
- $f->open( "ab+" );
- MoblogLogger::log( "fileName = ".$tmpFolderName."/".$fileName );
- MoblogLogger::log( "Saving attachment as = ".$tmpFolderName."/".$fileName );
- //MoblogLogger::log( "base64 encoded data = ".$part->body );
- if( !$f->write( $part->body )) {
- MoblogLogger::log( "There was an error writing the temporary file" );
- die();
- }
- MoblogLogger::log( "File saved ok!" );
- MoblogLogger::log("FILENAME = $fileName");
- $uploadInfo = Array( "name" => $fileName,
- "type" => $part->ctype_primary."/".$part->ctype_secondary,
- "tmp_name" => $tmpName,
- "size" => $f->getSize(),
- "error" => 0 );
-
- $upload = new FileUpload( $uploadInfo );
- $upload->setFolder( $tmpFolderName );
- array_push( $this->_attachments, $upload );
- }
- }
- }
}
+
+ /**
+ * checks if there are any mime parts, perhaps attachments or something like
+ * that...
+ */
+ function parseMimeParts( $parts )
+ {
+ $this->_attachments = Array();
+ foreach( $parts as $part ) {
+ MoblogLogger::log( "attachment type = ".$part->ctype_primary."/".$part->ctype_secondary );
+
+ if( strtolower($part->ctype_primary) == "text" && strtolower($part->ctype_secondary) == "plain" ) {
+ // if ctype_primary == text and ctype_secondary == plain, it should be text format e-mail
+ MoblogLogger::log( "Reparsing the body of the message!" );
+ MoblogLogger::log( "text/plain part - contents = ".$part->body );
+ $this->parseBody( $part->body );
+ $this->_inputEncoding = strtoupper( $part->ctype_parameters['charset'] );
+ }
+ elseif( strtolower($part->ctype_primary) == "multipart" && strtolower($part->ctype_secondary) == "alternative") {
+ // if ctype_primary == multipart and ctype_secondary == alternative, it should be html format e-mail
+ // We should look into it's child to get the real body
+ foreach ( $part->parts as $childPart ) {
+ if( strtolower($childPart->ctype_primary) == "text" && strtolower($childPart->ctype_secondary) == "plain" ) {
+ $this->parseBody( $childPart->body );
+ $this->_inputEncoding = strtoupper( $childPart->ctype_parameters['charset'] );
+ }
+ }
+ }
+ else {
+ // whatever comes as a part, we will take it and treat it as if it was
+ // a normal resource as long as it's not an application/smil thingie...
+
+ if( strtolower($part->ctype_secondary) != 'smil' && MOBLOG_IGNORE_SMIL_ATTACHMENTS ) {
+ // GalleryResources::addResource only deals with uploaded files, so we'll
+ // have to pretend that this is one of them!
+ $config =& Config::getConfig();
+ // $tmpFolder = $config->getValue( "temp_folder" );
+ // $tmpFolderName = $tmpFolder."/".md5(microtime());
+ $tmpFolderName = $config->getValue( "temp_folder" );
+ File::createDir( $tmpFolderName );
+ MoblogLogger::log( "Creating temp folder = $tmpFolderName" );
+ $fileName = stripslashes($part->ctype_parameters["name"]);
+ if( $fileName == "" )
+ $fileName = stripslashes($part->d_parameters["filename"]);
+
+ $fileName = str_replace( "\"", "", $fileName );
+ $fileName = str_replace( "'", "", $fileName );
+ $tmpName = $tmpFolderName."/".md5(microtime())."_".$fileName;
+ $fileName = urldecode( $fileName );
+
+ if ( MOBLOG_FORCE_ENCODE_TO_UTF8 )
+ $fileName = $this->encodeToUTF8( $fileName, $this->_inputEncoding);
+
+ $f = new File( $tmpName );
+ $f->open( "ab+" );
+ MoblogLogger::log( "fileName = ".$tmpName );
+ MoblogLogger::log( "Saving attachment as = ".$tmpName );
+ //MoblogLogger::log( "base64 encoded data = ".$part->body );
+ if( !$f->write( $part->body )) {
+ MoblogLogger::log( "There was an error writing the temporary file" );
+ die();
+ }
+ MoblogLogger::log( "File saved ok!" );
+ MoblogLogger::log("FILENAME = $fileName");
+ $uploadInfo = Array( "name" => urldecode($fileName),
+ "type" => $part->ctype_primary."/".$part->ctype_secondary,
+ "tmp_name" => $tmpName,
+ "size" => $f->getSize(),
+ "error" => 0 );
+
+ $upload = new FileUpload( $uploadInfo );
+ $upload->setFolder( $tmpFolderName );
+ array_push( $this->_attachments, $upload );
+ }
+ }
+ }
+ }
+
+ function encodeToUTF8( $input, $inputEncoding)
+ {
+ if ( $inputEncoding == "UTF-8" || $inputEncoding == "" )
+ return $input;
+
+ if (function_exists('iconv')) {
+ $output = iconv($inputEncoding,'UTF-8', $input);
+ if ($output) {
+ return $output;
+ } elseif (function_exists('mb_convert_encoding')) {
+ $output = mb_convert_encoding($input, 'UTF-8', $inputEncoding );
+ if ($output) {
+ return $output;
+ } else {
+ return $input;
+ }
+ } else {
+ return $input;
+ }
+ }
+ }
- function tidy($text)
- {
- $text = str_replace(" <br />", "", $text);
- $text = preg_replace("/([\n\r\t])+/is", "\n", $text);
-
+ function tidy($text)
+ {
+ $text = str_replace(" <br />", "", $text);
+ $text = preg_replace("/([\n\r\t])+/is", "\n", $text);
+
return ($text);
- }
-
- function getUser()
- {
- return $this->_user;
- }
-
- function getBlogId()
- {
- return $this->_blogId;
- }
-
- function getBlogName()
- {
- return $this->_blogName;
- }
-
- function getPassword()
- {
- return $this->_pass;
- }
-
- function getTopic()
- {
- return $this->_topic;
- }
-
- function getBody()
- {
- return $this->_body;
- }
-
- function getReplyTo()
- {
- return $this->_replyAddress;
- }
-
- function getAttachments()
- {
- return $this->_attachments;
- }
- }
+ }
+
+ function getUser()
+ {
+ return $this->_user;
+ }
+
+ function getBlogId()
+ {
+ return $this->_blogId;
+ }
+
+ function getBlogName()
+ {
+ return $this->_blogName;
+ }
+
+ function getPassword()
+ {
+ return $this->_pass;
+ }
+
+ function getTopic()
+ {
+ if ( MOBLOG_FORCE_ENCODE_TO_UTF8 )
+ return $this->encodeToUTF8( $this->_topic, $this->_inputEncoding);
+ else
+ return $this->_topic;
+ }
+
+ function getBody()
+ {
+ if ( MOBLOG_FORCE_ENCODE_TO_UTF8 )
+ return $this->encodeToUTF8( $this->_body, $this->_inputEncoding);
+ else
+ return $this->_body;
+ }
+
+ function getReplyTo()
+ {
+ return $this->_replyAddress;
+ }
+
+ function getAttachments()
+ {
+ return $this->_attachments;
+ }
+ }
?>
\ No newline at end of file
Added: plugins/trunk/moblog/class/security/moblogbatchfilter.class.php
===================================================================
--- plugins/trunk/moblog/class/security/moblogbatchfilter.class.php 2005-06-10 09:00:01 UTC (rev 2187)
+++ plugins/trunk/moblog/class/security/moblogbatchfilter.class.php 2005-06-10 09:43:48 UTC (rev 2188)
@@ -0,0 +1,105 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/security/pipelinefilter.class.php" );
+ include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
+ include_once( PLOG_CLASS_PATH."class/net/baserequestgenerator.class.php" );
+ include_once( PLOG_CLASS_PATH."plugins/moblog/class/PEAR/Net/POP3.php" );
+ include_once( PLOG_CLASS_PATH."plugins/moblog/class/PEAR/HTTP/Request.php");
+
+ // custom error code that will be returned to the pipeline whenever an
+ // error is found... Be careful so as to not to have two different modules
+ // use the same code!!
+ define( "MOBLOGBATCH_FILTER_MATCH_FOUND", 2022 );
+
+ /**
+ * Filters the text posted in a comment by a user, to prevent spam-bots. This
+ * filter only works if the incoming request has the "op" parameter as
+ * "AddComment", because then it means that we're posting a comment. If it's not
+ * like that, then we'll quit. Otherwise, the process will continue as normally.
+ */
+ class MoblogBatchFilter extends PipelineFilter
+ {
+
+ function MoblogBatchFilter( $pipelineRequest )
+ {
+ $this->PipelineFilter( $pipelineRequest );
+ }
+
+ function filter()
+ {
+ $blogInfo = $this->_pipelineRequest->getBlogInfo();
+ $config =& Config::getConfig();
+
+ $pseudoBatch = $config->getValue('plugin_moblog_pseudobatch');
+ if( $pseudoBatch == "Off" || $pseudoBatch == "" ) {
+ $result = new PipelineResult();
+ return $result;
+ }
+
+ $lastUpdate = $config->getValue('plugin_moblog_lastupdate');
+ $timeDiff = time() - $lastUpdate;
+ if( $timeDiff <= $pseudoBatch*60 ) {
+ $result = new PipelineResult();
+ return $result;
+ }
+
+ $mailServer = $config->getValue('plugin_moblog_mailserver');
+ $port = $config->getValue('plugin_moblog_port');
+ $userName = $config->getValue('plugin_moblog_username');
+ $password = $config->getValue('plugin_moblog_password');
+
+ // pop3 connection and log-in
+ $pop3 =& new Net_POP3();
+
+ if(PEAR::isError( $ret = $pop3->connect($mailServer , $port )) ) {
+ // if there is a match, we can quit and reject this request
+ $locale = $blogInfo->getLocale();
+ $result = new PipelineResult( false, MOBLOGBATCH_FILTER_MATCH_FOUND, $locale->tr("error_moblogbatch_connect") );
+ return $result;
+ }
+
+ if(PEAR::isError( $ret = $pop3->login($userName , $password, 'USER' )) ) {
+ $locale = $blogInfo->getLocale();
+ $result = new PipelineResult( false, MOBLOGBATCH_FILTER_MATCH_FOUND, $locale->tr("error_moblogbatch_login") );
+ return $result;
+ }
+
+ $messageNumber = $pop3->numMsg();
+
+ if ($messageNumber == 0) {
+ $pop3->disconnect();
+ } else {
+ // get message list
+ $messageList = $pop3->getListing();
+ $messages = Array();
+
+ for ($cnt = 0; $cnt < count($messageList); $cnt++) {
+ $messages[$cnt] = $pop3->getMsg($messageList[$cnt]['msg_id']);
+ $pop3->deleteMsg($messageList[$cnt]['msg_id']);
+ }
+
+ // pop3 disconnect
+ $pop3->disconnect();
+
+ $config->setValue( "plugin_moblog_lastupdate", time() );
+ $config->save();
+
+ $url = &new BaseRequestGenerator();
+
+ for ($cnt = 0; $cnt < count($messages); $cnt++) {
+ $req = &new HTTP_Request($url->getBaseUrl(false)."/moblog.php");
+ $req->setMethod(HTTP_REQUEST_METHOD_POST);
+ $req->addPostData('message', $messages[$cnt]);
+ $req->sendRequest();
+ $response = $req->getResponseBody();
+ }
+ }
+
+ // if everything went fine, we can say so by returning
+ // a positive PipelineResult object
+ $result = new PipelineResult( true );
+
+ return $result;
+ }
+ }
+?>
Added: plugins/trunk/moblog/class/view/adminmoblogbatchpluginsettingsview.class.php
===================================================================
--- plugins/trunk/moblog/class/view/adminmoblogbatchpluginsettingsview.class.php 2005-06-10 09:00:01 UTC (rev 2187)
+++ plugins/trunk/moblog/class/view/adminmoblogbatchpluginsettingsview.class.php 2005-06-10 09:43:48 UTC (rev 2188)
@@ -0,0 +1,41 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
+ include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
+
+ /**
+ * loads and displays the plugin settings
+ */
+ class AdminMoblogBatchPluginSettingsView extends AdminPluginTemplatedView
+ {
+ function AdminMoblogBatchPluginSettingsView( $blogInfo )
+ {
+ $this->AdminPluginTemplatedView( $blogInfo, "moblog", "moblogbatchsettings" );
+ }
+
+ function render()
+ {
+ // load some configuration settings
+ $config =& Config::getConfig();
+ $mailServer = $config->getValue( "plugin_moblog_mailserver" );
+ $port = $config->getValue( "plugin_moblog_port" );
+ if ($port == "") $port = "110";
+ $userName = $config->getValue( "plugin_moblog_username" );
+ $password = $config->getValue( "plugin_moblog_password" );
+ $pseudoBatch = $config->getValue( "plugin_moblog_pseudobatch" );
+ if ($pseudoBatch == "") $pseudoBatch = "Off";
+ $lastUpdate = $config->getValue( "plugin_moblog_lastupdate" );
+
+ // create a view and export the settings to the template
+ $this->setValue( "mailServer", $mailServer );
+ $this->setValue( "port", $port );
+ $this->setValue( "userName", $userName );
+ $this->setValue( "password", $password );
+ $this->setValue( "pseudoBatch", $pseudoBatch );
+ $this->setValue( "lastUpdate", $lastUpdate );
+
+ parent::render();
+ }
+ }
+?>
\ No newline at end of file
Modified: plugins/trunk/moblog/pluginmoblog.class.php
===================================================================
--- plugins/trunk/moblog/pluginmoblog.class.php 2005-06-10 09:00:01 UTC (rev 2187)
+++ plugins/trunk/moblog/pluginmoblog.class.php 2005-06-10 09:43:48 UTC (rev 2188)
@@ -1,6 +1,7 @@
<?php
include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
+ include_once( PLOG_CLASS_PATH."plugins/moblog/class/security/moblogbatchfilter.class.php" );
/**
* implementation a plugin to give plog moblogging features (posting via email)
@@ -11,7 +12,7 @@
function PluginMoblog()
{
$this->id = "moblog";
- $this->author = "The pLog Project";
+ $this->author = "The pLog Team";
$this->locales = Array();
$this->desc = "
Send a message with the following format ('start' and 'end' messages not included!):<br/>
@@ -35,10 +36,16 @@
*/
function init()
{
+ // register the filter
+ $this->registerFilter( "MoblogBatchFilter" );
+
// register actions
$this->registerAdminAction( "moblogSettings", "AdminMoblogPluginSettingsAction" );
$this->registerAdminAction( "updateMoblogSettings", "AdminMoblogPluginUpdateSettingsAction" );
+ $this->registerAdminAction( "moblogbatchSettings", "AdminMoblogBatchPluginSettingsAction" );
+ $this->registerAdminAction( "updateMoblogBatchSettings", "AdminMoblogBatchPluginUpdateSettingsAction" );
+
// register menu entries
$this->addMenuEntry( "/menu/controlCenter/manageSettings", // menu path
"moblogSettings", // menu id
@@ -47,6 +54,7 @@
true, // can't...
false // ...remember :)
);
+ $this->addMenuEntry( "/menu/adminSettings/GlobalSettings", "moblogbatchSettings", "admin.php?op=moblogbatchSettings", "" );
}
}
?>
\ No newline at end of file
Added: plugins/trunk/moblog/templates/moblogbatchsettings.template
===================================================================
--- plugins/trunk/moblog/templates/moblogbatchsettings.template 2005-06-10 09:00:01 UTC (rev 2187)
+++ plugins/trunk/moblog/templates/moblogbatchsettings.template 2005-06-10 09:43:48 UTC (rev 2188)
@@ -0,0 +1,69 @@
+{include file="$admintemplatepath/header.template"}
+{include file="$admintemplatepath/navigation.template" showOpt=moblogbatchSettings title=$locale->tr("mobologbatch_plugin")}
+<form name="moblogbatchPluginConfig" method="post">
+ <fieldset class="inputField">
+ <legend>{$locale->tr("label_configuration")}</legend>
+ {include file="$admintemplatepath/successmessage.template"}
+ {include file="$admintemplatepath/errormessage.template"}
+ <div class="field">
+ <label for="mailServer">{$locale->tr("label_mailserver")}</label>
+ <span class="required">*</span>
+ <div class="formHelp">{$locale->tr("moblogbatch_mailserver")}</div>
+ <input class="text" type="text" name="mailServer" id="mailServer" value="{$mailServer}" width="30" />
+ </div>
+
+ <div class="field">
+ <label for="port">{$locale->tr("label_port")}</label>
+ <span class="required">*</span>
+ <div class="formHelp">{$locale->tr("moblogbatch_port")}</div>
+ <input class="text" type="text" name="port" id="port" value="{$port}" width="10" />
+ </div>
+
+ <div class="field">
+ <label for="userName">{$locale->tr("label_username")}</label>
+ <span class="required">*</span>
+ <div class="formHelp">{$locale->tr("moblogbatch_username")}</div>
+ <input class="text" type="text" name="userName" id="userName" value="{$userName}" width="30" />
+ </div>
+
+ <div class="field">
+ <label for="password">{$locale->tr("label_password")}</label>
+ <span class="required">*</span>
+ <div class="formHelp">{$locale->tr("moblogbatch_password")}</div>
+ <input class="text" type="text" name="password" id="password" value="{$password}" width="30" />
+ </div>
+
+ <div class="field">
+ <label for="pseudoBatch">{$locale->tr("label_pseudobatch")}</label>
+ <span class="required"></span>
+ <div class="formHelp">{$locale->tr("moblogbatch_pseudobatch")}</div>
+ <select name="pseudoBatch" id="pseudoBatch">
+ <option value="Off" {if $pseudoBatch=="Off"}selected="selected"{/if}>{$locale->tr("moblogbatch_off")}</option>
+ <option value="10" {if $pseudoBatch==10}selected="selected"{/if}>10</option>
+ <option value="20" {if $pseudoBatch==20}selected="selected"{/if}>20</option>
+ <option value="30" {if $pseudoBatch==30}selected="selected"{/if}>30</option>
+ <option value="40" {if $pseudoBatch==40}selected="selected"{/if}>40</option>
+ <option value="50" {if $pseudoBatch==50}selected="selected"{/if}>50</option>
+ <option value="60" {if $pseudoBatch==60}selected="selected"{/if}>60</option>
+ <option value="90" {if $pseudoBatch==90}selected="selected"{/if}>90</option>
+ <option value="120" {if $pseudoBatch==120}selected="selected"{/if}>120</option>
+ </select>
+ </div>
+
+ <div class="field">
+ <label for="lastUpdate">{$locale->tr("label_lastupdate")}</label>
+ <span class="required">*</span>
+ <div class="formHelp">{$locale->tr("moblogbatch_lastupdate")}</div>
+ <input class="text" type="text" name="lastUpdate" id="lastUpdate" value="{$lastUpdate}" width="10" />
+ </div>
+
+ </fieldset>
+
+ <div class="buttons">
+ <input type="hidden" name="op" value="updateMoblogBatchSettings" />
+ <input type="reset" name="{$locale->tr("reset")}" />
+ <input type="submit" name="{$locale->tr("update_settings")}" value="{$locale->tr("update")}" />
+ </div>
+</form>
+{include file="$admintemplatepath/footernavigation.template"}
+{include file="$admintemplatepath/footer.template"}
\ No newline at end of file
Modified: plugins/trunk/moblog.php
===================================================================
--- plugins/trunk/moblog.php 2005-06-10 09:00:01 UTC (rev 2187)
+++ plugins/trunk/moblog.php 2005-06-10 09:43:48 UTC (rev 2188)
@@ -185,7 +185,7 @@
$t = new Timestamp();
$albumId = $blogSettings->getValue( "plugin_moblog_gallery_resource_album_id" );
$album = $albums->getAlbum( $albumId, $blogInfo->getId());
- // check if the album was loaded
+ // check if the album was loaded
if( !$album ) {
$response = new MoblogResponse( $request->getReplyTo(),
"pLog Moblog: Error",
@@ -203,10 +203,10 @@
$resourceIds = Array();
foreach( $attachments as $attachment ) {
MoblogLogger::log( "-- Processing attachment ".$attachment->getFileName());
- //$result = $res->addResource( $blogInfo->getId(), $albumId, $attachment->getFileName(), $attachment );
- $filePath = $attachment->getFolder()."/".$attachment->getFileName();
- MoblogLogger::log( "filename = ".$attachment->getFileName()." - patch = ".$filePath );
- $result = $res->addResourceFromDisk( $blogInfo->getId(), $albumId, $attachment->getFileName(), $filePath );
+ $result = $res->addResource( $blogInfo->getId(), $albumId, $attachment->getFileName(), $attachment );
+ //$filePath = $attachment->getFolder()."/".$attachment->getFileName();
+ //MoblogLogger::log( "filename = ".$attachment->getFileName()." - patch = ".$filePath );
+ //$result = $res->addResourceFromDisk( $blogInfo->getId(), $albumId, $attachment->getFileName(), $filePath );
MoblogLogger::log( " Completed: result = $result" );
if( $result ) {
// keep this for later
@@ -263,7 +263,7 @@
);
$article->setDateObject( new Timestamp());
// enable or disable comments by default depending on the current config
- $commentsEnabled = $blogSettings->getValue( "comments_enabled" );
+ $commentsEnabled = $blogSettings->getValue( "comments_enabled" );
$article->setCommentsEnabled( $commentsEnabled );
$result = $articles->addArticle( $article );
Added: plugins/trunk/moblogbatch.php
===================================================================
--- plugins/trunk/moblogbatch.php 2005-06-10 09:00:01 UTC (rev 2187)
+++ plugins/trunk/moblogbatch.php 2005-06-10 09:43:48 UTC (rev 2188)
@@ -0,0 +1,65 @@
+<?php
+
+ // define the entry point
+ if (!defined( "PLOG_CLASS_PATH" )) {
+ define( "PLOG_CLASS_PATH", dirname(__FILE__)."/");
+ }
+
+ // bring in some code that we need
+ include_once( PLOG_CLASS_PATH."plugins/moblog/class/PEAR/Net/POP3.php" );
+ include_once( PLOG_CLASS_PATH."plugins/moblog/class/PEAR/HTTP/Request.php");
+ include_once( PLOG_CLASS_PATH."class/net/baserequestgenerator.class.php" );
+ include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
+
+ $config =& Config::getConfig();
+
+ $mailServer = $config->getValue('plugin_moblog_mailserver');
+ $port = $config->getValue('plugin_moblog_port');
+ $userName = $config->getValue('plugin_moblog_username');
+ $password = $config->getValue('plugin_moblog_password');
+
+ // pop3 connection and log-in
+ $pop3 =& new Net_POP3();
+
+ if(PEAR::isError( $ret= $pop3->connect($mailServer , $port ) )) {
+ echo "ERROR: " . $ret->getMessage() . "\n";
+ exit();
+ }
+
+ if(PEAR::isError( $ret= $pop3->login($userName , $password, 'USER' ) )){
+ echo "ERROR: " . $ret->getMessage() . "\n";
+ exit();
+ }
+
+ $messageNumber = $pop3->numMsg();
+
+ if ($messageNumber == 0) {
+ $pop3->disconnect();
+ die();
+ } else {
+ // get message list
+ $messageList = $pop3->getListing();
+ $messages = Array();
+
+ for ($cnt = 0; $cnt < count($messageList); $cnt++) {
+ $messages[$cnt] = $pop3->getMsg($messageList[$cnt]['msg_id']);
+ $pop3->deleteMsg($messageList[$cnt]['msg_id']);
+ }
+
+ // pop3 disconnect
+ $pop3->disconnect();
+
+ $config->setValue( "plugin_moblog_lastupdate", time() );
+ $config->save();
+
+ $url = &new BaseRequestGenerator();
+
+ for ($cnt = 0; $cnt < count($messages); $cnt++) {
+ $req = &new HTTP_Request($url->getBaseUrl(false)."/moblog.php");
+ $req->setMethod(HTTP_REQUEST_METHOD_POST);
+ $req->addPostData('message', $messages[$cnt]);
+ $req->sendRequest();
+ $response = $req->getResponseBody();
+ }
+ }
+?>
\ No newline at end of file
More information about the pLog-svn
mailing list