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