コード例 #1
0
ファイル: common.php プロジェクト: Cyberspace-Networks/TGPX
function &ScanGallery(&$gallery, &$category, &$whitelisted, $all_images = FALSE)
{
    require_once "{$GLOBALS['BASE_DIR']}/includes/http.class.php";
    require_once "{$GLOBALS['BASE_DIR']}/includes/htmlparser.class.php";
    // Setup default values
    $results = array('thumbnails' => 0, 'links' => 0, 'format' => FMT_PICTURES, 'has_recip' => FALSE, 'has_2257' => FALSE, 'thumbs' => array(), 'server_match' => TRUE);
    // Download the gallery page
    $http = new Http();
    $http_result = $http->Get($gallery['gallery_url'], $whitelisted['allow_redirect']);
    // Record the request results
    $results = array_merge($results, $http->request_info);
    $results['page_hash'] = md5($http->body);
    $results['gallery_ip'] = GetIpFromUrl($http->end_url);
    $results['bytes'] = intval($results['size_download']);
    $results['html'] = $http->body;
    $results['headers'] = trim($http->raw_response_headers);
    $results['status'] = $http->response_headers['status'];
    $results['success'] = $http_result;
    $results['errstr'] = $http->errstr;
    $results['end_url'] = $http->end_url;
    if (!$http_result) {
        $http_result = null;
        return $results;
    }
    // Check if reciprocal link and 2257 code are present
    $results['has_recip'] = CheckReciprocal($http->body);
    $results['has_2257'] = Check2257($http->body);
    // Extract information from the gallery HTML
    $parser = new PageParser($http->end_url, $category['pics_extensions'], $category['movies_extensions']);
    $parser->parse($http->body);
    $results['links'] = $parser->num_links;
    if ($parser->num_content_links > 0) {
        if ($parser->num_picture_links > $parser->num_movie_links) {
            $results['format'] = FMT_PICTURES;
            $results['thumbnails'] = $parser->num_picture_links;
            $results['preview'] = $parser->thumbs['pictures'][array_rand($parser->thumbs['pictures'])]['full'];
            $results['thumbs'] = array_values($parser->thumbs['pictures']);
        } else {
            $results['format'] = FMT_MOVIES;
            $results['thumbnails'] = $parser->num_movie_links;
            $results['preview'] = $parser->thumbs['movies'][array_rand($parser->thumbs['movies'])]['full'];
            $results['thumbs'] = array_values($parser->thumbs['movies']);
        }
    } else {
        if ($all_images) {
            $results['thumbnails'] = count($parser->images);
            $results['preview'] = $parser->images[array_rand($parser->images)]['full'];
            $results['thumbs'] = array_values($parser->images);
        }
    }
    // Check that gallery content is hosted on same server as the gallery itself
    $parsed_gallery_url = parse_url($results['end_url']);
    $parsed_gallery_url['host'] = preg_quote(preg_replace('~^www\\.~', '', $parsed_gallery_url['host']));
    foreach ($results['thumbs'] as $thumb) {
        $parsed_content_url = parse_url($thumb['content']);
        if (!preg_match("~{$parsed_gallery_url['host']}~", $parsed_content_url['host'])) {
            $results['server_match'] = FALSE;
            break;
        }
    }
    $parser->Cleanup();
    unset($parser);
    $http->Cleanup();
    unset($http);
    return $results;
}