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