function load() { if ($this->code) { $res = db_query("SELECT * FROM coursedefns WHERE STRCMP(code,'%s')=0", $this->code); } else { if ($this->id) { $res = db_query("SELECT * FROM coursedefns WHERE id='%d'", $this->id); } else { if ($this->title) { $res = db_query("SELECT * FROM coursedefns WHERE STRCMP(title,'%s')=0", $this->title); } else { Error::generate('debug', 'Not enough information to find course in CourseDefn::load().'); return false; } } } if (!$res) { Error::generate('debug', 'CourseDefn->load: $res is null'); return false; } $ret = db_get_assoc($res); if (!$ret) { Error::generate('debug', 'CourseDefn->load: $ret is null'); return false; } $this->title = $ret['title']; $this->code = $ret['code']; $this->id = $ret['id']; $this->descr = $ret['descr']; $this->cid = $ret['cid']; $this->university = $ret['university']; return $this; }
function wikipedia_search($procd_descr) { profiling_start('wikipedia_search'); $TERMS = wikipedia_process_term($procd_descr); $url = wikipedia_url($TERMS); $data = cached_file_get_contents($url); Error::setPrepend($data); Error::generate('debug', 'WIKIPEDIA'); eval('$arr = ' . $data . ';'); foreach ($arr['query']['pages'] as $k => $v) { $title = urlencode($v['title']); $url = urlencode($v['fullurl']); // https://dgl.cx/2008/10/wikipedia-summary-dns if ($k == -1) { // not found return array(); } break; } // this is probably a topic from a random unintended field like "frequency analysis (cryptoanalysis)" if (strlen($title) < strlen($TERMS) - 5 || strlen($title) > strlen($TERMS) + 5 || strrchr($title, '%28')) { return array(); } $store = array('title' => urldecode(str_replace('+', ' ', $title)), 'link' => urldecode($url), 'source' => 'wikipedia'); profiling_end('wikipedia_search'); return array($store); }
public static function Create($userCfg, $uploadPath) { global $ROOT; $owner = $userCfg['owner'] or $owner = 0; $context = $userCfg['context'] or $context = 1; $id = static::eav_create($userCfg['name'], $owner, $context); if ($id < 1) { // pretty sure this shouldn't happen with current schema Error::generate('notice', 'Filename already taken.', Error::$FLAGS['override']); return false; } // Copy the file from the uploadPath to the given userCfg['path'] if (!isset($userCfg['path']) || !move_uploaded_file($uploadPath, "{$ROOT}/" . $userCfg['path'])) { Error::generate('debug', 'Could not move file'); return false; } foreach ($userCfg as $attrib => $val) { switch (strtoupper($attrib)) { default: $storeval = $val; } static::store_attrib($id, $attrib, $storeval); } return $id; }
public static function ListAll($id = 1, $type = 1) { Error::generate('debug', "Comment::ListAll({$id}, {$type})"); $ret = static::eav_list($id, $type, 'ORDER BY node.creation_timestamp'); if (!$ret) { $ret = array(); } return array_reverse($ret, true); }
public static function ListAllMatching($val) { $ret = db_query("SELECT country.id, country.name\n\t\t\t\t\tFROM\t\tcountries\t\tAS country\n\t\t\t\t\tWHERE\t\tcountry.name REGEXP '.*%s.*'\n\t\t\t\t\tORDER BY\tcountry.name", $val); if (!$ret) { Error::generate('debug', 'Could not query db in Country::ListAll'); return array(); } $ret = db_get_list_assoc($ret); return $ret; }
function __construct($url, $method, $params, $perms = 'any') { $method = strtolower($method); if (!in_array($method, $this->ACCEPTED_METHODS)) { Error::generate('fatal', 'Invalid HTTP method.'); return; } $this->url = $url; $this->method = $method; $this->params = $params; $this->perms = $perms; }
function sigint_handler() { global $sock, $argv, $fp, $mch; curl_multi_close($mch); fclose($fp); socket_close($sock); unlink("/private/tmp/classmate{$argv['1']}"); db_close(); Error::showSeparator(); Error::setBgColour('#B66'); Error::generate('debug', "Finished running classmated {$argv['1']} normally"); Error::setBgColour('#555'); Error::showSeparator(); }
function perform_search($service, $descr, $tags, $crs) { Error::generate('debug', "perform_search({$service},{$descr},{$tags},crs)"); switch (strtolower($service)) { case 'youtube': return youtube_search($descr, $tags, $crs); case 'google': return google_search($descr); case 'itunesu': return itunesu_search($descr); case 'wikipedia': return wikipedia_search($descr); case 'khanacad': return khanacad_search($descr); } }
public static function ListAllMatching($country_id = false, $val) { if ($country_id) { $country = mysql_real_escape_string($country); $country_constraint = "AND country.id = '{$country_id}'"; } else { $country_constraint = ''; } $ret = db_query("SELECT area.id, area.name, country_name\n\t\t\t\t\tFROM\t\tareas\t\t\tAS area,\n\t\t\t\t\t\t\t\tcountries\t\tAS country\n\t\t\t\t\tWHERE\t\tarea.name REGEXP '.*%s.*'\n\t\t\t\t\t\tAND\t\tarea.country = country.id\n\t\t\t\t\t\t\t\t{$country_constraint}\n\t\t\t\t\tORDER BY\tarea.name", $val); if (!$ret) { Error::generate('debug', 'Could not query db in Area::ListAll'); return array(); } $ret = db_get_list_assoc($ret); return $ret; }
protected static function eav_list($id, $type = 1, $orderby = 0) { if ($orderby === 0) { $orderby = "ORDER BY node.creation_timestamp DESC"; } if (!$id || $id == 0) { Error::generate('debug', 'id is 0'); return array(); } $ret = db_query(' SELECT node.* FROM %ss AS node, %ss AS parent WHERE node.parent = parent.id AND parent.id = \'%d\' AND node.type = \'%d\' %s ', static::subGetClass(), static::subGetClass(), $id, $type, $orderby); if (!$ret) { Error::generate('debug', 'Could not query db in hierarchical eav list'); return array(); } //$ret = db_get_list_result($ret); $ret = db_get_list_assoc($ret); return $ret; }
$args['list'] = Comment::ListAll(); redirect('comment', 'list'); } } } else { if ($action == 'list') { $args['list'] = Comment::ListAll(); include 'views/list.view.php'; } else { if ($action == 'show') { $args['info'] = array(array('id', $params['id']), array('subject', Comment::GetSubject($params['id'])), array('created on', Comment::GetTimestamp($params['id'])), array('body', Comment::GetAttrib($params['id'], 'body'))); include 'views/show.view.php'; } else { if (isset($_GET['action']) && $_GET['action'] != "") { // Action with no params $action = $_GET['action']; switch ($action) { case 'create': include 'views/create.view.php'; break; default: Error::generate('suspicious', "Invalid action {$action} in /file/"); redirect(); } } else { include 'views/index.view.php'; } } } } db_close();
protected static function get_id($name) { $res = db_query("SELECT id FROM %ss WHERE name='%s'", static::subGetClass(), $name); if (!$res || !($ret = db_get_result($res))) { Error::generate('debug', 'Could not query database in get_id'); return false; } else { return intval($ret); } }
<?php @(include "{$ROOT}/includes/tags.inc"); @(include "dataacquisition/google.util.php"); @(include "dataacquisition/youtube.util.php"); @(include "dataacquisition/itunesu.util.php"); @(include "dataacquisition/khanacad.util.php"); @(include "{$ROOT}/includes/subjects.inc"); @(include "{$ROOT}/includes/universities.inc"); @(include "{$ROOT}/includes/geography.inc"); db_connect(); Error::showSeparator(); Error::generate('debug', 'Starting preload process'); Error::showSeparator(); foreach (CourseDefn::ListAll() as $crs) { Error::showSeparator(); Error::generate('debug', 'Preloading ' . $crs->university . ': ' . $crs->code); // TODO: preload Error::showSeparator(); } Error::showSeparator(); Error::generate('debug', 'Ending preload process'); Error::showSeparator();
} ?> <div id="sidebar_course_recommendations">People who viewed this course also viewed:</div> <div id="sidebar_recommendation_tagcloud_hidden" class="hidden"> <?php $ctr = 0; Error::setPrepend($other_views); Error::generate('debug', 'Recommendation array'); $reduced_recs = array(); $i = 0; foreach ($other_views as $k => $v) { $reduced_recs[$i++] = $v; } $n_rrecs = $i; Error::setPrepend($reduced_recs); Error::generate('debug', 'Reduced Recommendation array'); $topn = 10; // limit to $topn top results foreach ($other_views as $k => $v) { if (++$ctr == $topn) { break; } // limit to $topn top results $id = intval($k); $subj = ucfirst(Comment::GetSubject($id)); $crs = new CourseDefn($subj); $success = $crs->load(); $hrefid = $crs->id; // cloudinizr javascript is in template_end for ($i = 0; $i < $v / $reduced_recs[min(10, $n_rrecs - 1)]; $i++) { echo strtoupper("{$subj} ");
protected static function eav_list($id) { $ret = db_query(' SELECT node.id, node.subject, node.creation_timestamp FROM comments AS node, comments AS parent WHERE node.lft BETWEEN parent.lft+1 AND parent.rgt-1 AND parent.id = \'%d\' ORDER BY node.lft ', $id); if (!$ret) { Error::generate('debug', 'Could not query db in hierarchical eav list'); return array(); } $ret = db_get_list_result($ret); return $ret; }
public static function ListAllMatching($area_id = false, $country_id = false, $val) { if ($area_id) { $area_constraint = "AND area.id = '{$area_id}'"; } else { $area_constraint = ''; } if ($country_id) { $country_constraint = "AND country.id = '{$country_id}'"; } else { $country_constraint = ''; } $ret = db_query("SELECT uni.id, uni.name,\n\t\t\t\t\t\t\t\tarea.name AS area_name,\n\t\t\t\t\t\t\t\tcountry.name AS country_name\n\t\t\t\t\tFROM\t\tuniversities\tAS uni,\n\t\t\t\t\t\t\t\tareas\t\t\tAS area,\n\t\t\t\t\t\t\t\tcountries\t\tAS country\n\t\t\t\t\tWHERE\t\tuni.name REGEXP '.*%s.*'\n\t\t\t\t\t\tAND\t\tuni.area = area.id\n\t\t\t\t\t\tAND\t\tarea.country = country.id\n\t\t\t\t\t\t\t\t{$area_constraint}\n\t\t\t\t\t\t\t\t{$country_constraint}\n\t\t\t\t\tORDER BY\tuni.name", $val); if (!$ret) { Error::generate('debug', 'Could not query db in University::ListAll'); return array(); } $ret = db_get_list_assoc($ret); return $ret; }
<?php /***** RECENTLY VIEWED COURSES *****/ $recents = Pageview::ListAllForUser(get_viewer_id()); Error::generate('debug', $recents); if ($recents && count($recents) > 0) { ?> <div id="recent_courses"> <?php } else { ?> <div id="recent_courses" class="hidden"> <?php } ?> <div id="sidebar_recent_courses">Recent courses:</div> <?php $ctr = 0; $unique_recents = array(); foreach ($recents as $r) { $found = false; foreach ($unique_recents as $u) { if ($u['comment_id'] == $r['comment_id']) { $found = true; break; } } if (!$found) { $unique_recents[] = $r; if (++$ctr == 5) { break;
$gcourse_code = ""; $gtitle = ""; $gtags = ""; $gdescr = ""; /*foreach($ACTIONS as $key => $val) if($val->wasCalled()) $action = $key;*/ /** Identify course, populate fields */ if ($ACTIONS['search']->wasCalled()) { $params = $ACTIONS['search']->getParams(); $gcourse_code = $gtitle = $params[0]; $crs = new CourseDefn($gtitle); if (!$crs->load()) { Error::generate(Error::$PRIORITY['warn'], 'Course not found.'); } $gdescr = $crs->descr; $tags = split('[,]', $gtags); $procd_descr = process_description($gdescr); foreach ($procd_descr as $descr) { array_push($search_results, array('subject' => $descr, 'google' => google_search($descr), 'youtube' => youtube_search($descr, $tags), 'itunesu' => itunesu_search($descr), 'khanacad' => khanacad_search($descr))); } } /* else if(isset($_POST['save_name'])) { $crs = new Course( urlencode($_POST['save_name']), urlencode($_POST['course_prof']), $_SESSION['google'], $_SESSION['youtube']); $crs->save(); } else if(isset($_GET['course'])) { $crs = new Course($_GET['course'], $_GET['prof'], null, null); $crs->load();
public static function ValidateForgottenPasswordKey($key) { $id = intval(substr($key, 0, strpos($key, '_'))); $stored_key = static::get_attrib($id, static::get_attrib_id('FORGOTN_PASS_RST_KEY')); $stored_timestamp = static::get_attrib($id, static::get_attrib_id('FORGOTN_PASS_TIMESTAMP')); if ($key != $stored_key) { Error::generate('notice', 'The URL you have followed is invalid.'); return false; } if ((time() - $stored_timestamp) / (60 * 60 * 24) > 1) { // 1 day expiration Error::generate('notice', 'The URL you have followed is expired.'); return false; } return $id; }
} } else { if (isset($_GET['action']) && $_GET['action'] != "") { // Action with no params $action = $_GET['action']; switch ($action) { case 'list': $args['filelist'] = File::ListAll(); include "views/{$action}.view.php"; break; case 'show': Error::generate('notice', 'Invalid file ID', Error::$FLAGS['single']); header("Location: {$PAGE_REL_URL}"); break; default: Error::generate('suspicious', "Invalid action {$action} in /file/"); header("Location: {$PAGE_REL_URL}"); } } else { include "views/index.view.php"; } } } db_close(); profiling_end('all'); profiling_print_summary(); Error::showSeparator(); Error::setBgColour('#B66'); Error::generate('debug', "Finished rendering {$_SERVER['REQUEST_URI']} normally"); Error::setBgColour('#555'); Error::showSeparator();
if ($similarities && count($similarities) > 0) { ?> <div id="course_similarities"> <?php } else { ?> <div id="course_similarities" class="hidden"> <?php } ?> <div id="sidebar_course_similarities">Similar courses:</div> <div id="sidebar_similarities_tagcloud_hidden" class="hidden"> <?php $ctr = 0; Error::setPrepend($similarities); Error::generate('debug', 'Similarity array'); $topn = 10; // limit to $topn top results foreach ($similarities as $k => $v) { if (++$ctr == $topn) { break; } // limit to $topn top results $id = intval($k); $subj = ucfirst(Comment::GetSubject($id)); $crs = new CourseDefn($subj); $crs->load(); $hrefid = $crs->id; // cloudinizr javascript is in template_end for ($i = 0; $i < (double) $similarities[$k] * 10; $i++) { echo strtoupper("{$subj} ");