<?php
/**
* @name Func.php
* @description This file has all the functions necessary for the script!
* @package Punk Autoindex
* @author MobiHacK
* @copyright RockiTech Group
* @version 2.0
* @uses This has been done to minimize script size by storing same codes which are used in more than one place of this script as functions
*/
class PAI_Func
{
public function ext($file)
{
/**
* Name: ext()
* Use: To find extension of file!
* Example usage: ext('files/mobihack.png') will return png
*/
$ret = explode('.', $file);
return end($ret);
}
public function file($file)
{
/**
* Name: file()
* Use: To find if the given string is pointing to an actual file and not is a hackers attempt! If not a file then will return null
* Example Usage: file('files/mobihack.png')
*/
global $config;
$file = str_replace("\0", null, htmlspecialchars($file));
if (!file_exists($file) or !is_file($file) or !in_array($this->ext($file),
explode(',', $config->ext)) or strstr($file, '..') or strstr($file, '://')) {
$file = null;
}
return $file;
}
static function sortnew($file1, $file2)
{
/**
* Name: sortnew()
* Use: To sort files according to filemtime()
* Usage: This is an internal function and using this is highly discouraged!
*/
$time1 = filectime($file1);
$time2 = filectime($file2);
if ($time1 == $time2)
return 0;
elseif ($time1 > $time2)
return - 1;
else
return 1;
}
public function countf($dir, $filedir, $update)
{
/**
* Name: countf()
* Use: To count the number of files in dir recursively!
* Example Usage: countf('files/')
*/
global $config;
echo '<!-- PAIv2 - Punk AutoIndex v2 -->';
$cfile2 = str_replace('/', 'D', $dir);
$cfile = $config->real().'db/count/' . $cfile2 . '.dat';
$redirfile = $filedir .'/'. $dir . '/redirect.pai';
if (file_exists($cfile) and filemtime($cfile) < time() - 3600) {
$j = file_get_contents($cfile);
return intval($j);
} else {
if (file_exists($redirfile)) {
include ($redirfile);
file_put_contents($cfile, $redir['files']);
return $redir['files'];
} else {
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(str_replace('//','/',$filedir .'/'.
$dir)), RecursiveIteratorIterator::SELF_FIRST);
$all = 0;
foreach ($files as $file) {
if ($file->isFile())
$all++;
}
if ($all < 1)
$all = 0;
$count = (int)$all;
file_put_contents($cfile, $count);
return $count;
}
}
}
public function preview($file, $installdir, $type = null)
{
/**
* Name: preview()
* Use: Returns the url to the preview image of a file!
* Example Usage: preview('files/mobihack.png',$config->installdir)
*/
if ($this->ext($file) == 'jar') {
$scr = $installdir . '/preview.php?file=./' . $file;
} elseif ($this->ext($file) == 'iso') {
$scr = $installdir . '/customization/iso.png';
} elseif ($this->ext($file) == 'mp3') {
$scr = $installdir . '/customization/mp3.png';
} elseif ($this->ext($file) == 'avi' or $this->ext($file) == 'flv' or $this->ext
($file) == '3gp' or $this->ext($file) == 'mov' or $this->ext($file) == 'mp4' or
$this->ext($file) == 'mpeg' or $this->ext($file) == 'mpg') {
$scr = $installdir . '/preview.php?file=' . $file;
} elseif ($this->ext($file) == 'pdf') {
$scr = $installdir . '/customization/pdf.png';
} elseif ($this->ext($file) == 'rar') {
$scr = $installdir . '/customization/rar.png';
} elseif ($this->ext($file) == 'rtf') {
$scr = $installdir . '/customization/rtf.png';
} elseif ($this->ext($file) == 'txt') {
$scr = $installdir . '/customization/txt.png';
} elseif ($this->ext($file) == 'wav') {
$scr = $installdir . '/customization/wav.png';
} elseif ($this->ext($file) == 'wma') {
$scr = $installdir . '/customization/wma.png';
} elseif ($this->ext($file) == 'zip') {
$scr = $installdir . '/customization/zip.png';
} elseif ($this->ext($file) == 'jpg' or $this->ext($file) == 'gif' or $this->ext($file) == 'jpeg' or $this->ext
($file) == 'png') {
$scr = $installdir . '/preview.php?loc='.$type.'&file=' . $file;
} elseif ($this->ext($file) == 'nth' or $this->ext($file) == 'thm' or $this->ext
($file) == 'png') {
$scr = $installdir . '/preview.php?file=' . $file;
} elseif ($this->ext($file) == 'apk') {
$scr = $installdir . '/preview.php?file=' . $file;
} else
$scr = $installdir . '/customization/file.png';
return $scr;
}
public function nav_page($countstr, $page, $dir, $sort, $main, $installdir, $ptype = null)
{
/**
* Name: nav_page()
* Use: To create pagination for indexed files!
*/
global $config;
if (!empty($dir)) {
$s = $dir;
} else
$s = 'home';
if ($ptype !== 'web')
$list = 'Page (' . ($page + 1) . '/' . $countstr . ')<br /><br/>';
else
$list = null;
for ($i = 0; $i < 3; $i++) {
if ($i > $countstr - 1)
break;
if ($page != $i)
$list .= '<a class="border_4" href="'. $this->linkgen($s, $main, $sort, $i).'">' . ($i + 1) . '</a> ';
else
$list .= '<span class="pag">' . ($i + 1) . '</span> ';
}
if ($countstr > 3) {
for ($n = $page - 3; $n < $page + 3; $n++) {
if ($n > $countstr - 1)
break;
if ($n < 3)
continue;
if ($page != $n)
$list .= '<a class="border_4" href="'. $this->linkgen($s, $main, $sort, $n).'">' . ($n + 1) . '</a> ';
else
$list .= '<span class="pag">' . ($n + 1) . '</span> ';
}
$next = $n;
}
if (@$n < $countstr and isset($n)) {
for ($n = $countstr - 3; $n < $countstr; $n++) {
if ($n < @$next)
continue;
if ($page != $n)
$list .= '<a class="border_4" href="'. $this->linkgen($s, $main, $sort, $n).'">' . ($n + 1) . '</a> ';
else
$list .= '<span class="pag">' . ($n + 1) . '</span> ';
}
}
return $list . '<br />';
}
public function rating($file)
{
/**
* Name: rating()
* Use: To get rating of file in a scale of 0 to 5 saved in db!
* Example Usage: rating('files/mobihack.png');
*/
global $config;
if ($config->rating === true):
@include $config->rate;
//$rating=$this->rating($file);
if (@in_array($file, @array_keys($rating))) {
$tmp_rating = explode('|', $rating[$file]);
$show_rating = $tmp_rating[0];
$all_rating = $tmp_rating[1];
} else {
$show_rating = '0';
$all_rating = '0';
}
return array($show_rating, $all_rating);
else:
return null;
endif;
}
public function filesize($file,$value=null)
{
/**
* Name: filesize()
* Use: To get formatted filesize in scales of byte and kb!
* Example Usage: filsize('files/mobihack.png');
*/
global $config;
if(!is_null($value)):
$filesize=$value;
else:
$filesize = filesize($file);
endif;
if ($filesize > 1024) {
$filesize = round($filesize / 1024, 2) . ' kb';
} else {
$filesize .= ' Bytes';
}
return $filesize;
}
public function linkgen($url, $type, $sort, $page)
{
/**
* Name: linkgen()
* Use: To generate links for different types of contents!
*/
global $config;
if($sort===null)
$sort=0;
if($page===null)
$page=0;
if ($type == 'filemanager') {
if($url=='home'){
$url=null;
}
$return = $config->installdir . '/panel/filemanager.php?dir=' . htmlspecialchars($url).'&page='.$page;
}
if ($type == 'index') {
if ($config->staticurls === true) {
$return = $config->installdir . '/index/' . htmlspecialchars($url).'/'.$sort.'-'.$page.'.html';
}
else{
if($url=='home'){
$url=null;
}
$return = $config->installdir . '/index.php?dir=' . htmlspecialchars($url).'&page='.$page.'&sort='.$sort;
}
}
if($type=='file'){
if ($config->staticurls === true) {
$return = $config->installdir . '/view/' . htmlspecialchars($url).'.html';
}
else{
$return = $config->installdir . '/file.php?file=' . htmlspecialchars($url);
}
}
if($type=='search'){
if ($config->staticurls === true) {
$return = $config->installdir . '/search/' . htmlspecialchars($url).'/'.$sort.'-'.$page.'.html';
}
else{
$return = $config->installdir . '/search.php?search=' . htmlspecialchars($url).'&page='.$page.'&sort='.$sort;
}
}
return str_replace('x//','x/',$return);
}
public function SeoT($dir = null, $file = null, $index = false)
{
/**
* Name: SeoT()
* Use: To generate Search engine Optimized Titles!
* Example Usage:
*/
if (!is_null($dir)) {
if (isset($dir[0]))
$title = str_replace(array('/', '_'), array(' » ', ' '), $dir);
else {
if ($index === false)
$title = 'Home';
else {
$title = $config->defcattitle;
}
}
return $title;
} elseif (!is_null($file)) {
$title = str_replace('_', ' ', basename($file));
$title = str_replace(array(
'.gif',
'.png',
'.jpeg',
'.jpg',
'.3gp',
'.jar',
'.apk',
'.zip',
'.swf',
'.rar',
'.pdf',
'.mp3',
'.nth',
'.sis',
'.thm'), array(
'High Quality HD Animated Wallpapers Animations',
'High Quality HD Wallpapers',
'High Quality Wallpapers',
'High Quality Wallpapers Animations',
'HQ 3gp Mp4 avi High Quality Videos Movies',
'High Quality Games HD Softwares',
'High Quality Android Games and Softwares Downloads',
'High Quality PC Games Softwares',
'Highly Compressed PC Collections',
'Highly Compressed PC Collections',
'High Quality pdf Tutorials files',
'High Quality Mp3 Songs 320kbps, 192kbps, 128kbps, 64kbps, 48kbps',
'High Quality Nokia Themes 240x320, 128*160',
'High Quality Symbian Games Themes Softwares',
'High Quality HD Sony Ericson Themes'),'.'.$this->ext($file)).' '.basename($file);
$title = str_replace(array('.'.$this->ext($file),'.'),array(null,' '), $title);
return $title;
} else {
return 'Free Unlimited and High Quality Mobile and Pc HD Downloads';
}
}
public function navigation($d,$panel=false)
{
global $config,$func;
if($panel===true){
$type='filemanager';
$extra=' » <a href="main.php">Panel</a> » <a href="filemanager.php">Filemanager</a>';
}
else{
$type='index';
$extra=null;
}
$dir_exp = explode('/', $d);
$nav = '<span itemscope="itemscope" itemtype="http://data-voccabulary.org/Breadcrumb"><a href="' .
$config->installdir . '/"><span itemprop="title">Home</span></a></span>'.$extra;
if (($countj = count(explode('/', $d))) > 1) {
$j = explode('/', $d);
for ($i = 0; $i <= $countj; $i++) {
$u = @$j[count($j) - 2];
if ($u) {
unset($j[count($j) - 1]);
$g[$i] = '<span itemscope="itemscope" itemtype="http://data-voccabulary.org/Breadcrumb"> » <a href="'.$func->linkgen(htmlentities(join('/', $j)), $type, null, null).'" itemprop="url"><span itemprop="title">' . htmlentities($u) .
'</span></a></span>';
}
}
if (isset($g[0])) {
for ($i = count($g) - 1; $i >= 0; $i--) {
$nav .= $g[$i];
}
}
}
if(!is_null($dir_exp[count($dir_exp)-1]) and strlen($dir_exp[count($dir_exp) - 1])>0){
$nav .= ' » ' . htmlentities($dir_exp[count($dir_exp) - 1]);
}
return $nav;
}
}
?>