-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.php
149 lines (142 loc) · 6.43 KB
/
plugin.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
<?php
/*
Plugin Name: UTM Code Reporting
Plugin URI: http://www.firsthandfoundation.org
Description: A plugin to have a report on UTM codes.
Version: 1.0.1
Author: Darrell Agee
Author URI: https://www.firsthandfoundation.org
*/
// Register the plugin admin page
yourls_add_action( 'plugins_loaded', 'report_init' );
function report_init() {
yourls_register_plugin_page( 'UTM-Code-Reporting', 'UTM Report', 'report_display_page' );
}
// The function that will draw the admin page
function report_display_page() {
?>
<head>
<link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/tablesorter.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />
<script src="<?php yourls_site_url(); ?>/user/plugins/UTM-Code-Reporting/js/jquery.tablesorter.min.js" type="text/javascript"></script>
<script src="<?php yourls_site_url(); ?>/user/plugins/UTM-Code-Reporting/js/jquery.tablesorter.widgets.min.js" type="text/javascript"></script>
<script src="<?php yourls_site_url(); ?>/user/plugins/UTM-Code-Reporting/js/jquery.tablesorter.pager.min.js" type="text/javascript"></script>
<script src="<?php yourls_site_url(); ?>/user/plugins/UTM-Code-Reporting/js/main.js" type="text/javascript"></script>
<link rel="stylesheet" href="<?php yourls_site_url(); ?>/user/plugins/UTM-Code-Reporting/css/style.css" type="text/css"/>
</head>
<div class="pager">
<img src="<?php yourls_site_url(); ?>/user/plugins/UTM-Code-Reporting/css/images/first.png" class="first"/>
<img src="<?php yourls_site_url(); ?>/user/plugins/UTM-Code-Reporting/css/images/prev.png" class="prev"/>
<span class="pagedisplay"></span> <!-- this can be any element, including an input -->
<img src="<?php yourls_site_url(); ?>/user/plugins/UTM-Code-Reporting/css/images/next.png" class="next"/>
<img src="<?php yourls_site_url(); ?>/user/plugins/UTM-Code-Reporting/css/images/last.png" class="last"/>
<select class="pagesize" title="Select page size">
<option selected="selected" value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
<select class="gotoPage" title="Select page number"></select>
</div>
<div class="tblResponsive">
<table id="utm_table" class="tblSorter" cellpadding="0" cellspacing="1">
<thead>
<tr class="tablesorter-headerRow">
<th id="utm_table_head_shorturl" data-column="0" class="tablesorter-header">
Short URL
</th>
<th id="utm_table_head_title" data-column="1" class="tablesorter-header">
Title
</th>
<th id="utm_table_head_source" data-column="2" class="tablesorter-header">
Source
</th>
<th id="utm_table_head_medium" data-column="3" class="tablesorter-header">
Medium
</th>
<th id="utm_table_head_campaign" data-column="4" class="tablesorter-header">
Campaign
</th>
<th id="utm_table_head_date" data-column="5" class="tablesorter-header">
Date
</th>
<th id="utm_table_head_clicks" data-column="6" class="tablesorter-header">
Clicks
</th>
</tr>
</thead>
<tfoot>
<tr>
<th colspan="7" date-column="0">
<br>
</th>
</tr>
</tfoot>
<tbody>
<?php
global $ydb;
$utm_codes = ["utm_source=","utm_medium=","utm_campaign="];
$count = 1;
$table_url = YOURLS_DB_TABLE_URL;
$table_results = $ydb->get_results("SELECT keyword, url, title, timestamp, clicks FROM `$table_url`;");
foreach($table_results as $table_result)
{
$keyword = yourls_sanitize_string($table_result->keyword);
$long_url = stripslashes($table_result->url);
$title = $table_result->title;
$source = checkUTMCode($long_url, $utm_codes[0]);
$medium = checkUTMCode($long_url, $utm_codes[1]);
$campaign = checkUTMCode($long_url, $utm_codes[2]);
$timestamp = date("M d, Y H:i", strtotime($table_result->timestamp));
$clicks = $table_result->clicks;
echo '<tr><td>' . $keyword . '</td>
<td><a href="' . $long_url . '" target="_blank">' . $title . '</a></td>
<td>' . $source . '</td><td>' . $medium . '</td>
<td>' . $campaign . '</td><td>' . $timestamp . '</td>
<td>' . $clicks . '</td></tr>';
$count++;
}
?>
</tbody>
</table>
</div>
<br>
<div class="pager">
<img src="<?php yourls_site_url(); ?>/user/plugins/UTM-Code-Reporting/css/images/first.png" class="first"/>
<img src="<?php yourls_site_url(); ?>/user/plugins/UTM-Code-Reporting/css/images/prev.png" class="prev"/>
<span class="pagedisplay"></span> <!-- this can be any element, including an input -->
<img src="<?php yourls_site_url(); ?>/user/plugins/UTM-Code-Reporting/css/images/next.png" class="next"/>
<img src="<?php yourls_site_url(); ?>/user/plugins/UTM-Code-Reporting/css/images/last.png" class="last"/>
<select class="pagesize" title="Select page size">
<option selected="selected" value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
<select class="gotoPage" title="Select page number"></select>
</div>
<?php
}
function checkUTMCode($long_url, $utm_code)
{
if (strpos($long_url, $utm_code) !== false)
{
$value = returnUTMCode($long_url, $utm_code);
} else {
$value = '';
}
return $value;
}
function returnUTMCode($long_url, $utm_code)
{
$querySeperator = '&';
$firstPosition = strpos($long_url, $utm_code) + strlen($utm_code);
if (strpos($long_url, $querySeperator, $firstPosition) !== false)
{
$lastPosition = strpos($long_url, $querySeperator, $firstPosition);
$value = preg_replace("/\+/", " ", substr($long_url, $firstPosition, $lastPosition - $firstPosition));
} else {
$value = preg_replace("/\+/", " ", substr($long_url, $firstPosition));
}
return $value;
}
?>