<?php

/**
 * PL9 Forum Icons 1.1
 * 
 * Copyright © 2009 Project Level 9, All Rights Reserved
 *
 * Website: http://www.projectlevel9.com
 * Forum: http://forums.projectlevel9.com
 * PHPTPL PROVIDED BY YUMI OF MYBBOARD.NET COPYRIGHT YUMI 2008 - 2009
 */
 
if(!defined("IN_MYBB"))
    die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");

function pl9forumicons_info()
{
	global $lang;
	
	$lang->load("forum_pl9forumicons");

    return array(
        "name"          => $lang->pl9_forum_icons,
        "description"   => $lang->pl9_forum_icons_desc,
        "website"       => "http://forums.projectlevel9.com",
        "author"        => "Steve Moore",
        "authorsite"    => "http://www.projectlevel9.com",
        "version"       => "1.1",
        "guid" 			=> "33a4ae3af077c412cb29c9bb578c826d",
		"compatibility" => "14*"
    );
}

function pl9forumicons_install()
{
	global $mybb, $db;

	$db->write_query("ALTER TABLE `". TABLE_PREFIX . "forums` ADD `forum_icon` VARCHAR( 155 ) NOT NULL");

	global $db, $mybb;

     $group = array(
        "gid"            => "NULL",
        "title"          => "PL9 Forum Icons",
        "name"           => "pl9forumicons",
        "description"    => "Settings for PL9 Forum Icons.",
        "disporder"      => "1",
        "isdefault"      => "no",
    );
    
    $db->insert_query("settinggroups", $group);
    $gid = $db->insert_id(); //This will get the id of the just added record in the db
    
    
    $setting_1 = array(
        "sid"            => "NULL",
        "name"           => "enable_pl9ForumIcons",
        "title"          => "Enable PL9 Forum Icons",
        "description"    => "Enable/Disable PL9 Forum Icons?",
        "optionscode"    => "yesno",
        "value"          => 'yes',
        "disporder"      => '1',
        "gid"            => intval($gid),
    );

    $db->insert_query("settings", $setting_1);
    rebuild_settings();
}

function pl9forumicons_is_installed()
{
	global $mybb, $db;

	return $db->field_exists("forum_icon", "forums");
}

function pl9forumicons_uninstall()
{
	global $db, $mybb;

	$db->write_query("ALTER TABLE `". TABLE_PREFIX . "forums` DROP `forum_icon`");

    $db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='enable_pl9ForumIcons'");
    $db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='pl9forumicons'");
    rebuild_settings();
}

//All the activation processes go here
function pl9forumicons_activate()
{
    require MYBB_ROOT.'/inc/adminfunctions_templates.php';
    find_replace_templatesets("forumbit_depth2_forum", '#'.preg_quote('<img src="{$theme[\'imgdir\']}/{$lightbulb[\'folder\']}.gif" alt="{$lightbulb[\'altonoff\']}" title="{$lightbulb[\'altonoff\']}" class="ajax_mark_read" id="mark_read_{$forum[\'fid\']}" />').'#' , '<if $mybb->settings[\'enable_pl9ForumIcons\'] then><if $forum[\'forum_icon\'] then><img src="{$forum[\'forum_icon\']}" alt="{$lightbulb[\'altonoff\']}" title="{$lightbulb[\'altonoff\']}" class="ajax_mark_read" id="mark_read_{$forum[\'fid\']}" /><else /><img src="{$theme[\'imgdir\']}/{$lightbulb[\'folder\']}.gif" alt="{$lightbulb[\'altonoff\']}" title="{$lightbulb[\'altonoff\']}" class="ajax_mark_read" id="mark_read_{$forum[\'fid\']}" /></if><else /><img src="{$theme[\'imgdir\']}/{$lightbulb[\'folder\']}.gif" alt="{$lightbulb[\'altonoff\']}" title="{$lightbulb[\'altonoff\']}" class="ajax_mark_read" id="mark_read_{$forum[\'fid\']}" /></if>');
 }

//All deactivation processes go here
function pl9forumicons_deactivate()
{
    require MYBB_ROOT.'/inc/adminfunctions_templates.php';
    find_replace_templatesets("forumbit_depth2_forum", '#'.preg_quote('<if $mybb->settings[\'enable_pl9ForumIcons\'] then><if $forum[\'forum_icon\'] then><img src="{$forum[\'forum_icon\']}" alt="{$lightbulb[\'altonoff\']}" title="{$lightbulb[\'altonoff\']}" class="ajax_mark_read" id="mark_read_{$forum[\'fid\']}" /><else /><img src="{$theme[\'imgdir\']}/{$lightbulb[\'folder\']}.gif" alt="{$lightbulb[\'altonoff\']}" title="{$lightbulb[\'altonoff\']}" class="ajax_mark_read" id="mark_read_{$forum[\'fid\']}" /></if><else /><img src="{$theme[\'imgdir\']}/{$lightbulb[\'folder\']}.gif" alt="{$lightbulb[\'altonoff\']}" title="{$lightbulb[\'altonoff\']}" class="ajax_mark_read" id="mark_read_{$forum[\'fid\']}" /></if>').'#s' , '<img src="{$theme[\'imgdir\']}/{$lightbulb[\'folder\']}.gif" alt="{$lightbulb[\'altonoff\']}" title="{$lightbulb[\'altonoff\']}" class="ajax_mark_read" id="mark_read_{$forum[\'fid\']}" />',0);
} 
?>