Example #1
0
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);
}
Example #2
0
function google_search($procd_descr)
{
    profiling_start('google_search');
    $TERMS = urlencode($procd_descr . " Lecture Notes");
    $USERIP = $_SERVER['REMOTE_ADDR'];
    $url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q={$TERMS}&rsz=small";
    $data = cached_file_get_contents($url);
    $arr = json_decode($data, true);
    $results = $arr['responseData']['results'];
    $store = array();
    foreach ($results as $elem) {
        $link = $elem['url'];
        $title = $elem['titleNoFormatting'];
        array_push($store, array('title' => $title, 'link' => $link, 'source' => 'google'));
    }
    profiling_end('google_search');
    return $store;
}
Example #3
0
function khanacad_search($procd_descr, $tags = array())
{
    global $CONFIG;
    global $ROOT;
    profiling_start('khanacad_search');
    $TERMS = urlencode($procd_descr);
    $URL = "{$ROOT}/scraping/khan.xml";
    $data = file_get_contents($URL);
    $parser = xml_parser_create();
    $status = xml_parse_into_struct($parser, $data, $xml);
    if ($status == 0) {
        echo xml_error_string(xml_get_error_code($parser));
    }
    xml_parser_free($parser);
    $terms = preg_split("/\\s+|\\+/", $TERMS, null, PREG_SPLIT_NO_EMPTY);
    $ret = search_with_tags($terms, $tags, 'khanacad_query', $xml);
    profiling_end('khanacad_search');
    return $ret;
}
Example #4
0
function itunesu_search($procd_descr)
{
    $TERMS = urlencode($procd_descr);
    $USERIP = $_SERVER['REMOTE_ADDR'];
    $NRESULTS = 4;
    profiling_start('itunesu_search');
    ini_set('user_agent', 'iTunes/8.1');
    $url = "http://ax.search.itunes.apple.com/WebObjects/MZSearch.woa/wa/advancedSearch?descriptionTerm={$TERMS}&media=iTunesU";
    $data = cached_file_get_contents($url);
    $parser = xml_parser_create();
    xml_parse_into_struct($parser, $data, $xml);
    xml_parser_free($parser);
    $store = array();
    foreach ($xml as $key => $elem) {
        if ($elem['tag'] == 'GOTOURL' && $elem['level'] == 21 && $elem['type'] == 'open' && count($store) < $NRESULTS) {
            array_push($store, array('source' => 'itunesu', 'url' => $elem['attributes']['URL'], 'title' => $elem['attributes']['DRAGGINGNAME'], 'art' => $xml[$key + 2]['attributes']['URL']));
        }
    }
    profiling_end('itunesu_search');
    return $store;
}
Example #5
0
        }
    } 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();
Example #6
0
function youtube_query($TERMS, $srch, $crs)
{
    global $CONFIG;
    profiling_start('youtube_query');
    $TAGS = $srch;
    $rtags = get_full_tags($crs);
    $str = urlencode($TERMS);
    //."+".implode("+", $srch);
    $url = "http://gdata.youtube.com/feeds/api/videos?q={$str}&orderby=relevance&start-index=1&max-results=2&v=2&format=5";
    $data = cached_file_get_contents($url);
    $parser = xml_parser_create();
    xml_parse_into_struct($parser, $data, $xml);
    xml_parser_free($parser);
    $store = array();
    foreach ($xml as $elem) {
        switch ($elem['tag']) {
            case 'MEDIA:THUMBNAIL':
                $content['thumbnail_url'] = $elem['attributes']['URL'];
                $content['thumbnail_width'] = $elem['attributes']['WIDTH'];
                $content['thumbnail_height'] = $elem['attributes']['HEIGHT'];
                break;
            case 'MEDIA:PLAYER':
                $content['link'] = $elem['attributes']['URL'];
                break;
            case 'CONTENT':
                if ($elem['attributes']['TYPE'] == 'application/x-shockwave-flash') {
                    $val = $elem['attributes']['SRC'];
                } else {
                    continue 2;
                }
                $content['src'] = $val;
                break;
            case 'MEDIA:CATEGORY':
                if ($val != 'Howto' && $val != 'Education' && $val != 'News' && $val != 'Tech') {
                    continue 2;
                } else {
                    if ($val == 'Education') {
                        $content['rating'] += 5;
                    }
                }
                $val = $elem['value'];
                $content[strtolower($elem['tag'])] = $val;
                break;
            case 'CATEGORY':
                if ($elem['attributes']['SCHEME'] != 'http://gdata.youtube.com/schemas/2007/categories.cat') {
                    continue 2;
                } else {
                    $val = $elem['attributes']['TERM'];
                    if ($val != 'Howto' && $val != 'Education' && $val != 'News' && $val != 'Tech') {
                        continue 2;
                    } else {
                        if ($val == 'Education') {
                            $content['rating'] += 5;
                        }
                    }
                    $content[strtolower($elem['tag'])] = $val;
                }
                break;
            case 'MEDIA:KEYWORDS':
                $val = $elem['value'];
                if (!$val) {
                    continue 2;
                }
                if ($rtags) {
                    $matches = count_matches(explode(', ', $val), explode(',', $rtags));
                } else {
                    $matches = false;
                }
                if ($matches > 0) {
                    $content[strtolower($elem['tag'])] = $val;
                    $content['rating'] += 5;
                } else {
                    $content['rating'] -= 5;
                    continue 2;
                }
                break;
            case 'MEDIA:DESCRIPTION':
                // YT:RATING : attributes : NUMDISLIKES, NUMLIKES
                $val = $elem['value'];
                if ($rtags) {
                    $matches = count_matches(explode(' ', $val), explode(',', $rtags));
                } else {
                    $matches = false;
                }
                if ($matches && $matches > 0) {
                    $content[strtolower($elem['tag'])] = $val;
                    $content['rating'] += 2;
                } else {
                    $content['rating'] -= 2;
                    continue 2;
                }
                break;
            case 'TITLE':
                $val = $elem['value'];
                $content[strtolower($elem['tag'])] = $val;
                break;
            case 'ENTRY':
                if ($elem['type'] == 'open') {
                    $content = array('src' => false, 'title' => false, 'media:keywords' => false, 'media:description' => false, 'category' => false, 'rating' => 10, 'thumbnail_url' => false, 'thumbnail_width' => false, 'thumbnail_height' => false, 'link' => false, 'source' => 'youtube');
                } else {
                    if ($elem['type'] == 'close') {
                        if ($content['rating'] > 8) {
                            if ($CONFIG['debug']) {
                                $content['title'] .= ' - rating=' . $content['rating'];
                            }
                            array_push($store, $content);
                        }
                    }
                }
            default:
        }
    }
    profiling_end('youtube_query');
    return $store;
}
Example #7
0
 public static function generate($priority, $error, $flags = 'none')
 {
     global $CONFIG;
     global $ROOT;
     profiling_start('error::generate');
     $class = '';
     if (!self::$logging_enabled) {
         goto end;
     }
     //$class .= 'hidden';
     if (is_string($priority)) {
         $priority = self::$PRIORITY[$priority];
     }
     if ($CONFIG['debug'] === false && $priority == self::$PRIORITY['debug']) {
         goto end;
     }
     if (session_id() != "" && isset($_SESSION['errors'])) {
         self::$errors = $_SESSION['errors'];
     }
     if ($flags & self::$FLAGS['single'] && count(self::$errors) > 0) {
         goto end;
     }
     if ($flags & self::$FLAGS['override'] && count(self::$errors) > 0) {
         self::$errors = array();
     }
     // format string
     $pname = 'notice';
     foreach (self::$PRIORITY as $k => $v) {
         if ($v == $priority) {
             $pname = $k;
             break;
         }
     }
     $bgcolour = self::$bgcolour;
     $fmt = "<div class=\"{$pname} {$class}\" style=\"background-color: {$bgcolour}\">%s</div>\r\n";
     // log it
     $fp = fopen($ROOT . '/admin/debug.html', 'a');
     static::_output($fp, $fmt, $priority, $error);
     fclose($fp);
     // behaviour on error
     switch ($priority) {
         case self::$PRIORITY['fatal']:
             die($error);
             break;
         case self::$PRIORITY['warn']:
         case self::$PRIORITY['notice']:
         case self::$PRIORITY['success']:
             array_push(self::$errors, array('priority' => $priority, 'msg' => $error));
             break;
         case self::$PRIORITY['prod_debug']:
         case self::$PRIORITY['suspicious']:
             $fp = fopen($ROOT . '/admin/debug_special.html', 'a');
             static::_output($fp, $fmt, $priority, $error);
             fclose($fp);
             break;
         case self::$PRIORITY['debug']:
             break;
     }
     if (session_id() != "") {
         $_SESSION['errors'] = self::$errors;
     }
     end:
     profiling_end('error::generate');
 }