Commit 1c183339 authored by Nico Schallehn's avatar Nico Schallehn

getCastAsOwn

parent ccbc8c7d
......@@ -85,7 +85,7 @@ class IMDB
/**
* These are the regular expressions used to extract the data.
* If you don’t know what you’re doing, you shouldn’t touch them.
* If you don’t know what you’re doing, you shouldn’t touch them.
*/
const IMDB_AKA = '~<h5>Also Known As:<\/h5>(?:\s*)<div class="info-content">(?:\s*)"(.*)"~Ui';
const IMDB_ASPECT_RATIO = '~<h5>Aspect Ratio:<\/h5>(?:\s*)<div class="info-content">(.*)<\/div>~Ui';
......@@ -134,10 +134,10 @@ class IMDB
public function __construct($sSearch, $iCache = null, $sSearchFor = 'all') {
$this->sRoot = dirname(__FILE__);
if ( ! is_writable($this->sRoot . '/posters') && ! mkdir($this->sRoot . '/posters')) {
throw new IMDBException('The directory “' . $this->sRoot . '/posters” isn’t writable.');
throw new IMDBException('The directory “' . $this->sRoot . '/posters� isn’t writable.');
}
if ( ! is_writable($this->sRoot . '/cache') && ! mkdir($this->sRoot . '/cache')) {
throw new IMDBException('The directory “' . $this->sRoot . '/cache” isn’t writable.');
throw new IMDBException('The directory “' . $this->sRoot . '/cache� isn’t writable.');
}
if ( ! function_exists('curl_init')) {
throw new IMDBException('You need to enable the PHP cURL extension.');
......@@ -279,7 +279,7 @@ class IMDB
}
/**
* @return string “Also Known As” or $sNotFound.
* @return string “Also Known As� or $sNotFound.
*/
public function getAka() {
if (true === $this->isReady) {
......@@ -350,7 +350,7 @@ class IMDB
}
/**
* @return string “Aspect Ratio” or $sNotFound.
* @return string “Aspect Ratio� or $sNotFound.
*/
public function getAspectRatio() {
if (true === $this->isReady) {
......@@ -379,7 +379,7 @@ class IMDB
/**
* @param int $iLimit How many cast members should be returned?
* @param bool $bMore Add if there are more cast members than printed.
* @param bool $bMore Add … if there are more cast members than printed.
*
* @return string A list with cast members or $sNotFound.
*/
......@@ -394,7 +394,7 @@ class IMDB
$aReturn[] = IMDBHelper::cleanString($sName);
}
$bMore = (0 !== $iLimit && $bMore && (count($aMatch[2]) > $iLimit) ? '' : '');
$bMore = (0 !== $iLimit && $bMore && (count($aMatch[2]) > $iLimit) ? '…' : '');
$bHaveMore = ($bMore && (count($aMatch[2]) > $iLimit));
......@@ -407,7 +407,7 @@ class IMDB
/**
* @param int $iLimit How many cast members should be returned?
* @param bool $bMore Add if there are more cast members than printed.
* @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.
......@@ -431,10 +431,30 @@ class IMDB
return self::$sNotFound;
}
public function getCastAsOwn($iLimit = 0, $bMore = true, $sTarget = '') {
if (true === $this->isReady) {
$aMatch = IMDBHelper::matchRegex($this->sSource, self::IMDB_CAST);
if (count($aMatch[2])) {
foreach ($aMatch[2] as $i => $sName) {
if (0 !== $iLimit && $i >= $iLimit) {
break;
}
$aReturn[] = '' . IMDBHelper::cleanString($aMatch[1][$i]) . '>' . IMDBHelper::cleanString($sName) . '|';
}
$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.
* @param bool $bMore Add … if there are more cast members than printed.
*
* @return string A list with cast members and their character or
* $sNotFound.
......@@ -462,7 +482,7 @@ class IMDB
/**
* @param int $iLimit How many cast members should be returned?
* @param bool $bMore Add if there are more cast members than
* @param bool $bMore Add … if there are more cast members than
* printed.
* @param string $sTarget Add a target to the links?
*
......@@ -1230,7 +1250,7 @@ class IMDBHelper extends IMDB
}
if ($bHaveMore) {
$aReturn[] = '';
$aReturn[] = '…';
}
return $aReturn;
......@@ -1245,7 +1265,7 @@ class IMDBHelper extends IMDB
}
}
return implode($sSeparator, $aReturn) . (($bHaveMore) ? '' : '');
return implode($sSeparator, $aReturn) . (($bHaveMore) ? '…' : '');
}
}
......@@ -1292,7 +1312,7 @@ class IMDBHelper extends IMDB
list($sShort) = explode("\n", wordwrap($sText, $iLength - 1));
if (substr($sShort, -1) !== '.') {
return $sShort . '';
return $sShort . '…';
}
return $sShort;
......@@ -1326,7 +1346,7 @@ class IMDBHelper extends IMDB
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>';
echo '<pre><b>cURL returned wrong HTTP code “' . $aCurlInfo['http_code'] . '�, aborting.</b></pre>';
}
return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment