Support Forums

Development Forum

Automatic glossary markup


You must be signed-in to post.

AuthorSubject
  Page: 1
mwarner
glossary_1.zip

Attachment: glossary_1.zip
Subject: Automatic glossary markupQuote this post in your reply
ATutor version - 1.6.1

Since we sometimes have large glossaries, I've developed code to automatically add the [?] and [/?] to the first instance of a glossary word to the content of the page. It is case-insensitive.

I've attached a patch and have listed the modifications below.

Mike


/content.php
- add, on line 44:
$row['text']=$contentManager->markGlossaryWords($row['text']);


/include/html/dropdowns/glossary.inc.php
- add, on line 28:
$row['text']=$contentManager->markGlossaryWords($row['text']);


/include/classes/ContentManager.class.php
- add anywhere in the functions:

function markGlossaryWords($content){
$SQL="select group_concat(word) as words from ".TABLE_PREFIX."glossary where course_id=".$_SESSION["course_id"];
$glossaryResult=mysql_query($SQL);
if(mysql_num_rows($glossaryResult)){
$glossaryRow=mysql_fetch_assoc($glossaryResult);
if($glossaryRow["words"]){
$glossaryWords=$glossaryRow["words"];
$glossaryWords="/\b(".str_replace(",",")\b/i,/\b(",$glossaryWords).")\b/i";// \b is word boundary, i means case-insensitive
$glossaryWords=str_replace(" ","\ ",$glossaryWords);
$glossaryWordsArray=explode(",",$glossaryWords);
$content=preg_replace($glossaryWordsArray,"[?]$1[/?]",$content,1);//the 1 at the end tells it to replace only the first instance
}
}
return $content;
}
Posted: 2009-03-30 16:14:08
mwarner
Subject: Re: Automatic glossary markup - can this be deleted?Quote this post in your reply
got a double-post, where this first one has no attachment. Sorry about that. Can you delete this thread?

Thanks,
Mike
Posted: 2009-03-30 16:17:15
cindy

Avatar for cindy
Subject: Re: Automatic glossary markup - can this be deleted?Quote this post in your reply
Hi Mike,

Thanks for the contribution. A very good idea on glossary.

Somehow the code doesn't work well in my system. 2 problems:

1. the glossary word is replaced to "[?][/?]" instead of "[?]glossaryWord[/?]".

2. If the glossaryWord had already been wrapped in "[?][/?]", your function double wrap it, which ends up "[?][?][/?][/?]", as 1 specified, glossaryWord self is missing too.

As I don't have time for now to change the code. If you could not investigate further, I will pick up once have time.

BTW, your patch is created for version 1.6.1. The lucky thing is the scripts you changed didn't change much from 1.6.1 to current 1.6.2. Next time could you create patch on the latest version? So that we don't have to migrate.

Thanks.

Cindy
Posted: 2009-03-31 10:06:40
mwarner
glossary_1.zip

Attachment: glossary_1.zip
Subject: Re: Automatic glossary markup - can this be deleted?Quote this post in your reply
Hi Cindy,

not sure why #1 is happening on your system. Is it happening to words already marked with [?][/?] or to all glossary words?

the idea behind this patch was to make it so the content developer doesn't need to wrap the words with [?][/?]. As such, I wasn't looking for words already wrapped. To get by this for already wrapped words, you could add the following as the first line of the markGlossaryWords function:

$content=str_replace(array("[?]","[/?]"),"",$content);

I think I'll add that, anyway, so the code will work with courses already marked up for glossary words.
Posted: 2009-03-31 10:21:46
cindy

Avatar for cindy
Subject: Re: Automatic glossary markup - can this be deleted?Quote this post in your reply
Thanks.

Regarding ur question: happens to all glossary words.
Posted: 2009-03-31 10:55:51
mwarner
Subject: Re: Automatic glossary markup - can this be deleted?Quote this post in your reply
Interesting. Did you try with the addition to the markGlossaryWords function?
Posted: 2009-03-31 13:46:40
cindy

Avatar for cindy
Subject: Re: Automatic glossary markup - can this be deleted?Quote this post in your reply
yes.
Posted: 2009-03-31 13:48:41
mwarner
Subject: Re: Automatic glossary markup - can this be deleted?Quote this post in your reply
Interesting. Can you grant me temporary student access to a course via Authenticated Access so I can take a look? My email address is mwarner_at_mindedge.com I'd like to make sure this will work for you (and everyone else).

Mike
Posted: 2009-03-31 13:55:17
cindy

Avatar for cindy
Subject: Re: Automatic glossary markup - can this be deleted?Quote this post in your reply
Thanks, Mike. But my trial is on my localhost, cannot grant u access. I tried again on a fresh installed 1.6.1, same problem.
Posted: 2009-03-31 14:09:29
mwarner
Subject: Re: Automatic glossary markup - can this be deleted?Quote this post in your reply
hmmm...what are your server specs?

Operating system ATutor is installed on -
PHP version -
MySQL version -
Webserver & version -
Posted: 2009-03-31 15:20:00
cindy

Avatar for cindy
Subject: Re: Automatic glossary markup - can this be deleted?Quote this post in your reply
Thanks alot, Mike. If this takes too much of ur time, i will have a look once freed up.

ATutor Version:
1.6.1. Check Latest Version.
PHP Version:
5.2.5
MySQL Version:
5.0.51a
OS:
Windows NT 5.1
Webserver:
Apache/2.2.8 (Win32)
Posted: 2009-03-31 15:26:16
cindy

Avatar for cindy
Subject: Re: Automatic glossary markup - can this be deleted?Quote this post in your reply
Hi Mike,

I modified markGlossaryWords() function, change this line from

$content=preg_replace($glossaryWordsArray,"[?][/?]",$content, 1);

to

$content=preg_replace($glossaryWordsArray,"[?]\\1[/?]",$content);

Now it works. Thanks for your contribution.
Posted: 2009-04-30 10:50:51
mwarner
Subject: Re: Automatic glossary markup - can this be deleted?Quote this post in your reply
Great! I'm glad you got it working. I tried your modification and it works on a Linux server as well. Did the 1 limiter at the end not work at all for you?

Mike
Posted: 2009-04-30 11:22:23
cindy

Avatar for cindy
Subject: Re: Automatic glossary markup - can this be deleted?Quote this post in your reply
limit 1 worked. Only replace the first occurance.
Posted: 2009-04-30 11:34:03
mwarner
Subject: Re: Automatic glossary markup - can this be deleted?Quote this post in your reply
Great! Now I'll try to post this as an official patch request.

Thanks for the help in testing. We're finding this code very useful here.

Mike
Posted: 2009-04-30 11:40:21
 Page: 1

You must be signed-in to post.