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
+ ?>
0 commit comments