Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Trying to create an extension and need a little help

edited July 2006 in Vanilla 1.0 Help
I'm trying to port a Wordpress plugin for keywords and have 2 problems. The first is I get the error: Technical information (for support personel): Error Message The "weightedwords" class referenced by "weightedwords" does not appear to exist. Affected Elements ObjectFactory.NewObject(); I've created that class and it's working but I get this error when I try to sign out. I've looked at a lot of other extensions and tried to learn from them and I've looked at the documentation. But apparently, I've missed something. Any help would be appreciated.

Comments

  • MarkMark Vanilla Staff
    edited July 2006
    It sounds like you've got your class included only for people who are signed in. Once the person signs out it stops including the class in the page and throws the error. The easiest way to resolve the error would probably be for you to post your extension source on here between <code></code> blocks. If your extension has a lot of code, you can always rename it .txt and link to it so we can take a look.
  • edited July 2006
    Thanks, here is the code.
    <?php /* Extension Name: Weighted Words Extension Url: http://www.jwurster.us/gfe/ Description: An extension to display a weighted list of commonly-used words. Ported from WP plugin by Yami McMoots http://greengabbro.net. Version: 1.1 Author: Jim Wurster Author Url: http://www.jwurster.us/ */ $Context->Dictionary['WeightedWords'] = 'Weighted Words'; if (in_array($Context->SelfUrl, array("index.php", "account.php", "categories.php", "comments.php", "post.php", "search.php", "settings.php"))) { class weightedwords { function weighted_words($mincount=1, $minlength=3, $minfont=50, $maxfont=250) { global $wwordsDisplay; // Build the list of words and convert everything to lowercase. $now = gmdate("Y-m-d H:i:s",time()); // $postcontents = $wpdb->get_results("SELECT post_content FROM $wpdb->posts WHERE post_status = 'publish' AND post_date < '$now'"); mysql_select_db('vanilla'); $query = "SELECT * FROM LUM_Comment WHERE Body > ' ' AND CommentID > 1 AND Deleted = '0'"; $result = mysql_query($query); $num_results = mysql_num_rows($result); $string = ''; if ($result) { while ($row = mysql_fetch_array($result)) { $postwords = strip_tags($row[7]); $string = $string.$postwords; } } else { echo "empty array"; exit; } $string = strtolower($string); // Remove punctuation. $wordlist = preg_split('/\s*[\s+\.|\?|,|(|)|\-+|\'|\*|\"|=|;|%|\!|\[|\]|&#0215;|\$|\/|:|{|}]\s*/i', $string); // Build an array of the unique words and number of times they occur. $a = array_count_values( $wordlist ); // Remove words that don't matter--"stop words." // Edit this list as needed. $overusedwords = array('', 'a', 'am', 'an','the', 'and', 'of', 'i', 'to', 'is', 'in', 'for', 'as', 'that', 'on', 'at', 'this', 'my', 'was', 'our', 'it', 'its', 'you', 'we', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '10', 'about', 'actually', 'after', 'again', 'all', 'almost', 'along', 'also', 'always', 'another', 'any', 'anyone', 'anything', 'anyway', 'are', 'area', 'around', 'available', 'back', 'be', 'because', 'been', 'before', 'being', 'best', 'better', 'between', 'big', 'bit', 'both', 'but', 'by', 'c', 'came', 'can', 'capable', 'control', 'could', 'course', 'd', 'day', 'decided', 'did', 'didn', 'different', 'div', 'do', 'does', 'doesn', 'doing', 'down', 'drive', 'e', 'each', 'easy', 'else', 'end', 'enough', 'even', 'ever', 'every', 'example', 'few', 'find', 'first', 'found', 'from', 'get', 'go', 'going', 'good', 'got', 'had', 'hard', 'has', 'have', 'haven', 'he', 'her', 'hers', 'here', 'him', 'his', 'how', 'if', 'into', 'isn', 'just', 'kind', 'know', 'last', 'least', 'left', 'like', 'little', 'll', 'long', 'look', 'lot', 'm', 'made', 'make', 'many', 'may', 'maybe', 'me', 'might', 'more', 'most', 'much', 'my', 'name', 'nbsp', 'need', 'never', 'new', 'no', 'not', 'now', 'number', 'o', 'off', 'ok', 'okay', 'old', 'one', 'only', 'or', 'other', 'out', 'over', 'own', 'part', 'people', 'place', 'point', 'pretty', 'probably', 'problem', 'put', 'quite', 'quot', 'r', 're', 'really', 'results', 'right', 's', 'same', 'saw', 'say', 'see', 'set', 'several', 'she', 'should', 'since', 'size', 'small', 'so', 'some', 'someone', 'something', 'special', 'still', 'stuff', 'such', 'sure', 'system', 't', 'take', 'than', 'their', 'them', 'then', 'there', 'these', 'they', 'thing', 'things', 'think', 'those', 'though', 'through', 'time', 'today', 'together', 'too', 'took', 'two', 'up', 'us', 'use', 'used', 'using', 've', 'very', 'want', 'way', 'well', 'went', 'were', 'what', 'when', 'where', 'which', 'while', 'who', 'why', 'will', 'with', 'without', 'would', 'wouldn', 'x', 'y', 'your', 'however', 'simply', 'having', 'either', 'across', 'trying', 'instead', 'issues', 'coming', 'changed', 'called', 'become', 'article', 'everything'); // Remove the stop words from the list. foreach ($overusedwords as $word) { unset( $a[$word] ); } // Sort the keys alphabetically. ksort( $a ); // Remove short words. foreach ( $a as $word => $count ) { if ( strlen($word) < $minlength ) { unset( $a[$word] ); } } // Print the data. $wwordsDisplay = ' '; $wwordsDisplay = '<h2>Keywords</h2><p class="weightedwordlist">'; // Assign a font-size to the word based on frequency of use. $maxcount = max($a); $spread = $maxcount - $mincount; if ($spread <= 0) { $spread = 1; }; $fontspread = $maxfont - $minfont; $fontstep = $spread / $fontspread; if ($fontspread <= 0) { $fontspread = 1; } foreach ($a as $word => $count) { // Assign a size. $size = $minfont + $count/$fontstep; // The keyword needs to be referenced $mincount or more times to register, // and must be at least $minlength letters long. if ($count >= $mincount && strlen($word) >= $minlength) { $wwordsDisplay .= ' <span style="font-size: ' . $size . '%;"><a href="'; // $wwordsDisplay .= $Context->Configuration["BASE_URL"]; // bloginfo('url'); $wwordsDisplay .= '//localhost/vanilla.1'; // Edit this string to change your search URL. // $wwordsDisplay .= '/index.php?s=' . $word . '&submit=ww'; // If you want to search w/ http://www.example.com/search/word use: $wwordsDisplay .= '/search.php?PostBackAction=Search&Keywords=' . $word . '&Type=Comments&btnSubmit=Search'; $wwordsDisplay .= '" title="Count: ' . $count . '">'; $wwordsDisplay .= $word; $wwordsDisplay .= '</a></span> '; } } $wwordsDisplay .= '</p>'; return $wwordsDisplay; } // function Init_wwords() { $this->Now = time(); $this->BackColour = "Legend BlockedCategory"; } } } $weightedwords = $Context->ObjectFactory->NewContextObject($Context, 'weightedwords'); $weightedwords->weighted_words(); $Panel->AddString($wwordsDisplay, 500); //echo $wwordsDisplay; //$Page->AddRenderControl($wwordsDisplay, $Configuration["CONTROL_POSITION_HEAD"]+1); ?>
  • MarkMark Vanilla Staff
    It looks like the problem isn't session related. You've got that if statement at the top that only includes the class on certain pages and then at the bottom *after* the if statement you instantiate the class. You should move the instantiation up into the if braces.
  • That did it. Thank you very much. Since you were so helpful, maybe you could help with the second part. The WP plugin created a keyword list that when you clicked on the keyword, it would get all referenced posts and display them for you. It is different here because I am looking in Comments but I did figure that out. However, I don't seem to be able to get the syntax right for the "a href". What I have above works but is not clean. It feeds the keyword into the Search dialog and submits it. The Search dialog is displayed along with the list of Comments that contain the keyword. Does this seem like what the users would want to see? I was trying to get it to do the search and just display the list of Comments.
This discussion has been closed.