Title: Auto Smiley Insert v1.0

Author: Adam Clarke

Updated By: John Briggs

Description:
This mod will add add the ability to automatically insert smilies from the smilies directory.
This mod will add add the ability to automatically insert post icons from the smilies directory.

Copyright:  2005 Adam Clarke. All rights reserved.
Copyright:  2006 John Briggs. All rights reserved.

Compatability: XMB 1.9.5 Final

Install Note: Before adding this mod to your forum, you should back up all files related to this mod.

License Note: This mod is released under the GPL License. A copy is provided with this software.

Author Note:
You downloaded this hack from XMBMods.com, the #1 source for XMB related downloads.
Please visit http://www.xmbmods.com/ for support.

=======================================================================================================================================
=======
Step 1:
=======

==================
Edit File: cp2.php
==================

==========
Find Code:
==========

        <tr bgcolor="<?php echo $altbg1?>" class="tablerow">
        <td><?php echo $lang['textnewsmilie']?></td>
        <td><input type="text" name="newcode" /></td>
        <td colspan="2"><input type="text" name="newurl1" /></td>
        </tr>

===============
Add Code Below:
===============

        <tr class="ctrtablerow">
        <td bgcolor="<?php echo $altbg1?>"><input type="checkbox" name="autoinsertsmilies" value="1" /></td>
        <td bgcolor="<?php echo $altbg1?>" colspan="3"><?php echo $lang['autoinsertsmilies']?> (<?php echo $smdir?>)?</td>
        </tr>

==========
Find Code:
==========

        <tr bgcolor="<?php echo $altbg1?>" class="tablerow">
        <td colspan="4" align="left"><?php echo $lang['textnewpicon']?>&nbsp;&nbsp;<input type="text" name="newurl2" /></td>
        </tr>

===============
Add Code Below:
===============

        <tr class="tablerow">
        <td bgcolor="<?php echo $altbg1?>" align="center"><input type="checkbox" name="autoinsertposticons" value="1" /></td>
        <td bgcolor="<?php echo $altbg1?>" colspan="3"><?php echo $lang['autoinsertposticons']?> (<?php echo $smdir?>)?</td>
        </tr>

==========
Find Code:
==========

        if (isset($newcode) && $newcode != "") {
            // make sure we don't already have one like that
            if ($db->result($db->query("SELECT count(id) FROM $table_smilies WHERE code='$newcode'"), 0) > 0) {
                error($lang['smilieexists'], false, '</td></tr></table></td></tr></table><br />');
            }
            $query = $db->query("INSERT INTO $table_smilies ( type, code, url, id ) VALUES ('smiley', '$newcode', '$newurl1', '')");
        }

===============
Add Code Below:
===============

        if (isset($autoinsertsmilies) && $autoinsertsmilies == 1) {
            $smilies_count = $newsmilies_count = 0;
            // Load all existing smilies to ensure we don't insert a duplicate.
            $smiley_url = array();
            $smiley_code = array();
            $query = $db->query("SELECT * FROM $table_smilies WHERE type = 'smiley'");
            while ($smiley = $db->fetch_array($query)) {
                $smiley_url[] = $smiley['url'];
                $smiley_code[] = $smiley['code'];
            }
            $db->free_result($query);

            $dir = opendir($smdir);
            while ($smiley = readdir($dir)) {
                if ($smiley != '.' && $smiley != '..' && (strpos($smiley, '.gif') || strpos($smiley, '.jpg') || strpos($smiley, '.jpeg') || strpos($smiley, '.bmp') || strpos($smiley, '.png'))) {
                    $newsmiley_url = $smiley;
                    $newsmiley_code = $smiley;
                    $newsmiley_code = str_replace(array('.gif','.jpg','.jpeg','.bmp','.png','_'), array('','','','','',' '), $newsmiley_code);
                    $newsmiley_code = ':' . $newsmiley_code . ':';
                    if (!in_array($newsmiley_url, $smiley_url) && !in_array($newsmiley_code, $smiley_code)) {
                        $query = $db->query("INSERT INTO $table_smilies (type, code, url, id) VALUES ('smiley', '$newsmiley_code', '$newsmiley_url', '')");
                        $newsmilies_count++;
                    }
                    $smilies_count++;
                }
            }
            closedir($dir);
            echo '<tr bgcolor="'.$altbg2.'" class="ctrtablerow"><td>'.$newsmilies_count.' / '.$smilies_count.' '.$lang['smiliesadded'].'</td></tr>';
        }

==========
Find Code:
==========

        if (isset($newurl2) && $newurl2 != "") {
            if ($db->result($db->query("SELECT count(id) FROM $table_smilies WHERE url='$newurl2' AND type='picon'"), 0) > 0) {
                error($lang['piconexists'], false, '</td></tr></table></td></tr></table><br />');
            }
            $query = $db->query("INSERT INTO $table_smilies ( type, code, url, id ) VALUES ('picon', '', '$newurl2', '')");
        }

===============
Add Code Below:
===============

        if (isset($autoinsertposticons) && $autoinsertposticons == 1) {
            $posticons_count = $newposticons_count = 0;
            // Load all existing post icons to ensure we don't insert a duplicate.
            $posticon_url = array();
            $query = $db->query("SELECT * FROM $table_smilies WHERE type='picon'");
            while ($picon = $db->fetch_array($query)) {
                $posticon_url[] = $picon['url'];
            }
            $db->free_result($query);

            $dir = opendir($smdir);
            while ($picon = readdir($dir)) {
                if ($picon != '.' && $picon != '..' && (strpos($picon, '.gif') || strpos($picon, '.jpg') || strpos($picon, '.jpeg') || strpos($picon, '.bmp') || strpos($picon, '.png'))) {
                    $newposticon_url = $picon;
                    $newposticon_url = str_replace(' ', '%20', $newposticon_url);
                    if (!in_array($newposticon_url, $posticon_url)) {
                        $query = $db->query("INSERT INTO $table_smilies (type, code, url, id) VALUES ('picon', '', '$newposticon_url', '')");
                        $newposticons_count++;
                    }
                    $posticons_count++;
                }
            }
            closedir($dir);
            echo '<tr bgcolor="'.$altbg2.'" class="ctrtablerow"><td>'.$newposticons_count.' / '.$posticons_count.' '.$lang['posticonsadded'].'</td></tr>';
        }

=======================================================================================================================================
=======
Step 2:
=======

==========================
Edit File English.lang.php
==========================

================================
Add Code At Very Bottom Of File:
================================

$lang['autoinsertsmilies'] = "Insert all smilies from smilies directory";
$lang['autoinsertposticons'] = "Insert all post icons from smilies directory";
$lang['smiliesadded'] = "Smilies Have Been Added.";
$lang['posticonsadded'] = "Post Icons Have Been Added.";

=======================================================================================================================================
=======
Step 3:
=======

Upload all your smilies to the smilies directory and then goto Admin Panel -> Smilies.
Check the auto insert check box for smiles and/or post icons and click Submit Changes.

=======================================================================================================================================