Glossary & Tooltip : word replacement & processing
thanks pauli well spotted.
now fixed in the zip - see link on page 1
-- ok: just so you know that I know...
the glossary is far more resticked than you or I would like - this is all my fault I will be rewriting the glossary functionaliy entirely so as to add a little control on it's application as well as to remove it current reliance on a space being left either side of the word in question.
I have very little time this week but hope to start over the week end.
now fixed in the zip - see link on page 1
-- ok: just so you know that I know...
the glossary is far more resticked than you or I would like - this is all my fault I will be rewriting the glossary functionaliy entirely so as to add a little control on it's application as well as to remove it current reliance on a space being left either side of the word in question.
I have very little time this week but hope to start over the week end.
hi guys 'n' gals
I have rewritten my 'glossary' & 'tooltip' scripts as a complete do-over a the first was oh so poorly thought out'.
new features...
I have rewritten my 'glossary' & 'tooltip' scripts as a complete do-over a the first was oh so poorly thought out'.
new features...
- Glossry & tooltips are now the same script
- multiple words for a single glossary term
- html layouts for tooltip & glossary info: you can now create an html page as info if you so wish (links & forms etc will not work)
- no whitespace restrictions - allows for punctuation etc
- new VERY simple usage: totally 'code free' glossary terms list : just add --end-- to the end of each term and start the new term on the following line
FYI: as the glossary acts on the raw code of a page it will replace every instance of a the glossary term INCLUDING any values etc!
e.g:
if you had 'Forum' as a glossary term AND had the following form element in your site...
<label><input name="type_options[]" value="forum" type="checkbox">Forum</label>
this would give bad results as the glossary script will replace the value="forum" too
A worka round is to use a slight ly different word for your value.
you could try and keep the glossary term to muliple word or phrases as values can not containe spaces
be carefull for now (a fix will come
)
e.g:
if you had 'Forum' as a glossary term AND had the following form element in your site...
<label><input name="type_options[]" value="forum" type="checkbox">Forum</label>
this would give bad results as the glossary script will replace the value="forum" too
A worka round is to use a slight ly different word for your value.
you could try and keep the glossary term to muliple word or phrases as values can not containe spaces
be carefull for now (a fix will come
)
Last edited by pSouper on Mon 19. Jun 2006, 17:39, edited 1 time in total.
Hi pSouper,
always liked your piece of code/idea, so I enhanced it a little bit
I guess this post is for people that have tried it...
This is it:
- since the DEV 1.2.5 (or 1.2.6?) there is a new thing in backend called Keyword, (it's just a single table with ID, name in mysql, called phpwcms_keyword ) so I added a new column to it: keyword_description (long text).
Mysql, something like:
- I modified the backend to have the possibility to add the description (when you click on keyword you can now add a .. description, just 1 field TEXTAREA with like 10 rows
So, modified /include/inc.tmpl/admin.keyword.tmpl.php
to:
- I modified your glossary.php to something like:
- Result: you don't need the glossary.glos file any more it is replaced by the values you put in keywords at backend.
- Little plus:
a) create a hidden site structure you call GLOSSARY (for example) and with glossary as ALIAS.
b) Put in it an article with plain html text, where you put this:
Voilà a little complicated but now you have:
{TOOLTIP:keyword} that gets the keyword from the backend and when u click on the keyword you get the automatic generated glossary page with a names
{TOOLTIP:keyword:description} that acts like your tootltip
PD:
- don't forget to put the tooltip replacement tag in frontend render
- don't forget your css too for the box
Cheers
always liked your piece of code/idea, so I enhanced it a little bit
I guess this post is for people that have tried it...
This is it:
- since the DEV 1.2.5 (or 1.2.6?) there is a new thing in backend called Keyword, (it's just a single table with ID, name in mysql, called phpwcms_keyword ) so I added a new column to it: keyword_description (long text).
Mysql, something like:
Code: Select all
ALTER TABLE `phpwcms_keyword` ADD `keyword_description` LONGTEXT AFTER `keyword_name`;
So, modified /include/inc.tmpl/admin.keyword.tmpl.php
to:
Code: Select all
<?php
/*************************************************************************************
Copyright notice blah blah
*/
$keyword["id"] = 0;
?>
<table width="538" border="0" cellpadding="0" cellspacing="0">
<tr><td colspan="2" class="title"><?php echo $BL['be_admin_keywords'] ?></td></tr>
<tr><td colspan="2"><img src="img/leer.gif" width="1" height="4"></td></tr>
<?php
if(isset($_GET["keyid"])) {
?>
<tr><td colspan="2"><img src="img/lines/l538_70.gif" width="538" height="1"></td></tr>
<tr bgcolor="#F0F2F4"><td colspan="2"><img src="img/leer.gif" width="1" height="10"></td></tr>
<?php
$keyword["id"] = intval($_GET["keyid"]);
if($keyword["id"]) {
$sql = "SELECT * FROM ".DB_PREPEND."phpwcms_keyword WHERE keyword_id=".$keyword["id"]." LIMIT 1;";
if($result = mysql_query($sql, $db) or die("error 1 while retrieving keywords")) {
if($row = mysql_fetch_array($result)) {
$keyword["name"] = $row["keyword_name"];
$keyword["description"] = $row["keyword_description"];
}
mysql_free_result($result);
}
$sendbutton = $BL['be_admin_fcat_button1'];
} else {
$sendbutton = $BL['be_admin_fcat_button2'];
}
if(isset($_POST["keyword_aktion"])) { // show form for editing keywords
$keyword["name"] = clean_slweg($_POST["keyword_name"], 250);
$keyword["description"] = $_POST["keyword_description"];
$keyword["id"] = intval($_POST["keyword_id"]);
$keyword["name"] = str_replace(';', ' ', $keyword["name"]);
$keyword["name"] = str_replace(',', ' ', $keyword["name"]);
$keyword["name"] = preg_replace('/\s{1,}/', ' ', $keyword["name"]);
if(empty($keyword["name"])) {
$keyword["error"] = 1;
} else {
if(!$keyword["id"]) {
$sql = "INSERT INTO ".DB_PREPEND."phpwcms_keyword SET ";
$sql .= "keyword_name='".aporeplace($keyword["name"])."', ";
$sql .= "keyword_description='".aporeplace($keyword["description"])."'";
} else {
$sql = "UPDATE ".DB_PREPEND."phpwcms_keyword SET ";
$sql .= "keyword_name='".aporeplace($keyword["name"])."', ";
$sql .= "keyword_description='".aporeplace($keyword["description"])."'";
$sql .= "WHERE keyword_id=".$keyword["id"];
}
// UPDATE `phpwcms_keyword` SET `keyword_name` = 'phpwcmsedite',
// `keyword_description` = 'edite' WHERE `keyword_id` =3 LIMIT 1 ;
if($result = mysql_query($sql, $db) or die("error 2 while inserting/updating keyword")) {
if(!$keyword["id"]) $keyword["id"] = mysql_insert_id($db);
header("Location: ".PHPWCMS_URL."phpwcms.php?do=admin&p=5");
exit();
}
}
}
?>
<form action="phpwcms.php?do=admin&p=5&keyid=<?php echo $keyword["id"] ?>" method="post" name="keywords">
<tr align="center" bgcolor="#F0F2F4"><td colspan="2"><table border="0" cellspacing="0" cellpadding="0">
<?php if(!empty($keyword["error"])) { ?>
<tr>
<td align="right" class="chatlist"><font color="#FF3300"><?php echo $BL['be_admin_usr_err'] ?>:</font> </td>
<td class="error"><strong><?php echo $BL['be_admin_keywords_err'] ?></strong></td>
</tr>
<tr><td colspan="2"><img src="img/leer.gif" width="1" height="3"></td></tr>
<?php } ?>
<tr>
<td align="right" class="chatlist"><?php echo $BL['be_admin_keywords_key'] ?>: </td>
<td><input name="keyword_name" type="text" id="keyword_name" class="f11b" style="width: 430px" value="<?php echo empty($keyword["name"]) ? '' : html_specialchars($keyword["name"]) ?>" size="40" maxlength="250"></td>
</tr>
<tr>
<td align="right" valign="top" class="chatlist"><?php echo $BL['be_admin_keywords_description'] ?>: </td>
<td><textarea rows="10" class="f11b" id="keyword_description" style="width: 430px" input name="keyword_description" ><?php echo empty($keyword["description"]) ? '' : html_specialchars($keyword["description"]) ?></textarea></td>
</tr>
<tr><td colspan="2"><img src="img/leer.gif" width="1" height="10"></td></tr>
<tr>
<td><input name="keyword_id" type="hidden" id="keyword_id" value="<?php echo intval($keyword["id"]) ?>"><input name="keyword_aktion" type="hidden" id="keyword_aktion" value="1"></td>
<td><input name="Submit" type="submit" class="button10" style="width: 150px;" value="<?php echo $sendbutton ?>"> <input name="donotsubmit" type="button" class="button10" style="width: 80px;" value="<?php echo $BL['be_admin_fcat_exit'] ?>" onClick="location.href='phpwcms.php?do=admin&p=5';"></td>
</tr>
</table></td>
</tr>
<tr bgcolor="#F0F2F4"><td colspan="2"><img src="img/leer.gif" width="1" height="15"></td></tr>
</form>
<?php
} //Ende Anzeige Category Name Formular
?>
<tr><td colspan="2"><img src="img/lines/l538_70.gif" width="538" height="1"></td></tr>
<tr><td colspan="2"><img src="img/leer.gif" width="1" height="5"></td></tr>
<?php
$sql = "SELECT * FROM ".DB_PREPEND."phpwcms_keyword WHERE keyword_trash=0 ORDER BY keyword_name;";
if($result = mysql_query($sql, $db) or die("error while browsing keyword list")) {
while($row = mysql_fetch_assoc($result)) {
echo "<tr onMouseOver=\"this.bgColor='#CCFF00';\" onMouseOut=\"this.bgColor='#FFFFFF';\">\n";
echo "<td width=\"483\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tr>\n";
echo "<td>";
echo "<img src=\"img/symbole/plus_empty.gif\" width=\"15\" height=\"15\" border=\"0\"></td>\n";
echo "<td><img src=\"img/leer.gif\" width=\"2\" height=\"15\"></td>\n";
echo "<td class=\"dir\"><strong>".html_specialchars($row["keyword_name"])."</strong></td>\n";
echo "</tr>\n</table></td>\n<td width=\"55\" align=\"right\">";
echo "<a href=\"phpwcms.php?do=admin&p=5&keyid=".$row["keyword_id"]."\" title =\"".$BL['be_admin_keyword_edit']."\">";
echo "<img src=\"img/button/edit_22x11.gif\" width=\"22\" height=\"11\" border=\"0\"></a>";
echo "<a href=\"include/inc_act/act_filecat.php?do=8,".$row["keyword_id"]."\" title =\"".$BL['be_admin_keyword_del']."\" ";
echo "onClick=\"GP_popupConfirmMsg('".$BL['be_admin_keyword_delmsg']."\\n[".html_specialchars($row["keyword_name"])."] ');return document.MM_returnValue;\">";
echo "<img src=\"img/button/del_11x11.gif\" width=\"11\" height=\"11\" border=\"0\"></a>";
echo "</td>\n</tr>\n";
}
mysql_free_result($result);
}
?>
<tr><td colspan="2"><img src="img/leer.gif" width="1" height="5"></td></tr>
<tr><td colspan="2"><img src="img/lines/l538_70.gif" width="538" height="1"></td></tr>
<tr>
<td><img src="img/leer.gif" width="483" height="1"></td>
<td><img src="img/leer.gif" width="55" height="5"></td>
</tr>
<tr><td colspan="2"><form action="phpwcms.php?do=admin&p=5&keyid=0" method="post"><input type="submit" value="<?php echo $BL['be_admin_keyword_add'] ?>" class="button10" title="<?php echo $BL['be_admin_keyword_add'] ?>"></form></td></tr>
</table>
Code: Select all
function glossaryReplace ($string){
$query="SELECT `keyword_name` , `keyword_description` FROM `phpwcms_keyword`" ;
$result = mysql_query($query)or die("There was an error<br /> " . mysql_error() . "<hr />");
while ($row = mysql_fetch_array($result)) {
$keyword_name=$row['keyword_name'];
$ToolTip_keyword_name="{TOOLTIP:".$row['keyword_name']."}";
$keyword_description=$row['keyword_description'];
$glos_code[$keyword_name]='<a class="tooltip" href="index.php?glossary#'.$keyword_name.'">'.$keyword_name.'<span>'.$keyword_description.'</span></a>';
$string=str_replace($ToolTip_keyword_name, $glos_code[$keyword_name], $string);
}
return $string; // spit out the final webpage for display
}
$content["all"] = (glossaryReplace($content["all"]));
- Little plus:
a) create a hidden site structure you call GLOSSARY (for example) and with glossary as ALIAS.
b) Put in it an article with plain html text, where you put this:
Code: Select all
[PHP]
$query="SELECT `keyword_name` , `keyword_description` FROM `phpwcms_keyword` ORDER BY `keyword_name`" ;
$result = mysql_query($query)or die("There was an error<br /> " . mysql_error() . "<hr />");
while ($row = mysql_fetch_array($result)) {
$keyword_name=$row['keyword_name'];
$keyword_description=$row['keyword_description'];
echo "<a name=\"$keyword_name\"></a>[br]<strong>$keyword_name</strong>: $keyword_description [br][br]";
}
[/PHP]
{TOOLTIP:keyword} that gets the keyword from the backend and when u click on the keyword you get the automatic generated glossary page with a names
{TOOLTIP:keyword:description} that acts like your tootltip
PD:
- don't forget to put the tooltip replacement tag in frontend render
- don't forget your css too for the box
Code: Select all
//tooltip replacement
$search[3] = '/\{TOOLTIP:(.*?):(.*?)}/';
$replace[3] = '<a class="tooltip" href="">$1<span>$2</span></a>';
Cheers
Last edited by Kosse on Mon 26. May 2008, 13:40, edited 1 time in total.
1.3 out, testing, testing...
Sponsoring 4 phpwcms Blog and Usermanagement
Sponsoring 4 phpwcms Blog and Usermanagement
Nope Ronald cant spell... He says i'm loving itpSouper wrote:in the words of the immortal Ronald McDonald... I'm Lovin' it
pSouper you'r alive... nice to know!!
http://www.studmed.dk Portal for doctors and medical students in Denmark
Giving back what has been given np, my pleasure, hope my explanation wasn't too ~messy~ I'll try to make a zip file so pple can just dl it and use it, maybe next few weeks I can make a MOD of it.pSouper wrote:in the words of the immortal Ronald McDonald... I'm Lovin' it
fantastic Kosse - just the stuff that I was bieng asked to do but have not had any speare time to do -this also explains my sadly too infrequent contributions to this forum too
pSouper
"come back pSouper forum needs you" && "PhpWMc'S I luve it" == nice feature
Cheers
1.3 out, testing, testing...
Sponsoring 4 phpwcms Blog and Usermanagement
Sponsoring 4 phpwcms Blog and Usermanagement