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

Version Description

  • Added support for Pre-Slug URL elements -- this will be helpful for those users who don't have rewrite working fully
  • Additional, unnecessary postmeta fields not being created anymore for pro users
  • Fixed auto pretty link creation and auto twitter posting on scheduled and xml-rpc post for pro users
  • Fixed twitter badge count issue -- it was reporting incorrect tweet results for some pro users on some posts
  • Added Option to show tweet badge and/or social buttons in the RSS Feed
Download this release

Release Info

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

Version 1.4.40

Files changed (109) hide show
  1. classes/models/PrliClick.php +279 -0
  2. classes/models/PrliGroup.php +124 -0
  3. classes/models/PrliLink.php +332 -0
  4. classes/models/PrliLinkMeta.php +59 -0
  5. classes/models/PrliOptions.php +266 -0
  6. classes/models/PrliUpdate.php +313 -0
  7. classes/models/PrliUrlUtils.php +122 -0
  8. classes/models/PrliUtils.php +1025 -0
  9. classes/models/models.inc.php +46 -0
  10. classes/views/prli-clicks/csv.php +24 -0
  11. classes/views/prli-clicks/head.php +105 -0
  12. classes/views/prli-clicks/list.php +151 -0
  13. classes/views/prli-dashboard-widget/widget.php +23 -0
  14. classes/views/prli-groups/edit.php +58 -0
  15. classes/views/prli-groups/head.php +35 -0
  16. classes/views/prli-groups/list.php +85 -0
  17. classes/views/prli-groups/new.php +59 -0
  18. classes/views/prli-links/bar.php +12 -0
  19. classes/views/prli-links/edit.php +22 -0
  20. classes/views/prli-links/form.php +94 -0
  21. classes/views/prli-links/head.php +91 -0
  22. classes/views/prli-links/list.php +185 -0
  23. classes/views/prli-links/new.php +22 -0
  24. classes/views/prli-links/ultra-cloak.php +11 -0
  25. classes/views/prli-options/form.php +176 -0
  26. classes/views/prli-options/head.php +54 -0
  27. classes/views/prli-options/pro-settings.php +18 -0
  28. classes/views/prli-tools/form.php +20 -0
  29. classes/views/shared/errors.php +19 -0
  30. classes/views/shared/link-table-nav.php +102 -0
  31. classes/views/shared/nav.php +18 -0
  32. classes/views/shared/table-nav.php +93 -0
  33. images/arrow_down.png +0 -0
  34. images/arrow_up.png +0 -0
  35. images/bar_background.png +0 -0
  36. images/bar_map.png +0 -0
  37. images/bookmark.png +0 -0
  38. images/co.mments.gif +0 -0
  39. images/delicious_32.png +0 -0
  40. images/digg_32.png +0 -0
  41. images/email_32.png +0 -0
  42. images/facebook.png +0 -0
  43. images/facebook_32.png +0 -0
  44. images/forward_params.png +0 -0
  45. images/hyves_32.png +0 -0
  46. images/linkedin_32.png +0 -0
  47. images/mixx_32.png +0 -0
  48. images/newsvine_32.png +0 -0
  49. images/nofollow.png +0 -0
  50. images/not_tracking.png +0 -0
  51. images/pixel_track.png +0 -0
  52. images/pretty-link-48x48.png +0 -0
  53. images/pretty-link-add.png +0 -0
  54. images/pretty-link-med.png +0 -0
  55. images/pretty-link-small.png +0 -0
  56. images/prettylink_logo.jpg +0 -0
  57. images/prettylink_logo_med.jpg +0 -0
  58. images/prettylink_logo_small.jpg +0 -0
  59. images/reddit_32.png +0 -0
  60. images/sphinn_32.png +0 -0
  61. images/stumbleupon_32.png +0 -0
  62. images/technorati_32.png +0 -0
  63. images/tracking.png +0 -0
  64. images/twitter.png +0 -0
  65. images/twitter_32.png +0 -0
  66. images/ultra-cloak.png +0 -0
  67. images/url_icon.gif +0 -0
  68. images/whatever.txt +13 -0
  69. images/yahoobuzz_32.png +0 -0
  70. includes/jquery/css/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  71. includes/jquery/css/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  72. includes/jquery/css/ui-lightness/images/ui-bg_flat_10_000000_40x100.png +0 -0
  73. includes/jquery/css/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  74. includes/jquery/css/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  75. includes/jquery/css/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  76. includes/jquery/css/ui-lightness/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  77. includes/jquery/css/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  78. includes/jquery/css/ui-lightness/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  79. includes/jquery/css/ui-lightness/images/ui-icons_222222_256x240.png +0 -0
  80. includes/jquery/css/ui-lightness/images/ui-icons_228ef1_256x240.png +0 -0
  81. includes/jquery/css/ui-lightness/images/ui-icons_ef8c08_256x240.png +0 -0
  82. includes/jquery/css/ui-lightness/images/ui-icons_ffd27a_256x240.png +0 -0
  83. includes/jquery/css/ui-lightness/images/ui-icons_ffffff_256x240.png +0 -0
  84. includes/jquery/css/ui-lightness/jquery-ui-1.7.1.custom.css +404 -0
  85. includes/jquery/js/jquery-1.3.2.min.js +19 -0
  86. includes/jquery/js/jquery-ui-1.7.1.custom.min.js +273 -0
  87. includes/php/php_browsecap.ini +17350 -0
  88. includes/version-2-kvasir/README.txt +8 -0
  89. includes/version-2-kvasir/js/README.txt +12 -0
  90. includes/version-2-kvasir/js/json/json2.js +461 -0
  91. includes/version-2-kvasir/js/swfobject.js +5 -0
  92. includes/version-2-kvasir/open-flash-chart.swf +0 -0
  93. pretty-bar.php +242 -0
  94. pretty-link.php +38 -0
  95. prli-add-link.php +9 -0
  96. prli-api.php +233 -0
  97. prli-bookmarklet.php +94 -0
  98. prli-clicks.php +237 -0
  99. prli-config.php +131 -0
  100. prli-dashboard-widget.php +13 -0
  101. prli-groups.php +175 -0
  102. prli-image-lookups.php +136 -0
  103. prli-links.php +233 -0
  104. prli-main.php +354 -0
  105. prli-options.php +138 -0
  106. prli-pro-settings.php +34 -0
  107. prli-tools.php +3 -0
  108. prli-xmlrpc.php +333 -0
  109. readme.txt +249 -0
classes/models/PrliClick.php ADDED
@@ -0,0 +1,279 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_exclude_where_clause( $where = '', $abbr = 'cl')
13
+ {
14
+ global $prli_options;
15
+ $exclude_list = trim($prli_options->prli_exclude_ips);
16
+ $filter_bots = (int)$prli_options->filter_robots;
17
+ $return_stmt = '';
18
+
19
+ if(empty($exclude_list) and $filter_bots == 0)
20
+ return $return_stmt;
21
+
22
+ $return_stmt .= (empty($where)?'':' AND');
23
+
24
+ if(!empty($exclude_list))
25
+ {
26
+ $exclude_ips = explode(',',$exclude_list);
27
+ for($i = 0; $i < count($exclude_ips); $i++)
28
+ {
29
+ $exclude_ip = trim(preg_replace('#\*#','%',$exclude_ips[$i]));
30
+
31
+ if($i > 0)
32
+ $return_stmt .= ' AND';
33
+
34
+ $return_stmt .= " {$abbr}.ip NOT LIKE '{$exclude_ip}'";
35
+ }
36
+ }
37
+
38
+ if($filter_bots != 0)
39
+ {
40
+ $return_stmt .= (empty($exclude_list)?' (':' AND (');
41
+ $whitelist = trim($prli_options->whitelist_ips);
42
+
43
+ if(!empty($whitelist))
44
+ {
45
+ $whitelist_ips = explode(',',$whitelist);
46
+ for($i = 0; $i <= count($whitelist_ips); $i++)
47
+ {
48
+ if($i == count($whitelist_ips))
49
+ {
50
+ $return_stmt .= ' OR';
51
+ break;
52
+ }
53
+
54
+ $whitelist_ip = trim(preg_replace('#\*#','%',$whitelist_ips[$i]));
55
+
56
+ if($i > 0)
57
+ $return_stmt .= ' OR';
58
+
59
+ $return_stmt .= " {$abbr}.ip LIKE '{$whitelist_ip}'";
60
+ }
61
+
62
+ }
63
+
64
+ $return_stmt .= " {$abbr}.robot=0 )";
65
+ }
66
+
67
+ return $return_stmt;
68
+ }
69
+
70
+ function getOne( $id )
71
+ {
72
+ global $wpdb, $prli_link, $prli_utils;
73
+ $click_table = $wpdb->prefix . "prli_clicks";
74
+ $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());
75
+
76
+ return $wpdb->get_row($query);
77
+ }
78
+
79
+ // 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
80
+ function getAll($where = '', $order = '', $include_stats = false)
81
+ {
82
+ global $wpdb, $prli_link, $prli_utils;
83
+ $click_table = $wpdb->prefix . "prli_clicks";
84
+ $where .= $this->get_exclude_where_clause( $where );
85
+ $where = $prli_utils->prepend_and_or_where(' AND', $where);
86
+ if($include_stats)
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;
88
+ else
89
+ $query = 'SELECT cl.*, li.name as link_name FROM ' . $this->table_name . ' cl, ' . $prli_link->table_name . ' li WHERE li.id = cl.link_id' . $where . $order;
90
+ return $wpdb->get_results($query);
91
+ }
92
+
93
+ // Delete all of the clicks from the database.
94
+ function clearAllClicks()
95
+ {
96
+ global $wpdb;
97
+ $query = "TRUNCATE TABLE " . $this->table_name;
98
+ return $wpdb->query($query);
99
+ }
100
+
101
+ // Pagination Methods
102
+ function getRecordCount($where='')
103
+ {
104
+ global $wpdb, $prli_link, $prli_utils;
105
+ $where .= $this->get_exclude_where_clause( $where );
106
+ $where = $prli_utils->prepend_and_or_where(' WHERE', $where);
107
+ $query = 'SELECT COUNT(*) FROM ' . $this->table_name . ' cl'. $where;
108
+ return $wpdb->get_var($query);
109
+ }
110
+
111
+ function getPageCount($p_size, $where='')
112
+ {
113
+ return ceil((int)$this->getRecordCount($where) / (int)$p_size);
114
+ }
115
+
116
+ function getPage($current_p,$p_size, $where = '', $order = '',$include_stats=false)
117
+ {
118
+ global $wpdb, $prli_link, $prli_utils;
119
+ $click_table = $wpdb->prefix . "prli_clicks";
120
+ $end_index = $current_p * $p_size;
121
+ $start_index = $end_index - $p_size;
122
+ $where .= $this->get_exclude_where_clause( $where );
123
+ $where = $prli_utils->prepend_and_or_where(' AND', $where);
124
+ if($include_stats)
125
+ $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 . ';';
126
+ else
127
+ $query = 'SELECT cl.*, 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 . ';';
128
+ $results = $wpdb->get_results($query);
129
+ return $results;
130
+ }
131
+
132
+ function generateUniqueVisitorId($num_chars = 6)
133
+ {
134
+ global $wpdb, $prli_utils;
135
+
136
+ // We're doing a base 36 hash which is why we're always doing everything by 36
137
+ $max_vuid_value = pow(36,$num_chars);
138
+ $min_vuid_value = 37;
139
+ $vuid = base_convert( mt_rand($min_vuid_value,$max_vuid_value), 10, 36 );
140
+
141
+ $query = "SELECT DISTINCT vuid FROM ".$this->table_name;
142
+ $vuids = $wpdb->get_col($query,0);
143
+
144
+ // It is highly unlikely that we'll ever see 2 identical random vuids
145
+ // but just in case, here's some code to prevent collisions
146
+ while( in_array($vuid,$vuids) )
147
+ $vuid = base_convert( mt_rand($min_vuid_value,$max_vuid_value), 10, 36 );
148
+
149
+ return $vuid;
150
+ }
151
+
152
+ function get_counts_by_days($start_timestamp, $end_timestamp, $link_id = "all", $type = "all", $group = '')
153
+ {
154
+ global $wpdb, $prli_link;
155
+
156
+ $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' );
157
+
158
+ if($link_id != "all")
159
+ $query .= " AND link_id=$link_id";
160
+
161
+ if(!empty($group))
162
+ $query .= " AND link_id IN (SELECT id FROM " . $prli_link->table_name . " WHERE group_id=$group)";
163
+
164
+ if($type == "unique")
165
+ $query .= " AND first_click=1";
166
+
167
+ $query .= ' GROUP BY DATE(cl.created_at)';
168
+
169
+ $clicks_array = $wpdb->get_results($query);
170
+
171
+ $temp_array = array();
172
+ $counts_array = array();
173
+ $dates_array = array();
174
+
175
+ // Refactor Array for use later on
176
+ foreach($clicks_array as $c)
177
+ $temp_array[$c->cldate] = $c->clcount;
178
+
179
+ // Get the dates array
180
+ for($c = $start_timestamp; $c <= $end_timestamp; $c += 60*60*24)
181
+ $dates_array[] = date("Y-m-d",$c);
182
+
183
+ // Make sure counts array is in order and includes zero click days
184
+ foreach($dates_array as $date_str)
185
+ {
186
+ if(isset($temp_array[$date_str]))
187
+ $counts_array[$date_str] = $temp_array[$date_str];
188
+ else
189
+ $counts_array[$date_str] = 0;
190
+ }
191
+
192
+ return $counts_array;
193
+ }
194
+
195
+
196
+ function setupClickLineGraph($start_timestamp,$end_timestamp, $link_id = "all", $type = "all", $group = '')
197
+ {
198
+ global $wpdb, $prli_utils, $prli_link, $prli_group;
199
+
200
+ $dates_array = $this->get_counts_by_days($start_timestamp,$end_timestamp,$link_id,$type,$group);
201
+
202
+ $top_click_count = $prli_utils->getTopValue(array_values($dates_array));
203
+
204
+ if(!empty($group))
205
+ $link_slug = "group: '" . $wpdb->get_var("SELECT name FROM ".$prli_group->table_name." WHERE id=$group") . "'";
206
+ else if($link_id == "all")
207
+ $link_slug = "all links";
208
+ else
209
+ $link_slug = "'/".$wpdb->get_var("SELECT slug FROM ".$prli_link->table_name." WHERE id=$link_id") . "'";
210
+
211
+ if($type == "all")
212
+ $type_string = "All hits";
213
+ else
214
+ $type_string = "Unique hits";
215
+
216
+ $json_array = array(
217
+ "elements" => array( array(
218
+ "type" => "line",
219
+ "values" => array_values($dates_array),
220
+ "dot-style" => array(
221
+ "type" => "dot",
222
+ "dot-size" => 4,
223
+ "colour" => "#ffc94e",
224
+ "halo-size" => 1,
225
+ "tip" => "#val# Hits<br>#x_label#"
226
+ ),
227
+ "width" => 2
228
+ ) ),
229
+ "title" => array(
230
+ "text" => 'Pretty Link: '.$type_string.' on '.$link_slug. ' between ' . date("Y-n-j",$start_timestamp) . ' and ' . date("Y-n-j",$end_timestamp),
231
+ "style" => "font-size: 16px; font-weight: bold; color: #3030d0; text-align: center; padding-bottom: 5px;"
232
+ ),
233
+ "bg_colour" => "-1",
234
+ "y_axis" => array(
235
+ "min" => 0,
236
+ "max" => $top_click_count,
237
+ "steps" => (int)(($top_click_count>=10)?$top_click_count/10:1),
238
+ "colour" => "#A2ACBA"
239
+ ),
240
+ "x_axis" => array(
241
+ "colour" => "#A2ACBA",
242
+ "grid-colour" => "#ffefa7",
243
+ "offset" => false,
244
+ "steps" => 4,
245
+ "labels" => array(
246
+ "steps" => 2,
247
+ "rotate" => 25,
248
+ "colour" => "#000000",
249
+ "labels" => array_keys($dates_array)
250
+ )
251
+ )
252
+ );
253
+
254
+ return $prli_utils->prli_json_encode($json_array);
255
+ }
256
+
257
+
258
+ // Set defaults and grab get or post of each possible param
259
+ function get_params_array()
260
+ {
261
+ $values = array(
262
+ 'paged' => (isset($_GET['paged'])?$_GET['paged']:(isset($_POST['paged'])?$_POST['paged']:1)),
263
+ 'l' => (isset($_GET['l'])?$_GET['l']:(isset($_POST['l'])?$_POST['l']:'all')),
264
+ 'group' => (isset($_GET['group'])?$_GET['group']:(isset($_POST['group'])?$_POST['group']:'')),
265
+ 'ip' => (isset($_GET['ip'])?$_GET['ip']:(isset($_POST['ip'])?$_POST['ip']:'')),
266
+ 'vuid' => (isset($_GET['vuid'])?$_GET['vuid']:(isset($_POST['vuid'])?$_POST['vuid']:'')),
267
+ 'sdate' => (isset($_GET['sdate'])?$_GET['sdate']:(isset($_POST['sdate'])?$_POST['sdate']:'')),
268
+ 'edate' => (isset($_GET['edate'])?$_GET['edate']:(isset($_POST['edate'])?$_POST['edate']:'')),
269
+ 'type' => (isset($_GET['type'])?$_GET['type']:(isset($_POST['type'])?$_POST['type']:'all')),
270
+ 'search' => (isset($_GET['search'])?$_GET['search']:(isset($_POST['search'])?$_POST['search']:'')),
271
+ 'sort' => (isset($_GET['sort'])?$_GET['sort']:(isset($_POST['sort'])?$_POST['sort']:'')),
272
+ 'sdir' => (isset($_GET['sdir'])?$_GET['sdir']:(isset($_POST['sdir'])?$_POST['sdir']:''))
273
+ );
274
+
275
+ return $values;
276
+ }
277
+
278
+ }
279
+ ?>
classes/models/PrliGroup.php ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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, $include_stats = false )
53
+ {
54
+ global $wpdb, $prli_link, $prli_click;
55
+
56
+ if($include_stats)
57
+ $query = 'SELECT gr.*, (SELECT COUNT(*) FROM ' . $prli_link->table_name . ' li WHERE li.group_id = gr.id) as link_count FROM ' . $this->table_name . ' gr WHERE id=' . $id;
58
+ else
59
+ $query = 'SELECT gr.* FROM ' . $this->table_name . ' gr WHERE id=' . $id;
60
+ return $wpdb->get_row($query);
61
+ }
62
+
63
+ function getAll( $where = '', $order_by = '', $return_type = OBJECT, $include_stats = false )
64
+ {
65
+ global $wpdb, $prli_utils, $prli_link, $prli_click;
66
+
67
+ if($include_stats)
68
+ $query = 'SELECT gr.*, (SELECT COUNT(*) FROM ' . $prli_link->table_name . ' li WHERE li.group_id = gr.id) as link_count FROM ' . $this->table_name . ' gr' . $prli_utils->prepend_and_or_where(' WHERE', $where) . $order_by;
69
+ else
70
+ $query = 'SELECT gr.* FROM ' . $this->table_name . " gr" . $prli_utils->prepend_and_or_where(' WHERE', $where) . $order_by;
71
+ return $wpdb->get_results($query, $return_type);
72
+ }
73
+
74
+ // Pagination Methods
75
+ function getRecordCount($where="")
76
+ {
77
+ global $wpdb, $prli_utils;
78
+ $query = 'SELECT COUNT(*) FROM ' . $this->table_name . $prli_utils->prepend_and_or_where(' WHERE', $where);
79
+ return $wpdb->get_var($query);
80
+ }
81
+
82
+ function getPageCount($p_size, $where="")
83
+ {
84
+ return ceil((int)$this->getRecordCount($where) / (int)$p_size);
85
+ }
86
+
87
+ function getPage($current_p,$p_size, $where = "", $order_by = '')
88
+ {
89
+ global $wpdb, $prli_link, $prli_utils, $prli_click;
90
+ $end_index = $current_p * $p_size;
91
+ $start_index = $end_index - $p_size;
92
+ $query = 'SELECT gr.*, (SELECT COUNT(*) FROM ' . $prli_link->table_name . ' li WHERE li.group_id = gr.id) as link_count FROM ' . $this->table_name . ' gr' . $prli_utils->prepend_and_or_where(' WHERE', $where) . $order_by .' LIMIT ' . $start_index . ',' . $p_size;
93
+ $results = $wpdb->get_results($query);
94
+ return $results;
95
+ }
96
+
97
+ // Set defaults and grab get or post of each possible param
98
+ function get_params_array()
99
+ {
100
+ $values = array(
101
+ 'action' => (isset($_GET['action'])?$_GET['action']:(isset($_POST['action'])?$_POST['action']:'list')),
102
+ 'id' => (isset($_GET['id'])?$_GET['id']:(isset($_POST['id'])?$_POST['id']:'')),
103
+ 'paged' => (isset($_GET['paged'])?$_GET['paged']:(isset($_POST['paged'])?$_POST['paged']:1)),
104
+ 'group' => (isset($_GET['group'])?$_GET['group']:(isset($_POST['group'])?$_POST['group']:'')),
105
+ 'search' => (isset($_GET['search'])?$_GET['search']:(isset($_POST['search'])?$_POST['search']:'')),
106
+ 'sort' => (isset($_GET['sort'])?$_GET['sort']:(isset($_POST['sort'])?$_POST['sort']:'')),
107
+ 'sdir' => (isset($_GET['sdir'])?$_GET['sdir']:(isset($_POST['sdir'])?$_POST['sdir']:''))
108
+ );
109
+
110
+ return $values;
111
+ }
112
+
113
+ function validate( $values )
114
+ {
115
+ global $wpdb, $prli_utils;
116
+
117
+ $errors = array();
118
+ if( empty($values['name']) )
119
+ $errors[] = "Group must have a name.";
120
+
121
+ return $errors;
122
+ }
123
+ }
124
+ ?>
classes/models/PrliLink.php ADDED
@@ -0,0 +1,332 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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, $prli_url_utils;
15
+
16
+ $values['name'] = (!empty($values['name'])?$values['name']:$prli_url_utils->get_title($values['url'],$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, $prli_url_utils;
53
+
54
+ $values['name'] = (!empty($values['name'])?$values['name']:$prli_url_utils->get_title($values['url'],$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, $include_stats = false )
117
+ {
118
+ global $wpdb, $prli_click;
119
+ if($include_stats)
120
+ $query = 'SELECT li.*, ' .
121
+ '(SELECT COUNT(*) FROM ' . $prli_click->table_name . ' cl ' .
122
+ 'WHERE cl.link_id = li.id' . $prli_click->get_exclude_where_clause( ' AND' ) . ') as clicks, ' .
123
+ '(SELECT COUNT(*) FROM ' . $prli_click->table_name . ' cl ' .
124
+ 'WHERE cl.link_id = li.id ' .
125
+ 'AND cl.first_click <> 0' . $prli_click->get_exclude_where_clause( ' AND' ) . ') as uniques ' .
126
+ "FROM {$this->table_name} li " .
127
+ 'WHERE slug=%s';
128
+ else
129
+ $query = "SELECT * FROM {$this->table_name} WHERE slug=%s";
130
+
131
+ $query = $wpdb->prepare($query, $slug);
132
+ return $wpdb->get_row($query, $return_type);
133
+ }
134
+
135
+ function getOne( $id, $return_type = OBJECT, $include_stats = false )
136
+ {
137
+ global $wpdb, $prli_click;
138
+ if( !isset($id) or empty($id) )
139
+ return false;
140
+
141
+ if($include_stats)
142
+ $query = 'SELECT li.*, ' .
143
+ '(SELECT COUNT(*) FROM ' . $prli_click->table_name . ' cl ' .
144
+ 'WHERE cl.link_id = li.id' . $prli_click->get_exclude_where_clause( ' AND' ) . ') as clicks, ' .
145
+ '(SELECT COUNT(*) FROM ' . $prli_click->table_name . ' cl ' .
146
+ 'WHERE cl.link_id = li.id ' .
147
+ 'AND cl.first_click <> 0' . $prli_click->get_exclude_where_clause( ' AND' ) . ') as uniques ' .
148
+ 'FROM ' . $this->table_name . ' li ' .
149
+ 'WHERE id=%d';
150
+ else
151
+ $query = "SELECT * FROM {$this->table_name} WHERE id=%d";
152
+
153
+ $query = $wpdb->prepare($query, $id);
154
+ return $wpdb->get_row($query, $return_type);
155
+ }
156
+
157
+ function find_first_target_url($target_url)
158
+ {
159
+ global $wpdb;
160
+ $query_str = "SELECT id FROM {$this->table_name} WHERE url=%s LIMIT 1";
161
+ $query = $wpdb->prepare($query_str,$target_url);
162
+ return $wpdb->get_var($query);
163
+ }
164
+
165
+ function get_link_min( $id, $return_type = OBJECT )
166
+ {
167
+ global $wpdb;
168
+ $query_str = "SELECT * FROM {$this->table_name} WHERE id=%d";
169
+ $query = $wpdb->prepare($query_str, $id);
170
+ return $wpdb->get_row($query, $return_type);
171
+ }
172
+
173
+ function getAll($where = '', $order_by = '', $return_type = OBJECT, $include_stats = false)
174
+ {
175
+ global $wpdb, $prli_click, $prli_group, $prli_utils;
176
+
177
+ if($include_stats)
178
+ $query = 'SELECT li.*, ' .
179
+ '(SELECT COUNT(*) FROM ' . $prli_click->table_name . ' cl ' .
180
+ 'WHERE cl.link_id = li.id' . $prli_click->get_exclude_where_clause( ' AND' ) . ') as clicks, ' .
181
+ '(SELECT COUNT(*) FROM ' . $prli_click->table_name . ' cl ' .
182
+ 'WHERE cl.link_id = li.id ' .
183
+ 'AND cl.first_click <> 0' . $prli_click->get_exclude_where_clause( ' AND' ) . ') as uniques, ' .
184
+ 'gr.name as group_name ' .
185
+ 'FROM '. $this->table_name . ' li ' .
186
+ 'LEFT OUTER JOIN ' . $prli_group->table_name . ' gr ON li.group_id=gr.id' .
187
+ $prli_utils->prepend_and_or_where(' WHERE', $where) . $order_by;
188
+ else
189
+ $query = "SELECT li.*, gr.name as group_name FROM {$this->table_name} li " .
190
+ 'LEFT OUTER JOIN ' . $prli_group->table_name . ' gr ON li.group_id=gr.id' .
191
+ $prli_utils->prepend_and_or_where(' WHERE', $where) . $order_by;
192
+
193
+
194
+ return $wpdb->get_results($query, $return_type);
195
+ }
196
+
197
+ // Pagination Methods
198
+ function getRecordCount($where="")
199
+ {
200
+ global $wpdb, $prli_utils;
201
+ $query = 'SELECT COUNT(*) FROM ' . $this->table_name . ' li' . $prli_utils->prepend_and_or_where(' WHERE', $where);
202
+ return $wpdb->get_var($query);
203
+ }
204
+
205
+ function getPageCount($p_size, $where="")
206
+ {
207
+ return ceil((int)$this->getRecordCount($where) / (int)$p_size);
208
+ }
209
+
210
+ function getPage($current_p,$p_size, $where = "", $order_by = '', $return_type = OBJECT)
211
+ {
212
+ global $wpdb, $prli_click, $prli_utils, $prli_group;
213
+ $end_index = $current_p * $p_size;
214
+ $start_index = $end_index - $p_size;
215
+ $query = 'SELECT li.*, ' .
216
+ '(SELECT COUNT(*) FROM ' . $prli_click->table_name . ' cl ' .
217
+ 'WHERE cl.link_id = li.id' . $prli_click->get_exclude_where_clause( ' AND' ) . ') as clicks, ' .
218
+ '(SELECT COUNT(*) FROM ' . $prli_click->table_name . ' cl ' .
219
+ 'WHERE cl.link_id = li.id ' .
220
+ 'AND cl.first_click <> 0' . $prli_click->get_exclude_where_clause( ' AND' ) . ') as uniques, ' .
221
+ 'gr.name as group_name ' .
222
+ 'FROM ' . $this->table_name . ' li ' .
223
+ 'LEFT OUTER JOIN ' . $prli_group->table_name . ' gr ON li.group_id=gr.id' .
224
+ $prli_utils->prepend_and_or_where(' WHERE', $where) . $order_by . ' ' .
225
+ 'LIMIT ' . $start_index . ',' . $p_size . ';';
226
+ $results = $wpdb->get_results($query, $return_type);
227
+ return $results;
228
+ }
229
+
230
+ /** I'm generating a slug that is by default 2-3 characters long.
231
+ * This gives us a possibility of 36^3 - 37 = 46,619 possible
232
+ * random slugs. That should be *more* than enough slugs for
233
+ * any website -- if I get any feedback that we need more then
234
+ * I can always make a config option to raise the # of chars.
235
+ */
236
+ function generateValidSlug($num_chars = 3)
237
+ {
238
+ global $wpdb, $prli_utils;
239
+
240
+ // We're doing a base 36 hash which is why we're always doing everything by 36
241
+ $max_slug_value = pow(36,$num_chars);
242
+ $min_slug_value = 37; // we want to have at least 2 characters in the slug
243
+ $slug = base_convert( rand($min_slug_value,$max_slug_value), 10, 36 );
244
+
245
+ $query = "SELECT slug FROM " . $this->table_name; // . " WHERE slug='" . $slug . "'";
246
+ $slugs = $wpdb->get_col($query,0);
247
+
248
+ // It is highly unlikely that we'll ever see 2 identical random slugs
249
+ // but just in case, here's some code to prevent collisions
250
+ while( in_array($slug,$slugs) or !$prli_utils->slugIsAvailable($slug) )
251
+ $slug = base_convert( rand($min_slug_value,$max_slug_value), 10, 36 );
252
+
253
+ return $slug;
254
+ }
255
+
256
+ function get_pretty_link_url($slug)
257
+ {
258
+ global $prli_blogurl;
259
+
260
+ $link = $this->getOneFromSlug($slug);
261
+
262
+ if((isset($link->param_forwarding) and $link->param_forwarding == 'custom') and
263
+ (isset($link->redirect_type) and $link->redirect_type == 'pixel'))
264
+ return "&lt;img src=\"".$prli_blogurl . PrliUtils::get_permalink_pre_slug_uri() . $link->slug . $link->param_struct . "\" width=\"1\" height=\"1\" style=\"display: none\" /&gt;";
265
+ else if((!isset($link->param_forwarding) or $link->param_forwarding != 'custom') and
266
+ (isset($link->redirect_type) and $link->redirect_type == 'pixel'))
267
+ return "&lt;img src=\"".$prli_blogurl . PrliUtils::get_permalink_pre_slug_uri() . $link->slug . "\" width=\"1\" height=\"1\" style=\"display: none\" /&gt;";
268
+ else if((isset($link->param_forwarding) and $link->param_forwarding == 'custom') and
269
+ (!isset($link->redirect_type) or $link->redirect_type != 'pixel'))
270
+ return $prli_blogurl . PrliUtils::get_permalink_pre_slug_uri() . $link->slug . $link->param_struct;
271
+ else
272
+ return $prli_blogurl . PrliUtils::get_permalink_pre_slug_uri() . $link->slug;
273
+ }
274
+
275
+ // Set defaults and grab get or post of each possible param
276
+ function get_params_array()
277
+ {
278
+ $values = array(
279
+ 'action' => (isset($_GET['action'])?$_GET['action']:(isset($_POST['action'])?$_POST['action']:'list')),
280
+ 'regenerate' => (isset($_GET['regenerate'])?$_GET['regenerate']:(isset($_POST['regenerate'])?$_POST['regenerate']:'false')),
281
+ 'id' => (isset($_GET['id'])?$_GET['id']:(isset($_POST['id'])?$_POST['id']:'')),
282
+ 'group_name' => (isset($_GET['group_name'])?$_GET['group_name']:(isset($_POST['group_name'])?$_POST['group_name']:'')),
283
+ 'paged' => (isset($_GET['paged'])?$_GET['paged']:(isset($_POST['paged'])?$_POST['paged']:1)),
284
+ 'group' => (isset($_GET['group'])?$_GET['group']:(isset($_POST['group'])?$_POST['group']:'')),
285
+ 'search' => (isset($_GET['search'])?$_GET['search']:(isset($_POST['search'])?$_POST['search']:'')),
286
+ 'sort' => (isset($_GET['sort'])?$_GET['sort']:(isset($_POST['sort'])?$_POST['sort']:'')),
287
+ 'sdir' => (isset($_GET['sdir'])?$_GET['sdir']:(isset($_POST['sdir'])?$_POST['sdir']:''))
288
+ );
289
+
290
+ return $values;
291
+ }
292
+
293
+ function validate( $values )
294
+ {
295
+ global $wpdb, $prli_utils, $prli_blogurl;
296
+
297
+ $errors = array();
298
+ if( ( $values['url'] == null or $values['url'] == '') and $values['redirect_type'] != 'pixel' )
299
+ $errors[] = "Target URL can't be blank";
300
+
301
+ if( $values['slug'] == null or $values['slug'] == '' )
302
+ $errors[] = "Pretty Link can't be blank";
303
+
304
+ if( $values['url'] == $prli_blogurl.PrliUtils::get_permalink_pre_slug_uri().$values['slug'] )
305
+ $errors[] = "Target URL must be different than the Pretty Link";
306
+
307
+ if( !empty($values['url']) and
308
+ !preg_match('/^http.?:\/\/.*\..*$/', $values['url'] ) and
309
+ !preg_match('!^(http|https)://(localhost|127\.0\.0\.1)(:\d+)?(/[\w- ./?%&=]*)?!', $values['url'] ) )
310
+ $errors[] = "Link URL must be a correctly formatted url";
311
+
312
+ if( preg_match('/^[\?\&\#]+$/', $values['slug'] ) )
313
+ $errors[] = "Pretty Link must not contain question marks, ampersands or number signs.";
314
+
315
+ if( !$prli_utils->slugIsAvailable($values['slug'],$values['id']) )
316
+ $errors[] = "This pretty link slug is already taken, please choose a different one";
317
+
318
+ if( isset($values['param_forwarding']) and $values['param_forwarding'] == 'custom' and empty($values['param_struct']) )
319
+ $errors[] = "If Custom Parameter Forwarding has been selected then you must specify a forwarding format.";
320
+
321
+ if( isset($values['param_forwarding']) and $values['param_forwarding'] == 'custom' and !preg_match('#%.*?%#', $values['param_struct']) )
322
+ $errors[] = "Your parameter forwarding must have at least one parameter specified in the format ex: <code>/%var1%/%var_two%/%varname3% ...</code>";
323
+
324
+ /*
325
+ if( !empty($values['url']) and !PrliUrlUtils::valid_url($values['url']) )
326
+ $errors[] = __("Your Target URL doesn't work -- check the spelling and try it again");
327
+ */
328
+
329
+ return $errors;
330
+ }
331
+ }
332
+ ?>
classes/models/PrliLinkMeta.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $status = false;
43
+ foreach($meta_values as $meta_value)
44
+ $status = $this->add_link_meta($link_id, $meta_key, $meta_value);
45
+
46
+ return $status;
47
+ }
48
+
49
+ function delete_link_meta($link_id, $meta_key)
50
+ {
51
+ global $wpdb;
52
+
53
+ $query_str = "DELETE FROM {$this->table_name} " .
54
+ "WHERE meta_key=%s AND link_id=%d";
55
+ $query = $wpdb->prepare($query_str, $meta_key, $link_id);
56
+ return $wpdb->query($query);
57
+ }
58
+ }
59
+ ?>
classes/models/PrliOptions.php ADDED
@@ -0,0 +1,266 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class PrliOptions
3
+ {
4
+ var $prli_exclude_ips;
5
+ var $whitelist_ips;
6
+ var $filter_robots;
7
+ var $prettybar_image_url;
8
+ var $prettybar_background_image_url;
9
+ var $prettybar_color;
10
+ var $prettybar_text_color;
11
+ var $prettybar_link_color;
12
+ var $prettybar_hover_color;
13
+ var $prettybar_visited_color;
14
+ var $prettybar_show_title;
15
+ var $prettybar_show_description;
16
+ var $prettybar_show_share_links;
17
+ var $prettybar_show_target_url_link;
18
+ var $prettybar_title_limit;
19
+ var $prettybar_desc_limit;
20
+ var $prettybar_link_limit;
21
+
22
+ var $link_redirect_type;
23
+ var $link_track_me;
24
+ var $link_nofollow;
25
+
26
+ var $bookmarklet_auth;
27
+
28
+ function PrliOptions()
29
+ {
30
+ $this->set_default_options();
31
+ }
32
+
33
+ function set_default_options()
34
+ {
35
+ // Must account for the Legacy Options
36
+ $prli_exclude_ips = 'prli_exclude_ips';
37
+ $prettybar_image_url = 'prli_prettybar_image_url';
38
+ $prettybar_background_image_url = 'prli_prettybar_background_image_url';
39
+ $prettybar_color = 'prli_prettybar_color';
40
+ $prettybar_text_color = 'prli_prettybar_text_color';
41
+ $prettybar_link_color = 'prli_prettybar_link_color';
42
+ $prettybar_hover_color = 'prli_prettybar_hover_color';
43
+ $prettybar_visited_color = 'prli_prettybar_visited_color';
44
+ $prettybar_show_title = 'prli_prettybar_show_title';
45
+ $prettybar_show_description = 'prli_prettybar_show_description';
46
+ $prettybar_show_share_links = 'prli_prettybar_show_share_links';
47
+ $prettybar_show_target_url_link = 'prli_prettybar_show_target_url_link';
48
+ $prettybar_title_limit = 'prli_prettybar_title_limit';
49
+ $prettybar_desc_limit = 'prli_prettybar_desc_limit';
50
+ $prettybar_link_limit = 'prli_prettybar_link_limit';
51
+ $link_show_prettybar = 'prli_link_show_prettybar';
52
+ $link_ultra_cloak = 'prli_link_ultra_cloak';
53
+ $link_track_me = 'prli_link_track_me';
54
+ $link_track_as_pixel = 'prli_link_track_as_pixel';
55
+ $link_nofollow = 'prli_link_nofollow';
56
+ $link_redirect_type = 'prli_link_redirect_type';
57
+
58
+
59
+ if(!isset($this->prettybar_show_title)) {
60
+ if($var = get_option( $prettybar_show_title )) {
61
+ $this->prettybar_show_title = $var;
62
+ delete_option( $prettybar_show_title );
63
+ }
64
+ else
65
+ $this->prettybar_show_title = '1';
66
+ }
67
+
68
+ if(!isset($this->prettybar_show_description)) {
69
+ if($var = get_option( $prettybar_show_description )) {
70
+ $this->prettybar_show_description = $var;
71
+ delete_option( $prettybar_show_description );
72
+ }
73
+ else
74
+ $this->prettybar_show_description = '1';
75
+ }
76
+
77
+ if(!isset($this->prettybar_show_share_links)) {
78
+ if($var = get_option( $prettybar_show_share_links )) {
79
+ $this->prettybar_show_share_links = $var;
80
+ delete_option( $prettybar_show_share_links );
81
+ }
82
+ else
83
+ $this->prettybar_show_share_links = '1';
84
+ }
85
+
86
+ if(!isset($this->prettybar_show_target_url_link)) {
87
+ if($var = get_option( $prettybar_show_target_url_link )) {
88
+ $this->prettybar_show_target_url_link = $var;
89
+ delete_option( $prettybar_show_target_url_link );
90
+ }
91
+ else
92
+ $this->prettybar_show_target_url_link = '1';
93
+ }
94
+
95
+ if(!isset($this->link_track_me)) {
96
+ if($var = get_option( $link_track_me )) {
97
+ $this->link_track_me = $var;
98
+ delete_option( $link_track_me );
99
+ }
100
+ else
101
+ $this->link_track_me = '1';
102
+ }
103
+
104
+ if(!isset($this->link_nofollow)) {
105
+ if($var = get_option( $link_nofollow )) {
106
+ $this->link_nofollow = $var;
107
+ delete_option( $link_nofollow );
108
+ }
109
+ else
110
+ $this->link_nofollow = '0';
111
+ }
112
+
113
+ if(!isset($this->link_redirect_type)) {
114
+ if($var = get_option( $link_track_as_pixel )) {
115
+ $this->link_redirect_type = 'pixel';
116
+ delete_option( $link_show_prettybar );
117
+ delete_option( $link_ultra_cloak );
118
+ delete_option( $link_track_as_pixel );
119
+ delete_option( $link_redirect_type );
120
+ }
121
+ if($var = get_option( $link_show_prettybar )) {
122
+ $this->link_redirect_type = 'prettybar';
123
+ delete_option( $link_show_prettybar );
124
+ delete_option( $link_ultra_cloak );
125
+ delete_option( $link_track_as_pixel );
126
+ delete_option( $link_redirect_type );
127
+ }
128
+ if($var = get_option( $link_ultra_cloak )) {
129
+ $this->link_redirect_type = 'cloak';
130
+ delete_option( $link_show_prettybar );
131
+ delete_option( $link_ultra_cloak );
132
+ delete_option( $link_track_as_pixel );
133
+ delete_option( $link_redirect_type );
134
+ }
135
+ if($var = get_option( $link_redirect_type )) {
136
+ $this->link_redirect_type = $var;
137
+ delete_option( $link_show_prettybar );
138
+ delete_option( $link_ultra_cloak );
139
+ delete_option( $link_track_as_pixel );
140
+ delete_option( $link_redirect_type );
141
+ }
142
+ else
143
+ $this->link_redirect_type = '307';
144
+ }
145
+
146
+ if(!isset($this->prli_exclude_ips))
147
+ {
148
+ if($var = get_option( $prli_exclude_ips )) {
149
+ $this->prli_exclude_ips = $var;
150
+ delete_option( $prli_exclude_ips );
151
+ }
152
+ else
153
+ $this->prli_exclude_ips = '';
154
+ }
155
+
156
+ if(!isset($this->prettybar_image_url))
157
+ {
158
+ if($var = get_option( $prettybar_image_url )) {
159
+ $this->prettybar_image_url = $var;
160
+ delete_option( $prettybar_image_url );
161
+ }
162
+ else
163
+ $this->prettybar_image_url = PRLI_URL . '/images/pretty-link-48x48.png';
164
+ }
165
+
166
+ if(!isset($this->prettybar_background_image_url))
167
+ {
168
+ if($var = get_option( $prettybar_background_image_url )) {
169
+ $this->prettybar_background_image_url = $var;
170
+ delete_option( $prettybar_background_image_url );
171
+ }
172
+ else
173
+ $this->prettybar_background_image_url = PRLI_URL . '/images/bar_background.png';
174
+ }
175
+
176
+ if(!isset($this->prettybar_color))
177
+ {
178
+ if($var = get_option( $prettybar_color )) {
179
+ $this->prettybar_color = $var;
180
+ delete_option( $prettybar_color );
181
+ }
182
+ else
183
+ $this->prettybar_color = '';
184
+ }
185
+
186
+ if(!isset($this->prettybar_text_color))
187
+ {
188
+ if($var = get_option( $prettybar_text_color )) {
189
+ $this->prettybar_text_color = $var;
190
+ delete_option( $prettybar_text_color );
191
+ }
192
+ else
193
+ $this->prettybar_text_color = '000000';
194
+ }
195
+
196
+ if(!isset($this->prettybar_link_color))
197
+ {
198
+ if($var = get_option( $prettybar_link_color )) {
199
+ $this->prettybar_link_color = $var;
200
+ delete_option( $prettybar_link_color );
201
+ }
202
+ else
203
+ $this->prettybar_link_color = '0000ee';
204
+ }
205
+
206
+ if(!isset($this->prettybar_hover_color))
207
+ {
208
+ if($var = get_option( $prettybar_hover_color )) {
209
+ $this->prettybar_hover_color = $var;
210
+ delete_option( $prettybar_hover_color );
211
+ }
212
+ else
213
+ $this->prettybar_hover_color = 'ababab';
214
+ }
215
+
216
+ if(!isset($this->prettybar_visited_color))
217
+ {
218
+ if($var = get_option( $prettybar_visited_color )) {
219
+ $this->prettybar_visited_color = $var;
220
+ delete_option( $prettybar_visited_color );
221
+ }
222
+ else
223
+ $this->prettybar_visited_color = '551a8b';
224
+ }
225
+
226
+ if(!isset($this->prettybar_title_limit))
227
+ {
228
+ if($var = get_option( $prettybar_title_limit )) {
229
+ $this->prettybar_title_limit = $var;
230
+ delete_option( $prettybar_title_limit );
231
+ }
232
+ else
233
+ $this->prettybar_title_limit = '25';
234
+ }
235
+
236
+ if(!isset($this->prettybar_desc_limit))
237
+ {
238
+ if($var = get_option( $prettybar_desc_limit )) {
239
+ $this->prettybar_desc_limit = $var;
240
+ delete_option( $prettybar_desc_limit );
241
+ }
242
+ else
243
+ $this->prettybar_desc_limit = '30';
244
+ }
245
+
246
+ if(!isset($this->prettybar_link_limit))
247
+ {
248
+ if($var = get_option( $prettybar_link_limit )) {
249
+ $this->prettybar_link_limit = $var;
250
+ delete_option( $prettybar_link_limit );
251
+ }
252
+ else
253
+ $this->prettybar_link_limit = '30';
254
+ }
255
+
256
+ if(!isset($this->bookmarklet_auth))
257
+ $this->bookmarklet_auth = md5(get_option('auth_salt') . time());
258
+
259
+ if(!isset($this->whitelist_ips))
260
+ $this->whitelist_ips = '';
261
+
262
+ if(!isset($this->filter_robots))
263
+ $this->filter_robots = 0;
264
+ }
265
+ }
266
+ ?>
classes/models/PrliUpdate.php ADDED
@@ -0,0 +1,313 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /** Okay, this class is not a pure model -- it contains all the functions
4
+ * necessary to successfully provide an update mechanism for PrettyLinkPro!
5
+ */
6
+ class PrliUpdate
7
+ {
8
+ var $plugin_name;
9
+ var $plugin_slug;
10
+ var $plugin_url;
11
+ var $pro_script;
12
+ var $pro_mothership;
13
+
14
+ var $pro_cred_store;
15
+ var $pro_auth_store;
16
+
17
+ var $pro_username_label;
18
+ var $pro_password_label;
19
+
20
+ var $pro_username_str;
21
+ var $pro_password_str;
22
+
23
+ var $pro_error_message_str;
24
+
25
+ var $pro_check_interval;
26
+ var $pro_last_checked_store;
27
+
28
+ var $pro_username;
29
+ var $pro_password;
30
+ var $pro_mothership_xmlrpc_url;
31
+
32
+ function PrliUpdate()
33
+ {
34
+ // Where all the vitals are defined for this plugin
35
+ $this->plugin_name = 'pretty-link/pretty-link.php';
36
+ $this->plugin_slug = 'pretty-link';
37
+ $this->plugin_url = 'http://blairwilliams.com/pl';
38
+ $this->pro_script = PRLI_PATH . '/pro/pretty-link-pro.php';
39
+ $this->pro_mothership = 'http://prettylinkpro.com';
40
+ $this->pro_cred_store = 'prlipro-credentials';
41
+ $this->pro_auth_store = 'prlipro_activated';
42
+ $this->pro_last_checked_store = 'prlipro_last_checked_update';
43
+ $this->pro_username_label = __('Pretty Link Pro Username');
44
+ $this->pro_password_label = __('Pretty Link Pro Password');
45
+ $this->pro_error_message_str = __('Your Pretty Link Pro Username or Password was Invalid');
46
+
47
+ // Don't modify these variables
48
+ $this->pro_check_interval = 60*60; // Checking every hour
49
+ $this->pro_username_str = 'proplug-username';
50
+ $this->pro_password_str = 'proplug-password';
51
+ $this->pro_mothership_xmlrpc_url = $this->pro_mothership . '/xmlrpc.php';
52
+
53
+ // Retrieve Pro Credentials
54
+ $creds = get_option($this->pro_cred_store);
55
+ if($creds and is_array($creds))
56
+ {
57
+ extract($creds);
58
+ $this->pro_username = ((isset($username) and !empty($username))?$username:'');
59
+ $this->pro_password = ((isset($password) and !empty($password))?$password:'');
60
+
61
+ // Plugin Update Actions -- gotta make sure the right url is used with pro ... don't want any downgrades of course
62
+ add_action('update_option_update_plugins', array($this, 'check_for_update_now')); // for WordPress 2.7
63
+ add_action('update_option__transient_update_plugins', array($this, 'check_for_update_now')); // for WordPress 2.8
64
+ add_action("admin_init", array($this, 'periodically_check_for_update'));
65
+ }
66
+ }
67
+
68
+ function pro_is_installed()
69
+ {
70
+ return file_exists($this->pro_script);
71
+ }
72
+
73
+ function pro_is_authorized($force_check=false)
74
+ {
75
+ if( !empty($this->pro_username) and
76
+ !empty($this->pro_password) )
77
+ {
78
+ $authorized = get_option($this->pro_auth_store);
79
+ if(!$force_check and isset($authorized))
80