-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
185 lines (153 loc) · 6.56 KB
/
index.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
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
<!DOCTYPE html>
<!--
UCLA Astro Coffee Page, by Abhimat Gautam
based on previous versions by Ryan T. Hamilton, Ian J. Crossfield, and Nathaniel Ross
-->
<?php
//
//
// If you see this text in your browser, it means PHP scripts are not
// enabled on this web server. Consult the internet or your local system
// administrator to enable PHP scripting.
//
//
// SET THE PATH TO YOUR PYTHON VERSION HERE
// $python = '/usr/bin/python';
$python = '/Users/abhimat/software/Ureka/variants/common/bin/python';
// CHOOSE YOUR TIMEZONE FROM THE LINK BELOW AND SET IT HERE
$CurrentVer = phpversion();
if(version_compare($CurrentVer, '5.1.0')>=0) {
date_default_timezone_set('US/Pacific');
#http://www.php.net/manual/en/timezones.others.php
}
$paperFile = "papers_next";
$logFile = "dregs.log";
$listManager = "listmanager.php";
$article = $_POST["article"];
$ipOfSubmitter=$_SERVER["REMOTE_ADDR"];
if ((!isset($_POST["submit"])) and (!isset($_POST["submitcheck"])))
{ // if page is not submitted, show the form
?>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>UCLA Astro Coffee</title>
<!-- Preparing for the robot revolution -->
<meta name="ROBOTS" content="NOINDEX, NOFOLLOW">
<!-- Google Web Fonts -->
<link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,600,700,900,400italic,600italic,700italic,900italic' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Bree+Serif' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Montserrat:400,700' rel='stylesheet' type='text/css'>
<meta name=viewport content='width=device-width, initial-scale=1'>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!-- Favicon -->
<link rel="shortcut icon" href="images/favicon.png">
<link rel="apple-touch-icon" href="images/touch-icon.png">
<!-- Styles -->
<link rel="stylesheet" href="./styles.css" type="text/css" media="screen" />
<!-- MathJax -->
<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [['$','$'], ['\\(','\\)'], ['{','}']],
processEscapes: true
}
});
</script>
</head>
<body>
<header>
<!-- <p><a href="http://www.astro.ucla.edu"><semibold><em>UCLA</em> Astronomy and Astrophysics</semibold></a></p> -->
<!-- <h1>Astro Coffee</h1> -->
<picture>
<source srcset="./images/Header-Dark_1x.png 1x, ./images/Header-Dark_2x.png 2x" media="(prefers-color-scheme: dark)">
<img src="./images/Header_2x.png" srcset="./images/Header_1x.png 1x, ./images/Header_2x.png 2x" alt="Astro Coffee" />
</picture>
<center><ul class="pages">
<li><strong>Current Articles</strong></li>
<li><a href="./archive/">Archive</a></li>
<li><a href="./usefullinks/">Useful Links</a></li>
</ul></center>
<form method="post" class="submission" action="<?php echo $PHP_SELF;?>">
<center><input type="text" name="article" maxlength="128" placeholder="Submit a URL or arXiv-ID" class="field"/></center>
<input type="submit" value="submit" name="submit" class="button"/>
</form>
<center><ul class="pages-small small">
<li><a href="./bookmarklet/">Bookmarklet</a></li>
<li><a href="./listmanager.php">Submissions</a></li>
<li><a href="./status.log">Status Log</a></li>
</ul></center>
</header>
<div class="content wrap">
<section class="blocks">
<?php include("astro_coffee.php"); ?>
</section> <!-- /blocks -->
</div> <!-- /content -->
<footer class="small wrap">
<center><p class="small"><strong>Astro Coffee 2</strong><br>by <a href="http://astro.ucla.edu/~abhimat/">Abhimat Gautam</a></p></center>
<!-- <center><p class="small">Based on previous versions of astroph.py by<br>Ryan T. Hamilton, Ian J. Crossfield, and Nathaniel Ross.</p></center> -->
<center><p class="small"><a href="https://github.com/abhimat/AstroCoffee">Contribute on GitHub!</a></p></center>
</footer>
</body>
</html>
<? // If check-form _was_ submitted, display this instead:
} elseif (isset($_POST["submitcheck"])) {
echo 'Loading article list manager...<br>';
echo '<META HTTP-EQUIV=Refresh CONTENT="1;'.$listManager.'">';
// If submit-form _was_ submitted, display this instead:
} elseif (isset($_POST["submit"])) {
$minlength = 5;
echo "<head>";
echo " <link rel=\"stylesheet\" href=\"./styles.css\" type=\"text/css\" media=\"screen\" />";
echo "</head>";
echo '<META HTTP-EQUIV=Refresh CONTENT="10">';
// echo "<p>You submitted ".$article."</p>";
# Check for invalid characters
if (preg_match("/[^A-Za-z0-9\:\.\/\?\_\#\-\=]/", $article))
{
echo '<p><strong>Your submission contains invalid characters!</strong></p>';
echo '<p>If you think this is an error, tell the coffee website manager.</p>';
echo "<p>You will be returned to your original page in 10 seconds.</p>";
echo "<p>If not, click <a href='./'>here</a></p>";
die;
}
# Testing for duplicates
$papers = file($paperFile) or die("can't open file: ".$paperFile);
foreach ($papers as $pap){
if (trim($article) == trim($pap)) {
echo '<p>Your submission is a duplicate of a paper already submitted!</p>';
echo '<p>If you think this is an error, tell the coffee czar.</p>';
echo "<p>Returning to the main page automatically in 10 seconds</p>";
echo "<p>If not, click <a href='./'>here</a></p>";
die;
}
}
if (strlen($article)>$minlength) {
$f = fopen($paperFile,"a") or die("can't open file: ".$paperFile);
fwrite($f, "\n".trim($article));
fclose($f);
# Get estimate of run time for the user
$lines = count(file($paperFile));
$time = $lines * 10;
echo "<p>Your sumission was successfully added to the list. </p>";
echo "<p>Thanks for advancing knowledge!</p>";
echo "<p>It may be several minutes before the main page is updated.</p>";
echo "<p>I see $lines items to update, so it will take >$time seconds.</p>";
echo "<p>You will be returned to the main page in 10 seconds.</p>";
echo "<p>If not, click <a href='./'>here</a></p>";
$str4log = date('D, d M Y H:i:s')." ".$article." ".$ipOfSubmitter;
$f2 = fopen($logFile,"a") or die("can`t open file: ".$logFile);
fwrite($f2, $str4log."\n");
fclose($f2);
$nullRet = `$python runcoffee.py > /dev/null &`;
} else {
echo "This is shorter than the minimum valid string length (".$minlength.").";
echo "Thus your submission was not added to the papers list.";
}
} else {
echo "you should not have reached this point!";
}
?>