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

Version Description

  • Added some more support options
  • fixed some minor bugs in keyword replacement and pro options.
Download this release

Release Info

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

Version 1.4.29

Files changed (107) hide show
  1. classes/models/PrliClick.php +273 -0
  2. classes/models/PrliGroup.php +116 -0
  3. classes/models/PrliLink.php +317 -0
  4. classes/models/PrliLinkMeta.php +59 -0
  5. classes/models/PrliOptions.php +266 -0
  6. classes/models/PrliUrlUtils.php +128 -0
  7. classes/models/PrliUtils.php +1091 -0
  8. classes/models/models.inc.php +43 -0
  9. classes/views/prli-clicks/csv.php +24 -0
  10. classes/views/prli-clicks/head.php +105 -0
  11. classes/views/prli-clicks/list.php +151 -0
  12. classes/views/prli-dashboard-widget/widget.php +23 -0
  13. classes/views/prli-groups/edit.php +58 -0
  14. classes/views/prli-groups/head.php +35 -0
  15. classes/views/prli-groups/list.php +88 -0
  16. classes/views/prli-groups/new.php +59 -0
  17. classes/views/prli-links/bar.php +12 -0
  18. classes/views/prli-links/edit.php +22 -0
  19. classes/views/prli-links/form.php +94 -0
  20. classes/views/prli-links/head.php +91 -0
  21. classes/views/prli-links/list.php +183 -0
  22. classes/views/prli-links/new.php +22 -0
  23. classes/views/prli-links/ultra-cloak.php +11 -0
  24. classes/views/prli-options/form.php +176 -0
  25. classes/views/prli-options/head.php +54 -0
  26. classes/views/prli-options/pro-settings.php +44 -0
  27. classes/views/prli-tools/form.php +20 -0
  28. classes/views/shared/errors.php +19 -0
  29. classes/views/shared/link-table-nav.php +102 -0
  30. classes/views/shared/nav.php +18 -0
  31. classes/views/shared/table-nav.php +93 -0
  32. images/arrow_down.png +0 -0
  33. images/arrow_up.png +0 -0
  34. images/bar_background.png +0 -0
  35. images/bar_map.png +0 -0
  36. images/bookmark.png +0 -0
  37. images/co.mments.gif +0 -0
  38. images/delicious_32.png +0 -0
  39. images/digg_32.png +0 -0
  40. images/email_32.png +0 -0
  41. images/facebook.png +0 -0
  42. images/facebook_32.png +0 -0
  43. images/forward_params.png +0 -0
  44. images/hyves_32.png +0 -0
  45. images/linkedin_32.png +0 -0
  46. images/mixx_32.png +0 -0
  47. images/newsvine_32.png +0 -0
  48. images/nofollow.png +0 -0
  49. images/not_tracking.png +0 -0
  50. images/pixel_track.png +0 -0
  51. images/pretty-link-48x48.png +0 -0
  52. images/pretty-link-add.png +0 -0
  53. images/pretty-link-med.png +0 -0
  54. images/pretty-link-small.png +0 -0
  55. images/prettylink_logo.jpg +0 -0
  56. images/prettylink_logo_med.jpg +0 -0
  57. images/prettylink_logo_small.jpg +0 -0
  58. images/reddit_32.png +0 -0
  59. images/sphinn_32.png +0 -0
  60. images/stumbleupon_32.png +0 -0
  61. images/technorati_32.png +0 -0
  62. images/tracking.png +0 -0
  63. images/twitter.png +0 -0
  64. images/twitter_32.png +0 -0
  65. images/ultra-cloak.png +0 -0
  66. images/url_icon.gif +0 -0
  67. images/whatever.txt +13 -0
  68. images/yahoobuzz_32.png +0 -0
  69. includes/jquery/css/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  70. includes/jquery/css/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  71. includes/jquery/css/ui-lightness/images/ui-bg_flat_10_000000_40x100.png +0 -0
  72. includes/jquery/css/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  73. includes/jquery/css/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  74. includes/jquery/css/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  75. includes/jquery/css/ui-lightness/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  76. includes/jquery/css/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  77. includes/jquery/css/ui-lightness/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  78. includes/jquery/css/ui-lightness/images/ui-icons_222222_256x240.png +0 -0
  79. includes/jquery/css/ui-lightness/images/ui-icons_228ef1_256x240.png +0 -0
  80. includes/jquery/css/ui-lightness/images/ui-icons_ef8c08_256x240.png +0 -0
  81. includes/jquery/css/ui-lightness/images/ui-icons_ffd27a_256x240.png +0 -0
  82. includes/jquery/css/ui-lightness/images/ui-icons_ffffff_256x240.png +0 -0
  83. includes/jquery/css/ui-lightness/jquery-ui-1.7.1.custom.css +404 -0
  84. includes/jquery/js/jquery-1.3.2.min.js +19 -0
  85. includes/jquery/js/jquery-ui-1.7.1.custom.min.js +273 -0
  86. includes/php/php_browsecap.ini +16939 -0
  87. includes/version-2-kvasir/README.txt +8 -0
  88. includes/version-2-kvasir/js/README.txt +12 -0
  89. includes/version-2-kvasir/js/json/json2.js +461 -0
  90. includes/version-2-kvasir/js/swfobject.js +5 -0
  91. includes/version-2-kvasir/open-flash-chart.swf +0 -0
  92. pretty-bar.php +242 -0
  93. pretty-link.php +347 -0
  94. prli-add-link.php +9 -0
  95. prli-api.php +233 -0
  96. prli-bookmarklet.php +94 -0
  97. prli-clicks.php +237 -0
  98. prli-config.php +131 -0
  99. prli-dashboard-widget.php +13 -0
  100. prli-groups.php +175 -0
  101. prli-image-lookups.php +136 -0
  102. prli-links.php +233 -0
  103. prli-options.php +138 -0
  104. prli-pro-settings.php +77 -0
  105. prli-tools.php +3 -0
  106. prli-xmlrpc.php +333 -0
  107. readme.txt +197 -0
classes/models/PrliClick.php ADDED
@@ -0,0 +1,273 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = '')
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
+ $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;
87
+ return $wpdb->get_results($query);
88
+ }
89
+
90
+ // Delete all of the clicks from the database.
91
+ function clearAllClicks()
92
+ {
93
+ global $wpdb;
94
+ $query = "TRUNCATE TABLE " . $this->table_name;
95
+ return $wpdb->query($query);
96
+ }
97
+
98
+ // Pagination Methods
99
+ function getRecordCount($where='')
100
+ {
101
+ global $wpdb, $prli_link, $prli_utils;
102
+ $where .= $this->get_exclude_where_clause( $where );
103
+ $where = $prli_utils->prepend_and_or_where(' WHERE', $where);
104
+ $query = 'SELECT COUNT(*) FROM ' . $this->table_name . ' cl'. $where;
105
+ return $wpdb->get_var($query);
106
+ }
107
+
108
+ function getPageCount($p_size, $where='')
109
+ {
110
+ return ceil((int)$this->getRecordCount($where) / (int)$p_size);
111
+ }
112
+
113
+ function getPage($current_p,$p_size, $where = '', $order = '')
114
+ {
115
+ global $wpdb, $prli_link, $prli_utils;
116
+ $click_table = $wpdb->prefix . "prli_clicks";
117
+ $end_index = $current_p * $p_size;
118
+ $start_index = $end_index - $p_size;
119
+ $where .= $this->get_exclude_where_clause( $where );
120
+ $where = $prli_utils->prepend_and_or_where(' AND', $where);
121
+ $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 . ';';
122
+ $results = $wpdb->get_results($query);
123
+ return $results;
124
+ }
125
+
126
+ function generateUniqueVisitorId($num_chars = 6)
127
+ {
128
+ global $wpdb, $prli_utils;
129
+
130
+ // We're doing a base 36 hash which is why we're always doing everything by 36
131
+ $max_vuid_value = pow(36,$num_chars);
132
+ $min_vuid_value = 37;
133
+ $vuid = base_convert( mt_rand($min_vuid_value,$max_vuid_value), 10, 36 );
134
+
135
+ $query = "SELECT DISTINCT vuid FROM ".$this->table_name;
136
+ $vuids = $wpdb->get_col($query,0);
137
+
138
+ // It is highly unlikely that we'll ever see 2 identical random vuids
139
+ // but just in case, here's some code to prevent collisions
140
+ while( in_array($vuid,$vuids) )
141
+ $vuid = base_convert( mt_rand($min_vuid_value,$max_vuid_value), 10, 36 );
142
+
143
+ return $vuid;
144
+ }
145
+
146
+ function get_counts_by_days($start_timestamp, $end_timestamp, $link_id = "all", $type = "all", $group = '')
147
+ {
148
+ global $wpdb, $prli_link;
149
+
150
+ $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' );
151
+
152
+ if($link_id != "all")
153
+ $query .= " AND link_id=$link_id";
154
+
155
+ if(!empty($group))
156
+ $query .= " AND link_id IN (SELECT id FROM " . $prli_link->table_name . " WHERE group_id=$group)";
157
+
158
+ if($type == "unique")
159
+ $query .= " AND first_click=1";
160
+
161
+ $query .= ' GROUP BY DATE(cl.created_at)';
162
+
163
+ $clicks_array = $wpdb->get_results($query);
164
+
165
+ $temp_array = array();
166
+ $counts_array = array();
167
+ $dates_array = array();
168
+
169
+ // Refactor Array for use later on
170
+ foreach($clicks_array as $c)
171
+ $temp_array[$c->cldate] = $c->clcount;
172
+
173
+ // Get the dates array
174
+ for($c = $start_timestamp; $c <= $end_timestamp; $c += 60*60*24)
175
+ $dates_array[] = date("Y-m-d",$c);
176
+
177
+ // Make sure counts array is in order and includes zero click days
178
+ foreach($dates_array as $date_str)
179
+ {
180
+ if(isset($temp_array[$date_str]))
181
+ $counts_array[$date_str] = $temp_array[$date_str];
182
+ else
183
+ $counts_array[$date_str] = 0;
184
+ }
185
+
186
+ return $counts_array;
187
+ }
188
+
189
+
190
+ function setupClickLineGraph($start_timestamp,$end_timestamp, $link_id = "all", $type = "all", $group = '')
191
+ {
192
+ global $wpdb, $prli_utils, $prli_link, $prli_group;
193
+
194
+ $dates_array = $this->get_counts_by_days($start_timestamp,$end_timestamp,$link_id,$type,$group);
195
+
196
+ $top_click_count = $prli_utils->getTopValue(array_values($dates_array));
197
+
198
+ if(!empty($group))
199
+ $link_slug = "group: '" . $wpdb->get_var("SELECT name FROM ".$prli_group->table_name." WHERE id=$group") . "'";
200
+ else if($link_id == "all")
201
+ $link_slug = "all links";
202
+ else
203
+ $link_slug = "'/".$wpdb->get_var("SELECT slug FROM ".$prli_link->table_name." WHERE id=$link_id") . "'";
204
+
205
+ if($type == "all")
206
+ $type_string = "All hits";
207
+ else
208
+ $type_string = "Unique hits";
209
+
210
+ $json_array = array(
211
+ "elements" => array( array(
212
+ "type" => "line",
213
+ "values" => array_values($dates_array),
214
+ "dot-style" => array(
215
+ "type" => "dot",
216
+ "dot-size" => 4,
217
+ "colour" => "#ffc94e",
218
+ "halo-size" => 1,
219
+ "tip" => "#val# Hits<br>#x_label#"
220
+ ),
221
+ "width" => 2
222
+ ) ),
223
+ "title" => array(
224
+ "text" => 'Pretty Link: '.$type_string.' on '.$link_slug. ' between ' . date("Y-n-j",$start_timestamp) . ' and ' . date("Y-n-j",$end_timestamp),
225
+ "style" => "font-size: 16px; font-weight: bold; color: #3030d0; text-align: center; padding-bottom: 5px;"
226
+ ),
227
+ "bg_colour" => "-1",
228
+ "y_axis" => array(
229
+ "min" => 0,
230
+ "max" => $top_click_count,
231
+ "steps" => (int)(($top_click_count>=10)?$top_click_count/10:1),
232
+ "colour" => "#A2ACBA"
233
+ ),
234
+ "x_axis" => array(
235
+ "colour" => "#A2ACBA",
236
+ "grid-colour" => "#ffefa7",
237
+ "offset" => false,
238
+ "steps" => 4,
239
+ "labels" => array(
240
+ "steps" => 2,
241
+ "rotate" => 25,
242
+ "colour" => "#000000",
243
+ "labels" => array_keys($dates_array)
244
+ )
245
+ )
246
+ );
247
+
248
+ return $prli_utils->prli_json_encode($json_array);
249
+ }
250
+
251
+
252
+ // Set defaults and grab get or post of each possible param
253
+ function get_params_array()
254
+ {
255
+ $values = array(
256
+ 'paged' => (isset($_GET['paged'])?$_GET['paged']:(isset($_POST['paged'])?$_POST['paged']:1)),
257
+ 'l' => (isset($_GET['l'])?$_GET['l']:(isset($_POST['l'])?$_POST['l']:'all')),
258
+ 'group' => (isset($_GET['group'])?$_GET['group']:(isset($_POST['group'])?$_POST['group']:'')),
259
+ 'ip' => (isset($_GET['ip'])?$_GET['ip']:(isset($_POST['ip'])?$_POST['ip']:'')),
260
+ 'vuid' => (isset($_GET['vuid'])?$_GET['vuid']:(isset($_POST['vuid'])?$_POST['vuid']:'')),
261
+ 'sdate' => (isset($_GET['sdate'])?$_GET['sdate']:(isset($_POST['sdate'])?$_POST['sdate']:'')),
262
+ 'edate' => (isset($_GET['edate'])?$_GET['edate']:(isset($_POST['edate'])?$_POST['edate']:'')),
263
+ 'type' => (isset($_GET['type'])?$_GET['type']:(isset($_POST['type'])?$_POST['type']:'all')),
264
+ 'search' => (isset($_GET['search'])?$_GET['search']:(isset($_POST['search'])?$_POST['search']:'')),
265
+ 'sort' => (isset($_GET['sort'])?$_GET['sort']:(isset($_POST['sort'])?$_POST['sort']:'')),
266
+ 'sdir' => (isset($_GET['sdir'])?$_GET['sdir']:(isset($_POST['sdir'])?$_POST['sdir']:''))
267
+ );
268
+
269
+ return $values;
270
+ }
271
+
272
+ }
273
+ ?>
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,317 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)
174
+ {
175
+ global $wpdb, $prli_click, $prli_group, $prli_utils;
176
+ $query = 'SELECT li.*, ' .
177
+ '(SELECT COUNT(*) FROM ' . $prli_click->table_name . ' cl ' .
178
+ 'WHERE cl.link_id = li.id' . $prli_click->get_exclude_where_clause( ' AND' ) . ') as clicks, ' .
179
+ '(SELECT COUNT(*) FROM ' . $prli_click->table_name . ' cl ' .
180
+ 'WHERE cl.link_id = li.id ' .
181
+ 'AND cl.first_click <> 0' . $prli_click->get_exclude_where_clause( ' AND' ) . ') as uniques, ' .
182
+ 'gr.name as group_name ' .
183
+ 'FROM '. $this->table_name . ' li ' .
184
+ 'LEFT OUTER JOIN ' . $prli_group->table_name . ' gr ON li.group_id=gr.id' .
185
+ $prli_utils->prepend_and_or_where(' WHERE', $where) . $order_by;
186
+ return $wpdb->get_results($query, $return_type);
187
+ }
188
+
189
+ // Pagination Methods
190
+ function getRecordCount($where="")
191
+ {
192
+ global $wpdb, $prli_utils;
193
+ $query = 'SELECT COUNT(*) FROM ' . $this->table_name . ' li' . $prli_utils->prepend_and_or_where(' WHERE', $where);
194
+ return $wpdb->get_var($query);
195
+ }
196
+
197
+ function getPageCount($p_size, $where="")
198
+ {
199
+ return ceil((int)$this->getRecordCount($where) / (int)$p_size);
200
+ }
201
+
202
+ function getPage($current_p,$p_size, $where = "", $order_by = '', $return_type = OBJECT)
203
+ {
204
+ global $wpdb, $prli_click, $prli_utils, $prli_group;
205
+ $end_index = $current_p * $p_size;
206
+ $start_index = $end_index - $p_size;
207
+ $query = 'SELECT li.*, ' .
208
+ '(SELECT COUNT(*) FROM ' . $prli_click->table_name . ' cl ' .
209
+ 'WHERE cl.link_id = li.id' . $prli_click->get_exclude_where_clause( ' AND' ) . ') as clicks, ' .
210
+ '(SELECT COUNT(*) FROM ' . $prli_click->table_name . ' cl ' .
211
+ 'WHERE cl.link_id = li.id ' .
212
+ 'AND cl.first_click <> 0' . $prli_click->get_exclude_where_clause( ' AND' ) . ') as uniques, ' .
213
+ 'gr.name as group_name ' .
214
+ 'FROM ' . $this->table_name . ' li ' .
215
+ 'LEFT OUTER JOIN ' . $prli_group->table_name . ' gr ON li.group_id=gr.id' .
216
+ $prli_utils->prepend_and_or_where(' WHERE', $where) . $order_by . ' ' .
217
+ 'LIMIT ' . $start_index . ',' . $p_size . ';';
218
+ $results = $wpdb->get_results($query, $return_type);
219
+ return $results;
220
+ }
221
+
222
+ /** I'm generating a slug that is by default 2-3 characters long.
223
+ * This gives us a possibility of 36^3 - 37 = 46,619 possible
224
+ * random slugs. That should be *more* than enough slugs for
225
+ * any website -- if I get any feedback that we need more then
226
+ * I can always make a config option to raise the # of chars.
227
+ */
228
+ function generateValidSlug($num_chars = 3)
229
+ {
230
+ global $wpdb, $prli_utils;
231
+
232
+ // We're doing a base 36 hash which is why we're always doing everything by 36
233
+ $max_slug_value = pow(36,$num_chars);
234
+ $min_slug_value = 37; // we want to have at least 2 characters in the slug
235
+ $slug = base_convert( rand($min_slug_value,$max_slug_value), 10, 36 );
236
+
237
+ $query = "SELECT slug FROM " . $this->table_name; // . " WHERE slug='" . $slug . "'";
238
+ $slugs = $wpdb->get_col($query,0);
239
+
240
+ // It is highly unlikely that we'll ever see 2 identical random slugs
241
+ // but just in case, here's some code to prevent collisions
242
+ while( in_array($slug,$slugs) or !$prli_utils->slugIsAvailable($slug) )
243
+ $slug = base_convert( rand($min_slug_value,$max_slug_value), 10, 36 );
244
+
245
+ return $slug;
246
+ }
247
+
248
+ function get_pretty_link_url($slug)
249
+ {
250
+ global $prli_blogurl;
251
+
252
+ $link = $this->getOneFromSlug($slug);
253
+
254
+ if((isset($link->param_forwarding) and $link->param_forwarding == 'custom') and
255
+ (isset($link->redirect_type) and $link->redirect_type == 'pixel'))
256
+ return "&lt;img src=\"".$prli_blogurl . '/' . $link->slug . $link->param_struct . "\" width=\"1\" height=\"1\" style=\"display: none\" /&gt;";
257
+ else if((!isset($link->param_forwarding) or $link->param_forwarding != 'custom') and
258
+ (isset($link->redirect_type) and $link->redirect_type == 'pixel'))
259
+ return "&lt;img src=\"".$prli_blogurl . '/' . $link->slug . "\" width=\"1\" height=\"1\" style=\"display: none\" /&gt;";
260
+ else if((isset($link->param_forwarding) and $link->param_forwarding == 'custom') and
261
+ (!isset($link->redirect_type) or $link->redirect_type != 'pixel'))
262
+ return $prli_blogurl . '/' . $link->slug . $link->param_struct;
263
+ else
264
+ return $prli_blogurl . '/' . $link->slug;
265
+ }
266
+
267
+ // Set defaults and grab get or post of each possible param
268
+ function get_params_array()
269
+ {
270
+ $values = array(
271
+ 'action' => (isset($_GET['action'])?$_GET['action']:(isset($_POST['action'])?$_POST['action']:'list')),
272
+ 'regenerate' => (isset($_GET['regenerate'])?$_GET['regenerate']:(isset($_POST['regenerate'])?$_POST['regenerate']:'false')),
273
+ 'id' => (isset($_GET['id'])?$_GET['id']:(isset($_POST['id'])?$_POST['id']:'')),
274
+ 'group_name' => (isset($_GET['group_name'])?$_GET['group_name']:(isset($_POST['group_name'])?$_POST['group_name']:'')),
275
+ 'paged' => (isset($_GET['paged'])?$_GET['paged']:(isset($_POST['paged'])?$_POST['paged']:1)),
276
+ 'group' => (isset($_GET['group'])?$_GET['group']:(isset($_POST['group'])?$_POST['group']:'')),
277
+ 'search' => (isset($_GET['search'])?$_GET['search']:(isset($_POST['search'])?$_POST['search']:'')),
278
+ 'sort' => (isset($_GET['sort'])?$_GET['sort']:(isset($_POST['sort'])?$_POST['sort']:'')),
279
+ 'sdir' => (isset($_GET['sdir'])?$_GET['sdir']:(isset($_POST['sdir'])?$_POST['sdir']:''))
280
+ );
281
+
282
+ return $values;
283
+ }
284
+
285
+ function validate( $values )
286
+ {
287
+ global $wpdb, $prli_utils, $prli_blogurl;
288
+
289
+ $errors = array();
290
+ if( ( $values['url'] == null or $values['url'] == '') and $values['redirect_type'] != 'pixel' )
291
+ $errors[] = "Target URL can't be blank";
292
+
293
+ if( $values['slug'] == null or $values['slug'] == '' )
294
+ $errors[] = "Pretty Link can't be blank";
295
+
296
+ if( $values['url'] == "$prli_blogurl/".$values['slug'] )
297
+ $errors[] = "Target URL must be different than the Pretty Link";
298
+
299
+ if( !empty($values['url']) and !preg_match('/^http.?:\/\/.*\..*$/', $values['url'] ) )
300
+ $errors[] = "Link URL must be a correctly formatted url";
301
+
302
+ if( preg_match('/^[\?\&\#]+$/', $values['slug'] ) )
303
+ $errors[] = "Pretty Link must not contain question marks, ampersands or number signs.";
304
+
305
+ if( !$prli_utils->slugIsAvailable($values['slug'],$values['id']) )
306
+ $errors[] = "This pretty link slug is already taken, please choose a different one";
307
+
308
+ if( isset($values['param_forwarding']) and $values['param_forwarding'] == 'custom' and empty($values['param_struct']) )
309
+ $errors[] = "If Custom Parameter Forwarding has been selected then you must specify a forwarding format.";
310
+
311
+ if( isset($values['param_forwarding']) and $values['param_forwarding'] == 'custom' and !preg_match('#%.*?%#', $values['param_struct']) )
312
+ $errors[] = "Your parameter forwarding must have at least one parameter specified in the format ex: <code>/%var1%/%var_two%/%varname3% ...</code>";
313
+
314
+ return $errors;
315
+ }
316
+ }
317
+ ?>
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/PrliUrlUtils.php ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class PrliUrlUtils {
3
+
4
+ function get_title($url, $slug='')
5
+ {
6
+ // Grab the title tag
7
+ $title = $this->url_grab_title($url);
8
+
9
+ if(!$title)
10
+ return $slug;
11
+
12
+ return $title;
13
+ }
14
+
15
+ /*
16
+ Go out to the web and see if the url resolves
17
+ */
18
+ function valid_url($url)
19
+ {
20
+ $valid = false;
21
+
22
+ $remote_page = $this->read_remote_file($url,1);
23
+ if($remote_page and !empty($remote_page))
24
+ $valid = true;
25
+
26
+ return $valid;
27
+ }
28
+
29
+ function url_grab_title($url)
30
+ {
31
+ $title = false;
32
+
33
+ $remote_page = $this->read_remote_file($url,10);
34
+
35
+ // Look for <title>(.*?)</title> in the text
36
+ if($remote_page and preg_match('#<title>[\s\n\r]*?(.*?)[\s\n\r]*?</title>#im', $remote_page, $matches))
37
+ $title = trim($matches[1]);
38
+
39
+ return $title;
40
+ }
41
+
42
+ /**
43
+ * Sends http request ensuring the request will fail before $timeout seconds
44
+ * gotta use a socket connection because some hosting setups don't allow fopen.
45
+ * Supports SSL sites as well as 301, 302 & 307 redirects
46
+ * Returns the response content (no header, trimmed)
47
+ * @param string $url
48
+ * @param string $num_chunks Set to 0 if you want to read the full file
49
+ * @param string $chunk_size In bytes
50
+ * @param int $timeout
51
+ * @return string|false false if request failed
52
+ */
53
+ function read_remote_file($url, $num_chunks=0, $headers='', $params='', $chunk_size=1024, $timeout=30 )
54
+ {
55
+ $purl = @parse_url($url);
56
+
57
+ $sock_host = $purl['host'];
58
+ $sock_port = 80;
59
+ $sock_scheme = $purl['scheme'];
60
+
61
+ $req_host = $purl['host'];
62
+ $req_path = $purl['path'];
63
+
64
+ if(empty($req_path))
65
+ $req_path = "/";
66
+
67
+ if($sock_scheme == 'https')
68
+ {
69
+ $sock_port = 443;
70
+ $sock_host = "ssl://{$sock_host}";
71
+ }
72
+
73
+ $fp = fsockopen($sock_host, $sock_port, $errno, $errstr, $timeout);
74
+ $contents = '';
75
+ $header = '';
76
+
77
+ if (!$fp)
78
+ return false;
79
+ else
80
+ {
81
+ // Send get request
82
+ $request = "GET {$req_path}{$params} HTTP/1.1\r\n";
83
+ $request .= "Host: {$req_host}\r\n";
84
+ $request .= $headers;
85
+ $request .= "Connection: Close\r\n\r\n";
86
+ fwrite($fp, $request);
87
+
88
+ // Read response
89
+ $head_end_found = false;
90
+ $buffer = '';
91
+ for($i = 0; !feof($fp); $i++)
92
+ {
93
+ if($num_chunks > 0 and $i >= $num_chunks)
94
+ break;
95
+
96
+ $out = fread($fp,$chunk_size);
97
+ if($head_end_found)
98
+ $contents .= $out;
99
+ else
100
+ {
101
+ $buffer .= $out;
102
+ $head_end = strpos($buffer, "\r\n\r\n");
103
+ if($head_end !== false)
104
+ {
105
+ $head_end_found = true;
106
+ $contents .= substr($buffer, ($head_end + 4));
107
+ $header .= substr($buffer, 0, $head_end);
108
+ // Follow HTTP redirects
109
+ if(preg_match("#http/1\.1 301#i",$header) or
110
+ preg_match("#http/1\.1 302#i",$header) or
111
+ preg_match("#http/1\.1 307#i",$header))
112
+ {
113
+ preg_match("#^Location:(.*?)$#im",$header,$matches);
114
+ return $this->read_remote_file(trim($matches[1]));
115
+ }
116
+ }
117
+ }
118
+ }
119
+ fclose($fp);
120
+ }
121
+
122
+ if(empty($contents))
123
+ return false;
124
+ else
125
+ return trim($contents);
126
+ }
127
+ }
128
+ ?>
classes/models/PrliUtils.php ADDED
@@ -0,0 +1,1091 @@