Skip to content

Commit 940711f

Browse files
committed
add: use kirby component in stats
1 parent d3d8cf7 commit 940711f

File tree

6 files changed

+441
-1545
lines changed

6 files changed

+441
-1545
lines changed

index.js

Lines changed: 24 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.php

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
'Plugin\Podcaster\PodcasterUtils' => 'utils/PodcasterUtils.php',
1414
'Plugin\Podcaster\PodcasterAudioUtils' => 'utils/PodcasterAudioUtils.php',
1515
'Plugin\Podcaster\PodcasterStats' => 'utils/PodcasterStats.php',
16+
'Plugin\Podcaster\PodcasterStatsMySql' => 'utils/PodcasterStatsMatomo.php',
1617
'Plugin\Podcaster\PodcasterStatsMySql' => 'utils/PodcasterStatsMysql.php',
1718
'Plugin\Podcaster\PodcasterStatsFile' => 'utils/PodcasterStatsFile.php',
1819
'Plugin\Podcaster\PodcasterStatsPodTrac' => 'utils/PodcasterStatsPodTrac.php',
@@ -89,48 +90,27 @@
8990
'pattern' => '(:all)/' . option('mauricerenck.podcaster.defaultFeed', 'feed'),
9091
'action' => function ($slug) {
9192
$podcasterUtils = new PodcasterUtils();
92-
93-
$feed = $podcasterUtils->getPageFromSlug($slug . '/' . option('mauricerenck.podcaster.defaultFeed', 'feed'));
93+
$podcast = $podcasterUtils->getPageFromSlug($slug . '/' . option('mauricerenck.podcaster.defaultFeed', 'feed'));
9494

9595
if (option('mauricerenck.podcaster.statsInternal') === true) {
9696
$stats = new PodcasterStats();
9797
$trackingDate = time();
98-
$stats->increaseFeedVisits($feed, $trackingDate);
98+
$stats->increaseFeedVisits($podcast, $trackingDate);
9999
}
100100

101101
if ($feed->podcasterMatomoFeedEnabled()->isTrue()) {
102-
$matomo = new PiwikTracker($feed->podcasterMatomoFeedSiteId(), option('mauricerenck.podcaster.matomoBaseUrl'));
103-
104-
$matomo->setTokenAuth(option('mauricerenck.podcaster.matomoToken'));
105-
$matomo->disableSendImageResponse();
106-
$matomo->disableCookieSupport();
107-
$matomo->setUrl($feed->url());
108-
$matomo->setIp($_SERVER['REMOTE_ADDR']);
109-
110-
if ($feed->podcasterMatomoFeedPage()->isNotEmpty() && $feed->podcasterMatomoFeedPage()->isTrue()) {
111-
$matomo->doTrackPageView($feed->podcasterTitle());
112-
}
113-
114-
if ($feed->podcasterMatomoFeedGoalId()->isNotEmpty()) {
115-
$matomo->doTrackGoal($feed->podcasterMatomoFeedGoalId(), 1);
116-
}
117-
118-
if ($feed->podcasterMatomoFeedEventName()->isNotEmpty()) {
119-
$matomo->doTrackEvent($feed->podcasterTitle(), $feed->podcasterMatomoFeedEventName(), 1);
120-
}
121-
122-
if ($feed->podcasterMatomoFeedAction()->isTrue()) {
123-
$matomo->doTrackAction($feed->url(), 'download');
124-
}
102+
$matomoUtils = new PodcasterStatsMatomo($podcast->podcasterMatomoSiteId(), $episode);
103+
$matomoUtils->trackEpisodeDownload($podcast);
125104
}
126105

127-
return new Response($feed->render(), 'text/xml');
106+
return new Response($podcast->render(), 'text/xml');
128107
}
129108
],
130109
[
131110
'pattern' => '(:all)/' . option('mauricerenck.podcaster.downloadTriggerPath', 'download') . '/(:any)',
132111
'action' => function ($slug, $filename) {
133112
$podcasterUtils = new PodcasterUtils();
113+
134114
$episode = $podcasterUtils->getPageFromSlug($slug);
135115
$podcasterUtils->setCurrentEpisode($episode);
136116

@@ -143,26 +123,8 @@
143123
}
144124

145125
if ($podcast->podcasterMatomoEnabled()->isTrue()) {
146-
$matomo = new PiwikTracker($podcast->podcasterMatomoSiteId(), option('mauricerenck.podcaster.matomoBaseUrl'));
147-
148-
// setup
149-
$matomo->setTokenAuth(option('mauricerenck.podcaster.matomoToken'));
150-
$matomo->disableSendImageResponse();
151-
$matomo->disableCookieSupport();
152-
$matomo->setUrl($episode->url());
153-
$matomo->setIp($_SERVER['REMOTE_ADDR']);
154-
155-
if ($podcast->podcasterMatomoGoalId()->isNotEmpty()) {
156-
$matomo->doTrackGoal($podcast->podcasterMatomoGoalId(), 1);
157-
}
158-
159-
if ($podcast->podcasterMatomoEventName()->isNotEmpty()) {
160-
$matomo->doTrackEvent($podcast->podcasterTitle(), $episode->title(), $podcast->podcasterMatomoEventName());
161-
}
162-
163-
if ($podcast->podcasterMatomoAction()->isTrue()) {
164-
$matomo->doTrackAction($episode->url(), 'download');
165-
}
126+
$matomoUtils = new PodcasterStatsMatomo($podcast->podcasterMatomoSiteId(), $episode);
127+
$matomoUtils->trackEpisodeDownload($podcast);
166128
}
167129

168130
$filename = str_replace('.mp3', '', $filename);

package.json

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
{
2-
"name": "podcaster",
3-
"version": "1.2.5",
4-
"description": "A Kirby Podcast Plugin",
5-
"main": "index.js",
6-
"author": "Maurice Renck",
7-
"scripts": {
8-
"dev": "parcel watch src/index.js --no-source-maps -d ./",
9-
"build": "parcel build src/index.js --no-source-maps -d ./"
10-
},
11-
"devDependencies": {
12-
"@vue/component-compiler-utils": "^3.0.0",
13-
"cssnano": "^4.1.10",
14-
"sass": "^1.20.3",
15-
"vue-template-compiler": "^2.6.10"
16-
},
17-
"dependencies": {
18-
"date-fns": "2.0.0-alpha.31",
19-
"frappe-charts": "^1.2.0",
20-
"vue": "^2.2.4",
21-
"vue-hot-reload-api": "^2.3.3"
22-
}
23-
}
2+
"name": "podcaster",
3+
"version": "1.2.6",
4+
"description": "A Kirby Podcast Plugin",
5+
"main": "index.js",
6+
"author": "Maurice Renck",
7+
"scripts": {
8+
"dev": "parcel watch src/index.js --no-source-maps -d ./",
9+
"build": "parcel build src/index.js --no-source-maps -d ./"
10+
},
11+
"devDependencies": {
12+
"@vue/component-compiler-utils": "^3.0.0",
13+
"cssnano": "^4.1.10",
14+
"sass": "^1.20.3",
15+
"vue-template-compiler": "^2.6.10"
16+
},
17+
"dependencies": {
18+
"date-fns": "2.11.0",
19+
"frappe-charts": "^1.2.0",
20+
"vue": "^2.2.4",
21+
"vue-hot-reload-api": "^2.3.3"
22+
}
23+
}

src/components/Episode.vue

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@
66
</div>
77
<k-text>{{ error }}</k-text>
88
<k-headline>{{ headline }}</k-headline>
9-
<table id="episodeStats">
10-
<tr v-for="episode in episodes">
11-
<td>{{ episode.downloads }}</td>
12-
<td>{{ episode.title }}</td>
13-
</tr>
14-
</table>
9+
<k-list :items="episodes" />
1510

1611
</section>
1712
</template>
@@ -81,7 +76,7 @@ export default {
8176
},
8277
computeStats(stats) {
8378
const episodeStats = stats.episodes.map(function(episode) {
84-
return { title: episode.episode.replace(/-/g, ' '), downloads: episode.downloaded }
79+
return { text: episode.episode.replace(/-/g, ' '), info: episode.downloaded }
8580
})
8681
8782
return episodeStats

src/components/TopTen.vue

Lines changed: 88 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -2,109 +2,113 @@
22
<section class="k-modified-section">
33
<k-text>{{ error }}</k-text>
44
<k-headline>{{ headline }}</k-headline>
5-
<table id="topTen">
6-
<tr v-for="episode in topEpisodes">
7-
<td>{{ episode.downloads }}</td>
8-
<td>{{ episode.title }}</td>
9-
</tr>
10-
</table>
115

6+
<k-list :items="topEpisodes" />
127
</section>
138
</template>
149

1510
<script>
16-
import sanitizeTitle from '../utils'
11+
import sanitizeTitle from "../utils";
1712
1813
export default {
19-
data: function() {
20-
return {
21-
limit: 10,
22-
headline: null,
23-
topEpisodes: [],
24-
error: null,
25-
podcasterSlug: null
14+
data: function() {
15+
return {
16+
limit: 10,
17+
headline: null,
18+
topEpisodes: [],
19+
error: null,
20+
podcasterSlug: null
21+
};
22+
},
23+
mounted() {
24+
this.podcasterSlug = sanitizeTitle(this.pageValues.podcastertitle);
25+
this.getStats();
26+
},
27+
created: function() {
28+
this.load().then(response => {
29+
this.headline = response.headline;
30+
});
31+
},
32+
computed: {
33+
pageValues() {
34+
return this.$store.getters["content/values"](this.id);
35+
}
36+
},
37+
methods: {
38+
getStats() {
39+
fetch(
40+
"/api/podcaster/stats/" + this.podcasterSlug + "/top/" + this.limit,
41+
{
42+
method: "GET",
43+
headers: {
44+
"X-CSRF": panel.csrf
45+
}
2646
}
27-
},
28-
mounted() {
29-
this.podcasterSlug = sanitizeTitle(this.pageValues.podcastertitle)
30-
this.getStats()
31-
},
32-
created: function() {
33-
this.load().then(response => {
34-
this.headline = response.headline;
47+
)
48+
.then(response => {
49+
if (response.status !== 200) {
50+
throw "You are tracking your downloads, using the file method. Stats are currently available only when using mysql";
51+
}
52+
53+
return response;
54+
})
55+
.then(response => response.json())
56+
.then(response => {
57+
this.topEpisodes = this.computeStats(response.stats);
58+
})
59+
.catch(error => {
60+
this.error = error;
3561
});
36-
},
37-
computed: {
38-
pageValues() {
39-
return this.$store.getters['content/values'](this.id)
40-
},
4162
},
42-
methods: {
43-
getStats() {
44-
fetch('/api/podcaster/stats/'+ this.podcasterSlug + '/top/' + this.limit, {
45-
method: 'GET',
46-
headers: {
47-
'X-CSRF': panel.csrf,
48-
},
49-
})
50-
.then(response => {
51-
if(response.status !== 200) {
52-
throw 'You are tracking your downloads, using the file method. Stats are currently available only when using mysql'
53-
}
54-
55-
return response
56-
})
57-
.then(response => response.json())
58-
.then(response => {
59-
this.topEpisodes = this.computeStats(response.stats)
60-
})
61-
.catch(error => {
62-
this.error = error
63-
})
64-
},
65-
computeStats(stats) {
66-
const episodeStats = stats.map(function(episode) {
67-
return { title: episode.episode.replace(/-/g, ' '), downloads: episode.downloaded }
68-
})
69-
70-
return episodeStats
71-
},
63+
computeStats(stats) {
64+
const episodeStats = stats.map(function(episode) {
65+
return {
66+
text: episode.episode.replace(/-/g, " "),
67+
info: episode.downloaded,
68+
icon: {
69+
type: "file",
70+
back: "black"
71+
}
72+
};
73+
});
7274
73-
},
74-
}
75+
return episodeStats;
76+
}
77+
}
78+
};
7579
</script>
7680

7781
<style lang="scss">
7882
.k-section-name-podstatsTop {
79-
table {
80-
width: 100%;
81-
border: 1px solid #ccc;
82-
background: #fff;
83-
margin-top: 0.5em;
84-
}
83+
table {
84+
width: 100%;
85+
border: 1px solid #ccc;
86+
background: #fff;
87+
margin-top: 0.5em;
88+
}
8589
86-
td {
87-
border-bottom: 1px solid #ccc;
88-
line-height: 2;
89-
padding: 0 10px;
90-
}
90+
td {
91+
border-bottom: 1px solid #ccc;
92+
line-height: 2;
93+
padding: 0 10px;
94+
}
9195
92-
td:first-child {
93-
text-align: right;
94-
}
96+
td:first-child {
97+
text-align: right;
98+
}
9599
96-
.podcaster-prev-next {
97-
display: inline;
98-
text-align: right;
99-
color: #666;
100-
}
100+
.podcaster-prev-next {
101+
display: inline;
102+
text-align: right;
103+
color: #666;
104+
}
101105
102-
.k-headline {
103-
display: inline;
104-
}
106+
.k-headline {
107+
display: inline;
108+
}
105109
106-
.k-text {
107-
color: red;
108-
}
110+
.k-text {
111+
color: red;
112+
}
109113
}
110114
</style>

0 commit comments

Comments
 (0)