Hide spammy referrers by default.
Added the panel_statistics_spam_hide phrase. Added the panel_statistics_spam_show phrase.
This commit is contained in:
parent
182a5640eb
commit
b44f7bc157
|
@ -424,6 +424,13 @@ type PanelAnalyticsAgentsPage struct {
|
||||||
TimeRange string
|
TimeRange string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PanelAnalyticsReferrersPage struct {
|
||||||
|
*BasePanelPage
|
||||||
|
ItemList []PanelAnalyticsAgentsItem
|
||||||
|
TimeRange string
|
||||||
|
ShowSpam bool
|
||||||
|
}
|
||||||
|
|
||||||
type PanelAnalyticsRoutePage struct {
|
type PanelAnalyticsRoutePage struct {
|
||||||
*BasePanelPage
|
*BasePanelPage
|
||||||
Route string
|
Route string
|
||||||
|
|
|
@ -887,6 +887,9 @@
|
||||||
"panel_statistics_memory_head":"Memory Usage",
|
"panel_statistics_memory_head":"Memory Usage",
|
||||||
"panel_statistics_active_memory_head":"Active Memory",
|
"panel_statistics_active_memory_head":"Active Memory",
|
||||||
|
|
||||||
|
"panel_statistics_spam_hide":"Hide Spam",
|
||||||
|
"panel_statistics_spam_show":"Show Spam",
|
||||||
|
|
||||||
"panel_statistics_time_range_one_year":"1 year",
|
"panel_statistics_time_range_one_year":"1 year",
|
||||||
"panel_statistics_time_range_three_months":"3 months",
|
"panel_statistics_time_range_three_months":"3 months",
|
||||||
"panel_statistics_time_range_one_month":"1 month",
|
"panel_statistics_time_range_one_month":"1 month",
|
||||||
|
|
|
@ -885,9 +885,23 @@ function mainInit(){
|
||||||
});
|
});
|
||||||
|
|
||||||
// The time range selector for the time graphs in the Control Panel
|
// The time range selector for the time graphs in the Control Panel
|
||||||
$(".timeRangeSelector").change(function(){
|
/*$(".timeRangeSelector").change(function(){
|
||||||
console.log("Changed the time range to " + this.options[this.selectedIndex].getAttribute("val"));
|
console.log("Changed the time range to " + this.options[this.selectedIndex].getAttribute("val"));
|
||||||
window.location = this.form.getAttribute("action")+"?timeRange=" + this.options[this.selectedIndex].getAttribute("val"); // Do a redirect as a form submission refuses to work properly
|
window.location = this.form.getAttribute("action")+"?timeRange=" + this.options[this.selectedIndex].getAttribute("val"); // Do a redirect as a form submission refuses to work properly
|
||||||
|
});*/
|
||||||
|
$(".autoSubmitRedirect").change(function(){
|
||||||
|
let elems = this.form.elements;
|
||||||
|
let s = "";
|
||||||
|
for(let i = 0; i < elems.length; i++) {
|
||||||
|
let elem = elems[i];
|
||||||
|
if(elem.nodeName=="SELECT") {
|
||||||
|
s += elem.name + "=" + elem.options[elem.selectedIndex].getAttribute("val") + "&";
|
||||||
|
}
|
||||||
|
// TODO: Implement other element types...
|
||||||
|
}
|
||||||
|
if(s.length > 0) s = "?" + s.substr(0, s.length-1);
|
||||||
|
|
||||||
|
window.location = this.form.getAttribute("action") + s; // Do a redirect as a form submission refuses to work properly
|
||||||
});
|
});
|
||||||
|
|
||||||
$(".unix_to_24_hour_time").each(function(){
|
$(".unix_to_24_hour_time").each(function(){
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
c "github.com/Azareal/Gosora/common"
|
c "github.com/Azareal/Gosora/common"
|
||||||
|
@ -1036,6 +1037,8 @@ func AnalyticsLanguages(w http.ResponseWriter, r *http.Request, user c.User) c.R
|
||||||
return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right", "analytics", "panel_analytics_langs", pi})
|
return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right", "analytics", "panel_analytics_langs", pi})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var spamDomains = []string{"porn", "sexy"}
|
||||||
|
|
||||||
func AnalyticsReferrers(w http.ResponseWriter, r *http.Request, user c.User) c.RouteError {
|
func AnalyticsReferrers(w http.ResponseWriter, r *http.Request, user c.User) c.RouteError {
|
||||||
basePage, ferr := buildBasePage(w, r, &user, "analytics", "analytics")
|
basePage, ferr := buildBasePage(w, r, &user, "analytics", "analytics")
|
||||||
if ferr != nil {
|
if ferr != nil {
|
||||||
|
@ -1054,16 +1057,30 @@ func AnalyticsReferrers(w http.ResponseWriter, r *http.Request, user c.User) c.R
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.InternalError(err, w, r)
|
return c.InternalError(err, w, r)
|
||||||
}
|
}
|
||||||
|
showSpam := r.FormValue("spam") == "1"
|
||||||
|
|
||||||
|
var isSpammy = func(domain string) bool {
|
||||||
|
for _, substr := range spamDomains {
|
||||||
|
if strings.Contains(domain, substr) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Sort this slice
|
// TODO: Sort this slice
|
||||||
var refItems []c.PanelAnalyticsAgentsItem
|
var refItems []c.PanelAnalyticsAgentsItem
|
||||||
for domain, count := range refMap {
|
for domain, count := range refMap {
|
||||||
|
sdomain := c.SanitiseSingleLine(domain)
|
||||||
|
if !showSpam && isSpammy(sdomain) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
refItems = append(refItems, c.PanelAnalyticsAgentsItem{
|
refItems = append(refItems, c.PanelAnalyticsAgentsItem{
|
||||||
Agent: c.SanitiseSingleLine(domain),
|
Agent: sdomain,
|
||||||
Count: count,
|
Count: count,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pi := c.PanelAnalyticsAgentsPage{basePage, refItems, timeRange.Range}
|
pi := c.PanelAnalyticsReferrersPage{basePage, refItems, timeRange.Range, showSpam}
|
||||||
return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right", "analytics", "panel_analytics_referrers", pi})
|
return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right", "analytics", "panel_analytics_referrers", pi})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
<div class="colstack_item colstack_head">
|
<div class="colstack_item colstack_head">
|
||||||
<div class="rowitem">
|
<div class="rowitem">
|
||||||
<h1>{{lang "panel_statistics_referrers_head"}}</h1>
|
<h1>{{lang "panel_statistics_referrers_head"}}</h1>
|
||||||
|
<select form="timeRangeForm" class="spamSelector to_right autoSubmitRedirect" name="spam">
|
||||||
|
<option val="0"{{if not .ShowSpam}} selected{{end}}>{{lang "panel_statistics_spam_hide"}}</option>
|
||||||
|
<option val="1"{{if .ShowSpam}} selected{{end}}>{{lang "panel_statistics_spam_show"}}</option>
|
||||||
|
</select>
|
||||||
{{template "panel_analytics_time_range.html" . }}
|
{{template "panel_analytics_time_range.html" . }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<select form="timeRangeForm" class="timeRangeSelector to_right" name="timeRange">
|
<select form="timeRangeForm" class="timeRangeSelector to_right autoSubmitRedirect" name="timeRange">
|
||||||
<option val="one-year"{{if eq .TimeRange "one-year"}} selected{{end}}>{{lang "panel_statistics_time_range_one_year"}}</option>
|
<option val="one-year"{{if eq .TimeRange "one-year"}} selected{{end}}>{{lang "panel_statistics_time_range_one_year"}}</option>
|
||||||
<option val="three-months"{{if eq .TimeRange "three-months"}} selected{{end}}>{{lang "panel_statistics_time_range_three_months"}}</option>
|
<option val="three-months"{{if eq .TimeRange "three-months"}} selected{{end}}>{{lang "panel_statistics_time_range_three_months"}}</option>
|
||||||
<option val="one-month"{{if eq .TimeRange "one-month"}} selected{{end}}>{{lang "panel_statistics_time_range_one_month"}}</option>
|
<option val="one-month"{{if eq .TimeRange "one-month"}} selected{{end}}>{{lang "panel_statistics_time_range_one_month"}}</option>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<select form="timeRangeForm" class="timeRangeSelector to_right" name="timeRange">
|
<select form="timeRangeForm" class="timeRangeSelector to_right autoSubmitRedirect" name="timeRange">
|
||||||
<option val="one-month"{{if eq .TimeRange "one-month"}} selected{{end}}>{{lang "panel_statistics_time_range_one_month"}}</option>
|
<option val="one-month"{{if eq .TimeRange "one-month"}} selected{{end}}>{{lang "panel_statistics_time_range_one_month"}}</option>
|
||||||
<option val="one-week"{{if eq .TimeRange "one-week"}} selected{{end}}>{{lang "panel_statistics_time_range_one_week"}}</option>
|
<option val="one-week"{{if eq .TimeRange "one-week"}} selected{{end}}>{{lang "panel_statistics_time_range_one_week"}}</option>
|
||||||
<option val="two-days"{{if eq .TimeRange "two-days"}} selected{{end}}>{{lang "panel_statistics_time_range_two_days"}}</option>
|
<option val="two-days"{{if eq .TimeRange "two-days"}} selected{{end}}>{{lang "panel_statistics_time_range_two_days"}}</option>
|
||||||
|
|
|
@ -353,6 +353,9 @@
|
||||||
.analytics .colstack_head h1 {
|
.analytics .colstack_head h1 {
|
||||||
margin-top: 2px;
|
margin-top: 2px;
|
||||||
}
|
}
|
||||||
|
.spamSelector + .timeRangeSelector {
|
||||||
|
margin-left: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
/* Experimental header tweaks */
|
/* Experimental header tweaks */
|
||||||
.colstack_head a {
|
.colstack_head a {
|
||||||
|
@ -369,10 +372,7 @@
|
||||||
display: flex;
|
display: flex;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
#widgetTmpl {
|
#widgetTmpl, .widget_disabled {
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
.widget_disabled {
|
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
.bg_red .widget_disabled {
|
.bg_red .widget_disabled {
|
||||||
|
|
|
@ -172,6 +172,10 @@ button, .formbutton, .panel_right_button:not(.has_inner_button), #panel_users .p
|
||||||
color: rgb(200,200,200);
|
color: rgb(200,200,200);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
.spamSelector + .timeRangeSelector {
|
||||||
|
margin-left: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
.colstack_graph_holder {
|
.colstack_graph_holder {
|
||||||
background-color: #444444;
|
background-color: #444444;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
|
|
|
@ -129,11 +129,11 @@
|
||||||
.ct-series-a .ct-bar, .ct-series-a .ct-line, .ct-series-a .ct-point, .ct-series-a .ct-slice-donut {
|
.ct-series-a .ct-bar, .ct-series-a .ct-line, .ct-series-a .ct-point, .ct-series-a .ct-slice-donut {
|
||||||
stroke: hsl(359,98%,43%) !important;
|
stroke: hsl(359,98%,43%) !important;
|
||||||
}
|
}
|
||||||
|
.spamSelector + .timeRangeSelector {
|
||||||
#widgetTmpl {
|
margin-left: 8px;
|
||||||
display: none;
|
|
||||||
}
|
}
|
||||||
.widget_disabled {
|
|
||||||
|
#widgetTmpl, .widget_disabled {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
.bg_red .widget_disabled {
|
.bg_red .widget_disabled {
|
||||||
|
|
|
@ -162,6 +162,7 @@
|
||||||
padding-left: 2px;
|
padding-left: 2px;
|
||||||
padding-right: 2px;
|
padding-right: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ct_chart {
|
.ct_chart {
|
||||||
padding-left: 10px;
|
padding-left: 10px;
|
||||||
padding-top: 14px;
|
padding-top: 14px;
|
||||||
|
@ -172,11 +173,11 @@
|
||||||
background-color: white;
|
background-color: white;
|
||||||
border: 1px solid hsl(0,0%,85%);
|
border: 1px solid hsl(0,0%,85%);
|
||||||
}
|
}
|
||||||
|
.spamSelector + .timeRangeSelector {
|
||||||
#widgetTmpl {
|
margin-left: 8px;
|
||||||
display: none;
|
|
||||||
}
|
}
|
||||||
.widget_disabled {
|
|
||||||
|
#widgetTmpl, .widget_disabled {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
.bg_red .widget_disabled {
|
.bg_red .widget_disabled {
|
||||||
|
|
Loading…
Reference in New Issue