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

Version Description

Download this release

Release Info

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

Version 1.3.24

Files changed (238) hide show
  1. classes/models/PrliClick.php +239 -0
  2. classes/models/PrliGroup.php +114 -0
  3. classes/models/PrliLink.php +235 -0
  4. classes/models/PrliUtils.php +409 -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 +22 -0
  15. classes/views/prli-links/form.php +110 -0
  16. classes/views/prli-links/head.php +96 -0
  17. classes/views/prli-links/list.php +159 -0
  18. classes/views/prli-links/new.php +22 -0
  19. classes/views/prli-links/ultra-cloak.php +11 -0
  20. classes/views/prli-options/form.php +143 -0
  21. classes/views/prli-options/head.php +36 -0
  22. classes/views/shared/errors.php +19 -0
  23. classes/views/shared/table-nav.php +93 -0
  24. images/arrow_down.png +0 -0
  25. images/arrow_up.png +0 -0
  26. images/bar_background.png +0 -0
  27. images/bar_map.png +0 -0
  28. images/bookmark.png +0 -0
  29. images/browser/abilon.png +0 -0
  30. images/browser/adobe.png +0 -0
  31. images/browser/akregator.png +0 -0
  32. images/browser/alcatel.png +0 -0
  33. images/browser/amaya.png +0 -0
  34. images/browser/amigavoyager.png +0 -0
  35. images/browser/analogx.png +0 -0
  36. images/browser/apt.png +0 -0
  37. images/browser/avant.png +0 -0
  38. images/browser/aweb.png +0 -0
  39. images/browser/bpftp.png +0 -0
  40. images/browser/bytel.png +0 -0
  41. images/browser/chimera.png +0 -0
  42. images/browser/chrome.png +0 -0
  43. images/browser/cyberdog.png +0 -0
  44. images/browser/da.png +0 -0
  45. images/browser/dillo.png +0 -0
  46. images/browser/doris.png +0 -0
  47. images/browser/dreamcast.png +0 -0
  48. images/browser/ecatch.png +0 -0
  49. images/browser/encompass.png +0 -0
  50. images/browser/epiphany.png +0 -0
  51. images/browser/ericsson.png +0 -0
  52. images/browser/feeddemon.png +0 -0
  53. images/browser/feedreader.png +0 -0
  54. images/browser/firefox.png +0 -0
  55. images/browser/flashget.png +0 -0
  56. images/browser/fpexpress.png +0 -0
  57. images/browser/fresco.png +0 -0
  58. images/browser/freshdownload.png +0 -0
  59. images/browser/frontpage.png +0 -0
  60. images/browser/galeon.png +0 -0
  61. images/browser/getright.png +0 -0
  62. images/browser/gnome.png +0 -0
  63. images/browser/gnus.png +0 -0
  64. images/browser/gozilla.png +0 -0
  65. images/browser/hotjava.png +0 -0
  66. images/browser/httrack.png +0 -0
  67. images/browser/ibrowse.png +0 -0
  68. images/browser/icab.png +0 -0
  69. images/browser/java.png +0 -0
  70. images/browser/jetbrains_omea.png +0 -0
  71. images/browser/kmeleon.png +0 -0
  72. images/browser/konqueror.png +0 -0
  73. images/browser/leechget.png +0 -0
  74. images/browser/lg.png +0 -0
  75. images/browser/lotusnotes.png +0 -0
  76. images/browser/lynx.png +0 -0
  77. images/browser/macweb.png +0 -0
  78. images/browser/mediaplayer.png +0 -0
  79. images/browser/motorola.png +0 -0
  80. images/browser/mozilla.png +0 -0
  81. images/browser/mplayer.png +0 -0
  82. images/browser/msie.png +0 -0
  83. images/browser/msie_large.png +0 -0
  84. images/browser/multizilla.png +0 -0
  85. images/browser/ncsa_mosaic.png +0 -0
  86. images/browser/neon.png +0 -0
  87. images/browser/netnewswire.png +0 -0
  88. images/browser/netpositive.png +0 -0
  89. images/browser/netscape.png +0 -0
  90. images/browser/netscape_large.png +0 -0
  91. images/browser/netshow.png +0 -0
  92. images/browser/newsfire.png +0 -0
  93. images/browser/newsgator.png +0 -0
  94. images/browser/newzcrawler.png +0 -0
  95. images/browser/nokia.png +0 -0
  96. images/browser/notavailable.png +0 -0
  97. images/browser/omniweb.png +0 -0
  98. images/browser/opera.png +0 -0
  99. images/browser/panasonic.png +0 -0
  100. images/browser/pdaphone.png +0 -0
  101. images/browser/philips.png +0 -0
  102. images/browser/phoenix.png +0 -0
  103. images/browser/pluck.png +0 -0
  104. images/browser/pulpfiction.png +0 -0
  105. images/browser/real.png +0 -0
  106. images/browser/rss.png +0 -0
  107. images/browser/rssbandit.png +0 -0
  108. images/browser/rssowl.png +0 -0
  109. images/browser/rssreader.png +0 -0
  110. images/browser/rssxpress.png +0 -0
  111. images/browser/safari.png +0 -0
  112. images/browser/sagem.png +0 -0
  113. images/browser/samsung.png +0 -0
  114. images/browser/sharp.png +0 -0
  115. images/browser/sharpreader.png +0 -0
  116. images/browser/shrook.png +0 -0
  117. images/browser/siemens.png +0 -0
  118. images/browser/sony.png +0 -0
  119. images/browser/staroffice.png +0 -0
  120. images/browser/subversion.png +0 -0
  121. images/browser/teleport.png +0 -0
  122. images/browser/trium.png +0 -0
  123. images/browser/unknown.png +0 -0
  124. images/browser/w3c.png +0 -0
  125. images/browser/webcopier.png +0 -0
  126. images/browser/webreaper.png +0 -0
  127. images/browser/webtv.png +0 -0
  128. images/browser/webzip.png +0 -0
  129. images/browser/winxbox.png +0 -0
  130. images/browser/wizz.png +0 -0
  131. images/forward_params.png +0 -0
  132. images/nofollow.png +0 -0
  133. images/not_tracking.png +0 -0
  134. images/os/aix.png +0 -0
  135. images/os/amigaos.png +0 -0
  136. images/os/apple.png +0 -0
  137. images/os/atari.png +0 -0
  138. images/os/beos.png +0 -0
  139. images/os/bsd.png +0 -0
  140. images/os/bsdfreebsd.png +0 -0
  141. images/os/bsdi.png +0 -0
  142. images/os/bsdnetbsd.png +0 -0
  143. images/os/bsdopenbsd.png +0 -0
  144. images/os/commodore.png +0 -0
  145. images/os/cpm.png +0 -0
  146. images/os/debian.png +0 -0
  147. images/os/digital.png +0 -0
  148. images/os/dos.png +0 -0
  149. images/os/dreamcast.png +0 -0
  150. images/os/freebsd.png +0 -0
  151. images/os/gnu.png +0 -0
  152. images/os/hpux.png +0 -0
  153. images/os/ibm.png +0 -0
  154. images/os/imode.png +0 -0
  155. images/os/irix.png +0 -0
  156. images/os/java.png +0 -0
  157. images/os/kfreebsd.png +0 -0
  158. images/os/linux.png +0 -0
  159. images/os/linuxcentos.png +0 -0
  160. images/os/linuxdebian.png +0 -0
  161. images/os/linuxfedora.png +0 -0
  162. images/os/linuxgentoo.png +0 -0
  163. images/os/linuxmandr.png +0 -0
  164. images/os/linuxredhat.png +0 -0
  165. images/os/linuxsuse.png +0 -0
  166. images/os/linuxubuntu.png +0 -0
  167. images/os/mac.png +0 -0
  168. images/os/macintosh.png +0 -0
  169. images/os/macosx.png +0 -0
  170. images/os/netbsd.png +0 -0
  171. images/os/netware.png +0 -0
  172. images/os/next.png +0 -0
  173. images/os/openbsd.png +0 -0
  174. images/os/os2.png +0 -0
  175. images/os/osf.png +0 -0
  176. images/os/psp.png +0 -0
  177. images/os/qnx.png +0 -0
  178. images/os/riscos.png +0 -0
  179. images/os/sco.png +0 -0
  180. images/os/sunos.png +0 -0
  181. images/os/symbian.png +0 -0
  182. images/os/unix.png +0 -0
  183. images/os/unknown.png +0 -0
  184. images/os/vms.png +0 -0
  185. images/os/webtv.png +0 -0
  186. images/os/win.png +0 -0
  187. images/os/win16.png +0 -0
  188. images/os/win2000.png +0 -0
  189. images/os/win2003.png +0 -0
  190. images/os/win95.png +0 -0
  191. images/os/win98.png +0 -0
  192. images/os/wince.png +0 -0
  193. images/os/winlong.png +0 -0
  194. images/os/winme.png +0 -0
  195. images/os/winnt.png +0 -0
  196. images/os/winunknown.png +0 -0
  197. images/os/winxbox.png +0 -0
  198. images/os/winxp.png +0 -0
  199. images/pixel_track.png +0 -0
  200. images/pretty-link-48x48.png +0 -0
  201. images/pretty-link-add.png +0 -0
  202. images/pretty-link-med.png +0 -0
  203. images/pretty-link-small.png +0 -0
  204. images/tracking.png +0 -0
  205. images/url_icon.gif +0 -0
  206. includes/jquery/css/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  207. includes/jquery/css/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  208. includes/jquery/css/ui-lightness/images/ui-bg_flat_10_000000_40x100.png +0 -0
  209. includes/jquery/css/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  210. includes/jquery/css/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  211. includes/jquery/css/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  212. includes/jquery/css/ui-lightness/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  213. includes/jquery/css/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  214. includes/jquery/css/ui-lightness/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  215. includes/jquery/css/ui-lightness/images/ui-icons_222222_256x240.png +0 -0
  216. includes/jquery/css/ui-lightness/images/ui-icons_228ef1_256x240.png +0 -0
  217. includes/jquery/css/ui-lightness/images/ui-icons_ef8c08_256x240.png +0 -0
  218. includes/jquery/css/ui-lightness/images/ui-icons_ffd27a_256x240.png +0 -0
  219. includes/jquery/css/ui-lightness/images/ui-icons_ffffff_256x240.png +0 -0
  220. includes/jquery/css/ui-lightness/jquery-ui-1.7.1.custom.css +404 -0
  221. includes/jquery/js/jquery-1.3.2.min.js +19 -0
  222. includes/jquery/js/jquery-ui-1.7.1.custom.min.js +273 -0
  223. includes/php/php_browsecap.ini +16810 -0
  224. includes/version-2-ichor/README.txt +8 -0
  225. includes/version-2-ichor/js/README.txt +12 -0
  226. includes/version-2-ichor/js/json/json2.js +461 -0
  227. includes/version-2-ichor/js/swfobject.js +5 -0
  228. includes/version-2-ichor/open-flash-chart.swf +0 -0
  229. pretty-bar.php +208 -0
  230. pretty-link.php +340 -0
  231. prli-add-link.php +9 -0
  232. prli-clicks.php +231 -0
  233. prli-config.php +102 -0
  234. prli-groups.php +175 -0
  235. prli-image-lookups.php +136 -0
  236. prli-links.php +182 -0
  237. prli-options.php +144 -0
  238. readme.txt +74 -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 cl.created_at BETWEEN '".date("Y-n-j",$start_timestamp)." 00:00:00' AND '".date("Y-n-j",$end_timestamp)." 23:59:59'".$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,235 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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,use_ultra_cloak,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['use_ultra_cloak']) . ',' .
29
+ (int)isset($values['track_as_img']) . ',' .
30
+ (isset($values['group_id'])?(int)$values['group_id']:'NULL') . ',' .
31
+ 'NOW())';
32
+ $query_results = $wpdb->query($query);
33
+ return $query_results;
34
+ }
35
+
36
+ function update( $id, $values )
37
+ {
38
+ global $wpdb;
39
+
40
+ $values['name'] = (!empty($values['name'])?$values['name']:$values['slug']);
41
+ $query = 'UPDATE ' . $this->table_name() .
42
+ ' SET url=\'' . $values['url'] . '\', ' .
43
+ ' slug=\'' . $values['slug'] . '\', ' .
44
+ ' name=\'' . $values['name'] . '\', ' .
45
+ ' param_forwarding=\'' . $values['param_forwarding'] . '\', ' .
46
+ ' param_struct=\'' . $values['param_struct'] . '\', ' .
47
+ ' redirect_type=\'' . $values['redirect_type'] . '\', ' .
48
+ ' description=\'' . $values['description'] . '\', ' .
49
+ ' gorder=' . $values['gorder'] . ', ' .
50
+ ' track_me=' . (int)isset($values['track_me']) . ',' .
51
+ ' nofollow=' . (int)isset($values['nofollow']) . ',' .
52
+ ' use_prettybar=' . (int)isset($values['use_prettybar']) . ',' .
53
+ ' use_ultra_cloak=' . (int)isset($values['use_ultra_cloak']) . ',' .
54
+ ' track_as_img=' . (int)isset($values['track_as_img']) . ',' .
55
+ ' group_id=' . (isset($values['group_id'])?(int)$values['group_id']:'NULL') .
56
+ ' WHERE id='.$id;
57
+ $query_results = $wpdb->query($query);
58
+ return $query_results;
59
+ }
60
+
61
+ function update_group( $id, $value, $group_id )
62
+ {
63
+ global $wpdb;
64
+ $query = 'UPDATE ' . $this->table_name() .
65
+ ' SET group_id=' . (isset($value)?$group_id:'NULL') .
66
+ ' WHERE id='.$id;
67
+ $query_results = $wpdb->query($query);
68
+ return $query_results;
69
+ }
70
+
71
+ function destroy( $id )
72
+ {
73
+ require_once(PRLI_MODELS_PATH.'/models.inc.php');
74
+ global $wpdb, $prli_click;
75
+
76
+ $reset = 'DELETE FROM ' . $prli_click->table_name() . ' WHERE link_id=' . $id;
77
+ $destroy = 'DELETE FROM ' . $this->table_name() . ' WHERE id=' . $id;
78
+
79
+ $wpdb->query($reset);
80
+ return $wpdb->query($destroy);
81
+ }
82
+
83
+ function reset( $id )
84
+ {
85
+ require_once(PRLI_MODELS_PATH.'/models.inc.php');
86
+ global $wpdb, $prli_click;
87
+
88
+ $reset = 'DELETE FROM ' . $prli_click->table_name() . ' WHERE link_id=' . $id;
89
+ return $wpdb->query($reset);
90
+ }
91
+
92
+ function getOneFromSlug( $slug )
93
+ {
94
+ global $wpdb;
95
+ $query = 'SELECT * FROM ' . $this->table_name() . ' WHERE slug=\'' . $slug . '\'';
96
+ return $wpdb->get_row($query);
97
+ }
98
+
99
+ function getOne( $id )
100
+ {
101
+ global $wpdb, $prli_click;
102
+ $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;
103
+ return $wpdb->get_row($query);
104
+ }
105
+
106
+ function getAll($where = '', $order_by = '')
107
+ {
108
+ global $wpdb, $prli_click, $prli_group, $prli_utils;
109
+ $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;
110
+ return $wpdb->get_results($query);
111
+ }
112
+
113
+ // Pagination Methods
114
+ function getRecordCount($where="")
115
+ {
116
+ global $wpdb, $prli_utils;
117
+ $query = 'SELECT COUNT(*) FROM ' . $this->table_name() . $prli_utils->prepend_and_or_where(' WHERE', $where);
118
+ return $wpdb->get_var($query);
119
+ }
120
+
121
+ function getPageCount($p_size, $where="")
122
+ {
123
+ return ceil((int)$this->getRecordCount($where) / (int)$p_size);
124
+ }
125
+
126
+ function getPage($current_p,$p_size, $where = "", $order_by = '')
127
+ {
128
+ global $wpdb, $prli_click, $prli_utils, $prli_group;
129
+ $end_index = $current_p * $p_size;
130
+ $start_index = $end_index - $p_size;
131
+ $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 . ';';
132
+ $results = $wpdb->get_results($query);
133
+ return $results;
134
+ }
135
+
136
+ /** I'm generating a slug that is by default 2-3 characters long.
137
+ * This gives us a possibility of 36^3 - 37 = 46,619 possible
138
+ * random slugs. That should be *more* than enough slugs for
139
+ * any website -- if I get any feedback that we need more then
140
+ * I can always make a config option to raise the # of chars.
141
+ */
142
+ function generateValidSlug($num_chars = 3)
143
+ {
144
+ global $wpdb, $prli_utils;
145
+
146
+ // We're doing a base 36 hash which is why we're always doing everything by 36
147
+ $max_slug_value = pow(36,$num_chars);
148
+ $min_slug_value = 37; // we want to have at least 2 characters in the slug
149
+ $slug = base_convert( rand($min_slug_value,$max_slug_value), 10, 36 );
150
+
151
+ $query = "SELECT slug FROM " . $this->table_name(); // . " WHERE slug='" . $slug . "'";
152
+ $slugs = $wpdb->get_col($query,0);
153
+
154
+ // It is highly unlikely that we'll ever see 2 identical random slugs
155
+ // but just in case, here's some code to prevent collisions
156
+ while( in_array($slug,$slugs) or !$prli_utils->slugIsAvailable($slug) )
157
+ $slug = base_convert( rand($min_slug_value,$max_slug_value), 10, 36 );
158
+
159
+ return $slug;
160
+ }
161
+
162
+ function get_pretty_link_url($slug)
163
+ {
164
+ global $prli_blogurl;
165
+
166
+ $link = $this->getOneFromSlug($slug);
167
+
168
+ if((isset($link->param_forwarding) and $link->param_forwarding == 'custom') and
169
+ (isset($link->track_as_img) and $link->track_as_img == 1))
170
+ return "&lt;img src=\"".$prli_blogurl . '/' . $link->slug . $link->param_struct . "\" width=\"1\" height=\"1\" style=\"display: none\" /&gt;";
171
+ else if((!isset($link->param_forwarding) or $link->param_forwarding != 'custom') and
172
+ (isset($link->track_as_img) and $link->track_as_img == 1))
173
+ return "&lt;img src=\"".$prli_blogurl . '/' . $link->slug . "\" width=\"1\" height=\"1\" style=\"display: none\" /&gt;";
174
+ else if((isset($link->param_forwarding) and $link->param_forwarding == 'custom') and
175
+ (!isset($link->track_as_img) or $link->track_as_img == 0))
176
+ return $prli_blogurl . '/' . $link->slug . $link->param_struct;
177
+ else
178
+ return $prli_blogurl . '/' . $link->slug;
179
+ }
180
+
181
+ // Set defaults and grab get or post of each possible param
182
+ function get_params_array()
183
+ {
184
+ $values = array(
185
+ 'action' => (isset($_GET['action'])?$_GET['action']:(isset($_POST['action'])?$_POST['action']:'list')),
186
+ 'regenerate' => (isset($_GET['regenerate'])?$_GET['regenerate']:(isset($_POST['regenerate'])?$_POST['regenerate']:'false')),
187
+ 'id' => (isset($_GET['id'])?$_GET['id']:(isset($_POST['id'])?$_POST['id']:'')),
188
+ 'group_name' => (isset($_GET['group_name'])?$_GET['group_name']:(isset($_POST['group_name'])?$_POST['group_name']:'')),
189
+ 'paged' => (isset($_GET['paged'])?$_GET['paged']:(isset($_POST['paged'])?$_POST['paged']:1)),
190
+ 'group' => (isset($_GET['group'])?$_GET['group']:(isset($_POST['group'])?$_POST['group']:'')),
191
+ 'search' => (isset($_GET['search'])?$_GET['search']:(isset($_POST['search'])?$_POST['search']:'')),
192
+ 'sort' => (isset($_GET['sort'])?$_GET['sort']:(isset($_POST['sort'])?$_POST['sort']:'')),
193
+ 'sdir' => (isset($_GET['sdir'])?$_GET['sdir']:(isset($_POST['sdir'])?$_POST['sdir']:''))
194
+ );
195
+
196
+ return $values;
197
+ }
198
+
199
+ function validate( $values )
200
+ {
201
+ global $wpdb, $prli_utils;
202
+
203
+ $errors = array();
204
+ if( ( $values['url'] == null or $values['url'] == '') and $values['track_as_img'] != 'on' )
205
+ $errors[] = "Target URL can't be blank -- unless this Pretty Link is being used as a tracking pixel (see Advanced Options on this page)";
206
+
207
+ if( $values['slug'] == null or $values['slug'] == '' )
208
+ $errors[] = "Pretty Link can't be blank";
209
+
210
+ if( !empty($values['url']) and !preg_match('/^http.?:\/\/.*\..*$/', $values['url'] ) )
211
+ $errors[] = "Link URL must be a correctly formatted url";
212
+
213
+ if( !preg_match('/^[a-zA-Z0-9\.\-_]+$/', $values['slug'] ) )
214
+ $errors[] = "Pretty Link must not contain spaces or special characters";
215
+
216
+ if($values['id'] != null and $values['id'] != '')
217
+ $query = "SELECT slug FROM " . $this->table_name() . " WHERE slug='" . $values['slug'] . "' AND id <> " . $values['id'];
218
+ else
219
+ $query = "SELECT slug FROM " . $this->table_name() . " WHERE slug='" . $values['slug'] . "'";
220
+
221
+ $slug_already_exists = $wpdb->get_var($query);
222
+
223
+ if( $slug_already_exists or !$prli_utils->slugIsAvailable($values['slug']) )
224
+ $errors[] = "This pretty link slug is already taken, please choose a different one";
225
+
226
+ if( isset($values['param_forwarding']) and $values['param_forwarding'] == 'custom' and empty($values['param_struct']) )
227
+ $errors[] = "If Custom Parameter Forwarding has been selected then you must specify a forwarding format.";
228
+
229
+ if( isset($values['param_forwarding']) and $values['param_forwarding'] == 'custom' and !preg_match('#%.*?%#', $values['param_struct']) )
230
+ $errors[] = "Your parameter forwarding must have at least one parameter specified in the format ex: <code>/%var1%/%var_two%/%varname3% ...</code>";
231
+
232
+ return $errors;
233
+ }
234
+ }
235
+ ?>
classes/models/PrliUtils.php ADDED
@@ -0,0 +1,409 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }
207
+
208
+ // Reformat Parameters
209
+ $param_string = '';
210
+
211
+ if(isset($pretty_link->param_forwarding) and $pretty_link->param_forwarding and isset($values) and count($values) > 1)
212
+ {
213
+ $first_param = true;
214
+ foreach($values as $key => $value)
215
+ {
216
+ if($first_param)
217
+ {
218
+ $param_string = (preg_match("#\?#", $pretty_link->url)?"&":"?");
219
+ $first_param = false;
220
+ }
221
+ else
222
+ $param_string .= "&";
223
+
224
+ $param_string .= "$key=$value";
225
+ }
226
+ }
227
+
228
+ //Redirect to Product URL
229
+ if(!isset($pretty_link->track_as_img) or $pretty_link->track_as_img == 0)
230
+ {
231
+ if(isset($pretty_link->nofollow) and $pretty_link->nofollow)
232
+ header('X-Robots-Tag: noindex, nofollow');
233
+
234
+ // If we're using the pretty bar then don't redirect -- load the pretty bar view
235
+ if( isset($pretty_link->use_prettybar) and $pretty_link->use_prettybar )
236
+ {
237
+ global $prli_blogurl;
238
+ require_once PRLI_VIEWS_PATH . '/prli-links/bar.php';
239
+ }
240
+ else if( isset($pretty_link->use_ultra_cloak) and $pretty_link->use_ultra_cloak )
241
+ require_once PRLI_VIEWS_PATH . '/prli-links/ultra-cloak.php';
242
+ else
243
+ wp_redirect($pretty_link->url.$param_string, (int)$pretty_link->redirect_type);
244
+ }
245
+ }
246
+
247
+ function get_custom_forwarding_rule($param_struct)
248
+ {
249
+ $param_struct = preg_replace('#%.*?%#','(.*?)',$param_struct);
250
+ return preg_replace('#\(\.\*\?\)$#','(.*)',$param_struct); // replace the last one with a greedy operator
251
+ }
252
+
253
+ function get_custom_forwarding_params($param_struct, $start_index = 1)
254
+ {
255
+ preg_match_all('#%(.*?)%#', $param_struct, $matches);
256
+
257
+ $param_string = '';
258
+ $match_index = $start_index;
259
+ for($i = 0; $i < count($matches[1]); $i++)
260
+ {
261
+ if($i == 0 and $start_index == 1)
262
+ $param_string .= "?";
263
+ else
264
+ $param_string .= "&";
265
+
266
+ $param_string .= $matches[1][$i] . "=$$match_index";
267
+ $match_index++;
268
+ }
269
+
270
+ return $param_string;
271
+ }
272
+
273
+ function decode_custom_param_str($param_struct, $uri_string)
274
+ {
275
+ // Get the structure matches (param names)
276
+ preg_match_all('#%(.*?)%#', $param_struct, $struct_matches);
277
+
278
+ // Get the uri matches (param values)
279
+ $match_str = '#'.$this->get_custom_forwarding_rule($param_struct).'#';
280
+ preg_match($match_str, $uri_string, $uri_matches);
281
+
282
+ $param_array = array();
283
+ for($i = 0; $i < count($struct_matches[1]); $i++)
284
+ $param_array[$struct_matches[1][$i]] = $uri_matches[$i+1];
285
+
286
+ return $param_array;
287
+ }
288
+
289
+ // Detects whether an array is a true numerical array or an
290
+ // associative array (or hash).
291
+ function prli_array_type($item)
292
+ {
293
+ $array_type = 'unknown';
294
+
295
+ if(is_array($item))
296
+ {
297
+ $array_type = 'array';
298
+
299
+ foreach($item as $key => $value)
300
+ {
301
+ if(!is_numeric($key))
302
+ {
303
+ $array_type = 'hash';
304
+ break;
305
+ }
306
+ }
307
+ }
308
+
309
+ return $array_type;
310
+ }
311
+
312
+ // This eliminates the need to use php's built in json_encoder
313
+ // which only works with PHP 5.2 and above.
314
+ function prli_json_encode($json_array)
315
+ {
316
+ $json_str = '';
317
+
318
+ if(is_array($json_array))
319
+ {
320
+ if($this->prli_array_type($json_array) == 'array')
321
+ {
322
+ $first = true;
323
+ $json_str .= "[";
324
+ foreach($json_array as $item)
325
+ {
326
+ if(!$first)
327
+ $json_str .= ",";
328
+
329
+ if(is_numeric($item))
330
+ $json_str .= (($item < 0)?"\"$item\"":$item);
331
+ else if(is_array($item))
332
+ $json_str .= $this->prli_json_encode($item);
333
+ else if(is_string($item))
334
+ $json_str .= '"'.$item.'"';
335
+ else if(is_bool($item))
336
+ $json_str .= (($item)?"true":"false");
337
+
338
+ $first = false;
339
+ }
340
+ $json_str .= "]";
341
+ }
342
+ else if($this->prli_array_type($json_array) == 'hash')
343
+ {
344
+ $first = true;
345
+ $json_str .= "{";
346
+ foreach($json_array as $key => $item)
347
+ {
348
+ if(!$first)
349
+ $json_str .= ",";
350
+
351
+ $json_str .= "\"$key\":";
352
+
353
+ if(is_numeric($item))
354
+ $json_str .= (($item < 0)?"\"$item\"":$item);
355
+ else if(is_array($item))
356
+ $json_str .= $this->prli_json_encode($item);
357
+ else if(is_string($item))
358
+ $json_str .= "\"$item\"";
359
+ else if(is_bool($item))
360
+ $json_str .= (($item)?"true":"false");
361
+
362
+ $first = false;
363
+ }
364
+ $json_str .= "}";
365
+ }
366
+ }
367
+
368
+ return $json_str;
369
+ }
370
+
371
+ // Get the timestamp of the start date
372
+ function get_start_date($values,$min_date = '')
373
+ {
374
+ // set default to 30 days ago
375
+ if(empty($min_date))
376
+ $min_date = 30;
377
+
378
+ if(!empty($values['sdate']))
379
+ {
380
+ $sdate = explode("-",$values['sdate']);
381
+ $start_timestamp = mktime(0,0,0,$sdate[1],$sdate[2],$sdate[0]);
382
+ }
383
+ else
384
+ $start_timestamp = time()-60*60*24*(int)$min_date;
385
+
386
+ return $start_timestamp;
387
+ }
388
+
389
+ // Get the timestamp of the end date
390
+ function get_end_date($values)
391
+ {
392
+ if(!empty($values['edate']))
393
+ {
394
+ $edate = explode("-",$values['edate']);
395
+ $end_timestamp = mktime(0,0,0,$edate[1],$edate[2],$edate[0]);
396
+ }
397
+ else
398
+ $end_timestamp = time();
399
+
400
+ return $end_timestamp;
401
+ }
402
+
403
+ function prepend_and_or_where( $starts_with = ' WHERE', $where = '' )
404
+ {
405
+ return (( $where == '' )?'':$starts_with . $where);
406
+ }
407
+
408
+ }
409
+ ?>
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 @@