WACSip

Web-based Adult Content Server

A PHP interface for WACS

Contents

Overview

This document is intended for web developers using the php language and wishing to access a WACS server infrastructure from their own php-based web pages. It is important to stress that ALL of the collection management tools are implemented in Perl and the PHP interface is an optional addition to, not an alternative to, the core Wacs system which is perl based. Given the relative youth of the Wacs system, php5 has been selected for the implementation to save future porting efforts as it is expected that php5 or later will be the minimum common standard by the time Wacs reaches 1.0. There is no intention to support older dialects of php at this point.

Some knowledge of how the WACS system works is required in order to make use of this interface module, not least the data structures and basic API calls. All of this documentation is included in the main Wacs distribution and is available at the project page on sourceforge. For more information on WACS itself and this documentation, please visit the project page on sourceforge (http://wacsip.sourceforge.net/). What follows is a very brief introduction to using Wacs from a PHP application/web page; for more details see both the API reference section and the sample programs included with wacs-php.

Getting Started

The first step is to include the required modules (Wacs and DB) into your PHP program which mandates use of the required_once directive and then creating an instance of the wacs module:
require_once "wacs.php";
require_once 'DB.php';

$wacs = new Wacs;
 
The second step is to invoke the Wacs php module so it reads the configuration file and checks the security rules for the current connection:
// read the Wacs configuration files
$wacs->read_conf();

// check the auth(entication and authorisation) of this user
$wacs->check_auth( $_SERVER['REMOTE_ADDR'], 1 );
 
The third step is to initialise the database connection. Since some databases require an environment variable to determine where their configuration files have been stored, this needs to be set first. Wacs provides for this and this code will create that environment variable, if needed, and then proceed to establish the database connection itself. Note that you might wish to have completed the output of the HTML header section and started the body by this point so that should the database connection fail, the error message will be visible:
// database initialisation
$dbienv = $wacs->conf_get_attr("database","dbienvvar");
if( ! empty( $dbienv ))
{
        putenv($dbienv."=".$wacs->conf_get_attr("database","dbienvvalue"));
}
$dbhandle= DB::connect( $wacs->conf_get_attr("database","phpdbconnect") );
if( DB::iserror($dbhandle))
{
        print "Can't connect to database\n";
}
 

Generating Output

At this point the Wacs subsystem is operational and you can go ahead with generating the required output. A very simple example is shown here - take a look at the samples directory for slightly more complex examples. The first step is to execute the query and get back some results:
// do db select
//                                    0      1        2          3
$results = $dbhandle->getAll("select mname, modelno, mbigimage, mimage from ".
                        $wacs->conf_get_attr("tables","models").
                        " where mflag = 'C' order by mname");
 
And finally the actual output code which lists the names of those models flagged as Cuties within the Wacs database.
echo "<ul>\n";
while( isset( $results[$entryno] ))
{
	echo "<li>";
	echo "<a href=\"".$wacs->conf_get_attr("server","cgiurl");
	echo "wacsmpthumbs/".$results[$entryno][1]."\">";
	echo $results[$entryno][0]."</a></li>\n";
	$entryno++;
}
echo "</ul>\n";
and finally you finish off the html output. If you take a look at the program simple.php in the samples directory, it is an embedded php version of the above program segments. The faves.php program is basically a slightly more sophisticated version of the same thing written as a conventional program.

Using The Wacs UI Module

New in 0.7.3 Starting with Wacs-PHP 0.7.3 (also in Wacs 0.7.3 core), there is a new Wacs module called WacsUI which provides routines to ease building user interface applications based upon Wacs. It offers the same functions in both perl and PHP. To use it in PHP, you have to instantiate it in much the same way as you do the Core Wacs PHP interface, namely:
require_once "wacsui.php";

$wacsui = new WacsUI;
 

If you then want to use a given function, in this instance describeher (which produces a readable description of the model), you would use:

print $wacsui->describeher(  array( 'hair'=>$results[$entryno][4],
                                   'length'=>$results[$entryno][5],
                                   'titsize'=>$results[$entryno][6],
                                   'pussy'=>$results[$entryno][7],
                                   'race'=>$results[$entryno][8],
                                   'build'=>$results[$entryno][9],
                                   'height'=>$results[$entryno][10],
                                   'weight'=>$results[$entryno][11],
                                   'occupation'=>$results[$entryno][12]))."\n";
 

The above example is based upon modifying the select example in the previous section to add the following extra fields into the query: mhair, mlength, mtitsize, mpussy, mrace, mbuild, mheight, mweight, moccupation after the mimage (with a comma of course) and before the from clause.

For further information on programming for Wacs, refer to the regular wacs documentation. The APIs provided by the perl and php implementations are function call identical whereever possible.


Back to Wacs-PHP documentation