Skip to content
Extraits de code Groupes Projets
Controller.php 5,73 ko
Newer Older
  • Learn to ignore specific revisions
  • <?php
    /**
    
     * Piwik - free/libre analytics platform
    
     * @link http://piwik.org
    
    robocoder's avatar
    robocoder a validé
     * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
    
    use Piwik\API\DocumentationGenerator;
    use Piwik\API\Proxy;
    
    mattab's avatar
    mattab a validé
    use Piwik\Common;
    
    use Piwik\UrlHelper;
    
    class Controller extends \Piwik\Plugin\Controller
    
            $token = 'token_auth=' . Common::getRequestVar('token_auth', 'anonymous', 'string');
    
    
            // when calling the API through http, we limit the number of returned results
            if (!isset($_GET['filter_limit'])) {
    
                if (isset($_POST['filter_limit'])) {
                    $_GET['filter_limit'] = $_POST['filter_limit'];
                } else {
                    $_GET['filter_limit'] = Config::getInstance()->General['API_datatable_default_limit'];
                }
    
            $response = $request->process();
    
            if (is_array($response)) {
                $response = var_export($response, true);
            }
    
            return $response;
    
        public function listAllMethods()
        {
    
            Piwik::checkUserHasSomeViewAccess();
    
    
            $ApiDocumentation = new DocumentationGenerator();
    
            $prefixUrls = Common::getRequestVar('prefixUrl', 'http://demo.piwik.org/', 'string');
    
            if (!UrlHelper::isLookLikeUrl($prefixUrls) || strpos($prefixUrls, 'http') !== 0) {
    
                $prefixUrls = '';
            }
    
            return $ApiDocumentation->getApiDocumentationAsStringForDeveloperReference($outputExampleUrls = true, $prefixUrls);
    
            $view = new View("@API/listAllAPI");
    
            $this->setGeneralVariablesView($view);
    
    
            $ApiDocumentation = new DocumentationGenerator();
            $view->countLoadedAPI = Proxy::getInstance()->getCountRegisteredClasses();
    
            $view->list_api_methods_with_links = $ApiDocumentation->getApiDocumentationAsString();
    
            return $view->render();
    
            $segments = API::getInstance()->getSegmentsMetadata($this->idSite);
    
    
            $tableDimensions = $tableMetrics = '';
            $customVariables = 0;
            $lastCategory = array();
            foreach ($segments as $segment) {
    
                // Eg. Event Value is a metric, not in the Visit metric category,
                // we make sure it is displayed along with the Events dimensions
    
                if ($segment['type'] == 'metric' && $segment['category'] != Piwik::translate('General_Visit')) {
    
    Thomas Steur's avatar
    Thomas Steur a validé
                $onlyDisplay = array('customVariableName1', 'customVariableName2',
                                     'customVariableValue1', 'customVariableValue2',
                                     'customVariablePageName1', 'customVariablePageValue1');
    
    
                $customVariableWillBeDisplayed = in_array($segment['segment'], $onlyDisplay);
                // Don't display more than 4 custom variables name/value rows
                if ($segment['category'] == 'Custom Variables'
                    && !$customVariableWillBeDisplayed
                ) {
                    continue;
                }
    
                $thisCategory = $segment['category'];
                $output = '';
                if (empty($lastCategory[$segment['type']])
                    || $lastCategory[$segment['type']] != $thisCategory
                ) {
                    $output .= '<tr><td class="segmentCategory" colspan="2"><b>' . $thisCategory . '</b></td></tr>';
                }
    
                $lastCategory[$segment['type']] = $thisCategory;
    
                $exampleValues = isset($segment['acceptedValues'])
                    ? 'Example values: <code>' . $segment['acceptedValues'] . '</code>'
                    : '';
                $restrictedToAdmin = isset($segment['permission']) ? '<br/>Note: This segment can only be used by an Admin user' : '';
                $output .= '<tr>
    							<td class="segmentString">' . $segment['segment'] . '</td>
    							<td class="segmentName">' . $segment['name'] . $restrictedToAdmin . '<br/>' . $exampleValues . ' </td>
    
    
                // Show only 2 custom variables and display message for rest
                if ($customVariableWillBeDisplayed) {
                    $customVariables++;
                    if ($customVariables == count($onlyDisplay)) {
                        $output .= '<tr><td colspan="2"> There are 5 custom variables available, so you can segment across any segment name and value range.
    
        						<br/>For example, <code>customVariableName1==Type;customVariableValue1==Customer</code>
        						<br/>Returns all visitors that have the Custom Variable "Type" set to "Customer".
    
    mattpiwik's avatar
    mattpiwik a validé
        						<br/>Custom Variables of scope "page" can be queried separately. For example, to query the Custom Variable of scope "page",
        						<br/>stored in index 1, you would use the segment <code>customVariablePageName1==ArticleLanguage;customVariablePageValue1==FR</code>
    
                    }
                }
    
                if ($segment['type'] == 'dimension') {
                    $tableDimensions .= $output;
                } else {
                    $tableMetrics .= $output;
                }
            }
    
    
    		<strong>Dimensions</strong>
    
    		<strong>Metrics</strong>
    
    
        public function glossary()
        {
            Piwik::checkUserHasSomeViewAccess();
    
            return $this->renderTemplate('glossary', array(
    
                'reports' => Request::processRequest('API', array('method' => 'API.getGlossaryReports', 'filter_limit' => -1)),
                'metrics' => Request::processRequest('API', array('method' => 'API.getGlossaryMetrics', 'filter_limit' => -1)),