Skip to content

Commit 19b8b5b

Browse files
committed
Merge branch 'feature/spaRefactor' into develop
2 parents aa9f40b + 284454d commit 19b8b5b

File tree

78 files changed

+4395
-4974
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+4395
-4974
lines changed

.gitignore

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
1-
# Ignore PhpStorm files
2-
.idea
1+
#### PROJECT IGNORES ####
32

43
# Ignore configuration files
54
inc/config.php
65

76
# Ignore schedule images
87
img/schedules/*.png
98

9+
# Ignore node_modules dependencies
10+
node_modules/*
11+
12+
# Ignore built files
13+
assets/prod/*
14+
!assets/prod/.gitkeep
15+
16+
#### EDITOR IGNORES####
17+
18+
# Ignore PhpStorm files
19+
.idea
20+
1021
# Ignore Eclipse files
1122
.settings
1223
.project
1324
.buildpath
1425

1526
# Ignore VisualStudio files
16-
/*.phpproj*
17-
/*.sln
18-
/*.suo
19-
/WebEssentials-Settings.json
27+
*.phpproj*
28+
*.sln
29+
*.suo
30+
web.config
31+
vwd.webinfo
32+
WebEssentials-Settings.json

.htaccess

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,23 @@
1-
RewriteEngine On
2-
RewriteRule ^schedule/([^/]*)(?:/([^/]*))?$ /schedule.php?id=$1&mode=$2 [L]
1+
RewriteEngine On
2+
3+
#Legacy Rewrites
4+
RewriteCond %{QUERY_STRING} ^id=(.*)$ [NC]
5+
RewriteRule ^schedule.php$ /schedule/%1? [NC,L,R=302]
6+
7+
8+
# Let old ScheduleMaker handle Resig's schedules for now
9+
#RewriteCond %{QUERY_STRING} ^mode=old&id=(.*)$ [NC]
10+
RewriteRule ^schedule.php$ http://schedule-old.csh.rit.edu/schedule.php [NC,L,R=302]
11+
12+
RewriteCond %{HTTP:Accept} application/json [NC]
13+
RewriteRule ^(schedule|generate|entity|search|status|rmp)(?:/([^/]*))*$ api/$1.php [L]
14+
15+
16+
# Don't rewrite files or directories
17+
RewriteCond %{REQUEST_FILENAME} -f [OR]
18+
RewriteCond %{REQUEST_FILENAME} -d
19+
RewriteRule ^ - [L]
20+
21+
22+
# Rewrite everything else to index.html to allow html5 state links
23+
RewriteRule ^ index.php [L]

js/entityAjax.php renamed to api/entity.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,9 @@
2222
$_POST = sanitize($_POST);
2323

2424
// MAIN EXECUTION //////////////////////////////////////////////////////////
25-
if(empty($_POST['action'])) {
26-
die(json_encode(array("error" => "argument", "msg" => "You must provide an action")));
27-
}
2825

2926
// Switch on the action
30-
switch($_POST['action']) {
27+
switch(getAction()) {
3128
case "getCourses":
3229
// Query for the courses in this department
3330

Lines changed: 3 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22
////////////////////////////////////////////////////////////////////////////
3-
// SCHEDULE AJAX CALLS
3+
// GENERATION AJAX CALLS
44
//
55
// @author Ben Russell ([email protected])
66
//
7-
// @file js/scheduleAjax.php
7+
// @file api/generate.php
88
// @descrip Provides standalone JSON object retreival for schedule designing
99
// form and display
1010
////////////////////////////////////////////////////////////////////////////
@@ -184,42 +184,6 @@ function timeStringToMinutes($str) {
184184
return $hour * 60 + $minute;
185185
}
186186

187-
/**
188-
* Generates a render of schedule's SVG. The PNG render of the image will be
189-
* stored in /img/schedules/ with a filename equal to the id of the schedule.
190-
* @param $svg string The SVG code for the image
191-
* @param $id string The ID of the schedule, for file name generation
192-
* @return bool True on success, False otherwise.
193-
*/
194-
function renderSvg($svg, $id) {
195-
try {
196-
197-
// Prepend parsing info
198-
$svg = preg_replace('/(.*<svg[^>]* width=")(100\%)(.*)/', '${1}1000px${3}', $svg);
199-
$svg = '<?xml version="1.1" encoding="UTF-8" standalone="no"?>' . $svg;
200-
// Load the image into an ImageMagick object
201-
$im = new Imagick();
202-
$im->readimageblob($svg);
203-
204-
// Convert it to png
205-
$im->setImageFormat("png24");
206-
207-
$im->scaleimage(1000, 600, true);
208-
209-
210-
// Write it to the filesystem
211-
$im->writeimage("../img/schedules/{$id}.png");
212-
$im->clear();
213-
$im->destroy();
214-
215-
// Success!
216-
return true;
217-
218-
} catch(Exception $e) {
219-
return false;
220-
}
221-
}
222-
223187
////////////////////////////////////////////////////////////////////////////
224188
// MAIN EXECUTION
225189

@@ -229,12 +193,7 @@ function renderSvg($svg, $id) {
229193
// Escape the post data
230194
$_POST = sanitize($_POST);
231195

232-
// What action are we performing today?
233-
if(empty($_POST['action'])) {
234-
$_POST['action'] = null;
235-
}
236-
237-
switch($_POST['action']) {
196+
switch(getAction()) {
238197
////////////////////////////////////////////////////////////////////////
239198
// GET COURSE OPTIONS
240199
case "getCourseOpts":
@@ -328,22 +287,6 @@ function renderSvg($svg, $id) {
328287

329288
break;
330289

331-
////////////////////////////////////////////////////////////////////////
332-
// GET TIME DROPDOWNS
333-
case "getTimeField":
334-
// Verify that we have the field name and the default time
335-
if(empty($_POST['name'])) {
336-
die(json_encode(array("error"=>"argument", "msg"=>"A field name must be provided", "arg"=>"name")));
337-
}
338-
if(empty($_POST['default'])) {
339-
die(json_encode(array("error"=>"argument", "msg"=>"A default time must be provided", "arg"=>"default")));
340-
}
341-
342-
// Return the code
343-
echo json_encode(array("code" => getTimeField($_POST['name'], $_POST['default'])));
344-
345-
break;
346-
347290
////////////////////////////////////////////////////////////////////////
348291
// GET MATCHING SCHEDULES
349292
case "getMatchingSchedules":
@@ -434,76 +377,7 @@ function renderSvg($svg, $id) {
434377

435378
break;
436379

437-
////////////////////////////////////////////////////////////////////////
438-
// STORE A SCHEDULE
439-
case "saveSchedule":
440-
// There has to be a json object given
441-
if(empty($_POST['data'])) {
442-
die(json_encode(array("error" => "argument", "msg" => "No schedule was provided", "arg" => "schedule")));
443-
}
444-
$_POST['data'] = html_entity_decode($_POST['data'], ENT_QUOTES);
445-
$json = stripslashes($_POST['data']);
446-
447-
// Make sure the object was successfully decoded
448-
$json = json_decode($json, true);
449-
if($json == null) {
450-
die(json_encode(array("error" => "argument", "msg" => "The schedule could not be decoded", "arg" => "schedule")));
451-
}
452-
if(!isset($json['starttime']) || !isset($json['endtime']) || !isset($json['building']) || !isset($json['startday']) || !isset($json['endday'])) {
453-
die(json_encode(array("error" => "argument", "msg" => "A required schedule parameter was not provided")));
454-
}
455-
456-
// Start the storing process with storing the data about the schedule
457-
$query = "INSERT INTO schedules (oldid, startday, endday, starttime, endtime, building, quarter)" .
458-
" VALUES('', '{$json['startday']}', '{$json['endday']}', '{$json['starttime']}', '{$json['endtime']}', '{$json['building']}', " .
459-
" '{$json['term']}')";
460-
$result = mysql_query($query);
461-
if(!$result) {
462-
die(json_encode(array("error" => "mysql", "msg" => "Failed to store the schedule: " . mysql_error($dbConn))));
463-
}
464-
465-
// Grab the latest id for the schedule
466-
$schedId = mysql_insert_id();
467-
468-
// Optionally process the svg for the schedule
469-
$image = false;
470-
if(!empty($_POST['svg']) && renderSvg(html_entity_decode($_POST['svg']), $schedId)) {
471-
$query = "UPDATE schedules SET image = ((1)) WHERE id = '{$schedId}'";
472-
mysql_query($query); // We don't particularly care if this fails
473-
}
474380

475-
// Now iterate through the schedule
476-
foreach($json['schedule'] as $item) {
477-
// Process it into schedulenoncourses if the item is a non-course item
478-
if($item['courseNum'] == "non") {
479-
// Process each time as a seperate item
480-
foreach($item['times'] as $time) {
481-
$query = "INSERT INTO schedulenoncourses (title, day, start, end, schedule)" .
482-
" VALUES('{$item['title']}', '{$time['day']}', '{$time['start']}', '{$time['end']}', '{$schedId}')";
483-
$result = mysql_query($query);
484-
if(!$result) {
485-
die(json_encode(array("error" => "mysql", "msg" => "Storing non-course item '{$item['title']}' failed: " . mysql_error($dbConn))));
486-
}
487-
}
488-
} else {
489-
// Process each course. It's crazy simple now.
490-
$query = "INSERT INTO schedulecourses (schedule, section)" .
491-
" VALUES('{$schedId}', '{$item['id']}')";
492-
$result = mysql_query($query);
493-
if(!$result) {
494-
die(json_encode(array("error" => "mysql", "msg" => "Storing a course '{$item['courseNum']}' failed: " . mysql_error($dbConn))));
495-
}
496-
}
497-
}
498-
499-
// Everything was successful, return a nice, simple URL to the schedule
500-
// To make it cool, let's make it a hex id
501-
$hexId = dechex($schedId);
502-
$url = "{$HTTPROOTADDRESS}schedule/{$hexId}";
503-
504-
echo json_encode(array("url" => $url, "id" => $hexId));
505-
506-
break;
507381

508382
////////////////////////////////////////////////////////////////////////
509383
// DEFAULT ACTION

js/rmp.php renamed to api/rmp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
$curl = curl_init();
1111
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
1212
curl_setopt($curl, CURLOPT_HEADER, false);
13-
$name = $_GET['professor'];
13+
$name = explode('/', $_SERVER['REQUEST_URI'])[2];
1414
curl_setopt ($curl, CURLOPT_URL, "http://www.ratemyprofessors.com/SelectTeacher.jsp?searchName=".$name."&search_submit1=Search&sid=807");
1515
echo curl_exec($curl);

0 commit comments

Comments
 (0)