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

Version Description

Download this release

Release Info

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

Version 1.3.41

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