This repository was archived by the owner on Jun 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserpanel.php
More file actions
235 lines (231 loc) · 9.87 KB
/
Copy pathuserpanel.php
File metadata and controls
235 lines (231 loc) · 9.87 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<?php
session_start();
include 'connect.php';
include 'functions.php';
$code = $_GET["code"];
$userdenied = htmlspecialchars($_GET["error_reason"]);
$accessdenied = htmlspecialchars($_GET["error"]);
$descriptiondenied = htmlspecialchars($_GET["error_description"]);
define("clientID", '[**CLIENT ID**]');
define("clientSecret", '[**CLIENT SECRET**]');
define("redirectURI", '[**URL**]/userpanel.php');
if($userdenied == "user_denied" || $accessdenied == "access_denied" || $descriptiondenied == "The+user+denied+your+request.") {
$error = 4;
include "linkpage.php";
return;
} else if (!$code) {
$error = 1;
include "linkpage.php";
return;
} else {
$url = "https://api.instagram.com/oauth/access_token";
$access_token_settings = array(
'client_id' => clientID,
'client_secret' => clientSecret,
'grant_type' => 'authorization_code',
'redirect_uri' => redirectURI,
'code' => $code
);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $access_token_settings);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($curl);
curl_close($curl);
$results = json_decode($result, true);
$username = $results['user']['username'];
$userID = $results['user']['id'];
$access_token = $results['access_token'];
$userpic = $results['user']['profile_picture'];
if (!$userID) {
$error = 2;
include "linkpage.php";
return;
}
?>
<!DOCTYPE html>
<head>
<title>LinkPage - User Panel</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="apple-touch-icon" sizes="180x180" href="favicons/apple-touch-icon.png?v=47MOxMmn7N">
<link rel="icon" type="image/png" sizes="32x32" href="favicons/favicon-32x32.png?v=47MOxMmn7N">
<link rel="icon" type="image/png" sizes="16x16" href="favicons/favicon-16x16.png?v=47MOxMmn7N">
<link rel="manifest" href="favicons/manifest.json?v=47MOxMmn7N">
<link rel="mask-icon" href="favicons/safari-pinned-tab.svg?v=47MOxMmn7N" color="#00a300">
<link rel="shortcut icon" href="favicons/favicon.ico?v=47MOxMmn7N">
<meta name="apple-mobile-web-app-title" content="LinkPage">
<meta name="application-name" content="LinkPage">
<meta name="msapplication-config" content="favicons/browserconfig.xml?v=47MOxMmn7N">
<meta name="theme-color" content="#ffffff">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="linkpage.css">
</head>
<?php
$error = 0;
echo ("<div class='jumbotron center''>
<a href='[**URL**]/linkpage.php'><h1>LinkPage</h1></a>
<p>Create an Instagram feed with personalized links for each post.</p>
</div>");
echo ("<div class='container'>
<div class='row' id='usertop'>
<div class='col-sm-2'>
<img src='".$userpic."'>
</div>
<div class='col-sm-10'>
<h1>User Panel</h1><br>
<p>Choose your recent posts and add your own link to them.</p>
<p>Your public profile link: <a class='bg-info' target='_blank' href='[**URL**]/profile.php?id=".$userID."'>https://web.njit.edu/~lpb6/iglink/profile.php?id=".$userID."</a>
</div>
</div>
<div class='row'>
<div class='col-sm-4'>
<p>Welcome <strong>".$username."</strong>.</p>
<a href='[**URL**]/logout.php' class='btn btn-primary btn-xs'>
<span class='glyphicon glyphicon-log-out'></span> Log out</a>
</div>
</div>
</div>");
getUserImages($access_token);
?>
<body>
<div class="container center">
<p><a href="[**URL**]/privacypolicy">Privacy Policy</a> | <a href="[**URL**]/guide">Guide</a></p>
</div>
<div class="footer">
<p><a href="https://lucasbastos.com"><small>By Lucas B. Ξ</small><a></p>
</div>
<script type="text/javascript">
var httpsarray = ["http://", "https://"];
function isURL(str) {
var pattern = new RegExp('^(https?:\\/\\/)?'+
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+
'((\\d{1,3}\\.){3}\\d{1,3}))'+
'(\\:\\d+)?'+
'(\\/[-a-z\\d%@_.~+&:]*)*'+
'(\\?[;&a-z\\d%@_.,~+&:=-]*)?'+
'(\\#[-a-z\\d_]*)?$','i');
return pattern.test(str);
}
function embedEnable(image_id, image_link) {
var postID = image_id;
postID = postID.replace(/['"]+/g, '');
var userID = <?php echo ($userID); ?>;
var postLink = image_link;
postLinkFinal = postLink.replace(/['"]+/g, '');
var userLink = document.getElementById("userlink"+postLink).value;
userLink = userLink.toLowerCase();
if (isURL(userLink) == false) {
document.getElementById("warning"+postLink).style = "display:block";
document.getElementById("warningbox"+postLink).innerHTML = "<strong>Not a valid link.</strong> Make sure your link is a valid link.";
}
if (isURL(userLink) == true){
if (!userLink.includes(httpsarray[0]) && !userLink.includes(httpsarray[1])) {
userLink = "http://"+userLink;
}
document.getElementById("warning"+postLink).style = "display:none";
document.getElementById("warningbox"+postLink).innerHTML = "";
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
} else {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("userlink"+postLink).setAttribute("disabled","");
document.getElementById("userlink"+postLink).placeholder = userLink;
document.getElementById("userlink"+postLink).value = "";
document.getElementById("button"+postLink).className = "btn btn-success";
document.getElementById("button"+postLink).innerHTML = "Edit";
document.getElementById("button"+postLink).setAttribute("onclick","embedSwitch('"+postID+"', '"+postLink+"');");
document.getElementById("deletebutton"+postLink).style = "display:inline-block;";
}
}
xmlhttp.open("POST","insertarray.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("postID="+postID+"&userID="+userID+"&postLink="+postLinkFinal+"&userLink="+userLink);
}
}
function embedSwitch(image_id, image_link){
var postID = image_id;
postID = postID.replace(/['"]+/g, '');
var userID = <?php echo ($userID); ?>;
var postLink = image_link;
postLinkFinal = postLink.replace(/['"]+/g, '');
var userLink = document.getElementById("userlink"+postLink).value;
userLink = userLink.toLowerCase();
document.getElementById("userlink"+postLink).removeAttribute("disabled");
document.getElementById("button"+postLink).className = "btn btn-primary";
document.getElementById("button"+postLink).innerHTML = "Submit";
document.getElementById("button"+postLink).setAttribute("onclick","embedUpdate('"+postID+"', '"+postLink+"');");
document.getElementById("deletebutton"+postLink).style = "display:none;";
}
function embedUpdate(image_id, image_link){
var postID = image_id;
postID = postID.replace(/['"]+/g, '');
var postLink = image_link;
postLinkFinal = postLink.replace(/['"]+/g, '');
var userLink = document.getElementById("userlink"+postLink).value;
userLink = userLink.toLowerCase();
if (!isURL(userLink)) {
document.getElementById("warning"+postLink).style = "display:block";
document.getElementById("warningbox"+postLink).innerHTML = "<strong>Not a valid link.</strong> Make sure your link is a valid link.";
}
else {
if (!userLink.includes(httpsarray[0]) && !userLink.includes(httpsarray[1])) {
userLink = "http://"+userLink;
}
document.getElementById("warning"+postLink).style = "display:none";
document.getElementById("warningbox"+postLink).innerHTML = "";
console.log("userLink");
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
} else {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("userlink"+postLink).placeholder = userLink;
document.getElementById("userlink"+postLink).value = "";
document.getElementById("userlink"+postLink).setAttribute("disabled","");
document.getElementById("button"+postLink).className = "btn btn-success";
document.getElementById("button"+postLink).innerHTML = "Edit";
document.getElementById("button"+postLink).setAttribute("onclick","embedSwitch('"+postID+"', '"+postLink+"');");
document.getElementById("deletebutton"+postLink).style = "display:inline-block;";
}
}
xmlhttp.open("POST","updatearray.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("postID="+postID+"&userLink="+userLink);
}
}
function embedDelete(image_id, image_link){
var postID = image_id;
postID = postID.replace(/['"]+/g, '');
var postLink = image_link;
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
} else {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
embedSwitch(postID, postLink);
document.getElementById("button"+postLink).setAttribute("onclick","embedEnable('"+postID+"', '"+postLink+"');");
document.getElementById("userlink"+postLink).placeholder = "Link";
}
}
xmlhttp.open("POST","deletearray.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("postID="+postID);
}
</script>
<script async="" defer="defer" src="http//platform.instagram.com/en_US/embeds.js"></script>
</body>
</html>
<?php } ?>