Hi
I had two problems,i have solved the first one , the href issue was solved with:
echo "<A HREF=html/$filename>Open file:</A><BR>"; in my index.php,
its is slow thats the only issue when opening the file wheni click on the link!
2nd issue:
I now need to add pagination to index.php, using pagination.class.php.
i tried adding : include("pagination.class.php"); to index.php, i get no errors, but no pagination is added,have i set the variables right in pagination.class.php?
basically index.php displays the outputs of pages in one page i want to add pagination so i get:
<<previous 1,2,3,4.. next>>
what am i doing worng?
Code: Select all
/*************************************************************************************************/
index.php:
<?php
include("get_files.php");
include("parse_html.php");
include("pagination.class.php");
$dir = "C:\Inetpub\wwwroot\html";
$file_types = array("htm", "html");
$files = get_files($dir, $file_types);
foreach($files as $file)
{
$html = new Parse_html($file);
$html->remove_tags(array(
'a' => 0,
'img' => 0,
'h' => 1,
'div' => 1,
'span' => 0,
'p' => 1,
'br' => 1,
'ALL' => 0
));
$title = $html->get_html_title();
$lines = $html->get_some_lines(4);
echo "<fieldset>\n\t<legend>\n".$title."\n\t</legend>\n".join($lines, "<br />")."\n</fieldset><br />\n";
$filename=substr($file,strrpos($file,"/")+1);
echo "<A HREF=html/$filename>Open file:</A><BR>";
}
?>
/*************************************************************************************************/
<?php
class pagination{
/*
Script Name: *Digg Style Paginator Class
Script URI: http://www.mis-algoritmos.com/2007/05/27/digg-style-pagination-class/
Description: Class in PHP that allows to use a pagination like a digg or sabrosus style.
Script Version: 0.3.1
Author: Victor De la Rocha
Author URI: http://www.mis-algoritmos.com
*/
/*Default values*/
var $total_pages = 10;
var $limit = 10;
var $target = "";
var $page = 1;
var $adjacents = 2;
var $showCounter = false;
var $className = "pagination";
var $parameterName = "page";
var $urlF = false;//urlFriendly
/*Buttons next and previous*/
var $nextT = "Next";
var $nextI = "»"; //►
var $prevT = "Previous";
var $prevI = "«"; //◄
/*****/
var $calculate = false;
#Total items
function items($value){$this->total_pages = intval($value);}
#how many items to show per page
function limit($value){$this->limit = intval($value);}
#Page to sent the page value
function target($value){$this->target = $value;}
#Current page
function currentPage($value){$this->page = intval($value);}
#How many adjacent pages should be shown on each side of the current page?
function adjacents($value){$this->adjacents = intval($value);}
#show counter?
function showCounter($value=""){$this->showCounter=($value===true)?true:false;}
#to change the class name of the pagination div
function changeClass($value=""){$this->className=$value;}
function nextLabel($value){$this->nextT = $value;}
function nextIcon($value){$this->nextI = $value;}
function prevLabel($value){$this->prevT = $value;}
function prevIcon($value){$this->prevI = $value;}
#to change the class name of the pagination div
function parameterName($value=""){$this->parameterName=$value;}
#to change urlFriendly
function urlFriendly($value="%"){
if(eregi('^ *$',$value)){
$this->urlF=false;
return false;
}
$this->urlF=$value;
}
var $pagination;
function pagination(){}
function show(){
if(!$this->calculate)
if($this->calculate())
echo "<div class=\"$this->className\">$this->pagination</div>";
}
function get_pagenum_link($id){
if(strpos($this->target,'?')===false)
if($this->urlF)
return str_replace($this->urlF,$id,$this->target);
else
return "$this->target?$this->parameterName=$id";
else
return "$this->target&$this->parameterName=$id";
}
function calculate(){
$this->pagination = "";
$this->calculate == true;
$error = false;
if($this->urlF and $this->urlF != '%' and strpos($this->target,$this->urlF)===false){
//Es necesario especificar el comodin para sustituir
echo "Especificaste un wildcard para sustituir, pero no existe en el target<br />";
$error = true;
}elseif($this->urlF and $this->urlF == '%' and strpos($this->target,$this->urlF)===false){
echo "Es necesario especificar en el target el comodin % para sustituir el número de página<br />";
$error = true;
}
if($this->total_pages == null){
echo "It is necessary to specify the <strong>number of pages</strong> (\$class->items(1000))<br />";
$error = true;
}
if($this->limit == null){
echo "It is necessary to specify the <strong>limit of items</strong> to show per page (\$class->limit(10))<br />";
$error = true;
}
if($error)return false;
$n = trim($this->nextT.' '.$this->nextI);
$p = trim($this->prevI.' '.$this->prevT);
/* Setup vars for query. */
if($this->page)
$start = ($this->page - 1) * $this->limit; //first item to display on this page
else
$start = 0; //if no page var is given, set start to 0
/* Setup page vars for display. */
if ($this->page == 0) $this->page = 1; //if no page var is given, default to 1.
$prev = $this->page - 1; //previous page is page - 1
$next = $this->page + 1; //next page is page + 1
$lastpage = round($this->total_pages/$this->limit); //lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage - 1; //last page minus 1
/*
Now we apply our rules and draw the pagination object.
We're actually saving the code to a variable in case we want to draw it more than once.
*/
if($lastpage > 1){
//anterior button
if($this->page > 1)
$this->pagination .= "<a href=\"".$this->get_pagenum_link($prev)."\">$p</a>";
else
$this->pagination .= "<span class=\"disabled\">$p</span>";
//pages
if ($lastpage < 7 + ($this->adjacents * 2)){//not enough pages to bother breaking it up
for ($counter = 1; $counter <= $lastpage; $counter++){
if ($counter == $this->page)
$this->pagination .= "<span class=\"current\">$counter</span>";
else
$this->pagination .= "<a href=\"".$this->get_pagenum_link($counter)."\">$counter</a>";
}
}
elseif($lastpage > 5 + ($this->adjacents * 2)){//enough pages to hide some
//close to beginning; only hide later pages
if($this->page < 1 + ($this->adjacents * 2)){
for ($counter = 1; $counter < 4 + ($this->adjacents * 2); $counter++){
if ($counter == $this->page)
$this->pagination .= "<span class=\"current\">$counter</span>";
else
$this->pagination .= "<a href=\"".$this->get_pagenum_link($counter)."\">$counter</a>";
}
$this->pagination .= "...";
$this->pagination .= "<a href=\"".$this->get_pagenum_link($lpm1)."\">$lpm1</a>";
$this->pagination .= "<a href=\"".$this->get_pagenum_link($lastpage)."\">$lastpage</a>";
}
//in middle; hide some front and some back
elseif($lastpage - ($this->adjacents * 2) > $this->page && $this->page > ($this->adjacents * 2)){
$this->pagination .= "<a href=\"".$this->get_pagenum_link(1)."\">1</a>";
$this->pagination .= "<a href=\"".$this->get_pagenum_link(2)."\">2</a>";
$this->pagination .= "...";
for ($counter = $this->page - $this->adjacents; $counter <= $this->page + $this->adjacents; $counter++)
if ($counter == $this->page)
$this->pagination .= "<span class=\"current\">$counter</span>";
else
$this->pagination .= "<a href=\"".$this->get_pagenum_link($counter)."\">$counter</a>";
$this->pagination .= "...";
$this->pagination .= "<a href=\"".$this->get_pagenum_link($lpm1)."\">$lpm1</a>";
$this->pagination .= "<a href=\"".$this->get_pagenum_link($lastpage)."\">$lastpage</a>";
}
//close to end; only hide early pages
else{
$this->pagination .= "<a href=\"".$this->get_pagenum_link(1)."\">1</a>";
$this->pagination .= "<a href=\"".$this->get_pagenum_link(2)."\">2</a>";
$this->pagination .= "...";
for ($counter = $lastpage - (2 + ($this->adjacents * 2)); $counter <= $lastpage; $counter++)
if ($counter == $this->page)
$this->pagination .= "<span class=\"current\">$counter</span>";
else
$this->pagination .= "<a href=\"".$this->get_pagenum_link($counter)."\">$counter</a>";
}
}
//siguiente button
if ($this->page < $counter - 1)
$this->pagination .= "<a href=\"".$this->get_pagenum_link($next)."\">$n</a>";
else
$this->pagination .= "<span class=\"disabled\">$n</span>";
if($this->showCounter)$this->pagination .= "<div class=\"pagination_data\">($this->total_pages Pages)</div>";
}
return true;
}
}
?>
/*************************************************************************************************/
<?php
//
// parse_html.php
class Parse_html
{
var $content;
var $remove_tags = array(
'ALL' => 0,
'a' => 0,
'img' => 0,
'h' => 0,
'div' => 0,
'span' => 0,
'p' => 0,
'br' => 0
);
function Parse_html($file)
{
$fp = fopen($file, "r");
$this->content = fread($fp, filesize($file));
fclose($fp);
}
function remove_tags($array)
{
foreach($array as $key => $value)
{
$this->remove_tags[$key] = $value;
}
}
function get_html_title()
{
if(preg_match("/<title>([^<]+)<\/title>/i", $this->content, $match))
{
return $match[1];
}
else
{
return "(No title)";
}
}
function get_body_code()
{
$lines = array();
if(preg_match("/<strong([^>]+)?>([^<]+)<\/p>/i", $this->content, $match))
{
$lines = split("\n", $match[2]);
}
else if(preg_match("/<p([^>]+)?>/i", $this->content, $match))
{
if(!empty($match[0]))
{
$body = substr($this->content, strpos($this->content, $match[0])+strlen($match[0]), strlen($this->content));
$lines = split("\n", $body);
}
}
return $lines;
}
function get_some_lines($num_lines)
{
$final_lines = array();
$i = 0;
$j = 0;
$lines = $this->get_body_code();
while($i<$num_lines && $j<count($lines))
{
$line = $lines[$j];
if(intval($this->remove_tags['ALL'])) $line = preg_replace("/<([^>]+)>/", "", $line); // Remove all HTML tags
else
{
if(intval($this->remove_tags['h'])) $line = preg_replace("/<\/?h([0-9]+)>/i", "", $line); // Remove all HTML header tags: h1, h2, h3, h4, h5, h6
if(intval($this->remove_tags['img'])) $line = preg_replace("/<img([^>]+)>/i", "", $line); // Remove all HTML image tags: img
if(intval($this->remove_tags['div'])) $line = preg_replace("/<\/?div([^>]*)>/i", "", $line); // Removes all <div> tags
if(intval($this->remove_tags['span'])) $line = preg_replace("/<\/?span([^>]*)>/i", "", $line); // Removes all <span> tags
if(intval($this->remove_tags['p'])) $line = preg_replace("/<\/?p([^>]*)>/i", "", $line); // Removes all <p> tags
if(intval($this->remove_tags['a'])) $line = preg_replace("/<\/?a([^>]*)>/i", "", $line); // Remove all <a> tags
if(intval($this->remove_tags['br'])) $line = preg_replace("/<\/?br([^>]*)>/i", "", $line); // Remove all <br> tags
}
$line = trim($line);
if(!empty($line))
{
$final_lines[] = $line;
$i++;
}
$j++;
}
return $final_lines;
}
}
?>
/*************************************************************************************************/
<?php
//
// get_files.php
//
function get_files($dir, $file_types)
{
if(substr($dir, -1)!="/") $dir .= "/";
$opendir = opendir($dir);
$files = array();
while($item = readdir($opendir))
{
if(in_array(file_extension($item), $file_types))
{
$files[] = $dir.$item;
}
}
return $files;
}
function file_extension($file)
{
return substr($file, strrpos($file, ".")+1, strlen($file));
include("C:\Inetpub\wwwroot\pagination.class.php");
}
?>
/*************************************************************************************************/