Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • alpha
  • beta
  • develop
  • docs/fix-readme
  • docs/update-vitepress
  • draft/rss-feed
  • feat/dashboard
  • feat/episodes-page-ux
  • feat/generator-user-agent
  • feat/headliner
  • feat/new-languages
  • feat/plugins
  • fix/federation
  • fix/forms-ux
  • i18n
  • main
  • next
  • refactor/transcripts
  • v1.0.0
  • v1.0.0-alpha.1
  • v1.0.0-alpha.10
  • v1.0.0-alpha.11
  • v1.0.0-alpha.12
  • v1.0.0-alpha.13
  • v1.0.0-alpha.14
  • v1.0.0-alpha.15
  • v1.0.0-alpha.16
  • v1.0.0-alpha.17
  • v1.0.0-alpha.18
  • v1.0.0-alpha.19
  • v1.0.0-alpha.2
  • v1.0.0-alpha.20
  • v1.0.0-alpha.21
  • v1.0.0-alpha.22
  • v1.0.0-alpha.23
  • v1.0.0-alpha.24
  • v1.0.0-alpha.25
  • v1.0.0-alpha.26
  • v1.0.0-alpha.27
  • v1.0.0-alpha.28
  • v1.0.0-alpha.29
  • v1.0.0-alpha.3
  • v1.0.0-alpha.30
  • v1.0.0-alpha.31
  • v1.0.0-alpha.32
  • v1.0.0-alpha.33
  • v1.0.0-alpha.34
  • v1.0.0-alpha.35
  • v1.0.0-alpha.36
  • v1.0.0-alpha.37
  • v1.0.0-alpha.38
  • v1.0.0-alpha.39
  • v1.0.0-alpha.4
  • v1.0.0-alpha.40
  • v1.0.0-alpha.41
  • v1.0.0-alpha.42
  • v1.0.0-alpha.43
  • v1.0.0-alpha.44
  • v1.0.0-alpha.45
  • v1.0.0-alpha.46
  • v1.0.0-alpha.47
  • v1.0.0-alpha.48
  • v1.0.0-alpha.49
  • v1.0.0-alpha.5
  • v1.0.0-alpha.50
  • v1.0.0-alpha.51
  • v1.0.0-alpha.52
  • v1.0.0-alpha.53
  • v1.0.0-alpha.54
  • v1.0.0-alpha.55
  • v1.0.0-alpha.56
  • v1.0.0-alpha.57
  • v1.0.0-alpha.58
  • v1.0.0-alpha.59
  • v1.0.0-alpha.6
  • v1.0.0-alpha.60
  • v1.0.0-alpha.61
  • v1.0.0-alpha.62
  • v1.0.0-alpha.63
  • v1.0.0-alpha.64
  • v1.0.0-alpha.65
  • v1.0.0-alpha.66
  • v1.0.0-alpha.67
  • v1.0.0-alpha.68
  • v1.0.0-alpha.69
  • v1.0.0-alpha.7
  • v1.0.0-alpha.70
  • v1.0.0-alpha.71
  • v1.0.0-alpha.72
  • v1.0.0-alpha.73
  • v1.0.0-alpha.74
  • v1.0.0-alpha.75
  • v1.0.0-alpha.76
  • v1.0.0-alpha.77
  • v1.0.0-alpha.78
  • v1.0.0-alpha.79
  • v1.0.0-alpha.8
  • v1.0.0-alpha.80
  • v1.0.0-alpha.9
  • v1.0.0-beta.1
  • v1.0.0-beta.10
  • v1.0.0-beta.11
  • v1.0.0-beta.12
  • v1.0.0-beta.13
  • v1.0.0-beta.14
  • v1.0.0-beta.15
  • v1.0.0-beta.16
  • v1.0.0-beta.17
  • v1.0.0-beta.18
  • v1.0.0-beta.19
  • v1.0.0-beta.2
  • v1.0.0-beta.20
  • v1.0.0-beta.21
  • v1.0.0-beta.22
  • v1.0.0-beta.23
  • v1.0.0-beta.24
  • v1.0.0-beta.3
  • v1.0.0-beta.4
118 results

Target

Select target project
  • adaures/castopod
  • mkljczk/castopod-host
  • spaetz/castopod-host
  • PatrykMis/castopod
  • jonas/castopod
  • ajeremias/castopod
  • misuzu/castopod
  • KrzysztofDomanczyk/castopod
  • Behel/castopod
  • nebulon/castopod
  • ewen/castopod
  • NeoluxConsulting/castopod
  • nateritter/castopod-og
  • prcutler/castopod
14 results
Select Git revision
  • alpha
  • beta
  • develop
  • feat/external-chapters
  • feat/import-externals
  • feat/social-interact
  • main
  • v1.0.0-alpha.1
  • v1.0.0-alpha.10
  • v1.0.0-alpha.11
  • v1.0.0-alpha.12
  • v1.0.0-alpha.13
  • v1.0.0-alpha.14
  • v1.0.0-alpha.15
  • v1.0.0-alpha.16
  • v1.0.0-alpha.17
  • v1.0.0-alpha.18
  • v1.0.0-alpha.19
  • v1.0.0-alpha.2
  • v1.0.0-alpha.20
  • v1.0.0-alpha.21
  • v1.0.0-alpha.22
  • v1.0.0-alpha.23
  • v1.0.0-alpha.24
  • v1.0.0-alpha.25
  • v1.0.0-alpha.26
  • v1.0.0-alpha.27
  • v1.0.0-alpha.28
  • v1.0.0-alpha.29
  • v1.0.0-alpha.3
  • v1.0.0-alpha.30
  • v1.0.0-alpha.31
  • v1.0.0-alpha.32
  • v1.0.0-alpha.33
  • v1.0.0-alpha.34
  • v1.0.0-alpha.35
  • v1.0.0-alpha.36
  • v1.0.0-alpha.37
  • v1.0.0-alpha.38
  • v1.0.0-alpha.39
  • v1.0.0-alpha.4
  • v1.0.0-alpha.40
  • v1.0.0-alpha.41
  • v1.0.0-alpha.42
  • v1.0.0-alpha.43
  • v1.0.0-alpha.44
  • v1.0.0-alpha.45
  • v1.0.0-alpha.46
  • v1.0.0-alpha.47
  • v1.0.0-alpha.48
  • v1.0.0-alpha.49
  • v1.0.0-alpha.5
  • v1.0.0-alpha.50
  • v1.0.0-alpha.51
  • v1.0.0-alpha.52
  • v1.0.0-alpha.53
  • v1.0.0-alpha.54
  • v1.0.0-alpha.55
  • v1.0.0-alpha.56
  • v1.0.0-alpha.57
  • v1.0.0-alpha.58
  • v1.0.0-alpha.59
  • v1.0.0-alpha.6
  • v1.0.0-alpha.60
  • v1.0.0-alpha.61
  • v1.0.0-alpha.62
  • v1.0.0-alpha.63
  • v1.0.0-alpha.64
  • v1.0.0-alpha.65
  • v1.0.0-alpha.66
  • v1.0.0-alpha.67
  • v1.0.0-alpha.68
  • v1.0.0-alpha.69
  • v1.0.0-alpha.7
  • v1.0.0-alpha.70
  • v1.0.0-alpha.71
  • v1.0.0-alpha.72
  • v1.0.0-alpha.73
  • v1.0.0-alpha.74
  • v1.0.0-alpha.75
  • v1.0.0-alpha.76
  • v1.0.0-alpha.77
  • v1.0.0-alpha.78
  • v1.0.0-alpha.79
  • v1.0.0-alpha.8
  • v1.0.0-alpha.80
  • v1.0.0-alpha.9
  • v1.0.0-beta.1
  • v1.0.0-beta.2
  • v1.0.0-beta.3
  • v1.0.0-beta.4
  • v1.0.0-beta.5
  • v1.0.0-beta.6
  • v1.0.0-beta.7
  • v1.0.0-beta.8
95 results
Show changes
Showing
with 0 additions and 1207 deletions
<?php
/**
* Class AnalyticsPodcastsByEpisode
* Entity for AnalyticsPodcastsByEpisode
* @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
namespace Analytics\Entities;
use CodeIgniter\Entity;
class AnalyticsPodcastsByEpisode extends Entity
{
protected $casts = [
'podcast_id' => 'integer',
'episode_id' => 'integer',
'date' => 'datetime',
'hits' => 'integer',
];
}
<?php
/**
* Class AnalyticsPodcastsByHour
* Entity for AnalyticsPodcastsByHour
* @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
namespace Analytics\Entities;
use CodeIgniter\Entity;
class AnalyticsPodcastsByHour extends Entity
{
protected $casts = [
'podcast_id' => 'integer',
'date' => 'datetime',
'hour' => 'integer',
'hits' => 'integer',
];
}
<?php
/**
* Class AnalyticsPodcastsByPlayer
* Entity for AnalyticsPodcastsByPlayer
* @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
namespace Analytics\Entities;
use CodeIgniter\Entity;
class AnalyticsPodcastsByPlayer extends Entity
{
protected $casts = [
'podcast_id' => 'integer',
'app' => '?string',
'device' => '?string',
'os' => '?string',
'is_bot' => 'boolean',
'date' => 'datetime',
'hits' => 'integer',
];
}
<?php
/**
* Class AnalyticsPodcastsByRegion
* Entity for AnalyticsPodcastsByRegion
* @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
namespace Analytics\Entities;
use CodeIgniter\Entity;
class AnalyticsPodcastsByRegion extends Entity
{
protected $casts = [
'podcast_id' => 'integer',
'country_code' => 'string',
'region_code' => '?string',
'latitude' => '?float',
'longitude' => '?float',
'date' => 'datetime',
'hits' => 'integer',
];
public function getCountryCode()
{
return lang('Countries.' . $this->attributes['country_code']);
}
}
<?php
/**
* Class AnalyticsPodcastsByService
* Entity for AnalyticsPodcastsByService
* @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
namespace Analytics\Entities;
use CodeIgniter\Entity;
class AnalyticsPodcastsByService extends Entity
{
/**
* @var string
*/
protected $labels;
protected $casts = [
'podcast_id' => 'integer',
'app' => '?string',
'device' => '?string',
'os' => '?string',
'is_bot' => 'boolean',
'date' => 'datetime',
'hits' => 'integer',
];
public function getLabels()
{
return \Opawg\UserAgentsPhp\UserAgentsRSS::getName(
$this->attributes['labels'],
) ?? $this->attributes['labels'];
}
}
<?php
/**
* Class AnalyticsUnknownUseragents
* Entity for AnalyticsUnknownUseragents
* @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
namespace Analytics\Entities;
use CodeIgniter\Entity;
class AnalyticsUnknownUseragents extends Entity
{
protected $casts = [
'useragent' => 'integer',
'hits' => 'integer',
];
}
<?php
/**
* Class AnalyticsWebsiteByBrowser
* Entity for AnalyticsWebsiteByBrowser
* @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
namespace Analytics\Entities;
use CodeIgniter\Entity;
class AnalyticsWebsiteByBrowser extends Entity
{
protected $casts = [
'podcast_id' => 'integer',
'browser' => 'string',
'date' => 'datetime',
'hits' => 'integer',
];
}
<?php
/**
* Class AnalyticsWebsiteByEntryPage
* Entity for AnalyticsWebsiteByEntryPage
* @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
namespace Analytics\Entities;
use CodeIgniter\Entity;
class AnalyticsWebsiteByEntryPage extends Entity
{
protected $casts = [
'podcast_id' => 'integer',
'entry_page_url' => 'string',
'date' => 'datetime',
'hits' => 'integer',
];
}
<?php
/**
* Class class AnalyticsWebsiteByReferer
* Entity for AnalyticsWebsiteByReferer
* @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
namespace Analytics\Entities;
use CodeIgniter\Entity;
class AnalyticsWebsiteByReferer extends Entity
{
protected $casts = [
'podcast_id' => 'integer',
'referer_url' => 'string',
'date' => 'datetime',
'hits' => 'integer',
];
}
<?php
/**
* @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
use CodeIgniter\Router\Exceptions\RouterException;
if (!function_exists('base64_url_encode')) {
/**
* Encode Base64 for URLs
*/
function base64_url_encode($input)
{
return strtr(base64_encode($input), '+/=', '._-');
}
}
if (!function_exists('base64_url_decode')) {
/**
* Decode Base64 from URL
*/
function base64_url_decode($input)
{
return base64_decode(strtr($input, '._-', '+/='));
}
}
if (!function_exists('generate_episode_analytics_url')) {
/**
* Builds the episode analytics url that redirects to the enclosure url
* after analytics hit.
*
* @param int $podcastId
* @param int $episodeId
* @param string $enclosureUri
* @param int $enclosureDuration
* @param int $enclosureFilesize
* @param int $enclosureHeadersize
* @param \CodeIgniter\I18n\Time $publicationDate
*
* @return string
* @throws RouterException
*/
function generate_episode_analytics_url(
$podcastId,
$episodeId,
$enclosureUri,
$enclosureDuration,
$enclosureFilesize,
$enclosureHeadersize,
$publicationDate
) {
return url_to(
'episode-analytics-hit',
base64_url_encode(
pack(
'I*',
$podcastId,
$episodeId,
// bytes_threshold: number of bytes that must be downloaded for an episode to be counted in download analytics
// - if file is shorter than 60sec, then it's enclosure_filesize
// - if file is longer than 60 seconds then it's enclosure_headersize + 60 seconds
$enclosureDuration <= 60
? $enclosureFilesize
: $enclosureHeadersize +
floor(
(($enclosureFilesize - $enclosureHeadersize) /
$enclosureDuration) *
60,
),
$enclosureFilesize,
$enclosureDuration,
strtotime($publicationDate),
),
),
$enclosureUri,
);
}
}
if (!function_exists('set_user_session_deny_list_ip')) {
/**
* Set user country in session variable, for analytic purposes
*/
function set_user_session_deny_list_ip()
{
$session = \Config\Services::session();
$session->start();
if (!$session->has('denyListIp')) {
$session->set(
'denyListIp',
\Podlibre\Ipcat\IpDb::find($_SERVER['REMOTE_ADDR']) != null,
);
}
}
}
if (!function_exists('set_user_session_location')) {
/**
* Set user country in session variable, for analytic purposes
*/
function set_user_session_location()
{
$session = \Config\Services::session();
$session->start();
$location = [
'countryCode' => 'N/A',
'regionCode' => 'N/A',
'latitude' => null,
'longitude' => null,
];
// Finds location:
if (!$session->has('location')) {
try {
$cityReader = new \GeoIp2\Database\Reader(
WRITEPATH . 'uploads/GeoLite2-City/GeoLite2-City.mmdb',
);
$city = $cityReader->city($_SERVER['REMOTE_ADDR']);
$location = [
'countryCode' => empty($city->country->isoCode)
? 'N/A'
: $city->country->isoCode,
'regionCode' => empty($city->subdivisions[0]->isoCode)
? 'N/A'
: $city->subdivisions[0]->isoCode,
'latitude' => round($city->location->latitude, 3),
'longitude' => round($city->location->longitude, 3),
];
} catch (\Exception $e) {
// If things go wrong the show must go on and the user must be able to download the file
}
$session->set('location', $location);
}
}
}
if (!function_exists('set_user_session_player')) {
/**
* Set user player in session variable, for analytic purposes
*/
function set_user_session_player()
{
$session = \Config\Services::session();
$session->start();
if (!$session->has('player')) {
$playerFound = null;
$userAgent = $_SERVER['HTTP_USER_AGENT'];
try {
$playerFound = \Opawg\UserAgentsPhp\UserAgents::find(
$userAgent,
);
} catch (\Exception $e) {
// If things go wrong the show must go on and the user must be able to download the file
}
if ($playerFound) {
$session->set('player', $playerFound);
} else {
$session->set('player', [
'app' => '- unknown -',
'device' => '',
'os' => '',
'bot' => 0,
]);
// Add to unknown list
try {
$db = \Config\Database::connect();
$procedureNameAnalyticsUnknownUseragents = $db->prefixTable(
'analytics_unknown_useragents',
);
$db->query(
"CALL $procedureNameAnalyticsUnknownUseragents(?)",
[$userAgent],
);
} catch (\Exception $e) {
// If things go wrong the show must go on and the user must be able to download the file
}
}
}
}
}
if (!function_exists('set_user_session_browser')) {
/**
* Set user browser in session variable, for analytic purposes
*
* @return void
*/
function set_user_session_browser()
{
$session = \Config\Services::session();
$session->start();
if (!$session->has('browser')) {
$browserName = '- Other -';
try {
$whichbrowser = new \WhichBrowser\Parser(getallheaders());
$browserName = $whichbrowser->browser->name;
} catch (\Exception $e) {
$browserName = '- Could not get browser name -';
}
if ($browserName == null) {
$browserName = '- Could not get browser name -';
}
$session->set('browser', $browserName);
}
}
}
if (!function_exists('set_user_session_referer')) {
/**
* Set user referer in session variable, for analytic purposes
*
* @return void
*/
function set_user_session_referer()
{
$session = \Config\Services::session();
$session->start();
$newreferer = isset($_SERVER['HTTP_REFERER'])
? $_SERVER['HTTP_REFERER']
: '- Direct -';
$newreferer =
parse_url($newreferer, PHP_URL_HOST) ==
parse_url(current_url(false), PHP_URL_HOST)
? '- Direct -'
: $newreferer;
if (!$session->has('referer') or $newreferer != '- Direct -') {
$session->set('referer', $newreferer);
}
}
}
if (!function_exists('set_user_session_entry_page')) {
/**
* Set user entry page in session variable, for analytic purposes
*
* @return void
*/
function set_user_session_entry_page()
{
$session = \Config\Services::session();
$session->start();
$entryPage = $_SERVER['REQUEST_URI'];
if (!$session->has('entryPage')) {
$session->set('entryPage', $entryPage);
}
}
}
if (!function_exists('podcast_hit')) {
/**
* Counting podcast episode downloads for analytic purposes
* ✅ No IP address is ever stored on the server.
* ✅ Only aggregate data is stored in the database.
* We follow IAB Podcast Measurement Technical Guidelines Version 2.0:
* https://iabtechlab.com/standards/podcast-measurement-guidelines/
* https://iabtechlab.com/wp-content/uploads/2017/12/Podcast_Measurement_v2-Dec-20-2017.pdf
* ✅ Rolling 24-hour window
* ✅ Castopod does not do pre-load
* ✅ IP deny list https://github.com/client9/ipcat
* ✅ User-agent Filtering https://github.com/opawg/user-agents
* ✅ RSS User-agent https://github.com/opawg/podcast-rss-useragents
* ✅ Ignores 2 bytes range "Range: 0-1" (performed by official Apple iOS Podcast app)
* ✅ In case of partial content, adds up all requests to check >1mn was downloaded
* ✅ Identifying Uniques is done with a combination of IP Address and User Agent
* @param integer $podcastId The podcast ID
* @param integer $episodeId The Episode ID
* @param integer $bytesThreshold The minimum total number of bytes that must be downloaded so that an episode is counted (>1mn)
* @param integer $fileSize The podcast complete file size
* @param string $serviceName The name of the service that had fetched the RSS feed
*
* @return void
*/
function podcast_hit(
$podcastId,
$episodeId,
$bytesThreshold,
$fileSize,
$duration,
$publicationDate,
$serviceName
) {
$session = \Config\Services::session();
$session->start();
// We try to count (but if things went wrong the show should go on and the user should be able to download the file):
try {
// If the user IP is denied it's probably a bot:
if ($session->get('denyListIp')) {
$session->get('player')['bot'] = true;
}
//We get the HTTP header field `Range`:
$httpRange = isset($_SERVER['HTTP_RANGE'])
? $_SERVER['HTTP_RANGE']
: null;
// We create a sha1 hash for this IP_Address+User_Agent+Episode_ID (used to count only once multiple episode downloads):
$episodeHashId =
'_IpUaEp_' .
sha1(
$_SERVER['REMOTE_ADDR'] .
'_' .
$_SERVER['HTTP_USER_AGENT'] .
'_' .
$episodeId,
);
// Was this episode downloaded in the past 24h:
$downloadedBytes = cache($episodeHashId);
// Rolling window is 24 hours (86400 seconds):
$rollingTTL = 86400;
if ($downloadedBytes) {
// In case it was already downloaded, TTL should be adjusted (rolling window is 24h since 1st download):
$rollingTTL =
cache()->getMetadata($episodeHashId)['expire'] - time();
} else {
// If it was never downloaded that means that zero byte were downloaded:
$downloadedBytes = 0;
}
// If the number of downloaded bytes was previously below the 1mn threshold we go on:
// (Otherwise it means that this was already counted, therefore we don't do anything)
if ($downloadedBytes < $bytesThreshold) {
// If HTTP_RANGE is null we are downloading the complete file:
if (!$httpRange) {
$downloadedBytes = $fileSize;
} else {
// [0-1] bytes range requests are used (by Apple) to check that file exists and that 206 partial content is working.
// We don't count these requests:
if ($httpRange != 'bytes=0-1') {
// We calculate how many bytes are being downloaded based on HTTP_RANGE values:
$ranges = explode(',', substr($httpRange, 6));
foreach ($ranges as $range) {
$parts = explode('-', $range);
$downloadedBytes += empty($parts[1])
? $fileSize
: $parts[1] -
(empty($parts[0]) ? 0 : $parts[0]);
}
}
}
// We save the number of downloaded bytes for this user and this episode:
cache()->save($episodeHashId, $downloadedBytes, $rollingTTL);
// If more that 1mn was downloaded, that's a hit, we send that to the database:
if ($downloadedBytes >= $bytesThreshold) {
$db = \Config\Database::connect();
$procedureName = $db->prefixTable('analytics_podcasts');
$age = intdiv(time() - $publicationDate, 86400);
// We create a sha1 hash for this IP_Address+User_Agent+Podcast_ID (used to count unique listeners):
$listenerHashId =
'_IpUaPo_' .
sha1(
$_SERVER['REMOTE_ADDR'] .
'_' .
$_SERVER['HTTP_USER_AGENT'] .
'_' .
$podcastId,
);
$newListener = 1;
// Has this listener already downloaded an episode today:
$downloadsByUser = cache($listenerHashId);
// We add one download
if ($downloadsByUser) {
$newListener = 0;
$downloadsByUser++;
} else {
$downloadsByUser = 1;
}
// Listener count is calculated from 00h00 to 23h59:
$midnightTTL = strtotime('tomorrow') - time();
// We save the download count for this user until midnight:
cache()->save(
$listenerHashId,
$downloadsByUser,
$midnightTTL,
);
$db->query(
"CALL $procedureName(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);",
[
$podcastId,
$episodeId,
$session->get('location')['countryCode'],
$session->get('location')['regionCode'],
$session->get('location')['latitude'],
$session->get('location')['longitude'],
$serviceName,
$session->get('player')['app'],
$session->get('player')['device'],
$session->get('player')['os'],
$session->get('player')['bot'],
$fileSize,
$duration,
$age,
$newListener,
],
);
}
}
} catch (\Exception $e) {
// If things go wrong the show must go on and the user must be able to download the file
log_message('critical', $e);
}
}
}
<?php
/**
* Class AnalyticsPodcastByCountryModel
* Model for analytics_podcasts_by_country table in database
* @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
namespace Analytics\Models;
use CodeIgniter\Model;
class AnalyticsPodcastByCountryModel extends Model
{
protected $table = 'analytics_podcasts_by_country';
protected $allowedFields = [];
protected $returnType = \Analytics\Entities\AnalyticsPodcastsByCountry::class;
protected $useSoftDeletes = false;
protected $useTimestamps = false;
/**
* Gets country data for a podcast
*
* @param int $podcastId
*
* @return array
*/
public function getDataWeekly(int $podcastId): array
{
if (
!($found = cache(
"{$podcastId}_analytics_podcast_by_country_weekly",
))
) {
$oneWeekAgo = date('Y-m-d', strtotime('-1 week'));
$found = $this->select('country_code as labels')
->selectSum('hits', 'values')
->where([
'podcast_id' => $podcastId,
'date >' => $oneWeekAgo,
])
->groupBy('labels')
->orderBy('values', 'DESC')
->findAll();
cache()->save(
"{$podcastId}_analytics_podcast_by_country_weekly",
$found,
600,
);
}
return $found;
}
/**
* Gets country data for a podcast
*
* @param int $podcastId
*
* @return array
*/
public function getDataYearly(int $podcastId): array
{
if (
!($found = cache(
"{$podcastId}_analytics_podcast_by_country_yearly",
))
) {
$oneYearAgo = date('Y-m-d', strtotime('-1 year'));
$found = $this->select('country_code as labels')
->selectSum('hits', 'values')
->where([
'podcast_id' => $podcastId,
'date >' => $oneYearAgo,
])
->groupBy('labels')
->orderBy('values', 'DESC')
->findAll();
cache()->save(
"{$podcastId}_analytics_podcast_by_country_yearly",
$found,
600,
);
}
return $found;
}
}
<?php
/**
* Class AnalyticsPodcastByEpisodeModel
* Model for analytics_podcasts_by_episodes table in database
* @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
namespace Analytics\Models;
use CodeIgniter\Model;
class AnalyticsPodcastByEpisodeModel extends Model
{
protected $table = 'analytics_podcasts_by_episode';
protected $allowedFields = [];
protected $returnType = \Analytics\Entities\AnalyticsPodcastsByEpisode::class;
protected $useSoftDeletes = false;
protected $useTimestamps = false;
/**
* @param int $podcastId
* @param int $episodeId
*
* @return array
*/
public function getDataByDay(int $podcastId, int $episodeId): array
{
if (
!($found = cache(
"{$podcastId}_{$episodeId}_analytics_podcast_by_episode_by_day",
))
) {
$found = $this->select('date as labels')
->selectSum('hits', 'values')
->where([
'episode_id' => $episodeId,
'podcast_id' => $podcastId,
'age <' => 60,
])
->groupBy('labels')
->orderBy('labels', 'ASC')
->findAll();
cache()->save(
"{$podcastId}_{$episodeId}_analytics_podcast_by_episode_by_day",
$found,
600,
);
}
return $found;
}
/**
* @param int $podcastId
* @param int $episodeId
*
* @return array
*/
public function getDataByMonth(int $podcastId, int $episodeId = null): array
{
if (
!($found = cache(
"{$podcastId}_{$episodeId}_analytics_podcast_by_episode_by_month",
))
) {
$found = $this->select('DATE_FORMAT(date,"%Y-%m-01") as labels')
->selectSum('hits', 'values')
->where([
'episode_id' => $episodeId,
'podcast_id' => $podcastId,
])
->groupBy('labels')
->orderBy('labels', 'ASC')
->findAll();
cache()->save(
"{$podcastId}_{$episodeId}_analytics_podcast_by_episode_by_month",
$found,
600,
);
}
return $found;
}
}
<?php
/**
* Class AnalyticsPodcastByHour
* Model for analytics_podcasts_by_hour table in database
* @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
namespace Analytics\Models;
use CodeIgniter\Model;
class AnalyticsPodcastByHourModel extends Model
{
protected $table = 'analytics_podcasts_by_hour';
protected $allowedFields = [];
protected $returnType = \Analytics\Entities\AnalyticsPodcastsByHour::class;
protected $useSoftDeletes = false;
protected $useTimestamps = false;
/**
* Gets hits data for a podcast
*
* @param int $podcastId
*
* @return array
*/
public function getData(int $podcastId): array
{
if (!($found = cache("{$podcastId}_analytics_podcasts_by_hour"))) {
$found = $this->select(
'right(concat(\'0\',hour,\'h\'),3) as labels',
)
->selectSum('hits', 'values')
->where([
'podcast_id' => $podcastId,
'date >' => date('Y-m-d', strtotime('-60 days')),
])
->groupBy('labels')
->orderBy('labels', 'ASC')
->findAll();
cache()->save(
"{$podcastId}_analytics_podcasts_by_hour",
$found,
600,
);
}
return $found;
}
}
<?php
/**
* Class AnalyticsPodcastByPlayerModel
* Model for analytics_podcasts_by_player table in database
* @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
namespace Analytics\Models;
use CodeIgniter\Model;
class AnalyticsPodcastByPlayerModel extends Model
{
protected $table = 'analytics_podcasts_by_player';
protected $allowedFields = [];
protected $returnType = \Analytics\Entities\AnalyticsPodcastsByPlayer::class;
protected $useSoftDeletes = false;
protected $useTimestamps = false;
/**
* Gets player data for a podcast
*
* @param int $podcastId
*
* @return array
*/
public function getDataByAppWeekly(int $podcastId): array
{
if (
!($found = cache(
"{$podcastId}_analytics_podcasts_by_player_by_app_weekly",
))
) {
$oneWeekAgo = date('Y-m-d', strtotime('-1 week'));
$found = $this->select('app as labels')
->selectSum('hits', 'values')
->where([
'podcast_id' => $podcastId,
'app !=' => '',
'is_bot' => 0,
'date >' => $oneWeekAgo,
])
->groupBy('labels')
->orderBy('values', 'DESC')
->findAll();
cache()->save(
"{$podcastId}_analytics_podcasts_by_player_by_app_weekly",
$found,
600,
);
}
return $found;
}
/**
* Gets player data for a podcast
*
* @param int $podcastId
*
* @return array
*/
public function getDataByAppYearly(int $podcastId): array
{
if (
!($found = cache(
"{$podcastId}_analytics_podcasts_by_player_by_app_yearly",
))
) {
$oneYearAgo = date('Y-m-d', strtotime('-1 year'));
$found = $this->select('app as labels')
->selectSum('hits', 'values')
->where([
'podcast_id' => $podcastId,
'app !=' => '',
'is_bot' => 0,
'date >' => $oneYearAgo,
])
->groupBy('labels')
->orderBy('values', 'DESC')
->findAll();
cache()->save(
"{$podcastId}_analytics_podcasts_by_player_by_app_yearly",
$found,
600,
);
}
return $found;
}
/**
* Gets os data for a podcast
*
* @param int $podcastId
*
* @return array
*/
public function getDataByOsWeekly(int $podcastId): array
{
if (
!($found = cache(
"{$podcastId}_analytics_podcasts_by_player_by_os_weekly",
))
) {
$oneWeekAgo = date('Y-m-d', strtotime('-1 week'));
$found = $this->select('os as labels')
->selectSum('hits', 'values')
->where([
'podcast_id' => $podcastId,
'app !=' => '',
'os !=' => '',
'is_bot' => 0,
'date >' => $oneWeekAgo,
])
->groupBy('labels')
->orderBy('values', 'DESC')
->findAll();
cache()->save(
"{$podcastId}_analytics_podcasts_by_player_by_os_weekly",
$found,
600,
);
}
return $found;
}
/**
* Gets player data for a podcast
*
* @param int $podcastId
*
* @return array
*/
public function getDataByDeviceWeekly(int $podcastId): array
{
if (
!($found = cache(
"{$podcastId}_analytics_podcasts_by_player_by_device_weekly",
))
) {
$oneWeekAgo = date('Y-m-d', strtotime('-1 week'));
$found = $this->select('device as labels')
->selectSum('hits', 'values')
->where([
'podcast_id' => $podcastId,
'device !=' => '',
'is_bot' => 0,
'date >' => $oneWeekAgo,
])
->groupBy('labels')
->orderBy('values', 'DESC')
->findAll();
cache()->save(
"{$podcastId}_analytics_podcasts_by_player_by_device_weekly",
$found,
600,
);
}
return $found;
}
/**
* Gets bots data for a podcast
*
* @param int $podcastId
*
* @return array
*/
public function getDataBots(int $podcastId): array
{
if (
!($found = cache("{$podcastId}_analytics_podcasts_by_player_bots"))
) {
$oneYearAgo = date('Y-m-d', strtotime('-1 year'));
$found = $this->select('DATE_FORMAT(date,"%Y-%m-01") as labels')
->selectSum('hits', 'values')
->where([
'podcast_id' => $podcastId,
'is_bot' => 1,
'date >' => $oneYearAgo,
])
->groupBy('labels')
->orderBy('labels', 'ASC')
->findAll();
cache()->save(
"{$podcastId}_analytics_podcasts_by_player_bots",
$found,
600,
);
}
return $found;
}
}
<?php
/**
* Class AnalyticsPodcastByRegionModel
* Model for analytics_podcasts_by_region table in database
* @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
namespace Analytics\Models;
use CodeIgniter\Model;
class AnalyticsPodcastByRegionModel extends Model
{
protected $table = 'analytics_podcasts_by_region';
protected $allowedFields = [];
protected $returnType = \Analytics\Entities\AnalyticsPodcastsByRegion::class;
protected $useSoftDeletes = false;
protected $useTimestamps = false;
/**
* Gets region data for a podcast
*
* @param int $podcastId
*
* @return array
*/
public function getData(int $podcastId): array
{
$locale = service('request')->getLocale();
if (
!($found = cache(
"{$podcastId}_analytics_podcast_by_region_{$locale}",
))
) {
$found = $this->select('country_code, region_code')
->selectSum('hits', 'value')
->selectAvg('latitude')
->selectAvg('longitude')
->groupBy('country_code, region_code')
->where([
'podcast_id' => $podcastId,
'date >' => date('Y-m-d', strtotime('-1 week')),
])
->orderBy('value', 'DESC')
->findAll();
cache()->save(
"{$podcastId}_analytics_podcast_by_region_{$locale}",
$found,
600,
);
}
return $found;
}
}
<?php
/**
* Class AnalyticsPodcastByServiceModel
* Model for analytics_podcasts_by_player table in database
* @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
namespace Analytics\Models;
use CodeIgniter\Model;
class AnalyticsPodcastByServiceModel extends Model
{
protected $table = 'analytics_podcasts_by_player';
protected $allowedFields = [];
protected $returnType = \Analytics\Entities\AnalyticsPodcastsByService::class;
protected $useSoftDeletes = false;
protected $useTimestamps = false;
/**
* Gets service data for a podcast
*
* @param int $podcastId
*
* @return array
*/
public function getDataByServiceWeekly(int $podcastId): array
{
if (
!($found = cache(
"{$podcastId}_analytics_podcasts_by_service_weekly",
))
) {
$oneWeekAgo = date('Y-m-d', strtotime('-1 week'));
$found = $this->select('service as labels')
->selectSum('hits', 'values')
->where([
'podcast_id' => $podcastId,
'service !=' => '',
'is_bot' => 0,
'date >' => $oneWeekAgo,
])
->groupBy('labels')
->orderBy('values', 'DESC')
->findAll();
cache()->save(
"{$podcastId}_analytics_podcasts_by_service_weekly",
$found,
600,
);
}
return $found;
}
}