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:
Code: Select all
ALTER TABLE `phpwcms_keyword` ADD `keyword_description` LONGTEXT AFTER `keyword_name`;
- 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:
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>
- I modified your glossary.php to something like:
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"]));
- 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:
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]
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
Code: Select all
//tooltip replacement
$search[3] = '/\{TOOLTIP:(.*?):(.*?)}/';
$replace[3] = '<a class="tooltip" href="">$1<span>$2</span></a>';
Cheers