File: example.php

Recommend this page to a friend!
  Classes of Olaf Lederer  >  Import templates  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: An example for handling and simple output
Class: Import templates
Import data about TemplateMonster.com templates
Author: By
Last change: added/updated the new functions from the class
Date: 15 years ago
Size: 4,754 bytes
 

Contents

Class file image Download
<?php
include($_SERVER['DOCUMENT_ROOT']."/classes/import_templates/import_templates.php");

function
microtime_float() {
   list(
$usec, $sec) = explode(" ", microtime());
   return ((float)
$usec + (float)$sec);
}
$time_start = microtime_float();

class
Template_test extends Import_templates {
   
    var
$sel_thumbs = array();
    var
$base_url;
    var
$num_records;
   
    function
Template_test() {
       
$this->connect_db();
       
$this->base_url = "http://www.all4yourwebsite.com/"; // change this to your own
   
}
   
    function
create_zero_data($how_much = 4) {
       
$sql = sprintf("SELECT id, price FROM %s WHERE num_downloads = 0 ORDER BY date_added DESC LIMIT 0, %d", SS_TABLE, $how_much);
       
$res = mysql_query($sql);
        if (!
$res) {
           
$this->messages[] = $this->error_list(13);
        } else {
           
$this->num_records = mysql_num_rows($res);
            while(
$obj = mysql_fetch_object($res)) {
               
$this->sel_thumbs['thumb'][] = $obj->id."-m.jpg";
               
$this->sel_thumbs['price'][] = $obj->price;
            }
           
mysql_free_result($res);
        }
    }
}

$test_import = new Template_test;

$req = (isset($_GET['functie'])) ? $_GET['functie'] : header("Location: /admin/index.php");
switch (
$req) {
    case
"screenshots":
   
// handle_screenshots($from = 1, $empty_first = "no", $full_path = "false")
   
$test_import->handle_screenshots(1, "yes");
    break;
    case
"categories":
   
$test_import->handle_categorie_list("en", "yes");
    break;
    case
"cat_links":
   
$test_import->handle_categories(1, "yes");
    break;
    case
"authors":
   
$test_import->handle_authors("yes");
    break;
    case
"keywords":
   
$test_import->handle_keywords(1, "yes");
    break;
    case
"zero_thumbs":
   
$test_import->get_zero_thumbs();
    break;
    case
"log_date":
   
$test_import->write_log(1);
    break;
    case
"update_data":
   
$test_import->update_keyword_categorie_data();
    break;
    case
"del_sold":
   
$test_import->remove_sold_template_data();
    break;
    case
"remove_bad";
   
$test_import->remove_bad_categories();
    break;
    default:
// create some example output
   
$test_import->create_zero_data();
}


$time_end = microtime_float();
$time = $time_end - $time_start;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example page: Import templateMonster data</title>
<style type="text/css">
<!--
#thumb {
    width: 160px;
    height:220px;
    border: 1px solid #333333;
    padding-top: 5px;
    float: left;
    margin-right:10px;
    text-align:center;
}
#container {
    width: 780px;
}
-->
</style>
</head>

<body>

<h2>Import /update template data</h2>
<ul>
  <li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?functie=screenshots">update screenshot data</a></li>
  <li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?functie=zero_thumbs">update zero thumbs</a></li>
  <li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?functie=categories"><b>update categories (list)</b></a></li>
  <li><a href="<?php echo $_SERVER['PHP_SELF']; ?>=keywords">update keywords</a></li>
  <li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?functie=cat_links">update categorie (links)</a></li>
  <li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?functie=authors"><b>update authors names</b></a></li>
  <li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?functie=update_data"><b>update keywords and categories</b></a></li>
  <li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?functie=remove_bad">remove bad categories</a></li>
  <li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?functie=del_sold"><b>remove sold templates</b></a></li>
  <li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?functie=log_date">insert log data</a></li>
  <li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?functie="><b>example output</b></a></li>
</ul>
<i>(regular styled (not bolded) links should be processed daily</i>
<p><a href="<?php echo $test_import->base_url; ?>"><b>A real world (output) example... </b></a></p>
<?php
if (isset($test_import->num_records)) {
    echo
"<h3>Example output:</h3>\n";
    echo
"<div id=\"container\">\n";
    for (
$i = 0; $i < $test_import->num_records; $i++) {
       
$image = THUMB_FOLDER.$test_import->sel_thumbs['thumb'][$i];
       
$img_size = getimagesize($_SERVER['DOCUMENT_ROOT'].$image);
       
$tpl_price = $test_import->sel_thumbs['price'][$i];
        echo
"
        <div id=\"thumb\">
          <p>Price: "
.$tpl_price."$</p>
          <img src=\""
.$image."\" ".$img_size[3]." border=\"0\">
        </div>\n"
;
    }
    echo
"</div>\n";
    echo
"<br clear=\"all\">\n";
}
// end output example
echo $test_import->show_messages("<br>\n");

echo
"<br><br>The script's execution time was ".number_format($time, 4, ".", "")." seconds...<br>";
?>
</body>
</html>


For more information send a message to info at phpclasses dot org.