Delete
Delete pagination
This commit is contained in:
326
-child/fetch_pages.php
Executable file
326
-child/fetch_pages.php
Executable file
@@ -0,0 +1,326 @@
|
||||
<?php
|
||||
/* Title : Ajax Pagination with jQuery & PHP
|
||||
Example URL : http://www.sanwebe.com/2013/03/ajax-pagination-with-jquery-php */
|
||||
|
||||
function preprint($s, $return=false) {
|
||||
$x = "<pre>";
|
||||
$x .= print_r($s, 1);
|
||||
$x .= "</pre>";
|
||||
if ($return) return $x;
|
||||
else print $x;
|
||||
}
|
||||
|
||||
function displayRetina ($filename,$album) {
|
||||
// 6_2012.jpg
|
||||
// 4_2014_180_thumb.jpg 4_2014_360_thumb.jpg
|
||||
$path = "../../../../zenphoto/cache/" . $album . "/";
|
||||
$file = explode(".", $filename);
|
||||
|
||||
//$a = $path . $filename;
|
||||
//echo $a. "<br>";
|
||||
|
||||
$file_sd = $path . $file[0] . "_180_thumb.jpg";
|
||||
$file_hd = $path . $file[0] . "_360_thumb.jpg";
|
||||
/*
|
||||
$file_sd = $path . $file[0] . "_180_watermark.jpg";
|
||||
$file_hd = $path . $file[0] . "_360_watermark.jpg";
|
||||
*/
|
||||
//
|
||||
$th_sd = false;
|
||||
$th_hd = false;
|
||||
|
||||
if (file_exists($file_sd)) {
|
||||
$th_sd = true;
|
||||
$size_sd = getimagesize($file_sd, $info);
|
||||
$thumb['sd'] = array(
|
||||
'url' => "../" . $file_sd,
|
||||
'width' => $size_sd[0],
|
||||
'height' => $size_sd[1]
|
||||
);
|
||||
}
|
||||
if (file_exists($file_hd)) {
|
||||
$th_hd = true;
|
||||
$size_hd = getimagesize($file_hd, $info);
|
||||
$thumb['hd'] = array(
|
||||
'url' => "../" . $file_hd,
|
||||
'width' => $size_hd[0],
|
||||
'height' => $size_hd[1]
|
||||
);
|
||||
}
|
||||
//preprint($thumb);
|
||||
|
||||
if (($th_sd == true) && ($th_hd == true)) {
|
||||
$standard = $thumb['sd']['url'] . ', ' . $thumb['hd']['url'] . ' 2x';
|
||||
}
|
||||
elseif ($th_sd == true) {
|
||||
$standard = $thumb['sd']['url'];
|
||||
}
|
||||
elseif ($th_hd == true) {
|
||||
$standard = $thumb['hd']['url'] . ' 2x';
|
||||
}
|
||||
|
||||
$display = '<div class="album">';
|
||||
//$display .= '<div class="holder">';
|
||||
//$display .= '<a href="../../zenphoto/albums/'.$album.'/'.$filename.'" title="'.date_archive($filename).'" class="swipebox">';
|
||||
$display .= '<div class="thumb">';
|
||||
$display .= '<a class="wraptocenter" href="../../zenphoto/albums/'.$album.'/'.$filename.'" title="'.date_archive($filename).'" data-featherlight="image">';
|
||||
//$display .= '<a class="wraptocenter gallery" href="../../zenphoto/albums/'.$album.'/'.$filename.'" title="'.date_archive($filename).'">';
|
||||
//$display .= '<a href="../../zenphoto/albums/'.$album.'/'.$filename.'" title="'.date_archive($filename).'" class="wraptocenter">';
|
||||
|
||||
$display .= '<picture data-picture data-alt="">';
|
||||
$display .= '<!--[if IE 9]><video style="display: none;"><![endif]-->';
|
||||
$display .= '<source class="image_standard" srcset="' . $standard . '">';
|
||||
|
||||
$display .= '<!--[if IE 9]></video><![endif]-->';
|
||||
$display .= '<img srcset="' . $thumb['sd']['url'] . '" width="' . $thumb['sd']['width'] . '" height="' . $thumb['sd']['height'] . '"alt="">';
|
||||
$display .= '</picture>';
|
||||
|
||||
$display .= '</a>';
|
||||
$display .= '</div>';
|
||||
$display .= '<div class="albumdesc">';
|
||||
$display .= '<a href="../../zenphoto/index.php?album='.$album.'&image='.$filename.'" title= "'.date_archive($filename).'" class="">';
|
||||
$display .= '<span class="exif">'.date_archive($filename).'</span>';
|
||||
$display .= '</a></div>';
|
||||
$display .= '</div>';
|
||||
|
||||
return $display;
|
||||
}
|
||||
|
||||
function date_archive ($chaine) {
|
||||
$pieces = explode(".", $chaine);
|
||||
$b = explode("_", $pieces[0]);
|
||||
$mois = $b[0];
|
||||
$an = $b[1];
|
||||
$chaine = mois2($mois) . ' '. $an;
|
||||
return $chaine;
|
||||
}
|
||||
|
||||
function mois2 ($mois) {
|
||||
switch ($mois)
|
||||
{
|
||||
case 00:
|
||||
$mois = "00";
|
||||
break;
|
||||
case 1:
|
||||
$mois = gettext('January');
|
||||
break;
|
||||
case 2:
|
||||
$mois = gettext('February');
|
||||
break;
|
||||
case 3:
|
||||
$mois = gettext('March');
|
||||
break;
|
||||
case 4:
|
||||
$mois = gettext('April');
|
||||
break;
|
||||
case 5:
|
||||
$mois = gettext('May');
|
||||
break;
|
||||
case 6:
|
||||
$mois = gettext('June');
|
||||
break;
|
||||
case 7:
|
||||
$mois = gettext('July');
|
||||
break;
|
||||
case 8:
|
||||
$mois = gettext('August');
|
||||
break;
|
||||
case 9:
|
||||
$mois = gettext('September');
|
||||
break;
|
||||
case 10:
|
||||
$mois = gettext('October');
|
||||
break;
|
||||
case 11:
|
||||
$mois = gettext('November');
|
||||
break;
|
||||
case 12:
|
||||
$mois = gettext('December');
|
||||
break;
|
||||
}
|
||||
return $mois;
|
||||
}
|
||||
|
||||
//continue only if $_POST is set and it is a Ajax request
|
||||
if(isset($_POST) && isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
|
||||
|
||||
//include("config.inc.php"); //include config file
|
||||
//require_once($_SERVER['DOCUMENT_ROOT'].'/Connections/cnx.php');
|
||||
$db_host = 'localhost';
|
||||
$db_username = 'root';
|
||||
$db_password = 'sncfp1p2';
|
||||
$db_name = 'zenphoto';
|
||||
$zptable = 'zenphoto';
|
||||
|
||||
$album = 'photos-du-mois'; //Photos du mois
|
||||
$item_per_page = 12; //item to display per page
|
||||
|
||||
$table = array();
|
||||
if ($_SERVER['HTTP_HOST'] == "macbook-pro.local") {
|
||||
$table['images'] = ".images";
|
||||
$table['albums'] = ".albums";
|
||||
}
|
||||
if ($_SERVER['HTTP_HOST'] == "clicclac.info") {
|
||||
$table['images'] = "zenphoto_images";
|
||||
$table['albums'] = "zenphoto_albums";
|
||||
}
|
||||
|
||||
$mysqli = new mysqli($db_host, $db_username, $db_password, $db_name);
|
||||
//Output any connection error
|
||||
if ($mysqli->connect_error) {
|
||||
die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
|
||||
}
|
||||
|
||||
|
||||
// Récupérer l'ID de l'album 'photos-du-mois' ($id_album)
|
||||
$i = 0;
|
||||
$conn = new mysqli($db_host, $db_username, $db_password, $zptable);
|
||||
if ($conn->connect_error) {
|
||||
trigger_error('Database connection failed: ' . $conn->connect_error, E_USER_ERROR);
|
||||
exit();
|
||||
}
|
||||
$conn->set_charset("utf8");
|
||||
|
||||
$excquery = "SELECT `id` FROM `" . $table['albums'] . "` WHERE `folder` = '" . $album . "'";
|
||||
|
||||
if ($result = $conn->query($excquery)) {
|
||||
$result->data_seek(0);
|
||||
$row = $result->fetch_row();
|
||||
$id_album = $row[0];
|
||||
$result->close();
|
||||
}
|
||||
|
||||
$conn->close();
|
||||
|
||||
|
||||
//Get page number from Ajax POST
|
||||
if(isset($_POST["page"])){
|
||||
$page_number = filter_var($_POST["page"], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH); //filter number
|
||||
if(!is_numeric($page_number)){die('Invalid page number!');} //incase of invalid page number
|
||||
}else{
|
||||
$page_number = 1; //if there's no page number, set it to 1
|
||||
}
|
||||
|
||||
//get total number of records from database for pagination
|
||||
//$results = $mysqli->query("SELECT COUNT(*) FROM paginate");
|
||||
$results = $mysqli->query("SELECT COUNT(*) FROM `" . $table['images'] . "` WHERE `albumid` = $id_album ");
|
||||
$get_total_rows = $results->fetch_row(); //hold total records in variable
|
||||
|
||||
//break records into pages
|
||||
$total_pages = ceil($get_total_rows[0]/$item_per_page);
|
||||
|
||||
//get starting position to fetch the records
|
||||
$page_position = (($page_number-1) * $item_per_page);
|
||||
|
||||
|
||||
//Limit our results within a specified range.
|
||||
$results = $mysqli->prepare("SELECT `filename` FROM `" . $table['images'] . "` WHERE `albumid` = ? ORDER BY `date` DESC LIMIT $page_position, $item_per_page");
|
||||
$results->bind_param('i', $id_album);
|
||||
$results->execute(); //Execute prepared Query
|
||||
$results->bind_result($filename); //bind variables to prepared statement
|
||||
|
||||
$path = "../../zenphoto/cache/" . $album . "/";
|
||||
|
||||
//echo '<section data-featherlight-gallery data-featherlight-filter="a">';
|
||||
|
||||
|
||||
while($results->fetch()){ //fetch values
|
||||
|
||||
/* ----
|
||||
$file = explode(".", $filename);
|
||||
|
||||
$file_sd = $path . $file[0] . "_180_thumb.jpg";
|
||||
$size_sd = getimagesize($file_sd, $info);
|
||||
$thumb['sd'] = array(
|
||||
'url' => "../../" . $file_sd,
|
||||
'width' => $size_sd[0],
|
||||
'height' => $size_sd[1]
|
||||
);
|
||||
|
||||
$file_hd = $path . $file[0] . "_360_thumb.jpg";
|
||||
$size_hd = getimagesize($file_hd, $info);
|
||||
$thumb['hd'] = array(
|
||||
'url' => "../../" . $file_hd,
|
||||
'width' => $size_hd[0],
|
||||
'height' => $size_hd[1]
|
||||
);*/
|
||||
/* ---- */
|
||||
|
||||
/*
|
||||
//echo $filename;
|
||||
$display .= '<a href="../../zenphoto/albums/'.$album.'/'.$filename.'" title="'.date_archive($filename).'" class="swipebox">';
|
||||
$display .= '<img srcset="' . $thumb['hd']['url'] . '" width="' . $thumb['hd']['width'] . '" height="' . $thumb['hd']['height'] . '"alt="">';
|
||||
$display .= '</a>';
|
||||
echo $display;
|
||||
$display = "";
|
||||
*/
|
||||
//echo '<a href="../../zenphoto/albums/">';
|
||||
//echo '<img src="test.jpg"></a>';
|
||||
//echo '<a href="aa.php"><img src="test.jpg"></a>';
|
||||
|
||||
echo displayRetina($filename,$album);
|
||||
|
||||
}
|
||||
|
||||
//echo '</section>';
|
||||
|
||||
echo '<p style="clear: both; "></p>';
|
||||
echo '<div align="center">';
|
||||
/* We call the pagination function here to generate Pagination link for us.
|
||||
As you can see I have passed several parameters to the function. */
|
||||
echo paginate_function($item_per_page, $page_number, $get_total_rows[0], $total_pages);
|
||||
echo '</div>';
|
||||
echo '<p style="clear: both; "></p>';
|
||||
|
||||
exit;
|
||||
}
|
||||
################ pagination function #########################################
|
||||
function paginate_function($item_per_page, $current_page, $total_records, $total_pages)
|
||||
{
|
||||
$pagination = '';
|
||||
if($total_pages > 0 && $total_pages != 1 && $current_page <= $total_pages){ //verify total pages and current page number
|
||||
$pagination .= '<ul class="pagination">';
|
||||
|
||||
$right_links = $current_page + 3;
|
||||
$previous = $current_page - 3; //previous link
|
||||
$next = $current_page + 1; //next link
|
||||
$first_link = true; //boolean var to decide our first link
|
||||
|
||||
if($current_page > 1){
|
||||
$previous_link = ($previous==0)? 1: $previous;
|
||||
$pagination .= '<li class="first"><a href="#" data-page="1" title="First">«</a></li>'; //first link
|
||||
$pagination .= '<li><a href="#" data-page="'.$previous_link.'" title="Previous"><</a></li>'; //previous link
|
||||
for($i = ($current_page-2); $i < $current_page; $i++){ //Create left-hand side links
|
||||
if($i > 0){
|
||||
$pagination .= '<li><a href="#" data-page="'.$i.'" title="Page'.$i.'">'.$i.'</a></li>';
|
||||
}
|
||||
}
|
||||
$first_link = false; //set first link to false
|
||||
}
|
||||
|
||||
if($first_link){ //if current active page is first link
|
||||
$pagination .= '<li class="first active">'.$current_page.'</li>';
|
||||
}elseif($current_page == $total_pages){ //if it's the last active link
|
||||
$pagination .= '<li class="last active">'.$current_page.'</li>';
|
||||
}else{ //regular current link
|
||||
$pagination .= '<li class="active">'.$current_page.'</li>';
|
||||
}
|
||||
|
||||
for($i = $current_page+1; $i < $right_links ; $i++){ //create right-hand side links
|
||||
if($i<=$total_pages){
|
||||
$pagination .= '<li><a href="#" data-page="'.$i.'" title="Page '.$i.'">'.$i.'</a></li>';
|
||||
}
|
||||
}
|
||||
if($current_page < $total_pages){
|
||||
$next_link = ($i > $total_pages) ? $total_pages : $i;
|
||||
$pagination .= '<li><a href="#" data-page="'.$next_link.'" title="Next">></a></li>'; //next link
|
||||
$pagination .= '<li class="last"><a href="#" data-page="'.$total_pages.'" title="Last">»</a></li>'; //last link
|
||||
}
|
||||
|
||||
$pagination .= '</ul>';
|
||||
}
|
||||
return $pagination; //return pagination links
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user