#################################################################
## MOD Title: Acronym Mod
## MOD Author: CodeMonkeyX <nickyoungso@yahoo.com> - http://www.codemonkeyx.net
## MOD Description: Proporciona acrnimos aadidos automticamente en los mensajes del foro.
##
## MOD Version: 0.9.4
##
## Traduccin: JANU1535 - www.JanuWeb.Com
##
## Installation Level: Easy
## Installation Time: 5 Minutes
## Files To Edit:   constants.php
##                  bbcode.php
##									language/lang_english/lang_admin.php
##									language/lang_spanish/lang_admin.php
##
## Included Files:  acronyms.php
##                  admin_acronyms.php
##                  acronyms_list_body.tpl
##                  acronyms_edit_body.tpl
##
##############################################################
## For Security Purposes, Please Check: http://www.phpbb.com/mods/ for the
## latest version of this MOD. Downloading this MOD from other sites could cause malicious code
## to enter into your phpBB Forum. As such, phpBB will not offer support for MOD's not offered
## in our MOD-Database, located at: http://www.phpbb.com/mods/
##############################################################
##
## Author Notes:
##   Version 0.9.4 is pretty much a complete rewrite. I saw that after
##   adding all the checks for existing tags, and urls etc the previous
##   method was more trouble than it was worth. So I changed it.
##   As of V0.9.4 acronyms are now parsed and added when the message
##   is viewed. This has two main:
##        * It makes newly added acronyms appear in old posts.
##        * It is much simpler to insure acronym tags are not inserted into
##          the wrong place.
##   The only dis advantage is that it adds some more processing time
##   to viewtopic.php.
##        
##
#################################################################
##
## MOD History:
##
## v0.9.5
## - General
##   Fixed a problem with acronym tags already in the message body.
## - acronyms_list_body.tpl
##   Added a "Add Acronym" button to the top of the list.
## - admin_acronym.php
##   Added a check for Acronyms that are already in the Database.
##
## v0.9.4
## - Rewrite of the mod.
##
## v0.9.3
## - Fixed problem where url's not inside [url] tags were having
##   acronyms inserted.
##
## v0.9.2
## - Updated admin_acronyms so that some special characters will not
##   cause the SQL statements to fail.
## - Added Mighty_Y's acronym listing page.
## - Fixed problems where acronyms were being inserted into URL's, e-mail addresses, and images.
##
## v0.9.1
## - Made the acronym search case sensitive.
## - Improved search algorithm so that more acronyms are detected.
##
## v0.9.0
## - Initial Release.
##
#################################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
#################################################################

#
#-----[ COPY ]------------------------------------------
#
copy admin_acronyms.php to admin/admin_acronyms.php
copy acronyms.php to acronyms.php
copy acronym_body.tpl to templates/subSilver/acronym_body.tpl
copy acronyms_edit_body.tpl to templates/subSilver/admin/acronyms_edit_body.tpl
copy acronyms_list_body.tpl to templates/subSilver/admin/acronyms_list_body.tpl

#
#-----[ SQL ]------------------------------------------
#
CREATE TABLE `phpbb_acronyms` (
`acronym_id` MEDIUMINT NOT NULL AUTO_INCREMENT,
`acronym` VARCHAR( 80 ) NOT NULL ,
`description` VARCHAR( 255 ) NOT NULL ,
PRIMARY KEY ( `acronym_id` )
);

#
#-----[ OPEN ]------------------------------------------
#
viewtopic.php

#
#-----[ FIND ]------------------------------------------
#
	$message = str_replace("\n", "\n<br />\n", $message);

#
#-----[ BEFORE, ADD ]------------------------------------------
#
	$message = acronym_pass( $message );
	
#
#-----[ OPEN ]------------------------------------------
#
includes/constants.php

#
#-----[ FIND ]------------------------------------------
#
?>

#
#-----[ BEFORE, ADD ]------------------------------------------
#
define('ACRONYMS_TABLE', $table_prefix.'acronyms');

#
#-----[ OPEN ]------------------------------------------
#
includes/bbcode.php

#
#-----[ FIND ]------------------------------------------
#
function smiley_sort($a, $b)

#
#-----[ BEFORE, ADD ]------------------------------------------
#
function acronym_pass($message)
{
	static $orig, $repl;

	if( !isset($orig) )
	{
		global $db, $board_config;
		$orig = $repl = array();

		$sql = 'SELECT * FROM ' . ACRONYMS_TABLE;
		if( !$result = $db->sql_query($sql) )
		{
			message_die(GENERAL_ERROR, "Couldn't obtain acronyms data", "", __LINE__, __FILE__, $sql);
		}
		
		$acronyms = $db->sql_fetchrowset($result);

		if( count($acronyms) )
		{
			usort( $acronyms, 'acronym_sort' );
		}

		for ($i = 0; $i < count($acronyms); $i++)
		{
			$orig[] = '#\b(' . phpbb_preg_quote( $acronyms[$i]['acronym'], "/") . ')\b#';
			//$orig[] = "/(?<=.\W|\W.|^\W)" . phpbb_preg_quote($acronyms[$i]['acronym'], "/") . "(?=.\W|\W.|\W$)/";
			$repl[] = '<acronym title="' . $acronyms[$i]['description'] . '">' . $acronyms[$i]['acronym'] . '</acronym>'; ;
		}
	}
	
	if( count( $orig ) )
	{
		$segments = preg_split( '#(<acronym.+?>.+?</acronym>|<.+?>)#s' , $message, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);

		$message = '';

		foreach( $segments as $seg )
		{
			if( $seg[0] != '<' && $seg[0] != '[' )
			{
				$message .= str_replace('\"', '"', substr(preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "preg_replace(\$orig, \$repl, '\\0')", '>' . $seg . '<'), 1, -1));
			}
			else
			{
				$message .= $seg;
			}
		}
	}
	
	return $message;
}

#
#-----[ FIND ]------------------------------------------
#
?>

#
#-----[ BEFORE, ADD ]------------------------------------------
#
function acronym_sort($a, $b)
{
	if ( strlen($a['acronym']) == strlen($b['acronym']) )
	{
		return 0;
	}

	return ( strlen($a['acronym']) > strlen($b['acronym']) ) ? -1 : 1;
}

#
#-----[ OPEN ]------------------------------------------
#
language/lang_english/lang_admin.php

#
#-----[ FIND ]------------------------------------------
#
$lang['Click_return_wordadmin'] = 'Click %sHere%s to return to Word Censor Administration';

#
#-----[ AFTER, ADD ]------------------------------------------
#
//
// Acronyms
//
$lang['Acronyms_title'] = 'Acronyms Administration';
$lang['Acronyms_explain'] = 'From this control panel you can add, edit, and remove acronyms that will be automatically added to posts on your forums.';
$lang['Acronym'] = 'Acronym';
$lang['Acronyms'] = 'Acronyms';
$lang['Edit_acronym'] = 'Edit Acronym';
$lang['Description'] = 'Description';
$lang['Add_new_acronym'] = 'Add new acronym';
$lang['Update_acronym'] = 'Update acronym';

$lang['Must_enter_acronym'] = 'You must enter a acronym and its description';
$lang['No_acronym_selected'] = 'No acronym selected for editing';

$lang['Acronym_updated'] = 'The selected acronym has been successfully updated';
$lang['Acronym_added'] = 'The acronym has been successfully added';
$lang['Acronym_removed'] = 'The selected acronym has been successfully removed';

$lang['Click_return_acronymadmin'] = 'Click %sHere%s to return to Acronym Administration';

#
#-----[ OPEN ]------------------------------------------
#
language/lang_spanish/lang_admin.php

#
#-----[ FIND ]------------------------------------------
#
$lang['Click_return_wordadmin'] = 'Pulse %sAqu%s para volver a Administracin del Censor de Palabras';

#
#-----[ AFTER, ADD ]------------------------------------------
#
//
// Acronyms
//
$lang['Acronyms_title'] = 'Administrar Acrnimos';
$lang['Acronyms_explain'] = 'Desde este panel de control usted puede aadir, editar y borrar acrnimos que sern aadidos automticamente en los mensajes de su foro.';
$lang['Acronym'] = 'Acrnimo';
$lang['Acronyms'] = 'Acrnimos';
$lang['Edit_acronym'] = 'Editar Acrnimo';
$lang['Description'] = 'Descripcin';
$lang['Add_new_acronym'] = 'Aadir nuevo acrnimo';
$lang['Update_acronym'] = 'Actualizar acrnimo';

$lang['Must_enter_acronym'] = 'Debe introducir el acrnimo y su descripcin';
$lang['No_acronym_selected'] = 'No ha seleccionado ningn acrnimo para editar';

$lang['Acronym_updated'] = 'El acrnimo seleccionado ha sido actualizado satisfactoriamente';
$lang['Acronym_added'] = 'El acrnimo ha sido aadido satisfactoriamente';
$lang['Acronym_removed'] = 'El acrnimo seleccionado ha sido borrado satisfactoriamente';

$lang['Click_return_acronymadmin'] = 'Pulse %sAqu%s para volver a la Administracin de Acrnimos';

#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM
