-
Notifications
You must be signed in to change notification settings - Fork 0
/
ubiquity.php
executable file
·217 lines (179 loc) · 7.03 KB
/
ubiquity.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php
/*
Plugin Name: Ubiquity Toolbar v2
Plugin URI: http://p2.importantmedia.org
Description: The Everything Plugin for the Important Media Network
Version: 0.3
Author: Andrew Norcross
Author URI: http://andrewnorcross.com
License: MIT
*/
require_once('includes/wp-admin.php');
require_once('includes/wp-social.php');
require_once('includes/wp-widgets.php');
require_once('includes/wp-aggregate.php');
// nav bar
add_action('wp_print_scripts', 'ubiquity_scripts_action', 50);
add_action('ubiquity_body_scripts', 'ubiq_print_liftium_header', 75);
add_action('wp_print_styles', 'ubiquity_styles_action');
add_action('wp_footer','ubiquity_print_tracker_bodybottom');
// analytics
add_action('wp_head','ubiquity_print_ga_tracking_header');
add_action('wp_footer','ubiquity_print_ga_tracking_footer');
add_action('wp_head', 'ubiquity_print_customer_analytics_header');
add_action('wp_footer', 'ubiquity_print_customer_analytics_footer');
add_shortcode('field', 'ubiq_shortcode_field');
function ubiq_shortcode_field($atts) {
extract(shortcode_atts(array(
'name' => 'bar',
), $atts));
$return = get_post_meta(get_the_ID(), $name, true);
return $return;
}
function ubiquity_print_customer_analytics_header() {
if(!is_admin()) {
echo get_option('ubiq_analytics_other');
}
}
function ubiquity_print_customer_analytics_footer() {
if(!is_admin()) {
echo get_option('ubiq_analytics_footer');
}
}
function ubiquity_print_ga_tracking_footer() {
if (get_option('ubiq_ga_siteid')) {
?>
<script type="text/javascript"> (function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<?php
}
}
function ubiquity_print_ga_tracking_header() {
if (get_option('ubiq_ga_siteid')) {
$blogurl = preg_replace("/^https?:\/\/(.+)$/i","\\1", get_bloginfo( 'url' ));
?>
<script type="text/javascript">var _sf_startpt=(new Date()).getTime()</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(
['_setAccount', '<?php echo get_option('ubiq_ga_siteid') ?>'],
['_setAllowHash', false],
['_setDomainName', '.<?php echo $blogurl ?>'],
['_setAllowLinker',true],
['_trackPageview']
<?php if(get_option('ubiq_ga_rollup')) { ?>
, ['b._setAccount', 'UA-17151946-1'],
['b._setAllowHash', false],
['b._setDomainName', '.<?php echo $blogurl ?>'],
['b._setAllowLinker',true],
['b._trackPageview']
<?php } ?>
<?php if( is_single() ) {
global $post;
global $blog_id;
?>
, ['c._setAccount', 'UA-19342255-1'],
['c._setAllowHash', false],
['c._setDomainName', '.<?php echo $blogurl ?>'],
['c._setAllowLinker',true],
['c._trackPageview', '/blog/<?php echo $blog_id; ?>/author/<?php echo $post->post_author; ?>/']
<?php } else {
global $blog_id;
?>
, ['c._setAccount', 'UA-19342255-1'],
['c._setAllowHash', false],
['c._setDomainName', '.<?php echo $blogurl ?>'],
['c._setAllowLinker',true],
['c._trackPageview', '/blog/<?php echo $blog_id; ?>/other/']
<?php } ?>
);
</script>
<?php
}
}
function ubiquity_print($function) {
if (!get_option('ubiq_shownavbar') && !is_admin()) { return; }
switch ($function) {
case "navigation": //legacy
ubiquity_print_navigation();
break;
case "tracker_bodytop": //legacy
ubiquity_print_tracker_bodytop();
break;
case "tracker_bodybottom":
//ubiquity_print_tracker_bodybottom();
break;
case "navbar_header":
ubiquity_print_tracker_bodytop();
ubiquity_print_navigation();
break;
}
}
function ubiquity_print_navigation() {
include("includes/ubiquity-nav.php");
}
function ubiquity_print_tracker_bodytop() { ?>
<?php
}
function ubiquity_print_tracker_bodybottom() {
if (!get_option('ubiq_shownavbar') && !is_admin()) { return; }
?>
<script type='text/javascript'> var mp_protocol = (('https:' == document.location.protocol) ? 'https://' : 'http://'); document.write(unescape('%3Cscript src="' + mp_protocol + 'api.mixpanel.com/site_media/js/api/mixpanel.js" type="text/javascript"%3E%3C/script%3E')); </script> <script type='text/javascript'> try { var mpmetrics = new MixpanelLib('a32eb79d576c46f49e555808f0e9bf7a'); } catch(err) { null_fn = function () {}; var mpmetrics = { track: null_fn, track_funnel: null_fn, register: null_fn, register_once: null_fn, register_funnel: null_fn }; } </script>
<?php
}
function ubiquity_scripts_action() {
if (!is_admin()) {
$ubiquity_plugin_url = trailingslashit( get_bloginfo('wpurl') ).PLUGINDIR.'/'. dirname( plugin_basename(__FILE__) );
wp_enqueue_script('ubiquity_social_script', $ubiquity_plugin_url.'/scripts/ubiquity.social.js',array('jquery'));
}
if (!get_option('ubiq_shownavbar') && !is_admin()) { return; }
global $user_login;
$ubiquity_plugin_url = trailingslashit( get_bloginfo('wpurl') ).PLUGINDIR.'/'. dirname( plugin_basename(__FILE__) );
$local_user = '';
if(is_user_logged_in()) {
get_currentuserinfo();
$local_user = $user_login;
}
wp_enqueue_script('ubiquity_jplug', $ubiquity_plugin_url.'/scripts/ubiquity.jplug.1.0.js', array('jquery'));
wp_localize_script( 'ubiquity_jplug', 'UbiquitySettings', array(
'username' => $local_user
));
}
function ubiquity_styles_action() {
if (!is_admin()) {
$ubiquity_plugin_url = trailingslashit( get_bloginfo('wpurl') ).PLUGINDIR.'/'. dirname( plugin_basename(__FILE__) );
wp_register_style('ubiquity_widget_style', $ubiquity_plugin_url.'/css/ubiq_widgets.css');
wp_enqueue_style('ubiquity_widget_style');
}
if (!get_option('ubiq_shownavbar') && !is_admin()) { return; }
$ubiquity_plugin_url = trailingslashit( get_bloginfo('wpurl') ).PLUGINDIR.'/'. dirname( plugin_basename(__FILE__) );
wp_register_style('ubiquity_style', $ubiquity_plugin_url.'/css/ubiquity_nav.css');
wp_enqueue_style('ubiquity_style');
}
function ubiquity_print_init_script() { ?>
<?php
}
function ubiq_get_ID_by_slug($page_slug) {
$page = get_page_by_path($page_slug);
if ($page) {
return $page->ID;
} else {
return null;
}
}
function ubiq_custom_avatar($id) {
if (function_exists('author_avatar_url')) return author_avatar_url($id);
}
function ubiq_print_liftium_header() {
if (!is_admin() && get_option('ubiq_liftium_pubid')) {
?>
<script>LiftiumOptions = {pubid: <?php echo get_option('ubiq_liftium_pubid') ?>, placement : "<?php echo get_option('ubiq_liftium_placement') ?>"}</script>
<script src="http://delivery.importantmedia.org/js/Liftium.js"></script>
<?php
}
}
?>