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

Version Description

Download this release

Release Info

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

Version 1.0.0

classes/models/PrliLink.php ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class PrliLink
3
+ {
4
+ public $table_name;
5
+
6
+ public function __construct()
7
+ {
8
+ global $wpdb;
9
+ $this->table_name = $wpdb->prefix . 'prli_links';
10
+ }
11
+
12
+ public function tableName()
13
+ {
14
+ return $this->table_name;
15
+ }
16
+
17
+ public function create( $values )
18
+ {
19
+ global $wpdb, $wp_rewrite;
20
+ $query = 'INSERT INTO ' . $this->table_name .
21
+ ' (url,slug,created_at) VALUES (\'' .
22
+ $values['url'] . '\',\'' .
23
+ $values['slug'] . '\',' .
24
+ 'NOW())';
25
+ $query_results = $wpdb->query($query);
26
+ $wp_rewrite->flush_rules();
27
+ return $query_results;
28
+ }
29
+
30
+ public function update( $id, $values )
31
+ {
32
+ global $wpdb, $wp_rewrite;
33
+ $query = 'UPDATE ' . $this->table_name .
34
+ ' SET url=\'' . $values['url'] . '\', ' .
35
+ ' slug=\'' . $values['slug'] . '\' ' .
36
+ 'WHERE id='.$id;
37
+ $query_results = $wpdb->query($query);
38
+ $wp_rewrite->flush_rules();
39
+ return $query_results;
40
+ }
41
+
42
+ public function destroy( $id )
43
+ {
44
+ require_once(PRLI_MODELS_PATH.'/models.inc.php');
45
+ global $wpdb, $wp_rewrite;
46
+ $destroy = 'DELETE FROM ' . $this->table_name . ' WHERE id=' . $id;
47
+ $wp_rewrite->flush_rules();
48
+ return $wpdb->query($destroy);
49
+ }
50
+
51
+ public function getOne( $id )
52
+ {
53
+ global $wpdb;
54
+ $click_table = $wpdb->prefix . "prli_clicks";
55
+ $query = 'SELECT li.*, (SELECT COUNT(*) FROM ' . $click_table . ' cl WHERE cl.link_id = li.id) as clicks FROM ' . $this->table_name . ' li WHERE id=' . $id . ';';
56
+ return $wpdb->get_row($query);
57
+ }
58
+
59
+ public function getAll()
60
+ {
61
+ global $wpdb;
62
+ $click_table = $wpdb->prefix . "prli_clicks";
63
+ $query = 'SELECT li.*, (SELECT COUNT(*) FROM ' . $click_table . ' cl WHERE cl.link_id = li.id) as clicks FROM ' . $this->table_name . ' li;';
64
+ return $wpdb->get_results($query);
65
+ }
66
+
67
+ // Pagination Methods
68
+ public function getRecordCount($where="")
69
+ {
70
+ global $wpdb;
71
+ $query = 'SELECT COUNT(*) FROM ' . $this->table_name . $where;
72
+ return $wpdb->get_var($query);
73
+ }
74
+
75
+ public function getPageCount($p_size, $where="")
76
+ {
77
+ return ceil((int)$this->getRecordCount($where) / (int)$p_size);
78
+ }
79
+
80
+ public function getPage($current_p,$p_size, $where = "")
81
+ {
82
+ global $wpdb;
83
+ $click_table = $wpdb->prefix . "prli_clicks";
84
+ $end_index = $current_p * $p_size;
85
+ $start_index = $end_index - $p_size;
86
+ $query = 'SELECT li.*, (SELECT COUNT(*) FROM ' . $click_table . ' cl WHERE cl.link_id = li.id) as clicks FROM ' . $this->table_name . ' li' . $where . ' LIMIT ' . $start_index . ',' . $p_size . ';';
87
+ $results = $wpdb->get_results($query);
88
+ return $results;
89
+ }
90
+
91
+ /** I'm generating a slug that is by default 2-3 characters long.
92
+ * This gives us a possibility of 36^3 - 37 = 46,619 possible
93
+ * random slugs. That should be *more* than enough slugs for
94
+ * any website -- if I get any feedback that we need more then
95
+ * I can always make a config option to raise the # of chars.
96
+ */
97
+ public function generateValidSlug($num_chars = 3)
98
+ {
99
+ global $wpdb, $prli_utils;
100
+
101
+ // We're doing a base 36 hash which is why we're always doing everything by 36
102
+ $max_slug_value = pow(36,$num_chars);
103
+ $min_slug_value = 37; // we want to have at least 2 characters in the slug
104
+ $slug = base_convert( rand($min_slug_value,$max_slug_value), 10, 36 );
105
+
106
+ $query = "SELECT slug FROM " . $this->table_name; // . " WHERE slug='" . $slug . "'";
107
+ $slugs = $wpdb->get_col($query,0);
108
+
109
+ // It is highly unlikely that we'll ever see 2 identical random slugs
110
+ // but just in case, here's some code to prevent collisions
111
+ while( in_array($slug,$slugs) or !$prli_utils->slugIsAvailable($slug) )
112
+ $slug = base_convert( rand($min_slug_value,$max_slug_value), 10, 36 );
113
+
114
+ return $slug;
115
+ }
116
+
117
+ public function validate( $values )
118
+ {
119
+ global $wpdb, $prli_utils;
120
+
121
+ $errors = array();
122
+ if( $values['url'] == null or $values['url'] == '' )
123
+ $errors[] = "Link URL can't be blank";
124
+
125
+ if( $values['slug'] == null or $values['slug'] == '' )
126
+ $errors[] = "Pretty Link can't be blank";
127
+
128
+ if( !preg_match('/^http.?:\/\/.*\..*$/', $values['url'] ) )
129
+ $errors[] = "Link URL must be a correctly formatted url";
130
+
131
+ if( !preg_match('/^[a-z0-9\.\-_]+$/', $values['slug'] ) )
132
+ $errors[] = "Pretty Link must not contain spaces or special characters";
133
+
134
+ if($values['id'] != null and $values['id'] != '')
135
+ $query = "SELECT slug FROM " . $this->table_name . " WHERE slug='" . $values['slug'] . "' AND id <> " . $values['id'];
136
+ else
137
+ $query = "SELECT slug FROM " . $this->table_name . " WHERE slug='" . $values['slug'] . "'";
138
+
139
+ $slug_already_exists = $wpdb->get_var($query);
140
+
141
+ if( $slug_already_exists or !$prli_utils->slugIsAvailable($values['slug']) )
142
+ $errors[] = "This pretty link slug is already taken, please choose a different one";
143
+
144
+ return $errors;
145
+ }
146
+ };
147
+ ?>
classes/models/PrliUtils.php ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'models.inc.php';
3
+
4
+ class PrliUtils
5
+ {
6
+
7
+ /** Okay I realize that Percentagize isn't really a word but
8
+ * this is so that the values we have will work with google
9
+ * charts.
10
+ */
11
+ public function percentagizeArray($data,$max_value)
12
+ {
13
+ $new_data = array();
14
+ foreach($data as $point)
15
+ {
16
+ if( $max_value > 0 )
17
+ {
18
+ $new_data[] = $point / $max_value * 100;
19
+ }
20
+ else
21
+ {
22
+ $new_data[] = 0;
23
+ }
24
+ }
25
+ return $new_data;
26
+ }
27
+
28
+ public function getTopValue($values_array)
29
+ {
30
+ rsort($values_array);
31
+ return $values_array[0];
32
+ }
33
+
34
+
35
+ public function getMonthsArray()
36
+ {
37
+ global $wpdb;
38
+ global $prli_click;
39
+
40
+ $months = array();
41
+ $year = date("Y");
42
+ $month = date("m");
43
+ $current_timestamp = time();
44
+ $current_month_timestamp = mktime(0, 0, 0, date("m", $current_timestamp), 1, date("Y", $current_timestamp));
45
+
46
+ $clicks_table = $prli_click->tableName();
47
+ $first_click = $wpdb->get_var("SELECT created_at FROM $clicks_table ORDER BY created_at LIMIT 1;");
48
+ $first_timestamp = ((empty($first_click))?$current_timestamp:strtotime($first_click));
49
+ $first_date = mktime(0, 0, 0, date("m", $first_timestamp), 1, date("Y", $first_timestamp));
50
+
51
+ while($current_month_timestamp >= $first_date)
52
+ {
53
+ $months[] = $current_month_timestamp;
54
+ if(date("m") == 1)
55
+ {
56
+ $current_month_timestamp = mktime(0, 0, 0, 12, 1, date("Y", $current_month_timestamp)-1);
57
+ }
58
+ else
59
+ {
60
+ $current_month_timestamp = mktime(0, 0, 0, date("m", $current_month_timestamp)-1, 1, date("Y", $current_month_timestamp));
61
+ }
62
+ }
63
+ return $months;
64
+ }
65
+
66
+ // For Pagination
67
+ public function getLastRecordNum($r_count,$current_p,$p_size)
68
+ {
69
+ return (($r_count < ($current_p * $p_size))?$r_count:($current_p * $p_size));
70
+ }
71
+
72
+ // For Pagination
73
+ public function getFirstRecordNum($r_count,$current_p,$p_size)
74
+ {
75
+ if($current_p == 1)
76
+ {
77
+ return 1;
78
+ }
79
+ else
80
+ {
81
+ return ($this->getLastRecordNum($r_count,($current_p - 1),$p_size) + 1);
82
+ }
83
+ }
84
+
85
+ public function slugIsAvailable($slug)
86
+ {
87
+ global $wpdb;
88
+
89
+ $posts_table = $wpdb->prefix . "posts";
90
+ $terms_table = $wpdb->prefix . "terms";
91
+
92
+ $post_slug = $wpdb->get_var("SELECT post_name FROM $posts_table WHERE post_name='$slug'");
93
+ $term_slug = $wpdb->get_col("SELECT slug FROM $terms_table WHERE slug='$slug'");
94
+
95
+ return ( $post_slug != $slug and $term_slug != $slug );
96
+ }
97
+
98
+ };
99
+ ?>
classes/models/models.inc.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once(PRLI_MODELS_PATH.'/PrliLink.php');
3
+ require_once(PRLI_MODELS_PATH.'/PrliUtils.php');
4
+
5
+ $prli_link = new PrliLink();
6
+ $prli_utils = new PrliUtils();
7
+ ?>
classes/views/prli-links/edit.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="wrap">
2
+ <h2><img src="<?php echo PRLI_URL.'/images/pretty-link-med.png'; ?>"/>&nbsp;Pretty Link: Edit Link</h2>
3
+
4
+ <?php
5
+ require(PRLI_VIEWS_PATH.'/shared/errors.php');
6
+ ?>
7
+
8
+ <form name="form1" method="post" action="?page=<?php print PRLI_PLUGIN_NAME ?>/prli-links.php">
9
+ <input type="hidden" name="action" value="update">
10
+ <input type="hidden" name="id" value="<?php print $id; ?>">
11
+ <?php wp_nonce_field('update-options'); ?>
12
+
13
+ <table class="form-table">
14
+ <tr>
15
+ <td width="75px" valign="top">URL*: </td>
16
+ <td><input type="text" name="url" value="<?php print (($_POST['url'] != null and $record == null)?$_POST['url']:$record->url); ?>" size="75">
17
+ <br/><span class="setting-description">Enter the URL you want to mask and track. Don't forget to start your url with <code>http://</code> or <code>https://</code>. Example: <code>http://www.yoururl.com</code></span></td>
18
+ </tr>
19
+ <tr>
20
+ <td valign="top">Pretty Link*: </td>
21
+ <td><strong><?php print get_option('siteurl'); ?></strong>/<input type="text" name="slug" value="<?php print (($_POST['slug'] != null and $record == null)?$_POST['slug']:$record->slug); ?>" size="25">
22
+ <br/><span class="setting-description">Enter the slug (word trailing your main URL) that will form your pretty link and redirect to the URL above.</span></td>
23
+ </tr>
24
+ </table>
25
+
26
+ <p class="submit">
27
+ <input type="submit" name="Submit" value="Update" />&nbsp;or&nbsp;<a href="?page=<?php print PRLI_PLUGIN_NAME ?>/prli-links.php">Cancel</a>
28
+ </p>
29
+
30
+ </form>
31
+ </div>
classes/views/prli-links/list.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="wrap">
2
+ <h2><img src="<?php echo PRLI_URL.'/images/pretty-link-med.png'; ?>"/>&nbsp;Pretty Link: Links</h2>
3
+ <p>Get started by <a href="?page=<?php print PRLI_PLUGIN_NAME; ?>/prli-links.php&action=new">adding a URL</a> that you want to turn into a pretty link. Come back to check how many times it was clicked.</p>
4
+ <p><a href="?page=<?php print PRLI_PLUGIN_NAME; ?>/prli-links.php&action=new"><img src="<?php echo PRLI_URL.'/images/pretty-link-add.png'; ?>"/> Add a Pretty Link</a></p>
5
+ <?php
6
+ require(PRLI_VIEWS_PATH.'/shared/table-nav.php');
7
+ ?>
8
+ <table class="widefat post fixed" cellspacing="0">
9
+ <thead>
10
+ <tr>
11
+ <th class="manage-column" width="10%">Slug</th>
12
+ <th class="manage-column" width="45%">URL</th>
13
+ <th class="manage-column" width="25%">Pretty Link</th>
14
+ <th class="manage-column" width="5%">Clicks</th>
15
+ <th class="manage-column" width="5%">Destroy</th>
16
+ </tr>
17
+ </thead>
18
+ <?php
19
+
20
+ if(count($links) <= 0)
21
+ {
22
+ ?>
23
+ <tr>
24
+ <td colspan="5"><a href="?page=<?php print PRLI_PLUGIN_NAME; ?>/prli-links.php&action=new"><img src="<?php echo PRLI_URL.'/images/pretty-link-add.png'; ?>"/> Add your First Pretty Link</a></td>
25
+ </tr>
26
+ <?php
27
+ }
28
+ else
29
+ {
30
+ foreach($links as $link)
31
+ {
32
+ ?>
33
+ <tr>
34
+ <td><a href="?page=<?php print PRLI_PLUGIN_NAME; ?>/prli-links.php&action=edit&id=<?php print $link->id; ?>"><?php print $link->slug; ?></a></td>
35
+ <td><a href="<? print $link->url; ?>" target="_blank" title="Visit URL in New Window"><img src="<?php echo PRLI_URL.'/images/url_icon.gif'; ?>" name="Visit" alt="Visit"/></a>&nbsp;&nbsp;<? print $link->url; ?></td>
36
+ <td><input type='text' style="font-size: 10px;" readonly="true" onclick='this.select();' onfocus='this.select();' value='<?php echo get_option('siteurl') . '/' . $link->slug; ?>' size="30" /></td>
37
+ <td><?php print $link->clicks; ?></td>
38
+ <td><a href="?page=<?php print PRLI_PLUGIN_NAME; ?>/prli-links.php&action=destroy&id=<?php print $link->id; ?>" onclick="return confirm('Are you sure you want to delete this link?');">Destroy</a></td>
39
+ </tr>
40
+ <?php
41
+ }
42
+ }
43
+ ?>
44
+ <tfoot>
45
+ <tr>
46
+ <th class="manage-column">Slug</th>
47
+ <th class="manage-column">URL</th>
48
+ <th class="manage-column">Pretty Link</th>
49
+ <th class="manage-column">Clicks</th>
50
+ <th class="manage-column">Destroy</th>
51
+ </tr>
52
+ </tfoot>
53
+ </table>
54
+ <?php
55
+ require(PRLI_VIEWS_PATH.'/shared/table-nav.php');
56
+ ?>
57
+
58
+ </div>
classes/views/prli-links/new.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="wrap">
2
+ <h2><img src="<?php echo PRLI_URL.'/images/pretty-link-med.png'; ?>"/>&nbsp;Pretty Link: Add Link</h2>
3
+
4
+ <?php
5
+ require(PRLI_VIEWS_PATH.'/shared/errors.php');
6
+ ?>
7
+
8
+ <form name="form1" method="post" action="?page=<?php print PRLI_PLUGIN_NAME ?>/prli-links.php">
9
+ <input type="hidden" name="action" value="create">
10
+ <?php wp_nonce_field('update-options'); ?>
11
+ <input type="hidden" name="id" value="<?php print $id; ?>">
12
+
13
+ <table class="form-table">
14
+ <tr>
15
+ <td width="75px" valign="top">URL*: </td>
16
+ <td><input type="text" name="url" value="<?php print (($_POST['url'] != null)?$_POST['url']:''); ?>" size="75">
17
+ <br/><span class="setting-description">Enter the URL you want to mask and track. Don't forget to start your url with <code>http://</code> or <code>https://</code>. Example: <code>http://www.yoururl.com</code></span></td>
18
+ </tr>
19
+ <tr>
20
+ <td valign="top">Pretty Link*: </td>
21
+ <td><strong><?php print get_option('siteurl'); ?></strong>/<input type="text" name="slug" value="<?php print (($_POST['slug'] != null)?$_POST['slug']:$prli_link->generateValidSlug()); ?>" size="25">
22
+ <br/><span class="setting-description">Use the auto-generated short slug (2-3 characters) here or enter any word (must only contain letters, numbers or the following special characters: ".","-" or "_") that will form your pretty link and redirect to the URL above. Just refresh this page to auto-generate another slug.</span></td>
23
+ </tr>
24
+ </table>
25
+
26
+ <p class="submit">
27
+ <input type="submit" name="Submit" value="Create" />&nbsp;or&nbsp;<a href="?page=<?php print PRLI_PLUGIN_NAME ?>/prli-links.php">Cancel</a>
28
+ </p>
29
+
30
+ </form>
31
+ </div>
classes/views/shared/errors.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if( $errors != null and count($errors) > 0 )
3
+ {
4
+ ?>
5
+ <div class="error">
6
+ <ul>
7
+ <?php
8
+ foreach( $errors as $error )
9
+ {
10
+ ?>
11
+ <li><strong>ERROR</strong>: <?php print $error; ?></li>
12
+ <?php
13
+ }
14
+ ?>
15
+ </ul>
16
+ </div>
17
+ <?php
18
+ }
19
+ ?>
classes/views/shared/table-nav.php ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Only show the pager bar if there is more than 1 page
3
+ if($page_count > 1)
4
+ {
5
+ ?>
6
+ <div class="tablenav">
7
+ <div class='tablenav-pages'><span class="displaying-num">Displaying <?php print "$page_first_record&#8211;$page_last_record of $record_count"; ?></span>
8
+
9
+ <?php
10
+ // Only show the prev page button if the current page is not the first page
11
+ if($current_page > 1)
12
+ {
13
+ ?>
14
+ <a class='prev page-numbers' href='?page=<?php print PRLI_PLUGIN_NAME; ?>/<?php print $controller_file . $page_params; ?>&paged=<?php print($current_page-1); ?>'>&laquo;</a>
15
+ <?php
16
+ }
17
+
18
+ // First page is always displayed
19
+ if($current_page==1)
20
+ {
21
+ ?>
22
+ <span class='page-numbers current'>1</span>
23
+ <?php
24
+ }
25
+ else
26
+ {
27
+ ?>
28
+ <a class='page-numbers' href='?page=<?php print PRLI_PLUGIN_NAME; ?>/<?php print $controller_file . $page_params; ?>&paged=1'>1</a>
29
+ <?php
30
+ }
31
+
32
+ // If the current page is more than 2 spaces away from the first page then we put some dots in here
33
+ if($current_page >= 5)
34
+ {
35
+ ?>
36
+ <span class='page-numbers dots'>...</span>
37
+ <?php
38
+ }
39
+
40
+ // display the current page icon and the 2 pages beneath and above it
41
+ $low_page = (($current_page >= 5)?($current_page-2):2);
42
+ $high_page = ((($current_page + 2) < ($page_count-1))?($current_page+2):($page_count-1));
43
+ for($i = $low_page; $i <= $high_page; $i++)
44
+ {
45
+ if($current_page==$i)
46
+ {
47
+ ?>
48
+ <span class='page-numbers current'><?php print $i; ?></span>
49
+ <?php
50
+ }
51
+ else
52
+ {
53
+ ?>
54
+ <a class='page-numbers' href='?page=<?php print PRLI_PLUGIN_NAME; ?>/<?php print $controller_file . $page_params; ?>&paged=<?php print $i; ?>'><?php print $i; ?></a>
55
+ <?php
56
+ }
57
+ }
58
+
59
+ // If the current page is more than 2 away from the last page then show ellipsis
60
+ if($current_page < ($page_count - 3))
61
+ {
62
+ ?>
63
+ <span class='page-numbers dots'>...</span>
64
+ <?php
65
+ }
66
+
67
+ // Display the last page icon
68
+ if($current_page == $page_count)
69
+ {
70
+ ?>
71
+ <span class='page-numbers current'><?php print $page_count; ?></span>
72
+ <?php
73
+ }
74
+ else
75
+ {
76
+ ?>
77
+ <a class='page-numbers' href='?page=<?php print PRLI_PLUGIN_NAME; ?>/<?php print $controller_file . $page_params; ?>&paged=<?php print $page_count; ?>'><?php print $page_count; ?></a>
78
+ <?php
79
+ }
80
+
81
+ // Display the next page icon if there is a next page
82
+ if($current_page < $page_count)
83
+ {
84
+ ?>
85
+ <a class='next page-numbers' href='?page=<?php print PRLI_PLUGIN_NAME; ?>/<?php print $controller_file . $page_params; ?>&paged=<?php print($current_page + 1); ?>'>&raquo;</a>
86
+ <?php
87
+ }
88
+ ?>
89
+ </div>
90
+ </div>
91
+ <?php
92
+ }
93
+ ?>
images/bookmark.png ADDED
Binary file
images/pretty-link-add.png ADDED
Binary file
images/pretty-link-med.png ADDED
Binary file
images/pretty-link-small.png ADDED
Binary file
images/url_icon.gif ADDED
Binary file
pretty-link.php ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 they get using Pretty Link. For instance, this URL: http://www.yourdomain.com/cnn could link to http://www.cnn.com -- this 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 the click count.
6
+ Version: 1.0.0
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
+ register_activation_hook(__FILE__,'prli_install');
31
+
32
+ add_action('admin_menu', 'prli_menu');
33
+
34
+ function prli_menu() {
35
+ add_menu_page('Pretty Link', 'Pretty Link', 8, PRLI_PATH.'/prli-links.php','',PRLI_URL.'/images/pretty-link-small.png');
36
+ // add_submenu_page(PRLI_PATH.'/prli-main.php', 'Pretty Link | Links', 'Links', 8, PRLI_PATH.'/prli-links.php');
37
+ // add_submenu_page(PRLI_PATH.'/prli-main.php', 'Pretty Link | Reports', 'Reports', 8, PRLI_PATH.'/prli-links.php');
38
+ }
39
+
40
+ /********* ADD REDIRECTS YO ***********/
41
+ function link_rewrite($wp_rewrite) {
42
+ global $prli_link, $prli_utils;
43
+
44
+ $pretty_links = $prli_link->getAll();
45
+
46
+ foreach($pretty_links as $pl)
47
+ {
48
+ if( $pl->slug != null and $pl->slug != '' and $prli_utils->slugIsAvailable($pl->slug) )
49
+ {
50
+ add_rewrite_rule('(' . $pl->slug . ')/?$', 'wp-content/plugins/' . PRLI_PLUGIN_NAME . '/prli.php?s=$1');
51
+ }
52
+
53
+ }
54
+ }
55
+
56
+ // Add rules after the rest of the rules are run
57
+ add_filter('generate_rewrite_rules', 'link_rewrite');
58
+
59
+ /********* INSTALL PLUGIN ***********/
60
+ $prli_db_version = "0.0.3";
61
+
62
+ function prli_install() {
63
+ global $wpdb;
64
+ global $prli_db_version;
65
+
66
+
67
+ $clicks_table = $wpdb->prefix . "prli_clicks";
68
+ $pretty_links_table = $wpdb->prefix . "prli_links";
69
+
70
+ $prli_db_version = 'prli_db_version';
71
+ $prli_current_db_version = get_option( $prli_db_version );
72
+
73
+ if( empty($prli_current_db_version) or ($prli_current_db_version != $prli_new_db_version))
74
+ {
75
+ /* Create/Upgrade Clicks Table */
76
+ $sql = "CREATE TABLE " . $clicks_table . " (
77
+ id int(11) NOT NULL auto_increment,
78
+ ip varchar(255) default NULL,
79
+ browser varchar(255) default NULL,
80
+ first_click tinyint default 0,
81
+ created_at datetime NOT NULL,
82
+ link_id int(11) default NULL,
83
+ PRIMARY KEY (id),
84
+ KEY link_id (link_id),
85
+ CONSTRAINT ".$clicks_table."_ibfk_1 FOREIGN KEY (link_id) REFERENCES $pretty_links_table (link_id)
86
+ );";
87
+
88
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
89
+
90
+ dbDelta($sql);
91
+
92
+ /* Create/Upgrade Pretty Links Table */
93
+ $sql = "CREATE TABLE " . $pretty_links_table . " (
94
+ id int(11) NOT NULL auto_increment,
95
+ url varchar(255) default NULL,
96
+ slug varchar(255) default NULL,
97
+ created_at datetime NOT NULL,
98
+ PRIMARY KEY (id),
99
+ KEY slug (slug)
100
+ );";
101
+
102
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
103
+
104
+ dbDelta($sql);
105
+ }
106
+ }
107
+ ?>
prli-config.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ define(PRLI_PLUGIN_NAME,"pretty-link");
3
+ define(PRLI_PATH,WP_PLUGIN_DIR.'/'.PRLI_PLUGIN_NAME);
4
+ define(PRLI_MODELS_PATH,PRLI_PATH.'/classes/models');
5
+ define(PRLI_VIEWS_PATH,PRLI_PATH.'/classes/views');
6
+ define(PRLI_URL,WP_PLUGIN_URL.'/'.PRLI_PLUGIN_NAME);
7
+
8
+ // The number of items per page on a table
9
+ $page_size = 15;
10
+ ?>
prli-links.php ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'prli-config.php';
3
+ require_once(PRLI_MODELS_PATH . '/models.inc.php');
4
+
5
+ $controller_file = 'prli-links.php';
6
+
7
+ if($_GET['action'] == null and $_POST['action'] == null)
8
+ {
9
+ // Required for Pagination to work
10
+ if($_GET['paged'] != null)
11
+ {
12
+ $current_page = $_GET['paged'];
13
+ }
14
+ else
15
+ {
16
+ $current_page = 1;
17
+ }
18
+
19
+ $record_count = $prli_link->getRecordCount();
20
+ $page_count = $prli_link->getPageCount($page_size);
21
+ $links = $prli_link->getPage($current_page,$page_size);
22
+ $page_last_record = $prli_utils->getLastRecordNum($record_count,$current_page,$page_size);
23
+ $page_first_record = $prli_utils->getFirstRecordNum($record_count,$current_page,$page_size);
24
+ $page_params = "";
25
+ require_once 'classes/views/prli-links/list.php';
26
+ }
27
+ else if($_GET['action'] == 'new' or $_POST['action'] == 'new')
28
+ {
29
+ require_once 'classes/views/prli-links/new.php';
30
+ }
31
+ else if($_GET['action'] == 'create' or $_POST['action'] == 'create')
32
+ {
33
+ $errors = $prli_link->validate($_POST);
34
+ if( count($errors) > 0 )
35
+ {
36
+ require_once 'classes/views/prli-links/new.php';
37
+ }
38
+ else
39
+ {
40
+ $record = $prli_link->create( $_POST );
41
+
42
+ // Required for Pagination to work
43
+ $current_page = 1;
44
+ $record_count = $prli_link->getRecordCount();
45
+ $page_count = $prli_link->getPageCount($page_size);
46
+ $links = $prli_link->getPage($current_page,$page_size);
47
+ $page_last_record = $prli_utils->getLastRecordNum($record_count,$current_page,$page_size);
48
+ $page_first_record = $prli_utils->getFirstRecordNum($record_count,$current_page,$page_size);
49
+ $page_params = "";
50
+
51
+ require_once 'classes/views/prli-links/list.php';
52
+ }
53
+ }
54
+ else if($_GET['action'] == 'edit' or $_POST['action'] == 'edit')
55
+ {
56
+ $record = $prli_link->getOne( $_GET['id'] );
57
+ $id = $_GET['id'];
58
+ require_once 'classes/views/prli-links/edit.php';
59
+ }
60
+ else if($_GET['action'] == 'update' or $_POST['action'] == 'update')
61
+ {
62
+ $errors = $prli_link->validate($_POST);
63
+ $id = $_POST['id'];
64
+ if( count($errors) > 0 )
65
+ {
66
+ require_once 'classes/views/prli-links/edit.php';
67
+ }
68
+ else
69
+ {
70
+ $record = $prli_link->update( $_POST['id'], $_POST );
71
+
72
+ // Required for Pagination to work
73
+ $current_page = 1;
74
+ $record_count = $prli_link->getRecordCount();
75
+ $page_count = $prli_link->getPageCount($page_size);
76
+ $links = $prli_link->getPage($current_page,$page_size);
77
+ $page_last_record = $prli_utils->getLastRecordNum($record_count,$current_page,$page_size);
78
+ $page_first_record = $prli_utils->getFirstRecordNum($record_count,$current_page,$page_size);
79
+ $page_params = "";
80
+
81
+ require_once 'classes/views/prli-links/list.php';
82
+ }
83
+ }
84
+ else if($_GET['action'] == 'destroy')
85
+ {
86
+ $prli_link->destroy( $_GET['id'] );
87
+
88
+ // Required for Pagination to work
89
+ $current_page = 1;
90
+ $record_count = $prli_link->getRecordCount();
91
+ $page_count = $prli_link->getPageCount($page_size);
92
+ $links = $prli_link->getPage($current_page,$page_size);
93
+ $page_last_record = $prli_utils->getLastRecordNum($record_count,$current_page,$page_size);
94
+ $page_first_record = $prli_utils->getFirstRecordNum($record_count,$current_page,$page_size);
95
+ $page_params = "";
96
+ require_once 'classes/views/prli-links/list.php';
97
+ }
98
+ ?>
prli.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* This file tracks clicks */
3
+
4
+ require_once(dirname(__FILE__) . '/../../../wp-config.php');
5
+
6
+ if( $_GET['s'] != null and $_GET['s'] != '' )
7
+ {
8
+ $slug = $_GET['s'];
9
+
10
+ $click_table = $wpdb->prefix . "prli_clicks";
11
+ $pretty_links_table = $wpdb->prefix . "prli_links";
12
+
13
+ $query = "SELECT id,url FROM $pretty_links_table WHERE slug='$slug' LIMIT 1";
14
+ $pretty_link = $wpdb->get_row($query);
15
+
16
+ $first_click = false;
17
+
18
+ $click_ip = $_SERVER['REMOTE_ADDR'];
19
+ $click_browser = $_SERVER['HTTP_USER_AGENT'];
20
+
21
+ //Set Cookie if it doesn't exist
22
+ $cookie_name = 'prli_click_' . $pretty_link->id;
23
+ $cookie_expire_time = time()+60*60*24*30; // Expire in 30 days
24
+
25
+ if($_COOKIE[$cookie_name] == null)
26
+ {
27
+ setcookie($cookie_name,$slug,$cookie_expire_time);
28
+ $first_click = true;
29
+ }
30
+
31
+ //Record Click in DB
32
+ $insert = "INSERT INTO $click_table (link_id,ip,browser,first_click,created_at) VALUES ($pretty_link->id,'$click_ip','$click_browser','$first_click',NOW())";
33
+
34
+ $results = $wpdb->query( $insert );
35
+
36
+ //Redirect to Product URL
37
+ header("Location: $pretty_link->url");
38
+ }
39
+ ?>
readme.txt ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Pretty Link ===
2
+ Contributors: supercleanse
3
+ Donate link: http://blairwilliams.com/pretty-link
4
+ Tags: links, link, url, urls, affiliate, affiliates, pretty, marketing, redirect, redirect, rewrite, short, shorten, click, clicks, track, tracking, tiny, tinyurl, budurl, shrinking, domain, shrink, mask, masking, slug, slugs, admin, stats, statistics, stat, statistic
5
+ Requires at least: 2.7.1
6
+ Tested up to: 2.7.1
7
+ Stable tag: 1.0.0
8
+
9
+ Create clean, simple, trackable links on your website that redirect to other URLs and then analyze the number of clicks they get using Pretty Link. For instance, this URL: http://www.yourdomain.com/cnn could link to http://www.cnn.com -- this 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 the click count.
10
+
11
+ == Description ==
12
+
13
+ Create clean, simple, trackable links on your website that redirect to other URLs and then analyze the number of clicks they get using Pretty Link. For instance, this URL: http://www.yourdomain.com/cnn could link to http://www.cnn.com -- this 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 the click count.
14
+
15
+ = Features =
16
+
17
+ * Gives you the ability to create clean, simple URLs on your website that redirect to any other URL
18
+ * Generates random 2-3 character slugs for your URL or allows you to name a custom slug for your URL
19
+ * Tracks the Number of Clicks per link
20
+
21
+ == Installation ==
22
+
23
+ 1. Upload 'pretty-link.zip' to the '/wp-content/plugins/' directory
24
+
25
+ 2. Activate the plugin through the 'Plugins' menu in WordPress
26
+
27
+ 3. Make sure you have changed your permalink Common Settings in Settings -> Permalinks away from "Default" to something else. I prefer using custom and then "/%postname%/" for the simplest possible URL slugs.
28
+
29
+ == Frequently Asked Questions ==
30
+
31
+ * This plugin is extremely simple. All you have to do is to find the pretty link admin menu (bottom left of your admin page) and start by clicking "Add a Pretty Link."
32
+
33
+ = NOTE: =
34
+
35
+ You must have pretty permalinks and rewrite working in your Wordpress/PHP/Apache install before pretty links will work (this is already done in most cases but if you can't get anything but Default permalinks working then you may need to contact your system administrator). Pretty links utlilzes Wordpress's URL rewriting capabilities (via Apache's mod_rewrite) which are only turned on when you change the settings in "Settings -> Permalinks" from "Default" to something else. If you want your blog to have any kind of decent SEO then you really should do this anyway.
36
+
37
+
38
+ == Screenshots ==
39
+
40
+ 1. Screenshot List of Links
41
+ 2. Screenshot Adding a Link
42
+ 3. Screenshot Editing a Link
screenshot-1.png ADDED
Binary file
screenshot-2.png ADDED
Binary file
screenshot-3.png ADDED
Binary file