<?php
define('_IN_JOHNCMS', 1);
$server = $_SERVER['DOCUMENT_ROOT'];
require($server . '/system/bootstrap.php');
/** @var Psr\Container\ContainerInterface $container */
$container = App::getContainer();

/** @var PDO $db */
$db = $container->get(PDO::class);

/** @var Johncms\Api\UserInterface $systemUser */
$systemUser = $container->get(Johncms\Api\UserInterface::class);

/** @var Johncms\Api\ToolsInterface $tools */
$tools = $container->get(Johncms\Api\ToolsInterface::class);

/** @var Johncms\Api\EnvironmentInterface $env */
$env = $container->get(Johncms\Api\EnvironmentInterface::class);

/** @var Johncms\Api\BbcodeInterface $bbcode */
$bbcode = $container->get(Johncms\Api\BbcodeInterface::class);

/** @var Johncms\Api\ConfigInterface $config */
$config = $container->get(Johncms\Api\ConfigInterface::class);



$headmod = 'pornhub';
require($server . '/system/head.php');
if ($systemUser->premium !== '1') {

echo '<div class="mainblok">';
echo '<div class="phdr">PornHub Videos</div>';
echo '<div class="rmenu">Please upgrade your account to premium bellow. to show this content</div>';
echo '</div>';
require($server . '/system/end.php');
 
} else {


$Pag = isset($_GET['pag']) ? trim($_GET['pag']) : '';
if(!empty($Pag)){
$vpage = $Pag;
} else{
$vpage = 1;
}
$q = isset($_GET['q']) ? trim($_GET['q']) : '';
 
if(!empty($q)){

echo '<a href="http://wap4dollar.com/ad/serve.php?id=79qvgpader"><img src="http://wap4dollar.com/ad/imgs/wap4dollar_banner_3.jpg" border="0" /></a>' .
  '<script type="text/javascript" src="http://wap4dollar.com/ad/codex/?id=79qvgpader"></script>';

echo '<div class="mainblok">';
echo '<div class="phdr">PornHub Videos  |  <a href="categories.php">Category</a></div>';
echo '<div class="topmenu"><form action="search.php" method="get"><input type="text" name="q" value="" /><input type="submit" value="Search" /></form></div>';
echo '<div class="gmenu">'; 


function hapus($txt){
$txt = preg_replace("/[^a-zA-Z0-9\.-]/", " ", trim($txt));
return $txt;
}

function hapus1($txt){
$txt = preg_replace("/[^a-zA-Z0-9_\-]/", "+", trim($txt));
return $txt;
}

$query = $q;

$AddHeaders = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>"User-Agent: Opera/9.80 (J2ME/MIDP; Opera Mini/9.80 (J2ME/23.377; U; en) Presto/2.5.25 Version/10.54"
  )
);

$context = stream_context_create($AddHeaders);
$GrabURL = file_get_contents('http://www.pornhub.com/video/search?search='.hapus1($query).'&page='.$vpage.'',false,$context);
$GrabURL = strstr($GrabURL,'<div class="thumb">');
$GrabURL = str_replace('href="/view_video.php?viewkey=','href="view.php?id=',$GrabURL);
$GrabURL = str_replace('Length:','Duration:',$GrabURL);
$GrabURL = preg_replace('#<div class="premiumAd(.*?)</div>(.*?)#s','',$GrabURL);
$GrabURL = preg_replace('#<div class="adCont(.*?)</html>(.*?)#s','',$GrabURL);

echo '<b>Results for '.hapus($query).'</b>';


echo '<div class="rmenu">';
echo $GrabURL;
echo '</div>';
//echo '</div>';
//echo '<div class="phdr">'; 


echo '<div class="topmenu">'; 

if($vpage > 1){
$navpage1 = $vpage-1;
$navpage2 = $vpage+1;
echo '<a href="search.php?q='.hapus1($query).'&amp;pag='.$navpage1.'" title="prev">&laquo; Previous</a> | <a href="search.php?q='.hapus1($query).'&amp;pag='.$navpage2.'" title="Next">Next &raquo;</a>';
}
else{
$navpage = $vpage+1;
echo '<span style="color: silver;">&laquo; Previous</span> | <a href="search.php?q='.hapus1($query).'&amp;pag='.$navpage.'" title="Next">Next &raquo;</a>';
}
echo '</div>';
//echo '</div>';
}
else{
echo '<div class="mainblok">';
echo '<div class="phdr">PornHub Videos  |  <a href="categories.php">Category</a></div>';
echo '<div class="rmenu">Results for null</div>';
echo '<div class="rmenu">You must enter at least one character and then press the button: "<b>Search</b>".</div>';
echo '<div class="phdr"><a href="index.php"> Back </a></div>';
echo '</div>';
}


echo '<a href="http://wap4dollar.com/ad/serve.php?id=79qvgpader"><img src="http://wap4dollar.com/ad/imgs/wap4dollar_banner_4.jpg" border="0" /></a>' .
  '<script type="text/javascript" src="http://wap4dollar.com/ad/codex/?id=79qvgpader"></script>';
 
require($server . '/system/end.php');

}

?>