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

Controller.php « CoreHome « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c95b5d61ce7fa35bf21fe8c66a0d53c850391e8b (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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?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 Piwik_CoreHome
 */
use Piwik\Piwik;
use Piwik\Common;
use Piwik\Date;
use Piwik\Site;

/**
 *
 * @package Piwik_CoreHome
 */
class Piwik_CoreHome_Controller extends Piwik_Controller
{
    function getDefaultAction()
    {
        return 'redirectToCoreHomeIndex';
    }

    function redirectToCoreHomeIndex()
    {
        $defaultReport = Piwik_UsersManager_API::getInstance()->getUserPreference(Piwik::getCurrentUserLogin(), Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT);
        $module = 'CoreHome';
        $action = 'index';

        // User preference: default report to load is the All Websites dashboard
        if ($defaultReport == 'MultiSites'
            && \Piwik\PluginsManager::getInstance()->isPluginActivated('MultiSites')
        ) {
            $module = 'MultiSites';
        }
        if ($defaultReport == Piwik::getLoginPluginName()) {
            $module = Piwik::getLoginPluginName();
        }
        $idSite = Common::getRequestVar('idSite', false, 'int');

        parent::redirectToIndex($module, $action, !empty($idSite) ? $idSite : null);
    }

    public function showInContext()
    {
        $controllerName = Common::getRequestVar('moduleToLoad');
        $actionName = Common::getRequestVar('actionToLoad', 'index');
        if ($actionName == 'showInContext') {
            throw new Exception("Preventing infinite recursion...");
        }
        $view = $this->getDefaultIndexView();
        $view->content = Piwik_FrontController::getInstance()->fetchDispatch($controllerName, $actionName);
        echo $view->render();
    }

    protected function getDefaultIndexView()
    {
        $view = new Piwik_View('@CoreHome/getDefaultIndexView');
        $this->setGeneralVariablesView($view);
        $view->menu = Piwik_GetMenu();
        $view->content = '';
        return $view;
    }

    protected function setDateTodayIfWebsiteCreatedToday()
    {
        $date = Common::getRequestVar('date', false);
        if ($date == 'today'
            || Common::getRequestVar('period', false) == 'range'
        ) {
            return;
        }
        $websiteId = Common::getRequestVar('idSite', false, 'int');
        if ($websiteId) {
            $website = new Site($websiteId);
            $datetimeCreationDate = $this->site->getCreationDate()->getDatetime();
            $creationDateLocalTimezone = Date::factory($datetimeCreationDate, $website->getTimezone())->toString('Y-m-d');
            $todayLocalTimezone = Date::factory('now', $website->getTimezone())->toString('Y-m-d');
            if ($creationDateLocalTimezone == $todayLocalTimezone) {
                Piwik::redirectToModule('CoreHome', 'index',
                    array('date'   => 'today',
                          'idSite' => $websiteId,
                          'period' => Common::getRequestVar('period'))
                );
            }
        }
    }

    public function index()
    {
        $this->setDateTodayIfWebsiteCreatedToday();
        $view = $this->getDefaultIndexView();
        echo $view->render();
    }

    /**
     * This method is called when the asset manager is configured in merged mode.
     * It returns the content of the css merged file.
     *
     * @see core/AssetManager.php
     */
    public function getCss()
    {
        $cssMergedFile = Piwik_AssetManager::getMergedCssFileLocation();
        Piwik::serveStaticFile($cssMergedFile, "text/css");
    }

    /**
     * This method is called when the asset manager is configured in merged mode.
     * It returns the content of the js merged file.
     *
     * @see core/AssetManager.php
     */
    public function getJs()
    {
        $jsMergedFile = Piwik_AssetManager::getMergedJsFileLocation();
        Piwik::serveStaticFile($jsMergedFile, "application/javascript; charset=UTF-8");
    }


    //  --------------------------------------------------------
    //  ROW EVOLUTION
    //  The following methods render the popover that shows the
    //  evolution of a singe or multiple rows in a data table
    //  --------------------------------------------------------

    /**
     * This static cache is necessary because the signature cannot be modified
     * if the method renders a ViewDataTable. So we use it to pass information
     * to getRowEvolutionGraph()
     * @var Piwik_CoreHome_DataTableAction_Evolution
     */
    private static $rowEvolutionCache = null;

    /** Render the entire row evolution popover for a single row */
    public function getRowEvolutionPopover()
    {
        $rowEvolution = $this->makeRowEvolution($isMulti = false);
        self::$rowEvolutionCache = $rowEvolution;
        $view = new Piwik_View('@CoreHome/getRowEvolutionPopover');
        echo $rowEvolution->renderPopover($this, $view);
    }

    /** Render the entire row evolution popover for multiple rows */
    public function getMultiRowEvolutionPopover()
    {
        $rowEvolution = $this->makeRowEvolution($isMulti = true);
        self::$rowEvolutionCache = $rowEvolution;
        $view = new Piwik_View('@CoreHome/getMultiRowEvolutionPopover');
        echo $rowEvolution->renderPopover($this, $view);
    }

    /** Generic method to get an evolution graph or a sparkline for the row evolution popover */
    public function getRowEvolutionGraph($fetch = false)
    {
        $rowEvolution = self::$rowEvolutionCache;
        if ($rowEvolution === null) {
            $paramName = Piwik_CoreHome_DataTableRowAction_MultiRowEvolution::IS_MULTI_EVOLUTION_PARAM;
            $isMultiRowEvolution = Common::getRequestVar($paramName, false, 'int');

            $rowEvolution = $this->makeRowEvolution($isMultiRowEvolution, $graphType = 'graphEvolution');
            $rowEvolution->useAvailableMetrics();
            self::$rowEvolutionCache = $rowEvolution;
        }

        $view = $rowEvolution->getRowEvolutionGraph();
        return $this->renderView($view, $fetch);
    }

    /** Utility function. Creates a RowEvolution instance. */
    private function makeRowEvolution($isMultiRowEvolution, $graphType = null)
    {
        if ($isMultiRowEvolution) {
            return new Piwik_CoreHome_DataTableRowAction_MultiRowEvolution($this->idSite, $this->date, $graphType);
        } else {
            return new Piwik_CoreHome_DataTableRowAction_RowEvolution($this->idSite, $this->date, $graphType);
        }
    }

    /**
     * Forces a check for updates and re-renders the header message.
     *
     * This will check piwik.org at most once per 10s.
     */
    public function checkForUpdates()
    {
        Piwik::checkUserHasSomeAdminAccess();
        $this->checkTokenInUrl();

        // perform check (but only once every 10s)
        Piwik_UpdateCheck::check($force = false, Piwik_UpdateCheck::UI_CLICK_CHECK_INTERVAL);

        $view = new Piwik_View('@CoreHome/checkForUpdates');
        $this->setGeneralVariablesView($view);
        echo $view->render();
    }

    /**
     * Renders and echo's the in-app donate form w/ slider.
     */
    public function getDonateForm()
    {
        $view = new Piwik_View('@CoreHome/getDonateForm');
        if (Common::getRequestVar('widget', false)
            && Piwik::isUserIsSuperUser()
        ) {
            $view->footerMessage = Piwik_Translate('CoreHome_OnlyForAdmin');
        }
        echo $view->render();
    }

    /**
     * Renders and echo's HTML that displays the Piwik promo video.
     */
    public function getPromoVideo()
    {
        $view = new Piwik_View('@CoreHome/getPromoVideo');
        $view->shareText = Piwik_Translate('CoreHome_SharePiwikShort');
        $view->shareTextLong = Piwik_Translate('CoreHome_SharePiwikLong');
        $view->promoVideoUrl = 'http://www.youtube.com/watch?v=OslfF_EH81g';
        echo $view->render();
    }
    
    /**
     * Redirects the user to a paypal so they can donate to Piwik.
     */
    public function redirectToPaypal()
    {
        $parameters = Piwik_API_Request::getRequestArrayFromString($request = null);
        foreach ($parameters as $name => $param) {
            if ($name == 'idSite'
                || $name == 'module'
                || $name == 'action'
            ) {
                unset($parameters[$name]);
            }
        }
        
        $url = "https://www.paypal.com/cgi-bin/webscr?".Piwik_Url::getQueryStringFromParameters($parameters);
        
        header("Location: $url");
        exit;
    }
}