pretty-link
Last commit date
classes
17 years ago
images
17 years ago
includes
17 years ago
pretty-link.php
15 years ago
prli-config.php
17 years ago
prli-links.php
17 years ago
prli-reports.php
17 years ago
prli.php
17 years ago
readme.txt
17 years ago
screenshot-1.png
17 years ago
screenshot-2.png
17 years ago
screenshot-3.png
17 years ago
screenshot-4.png
17 years ago
pretty-link.php
255 lines
| 1 | <?php |
| 2 | /* |
| 3 | Plugin Name: Pretty Link |
| 4 | Plugin URI: http://blairwilliams.com/pretty-link |
| 5 | Description: Create clean, simple, trackable links on your website that redirect to other URLs and then analyze the number of clicks and unique clicks they get per day using Pretty Link. For instance you could create this URL: http://www.yourdomain.com/cnn that could redirect to http://www.cnn.com. This type of trackable redirection is EXTREMELY useful for masking Affiliate Links. Pretty Link is a superior alternative to using TinyURL, BudURL or other link shrinking service because the URLs are coming from your website's domain name. When these links are used, pretty link not only redirects but also keeps track of their clicks, unique clicks and other data about them which can be analyzed immediately. |
| 6 | Version: 1.2.1 |
| 7 | Author: Blair Williams |
| 8 | Author URI: http://blairwilliams.com |
| 9 | Copyright: 2009, Caseproof, LLC |
| 10 | |
| 11 | GNU General Public License, Free Software Foundation <http://creativecommons.org/licenses/GPL/2.0/> |
| 12 | This program is free software; you can redistribute it and/or modify |
| 13 | it under the terms of the GNU General Public License as published by |
| 14 | the Free Software Foundation; either version 2 of the License, or |
| 15 | (at your option) any later version. |
| 16 | |
| 17 | This program is distributed in the hope that it will be useful, |
| 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | GNU General Public License for more details. |
| 21 | |
| 22 | You should have received a copy of the GNU General Public License |
| 23 | along with this program; if not, write to the Free Software |
| 24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 | */ |
| 26 | |
| 27 | require_once('prli-config.php'); |
| 28 | require_once(PRLI_MODELS_PATH . '/models.inc.php'); |
| 29 | |
| 30 | |
| 31 | function prli_menu() |
| 32 | { |
| 33 | add_menu_page('Pretty Link', 'Pretty Link', 8, PRLI_PATH.'/prli-links.php','',PRLI_URL.'/images/pretty-link-small.png'); |
| 34 | add_submenu_page(PRLI_PATH.'/prli-links.php', 'Pretty Link | Reports', 'Reports', 8, PRLI_PATH.'/prli-reports.php'); |
| 35 | |
| 36 | add_action('admin_head-pretty-link/prli-reports.php', 'prli_reports_admin_header'); |
| 37 | } |
| 38 | |
| 39 | add_action('admin_menu', 'prli_menu'); |
| 40 | |
| 41 | /* Add header to prli-reports page */ |
| 42 | function prli_reports_admin_header() |
| 43 | { |
| 44 | global $prli_report, $prli_utils; |
| 45 | |
| 46 | if(isset($_POST['link'])) |
| 47 | $link_id = $_POST['link']; |
| 48 | else |
| 49 | $link_id = "all"; |
| 50 | |
| 51 | if(isset($_POST['type'])) |
| 52 | $type = $_POST['type']; |
| 53 | else |
| 54 | $type = "all"; |
| 55 | |
| 56 | $first_click = $prli_utils->getFirstClickDate(); |
| 57 | |
| 58 | // Adjust for the first click |
| 59 | if(isset($first_click)) |
| 60 | { |
| 61 | $min_date = (int)((time()-$first_click)/60/60/24); |
| 62 | |
| 63 | if(isset($_POST['sdate']) and $_POST['sdate'] != '') |
| 64 | { |
| 65 | $sdate = explode("-",$_POST['sdate']); |
| 66 | $start_timestamp = mktime(0,0,0,$sdate[1],$sdate[2],$sdate[0]); |
| 67 | } |
| 68 | else |
| 69 | { |
| 70 | // Default to min_date or 30 days ago |
| 71 | if($min_date < 30) |
| 72 | $start_timestamp = time()-60*60*24*(int)$min_date; |
| 73 | else |
| 74 | $start_timestamp = time()-60*60*24*30; |
| 75 | } |
| 76 | |
| 77 | if(isset($_POST['edate']) and $_POST['edate'] != '') |
| 78 | { |
| 79 | $edate = explode("-",$_POST['edate']); |
| 80 | $end_timestamp = mktime(0,0,0,$edate[1],$edate[2],$edate[0]); |
| 81 | } |
| 82 | else |
| 83 | { |
| 84 | $end_timestamp = time(); |
| 85 | } |
| 86 | } |
| 87 | else |
| 88 | { |
| 89 | $min_date = 0; |
| 90 | $start_timestamp = time(); |
| 91 | $end_timestamp = time(); |
| 92 | } |
| 93 | ?> |
| 94 | <link type="text/css" href="/wp-content/plugins/<?php echo PRLI_PLUGIN_NAME; ?>/includes/jquery/css/ui-lightness/jquery-ui-1.7.1.custom.css" rel="stylesheet" /> |
| 95 | <script type="text/javascript" src="/wp-content/plugins/<?php echo PRLI_PLUGIN_NAME; ?>/includes/jquery/js/jquery-1.3.2.min.js"></script> |
| 96 | <script type="text/javascript" src="/wp-content/plugins/<?php echo PRLI_PLUGIN_NAME; ?>/includes/jquery/js/jquery-ui-1.7.1.custom.min.js"></script> |
| 97 | |
| 98 | <script type="text/javascript"> |
| 99 | $(document).ready(function(){ |
| 100 | $("#sdate").datepicker({ dateFormat: 'yy-mm-dd', defaultDate: -30, minDate: -<?php echo $min_date; ?>, maxDate: 0 }); |
| 101 | $("#edate").datepicker({ dateFormat: 'yy-mm-dd', minDate: -<?php echo $min_date; ?>, maxDate: 0 }); |
| 102 | }); |
| 103 | </script> |
| 104 | <script type="text/javascript" src="/wp-content/plugins/<?php echo PRLI_PLUGIN_NAME; ?>/includes/version-2-ichor/js/json/json2.js"></script> |
| 105 | <script type="text/javascript" src="/wp-content/plugins/<?php echo PRLI_PLUGIN_NAME; ?>/includes/version-2-ichor/js/swfobject.js"></script> |
| 106 | <script type="text/javascript"> |
| 107 | swfobject.embedSWF("/wp-content/plugins/<?php echo PRLI_PLUGIN_NAME; ?>/includes/version-2-ichor/open-flash-chart.swf", "my_chart", "100%", "400", "9.0.0"); |
| 108 | </script> |
| 109 | |
| 110 | <script type="text/javascript"> |
| 111 | $(document).ready(function(){ |
| 112 | $("#sdate").datepicker(); |
| 113 | $("#edate").datepicker(); |
| 114 | }); |
| 115 | </script> |
| 116 | |
| 117 | |
| 118 | <script type="text/javascript"> |
| 119 | |
| 120 | function ofc_ready() |
| 121 | { |
| 122 | //alert('ofc_ready'); |
| 123 | } |
| 124 | |
| 125 | function open_flash_chart_data() |
| 126 | { |
| 127 | //alert( 'reading data' ); |
| 128 | return JSON.stringify(data); |
| 129 | } |
| 130 | |
| 131 | function findSWF(movieName) { |
| 132 | if (navigator.appName.indexOf("Microsoft")!= -1) { |
| 133 | return window[movieName]; |
| 134 | } else { |
| 135 | return document[movieName]; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | OFC = {}; |
| 140 | |
| 141 | OFC.jquery = { |
| 142 | name: "jQuery", |
| 143 | version: function(src) { return $('#'+ src)[0].get_version() }, |
| 144 | rasterize: function (src, dst) { $('#'+ dst).replaceWith(OFC.jquery.image(src)) }, |
| 145 | image: function(src) { return "<img src='data:image/png;base64," + $('#'+src)[0].get_img_binary() + "' />"}, |
| 146 | popup: function(src) { |
| 147 | var img_win = window.open('', 'Charts: Export as Image') |
| 148 | with(img_win.document) { |
| 149 | write('<html><head><title>Charts: Export as Image<\/title><\/head><body>' + OFC.jquery.image(src) + '<div>Right-Click on the above Image to Save<\/div><\/body><\/html>') } |
| 150 | // stop the 'loading...' message |
| 151 | img_win.document.close(); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | // Using an object as namespaces is JS Best Practice. I like the Control.XXX style. |
| 156 | //if (!Control) {var Control = {}} |
| 157 | //if (typeof(Control == "undefined")) {var Control = {}} |
| 158 | if (typeof(Control == "undefined")) {var Control = {OFC: OFC.jquery}} |
| 159 | |
| 160 | |
| 161 | // By default, right-clicking on OFC and choosing "save image locally" calls this function. |
| 162 | // You are free to change the code in OFC and call my wrapper (Control.OFC.your_favorite_save_method) |
| 163 | // function save_image() { alert(1); Control.OFC.popup('my_chart') } |
| 164 | function save_image() { |
| 165 | //alert(1); |
| 166 | OFC.jquery.popup('my_chart') |
| 167 | } |
| 168 | |
| 169 | function moo() { |
| 170 | //alert(99); |
| 171 | }; |
| 172 | |
| 173 | var data = <?php echo $prli_report->setupClickReport($start_timestamp,$end_timestamp,$link_id,$type); ?>; |
| 174 | |
| 175 | </script> |
| 176 | |
| 177 | <?php |
| 178 | } |
| 179 | |
| 180 | /********* ADD REDIRECTS YO ***********/ |
| 181 | function prli_link_rewrite($wp_rewrite) { |
| 182 | global $prli_link, $prli_utils; |
| 183 | |
| 184 | $pretty_links = $prli_link->getAll(); |
| 185 | |
| 186 | foreach($pretty_links as $pl) |
| 187 | { |
| 188 | if( $pl->slug != null and $pl->slug != '' and $prli_utils->slugIsAvailable($pl->slug) ) |
| 189 | { |
| 190 | if(isset($pl->forward_params) and $pl->forward_params) |
| 191 | add_rewrite_rule('(' . $pl->slug . ')/?\??(.*?)$', 'wp-content/plugins/' . PRLI_PLUGIN_NAME . '/prli.php?sprli=$1&$2'); |
| 192 | else |
| 193 | add_rewrite_rule('(' . $pl->slug . ')/?$', 'wp-content/plugins/' . PRLI_PLUGIN_NAME . '/prli.php?sprli=$1'); |
| 194 | } |
| 195 | |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | // Add rules after the rest of the rules are run |
| 200 | add_filter('generate_rewrite_rules', 'prli_link_rewrite'); |
| 201 | |
| 202 | /********* INSTALL PLUGIN ***********/ |
| 203 | $prli_db_version = "0.0.9"; |
| 204 | |
| 205 | function prli_install() { |
| 206 | global $wpdb, $prli_db_version; |
| 207 | |
| 208 | $clicks_table = $wpdb->prefix . "prli_clicks"; |
| 209 | $pretty_links_table = $wpdb->prefix . "prli_links"; |
| 210 | |
| 211 | $prli_db_version = 'prli_db_version'; |
| 212 | $prli_current_db_version = get_option( $prli_db_version ); |
| 213 | |
| 214 | if( empty($prli_current_db_version) or ($prli_current_db_version != $prli_new_db_version)) |
| 215 | { |
| 216 | /* Create/Upgrade Clicks Table */ |
| 217 | $sql = "CREATE TABLE " . $clicks_table . " ( |
| 218 | id int(11) NOT NULL auto_increment, |
| 219 | ip varchar(255) default NULL, |
| 220 | browser varchar(255) default NULL, |
| 221 | first_click tinyint default 0, |
| 222 | created_at datetime NOT NULL, |
| 223 | link_id int(11) default NULL, |
| 224 | PRIMARY KEY (id), |
| 225 | KEY link_id (link_id), |
| 226 | CONSTRAINT ".$clicks_table."_ibfk_1 FOREIGN KEY (link_id) REFERENCES $pretty_links_table (link_id) |
| 227 | );"; |
| 228 | |
| 229 | require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
| 230 | |
| 231 | dbDelta($sql); |
| 232 | |
| 233 | /* Create/Upgrade Pretty Links Table */ |
| 234 | $sql = "CREATE TABLE " . $pretty_links_table . " ( |
| 235 | id int(11) NOT NULL auto_increment, |
| 236 | url varchar(255) default NULL, |
| 237 | slug varchar(255) default NULL, |
| 238 | track_as_img tinyint(1) default 0, |
| 239 | forward_params tinyint(1) default 0, |
| 240 | created_at datetime NOT NULL, |
| 241 | PRIMARY KEY (id), |
| 242 | KEY slug (slug) |
| 243 | );"; |
| 244 | |
| 245 | require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
| 246 | |
| 247 | dbDelta($sql); |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | // Ensure this gets called on first install |
| 252 | register_activation_hook(__FILE__,'prli_install'); |
| 253 | |
| 254 | ?> |
| 255 |