This experimental hack searches
News 1.44 articles looking for
Wordbook 1.16 terms. It will automatically locate, code links and add styling emphasis to any Wordbook terms found in the news article. It can be modified to create links to Wordbook definitions or referral URLs.
The code was copied from Wordbook 1.6 entry.php (line 112 thru 141). I am not a coder, so I can't really develop this much further. I offer it here in hope that someone with more skill will improve it or develop a better method.
Thanks to herve (News 1.44) and hsalasar (Wordbook).
Insert the following code into a copy of news/article.php after line 182 "$bodytext = $article->bodytext();"
//** TCNET HACK News module for Wordbook Glossary links **
//Warning: Experimental Hack! Use at your own risk! Make backups first!
//News article's with hyperlink text containing glossary
//terms will be split or completely broken by this hack.
$parts = explode("|TERMSON|", $bodytext);
// Retrieve all terms from the Wordbook glossary.
$allterms = $xoopsDB -> query( "SELECT entryID, term FROM " . $xoopsDB -> prefix( "wbentries" ));
while ( list( $entryID, $term ) = $xoopsDB -> fetchrow($allterms ))
{
foreach($parts as $key=>$part)
{
// singular
$term_q = preg_quote($term, '/');
$search_term = "/b$term_qb/i";
$replace_term = ".XOOPS_URL."/modules/wordbook/entry.php?entryID=".$entryID."' title=' View a definition for ".$term."'>".$term."";
$parts[$key] = preg_replace($search_term, $replace_term,$parts[$key]);
// plural
$term = $term."s";
$term_q = preg_quote($term, '/');
$search_term = "/b$term_qb/i";
$replace_term = ".XOOPS_URL."/modules/wordbook/entry.php?entryID=".$entryID."' title=' View a definition for ".$term."'>".$term."";
$parts[$key] = preg_replace($search_term, $replace_term,$parts[$key]);
// plural with e
$term = $term."es";
$term_q = preg_quote($term, '/');
$search_term = "/b$term_qb/i";
$replace_term = ".XOOPS_URL."/modules/wordbook/entry.php?entryID=".$entryID."' title=' View a definition for ".$term."'>".$term."";
$parts[$key] = preg_replace($search_term, $replace_term,$parts[$key]);
}
}
$bodytext = implode("|TERMSON|", $parts);
//**** END TCNET HACK for Wordbook module terms ****
There are two ways to apply this hack:1) Glossary links always on.-Insert the hack into news/article.php after line 182.
-Save and publish article.php to the news directory.
I think this option will help search engine rankings because it automatically locates and adds emphasis to specific keywords in the article. The disadvantage to this option is that it may cause high cpu load if you have long articles or many glossary terms.
2) Glossary links off with a link to display them. -Copy news/article.php and rename as article_glossary.php
-Insert the hack after line 182.
-Publish article_glossary.php to the news module directory.
-Publish a "Glossary View" link to articles_glossary.php in news/templates/news_item.html.
See a demo by viewing any news article at
http://www.technicalcrew.com and selecting "View with Glossary Links".
This option causes less server load because it only displays the links when requested. The disadvantage is that search engines may penalize you for duplicate content. For this option add rel="nofollow" to the "Glossary View" link to exclude article_glossary.php from robots.
Sample code for "View Glossary" link in the news_item.html template:
<a href="<{xoops_url}>/modules/news/article_glossary.php?storyid=<{$story.id}>" title="Click to display glossary links." rel="nofollow">View with Glossary Linksa>
>>>>>>>>>>>>>>>
Display Links to a WB Definition or URLUsing Wordbook's url field, you can modify this hack to create internal or external links instead of definition links.
-Modify db query:
replace:
$allterms = $xoopsDB -> query( "SELECT entryID, term FROM " . $xoopsDB -> prefix( "wbentries" ));
while ( list( $entryID, $term ) = $xoopsDB -> fetchrow($allterms ))
with:
$allterms = $xoopsDB -> query( "SELECT url, term FROM " . $xoopsDB -> prefix( "wbentries" ));
while ( list( $term_url, $term ) = $xoopsDB -> fetchrow($allterms ))
-Modify the link text:
replace:
<a style='color: #009933; text-decoration: underline; 'href='".XOOPS_URL."/modules/wordbook/entry.php?entryID=".$entryID."' title=' View a definition for ".$term."'>".$term."a>
with:
<a style='color: #009933; text-decoration: underline; ' href='".$term_url."' title='Visit ".$term_url."'>".$term."a>
>>>>>>>>>>>>>>>
Warning:This hack may not be suitable if your articles have link anchor text that contains glossary terms.
-Anchor text that contains a glossary term is split into multiple working links.
Example -Anchor text displaying URLs that contain glossary terms are split into multiple links and the original href url is ruined.
ExampleI need help coming up with some code that will ignore text in anchor tags. Any help appreciated!
>>>>>>>>>>>>>>>
QUESTION:The explode ">" only worked with dhtml or xoopseditor text and when I replaced the ">" with any other character, the html worked as well. What are the proper characters to use in that parameter? Could it be used as a string variable in an article's bodytext to switch the glossary links on? Example: Explode only when the string "|TERMSON|" is found in the body text.
Wordbook Code changes:
//$parts = explode(">", $definition); //Original code
$parts = explode("|TERMSON|", $bodytext); //New Code
//replaced $definition with $bodytext and ">" with |TERMSON|.
>>>>>>>>>>
Possible Future Improvements:-Modify the hack to work with other glossary modules. WB is inactive and outdated.
-Modify the hack to work with other popular content modules
-Automatically add found terms to the article's keyword meta tag.
-Open the definition in a popup window.
-Rollover link and definition in tool tip box.
Thanks for your constructive feedback. This is my first published hack, so please be gentle.*/