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

Feedback.php « Feedback « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9a75c51c9213f754866216dc1c600635d0b1b2c8 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
/**
 * Matomo - free/libre analytics platform
 *
 * @link https://matomo.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 *
 */
namespace Piwik\Plugins\Feedback;

use Piwik\Date;
use Piwik\Plugins\UsersManager\API as APIUsersManager;
use Piwik\Plugins\UsersManager\UsersManager;
use Piwik\Site;
use Piwik\View;
use Piwik\Piwik;
use Piwik\Common;
use Piwik\Plugin\Manager as PluginManager;
use Piwik\Plugins\Feedback\FeedbackReminder;

/**
 *
 */
class Feedback extends \Piwik\Plugin
{
    const NEVER_REMIND_ME_AGAIN = "-1";

    /**
     * @see \Piwik\Plugin::registerEvents
     */
    public function registerEvents()
    {
        return array(
            'AssetManager.getStylesheetFiles'        => 'getStylesheetFiles',
            'AssetManager.getJavaScriptFiles'        => 'getJsFiles',
            'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys',
            'Controller.CoreHome.index.end'          => 'renderViewsAndAddToPage'
        );
    }

    public function getStylesheetFiles(&$stylesheets)
    {
        $stylesheets[] = "plugins/Feedback/stylesheets/feedback.less";
        $stylesheets[] = "plugins/Feedback/vue/src/RateFeature/RateFeature.less";
        $stylesheets[] = "plugins/Feedback/vue/src/ReviewLinks/ReviewLinks.less";
        $stylesheets[] = "plugins/Feedback/vue/src/FeedbackQuestion/FeedbackQuestion.less";
    }

    public function getJsFiles(&$jsFiles)
    {
    }

    public function getClientSideTranslationKeys(&$translationKeys)
    {
        $translationKeys[] = 'Feedback_ThankYouHeart';
        $translationKeys[] = 'Feedback_ThankYouForSpreading';
        $translationKeys[] = 'Feedback_RateFeatureTitle';
        $translationKeys[] = 'Feedback_RateFeatureThankYouTitle';
        $translationKeys[] = 'Feedback_RateFeatureLeaveMessageLike';
        $translationKeys[] = 'Feedback_RateFeatureLeaveMessageLikeNamedFeature';
        $translationKeys[] = 'Feedback_RateFeatureLeaveMessageLikeExtra';
        $translationKeys[] = 'Feedback_RateFeatureLeaveMessageLikeExtraConfigurable';
        $translationKeys[] = 'Feedback_RateFeatureLeaveMessageLikeExtraEasy';
        $translationKeys[] = 'Feedback_RateFeatureLeaveMessageLikeExtraUseful';
        $translationKeys[] = 'Feedback_RateFeatureLeaveMessageDislike';
        $translationKeys[] = 'Feedback_RateFeatureLeaveMessageDislikeNamedFeature';
        $translationKeys[] = 'Feedback_RateFeatureLeaveMessageDislikeExtra';
        $translationKeys[] = 'Feedback_RateFeatureLeaveMessageDislikeExtraBugs';
        $translationKeys[] = 'Feedback_RateFeatureLeaveMessageDislikeExtraMissing';
        $translationKeys[] = 'Feedback_RateFeatureLeaveMessageDislikeExtraSpeed';
        $translationKeys[] = 'Feedback_RateFeatureLeaveMessageDislikeExtraEasier';
        $translationKeys[] = 'Feedback_RateFeatureOtherReason';
        $translationKeys[] = 'Feedback_SendFeedback';
        $translationKeys[] = 'Feedback_RateFeatureSendFeedbackInformation';
        $translationKeys[] = 'Feedback_RateFeatureUsefulInfo';
        $translationKeys[] = 'Feedback_RateFeatureEasyToUse';
        $translationKeys[] = 'Feedback_RateFeatureConfigurable';
        $translationKeys[] = 'Feedback_RateFeatureDislikeAddMissingFeatures';
        $translationKeys[] = 'Feedback_RateFeatureDislikeMakeEasier';
        $translationKeys[] = 'Feedback_RateFeatureDislikeSpeedUp';
        $translationKeys[] = 'Feedback_RateFeatureDislikeFixBugs';
        $translationKeys[] = 'Feedback_ReviewMatomoTitle';
        $translationKeys[] = 'Feedback_PleaseLeaveExternalReviewForMatomo';
        $translationKeys[] = 'Feedback_RemindMeLater';
        $translationKeys[] = 'Feedback_NeverAskMeAgain';
        $translationKeys[] = 'Feedback_WontShowAgain';
        $translationKeys[] = 'Feedback_AppreciateFeedback';
        $translationKeys[] = 'Feedback_Policy';
        $translationKeys[] = 'General_Ok';
        $translationKeys[] = 'General_Cancel';
        $translationKeys[] = 'Feedback_Question0';
        $translationKeys[] = 'Feedback_Question1';
        $translationKeys[] = 'Feedback_Question2';
        $translationKeys[] = 'Feedback_Question3';
        $translationKeys[] = 'Feedback_Question4';
        $translationKeys[] = 'Feedback_FeedbackTitle';
        $translationKeys[] = 'Feedback_FeedbackSubtitle';
        $translationKeys[] = 'Feedback_Policy';
        $translationKeys[] = 'Feedback_ThankYourForFeedback';
        $translationKeys[] = 'Feedback_ThankYou';
        $translationKeys[] = 'Feedback_MessageBodyValidationError';
    }

    public function renderViewsAndAddToPage(&$pageHtml)
    {
        //only show on superuser
        if (!Piwik::hasUserSuperUserAccess()) {
            return $pageHtml;
        }
        $feedbackQuestionBanner = $this->renderFeedbackQuestion();

        $matches = preg_split('/(<body.*?>)/i', $pageHtml, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
        $pageHtml = $matches[0] . $matches[1] . $feedbackQuestionBanner . $matches[2];
    }


    public function renderFeedbackQuestion()
    {
        $feedbackQuestionBanner = new View('@Feedback/feedbackQuestionBanner');
        $feedbackQuestionBanner->showQuestionBanner = (int)$this->showQuestionBanner();

        return $feedbackQuestionBanner->render();
    }

    public function showQuestionBanner()
    {
        if (Piwik::isUserIsAnonymous()) {
            return false;
        }

        // Hide Feedback popup in all tests except if forced
        if ($this->isDisabledInTestMode()) {
            return false;
        }

        $shouldShowQuestionBanner = true;

        Piwik::postEvent('Feedback.showQuestionBanner', [&$shouldShowQuestionBanner]);

        if (!$shouldShowQuestionBanner) {
            return false;
        }

        $feedbackReminder = new FeedbackReminder();
        $nextReminderDate = $feedbackReminder->getUserOption();
        $now = Date::now()->getTimestamp();

        // If there isn't any reminder date set, or never remind me was selected previously (-1) we determine a new date
        if ($nextReminderDate === false || $nextReminderDate <= 0) {

            // if user was created within the last 6 months, we set the date to 6 months after his creation date
            $userCreatedDate = Piwik::getCurrentUserCreationDate();
            if (!empty($userCreatedDate) && Date::factory($userCreatedDate)->addMonth(6)->getTimestamp() > $now) {
                $nextReminder = Date::factory($userCreatedDate)->addMonth(6)->toString('Y-m-d');
                $feedbackReminder->setUserOption($nextReminder);
                return false;
            }

            // Otherwise we set the date to somewhen within the next 6 months
            $nextReminder = Date::now()->getStartOfDay()->addDay(Common::getRandomInt(1, 6*30))->toString('Y-m-d');
            $feedbackReminder->setUserOption($nextReminder);
            return false;
        }

        $nextReminderDate = Date::factory($nextReminderDate);
        if ($nextReminderDate->getTimestamp() > $now) {
            return false;
        }
        return true;

    }

    // needs to be protected not private for testing purpose
    protected function isDisabledInTestMode()
    {
        return defined('PIWIK_TEST_MODE') && PIWIK_TEST_MODE && !Common::getRequestVar('forceFeedbackTest', false);
    }

}