PDA

View Full Version : How do I make keyword cloud module?


osousous
10-07-2007, 07:19 PM
There is an add on for a keword page, but I would like to put this into a module.

There is only one php file:


<?php

error_reporting(E_ALL & ~E_NOTICE);

define('THIS_SCRIPT','wordcloud');

$phrasegroups = array();
$specialtemplates = array();
$globaltemplates = array('shell_blank');
$actiontemplates = array();

require_once('./global.php');

$vbphrase['wordcloud_score'] = 'Score';
$vbphrase['wordcloud_word_cloud'] = 'Word Cloud';

$wordcloud_infos = $db->query_read("
SELECT SUM(score) AS f1, t2.title AS f2
FROM " . TABLE_PREFIX . "postindex AS t1, " . TABLE_PREFIX . "word AS t2
WHERE t1.wordid = t2.wordid GROUP BY t1.wordid ORDER BY f1 DESC LIMIT 100
");

$wordcloud_scoreinit = 0;
$wordcloud_fontinit = 144;
$wordcloud_htmlarray = array();

while ($wordcloud_info = $db->fetch_array($wordcloud_infos))
{
if (!$wordcloud_scoreinit)
{
$wordcloud_scoreinit = intval($wordcloud_info['f1']);
}

$wordcloud_scorerow = intval($wordcloud_info['f1']);
$wordcloud_wordrow = htmlspecialchars($wordcloud_info['f2']);
$wordcloud_queryrow = urlencode($wordcloud_info['f2']);

$wordcloud_fontrow = 10;
if ($wordcloud_scoreinit > 0)
{
$wordcloud_fontrow = intval($wordcloud_scorerow / $wordcloud_scoreinit * $wordcloud_fontinit);
}
if ($wordcloud_fontrow > 72)
{
$wordcloud_fontrow = 72;
}
if ($wordcloud_fontrow < 10)
{
$wordcloud_fontrow = 10;
}

$wordcloud_scorerow = vb_number_format($wordcloud_scorerow);

$wordcloud_htmlarray[] = '
<a style="text-decoration: none;" href="search.php?' . $vbulletin->vars->session['sessionurl'] .
'do=process&amp;query=' . $wordcloud_queryrow .
'" title="' . $vbphrase['wordcloud_score'] . ': ' . $wordcloud_scorerow . '"><span style="font: ' .
$wordcloud_fontrow . 'px tahoma, verdana, geneva, arial, helvetica, sans-serif;">' .
$wordcloud_wordrow . '</span></a>
';
}

$db->free_result($wordcloud_infos);

shuffle($wordcloud_htmlarray);
$html = implode('', $wordcloud_htmlarray);
$html = '
<table border="0" width="90%" cellpadding="0" cellspacing="0" align="center"><tr><td align="center">
' . $html . '
</td></tr></table>
<br /><br />
';

$navbits = array('' => $vbphrase['wordcloud_word_cloud']);
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('shell_blank') . '");');

?>


Any idea would be much appreciated!

osousous
10-08-2007, 03:57 PM
Anybody?

I can pay a small fee if needs be?

Our Sponsors
 

Unkalledfor
10-08-2007, 05:25 PM
theres a mod called Zoints Tags.. search for it at vbulletin.org

osousous
10-08-2007, 07:02 PM
theres a mod called Zoints Tags.. search for it at vbulletin.orgYep thats for tags - this is different. Thanks.

Our Sponsors
 

Brian
10-09-2007, 12:20 PM
Try creating a new PHP file with the content below, save it to your forum/modules folder, add a new PHP file module through your Admin CP, and be sure to select the file that you just created as the 'File to Include'.
<?php

$vbphrase['wordcloud_score'] = 'Score';
$vbphrase['wordcloud_word_cloud'] = 'Word Cloud';

$wordcloud_infos = $db->query_read("
SELECT SUM(score) AS f1, t2.title AS f2
FROM " . TABLE_PREFIX . "postindex AS t1, " . TABLE_PREFIX . "word AS t2
WHERE t1.wordid = t2.wordid GROUP BY t1.wordid ORDER BY f1 DESC LIMIT 100
");

$wordcloud_scoreinit = 0;
$wordcloud_fontinit = 144;
$wordcloud_htmlarray = array();

while ($wordcloud_info = $db->fetch_array($wordcloud_infos))
{
if (!$wordcloud_scoreinit)
{
$wordcloud_scoreinit = intval($wordcloud_info['f1']);
}

$wordcloud_scorerow = intval($wordcloud_info['f1']);
$wordcloud_wordrow = htmlspecialchars($wordcloud_info['f2']);
$wordcloud_queryrow = urlencode($wordcloud_info['f2']);

$wordcloud_fontrow = 10;
if ($wordcloud_scoreinit > 0)
{
$wordcloud_fontrow = intval($wordcloud_scorerow / $wordcloud_scoreinit * $wordcloud_fontinit);
}
if ($wordcloud_fontrow > 72)
{
$wordcloud_fontrow = 72;
}
if ($wordcloud_fontrow < 10)
{
$wordcloud_fontrow = 10;
}

$wordcloud_scorerow = vb_number_format($wordcloud_scorerow);

$wordcloud_htmlarray[] = '
<a style="text-decoration: none;" href="search.php?' . $vbulletin->vars->session['sessionurl'] .
'do=process&amp;query=' . $wordcloud_queryrow .
'" title="' . $vbphrase['wordcloud_score'] . ': ' . $wordcloud_scorerow . '"><span style="font: ' .
$wordcloud_fontrow . 'px tahoma, verdana, geneva, arial, helvetica, sans-serif;">' .
$wordcloud_wordrow . '</span></a>
';
}

$db->free_result($wordcloud_infos);

shuffle($wordcloud_htmlarray);
$html = implode('', $wordcloud_htmlarray);

$show['tablerow'] = true;

$home[$mods['modid']]['content'] = $html;

?>

osousous
10-09-2007, 03:31 PM
I have tried that and it crashed the home page.

I'll state again - anyone that can achieve this for me can receive a nice cash donation from myself.

Cheers.

Brian
10-10-2007, 03:46 PM
How exactly is it "crashing" the homepage?

osousous
10-10-2007, 06:08 PM
How exactly is it "crashing" the homepage?
Sorry, I should be more accurate.

When I put it into the module as you instructed, and place that module on the home page I just get a blank page on the home page.

Brian
10-11-2007, 10:53 AM
Does the code work ok when you access it using the default PHP file? If so, there really shouldn't be any differences between the two or any reason it shouldn't work as a module.

osousous
10-11-2007, 02:42 PM
Does the code work ok when you access it using the default PHP file? If so, there really shouldn't be any differences between the two or any reason it shouldn't work as a module.Yep it works as a php file.

I can't understand why it isn't working.

Is there any options or any silly mistakes, minor details I may be making or missing?

Brian
10-12-2007, 12:41 PM
I tried testing the module here, but didn't have any problems. I'll attach the .module file here so you can just try uploading it via the 'Download / Upload Module' link and see if you get any better results.

osousous
10-12-2007, 07:53 PM
I tried testing the module here, but didn't have any problems. I'll attach the .module file here so you can just try uploading it via the 'Download / Upload Module' link and see if you get any better results.
wow. It works. Thank you very much.

neverstop
10-12-2007, 09:15 PM
Hi Brian,

Do you think this can be modified for use with the links directory? I was thinking of something like a "recent searches" module where the query searches the last x searchids from adv_links_search (string) and returns the results with the different font sizes and such. Did that makes sense?

Cheers,
Ian

eden
11-19-2007, 07:09 PM
This works on VbAdvanced CMPS or only into dynamics?

Brian
11-20-2007, 10:48 AM
It should work with either.

GentleOceanWind
03-31-2008, 02:35 AM
Sweet! Is there any way to modify the size/number of words displayed?

ETA: changed the settings through .module file :)

LOVE this, thanks so much, so easy, too! :D

reoxer
04-29-2008, 01:24 AM
modul work vba version 3.0.1 WOw!!!