Вход Регистрация
Файл: admin/admin_smilies.php
Строк: 322
<?php
/***************************************************************************
*                               admin_smilies.php
*                              -------------------
 *      Разработка: phpBB Group.
 *      Оптимизация под WAP: Гутник Игорь ( чел ).
 *          2009 год
**************************************************************************/

define('IN_PHPBB'1);

if( !empty(
$setmodules) )
{
    
$filename basename(__FILE__);
    
$module['General']['Smilies'] = $filename;

    return;
}

$phpbb_root_path "./../";
require(
$phpbb_root_path 'extension.inc');
$cancel = ( isset($_POST['cancel']) || isset($_POST['cancel']) ) ? true false;
$no_page_header $cancel;

if ((!empty(
$_GET['export_pack']) && $_GET['export_pack'] == 'send') || (!empty($_GET['export_pack']) && $_GET['export_pack'] == 'send'))
{
    
$no_page_header true;
}

require(
'./pagestart.' $phpEx);

if (
$cancel)
{
    
redirect('admin/' append_sid("admin_smilies.$phpEx"true));
}

if( isset(
$_POST['mode']) || isset($_GET['mode']) )
{
    
$mode = ( isset($_POST['mode']) ) ? $_POST['mode'] : $_GET['mode'];
    
$mode htmlspecialchars($mode);
}
else
{
    
$mode "";
}

$delimeter  '=+:';

$dir = @opendir($phpbb_root_path $board_config['smilies_path']);

while(
$file = @readdir($dir))
{
    if( !@
is_dir(phpbb_realpath($phpbb_root_path $board_config['smilies_path'] . '/' $file)) )
    {
        
$img_size = @getimagesize($phpbb_root_path $board_config['smilies_path'] . '/' $file);

        if( 
$img_size[0] && $img_size[1] )
        {
            
$smiley_images[] = $file;
        }
        else if( 
eregi('.pak$'$file) )
        {    
            
$smiley_paks[] = $file;
        }
    }
}

@
closedir($dir);

if( isset(
$_GET['import_pack']) || isset($_POST['import_pack']) )
{

    
$smile_pak = ( isset($_POST['smile_pak']) ) ? $_POST['smile_pak'] : $_GET['smile_pak'];
    
$clear_current = ( isset($_POST['clear_current']) ) ? $_POST['clear_current'] : $_GET['clear_current'];
    
$replace_existing = ( isset($_POST['replace']) ) ? $_POST['replace'] : $_GET['replace'];

    if ( !empty(
$smile_pak) )
    {

        if( !empty(
$clear_current)  )
        {
            
$sql "DELETE 
                FROM " 
SMILIES_TABLE;
            if( !
$result $db->sql_query($sql) )
            {
                
message_die(GENERAL_ERROR"Couldn't delete current smilies"""__LINE____FILE__$sql);
            }
        }
        else
        {
            
$sql "SELECT code 
                FROM "
SMILIES_TABLE;
            if( !
$result $db->sql_query($sql) )
            {
                
message_die(GENERAL_ERROR"Couldn't get current smilies"""__LINE____FILE__$sql);
            }

            
$cur_smilies $db->sql_fetchrowset($result);

            for( 
$i 0$i count($cur_smilies); $i++ )
            {
                
$k $cur_smilies[$i]['code'];
                
$smiles[$k] = 1;
            }
        }

        
$fcontents = @file($phpbb_root_path $board_config['smilies_path'] . '/'$smile_pak);

        if( empty(
$fcontents) )
        {
            
message_die(GENERAL_ERROR"Couldn't read smiley pak file"""__LINE____FILE__$sql);
        }

        for( 
$i 0$i count($fcontents); $i++ )
        {
            
$smile_data explode($delimetertrim(addslashes($fcontents[$i])));

            for( 
$j 2$j count($smile_data); $j++)
            {

                
$smile_data[$j] = str_replace("<""&lt;"$smile_data[$j]);
                
$smile_data[$j] = str_replace(">""&gt;"$smile_data[$j]);
                
$k $smile_data[$j];

                if( 
$smiles[$k] == )
                {
                    if( !empty(
$replace_existing) )
                    {
                        
$sql "UPDATE " SMILIES_TABLE 
                            SET smile_url = '" 
str_replace("'""''"$smile_data[0]) . "', emoticon = '" str_replace("'""''"$smile_data[1]) . "' 
                            WHERE code = '" 
str_replace("'""''"$smile_data[$j]) . "'";
                    }
                    else
                    {
                        
$sql '';
                    }
                }
                else
                {
                    
$sql "INSERT INTO " SMILIES_TABLE " (code, smile_url, emoticon)
                        VALUES('" 
str_replace("'""''"$smile_data[$j]) . "', '" str_replace("'""''"$smile_data[0]) . "', '" str_replace("'""''"$smile_data[1]) . "')";
                }

                if( 
$sql != '' )
                {
                    
$result $db->sql_query($sql);
                    if( !
$result )
                    {
                        
message_die(GENERAL_ERROR"Couldn't update smilies!"""__LINE____FILE__$sql);
                    }
                }
            }
        }

        
$message $lang['smiley_import_success'] . "<br /><br />" sprintf($lang['Click_return_smileadmin'], "<a href="" . append_sid("admin_smilies.$phpEx") . "">""</a>") . "<br /><br />" sprintf($lang['Click_return_admin_index'], "<a href="" . append_sid("index.$phpEx?pane=right") . "">""</a>");

        
message_die(GENERAL_MESSAGE$message);
        
    }
    else
    {

        
$smile_paks_select "<select name='smile_pak'><option value=''>" $lang['Select_pak'] . "</option>";
        while( list(
$key$value) = @each($smiley_paks) )
        {
            if ( !empty(
$value) ) 
            {
                
$smile_paks_select .= "<option>" $value "</option>";
            }
        }
        
$smile_paks_select .= "</select>";

        
$hidden_vars "<input type='hidden' name='mode' value='import'>";    

        
$template->set_filenames(array(
            
"body" => "admin/smile_import_body.tpl")
        );

        
$template->assign_vars(array(
            
"L_SMILEY_TITLE" => $lang['smiley_title'],
            
"L_SMILEY_EXPLAIN" => $lang['smiley_import_inst'],
            
"L_SMILEY_IMPORT" => $lang['smiley_import'],
            
"L_SELECT_LBL" => $lang['choose_smile_pak'],
            
"L_IMPORT" => $lang['import'],
            
"L_CONFLICTS" => $lang['smile_conflicts'],
            
"L_DEL_EXISTING" => $lang['del_existing_smileys'], 
            
"L_REPLACE_EXISTING" => $lang['replace_existing'], 
            
"L_KEEP_EXISTING" => $lang['keep_existing'], 

            
"S_SMILEY_ACTION" => append_sid("admin_smilies.$phpEx"),
            
"S_SMILE_SELECT" => $smile_paks_select,
            
"S_HIDDEN_FIELDS" => $hidden_vars)
        );
        }
        
$template->pparse("body");
    }

else if( isset(
$_POST['export_pack']) || isset($_GET['export_pack']) )
{

    if ( 
$_GET['export_pack'] == "send" )
    {    
        
$sql "SELECT * 
            FROM " 
SMILIES_TABLE;
        if( !
$result $db->sql_query($sql) )
        {
            
message_die(GENERAL_ERROR"Could not get smiley list"""__LINE____FILE__$sql);
        }

        
$resultset $db->sql_fetchrowset($result);

        
$smile_pak "";
        for(
$i 0$i count($resultset); $i++ )
        {
            
$smile_pak .= $resultset[$i]['smile_url'] . $delimeter;
            
$smile_pak .= $resultset[$i]['emoticon'] . $delimeter;
            
$smile_pak .= $resultset[$i]['code'] . "n";
        }

        
header("Content-Type: text/x-delimtext; name="smiles.pak"");
        
header("Content-disposition: attachment; filename=smiles.pak");

        echo 
$smile_pak;

        exit;
    }

    
$message sprintf($lang['export_smiles'], "<a href="" . append_sid("admin_smilies.$phpEx?export_pack=send", true) . "">""</a>") . "<br /><br />" sprintf($lang['Click_return_smileadmin'], "<a href="" . append_sid("admin_smilies.$phpEx") . "">""</a>") . "<br /><br />" sprintf($lang['Click_return_admin_index'], "<a href="" . append_sid("index.$phpEx?pane=right") . "">""</a>");

    
message_die(GENERAL_MESSAGE$message);

}
else if( isset(
$_POST['add']) || isset($_GET['add']) )
{

    
$template->set_filenames(array(
        
"body" => "admin/smile_edit_body.tpl")
    );
###############
$sql "SELECT * FROM FOR_smilies_cat ORDER BY id ASC ";
$smiles_cat_list '';
if (
$result $db->sql_query($sql))
    {
while (
$row $db->sql_fetchrow($result))
{
$smiles_cat_list .=' <option value="'.$row['id'].'">'.$row['cat_title'].'</option> ';
}}

##############
    
$filename_list "";
    for( 
$i 0$i count($smiley_images); $i++ )
    {
        
$filename_list .= '<option value="' $smiley_images[$i] . '">' $smiley_images[$i] . '</option>';
    }

    
$s_hidden_fields '<input type="hidden" name="mode" value="savenew" />';

    
$template->assign_vars(array(
    
"SMILES_CAT"=> $smiles_cat_list,
        
"L_SMILEY_TITLE" => $lang['smiley_title'],
        
"L_SMILEY_CONFIG" => $lang['smiley_config'],
        
"L_SMILEY_EXPLAIN" => $lang['smile_desc'],
        
"L_SMILEY_CODE" => $lang['smiley_code'],
        
"L_SMILEY_URL" => $lang['smiley_url'],
        
"L_SMILEY_EMOTION" => $lang['smiley_emot'],
        
"L_SUBMIT" => $lang['Submit'],
        
"L_RESET" => $lang['Reset'],

        
"SMILEY_IMG" => $phpbb_root_path $board_config['smilies_path'] . '/' $smiley_images[0], 

        
"S_SMILEY_ACTION" => append_sid("admin_smilies.$phpEx"), 
        
"S_HIDDEN_FIELDS" => $s_hidden_fields
        
"S_FILENAME_OPTIONS" => $filename_list
        
"S_SMILEY_BASEDIR" => $phpbb_root_path $board_config['smilies_path'])
    );

    
$template->pparse("body");
}
else if ( 
$mode != "" )
{
    switch( 
$mode )
    {
        case 
'delete':

            
$smiley_id = ( !empty($_POST['id']) ) ? $_POST['id'] : $_GET['id'];
            
$smiley_id intval($smiley_id);

            
$confirm = isset($_POST['confirm']);

            if( 
$confirm )
            {
                
$sql "DELETE FROM " SMILIES_TABLE "
                    WHERE smilies_id = " 
$smiley_id;
                
$result $db->sql_query($sql);
                if( !
$result )
                {
                    
message_die(GENERAL_ERROR"Couldn't delete smiley"""__LINE____FILE__$sql);
                }

                
$message $lang['smiley_del_success'] . "<br /><br />" sprintf($lang['Click_return_smileadmin'], "<a href="" . append_sid("admin_smilies.$phpEx") . "">""</a>") . "<br /><br />" sprintf($lang['Click_return_admin_index'], "<a href="" . append_sid("index.$phpEx?pane=right") . "">""</a>");

                
message_die(GENERAL_MESSAGE$message);
            }
            else
            {
                
$template->set_filenames(array(
                    
'body' => 'admin/confirm_body.tpl')
                );

                
$hidden_fields '<input type="hidden" name="mode" value="delete" /><input type="hidden" name="id" value="' $smiley_id '" />';

                
$template->assign_vars(array(
                    
'MESSAGE_TITLE' => $lang['Confirm'],
                    
'MESSAGE_TEXT' => $lang['Confirm_delete_smiley'],

                    
'L_YES' => $lang['Yes'],
                    
'L_NO' => $lang['No'],

                    
'S_CONFIRM_ACTION' => append_sid("admin_smilies.$phpEx"),
                    
'S_HIDDEN_FIELDS' => $hidden_fields)
                );
                
$template->pparse('body');
            }
            break;

        case 
'edit':

            
$smiley_id = ( !empty($_POST['id']) ) ? $_POST['id'] : $_GET['id'];
            
$smiley_id intval($smiley_id);

            
$sql "SELECT *
                FROM " 
SMILIES_TABLE "
                WHERE smilies_id = " 
$smiley_id;
            
$result $db->sql_query($sql);
            if( !
$result )
            {
                
message_die(GENERAL_ERROR'Could not obtain emoticon information'""__LINE____FILE__$sql);
            }
            
$smile_data $db->sql_fetchrow($result);
###############
$sql "SELECT * FROM FOR_smilies_cat ORDER BY id ASC ";
$smiles_cat_list '';
if (
$result $db->sql_query($sql))
    {
while (
$row $db->sql_fetchrow($result))
{
$smiles_cat_list .=' <option value="'.$row['id'].'">'.$row['cat_title'].'</option> ';
}}

##############
            
$filename_list "";
            for( 
$i 0$i count($smiley_images); $i++ )
            {
                if( 
$smiley_images[$i] == $smile_data['smile_url'] )
                {
                    
$smiley_selected "selected="selected"";
                    
$smiley_edit_img $smiley_images[$i];
                }
                else
                {
                    
$smiley_selected "";
                }

                
$filename_list .= '<option value="' $smiley_images[$i] . '"' $smiley_selected '>' $smiley_images[$i] . '</option>';
            }

            
$template->set_filenames(array(
                
"body" => "admin/smile_edit_body.tpl")
            );

            
$s_hidden_fields '<input type="hidden" name="mode" value="save" /><input type="hidden" name="smile_id" value="' $smile_data['smilies_id'] . '" />';

            
$template->assign_vars(array(
            
"SMILES_CAT" => $smiles_cat_list
                
"SMILEY_CODE" => $smile_data['code'],
                
"SMILEY_EMOTICON" => $smile_data['emoticon'],

                
"L_SMILEY_TITLE" => $lang['smiley_title'],
                
"L_SMILEY_CONFIG" => $lang['smiley_config'],
                
"L_SMILEY_EXPLAIN" => $lang['smile_desc'],
                
"L_SMILEY_CODE" => $lang['smiley_code'],
                
"L_SMILEY_URL" => $lang['smiley_url'],
                
"L_SMILEY_EMOTION" => $lang['smiley_emot'],
                
"L_SUBMIT" => $lang['Submit'],
                
"L_RESET" => $lang['Reset'],

                
"SMILEY_IMG" => $phpbb_root_path $board_config['smilies_path'] . '/' $smiley_edit_img

                
"S_SMILEY_ACTION" => append_sid("admin_smilies.$phpEx"),
                
"S_HIDDEN_FIELDS" => $s_hidden_fields
                
"S_FILENAME_OPTIONS" => $filename_list
                
"S_SMILEY_BASEDIR" => $phpbb_root_path $board_config['smilies_path'])
            );

            
$template->pparse("body");
            break;

        case 
"save":

            
$smile_code = ( isset($_POST['smile_code']) ) ? trim($_POST['smile_code']) : '';
            
$smile_url = ( isset($_POST['smile_url']) ) ? trim($_POST['smile_url']) : '';
            
$smile_url phpbb_ltrim(basename($smile_url), "'");
            
##########
            
$smile_cat_id = ( isset($_POST['smile_cat_id']) ) ? $_POST['smile_cat_id'] : '';
            
##########
            
$smile_emotion = ( isset($_POST['smile_emotion']) ) ? htmlspecialchars(trim($_POST['smile_emotion'])) : '';
            
$smile_id = ( isset($_POST['smile_id']) ) ? intval($_POST['smile_id']) : 0;
            
$smile_code trim($smile_code);
            
$smile_url trim($smile_url);

            if (
$smile_code == '' || $smile_url == '')
            {
                
message_die(GENERAL_MESSAGE$lang['Fields_empty']);
            }

            
$smile_code str_replace('<''&lt;'$smile_code);
            
$smile_code str_replace('>''&gt;'$smile_code);

            
$sql "UPDATE " SMILIES_TABLE "
                SET smile_cat = 
$smile_cat_id , code = '" str_replace("'""''"$smile_code) . "', smile_url = '" str_replace("'""''"$smile_url) . "', emoticon = '" str_replace("'""''"$smile_emotion) . "'
                WHERE smilies_id = 
$smile_id";
            if( !(
$result $db->sql_query($sql)) )
            {
                
message_die(GENERAL_ERROR"Couldn't update smilies info"""__LINE____FILE__$sql);
            }

            
$message $lang['smiley_edit_success'] . "<br /><br />" sprintf($lang['Click_return_smileadmin'], "<a href="" . append_sid("admin_smilies.$phpEx") . "">""</a>") . "<br /><br />" sprintf($lang['Click_return_admin_index'], "<a href="" . append_sid("index.$phpEx?pane=right") . "">""</a>");

            
message_die(GENERAL_MESSAGE$message);
            break;

        case 
"savenew":

            
$smile_code = ( isset($_POST['smile_code']) ) ? $_POST['smile_code'] : '';
            
$smile_url = ( isset($_POST['smile_url']) ) ? $_POST['smile_url'] : '';
            
##########
            
$smile_cat_id = ( isset($_POST['smile_cat_id']) ) ? $_POST['smile_cat_id'] : '';
            
##########
            
$smile_url phpbb_ltrim(basename($smile_url), "'");
            
$smile_emotion = ( isset($_POST['smile_emotion']) ) ? htmlspecialchars(trim($_POST['smile_emotion'])) : '';
            
$smile_code trim($smile_code);
            
$smile_url trim($smile_url);

            if (
$smile_code == '' || $smile_url == '')
            {
                
message_die(GENERAL_MESSAGE$lang['Fields_empty']);
            }

            
$sql "INSERT INTO " SMILIES_TABLE " (smile_cat, code, smile_url, emoticon)
                VALUES ('"
.$smile_cat_id."','" str_replace("'""''"$smile_code) . "', '" str_replace("'""''"$smile_url) . "', '" str_replace("'""''"$smile_emotion) . "')";
            
$result $db->sql_query($sql);
            if( !
$result )
            {
                
message_die(GENERAL_ERROR"Couldn't insert new smiley"""__LINE____FILE__$sql);
            }

            
$message $lang['smiley_add_success'] . "<br /><br />" sprintf($lang['Click_return_smileadmin'], "<a href="" . append_sid("admin_smilies.$phpEx") . "">""</a>") . "<br /><br />" sprintf($lang['Click_return_admin_index'], "<a href="" . append_sid("index.$phpEx?pane=right") . "">""</a>");

            
message_die(GENERAL_MESSAGE$message);
            break;
    }
}
else
{

    
$sql "SELECT *
        FROM " 
SMILIES_TABLE;
    
$result $db->sql_query($sql);
    if( !
$result )
    {
        
message_die(GENERAL_ERROR"Couldn't obtain smileys from database"""__LINE____FILE__$sql);
    }

    
$smilies $db->sql_fetchrowset($result);

    
$template->set_filenames(array(
        
"body" => "admin/smile_list_body.tpl")
    );

    
$template->assign_vars(array(
        
"L_ACTION" => $lang['Action'],
        
"L_SMILEY_TITLE" => $lang['smiley_title'],
        
"L_SMILEY_TEXT" => $lang['smile_desc'],
        
"L_DELETE" => $lang['Delete'],
        
"L_EDIT" => $lang['Edit'],
        
"L_SMILEY_ADD" => $lang['smile_add'],
        
"L_CODE" => $lang['Code'],
        
"L_EMOT" => $lang['Emotion'],
        
"L_SMILE" => $lang['Smile'],
        
"L_IMPORT_PACK" => $lang['import_smile_pack'],
        
"L_EXPORT_PACK" => $lang['export_smile_pack'],
        
        
"S_HIDDEN_FIELDS" => $s_hidden_fields
        
"S_SMILEY_ACTION" => append_sid("admin_smilies.$phpEx"))
    );

    for(
$i 0$i count($smilies); $i++)
    {

        
$smilies[$i]['code'] = str_replace('&lt;''<'$smilies[$i]['code']);
        
$smilies[$i]['code'] = str_replace('&gt;''>'$smilies[$i]['code']);
        
        
$row_color '';
        
$row_class = ( !($i 2) ) ? 'row_easy' 'row_hard';

        
$template->assign_block_vars("smiles", array(
            
"ROW_COLOR" => "#" $row_color,
            
"ROW_CLASS" => $row_class,
            
            
"SMILEY_IMG" =>  $phpbb_root_path $board_config['smilies_path'] . '/' $smilies[$i]['smile_url'], 
            
"CODE" => $smilies[$i]['code'],
            
"EMOT" => $smilies[$i]['emoticon'],
            
"U_SMILEY_EDIT" => append_sid("admin_smilies.$phpEx?mode=edit&amp;id=" $smilies[$i]['smilies_id']), 
            
"U_SMILEY_DELETE" => append_sid("admin_smilies.$phpEx?mode=delete&amp;id=" $smilies[$i]['smilies_id']))
        );
    }

    
$template->pparse("body");
}

include(
'./page_footer_admin.'.$phpEx);

?>
Онлайн: 2
Реклама