[pLog-svn] r1970 - in plugins/trunk: . moblog moblog/class
moblog/class/action moblog/class/log moblog/class/moblog
moblog/class/view moblog/locale moblog/templates
oscar at devel.plogworld.net
oscar at devel.plogworld.net
Sun May 8 21:42:01 GMT 2005
Author: oscar
Date: 2005-05-08 21:42:00 +0000 (Sun, 08 May 2005)
New Revision: 1970
Added:
plugins/trunk/moblog.php
plugins/trunk/moblog/
plugins/trunk/moblog/class/
plugins/trunk/moblog/class/action/
plugins/trunk/moblog/class/action/adminmoblogpluginsettingsaction.class.php
plugins/trunk/moblog/class/action/adminmoblogpluginupdatesettingsaction.class.php
plugins/trunk/moblog/class/log/
plugins/trunk/moblog/class/log/mobloglogger.class.php
plugins/trunk/moblog/class/moblog/
plugins/trunk/moblog/class/moblog/mimeDecode.class.php
plugins/trunk/moblog/class/moblog/moblogconstants.properties.php
plugins/trunk/moblog/class/moblog/moblogrequest.class.php
plugins/trunk/moblog/class/moblog/moblogresponse.class.php
plugins/trunk/moblog/class/view/
plugins/trunk/moblog/class/view/adminmoblogpluginsettingsview.class.php
plugins/trunk/moblog/locale/
plugins/trunk/moblog/locale/locale_en_UK.php
plugins/trunk/moblog/pluginmoblog.class.php
plugins/trunk/moblog/templates/
plugins/trunk/moblog/templates/pluginsettings.template
Log:
due to popular demand, this is the first working version of the 'moblog' plugin that allows for blogging via email. Let's see if I can get it working with all email clients, but so far it works great with Apple's Mail.app. I will set up a mail gateway in devel.plogworld.net for help in the testings.
Added: plugins/trunk/moblog/class/action/adminmoblogpluginsettingsaction.class.php
===================================================================
--- plugins/trunk/moblog/class/action/adminmoblogpluginsettingsaction.class.php 2005-05-08 17:07:07 UTC (rev 1969)
+++ plugins/trunk/moblog/class/action/adminmoblogpluginsettingsaction.class.php 2005-05-08 21:42:00 UTC (rev 1970)
@@ -0,0 +1,24 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/action/admin/blogowneradminaction.class.php" );
+ include_once( PLOG_CLASS_PATH."plugins/moblog/class/view/adminmoblogpluginsettingsview.class.php" );
+
+ /**
+ * doesn't do almost anything :))
+ */
+ class AdminMoblogPluginSettingsAction extends BlogOwnerAdminAction
+ {
+ function AdminMoblogPluginSettingsAction( $actionInfo, $request )
+ {
+ $this->BlogOwnerAdminAction( $actionInfo, $request );
+ }
+
+ function perform()
+ {
+ $this->_view = new AdminMoblogPluginSettingsView( $this->_blogInfo, $this->_userInfo );
+ $this->setCommonData();
+
+ return true;
+ }
+ }
+?>
\ No newline at end of file
Added: plugins/trunk/moblog/class/action/adminmoblogpluginupdatesettingsaction.class.php
===================================================================
--- plugins/trunk/moblog/class/action/adminmoblogpluginupdatesettingsaction.class.php 2005-05-08 17:07:07 UTC (rev 1969)
+++ plugins/trunk/moblog/class/action/adminmoblogpluginupdatesettingsaction.class.php 2005-05-08 21:42:00 UTC (rev 1970)
@@ -0,0 +1,56 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/action/admin/blogowneradminaction.class.php" );
+ include_once( PLOG_CLASS_PATH."plugins/moblog/class/view/adminmoblogpluginsettingsview.class.php" );
+ include_once( PLOG_CLASS_PATH."plugins/moblog/class/moblog/moblogconstants.properties.php" );
+
+ class AdminMoblogPluginUpdateSettingsAction extends BlogOwnerAdminAction
+ {
+
+ var $_pluginEnabled;
+
+ function AdminMoblogPluginUpdateSettingsAction( $actionInfo, $request )
+ {
+ $this->BlogOwnerAdminAction( $actionInfo, $request );
+ }
+
+ function validate()
+ {
+ $this->_pluginEnabled = $this->_request->getValue( "pluginEnabled" );
+ $this->_categoryId = $this->_request->getValue( "categoryId" );
+ $this->_albumId = $this->_request->getValue( "albumId" );
+ $this->_password = $this->_request->getValue( "password" );
+ // check how images should be embedded
+ $this->_previewType = $this->_request->getValue( "resourcePreviewType" );
+ if( $this->_previewType < MOBLOG_EMBED_SMALL_PREVIEW ||
+ $this->_previewType > MOBLOG_EMBED_FULL_SIZE )
+ $this->_previewType = MOBLOG_EMBED_SMALL_PREVIEW;
+
+ return true;
+ }
+
+ function perform()
+ {
+ // save the settings
+ $blogSettings = $this->_blogInfo->getSettings();
+ $blogSettings->setValue( "plugin_moblog_article_category_id", $this->_categoryId );
+ $blogSettings->setValue( "plugin_moblog_gallery_resource_album_id", $this->_albumId );
+ $blogSettings->setValue( "plugin_moblog_resource_preview_type", $this->_previewType );
+ $blogSettings->setValue( "plugin_moblog_enabled", $this->_pluginEnabled );
+ // update the settings in the database *and* in the session, otherwise we will
+ // keep using the old settings!!
+ $blogs = new Blogs();
+ $this->_blogInfo->setSettings( $blogSettings );
+ $blogs->updateBlogSettings( $this->_blogInfo->getId(), $this->_blogInfo->getSettings());
+ $this->_session->setValue( "blogInfo", $this->_blogInfo );
+ $this->saveSession();
+
+ // show an informative message
+ $this->_view = new AdminMoblogPluginSettingsView( $this->_blogInfo, $this->_userInfo );
+ $this->_view->setSuccessMessage( $this->_locale->tr("atom_plugin_settings_saved_ok"));
+ $this->setCommonData();
+
+ return true;
+ }
+ }
+?>
\ No newline at end of file
Added: plugins/trunk/moblog/class/log/mobloglogger.class.php
===================================================================
--- plugins/trunk/moblog/class/log/mobloglogger.class.php 2005-05-08 17:07:07 UTC (rev 1969)
+++ plugins/trunk/moblog/class/log/mobloglogger.class.php 2005-05-08 21:42:00 UTC (rev 1970)
@@ -0,0 +1,25 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/object/object.class.php" );
+ include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
+
+ /**
+ * simple class that logs a message to the standard log file, but only if enabled
+ *
+ * @see LoggerManager
+ */
+ class MoblogLogger extends Object
+ {
+ /**
+ * logs a simple message to the log file, using the "debug" priority
+ */
+ function Log( $message )
+ {
+ $config =& Config::getConfig();
+ if( $config->getValue( "moblog_logging_enabled" )) {
+ $logger =& LoggerManager::getLogger();
+ $logger->debug( $message );
+ }
+ }
+ }
+?>
\ No newline at end of file
Added: plugins/trunk/moblog/class/moblog/mimeDecode.class.php
===================================================================
--- plugins/trunk/moblog/class/moblog/mimeDecode.class.php 2005-05-08 17:07:07 UTC (rev 1969)
+++ plugins/trunk/moblog/class/moblog/mimeDecode.class.php 2005-05-08 21:42:00 UTC (rev 1970)
@@ -0,0 +1,808 @@
+<?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> |
+// +-----------------------------------------------------------------------+
+
+//require_once 'PEAR.php';
+
+/**
+* +----------------------------- IMPORTANT ------------------------------+
+* | Usage of this class compared to native php extensions such as |
+* | mailparse or imap, is slow and may be feature deficient. If available|
+* | you are STRONGLY recommended to use the php extensions. |
+* +----------------------------------------------------------------------+
+*
+* Mime Decoding class
+*
+* This class will parse a raw mime email and return
+* the structure. Returned structure is similar to
+* that returned by imap_fetchstructure().
+*
+* USAGE: (assume $input is your raw email)
+*
+* $decode = new Mail_mimeDecode($input, "\r\n");
+* $structure = $decode->decode();
+* print_r($structure);
+*
+* Or statically:
+*
+* $params['input'] = $input;
+* $structure = Mail_mimeDecode::decode($params);
+* print_r($structure);
+*
+* TODO:
+* - Implement further content types, eg. multipart/parallel,
+* perhaps even message/partial.
+*
+* @author Richard Heyes <richard at phpguru.org>
+* @version $Revision: 1.3 $
+* @package Mail
+*/
+
+class Mail_mimeDecode
+{
+
+ /**
+ * The raw email to decode
+ * @var string
+ */
+ var $_input;
+
+ /**
+ * The header part of the input
+ * @var string
+ */
+ var $_header;
+
+ /**
+ * The body part of the input
+ * @var string
+ */
+ var $_body;
+
+ /**
+ * If an error occurs, this is used to store the message
+ * @var string
+ */
+ var $_error;
+
+ /**
+ * Flag to determine whether to include bodies in the
+ * returned object.
+ * @var boolean
+ */
+ var $_include_bodies;
+
+ /**
+ * Flag to determine whether to decode bodies
+ * @var boolean
+ */
+ var $_decode_bodies;
+
+ /**
+ * Flag to determine whether to decode headers
+ * @var boolean
+ */
+ var $_decode_headers;
+
+ /**
+ * If invoked from a class, $this will be set. This has problematic
+ * connotations for calling decode() statically. Hence this variable
+ * is used to determine if we are indeed being called statically or
+ * via an object.
+ */
+ var $mailMimeDecode;
+
+ /**
+ * Constructor.
+ *
+ * Sets up the object, initialise the variables, and splits and
+ * stores the header and body of the input.
+ *
+ * @param string The input to decode
+ * @access public
+ */
+ function Mail_mimeDecode($input)
+ {
+ list($header, $body) = $this->_splitBodyHeader($input);
+
+ $this->_input = $input;
+ $this->_header = $header;
+ $this->_body = $body;
+ $this->_decode_bodies = false;
+ $this->_include_bodies = true;
+
+ $this->mailMimeDecode = true;
+ }
+
+ /**
+ * Begins the decoding process. If called statically
+ * it will create an object and call the decode() method
+ * of it.
+ *
+ * @param array An array of various parameters that determine
+ * various things:
+ * include_bodies - Whether to include the body in the returned
+ * object.
+ * decode_bodies - Whether to decode the bodies
+ * of the parts. (Transfer encoding)
+ * decode_headers - Whether to decode headers
+ * input - If called statically, this will be treated
+ * as the input
+ * @return object Decoded results
+ * @access public
+ */
+ function decode($params = null)
+ {
+
+ // Have we been called statically? If so, create an object and pass details to that.
+ if (!isset($this->mailMimeDecode) AND isset($params['input'])) {
+
+ $obj = new Mail_mimeDecode($params['input']);
+ $structure = $obj->decode($params);
+
+ // Called statically but no input
+ } elseif (!isset($this->mailMimeDecode)) {
+ //return PEAR::raiseError('Called statically and no input given');
+ return false;
+
+ // Called via an object
+ } else {
+ $this->_include_bodies = isset($params['include_bodies']) ? $params['include_bodies'] : false;
+ $this->_decode_bodies = isset($params['decode_bodies']) ? $params['decode_bodies'] : false;
+ $this->_decode_headers = isset($params['decode_headers']) ? $params['decode_headers'] : false;
+
+ $structure = $this->_decode($this->_header, $this->_body);
+ if ($structure === false) {
+ $structure = $this->raiseError($this->_error);
+ }
+ }
+
+ return $structure;
+ }
+
+ /**
+ * Performs the decoding. Decodes the body string passed to it
+ * If it finds certain content-types it will call itself in a
+ * recursive fashion
+ *
+ * @param string Header section
+ * @param string Body section
+ * @return object Results of decoding process
+ * @access private
+ */
+ function _decode($headers, $body, $default_ctype = 'text/plain')
+ {
+ $return = new stdClass;
+ $headers = $this->_parseHeaders($headers);
+
+ foreach ($headers as $value) {
+ if (isset($return->headers[strtolower($value['name'])]) AND !is_array($return->headers[strtolower($value['name'])])) {
+ $return->headers[strtolower($value['name'])] = array($return->headers[strtolower($value['name'])]);
+ $return->headers[strtolower($value['name'])][] = $value['value'];
+
+ } elseif (isset($return->headers[strtolower($value['name'])])) {
+ $return->headers[strtolower($value['name'])][] = $value['value'];
+
+ } else {
+ $return->headers[strtolower($value['name'])] = $value['value'];
+ }
+ }
+
+ reset($headers);
+ while (list($key, $value) = each($headers)) {
+ $headers[$key]['name'] = strtolower($headers[$key]['name']);
+ switch ($headers[$key]['name']) {
+
+ case 'content-type':
+ $content_type = $this->_parseHeaderValue($headers[$key]['value']);
+
+ if (preg_match('/([0-9a-z+.-]+)\/([0-9a-z+.-]+)/i', $content_type['value'], $regs)) {
+ $return->ctype_primary = $regs[1];
+ $return->ctype_secondary = $regs[2];
+ }
+
+ if (isset($content_type['other'])) {
+ while (list($p_name, $p_value) = each($content_type['other'])) {
+ $return->ctype_parameters[$p_name] = $p_value;
+ }
+ }
+ break;
+
+ case 'content-disposition';
+ $content_disposition = $this->_parseHeaderValue($headers[$key]['value']);
+ $return->disposition = $content_disposition['value'];
+ if (isset($content_disposition['other'])) {
+ while (list($p_name, $p_value) = each($content_disposition['other'])) {
+ $return->d_parameters[$p_name] = $p_value;
+ }
+ }
+ break;
+
+ case 'content-transfer-encoding':
+ $content_transfer_encoding = $this->_parseHeaderValue($headers[$key]['value']);
+ break;
+ }
+ }
+
+ if (isset($content_type)) {
+ switch (strtolower($content_type['value'])) {
+ case 'text/plain':
+ $encoding = isset($content_transfer_encoding) ? $content_transfer_encoding['value'] : '7bit';
+ $this->_include_bodies ? $return->body = ($this->_decode_bodies ? $this->_decodeBody($body, $encoding) : $body) : null;
+ break;
+
+ case 'text/html':
+ $encoding = isset($content_transfer_encoding) ? $content_transfer_encoding['value'] : '7bit';
+ $this->_include_bodies ? $return->body = ($this->_decode_bodies ? $this->_decodeBody($body, $encoding) : $body) : null;
+ break;
+
+ case 'multipart/parallel':
+ case 'multipart/report': // RFC1892
+ case 'multipart/signed': // PGP
+ case 'multipart/digest':
+ case 'multipart/alternative':
+ case 'multipart/related':
+ case 'multipart/mixed':
+ if(!isset($content_type['other']['boundary'])){
+ $this->_error = 'No boundary found for ' . $content_type['value'] . ' part';
+ return false;
+ }
+
+ $default_ctype = (strtolower($content_type['value']) === 'multipart/digest') ? 'message/rfc822' : 'text/plain';
+
+ $parts = $this->_boundarySplit($body, $content_type['other']['boundary']);
+ for ($i = 0; $i < count($parts); $i++) {
+ list($part_header, $part_body) = $this->_splitBodyHeader($parts[$i]);
+ $part = $this->_decode($part_header, $part_body, $default_ctype);
+ if($part === false)
+ $part = $this->raiseError($this->_error);
+ $return->parts[] = $part;
+ }
+ break;
+
+ case 'message/rfc822':
+ $obj = &new Mail_mimeDecode($body);
+ $return->parts[] = $obj->decode(array('include_bodies' => $this->_include_bodies));
+ unset($obj);
+ break;
+
+ default:
+ if(!isset($content_transfer_encoding['value']))
+ $content_transfer_encoding['value'] = '7bit';
+ $this->_include_bodies ? $return->body = ($this->_decode_bodies ? $this->_decodeBody($body, $content_transfer_encoding['value']) : $body) : null;
+ break;
+ }
+
+ } else {
+ $ctype = explode('/', $default_ctype);
+ $return->ctype_primary = $ctype[0];
+ $return->ctype_secondary = $ctype[1];
+ $this->_include_bodies ? $return->body = ($this->_decode_bodies ? $this->_decodeBody($body) : $body) : null;
+ }
+
+ return $return;
+ }
+
+ /**
+ * Given the output of the above function, this will return an
+ * array of references to the parts, indexed by mime number.
+ *
+ * @param object $structure The structure to go through
+ * @param string $mime_number Internal use only.
+ * @return array Mime numbers
+ */
+ function &getMimeNumbers(&$structure, $no_refs = false, $mime_number = '', $prepend = '')
+ {
+ $return = array();
+ if (!empty($structure->parts)) {
+ if ($mime_number != '') {
+ $structure->mime_id = $prepend . $mime_number;
+ $return[$prepend . $mime_number] = &$structure;
+ }
+ for ($i = 0; $i < count($structure->parts); $i++) {
+
+
+ if (!empty($structure->headers['content-type']) AND substr(strtolower($structure->headers['content-type']), 0, 8) == 'message/') {
+ $prepend = $prepend . $mime_number . '.';
+ $_mime_number = '';
+ } else {
+ $_mime_number = ($mime_number == '' ? $i + 1 : sprintf('%s.%s', $mime_number, $i + 1));
+ }
+
+ $arr = &Mail_mimeDecode::getMimeNumbers($structure->parts[$i], $no_refs, $_mime_number, $prepend);
+ foreach ($arr as $key => $val) {
+ $no_refs ? $return[$key] = '' : $return[$key] = &$arr[$key];
+ }
+ }
+ } else {
+ if ($mime_number == '') {
+ $mime_number = '1';
+ }
+ $structure->mime_id = $prepend . $mime_number;
+ $no_refs ? $return[$prepend . $mime_number] = '' : $return[$prepend . $mime_number] = &$structure;
+ }
+
+ return $return;
+ }
+
+ /**
+ * Given a string containing a header and body
+ * section, this function will split them (at the first
+ * blank line) and return them.
+ *
+ * @param string Input to split apart
+ * @return array Contains header and body section
+ * @access private
+ */
+ function _splitBodyHeader($input)
+ {
+ if (preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $input, $match)) {
+ return array($match[1], $match[2]);
+ }
+ $this->_error = 'Could not split header and body';
+ return false;
+ }
+
+ /**
+ * Parse headers given in $input and return
+ * as assoc array.
+ *
+ * @param string Headers to parse
+ * @return array Contains parsed headers
+ * @access private
+ */
+ function _parseHeaders($input)
+ {
+
+ if ($input !== '') {
+ // Unfold the input
+ $input = preg_replace("/\r?\n/", "\r\n", $input);
+ $input = preg_replace("/\r\n(\t| )+/", ' ', $input);
+ $headers = explode("\r\n", trim($input));
+
+ foreach ($headers as $value) {
+ $hdr_name = substr($value, 0, $pos = strpos($value, ':'));
+ $hdr_value = substr($value, $pos+1);
+ if($hdr_value[0] == ' ')
+ $hdr_value = substr($hdr_value, 1);
+
+ $return[] = array(
+ 'name' => $hdr_name,
+ 'value' => $this->_decode_headers ? $this->_decodeHeader($hdr_value) : $hdr_value
+ );
+ }
+ } else {
+ $return = array();
+ }
+
+ return $return;
+ }
+
+ /**
+ * Function to parse a header value,
+ * extract first part, and any secondary
+ * parts (after ;) This function is not as
+ * robust as it could be. Eg. header comments
+ * in the wrong place will probably break it.
+ *
+ * @param string Header value to parse
+ * @return array Contains parsed result
+ * @access private
+ */
+ function _parseHeaderValue($input)
+ {
+
+ if (($pos = strpos($input, ';')) !== false) {
+
+ $return['value'] = trim(substr($input, 0, $pos));
+ $input = trim(substr($input, $pos+1));
+
+ if (strlen($input) > 0) {
+
+ // This splits on a semi-colon, if there's no preceeding backslash
+ // Can't handle if it's in double quotes however. (Of course anyone
+ // sending that needs a good slap).
+ $parameters = preg_split('/\s*(?<!\\\\);\s*/i', $input);
+
+ for ($i = 0; $i < count($parameters); $i++) {
+ $param_name = substr($parameters[$i], 0, $pos = strpos($parameters[$i], '='));
+ $param_value = substr($parameters[$i], $pos + 1);
+ if ($param_value[0] == '"') {
+ $param_value = substr($param_value, 1, -1);
+ }
+ $return['other'][$param_name] = $param_value;
+ $return['other'][strtolower($param_name)] = $param_value;
+ }
+ }
+ } else {
+ $return['value'] = trim($input);
+ }
+
+ return $return;
+ }
+
+ /**
+ * This function splits the input based
+ * on the given boundary
+ *
+ * @param string Input to parse
+ * @return array Contains array of resulting mime parts
+ * @access private
+ */
+ function _boundarySplit($input, $boundary)
+ {
+ $tmp = explode('--'.$boundary, $input);
+
+ for ($i=1; $i<count($tmp)-1; $i++) {
+ $parts[] = $tmp[$i];
+ }
+
+ return $parts;
+ }
+
+ /**
+ * Given a header, this function will decode it
+ * according to RFC2047. Probably not *exactly*
+ * conformant, but it does pass all the given
+ * examples (in RFC2047).
+ *
+ * @param string Input header value to decode
+ * @return string Decoded header value
+ * @access private
+ */
+ function _decodeHeader($input)
+ {
+ // Remove white space between encoded-words
+ $input = preg_replace('/(=\?[^?]+\?(q|b)\?[^?]*\?=)(\s)+=\?/i', '\1=?', $input);
+
+ // For each encoded-word...
+ while (preg_match('/(=\?([^?]+)\?(q|b)\?([^?]*)\?=)/i', $input, $matches)) {
+
+ $encoded = $matches[1];
+ $charset = $matches[2];
+ $encoding = $matches[3];
+ $text = $matches[4];
+
+ switch (strtolower($encoding)) {
+ case 'b':
+ $text = base64_decode($text);
+ break;
+
+ case 'q':
+ $text = str_replace('_', ' ', $text);
+ preg_match_all('/=([a-f0-9]{2})/i', $text, $matches);
+ foreach($matches[1] as $value)
+ $text = str_replace('='.$value, chr(hexdec($value)), $text);
+ break;
+ }
+
+ $input = str_replace($encoded, $text, $input);
+ }
+
+ return $input;
+ }
+
+ /**
+ * Given a body string and an encoding type,
+ * this function will decode and return it.
+ *
+ * @param string Input body to decode
+ * @param string Encoding type to use.
+ * @return string Decoded body
+ * @access private
+ */
+ function _decodeBody($input, $encoding = '7bit')
+ {
+ switch ($encoding) {
+ case '7bit':
+ return $input;
+ break;
+
+ case 'quoted-printable':
+ return $this->_quotedPrintableDecode($input);
+ break;
+
+ case 'base64':
+ return base64_decode($input);
+ break;
+
+ default:
+ return $input;
+ }
+ }
+
+ /**
+ * Given a quoted-printable string, this
+ * function will decode and return it.
+ *
+ * @param string Input body to decode
+ * @return string Decoded body
+ * @access private
+ */
+ function _quotedPrintableDecode($input)
+ {
+ // Remove soft line breaks
+ $input = preg_replace("/=\r?\n/", '', $input);
+
+ // Replace encoded characters
+ $input = preg_replace('/=([a-f0-9]{2})/ie', "chr(hexdec('\\1'))", $input);
+
+ return $input;
+ }
+
+ /**
+ * Checks the input for uuencoded files and returns
+ * an array of them. Can be called statically, eg:
+ *
+ * $files =& Mail_mimeDecode::uudecode($some_text);
+ *
+ * It will check for the begin 666 ... end syntax
+ * however and won't just blindly decode whatever you
+ * pass it.
+ *
+ * @param string Input body to look for attahcments in
+ * @return array Decoded bodies, filenames and permissions
+ * @access public
+ * @author Unknown
+ */
+ function &uudecode($input)
+ {
+ // Find all uuencoded sections
+ preg_match_all("/begin ([0-7]{3}) (.+)\r?\n(.+)\r?\nend/Us", $input, $matches);
+
+ for ($j = 0; $j < count($matches[3]); $j++) {
+
+ $str = $matches[3][$j];
+ $filename = $matches[2][$j];
+ $fileperm = $matches[1][$j];
+
+ $file = '';
+ $str = preg_split("/\r?\n/", trim($str));
+ $strlen = count($str);
+
+ for ($i = 0; $i < $strlen; $i++) {
+ $pos = 1;
+ $d = 0;
+ $len=(int)(((ord(substr($str[$i],0,1)) -32) - ' ') & 077);
+
+ while (($d + 3 <= $len) AND ($pos + 4 <= strlen($str[$i]))) {
+ $c0 = (ord(substr($str[$i],$pos,1)) ^ 0x20);
+ $c1 = (ord(substr($str[$i],$pos+1,1)) ^ 0x20);
+ $c2 = (ord(substr($str[$i],$pos+2,1)) ^ 0x20);
+ $c3 = (ord(substr($str[$i],$pos+3,1)) ^ 0x20);
+ $file .= chr(((($c0 - ' ') & 077) << 2) | ((($c1 - ' ') & 077) >> 4));
+
+ $file .= chr(((($c1 - ' ') & 077) << 4) | ((($c2 - ' ') & 077) >> 2));
+
+ $file .= chr(((($c2 - ' ') & 077) << 6) | (($c3 - ' ') & 077));
+
+ $pos += 4;
+ $d += 3;
+ }
+
+ if (($d + 2 <= $len) && ($pos + 3 <= strlen($str[$i]))) {
+ $c0 = (ord(substr($str[$i],$pos,1)) ^ 0x20);
+ $c1 = (ord(substr($str[$i],$pos+1,1)) ^ 0x20);
+ $c2 = (ord(substr($str[$i],$pos+2,1)) ^ 0x20);
+ $file .= chr(((($c0 - ' ') & 077) << 2) | ((($c1 - ' ') & 077) >> 4));
+
+ $file .= chr(((($c1 - ' ') & 077) << 4) | ((($c2 - ' ') & 077) >> 2));
+
+ $pos += 3;
+ $d += 2;
+ }
+
+ if (($d + 1 <= $len) && ($pos + 2 <= strlen($str[$i]))) {
+ $c0 = (ord(substr($str[$i],$pos,1)) ^ 0x20);
+ $c1 = (ord(substr($str[$i],$pos+1,1)) ^ 0x20);
+ $file .= chr(((($c0 - ' ') & 077) << 2) | ((($c1 - ' ') & 077) >> 4));
+
+ }
+ }
+ $files[] = array('filename' => $filename, 'fileperm' => $fileperm, 'filedata' => $file);
+ }
+
+ return $files;
+ }
+
+ /**
+ * getSendArray() returns the arguments required for Mail::send()
+ * used to build the arguments for a mail::send() call
+ *
+ * Usage:
+ * $mailtext = Full email (for example generated by a template)
+ * $decoder = new Mail_mimeDecode($mailtext);
+ * $parts = $decoder->getSendArray();
+ * if (!PEAR::isError($parts) {
+ * list($recipents,$headers,$body) = $parts;
+ * $mail = Mail::factory('smtp');
+ * $mail->send($recipents,$headers,$body);
+ * } else {
+ * echo $parts->message;
+ * }
+ * @return mixed array of recipeint, headers,body or Pear_Error
+ * @access public
+ * @author Alan Knowles <alan at akbkhome.com>
+ */
+ function getSendArray()
+ {
+ // prevent warning if this is not set
+ $this->_decode_headers = FALSE;
+ $headerlist =$this->_parseHeaders($this->_header);
+ $to = "";
+ if (!$headerlist) {
+ return $this->raiseError("Message did not contain headers");
+ }
+ foreach($headerlist as $item) {
+ $header[$item['name']] = $item['value'];
+ switch (strtolower($item['name'])) {
+ case "to":
+ case "cc":
+ case "bcc":
+ $to = ",".$item['value'];
+ default:
+ break;
+ }
+ }
+ if ($to == "") {
+ return $this->raiseError("Message did not contain any recipents");
+ }
+ $to = substr($to,1);
+ return array($to,$header,$this->_body);
+ }
+
+
+
+
+
+
+
+
+
+ /**
+ * Returns a xml copy of the output of
+ * Mail_mimeDecode::decode. Pass the output in as the
+ * argument. This function can be called statically. Eg:
+ *
+ * $output = $obj->decode();
+ * $xml = Mail_mimeDecode::getXML($output);
+ *
+ * The DTD used for this should have been in the package. Or
+ * alternatively you can get it from cvs, or here:
+ * http://www.phpguru.org/xmail/xmail.dtd.
+ *
+ * @param object Input to convert to xml. This should be the
+ * output of the Mail_mimeDecode::decode function
+ * @return string XML version of input
+ * @access public
+ */
+ function getXML($input)
+ {
+ $crlf = "\r\n";
+ $output = '<?xml version=\'1.0\'?>' . $crlf .
+ '<!DOCTYPE email SYSTEM "http://www.phpguru.org/xmail/xmail.dtd">' . $crlf .
+ '<email>' . $crlf .
+ Mail_mimeDecode::_getXML($input) .
+ '</email>';
+
+ return $output;
+ }
+
+ /**
+ * Function that does the actual conversion to xml. Does a single
+ * mimepart at a time.
+ *
+ * @param object Input to convert to xml. This is a mimepart object.
+ * It may or may not contain subparts.
+ * @param integer Number of tabs to indent
+ * @return string XML version of input
+ * @access private
+ */
+ function _getXML($input, $indent = 1)
+ {
+ $htab = "\t";
+ $crlf = "\r\n";
+ $output = '';
+ $headers = @(array)$input->headers;
+
+ foreach ($headers as $hdr_name => $hdr_value) {
+
+ // Multiple headers with this name
+ if (is_array($headers[$hdr_name])) {
+ for ($i = 0; $i < count($hdr_value); $i++) {
+ $output .= Mail_mimeDecode::_getXML_helper($hdr_name, $hdr_value[$i], $indent);
+ }
+
+ // Only one header of this sort
+ } else {
+ $output .= Mail_mimeDecode::_getXML_helper($hdr_name, $hdr_value, $indent);
+ }
+ }
+
+ if (!empty($input->parts)) {
+ for ($i = 0; $i < count($input->parts); $i++) {
+ $output .= $crlf . str_repeat($htab, $indent) . '<mimepart>' . $crlf .
+ Mail_mimeDecode::_getXML($input->parts[$i], $indent+1) .
+ str_repeat($htab, $indent) . '</mimepart>' . $crlf;
+ }
+ } elseif (isset($input->body)) {
+ $output .= $crlf . str_repeat($htab, $indent) . '<body><![CDATA[' .
+ $input->body . ']]></body>' . $crlf;
+ }
+
+ return $output;
+ }
+
+ /**
+ * Helper function to _getXML(). Returns xml of a header.
+ *
+ * @param string Name of header
+ * @param string Value of header
+ * @param integer Number of tabs to indent
+ * @return string XML version of input
+ * @access private
+ */
+ function _getXML_helper($hdr_name, $hdr_value, $indent)
+ {
+ $htab = "\t";
+ $crlf = "\r\n";
+ $return = '';
+
+ $new_hdr_value = ($hdr_name != 'received') ? Mail_mimeDecode::_parseHeaderValue($hdr_value) : array('value' => $hdr_value);
+ $new_hdr_name = str_replace(' ', '-', ucwords(str_replace('-', ' ', $hdr_name)));
+
+ // Sort out any parameters
+ if (!empty($new_hdr_value['other'])) {
+ foreach ($new_hdr_value['other'] as $paramname => $paramvalue) {
+ $params[] = str_repeat($htab, $indent) . $htab . '<parameter>' . $crlf .
+ str_repeat($htab, $indent) . $htab . $htab . '<paramname>' . htmlspecialchars($paramname) . '</paramname>' . $crlf .
+ str_repeat($htab, $indent) . $htab . $htab . '<paramvalue>' . htmlspecialchars($paramvalue) . '</paramvalue>' . $crlf .
+ str_repeat($htab, $indent) . $htab . '</parameter>' . $crlf;
+ }
+
+ $params = implode('', $params);
+ } else {
+ $params = '';
+ }
+
+ $return = str_repeat($htab, $indent) . '<header>' . $crlf .
+ str_repeat($htab, $indent) . $htab . '<headername>' . htmlspecialchars($new_hdr_name) . '</headername>' . $crlf .
+ str_repeat($htab, $indent) . $htab . '<headervalue>' . htmlspecialchars($new_hdr_value['value']) . '</headervalue>' . $crlf .
+ $params .
+ str_repeat($htab, $indent) . '</header>' . $crlf;
+
+ return $return;
+ }
+
+} // End of class
+?>
Added: plugins/trunk/moblog/class/moblog/moblogconstants.properties.php
===================================================================
--- plugins/trunk/moblog/class/moblog/moblogconstants.properties.php 2005-05-08 17:07:07 UTC (rev 1969)
+++ plugins/trunk/moblog/class/moblog/moblogconstants.properties.php 2005-05-08 21:42:00 UTC (rev 1970)
@@ -0,0 +1,6 @@
+<?php
+
+ define( 'MOBLOG_EMBED_SMALL_PREVIEW', 1 );
+ define( 'MOBLOG_EMBED_MEDIUM_PREVIEW', 2 );
+ define( 'MOBLOG_EMBED_FULL_SIZE', 3 );
+?>
\ No newline at end of file
Added: plugins/trunk/moblog/class/moblog/moblogrequest.class.php
===================================================================
--- plugins/trunk/moblog/class/moblog/moblogrequest.class.php 2005-05-08 17:07:07 UTC (rev 1969)
+++ plugins/trunk/moblog/class/moblog/moblogrequest.class.php 2005-05-08 21:42:00 UTC (rev 1970)
@@ -0,0 +1,252 @@
+<?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( $message )
+ {
+ $this->Object();
+
+ $this->_message = $message;
+
+ // parse the mime message
+ $decode = new Mail_mimeDecode( $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
+ if (isset($structure->headers['x-loop'])) {
+ $this->_replyAddress = "";
+ }
+ else {
+ $replyTo1 = $structure->headers['from'];
+ $replyTo2 = $structure->headers['return-path'];
+ $this->_replyAddress = ($replyTo2 != "") ? $replyTo2 : $replyTo1;
+ }
+
+ $this->_topic = $structure->headers['subject'];
+ MoblogLogger::Log("subject is = ".$this->_topic );
+
+ $this->parseBody( $structure->body );
+ MoblogLogger::log( "There are ".count($structure->parts)." MIME parts available to parse" );
+ $this->parseMimeParts( $structure->parts );
+ }
+
+ /**
+ * 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>");
+
+ //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]);
+ }
+
+ //We repeat the same trick as above... for all vars wanted
+ if (preg_match("/^host:(.*)/mi", $body, $host)) {
+ $this->_host = trim($host[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 also allow people to write 'cat' instead of 'category' if they want to...
+ /*if (preg_match("/^cat:(.*)/mi", $body, $cat)) {
+ $this->_category = trim($cat[1]);
+ } else if (preg_match("/^category:(.*)/mi", $body, $category)) {
+ $this->_category = trim($category[1]);
+ }*/
+
+ // maybe the user is requesting help...
+ /*if (preg_match("/^help:(.*)/mi", $body, $help)) {
+ $this->_help = trim($help[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 = Textfilter::autoP($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 );
+ }
+ else {
+ // whatever comes as a part, we will take it and treat it as if it was
+ // a normal resource
+
+ // 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"]);
+ $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 );
+ }
+ }
+ }
+
+ 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 getCategory()
+ {
+ return $this->_category;
+ }
+
+ function getBody()
+ {
+ return $this->_body;
+ }
+
+ function getReplyTo()
+ {
+ return $this->_replyAddress;
+ }
+
+ function getHost()
+ {
+ return $this->_host;
+ }
+
+ function getAttachments()
+ {
+ return $this->_attachments;
+ }
+
+ function isHelpRequest()
+ {
+ return( $this->_user == "" && $this->_pass == "" );
+ }
+ }
+?>
\ No newline at end of file
Added: plugins/trunk/moblog/class/moblog/moblogresponse.class.php
===================================================================
--- plugins/trunk/moblog/class/moblog/moblogresponse.class.php 2005-05-08 17:07:07 UTC (rev 1969)
+++ plugins/trunk/moblog/class/moblog/moblogresponse.class.php 2005-05-08 21:42:00 UTC (rev 1970)
@@ -0,0 +1,61 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/object/object.class.php" );
+ include_once( PLOG_CLASS_PATH."plugins/moblog/class/log/mobloglogger.class.php" );
+ include_once( PLOG_CLASS_PATH."class/mail/emailmessage.class.php" );
+ include_once( PLOG_CLASS_PATH."class/mail/emailservice.class.php" );
+
+ /**
+ * this is the response that we will send back to the user
+ *
+ * It uses pLog's messaging service to send the email, so we will
+ * use the same settings as used by the core itself to send
+ * messages.
+ */
+ class MoblogResponse extends Object
+ {
+
+ var $_message;
+
+ function MoblogResponse( $to = null, $subject = null, $text = null )
+ {
+ $this->Object();
+
+ $this->_message = new EmailMessage();
+
+ if( $to != null )
+ $this->setTo( $to );
+
+ if( $subject != null )
+ $this->setSubject( $subject );
+
+ if( $text != null )
+ $this->setText( $text );
+ }
+
+ function setTo( $address )
+ {
+ $this->_message->addTo( $address );
+ }
+
+ function setSubject( $subject )
+ {
+ $this->_message->setSubject( $subject );
+ }
+
+ function setText( $text )
+ {
+ $this->_message->setBody( $text );
+ }
+
+ function send()
+ {
+ $emailService = new EmailService();
+ $result = $emailService->sendMessage( $this->_message );
+
+ MoblogLogger::log( "Response message sent!" );
+
+ return $result;
+ }
+ }
+?>
\ No newline at end of file
Added: plugins/trunk/moblog/class/view/adminmoblogpluginsettingsview.class.php
===================================================================
--- plugins/trunk/moblog/class/view/adminmoblogpluginsettingsview.class.php 2005-05-08 17:07:07 UTC (rev 1969)
+++ plugins/trunk/moblog/class/view/adminmoblogpluginsettingsview.class.php 2005-05-08 21:42:00 UTC (rev 1970)
@@ -0,0 +1,49 @@
+<?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 AdminMoblogPluginSettingsView extends AdminPluginTemplatedView
+ {
+
+ var $_userInfo;
+
+ function AdminMoblogPluginSettingsView( $blogInfo, $userInfo )
+ {
+ $this->AdminPluginTemplatedView( $blogInfo, "moblog", "pluginsettings" );
+
+ $this->_userInfo = $userInfo;
+ }
+
+ function render()
+ {
+ // fetch the current settings
+ $blogSettings = $this->_blogInfo->getSettings();
+ $pluginEnabled = $blogSettings->getValue( "plugin_moblog_enabled" );
+ $categoryId = $blogSettings->getValue( "plugin_moblog_article_category_id" );
+ $albumId = $blogSettings->getValue( "plugin_moblog_gallery_resource_album_id" );
+ $resourcePreviewType = $blogSettings->getValue( "plugin_moblog_resource_preview_type" );
+
+ // fetch all the current article categories
+ $categories = new ArticleCategories();
+ $blogCategories = $categories->getBlogCategories( $this->_blogInfo->getId());
+ // fetch all the current gallery albums
+ $albums = new GalleryAlbums();
+ $blogAlbums = $albums->getUserAlbums( $this->_blogInfo->getId());
+
+ // finally pass all these things to the templates
+ $this->setValue( "pluginEnabled", $pluginEnabled );
+ $this->setValue( "categoryId", $categoryId );
+ $this->setValue( "albumId", $albumId );
+ $this->setValue( "albums", $blogAlbums );
+ $this->setValue( "categories", $blogCategories );
+ $this->setValue( "resourcePreviewType", $resourcePreviewType );
+
+ parent::render();
+ }
+ }
+?>
\ No newline at end of file
Added: plugins/trunk/moblog/locale/locale_en_UK.php
===================================================================
--- plugins/trunk/moblog/locale/locale_en_UK.php 2005-05-08 17:07:07 UTC (rev 1969)
+++ plugins/trunk/moblog/locale/locale_en_UK.php 2005-05-08 21:42:00 UTC (rev 1970)
@@ -0,0 +1,10 @@
+<?php
+
+$messages["moblogSettings"] = "Moblog Settings";
+$messages["enable_plugin"] = "Enable plugin";
+$messages["enable_moblog_plugin_help"] = "Enable the moblog plugin";
+$messages["moblog_articles_help"] = "In which category would you like articles posted via Atom to be categorized?";
+$messages["moblog_resources_help"] = "Uploading resources such as images and videos is also supported by this implementation. In which album would you like files to be classified?";
+$messages["moblog_image_preview_type_help"] = "When embedding images in moblogged posts, how should the image be embedded?'";
+
+?>
\ No newline at end of file
Added: plugins/trunk/moblog/pluginmoblog.class.php
===================================================================
--- plugins/trunk/moblog/pluginmoblog.class.php 2005-05-08 17:07:07 UTC (rev 1969)
+++ plugins/trunk/moblog/pluginmoblog.class.php 2005-05-08 21:42:00 UTC (rev 1970)
@@ -0,0 +1,52 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
+
+ /**
+ * implementation a plugin to give plog moblogging features (posting via email)
+ */
+ class PluginMoblog extends PluginBase
+ {
+
+ function PluginMoblog()
+ {
+ $this->id = "moblog";
+ $this->author = "The pLog Project";
+ $this->locales = Array();
+ $this->desc = "
+Send a message with the following format ('start' and 'end' messages not included!):<br/>
+<br/>
+--- start of moblog message format ---<br/>
+<br/>
+USER: your-plog-username<br/>
+PASS: your-plog-password<br/>
+BLOG: your-plog-blog-name<br/>
+<br/>
+--- end of moblog message format ---<br/>
+<br/>
+The must be sent as plain text, and it can include as many attachment as needed.";
+
+ $this->init();
+ }
+
+ /**
+ * set some actions and menu options
+ * @private
+ */
+ function init()
+ {
+ // register actions
+ $this->registerAdminAction( "moblogSettings", "AdminMoblogPluginSettingsAction" );
+ $this->registerAdminAction( "updateMoblogSettings", "AdminMoblogPluginUpdateSettingsAction" );
+
+ // register menu entries
+ $this->addMenuEntry( "/menu/controlCenter/manageSettings", // menu path
+ "moblogSettings", // menu id
+ "admin.php?op=moblogSettings", // url
+ "Moblog", // text to show
+ true, // can't...
+ false // ...remember :)
+ );
+ }
+ }
+?>
\ No newline at end of file
Added: plugins/trunk/moblog/templates/pluginsettings.template
===================================================================
--- plugins/trunk/moblog/templates/pluginsettings.template 2005-05-08 17:07:07 UTC (rev 1969)
+++ plugins/trunk/moblog/templates/pluginsettings.template 2005-05-08 21:42:00 UTC (rev 1970)
@@ -0,0 +1,53 @@
+{include file="$admintemplatepath/header.template"}
+{include file="$admintemplatepath/navigation.template" showOpt=moblogSettings title=$locale->tr("moblogSettings")}
+<form name="pluginAtomSettings" method="post" action="admin.php">
+ <fieldset class="inputField">
+ <legend>{$locale->tr("moblogSettings")}</legend>
+ {include file="$admintemplatepath/successmessage.template"}
+ {include file="$admintemplatepath/errormessage.template"}
+ <div class="field">
+ <label for="pluginEnabled">{$locale->tr("enable_plugin")}</label>
+ <div class="formHelp">
+ <input type="checkbox" name="pluginEnabled" value="1" type="checkbox" {if $pluginEnabled}checked="checked"{/if} />
+ {$locale->tr("enable_atom_plugin_help")}
+ </div>
+ </div>
+
+ <!-- article categories -->
+ <div class="field">
+ <label for="categoryId">{$locale->tr("posts")}</label>
+ <div class="formHelp">{$locale->tr("moblog_articles_help")}</div>
+ <select name="categoryId">
+ {foreach from=$categories item=category}
+ <option value="{$category->getId()}" {if $categoryId == $category->getId()}selected="selected"{/if}>{$category->getName()}</option>
+ {/foreach}
+ </select>
+ </div>
+
+ <!-- album categories -->
+ <div class="field">
+ <label for="albumId">{$locale->tr("resources")}</label>
+ <div class="formHelp">{$locale->tr("moblog_resources_help")}</div>
+ <select name="albumId">
+ {foreach from=$albums item=album}
+ <option value="{$album->getId()}" {if $albumId == $album->getId()}selected="selected"{/if}>{$album->getName()}</option>
+ {/foreach}
+ </select>
+ <br/>
+ <div class="formHelp">{$locale->tr("moblog_image_preview_type_help")}</div>
+ <select name="resourcePreviewType">
+ <option value="1" {if $resourcePreviewType==1}selected="selected"{/if}>{$locale->tr("small_preview")}</option>
+ <option value="2" {if $resourcePreviewType==2}selected="selected"{/if}>{$locale->tr("medium_preview")}</option>
+ <option value="3" {if $resourcePreviewType==3}selected="selected"{/if}>{$locale->tr("full_size")}</option>
+ </select>
+ </div>
+
+</fieldset>
+<div class="buttons">
+ <input type="hidden" name="op" value="updateMoblogSettings" />
+ <input type="reset" name="reset" value="{$locale->tr("reset")}" />
+ <input type="submit" name="submit" value="{$locale->tr("update")}" />
+</div>
+</form>
+{include file="$admintemplatepath/footernavigation.template"}
+{include file="$admintemplatepath/footer.template"}
\ No newline at end of file
Added: plugins/trunk/moblog.php
===================================================================
--- plugins/trunk/moblog.php 2005-05-08 17:07:07 UTC (rev 1969)
+++ plugins/trunk/moblog.php 2005-05-08 21:42:00 UTC (rev 1970)
@@ -0,0 +1,324 @@
+<?php
+
+ // define the entry point
+ if (!defined( "PLOG_CLASS_PATH" )) {
+ define( "PLOG_CLASS_PATH", dirname(__FILE__)."/");
+ }
+
+ //
+ // comment this out if you don't want this script to log
+ // its steps
+ //
+ define( "MOBLOG_DEBUG", true );
+
+ // bring in some code that we need
+ include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
+ include_once( PLOG_CLASS_PATH."class/file/file.class.php" );
+ include_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
+ include_once( PLOG_CLASS_PATH."class/net/http/httpvars.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+ include_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
+ include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
+ include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" );
+ include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" );
+ include_once( PLOG_CLASS_PATH."plugins/moblog/class/log/mobloglogger.class.php" );
+ include_once( PLOG_CLASS_PATH."plugins/moblog/class/moblog/moblogrequest.class.php" );
+ include_once( PLOG_CLASS_PATH."plugins/moblog/class/moblog/moblogresponse.class.php" );
+ include_once( PLOG_CLASS_PATH."plugins/moblog/class/moblog/moblogconstants.properties.php" );
+ include_once( PLOG_CLASS_PATH."class/template/cachecontrol.class.php" );
+
+//// help message sent to users requesting it ////
+ $helpMessage = <<< EOD
+pLog Moblog
+-----------
+Send a message with the following format ('start' and 'end' messages not included!):
+
+<<<<< start of moblog message format >>>>>
+
+USER: your-plog-username
+PASS: your-plog-password
+BLOG: your-plog-blog-name
+
+<<<<< end of moblog message format >>>>>
+
+The must be sent as plain text, and it can include as many attachment as needed.
+EOD;
+///////////////////////
+
+
+ // initialize the logging system
+ MoblogLogger::log( "-- Initialized");
+
+ // get the request
+ $request = HttpVars::getRequest();
+ $message = $request["message"];
+ if( $message == "" ) {
+ MoblogLogger::log( "There was no message!" );
+ die();
+ }
+
+ MoblogLogger::log("-- message --");
+ MoblogLogger::log($message);
+ MoblogLogger::log("-- end --");
+
+ // parse the message
+ $request = new MoblogRequest( $message );
+
+ // check if it's a help message
+ if( $request->isHelpRequest()) {
+ $response = new MoblogResponse( $request->getReplyTo(),
+ "pLog Moblog: Help",
+ $helpMessage );
+ $response->send();
+ die();
+ }
+
+ // let's see what we get...
+ MoblogLogger::log( "user = '".$request->getUser()."'");
+ // uncomment the following if you want to see passwords... :)
+ //MoblogLogger::log( "pass = ".$request->getPassword()."'");
+ MoblogLogger::log( "blog id = ".$request->getBlogId());
+ MoblogLogger::log( "topic = ".$request->getTopic());
+ MoblogLogger::log( "category = ".$request->getCategory());
+ MoblogLogger::log( "reply to = ".$request->getReplyTo());
+ MoblogLogger::log( "body = ".$request->getBody());
+
+ //
+ // start processing the message...
+ //
+
+ //
+ // first, try to authenticate the user
+ //
+ $users = new Users();
+ $userInfo = $users->getUserInfo( $request->getUser(), $request->getPassword());
+ if( !$userInfo ) {
+ $response = new MoblogResponse( $request->getReplyTo(),
+ "pLog Moblog: Error",
+ "User or password are not correct."
+ );
+ MoblogLogger::log( "User ".$request->getUser()." did not authenticate correctly." );
+ $response->send();
+ return false;
+ }
+
+ //
+ // if user was authenticated, then proceed... and the first thing we should do
+ // is see if the blog id is correct and if the user has permissions in that
+ // blog
+ //
+ $blogs = new Blogs();
+ if( $request->getBlogId() == "" ) {
+ // user gave a blog name instead of a blog id
+ $allBlogs = $blogs->getAllBlogs();
+ if( $allBlogs ) {
+ $found = false;
+ $blogName = stripslashes($request->getBlogName());
+ while( !$found && !empty($allBlogs)) {
+ $blogInfo = array_pop( $allBlogs );
+ if( strcasecmp($blogInfo->getBlog(), $blogName) == 0 ) {
+ $found = true;
+ MoblogLogger::log( "Blog '".$blogInfo->getBlog()."' found with id = '".$blogInfo->getId()."'");
+ }
+ }
+
+ if( !$found ) {
+ $response = new MoblogResponse( $request->getReplyTo(),
+ "pLog Moblog: Error",
+ "Incorrect blog."
+ );
+ MoblogLogger::log( "Blog ".$request->getBlogId()." does not exist." );
+ $response->send();
+ return false;
+ }
+ }
+ }
+ else {
+ $blogInfo = $blogs->getBlogInfo( $request->getBlogId());
+ if( !$blogInfo ) {
+ $response = new MoblogResponse( $request->getReplyTo(),
+ "pLog Moblog: Error",
+ "Incorrect blog identifier."
+ );
+ MoblogLogger::log( "Blog ".$request->getBlogId()." is not valid." );
+ $response->send();
+ return false;
+ }
+ }
+
+ //
+ // check if the plugin has been enabled for this blog
+ //
+ $blogSettings = $blogInfo->getSettings();
+ $pluginEnabled = $blogSettings->getValue( "plugin_moblog_enabled" );
+ if( !$pluginEnabled ) {
+ $response = new MoblogResponse( $request->getReplyTo(),
+ "pLog Moblog: Error",
+ "The plugin has not been enabled for this blog."
+ );
+ MoblogLogger::log( "Plugin not enabled for blog ".$request->getBlogId());
+ $response->send();
+ return false;
+ }
+
+ //
+ // now check if the user has permissions over the blog
+ //
+ $userPermissions = new UserPermissions();
+ $userPerm = $userPermissions->getUserPermissions( $userInfo->getId(), $blogInfo->getId());
+ if( !$userPerm ) {
+ $response = new MoblogResponse( $request->getReplyTo(),
+ "pLog Moblog: Error",
+ "You have no permissions in the given blog."
+ );
+ MoblogLogger::log( "User '".$request->getUser()."' has no permissions in blog ".$request->getBlogId());
+ $response->send();
+ return false;
+ }
+
+ //
+ // if everything's correct, then we can proceed to find if the category
+ // chosen by the user exists. Since there is no way to fetch a category by its name,
+ // we'll have to fetch them all and loop through them
+ //
+ $articleCategories = new ArticleCategories();
+ if( $request->getCategory()) {
+ $categories = $articleCategories->getBlogCategories( $blogInfo->getId());
+ $found = false;
+ while( !$found && !empty($categories)) {
+ $category = array_pop( $categories );
+ if( strcasecmp($category->getName(),$request->getCategory()) == 0 ) {
+ $found = true;
+ MoblogLogger::log( "Category '".$category->getName()."' found with id = '".$category->getId()."'");
+ }
+ }
+ }
+ else {
+ // load the category as defined in the plugin settings page
+ $categoryId = $blogSettings->getValue( "plugin_moblog_article_category_id" );
+ $category = $articleCategories->getCategory( $categoryId, $blogInfo->getId());
+ // check if the category was loaded just fine
+ $found = ( $category != null );
+ }
+
+ // if there was no such category, we should send an error and to make it more useful, send
+ // as part of the error message the list of available categories
+ if( !$found ) {
+ $response = new MoblogResponse( $request->getReplyTo(),
+ "pLog Moblog: Error",
+ "The category does not exist."
+ );
+ MoblogLogger::log( "User '".$request->getUser()."' tried to use category '".$request->getCategory().
+ "' which does not exist.");
+ $response->send();
+ }
+
+ //
+ // finally, add the resources to the database
+ //
+
+ // first, create a new album to hold these attachments
+ $albums = new GalleryAlbums();
+ $userAlbums = $albums->getUserAlbums( $blogInfo->getId());
+ $t = new Timestamp();
+ $albumId = $blogSettings->getValue( "plugin_moblog_gallery_resource_album_id" );
+ $album = $albums->getAlbum( $albumId, $blogInfo->getId());
+ $found = ( $album != null );
+
+ if( !$found ) {
+ $response = new MoblogResponse( $request->getReplyTo(),
+ "pLog Moblog: Error",
+ "The album does not exist."
+ );
+ MoblogLogger::log( "User '".$request->getUser()."' tried to use category '".$request->getCategory().
+ "' which does not exist.");
+ $response->send();
+ }
+ MoblogLogger::log( "Adding resources to album ".$album->getName());
+
+ $attachments = $request->getAttachments();
+ $res = new GalleryResources();
+ $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 );
+ MoblogLogger::log( " Completed: result = $result" );
+ if( $result ) {
+ // keep this for later
+ array_push( $resourceIds, $result );
+ }
+ }
+
+ //
+ // if everything went fine, we can now proceed and publish the post, finally!!!! :)
+ //
+
+ // before adding the article, we need to add some additional markup
+ // with links to the attachments that were sent
+ $rg = $blogInfo->getBlogRequestGenerator();
+ $postBody = $request->getBody()."<br/>";
+ foreach( $resourceIds as $resId ) {
+ $resource = $res->getResource( $resId );
+ $markup = "<a href=\"".$rg->resourceLink( $resource )."\">";
+ if( $resource->isImage()) {
+ $previewType = $blogSettings->getValue( "plugin_moblog_resource_preview_type" );
+ if( $previewType == MOBLOG_EMBED_MEDIUM_PREVIEW )
+ $link = $rg->resourceMediumSizePreviewLink( $resource );
+ elseif( $previewType == MOBLOG_EMBED_FULL_SIZE_VIEW )
+ $link = $rg->resourceDownloadLink( $resource );
+ else
+ $link = $rg->resourcePreviewLink( $resource );
+
+ $markup .= "<img src=\"$link\" alt=\"".$resource->getDescription()."\" />";
+ }
+ else {
+ $markup .= $resource->getDescription();
+ }
+ $markup .= "</a><br/>";
+ MoblogLogger::log( "Adding markup $markup" );
+ $postBody .= $markup;
+ $resNames .= $resource->getDescription()."\n";
+ }
+
+ // add the article
+ $articles = new Articles();
+ $article = new Article( $request->getTopic(),
+ $postBody,
+ Array( $category->getId()),
+ $userInfo->getId(),
+ $blogInfo->getId(),
+ POST_STATUS_PUBLISHED,
+ 0
+ );
+ $article->setDateObject( new Timestamp());
+ $article->setCommentsEnabled( true );
+ $result = $articles->addArticle( $article );
+
+ // reset the cache in case it is enabled
+ CacheControl::resetBlogCache( $blogInfo->getId());
+
+ if( !$result ) {
+ $response = new MoblogResponse( $request->getReplyTo(),
+ "pLog Moblog: Error",
+ "There was an error adding the post to the database."
+ );
+ MoblogLogger::log( "There was an error adding the post to the database.");
+ }
+ else {
+ $responseBody = "Post was successfully added to the database with topic '".$request->getTopic()."\n\n";
+ if( count($request->getAttachments()) > 0 ) {
+ $responseBody .= "The following attachments have been added:\n\n";
+ $responseBody .= $resNames;
+ }
+ $response = new MoblogResponse( $request->getReplyTo(), "pLog Moblog: Success", $responseBody );
+ MoblogLogger::log( "Post was successfully added to the database." );
+ }
+ $response->send();
+
+ // end of it...
+ MoblogLogger::log( "-- End");
+?>
More information about the pLog-svn
mailing list