Shortlinks by Pretty Links – Best WordPress Link Tracking Plugin - Version 1.3.20

Version Description

Download this release

Release Info

Developer supercleanse
Plugin Icon 128x128 Shortlinks by Pretty Links – Best WordPress Link Tracking Plugin
Version 1.3.20
Comparing to
See all releases

Version 1.3.20

Files changed (228) hide show
  1. classes/models/PrliClick.php +239 -0
  2. classes/models/PrliGroup.php +114 -0
  3. classes/models/PrliLink.php +233 -0
  4. classes/models/PrliUtils.php +410 -0
  5. classes/models/models.inc.php +11 -0
  6. classes/views/prli-clicks/csv.php +24 -0
  7. classes/views/prli-clicks/head.php +105 -0
  8. classes/views/prli-clicks/list.php +149 -0
  9. classes/views/prli-groups/edit.php +58 -0
  10. classes/views/prli-groups/head.php +44 -0
  11. classes/views/prli-groups/list.php +86 -0
  12. classes/views/prli-groups/new.php +59 -0
  13. classes/views/prli-links/bar.php +12 -0
  14. classes/views/prli-links/edit.php +130 -0
  15. classes/views/prli-links/head.php +44 -0
  16. classes/views/prli-links/list.php +154 -0
  17. classes/views/prli-links/new.php +130 -0
  18. classes/views/shared/errors.php +19 -0
  19. classes/views/shared/table-nav.php +93 -0
  20. images/arrow_down.png +0 -0
  21. images/arrow_up.png +0 -0
  22. images/bookmark.png +0 -0
  23. images/browser/abilon.png +0 -0
  24. images/browser/adobe.png +0 -0
  25. images/browser/akregator.png +0 -0
  26. images/browser/alcatel.png +0 -0
  27. images/browser/amaya.png +0 -0
  28. images/browser/amigavoyager.png +0 -0
  29. images/browser/analogx.png +0 -0
  30. images/browser/apt.png +0 -0
  31. images/browser/avant.png +0 -0
  32. images/browser/aweb.png +0 -0
  33. images/browser/bpftp.png +0 -0
  34. images/browser/bytel.png +0 -0
  35. images/browser/chimera.png +0 -0
  36. images/browser/chrome.png +0 -0
  37. images/browser/cyberdog.png +0 -0
  38. images/browser/da.png +0 -0
  39. images/browser/dillo.png +0 -0
  40. images/browser/doris.png +0 -0
  41. images/browser/dreamcast.png +0 -0
  42. images/browser/ecatch.png +0 -0
  43. images/browser/encompass.png +0 -0
  44. images/browser/epiphany.png +0 -0
  45. images/browser/ericsson.png +0 -0
  46. images/browser/feeddemon.png +0 -0
  47. images/browser/feedreader.png +0 -0
  48. images/browser/firefox.png +0 -0
  49. images/browser/flashget.png +0 -0
  50. images/browser/fpexpress.png +0 -0
  51. images/browser/fresco.png +0 -0
  52. images/browser/freshdownload.png +0 -0
  53. images/browser/frontpage.png +0 -0
  54. images/browser/galeon.png +0 -0
  55. images/browser/getright.png +0 -0
  56. images/browser/gnome.png +0 -0
  57. images/browser/gnus.png +0 -0
  58. images/browser/gozilla.png +0 -0
  59. images/browser/hotjava.png +0 -0
  60. images/browser/httrack.png +0 -0
  61. images/browser/ibrowse.png +0 -0
  62. images/browser/icab.png +0 -0
  63. images/browser/java.png +0 -0
  64. images/browser/jetbrains_omea.png +0 -0
  65. images/browser/kmeleon.png +0 -0
  66. images/browser/konqueror.png +0 -0
  67. images/browser/leechget.png +0 -0
  68. images/browser/lg.png +0 -0
  69. images/browser/lotusnotes.png +0 -0
  70. images/browser/lynx.png +0 -0
  71. images/browser/macweb.png +0 -0
  72. images/browser/mediaplayer.png +0 -0
  73. images/browser/motorola.png +0 -0
  74. images/browser/mozilla.png +0 -0
  75. images/browser/mplayer.png +0 -0
  76. images/browser/msie.png +0 -0
  77. images/browser/msie_large.png +0 -0
  78. images/browser/multizilla.png +0 -0
  79. images/browser/ncsa_mosaic.png +0 -0
  80. images/browser/neon.png +0 -0
  81. images/browser/netnewswire.png +0 -0
  82. images/browser/netpositive.png +0 -0
  83. images/browser/netscape.png +0 -0
  84. images/browser/netscape_large.png +0 -0
  85. images/browser/netshow.png +0 -0
  86. images/browser/newsfire.png +0 -0
  87. images/browser/newsgator.png +0 -0
  88. images/browser/newzcrawler.png +0 -0
  89. images/browser/nokia.png +0 -0
  90. images/browser/notavailable.png +0 -0
  91. images/browser/omniweb.png +0 -0
  92. images/browser/opera.png +0 -0
  93. images/browser/panasonic.png +0 -0
  94. images/browser/pdaphone.png +0 -0
  95. images/browser/philips.png +0 -0
  96. images/browser/phoenix.png +0 -0
  97. images/browser/pluck.png +0 -0
  98. images/browser/pulpfiction.png +0 -0
  99. images/browser/real.png +0 -0
  100. images/browser/rss.png +0 -0
  101. images/browser/rssbandit.png +0 -0
  102. images/browser/rssowl.png +0 -0
  103. images/browser/rssreader.png +0 -0
  104. images/browser/rssxpress.png +0 -0
  105. images/browser/safari.png +0 -0
  106. images/browser/sagem.png +0 -0
  107. images/browser/samsung.png +0 -0
  108. images/browser/sharp.png +0 -0
  109. images/browser/sharpreader.png +0 -0
  110. images/browser/shrook.png +0 -0
  111. images/browser/siemens.png +0 -0
  112. images/browser/sony.png +0 -0
  113. images/browser/staroffice.png +0 -0
  114. images/browser/subversion.png +0 -0
  115. images/browser/teleport.png +0 -0
  116. images/browser/trium.png +0 -0
  117. images/browser/unknown.png +0 -0
  118. images/browser/w3c.png +0 -0
  119. images/browser/webcopier.png +0 -0
  120. images/browser/webreaper.png +0 -0
  121. images/browser/webtv.png +0 -0
  122. images/browser/webzip.png +0 -0
  123. images/browser/winxbox.png +0 -0
  124. images/browser/wizz.png +0 -0
  125. images/forward_params.png +0 -0
  126. images/os/aix.png +0 -0
  127. images/os/amigaos.png +0 -0
  128. images/os/apple.png +0 -0
  129. images/os/atari.png +0 -0
  130. images/os/beos.png +0 -0
  131. images/os/bsd.png +0 -0
  132. images/os/bsdfreebsd.png +0 -0
  133. images/os/bsdi.png +0 -0
  134. images/os/bsdnetbsd.png +0 -0
  135. images/os/bsdopenbsd.png +0 -0
  136. images/os/commodore.png +0 -0
  137. images/os/cpm.png +0 -0
  138. images/os/debian.png +0 -0
  139. images/os/digital.png +0 -0
  140. images/os/dos.png +0 -0
  141. images/os/dreamcast.png +0 -0
  142. images/os/freebsd.png +0 -0
  143. images/os/gnu.png +0 -0
  144. images/os/hpux.png +0 -0
  145. images/os/ibm.png +0 -0
  146. images/os/imode.png +0 -0
  147. images/os/irix.png +0 -0
  148. images/os/java.png +0 -0
  149. images/os/kfreebsd.png +0 -0
  150. images/os/linux.png +0 -0
  151. images/os/linuxcentos.png +0 -0
  152. images/os/linuxdebian.png +0 -0
  153. images/os/linuxfedora.png +0 -0
  154. images/os/linuxgentoo.png +0 -0
  155. images/os/linuxmandr.png +0 -0
  156. images/os/linuxredhat.png +0 -0
  157. images/os/linuxsuse.png +0 -0
  158. images/os/linuxubuntu.png +0 -0
  159. images/os/mac.png +0 -0
  160. images/os/macintosh.png +0 -0
  161. images/os/macosx.png +0 -0
  162. images/os/netbsd.png +0 -0
  163. images/os/netware.png +0 -0
  164. images/os/next.png +0 -0
  165. images/os/openbsd.png +0 -0
  166. images/os/os2.png +0 -0
  167. images/os/osf.png +0 -0
  168. images/os/psp.png +0 -0
  169. images/os/qnx.png +0 -0
  170. images/os/riscos.png +0 -0
  171. images/os/sco.png +0 -0
  172. images/os/sunos.png +0 -0
  173. images/os/symbian.png +0 -0
  174. images/os/unix.png +0 -0
  175. images/os/unknown.png +0 -0
  176. images/os/vms.png +0 -0
  177. images/os/webtv.png +0 -0
  178. images/os/win.png +0 -0
  179. images/os/win16.png +0 -0
  180. images/os/win2000.png +0 -0
  181. images/os/win2003.png +0 -0
  182. images/os/win95.png +0 -0
  183. images/os/win98.png +0 -0
  184. images/os/wince.png +0 -0
  185. images/os/winlong.png +0 -0
  186. images/os/winme.png +0 -0
  187. images/os/winnt.png +0 -0
  188. images/os/winunknown.png +0 -0
  189. images/os/winxbox.png +0 -0
  190. images/os/winxp.png +0 -0
  191. images/pixel_track.png +0 -0
  192. images/pretty-link-add.png +0 -0
  193. images/pretty-link-med.png +0 -0
  194. images/pretty-link-small.png +0 -0
  195. images/url_icon.gif +0 -0
  196. includes/jquery/css/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  197. includes/jquery/css/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  198. includes/jquery/css/ui-lightness/images/ui-bg_flat_10_000000_40x100.png +0 -0
  199. includes/jquery/css/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  200. includes/jquery/css/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  201. includes/jquery/css/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  202. includes/jquery/css/ui-lightness/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  203. includes/jquery/css/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  204. includes/jquery/css/ui-lightness/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  205. includes/jquery/css/ui-lightness/images/ui-icons_222222_256x240.png +0 -0
  206. includes/jquery/css/ui-lightness/images/ui-icons_228ef1_256x240.png +0 -0
  207. includes/jquery/css/ui-lightness/images/ui-icons_ef8c08_256x240.png +0 -0
  208. includes/jquery/css/ui-lightness/images/ui-icons_ffd27a_256x240.png +0 -0
  209. includes/jquery/css/ui-lightness/images/ui-icons_ffffff_256x240.png +0 -0
  210. includes/jquery/css/ui-lightness/jquery-ui-1.7.1.custom.css +404 -0
  211. includes/jquery/js/jquery-1.3.2.min.js +19 -0
  212. includes/jquery/js/jquery-ui-1.7.1.custom.min.js +273 -0
  213. includes/php/php_browsecap.ini +16810 -0
  214. includes/version-2-ichor/README.txt +8 -0
  215. includes/version-2-ichor/js/README.txt +12 -0
  216. includes/version-2-ichor/js/json/json2.js +461 -0
  217. includes/version-2-ichor/js/swfobject.js +5 -0
  218. includes/version-2-ichor/open-flash-chart.swf +0 -0
  219. pretty-bar.php +81 -0
  220. pretty-link.php +296 -0
  221. prli-add-link.php +8 -0
  222. prli-clicks.php +231 -0
  223. prli-config.php +15 -0
  224. prli-groups.php +175 -0
  225. prli-image-lookups.php +136 -0
  226. prli-links.php +181 -0
  227. prli-options.php +85 -0
  228. readme.txt +68 -0
classes/models/PrliClick.php ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class PrliClick
3
+ {
4
+ function table_name()
5
+ {
6
+ global $wpdb;
7
+ return $wpdb->prefix . 'prli_clicks';
8
+ }
9
+
10
+ function get_ip_exclude_list()
11
+ {
12
+ $exclude_list = get_option('prli_exclude_ips');
13
+ $exclude_list = preg_replace('#[ \t]#','',$exclude_list);
14
+
15
+ if($exclude_list)
16
+ return "'" . implode("','", explode(',',$exclude_list)) . "'";
17
+ else
18
+ return '';
19
+ }
20
+
21
+ function get_exclude_where_clause( $where = '')
22
+ {
23
+ $exclude_list = $this->get_ip_exclude_list();
24
+
25
+ if($where == '')
26
+ $starts_with = '';
27
+ else
28
+ $starts_with = ' AND';
29
+
30
+ if( $exclude_list != '')
31
+ return $starts_with . ' cl.ip NOT IN (' . $exclude_list . ')';
32
+ else
33
+ return '';
34
+ }
35
+
36
+ function getOne( $id )
37
+ {
38
+ global $wpdb, $prli_link, $prli_utils;
39
+ $click_table = $wpdb->prefix . "prli_clicks";
40
+ $query = 'SELECT cl.*, (SELECT count(*) FROM '. $this->table_name() .' cl2 WHERE cl2.ip = cl.ip) as ip_count, (SELECT count(*) FROM '. $this->table_name() .' cl3 WHERE cl3.vuid = cl.vuid) as vuid_count, li.name as link_name FROM ' . $this->table_name() . ' cl, ' . $prli_link->table_name() . ' li WHERE li.id = cl.link_id AND id=' . $id . $prli_utils->prepend_and_or_where(' AND',$this->get_exclude_where_clause());
41
+
42
+ return $wpdb->get_row($query);
43
+ }
44
+
45
+ // SELECT cl.*,li.name as link_name FROM wp_prli_clicks cl, wp_prli_links li WHERE li.id = cl.link_id ORDER BY created_at DESC
46
+ function getAll($where = '', $order = '')
47
+ {
48
+ global $wpdb, $prli_link, $prli_utils;
49
+ $click_table = $wpdb->prefix . "prli_clicks";
50
+ $where .= $this->get_exclude_where_clause( $where );
51
+ $where = $prli_utils->prepend_and_or_where(' AND', $where);
52
+ $query = 'SELECT cl.*, (SELECT count(*) FROM '. $this->table_name() .' cl2 WHERE cl2.ip = cl.ip) as ip_count, (SELECT count(*) FROM '. $this->table_name() .' cl3 WHERE cl3.vuid = cl.vuid) as vuid_count, li.name as link_name FROM ' . $this->table_name() . ' cl, ' . $prli_link->table_name() . ' li WHERE li.id = cl.link_id' . $where . $order;
53
+ return $wpdb->get_results($query);
54
+ }
55
+
56
+ // Delete all of the clicks from the database.
57
+ function clearAllClicks()
58
+ {
59
+ global $wpdb;
60
+ $query = "TRUNCATE TABLE " . $this->table_name();
61
+ return $wpdb->query($query);
62
+ }
63
+
64
+ // Pagination Methods
65
+ function getRecordCount($where='')
66
+ {
67
+ global $wpdb, $prli_link, $prli_utils;
68
+ $where .= $this->get_exclude_where_clause( $where );
69
+ $where = $prli_utils->prepend_and_or_where(' WHERE', $where);
70
+ $query = 'SELECT COUNT(*) FROM ' . $this->table_name() . ' cl'. $where;
71
+ return $wpdb->get_var($query);
72
+ }
73
+
74
+ function getPageCount($p_size, $where='')
75
+ {
76
+ return ceil((int)$this->getRecordCount($where) / (int)$p_size);
77
+ }
78
+
79
+ function getPage($current_p,$p_size, $where = '', $order = '')
80
+ {
81
+ global $wpdb, $prli_link, $prli_utils;
82
+ $click_table = $wpdb->prefix . "prli_clicks";
83
+ $end_index = $current_p * $p_size;
84
+ $start_index = $end_index - $p_size;
85
+ $where .= $this->get_exclude_where_clause( $where );
86
+ $where = $prli_utils->prepend_and_or_where(' AND', $where);
87
+ $query = 'SELECT cl.*, (SELECT count(*) FROM '. $this->table_name() .' cl2 WHERE cl2.ip = cl.ip) as ip_count, (SELECT count(*) FROM '. $this->table_name() .' cl3 WHERE cl3.vuid = cl.vuid) as vuid_count, li.name as link_name FROM ' . $this->table_name() . ' cl, ' . $prli_link->table_name() . ' li WHERE li.id = cl.link_id' . $where . $order . ' LIMIT ' . $start_index . ',' . $p_size . ';';
88
+ $results = $wpdb->get_results($query);
89
+ return $results;
90
+ }
91
+
92
+ function generateUniqueVisitorId($num_chars = 6)
93
+ {
94
+ global $wpdb, $prli_utils;
95
+
96
+ // We're doing a base 36 hash which is why we're always doing everything by 36
97
+ $max_vuid_value = pow(36,$num_chars);
98
+ $min_vuid_value = 37;
99
+ $vuid = base_convert( mt_rand($min_vuid_value,$max_vuid_value), 10, 36 );
100
+
101
+ $query = "SELECT DISTINCT vuid FROM ".$this->table_name();
102
+ $vuids = $wpdb->get_col($query,0);
103
+
104
+ // It is highly unlikely that we'll ever see 2 identical random vuids
105
+ // but just in case, here's some code to prevent collisions
106
+ while( in_array($vuid,$vuids) )
107
+ $vuid = base_convert( mt_rand($min_vuid_value,$max_vuid_value), 10, 36 );
108
+
109
+ return $vuid;
110
+ }
111
+
112
+ function get_counts_by_days($start_timestamp, $end_timestamp, $link_id = "all", $type = "all", $group = '')
113
+ {
114
+ global $wpdb, $prli_link;
115
+
116
+ $query = "SELECT DATE(cl.created_at) as cldate,COUNT(*) as clcount FROM ".$this->table_name()." cl WHERE DATE(cl.created_at) BETWEEN '".date("Y-n-j",$start_timestamp)."' AND '".date("Y-n-j",$end_timestamp)."'".$search_where.$this->get_exclude_where_clause( ' AND' );
117
+
118
+ if($link_id != "all")
119
+ $query .= " AND link_id=$link_id";
120
+
121
+ if(!empty($group))
122
+ $query .= " AND link_id IN (SELECT id FROM " . $prli_link->table_name() . " WHERE group_id=$group)";
123
+
124
+ if($type == "unique")
125
+ $query .= " AND first_click=1";
126
+
127
+ $query .= ' GROUP BY DATE(cl.created_at)';
128
+
129
+ $clicks_array = $wpdb->get_results($query);
130
+
131
+ $temp_array = array();
132
+ $counts_array = array();
133
+ $dates_array = array();
134
+
135
+ // Refactor Array for use later on
136
+ foreach($clicks_array as $c)
137
+ $temp_array[$c->cldate] = $c->clcount;
138
+
139
+ // Get the dates array
140
+ for($c = $start_timestamp; $c <= $end_timestamp; $c += 60*60*24)
141
+ $dates_array[] = date("Y-m-d",$c);
142
+
143
+ // Make sure counts array is in order and includes zero click days
144
+ foreach($dates_array as $date_str)
145
+ {
146
+ if(isset($temp_array[$date_str]))
147
+ $counts_array[$date_str] = $temp_array[$date_str];
148
+ else
149
+ $counts_array[$date_str] = 0;
150
+ }
151
+
152
+ return $counts_array;
153
+ }
154
+
155
+
156
+ function setupClickLineGraph($start_timestamp,$end_timestamp, $link_id = "all", $type = "all", $group = '')
157
+ {
158
+ global $wpdb, $prli_utils, $prli_link, $prli_group;
159
+
160
+ $dates_array = $this->get_counts_by_days($start_timestamp,$end_timestamp,$link_id,$type,$group);
161
+
162
+ $top_click_count = $prli_utils->getTopValue(array_values($dates_array));
163
+
164
+ if(!empty($group))
165
+ $link_slug = "group: '" . $wpdb->get_var("SELECT name FROM ".$prli_group->table_name()." WHERE id=$group") . "'";
166
+ else if($link_id == "all")
167
+ $link_slug = "all links";
168
+ else
169
+ $link_slug = "'/".$wpdb->get_var("SELECT slug FROM ".$prli_link->table_name()." WHERE id=$link_id") . "'";
170
+
171
+ if($type == "all")
172
+ $type_string = "All hits";
173
+ else
174
+ $type_string = "Unique hits";
175
+
176
+ $json_array = array(
177
+ "elements" => array( array(
178
+ "type" => "line",
179
+ "values" => array_values($dates_array),
180
+ "dot-style" => array(
181
+ "type" => "dot",
182
+ "dot-size" => 4,
183
+ "colour" => "#ffc94e",
184
+ "halo-size" => 1,
185
+ "tip" => "#val# hits"
186
+ ),
187
+ "width" => 2
188
+ ) ),
189
+ "title" => array(
190
+ "text" => 'Pretty Link: '.$type_string.' on '.$link_slug. ' between ' . date("Y-n-j",$start_timestamp) . ' and ' . date("Y-n-j",$end_timestamp),
191
+ "style" => "font-size: 16px; font-weight: bold; color: #3030d0; text-align: center; padding-bottom: 5px;"
192
+ ),
193
+ "bg_colour" => "-1",
194
+ "y_axis" => array(
195
+ "min" => 0,
196
+ "max" => $top_click_count,
197
+ "steps" => (int)(($top_click_count>=10)?$top_click_count/10:1),
198
+ "colour" => "#A2ACBA"
199
+ ),
200
+ "x_axis" => array(
201
+ "colour" => "#A2ACBA",
202
+ "grid-colour" => "#ffefa7",
203
+ "offset" => false,
204
+ "steps" => 4,
205
+ "labels" => array(
206
+ "steps" => 2,
207
+ "rotate" => 45,
208
+ "colour" => "#000000",
209
+ "labels" => array_keys($dates_array)
210
+ )
211
+ )
212
+ );
213
+
214
+ return $prli_utils->prli_json_encode($json_array);
215
+ }
216
+
217
+
218
+ // Set defaults and grab get or post of each possible param
219
+ function get_params_array()
220
+ {
221
+ $values = array(
222
+ 'paged' => (isset($_GET['paged'])?$_GET['paged']:(isset($_POST['paged'])?$_POST['paged']:1)),
223
+ 'l' => (isset($_GET['l'])?$_GET['l']:(isset($_POST['l'])?$_POST['l']:'all')),
224
+ 'group' => (isset($_GET['group'])?$_GET['group']:(isset($_POST['group'])?$_POST['group']:'')),
225
+ 'ip' => (isset($_GET['ip'])?$_GET['ip']:(isset($_POST['ip'])?$_POST['ip']:'')),
226
+ 'vuid' => (isset($_GET['vuid'])?$_GET['vuid']:(isset($_POST['vuid'])?$_POST['vuid']:'')),
227
+ 'sdate' => (isset($_GET['sdate'])?$_GET['sdate']:(isset($_POST['sdate'])?$_POST['sdate']:'')),
228
+ 'edate' => (isset($_GET['edate'])?$_GET['edate']:(isset($_POST['edate'])?$_POST['edate']:'')),
229
+ 'type' => (isset($_GET['type'])?$_GET['type']:(isset($_POST['type'])?$_POST['type']:'all')),
230
+ 'search' => (isset($_GET['search'])?$_GET['search']:(isset($_POST['search'])?$_POST['search']:'')),
231
+ 'sort' => (isset($_GET['sort'])?$_GET['sort']:(isset($_POST['sort'])?$_POST['sort']:'')),
232
+ 'sdir' => (isset($_GET['sdir'])?$_GET['sdir']:(isset($_POST['sdir'])?$_POST['sdir']:''))
233
+ );
234
+
235
+ return $values;
236
+ }
237
+
238
+ }
239
+ ?>
classes/models/PrliGroup.php ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class PrliGroup
3
+ {
4
+ function table_name()
5
+ {
6
+ global $wpdb;
7
+ return $wpdb->prefix . 'prli_groups';
8
+ }
9
+
10
+ function create( $values )
11
+ {
12
+ global $wpdb, $wp_rewrite;
13
+
14
+ $query = 'INSERT INTO ' . $this->table_name() .
15
+ ' (name,description,created_at) VALUES (\'' .
16
+ $values['name'] . '\',\'' .
17
+ $values['description'] . '\',' .
18
+ 'NOW())';
19
+ $query_results = $wpdb->query($query);
20
+ return $wpdb->insert_id;
21
+ }
22
+
23
+ function update( $id, $values )
24
+ {
25
+ global $wpdb, $wp_rewrite;
26
+
27
+ $query = 'UPDATE ' . $this->table_name() .
28
+ ' SET name=\'' . $values['name'] . '\', ' .
29
+ ' description=\'' . $values['description'] . '\' ' .
30
+ ' WHERE id='.$id;
31
+ $query_results = $wpdb->query($query);
32
+ return $query_results;
33
+ }
34
+
35
+ function destroy( $id )
36
+ {
37
+ require_once(PRLI_MODELS_PATH.'/models.inc.php');
38
+ global $wpdb, $prli_link, $wp_rewrite;
39
+
40
+ // Disconnect the links from this group
41
+ $query = 'UPDATE ' . $prli_link->table_name() .
42
+ ' SET group_id = NULL ' .
43
+ ' WHERE group_id='.$id;
44
+ $query_results = $wpdb->query($query);
45
+
46
+ $destroy = 'DELETE FROM ' . $this->table_name() . ' WHERE id=' . $id;
47
+ return $wpdb->query($destroy);
48
+ }
49
+
50
+ function getOne( $id )
51
+ {
52
+ global $wpdb, $prli_link, $prli_click;
53
+ $query = 'SELECT gr.*, (SELECT COUNT(*) FROM ' . $prli_link->table_name() . ' li WHERE li.group_id = gr.id) as link_count, (SELECT COUNT(*) FROM ' . $prli_click->table_name() . ' cl WHERE link_id IN (SELECT li2.id FROM ' . $prli_link->table_name() . ' li2 WHERE li2.group_id=gr.id)) as click_count FROM ' . $this->table_name() . ' gr WHERE id=' . $id . ';';
54
+ return $wpdb->get_row($query);
55
+ }
56
+
57
+ function getAll( $where = '', $order_by = '' )
58
+ {
59
+ global $wpdb, $prli_utils, $prli_link, $prli_click;
60
+ $query = 'SELECT gr.*, (SELECT COUNT(*) FROM ' . $prli_link->table_name() . ' li WHERE li.group_id = gr.id) as link_count, (SELECT COUNT(*) FROM ' . $prli_click->table_name() . ' cl WHERE link_id IN (SELECT li2.id FROM ' . $prli_link->table_name() . ' li2 WHERE li2.group_id=gr.id)) as click_count FROM ' . $this->table_name() . ' gr' . $prli_utils->prepend_and_or_where(' WHERE', $where) . $order_by;
61
+ return $wpdb->get_results($query);
62
+ }
63
+
64
+ // Pagination Methods
65
+ function getRecordCount($where="")
66
+ {
67
+ global $wpdb, $prli_utils;
68
+ $query = 'SELECT COUNT(*) FROM ' . $this->table_name() . $prli_utils->prepend_and_or_where(' WHERE', $where);
69
+ return $wpdb->get_var($query);
70
+ }
71
+
72
+ function getPageCount($p_size, $where="")
73
+ {
74
+ return ceil((int)$this->getRecordCount($where) / (int)$p_size);
75
+ }
76
+
77
+ function getPage($current_p,$p_size, $where = "", $order_by = '')
78
+ {
79
+ global $wpdb, $prli_link, $prli_utils, $prli_click;
80
+ $end_index = $current_p * $p_size;
81
+ $start_index = $end_index - $p_size;
82
+ $query = 'SELECT gr.*, (SELECT COUNT(*) FROM ' . $prli_link->table_name() . ' li WHERE li.group_id = gr.id) as link_count, (SELECT COUNT(*) FROM ' . $prli_click->table_name() . ' cl WHERE link_id IN (SELECT li2.id FROM ' . $prli_link->table_name() . ' li2 WHERE li2.group_id=gr.id)) as click_count FROM ' . $this->table_name() . ' gr' . $prli_utils->prepend_and_or_where(' WHERE', $where) . $order_by .' LIMIT ' . $start_index . ',' . $p_size;
83
+ $results = $wpdb->get_results($query);
84
+ return $results;
85
+ }
86
+
87
+ // Set defaults and grab get or post of each possible param
88
+ function get_params_array()
89
+ {
90
+ $values = array(
91
+ 'action' => (isset($_GET['action'])?$_GET['action']:(isset($_POST['action'])?$_POST['action']:'list')),
92
+ 'id' => (isset($_GET['id'])?$_GET['id']:(isset($_POST['id'])?$_POST['id']:'')),
93
+ 'paged' => (isset($_GET['paged'])?$_GET['paged']:(isset($_POST['paged'])?$_POST['paged']:1)),
94
+ 'group' => (isset($_GET['group'])?$_GET['group']:(isset($_POST['group'])?$_POST['group']:'')),
95
+ 'search' => (isset($_GET['search'])?$_GET['search']:(isset($_POST['search'])?$_POST['search']:'')),
96
+ 'sort' => (isset($_GET['sort'])?$_GET['sort']:(isset($_POST['sort'])?$_POST['sort']:'')),
97
+ 'sdir' => (isset($_GET['sdir'])?$_GET['sdir']:(isset($_POST['sdir'])?$_POST['sdir']:''))
98
+ );
99
+
100
+ return $values;
101
+ }
102
+
103
+ function validate( $values )
104
+ {
105
+ global $wpdb, $prli_utils;
106
+
107
+ $errors = array();
108
+ if( empty($values['name']) )
109
+ $errors[] = "Group must have a name.";
110
+
111
+ return $errors;
112
+ }
113
+ }
114
+ ?>
classes/models/PrliLink.php ADDED
@@ -0,0 +1,233 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class PrliLink
3
+ {
4
+ function table_name()
5
+ {
6
+ global $wpdb;
7
+ return $wpdb->prefix . 'prli_links';
8
+ }
9
+
10
+ function create( $values )
11
+ {
12
+ global $wpdb;
13
+
14
+ $values['name'] = (!empty($values['name'])?$values['name']:$values['slug']);
15
+ $query = 'INSERT INTO ' . $this->table_name() .
16
+ ' (url,slug,name,param_forwarding,param_struct,redirect_type,description,gorder,track_me,nofollow,use_prettybar,track_as_img,group_id,created_at) VALUES (\'' .
17
+ $values['url'] . '\',\'' .
18
+ $values['slug'] . '\',\'' .
19
+ $values['name'] . '\',\'' .
20
+ $values['param_forwarding'] . '\',\'' .
21
+ $values['param_struct'] . '\',\'' .
22
+ $values['redirect_type'] . '\',\'' .
23
+ $values['description'] . '\',' .
24
+ $values['gorder'] . ',' .
25
+ (int)isset($values['track_me']) . ',' .
26
+ (int)isset($values['nofollow']) . ',' .
27
+ (int)isset($values['use_prettybar']) . ',' .
28
+ (int)isset($values['track_as_img']) . ',' .
29
+ (isset($values['group_id'])?(int)$values['group_id']:'NULL') . ',' .
30
+ 'NOW())';
31
+ $query_results = $wpdb->query($query);
32
+ return $query_results;
33
+ }
34
+
35
+ function update( $id, $values )
36
+ {
37
+ global $wpdb;
38
+
39
+ $values['name'] = (!empty($values['name'])?$values['name']:$values['slug']);
40
+ $query = 'UPDATE ' . $this->table_name() .
41
+ ' SET url=\'' . $values['url'] . '\', ' .
42
+ ' slug=\'' . $values['slug'] . '\', ' .
43
+ ' name=\'' . $values['name'] . '\', ' .
44
+ ' param_forwarding=\'' . $values['param_forwarding'] . '\', ' .
45
+ ' param_struct=\'' . $values['param_struct'] . '\', ' .
46
+ ' redirect_type=\'' . $values['redirect_type'] . '\', ' .
47
+ ' description=\'' . $values['description'] . '\', ' .
48
+ ' gorder=' . $values['gorder'] . ', ' .
49
+ ' track_me=' . (int)isset($values['track_me']) . ',' .
50
+ ' nofollow=' . (int)isset($values['nofollow']) . ',' .
51
+ ' use_prettybar=' . (int)isset($values['use_prettybar']) . ',' .
52
+ ' track_as_img=' . (int)isset($values['track_as_img']) . ',' .
53
+ ' group_id=' . (isset($values['group_id'])?(int)$values['group_id']:'NULL') .
54
+ ' WHERE id='.$id;
55
+ $query_results = $wpdb->query($query);
56
+ return $query_results;
57
+ }
58
+
59
+ function update_group( $id, $value, $group_id )
60
+ {
61
+ global $wpdb;
62
+ $query = 'UPDATE ' . $this->table_name() .
63
+ ' SET group_id=' . (isset($value)?$group_id:'NULL') .
64
+ ' WHERE id='.$id;
65
+ $query_results = $wpdb->query($query);
66
+ return $query_results;
67
+ }
68
+
69
+ function destroy( $id )
70
+ {
71
+ require_once(PRLI_MODELS_PATH.'/models.inc.php');
72
+ global $wpdb, $prli_click;
73
+
74
+ $reset = 'DELETE FROM ' . $prli_click->table_name() . ' WHERE link_id=' . $id;
75
+ $destroy = 'DELETE FROM ' . $this->table_name() . ' WHERE id=' . $id;
76
+
77
+ $wpdb->query($reset);
78
+ return $wpdb->query($destroy);
79
+ }
80
+
81
+ function reset( $id )
82
+ {
83
+ require_once(PRLI_MODELS_PATH.'/models.inc.php');
84
+ global $wpdb, $prli_click;
85
+
86
+ $reset = 'DELETE FROM ' . $prli_click->table_name() . ' WHERE link_id=' . $id;
87
+ return $wpdb->query($reset);
88
+ }
89
+
90
+ function getOneFromSlug( $slug )
91
+ {
92
+ global $wpdb;
93
+ $query = 'SELECT * FROM ' . $this->table_name() . ' WHERE slug=\'' . $slug . '\'';
94
+ return $wpdb->get_row($query);
95
+ }
96
+
97
+ function getOne( $id )
98
+ {
99
+ global $wpdb, $prli_click;
100
+ $query = 'SELECT li.*, (SELECT COUNT(*) FROM ' . $prli_click->table_name() . ' cl WHERE cl.link_id = li.id' . $prli_click->get_exclude_where_clause( ' AND' ) . ') as clicks FROM ' . $this->table_name() . ' li WHERE id=' . $id;
101
+ return $wpdb->get_row($query);
102
+ }
103
+
104
+ function getAll($where = '', $order_by = '')
105
+ {
106
+ global $wpdb, $prli_click, $prli_group, $prli_utils;
107
+ $query = 'SELECT li.*, (SELECT COUNT(*) FROM ' . $prli_click->table_name() . ' cl WHERE cl.link_id = li.id' . $prli_click->get_exclude_where_clause( ' AND' ) . ') as clicks, gr.name as group_name FROM '. $this->table_name() . ' li LEFT OUTER JOIN ' . $prli_group->table_name() . ' gr ON li.group_id=gr.id' . $prli_utils->prepend_and_or_where(' WHERE', $where) . $order_by;
108
+ return $wpdb->get_results($query);
109
+ }
110
+
111
+ // Pagination Methods
112
+ function getRecordCount($where="")
113
+ {
114
+ global $wpdb, $prli_utils;
115
+ $query = 'SELECT COUNT(*) FROM ' . $this->table_name() . $prli_utils->prepend_and_or_where(' WHERE', $where);
116
+ return $wpdb->get_var($query);
117
+ }
118
+
119
+ function getPageCount($p_size, $where="")
120
+ {
121
+ return ceil((int)$this->getRecordCount($where) / (int)$p_size);
122
+ }
123
+
124
+ function getPage($current_p,$p_size, $where = "", $order_by = '')
125
+ {
126
+ global $wpdb, $prli_click, $prli_utils, $prli_group;
127
+ $end_index = $current_p * $p_size;
128
+ $start_index = $end_index - $p_size;
129
+ $query = 'SELECT li.*, (SELECT COUNT(*) FROM ' . $prli_click->table_name() . ' cl WHERE cl.link_id = li.id' . $prli_click->get_exclude_where_clause( ' AND' ) . ') as clicks, gr.name as group_name FROM ' . $this->table_name() . ' li LEFT OUTER JOIN ' . $prli_group->table_name() . ' gr ON li.group_id=gr.id' . $prli_utils->prepend_and_or_where(' WHERE', $where) . $order_by .' LIMIT ' . $start_index . ',' . $p_size . ';';
130
+ $results = $wpdb->get_results($query);
131
+ return $results;
132
+ }
133
+
134
+ /** I'm generating a slug that is by default 2-3 characters long.
135
+ * This gives us a possibility of 36^3 - 37 = 46,619 possible
136
+ * random slugs. That should be *more* than enough slugs for
137
+ * any website -- if I get any feedback that we need more then
138
+ * I can always make a config option to raise the # of chars.
139
+ */
140
+ function generateValidSlug($num_chars = 3)
141
+ {
142
+ global $wpdb, $prli_utils;
143
+
144
+ // We're doing a base 36 hash which is why we're always doing everything by 36
145
+ $max_slug_value = pow(36,$num_chars);
146
+ $min_slug_value = 37; // we want to have at least 2 characters in the slug
147
+ $slug = base_convert( rand($min_slug_value,$max_slug_value), 10, 36 );
148
+
149
+ $query = "SELECT slug FROM " . $this->table_name(); // . " WHERE slug='" . $slug . "'";
150
+ $slugs = $wpdb->get_col($query,0);
151
+
152
+ // It is highly unlikely that we'll ever see 2 identical random slugs
153
+ // but just in case, here's some code to prevent collisions
154
+ while( in_array($slug,$slugs) or !$prli_utils->slugIsAvailable($slug) )
155
+ $slug = base_convert( rand($min_slug_value,$max_slug_value), 10, 36 );
156
+
157
+ return $slug;
158
+ }
159
+
160
+ function get_pretty_link_url($slug)
161
+ {
162
+ global $prli_blogurl;
163
+
164
+ $link = $this->getOneFromSlug($slug);
165
+
166
+ if((isset($link->param_forwarding) and $link->param_forwarding == 'custom') and
167
+ (isset($link->track_as_img) and $link->track_as_img == 1))
168
+ return "&lt;img src=\"".$prli_blogurl . '/' . $link->slug . $link->param_struct . "\" width=\"1\" height=\"1\" style=\"display: none\" /&gt;";
169
+ else if((!isset($link->param_forwarding) or $link->param_forwarding != 'custom') and
170
+ (isset($link->track_as_img) and $link->track_as_img == 1))
171
+ return "&lt;img src=\"".$prli_blogurl . '/' . $link->slug . "\" width=\"1\" height=\"1\" style=\"display: none\" /&gt;";
172
+ else if((isset($link->param_forwarding) and $link->param_forwarding == 'custom') and
173
+ (!isset($link->track_as_img) or $link->track_as_img == 0))
174
+ return $prli_blogurl . '/' . $link->slug . $link->param_struct;
175
+ else
176
+ return $prli_blogurl . '/' . $link->slug;
177
+ }
178
+
179
+ // Set defaults and grab get or post of each possible param
180
+ function get_params_array()
181
+ {
182
+ $values = array(
183
+ 'action' => (isset($_GET['action'])?$_GET['action']:(isset($_POST['action'])?$_POST['action']:'list')),
184
+ 'regenerate' => (isset($_GET['regenerate'])?$_GET['regenerate']:(isset($_POST['regenerate'])?$_POST['regenerate']:'false')),
185
+ 'id' => (isset($_GET['id'])?$_GET['id']:(isset($_POST['id'])?$_POST['id']:'')),
186
+ 'group_name' => (isset($_GET['group_name'])?$_GET['group_name']:(isset($_POST['group_name'])?$_POST['group_name']:'')),
187
+ 'paged' => (isset($_GET['paged'])?$_GET['paged']:(isset($_POST['paged'])?$_POST['paged']:1)),
188
+ 'group' => (isset($_GET['group'])?$_GET['group']:(isset($_POST['group'])?$_POST['group']:'')),
189
+ 'search' => (isset($_GET['search'])?$_GET['search']:(isset($_POST['search'])?$_POST['search']:'')),
190
+ 'sort' => (isset($_GET['sort'])?$_GET['sort']:(isset($_POST['sort'])?$_POST['sort']:'')),
191
+ 'sdir' => (isset($_GET['sdir'])?$_GET['sdir']:(isset($_POST['sdir'])?$_POST['sdir']:''))
192
+ );
193
+
194
+ return $values;
195
+ }
196
+
197
+ function validate( $values )
198
+ {
199
+ global $wpdb, $prli_utils;
200
+
201
+ $errors = array();
202
+ if( ( $values['url'] == null or $values['url'] == '') and $values['track_as_img'] != 'on' )
203
+ $errors[] = "Target URL can't be blank -- unless this Pretty Link is being used as a tracking pixel (see Advanced Options on this page)";
204
+
205
+ if( $values['slug'] == null or $values['slug'] == '' )
206
+ $errors[] = "Pretty Link can't be blank";
207
+
208
+ if( !empty($values['url']) and !preg_match('/^http.?:\/\/.*\..*$/', $values['url'] ) )
209
+ $errors[] = "Link URL must be a correctly formatted url";
210
+
211
+ if( !preg_match('/^[a-zA-Z0-9\.\-_]+$/', $values['slug'] ) )
212
+ $errors[] = "Pretty Link must not contain spaces or special characters";
213
+
214
+ if($values['id'] != null and $values['id'] != '')
215
+ $query = "SELECT slug FROM " . $this->table_name() . " WHERE slug='" . $values['slug'] . "' AND id <> " . $values['id'];
216
+ else
217
+ $query = "SELECT slug FROM " . $this->table_name() . " WHERE slug='" . $values['slug'] . "'";
218
+
219
+ $slug_already_exists = $wpdb->get_var($query);
220
+
221
+ if( $slug_already_exists or !$prli_utils->slugIsAvailable($values['slug']) )
222
+ $errors[] = "This pretty link slug is already taken, please choose a different one";
223
+
224
+ if( isset($values['param_forwarding']) and $values['param_forwarding'] == 'custom' and empty($values['param_struct']) )
225
+ $errors[] = "If Custom Parameter Forwarding has been selected then you must specify a forwarding format.";
226
+
227
+ if( isset($values['param_forwarding']) and $values['param_forwarding'] == 'custom' and !preg_match('#%.*?%#', $values['param_struct']) )
228
+ $errors[] = "Your parameter forwarding must have at least one parameter specified in the format ex: <code>/%var1%/%var_two%/%varname3% ...</code>";
229
+
230
+ return $errors;
231
+ }
232
+ }
233
+ ?>
classes/models/PrliUtils.php ADDED
@@ -0,0 +1,410 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'models.inc.php';
3
+
4
+ class PrliUtils
5
+ {
6
+
7
+ /** Okay I realize that Percentagize isn't really a word but
8
+ * this is so that the values we have will work with google
9
+ * charts.
10
+ */
11
+ function percentagizeArray($data,$max_value)
12
+ {
13
+ $new_data = array();
14
+ foreach($data as $point)
15
+ {
16
+ if( $max_value > 0 )
17
+ {
18
+ $new_data[] = $point / $max_value * 100;
19
+ }
20
+ else
21
+ {
22
+ $new_data[] = 0;
23
+ }
24
+ }
25
+ return $new_data;
26
+ }
27
+
28
+ function getTopValue($values_array)
29
+ {
30
+ rsort($values_array);
31
+ return $values_array[0];
32
+ }
33
+
34
+ function getFirstClickDate()
35
+ {
36
+ global $wpdb;
37
+
38
+ $clicks_table = $wpdb->prefix . "prli_clicks";
39
+ $query = "SELECT created_at FROM $clicks_table ORDER BY created_at LIMIT 1";
40
+ $first_click = $wpdb->get_var($query);
41
+
42
+ if(isset($first_click))
43
+ {
44
+ return strtotime($first_click);
45
+ }
46
+ else
47
+ return null;
48
+ }
49
+
50
+ function getMonthsArray()
51
+ {
52
+ global $wpdb;
53
+ global $prli_click;
54
+
55
+ $months = array();
56
+ $year = date("Y");
57
+ $month = date("m");
58
+ $current_timestamp = time();
59
+ $current_month_timestamp = mktime(0, 0, 0, date("m", $current_timestamp), 1, date("Y", $current_timestamp));
60
+
61
+ $clicks_table = $prli_click->tableName();
62
+ $first_click = $wpdb->get_var("SELECT created_at FROM $clicks_table ORDER BY created_at LIMIT 1;");
63
+ $first_timestamp = ((empty($first_click))?$current_timestamp:strtotime($first_click));
64
+ $first_date = mktime(0, 0, 0, date("m", $first_timestamp), 1, date("Y", $first_timestamp));
65
+
66
+ while($current_month_timestamp >= $first_date)
67
+ {
68
+ $months[] = $current_month_timestamp;
69
+ if(date("m") == 1)
70
+ {
71
+ $current_month_timestamp = mktime(0, 0, 0, 12, 1, date("Y", $current_month_timestamp)-1);
72
+ }
73
+ else
74
+ {
75
+ $current_month_timestamp = mktime(0, 0, 0, date("m", $current_month_timestamp)-1, 1, date("Y", $current_month_timestamp));
76
+ }
77
+ }
78
+ return $months;
79
+ }
80
+
81
+ // For Pagination
82
+ function getLastRecordNum($r_count,$current_p,$p_size)
83
+ {
84
+ return (($r_count < ($current_p * $p_size))?$r_count:($current_p * $p_size));
85
+ }
86
+
87
+ // For Pagination
88
+ function getFirstRecordNum($r_count,$current_p,$p_size)
89
+ {
90
+ if($current_p == 1)
91
+ {
92
+ return 1;
93
+ }
94
+ else
95
+ {
96
+ return ($this->getLastRecordNum($r_count,($current_p - 1),$p_size) + 1);
97
+ }
98
+ }
99
+
100
+ function slugIsAvailable($slug)
101
+ {
102
+ global $wpdb;
103
+
104
+ $posts_table = $wpdb->prefix . "posts";
105
+ $terms_table = $wpdb->prefix . "terms";
106
+
107
+ $post_slug = $wpdb->get_var("SELECT post_name FROM $posts_table WHERE post_name='$slug'");
108
+ $term_slug = $wpdb->get_col("SELECT slug FROM $terms_table WHERE slug='$slug'");
109
+
110
+ return ( $post_slug != $slug and $term_slug != $slug );
111
+ }
112
+
113
+ /* Needed because we don't know if the target uesr will have a browsercap file installed
114
+ on their server ... particularly in a shared hosting environment this is difficult
115
+ */
116
+ function php_get_browser($agent = NULL)
117
+ {
118
+ $agent=$agent?$agent:$_SERVER['HTTP_USER_AGENT'];
119
+ $yu=array();
120
+ $q_s=array("#\.#","#\*#","#\?#");
121
+ $q_r=array("\.",".*",".?");
122
+ $brows=parse_ini_file(PRLI_PATH."/includes/php/php_browsecap.ini",true);
123
+ foreach($brows as $k=>$t)
124
+ {
125
+ if(fnmatch($k,$agent))
126
+ {
127
+ $yu['browser_name_pattern']=$k;
128
+ $pat=preg_replace($q_s,$q_r,$k);
129
+ $yu['browser_name_regex']=strtolower("^$pat$");
130
+ foreach($brows as $g=>$r)
131
+ {
132
+ if($t['Parent']==$g)
133
+ {
134
+ foreach($brows as $a=>$b)
135
+ {
136
+ if($r['Parent']==$a)
137
+ {
138
+ $yu=array_merge($yu,$b,$r,$t);
139
+ foreach($yu as $d=>$z)
140
+ {
141
+ $l=strtolower($d);
142
+ $hu[$l]=$z;
143
+ }
144
+ }
145
+ }
146
+ }
147
+ }
148
+
149
+ break;
150
+ }
151
+ }
152
+
153
+ return $hu;
154
+ }
155
+
156
+ // This is where the magic happens!
157
+ function track_link($slug,$values)
158
+ {
159
+ global $wpdb, $prli_click, $prli_link;
160
+
161
+ $query = "SELECT * FROM ".$prli_link->table_name()." WHERE slug='$slug' LIMIT 1";
162
+ $pretty_link = $wpdb->get_row($query);
163
+
164
+ if(isset($pretty_link->track_me) and $pretty_link->track_me)
165
+ {
166
+ $first_click = false;
167
+
168
+ $click_ip = $_SERVER['REMOTE_ADDR'];
169
+ $click_referer = $_SERVER['HTTP_REFERER'];
170
+ $click_host = gethostbyaddr($click_ip);
171
+
172
+ $click_uri = $_SERVER['REQUEST_URI'];
173
+ $click_user_agent = $_SERVER['HTTP_USER_AGENT'];
174
+ $click_browser = $this->php_get_browser();
175
+
176
+ //Set Cookie if it doesn't exist
177
+ $cookie_name = 'prli_click_' . $pretty_link->id;
178
+ //Used for unique click tracking
179
+ $cookie_expire_time = time()+60*60*24*30; // Expire in 30 days
180
+
181
+ $visitor_cookie = 'prli_visitor';
182
+ //Used for visitor activity
183
+ $visitor_cookie_expire_time = time()+60*60*24*365; // Expire in 1 year
184
+
185
+
186
+ if($_COOKIE[$cookie_name] == null)
187
+ {
188
+ setcookie($cookie_name,$slug,$cookie_expire_time);
189
+ $first_click = true;
190
+ }
191
+
192
+ // Retrieve / Generate visitor id
193
+ if($_COOKIE[$visitor_cookie] == null)
194
+ {
195
+ $visitor_uid = $prli_click->generateUniqueVisitorId();
196
+ setcookie($visitor_cookie,$visitor_uid,$visitor_cookie_expire_time);
197
+ }
198
+ else
199
+ $visitor_uid = $_COOKIE[$visitor_cookie];
200
+
201
+ //Record Click in DB
202
+ $insert = "INSERT INTO ".$prli_click->table_name()." (link_id,vuid,ip,browser,btype,bversion,os,referer,uri,host,first_click,created_at) VALUES ($pretty_link->id,'$visitor_uid','$click_ip','$click_user_agent','".$click_browser['browser']."','".$click_browser['version']."','".$click_browser['platform']."','$click_referer','$click_uri','$click_host','$first_click',NOW())";
203
+
204
+ $results = $wpdb->query( $insert );
205
+
206
+ // Reformat Parameters
207
+ $param_string = '';
208
+ }
209
+
210
+ if(isset($pretty_link->param_forwarding) and $pretty_link->param_forwarding and isset($values) and count($values) > 1)
211
+ {
212
+ $first_param = true;
213
+ foreach($values as $key => $value)
214
+ {
215
+ // Ignore the 'sprli' parameter
216
+ if($key != 'sprli')
217
+ {
218
+ if($first_param)
219
+ {
220
+ $param_string = (preg_match("#\?#", $pretty_link->url)?"&":"?");
221
+ $first_param = false;
222
+ }
223
+ else
224
+ $param_string .= "&";
225
+
226
+ $param_string .= "$key=$value";
227
+ }
228
+ }
229
+ }
230
+
231
+ //Redirect to Product URL
232
+ if(!isset($pretty_link->track_as_img) or $pretty_link->track_as_img == 0)
233
+ {
234
+ if(isset($pretty_link->nofollow) and $pretty_link->nofollow)
235
+ header('X-Robots-Tag: noindex, nofollow');
236
+
237
+ // If we're using the pretty bar then don't redirect -- load the pretty bar view
238
+ if(!isset($pretty_link->use_prettybar) or !$pretty_link->use_prettybar)
239
+ wp_redirect($pretty_link->url.$param_string, (int)$pretty_link->redirect_type);
240
+ else
241
+ {
242
+ global $prli_blogurl;
243
+ require_once PRLI_VIEWS_PATH . '/prli-links/bar.php';
244
+ }
245
+ }
246
+ }
247
+
248
+ function get_custom_forwarding_rule($param_struct)
249
+ {
250
+ $param_struct = preg_replace('#%.*?%#','(.*?)',$param_struct);
251
+ return preg_replace('#\(\.\*\?\)$#','(.*)',$param_struct); // replace the last one with a greedy operator
252
+ }
253
+
254
+ function get_custom_forwarding_params($param_struct, $start_index = 1)
255
+ {
256
+ preg_match_all('#%(.*?)%#', $param_struct, $matches);
257
+
258
+ $param_string = '';
259
+ $match_index = $start_index;
260
+ for($i = 0; $i < count($matches[1]); $i++)
261
+ {
262
+ if($i == 0 and $start_index == 1)
263
+ $param_string .= "?";
264
+ else
265
+ $param_string .= "&";
266
+
267
+ $param_string .= $matches[1][$i] . "=$$match_index";
268
+ $match_index++;
269
+ }
270
+
271
+ return $param_string;
272
+ }
273
+
274
+ function decode_custom_param_str($param_struct, $uri_string)
275
+ {
276
+ // Get the structure matches (param names)
277
+ preg_match_all('#%(.*?)%#', $param_struct, $struct_matches);
278
+
279
+ // Get the uri matches (param values)
280
+ $match_str = '#'.$this->get_custom_forwarding_rule($param_struct).'#';
281
+ preg_match($match_str, $uri_string, $uri_matches);
282
+
283
+ $param_array = array();
284
+ for($i = 0; $i < count($struct_matches[1]); $i++)
285
+ $param_array[$struct_matches[1][$i]] = $uri_matches[$i+1];
286
+
287
+ return $param_array;
288
+ }
289
+
290
+ // Detects whether an array is a true numerical array or an
291
+ // associative array (or hash).
292
+ function prli_array_type($item)
293
+ {
294
+ $array_type = 'unknown';
295
+
296
+ if(is_array($item))
297
+ {
298
+ $array_type = 'array';
299
+
300
+ foreach($item as $key => $value)
301
+ {
302
+ if(!is_numeric($key))
303
+ {
304
+ $array_type = 'hash';
305
+ break;
306
+ }
307
+ }
308
+ }
309
+
310
+ return $array_type;
311
+ }
312
+
313
+ // This eliminates the need to use php's built in json_encoder
314
+ // which only works with PHP 5.2 and above.
315
+ function prli_json_encode($json_array)
316
+ {
317
+ $json_str = '';
318
+
319
+ if(is_array($json_array))
320
+ {
321
+ if($this->prli_array_type($json_array) == 'array')
322
+ {
323
+ $first = true;
324
+ $json_str .= "[";
325
+ foreach($json_array as $item)
326
+ {
327
+ if(!$first)
328
+ $json_str .= ",";
329
+
330
+ if(is_numeric($item))
331
+ $json_str .= (($item < 0)?"\"$item\"":$item);
332
+ else if(is_array($item))
333
+ $json_str .= $this->prli_json_encode($item);
334
+ else if(is_string($item))
335
+ $json_str .= '"'.$item.'"';
336
+ else if(is_bool($item))
337
+ $json_str .= (($item)?"true":"false");
338
+
339
+ $first = false;
340
+ }
341
+ $json_str .= "]";
342
+ }
343
+ else if($this->prli_array_type($json_array) == 'hash')
344
+ {
345
+ $first = true;
346
+ $json_str .= "{";
347
+ foreach($json_array as $key => $item)
348
+ {
349
+ if(!$first)
350
+ $json_str .= ",";
351
+
352
+ $json_str .= "\"$key\":";
353
+
354
+ if(is_numeric($item))
355
+ $json_str .= (($item < 0)?"\"$item\"":$item);
356
+ else if(is_array($item))
357
+ $json_str .= $this->prli_json_encode($item);
358
+ else if(is_string($item))
359
+ $json_str .= "\"$item\"";
360
+ else if(is_bool($item))
361
+ $json_str .= (($item)?"true":"false");
362
+
363
+ $first = false;
364
+ }
365
+ $json_str .= "}";
366
+ }
367
+ }
368
+
369
+ return $json_str;
370
+ }
371
+
372
+ // Get the timestamp of the start date
373
+ function get_start_date($values,$min_date = '')
374
+ {
375
+ // set default to 30 days ago
376
+ if(empty($min_date))
377
+ $min_date = 30;
378
+
379
+ if(!empty($values['sdate']))
380
+ {
381
+ $sdate = explode("-",$values['sdate']);
382
+ $start_timestamp = mktime(0,0,0,$sdate[1],$sdate[2],$sdate[0]);
383
+ }
384
+ else
385
+ $start_timestamp = time()-60*60*24*(int)$min_date;
386
+
387
+ return $start_timestamp;
388
+ }
389
+
390
+ // Get the timestamp of the end date
391
+ function get_end_date($values)
392
+ {
393
+ if(!empty($values['edate']))
394
+ {
395
+ $edate = explode("-",$values['edate']);
396
+ $end_timestamp = mktime(0,0,0,$edate[1],$edate[2],$edate[0]);
397
+ }
398
+ else
399
+ $end_timestamp = time();
400
+
401
+ return $end_timestamp;
402
+ }
403
+
404
+ function prepend_and_or_where( $starts_with = ' WHERE', $where = '' )
405
+ {
406
+ return (( $where == '' )?'':$starts_with . $where);
407
+ }
408
+
409
+ }
410
+ ?>
classes/models/models.inc.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once(PRLI_MODELS_PATH.'/PrliLink.php');
3
+ require_once(PRLI_MODELS_PATH.'/PrliClick.php');
4
+ require_once(PRLI_MODELS_PATH.'/PrliGroup.php');
5
+ require_once(PRLI_MODELS_PATH.'/PrliUtils.php');
6
+
7
+ $prli_link = new PrliLink();
8
+ $prli_click = new PrliClick();
9
+ $prli_group = new PrliGroup();
10
+ $prli_utils = new PrliUtils();
11
+ ?>
classes/views/prli-clicks/csv.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once('prli-config.php');
3
+
4
+ if(is_user_logged_in() and $current_user->user_level >= 8)
5
+ {
6
+ $filename = date("ymdHis",time()) . '_' . $link_name . '_pretty_link_clicks.csv';
7
+ header("Content-Type: text/x-csv");
8
+ header("Content-Disposition: attachment; filename=\"$filename\"");
9
+ header("Expires: ".gmdate("D, d M Y H:i:s", mktime(date("H")+2, date("i"), date("s"), date("m"), date("d"), date("Y")))." GMT");
10
+ header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
11
+ header("Cache-Control: no-cache, must-revalidate");
12
+ header("Pragma: no-cache");
13
+
14
+ echo '"Browser","Browser Version","Platform","IP","Visitor ID","Timestamp","Host","URI","Referrer","Link"' . "\n";
15
+ foreach($clicks as $click)
16
+ {
17
+ $link = $prli_link->getOne($click->link_id);
18
+
19
+ echo "\"$click->btype\",\"$click->bversion\",\"$click->os\",\"$click->ip\",\"$click->vuid\",\"$click->created_at\",\"$click->host\",\"$click->uri\",\"$click->referer\",\"" . ((empty($link->name))?$link->slug:$link->name) . "\"\n";
20
+ }
21
+ }
22
+ else
23
+ header("Location: " . $prli_blogurl);
24
+ ?>
classes/views/prli-clicks/head.php ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!-- JQuery UI Includes -->
2
+ <link type="text/css" href="<?php echo $prli_siteurl; ?>/wp-content/plugins/<?php echo PRLI_PLUGIN_NAME; ?>/includes/jquery/css/ui-lightness/jquery-ui-1.7.1.custom.css" rel="stylesheet" />
3
+ <script type="text/javascript" src="<?php echo $prli_siteurl; ?>/wp-content/plugins/<?php echo PRLI_PLUGIN_NAME; ?>/includes/jquery/js/jquery-1.3.2.min.js"></script>
4
+ <script type="text/javascript" src="<?php echo $prli_siteurl; ?>/wp-content/plugins/<?php echo PRLI_PLUGIN_NAME; ?>/includes/jquery/js/jquery-ui-1.7.1.custom.min.js"></script>
5
+
6
+ <script type="text/javascript">
7
+ $(document).ready(function(){
8
+ $("#sdate").datepicker({ dateFormat: 'yy-mm-dd', defaultDate: -30, minDate: -<?php echo $min_date; ?>, maxDate: 0 });
9
+ $("#edate").datepicker({ dateFormat: 'yy-mm-dd', minDate: -<?php echo $min_date; ?>, maxDate: 0 });
10
+ });
11
+ </script>
12
+
13
+ <script type="text/javascript">
14
+ $(document).ready(function(){
15
+ $(".filter_pane").hide();
16
+ $(".filter_toggle").click( function () {
17
+ $(".filter_pane").slideToggle("slow");
18
+ });
19
+ });
20
+ </script>
21
+
22
+ <style type="text/css">
23
+ .filter_toggle {
24
+ line-height: 34px;
25
+ font-size: 14px;
26
+ font-weight: bold;
27
+ padding-bottom: 10px;
28
+ }
29
+
30
+ .filter_pane {
31
+ background-color: white;
32
+ border: 2px solid #777777;
33
+ height: 275px;
34
+ width: 600px;
35
+ padding-left: 20px;
36
+ padding-top: 10px;
37
+ }
38
+
39
+ </style>
40
+
41
+ <!-- Open Flash Chart Includes -->
42
+ <script type="text/javascript" src="<?php echo $prli_siteurl; ?>/wp-content/plugins/<?php echo PRLI_PLUGIN_NAME; ?>/includes/version-2-ichor/js/json/json2.js"></script>
43
+ <script type="text/javascript" src="<?php echo $prli_siteurl; ?>/wp-content/plugins/<?php echo PRLI_PLUGIN_NAME; ?>/includes/version-2-ichor/js/swfobject.js"></script>
44
+ <script type="text/javascript">
45
+ swfobject.embedSWF("<?php echo $prli_siteurl; ?>/wp-content/plugins/<?php echo PRLI_PLUGIN_NAME; ?>/includes/version-2-ichor/open-flash-chart.swf", "my_chart", "100%", "250", "9.0.0");
46
+ </script>
47
+
48
+ <script type="text/javascript">
49
+
50
+ function ofc_ready()
51
+ {
52
+ //alert('ofc_ready');
53
+ }
54
+
55
+ function open_flash_chart_data()
56
+ {
57
+ //alert( 'reading data' );
58
+ return JSON.stringify(data);
59
+ }
60
+
61
+ function findSWF(movieName) {
62
+ if (navigator.appName.indexOf("Microsoft")!= -1) {
63
+ return window[movieName];
64
+ } else {
65
+ return document[movieName];
66
+ }
67
+ }
68
+
69
+ OFC = {};
70
+
71
+ OFC.jquery = {
72
+ name: "jQuery",
73
+ version: function(src) { return $('#'+ src)[0].get_version() },
74
+ rasterize: function (src, dst) { $('#'+ dst).replaceWith(OFC.jquery.image(src)) },
75
+ image: function(src) { return "<img src='data:image/png;base64," + $('#'+src)[0].get_img_binary() + "' />"},
76
+ popup: function(src) {
77
+ var img_win = window.open('', 'Charts: Export as Image')
78
+ with(img_win.document) {
79
+ write('<html><head><title>Charts: Export as Image<\/title><\/head><body>' + OFC.jquery.image(src) + '<div>Right-Click on the above Image to Save<\/div><\/body><\/html>') }
80
+ // stop the 'loading...' message
81
+ img_win.document.close();
82
+ }
83
+ }
84
+
85
+ // Using an object as namespaces is JS Best Practice. I like the Control.XXX style.
86
+ //if (!Control) {var Control = {}}
87
+ //if (typeof(Control == "undefined")) {var Control = {}}
88
+ if (typeof(Control == "undefined")) {var Control = {OFC: OFC.jquery}}
89
+
90
+
91
+ // By default, right-clicking on OFC and choosing "save image locally" calls this function.
92
+ // You are free to change the code in OFC and call my wrapper (Control.OFC.your_favorite_save_method)
93
+ // function save_image() { alert(1); Control.OFC.popup('my_chart') }
94
+ function save_image() {
95
+ //alert(1);
96
+ OFC.jquery.popup('my_chart')
97
+ }
98
+
99
+ function moo() {
100
+ //alert(99);
101
+ };
102
+
103
+ var data = <?php echo $prli_click->setupClickLineGraph($start_timestamp,$end_timestamp,$link_id,$type,$group); ?>;
104
+
105
+ </script>
classes/views/prli-clicks/list.php ADDED
@@ -0,0 +1,149 @@