Login
Username: Password:
Remember me

[Sign Up] / [Recover Password]

Theme / Language

Popular
New Torrents
new name
Size: 18.40 MB
Most active
new name
S: 74 L: 3
New Posters
User Posts

Go to Profile

ratio — 2020-11-13 18:27:31 in v3 Support
It's on v2.08
function get_ratio_color($ratio)
{
   if ($ratio < 0.1) {
       return "#ff0000";
   }

   if ($ratio < 0.2) {
       return "#ee0000";
   }

   if ($ratio < 0.3) {
       return "#dd0000";
   }

   if ($ratio < 0.4) {
       return "#cc0000";
   }

   if ($ratio < 0.5) {
       return "#bb0000";
   }

   if ($ratio < 0.6) {
       return "#aa0000";
   }

   if ($ratio < 0.7) {
       return "#990000";
   }

   if ($ratio < 0.8) {
       return "#880000";
   }

   if ($ratio < 0.9) {
       return "#770000";
   }

   if ($ratio < 1) {
       return "#660000";
   }

   return "#000000";
ratio — 2020-11-13 05:13:07 in v3 Support
You can try this, depending where you put it the id needs changing for show we use $CUR[user]
$res = SQL_Query_exec("SELECT uploaded, downloaded FROM users WHERE id = $CURUSER[id]");
while ($row = mysqli_fetch_assoc($res)) {

 if ($row['downloaded'] > 0)
{
$ratio = $row['uploaded'] / $row['downloaded'];
$ratio = number_format($ratio, 2);
$color = get_ratio_color($ratio);
if ($color)
     $ratio = "<font color=#ffff00>$ratio</font>";
} else if ($row['uploaded'] > 0)
    $ratio = 'Inf.';
}
echo $ratio;
}

Test on index.php at top (above check block) if it works we look at you memberlist.php
i found a better example lol one template for so many pages, this example is the comfirmok but this can be used in so many places (i use with flash message) so style is much easier
dont use this but it will be in next update  ?
the template
<section class="h-100">
           <div class="container h-100">
               <div class="row justify-content-md-center h-100">
                   <div class="card-wrapper">
                       <div class="card fat">
                           <div class="card-body">
                           <div class="alert alert-info">
                           <?php echo $data['message']; ?>
                           </div>
                           </div>
                       </div>
                   </div>
               </div>
           </div>
       </section>



then in controller (confirmok) i reuse template
<?php
} elseif ($type == "confirmed") {
           stdhead(T_("ACCOUNT_ALREADY_CONFIRMED"));
           $message = T_("ACCOUNT_ALREADY_CONFIRMED");
           $data = [
               'message' => $message,
           ];
           $this->view('account/confirmok', $data);
       }

       //invite code
       elseif ($type == "invite" && $_GET["email"]) {
           stdhead(T_("INVITE_USER"));
           $message = "<center>" . T_("INVITE_SUCCESSFUL") . "!</center><br /><br />" . T_("A_CONFIRMATION_EMAIL_HAS_BEEN_SENT") . " (" . htmlspecialchars($email) . "). " . T_("THEY_NEED_TO_READ_AND_RESPOND_TO_THIS_EMAIL") . "";
           $data = [
               'message' => $message,
           ];
           $this->view('account/confirmok', $data);
           die;
       } //end invite code

       elseif ($type == "confirm") {
           if (isset($_SESSION)) {
               stdhead(T_("ACCOUNT_SIGNUP_CONFIRMATION"));
               begin_frame(T_("ACCOUNT_SUCCESS_CONFIRMED"));
               print(T_("ACCOUNT_ACTIVATED") . " <a href='" . $config["SITEURL"] . "/index.php'>" . T_("ACCOUNT_ACTIVATED_REST") . "\n");
               print(T_("ACCOUNT_BEFOR_USING") . " " . $config["SITENAME"] . " " . T_("ACCOUNT_BEFOR_USING_REST") . "\n");
               end_frame();
           } else {
               stdhead(T_("ACCOUNT_SIGNUP_CONFIRMATION"));
               $message = T_("ACCOUNT_ACTIVATED");
               $data = [
                   'message' => $message,
               ];
               $this->view('account/confirmok', $data);
           }
       } else {
           die();
another example views/account/recover.php, ill make my way through these templates other next few days, ive got loads on one of my projects
    <section class="h-100">
           <div class="container h-100">
               <div class="row justify-content-md-center h-100">
                   <div class="card-wrapper">
                       <div class="card fat">
                           <div class="card-body">
                               <h4 class="card-title"><?php echo T_("RECOVER_ACCOUNT"); ?></h4>
                               <form method="post" action="<?php echo TTURL; ?>/account/recover?take=1">
                                   
                                   <p> <?php echo T_("USE_FORM_FOR_ACCOUNT_DETAILS"); ?> </p>
                                   <div class="form-group">
                                       <label for="email"><?php echo T_("EMAIL_ADDRESS"); ?>:</label>
                                       <input id="email" type="email" class="form-control" name="email" required data-eye>
                                   </div>
                                   <div class="form-group no-margin">
                                       <button class="btn btn-default" onclick="location.href='<?php echo TTURL; ?>/account/login'; ?>'" type="button">Cancel</button>
                                       <button type="submit" class="btn btn-primary "> Submit </button>
                                   </div>
                               </form>
                           </div>
                       </div>
                   </div>
               </div>
               <?php require_once "themes/" . ($_SESSION['stylesheet'] ?: $config['default_theme']) . "/footer.php";?>
           </div>
       </section>
The functions for blocks will be slowly be removed and replaced by templates (bootstrap)
Another example is the begin_frame / end_frame functions this makes styling easy here is the login example this is for show and will work

replace all in views/account/login.php
    <section class="h-100">
           <div class="container h-100">
               <div class="row justify-content-md-center h-100">
                   <div class="card-wrapper">
                       <div class="card fat">
                           <div class="card-body">
                               <h4 class="card-title">Login</h4>

                               <form method="post" action="<?php echo TTURL; ?>/account/login" autocomplete="off">
                                   <div class="form-group">
                                       <label for="name">Username</label>
                                       <input id="name" type="text" class="form-control" name="username" minlength="3" maxlength="25" required autofocus>
                                   </div>
                                   <div class="form-group">
                                       <label for="password">Password</label>
                                       <input id="password" type="password" class="form-control" name="password" minlength="6" maxlength="16" required data-eye>
                                   </div>
                                   <div class="form-group no-margin">
                                       <button type="submit" class="btn btn-primary btn-block"> Login </button>
                                   </div>
                                   <div class="margin-top20 text-center">
                                   <a href="<?php echo TTURL; ?>/account/signup"; ?>Create Account</a> Or <a href="<?php echo TTURL; ?>/account/recover"; ?>Recover Account</a>
                                   </div>
                               </form>
                               <?php // include "views/flash.php" ?>
                           </div>
                       </div>
                   </div>
               </div>
           </div>
       </section>
access to download — 2020-11-04 21:58:09 in v3 Mods Requests
Sorry I should be clearer :D

##########################
# BANN DOWNLOAD FAIBLE RATIO#
##########################

// ban download if ratio 0.49
$minratio = 0.49;
$vipnumber = 3; // or $site_config['vip'];
$stmt = SQL_Query_exec("SELECT id FROM users WHERE uploaded / downloaded < $minratio AND class < $vipnumber");
while ($arr = mysqli_fetch_assoc($stmt)) {
// now we link download banned mod
SQL_Query_exec("UPDATE users SET downloadbanned = 'yes' WHERE id = $arr[id]");
}

##########################
# END BANN DOWNLOAD FAIBLE RATIO#
##########################


##########################
# NO DOWNLOAD FAIBLE RATIO#
##########################

// allow download if ratio 0.50
$minratio = 0.50;
$stmt = SQL_Query_exec("SELECT id FROM users WHERE uploaded / downloaded > $minratio");
$time = get_date_time();
while ($arr = mysqli_fetch_assoc($stmt)) {
// now we link download banned mod
SQL_Query_exec("UPDATE users SET downloadbanned = 'no' WHERE id = $arr[id]");
}

##########################
# END NO DOWNLOAD FAIBLE RATIO#
##########################
This is the error causing the issue  ? it's fine on xampp so I'll check the phpinfo
Quote:

Notice: fwrite(): send of 16 bytes failed with errno=1 Operation not permitted in /home/torrentt/public_html/classes/Udptscraper.php on line 21


This is the line
$current_connid = "\x00\x00\x04\x17\x27\x10\x19\x80";
— 2020-11-04 17:21:43 in
ill sign up and have a look around mate  ?
access to download — 2020-11-04 17:19:55 in v3 Mods Requests
Try this mate
// ban download if ratio 0.49
$minratio = 0.49;
$vipnumber = 3; // or $site_config['vip'];
$stmt = SQL_Query_exec("SELECT id FROM users WHERE uploaded / downloaded < $minratio AND class < $vipnumber");


I added option for class color mod, you vip class maybe different number than 3
oops the bottom file should be named Udptscraper.php (missing r) - see if that works
on xampp its perfect -  but on live server causing me bit of a headache :unsure:
access to download — 2020-11-03 15:34:38 in v3 Mods Requests
"niki, post: 69499, member: 20338":

I just tested and it works, the member with a ratio lower than 0.5 can't download anymore but when the member has recovered a ratio higher than 0.5 his account doesn't update to have the authorization to download ??


it depends why you would ban someone from downloading

it could be banned for ratio only - which would be simple
// allow download if ratio 0.6
$minratio = 0.6;
$stmt = SQL_Query_exec("SELECT id FROM users WHERE uploaded / downloaded > $minratio");
while ($arr = mysqli_fetch_assoc($stmt)) {
     // now we link download banned mod
      SQL_Query_exec("UPDATE users SET downloadbanned = 'no' WHERE id = $arr[id]");
}


if you ban download for various things - eg bad comments - it becomes more difficult
access to download — 2020-11-02 19:26:26 in v3 Mods Requests
The ban download mod is important so staff can change in account details, it also adds ban on download.php, i use this with available slots - to piece together that just leaves cleanup.php

something like this in cleanup.php

// ban download if ratio 0.5
$minratio = 0.5;
$stmt = SQL_Query_exec("SELECT id FROM users WHERE uploaded / downloaded < $minratio");
while ($arr = mysqli_fetch_assoc($stmt)) {
     // now we link download banned mod
      SQL_Query_exec("UPDATE users SET downloadbanned = 'yes' WHERE id = $arr[id]");
}
access to download — 2020-11-02 16:38:00 in v3 Mods Requests
Here is what I did with pdo one
Ban download
[URL unfurl="true"]https://www.torrenttrader.xyz/index.php?threads/mod-stop-user-downloading.1651/[/url]

Available slots
[URL unfurl="true"]https://www.torrenttrader.xyz/index.php?threads/slot-peer-class.10022/#post-68594[/url]

That just leaves cleanup, if ratio below 0.5 user download banned, see of you are able to get these two mods working I have them installed so should be able to help
access to download — 2020-11-02 16:02:40 in v3 Mods Requests
The problem I had with this is members can not upload with ratio 0.5
Well you can upload but can not download torrent with your own passkey when upload is complete
access to download — 2020-11-02 16:00:26 in v3 Mods Requests
This has been a problem for me before, if you ban member there can not seed to improve ratio
I had leechers group for user with 0.5 ratio but you still have same problem.
I will look at this,  you can restrict download in download.php then members can still seed, the problem is any current torrents will be finished - you can use slots mod this stops members downloading x torrents
[USER=19833]@Botanicar[/USER] i think its working again, try this

in classes folder create these two files (names are important)

Tscraper.php

<?php
   class ScraperException extends Exception
   {
       private $connectionerror;
     
       public function __construct($message,$code=0,$connectionerror=false)
       {
           $this->connectionerror = $connectionerror;
           parent::__construct($message, $code);
       }
     
       public function isConnectionError()
       {
           return($this->connectionerror);
       }
   }
 
   abstract class Tscraper
   {
       protected $timeout;
     
       public function __construct($timeout=2)
       {
           $this->timeout = $timeout;
       }
   }
?>


Udptscraper.php

<?php
class Udptscraper extends Tscraper
{
   public function scrape($url, $infohash)
   {
       if (!is_array($infohash)) {$infohash = array($infohash);}
       foreach ($infohash as $hash) {
           if (!preg_match('#^[a-f0-9]{40}$#i', $hash)) {throw new ScraperException('Invalid infohash: ' . $hash . '.');}
       }
       if (count($infohash) > 74) {throw new ScraperException('Too many infohashes provided.');}
       if (!preg_match('%udp://([^:/]*)(?::([0-9]*))?(?:/)?%si', $url, $m)) {throw new ScraperException('Invalid tracker url.');}
       $tracker = 'udp://' . $m[1];
       $port = isset($m[2]) ? $m[2] : 80;
       $transaction_id = mt_rand(0, 65535);
       $fp = fsockopen($tracker, $port, $errno, $errstr);
       if (!$fp) {throw new ScraperException('Could not open UDP connection: ' . $errno . ' - ' . $errstr, 0, true);}
       stream_set_timeout($fp, $this->timeout);
       $current_connid = "\x00\x00\x04\x17\x27\x10\x19\x80";
       //Connection request
       $packet = $current_connid . pack("N", 0) . pack("N", $transaction_id);
       fwrite($fp, $packet);
       //Connection response
       $ret = fread($fp, 16);
       if (strlen($ret) < 1) {throw new ScraperException('No connection response.', 0, true);}
       if (strlen($ret) < 16) {throw new ScraperException('Too short connection response.');}
       $retd = unpack("Naction/Ntransid", $ret);
       if ($retd['action'] != 0 || $retd['transid'] != $transaction_id) {
           throw new ScraperException('Invalid connection response.');
       }
       $current_connid = substr($ret, 8, 8);
       //Scrape request
       $hashes = '';
       foreach ($infohash as $hash) {$hashes .= pack('H*', $hash);}
       $packet = $current_connid . pack("N", 2) . pack("N", $transaction_id) . $hashes;
       fwrite($fp, $packet);
       //Scrape response
       $readlength = 8 + (12 * count($infohash));
       $ret = fread($fp, $readlength);
       if (strlen($ret) < 1) {throw new ScraperException('No scrape response.', 0, true);}
       if (strlen($ret) < 8) {throw new ScraperException('Too short scrape response.');}
       $retd = unpack("Naction/Ntransid", $ret);
       // Todo check for error string if response = 3
       if ($retd['action'] != 2 || $retd['transid'] != $transaction_id) {
           throw new ScraperException('Invalid scrape response.');
       }
       if (strlen($ret) < $readlength) {throw new ScraperException('Too short scrape response.');}
       $torrents = array();
       $index = 8;
       foreach ($infohash as $hash) {
           $retd = unpack("Nseeders/Ncompleted/Nleechers", substr($ret, $index, 12));
           $retd['infohash'] = $hash;
           $torrents[$hash] = $retd;
           $index = $index + 12;
       }
       return ($torrents);
   }
}


in views/torrent/read.php find
<!--buttonsstart-->
<td align="left"> <?php


replace everything below with
// Scrape External Torrents
if ($row["external"]=='yes')
{
   print ("<td width='160' align='right' valign='top'><table><tr>");
   if ($scrape =='1')
   {
       print("<td class='table_col1' width='150' valign='middle'>
       <div style='margin-top:5px; margin-bottom:10px; font:bold 16px Times'
        align='center'><font color='#FF2000'>".T_("EXTERNAL_TORRENT")."</font>
        </div>");

       //===| UDP Scraper
       $resu = $pdo->run("SELECT id, info_hash FROM torrents WHERE external = 'yes' AND id = $id");
       while ($rowu = $resu->fetch(PDO::FETCH_ASSOC))
       {
           // if broke try play with path - site_config url
           $TorrentInfo = ParseTorrent("uploads/$rowu[id].torrent");
           $ann = $TorrentInfo[0];
//var_dump($ann);
           $annlist = array();

           if ($TorrentInfo[6])
           {
               foreach ($TorrentInfo[6] as $ann)
               {
                   $annlist[] = $ann[0];
               }
           }
           else
               $annlist = array($ann);
//var_dump($annlist);

           $seeders = $leechers = $downloaded = null;
           foreach ($annlist as $ann)
           {
               $tracker = explode("/", $ann);
               $path = array_pop($tracker);
               $path = str_replace("announce", "scrape", $path);
               $tracker = implode("/", $tracker)."/".$path;
//var_dump($tracker);
               if(preg_match('/udp:\/\//', $tracker))
               {
                   $udp=true;
                   try
                   {
                       $timeout = 5;
                       $udp= new Udptscraper($timeout);
                       $stats=$udp->scrape($tracker, $rowu["info_hash"]);
                       //var_dump($udp->scrape($tracker, $rowu["info_hash"]));
                       foreach ($stats as $idu=>$scrape)
                       {
                           $seeders += $scrape['seeders'];
                           $leechers += $scrape['leechers'];
                           $downloaded    += $scrape['completed'];
                       }
                   }
                   catch(ScraperException $e)
                   {
                       $e->isConnectionError();
                   }
               }
               else
               {
                   $stats = torrent_scrape_url($tracker, $rowu["info_hash"]);
               }

               if ($stats['seeds'] != -1)
               {
                   $seeders += $stats['seeds'];
                   $leechers += $stats['peers'];
                   $downloaded += $stats['downloaded'];

                   $pdo->run("UPDATE `announce` SET `online` = 'yes', `seeders` = '".$stats['seeds']."', `leechers` = '".$stats['peers']."', `times_completed` = '".$stats['downloaded']."' WHERE `url` = ".sqlesc($ann)." AND `torrent` = $rowu[id]");
               }
               else
               {
                   $pdo->run("UPDATE `announce` SET `online` = 'no' WHERE `url` = ".sqlesc($ann)." AND `torrent` = $rowu[id]");
               }
           }

           if ($seeders !== null)
           {
               $pdo->run("UPDATE torrents SET leechers = '".$leechers."', seeders = '".$seeders."', times_completed = '".$downloaded."', last_action = '".get_date_time()."', visible = 'yes' WHERE id = '".$rowu['id']."'");
           }
           else
           {
               $pdo->run("UPDATE torrents SET last_action = '".get_date_time()."' WHERE id='".$rowu['id']."'");
           }
       }
       //===| End UDP Scraper
         
       if ($seeders !== null)
       {
           print ("<div style='margin-bottom:5px; margin-left:20px'><b>".T_("LIVE_STATS")."</b>: </div>");
           print ("<div style='margin-left:20px'>".T_("SEEDERS").": <font color='limegreen'>".$seeders."</font></div>");
           print ("<div style='margin-left:20px'>".T_("LEECHERS").": <font color='#FF2000'>".$leechers."</font></div>");
           print ("<div style='margin-left:20px'>".T_("COMPLETED").": <font color='#0080FF'>".$downloaded."</font></div>");
           print ("</br>");
       }
       else
       {
           print ("<div style='margin-top:10px; margin-bottom:5px' align='center'><b>".T_("LIVE_STATS")."</b>: </div>");
           print ("<div style='font:italic 14px Times' align='center'><font color='#FF2000'>".T_("TRACKERS_OFFLINE")."!</font></div>");
       }
       print ("</td>");
   }
   else
   {
       print ("<td class='table_col1' width='150' valign='middle' align='center'>
           <div style='margin-top:5px; margin-bottom:10px; font:bold 16px Times' align='center'><font color='#FF2000'>".T_("EXTERNAL_TORRENT")."</font></div>
           </div>
               <form action='$config[SITEURL]/torrents/read?id=$id&amp;scrape=1' method='post'>
                   <div style='margin-top:5px; margin-bottom:10px' align='center'><input type='submit' name='submit' value=".T_("UPDATE_STATS")." /></div>
               </form>
           </td>");
   }
   print ("</tr></table></td>");
//===| End Scrape External Torrents
///END SCRAPE
   }?>
           </td>
           </td>
       </tr>
       </table>
       <?php
}

//DISPLAY NFO BLOCK
if ($row["nfo"] == "yes") {
   $nfofilelocation = "$nfo_dir/$row[id].nfo";
   $filegetcontents = file_get_contents($nfofilelocation);
   // needs filtering better todo
   //    $nfo = htmlspecialchars($filegetcontents);
   $nfo = $filegetcontents;
   if ($nfo) {
       $nfo = my_nfo_translate($nfo);
       echo "<br /><br /><b>NFO:</b><br />";
       print("<div><textarea class='nfo' style='width:98%;height:100%;' rows='20' cols='20' readonly='readonly'>" . stripslashes($nfo) . "</textarea></div>");
   } else {
       print(T_("ERROR") . " reading .nfo file!");
   }
}
Here is the original class, https://github.com/FabianBeiner/PHP-IMDB-Grabber

Theres a example there, the paths caused me problems but just needs fine tuning now. A lot of the class functions aren't needed so could be slimmed it's mainly better caching that needs better implementation
Seem to have broken something lol got so many things on at once
Luckily I made a couple of backups so I'll look through them and update post before weekend  (y)
You can call most of the class functions here is a few examples to show on index.php
            echo '<p><a href="' .
                $oIMDB->getUrl() .
                '">' .
                $oIMDB->getTitle() .
                '</a><br> Certificate ' .
                // New Example
                $oIMDB->getCertification() .
                ' <br> Director <br> ' .
                // New Example
                $oIMDB->getDirector() .
                '<br> got rated <br>' .
                $oIMDB->getRating() .
                '.</p>';


for v3 search imdb.php for $config change to $site_config
[color=rgb(247, 218, 100)]UPDATED 30/11/20[/color]

Current progress this is writeen for pdo version but ive made it as simple as possible so can be added to v3

the class IMDBnew.php im in the process of slimming this down (you dont need to include it anywhere)
<?php
/**
* PHP IMDb.com Grabber
* @link    https://github.com/FabianBeiner/PHP-IMDB-Grabber/ GitHub Repository
*/
class IMDBnew
{
   // Set this to true if you run into problems.
   const IMDB_DEBUG = true;
   // Set the preferred language for the User Agent.
   const IMDB_LANG = 'en-US,en;q=0.9';
   // Define the timeout for cURL requests.
   const IMDB_TIMEOUT = 15;
   /**
    * These are the regular expressions used to extract the data.
    * If you don’t know what you’re doing, you shouldn’t touch them.
    */
   const IMDB_AKA           = '~<td[^>]*>\s*Also\s*Known\s*As\s*</td>\s*<td>(.+)</td>~Uis';
   const IMDB_ASPECT_RATIO  = '~<td[^>]*>Aspect\s*Ratio</td>\s*<td>(.+)</td>~Uis';
   const IMDB_AWARDS        = '~<div\s*class="titlereference-overview-section">\s*Awards:(.+)</div>~Uis';
   const IMDB_BUDGET        = '~<td[^>]*>Budget<\/td>\s*<td>\s*(.*)(?:\(estimated\))\s*<\/td>~Ui';
   const IMDB_CAST          = '~<td[^>]*itemprop="actor"[^>]*>\s*<a\s*href="/name/([^/]*)/\?[^"]*"[^>]*>\s*<span.+>(.+)</span~Ui';
   const IMDB_CAST_IMAGE    = '~(loadlate="(.*)"[^>]*><\/a>\s+<\/td>\s+)?<td[^>]*itemprop="actor"[^>]*>\s*<a\s*href="\/name\/([^/]*)\/\?[^"]*"[^>]*>\s*<span.+>(.+)<\/span+~Uis';
   const IMDB_CERTIFICATION = '~<td[^>]*>\s*Certification\s*</td>\s*<td>(.+)</td>~Ui';
   const IMDB_CHAR          = '~<td class="character">(?:\s+)<div>(.*)(?:\s+)(?: /| \(.*\)|<\/div>)~Ui';
   const IMDB_COLOR         = '~<a href="\/search\/title\?colors=(?:.*)">(.*)<\/a>~Ui';
   const IMDB_COMPANY       = '~href="[^"]*update=[t0-9]+:production_companies[^"]*">Edit</a>\s*</header>\s*<ul\s*class="simpleList">.+<a href="\/company\/(.*)\/">(.*)</a>~Ui';
   const IMDB_COUNTRY       = '~<a href="/country/(\w+)">(.*)</a>~Ui';
   const IMDB_CREATOR       = '~<div[^>]*>\s*(?:Creator|Creators)\s*:\s*<ul[^>]*>(.+)</ul>~Uxsi';
   const IMDB_DIRECTOR      = '~<div[^>]*>\s*(?:Director|Directors)\s*:\s*<ul[^>]*>(.+)</ul>~Uxsi';
   const IMDB_GENRE         = '~href="/genre/([a-zA-Z_-]*)/?">([a-zA-Z_ -]*)</a>~Ui';
   const IMDB_GROSS         = '~pl-zebra-list__label">Cumulative Worldwide Gross<\/td>\s+<td>\s+(.*)\s+<~Uxsi';
   const IMDB_ID            = '~((?:tt\d{6,})|(?:itle\?\d{6,}))~';
   const IMDB_LANGUAGE      = '~<a href="\/language\/(\w+)">(.*)<\/a>~Ui';
   const IMDB_LOCATION      = '~href="\/search\/title\?locations=(.*)">(.*)<\/a>~Ui';
   const IMDB_LOCATIONS     = '~href="\/search\/title\?locations=[^>]*>\s?(.*)\s?<\/a>[^"]*<dd>\s?(.*)\s<\/dd>~Ui';
   const IMDB_MPAA          = '~<li class="ipl-inline-list__item">(?:\s+)(TV-Y|TV-Y7|TV-G|TV-PG|TV-14|TV-MA|G|PG|PG-13|R|NC-17|NR|UR)(?:\s+)<\/li>~Ui';
   const IMDB_NAME          = '~href="/name/(.+)/?(?:\?[^"]*)?"[^>]*>(.+)</a>~Ui';
   const IMDB_DESCRIPTION   = '~<section class="titlereference-section-overview">\s+<div>(.*)</div>\s+<hr>~Ui';
   const IMDB_NOT_FOUND     = '~<h1 class="findHeader">No results found for ~Ui';
   const IMDB_PLOT          = '~<td[^>]*>\s*Plot\s*Summary\s*</td>\s*<td>\s*<p>(.+)</p>~Ui';
   const IMDB_PLOT_KEYWORDS = '~<td[^>]*>Plot\s*Keywords</td>\s*<td>(.+)(?:<a\s*href="/title/[^>]*>[^<]*</a>\s*</li>\s*</ul>\s*)?</td>~Ui';
   const IMDB_POSTER        = '~<link\s*rel=\'image_src\'\s*href="(.*)">~Ui';
   const IMDB_RATING        = '~class="ipl-rating-star__rating">(.*)<~Ui';
   const IMDB_RATING_COUNT  = '~class="ipl-rating-star__total-votes">\((.*)\)<~Ui';
   const IMDB_RELEASE_DATE  = '~href="/title/[t0-9]*/releaseinfo">(.*)<~Ui';
   const IMDB_RUNTIME       = '~<td[^>]*>\s*Runtime\s*</td>\s*<td>(.+)</td>~Ui';
   const IMDB_SEARCH        = '~<td class="result_text"> <a href="\/title\/(tt\d{6,})\/(?:.*)"(?:\s*)>(?:.*)<\/a>~Ui';
   const IMDB_SEASONS       = '~episodes\?season=(?:\d+)">(\d+)<~Ui';
   const IMDB_SOUND_MIX     = '~<td[^>]*>\s*Sound\s*Mix\s*</td>\s*<td>(.+)</td>~Ui';
   const IMDB_TAGLINE       = '~<td[^>]*>\s*Taglines\s*</td>\s*<td>(.+)</td>~Ui';
   const IMDB_TITLE         = '~itemprop="name">(.*)(<\/h3>|<span)~Ui';
   const IMDB_TITLE_ORIG    = '~</h3>(?:\s+)(.*)(?:\s+)<span class=\"titlereference-original-title-label~Ui';
   const IMDB_TRAILER       = '~href="videoplayer/(vi[0-9]*)"~Ui';
   const IMDB_URL           = '~https?://(?:.*\.|.*)imdb.com/(?:t|T)itle(?:\?|/)(..\d+)~i';
   const IMDB_USER_REVIEW   = '~href="/title/[t0-9]*/reviews"[^>]*>([^<]*)\s*User~Ui';
   const IMDB_VOTES         = '~"ipl-rating-star__total-votes">\s*\((.*)\)\s*<~Ui';
   const IMDB_WRITER        = '~<div[^>]*>\s*(?:Writer|Writers)\s*:\s*<ul[^>]*>(.+)</ul>~Ui';
   const IMDB_YEAR          = '~og:title\' content="(?:.*)\((?:.*)(\d{4})(?:.*)\)~Ui';

   /**
    * @var string The string returned, if nothing is found.
    */
   public static $sNotFound = 'n/A';

   /**
    * @var null|int The ID of the movie.
    */
   public $iId = null;

   /**
    * @var bool Is the content ready?
    */
   public $isReady = false;

   /**
    * @var string Char that separates multiple entries.
    */
   public $sSeparator = ' / ';

   /**
    * @var null|string The URL to the movie.
    */
   public $sUrl = null;

   /**
    * @var bool Return responses enclosed in array
    */
   public $bArrayOutput = false;

   /**
    * @var int Maximum cache time.
    */
   private $iCache = 11440;

   /**
    * @var null|string Holds the source.
    */
   private $sSource = null;

   /**
    * @var string What to search for?
    */
   private $sSearchFor = 'all';

   /**
    * @param string $sSearch    IMDb URL or movie title to search for.
    * @param null   $iCache     Custom cache time in minutes.
    * @param string $sSearchFor What to search for?
    *
    * @throws Exception
    */
   public function __construct($sSearch, $iCache = null, $sSearchFor = 'all')
   {
       $this->sRoot = TTURL;
       global $config;
       if ( ! is_writable('uploads/imdb') && ! mkdir('uploads/imdb')) {
           throw new Exception('The directory “uploads/imdb” isn’t writable.');
       }
       if ( ! is_writable('cache/imdb') && ! mkdir('cache/imdb')) {
           throw new Exception('The directory “cache/imdb” isn’t writable.');
       }
       if ( ! is_writable('uploads/cast') && ! mkdir('uploads/cast')) {
           throw new Exception('The directory “uploads/cast” isn’t writable.');
       }
       if ( ! function_exists('curl_init')) {
           throw new Exception('You need to enable the PHP cURL extension.');
       }
       if (in_array(
           $sSearchFor,
           [
               'movie',
               'tv',
               'episode',
               'game',
               'all',
           ]
       )) {
           $this->sSearchFor = $sSearchFor;
       }
       if (true === self::IMDB_DEBUG) {
           ini_set('display_errors', 1);
           ini_set('display_startup_errors', 1);
           error_reporting(-1);
           echo '<pre><b>Running:</b> fetchUrl("' . $sSearch . '")</pre>';
       }
       if (null !== $iCache && (int) $iCache > 0) {
           $this->iCache = (int) $iCache;
       }
       $this->fetchUrl($sSearch);
   }

   /**
    * @param string $sSearch IMDb URL or movie title to search for.
    *
    * @return bool True on success, false on failure.
    */
   private function fetchUrl($sSearch)
   {
       $sSearch = trim($sSearch);

       // Try to find a valid URL.
       $sId = IMDBHelper::matchRegex($sSearch, self::IMDB_ID, 1);
       if (false !== $sId) {
           $this->iId  = preg_replace('~[\D]~', '', $sId);
           $this->sUrl = 'https://www.imdb.com/title/tt' . $this->iId . '/reference';
           $bSearch    = false;
       } else {
           switch (strtolower($this->sSearchFor)) {
               case 'movie':
                   $sParameters = '&s=tt&ttype=ft';
                   break;
               case 'tv':
                   $sParameters = '&s=tt&ttype=tv';
                   break;
               case 'episode':
                   $sParameters = '&s=tt&ttype=ep';
                   break;
               case 'game':
                   $sParameters = '&s=tt&ttype=vg';
                   break;
               default:
                   $sParameters = '&s=tt';
           }

           $this->sUrl = 'https://www.imdb.com/find?q=' . rawurlencode(str_replace(' ', '+', $sSearch)) . $sParameters;
           $bSearch    = true;

           // Was this search already performed and cached?
           $sRedirectFile = 'cache/imdb/' . sha1($this->sUrl) . '.redir';
           if (is_readable($sRedirectFile)) {
               if (self::IMDB_DEBUG) {
                   echo '<pre><b>Using redirect:</b> ' . basename($sRedirectFile) . '</pre>';
               }
               $sRedirect  = file_get_contents($sRedirectFile);
               $this->sUrl = trim($sRedirect);
               $this->iId  = preg_replace('~[\D]~', '', IMDBHelper::matchRegex($sRedirect, self::IMDB_ID, 1));
               $bSearch    = false;
           }
       }

       // Does a cache of this movie exist?
       $sCacheFile = 'cache/imdb/' . sha1($this->iId) . '.cache';
       if (is_readable($sCacheFile)) {
           $iDiff = round(abs(time() - filemtime($sCacheFile)) / 60);
           if ($iDiff < $this->iCache) {
               if (true === self::IMDB_DEBUG) {
                   echo '<pre><b>Using cache:</b> ' . basename($sCacheFile) . '</pre>';
               }
               $this->sSource = file_get_contents($sCacheFile);
               $this->isReady = true;

               return true;
           }
       }

       // Run cURL on the URL.
       if (true === self::IMDB_DEBUG) {
           echo '<pre><b>Running cURL:</b> ' . $this->sUrl . '</pre>';
       }

       $aCurlInfo = IMDBHelper::runCurl($this->sUrl);
       $sSource   = $aCurlInfo['contents'];

       if (false === $sSource) {
           if (true === self::IMDB_DEBUG) {
               echo '<pre><b>cURL error:</b> ' . var_dump($aCurlInfo) . '</pre>';
           }

           return false;
       }

       // Was the movie found?
       $sMatch = IMDBHelper::matchRegex($sSource, self::IMDB_SEARCH, 1);
       if (false !== $sMatch) {
           $sUrl = 'https://www.imdb.com/title/' . $sMatch . '/reference';
           if (true === self::IMDB_DEBUG) {
               echo '<pre><b>New redirect saved:</b> ' . basename($sRedirectFile) . ' => ' . $sUrl . '</pre>';
           }
           file_put_contents($sRedirectFile, $sUrl);
           $this->sSource = null;
           $this->fetchUrl($sUrl);

           return true;
       }
       $sMatch = IMDBHelper::matchRegex($sSource, self::IMDB_NOT_FOUND, 0);
       if (false !== $sMatch) {
           if (true === self::IMDB_DEBUG) {
               echo '<pre><b>Movie not found:</b> ' . $sSearch . '</pre>';
           }

           return false;
       }

       $this->sSource = str_replace(
           [
               "\n",
               "\r\n",
               "\r",
           ],
           '',
           $sSource
       );
       $this->isReady = true;

       // Save cache.
       if (false === $bSearch) {
           if (true === self::IMDB_DEBUG) {
               echo '<pre><b>Cache created:</b> ' . basename($sCacheFile) . '</pre>';
           }
           file_put_contents($sCacheFile, $this->sSource);
       }

       return true;
   }

   /**
    * @return array All data.
    */
   public function getAll()
   {
       $aData = [];
       foreach (get_class_methods(__CLASS__) as $method) {
           if (substr($method, 0, 3) === 'get' && $method !== 'getAll' && $method !== 'getCastImages') {
               $aData[$method] = [
                   'name'  => ltrim($method, 'get'),
                   'value' => $this->{$method}(),
               ];
           }
       }
       array_multisort($aData);

       return $aData;
   }

   /**
    * @return string “Also Known As” or $sNotFound.
    */
   public function getAka()
   {
       if (true === $this->isReady) {
           $sMatch = IMDBHelper::matchRegex($this->sSource, self::IMDB_AKA, 1);
           if (false !== $sMatch) {
               return IMDBHelper::cleanString($sMatch);
           }
       }

       return self::$sNotFound;
   }

   /**
    * Returns all local names
    *
    * @return string All local names.
    */
   public function getAkas()
   {
       if (true === $this->isReady) {
           // Does a cache of this movie exist?
           $sCacheFile = 'cache/imdb/' . sha1($this->iId) . '_akas.cache';
           $bUseCache  = false;

           if (is_readable($sCacheFile)) {
               $iDiff = round(abs(time() - filemtime($sCacheFile)) / 60);
               if ($iDiff < $this->iCache || false) {
                   $bUseCache = true;
               }
           }

           if ($bUseCache) {
               $aRawReturn = file_get_contents($sCacheFile);
               $aReturn    = unserialize($aRawReturn);

               return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound, $aReturn);
           } else {
               $fullAkas  = sprintf('https://www.imdb.com/title/tt%s/releaseinfo', $this->iId);
               $aCurlInfo = IMDBHelper::runCurl($fullAkas);
               $sSource   = $aCurlInfo['contents'];

               if (false === $sSource) {
                   if (true === self::IMDB_DEBUG) {
                       echo '<pre><b>cURL error:</b> ' . var_dump($aCurlInfo) . '</pre>';
                   }

                   return false;
               }

               $aReturned = IMDBHelper::matchRegex($sSource, "~<td>(.*?)<\/td>\s+<td>(.*?)<\/td>~");

               if ($aReturned) {
                   $aReturn = [];
                   foreach ($aReturned[1] as $i => $strName) {
                       if (strpos($strName, '(') === false) {
                           $aReturn[] = [
                               'title'   => IMDBHelper::cleanString($aReturned[2][$i]),
                               'country' => IMDBHelper::cleanString($strName),
                           ];
                       }
                   }

                   file_put_contents($sCacheFile, serialize($aReturn));

                   return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound, $aReturn);
               }
           }
       }

       return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound);
   }

   /**
    * @return string “Aspect Ratio” or $sNotFound.
    */
   public function getAspectRatio()
   {
       if (true === $this->isReady) {
           $sMatch = IMDBHelper::matchRegex($this->sSource, self::IMDB_ASPECT_RATIO, 1);
           if (false !== $sMatch) {
               return IMDBHelper::cleanString($sMatch);
           }
       }

       return self::$sNotFound;
   }

   /**
    * @return string The awards of the movie or $sNotFound.
    */
   public function getAwards()
   {
       if (true === $this->isReady) {
           $sMatch = IMDBHelper::matchRegex($this->sSource, self::IMDB_AWARDS, 1);
           if (false !== $sMatch) {
               return IMDBHelper::cleanString($sMatch);
           }
       }

       return self::$sNotFound;
   }

   /**
    * @param int    $iLimit  How many cast members should be returned?
    * @param bool   $bMore   Add … if there are more cast members than printed.
    * @param string $sTarget Add a target to the links?
    *
    * @return string A list with linked cast members or $sNotFound.
    */
   public function getCastAsUrl($iLimit = 0, $bMore = true, $sTarget = '')
   {
       if (true === $this->isReady) {
           $aMatch  = IMDBHelper::matchRegex($this->sSource, self::IMDB_CAST);
           $aReturn = [];
           if (count($aMatch[2])) {
               foreach ($aMatch[2] as $i => $sName) {
                   if (0 !== $iLimit && $i >= $iLimit) {
                       break;
                   }
                   $aReturn[] = '<a href="https://www.imdb.com/name/' . IMDBHelper::cleanString(
                           $aMatch[1][$i]
                       ) . '/"' . ($sTarget ? ' target="' . $sTarget . '"' : '') . '>' . IMDBHelper::cleanString(
                           $sName
                       ) . '</a>';
               }

               $bHaveMore = ($bMore && (count($aMatch[2]) > $iLimit));

               return IMDBHelper::arrayOutput(
                   $this->bArrayOutput,
                   $this->sSeparator,
                   self::$sNotFound,
                   $aReturn,
                   $bHaveMore
               );
           }
       }

       return self::$sNotFound;
   }

   /**
    * @param int  $iLimit How many cast members should be returned?
    * @param bool $bMore  Add … if there are more cast members than printed.
    *
    * @return string A list with cast members or $sNotFound.
    */
   public function getCast($iLimit = 0, $bMore = true)
   {
       if (true === $this->isReady) {
           $aMatch  = IMDBHelper::matchRegex($this->sSource, self::IMDB_CAST);
           $aReturn = [];
           if (count($aMatch[2])) {
               foreach ($aMatch[2] as $i => $sName) {
                   if (0 !== $iLimit && $i >= $iLimit) {
                       break;
                   }
                   $aReturn[] = IMDBHelper::cleanString($sName);
               }

               $bMore = (0 !== $iLimit && $bMore && (count($aMatch[2]) > $iLimit) ? '…' : '');

               $bHaveMore = ($bMore && (count($aMatch[2]) > $iLimit));

               return IMDBHelper::arrayOutput(
                   $this->bArrayOutput,
                   $this->sSeparator,
                   self::$sNotFound,
                   $aReturn,
                   $bHaveMore
               );
           }
       }

       return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound);
   }

   /**
    * @param int    $iLimit    How many cast images should be returned?
    * @param bool   $bMore     Add … if there are more cast members than printed.
    * @param string $sSize     small, mid or big cast images
    * @param bool   $bDownload Return URL or Download
    *
    * @return array Array with cast name as key, and image as value.
    */
   public function getCastImages($iLimit = 0, $bMore = true, $sSize = 'small', $bDownload = false)
   {
       if (true === $this->isReady) {
           $aMatch  = IMDBHelper::matchRegex($this->sSource, self::IMDB_CAST_IMAGE);
           $aReturn = [];
           if (count($aMatch[4])) {
               foreach ($aMatch[4] as $i => $sName) {
                   if (0 !== $iLimit && $i >= $iLimit) {
                       break;
                   }
                   $sMatch = $aMatch[2][$i];

                   if ('big' === strtolower($sSize) && false !== strstr($aMatch[2][$i], '@._')) {
                       $sMatch = substr($aMatch[2][$i], 0, strpos($aMatch[2][$i], '@._')) . '@.jpg';
                   } elseif ('mid' === strtolower($sSize) && false !== strstr($aMatch[2][$i], '@._')) {
                       $sMatch = substr($aMatch[2][$i], 0, strpos($aMatch[2][$i], '@._')) . '@._V1_UX214_AL_.jpg';
                   }

                   if (false === $bDownload) {
                       $sMatch = IMDBHelper::cleanString($sMatch);
                   } else {
                       $sLocal = IMDBHelper::saveImageCast($sMatch, $aMatch[3][$i]);
                       if (file_exists(dirname(__FILE__) . '/' . $sLocal)) {
                           $sMatch = $sLocal;
                       } else {
                           //the 'big' image isn't available, try the 'mid' one (vice versa)
                           if ('big' === strtolower($sSize) && false !== strstr($aMatch[2][$i], '@._')) {
                               //trying the 'mid' one
                               $sMatch = substr(
                                       $aMatch[2][$i],
                                       0,
                                       strpos($aMatch[2][$i], '@._')
                                   ) . '@._V1_UX214_AL_.jpg';
                           } else {
                               //trying the 'big' one
                               $sMatch = substr($aMatch[2][$i], 0, strpos($aMatch[2][$i], '@._')) . '@.jpg';
                           }

                           $sLocal = IMDBHelper::saveImageCast($sMatch, $aMatch[3][$i]);
                           if (file_exists(dirname(__FILE__) . '/' . $sLocal)) {
                               $sMatch = $sLocal;
                           } else {
                               $sMatch = IMDBHelper::cleanString($aMatch[2][$i]);
                           }
                       }
                   }

                   $aReturn[IMDBHelper::cleanString($aMatch[4][$i])] = $sMatch;
               }

               $bMore = (0 !== $iLimit && $bMore && (count($aMatch[4]) > $iLimit) ? '…' : '');

               $bHaveMore = ($bMore && (count($aMatch[4]) > $iLimit));

               $aReturn = array_replace(
                   $aReturn,
                   array_fill_keys(
                       array_keys($aReturn, self::$sNotFound),
                       'uploads/cast/not-found.jpg'
                   )
               );

               return $aReturn;
           }
       }

       return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound);
   }

   /**
    * @param int    $iLimit  How many cast members should be returned?
    * @param bool   $bMore   Add … if there are more cast members than
    *                        printed.
    * @param string $sTarget Add a target to the links?
    *
    * @return string A list with linked cast members and their character or
    *                $sNotFound.
    */
   public function getCastAndCharacterAsUrl($iLimit = 0, $bMore = true, $sTarget = '')
   {
       if (true === $this->isReady) {
           $aMatch     = IMDBHelper::matchRegex($this->sSource, self::IMDB_CAST);
           $aMatchChar = IMDBHelper::matchRegex($this->sSource, self::IMDB_CHAR);
           $aReturn    = [];
           if (count($aMatch[2])) {
               foreach ($aMatch[2] as $i => $sName) {
                   if (0 !== $iLimit && $i >= $iLimit) {
                       break;
                   }
                   $aReturn[] = '<a href="https://www.imdb.com/name/' . IMDBHelper::cleanString(
                           $aMatch[1][$i]
                       ) . '/"' . ($sTarget ? ' target="' . $sTarget . '"' : '') . '>' . IMDBHelper::cleanString(
                           $sName
                       ) . '</a> as ' . IMDBHelper::cleanString($aMatchChar[1][$i]);
               }

               $bHaveMore = ($bMore && (count($aMatch[2]) > $iLimit));

               return IMDBHelper::arrayOutput(
                   $this->bArrayOutput,
                   $this->sSeparator,
                   self::$sNotFound,
                   $aReturn,
                   $bHaveMore
               );
           }
       }

       return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound);
   }

   /**
    * @param int  $iLimit How many cast members should be returned?
    * @param bool $bMore  Add … if there are more cast members than printed.
    *
    * @return string  A list with cast members and their character or
    *                 $sNotFound.
    */
   public function getCastAndCharacter($iLimit = 0, $bMore = true)
   {
       if (true === $this->isReady) {
           $aMatch     = IMDBHelper::matchRegex($this->sSource, self::IMDB_CAST);
           $aMatchChar = IMDBHelper::matchRegex($this->sSource, self::IMDB_CHAR);
           $aReturn    = [];
           if (count($aMatch[2])) {
               foreach ($aMatch[2] as $i => $sName) {
                   if (0 !== $iLimit && $i >= $iLimit) {
                       break;
                   }
                   $aReturn[] = IMDBHelper::cleanString($sName) . ' as ' . IMDBHelper::cleanString($aMatchChar[1][$i]);
               }

               $bHaveMore = ($bMore && (count($aMatch[2]) > $iLimit));

               return IMDBHelper::arrayOutput(
                   $this->bArrayOutput,
                   $this->sSeparator,
                   self::$sNotFound,
                   $aReturn,
                   $bHaveMore
               );
           }
       }

       return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound);
   }

   /**
    * @return string The certification of the movie or $sNotFound.
    */
   public function getCertification()
   {
       if (true === $this->isReady) {
           $sMatch = IMDBHelper::matchRegex($this->sSource, self::IMDB_CERTIFICATION, 1);
           if (false !== $sMatch) {
               return IMDBHelper::cleanString($sMatch);
           }
       }

       return self::$sNotFound;
   }

   /**
    * @return string Color or $sNotFound.
    */
   public function getColor()
   {
       if (true === $this->isReady) {
           $sMatch = IMDBHelper::matchRegex($this->sSource, self::IMDB_COLOR, 1);
           if (false !== $sMatch) {
               return IMDBHelper::cleanString($sMatch);
           }
       }

       return self::$sNotFound;
   }

   /**
    * @return string The company producing the movie or $sNotFound.
    */
   public function getCompany()
   {
       if (true === $this->isReady) {
           $sMatch = $this->getCompanyAsUrl();
           if (self::$sNotFound !== $sMatch) {
               return IMDBHelper::cleanString($sMatch);
           }
       }

       return self::$sNotFound;
   }

   /**
    * @param string $sTarget Add a target to the links?
    *
    * @return string The linked company producing the movie or $sNotFound.
    */
   public function getCompanyAsUrl($sTarget = '')
   {
       if (true === $this->isReady) {
           $aMatch = IMDBHelper::matchRegex($this->sSource, self::IMDB_COMPANY);
           if (isset($aMatch[2][0])) {
               return '<a href="https://www.imdb.com/company/' . IMDBHelper::cleanString(
                       $aMatch[1][0]
                   ) . '/"' . ($sTarget ? ' target="' . $sTarget . '"' : '') . '>' . IMDBHelper::cleanString(
                       $aMatch[2][0]
                   ) . '</a>';
           }
       }

       return self::$sNotFound;
   }

   /**
    * @return string A list with countries or $sNotFound.
    */
   public function getCountry()
   {
       if (true === $this->isReady) {
           $sMatch = $this->getCountryAsUrl();
           if (self::$sNotFound !== $sMatch) {
               return IMDBHelper::cleanString($sMatch);
           }
       }

       return self::$sNotFound;
   }

   /**
    * @param string $sTarget Add a target to the links?
    *
    * @return string A list with linked countries or $sNotFound.
    */
   public function getCountryAsUrl($sTarget = '')
   {
       if (true === $this->isReady) {
           $aMatch  = IMDBHelper::matchRegex($this->sSource, self::IMDB_COUNTRY);
           $aReturn = [];
           if (count($aMatch[2])) {
               foreach ($aMatch[2] as $i => $sName) {
                   $aReturn[] = '<a href="https://www.imdb.com/country/' . trim(
                           $aMatch[1][$i]
                       ) . '/"' . ($sTarget ? ' target="' . $sTarget . '"' : '') . '>' . IMDBHelper::cleanString(
                           $sName
                       ) . '</a>';
               }

               return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound, $aReturn);
           }
       }

       return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound);
   }

   /**
    * @return string A list with the creators or $sNotFound.
    */
   public function getCreator()
   {
       if (true === $this->isReady) {
           $sMatch = $this->getCreatorAsUrl();
           if (self::$sNotFound !== $sMatch) {
               return IMDBHelper::cleanString($sMatch);
           }
       }

       return self::$sNotFound;
   }

   /**
    * @param string $sTarget Add a target to the links?
    *
    * @return string A list with the linked creators or $sNotFound.
    */
   public function getCreatorAsUrl($sTarget = '')
   {
       if (true === $this->isReady) {
           $sMatch  = IMDBHelper::matchRegex($this->sSource, self::IMDB_CREATOR, 1);
           $aMatch  = IMDBHelper::matchRegex($sMatch, self::IMDB_NAME);
           $aReturn = [];
           if (count($aMatch[2])) {
               foreach ($aMatch[2] as $i => $sName) {
                   $aReturn[] = '<a href="https://www.imdb.com/name/' . IMDBHelper::cleanString(
                           $aMatch[1][$i]
                       ) . '/"' . ($sTarget ? ' target="' . $sTarget . '"' : '') . '>' . IMDBHelper::cleanString(
                           $sName
                       ) . '</a>';
               }

               return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound, $aReturn);
           }
       }

       return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound);
   }

   /**
    * @return string The description of the movie or $sNotFound.
    */
   public function getDescription()
   {
       if (true === $this->isReady) {
           $sMatch = IMDBHelper::matchRegex($this->sSource, self::IMDB_DESCRIPTION, 1);
           if (false !== $sMatch) {
               return IMDBHelper::cleanString($sMatch);
           }
       }

       return self::$sNotFound;
   }

   /**
    * @return string A list with the directors or $sNotFound.
    */
   public function getDirector()
   {
       if (true === $this->isReady) {
           $sMatch = $this->getDirectorAsUrl();
           if (self::$sNotFound !== $sMatch) {
               return IMDBHelper::cleanString($sMatch);
           }
       }

       return self::$sNotFound;
   }

   /**
    * @param string $sTarget Add a target to the links?
    *
    * @return string A list with the linked directors or $sNotFound.
    */
   public function getDirectorAsUrl($sTarget = '')
   {
       if (true === $this->isReady) {
           $sMatch  = IMDBHelper::matchRegex($this->sSource, self::IMDB_DIRECTOR, 1);
           $aMatch  = IMDBHelper::matchRegex($sMatch, self::IMDB_NAME);
           $aReturn = [];
           if (count($aMatch[2])) {
               foreach ($aMatch[2] as $i => $sName) {
                   $aReturn[] = '<a href="https://www.imdb.com/name/' . IMDBHelper::cleanString(
                           $aMatch[1][$i]
                       ) . '/"' . ($sTarget ? ' target="' . $sTarget . '"' : '') . '>' . IMDBHelper::cleanString(
                           $sName
                       ) . '</a>';
               }

               return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound, $aReturn);
           }
       }

       return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound);
   }

   /**
    * @return string A list with the genres or $sNotFound.
    */
   public function getGenre()
   {
       if (true === $this->isReady) {
           $sMatch = $this->getGenreAsUrl();
           if (self::$sNotFound !== $sMatch) {
               return IMDBHelper::cleanString($sMatch);
           }
       }

       return self::$sNotFound;
   }

   /**
    * @param string $sTarget Add a target to the links?
    *
    * @return string A list with the linked genres or $sNotFound.
    */
   public function getGenreAsUrl($sTarget = '')
   {
       if (true === $this->isReady) {
           $aMatch  = IMDBHelper::matchRegex($this->sSource, self::IMDB_GENRE);
           $aReturn = [];
           if (count($aMatch[2])) {
               foreach (array_unique($aMatch[2]) as $i => $sName) {
                   $aReturn[] = '<a href="https://www.imdb.com/search/title?genres=' . IMDBHelper::cleanString(
                           $aMatch[1][$i]
                       ) . '"' . ($sTarget ? ' target="' . $sTarget . '"' : '') . '>' . IMDBHelper::cleanString(
                           $sName
                       ) . '</a>';
               }

               return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound, $aReturn);
           }
       }

       return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound);
   }

   /**
    * @return string cumulative worldwide gross or $sNotFound.
    */
   public function getGross()
   {
       if (true === $this->isReady) {
           $sMatch = IMDBHelper::matchRegex($this->sSource, self::IMDB_GROSS, 1);
           if (false !== $sMatch) {
               return IMDBHelper::cleanString($sMatch);
           }
       }

       return self::$sNotFound;
   }

   /**
    * @return string A list with the languages or $sNotFound.
    */
   public function getLanguage()
   {
       if (true === $this->isReady) {
           $sMatch = $this->getLanguageAsUrl();
           if (self::$sNotFound !== $sMatch) {
               return IMDBHelper::cleanString($sMatch);
           }
       }

       return self::$sNotFound;
   }

   /**
    * @param string $sTarget Add a target to the links?
    *
    * @return string A list with the linked languages or $sNotFound.
    */
   public function getLanguageAsUrl($sTarget = '')
   {
       if (true === $this->isReady) {
           $aMatch  = IMDBHelper::matchRegex($this->sSource, self::IMDB_LANGUAGE);
           $aReturn = [];
           if (count($aMatch[2])) {
               foreach ($aMatch[2] as $i => $sName) {
                   $aReturn[] = '<a href="https://www.imdb.com/language/' . IMDBHelper::cleanString(
                           $aMatch[1][$i]
                       ) . '"' . ($sTarget ? ' target="' . $sTarget . '"' : '') . '>' . IMDBHelper::cleanString(
                           $sName
                       ) . '</a>';
               }

               return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound, $aReturn);
           }
       }

       return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound);
   }

   /**
    * @return string A list with the location or $sNotFound.
    */
   public function getLocation()
   {
       if (true === $this->isReady) {
           $sMatch = $this->getLocationAsUrl();
           if (self::$sNotFound !== $sMatch) {
               return IMDBHelper::cleanString($sMatch);
           }
       }

       return self::$sNotFound;
   }

   /**
    * @param string $sTarget Add a target to the links?
    *
    * @return string A list with the linked location or $sNotFound.
    */
   public function getLocationAsUrl($sTarget = '')
   {
       if (true === $this->isReady) {
           $aMatch  = IMDBHelper::matchRegex($this->sSource, self::IMDB_LOCATION);
           $aReturn = [];
           if (count($aMatch[2])) {
               foreach ($aMatch[2] as $i => $sName) {
                   $aReturn[] = '<a href="https://www.imdb.com/search/title?locations=' . IMDBHelper::cleanString(
                           $aMatch[1][$i]
                       ) . '"' . ($sTarget ? ' target="' . $sTarget . '"' : '') . '>' . IMDBHelper::cleanString(
                           $sName
                       ) . '</a>';
               }

               return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound, $aReturn);
           }
       }

       return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound);
   }

   /**
    * Returns all locations
    *
    * @return string location
    * @return string specification
    */
   public function getLocations()
   {
       if (true === $this->isReady) {
           // Does a cache of this movie exist?
           $sCacheFile = 'cache/imdb/' . sha1($this->iId) . '_locations.cache';
           $bUseCache  = false;

           if (is_readable($sCacheFile)) {
               $iDiff = round(abs(time() - filemtime($sCacheFile)) / 60);
               if ($iDiff < $this->iCache || false) {
                   $bUseCache = true;
               }
           }

           if ($bUseCache) {
               $aRawReturn = file_get_contents($sCacheFile);
               $aReturn    = unserialize($aRawReturn);

               return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound, $aReturn);
           } else {
               $fullLocations = sprintf('https://www.imdb.com/title/tt%s/locations', $this->iId);
               $aCurlInfo     = IMDBHelper::runCurl($fullLocations);
               $sSource       = $aCurlInfo['contents'];

               if (false === $sSource) {
                   if (true === self::IMDB_DEBUG) {
                       echo '<pre><b>cURL error:</b> ' . var_dump($aCurlInfo) . '</pre>';
                   }

                   return false;
               }

               $aReturned = IMDBHelper::matchRegex($sSource, self::IMDB_LOCATIONS);

               if ($aReturned) {
                   $aReturn = [];
                   foreach ($aReturned[1] as $i => $strName) {
                       if (strpos($strName, '(') === false) {
                           $aReturn[] = [
                               'location' => IMDBHelper::cleanString($strName),
                           ];
                       }
                       if (strpos($aReturned[2][$i], '(') !== false) {
                           $aReturn[] = [
                               'specification' => IMDBHelper::cleanString($aReturned[2][$i]),
                           ];
                       }
                   }

                   file_put_contents($sCacheFile, serialize($aReturn));

                   return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound, $aReturn);
               }
           }
       }

       return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound);
   }

   /**
    * @return string The MPAA of the movie or $sNotFound.
    */
   public function getMpaa()
   {
       if (true === $this->isReady) {
           $sMatch = IMDBHelper::matchRegex($this->sSource, self::IMDB_MPAA, 1);
           if (false !== $sMatch) {
               return IMDBHelper::cleanString($sMatch);
           }
       }

       return self::$sNotFound;
   }

   /**
    * @return string A list with the plot keywords or $sNotFound.
    */
   public function getPlotKeywords()
   {
       if (true === $this->isReady) {
           $sMatch = IMDBHelper::matchRegex($this->sSource, self::IMDB_PLOT_KEYWORDS, 1);
           if (false !== $sMatch) {
               $aReturn = explode('|', IMDBHelper::cleanString($sMatch));

               return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound, $aReturn);
           }
       }

       return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound);
   }

   /**
    * @param int $iLimit The limit.
    *
    * @return string The plot of the movie or $sNotFound.
    */
   public function getPlot($iLimit = 0)
   {
       if (true === $this->isReady) {
           $sMatch = IMDBHelper::matchRegex($this->sSource, self::IMDB_PLOT, 1);
           if (false !== $sMatch) {
               if ($iLimit !== 0) {
                   return IMDBHelper::getShortText(IMDBHelper::cleanString($sMatch), $iLimit);
               }

               return IMDBHelper::cleanString($sMatch);
           }
       }

       return self::$sNotFound;
   }

   /**
    * @param string $sSize     Small, big, xxs, xs, s poster?
    * @param bool   $bDownload Return URL to the poster or download it?
    *
    * @return bool|string Path to the poster.
    */
   public function getPoster($sSize = 'small', $bDownload = false)
   {
       if (true === $this->isReady) {
           $sMatch = IMDBHelper::matchRegex($this->sSource, self::IMDB_POSTER, 1);
           if (false !== $sMatch) {
               if ('big' === strtolower($sSize) && false !== strstr($sMatch, '@._')) {
                   $sMatch = substr($sMatch, 0, strpos($sMatch, '@._')) . '@.jpg';
               }
               if ('xxs' === strtolower($sSize) && false !== strstr($sMatch, '@._')) {
                   $sMatch = substr($sMatch, 0, strpos($sMatch, '@._')) . '@._V1_UY67_CR0,0,45,67_AL_.jpg';
               }
               if ('xs' === strtolower($sSize) && false !== strstr($sMatch, '@._')) {
                   $sMatch = substr($sMatch, 0, strpos($sMatch, '@._')) . '@._V1_UY113_CR0,0,76,113_AL_.jpg';
               }
               if ('s' === strtolower($sSize) && false !== strstr($sMatch, '@._')) {
                   $sMatch = substr($sMatch, 0, strpos($sMatch, '@._')) . '@._V1_UX182_CR0,0,182,268_AL_.jpg';
               }
               if (false === $bDownload) {
                   return IMDBHelper::cleanString($sMatch);
               } else {
                   $sLocal = IMDBHelper::saveImage($sMatch, $this->iId);
                   if (file_exists($sLocal)) {
                       return $sLocal;
                   } else {
                       return $sMatch;
                   }
               }
           }
       }

       return self::$sNotFound;
   }

   /**
    * @return string The rating of the movie or $sNotFound.
    */
   public function getRating()
   {
       if (true === $this->isReady) {
           $sMatch = IMDBHelper::matchRegex($this->sSource, self::IMDB_RATING, 1);
           if (false !== $sMatch) {
               return IMDBHelper::cleanString($sMatch);
           }
       }

       return self::$sNotFound;
   }

   /**
    * @return string The rating count of the movie or $sNotFound.
    */
   public function getRatingCount()
   {
       if (true === $this->isReady) {
           $sMatch = IMDBHelper::matchRegex($this->sSource, self::IMDB_RATING_COUNT, 1);
           if (false !== $sMatch) {
               return str_replace(',', '', IMDBHelper::cleanString($sMatch));
           }
       }

       return self::$sNotFound;
   }

   /**
    * Release date doesn't contain all the information we need to create a media and
    * we need this function that checks if users can vote target media (if can, it's released).
    *
    * @return  true If the media is released
    */
   public function isReleased()
   {
       $strReturn = $this->getReleaseDate();
       if ($strReturn == self::$sNotFound || $strReturn == 'Not yet released') {
           return false;
       }

       return true;
   }

   /**
    * @return string The release date of the movie or $sNotFound.
    */
   public function getReleaseDate()
   {
       if (true === $this->isReady) {
           $sMatch = IMDBHelper::matchRegex($this->sSource, self::IMDB_RELEASE_DATE, 1);
           if (false !== $sMatch) {
               return IMDBHelper::cleanString($sMatch);
           }
       }

       return self::$sNotFound;
   }

   /**
    * Returns all local names
    *
    * @return string country
    * @return string release date
    */
   public function getReleaseDates()
   {
       if (true === $this->isReady) {
           // Does a cache of this movie exist?
           $sCacheFile = 'cache/imdb/' . sha1($this->iId) . '_akas.cache';
           $bUseCache  = false;

           if (is_readable($sCacheFile)) {
               $iDiff = round(abs(time() - filemtime($sCacheFile)) / 60);
               if ($iDiff < $this->iCache || false) {
                   $bUseCache = true;
               }
           }

           if ($bUseCache) {
               $aRawReturn = file_get_contents($sCacheFile);
               $aReturn    = unserialize($aRawReturn);

               return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound, $aReturn);
           } else {
               $fullAkas  = sprintf('https://www.imdb.com/title/tt%s/releaseinfo', $this->iId);
               $aCurlInfo = IMDBHelper::runCurl($fullAkas);
               $sSource   = $aCurlInfo['contents'];

               if (false === $sSource) {
                   if (true === self::IMDB_DEBUG) {
                       echo '<pre><b>cURL error:</b> ' . var_dump($aCurlInfo) . '</pre>';
                   }

                   return false;
               }

               $aReturned = IMDBHelper::matchRegex(
                   $sSource,
                   '~>(.*)<\/a><\/td>\s+<td class="release_date">(.*)<\/td>~'
               );

               if ($aReturned) {
                   $aReturn = [];
                   foreach ($aReturned[1] as $i => $strName) {
                       if (strpos($strName, '(') === false) {
                           $aReturn[] = [
                               'country'     => IMDBHelper::cleanString($strName),
                               'releasedate' => IMDBHelper::cleanString($aReturned[2][$i]),
                           ];
                       }
                   }

                   file_put_contents($sCacheFile, serialize($aReturn));

                   return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound, $aReturn);
               }
           }
       }

       return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound);
   }

   /**
    * @return string The runtime of the movie or $sNotFound.
    */
   public function getRuntime()
   {
       if (true === $this->isReady) {
           $sMatch = IMDBHelper::matchRegex($this->sSource, self::IMDB_RUNTIME, 1);
           if (false !== $sMatch) {
               return IMDBHelper::cleanString($sMatch);
           }
       }

       return self::$sNotFound;
   }

   /**
    * @return string A list with the seasons or $sNotFound.
    */
   public function getSeasons()
   {
       if (true === $this->isReady) {
           $sMatch = $this->getSeasonsAsUrl();
           if (self::$sNotFound !== $sMatch) {
               return IMDBHelper::cleanString($sMatch);
           }
       }

       return self::$sNotFound;
   }

   /**
    * @param string $sTarget Add a target to the links?
    *
    * @return string A list with the linked seasons or $sNotFound.
    */
   public function getSeasonsAsUrl($sTarget = '')
   {
       if (true === $this->isReady) {
           $aMatch  = IMDBHelper::matchRegex($this->sSource, self::IMDB_SEASONS);
           $aReturn = [];
           if (count($aMatch[1])) {
               foreach (range(1, max($aMatch[1])) as $i => $sName) {
                   $aReturn[] = '<a href="https://www.imdb.com/title/tt' . $this->iId . '/episodes?season=' . $sName . '"' . ($sTarget ? ' target="' . $sTarget . '"' : '') . '>' . $sName . '</a>';
               }

               return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound, $aReturn);
           }
       }

       return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound);
   }

   /**
    * @return string The sound mix of the movie or $sNotFound.
    */
   public function getSoundMix()
   {
       if (true === $this->isReady) {
           $sMatch = IMDBHelper::matchRegex($this->sSource, self::IMDB_SOUND_MIX, 1);
           if (false !== $sMatch) {
               return IMDBHelper::cleanString($sMatch);
           }
       }

       return self::$sNotFound;
   }

   /**
    * @return string The tagline of the movie or $sNotFound.
    */
   public function getTagline()
   {
       if (true === $this->isReady) {
           $sMatch = IMDBHelper::matchRegex($this->sSource, self::IMDB_TAGLINE, 1);
           if (false !== $sMatch) {
               return IMDBHelper::cleanString($sMatch);
           }
       }

       return self::$sNotFound;
   }

   /**
    * @param bool $bForceLocal Try to return the original name of the movie.
    *
    * @return string The title of the movie or $sNotFound.
    */
   public function getTitle($bForceLocal = false)
   {
       if (true === $this->isReady) {
           if (true === $bForceLocal) {
               $sMatch = IMDBHelper::matchRegex($this->sSource, self::IMDB_TITLE_ORIG, 1);
               if (false !== $sMatch && "" !== $sMatch) {
                   return IMDBHelper::cleanString($sMatch);
               }
           }

           $sMatch = IMDBHelper::matchRegex($this->sSource, self::IMDB_TITLE, 1);
           $sMatch = preg_replace('~\(\d{4}\)$~Ui', '', $sMatch);
           if (false !== $sMatch && "" !== $sMatch) {
               return IMDBHelper::cleanString($sMatch);
           }
       }

       return self::$sNotFound;
   }

   /**
    * @param bool $bEmbed Link to player directly?
    *
    * @return string The URL to the trailer of the movie or $sNotFound.
    */
   public function getTrailerAsUrl($bEmbed = false)
   {
       if (true === $this->isReady) {
           $sMatch = IMDBHelper::matchRegex($this->sSource, self::IMDB_TRAILER, 1);
           if (false !== $sMatch) {
               $sUrl = 'https://www.imdb.com/video/imdb/' . $sMatch . '/' . ($bEmbed ? 'player' : '');

               return IMDBHelper::cleanString($sUrl);
           }
       }

       return self::$sNotFound;
   }

   /**
    * @return string The IMDb URL.
    */
   public function getUrl()
   {
       if (true === $this->isReady) {
           return IMDBHelper::cleanString(str_replace('reference', '', $this->sUrl));
       }

       return self::$sNotFound;
   }

   /**
    * @return string The user review of the movie or $sNotFound.
    */
   public function getUserReview()
   {
       if (true === $this->isReady) {
           $sMatch = IMDBHelper::matchRegex($this->sSource, self::IMDB_USER_REVIEW, 1);
           if (false !== $sMatch) {
               return IMDBHelper::cleanString($sMatch);
           }
       }

       return self::$sNotFound;
   }

   /**
    * @return string The votes of the movie or $sNotFound.
    */
   public function getVotes()
   {
       if (true === $this->isReady) {
           $sMatch = IMDBHelper::matchRegex($this->sSource, self::IMDB_VOTES, 1);
           if (false !== $sMatch) {
               return IMDBHelper::cleanString($sMatch);
           }
       }

       return self::$sNotFound;
   }

   /**
    * @return string A list with the writers or $sNotFound.
    */
   public function getWriter()
   {
       if (true === $this->isReady) {
           $sMatch = $this->getWriterAsUrl();
           if (self::$sNotFound !== $sMatch) {
               return IMDBHelper::cleanString($sMatch);
           }
       }

       return self::$sNotFound;
   }

   /**
    * @param string $sTarget Add a target to the links?
    *
    * @return string A list with the linked writers or $sNotFound.
    */
   public function getWriterAsUrl($sTarget = '')
   {
       if (true === $this->isReady) {
           $sMatch  = IMDBHelper::matchRegex($this->sSource, self::IMDB_WRITER, 1);
           $aMatch  = IMDBHelper::matchRegex($sMatch, self::IMDB_NAME);
           $aReturn = [];
           if (count($aMatch[2])) {
               foreach ($aMatch[2] as $i => $sName) {
                   $aReturn[] = '<a href="https://www.imdb.com/name/' . IMDBHelper::cleanString(
                           $aMatch[1][$i]
                       ) . '/"' . ($sTarget ? ' target="' . $sTarget . '"' : '') . '>' . IMDBHelper::cleanString(
                           $sName
                       ) . '</a>';
               }

               return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound, $aReturn);
           }
       }

       return self::$sNotFound;
   }

   /**
    * @return string The year of the movie or $sNotFound.
    */
   public function getYear()
   {
       if (true === $this->isReady) {
           $sMatch = IMDBHelper::matchRegex($this->sSource, self::IMDB_YEAR, 1);
           if (false !== $sMatch) {
               return IMDBHelper::cleanString($sMatch);
           }
       }

       return self::$sNotFound;
   }

   /**
    * @return string The budget of the movie or $sNotFound.
    */
   public function getBudget()
   {
       if (true === $this->isReady) {
           $sMatch = IMDBHelper::matchRegex($this->sSource, self::IMDB_BUDGET, 1);
           if (false !== $sMatch) {
               return IMDBHelper::cleanString($sMatch);
           }
       }

       return self::$sNotFound;
   }
}

class IMDBHelper extends IMDBnew
{
   /**
    * Regular expression helper.
    *
    * @param string $sContent The content to search in.
    * @param string $sPattern The regular expression.
    * @param null   $iIndex   The index to return.
    *
    * @return bool   If no match was found.
    * @return string If one match was found.
    * @return array  If more than one match was found.
    */
   public static function matchRegex($sContent, $sPattern, $iIndex = null)
   {
       preg_match_all($sPattern, $sContent, $aMatches);
       if ($aMatches === false) {
           return false;
       }
       if ($iIndex !== null && is_int($iIndex)) {
           if (isset($aMatches[$iIndex][0])) {
               return $aMatches[$iIndex][0];
           }

           return false;
       }

       return $aMatches;
   }

   /**
    * Preferred output in responses with multiple elements
    *
    * @param bool   $bArrayOutput Native array or string with separators.
    * @param string $sSeparator   String separator.
    * @param string $sNotFound    Not found text.
    * @param array  $aReturn      Original input.
    * @param bool   $bHaveMore    Have more elements indicator.
    *
    * @return string|array Multiple results separated by selected separator string, or enclosed into native array.
    */
   public static function arrayOutput($bArrayOutput, $sSeparator, $sNotFound, $aReturn = null, $bHaveMore = false)
   {
       if ($bArrayOutput) {
           if ($aReturn == null || ! is_array($aReturn)) {
               return [];
           }

           if ($bHaveMore) {
               $aReturn[] = '…';
           }

           return $aReturn;
       } else {
           if ($aReturn == null || ! is_array($aReturn)) {
               return $sNotFound;
           }

           foreach ($aReturn as $i => $value) {
               if (is_array($value)) {
                   $aReturn[$i] = implode($sSeparator, $value);
               }
           }

           return implode($sSeparator, $aReturn) . (($bHaveMore) ? '…' : '');
       }
   }

   /**
    * @param string $sInput Input (eg. HTML).
    *
    * @return string Cleaned string.
    */
   public static function cleanString($sInput)
   {
       $aSearch  = [
           'Full summary &raquo;',
           'Full synopsis &raquo;',
           'Add summary &raquo;',
           'Add synopsis &raquo;',
           'See more &raquo;',
           'See why on IMDbPro.',
           "\n",
           "\r",
       ];
       $aReplace = [
           '',
           '',
           '',
           '',
           '',
           '',
           '',
           '',
       ];
       $sInput   = str_replace('</li>', ' | ', $sInput);
       $sInput   = strip_tags($sInput);
       $sInput   = str_replace('&nbsp;', ' ', $sInput);
       $sInput   = str_replace($aSearch, $aReplace, $sInput);
       $sInput   = html_entity_decode($sInput, ENT_QUOTES | ENT_HTML5);
       $sInput   = preg_replace('/\s+/', ' ', $sInput);
       $sInput   = trim($sInput);
       $sInput   = rtrim($sInput, ' |');

       return ($sInput ? trim($sInput) : self::$sNotFound);
   }

   /**
    * @param string $sText   The long text.
    * @param int    $iLength The maximum length of the text.
    *
    * @return string The shortened text.
    */
   public static function getShortText($sText, $iLength = 100)
   {
       if (mb_strlen($sText) <= $iLength) {
           return $sText;
       }

       list($sShort) = explode("\n", wordwrap($sText, $iLength - 1));

       if (substr($sShort, -1) !== '.') {
           return $sShort . '…';
       }

       return $sShort;
   }

   /**
    * @param string $sUrl The URL to the image to download.
    * @param int    $iId  The ID of the movie.
    *
    * @return string Local path.
    */
   public static function saveImage($sUrl, $iId)
   {
       if (preg_match('~title_addposter.jpg|imdb-share-logo.png~', $sUrl)) {
           return 'uploads/imdb/not-found.jpg';
       }

       $sFilename = 'uploads/imdb/' . $iId . '.jpg';
       if (file_exists($sFilename)) {
           return 'uploads/imdb/' . $iId . '.jpg';
       }

       $aCurlInfo = self::runCurl($sUrl, true);
       $sData     = $aCurlInfo['contents'];
       if (false === $sData) {
           return 'uploads/imdb/not-found.jpg';
       }

       $oFile = fopen($sFilename, 'x');
       fwrite($oFile, $sData);
       fclose($oFile);

       return 'uploads/imdb/' . $iId . '.jpg';
   }

   /**
    * @param string $sUrl      The URL to fetch.
    * @param bool   $bDownload Download?
    *
    * @return bool|mixed Array on success, false on failure.
    */
   public static function runCurl($sUrl, $bDownload = false)
   {
       $oCurl = curl_init($sUrl);
       curl_setopt_array(
           $oCurl,
           [
               CURLOPT_BINARYTRANSFER => ($bDownload ? true : false),
               CURLOPT_CONNECTTIMEOUT => self::IMDB_TIMEOUT,
               CURLOPT_ENCODING       => '',
               CURLOPT_FOLLOWLOCATION => 0,
               CURLOPT_FRESH_CONNECT  => 0,
               CURLOPT_HEADER         => ($bDownload ? false : true),
               CURLOPT_HTTPHEADER     => [
                   'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
                   'Accept-Charset: utf-8, iso-8859-1;q=0.5',
                   'Accept-Language: ' . self::IMDB_LANG,
               ],
               CURLOPT_REFERER        => 'https://www.imdb.com',
               CURLOPT_RETURNTRANSFER => 1,
               CURLOPT_SSL_VERIFYHOST => 0,
               CURLOPT_SSL_VERIFYPEER => 0,
               CURLOPT_TIMEOUT        => self::IMDB_TIMEOUT,
               CURLOPT_USERAGENT      => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0',
               CURLOPT_VERBOSE        => 0,
           ]
       );
       $sOutput   = curl_exec($oCurl);
       $aCurlInfo = curl_getinfo($oCurl);
       curl_close($oCurl);
       $aCurlInfo['contents'] = $sOutput;

       if (200 !== $aCurlInfo['http_code'] && 302 !== $aCurlInfo['http_code']) {
           if (true === self::IMDB_DEBUG) {
               echo '<pre><b>cURL returned wrong HTTP code “' . $aCurlInfo['http_code'] . '”, aborting.</b></pre>';
           }

           return false;
       }

       return $aCurlInfo;
   }

   /**
    * @param string $sUrl The URL to the image to download.
    * @param int    $cId  The cast ID of the actor.
    *
    * @return string Local path.
    */
   public static function saveImageCast($sUrl, $cId)
   {
       if ( ! preg_match('~http~', $sUrl)) {
           return 'uploads/cast/not-found.jpg';
       }

       $sFilename = dirname(__FILE__) . '/cast/' . $cId . '.jpg';
       if (file_exists($sFilename)) {
           return 'uploads/cast/' . $cId . '.jpg';
       }

       $aCurlInfo = self::runCurl($sUrl, true);
       $sData     = $aCurlInfo['contents'];
       if (false === $sData) {
           return 'uploads/cast/not-found.jpg';
       }

       $oFile = fopen($sFilename, 'x');
       fwrite($oFile, $sData);
       fclose($oFile);

       return 'uploads/cast/' . $cId . '.jpg';
   }
}


create a file called Testimdb.php (the include is in here classes/  (on pdo this file is controller for v3 normal root file)
For this example we use id 8 please change id to one torrent with imdb link
<?php
class Testimdb extends Controller
{
   public function __construct()
   {
       //$this->countriesModel = $this->model('Countries');
   }
   
   public function index()
   {
       dbconn();
       global $config, $pdo;
       loggedinonly();
       // The new class
       include_once 'classes/IMDBnew.php';
       // replace id for $id = $_GET['id']
       $id = 8;
       // The big var from torrent-details.php
       $res = $pdo->run("SELECT torrents.anon, torrents.seeders, torrents.tube, torrents.banned, torrents.leechers, torrents.info_hash, torrents.filename, torrents.nfo, torrents.last_action, torrents.numratings, torrents.name, torrents.imdb, torrents.owner, torrents.save_as, torrents.descr, torrents.visible, torrents.size, torrents.added, torrents.views, torrents.hits, torrents.times_completed, torrents.id, torrents.type, torrents.external, torrents.image1, torrents.image2, torrents.announce, torrents.numfiles, torrents.freeleech, IF(torrents.numratings < 2, NULL, ROUND(torrents.ratingsum / torrents.numratings, 1)) AS rating, torrents.numratings, categories.name AS cat_name, torrentlang.name AS lang_name, torrentlang.image AS lang_image, categories.parent_cat as cat_parent, users.username, users.privacy FROM torrents LEFT JOIN categories ON torrents.category = categories.id LEFT JOIN torrentlang ON torrents.torrentlang = torrentlang.id LEFT JOIN users ON torrents.owner = users.id WHERE torrents.id = $id");
       $row = $res->fetch(PDO::FETCH_ASSOC);
       // begin layout
       stdhead();
       begin_frame("test");
       // code start

       $oIMDB = new IMDBnew($row['imdb']);
       if ($oIMDB->isReady) {
           echo '<p><a href="'.$oIMDB->getUrl().'">'.$oIMDB->getTitle().'</a> got rated '.$oIMDB->getRating().'</p>';
           echo '<p><img src="'.$oIMDB->getPoster('small', true).'" style="float:left;margin:4px 10px 10px 0;"> <b>About the movie:</b>'.$oIMDB->getPlot().'</p>';
           
           echo '<h2>Cast</h2>';
           $castImages = $oIMDB->getCastImages(5, false, 'small');
           foreach (explode(' / ', $oIMDB->getCast(5, false)) as $name) {
               echo '<img src="' . $castImages[$name] . '" alt="' . $name . '">' . $name . '<br>';
           }

var_dump($oIMDB->getAll());
//Also KnownAs
echo $oIMDB->getAka().'<br>';
//All local names
echo $oIMDB->getAkas().'<br>';
//Aspect Ratio
echo $oIMDB->getAspectRatio().'<br>';
//Awards
echo $oIMDB->getAwards().'<br>';
//Budget
echo $oIMDB->getBudget().'<br>';
//Cast;
echo $oIMDB->getCast($iLimit = 0, $bMore = true).'<br>';// - $iLimit defines the maximum amount of people returned, $bMore if "…" should be added to the string if needed;
//Cast Images
echo $oIMDB->getCastImages($iLimit = 0, $bMore = true, $sSize = 'small', $bDownload = false).'<br>';// - $iLimit defines the maximum amount of people returned, $bMore if "…" should be added to the string if needed, $sSize defines the size of the cast image "small, mid and big", $bDownload if the cast image should be downloaded or not
//Cast (with links)
echo $oIMDB->getCastAsUrl($iLimit = 0, $bMore = true, $sTarget = '').'<br>';// - $iLimit defines the maximum amount of people returned, $bMore if "…" should be added to the string if needed, $sTarget defines a target
//Cast and Character
echo $oIMDB->getCastAndCharacter($iLimit = 0, $bMore = true).'<br>';// - $iLimit defines the maximum amount of people returned, $bMore if "…" should be added to the string if needed
//Cast and Character (with links)
echo $oIMDB->getCastAndCharacterAsUrl($iLimit = 0, $bMore = true, $sTarget = '').'<br>';// - $iLimit defines the maximum amount of people returned, $bMore if "…" should be added to the string if needed, $sTarget defines a target
//Certification
echo $oIMDB->getCertification().'<br>';
//Color
echo $oIMDB->getColor().'<br>';
// Company
echo $oIMDB->getCompany().'<br>';
//Company (with links)
echo $oIMDB->getCompanyAsUrl($sTarget = '').'<br>' ;//- $sTarget defines a target
//Country
echo $oIMDB->getCountry().'<br>';
//Country (with links)
echo $oIMDB->getCountryAsUrl($sTarget = '').'<br>';// - $sTarget defines a target
//creator
echo $oIMDB->getCreator().'<br>';
//Creator (with links)
echo $oIMDB->getCreatorAsUrl($sTarget = '').'<br>';// - $sTarget defines a target
//Description
echo $oIMDB->getDescription().'<br>';
//Director
echo $oIMDB->getDirector().'<br>';
// Director (with links)
echo $oIMDB->getDirectorAsUrl($sTarget = '').'<br>';// - $sTarget defines a target
//Genre
echo $oIMDB->getGenre().'<br>';
//Genre (with links)
echo $oIMDB->getGenreAsUrl($sTarget = '').'<br>';// - $sTarget defines a target
//Gross
echo $oIMDB->getGross().'<br>';// to get cumulative worldwide gross
//Language
echo $oIMDB->getLanguage().'<br>';
//Language (with links)
echo $oIMDB->getLanguageAsUrl($sTarget = '').'<br>';// - $sTarget defines a target
//Location
echo $oIMDB->getLocation().'<br>';
//Location (with links)
echo $oIMDB->getLocationAsUrl($sTarget = '').'<br>';// - $sTarget defines a target
//MPAA
echo $oIMDB->getMpaa().'<br>';
//Plot
echo $oIMDB->getPlot($iLimit = 0) .'<br>';//- $iLimit defines the maximum characters returned
//Plot Keywords
echo $oIMDB->getPlotKeywords().'<br>';
//Poster
echo $oIMDB->getPoster($sSize = 'small', $bDownload = true).'<br>';// - $sSize defines small or big poster size, $bDownload if the poster should be downloaded or not
//Rating
echo $oIMDB->getRating().'<br>';
//Release Date
echo $oIMDB->getReleaseDate().'<br>';
//Release Dates
echo $oIMDB->getReleaseDates().'<br>' ;//returning all release dates for each country
//Runtime
echo $oIMDB->getRuntime().'<br>';
//Seasons
echo $oIMDB->getSeasons().'<br>';
//Seasons (with links)
echo $oIMDB->getSeasonsAsUrl($sTarget = '') .'<br>';//- $sTarget defines a target
//S/ound Mix
echo $oIMDB->getSoundMix().'<br>';
//T/agline
echo $oIMDB->getTagline().'<br>';
//Title
echo $oIMDB->getTitle($bForceLocal = false).'<br>';// - $bForceLocal tries to return the original name of the movie
//Trailer
echo $oIMDB->getTrailerAsUrl($bEmbed = true).'<br>';/// - $bEmbed defines if you want to link to player directly or not.
//Url
echo $oIMDB->getUrl().'<br>';
//User Review
echo $oIMDB->getUserReview().'<br>';
//Votes
echo $oIMDB->getVotes().'<br>';
//Writer
echo $oIMDB->getWriter().'<br>';
//Writer (with links)
echo $oIMDB->getWriterAsUrl($sTarget = '').'<br>';// - $sTarget defines a target
//Year
echo $oIMDB->getYear().'<br>';

           $posterlink = $oIMDB->getTrailerAsUrl();
           ?>
           <iframe src="<?php echo $posterlink ?>imdb/embed?autoplay=false&width=620" style="float:right;margin:4px 10px 10px 0;" width="620" height="480" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true" frameborder="no" scrolling="no"></iframe>
           <?php
       } else {
           echo '<p>Movie not found!</p>';
       }

       // code end
       end_frame();
       stdfoot();
   }
}


notes for v3
you need to change $config to $site_config
include backend/functions.php on test file
Users online
Search



Statistics

    Torrents

  • Tracking: 3
  • Todays torrents: 0
  • Seeders: 0
  • Leechers: 0
  • Peers: 0
  • Downloaded: 89.96 GB
  • Uploaded: 9.86 GB

  • Members

  • We have: 838
  • New today: 0
  • Guest today: 10

  • Online

  • Total online: 4
  • Members: 1
  • Guests online: 3
  • Comments: 3
  • Messages: 1,728