Version Description
Download this release
Release Info
Developer | supercleanse |
Plugin | Shortlinks by Pretty Links – Best WordPress Link Tracking Plugin |
Version | 0.0.2 |
Comparing to | |
See all releases |
Version 0.0.2
- classes/models/PrliLink.php +121 -0
- classes/models/PrliUtils.php +99 -0
- classes/models/models.inc.php +7 -0
- classes/views/prli-links/edit.php +31 -0
- classes/views/prli-links/list.php +58 -0
- classes/views/prli-links/new.php +31 -0
- classes/views/shared/errors.php +19 -0
- classes/views/shared/table-nav.php +93 -0
- images/bookmark.png +0 -0
- pretty-link.php +107 -0
- prli-config.php +10 -0
- prli-links.php +98 -0
- prli.php +39 -0
- readme.txt +31 -0
classes/models/PrliLink.php
ADDED
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
public function validate( $values )
|
92 |
+
{
|
93 |
+
global $wpdb, $prli_utils;
|
94 |
+
|
95 |
+
$errors = array();
|
96 |
+
if( $values['url'] == null or $values['url'] == '' )
|
97 |
+
$errors[] = "Link URL can't be blank";
|
98 |
+
|
99 |
+
if( $values['slug'] == null or $values['slug'] == '' )
|
100 |
+
$errors[] = "Pretty Link can't be blank";
|
101 |
+
|
102 |
+
if( !preg_match('/^http.?:\/\/.*\..*$/', $values['url'] ) )
|
103 |
+
$errors[] = "Link URL must be a correctly formatted url";
|
104 |
+
|
105 |
+
if( !preg_match('/^[a-z0-9\.\-_]+$/', $values['slug'] ) )
|
106 |
+
$errors[] = "Pretty Link must not contain spaces or special characters";
|
107 |
+
|
108 |
+
if($values['id'] != null and $values['id'] != '')
|
109 |
+
$query = "SELECT slug FROM " . $this->table_name . " WHERE slug='" . $values['slug'] . "' AND id <> " . $values['id'];
|
110 |
+
else
|
111 |
+
$query = "SELECT slug FROM " . $this->table_name . " WHERE slug='" . $values['slug'] . "'";
|
112 |
+
|
113 |
+
$slug_already_exists = $wpdb->get_var($query);
|
114 |
+
|
115 |
+
if( $slug_already_exists or !$prli_utils->slugIsAvailable($values['slug']) )
|
116 |
+
$errors[] = "This pretty link slug is already taken, please choose a different one";
|
117 |
+
|
118 |
+
return $errors;
|
119 |
+
}
|
120 |
+
};
|
121 |
+
?>
|
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>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">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.</span></td>
|
18 |
+
</tr>
|
19 |
+
<tr>
|
20 |
+
<td>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="Create" /> | <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>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">+ Add 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="15%">Slug</th>
|
12 |
+
<th class="manage-column" width="25%">URL</th>
|
13 |
+
<th class="manage-column" width="30%">Pretty Link</th>
|
14 |
+
<th class="manage-column" width="20%">Clicks</th>
|
15 |
+
<th class="manage-column" width="10%">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">Create your First 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><? print $link->url; ?> | <a href="<? print $link->url; ?>" target="_blank">Visit</a></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>Pretty Link: New 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">URL*: </td>
|
16 |
+
<td><input type="text" name="url" value="<?php print (($_POST['url'] != null)?$_POST['url']:'http://yoururl.com'); ?>" size="75">
|
17 |
+
<br/><span class="setting-description">Enter the URL you want to mask and track.</span></td>
|
18 |
+
</tr>
|
19 |
+
<tr>
|
20 |
+
<td>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']:''); ?>" 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="Create" /> | <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–$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); ?>'>«</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); ?>'>»</a>
|
86 |
+
<?php
|
87 |
+
}
|
88 |
+
?>
|
89 |
+
</div>
|
90 |
+
</div>
|
91 |
+
<?php
|
92 |
+
}
|
93 |
+
?>
|
images/bookmark.png
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: Creates shortened, named URLs using your blog. This plugin makes the best possible links for your affiliate campaigns or other endeavors because the links appear to be coming from your site instead of from tinyurl, budurl or one of the other link shrinking services. You can track stats on your links easily and keep that data on your own database (instead of allowing it to be managed on other machines).
|
6 |
+
Version: 0.0.2
|
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/bookmark.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,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Pretty Link ===
|
2 |
+
Contributors: supercleanse
|
3 |
+
Donate link: http://blairwilliams.com/
|
4 |
+
Tags: links, pretty, link, url, urls, redirect, redirect, rewrite, short, tinyurl, budurl, shrink, mask, slug, slugs
|
5 |
+
Requires at least: 2.7.1
|
6 |
+
Tested up to: 2.7.1
|
7 |
+
Stable tag: trunk
|
8 |
+
|
9 |
+
With Pretty Link you can create shortened, named URLs using your website's domain name.
|
10 |
+
|
11 |
+
== Description ==
|
12 |
+
|
13 |
+
With Pretty Link you can create shortened, named URLs using your website's domain name. This plugin makes the cleanest links possible because they are on your site instead of from tinyurl, budurl or one of the other link shrinking services. You can also track stats on your links easily and keep that data on your own database.
|
14 |
+
|
15 |
+
== Installation ==
|
16 |
+
|
17 |
+
1. Upload `plugin-name.php` to the `/wp-content/plugins/` directory
|
18 |
+
2. Activate the plugin through the 'Plugins' menu in WordPress
|
19 |
+
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 tags.
|
20 |
+
|
21 |
+
= Features =
|
22 |
+
|
23 |
+
* Add URL Redirects to your Blog : You can redirect and track any link
|
24 |
+
|
25 |
+
== Frequently Asked Questions ==
|
26 |
+
|
27 |
+
* http://blairwilliams.com/pretty-link/faq
|
28 |
+
|
29 |
+
== Screenshots ==
|
30 |
+
|
31 |
+
* http://blairwilliams.com/pretty-link/screenshots
|