mirror of
https://github.com/ad-aures/castopod.git
synced 2026-04-11 10:46:43 +02:00
refactor(analytics): move all analytics files to a new Libraries/Analytics folder
- add page hit on podcast activity page - update development docs
This commit is contained in:
parent
1c0d6cee44
commit
247ae1824f
59 changed files with 865 additions and 752 deletions
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @copyright 2020 Podlibre
|
||||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
||||
* @link https://castopod.org/
|
||||
*/
|
||||
|
||||
namespace Analytics\Controllers;
|
||||
|
||||
use CodeIgniter\Controller;
|
||||
|
||||
class EpisodeAnalyticsController extends Controller
|
||||
{
|
||||
/**
|
||||
* 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'];
|
||||
|
||||
/**
|
||||
* @var \Analytics\Config\Analytics
|
||||
*/
|
||||
protected $config;
|
||||
/**
|
||||
* 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);
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Preload any models, libraries, etc, here.
|
||||
//--------------------------------------------------------------------
|
||||
// E.g.:
|
||||
// $this->session = \Config\Services::session();
|
||||
|
||||
set_user_session_deny_list_ip();
|
||||
set_user_session_location();
|
||||
set_user_session_player();
|
||||
|
||||
$this->config = config('Analytics');
|
||||
}
|
||||
|
||||
// Add one hit to this episode:
|
||||
public function hit($base64EpisodeData, ...$enclosureUri)
|
||||
{
|
||||
$session = \Config\Services::session();
|
||||
$session->start();
|
||||
$serviceName = '';
|
||||
if (isset($_GET['_from'])) {
|
||||
$serviceName = $_GET['_from'];
|
||||
} elseif (!empty($session->get('embeddable_player_domain'))) {
|
||||
$serviceName = $session->get('embeddable_player_domain');
|
||||
} elseif ($session->get('referer') !== '- Direct -') {
|
||||
$serviceName = parse_url($session->get('referer'), PHP_URL_HOST);
|
||||
}
|
||||
|
||||
$episodeData = unpack(
|
||||
'IpodcastId/IepisodeId/IbytesThreshold/IfileSize/Iduration/IpublicationDate',
|
||||
base64_url_decode($base64EpisodeData),
|
||||
);
|
||||
|
||||
podcast_hit(
|
||||
$episodeData['podcastId'],
|
||||
$episodeData['episodeId'],
|
||||
$episodeData['bytesThreshold'],
|
||||
$episodeData['fileSize'],
|
||||
$episodeData['duration'],
|
||||
$episodeData['publicationDate'],
|
||||
$serviceName,
|
||||
);
|
||||
|
||||
return redirect()->to($this->config->getEnclosureUrl($enclosureUri));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue