-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
148 lines (118 loc) · 4.43 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
global $AnalyticBridge;
/**
* Includes
*/
include( dirname( __FILE__ ) . '/inc/functions/staff-page.php');
include( dirname( __FILE__ ) . '/inc/functions/ads.php');
include( dirname( __FILE__ ) . '/inc/functions/redirects.php');
include( dirname( __FILE__ ) . '/inc/functions/header-charm.php');
include( dirname( __FILE__ ) . '/inc/functions/plugin-wp_nav_menu_extended.php');
include( dirname( __FILE__ ) . '/inc/functions/admin.php');
include( dirname( __FILE__ ) . '/inc/functions/wiki.php');
include( dirname( __FILE__ ) . '/inc/functions/user-management.php');
include( dirname( __FILE__ ) . '/inc/functions/dirty-bird.php');
include( dirname( __FILE__ ) . '/inc/functions/donate.php');
/**
* This is to fix a problem somewhere in our stack. From what I can tell
* the php process/worker is never told it's running https. Basically
*
* $_SERVER['https']='on'; should be set but never is.
*
* Well, this will fix that I guess.
*
*/
function _hexa_enforce_https_in_template_urls($url) {
if (strpos($url,"badgerherald.com") && !strpos($url,"staging.badgerherald.com")) {
return preg_replace("/^http:/i", "https:", $url);
}
return $url;
}
add_filter('stylesheet_directory_uri','_hexa_enforce_https_in_template_urls');
add_filter('template_directory_uri','_hexa_enforce_https_in_template_urls');
/**
* Enqueue hexa scripts and styles.
*/
function hexa_scripts() {
$mtime = filemtime(dirname(__FILE__) . '/js/hexa.js') ?: "";
wp_enqueue_script('hexa-script', get_stylesheet_directory_uri() . '/js/hexa.js',array('jquery'),$mtime,true);
wp_enqueue_script('', 'https://js.stripe.com/v3/',null,null,false);
$mtime = filemtime(dirname(__FILE__) . '/style.css') ?: "";
wp_enqueue_style('hexa-style', get_stylesheet_directory_uri().'/style.css', array('exa-style'),$mtime);
}
add_action('wp_enqueue_scripts', 'hexa_scripts');
/**
* Filter banter container classes
*/
function hexa_banter_container_classes($classes,$container) {
global $post;
if($container->name == "headline" && hexa_is_banter()) {
$classes .= " banter-headline";
}
return $classes;
}
add_filter("exa_container_classes","hexa_banter_container_classes",10,2);
function hexa_register_ad_menu() {
register_nav_menu( 'ad-nav', __( 'Advertising Menu', 'hexa' ) );
}
add_action( 'after_setup_theme', 'hexa_register_ad_menu' );
function hexa_editorial_report() {
global $AnalyticBridge;
$baseArgs = array(
'post_type' => 'post',
'post_status' => 'publish',
'order' => 'DESC',
'posts_per_page' => 20,
);
$yesterday = array( 'date_query' => array(
array(
'after' => 'yesterday', // or '-2 days'
'before' => 'today', // or '-2 days'
'inclusive' => true,
),
),
);
$today = array( 'date_query' => array(
array(
'after' => 'today', // or '-2 days'
'before' => 'now', // or '-2 days'
'inclusive' => true,
),
),
);
$todayQuery = new WP_Query($baseArgs + $today);
$yesterdayQuery = new WP_Query($baseArgs + $yesterday);
$t = date( "D", strtotime("Today") );
$tminus1 = date( "D", strtotime("Yesterday") );
$ret = "";
$ret .= "# Editorial Report\n\n";
$ret .= "Pageviews for content published in the past 2 days\n\n";
$ret .= "| Post | $tminus1 | $t | Avg Time |\n";
$ret .= "|:-----|---------:|---:|--------------:|\n";
$ret .= _hexa_editorial_report_loop( $todayQuery );
$ret .= "| | | | |\n";
$ret .= _hexa_editorial_report_loop( $yesterdayQuery );
$ret .= "\n";
return $ret;
}
function _hexa_editorial_report_loop($query) {
$ret = "";
while ($query->have_posts()) : $query->the_post();
$tViews = ak_metric(get_the_id(),'ga:pageviews','today') ?: "";
$tMinus1Views = ak_metric(get_the_id(),'ga:pageviews','yesterday') ?: "";
$tTop = intval( ak_metric(get_the_id(),'ga:avgTimeOnPage','today') ?: 0 );
$tMinus1Top = intval( ak_metric(get_the_id(),'ga:avgTimeOnPage','yesterday') ?: 0 );
$avgTop = "";
if ( $tTop && $tMinus1Top ) {
$avgTop = intval( ( $tTop + $tMinus1Top ) / 2 ) . "s";
} else if ( $tTop + $tMinus1Top ) {
$avgTop = ( $tTop + $tMinus1Top ) . "s ";
}
$title = get_the_title();
$editLink = "<a href='" . get_edit_post_link() . "'>Edit</a>";
$viewLink = "<a href='" . get_permalink() . "'>View</a>";
$links = "<span class='post-links'> $editLink $viewLink</span>";
$ret .= "| $title $links | $tMinus1Views | $tViews | $avgTop |\n";
endwhile;
return $ret;
}