Author Topic: Creating Dynamic PHP Web Page With TGPX MySQL Data  (Read 10080 times)

0 Members and 1 Guest are viewing this topic.

Offline a4evermedia

  • Global Moderator
  • Full Member
  • ***
  • Posts: 122
  • Karma: +25/-0
  • Gender: Male
    • View Profile
    • A4Ever Media
Creating Dynamic PHP Web Page With TGPX MySQL Data
« on: June 21, 2012, 02:12:11 AM »
You can build a dynamic PHP page served by your TGPX database.  The beauty of this is that the page is not built beforehand, the galleries are pulled from the database when the link is accessed.  New galleries and, in fact, new category pages are added simply by adding data to the DB.  The page is cached on the server so that a page is never 'created' more that once every set amount of time (currently 6 hours).  After that time only then will the DB be accessed to create a new page which will then be served to all those who click the link during the current time period.

PHP CODE FOR SELECTING / PRESENTING GALLERIES. Three PHP files.

Code for niche.php
Purpose:  Main file for displaying the galleries page.  Used with the t variable to indicate which category to display.  Defaults to Hardcore category if t is missing or invalid.  Also handles page cacheing and provides the html for genrating the webpage itself.  Uses PHP code snips to specify the category being view as well as in the <head> section for search engine optimization.
Code: [Select]
 $page = $_GET['t'];

  // set $page variable defaults to Hardcore category if GET variable is invalid or missing
   if((!isset($_GET['t'])) || (empty($_GET['t'])))
     {
       $page = 'Hardcore';
     }

   // $category is used on web pages
   $category = $page;

   $page = preg_replace('/\s+/','',ucwords($page));

   // Define path and name of cached file 

   $cachefile = '_cache/' . $page . md5('$page');

   // How long to keep cache file? 

   $cachetime = 6 * 3600;     

   // Is cache file still fresh? If so, serve it.     

   if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) { 

   include($cachefile); 

   exit; 

   } 

   // if no file or too old, render and capture HTML page. 

   ob_start();

   $categ = ucwords($category);

   include('includes/xconnect.php');
 ?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>

<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<TITLE>Kick Ass <?PHP echo $categ; ?> Porn  -  Beautiful Sexy Hardcore Amateur Fucking Pics Movie!</TITLE>
<META NAME="description" CONTENT="Sexy <?PHP echo $categ; ?> Amateur Girls Fucking Hardcore Pics Movie">
<META NAME="keywords" CONTENT="<?PHP echo $categ; ?>,black,white,ebony,pics,movie,sexy,hardcore,public">

<link rel="stylesheet" type="text/css" href="style.css" />

<base target="_blank" />

</head>
<body>
<div id="main-content" style="max-width:1200px;">

<div id="centered-content" class="max-width" style="margin-top:0; text-align:center;">

<div id='wrapper'>
<?PHP
$i=0;
while ($i < min($num, 30 )) {

$id_num=mysql_result($result,$i,"gallery_id");
$id_url=mysql_result($result,$i,"gallery_url");
$id_desc=mysql_result($result,$i,"description");
$id_prev=mysql_result($result,$i,"preview_url");

print "<li><a href='click.php?c=$categ&id=$id_num&u=$id_url'  target='_blank'><img src='$id_prev' height='180px' width='180px' /></a>
</li>";

$i++;
}
?>
</div>

</div>
<!-- END centered-content -->
</div>
<!-- END main-content -->

</body>
</html>

<?php 

     // Save the cached content to a file 

     $fp = fopen($cachefile, 'w'); 

     fwrite($fp, ob_get_contents()); 

     fclose($fp);     

   

     // Send browser output 

     ob_end_flush(); 

 ?>


Code for xconnect.php ( called by niche.php )
Purpose: Accesses the TGPX database.  Checks for a valid category hash tag which is required to retrieve the desired galleries.
Code: [Select]
<?php
// this file name - xconnect.php

// prepare DB for access
$username=;
$password=;
$database=;

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die('Error encountered with connection: '.mysql_error());

// find hash tag for desired category
$query = "SELECT *,`tx_categories`.`tag` FROM `tx_categories` WHERE `name` = '$categ' LIMIT 0, 30 ";

$result1=mysql_query($query);

// check if valid hash tag found - erase bad cachefile name if not
$num=mysql_numrows($result1);

if ($num == 0)
  {
   include('/home/public_html/includes/erasebadcache.php');
   $cachefile = '/home/public_html/_cache/Hardcore_cached_page';

   if (file_exists($cachefile)) { 

     include($cachefile); 

     exit;  }

   $categ = 'Hardcore';
   $taghash = '1c800aa97116d9afd83204d65d50199a';
  }
else
  {
   $taghash=mysql_result($result1,0,"tag");
  }

// select galleries for chosen category
$query = "SELECT *,`tx_galleries`.`gallery_id` AS `gallery_id` FROM `tx_galleries` LEFT JOIN `tx_gallery_previews` ON `tx_gallery_previews`.`gallery_id`=`tx_galleries`.`gallery_id` LEFT JOIN `tx_gallery_used_page` ON `tx_gallery_used_page`.`gallery_id`=`tx_galleries`.`gallery_id` WHERE `tx_gallery_used_page`.`gallery_id` IS NULL AND `has_preview`=1 AND MATCH(`categories`) AGAINST ('$taghash' IN BOOLEAN MODE) AND `status` IN ('used','holding','approved') ORDER BY RAND() LIMIT 60";

$result=mysql_query($query);

$num=mysql_numrows($result);

if ($num == 0)
  {
   echo "No results in this category";
  }

mysql_close();
?>


Code for erasebadcache.php ( called by xconnect.php )
Purpose:  When a category request is made through niche.php, a cachefile is created.  If this cachefile is determined to be invalid ( not a current or correct category ),  it is erased so you dont end up with a bunch of junk files in your _cache/ directory.
Code: [Select]
<?php
 // If bad cachefile exists, delete it.

   $cachefile = 'home/public_html/' . $cachefile;

   if (file_exists($cachefile)) {

   unlink($cachefile);

   } 
?>



Sample pages can be accessed here: 
http://www.kickass-porn.com/niche.php?t=Hardcore or http://www.kickass-porn.com/niche/ebony

http://www.sexworldtube.com/niche.php?t=Babes or http://www.sexworldtube.com/niche/big boobs


a4evermedia
kickass-porn.com
« Last Edit: July 07, 2013, 06:15:51 AM by a4evermedia »

Offline Chad

  • Administrator
  • Full Member
  • ***
  • Posts: 215
  • Karma: +27/-0
    • View Profile
Creating Dynamic PHP Web Page With TGPX MySQL Data
« Reply #1 on: June 23, 2012, 03:53:16 PM »
I could see where that would be handy.  No more needing to have to setup cron or remembering to log in to build all with new.

I'll try to get some time set aside to take a peek at it and see if I can figure out the correct code.

Thanks,
Chad

Offline a4evermedia

  • Global Moderator
  • Full Member
  • ***
  • Posts: 122
  • Karma: +25/-0
  • Gender: Male
    • View Profile
    • A4Ever Media
Creating Dynamic PHP Web Page With TGPX MySQL Data
« Reply #2 on: June 24, 2012, 03:09:06 AM »
Good news!  Got it working very well.  To reduce server load, pages are cached until needed.  They are not rebuilt unless the cached web page is over a predetermined age setting - NEAT!

Unlimited categories generated from one page template!
Categories are added or deleted automatically as the TGPX db is changed.

Found a great article on cacheing web pages.  This is a MUST READ!

http://www.internoetics.com/2011/05/04/cache-your-website-with-php-in-1-minute/
« Last Edit: July 11, 2013, 11:28:46 AM by a4evermedia »

Offline Freddy Marx

  • Newbie
  • *
  • Posts: 8
  • Karma: +1/-0
    • View Profile
Re: Creating Dynamic PHP Web Page With TGPX MySQL Data
« Reply #3 on: June 12, 2013, 10:31:26 AM »
This idea sounds very interesting. Can you elaborate a little more as to how to implement the code? The help would be greatly appreciated.

[EDIT] Just seen that the quoted code has corrupted some of the code ie. "&quot;".
I'm also guessing the erasebadcache.php is your caching solution and as I'm not that proficient in PHP can't deconstruct the code enough to get the rest working.

Fred
« Last Edit: June 12, 2013, 11:49:39 AM by Freddy Marx »

Offline a4evermedia

  • Global Moderator
  • Full Member
  • ***
  • Posts: 122
  • Karma: +25/-0
  • Gender: Male
    • View Profile
    • A4Ever Media
Re: Creating Dynamic PHP Web Page With TGPX MySQL Data
« Reply #4 on: June 23, 2013, 10:56:55 PM »
Hi Freddy,

Thanks for the heads-up, I think I corrected the corrupted code.

erasebadcache.php is used to delete cache files that are sometimes created if people use bad category names for the 't' variable in niche.php,  ie niche.php?t=BadCat

How can I help you, Freddy?
« Last Edit: July 11, 2013, 11:29:17 AM by a4evermedia »

Offline Freddy Marx

  • Newbie
  • *
  • Posts: 8
  • Karma: +1/-0
    • View Profile
Re: Creating Dynamic PHP Web Page With TGPX MySQL Data
« Reply #5 on: June 25, 2013, 09:16:29 AM »
Hi a4evermedia,

Thanks for replying. I suppose what I want is just to be able to create category pages in the way you've described so that I don't have to have a static set of pages that I have to paginate manually because I still haven't worked out how to have the script use pagination for my main page so that galleries that have passed the one or two day limit are pushed onto new pages automatically. the way I have accomplished this at the moment is using the global dupes option and building in a certain order but I have to create new pages manually and paginate accordingly. I know, what a mess right!?

Thanks in advance for any help.

Freddy

Offline a4evermedia

  • Global Moderator
  • Full Member
  • ***
  • Posts: 122
  • Karma: +25/-0
  • Gender: Male
    • View Profile
    • A4Ever Media
Re: Creating Dynamic PHP Web Page With TGPX MySQL Data
« Reply #6 on: June 25, 2013, 12:10:15 PM »
Hey Freddy,

I'm afraid I'm a bit rusty on using pagination in TGPX.  I havent used it at all yet.

Currently I am only building one page per category.  Each page has 165 galleries seperated into 3 sections of 55 unique galleries.  I use a MySQL query to pull 165 galleries from the TGPX database at one time and then I use some PHP code to distribute the galls into the 3 sections.  My goal was to prevent having to process a hundred different pages in TGPX with each rebuild.  I dont have to do that now.  I just add galleries and categories and the pages are automatically added/created and cached as necessary by the PHP code.

I havent tried to tackle having unique galls on seperate pages in one category yet, but in theory it should be possible.  The key lies in using the 3 sections of PHP code on 3 unique PHP pages, along with using the correct time-factored SELECT command in MySQL.  I'll have to think on this on for a bit :)

In the meantime, you might experiment with the code that I have shared to get a good idea of how this works in principle.

Yours,
Paul
« Last Edit: June 25, 2013, 12:52:44 PM by a4evermedia »

Offline Freddy Marx

  • Newbie
  • *
  • Posts: 8
  • Karma: +1/-0
    • View Profile
Re: Creating Dynamic PHP Web Page With TGPX MySQL Data
« Reply #7 on: June 27, 2013, 06:08:42 AM »
Hi Paul,

Thanks for the help. I hadn't even realized that the code you had put up was to be put in 3 separate files. Let me play with it for a bit and see if I can figure it out. I definitely agree that your way of doing it is much less resource intensive and I'd rather have mine like that.

Best,

Freddy

Offline a4evermedia

  • Global Moderator
  • Full Member
  • ***
  • Posts: 122
  • Karma: +25/-0
  • Gender: Male
    • View Profile
    • A4Ever Media
Re: Creating Dynamic PHP Web Page With TGPX MySQL Data
« Reply #8 on: June 27, 2013, 07:58:36 AM »
Hey Freddy

I've updated/corrected the code for the three PHP files necessary for using this technique.  I've also tried to explain the purpose of each PHP script.  Hope this helps.

Paul

Offline Freddy Marx

  • Newbie
  • *
  • Posts: 8
  • Karma: +1/-0
    • View Profile
Re: Creating Dynamic PHP Web Page With TGPX MySQL Data
« Reply #9 on: July 01, 2013, 03:39:44 AM »
Hi Paul,

I'm very grateful for all the help, the method works very well.

Best,

Fred

Offline a4evermedia

  • Global Moderator
  • Full Member
  • ***
  • Posts: 122
  • Karma: +25/-0
  • Gender: Male
    • View Profile
    • A4Ever Media
Re: Creating Dynamic PHP Web Page With TGPX MySQL Data
« Reply #10 on: July 02, 2013, 06:55:36 PM »
Thanks Freddy

If you come up with any improvements or optimizations to the code please post it!

Yours,
Paul

pls check your pm

Offline MRB

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Creating Dynamic PHP Web Page With TGPX MySQL Data
« Reply #11 on: July 25, 2013, 10:47:55 AM »
Has anyone been able to successfully use pageination with this? I am trying to get it to automatically split into pages based on total galleries available and a per page amount set by me similar to the search results page (say 800 results on search term and limits to 50 per page and automatically pageinates withouth creating multiple static pages).

I am trying to get it to do this for index (taking all galleries into account) and for each category (taking galleries in that category into account).

Offline a4evermedia

  • Global Moderator
  • Full Member
  • ***
  • Posts: 122
  • Karma: +25/-0
  • Gender: Male
    • View Profile
    • A4Ever Media
Re: Creating Dynamic PHP Web Page With TGPX MySQL Data
« Reply #12 on: July 29, 2013, 01:24:58 PM »
I haven't been able to do this yet.  I plan on making it my next project when I have the time.

Unofficial JMB Support Forums

Re: Creating Dynamic PHP Web Page With TGPX MySQL Data
« Reply #12 on: July 29, 2013, 01:24:58 PM »


Tags:
 

Related Topics

  Subject / Started by Replies Last post
12 Replies
18005 Views
Last post November 21, 2013, 10:48:28 AM
by a4evermedia
7 Replies
4245 Views
Last post June 04, 2013, 09:09:12 AM
by scubakevin
0 Replies
1547 Views
Last post August 12, 2013, 01:01:00 PM
by ppmedia
0 Replies
866 Views
Last post August 12, 2013, 01:55:18 PM
by Chad
3 Replies
1423 Views
Last post February 27, 2014, 02:37:42 PM
by dragosani