Skip to content

Commit e8c0b04

Browse files
committed
First real push
We'll see what happens
1 parent 04a0359 commit e8c0b04

File tree

7 files changed

+266
-16
lines changed

7 files changed

+266
-16
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mysql.php

.htaccess

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<IfModule mod_rewrite.c>
2+
RewriteEngine On
3+
RewriteCond %{REQUEST_FILENAME} !-f
4+
RewriteCond %{REQUEST_FILENAME} !-d
5+
RewriteRule ^(.*)$ index.php/$1 [L]
6+
</IfModule>

create.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE HTML>
2+
<head>
3+
<title></title>
4+
<style>
5+
pre {
6+
padding: 10px;
7+
width: 640px;
8+
background-color: #666666;
9+
color: #f5f5f5;
10+
overflow: scroll;
11+
}
12+
</style>
13+
</head>
14+
<body>
15+
<?php
16+
include("short_url_creator.php");
17+
//email generation
18+
?>
19+
<pre><code>
20+
<?php
21+
$shortUrl = new shortUrlCreator("suc");
22+
?>
23+
</pre></code>
24+
</body>
25+
</html>

index.php

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
<?php
2-
DEFINE('MYSQLI_SERVER', "localhost");
3-
DEFINE('MYSQLI_USER', "root");
4-
DEFINE('MYSQLI_PASSWORD', "");
5-
DEFINE('MYSQLI_DB', "shrty");
6-
$mysqli_connect = mysqli_connect(MYSQLI_SERVER, MYSQLI_USER,MYSQLI_PASSWORD) or die("Could not connect to server");
7-
$mysqli_db = mysqli_select_db($mysqli_connect, MYSQLI_DB) or die("Could not connect to database");
2+
include("mysql.php");
83
if(isset($_GET['url'])){
94
$url = urldecode($_GET['url']);
10-
if(preg_match('|^(https?)://[\w-.]+([.][a-z]{2,7})*(:[\d]+)?(/.*)?$|', $url)){
5+
if(preg_match('|^(https?)://[\w-.]+([.][a-z]{2,7})*(:[\d]+)?([/?].*)?$|', $url)){
116
if(isset($_GET['name'])){
127
$name = urldecode($_GET['name']);
138
} else {
@@ -16,14 +11,14 @@
1611
}
1712
$name =mysqli_real_escape_string($mysqli_connect, $name);
1813
$url = mysqli_real_escape_string($mysqli_connect, $url);
19-
if(mysqli_query($mysqli_connect, "INSERT INTO shrties (`short`, `long`) VALUES ('$name', '$url')")){
14+
if(mysqli_query($mysqli_connect, "INSERT INTO pncks (`short`, `long`) VALUES ('$name', '$url')")){
2015
//echo $name;
2116
} else{
2217
//echo mysqli_error($mysqli_connect);
2318
$errorNo = mysqli_errno($mysqli_connect);
2419
switch($errorNo){
2520
case 1062:
26-
$fetch_existing = mysqli_query($mysqli_connect, "SELECT `short` FROM `shrties` WHERE `long`='$url' LIMIT 1");
21+
$fetch_existing = mysqli_query($mysqli_connect, "SELECT `short` FROM `pncks` WHERE `long`='$url' LIMIT 1");
2722
if($fetch_existing){
2823
while($row = mysqli_fetch_array($fetch_existing)){
2924
$name = $row['short'];
@@ -46,17 +41,18 @@
4641
echo "Not a Valid URL";
4742
}
4843
} else {
49-
if(isset($_SERVER['PATH_INFO'])){
50-
$short = str_replace("/", "", $_SERVER['PATH_INFO']);
51-
mysqli_query($mysqli_connect, "UPDATE `shrties` SET `hits`= hits+1 WHERE`short`='$short'");
52-
$fetch_short = mysqli_query($mysqli_connect, "SELECT `long` FROM `shrties` WHERE `short`='$short' LIMIT 1");
44+
if(isset($_SERVER['REQUEST_URI'])){
45+
$short = str_replace("/", "", $_SERVER['REQUEST_URI']);
46+
mysqli_query($mysqli_connect, "UPDATE `pncks` SET `hits`= hits+1 WHERE`short`='$short'");
47+
include("tracking.php");
48+
$fetch_short = mysqli_query($mysqli_connect, "SELECT `long` FROM `pncks` WHERE `short`='$short' LIMIT 1");
5349
while($row = mysqli_fetch_array($fetch_short)){
5450
$long = $row['long'];
55-
//Header( "HTTP/1.1 301 Moved Permanently" );
56-
//Header( "Location: $long" );
51+
Header( "HTTP/1.1 301 Moved Permanently" );
52+
Header( "Location: $long" );
5753
}
5854
} else {
59-
//gui
55+
echo 'There is GUI, there is only ZUUL';
6056
}
6157
}
6258
mysqli_close($mysqli_connect);

mysql.dist.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
DEFINE('MYSQLI_SERVER', "localhost");
3+
DEFINE('MYSQLI_USER', "root");
4+
DEFINE('MYSQLI_PASSWORD', "");
5+
DEFINE('MYSQLI_DB', "pnck");
6+
$mysqli_connect = mysqli_connect(MYSQLI_SERVER, MYSQLI_USER,MYSQLI_PASSWORD) or die("Could not connect to server");
7+
$mysqli_db = mysqli_select_db($mysqli_connect, MYSQLI_DB) or die("Could not connect to database");
8+
?>

short_url_creator.php

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<?php
2+
class shortUrlCreator {
3+
//class shortUrlCreator extends module {
4+
protected $suc_source;
5+
protected $suc_medium;
6+
protected $suc_term;
7+
protected $suc_content;
8+
protected $suc_name;
9+
protected $suc_create_short;
10+
11+
protected $suc_original;
12+
protected $suc_final;
13+
protected $suc_short;
14+
protected $suc_create_tablesetup;
15+
16+
function __construct($name){
17+
$this->name = $name;
18+
if(isset($_POST['suc_submit'])){
19+
$this->processForm();
20+
} else {
21+
$this->formSetup();
22+
}
23+
}
24+
25+
function processForm(){
26+
foreach($_POST as $key=>$value){
27+
if(property_exists($this, $key)){
28+
$this->{$key} = $value;
29+
}
30+
}
31+
$this->getInfoFromWordpress($this->suc_original);
32+
$this->generateUrl();
33+
}
34+
function generateUrl(){
35+
if(isset($this->suc_original)){
36+
$final_url = "";
37+
if(!empty($this->suc_source)){
38+
$final_url = $final_url .'?utm_source='. $this->suc_source;
39+
if(!empty($this->suc_name)){
40+
$final_url = $final_url .'&utm_campaign='. $this->suc_name;
41+
if(!empty($this->suc_medium)){
42+
$final_url = $final_url .'&utm_source='. $this->suc_source;
43+
}else {
44+
//invalid
45+
}
46+
} else {
47+
//invalid
48+
}
49+
} else {
50+
//invalid
51+
}
52+
if(!empty($this->suc_term)){
53+
$final_url = $final_url .'&utm_term='. $this->suc_term;
54+
}
55+
if(!empty($this->suc_content)){
56+
$final_url = $final_url .'&tm_content='. $this->suc_term;
57+
}
58+
$this->suc_final = $this->suc_original .$final_url;
59+
if($this->suc_create_short){
60+
$temp = urlencode($this->suc_final);
61+
$this->suc_final = trim(file_get_contents("http://magx.us?url=$temp"));
62+
}
63+
if($this->suc_create_tablesetup){
64+
$this->generateTable();
65+
} else {
66+
echo $this->suc_final;
67+
}
68+
69+
}
70+
}
71+
public function getInfoFromWordpress(){
72+
$str = file_get_contents($this->suc_original);
73+
if(strlen($str)>0){
74+
preg_match("/\<title\>(.*)\<\/title\>/",$str, $title);
75+
$title = explode("|", $title[1]);
76+
$this->suc_page_title = $title[0];
77+
$this->suc_author = "TEST AUTHOR";
78+
$this->suc_article_title = "TEST TITLE";
79+
//$title = $this->suc_article_title;
80+
}
81+
}
82+
83+
public function generateTable(){
84+
$this->getInfoFromWordpress();
85+
$this->suc_final = trim($this->suc_final);
86+
$this->suc_page_title = trim($this->suc_page_title);
87+
$output = '<a href="'.$this->suc_final .'" target="_blank">'."\n".'<span class="title">'.$this->suc_page_title.'</span></a>'."\n By ".$this->suc_author;
88+
echo htmlentities($output);
89+
echo "\n";
90+
echo htmlentities($this->generateShares());
91+
}
92+
93+
public function formSetup(){
94+
echo '<form method="post" action="">';
95+
echo "Do the world a favor and leave off the WWW if possible <br>\n";
96+
echo '<label>Original URL:<span class="formhelp">No Spaces</span></label>';
97+
echo '<input type="url" name="'.$this->name .'_original" id="'.$this->name .'_original" placeholder="https://example.com" required value="">'."<br>\n";
98+
echo '<label>Campaign Name: <span class="formhelp">No Spaces</span></label>';
99+
echo '<input type="text" name="'.$this->name .'_name" id="'.$this->name .'_name" placeholder="product_promo" pattern="^[-\w-]{2,}$" value="">'."<br>\n";
100+
echo '<label>Campaign Source: <span class="formhelp">No Spaces</span></label>';
101+
echo '<input type="text" name="'.$this->name .'_source" id="'.$this->name .'_source" placeholder="newletter3" pattern="^[-\w]{2,}$" value="">'."<br>\n";
102+
echo '<label>Campaign Medium:<span class="formhelp">No Spaces</span></label>';
103+
echo '<input type="text" name="'.$this->name .'_medium" id="'.$this->name .'_medium" placeholder="bannerad" pattern="^[-\w]{2,}$" value="">'."<br>\n";
104+
105+
echo '<label>Campaign Term:<span class="formhelp">No Spaces</span></label>';
106+
echo '<input type="text" name="'.$this->name .'_term" id="'.$this->name .'_term" placeholder="paid keyword term" pattern="^[-\w]{2,}$" value="">'."<br>\n";
107+
108+
echo '<label>Campaign Content:<span class="formhelp">No Spaces. Additional info to sort sources</span></label>';
109+
echo '<input type="text" name="'.$this->name .'_content" id="'.$this->name .'_content" placeholder="homepage-top" pattern="^[\w]{3,}$" value="">'."<br>\n";
110+
echo '<label>Short Url?</label>';
111+
echo '<input type="checkbox" name="'.$this->name .'_create_short" id="'.$this->name .'_create_short">'."<br>\n";
112+
echo '<label>Create Table setup?</label>';
113+
echo '<input type="checkbox" name="'.$this->name .'_create_tablesetup" id="'.$this->name .'_create_tablesetup">'."<br>\n";
114+
echo '<input type="submit" name="'.$this->name .'_submit" id="'.$this->name .'_submit" value="Create Analytized link">'."<br>\n";
115+
echo '</form>';
116+
}
117+
118+
public function generateShares(){
119+
$encodedLink = urlencode($this->suc_final);
120+
$title = $this->suc_article_title;
121+
$facebook = '<a href="https://facebook.com/sharer.php?u='.$encodedLink.'" title="Share on Facebook"target="_blank"><img src="http://www.magazinexperts.com/conexec/email_images/facebook.png" border="0" alt="Share on Facebook" /></a>';
122+
$tweet = urlencode($title .' '. $this->suc_final . ' via @constructionmag');
123+
$twitter = '<a href="http://twitter.com/?status='.$tweet.'" title="Share on Twitter"target="_blank"><img src="http://www.magazinexperts.com/conexec/email_images/twitter.png" border="0" alt="Twitter" /></a>';
124+
$linkedin = '<a href="http://www.linkedin.com/shareArticle?mini=true&url='.$this->suc_final .'"title="Share on Linkedin"target="_blank"><img src="http://www.magazinexperts.com/conexec/email_images/linkedin.png" border="0" alt="Share on Linkedin" /></a>';
125+
$share = $facebook ."\n $twitter \n $linkedin";
126+
return $share;
127+
}
128+
}
129+
?>

tracking.php

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
if(isset($_SERVER['HTTP_USER_AGENT'])){
3+
$userAgent = $_SERVER['HTTP_USER_AGENT'];
4+
} else {
5+
$userAgent = "not found";
6+
}
7+
if(isset($_SERVER['REMOTE_ADDR'])){
8+
$ip = $_SERVER['REMOTE_ADDR'];
9+
} else {
10+
$ip = "not found";
11+
}
12+
if(isset($_SERVER['HTTP_REFERER'])){
13+
$referer = $_SERVER['HTTP_REFERER'];
14+
} else {
15+
$ip = "";
16+
}
17+
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
18+
$lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
19+
} else {
20+
$lang = "";
21+
}
22+
$hostname = gethostbyaddr($ip);
23+
$os = getOS($userAgent);
24+
25+
function getOS($userAgent) {
26+
$oses = array (
27+
'iPhone' => '(iPhone)',
28+
'Windows 3.11' => 'Win16',
29+
'Windows 95' => '(Windows 95)|(Win95)|(Windows_95)',
30+
'Windows 98' => '(Windows 98)|(Win98)',
31+
'Windows 2000' => '(Windows NT 5.0)|(Windows 2000)',
32+
'Windows XP' => '(Windows NT 5.1)|(Windows XP)',
33+
'Windows 2003' => '(Windows NT 5.2)',
34+
'Windows Vista' => '(Windows NT 6.0)|(Windows Vista)',
35+
'Windows 7' => '(Windows NT 6.1)|(Windows 7)',
36+
'Windows NT 4.0' => '(Windows NT 4.0)|(WinNT4.0)|(WinNT)|(Windows NT)',
37+
'Windows ME' => 'Windows ME',
38+
'Open BSD'=>'OpenBSD',
39+
'Sun OS'=>'SunOS',
40+
'Android'=>'(Android)',
41+
'iPad'=>'(iPod)',
42+
'iPhone'=>'(iPhone)',
43+
'iPod'=>'(iPad)',
44+
'Safari' => '(Safari)',
45+
'Macintosh'=>'(Mac_PowerPC)|(Macintosh)',
46+
'Mac OS X 10-6'=>'(Mac OS X 10_6)',
47+
'Mac OS X 10-7'=>'(Mac OS X 10_7)',
48+
'QNX'=>'QNX',
49+
'BeOS'=>'BeOS',
50+
'OS/2'=>'OS/2',
51+
'Linux'=>'(Linux)|(X11)',
52+
'Search Bot'=>'(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp/cat)|(msnbot)|(ia_archiver)'
53+
);
54+
55+
foreach($oses as $os=>$pattern){ // Loop through $oses array
56+
// Use regular expressions to check operating system type
57+
//if(eregi($pattern, $userAgent)) { // Check if a value in $oses array matches current user agent.
58+
if(preg_match("/$pattern/", $userAgent)) { // Check if a value in $oses array matches current user agent.
59+
return $os; // Operating system was matched so return $oses key
60+
}
61+
}
62+
return 'Unknown'; // Cannot find operating system so return Unknown
63+
}
64+
$pnck = $short;
65+
$sql = mysqli_query($mysqli_connect, "INSERT INTO `stats`(`pnck`, `useragent`, `ipv4`, `browser_lang`, `os`, `hostname`) VALUES ('$short', '$userAgent', '$ip','$lang', '$os', '$hostname')");
66+
if($sql){
67+
//echo "it works";
68+
} else {
69+
//echo mysqli_errno($mysqli_connect);
70+
//print_r(mysqli_error($mysqli_connect));
71+
}
72+
/*
73+
Link to Whois for IP
74+
Link to whois for Hostname
75+
Link to Ping and Traceroute
76+
Link to GeoIP DB
77+
Cookie laws (We store cookies)
78+
79+
split up user agent and look for browsers and versions.
80+
OS and Version
81+
82+
*/
83+
//sets a cookie to see if you've visited this site, or PNCK domain before
84+
//read OWA cookie for referer medium, source, search_terms
85+
?>

0 commit comments

Comments
 (0)