[ABD] Lexicon / Acronym MOD

Any abandoned MODs will be moved to this forum.

WARNING: MODs in this forum are not currently being supported or maintained by the original MOD author. Proceed at your own risk.
Forum rules
IMPORTANT: MOD Development Forum rules

WARNING: MODs in this forum are not currently being supported nor updated by the original MOD author. Proceed at your own risk.
reh
Registered User
Posts: 66
Joined: Mon Jun 28, 2004 7:55 am

Re: [ALPHA] Lexicon / Acronym MOD

Post by reh »

Ok, if i change from only replace strings in long words to replace entire words, i should also add some spaces before/after <acronym> ... </acronym> :-)
if (($acronyms = $this->get('_acronyms')) === false)
{
$sql = 'SELECT term_id, acronym, description, NOT ISNULL(long_desc) AS long_desc
FROM ' . LEXICON_TABLE . "
WHERE lang = '" . $user->data['user_lang'] . "'
ORDER BY LENGTH(TRIM(acronym)) DESC";
$result = $db->sql_query($sql);
$acronyms = array();
while ($row = $db->sql_fetchrow($result))
{
$firstspace = (!strstr($row['acronym'], ' ')? '(?:\s|^)+' : '');
$lastspace = (!strrchr($row['acronym'], ' ')? '[A-Za-z]*' : '');
$acronyms['match'][] = '#'. $firstspace. '([A-Za-z]*'. preg_quote($row['acronym'], '#'). $lastspace. ')#i';
$acronyms['replace'][] = $row['long_desc'] ?
' <acronym class="id' .$row['term_id']. '" title="' . $row['description'] . '"><b>\\1</b></acronym> ' :
' <acronym title="' . $row['description'] . '">\\1</acronym> ' ;
}
echo $acronyms['match'][2];
$db->sql_freeresult($result);
$this->put('_acronyms', $acronyms);
}

return $acronyms;
}

Bombybob
Registered User
Posts: 50
Joined: Sat Sep 06, 2008 11:51 am

Re: [ALPHA] Lexicon / Acronym MOD

Post by Bombybob »

Ok, i replace this with the code above ?
in functions_acronym.php

Code: Select all

$firstspace = (!strstr($row['acronym'], ' ')? '(?:\s|^)+' : '');
        $lastspace = (!strrchr($row['acronym'], ' ')? '[A-Za-z]*' : '');
        $acronyms['match'][] = '#'. $firstspace. '([A-Za-z]*'. preg_quote($row['acronym'], '#'). $lastspace. ')#i';
If yes ... error message

Code: Select all

Parse error: syntax error, unexpected T_RETURN, expecting T_FUNCTION in /home/o/l/e/oleronature/www/test/includes/functions_acronym.php on line 105
while ($row = $db->sql_fetchrow($result))
{

if (($acronyms = $this->get('_acronyms')) === false)
{
$sql = 'SELECT term_id, acronym, description, NOT ISNULL(long_desc) AS long_desc
FROM ' . LEXICON_TABLE . "
WHERE lang = '" . $user->data['user_lang'] . "'
ORDER BY LENGTH(TRIM(acronym)) DESC";
$result = $db->sql_query($sql);
$acronyms = array();
while ($row = $db->sql_fetchrow($result))
{
$firstspace = (!strstr($row['acronym'], ' ')? '(?:\s|^)+' : '');
$lastspace = (!strrchr($row['acronym'], ' ')? '[A-Za-z]*' : '');
$acronyms['match'][] = '#'. $firstspace. '([A-Za-z]*'. preg_quote($row['acronym'], '#'). $lastspace. ')#i';
$acronyms['replace'][] = $row['long_desc'] ?
' <acronym class="id' .$row['term_id']. '" title="' . $row['description'] . '"><b>\\1</b></acronym> ' :
' <acronym title="' . $row['description'] . '">\\1</acronym> ' ;
}
echo $acronyms['match'][2];
$db->sql_freeresult($result);
$this->put('_acronyms', $acronyms);
}

return $acronyms;
}// $acronyms['match'][] = '#(?<!\w)(' . preg_quote($row['acronym'], '#') . ')(?!\w)#i';
$acronyms['replace'][] = $row['long_desc'] ?
'<acronym class="id' .$row['term_id']. '" title="' . $row['description'] . '"><b>\\1</b></acronym>' :
'<acronym title="' . $row['description'] . '">\\1</acronym>' ;
}
$db->sql_freeresult($result);
$this->put('_acronyms', $acronyms);
}

return $acronyms;
}
//
// Acronym MOD - End Code Alteration
I retire
return $acronyms;
}


it's ok


But not if acronym is in a word. :cry:

exemple : degastrera


Thanks

reh
Registered User
Posts: 66
Joined: Mon Jun 28, 2004 7:55 am

Re: [ALPHA] Lexicon / Acronym MOD

Post by reh »

I posted the entire function rather then the single changes, you simply must add space before after the acronym or you must replace the function.

Sometimes it helps to think self ;-)

Bombybob
Registered User
Posts: 50
Joined: Sat Sep 06, 2008 11:51 am

Re: [ALPHA] Lexicon / Acronym MOD

Post by Bombybob »

I'm very sorry but i'm lost ... :|

Acronyme with a space at the beginning or/and at the end, the mod don't find my word.

reh
Registered User
Posts: 66
Joined: Mon Jun 28, 2004 7:55 am

Re: [ALPHA] Lexicon / Acronym MOD

Post by reh »

The links you post ask for a login, i have no glue, whats exact in which field of your database, ...

Bombybob
Registered User
Posts: 50
Joined: Sat Sep 06, 2008 11:51 am

Re: [ALPHA] Lexicon / Acronym MOD

Post by Bombybob »

Excuse me,link ok

In my database.

i follow the install;mod.xml

Code: Select all

CREATE TABLE `phpBB_lexicon` (
  `term_id` mediumint(9) NOT NULL auto_increment,
  `acronym` varchar(80) NOT NULL default '',
  `term` varchar(80) default NULL,
  `description` varchar(255) NOT NULL default '',
  `long_desc` longtext,
  `lang` varchar(15) NOT NULL default 'de',
  PRIMARY KEY  (`term_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;

Thanks

reh
Registered User
Posts: 66
Joined: Mon Jun 28, 2004 7:55 am

Re: [ALPHA] Lexicon / Acronym MOD

Post by reh »

I need to know, which VALUES you have in a row, not, which fields your table have.

Whats in term and whats in acronym, is the lang field set correct?

Bombybob
Registered User
Posts: 50
Joined: Sat Sep 06, 2008 11:51 am

Re: [ALPHA] Lexicon / Acronym MOD

Post by Bombybob »


reh
Registered User
Posts: 66
Joined: Mon Jun 28, 2004 7:55 am

Re: [ALPHA] Lexicon / Acronym MOD

Post by reh »

I dont know, where your problems come from.

Here is my complete functions_acronym.php

Code: Select all

<?php
/**
*
* @package acronym
*
*/

/**
 * @ignore
*/
if (!defined('IN_PHPBB'))
{
  exit;
}

/**
* automatic acronym insertion
*/
function acronym_pass($text)
{
  $acronym_cache = new acronym_cache();
  static $acronyms;
  global $cache;
  if (!isset($acronyms) || !is_array($acronyms))
  {
    // obtain_acronym_list is taking care of the users acronyms option and the board-wide option
    $acronyms = $acronym_cache->obtain_acronym_list();
  }

  if (sizeof($acronyms))
  {
    return preg_replace($acronyms['match'], $acronyms['replace'], $text);
  }

  return $text;
}


/**
* Class for grabbing/handling acronym cached entries, extends acm_file or acm_db depending on the setup
* @package acm
*/
class acronym_cache extends acm
{//----------------------------------------------------------------------
// Acronym MOD - Begin Code Alteration
//
  /**
  * Obtain list of lexicon words for acronyms and build preg style replacement arrays for use by the
  * calling script
  */
  function obtain_acronym_list()
  {
    global $config, $user, $db;

/*    if (!$user->optionget('viewcensors') && $config['allow_nocensors'])
    {
      return array();
    }
*/
    if (($acronyms = $this->get('_acronyms')) === false)
    {
      $sql = 'SELECT term_id, acronym, description, NOT ISNULL(long_desc) AS long_desc
        FROM ' . LEXICON_TABLE . "
          WHERE lang = '" . $user->data['user_lang'] . "'
        ORDER BY LENGTH(TRIM(acronym))  DESC";
      $result = $db->sql_query($sql);
      $acronyms = array();
      while ($row = $db->sql_fetchrow($result))
      {
        $firstspace = (!strstr($row['acronym'], ' ')? '(?:\s|^)+' : '');
        $lastspace = (!strrchr($row['acronym'], ' ')? '[A-Za-z]*' : '');
        $acronyms['match'][] = '#'. $firstspace. '([\w]*'. preg_quote($row['acronym'], '#'). $lastspace. ')#i';
        $acronyms['replace'][] = $row['long_desc'] ?
           ' <acronym class="id' .$row['term_id']. '" title="' . $row['description'] . '"><b>\\1</b></acronym> ' :
           ' <acronym title="' . $row['description'] . '">\\1</acronym> ' ;
      }
      $db->sql_freeresult($result);
      $this->put('_acronyms', $acronyms);
    }

    return $acronyms;
  }
//
// Acronym MOD - End Code Alteration
//----------------------------------------------------------------------

}
?>
and here the lexicon.php with an additional trim for the term

Code: Select all

<?php
/*
* Addon for the Acronym mod 
*/

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
require($phpbb_root_path . 'common.' . $phpEx);
require($phpbb_root_path . 'includes/functions_user.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
$user->add_lang('mods/lexicon');
// End session management

// Recherche les lettres présentes dans le lexicon
$sql = "SELECT DISTINCT UPPER(LEFT(TRIM(term),1)) AS a FROM " . LEXICON_TABLE. " WHERE lang = '" . $user->lang['USER_LANG'] . "' ORDER BY a" ;
if( !$result = $db->sql_query($sql) )
{
  message_die(GENERAL_ERROR, "Could not obtain lexicon data", "", __LINE__, __FILE__, $sql);
}

$abc_links = '';
$abc = array('#','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',$user->lang['LEXICON_ALL']);
$letter = request_var('letter', '');
$letter = ($letter == '0') ? '#' : $letter;
$letter = (!in_array($letter,$abc)) ? '' : $letter;

while($row = $db->sql_fetchrow($result))
{
  $row['a'] = str_replace (array("Ä", "Ö", "Ü"), array("A", "O", "U"),$row['a']);
  $alphabeth[] = in_array($row['a'], $abc) ?  $row['a'] : '#';
}

foreach ($abc as $l)  //make A-Z, link if entry
{
  $abc_links .= (in_array($l, $abc) OR $l == $user->lang['LEXICON_ALL']) ?
     "<a href='lexicon.php?letter=$l&' " . ($letter === $l ? "class='letter'>" : ">") .
      "$l</a><span class='page-sep'>, </span>" :
      "<span class='noabc'>$l</span><span class='page-sep'>, </span>" ;
}
$abc_links = str_replace('#&','0&',$abc_links);

$template->assign_vars(array(
  "LEXICON_ABC" => $letter == $user->lang['LEXICON_ALL'] ? $user->lang['LEXICON_ALL_TERMS'] : sprintf($user->lang['LEXICON_ABC'], $letter),
  "S_LETTER" => $letter ? true : false,
  "ABC" => $abc_links
));

if($letter)
{
  if($letter == $user->lang['LEXICON_ALL'])
  {
    $where = ' ';  // Select entrys with letter
  }
  else
  {
    // Select entrys with letter
    $where = " WHERE " . ($letter == "#" ?
             $db->sql_in_set('LEFT(term,1)', $abc, true) :  // all not-letters
             "term LIKE '$letter%' AND lang = '" . $user->lang['USER_LANG']."'");
  }
  $sql = "SELECT TRIM(term) AS term, description, long_desc FROM " . LEXICON_TABLE . $where . " ORDER BY term";

  if( !$result = $db->sql_query($sql) )
  {
    message_die(GENERAL_ERROR, "Could not obtain term data", "", __LINE__, __FILE__, $sql);
  }


  while( $term_row = $db->sql_fetchrow($result) )
  {
    $template->assign_block_vars("term_row", array(
      "TERM" => $term_row['term'],
      "DESCRIPTION" => $term_row['description'],
      "LONGTEXT" => $term_row['long_desc']
    ));
  }
}
else  {
  // kein Buchstabe ausgewählt

}

// Output page
page_header($user->lang['LEXICON_TITLE'] . " - $letter");

$template->set_filenames(array(
  "body" => "lexicon.html")
);

page_footer();

?>

Bombybob
Registered User
Posts: 50
Joined: Sat Sep 06, 2008 11:51 am

Re: [ALPHA] Lexicon / Acronym MOD

Post by Bombybob »

Hello, I replaced = no change. :cry:

I am going to begin again the installation since the beginning

Bombybob
Registered User
Posts: 50
Joined: Sat Sep 06, 2008 11:51 am

Re: [ALPHA] Lexicon / Acronym MOD

Post by Bombybob »

Hello,

i delete and i restart the installation, i have same probems.

Thanks

reh
Registered User
Posts: 66
Joined: Mon Jun 28, 2004 7:55 am

Re: [ALPHA] Lexicon / Acronym MOD

Post by reh »

Im sorry, but in my forum it works and i dont know, why not on yours
http://www.kaninchenwissen.de/viewtopic ... p=462#p462

Bombybob
Registered User
Posts: 50
Joined: Sat Sep 06, 2008 11:51 am

Re: [ALPHA] Lexicon / Acronym MOD

Post by Bombybob »

yes i see your forum, i have no explication. You want a access to my ftp for see ?

reh
Registered User
Posts: 66
Joined: Mon Jun 28, 2004 7:55 am

Re: [ALPHA] Lexicon / Acronym MOD

Post by reh »

write an "echo $sql;" after this line in lexicon.php

Code: Select all

$sql = "SELECT DISTINCT UPPER(LEFT(TRIM(term),1)) AS a FROM " . LEXICON_TABLE. " WHERE lang = '" . $user->lang['USER_LANG'] . "' ORDER BY a" ;
Copy the echoed code and execute it in phpMyAdmin, it should give you the list with letters from existing words.

reh
Registered User
Posts: 66
Joined: Mon Jun 28, 2004 7:55 am

Re: [ALPHA] Lexicon / Acronym MOD

Post by reh »

I packed the changes in lexicon_0.1.3.zip (see first post) and hope, i dont forgot anything.

Locked

Return to “[3.0.x] Abandoned MODs”