You've already forked joomla_test
first commit
This commit is contained in:
153
components/com_mailto/controller.php
Normal file
153
components/com_mailto/controller.php
Normal file
@ -0,0 +1,153 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_mailto
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_mailto
|
||||
* @since 1.5
|
||||
*/
|
||||
class MailtoController extends JControllerLegacy
|
||||
{
|
||||
/**
|
||||
* Show the form so that the user can send the link to someone
|
||||
*
|
||||
* @access public
|
||||
* @since 1.5
|
||||
*/
|
||||
public function mailto()
|
||||
{
|
||||
$session = JFactory::getSession();
|
||||
$session->set('com_mailto.formtime', time());
|
||||
$this->input->set('view', 'mailto');
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the message and display a notice
|
||||
*
|
||||
* @access public
|
||||
* @since 1.5
|
||||
*/
|
||||
public function send()
|
||||
{
|
||||
// Check for request forgeries
|
||||
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
|
||||
|
||||
$app = JFactory::getApplication();
|
||||
$session = JFactory::getSession();
|
||||
|
||||
$timeout = $session->get('com_mailto.formtime', 0);
|
||||
if ($timeout == 0 || time() - $timeout < 20)
|
||||
{
|
||||
JError::raiseNotice(500, JText::_('COM_MAILTO_EMAIL_NOT_SENT'));
|
||||
return $this->mailto();
|
||||
}
|
||||
|
||||
$SiteName = $app->getCfg('sitename');
|
||||
|
||||
$link = MailtoHelper::validateHash($this->input->get('link', '', 'post'));
|
||||
|
||||
// Verify that this is a local link
|
||||
if (!$link || !JUri::isInternal($link))
|
||||
{
|
||||
//Non-local url...
|
||||
JError::raiseNotice(500, JText::_('COM_MAILTO_EMAIL_NOT_SENT'));
|
||||
return $this->mailto();
|
||||
}
|
||||
|
||||
// An array of email headers we do not want to allow as input
|
||||
$headers = array ( 'Content-Type:',
|
||||
'MIME-Version:',
|
||||
'Content-Transfer-Encoding:',
|
||||
'bcc:',
|
||||
'cc:');
|
||||
|
||||
// An array of the input fields to scan for injected headers
|
||||
$fields = array(
|
||||
'mailto',
|
||||
'sender',
|
||||
'from',
|
||||
'subject',
|
||||
);
|
||||
|
||||
/*
|
||||
* Here is the meat and potatoes of the header injection test. We
|
||||
* iterate over the array of form input and check for header strings.
|
||||
* If we find one, send an unauthorized header and die.
|
||||
*/
|
||||
foreach ($fields as $field)
|
||||
{
|
||||
foreach ($headers as $header)
|
||||
{
|
||||
if (strpos($_POST[$field], $header) !== false)
|
||||
{
|
||||
JError::raiseError(403, '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Free up memory
|
||||
*/
|
||||
unset ($headers, $fields);
|
||||
|
||||
$email = $this->input->post->getString('mailto', '');
|
||||
$sender = $this->input->post->getString('sender', '');
|
||||
$from = $this->input->post->getString('from', '');
|
||||
$subject_default = JText::sprintf('COM_MAILTO_SENT_BY', $sender);
|
||||
$subject = $this->input->post->getString('subject', $subject_default);
|
||||
|
||||
// Check for a valid to address
|
||||
$error = false;
|
||||
if (! $email || ! JMailHelper::isEmailAddress($email))
|
||||
{
|
||||
$error = JText::sprintf('COM_MAILTO_EMAIL_INVALID', $email);
|
||||
JError::raiseWarning(0, $error);
|
||||
}
|
||||
|
||||
// Check for a valid from address
|
||||
if (! $from || ! JMailHelper::isEmailAddress($from))
|
||||
{
|
||||
$error = JText::sprintf('COM_MAILTO_EMAIL_INVALID', $from);
|
||||
JError::raiseWarning(0, $error);
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
return $this->mailto();
|
||||
}
|
||||
|
||||
// Build the message to send
|
||||
$msg = JText::_('COM_MAILTO_EMAIL_MSG');
|
||||
|
||||
$link = $link;
|
||||
$body = sprintf($msg, $SiteName, $sender, $from, $link);
|
||||
|
||||
// Clean the email data
|
||||
$subject = JMailHelper::cleanSubject($subject);
|
||||
$body = JMailHelper::cleanBody($body);
|
||||
|
||||
// To send we need to use punycode.
|
||||
$from = JStringPunycode::emailToPunycode($from);
|
||||
$from = JMailHelper::cleanAddress($from);
|
||||
$email = JStringPunycode::emailToPunycode($email);
|
||||
|
||||
// Send the email
|
||||
if (JFactory::getMailer()->sendMail($from, $sender, $email, $subject, $body) !== true)
|
||||
{
|
||||
JError::raiseNotice(500, JText::_('COM_MAILTO_EMAIL_NOT_SENT'));
|
||||
return $this->mailto();
|
||||
}
|
||||
|
||||
$this->input->set('view', 'sent');
|
||||
$this->display();
|
||||
}
|
||||
}
|
1
components/com_mailto/helpers/index.html
Normal file
1
components/com_mailto/helpers/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
84
components/com_mailto/helpers/mailto.php
Normal file
84
components/com_mailto/helpers/mailto.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_mailto
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_mailto
|
||||
*/
|
||||
abstract class MailtoHelper
|
||||
{
|
||||
/**
|
||||
* Adds a URL to the mailto system and returns the hash
|
||||
*
|
||||
* @param string url
|
||||
* @return URL hash
|
||||
*/
|
||||
public static function addLink($url)
|
||||
{
|
||||
$hash = sha1($url);
|
||||
self::cleanHashes();
|
||||
$session = JFactory::getSession();
|
||||
$mailto_links = $session->get('com_mailto.links', array());
|
||||
if (!isset($mailto_links[$hash]))
|
||||
{
|
||||
$mailto_links[$hash] = new stdClass;
|
||||
}
|
||||
$mailto_links[$hash]->link = $url;
|
||||
$mailto_links[$hash]->expiry = time();
|
||||
$session->set('com_mailto.links', $mailto_links);
|
||||
return $hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a URL is a Flash file
|
||||
*
|
||||
* @param string
|
||||
* @return URL
|
||||
*/
|
||||
public static function validateHash($hash)
|
||||
{
|
||||
$retval = false;
|
||||
$session = JFactory::getSession();
|
||||
self::cleanHashes();
|
||||
$mailto_links = $session->get('com_mailto.links', array());
|
||||
if (isset($mailto_links[$hash]))
|
||||
{
|
||||
$retval = $mailto_links[$hash]->link;
|
||||
}
|
||||
return $retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans out old hashes
|
||||
*
|
||||
* @since 1.6.1
|
||||
*/
|
||||
public static function cleanHashes($lifetime = 1440)
|
||||
{
|
||||
// flag for if we've cleaned on this cycle
|
||||
static $cleaned = false;
|
||||
if (!$cleaned)
|
||||
{
|
||||
$past = time() - $lifetime;
|
||||
$session = JFactory::getSession();
|
||||
$mailto_links = $session->get('com_mailto.links', array());
|
||||
foreach ($mailto_links as $index => $link)
|
||||
{
|
||||
if ($link->expiry < $past)
|
||||
{
|
||||
unset($mailto_links[$index]);
|
||||
}
|
||||
}
|
||||
$session->set('com_mailto.links', $mailto_links);
|
||||
$cleaned = true;
|
||||
}
|
||||
}
|
||||
}
|
1
components/com_mailto/index.html
Normal file
1
components/com_mailto/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
19
components/com_mailto/mailto.php
Normal file
19
components/com_mailto/mailto.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_mailto
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
require_once JPATH_COMPONENT.'/helpers/mailto.php';
|
||||
require_once JPATH_COMPONENT.'/controller.php';
|
||||
|
||||
$controller = JControllerLegacy::getInstance('Mailto');
|
||||
$controller->registerDefaultTask('mailto');
|
||||
$controller->execute(JFactory::getApplication()->input->get('task'));
|
||||
|
||||
//$controller->redirect();
|
32
components/com_mailto/mailto.xml
Normal file
32
components/com_mailto/mailto.xml
Normal file
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<extension type="component" version="3.1" method="upgrade">
|
||||
<name>com_mailto</name>
|
||||
<author>Joomla! Project</author>
|
||||
<creationDate>April 2006</creationDate>
|
||||
<copyright>(C) 2005 - 2013 Open Source Matters. All rights reserved. </copyright>
|
||||
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
|
||||
<authorEmail>admin@joomla.org</authorEmail>
|
||||
<authorUrl>www.joomla.org</authorUrl>
|
||||
<version>3.0.0</version>
|
||||
<description>COM_MAILTO_XML_DESCRIPTION</description>
|
||||
<files folder="site">
|
||||
<filename>controller.php</filename>
|
||||
<filename>index.html</filename>
|
||||
<filename>mailto.php</filename>
|
||||
<folder>views</folder>
|
||||
</files>
|
||||
<languages folder="site">
|
||||
<language tag="en-GB">language/en-GB.com_mailto.ini</language>
|
||||
</languages>
|
||||
<administration>
|
||||
<files folder="admin">
|
||||
<filename>index.html</filename>
|
||||
</files>
|
||||
<languages folder="admin">
|
||||
<language tag="en-GB">language/en-GB.com_mailto.sys.ini</language>
|
||||
</languages>
|
||||
</administration>
|
||||
<params>
|
||||
<param name="view" type="filelist" directory="/components/com_mailto/views" hide_none="1" hide_default="0" filter="." default="0" label="View Style" description="The view style for display" />
|
||||
</params>
|
||||
</extension>
|
1
components/com_mailto/views/index.html
Normal file
1
components/com_mailto/views/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
1
components/com_mailto/views/mailto/index.html
Normal file
1
components/com_mailto/views/mailto/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
2
components/com_mailto/views/mailto/metadata.xml
Normal file
2
components/com_mailto/views/mailto/metadata.xml
Normal file
@ -0,0 +1,2 @@
|
||||
<?xml version="1.0"?>
|
||||
<metadata />
|
76
components/com_mailto/views/mailto/tmpl/default.php
Normal file
76
components/com_mailto/views/mailto/tmpl/default.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_mailto
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
JHtml::_('behavior.keepalive');
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
Joomla.submitbutton = function(pressbutton)
|
||||
{
|
||||
var form = document.getElementById('mailtoForm');
|
||||
|
||||
// do field validation
|
||||
if (form.mailto.value == "" || form.from.value == "")
|
||||
{
|
||||
alert('<?php echo JText::_('COM_MAILTO_EMAIL_ERR_NOINFO'); ?>');
|
||||
return false;
|
||||
}
|
||||
form.submit();
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
$data = $this->get('data');
|
||||
?>
|
||||
|
||||
<div id="mailto-window">
|
||||
<h2>
|
||||
<?php echo JText::_('COM_MAILTO_EMAIL_TO_A_FRIEND'); ?>
|
||||
</h2>
|
||||
<div class="mailto-close">
|
||||
<a href="javascript: void window.close()" title="<?php echo JText::_('COM_MAILTO_CLOSE_WINDOW'); ?>">
|
||||
<span><?php echo JText::_('COM_MAILTO_CLOSE_WINDOW'); ?> </span></a>
|
||||
</div>
|
||||
|
||||
<form action="<?php echo JUri::base() ?>index.php" id="mailtoForm" method="post">
|
||||
<div class="formelm">
|
||||
<label for="mailto_field"><?php echo JText::_('COM_MAILTO_EMAIL_TO'); ?></label>
|
||||
<input type="text" id="mailto_field" name="mailto" class="inputbox" size="25" value="<?php echo $this->escape($data->mailto); ?>"/>
|
||||
</div>
|
||||
<div class="formelm">
|
||||
<label for="sender_field">
|
||||
<?php echo JText::_('COM_MAILTO_SENDER'); ?></label>
|
||||
<input type="text" id="sender_field" name="sender" class="inputbox" value="<?php echo $this->escape($data->sender); ?>" size="25" />
|
||||
</div>
|
||||
<div class="formelm">
|
||||
<label for="from_field">
|
||||
<?php echo JText::_('COM_MAILTO_YOUR_EMAIL'); ?></label>
|
||||
<input type="text" id="from_field" name="from" class="inputbox" value="<?php echo $this->escape($data->from); ?>" size="25" />
|
||||
</div>
|
||||
<div class="formelm">
|
||||
<label for="subject_field">
|
||||
<?php echo JText::_('COM_MAILTO_SUBJECT'); ?></label>
|
||||
<input type="text" id="subject_field" name="subject" class="inputbox" value="<?php echo $this->escape($data->subject); ?>" size="25" />
|
||||
</div>
|
||||
<p>
|
||||
<button class="button" onclick="return Joomla.submitbutton('send');">
|
||||
<?php echo JText::_('COM_MAILTO_SEND'); ?>
|
||||
</button>
|
||||
<button class="button" onclick="window.close();return false;">
|
||||
<?php echo JText::_('COM_MAILTO_CANCEL'); ?>
|
||||
</button>
|
||||
</p>
|
||||
<input type="hidden" name="layout" value="<?php echo $this->getLayout();?>" />
|
||||
<input type="hidden" name="option" value="com_mailto" />
|
||||
<input type="hidden" name="task" value="send" />
|
||||
<input type="hidden" name="tmpl" value="component" />
|
||||
<input type="hidden" name="link" value="<?php echo $data->link; ?>" />
|
||||
<?php echo JHtml::_('form.token'); ?>
|
||||
|
||||
</form>
|
||||
</div>
|
1
components/com_mailto/views/mailto/tmpl/index.html
Normal file
1
components/com_mailto/views/mailto/tmpl/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
75
components/com_mailto/views/mailto/view.html.php
Normal file
75
components/com_mailto/views/mailto/view.html.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_mailto
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_mailto
|
||||
* @since 1.5
|
||||
*/
|
||||
class MailtoViewMailto extends JViewLegacy
|
||||
{
|
||||
/**
|
||||
* @since 1.5
|
||||
*/
|
||||
public function display($tpl = null)
|
||||
{
|
||||
$data = $this->getData();
|
||||
if ($data === false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->set('data', $data);
|
||||
|
||||
parent::display($tpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.5
|
||||
*/
|
||||
function &getData()
|
||||
{
|
||||
$user = JFactory::getUser();
|
||||
$app = JFactory::getApplication();
|
||||
$data = new stdClass;
|
||||
|
||||
$data->link = urldecode(JRequest::getVar('link', '', 'method', 'base64'));
|
||||
|
||||
if ($data->link == '')
|
||||
{
|
||||
JError::raiseError(403, JText::_('COM_MAILTO_LINK_IS_MISSING'));
|
||||
$false = false;
|
||||
return $false;
|
||||
}
|
||||
|
||||
// Load with previous data, if it exists
|
||||
$mailto = $app->input->post->getString('mailto', '');
|
||||
$sender = $app->input->post->getString('sender', '');
|
||||
$from = $app->input->post->getString('from', '');
|
||||
$subject = $app->input->post->getString('subject', '');
|
||||
|
||||
if ($user->get('id') > 0)
|
||||
{
|
||||
$data->sender = $user->get('name');
|
||||
$data->from = $user->get('email');
|
||||
}
|
||||
else
|
||||
{
|
||||
$data->sender = $sender;
|
||||
$data->from = JStringPunycode::emailToPunycode($from);
|
||||
}
|
||||
|
||||
$data->subject = $subject;
|
||||
$data->mailto = JStringPunycode::emailToPunycode($mailto);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
1
components/com_mailto/views/sent/index.html
Normal file
1
components/com_mailto/views/sent/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
11
components/com_mailto/views/sent/metadata.xml
Normal file
11
components/com_mailto/views/sent/metadata.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0"?>
|
||||
<mosparam type="component" version="1.0.0">
|
||||
<name>Mailto</name>
|
||||
<author>Andrew Eddie</author>
|
||||
<creationDate>13 Mar 2006</creationDate>
|
||||
<copyright>Copyright (C) 2005 - 2013 Open Source Matters. All rights reserved.</copyright>
|
||||
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
|
||||
<authorEmail>admin@joomla.org</authorEmail>
|
||||
<authorUrl>www.joomla.org</authorUrl>
|
||||
<description>COM_MAILTO_XML_DESCRIPTION</description>
|
||||
</mosparam>
|
21
components/com_mailto/views/sent/tmpl/default.php
Normal file
21
components/com_mailto/views/sent/tmpl/default.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_mailto
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
?>
|
||||
<div style="padding: 10px;">
|
||||
<div style="text-align:right">
|
||||
<a href="javascript: void window.close()">
|
||||
<?php echo JText::_('COM_MAILTO_CLOSE_WINDOW'); ?> <?php echo JHtml::_('image', 'mailto/close-x.png', null, null, true); ?></a>
|
||||
</div>
|
||||
|
||||
<h2>
|
||||
<?php echo JText::_('COM_MAILTO_EMAIL_SENT'); ?>
|
||||
</h2>
|
||||
</div>
|
1
components/com_mailto/views/sent/tmpl/index.html
Normal file
1
components/com_mailto/views/sent/tmpl/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
26
components/com_mailto/views/sent/view.html.php
Normal file
26
components/com_mailto/views/sent/view.html.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_mailto
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_mailto
|
||||
* @since 1.5
|
||||
*/
|
||||
class MailtoViewSent extends JViewLegacy
|
||||
{
|
||||
/**
|
||||
* @since 1.5
|
||||
*/
|
||||
public function display($tpl = null)
|
||||
{
|
||||
parent::display($tpl);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user