tiki-tell_a_friend.php 5.01 KB
Newer Older
1
<?php
2
// (c) Copyright 2002-2011 by authors of the Tiki Wiki CMS Groupware Project
changi67's avatar
changi67 committed
3
// 
4 5
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
changi67's avatar
changi67 committed
6 7
// $Id$

8 9 10
require_once ('tiki-setup.php');
// To include a link in your tpl do
//<a href="tiki-tell_a_friend.php?url={$smarty.server.REQUEST_URI|escape:'url'}">{tr}Email this page{/tr}</a>
11

ricks99's avatar
ricks99 committed
12
$smarty->assign('headtitle', tra('Send a link to a friend '));
13
if (empty($_REQUEST['report'])) {
14 15
	$access->check_feature('feature_tell_a_friend');
	$access->check_permission('tiki_p_tell_a_friend');
changi67's avatar
changi67 committed
16
}
17

18
if (!empty($_REQUEST['report']) && $_REQUEST['report'] == 'y') {
19 20
	$access->check_feature('feature_site_report', '', 'look');
	$access->check_permission('tiki_p_site_report');
21
}
22

23 24 25 26 27 28 29 30 31
if (empty($_REQUEST['url']) && !empty($_SERVER['HTTP_REFERER'])) {
	$u = parse_url($_SERVER['HTTP_REFERER']);
	if ($u['host'] != $_SERVER['SERVER_NAME']) {
		$smarty->assign('msg', tra('Incorrect param'));
		$smarty->display('error.tpl');
		die;
	}
	$_REQUEST['url'] = $_REQUEST['HTTP_REFERER'];
}
32 33 34 35 36
if (empty($_REQUEST['url'])) {
	$smarty->assign('msg', tra('missing parameters'));
	$smarty->display('error.tpl');
	die;
}
37 38 39
$_REQUEST['url'] = urldecode($_REQUEST['url']);
if (strstr($_REQUEST['url'], 'tiki-tell_a_friend.php')) {
	$_REQUEST['url'] = preg_replace('/.*tiki-tell_a_friend.php\?url=/', '', $_REQUEST['url']);
changi67's avatar
changi67 committed
40
	header('location: tiki-tell_a_friend.php?url=' . $_REQUEST['url']);
41
}
42
$url_for_friend = $tikilib->httpPrefix( true ) . $_REQUEST['url'];
43
$smarty->assign('url', $_REQUEST['url']);
44
$smarty->assign('prefix', $tikilib->httpPrefix( true ));
sylvieg's avatar
sylvieg committed
45
$errors = array();
46 47
if (isset($_REQUEST['send'])) {
	check_ticket('tell-a-friend');
sampaioprimo's avatar
sampaioprimo committed
48
	if (empty($user) && $prefs['feature_antibot'] == 'y' && !$captchalib->validate()) {
sampaioprimo's avatar
sampaioprimo committed
49
		$errors[] = $captchalib->getErrors();
50
	}
51
	if (empty($_REQUEST['report']) || $_REQUEST['report'] != 'y') {
changi67's avatar
changi67 committed
52
		$emails = explode(',', str_replace(' ', '', $_REQUEST['addresses']));
53
	} else {
changi67's avatar
changi67 committed
54
		$email = !empty($prefs['feature_site_report_email']) ? $prefs['feature_site_report_email'] : (!empty($prefs['sender_email']) ? $prefs['sender_email'] : '');
55 56 57 58 59 60
		if (empty($email)) {
			$errors[] = tra("The mail can't be sent. Contact the administrator");
		}
		$_REQUEST['addresses'] = $email;
		$emails[] = $email;
	}
changi67's avatar
changi67 committed
61 62
	foreach($emails as $email) {
		include_once ('lib/registration/registrationlib.php');
63
		if (function_exists('validate_email')) {
64
			$ok = validate_email($email, $prefs['validateEmail']);
65
		} else {
changi67's avatar
changi67 committed
66
			$ret = $registrationlib->SnowCheckMail($email, '', 'mini');
67 68 69
			$ok = $ret[0];
		}
		if (!$ok) {
changi67's avatar
changi67 committed
70 71
			if (isset($_REQUEST['report']) && $_REQUEST['report'] == 'y') $errors[] = tra("The mail can't be sent. Contact the administrator");
			else $errors[] = tra('One of the email addresses you typed is invalid') . ': ' . $email;
72 73 74
		}
	}
	if (empty($_REQUEST['email'])) {
75
		$errors[] = tra('Your email is mandatory');
76
	} else {
changi67's avatar
changi67 committed
77
		$smarty->assign_by_ref('email', $_REQUEST['email']);
78
		if (validate_email($_REQUEST['email'])) {
sylvieg's avatar
sylvieg committed
79
			$from = str_replace(array("\r", "\n"), '', $_REQUEST['email']);
80
		} else {
changi67's avatar
changi67 committed
81
			$errors[] = tra('Invalid email') . ': ' . $_REQUEST['email'];
82 83
		}
	}
changi67's avatar
changi67 committed
84 85 86
	if (!empty($_REQUEST['addresses'])) $smarty->assign('addresses', $_REQUEST['addresses']);
	if (!empty($_REQUEST['name'])) $smarty->assign('name', $_REQUEST['name']);
	if (!empty($_REQUEST['comment'])) $smarty->assign('comment', $_REQUEST['comment']);
87 88 89 90
	if (empty($errors)) {
		include_once ('lib/webmail/tikimaillib.php');
		$mail = new TikiMail();
		$smarty->assign_by_ref('mail_site', $_SERVER['SERVER_NAME']);
91 92
		$mail->setFrom($from);
		$mail->setHeader("Return-Path", "<$from>");
changi67's avatar
changi67 committed
93
		$mail->setHeader("Reply-To", "<$from>");
94 95 96 97 98
		if (isset($_REQUEST['report']) && $_REQUEST['report'] == 'y') {
			$subject = tra('Report to the webmaster', $prefs['site_language']);
		} else {
			$subject = $smarty->fetch('mail/tellAFriend_subject.tpl');
		}
99 100 101 102 103 104 105 106 107

		if( $prefs['auth_token_tellafriend'] == 'y' && $prefs['auth_token_access'] == 'y' && isset($_POST['share_access']) ) {
			require_once 'lib/auth/tokens.php';
			$tokenlib = AuthTokens::build( $prefs );

			$url_for_friend = $tokenlib->includeToken( $url_for_friend, $globalperms->getGroups() );
		}

		$smarty->assign( 'url_for_friend', $url_for_friend );
108
		$txt = $smarty->fetch('mail/tellAFriend.tpl');
109
		$mail->setSubject($subject);
110 111
		$mail->setText($txt);
		$mail->buildMessage();
112
		$ok = true;
changi67's avatar
changi67 committed
113
		foreach($emails as $email) {
114 115 116
			$ok = $ok && $mail->send(array($email));
		}
		if ($ok) {
117
			$access->redirect( $_REQUEST['url'], tra('Your link was sent.') );
118 119
		} else {
			$errors = tra("The mail can't be sent. Contact the administrator");
120
		}
121
	}
122
	$smarty->assign_by_ref('errors', $errors);
123
	$smarty->assign('errortype', 'no_redirect_login');
124
} else {
125 126
	$smarty->assign_by_ref('name', $user);
	$smarty->assign('email', $userlib->get_user_email($user));
127
}
128 129 130
if (!empty($_REQUEST['report'])) {
	$smarty->assign_by_ref('report', $_REQUEST['report']);
}
131 132 133
ask_ticket('tell-a-friend');
$smarty->assign('mid', 'tiki-tell_a_friend.tpl');
$smarty->display('tiki.tpl');