2020-07-10 12:20:25 +00:00
|
|
|
<?php
|
2020-08-04 11:25:22 +00:00
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-06-12 20:41:09 +00:00
|
|
|
/**
|
2022-02-19 16:06:11 +00:00
|
|
|
* @copyright 2020 Ad Aures
|
2020-06-12 20:41:09 +00:00
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
2021-08-23 11:05:16 +00:00
|
|
|
namespace Modules\Analytics\Controllers;
|
2020-07-10 12:20:25 +00:00
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
use CodeIgniter\Controller;
|
|
|
|
use CodeIgniter\HTTP\RedirectResponse;
|
2021-05-06 14:00:48 +00:00
|
|
|
use CodeIgniter\HTTP\RequestInterface;
|
|
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
|
|
use Config\Services;
|
2021-08-23 11:05:16 +00:00
|
|
|
use Modules\Analytics\Config\Analytics;
|
2021-05-19 16:35:13 +00:00
|
|
|
use Psr\Log\LoggerInterface;
|
2020-06-12 20:41:09 +00:00
|
|
|
|
2021-04-14 15:58:40 +00:00
|
|
|
class EpisodeAnalyticsController extends Controller
|
2020-06-12 20:41:09 +00:00
|
|
|
{
|
2020-06-14 15:45:42 +00:00
|
|
|
/**
|
2021-05-19 16:35:13 +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.
|
2020-06-14 15:45:42 +00:00
|
|
|
*
|
2021-05-14 17:59:35 +00:00
|
|
|
* @var string[]
|
2020-06-14 15:45:42 +00:00
|
|
|
*/
|
|
|
|
protected $helpers = ['analytics'];
|
2020-06-12 20:41:09 +00:00
|
|
|
|
2021-05-18 17:16:36 +00:00
|
|
|
protected Analytics $config;
|
|
|
|
|
2020-06-14 15:45:42 +00:00
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*/
|
|
|
|
public function initController(
|
2021-05-06 14:00:48 +00:00
|
|
|
RequestInterface $request,
|
|
|
|
ResponseInterface $response,
|
|
|
|
LoggerInterface $logger
|
|
|
|
): void {
|
2020-06-14 15:45:42 +00:00
|
|
|
// Do Not Edit This Line
|
|
|
|
parent::initController($request, $response, $logger);
|
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();
|
2021-04-14 15:58:40 +00:00
|
|
|
|
|
|
|
$this->config = config('Analytics');
|
2020-06-12 20:41:09 +00:00
|
|
|
}
|
|
|
|
|
2022-01-21 08:52:28 +00:00
|
|
|
public function hit(string $base64EpisodeData, string ...$audioPath): RedirectResponse
|
2021-05-19 16:35:13 +00:00
|
|
|
{
|
2021-05-06 14:00:48 +00:00
|
|
|
$session = Services::session();
|
2021-02-27 21:21:26 +00:00
|
|
|
$session->start();
|
2021-05-06 14:00:48 +00:00
|
|
|
|
2021-02-27 21:21:26 +00:00
|
|
|
$serviceName = '';
|
|
|
|
if (isset($_GET['_from'])) {
|
|
|
|
$serviceName = $_GET['_from'];
|
2021-10-20 14:22:58 +00:00
|
|
|
} elseif ($session->get('embed_domain') !== null) {
|
|
|
|
$serviceName = $session->get('embed_domain');
|
2021-08-19 14:08:04 +00:00
|
|
|
} elseif ($session->get('referer') !== null && $session->get('referer') !== '- Direct -') {
|
2021-02-27 21:21:26 +00:00
|
|
|
$serviceName = parse_url($session->get('referer'), PHP_URL_HOST);
|
|
|
|
}
|
2020-10-21 16:04:18 +00:00
|
|
|
|
2020-10-29 17:27:16 +01:00
|
|
|
$episodeData = unpack(
|
|
|
|
'IpodcastId/IepisodeId/IbytesThreshold/IfileSize/Iduration/IpublicationDate',
|
2021-04-14 15:58:40 +00:00
|
|
|
base64_url_decode($base64EpisodeData),
|
2020-10-29 17:27:16 +01:00
|
|
|
);
|
|
|
|
|
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'],
|
2021-04-14 15:58:40 +00:00
|
|
|
$serviceName,
|
2020-10-21 16:04:18 +00:00
|
|
|
);
|
2021-04-14 15:58:40 +00:00
|
|
|
|
2022-01-21 08:52:28 +00:00
|
|
|
return redirect()->to($this->config->getAudioUrl(['podcasts', ...$audioPath]));
|
2020-06-12 20:41:09 +00:00
|
|
|
}
|
|
|
|
}
|