Glossary & Tooltip : word replacement & processing

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
User avatar
pSouper
Posts: 1552
Joined: Tue 11. Nov 2003, 15:45
Location: London
Contact:

Glossary & Tooltip : word replacement & processing

Post by pSouper »

the {TOOLTIP} replacement tag was a halfway rest-stop on my route to creating an auto Glossary script. You will need to apply the tooltip replacment tag for this to work....

create a new file... phpwcms_template/inc_script/frontend_render/glossary.php

Code: Select all

<?
function glossary( $string )
{
	$string = StrPrep($string);
	$harray = explode(' ',$string);
	$c = count($harray);
	for( $i = 0; $i <= $c; $i++)
	{
		$tip = swapword($harray[$i]);
		if (strtolower($tip) != strtolower($harray[$i])) {
		$harray[$i] = '{TOOLTIP:'.$harray[$i].','.$tip.'}';
		}
	}
   $string = implode(' ',$harray);
   $string = StrFix($string);
   return $string;
}
 
function swapword ($string)
{
	$lowstring = strtolower($string);
	switch($lowstring)
    {
		//start of glossary terms
		case "bumble": return "To move, act, or proceed clumsily";
		case "pickle": return "a sauce made from vegetables or fruit which have been preserved in a vinegar sauce or salty water";
		case "pebble": return "A small stone, especially one worn smooth by erosion";
		//case "design": return "something I do :)";
		//end of glossary
		default: return $string;
		break;
    }
}
function StrPrep ($s)
{
   $search[0] = '/\>/';   
   $replace[0] = '> ';
   
   $search[1] = '/\</';   
   $replace[1] = ' <';

  	$s = preg_replace($search, $replace, $s);
	//$s = str_replace('&#92*;&#039*;', '&#039*;', $s);
	//$s = str_replace('&amp*;quot*;', '&quot*;', $s);
   return $s;   // spit out the final webpage for display
}
function StrFix ($s)
{
   $search[0] = '/\> /';   
   $replace[0] = '>';
   
   $search[1] = '/ \</';   
   $replace[1] = '<';

  	$s = preg_replace($search, $replace, $s);
	//$s = str_replace('&#92*;&#039*;', '&#039*;', $s);
	//$s = str_replace('&amp*;quot*;', '&quot*;', $s);
   return $s;   // spit out the final webpage for display
}
?>
then add the following line in myTags.php (ref: my tooltips post) just above the line
"$content["all"]
= (myTagParser ($content["all"]));"

Code: Select all

$content["all"] = (myGlossaryParser ($content["all"]));
and just above the 'myTagParser()' function you should place the following function...

Code: Select all

function myGlossaryParser ($string)
{
include_once "glossary.php";
return (glossary($string));
}
and all should be well.


useage: just keep adding case lines as in the code :)
the words with automatically be replaced in the content of your site
BEWARE: ALL instances of the word will be replaced - even in menus etc.
Last edited by pSouper on Tue 18. Oct 2005, 23:12, edited 5 times in total.
User avatar
sustia
Posts: 651
Joined: Fri 2. Apr 2004, 22:29
Location: Lecce (Italy)
Contact:

Post by sustia »

Hi, I'm your nightmare :lol:

I have created the file glossary.php, modified the tooltip.php and the result is

Code: Select all

Fatal error: Call to undefined function: myglossaryparser() in /home/ortaggi/public_html/serbia/phpwcms_template/inc_script/frontend_render/tooltip.php on line 15
Campeones del mundo!
Vegetables!
User avatar
pSouper
Posts: 1552
Joined: Tue 11. Nov 2003, 15:45
Location: London
Contact:

Post by pSouper »

Hi Sustia,
you're no nightmare, you're my friendly beta tester :)

:oops: I had not included a new function in the myTags.php (your tooltips.php i think)

please review my post above for the new function.
User avatar
Fulvio Romanin
Posts: 394
Joined: Thu 4. Dec 2003, 11:12
Location: Udine, Italy
Contact:

Post by Fulvio Romanin »

errrm guys, an example?!? :)
Completeness is reached through subtraction, not through addition
User avatar
pSouper
Posts: 1552
Joined: Tue 11. Nov 2003, 15:45
Location: London
Contact:

Post by pSouper »

errrm, in a day or so - i promise :)
User avatar
sustia
Posts: 651
Joined: Fri 2. Apr 2004, 22:29
Location: Lecce (Italy)
Contact:

Post by sustia »

pSouper wrote:Hi Sustia,
you're no nightmare, you're my friendly beta tester :)

:oops: I had not included a new function in the myTags.php (your tooltips.php i think)

please review my post above for the new function.
Ok, I have made the corrections to the file, but unfortunately now the site is down, and I can't see if it works.

Fulvio, I will post the link when the site will come back online :wink:
Campeones del mundo!
Vegetables!
User avatar
sustia
Posts: 651
Joined: Fri 2. Apr 2004, 22:29
Location: Lecce (Italy)
Contact:

Post by sustia »

Ok, this is the link
http://www.ortaggipugliesi.it/serbia/index.php?faq


The glossary seems that doesn't works, but the tooltip yes.
The code in the glossary.php is this

Code: Select all

<?
function glossary( $string )
{
   $string = StrPrep($string);
   $harray = explode(' ',$string);
   $c = count($harray);
   for( $i = 0; $i <= $c; $i++)
   {
      $tip = swapword($harray[$i]);
      if (strtolower($tip) != strtolower($harray[$i])) {
      $harray[$i] = '{TOOLTIP:'.$harray[$i].','.$tip.'}';
      }
   }
   $string = implode(' ',$harray);
   $string = StrFix($string);
   return $string;
}

function swapword ($string)
{
   $lowstring = strtolower($string);
   switch($lowstring)
    {
      //start of glossary terms
      case "Apulia": return "The name of a region in south Italy";
      case "pickle": return "a sauce made from vegetables or fruit which have been preserved in a vinegar sauce or salty water";
      case "pebble": return "A small stone, especially one worn smooth by erosion";
      //case "design": return "something I do :)";
      //end of glossary
      default: return $string;
      break;
    }
}
function StrPrep ($s)
{
   $search[0] = '/\>/';
   $replace[0] = '> ';

   $search[1] = '/\</';
   $replace[1] = ' <';

     $s = preg_replace($search, $replace, $s);
   //$s = str_replace('\'', ''', $s);
   //$s = str_replace('&quot;', '"', $s);
   return $s;   // spit out the final webpage for display
}
function StrFix ($s)
{
   $search[0] = '/\> /';
   $replace[0] = '>';

   $search[1] = '/ \</';
   $replace[1] = '<';

     $s = preg_replace($search, $replace, $s);
   //$s = str_replace('&#92*;&#039*;', '&#039*;', $s);
   //$s = str_replace('&amp*;quot*;', '&quot*;', $s);
   return $s;   // spit out the final webpage for display
}
?>
but the Apulia word in page of the link above is not replaced :?
Campeones del mundo!
Vegetables!
User avatar
Kosse
Posts: 1066
Joined: Thu 9. Sep 2004, 12:08
Location: Brussels, Belgium
Contact:

Post by Kosse »

Hi all,

great thing, I like it!
Good job pSouper! This will improve even more usability for phpwcms.
And thx to s(o)uperbeta-tester Sustia ;)
Hope OG can integrate this in next release, you have my vote!
Thumbs up :D

Cheers
User avatar
pSouper
Posts: 1552
Joined: Tue 11. Nov 2003, 15:45
Location: London
Contact:

Post by pSouper »

Hi all,
following some trouble with the code above i am hosting both required files (tooltip & glossary) here: Tooltip & Glossary script

hope it works for you.

ps: I don't consider either to be of a suitable quality for inclusion within the phpwcms project however I will remove the bugs and issues where possible.
If the functionality proves popular then I would like to think that the functionality at least may be a default feature at some point.
Last edited by pSouper on Mon 17. Oct 2005, 11:44, edited 2 times in total.
User avatar
Kosse
Posts: 1066
Joined: Thu 9. Sep 2004, 12:08
Location: Brussels, Belgium
Contact:

Post by Kosse »

pSouper wrote: here: Tooltip & Glossary script

hope it works for you.

ps: I don't consider either to be of a suitable quality for inclusion within the phpwcms project however I will remove the bugs and issues where possible.
If the functionality proves popular then I would like to think that the functionality at least may be a default feature at some point.
The zip file seems missing (404 page)... :cry:
As for the inclusion into phpwcms, well if the quality of ur hack proves ok, why not, it's a usefull feature IMHO...

Cheers
User avatar
pSouper
Posts: 1552
Joined: Tue 11. Nov 2003, 15:45
Location: London
Contact:

Post by pSouper »

all good now :)
User avatar
sustia
Posts: 651
Joined: Fri 2. Apr 2004, 22:29
Location: Lecce (Italy)
Contact:

Post by sustia »

Hi pSouper, I have putted your files, but neither tooltip nor glossary work.

http://www.ortaggipugliesi.it/serbia/index.php?faq
Campeones del mundo!
Vegetables!
User avatar
pSouper
Posts: 1552
Joined: Tue 11. Nov 2003, 15:45
Location: London
Contact:

Post by pSouper »

and you do have the style cut from the tooltip.css and pasted into your frontend.css?

and both files are uploaded and unchanged fromthose downloaded?
Pauli
Posts: 92
Joined: Mon 30. Aug 2004, 11:53

Post by Pauli »

I see you have <a class="tootip"

shouldn't that be "tooltip" ?
User avatar
sustia
Posts: 651
Joined: Fri 2. Apr 2004, 22:29
Location: Lecce (Italy)
Contact:

Post by sustia »

pSouper wrote:and you do have the style cut from the tooltip.css and pasted into your frontend.css?

and both files are uploaded and unchanged fromthose downloaded?
Ok, perfect.
Missed a part in the css file, it was my fault :oops: but the glossary seems doesn't work.
Campeones del mundo!
Vegetables!
Post Reply