Customizing / Hacking

 
Jump to :
   

 Smileys menagement page   
posted by ds on 2005-28-11 08:05
               
       
 hits: 2722
attachments:
Add in include/form.php in javascript section these functions:

function storeCaret (textEl) {
if (navigator.appName.indexOf('Netscape') != -1) return true;
if (textEl.createTextRange)
textEl.caretPos = document.selection.createRange().duplicate();
}

function insertAtCaret (textEl, text) {
if (textEl.createTextRange && textEl.caretPos) {
var caretPos = textEl.caretPos;
caretPos.text = ' ' + text + ' ';
} else
textEl.value = textEl.value + ' ' + text + ' ';
}

function smile(smile) {
if (navigator.appName.indexOf('Netscape') != -1) {
document.form0.body.value += " " + smile + " ";
document.form0.body.focus();
} else {
insertAtCaret(document.form0.body, smile);
document.form0.body.focus();
}
}


Then find below

# ------------------------------------------------------------
# Display form
# ------------------------------------------------------------

and replace smileys help page with smileys.php?bn=$bn

Open forums/site/default/form.php (or your actual form template) and add in textarea tag attributes

ONSELECT="storeCaret(this);" ONCLICK="storeCaret(this);" ONKEYUP="storeCaret(this);" ONLOAD="storeCaret(this);"

Create directory images/smiles and make chmod 0777 images/smiles

copy all old smileys from images/icons to this directory

Upload in agora root directory attached file:
 
<?

require ("init.inc");
require (
"$cfg_file");

//to be moved in lang file
define ('ERROR_FILE_EXISTS''Такой файл уже есть');
define ('LABEL_CLICK_SMILE''Нажмите на смайлик');
define ('LABEL_COUNT_SMILEYS','Всего смайликов %s'); //$sm_count   
define ('LABEL_ALL_PAGES''Все страницы: '); //possible defined for
browse_thread.php

$path 
'images/smiles';
$sm_per_page 30;
if (!isset(
$pag)) $pag 1;
$navbar '';
$smileys read_smileys($path); 

if(
$is_moderator && (isset($_REQUEST['upload']))) {
    
$file $_FILES['file'];
    
$tmp $file['tmp_name'];
    if (@
file_exists($tmp)) {
        
$info = @getimagesize($tmp);
        if (
$info['mime'] != 'image/gif') die(ERROR_INVALID_FILE_TYPE);
        
$hashes create_hashes($path);
        if (
in_array(md5(file_get_contents($tmp)),$hashes))
die(
ERROR_FILE_EXISTS);
        
$dest $file['name'];
       
        
$i 1
        while (
array_key_exists($dest,$hashes) ||
array_key_exists(":".str_replace(".gif",""$dest).":",$smileys)) {
            
$dest "sm".$i.".gif";
            
$i++;            
        }
        
$smileys[":".str_replace(".gif",""$dest).":"] = str_replace(".gif","",
$dest);
        
move_uploaded_file($tmp,$path."/".$dest);
    }
}

$sm_count count($smileys);
if ((
$sm_count $sm_per_page) && ($pag != 'all')) {
    
$smileys array_chunk($smileys,$sm_per_page,TRUE);
    
$navbar .= ($pag 1) ? "<a href='smileys.$ext?bn=$bn&pag=".($pag-1)."'
title='"
.ALT_PREV_PAGE."'>&lt;&lt;&lt;</a>n" "";
    
$navbar .= "&nbsp;&nbsp;&nbsp;";
    
$navbar .= ($pag count($smileys)) ? "<a
href='smileys.$ext?bn=$bn&pag="
.($pag+1)."'
title='"
.ALT_NEXT_PAGE."'>&gt;&gt;&gt;</a>n" "";
    
$navbar .= "<br>n";
    
$navbar .= LABEL_ALL_PAGES;
    for (
$p=1$p <= count($smileys); $p++) {
        
$navbar .= ($p != $pag) ? "<a href='smileys.$ext?bn=$bn&pag=$p'
title='"
.sprintf(LABEL_PAGES_NUMBER,$p)."'><small>[$p]</small></a> n" :
"<b><small>[$p]</small></b> n";
    }

    
$smileys $smileys[$pag-1];
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HEAD>
<TITLE><?=LABEL_SMILEYS_HELP?></TITLE>
<SCRIPT type="text/javascript" language="JavaScript"> 
function smile(smile) {
    opener.smile(smile);
    close();
}
</SCRIPT>
<?
        
if (!empty($bn_style) && file_exists ("$bn_dir/$bn_style")) {
            echo 
"<!-- STYLE -->n";
            include 
"$bn_dir/$bn_style";
        } elseif (
file_exists ("$bn_dir_default/style.$ext") ) {
            include 
"$bn_dir_default/style.$ext";
        }
?>
</HEAD>
<HTML>
<body bgcolor="#f5eee6">
<CENTER>
<h3><?=LABEL_CLICK_SMILE?></h3><br>
<small><?printf(LABEL_COUNT_SMILEYS,$sm_count);?></small><br>
<?=$navbar?> 
<TABLE width="80%" bgcolor=#DEDFDF border=0>
<tr>
<td align='center' bgColor=#FEF5ED>
Обозначение
</td>
<td align='center' bgColor=#FEF5ED>
Смайлик
</td>
</tr>
<tr>
<?

$i 
1;
foreach (
$smileys as $k => $v) {
    echo 
"<td align='center' bgColor=#FEF5ED>$k</td>n";
    echo 
"<td align='center' bgColor=#FEF5ED><a
href="javascript:smile('$k')"><img src='$path/$v.gif' title='$k' alt='$k'
border=0></a></td>n"
;
    echo 
"</tr>n<tr>n";
}

?>
</tr>
</TABLE>
<?
if ($is_moderator) {
?>
<TABLE width="80%" bgcolor=#DEDFDF border=0>
<tr>
<td align='center' bgColor=#FEF5ED>
<form method='POST' enctype='multipart/form-data'
action='<?$_SERVER['SCRIPT_NAME']?>'>
<input type='file' name='file'><input type='submit' name='upload'
value='<?=LABEL_UPLOAD_NEW_FILE?>'>
</form>
</td>
</tr>
</table>
<?}?>
<?=$navbar?>
</CENTER>
</body>
<?
$db
->closeDB(); 
//create array of MD5 hashes
function create_hashes ($path) {
    
    
//open dir
    
$d dir($path);
  
    while (
false !== ($entry $d->read())) {
        
//not interest directories
        
if ($entry == '.' || $entry == '..') continue;
        
//but only images
        
if (preg_match("/.gif$/i",$entry)) {
            if (
is_file($path."/".$entry)) {
                
$hashes[$entry] = md5(file_get_contents($path."/".$entry));
            }
        }

    }

    
$d->close(); 
    return 
$hashes;  
}

//read smileys to an array
function read_smileys ($path) {
    
    
//open dir
    
$d dir($path);
    
    
//here is old smileys menaged by agora
    
$smileys = array ( 
        
":D" => "icon10",
        
":O" => "icon11",
        
":-)" => "icon7",
        
";-)" => "icon12",
        
"X-(" => "icon8",
        
":-(" => "icon9",
        
":-p" => "icon39",
        
":logo:" => "icon50",
        
":wahoo:" => "icon42",
        
":crazy:" => "icon41",
        
":hello:" => "icon40",
        
":sweat:" => "icon38",
        
":spookie:" => "icon37",
        
":benetton:" => "icon36",
        
":jap:" => "icon35",
        
":sleep:" => "icon34",
        
":bic:" => "icon33",
        
":sarcastic:" => "icon32",
        
":gun:" => "icon31",
        
":fou:" => "icon30",
        
":love:" => "icon29",
        
":lol:" => "icon28",
        
":sol:" => "icon27",
        
":hot:" => "icon26",
        
":hap:" => "icon25",
        
":eek:" => "icon24",
        
":ouch:" => "icon23",
        
":cry:" => "icon22",
        
":what:" => "icon21",
        
":bounce:" => "icon20",
        
":roll:" => "roll",
        
":kill:" => "kill"
    
);    
    
$d dir($path); 
    while (
false !== ($entry $d->read())) {
        
//not interest directories
        
if ($entry == '.' || $entry == '..') continue;
        
//but only images
        
if (preg_match("/.gif$/i",$entry)) {
            if (
is_file($path."/".$entry)) {
                
$entry str_replace('.gif','',$entry);
                if (
in_array($entry,$smileys)) continue;
                
$smileys[':'.$entry.':'] = $entry;
            }
        } 
    }
    
$d->close(); 
    return 
$smileys;
}
?>

   
  Topics Posted by Date
*  Smileys menagement page PHP script RUSK 2005-28-11 08:05
      Re: Smileys menagement page RUSK 2005-28-11 08:12
      Re: Smileys menagement page RUSK 2005-28-11 08:21
      Re: Smileys menagement page RUSK 2005-28-11 08:37
      Re: Smileys menagement page marc 2005-28-11 12:31
         Re: Smileys menagement page RUSK 2005-01-12 09:30
            Re: Smileys menagement page marc 2005-05-12 11:11