Repository navigation
Expand file tree
/
Copy pathshortener.php
More file actions
117 lines (108 loc) · 4.25 KB
/
Copy pathshortener.php
File metadata and controls
117 lines (108 loc) · 4.25 KB
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
<?php
global $civicrm_id;
include $_SERVER['DOCUMENT_ROOT'].'/login.php';
$result = "error";
if($_POST){
$yourls_params = array('signature' => YOURLS_SIGNATURE, 'action' => 'shorturl', 'format' => 'json',
'url' => $_POST["inputUrl"], 'keyword' => $_POST["inputShort"]);
if(isset($_POST["inputTitle"]) && $_POST["inputTitle"]){ $yourls_params["title"] = $_POST["inputTitle"]; }
$ch = curl_init(YOURLS_URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POST,count($yourls_params));
curl_setopt($ch,CURLOPT_POSTFIELDS,$yourls_params);
$reply = curl_exec($ch);
if(!$reply){
throw new Exception(curl_error($ch));
}
curl_close($ch);
$result = json_decode($reply, TRUE);
}
$access = STUDENT_VIS;
$title = "P2C URL Shortener";
$thisFile = "/shortener/";
$crumbs = array("Home" => "/", $title => $thisFile);
include $_SERVER['DOCUMENT_ROOT'].'/header.php';
?>
<script type="text/javascript">
$(document).ready(function() {
jQuery.validator.addMethod('yourls', function(shortlink, element) {
return this.optional(element) || shortlink.match(/^[a-z0-9-]+$/);
}, 'Short link can only contain lowercase letters, numbers, and hyphens');
$('#linkForm').validate({
ignore: ':not(select:hidden, input:visible, textarea:visible)',
rules: {
inputUrl: {
required: true
},
inputShort: {
yourls: true
}
},
errorElement: 'span',
highlight: function(element) {
$(element).closest('.form-group').removeClass('has-success').addClass('has-error');
},
success: function(element) {
$(element).closest('.form-group').removeClass('has-error').addClass('has-success');
$(element).removeClass('error').addClass('valid').addClass('error');
}
});
$("#inputUrl").focus();
});
</script>
<div >
<div class="row">
<div class="col-md-12">
<?php
if($result){
if($result["status"] == "fail"){
echo "<div class='text-danger text-center'>";
echo "<h3>" . $result["message"] . "</h3></div>";
}
else if($result["status"] == "success"){
echo "<div class='text-success text-center'>";
echo "<h3>Short Link <a href=\"" . $result["shorturl"] . "\" target='_blank'>" . $result["shorturl"] . "</a> created for ";
echo "URL <a href=\"" . $result["url"]["url"] . "\" target='_blank'>" . $result["url"]["url"] . "</a></h3></div>";
}
}
?>
<div class="well square">
<div>
<h4 class="pull-left"><i class="glyphicon glyphicon-link"></i> Create p2c.sh Short Link</h4>
</div>
<form class="form-horizontal" id="linkForm" role="form" action="<?php echo $thisFile; ?>" method="post">
<table class="table table-bordered table-striped">
<tbody>
<tr class="infoEdit">
<td>Long URL</td>
<td class="form-group">
<input type="text" class="form-control" id="inputUrl" name="inputUrl" placeholder="URL" value="<?php echo $_POST['inputUrl']; ?>">
</td>
</tr>
<tr class="infoEdit">
<td>Short Link</td>
<td class="form-group">
<div class="input-group">
<label class="input-group-addon">http://p2c.sh/</label>
<input type="text" class="form-control" id="inputShort" name="inputShort" placeholder="Short link" value="<?php echo $_POST['inputShort']; ?>">
</div>
<span class="error" for="inputShort"></span>
</td>
</tr>
<tr class="infoEdit">
<td>Optional Title</td>
<td class="form-group">
<input type="text" class="form-control" id="inputTitle" name="inputTitle" placeholder="Optional" value="<?php echo $_POST['inputTitle']; ?>">
</td>
</tr>
</tbody>
</table>
<button type="submit" class="btn btn-success">Submit</button>
</form>
</div>
</div>
<?php include $_SERVER['DOCUMENT_ROOT'].'/footer.php'; ?>
</body>
</html>