Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Controller.php « Feedback « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 412cea69abb0cfb3fab59e5940e1046a3f4f3273 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
 * Piwik - Open source web analytics
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 *
 * @category Piwik_Plugins
 * @package Feedback
 */
namespace Piwik\Plugins\Feedback;

use Exception;
use Piwik\Common;
use Piwik\Config;
use Piwik\IP;
use Piwik\Mail;
use Piwik\Nonce;
use Piwik\Piwik;
use Piwik\Url;
use Piwik\Version;
use Piwik\View;

/**
 *
 * @package Feedback
 */
class Controller extends \Piwik\Plugin\Controller
{
    function index()
    {
        $view = new View('@Feedback/index');
        $view->nonce = Nonce::getNonce('Feedback.sendFeedback', 3600);
        echo $view->render();
    }

    /**
     * send email to Piwik team and display nice thanks
     * @throws Exception
     */
    function sendFeedback()
    {
        $email = Common::getRequestVar('email', '', 'string');
        $body = Common::getRequestVar('body', '', 'string');
        $category = Common::getRequestVar('category', '', 'string');
        $nonce = Common::getRequestVar('nonce', '', 'string');

        $view = new View('@Feedback/sendFeedback');
        $view->feedbackEmailAddress = Config::getInstance()->General['feedback_email_address'];
        try {
            $minimumBodyLength = 40;
            if (strlen($body) < $minimumBodyLength
                // Avoid those really annoying automated security test emails
                || strpos($email, 'probe@') !== false
                || strpos($body, '&lt;probe') !== false
            ) {
                throw new Exception(Piwik::translate('Feedback_ExceptionBodyLength', array($minimumBodyLength)));
            }
            if (!Piwik::isValidEmailString($email)) {
                throw new Exception(Piwik::translate('UsersManager_ExceptionInvalidEmail'));
            }
            if (preg_match('/https?:/i', $body)) {
                throw new Exception(Piwik::translate('Feedback_ExceptionNoUrls'));
            }
            if (!Nonce::verifyNonce('Feedback.sendFeedback', $nonce)) {
                throw new Exception(Piwik::translate('General_ExceptionNonceMismatch'));
            }
            Nonce::discardNonce('Feedback.sendFeedback');

            $mail = new Mail();
            $mail->setFrom(Common::unsanitizeInputValue($email));
            $mail->addTo($view->feedbackEmailAddress, 'Piwik Team');
            $mail->setSubject('[ Feedback form - Piwik ] ' . $category);
            $mail->setBodyText(Common::unsanitizeInputValue($body) . "\n"
                . 'Piwik ' . Version::VERSION . "\n"
                . 'IP: ' . IP::getIpFromHeader() . "\n"
                . 'URL: ' . Url::getReferrer() . "\n");
            @$mail->send();
        } catch (Exception $e) {
            $view->errorString = $e->getMessage();
            $view->message = $body;
        }

        echo $view->render();
    }
}