TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,917
  • Total Topics: 21,308
  • Online today: 884
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 1
  • Guests: 381
  • Total: 382
  • @rjen

Word cloud

Started by JPDeni, August 04, 2006, 08:34:56 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Harro

True... That error is not really helpfull...
I'll take another look at it once I had some sleep and when my headache is over :)

JPDeni

I hope it goes away soon. Headaches are no fun.

Maybe there's a difference in the version of MySQL or php that we have. I've got both "clouds" active and I'm getting no errors at all.

eitbuzz

Thanks JPDeni , its Great :up:

gijs

also tried it, but also empty block...

would really love to get this working on my site! Any ideas what is wrong?

akulion

if ur using 1.0.8 it may not work...are u?

gijs

SMF 1.1 RC3 and TinyPortal v0.9.5 ...

akulion

then it should definately work....can u post the code ur using here (exactly from ur block)

That way when JPDeni comes around she can have a look :up:

gijs

This is resulting in just an empty block. My forum has hundreds of topics on it though..

Here we go:


global $db_prefix;
$number_of_words = 50;
$min_length = 4;

// This is the list of words to exclude from your cloud
  $exclude_words = array(
    '@http://@',
    '@ about @',
    '@ also @',
    '@ because @',
    '@ been @',
    '@ cant @',
    '@ could @',
    '@ didnt @',
    '@ doesnt @',
    '@ dont @',
    '@ even @',
    '@ from @',
    '@ going @',
    '@ have @',
    '@ havent @',
    '@ here @',
    '@ http_request @',
    '@ into @',
    '@ its @',
    '@ just @',
    '@ like @',
    '@ look @',
    '@ make @',
    '@ many @',
    '@ more @',
    '@ much @',
    '@ must @',
    '@ need @',
    '@ should @',
    '@ shouldnt @',
    '@ some @',
    '@ someone @',
    '@ such @',
    '@ the @',
    '@ take @',
    '@ that @',
    '@ their @',
    '@ then @',
    '@ there @',
     '@ theres @',
   '@ these @',
    '@ they @',
    '@ this @',
    '@ this @',
    '@ want @',
    '@ well @',
    '@ were @',
    '@ what @',
    '@ when @',
    '@ where @',
    '@ which @',
    '@ will @',
    '@ with @',
    '@ without @',
    '@ would @',
    '@ wouldnt @',
    '@ your @',
    '@ youre @'
  );

// Various punctuation that should be filtered from the cloud
  $exclude_symbs = array('@[0-9]@','@\.@','@\,@','@\:@','@"@','@\?@','@\(@','@\)@','@\!@','@\/@','@\&@');
  $apostrophe = '&#'. '39;';
  $exclamation = '&#'. '33;';
  $nbsp = 'nb' . 'sp;';
  $quot = 'qu' . 'ot;';

// Reset our class globals and other variables
  $cloudy = '';
  $word_list = array();
  $cnt = 0;
  $high_count = 0;
  $low_count = 0;
  $totalwords = '';

  $query = db_query(
    "SELECT body
     FROM {$db_prefix}messages AS mess
     LEFT JOIN {$db_prefix}boards AS board
     ON mess.ID_BOARD = board.ID_BOARD
     WHERE FIND_IN_SET(-1, board.memberGroups)
     AND board.permission_mode = 2
     ORDER BY posterTime DESC
     LIMIT 30", __FILE__, __LINE__);

  while ($row = mysql_fetch_assoc($query))
  {
    $words = $row['body'];
    $words = parse_bbc($words,1);
    $words = strip_tags($words); // Clean HTML tags
    $words = strtolower($words); // Make all words lower case
    $words = str_replace($apostrophe,'',$words); // remove apostrophes
    $words = str_replace($exclamation,'',$words); // remove exclamations
    $words = str_replace($nbsp,'',$words); // remove non-breaking space
    $words = str_replace($quot,'',$words); // remove quote
    $words = preg_replace($exclude_symbs, ' ', $words); // Strip excluded symbols
    $words = preg_replace($exclude_words, ' ', $words); // Strip excluded words
    $words = preg_replace('/\s\s+/', ' ', $words); // Strip extra white space
    $totalwords .= $words;
  }
  $words = '';
  $wordslist = explode(' ', $totalwords); // Turn it back into an array
  $word_count = array_count_values($wordslist); // Count word usage

// Clear out the big array of words.
  arsort($word_count); // Sort the array by usage count

// Here we build our smaller array of words that will be used.
  foreach ($word_count as $key => $val) {
    if (strlen($key) >= $min_length) {
      if ($high_count == 0)
        $high_count = $val;
      $word_list[$key] = $val;
      $cnt++;
    }
    if ($cnt >= $number_of_words) {
      $low_count = $val;
      break;
    }
  }


// Get the high and low, and calculate the range.
// This is used to weight the size of the words

  $range = ($high_count - $low_count) / 5;


// Sort the array randomly for the cloud
  $random = array_rand($word_list, $number_of_words);
echo '<div style="text-align: center">';
// Build the cloud's HTML
  foreach ($random as $value) {
    $fsize = $word_list[$value] + 7;
    echo '<span style="font-size:' . $fsize . 'pt;">' . $value . '</span> ';
  }
echo '</div>';

gijs

I think I've narrowed it down to this line of code. When I remove it, I see a tag cloud, but not sure what's the impact of leaving out the code:

WHERE FIND_IN_SET(-1, board.memberGroups) AND board.permission_mode = 2

JPDeni

I've found the same problem, although I don't know when it started. If you remove the
AND board.permission_mode = 2
you'll get it to work. The first part of the code just makes sure that guests are able to see the board so that posts from admin-only boards aren't included. I'll have to go see what the permission_mode thing does. I don't remember why I put it in there. :)

BTW, when you posted this, it was 1 am where I was. I haven't been ignoring you. I've been asleep.

This website is proudly hosted on Crocweb Cloud Website Hosting.