#!/usr/local/bin/php -q
<?
//This script is set to run as a CGI ver of PHP. Remove the 1st line
//if you want to run it from the web.
//
//The script connects to the templatemonster Webapi, downloads all
//of the data and builds a local database with the data. This comes
//handy if you want to build your own affiliate site and wand to use
//your own database.
//
//You should run this script on a daily basis to make sure that your
//data is accurate.
//Your DB connection
include"dbcon.inc";
//Change the name to your DB
mysql_select_db("Templates");
//Create Categories
function GetURL($domain,$uri) {
function GetCategories() {
mysql_query("DROP TABLE IF EXISTS Categories") or die(mysql_error());
mysql_query(" CREATE TABLE Categories (
CategoryID int(11) NOT NULL auto_increment,
TCategoryID int(11) NOT NULL default '0',
CategoryName varchar(50) NOT NULL default '',
PRIMARY KEY (CategoryID),
KEY TCategoryID (TCategoryID),
KEY CategoryName (CategoryName)
) TYPE=MyISAM
") or die(mysql_error());
$CategoryArray=GetURL("www.templatemonster.com","/webapi/categories.php?delim=;");
For($i = 0 ; $i < count($CategoryArray) ; $i++) {
$String=explode(";",$CategoryArray[$i]);
$String[0]=trim($String[0]);
$String[1]=trim($String[1]);
If($String[0] != "") {
mysql_query("INSERT INTO Categories
(TCategoryID,CategoryName)
VALUES
($String[0],'$String[1]')
") or die(mysql_error());
}
}
//Optional, to remove the Adult category, remove the remark from the next line.
//mysql_query("DELETE FROM Categories WHERE trim(CategoryName) = 'Adult'") or die(mysql_error());
}
//Create Templates
function GetTemplates() {
mysql_query("DROP TABLE IF EXISTS Templates") or die(mysql_error());
mysql_query("CREATE TABLE Templates (
TemplateID int(11) NOT NULL auto_increment,
TTemplateID int(11) NOT NULL default '0',
price int(11) NOT NULL default '0',
exclusive_price int(11) NOT NULL default '0',
date_of_adding date NOT NULL default '0000-00-00',
number_of_downloads int(11) NOT NULL default '0',
is_hosting tinyint(4) NOT NULL default '0',
is_flash tinyint(4) NOT NULL default '0',
is_adult tinyint(4) NOT NULL default '0',
is_unique_logo tinyint(4) NOT NULL default '0',
is_non_unique_logo tinyint(4) NOT NULL default '0',
is_unique_corporate tinyint(4) NOT NULL default '0',
is_non_unique_corporate tinyint(4) NOT NULL default '0',
TAuthorID int(11) NOT NULL default '0',
is_full_site_template tinyint(4) NOT NULL default '0',
number_of_pages int(11) NOT NULL default '0',
Screenshots varchar(255) NOT NULL default '',
PRIMARY KEY (TemplateID),
KEY TTemplateID (TTemplateID),
KEY TAuthorID (TAuthorID)
) TYPE=MyISAM
") or die(mysql_error());
$TemplateArray=GetURL("www.templatemonster.com","/webapi/templates_screenshots4.php?delim=;&filter=0");
For($i = 0 ; $i < count($TemplateArray) ; $i++) {
$String=explode(";",$TemplateArray[$i]);
$String[0]=trim($String[0]);
$String[1]=trim($String[1]);
$String[2]=trim($String[2]);
$String[3]=trim($String[3]);
$String[4]=trim($String[4]);
$String[5]=trim($String[5]);
$String[6]=trim($String[6]);
$String[7]=trim($String[7]);
$String[8]=trim($String[8]);
$String[9]=trim($String[9]);
$String[10]=trim($String[10]);
$String[11]=trim($String[11]);
$String[12]=trim($String[12]);
$String[13]=trim($String[13]);
$String[14]=trim($String[14]);
$String[15]=trim($String[15]);
Olaf Lederer wrote :1298
Hi Yahav,
funny... currently I`m busy with a class wit the same kind of functionallity. What I try do is to create the script much more compact without this long string split code. Take a look on my site later.