8
Mar

Minor videodb mod – allow adding genres

   Posted by: Roguetech   in PHP programming, videodb

Did a new mod to videodb. To be able to add custom genres, and automatically add imdb genres:

OPEN edit.php
FIND

// check if genre is found- otherwise fail silently
if (is_numeric($genre = getGenreId($gname)))
{
$genres[] = $genre;
}


REPLACE WITH

// BEGIN MOD - add genres
/*
// check if genre is found- otherwise fail silently
if (is_numeric($genre = getGenreId($gname)))
{
$genres[] = $genre;
}
*/

// check if genre is found- otherwise add genre
if (is_numeric($genre = getGenreId($gname)))
{
$genres[] = $genre;
} elseif(!empty($gname)) {
$genres[]=addGenre($gname);
}
// END MOD

OPEN core/genres.php
FIND

$SELECT = 'SELECT genres.id, genres.name
                 FROM '
.TBL_GENRES.' AS genres, '.TBL_VIDEOGENRE.' AS videogenre
                WHERE genres.id = videogenre.genre_id
                  AND videogenre.video_id = '
.$id;

AFTER, ADD

// BEGIN MOD - genres
$SELECT .= ' ORDER BY genres.name';
// END MOD

FIND

runSQL('INSERT INTO '.TBL_VIDEOGENRE.' SET video_id = '.$id.', genre_id = '.$genre);

REPLACE WITH

// BEGIN MOD - custom genres
/*
            runSQL('INSERT INTO '.TBL_VIDEOGENRE.' SET video_id = '.$id.', genre_id = '.$genre);
*/

if(!empty($genre)){
        if(!is_numeric($genre)){
                $genre=runSQL('INSERT INTO '. TBL_GENRES.' SET name="'.addslashes($genre).'"');
        }
            runSQL('INSERT INTO '.TBL_VIDEOGENRE.' SET video_id = '.$id.', genre_id = '.$genre);
                }
// END MOD

OPEN /templates/elegant/edit.tpl
FIND

{$genreselect}

AFTER, ADD

{* BEGIN MOD - custom genres *}
<label for="other">New genre: </label><input id="other" maxlength="32" name="genres[]" size="15" type="text" />
{* END MOD *}

[edit] Made a mistake. Selecting "Add missing" won't add genres the way originally written. To fix this:
OPEN edit.php
FIND:

if (count($genres) == 0 || ($lookup > 1))

REPLACE WITH:

// BEGIN MOD
/*
    if (count($genres) == 0 || ($lookup > 1))
*/

    if (count($genres) == 1 || ($lookup > 1))
// END MOD
This entry was posted on Monday, March 8th, 2010 at 5:19 pm and is filed under PHP programming, videodb. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

2 comments so far

LagmashFlooms
 1 

i seriously adore all your posting kind, very helpful,
don’t quit as well as keep writing considering it simply that is worth to look through it,
looking forward to browse through a lot more of your own well written articles, kind regards!

March 27th, 2010 at 6:11 pm
Gicci
 2 

I don’t think I’ve seen this depicted that way before. You actually have made this so much clearer for me. Thank you!

April 5th, 2010 at 3:03 am

Leave a reply

You must be logged in to post a comment.