PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Arturs Sosins   Episode tracker   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example usage
Class: Episode tracker
Get TV show episodes information from IMDB
Author: By
Last change: credits changed
Date: 12 years ago
Size: 6,030 bytes
 

Contents

Class file image Download
<?php
/*************************************************************
 * This script is developed by Arturs Sosins aka ar2rsawseen, http://webcodingeasy.com
 * Fee free to distribute and modify code, but keep reference to its creator
 *
 * This class uses IMDB API from http://imdbapi.poromenos.org/ which is
 * database of TV series and Episodes updated every day from IMDB interface files
 * This class can search for TV series by exact names or similar names or
 * combined method, return list of episodes and restructure it by seasons
 * and output restructured array with simple hide/show ability using javascript
 * It can also check if episode exists in specified TV series, so you can
 * use it as dictionary to rename your existing episodes etc.
 *
 * For more information, examples and online documentation visit:
 * http://webcodingeasy.com/PHP-classes/Episode-tracker-class
**************************************************************/

//This is an example usage of Episode tracker class
//There are two type of arrays used in this class
//First type is an episode list in random order, just for dictionary purpose
//Other is restructured array where episodes are grouped in right order by seasons
//There is also an example of using print_episodes method with hide/show ablity


//declaring class instance
include("./ep_track.class.php");
$ep = new ep_track();

//for user end view
echo "<a name='contents'><h3>Contents</h3></a>";
echo
"<p><a href='#get_similar_names'>Using get_similar_names method</a></p>";
echo
"<p><a href='#get_exact_names'>Using get_exact_names method</a></p>";
echo
"<p><a href='#transform'>Outputting restructured array</a></p>";
echo
"<p><a href='#get_episodes'>Using get_episodes method and otuputting episodes using print_episodes method with hide/show ability</a></p>";
echo
"<p><a href='#check_episode'>Checking if episode exists in specified TV series</a></p>";

/*---------------------------------------------------------------------*/
//Getting similar TV series by specified name,
//if only one found returns episode list
//if multiple, returns TV series names

//$arr = $ep->get_similar_names("Big theory"); //only one found(The Big bang theory)
$arr = $ep->get_similar_names("Lie"); //multiple TV series found
echo "<a name='get_similar_names'><h3>Using get_similar_names method with word \"Lie\"</h3></a>";
echo
"<p><a href='#contents'>Back to contents</a></p>";
//checking for errors
$errors = $ep->get_errors();
if(!empty(
$errors))
{
    foreach(
$errors as $error)
    {
        echo
"<p>".$error."</p>";
    }
}
else
// no error output array
{
    echo
"<pre>";
   
print_r($arr);
    echo
"</pre>";
   
//if multiple TV series provided next step to do is us get_exact_names for each TV series name
}

/*---------------------------------------------------------------------*/
//Getting TV series by exact name,
//if only one found returns episode list
//if multiple, returns TV series names

//Searching for exact names
$arr = $ep->get_exact_names("How I met your mother"); //only one found
//$arr = $ep->get_exact_names("Iron man"); //multiple TV series found

echo "<a name='get_exact_names'><h3>Using get_exact_names method with name \"How I met your mother\"</h3></a>";
echo
"<p><a href='#contents'>Back to contents</a></p>";

//checking for errors
$errors = $ep->get_errors();
if(!empty(
$errors))
{
    foreach(
$errors as $error)
    {
        echo
"<p>".$error."</p>";
    }
}
else
// no error output array
{
    echo
"<pre>";
   
print_r($arr);
    echo
"</pre>";
}
/*---------------------------------------------------------------------*/
//Restructuring and ordering array with list of episodes
echo "<a name='transform'><h3>Outputting restructured array</h3></a>";
echo
"<p><a href='#contents'>Back to contents</a></p>";
//getting episode list
$arr = $ep->get_exact_names("How I met your mother");

//restructuring array
$arr = $ep->transform($arr);

//checking for errors
$errors = $ep->get_errors();
if(!empty(
$errors))
{
    foreach(
$errors as $error)
    {
        echo
"<p>".$error."</p>";
    }
}
else
// no error
{
   
//printing array structure
   
echo "<pre>";
   
print_r($arr);
    echo
"</pre>";
}

/*---------------------------------------------------------------------*/
//Using get_episodes method which automatically checks for exact matches and then for similar matches if no exact founds
//and returns restructured array (like after transform method) of episodes of TV series that ar most similar to specified one

echo "<a name='get_episodes'><h3>Using get_episodes method and otuputting episodes using print_episodes method with hide/show ability with word \"Iron\"</h3></a>";
echo
"<p><a href='#contents'>Back to contents</a></p>";
//Getting episodes
$arr = $ep->get_episodes("Iron");

//checking for errors
$errors = $ep->get_errors();
if(!empty(
$errors))
{
    foreach(
$errors as $error)
    {
        echo
"<p>".$error."</p>";
    }
}
else
// no error
{
   
//printing array structure
   
echo "<pre>";
   
//print_r($arr);
   
echo "</pre>";
   
//or using print_episodes method with hide/show ability for seasons using javascript
    //pass false as second parameter if don't want to use hide/show
   
$ep->print_episodes($arr, true);
}

/*---------------------------------------------------------------------*/
//Checking if episode with wildcard %name% exists in TV series
//if exists returns array with all episodes mathicng wildcard with exact episode name, season and episode numbers

echo "<a name='check_episode'><h3>Checking if episode exists in specified TV series</h3></a>";
echo
"<p><a href='#contents'>Back to contents</a></p>";

//Checking if there is an episode with specified substring
$arr = $ep->check_episode("or false", "How I met your mother");

//checking for errors
$errors = $ep->get_errors();
if(!empty(
$errors))
{
    foreach(
$errors as $error)
    {
        echo
"<p>".$error."</p>";
    }
}
else
// no error
{
    echo
"<pre>";
   
print_r($arr);
    echo
"</pre>";
}

?>