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

Version Description

Download this release

Release Info

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

Version 1.4.11

Files changed (255) hide show
  1. classes/models/PrliClick.php +242 -0
  2. classes/models/PrliGroup.php +116 -0
  3. classes/models/PrliLink.php +307 -0
  4. classes/models/PrliLinkMeta.php +58 -0
  5. classes/models/PrliOptions.php +258 -0
  6. classes/models/PrliUtils.php +944 -0
  7. classes/models/models.inc.php +19 -0
  8. classes/views/prli-clicks/csv.php +24 -0
  9. classes/views/prli-clicks/head.php +105 -0
  10. classes/views/prli-clicks/list.php +151 -0
  11. classes/views/prli-dashboard-widget/widget.php +23 -0
  12. classes/views/prli-groups/edit.php +58 -0
  13. classes/views/prli-groups/head.php +35 -0
  14. classes/views/prli-groups/list.php +88 -0
  15. classes/views/prli-groups/new.php +59 -0
  16. classes/views/prli-links/bar.php +12 -0
  17. classes/views/prli-links/edit.php +22 -0
  18. classes/views/prli-links/form.php +94 -0
  19. classes/views/prli-links/head.php +91 -0
  20. classes/views/prli-links/list.php +182 -0
  21. classes/views/prli-links/new.php +22 -0
  22. classes/views/prli-links/ultra-cloak.php +11 -0
  23. classes/views/prli-options/form.php +160 -0
  24. classes/views/prli-options/head.php +36 -0
  25. classes/views/prli-options/pro-settings.php +43 -0
  26. classes/views/prli-tools/form.php +9 -0
  27. classes/views/shared/errors.php +19 -0
  28. classes/views/shared/link-table-nav.php +102 -0
  29. classes/views/shared/nav.php +1 -0
  30. classes/views/shared/table-nav.php +93 -0
  31. images/arrow_down.png +0 -0
  32. images/arrow_up.png +0 -0
  33. images/bar_background.png +0 -0
  34. images/bar_map.png +0 -0
  35. images/bookmark.png +0 -0
  36. images/browser/abilon.png +0 -0
  37. images/browser/adobe.png +0 -0
  38. images/browser/akregator.png +0 -0
  39. images/browser/alcatel.png +0 -0
  40. images/browser/amaya.png +0 -0
  41. images/browser/amigavoyager.png +0 -0
  42. images/browser/analogx.png +0 -0
  43. images/browser/apt.png +0 -0
  44. images/browser/avant.png +0 -0
  45. images/browser/aweb.png +0 -0
  46. images/browser/bpftp.png +0 -0
  47. images/browser/bytel.png +0 -0
  48. images/browser/chimera.png +0 -0
  49. images/browser/chrome.png +0 -0
  50. images/browser/cyberdog.png +0 -0
  51. images/browser/da.png +0 -0
  52. images/browser/dillo.png +0 -0
  53. images/browser/doris.png +0 -0
  54. images/browser/dreamcast.png +0 -0
  55. images/browser/ecatch.png +0 -0
  56. images/browser/encompass.png +0 -0
  57. images/browser/epiphany.png +0 -0
  58. images/browser/ericsson.png +0 -0
  59. images/browser/feeddemon.png +0 -0
  60. images/browser/feedreader.png +0 -0
  61. images/browser/firefox.png +0 -0
  62. images/browser/flashget.png +0 -0
  63. images/browser/fpexpress.png +0 -0
  64. images/browser/fresco.png +0 -0
  65. images/browser/freshdownload.png +0 -0
  66. images/browser/frontpage.png +0 -0
  67. images/browser/galeon.png +0 -0
  68. images/browser/getright.png +0 -0
  69. images/browser/gnome.png +0 -0
  70. images/browser/gnus.png +0 -0
  71. images/browser/gozilla.png +0 -0
  72. images/browser/hotjava.png +0 -0
  73. images/browser/httrack.png +0 -0
  74. images/browser/ibrowse.png +0 -0
  75. images/browser/icab.png +0 -0
  76. images/browser/java.png +0 -0
  77. images/browser/jetbrains_omea.png +0 -0
  78. images/browser/kmeleon.png +0 -0
  79. images/browser/konqueror.png +0 -0
  80. images/browser/leechget.png +0 -0
  81. images/browser/lg.png +0 -0
  82. images/browser/lotusnotes.png +0 -0
  83. images/browser/lynx.png +0 -0
  84. images/browser/macweb.png +0 -0
  85. images/browser/mediaplayer.png +0 -0
  86. images/browser/motorola.png +0 -0
  87. images/browser/mozilla.png +0 -0
  88. images/browser/mplayer.png +0 -0
  89. images/browser/msie.png +0 -0
  90. images/browser/msie_large.png +0 -0
  91. images/browser/multizilla.png +0 -0
  92. images/browser/ncsa_mosaic.png +0 -0
  93. images/browser/neon.png +0 -0
  94. images/browser/netnewswire.png +0 -0
  95. images/browser/netpositive.png +0 -0
  96. images/browser/netscape.png +0 -0
  97. images/browser/netscape_large.png +0 -0
  98. images/browser/netshow.png +0 -0
  99. images/browser/newsfire.png +0 -0
  100. images/browser/newsgator.png +0 -0
  101. images/browser/newzcrawler.png +0 -0
  102. images/browser/nokia.png +0 -0
  103. images/browser/notavailable.png +0 -0
  104. images/browser/omniweb.png +0 -0
  105. images/browser/opera.png +0 -0
  106. images/browser/panasonic.png +0 -0
  107. images/browser/pdaphone.png +0 -0
  108. images/browser/philips.png +0 -0
  109. images/browser/phoenix.png +0 -0
  110. images/browser/pluck.png +0 -0
  111. images/browser/pulpfiction.png +0 -0
  112. images/browser/real.png +0 -0
  113. images/browser/rss.png +0 -0
  114. images/browser/rssbandit.png +0 -0
  115. images/browser/rssowl.png +0 -0
  116. images/browser/rssreader.png +0 -0
  117. images/browser/rssxpress.png +0 -0
  118. images/browser/safari.png +0 -0
  119. images/browser/sagem.png +0 -0
  120. images/browser/samsung.png +0 -0
  121. images/browser/sharp.png +0 -0
  122. images/browser/sharpreader.png +0 -0
  123. images/browser/shrook.png +0 -0
  124. images/browser/siemens.png +0 -0
  125. images/browser/sony.png +0 -0
  126. images/browser/staroffice.png +0 -0
  127. images/browser/subversion.png +0 -0
  128. images/browser/teleport.png +0 -0
  129. images/browser/trium.png +0 -0
  130. images/browser/unknown.png +0 -0
  131. images/browser/w3c.png +0 -0
  132. images/browser/webcopier.png +0 -0
  133. images/browser/webreaper.png +0 -0
  134. images/browser/webtv.png +0 -0
  135. images/browser/webzip.png +0 -0
  136. images/browser/winxbox.png +0 -0
  137. images/browser/wizz.png +0 -0
  138. images/forward_params.png +0 -0
  139. images/nofollow.png +0 -0
  140. images/not_tracking.png +0 -0
  141. images/os/aix.png +0 -0
  142. images/os/amigaos.png +0 -0
  143. images/os/apple.png +0 -0
  144. images/os/atari.png +0 -0
  145. images/os/beos.png +0 -0
  146. images/os/bsd.png +0 -0
  147. images/os/bsdfreebsd.png +0 -0
  148. images/os/bsdi.png +0 -0
  149. images/os/bsdnetbsd.png +0 -0
  150. images/os/bsdopenbsd.png +0 -0
  151. images/os/commodore.png +0 -0
  152. images/os/cpm.png +0 -0
  153. images/os/debian.png +0 -0
  154. images/os/digital.png +0 -0
  155. images/os/dos.png +0 -0
  156. images/os/dreamcast.png +0 -0
  157. images/os/freebsd.png +0 -0
  158. images/os/gnu.png +0 -0
  159. images/os/hpux.png +0 -0
  160. images/os/ibm.png +0 -0
  161. images/os/imode.png +0 -0
  162. images/os/irix.png +0 -0
  163. images/os/java.png +0 -0
  164. images/os/kfreebsd.png +0 -0
  165. images/os/linux.png +0 -0
  166. images/os/linuxcentos.png +0 -0
  167. images/os/linuxdebian.png +0 -0
  168. images/os/linuxfedora.png +0 -0
  169. images/os/linuxgentoo.png +0 -0
  170. images/os/linuxmandr.png +0 -0
  171. images/os/linuxredhat.png +0 -0
  172. images/os/linuxsuse.png +0 -0
  173. images/os/linuxubuntu.png +0 -0
  174. images/os/mac.png +0 -0
  175. images/os/macintosh.png +0 -0
  176. images/os/macosx.png +0 -0
  177. images/os/netbsd.png +0 -0
  178. images/os/netware.png +0 -0
  179. images/os/next.png +0 -0
  180. images/os/openbsd.png +0 -0
  181. images/os/os2.png +0 -0
  182. images/os/osf.png +0 -0
  183. images/os/psp.png +0 -0
  184. images/os/qnx.png +0 -0
  185. images/os/riscos.png +0 -0
  186. images/os/sco.png +0 -0
  187. images/os/sunos.png +0 -0
  188. images/os/symbian.png +0 -0
  189. images/os/unix.png +0 -0
  190. images/os/unknown.png +0 -0
  191. images/os/vms.png +0 -0
  192. images/os/webtv.png +0 -0
  193. images/os/win.png +0 -0
  194. images/os/win16.png +0 -0
  195. images/os/win2000.png +0 -0
  196. images/os/win2003.png +0 -0
  197. images/os/win95.png +0 -0
  198. images/os/win98.png +0 -0
  199. images/os/wince.png +0 -0
  200. images/os/winlong.png +0 -0
  201. images/os/winme.png +0 -0
  202. images/os/winnt.png +0 -0
  203. images/os/winunknown.png +0 -0
  204. images/os/winxbox.png +0 -0
  205. images/os/winxp.png +0 -0
  206. images/pixel_track.png +0 -0
  207. images/pretty-link-48x48.png +0 -0
  208. images/pretty-link-add.png +0 -0
  209. images/pretty-link-med.png +0 -0
  210. images/pretty-link-small.png +0 -0
  211. images/prettylink_logo.jpg +0 -0
  212. images/prettylink_logo_med.jpg +0 -0
  213. images/prettylink_logo_small.jpg +0 -0
  214. images/tracking.png +0 -0
  215. images/ultra-cloak.png +0 -0
  216. images/url_icon.gif +0 -0
  217. includes/jquery/css/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  218. includes/jquery/css/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  219. includes/jquery/css/ui-lightness/images/ui-bg_flat_10_000000_40x100.png +0 -0
  220. includes/jquery/css/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  221. includes/jquery/css/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  222. includes/jquery/css/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  223. includes/jquery/css/ui-lightness/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  224. includes/jquery/css/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  225. includes/jquery/css/ui-lightness/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  226. includes/jquery/css/ui-lightness/images/ui-icons_222222_256x240.png +0 -0
  227. includes/jquery/css/ui-lightness/images/ui-icons_228ef1_256x240.png +0 -0
  228. includes/jquery/css/ui-lightness/images/ui-icons_ef8c08_256x240.png +0 -0
  229. includes/jquery/css/ui-lightness/images/ui-icons_ffd27a_256x240.png +0 -0
  230. includes/jquery/css/ui-lightness/images/ui-icons_ffffff_256x240.png +0 -0
  231. includes/jquery/css/ui-lightness/jquery-ui-1.7.1.custom.css +404 -0
  232. includes/jquery/js/jquery-1.3.2.min.js +19 -0
  233. includes/jquery/js/jquery-ui-1.7.1.custom.min.js +273 -0
  234. includes/php/php_browsecap.ini +16939 -0
  235. includes/version-2-kvasir/README.txt +8 -0
  236. includes/version-2-kvasir/js/README.txt +12 -0
  237. includes/version-2-kvasir/js/json/json2.js +461 -0
  238. includes/version-2-kvasir/js/swfobject.js +5 -0
  239. includes/version-2-kvasir/open-flash-chart.swf +0 -0
  240. pretty-bar.php +235 -0
  241. pretty-link.php +329 -0
  242. prli-add-link.php +9 -0
  243. prli-api.php +233 -0
  244. prli-bookmarklet.php +68 -0
  245. prli-clicks.php +237 -0
  246. prli-config.php +121 -0
  247. prli-dashboard-widget.php +20 -0
  248. prli-groups.php +175 -0
  249. prli-image-lookups.php +136 -0
  250. prli-links.php +247 -0
  251. prli-options.php +129 -0
  252. prli-pro-settings.php +77 -0
  253. prli-tools.php +3 -0
  254. prli-xmlrpc.php +333 -0
  255. readme.txt +101 -0
classes/models/PrliClick.php ADDED
@@ -0,0 +1,242 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class PrliClick
3
+ {
4
+ var $table_name;
5
+
6
+ function PrliClick()
7
+ {
8
+ global $wpdb;
9
+ $this->table_name = "{$wpdb->prefix}prli_clicks";
10
+ }
11
+
12
+ function get_ip_exclude_list()
13
+ {
14
+ global $prli_options;
15
+ $exclude_list = $prli_options->prli_exclude_ips;
16
+ $exclude_list = preg_replace('#[ \t]#','',$exclude_list);
17
+
18
+ if($exclude_list)
19
+ return "'" . implode("','", explode(',',$exclude_list)) . "'";
20
+ else
21
+ return '';
22
+ }
23
+
24
+ function get_exclude_where_clause( $where = '', $abbr = 'cl')
25
+ {
26
+ $exclude_list = $this->get_ip_exclude_list();
27
+
28
+ if($where == '')
29
+ $starts_with = '';
30
+ else
31
+ $starts_with = ' AND';
32
+
33
+ if( $exclude_list != '')
34
+ return $starts_with . " $abbr.ip NOT IN (" . $exclude_list . ')';
35
+ else
36
+ return '';
37
+ }
38
+
39
+ function getOne( $id )
40
+ {
41
+ global $wpdb, $prli_link, $prli_utils;
42
+ $click_table = $wpdb->prefix . "prli_clicks";
43
+ $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());
44
+
45
+ return $wpdb->get_row($query);
46
+ }
47
+
48
+ // 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
49
+ function getAll($where = '', $order = '')
50
+ {
51
+ global $wpdb, $prli_link, $prli_utils;
52
+ $click_table = $wpdb->prefix . "prli_clicks";
53
+ $where .= $this->get_exclude_where_clause( $where );
54
+ $where = $prli_utils->prepend_and_or_where(' AND', $where);
55
+ $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;
56
+ return $wpdb->get_results($query);
57
+ }
58
+
59
+ // Delete all of the clicks from the database.
60
+ function clearAllClicks()
61
+ {
62
+ global $wpdb;
63
+ $query = "TRUNCATE TABLE " . $this->table_name;
64
+ return $wpdb->query($query);
65
+ }
66
+
67
+ // Pagination Methods
68
+ function getRecordCount($where='')
69
+ {
70
+ global $wpdb, $prli_link, $prli_utils;
71
+ $where .= $this->get_exclude_where_clause( $where );
72
+ $where = $prli_utils->prepend_and_or_where(' WHERE', $where);
73
+ $query = 'SELECT COUNT(*) FROM ' . $this->table_name . ' cl'. $where;
74
+ return $wpdb->get_var($query);
75
+ }
76
+
77
+ function getPageCount($p_size, $where='')
78
+ {
79
+ return ceil((int)$this->getRecordCount($where) / (int)$p_size);
80
+ }
81
+
82
+ function getPage($current_p,$p_size, $where = '', $order = '')
83
+ {
84
+ global $wpdb, $prli_link, $prli_utils;
85
+ $click_table = $wpdb->prefix . "prli_clicks";
86
+ $end_index = $current_p * $p_size;
87
+ $start_index = $end_index - $p_size;
88
+ $where .= $this->get_exclude_where_clause( $where );
89
+ $where = $prli_utils->prepend_and_or_where(' AND', $where);
90
+ $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 . ';';
91
+ $results = $wpdb->get_results($query);
92
+ return $results;
93
+ }
94
+
95
+ function generateUniqueVisitorId($num_chars = 6)
96
+ {
97
+ global $wpdb, $prli_utils;
98
+
99
+ // We're doing a base 36 hash which is why we're always doing everything by 36
100
+ $max_vuid_value = pow(36,$num_chars);
101
+ $min_vuid_value = 37;
102
+ $vuid = base_convert( mt_rand($min_vuid_value,$max_vuid_value), 10, 36 );
103
+
104
+ $query = "SELECT DISTINCT vuid FROM ".$this->table_name;
105
+ $vuids = $wpdb->get_col($query,0);
106
+
107
+ // It is highly unlikely that we'll ever see 2 identical random vuids
108
+ // but just in case, here's some code to prevent collisions
109
+ while( in_array($vuid,$vuids) )
110
+ $vuid = base_convert( mt_rand($min_vuid_value,$max_vuid_value), 10, 36 );
111
+
112
+ return $vuid;
113
+ }
114
+
115
+ function get_counts_by_days($start_timestamp, $end_timestamp, $link_id = "all", $type = "all", $group = '')
116
+ {
117
+ global $wpdb, $prli_link;
118
+
119
+ $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' );
120
+
121
+ if($link_id != "all")
122
+ $query .= " AND link_id=$link_id";
123
+
124
+ if(!empty($group))
125
+ $query .= " AND link_id IN (SELECT id FROM " . $prli_link->table_name . " WHERE group_id=$group)";
126
+
127
+ if($type == "unique")
128
+ $query .= " AND first_click=1";
129
+
130
+ $query .= ' GROUP BY DATE(cl.created_at)';
131
+
132
+ $clicks_array = $wpdb->get_results($query);
133
+
134
+ $temp_array = array();
135
+ $counts_array = array();
136
+ $dates_array = array();
137
+
138
+ // Refactor Array for use later on
139
+ foreach($clicks_array as $c)
140
+ $temp_array[$c->cldate] = $c->clcount;
141
+
142
+ // Get the dates array
143
+ for($c = $start_timestamp; $c <= $end_timestamp; $c += 60*60*24)
144
+ $dates_array[] = date("Y-m-d",$c);
145
+
146
+ // Make sure counts array is in order and includes zero click days
147
+ foreach($dates_array as $date_str)
148
+ {
149
+ if(isset($temp_array[$date_str]))
150
+ $counts_array[$date_str] = $temp_array[$date_str];
151
+ else
152
+ $counts_array[$date_str] = 0;
153
+ }
154
+
155
+ return $counts_array;
156
+ }
157
+
158
+
159
+ function setupClickLineGraph($start_timestamp,$end_timestamp, $link_id = "all", $type = "all", $group = '')
160
+ {
161
+ global $wpdb, $prli_utils, $prli_link, $prli_group;
162
+
163
+ $dates_array = $this->get_counts_by_days($start_timestamp,$end_timestamp,$link_id,$type,$group);
164
+
165
+ $top_click_count = $prli_utils->getTopValue(array_values($dates_array));
166
+
167
+ if(!empty($group))
168
+ $link_slug = "group: '" . $wpdb->get_var("SELECT name FROM ".$prli_group->table_name." WHERE id=$group") . "'";
169
+ else if($link_id == "all")
170
+ $link_slug = "all links";
171
+ else
172
+ $link_slug = "'/".$wpdb->get_var("SELECT slug FROM ".$prli_link->table_name." WHERE id=$link_id") . "'";
173
+
174
+ if($type == "all")
175
+ $type_string = "All hits";
176
+ else
177
+ $type_string = "Unique hits";
178
+
179
+ $json_array = array(
180
+ "elements" => array( array(
181
+ "type" => "line",
182
+ "values" => array_values($dates_array),
183
+ "dot-style" => array(
184
+ "type" => "dot",
185
+ "dot-size" => 4,
186
+ "colour" => "#ffc94e",
187
+ "halo-size" => 1,
188
+ "tip" => "#val# Hits<br>#x_label#"
189
+ ),
190
+ "width" => 2
191
+ ) ),
192
+ "title" => array(
193
+ "text" => 'Pretty Link: '.$type_string.' on '.$link_slug. ' between ' . date("Y-n-j",$start_timestamp) . ' and ' . date("Y-n-j",$end_timestamp),
194
+ "style" => "font-size: 16px; font-weight: bold; color: #3030d0; text-align: center; padding-bottom: 5px;"
195
+ ),
196
+ "bg_colour" => "-1",
197
+ "y_axis" => array(
198
+ "min" => 0,
199
+ "max" => $top_click_count,
200
+ "steps" => (int)(($top_click_count>=10)?$top_click_count/10:1),
201
+ "colour" => "#A2ACBA"
202
+ ),
203
+ "x_axis" => array(
204
+ "colour" => "#A2ACBA",
205
+ "grid-colour" => "#ffefa7",
206
+ "offset" => false,
207
+ "steps" => 4,
208
+ "labels" => array(
209
+ "steps" => 2,
210
+ "rotate" => 25,
211
+ "colour" => "#000000",
212
+ "labels" => array_keys($dates_array)
213
+ )
214
+ )
215
+ );
216
+
217
+ return $prli_utils->prli_json_encode($json_array);
218
+ }
219
+
220
+
221
+ // Set defaults and grab get or post of each possible param
222
+ function get_params_array()
223
+ {
224
+ $values = array(
225
+ 'paged' => (isset($_GET['paged'])?$_GET['paged']:(isset($_POST['paged'])?$_POST['paged']:1)),
226
+ 'l' => (isset($_GET['l'])?$_GET['l']:(isset($_POST['l'])?$_POST['l']:'all')),
227
+ 'group' => (isset($_GET['group'])?$_GET['group']:(isset($_POST['group'])?$_POST['group']:'')),
228
+ 'ip' => (isset($_GET['ip'])?$_GET['ip']:(isset($_POST['ip'])?$_POST['ip']:'')),
229
+ 'vuid' => (isset($_GET['vuid'])?$_GET['vuid']:(isset($_POST['vuid'])?$_POST['vuid']:'')),
230
+ 'sdate' => (isset($_GET['sdate'])?$_GET['sdate']:(isset($_POST['sdate'])?$_POST['sdate']:'')),
231
+ 'edate' => (isset($_GET['edate'])?$_GET['edate']:(isset($_POST['edate'])?$_POST['edate']:'')),
232
+ 'type' => (isset($_GET['type'])?$_GET['type']:(isset($_POST['type'])?$_POST['type']:'all')),
233
+ 'search' => (isset($_GET['search'])?$_GET['search']:(isset($_POST['search'])?$_POST['search']:'')),
234
+ 'sort' => (isset($_GET['sort'])?$_GET['sort']:(isset($_POST['sort'])?$_POST['sort']:'')),
235
+ 'sdir' => (isset($_GET['sdir'])?$_GET['sdir']:(isset($_POST['sdir'])?$_POST['sdir']:''))
236
+ );
237
+
238
+ return $values;
239
+ }
240
+
241
+ }
242
+ ?>
classes/models/PrliGroup.php ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class PrliGroup
3
+ {
4
+ var $table_name;
5
+
6
+ function PrliGroup()
7
+ {
8
+ global $wpdb;
9
+ $this->table_name = "{$wpdb->prefix}prli_groups";
10
+ }
11
+
12
+ function create( $values )
13
+ {
14
+ global $wpdb, $wp_rewrite;
15
+
16
+ $query = 'INSERT INTO ' . $this->table_name .
17
+ ' (name,description,created_at) VALUES (\'' .
18
+ $values['name'] . '\',\'' .
19
+ $values['description'] . '\',' .
20
+ 'NOW())';
21
+ $query_results = $wpdb->query($query);
22
+ return $wpdb->insert_id;
23
+ }
24
+
25
+ function update( $id, $values )
26
+ {
27
+ global $wpdb, $wp_rewrite;
28
+
29
+ $query = 'UPDATE ' . $this->table_name .
30
+ ' SET name=\'' . $values['name'] . '\', ' .
31
+ ' description=\'' . $values['description'] . '\' ' .
32
+ ' WHERE id='.$id;
33
+ $query_results = $wpdb->query($query);
34
+ return $query_results;
35
+ }
36
+
37
+ function destroy( $id )
38
+ {
39
+ require_once(PRLI_MODELS_PATH.'/models.inc.php');
40
+ global $wpdb, $prli_link, $wp_rewrite;
41
+
42
+ // Disconnect the links from this group
43
+ $query = 'UPDATE ' . $prli_link->table_name .
44
+ ' SET group_id = NULL ' .
45
+ ' WHERE group_id='.$id;
46
+ $query_results = $wpdb->query($query);
47
+
48
+ $destroy = 'DELETE FROM ' . $this->table_name . ' WHERE id=' . $id;
49
+ return $wpdb->query($destroy);
50
+ }
51
+
52
+ function getOne( $id )
53
+ {
54
+ global $wpdb, $prli_link, $prli_click;
55
+ $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 . ';';
56
+ return $wpdb->get_row($query);
57
+ }
58
+
59
+ function getAll( $where = '', $order_by = '', $return_type = OBJECT )
60
+ {
61
+ global $wpdb, $prli_utils, $prli_link, $prli_click;
62
+ $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;
63
+ return $wpdb->get_results($query, $return_type);
64
+ }
65
+
66
+ // Pagination Methods
67
+ function getRecordCount($where="")
68
+ {
69
+ global $wpdb, $prli_utils;
70
+ $query = 'SELECT COUNT(*) FROM ' . $this->table_name . $prli_utils->prepend_and_or_where(' WHERE', $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_by = '')
80
+ {
81
+ global $wpdb, $prli_link, $prli_utils, $prli_click;
82
+ $end_index = $current_p * $p_size;
83
+ $start_index = $end_index - $p_size;
84
+ $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;
85
+ $results = $wpdb->get_results($query);
86
+ return $results;
87
+ }
88
+
89
+ // Set defaults and grab get or post of each possible param
90
+ function get_params_array()
91
+ {
92
+ $values = array(
93
+ 'action' => (isset($_GET['action'])?$_GET['action']:(isset($_POST['action'])?$_POST['action']:'list')),
94
+ 'id' => (isset($_GET['id'])?$_GET['id']:(isset($_POST['id'])?$_POST['id']:'')),
95
+ 'paged' => (isset($_GET['paged'])?$_GET['paged']:(isset($_POST['paged'])?$_POST['paged']:1)),
96
+ 'group' => (isset($_GET['group'])?$_GET['group']:(isset($_POST['group'])?$_POST['group']:'')),
97
+ 'search' => (isset($_GET['search'])?$_GET['search']:(isset($_POST['search'])?$_POST['search']:'')),
98
+ 'sort' => (isset($_GET['sort'])?$_GET['sort']:(isset($_POST['sort'])?$_POST['sort']:'')),
99
+ 'sdir' => (isset($_GET['sdir'])?$_GET['sdir']:(isset($_POST['sdir'])?$_POST['sdir']:''))
100
+ );
101
+
102
+ return $values;
103
+ }
104
+
105
+ function validate( $values )
106
+ {
107
+ global $wpdb, $prli_utils;
108
+
109
+ $errors = array();
110
+ if( empty($values['name']) )
111
+ $errors[] = "Group must have a name.";
112
+
113
+ return $errors;
114
+ }
115
+ }
116
+ ?>
classes/models/PrliLink.php ADDED
@@ -0,0 +1,307 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class PrliLink
3
+ {
4
+ var $table_name;
5
+
6
+ function PrliLink()
7
+ {
8
+ global $wpdb;
9
+ $this->table_name = "{$wpdb->prefix}prli_links";
10
+ }
11
+
12
+ function create( $values )
13
+ {
14
+ global $wpdb;
15
+
16
+ $values['name'] = (!empty($values['name'])?$values['name']:$values['slug']);
17
+ $query_str = "INSERT INTO {$this->table_name} " .
18
+ '(url,'.
19
+ 'slug,'.
20
+ 'name,'.
21
+ 'param_forwarding,'.
22
+ 'param_struct,'.
23
+ 'redirect_type,'.
24
+ 'description,'.
25
+ 'track_me,'.
26
+ 'nofollow,'.
27
+ 'group_id,'.
28
+ 'created_at) ' .
29
+ 'VALUES (%s,%s,%s,%s,%s,%s,%s,%d,%d,%d,NOW())';
30
+
31
+ $query = $wpdb->prepare( $query_str,
32
+ $values['url'],
33
+ $values['slug'],
34
+ $values['name'],
35
+ $values['param_forwarding'],
36
+ $values['param_struct'],
37
+ $values['redirect_type'],
38
+ $values['description'],
39
+ (int)isset($values['track_me']),
40
+ (int)isset($values['nofollow']),
41
+ (isset($values['group_id'])?(int)$values['group_id']:'NULL') );
42
+ $query_results = $wpdb->query($query);
43
+
44
+ if($query_results)
45
+ return $wpdb->insert_id;
46
+ else
47
+ return false;
48
+ }
49
+
50
+ function update( $id, $values )
51
+ {
52
+ global $wpdb;
53
+
54
+ $values['name'] = (!empty($values['name'])?$values['name']:$values['slug']);
55
+ $query_str = "UPDATE {$this->table_name} " .
56
+ 'SET url=%s, ' .
57
+ 'slug=%s, ' .
58
+ 'name=%s, ' .
59
+ 'param_forwarding=%s, ' .
60
+ 'param_struct=%s, ' .
61
+ 'redirect_type=%s, ' .
62
+ 'description=%s, ' .
63
+ 'track_me=%d, ' .
64
+ 'nofollow=%d, ' .
65
+ 'group_id=%d ' .
66
+ ' WHERE id=%d';
67
+
68
+ $query = $wpdb->prepare( $query_str,
69
+ $values['url'],
70
+ $values['slug'],
71
+ $values['name'],
72
+ $values['param_forwarding'],
73
+ $values['param_struct'],
74
+ $values['redirect_type'],
75
+ $values['description'],
76
+ (int)isset($values['track_me']),
77
+ (int)isset($values['nofollow']),
78
+ (isset($values['group_id'])?(int)$values['group_id']:'NULL'),
79
+ $id );
80
+
81
+ $query_results = $wpdb->query($query);
82
+ return $query_results;
83
+ }
84
+
85
+ function update_group( $id, $value, $group_id )
86
+ {
87
+ global $wpdb;
88
+ $query = 'UPDATE ' . $this->table_name .
89
+ ' SET group_id=' . (isset($value)?$group_id:'NULL') .
90
+ ' WHERE id='.$id;
91
+ $query_results = $wpdb->query($query);
92
+ return $query_results;
93
+ }
94
+
95
+ function destroy( $id )
96
+ {
97
+ require_once(PRLI_MODELS_PATH.'/models.inc.php');
98
+ global $wpdb, $prli_click;
99
+
100
+ $reset = 'DELETE FROM ' . $prli_click->table_name . ' WHERE link_id=' . $id;
101
+ $destroy = 'DELETE FROM ' . $this->table_name . ' WHERE id=' . $id;
102
+
103
+ $wpdb->query($reset);
104
+ return $wpdb->query($destroy);
105
+ }
106
+
107
+ function reset( $id )
108
+ {
109
+ require_once(PRLI_MODELS_PATH.'/models.inc.php');
110
+ global $wpdb, $prli_click;
111
+
112
+ $reset = 'DELETE FROM ' . $prli_click->table_name . ' WHERE link_id=' . $id;
113
+ return $wpdb->query($reset);
114
+ }
115
+
116
+ function getOneFromSlug( $slug, $return_type = OBJECT )
117
+ {
118
+ global $wpdb, $prli_click;
119
+ $query = 'SELECT li.*, ' .
120
+ '(SELECT COUNT(*) FROM ' . $prli_click->table_name . ' cl ' .
121
+ 'WHERE cl.link_id = li.id' . $prli_click->get_exclude_where_clause( ' AND' ) . ') as clicks, ' .
122
+ '(SELECT COUNT(*) FROM ' . $prli_click->table_name . ' cl ' .
123
+ 'WHERE cl.link_id = li.id ' .
124
+ 'AND cl.first_click <> 0' . $prli_click->get_exclude_where_clause( ' AND' ) . ') as uniques ' .
125
+ 'FROM ' . $this->table_name . ' li ' .
126
+ 'WHERE slug=\'' . $slug . '\'';
127
+ return $wpdb->get_row($query, $return_type);
128
+ }
129
+
130
+ function getOne( $id )
131
+ {
132
+ global $wpdb, $prli_click;
133
+ $query = 'SELECT li.*, ' .
134
+ '(SELECT COUNT(*) FROM ' . $prli_click->table_name . ' cl ' .
135
+ 'WHERE cl.link_id = li.id' . $prli_click->get_exclude_where_clause( ' AND' ) . ') as clicks, ' .
136
+ '(SELECT COUNT(*) FROM ' . $prli_click->table_name . ' cl ' .
137
+ 'WHERE cl.link_id = li.id ' .
138
+ 'AND cl.first_click <> 0' . $prli_click->get_exclude_where_clause( ' AND' ) . ') as uniques ' .
139
+ 'FROM ' . $this->table_name . ' li ' .
140
+ 'WHERE id=' . $id;
141
+ return $wpdb->get_row($query);
142
+ }
143
+
144
+ function get_link_min( $id, $return_type = OBJECT )
145
+ {
146
+ global $wpdb;
147
+ $query_str = 'SELECT id,'.
148
+ 'url,'.
149
+ 'slug,'.
150
+ 'name,'.
151
+ 'description,'.
152
+ 'group_id,'.
153
+ 'redirect_type,'.
154
+ 'track_me,'.
155
+ 'param_forwarding,'.
156
+ 'param_struct'.
157
+ "FROM {$this->table_name} ".
158
+ 'WHERE id=%d';
159
+ $query = $wpdb->prepare($query_str, $id);
160
+ return $wpdb->get_row($query, $return_type);
161
+ }
162
+
163
+ function getAll($where = '', $order_by = '', $return_type = OBJECT)
164
+ {
165
+ global $wpdb, $prli_click, $prli_group, $prli_utils;
166
+ $query = 'SELECT li.*, ' .
167
+ '(SELECT COUNT(*) FROM ' . $prli_click->table_name . ' cl ' .
168
+ 'WHERE cl.link_id = li.id' . $prli_click->get_exclude_where_clause( ' AND' ) . ') as clicks, ' .
169
+ '(SELECT COUNT(*) FROM ' . $prli_click->table_name . ' cl ' .
170
+ 'WHERE cl.link_id = li.id ' .
171
+ 'AND cl.first_click <> 0' . $prli_click->get_exclude_where_clause( ' AND' ) . ') as uniques, ' .
172
+ 'gr.name as group_name ' .
173
+ 'FROM '. $this->table_name . ' li ' .
174
+ 'LEFT OUTER JOIN ' . $prli_group->table_name . ' gr ON li.group_id=gr.id' .
175
+ $prli_utils->prepend_and_or_where(' WHERE', $where) . $order_by;
176
+ return $wpdb->get_results($query, $return_type);
177
+ }
178
+
179
+ // Pagination Methods
180
+ function getRecordCount($where="")
181
+ {
182
+ global $wpdb, $prli_utils;
183
+ $query = 'SELECT COUNT(*) FROM ' . $this->table_name . ' li' . $prli_utils->prepend_and_or_where(' WHERE', $where);
184
+ return $wpdb->get_var($query);
185
+ }
186
+
187
+ function getPageCount($p_size, $where="")
188
+ {
189
+ return ceil((int)$this->getRecordCount($where) / (int)$p_size);
190
+ }
191
+
192
+ function getPage($current_p,$p_size, $where = "", $order_by = '', $return_type = OBJECT)
193
+ {
194
+ global $wpdb, $prli_click, $prli_utils, $prli_group;
195
+ $end_index = $current_p * $p_size;
196
+ $start_index = $end_index - $p_size;
197
+ $query = 'SELECT li.*, ' .
198
+ '(SELECT COUNT(*) FROM ' . $prli_click->table_name . ' cl ' .
199
+ 'WHERE cl.link_id = li.id' . $prli_click->get_exclude_where_clause( ' AND' ) . ') as clicks, ' .
200
+ '(SELECT COUNT(*) FROM ' . $prli_click->table_name . ' cl ' .
201
+ 'WHERE cl.link_id = li.id ' .
202
+ 'AND cl.first_click <> 0' . $prli_click->get_exclude_where_clause( ' AND' ) . ') as uniques, ' .
203
+ 'gr.name as group_name ' .
204
+ 'FROM ' . $this->table_name . ' li ' .
205
+ 'LEFT OUTER JOIN ' . $prli_group->table_name . ' gr ON li.group_id=gr.id' .
206
+ $prli_utils->prepend_and_or_where(' WHERE', $where) . $order_by . ' ' .
207
+ 'LIMIT ' . $start_index . ',' . $p_size . ';';
208
+ $results = $wpdb->get_results($query, $return_type);
209
+ return $results;
210
+ }
211
+
212
+ /** I'm generating a slug that is by default 2-3 characters long.
213
+ * This gives us a possibility of 36^3 - 37 = 46,619 possible
214
+ * random slugs. That should be *more* than enough slugs for
215
+ * any website -- if I get any feedback that we need more then
216
+ * I can always make a config option to raise the # of chars.
217
+ */
218
+ function generateValidSlug($num_chars = 3)
219
+ {
220
+ global $wpdb, $prli_utils;
221
+
222
+ // We're doing a base 36 hash which is why we're always doing everything by 36
223
+ $max_slug_value = pow(36,$num_chars);
224
+ $min_slug_value = 37; // we want to have at least 2 characters in the slug
225
+ $slug = base_convert( rand($min_slug_value,$max_slug_value), 10, 36 );
226
+
227
+ $query = "SELECT slug FROM " . $this->table_name; // . " WHERE slug='" . $slug . "'";
228
+ $slugs = $wpdb->get_col($query,0);
229
+
230
+ // It is highly unlikely that we'll ever see 2 identical random slugs
231
+ // but just in case, here's some code to prevent collisions
232
+ while( in_array($slug,$slugs) or !$prli_utils->slugIsAvailable($slug) )
233
+ $slug = base_convert( rand($min_slug_value,$max_slug_value), 10, 36 );
234
+
235
+ return $slug;
236
+ }
237
+
238
+ function get_pretty_link_url($slug)
239
+ {
240
+ global $prli_blogurl;
241
+
242
+ $link = $this->getOneFromSlug($slug);
243
+
244
+ if((isset($link->param_forwarding) and $link->param_forwarding == 'custom') and
245
+ (isset($link->redirect_type) and $link->redirect_type == 'pixel'))
246
+ return "&lt;img src=\"".$prli_blogurl . '/' . $link->slug . $link->param_struct . "\" width=\"1\" height=\"1\" style=\"display: none\" /&gt;";
247
+ else if((!isset($link->param_forwarding) or $link->param_forwarding != 'custom') and
248
+ (isset($link->redirect_type) and $link->redirect_type == 'pixel'))
249
+ return "&lt;img src=\"".$prli_blogurl . '/' . $link->slug . "\" width=\"1\" height=\"1\" style=\"display: none\" /&gt;";
250
+ else if((isset($link->param_forwarding) and $link->param_forwarding == 'custom') and
251
+ (!isset($link->redirect_type) or $link->redirect_type != 'pixel'))
252
+ return $prli_blogurl . '/' . $link->slug . $link->param_struct;
253
+ else
254
+ return $prli_blogurl . '/' . $link->slug;
255
+ }
256
+
257
+ // Set defaults and grab get or post of each possible param
258
+ function get_params_array()
259
+ {
260
+ $values = array(
261
+ 'action' => (isset($_GET['action'])?$_GET['action']:(isset($_POST['action'])?$_POST['action']:'list')),
262
+ 'regenerate' => (isset($_GET['regenerate'])?$_GET['regenerate']:(isset($_POST['regenerate'])?$_POST['regenerate']:'false')),
263
+ 'id' => (isset($_GET['id'])?$_GET['id']:(isset($_POST['id'])?$_POST['id']:'')),
264
+ 'group_name' => (isset($_GET['group_name'])?$_GET['group_name']:(isset($_POST['group_name'])?$_POST['group_name']:'')),
265
+ 'paged' => (isset($_GET['paged'])?$_GET['paged']:(isset($_POST['paged'])?$_POST['paged']:1)),
266
+ 'group' => (isset($_GET['group'])?$_GET['group']:(isset($_POST['group'])?$_POST['group']:'')),
267
+ 'search' => (isset($_GET['search'])?$_GET['search']:(isset($_POST['search'])?$_POST['search']:'')),
268
+ 'sort' => (isset($_GET['sort'])?$_GET['sort']:(isset($_POST['sort'])?$_POST['sort']:'')),
269
+ 'sdir' => (isset($_GET['sdir'])?$_GET['sdir']:(isset($_POST['sdir'])?$_POST['sdir']:''))
270
+ );
271
+
272
+ return $values;
273
+ }
274
+
275
+ function validate( $values )
276
+ {
277
+ global $wpdb, $prli_utils, $prli_blogurl;
278
+
279
+ $errors = array();
280
+ if( ( $values['url'] == null or $values['url'] == '') and $values['redirect_type'] != 'pixel' )
281
+ $errors[] = "Target URL can't be blank";
282
+
283
+ if( $values['slug'] == null or $values['slug'] == '' )
284
+ $errors[] = "Pretty Link can't be blank";
285
+
286
+ if( $values['url'] == "$prli_blogurl/".$values['slug'] )
287
+ $errors[] = "Target URL must be different than the Pretty Link";
288
+
289
+ if( !empty($values['url']) and !preg_match('/^http.?:\/\/.*\..*$/', $values['url'] ) )
290
+ $errors[] = "Link URL must be a correctly formatted url";
291
+
292
+ if( !preg_match('/^[a-zA-Z0-9\.\-_\/]+$/', $values['slug'] ) )
293
+ $errors[] = "Pretty Link must not contain spaces or special characters";
294
+
295
+ if( !$prli_utils->slugIsAvailable($values['slug'],$values['id']) )
296
+ $errors[] = "This pretty link slug is already taken, please choose a different one";
297
+
298
+ if( isset($values['param_forwarding']) and $values['param_forwarding'] == 'custom' and empty($values['param_struct']) )
299
+ $errors[] = "If Custom Parameter Forwarding has been selected then you must specify a forwarding format.";
300
+
301
+ if( isset($values['param_forwarding']) and $values['param_forwarding'] == 'custom' and !preg_match('#%.*?%#', $values['param_struct']) )
302
+ $errors[] = "Your parameter forwarding must have at least one parameter specified in the format ex: <code>/%var1%/%var_two%/%varname3% ...</code>";
303
+
304
+ return $errors;
305
+ }
306
+ }
307
+ ?>
classes/models/PrliLinkMeta.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class PrliLinkMeta
3
+ {
4
+ var $table_name;
5
+
6
+ function PrliLinkMeta()
7
+ {
8
+ global $wpdb;
9
+ $this->table_name = "{$wpdb->prefix}prli_link_metas";
10
+ }
11
+
12
+ function get_link_meta($link_id,$meta_key,$return_var=false)
13
+ {
14
+ global $wpdb;
15
+ $query_str = "SELECT meta_value FROM {$this->table_name} WHERE meta_key=%s and link_id=%d";
16
+ $query = $wpdb->prepare($query_str,$meta_key,$link_id);
17
+
18
+ if($return_var)
19
+ return $wpdb->get_var("{$query} LIMIT 1");
20
+ else
21
+ return $wpdb->get_col($query, 0);
22
+ }
23
+
24
+ function add_link_meta($link_id, $meta_key, $meta_value)
25
+ {
26
+ global $wpdb;
27
+
28
+ $query_str = "INSERT INTO {$this->table_name} " .
29
+ '(meta_key,meta_value,link_id,created_at) VALUES (%s,%s,%d,NOW())';
30
+ $query = $wpdb->prepare($query_str, $meta_key, $meta_value, $link_id);
31
+ return $wpdb->query($query);
32
+ }
33
+
34
+ function update_link_meta($link_id, $meta_key, $meta_values)
35
+ {
36
+ global $wpdb;
37
+ $this->delete_link_meta($link_id, $meta_key);
38
+
39
+ if(!is_array($meta_values))
40
+ $meta_values = array($meta_values);
41
+
42
+ foreach($meta_values as $meta_value)
43
+ $this->add_link_meta($link_id, $meta_key, $meta_value);
44
+
45
+ return $wpdb->query($query);
46
+ }
47
+
48
+ function delete_link_meta($link_id, $meta_key)
49
+ {
50
+ global $wpdb;
51
+
52
+ $query_str = "DELETE FROM {$this->table_name} " .
53
+ "WHERE meta_key=%s AND link_id=%d";
54
+ $query = $wpdb->prepare($query_str, $meta_key, $link_id);
55
+ return $wpdb->query($query);
56
+ }
57
+ }
58
+ ?>
classes/models/PrliOptions.php ADDED
@@ -0,0 +1,258 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class PrliOptions
3
+ {
4
+ var $prli_exclude_ips;
5
+ var $prettybar_image_url;
6
+ var $prettybar_background_image_url;
7
+ var $prettybar_color;
8
+ var $prettybar_text_color;
9
+ var $prettybar_link_color;
10
+ var $prettybar_hover_color;
11
+ var $prettybar_visited_color;
12
+ var $prettybar_show_title;
13
+ var $prettybar_show_description;
14
+ var $prettybar_show_share_links;
15
+ var $prettybar_show_target_url_link;
16
+ var $prettybar_title_limit;
17
+ var $prettybar_desc_limit;
18
+ var $prettybar_link_limit;
19
+
20
+ var $link_redirect_type;
21
+ var $link_track_me;
22
+ var $link_nofollow;
23
+
24
+ var $bookmarklet_auth;
25
+
26
+ function PrliOptions()
27
+ {
28
+ $this->set_default_options();
29
+ }
30
+
31
+ function set_default_options()
32
+ {
33
+ // Must account for the Legacy Options
34
+ $prli_exclude_ips = 'prli_exclude_ips';
35
+ $prettybar_image_url = 'prli_prettybar_image_url';
36
+ $prettybar_background_image_url = 'prli_prettybar_background_image_url';
37
+ $prettybar_color = 'prli_prettybar_color';
38
+ $prettybar_text_color = 'prli_prettybar_text_color';
39
+ $prettybar_link_color = 'prli_prettybar_link_color';
40
+ $prettybar_hover_color = 'prli_prettybar_hover_color';
41
+ $prettybar_visited_color = 'prli_prettybar_visited_color';
42
+ $prettybar_show_title = 'prli_prettybar_show_title';
43
+ $prettybar_show_description = 'prli_prettybar_show_description';
44
+ $prettybar_show_share_links = 'prli_prettybar_show_share_links';
45
+ $prettybar_show_target_url_link = 'prli_prettybar_show_target_url_link';
46
+ $prettybar_title_limit = 'prli_prettybar_title_limit';
47
+ $prettybar_desc_limit = 'prli_prettybar_desc_limit';
48
+ $prettybar_link_limit = 'prli_prettybar_link_limit';
49
+ $link_show_prettybar = 'prli_link_show_prettybar';
50
+ $link_ultra_cloak = 'prli_link_ultra_cloak';
51
+ $link_track_me = 'prli_link_track_me';
52
+ $link_track_as_pixel = 'prli_link_track_as_pixel';
53
+ $link_nofollow = 'prli_link_nofollow';
54
+ $link_redirect_type = 'prli_link_redirect_type';
55
+
56
+
57
+ if(!isset($this->prettybar_show_title)) {
58
+ if($var = get_option( $prettybar_show_title )) {
59
+ $this->prettybar_show_title = $var;
60
+ delete_option( $prettybar_show_title );
61
+ }
62
+ else
63
+ $this->prettybar_show_title = '1';
64
+ }
65
+
66
+ if(!isset($this->prettybar_show_description)) {
67
+ if($var = get_option( $prettybar_show_description )) {
68
+ $this->prettybar_show_description = $var;
69
+ delete_option( $prettybar_show_description );
70
+ }
71
+ else
72
+ $this->prettybar_show_description = '1';
73
+ }
74
+
75
+ if(!isset($this->prettybar_show_share_links)) {
76
+ if($var = get_option( $prettybar_show_share_links )) {
77
+ $this->prettybar_show_share_links = $var;
78
+ delete_option( $prettybar_show_share_links );
79
+ }
80
+ else
81
+ $this->prettybar_show_share_links = '1';
82
+ }
83
+
84
+ if(!isset($this->prettybar_show_target_url_link)) {
85
+ if($var = get_option( $prettybar_show_target_url_link )) {
86
+ $this->prettybar_show_target_url_link = $var;
87
+ delete_option( $prettybar_show_target_url_link );
88
+ }
89
+ else
90
+ $this->prettybar_show_target_url_link = '1';
91
+ }
92
+
93
+ if(!isset($this->link_track_me)) {
94
+ if($var = get_option( $link_track_me )) {
95
+ $this->link_track_me = $var;
96
+ delete_option( $link_track_me );
97
+ }
98
+ else
99
+ $this->link_track_me = '1';
100
+ }
101
+
102
+ if(!isset($this->link_nofollow)) {
103
+ if($var = get_option( $link_nofollow )) {
104
+ $this->link_nofollow = $var;
105
+ delete_option( $link_nofollow );
106
+ }
107
+ else
108
+ $this->link_nofollow = '0';
109
+ }
110
+
111
+ if(!isset($this->link_redirect_type)) {
112
+ if($var = get_option( $link_track_as_pixel )) {
113
+ $this->link_redirect_type = 'pixel';
114
+ delete_option( $link_show_prettybar );
115
+ delete_option( $link_ultra_cloak );
116
+ delete_option( $link_track_as_pixel );
117
+ delete_option( $link_redirect_type );
118
+ }
119
+ if($var = get_option( $link_show_prettybar )) {
120
+ $this->link_redirect_type = 'prettybar';
121
+ delete_option( $link_show_prettybar );
122
+ delete_option( $link_ultra_cloak );
123
+ delete_option( $link_track_as_pixel );
124
+ delete_option( $link_redirect_type );
125
+ }
126
+ if($var = get_option( $link_ultra_cloak )) {
127
+ $this->link_redirect_type = 'cloak';
128
+ delete_option( $link_show_prettybar );
129
+ delete_option( $link_ultra_cloak );
130
+ delete_option( $link_track_as_pixel );
131
+ delete_option( $link_redirect_type );
132
+ }
133
+ if($var = get_option( $link_redirect_type )) {
134
+ $this->link_redirect_type = $var;
135
+ delete_option( $link_show_prettybar );
136
+ delete_option( $link_ultra_cloak );
137
+ delete_option( $link_track_as_pixel );
138
+ delete_option( $link_redirect_type );
139
+ }
140
+ else
141
+ $this->link_redirect_type = '307';
142
+ }
143
+
144
+ if(!isset($this->prli_exclude_ips))
145
+ {
146
+ if($var = get_option( $prli_exclude_ips )) {
147
+ $this->prli_exclude_ips = $var;
148
+ delete_option( $prli_exclude_ips );
149
+ }
150
+ else
151
+ $this->prli_exclude_ips = '';
152
+ }
153
+
154
+ if(!isset($this->prettybar_image_url))
155
+ {
156
+ if($var = get_option( $prettybar_image_url )) {
157
+ $this->prettybar_image_url = $var;
158
+ delete_option( $prettybar_image_url );
159
+ }
160
+ else
161
+ $this->prettybar_image_url = PRLI_URL . '/images/pretty-link-48x48.png';
162
+ }
163
+
164
+ if(!isset($this->prettybar_background_image_url))
165
+ {
166
+ if($var = get_option( $prettybar_background_image_url )) {
167
+ $this->prettybar_background_image_url = $var;
168
+ delete_option( $prettybar_background_image_url );
169
+ }
170
+ else
171
+ $this->prettybar_background_image_url = PRLI_URL . '/images/bar_background.png';
172
+ }
173
+
174
+ if(!isset($this->prettybar_color))
175
+ {
176
+ if($var = get_option( $prettybar_color )) {
177
+ $this->prettybar_color = $var;
178
+ delete_option( $prettybar_color );
179
+ }
180
+ else
181
+ $this->prettybar_color = '';
182
+ }
183
+
184
+ if(!isset($this->prettybar_text_color))
185
+ {
186
+ if($var = get_option( $prettybar_text_color )) {
187
+ $this->prettybar_text_color = $var;
188
+ delete_option( $prettybar_text_color );
189
+ }
190
+ else
191
+ $this->prettybar_text_color = '000000';
192
+ }
193
+
194
+ if(!isset($this->prettybar_link_color))
195
+ {
196
+ if($var = get_option( $prettybar_link_color )) {
197
+ $this->prettybar_link_color = $var;
198
+ delete_option( $prettybar_link_color );
199
+ }
200
+ else
201
+ $this->prettybar_link_color = '0000ee';
202
+ }
203
+
204
+ if(!isset($this->prettybar_hover_color))
205
+ {
206
+ if($var = get_option( $prettybar_hover_color )) {
207
+ $this->prettybar_hover_color = $var;
208
+ delete_option( $prettybar_hover_color );
209
+ }
210
+ else
211
+ $this->prettybar_hover_color = 'ababab';
212
+ }
213
+
214
+ if(!isset($this->prettybar_visited_color))
215
+ {
216
+ if($var = get_option( $prettybar_visited_color )) {
217
+ $this->prettybar_visited_color = $var;
218
+ delete_option( $prettybar_visited_color );
219
+ }
220
+ else
221
+ $this->prettybar_visited_color = '551a8b';
222
+ }
223
+
224
+ if(!isset($this->prettybar_title_limit))
225
+ {
226
+ if($var = get_option( $prettybar_title_limit )) {
227
+ $this->prettybar_title_limit = $var;
228
+ delete_option( $prettybar_title_limit );
229
+ }
230
+ else
231
+ $this->prettybar_title_limit = '25';
232
+ }
233
+
234
+ if(!isset($this->prettybar_desc_limit))
235
+ {
236
+ if($var = get_option( $prettybar_desc_limit )) {
237
+ $this->prettybar_desc_limit = $var;
238
+ delete_option( $prettybar_desc_limit );
239
+ }
240
+ else
241
+ $this->prettybar_desc_limit = '30';
242
+ }
243
+
244
+ if(!isset($this->prettybar_link_limit))
245
+ {
246
+ if($var = get_option( $prettybar_link_limit )) {
247
+ $this->prettybar_link_limit = $var;
248
+ delete_option( $prettybar_link_limit );
249
+ }
250
+ else
251
+ $this->prettybar_link_limit = '30';
252
+ }
253
+
254
+ if(!isset($this->bookmarklet_auth))
255
+ $this->bookmarklet_auth = md5(get_option('auth_salt') . time());
256
+ }
257
+ }
258
+ ?>
classes/models/PrliUtils.php ADDED
@@ -0,0 +1,944 @@