Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Keyword Highlighting

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 09-22-2008, 05:36 PM
 
paul@dimoda.com.au paul@dimoda.com.au is offline
 

Senior Member
  
Join Date: Aug 2007
Location: Perth, Australia
Posts: 148
 

Default Keyword Highlighting

I am hoping someone can assist and that others find the solution beneficial.

I am looking for a way to automatically highlight keywords in site content.

In the style of say wikipedia, once a repository of keyword and landing pages strings is created, anytime this string of keywords appears in site content (welcome text, product or category descriptions) the keywords will be automatically highlighted and hyperlinks created.

To illustrate, on our www.CoffeeShrine.com.au site we sell Coffee Machines, and coffee making supplies. A keywords string could be "Office Coffee Machines" which would link to the "office coffee machines" category page.

Anytime we used thee striong office coffee machines in content, it would be automatically highlighted with the link pointing to the category page.

The puprose of this is to significantly increase the deep linking and interconnectivity of pages in the site which would be beneficial to both humand and search engines.

I know a number of blog engines have mods like this - can anyone help please?

Could be one for the developers of XCSEO or CDSEO or the likes...
__________________
X-Cart Gold 4.1.10, 4.1.18, 4.4.4, 4.4.5
Reply With Quote
  #2  
Old 09-23-2008, 01:32 AM
  Victor D's Avatar 
Victor D Victor D is offline
 

X-Adept
  
Join Date: Aug 2008
Posts: 643
 

Default Re: Keyword Highlighting

It takes some time, but the task is quite simple.
Create Smarty output filter or postfilter (two ways are possible) like this
PHP Code:
function hyperlink_all_coffee($tpl_output, &$smarty)
{
 return 
str_replace("Coffee",  '<a href="http://link.to.coffee">Coffee</a>'$tpl_output);


and register it in smarty.php

PHP Code:
$smarty->register_outputfilter("hyperlink_all_coffee"); 

But it may cause some issues if these words are hyperlink already.

See the complete smarty.php below:
PHP Code:
<?php
/*****************************************************************************\
+-----------------------------------------------------------------------------+
| X-Cart                                                                      |
| Copyright (c) 2001-2008 Ruslan R. Fazliev <rrf@rrf.ru>                      |
| All rights reserved.                                                        |
+-----------------------------------------------------------------------------+
| PLEASE READ  THE FULL TEXT OF SOFTWARE LICENSE AGREEMENT IN THE "COPYRIGHT" |
| FILE PROVIDED WITH THIS DISTRIBUTION. THE AGREEMENT TEXT IS ALSO AVAILABLE  |
| AT THE FOLLOWING URL: http://www.x-cart.com/license.php                     |
|                                                                             |
| THIS  AGREEMENT  EXPRESSES  THE  TERMS  AND CONDITIONS ON WHICH YOU MAY USE |
| THIS SOFTWARE   PROGRAM   AND  ASSOCIATED  DOCUMENTATION   THAT  RUSLAN  R. |
| FAZLIEV (hereinafter  referred to as "THE AUTHOR") IS FURNISHING  OR MAKING |
| AVAILABLE TO YOU WITH  THIS  AGREEMENT  (COLLECTIVELY,  THE  "SOFTWARE").   |
| PLEASE   REVIEW   THE  TERMS  AND   CONDITIONS  OF  THIS  LICENSE AGREEMENT |
| CAREFULLY   BEFORE   INSTALLING   OR  USING  THE  SOFTWARE.  BY INSTALLING, |
| COPYING   OR   OTHERWISE   USING   THE   SOFTWARE,  YOU  AND  YOUR  COMPANY |
| (COLLECTIVELY,  "YOU")  ARE  ACCEPTING  AND AGREEING  TO  THE TERMS OF THIS |
| LICENSE   AGREEMENT.   IF  YOU    ARE  NOT  WILLING   TO  BE  BOUND BY THIS |
| AGREEMENT, DO  NOT INSTALL OR USE THE SOFTWARE.  VARIOUS   COPYRIGHTS   AND |
| OTHER   INTELLECTUAL   PROPERTY   RIGHTS    PROTECT   THE   SOFTWARE.  THIS |
| AGREEMENT IS A LICENSE AGREEMENT THAT GIVES  YOU  LIMITED  RIGHTS   TO  USE |
| THE  SOFTWARE   AND  NOT  AN  AGREEMENT  FOR SALE OR FOR  TRANSFER OF TITLE.|
| THE AUTHOR RETAINS ALL RIGHTS NOT EXPRESSLY GRANTED BY THIS AGREEMENT.      |
|                                                                             |
| The Initial Developer of the Original Code is Ruslan R. Fazliev             |
| Portions created by Ruslan R. Fazliev are Copyright (C) 2001-2008           |
| Ruslan R. Fazliev. All Rights Reserved.                                     |
+-----------------------------------------------------------------------------+
\*****************************************************************************/

#
# $Id: smarty.php,v 1.39.2.5 2008/04/28 07:34:54 max Exp $
#

if ( !defined('XCART_START') ) { header("Location: index.php"); die("Access denied"); }

umask(0);

#
# Define SMARTY_DIR to avoid problems with PHP 4.2.3 & SunOS
#
define('SMARTY_DIR'$xcart_dir.DIRECTORY_SEPARATOR."Smarty-2.6.19".DIRECTORY_SEPARATOR);

include_once(
$xcart_dir."/include/templater/templater.php");

#
# Smarty object for processing html templates
#
$smarty = new Templater;

#
# Store all compiled templates to the single directory
#
$smarty->use_sub_dirs false;
$smarty->request_use_auto_globals false;

$smarty->template_dir $xcart_dir."/skin1";
$smarty->compile_dir $var_dirs["templates_c"];
$smarty->config_dir $xcart_dir."/skin1";
$smarty->cache_dir $var_dirs["cache"];
$smarty->secure_dir $xcart_dir."/skin1";
$smarty->debug_tpl "file:debug_templates.tpl";

$smarty->assign("ImagesDir",$xcart_web_dir."/skin1/images");
$smarty->assign("SkinDir",$xcart_web_dir."/skin1");
$smarty->assign("template_dir"$smarty->template_dir);
$smarty->assign("sm_prnotice_txt", @$_prnotice_txt);

function 
hyperlink_all_coffee($tpl_output, &$smarty)
{
 return 
str_replace("Coffee",  '<a href="http://link.to.coffee">Coffee</a>'$tpl_output);
}
$smarty->register_outputfilter("hyperlink_all_coffee");
 
#
# Smarty object for processing mail templates
#
$mail_smarty $smarty;

#
# WARNING :
# Please ensure that you have no whitespaces / empty lines below this message.
# Adding a whitespace or an empty line below this line will cause a PHP error.
#
?>
__________________
Regards,
Victor Dubiniuk

X-Cart Skins Store
- twenty two different skins for 4.1.x and 4.2.x;
- 4.3.x compatible versions are available;
- refresh you store now!

Smart menu X-Cart add-on for 4.1.8 - 4.3.x
Featured Products Slide Show X-Cart add-on for 4.1.8 - 4.3.x
Reply With Quote
  #3  
Old 09-23-2008, 02:24 AM
 
paul@dimoda.com.au paul@dimoda.com.au is offline
 

Senior Member
  
Join Date: Aug 2007
Location: Perth, Australia
Posts: 148
 

Default Re: Keyword Highlighting

Wow, just like that!

Is there some way that I could limit this to just content (for example anything that is in a dialogue wrapper),

or exclude anything that is wrapped anything that in certain tags such as <a>, <h1> <h2> <h3> etc etc...
__________________
X-Cart Gold 4.1.10, 4.1.18, 4.4.4, 4.4.5
Reply With Quote
  #4  
Old 09-23-2008, 02:42 AM
  Victor D's Avatar 
Victor D Victor D is offline
 

X-Adept
  
Join Date: Aug 2008
Posts: 643
 

Default Re: Keyword Highlighting

to use this filter inside the dialogs you have to remove
PHP Code:
$smarty->register_outputfilter("hyperlink_all_coffee"); 
from smarty.php

and insert somewhere in your dialog.tpl
HTML Code:
{if $usertype eq 'C'} {php} $smarty->register_outputfilter("hyperlink_all_coffee"); {/php} {/if}


and
HTML Code:
{if $usertype eq 'C'} {php} $smarty->unregister_outputfilter("hyperlink_all_coffee"); {/php} {/if}

somewhere in the end of your dialog.tpl

Excluding all specific matches is also possible.
You have to use regular expressions instead of str_replace function in such case. But it's more complex task. I've just figured out the common way to get over it.
__________________
Regards,
Victor Dubiniuk

X-Cart Skins Store
- twenty two different skins for 4.1.x and 4.2.x;
- 4.3.x compatible versions are available;
- refresh you store now!

Smart menu X-Cart add-on for 4.1.8 - 4.3.x
Featured Products Slide Show X-Cart add-on for 4.1.8 - 4.3.x
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 11:16 PM.

   

 
X-Cart forums © 2001-2020