2020-07-10 12:20:25 +00:00
|
|
|
<?php
|
2020-08-04 11:25:22 +00:00
|
|
|
|
2020-06-12 20:41:09 +00:00
|
|
|
/**
|
|
|
|
* Class Analytics
|
|
|
|
* Creates Analytics controller
|
|
|
|
* @copyright 2020 Podlibre
|
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
2020-07-10 12:20:25 +00:00
|
|
|
namespace App\Controllers;
|
|
|
|
|
2020-06-12 20:41:09 +00:00
|
|
|
use CodeIgniter\Controller;
|
|
|
|
|
|
|
|
class Analytics extends Controller
|
|
|
|
{
|
2020-06-14 15:45:42 +00:00
|
|
|
/**
|
|
|
|
* An array of helpers to be loaded automatically upon
|
|
|
|
* class instantiation. These helpers will be available
|
|
|
|
* to all other controllers that extend Analytics.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $helpers = ['analytics'];
|
2020-06-12 20:41:09 +00:00
|
|
|
|
2020-06-14 15:45:42 +00:00
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*/
|
|
|
|
public function initController(
|
|
|
|
\CodeIgniter\HTTP\RequestInterface $request,
|
|
|
|
\CodeIgniter\HTTP\ResponseInterface $response,
|
|
|
|
\Psr\Log\LoggerInterface $logger
|
|
|
|
) {
|
|
|
|
// Do Not Edit This Line
|
|
|
|
parent::initController($request, $response, $logger);
|
2020-06-12 20:41:09 +00:00
|
|
|
|
2020-06-14 15:45:42 +00:00
|
|
|
//--------------------------------------------------------------------
|
|
|
|
// Preload any models, libraries, etc, here.
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
// E.g.:
|
|
|
|
// $this->session = \Config\Services::session();
|
2020-06-12 20:41:09 +00:00
|
|
|
|
2020-10-06 15:39:27 +00:00
|
|
|
set_user_session_deny_list_ip();
|
|
|
|
set_user_session_location();
|
2020-06-14 15:45:42 +00:00
|
|
|
set_user_session_player();
|
2020-06-12 20:41:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add one hit to this episode:
|
2020-10-29 17:27:16 +01:00
|
|
|
public function hit($base64EpisodeData, ...$filename)
|
|
|
|
{
|
|
|
|
helper('media', 'analytics');
|
2020-09-08 11:45:17 +00:00
|
|
|
|
2020-10-26 16:13:43 +00:00
|
|
|
$serviceName = isset($_GET['_from']) ? $_GET['_from'] : '';
|
2020-10-21 16:04:18 +00:00
|
|
|
|
2020-10-29 17:27:16 +01:00
|
|
|
$episodeData = unpack(
|
|
|
|
'IpodcastId/IepisodeId/IbytesThreshold/IfileSize/Iduration/IpublicationDate',
|
|
|
|
base64_url_decode($base64EpisodeData)
|
|
|
|
);
|
|
|
|
|
2020-10-21 16:04:18 +00:00
|
|
|
podcast_hit(
|
2020-10-29 17:27:16 +01:00
|
|
|
$episodeData['podcastId'],
|
|
|
|
$episodeData['episodeId'],
|
|
|
|
$episodeData['bytesThreshold'],
|
|
|
|
$episodeData['fileSize'],
|
|
|
|
$episodeData['duration'],
|
|
|
|
$episodeData['publicationDate'],
|
2020-10-21 16:04:18 +00:00
|
|
|
$serviceName
|
|
|
|
);
|
2020-10-26 16:13:43 +00:00
|
|
|
return redirect()->to(media_base_url($filename));
|
2020-06-12 20:41:09 +00:00
|
|
|
}
|
|
|
|
}
|