Просмотр файла index.php

Размер файла: 1.88Kb
<?php
require( realpath( dirname( __FILE__ ) ) . '/header.php' );
require( realpath( dirname( __FILE__ ) ) . '/phpquery/phpQuery.php' );
require( realpath( dirname( __FILE__ ) ) . '/config.php' );

$domain = 'ero.pulpy.ru';
$path = '/photo-session/';
$cacheDir = realpath( dirname( __FILE__ ) ) . '/cache';

if( !isset( $_GET['r'] ) OR strpos( $_GET['r'], $path ) !== 0 ) {
	$request = $path;
} else {
	$request = $_GET['r'];
}
$hashFile = $cacheDir . '/' . md5( $request );

if ( is_file( $hashFile ) AND filemtime( $hashFile ) + $cacheTime > time() ) {
	include $hashFile;
} else {
	$url = 'http://' . $domain . $request;
	$ch = curl_init( $url );
	curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
	curl_setopt( $ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; Q312461; Crazy Browser 1.0.5; .NET CLR 1.0.3705)' );
	$page = curl_exec( $ch );
	$doc = phpQuery::newDocument( $page );
	$doc['.content .promo']->remove();
	$doc['.content .category li:last']->remove();


	foreach ( $doc['a'] AS $a ) {
		if ( strpos( pq($a)->attr('href'), '.jpg' ) !== false ) {
			if ( strpos( pq($a)->attr('href'), $path ) === 0  ) {
				pq($a)->attr('href', 'http://' . $domain . pq($a)->attr('href') );
			}
		} elseif ( strpos( pq($a)->attr('href'), '?' ) === 0 ) {
			if ( strpos( $request, '?' ) !== false ) {
				$request = substr( $request, 0, strpos( $request, '?' ) );
			}
			pq($a)->attr('href', 'index.php?r=' . urlencode( $request . pq($a)->attr('href') ) );
		} else {
			pq($a)->attr('href', 'index.php?r=' . urlencode( pq($a)->attr('href') ) );
		}
	}

	$page = $doc['.content']->htmlOuter();
	$page = str_replace( 'Главная', $indexLinkName, $page );

	if ( is_writeable( $cacheDir ) ) {
		if ( is_file( $hashFile ) ) {
			unlink( $hashFile );
		}
		file_put_contents( $hashFile, $page );
		chmod( $hashFile, 0777 );
	}
	echo $page;
}

require( realpath( dirname( __FILE__ ) ) . '/footer.php' );