Skip to content

Commit 77ad61b

Browse files
committed
RMP popup works again!
1 parent 767234d commit 77ad61b

File tree

5 files changed

+100
-53
lines changed

5 files changed

+100
-53
lines changed

api/rmp.php

+24-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,34 @@
22
////////////////////////////////////////////////////////////////////////////
33
// RATE MY PROFESSORS PROXY
44
//
5-
// @author Ben Grawi (bgrawi@csh.rit.edu)
5+
// @author Mary Strodl (mstrodl@csh.rit.edu)
66
//
77
// @file js/rmp.php
88
// @descrip Provides a proxy to the RMP site to avoid XSS
99
////////////////////////////////////////////////////////////////////////////
1010
$curl = curl_init();
1111
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
12-
curl_setopt($curl, CURLOPT_HEADER, false);
13-
$name = explode('/', $_SERVER['REQUEST_URI'])[2];
14-
curl_setopt($curl, CURLOPT_URL, "http://www.ratemyprofessors.com/SelectTeacher.jsp?searchName=" . $name . "&search_submit1=Search&sid=807");
12+
curl_setopt($curl, CURLOPT_POST, true);
13+
curl_setopt($curl, CURLOPT_HTTPHEADER, [
14+
"Authorization: Basic dGVzdDp0ZXN0", // Literally test:test in base64... YES this is required.
15+
"Content-Type: application/json",
16+
]);
17+
$body = json_decode(file_get_contents('php://input'), true);
18+
$name = $body['name'];
19+
$payload = json_encode([
20+
"query" => "query TeacherSearchResultsPageQuery(\n \$query: TeacherSearchQuery!\n \$schoolID: ID\n \$includeSchoolFilter: Boolean!\n) {\n search: newSearch {\n ...TeacherSearchPagination_search_1ZLmLD\n }\n school: node(id: \$schoolID) @include(if: \$includeSchoolFilter) {\n __typename\n ... on School {\n name\n }\n id\n }\n}\n\nfragment TeacherSearchPagination_search_1ZLmLD on newSearch {\n teachers(query: \$query, first: 8, after: \"\") {\n didFallback\n edges {\n cursor\n node {\n ...TeacherCard_teacher\n id\n __typename\n }\n }\n pageInfo {\n hasNextPage\n endCursor\n }\n resultCount\n filters {\n field\n options {\n value\n id\n }\n }\n }\n}\n\nfragment TeacherCard_teacher on Teacher {\n id\n legacyId\n avgRating\n numRatings\n ...CardFeedback_teacher\n ...CardSchool_teacher\n ...CardName_teacher\n ...TeacherBookmark_teacher\n}\n\nfragment CardFeedback_teacher on Teacher {\n wouldTakeAgainPercent\n avgDifficulty\n}\n\nfragment CardSchool_teacher on Teacher {\n department\n school {\n name\n id\n }\n}\n\nfragment CardName_teacher on Teacher {\n firstName\n lastName\n}\n\nfragment TeacherBookmark_teacher on Teacher {\n id\n isSaved\n}\n",
21+
"variables" => [
22+
"query" => [
23+
"text" => $name,
24+
"schoolID" => "U2Nob29sLTgwNw==",
25+
"fallback" => false, // No results from other schools
26+
"departmentID" => null,
27+
],
28+
"schoolID" => "U2Nob29sLTgwNw==",
29+
"includeSchoolFilter" => true
30+
],
31+
]);
32+
curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
33+
34+
curl_setopt($curl, CURLOPT_URL, "https://www.ratemyprofessors.com/graphql");
1535
echo curl_exec($curl);

assets/src/modules/sm/App/directives/professorLookupDirective.ts

+66-46
Original file line numberDiff line numberDiff line change
@@ -6,59 +6,79 @@ angular.module('sm').directive('professorLookup', function ($http) {
66
},
77
template: '{{professorLookup}}',
88
link: {
9-
pre: function (scope, elm, attrs) {
10-
11-
},
9+
pre: function (scope, elm, attrs) {},
1210
post: function (scope, elm, attrs) {
1311
if (scope.professorLookup !== '' && scope.professorLookup !== 'TBA') {
1412
scope.stats = 'none'
1513
elm.on('click', function () {
16-
const nameParts = scope.professorLookup.split(' ')
17-
const lastName = nameParts[nameParts.length - 1]
1814
if (scope.stats === 'none') {
19-
$http({
20-
method: 'GET',
21-
url: '/rmp/' + lastName,
22-
headers: {
23-
Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
24-
}
25-
}).success(function (data, status, headers, config) {
26-
const parser = new DOMParser()
27-
const doc = parser.parseFromString(data, 'text/html')
28-
const entry = doc.querySelectorAll('#ratingTable .entry')[0]
29-
const getStat = function (selector) {
30-
return entry.querySelectorAll(selector)[0].innerHTML
31-
}
32-
const getUrl = function () {
33-
return 'http://www.ratemyprofessors.com/ShowRatings.jsp?tid=' + (entry.querySelectorAll('.profName a')[0] as HTMLLinkElement).href.split('?tid=')[1]
34-
}
35-
const ratingColor = function (score) {
36-
score = parseFloat(score)
37-
if (score >= 4) {
38-
return '#18BC9C'
39-
} else if (score >= 3) {
40-
return '#F39C12'
41-
} else {
42-
return '#E74C3C'
15+
$http
16+
.post(
17+
'/api/rmp.php',
18+
{ name: scope.professorLookup },
19+
{
20+
headers: {
21+
'Content-Type': 'application/json'
22+
}
4323
}
44-
}
45-
scope.stats = {
46-
name: getStat('.profName a'),
47-
url: getUrl(),
48-
dept: getStat('.profDept'),
49-
numRatings: getStat('.profRatings'),
50-
rating: getStat('.profAvg'),
51-
easiness: getStat('.profEasy')
52-
}
53-
elm.popover({
54-
html: true,
55-
trigger: 'manual',
56-
placement: 'auto left',
57-
title: '<a target="_blank" href="' + scope.stats.url + '">' + scope.stats.name + ' - ' + scope.stats.dept + '</a>',
58-
content: '<div class="row"><div class="col-xs-6 rmp-rating"><h2 style="background-color:' + ratingColor(scope.stats.rating) + '">' + scope.stats.rating + '</h2>Average Rating</div><div class="col-xs-6 rmp-rating"><h2 style="background-color:' + ratingColor(scope.stats.easiness) + '">' + scope.stats.easiness + '</h2>Easiness</div></div><div style="text-align:center">Based on ' + scope.stats.numRatings + ' ratings<br><a target="_blank" href="http://www.ratemyprofessors.com/SelectTeacher.jsp?searchName=' + lastName + '&search_submit1=Search&sid=807">Not the right professor?</a><br><small>&copy; 2013 <a target="_blank" href="http://www.ratemyprofessors.com">RateMyProfessors.com</a></small></div>'
24+
)
25+
.success(function (data, status, headers, config) {
26+
const results = data.data.search.teachers.edges
27+
if (!results[0]) {
28+
elm.popover('toggle')
29+
return
30+
}
31+
const teacher = results[0].node
32+
const ratingColor = function (score) {
33+
score = parseFloat(score)
34+
if (score >= 4) {
35+
return '#18BC9C'
36+
} else if (score >= 3) {
37+
return '#F39C12'
38+
} else {
39+
return '#E74C3C'
40+
}
41+
}
42+
scope.stats = {
43+
name: teacher.firstName + ' ' + teacher.lastName,
44+
url:
45+
'https://www.ratemyprofessors.com/professor/' +
46+
teacher.legacyId,
47+
dept: teacher.department,
48+
numRatings: teacher.numRatings,
49+
rating: teacher.avgRating,
50+
difficulty: teacher.avgDifficulty
51+
}
52+
const yearNumber = new Date().getFullYear()
53+
elm.popover({
54+
html: true,
55+
trigger: 'manual',
56+
placement: 'auto left',
57+
title:
58+
'<a target="_blank" href="' +
59+
scope.stats.url +
60+
'">' +
61+
scope.stats.name +
62+
' - ' +
63+
scope.stats.dept +
64+
'</a>',
65+
content:
66+
'<div class="row"><div class="col-xs-6 rmp-rating"><h2 style="background-color:' +
67+
ratingColor(scope.stats.rating) +
68+
'">' +
69+
scope.stats.rating +
70+
'</h2>Average Rating</div><div class="col-xs-6 rmp-rating"><h2 style="background-color:' +
71+
ratingColor(scope.stats.easiness) +
72+
'">' +
73+
scope.stats.difficulty +
74+
'</h2>Level of Difficulty</div></div><div style="text-align:center">Based on ' +
75+
scope.stats.numRatings +
76+
' ratings<br><a target="_blank" href="https://www.ratemyprofessors.com/search/professors/807?q=' +
77+
scope.professorLookup +
78+
`">Not the right professor?</a><br><small>&copy; ${yearNumber} <a target="_blank" href="http://www.ratemyprofessors.com">RateMyProfessors.com</a></small></div>`
79+
})
80+
elm.popover('show')
5981
})
60-
elm.popover('show')
61-
})
6282
} else {
6383
elm.popover('toggle')
6484
}

assets/src/modules/sm/App/providers/RMPUrlFilter.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ angular.module('sm').filter('RMPUrl', function () {
33
return function (input: string) {
44
if (input && input !== 'TBA') {
55
const EscapedName = encodeURIComponent(input)
6-
return '<a target="_blank" href="http://www.ratemyprofessors.com/search.jsp?queryBy=teacherName&queryoption=HEADER&query=' + EscapedName + '&facetSearch=true&schoolName=rochester+institute+of+technology">' + input + '</a>'
6+
return (
7+
'<a target="_blank" href="https://www.ratemyprofessors.com/search/professors/807?q=' +
8+
EscapedName +
9+
'">' +
10+
input +
11+
'</a>'
12+
)
713
} else {
814
return '<a href="#">' + input + '</a>'
915
}

assets/src/modules/sm/Generate/templates/courseselect.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<h4 class="list-group-item-heading"><span course-detail-popover="section.id">{{$index + 1}}. {{section.courseNum}}</span></h4>
3535
<small>{{section.title}}</small>
3636
<p class="list-group-item-text label-line ">
37-
<span class="label label-default label-professor" ng-bind-html="section.instructor | RMPUrl"></span>
37+
<span class="label label-default label-professor" professor-lookup="section.instructor"></span>
3838
</p>
3939
<div ng-init="parsedTimes = (section.times | parseSectionTimes)">
4040
<div ng-repeat="time in parsedTimes" style="font-size:small">{{time.days}} <span style="white-space:nowrap">{{time.start | formatTime}}-{{time.end | formatTime}}</span></div>

index.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@
103103
<div class="csh"><a target="_blank" rel="noopener" href="https://www.csh.rit.edu/"><img width="90" src="<?=$ASSETROOTADDRESS?>img/csh_logo_square.svg" alt="CSH" /></a></div>
104104
<a target="_blank" rel="noopener" href="https://github.com/ComputerScienceHouse/schedulemaker">Version: <?=$APP_VERSION?></a> | <a ui-sref="help">Help</a> | <a href="/status">Status</a> | <a target="_blank" rel="noopener" href="https://github.com/ComputerScienceHouse/schedulemaker/issues">Report Issues</a>
105105
<div>
106-
Development v3.1: Devin Matte (matted at csh.rit.edu)<br>
106+
Development v3.4: Mary Strodl (mstrodl at csh.rit.edu)<br>
107+
Development v3.1-3.3: Devin Matte (matted at csh.rit.edu)<br>
107108
Development v3: Ben Grawi (bgrawi at csh.rit.edu)<br>
108109
Development v2: Ben Russell (benrr101 at csh.rit.edu)<br>
109110
Idea: John Resig (phytar at csh.rit.edu)<br>

0 commit comments

Comments
 (0)