MyBB Community Forums

Full Version: IMDB Movie Tag issues
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I'm using this plugin, and for the most part it's working great. However, I'm having certain random problems with it.

For instance, titles with certain characters don't display correctly.

Here is a film titled "Them!". As you can see, the name isn't displaying properly:
[Image: QP5BGzn.png]

Here is another example of the cartoon "Ed, Edd n Eddy" where both the name and picture are messed up:
[Image: syVhewE.png]

Finally, here's an example of a perfect instance, where everything is correct:
[Image: TeRTxbr.png]

Here is the plugin code:
<?php
/**
 *	Copyright © 2018 Thor2705, e.ignea [at] edidesign [dot] ro
 *
 *	This program is free software: you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License as published by
 *	the Free Software Foundation, either version 3 of the License, or
 *	(at your option) any later version.
 *
 *	This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License
 *	along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

$plugins->add_hook("parse_message_start", "movietag_start");
$plugins->add_hook("parse_message_end", "movietag_end");

function movietag_info()
{
	return array(
		"name"			=> "Movies Info",
		"description"	=> "A plugin that allows you to show details of a movie.",
		"website"		=> "http://www.edidesign.ca",
		"author"		=> "Thor2705",
		"authorsite"	=> "http://www.edidesign.ca",
		"version"		=> "1.0",
		"guid" 			=> " ",
		"compatibility" => "18*"
	);
}

function movietag_install() {
	
	global $db, $cache, $movielink, $mybb;
	
$db->write_query("CREATE TABLE `".TABLE_PREFIX."movielink` (
`gid` INT(10) NOT NULL AUTO_INCREMENT,
`vid` CHAR(4) NOT NULL,
`title` TEXT NOT NULL,
`website` TEXT NOT NULL,
PRIMARY KEY (`gid`), 
KEY `vid` (`vid`)
) ENGINE=MyISAM".$db->build_create_table_collation().";");

	
	$query = $db->simple_select("settinggroups", "COUNT(*) as movierows");
	$movierows = $db->fetch_field($query, "movierows");
	$insertarray = array(
		'name' => 'movielink', 
		'title' => 'Movie Link', 
		'description' => 'Movie Link',
		'disporder' => $movierows+1, 
		'isdefault' => 0
	);
	$gid = $db->insert_query("settinggroups", $insertarray);
	$insertarray = array(
		'name' => 'moviek_enable',
		'title' => 'Movie Link Switch',
		'description' => 'Turns on or off Movie Link.',
		'optionscode' => 'onoff',
		'value' => 1,
		'disporder' => 0,
		'gid' => $gid
	);
	$db->insert_query("settings", $insertarray);

	$setting1 = array(
		"name"			=> 'APIKEY',
		"title"			=> "Api Key",
		"description"		=> "Insert your Api Key",
		"optionscode"		=> 'text',
		"value"			=> "your OMDB key here",
		"disporder"		=> 1,
		"gid"			=> $gid
	);
	

$db->insert_query("settings", $setting1);
	rebuild_settings();
	
}
function movietag_is_installed(){
	global $db;
	if($db->table_exists("movielink")){
		return true;
	}
	return false;
	}

function movietag_uninstall(){
	
	global $db, $mybb;
	$db->write_query("DROP TABLE `".TABLE_PREFIX."movielink`;");
	$query = $db->query("SELECT * FROM ".TABLE_PREFIX."settinggroups WHERE name='movielink'");
	$setting_group = $db->fetch_array($query);
	$db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE gid='".$setting_group['gid']."'");
	$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE gid='".$setting_group['gid']."'");
	$db->delete_query("settinggroups", "name = 'movielink'");
	rebuild_settings();
	

}
function movietag_deactivate()
{
	
}

function get_movie_data($id)
{
		global $lang, $mybb, $settings;
		
	
	
		$lang->load("movietag");
		$apiky = $settings['APIKEY'];
		$url = 'http://www.omdbapi.com/?i=tt'.$id.'&plot=full'.'&apikey='.$apiky;
        $ch = curl_init();
        $timeout = 10;
        curl_setopt($ch,CURLOPT_URL,$url);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
        $data = curl_exec($ch);
        curl_close($ch);
		if ($apiky !== "your OMDB key here"){
		$url2 = 'http://img.omdbapi.com/?i=tt'.$id.'&apikey='.$apiky;//.'&plot=full';
		$poster = "[IMG]".$url2."[/IMG]";
		preg_match('/[^\"Title\"\:\"][\w\- .]+/', $data, $title);
		$title = array_values($title)[0];
		if ($title !== "Response")   {
		if($title){ $title = "[SIZE=xx-large][COLOR=#c3ffff][B]".$title."[/B][/COLOR][/SIZE]\n"; }  //$type = ucfirst($type);
		preg_match('/","Type":"(movie|series|episode|game)/', $data, $type);
		$type = array_values($type)[1];
		if ($type == "movie" or $type == "game") { 
		$url2 = 'http://img.omdbapi.com/?i=tt'.$id.'&apikey='.$apiky;
		$poster = "[IMG]".$url2."[/IMG]";
		$type = ucfirst($type); $type = "[B]{$lang->imdbtag_type}[/B]".$type."\n"; }
		 elseif ($type == "series") {
		$url2 = 'http://img.omdbapi.com/?i=tt'.$id.'&apikey='.$apiky;
		$poster = "[IMG]".$url2."[/IMG]";
		 preg_match('/","totalSeasons":"([0-9]{1,2})/', $data, $seasons);
		$seasons = array_values($seasons)[1]; $type = ucfirst($type);
		$type = "[B]{$lang->imdbtag_type}[/B]".$type."\n"."[B]{$lang->imdbtag_seasons}[/B]".$seasons."\n";
		 }
		  elseif ($type == "episode") {
		 preg_match('/","Poster":"(https?:\/\/images-na.[a-zA-Z0-9\.\/\_\-\@]+)(\")/', $data, $poster);
		$poster = array_values($poster)[1];
		$poster = "[IMG]".$poster."[/IMG]";
		preg_match('/","Season":"([0-9]{1,2})/', $data, $season1);
		$season1 = array_values($season1)[1];
		preg_match('/","Episode":"([0-9]{1,2})/', $data, $episode1);
		$episode1 = array_values($episode1)[1];		
		$type = ucfirst($type);
		 $type = "[B]{$lang->imdbtag_type}[/B]".$type."\n"."[B]{$lang->imdbtag_season1}[/B]".$season1."\n"."[B]{$lang->imdbtag_episode}[/B]".$episode1."\n";
		 }
		preg_match('/","Year":"(\d{4})/', $data, $year);
		$year = array_values($year)[1];
		if($year){ $year = "[B]{$lang->imdbtag_year}[/B]".$year."\n"; }
		preg_match('/","Rated":"([PGTVNRCYMA1347-]{1,5})/', $data, $rated);
		$rated = array_values($rated)[1];
		if ($rated == "PG" || $rated =="G") {$rated = "[B][color=green]".$rated."[/color][/B]";;}
		elseif ($rated =="PG-13" || $rated =="R") {$rated = "[B][color=orange]".$rated."[/color][/B]";}
		elseif ($rated =="TV-PG" || $rated =="TV-14") {$rated = "[B][color=orange]".$rated."[/color][/B]";}
		elseif ($rated =="TV-Y" || $rated == "TV-Y7" || $rated == "TV-G") {$rated = "[B][color=green]".$rated."[/color][/B]";}
		elseif ($rated =="NC-17") {$rated = "[B][color=red]".$rated."[/color][/B]";}
		elseif ($rated =="TV-MA") {$rated = "[B][color=red]".$rated."[/color][/B]";}
		if($rated){ $rated = "[B]{$lang->imdbtag_rated}[/B]".$rated."\n"; } 
		preg_match('/"Runtime":"([0-9a-z ]{5,8})/', $data, $runtime);
		$runtime = array_values($runtime)[1];
		if($runtime){ $runtime = "[B]{$lang->imdbtag_runtime}[/B]".$runtime."\n"; }
		preg_match('/","Director":"([a-zA-Z0-9 ]{3,})/',$data, $director);
		$director = array_values($director)[1];
		if($director){ $director = "[B]{$lang->imdbtag_director}[/B]".$director."\n"; }
		for ($b = 0; $b < $a; $b++ ) {  
	}
		preg_match('/","Genre":"([a-zA-Z0-9 \,\.\'\_\-]{3,})/',$data,$genre);
		$genre = array_values($genre)[1];
		if($genre){ $genre = "[B]{$lang->imdbtag_genre}[/B]".$genre."\n"; }
		preg_match('/","Plot":"(.+)(?=","L)/', $data, $plot);
		$plot = array_values($plot)[1];
		if($plot){ $plot = "[B]{$lang->imdbtag_plot}[/B]".$plot."\n"; }
		preg_match('/","Actors":"([a-zA-Z0-9 \,]{3,})/',$data,$cast);
		$casts = array_values($cast)[1];
		if($casts){ $casts = "[B]{$lang->imdbtag_cast}[/B]".$casts."\n"; }   //"Language":"English", Country":"USA",
		preg_match('/"Language":"([a-zA-Z0-9 \,]{3,})/', $data, $language);
		$language = array_values($language)[1];
		if($language){ $language = "[B]{$lang->imdbtag_language}[/B]".$language."\n"; }
		preg_match('/"Country":"([a-zA-Z \,]{3,})/', $data, $country);
		$country = array_values($country)[1];
		if($country){ $country = "[B]{$lang->imdbtag_country}[/B]".$country."\n"; }
		$url3 = 'http://www.imdb.com/title/tt'.$id;
		$imdblink = "[B]{$lang->imdbtag_page}[/B] [URL]".$url3."[/URL]";
		preg_match('/","Website":"([^\"]*)/', $data, $url4);
		$url4 = array_values($url4)[1];
		if ($url4 !== "N/A" && $url4 !== NULL) {
		$weblink = "[B]{$lang->imdbtag_website}[/B] [URL]".$url4."[/URL]";}
		$output = "[IMDBSTYLE][POSTER]".$poster."[/POSTER]\n[DETAILS]".$title.$type.$year.$rated.$runtime.$director.$rating.$imrating.$star.$imvotes.$genre.$tagline.$plot.$awards.$casts.$language.$country."\n\n".$imdblink."\n".$weblink."[/DETAILS][/IMDBSTYLE]";
		}
		elseif ($title == "Response") { 
		preg_match('/","Error":"([a-zA-Z0-9 \,\.\'\_\-\\/\:\@]{3,})/', $data, $error);
		$error = array_values($error)[1];
		$output = "[IMDBSTYLE][SIZE=large][B]".$error."[/B][/SIZE]\n\n[/IMDBSTYLE]";}
		}
		elseif ($apiky == "your OMDB key here") {$error1 = "Error: Invalid API key!"; $output = "[IMDBSTYLE][SIZE=large][B]".$error1."[/B][/SIZE]\n\n[/IMDBSTYLE]";}
        return $output;
}

function movietag_start(&$message)
{
	global $lang;
	
	$lang->load("movietag");
	$message = preg_replace('/(https?:\/\/(?:www\.)?imdb\.com\/title\/tt([0-9]{7})([a-z0-9\_\=\?\/]*))/', "[oimdb]$2[/oimdb]", $message);
	$message = preg_replace_callback("#\[oimdb\]([0-9]{0,10})\[\/oimdb\]#", function ($m) { return get_movie_data($m[1]); }, $message);
}

function movietag_end(&$message)
{
	global $lang;
	
	$lang->load("movietag");
	
	$firsttable = '<table class="imdb">';
	$postertable = '<tr><td width="25%" align="center" valign="middle">';
	$postertable_end = '</td>';
	$detailstable = '<td style="padding: 8px;" width="75%" align="left" valign="middle">';
	$imagine = '<img src="';
	$imagine_end = '" border="0" alt="*" />';
	$detailstable_end = '</td></tr>';
	$lasttable = '</table>';
	
	$message = str_replace("[IMDBSTYLE]", $firsttable, $message);
	$message = str_replace("[POSTER]", $postertable, $message);
	$message = str_replace("[/POSTER]", $postertable_end, $message);
	$message = str_replace("[DETAILS]", $detailstable, $message);
	$message = str_replace("[IMAGINE]", $imagine, $message);
	$message = str_replace("[/IMAGINE]", $imagine_end, $message);
	$message = str_replace("[/DETAILS]", $detailstable_end, $message);
	$message = str_replace("[/IMDBSTYLE]", $lasttable, $message);
}
	
?>

Does anyone know what the issue could be?

Edit: Here's another title mess-up. It deleted the capitol "T" in "The":
https://i.imgur.com/jOfFboh.png

I'm assuming the title problems come down to this line:

preg_match('/[^\"Title\"\:\"][\w\- .]+/', $data, $title);

but unfortunately that's just a bunch of gibberish to me.
First of all, its not IMDB, its using Open Movie Database (OMDB) API.
Secondly, you guessed right, those are the regular expressions (REGEX) to fetch the data from chunk of text received from the API server using pattern matching and clearly the REGEX codes used in the plugin is not efficient.

You need to hire a dev to inspect the API responses applying use case and modify the REGEX code in the plugin to efficiently fetch the data from response. Unfortunately it involves a bit of exercise and time, not possible to troubleshoot upfront.
(2020-11-07, 03:48 PM)effone Wrote: [ -> ]First of all, its not IMDB, its using Open Movie Database (OMDB) API.
Secondly, you guessed right, those are the regular expressions (REGEX) to fetch the data from chunk of text received from the API server using pattern matching and clearly the REGEX codes used in the plugin is not efficient.

You need to hire a dev to inspect the API responses applying use case and modify the REGEX code in the plugin to efficiently fetch the data from response. Unfortunately it involves a bit of exercise and time, not possible to troubleshoot upfront.

Yes, it's using OMDB API. I've only ever simply referenced the literal name of the plugin itself, titled IMDB Movie Tag.

I'm not a coder but have been doing research regarding regex / preg_match and how to use it. The api spits out the title of the movie like this:

"Title":"Name of Movie"

Surely it isn't necessary to "hire a dev" for one single line of code. I'll likely ask for help on reddit or stack overflow or something on how to use preg_match to properly grab the bit where "Name of Movie" is.

Unless I'm missing something, doesn't this just have to be slightly tweaked? - preg_match('/[^\"Title\"\:\"][\w\- .]+/', $data, $title); - Everything else works properly.

Anyway, thanks for the response.
I don't know why the developer used regex at the first place when the API response is in JSON.
You can simply use json_decode() to obtain the exact return values.

I'll try to manage time to look into the plugin codes further...
(2020-11-07, 08:14 PM)effone Wrote: [ -> ]I don't know why the developer used regex at the first place when the API response is in JSON.
You can simply use json_decode() to obtain the exact return values.

I'll try to manage time to look into the plugin codes further...

That's what I was starting to think to after researching OMDB. I'm going to fiddle around with it as much as I can.

Anyway, of course I would be very grateful if you were able to do that, but completely understand if it doesn't/can't happen.

Thanks again
(2020-11-07, 10:17 PM)Omar G. Wrote: [ -> ]You can try alternatives.
https://community.mybb.com/mods.php?acti...w&pid=1380

Wow, great plugin! Thanks for your hard work.
I've just installed it an entered my api key and whatnot, and proceeded to make a test post but nothing seems to be showing anywhere (nor does the popup work).

I'm using a custom theme and wondering do I have to insert a variable into the postbit template or something?

I checked my database and everything is looking good, I guess it's just a matter of getting it to show on my forum.

https://i.imgur.com/uiF8FVJ.png

Okay, so I added "{$ougc_mediainfo_display}" into my showthread template and now that is working! I just have to figure out how to get the popup to work on hover.
It is probably caused because of your custom theme, try to apply the necessary template edits yourself.
https://github.com/Sama34/OUGC-Media-Inf...o.php#L363
(2020-11-08, 12:21 PM)Omar G. Wrote: [ -> ]It is probably caused because of your custom theme, try to apply the necessary template edits yourself.
https://github.com/Sama34/OUGC-Media-Inf...o.php#L363

Thank you for your help, it's all working now.
And thanks for the great plugin! It's awesome.

Just to let you know, "Country" in the language file is misspelled as "County".