statistics.php 728 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. /**
  3. * @file
  4. * Handles counts of node views via AJAX with minimal bootstrap.
  5. */
  6. use Drupal\Core\DrupalKernel;
  7. use Symfony\Component\HttpFoundation\Request;
  8. chdir('../../..');
  9. $autoloader = require_once 'autoload.php';
  10. $kernel = DrupalKernel::createFromRequest(Request::createFromGlobals(), $autoloader, 'prod');
  11. $kernel->boot();
  12. $container = $kernel->getContainer();
  13. $views = $container
  14. ->get('config.factory')
  15. ->get('statistics.settings')
  16. ->get('count_content_views');
  17. if ($views) {
  18. $nid = filter_input(INPUT_POST, 'nid', FILTER_VALIDATE_INT);
  19. if ($nid) {
  20. $container->get('request_stack')->push(Request::createFromGlobals());
  21. $container->get('statistics.storage.node')->recordView($nid);
  22. }
  23. }