Index: searchcloud.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/searchcloud/searchcloud.info,v retrieving revision 1.1 diff -u -p -r1.1 searchcloud.info --- searchcloud.info 31 Jul 2008 18:43:24 -0000 1.1 +++ searchcloud.info 27 Sep 2008 00:39:27 -0000 @@ -1,6 +1,6 @@ name = Search Index Cloud -description = "The module produces a tag cloud from stored search terms, based on term occurrences and various limits. The tag cloud is displayed in a dedicated block." -dependencies = search -version = "5.x-1.1" -project = "searchcloud" -package = "Other" \ No newline at end of file +description = The module produces a tag cloud from stored search terms, based on term occurrences and various limits. The tag cloud is displayed in a dedicated block. +core = 6.x +dependencies[] = search + +$Id$ \ No newline at end of file Index: searchcloud.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/searchcloud/searchcloud.install,v retrieving revision 1.1 diff -u -p -r1.1 searchcloud.install --- searchcloud.install 31 Jul 2008 18:43:24 -0000 1.1 +++ searchcloud.install 27 Sep 2008 00:39:27 -0000 @@ -2,30 +2,21 @@ /** * Implementation of hook_install(). */ + +function searchcloud_schema() { + $schema['searchcloud'] = array( + 'fields' => array( + 'searchcloud_term' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE), + 'searchcloud_count' => array('type' => 'int', 'not null' => TRUE, 'disp-width' => '11')), + 'indexes' => array( + 'searchcloud_term' => array('searchcloud_term')), + ); + return $schema; +} function searchcloud_install() { drupal_set_message(t('Beginning installation of searchcloud module.')); // db: - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - db_query("CREATE TABLE searchcloud ( - searchcloud_term VARCHAR( 255 ) NOT NULL , - searchcloud_count INT NOT NULL , - INDEX (searchcloud_term) - )"); - $success = TRUE; - break; - case 'pgsql': - db_query("CREATE TABLE searchcloud ( - searchcloud_term VARCHAR( 255 ) NOT NULL , - searchcloud_count INT NOT NULL , - INDEX (searchcloud_term) - )"); - $success = TRUE; - break; - default: - drupal_set_message(t('Unsupported database.')); - } + $result = drupal_install_schema('searchcloud'); // vars & cache: variable_set('searchcloud_minimum_tag_length', variable_get('minimum_word_size', 3)); variable_set('searchcloud_underline_links', 0); @@ -40,7 +31,7 @@ function searchcloud_install() { variable_get('searchcloud_tag_limit', 0); cache_clear_all(); // feedback: - if ($success) { + if ($result['success']) { drupal_set_message(t('The searchcloud module installed tables successfully.')); } else { @@ -53,19 +44,7 @@ function searchcloud_install() { function searchcloud_uninstall() { drupal_set_message(t('Beginning uninstallation of searchcloud module.')); // db: - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - db_query("DROP TABLE {searchcloud}"); - $success = TRUE; - break; - case 'pgsql': - db_query("DROP TABLE {searchcloud}"); - $success = TRUE; - break; - default: - drupal_set_message(t('Unsupported database.')); - } + $result = drupal_uninstall_schema('searchcloud'); // vars & cache: variable_del('searchcloud_minimum_tag_length'); variable_del('searchcloud_underline_links'); @@ -80,7 +59,7 @@ function searchcloud_uninstall() { variable_del('searchcloud_tag_limit'); cache_clear_all('variables', 'cache'); // feedback: - if ($success) { + if ($result['success']) { drupal_set_message(t('The searchcloud module was uninstalled successfully.')); } else { Index: searchcloud.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/searchcloud/searchcloud.module,v retrieving revision 1.1 diff -u -p -r1.1 searchcloud.module --- searchcloud.module 31 Jul 2008 18:43:24 -0000 1.1 +++ searchcloud.module 27 Sep 2008 00:39:28 -0000 @@ -1,4 +1,5 @@ 'textfield', - '#title' => t('Minimum font size'), - '#default_value' => variable_get('searchcloud_min_font_size', 14), - '#description' => t('Enter the minimum font size in pixels.'), - '#size'=>2 - ); - $form['searchcloud_max_font_size'] = array( - '#type' => 'textfield', - '#title' => t('Maximum font size'), - '#default_value' => variable_get('searchcloud_max_font_size', 24), - '#description' => t('Enter the maximum font size in pixels.'), - '#size'=>2 - ); - $form['searchcloud_use_colors'] = array( - '#type' => 'checkbox', - '#title' => t('Use color tones'), - '#default_value' => variable_get('searchcloud_use_colors', 1), - '#description' => t('Check this if you want to use color tones on tags. Make sure the number of light&dark color tones is equal to the difference between maximum and minimum font size.') - ); - $form['searchcloud_light_colors'] = array( - '#type' => 'textarea', - '#title' => t('Light color tones'), - '#default_value' => variable_get('searchcloud_light_colors', "#00FFFF,#F0F8FF,#FFF0F5,#FFE4B5,#EEE8AA,#98FB98,#B0C4DE,#FF00FF,#0000CD,#FDF5E6"), - '#description' => t('Separate colors with commas, nothing else.'), - '#cols' => 60, - '#rows' => 2 - ); - $form['searchcloud_dark_colors'] = array( - '#type' => 'textarea', - '#title' => t('Dark color tones'), - '#default_value' => variable_get('searchcloud_dark_colors', "#0000FF,#FF0000,#00008B,#A52A2A,#FF00FF,#008000,#C71585,#8B4513,#008080,#2F4F4F"), - '#description' => t('Separate colors with commas, nothing else.'), - '#cols' => 60, - '#rows' => 2 - ); - $form['searchcloud_use_light_colors'] = array( - '#type' => 'checkbox', - '#title' => t('Use the light color tones'), - '#default_value' => variable_get('searchcloud_use_light_colors', 0), - '#description' => t('Check this if you want to use the light color tones on tags.') - ); - $form['searchcloud_ignored_words'] = array( - '#type' => 'textarea', - '#title' => t('Ignored words'), - '#default_value' => variable_get('searchcloud_ignored_words', "?,of,the,is,off,you,them,then,at,with,i,it,We,we"), - '#description' => t('Separate words with commas, nothing else.'), - '#cols' => 60, - '#rows' => 2 - ); - $form['searchcloud_ignored_chars'] = array( - '#type' => 'textarea', - '#title' => t('Ignored chars'), - '#default_value' => variable_get('searchcloud_ignored_chars', "?,!,.,~,@,#,$,%,^,&,*,(,),-,_,+,=,<,>,/,[,],{,},:,;,~,`"), - '#description' => t('Separate chars with commas, nothing else. (commas and quotes are ignored internally)'), - '#cols' => 60, - '#rows' => 2 - ); - $form['searchcloud_minimum_tag_length'] = array( - '#type' => 'textfield', - '#title' => t('Minimum tag length'), - '#default_value' => variable_get('searchcloud_minimum_tag_length', variable_get('minimum_word_size', 3)), - '#description' => t('The minimum char length of the word, for the generator to consider it.'), - '#size'=>3 - ); - $form['searchcloud_underline_links'] = array( - '#type' => 'checkbox', - '#title' => t('Underline links'), - '#default_value' => variable_get('searchcloud_underline_links', 0), - '#description' => t('Check this if you want the cloud links to appear underlined.') - ); - $form['searchcloud_tag_limit'] = array( - '#type' => 'textfield', - '#title' => t('Tag limit'), - '#default_value' => variable_get('searchcloud_tag_limit', 0), - '#description' => t('How many tags will the cloud show. "0" means no limit.'), - '#size'=>3 - ); - return system_settings_form($form); + $form['searchcloud_min_font_size'] = array( + '#type' => 'textfield', + '#title' => t('Minimum font size'), + '#default_value' => variable_get('searchcloud_min_font_size', 14), + '#description' => t('Enter the minimum font size in pixels.'), + '#size' => 2 + ); + $form['searchcloud_max_font_size'] = array( + '#type' => 'textfield', + '#title' => t('Maximum font size'), + '#default_value' => variable_get('searchcloud_max_font_size', 24), + '#description' => t('Enter the maximum font size in pixels.'), + '#size' => 2 + ); + $form['searchcloud_use_colors'] = array( + '#type' => 'checkbox', + '#title' => t('Use color tones'), + '#default_value' => variable_get('searchcloud_use_colors', 1), + '#description' => t('Check this if you want to use color tones on tags. Make sure the number of light&dark color tones is equal to the difference between maximum and minimum font size.') + ); + $form['searchcloud_light_colors'] = array( + '#type' => 'textarea', + '#title' => t('Light color tones'), + '#default_value' => variable_get('searchcloud_light_colors', "#00FFFF,#F0F8FF,#FFF0F5,#FFE4B5,#EEE8AA,#98FB98,#B0C4DE,#FF00FF,#0000CD,#FDF5E6"), + '#description' => t('Separate colors with commas, nothing else.'), + '#cols' => 60, + '#rows' => 2 + ); + $form['searchcloud_dark_colors'] = array( + '#type' => 'textarea', + '#title' => t('Dark color tones'), + '#default_value' => variable_get('searchcloud_dark_colors', "#0000FF,#FF0000,#00008B,#A52A2A,#FF00FF,#008000,#C71585,#8B4513,#008080,#2F4F4F"), + '#description' => t('Separate colors with commas, nothing else.'), + '#cols' => 60, + '#rows' => 2 + ); + $form['searchcloud_use_light_colors'] = array( + '#type' => 'checkbox', + '#title' => t('Use the light color tones'), + '#default_value' => variable_get('searchcloud_use_light_colors', 0), + '#description' => t('Check this if you want to use the light color tones on tags.') + ); + $form['searchcloud_ignored_words'] = array( + '#type' => 'textarea', + '#title' => t('Ignored words'), + '#default_value' => variable_get('searchcloud_ignored_words', "?,of,the,is,off,you,them,then,at,with,i,it,We,we"), + '#description' => t('Separate words with commas, nothing else.'), + '#cols' => 60, + '#rows' => 2 + ); + $form['searchcloud_ignored_chars'] = array( + '#type' => 'textarea', + '#title' => t('Ignored chars'), + '#default_value' => variable_get('searchcloud_ignored_chars', "?,!,.,~,@,#,$,%,^,&,*,(,),-,_,+,=,<,>,/,[,],{,},:,;,~,`"), + '#description' => t('Separate chars with commas, nothing else. (commas and quotes are ignored internally)'), + '#cols' => 60, + '#rows' => 2 + ); + $form['searchcloud_minimum_tag_length'] = array( + '#type' => 'textfield', + '#title' => t('Minimum tag length'), + '#default_value' => variable_get('searchcloud_minimum_tag_length', variable_get('minimum_word_size', 3)), + '#description' => t('The minimum char length of the word, for the generator to consider it.'), + '#size' => 3 + ); + $form['searchcloud_underline_links'] = array( + '#type' => 'checkbox', + '#title' => t('Underline links'), + '#default_value' => variable_get('searchcloud_underline_links', 0), + '#description' => t('Check this if you want the cloud links to appear underlined.') + ); + $form['searchcloud_tag_limit'] = array( + '#type' => 'textfield', + '#title' => t('Tag limit'), + '#default_value' => variable_get('searchcloud_tag_limit', 0), + '#description' => t('How many tags will the cloud show. "0" means no limit.'), + '#size' => 3 + ); + return system_settings_form($form); } /** * Implementation of hook_menu(). */ -function searchcloud_menu($may_cache) { - $items = array(); - if ($may_cache) { - // - } - else { - $items[] = array( - 'path' => 'admin/settings/searchcloud', - 'title' => t('Search Index Cloud'), - 'description' => t('Configure color tones, ignored words & chars and more.'), - 'callback' => 'drupal_get_form', - 'callback arguments' => array('searchcloud_admin_settings'), - 'access' => user_access('administer site configuration') - ); - } - return $items; +function searchcloud_menu() { + $items = array(); + $items['admin/settings/searchcloud'] = array( + 'title' => 'Search Index Cloud', + 'description' => 'Configure color tones, ignored words & chars and more.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('searchcloud_admin_settings'), + 'access arguments' => array('administer site configuration'), + ); + return $items; } /** * Implementation of hook_search(). */ function searchcloud_search($op = 'search', $keys = NULL) { - if (module_exists("search")) { - switch ($op) { - case 'name'; - //print_r(search_get_keys()); - $sSearchTerm = trim(search_get_keys()); - if (strpos($sSearchTerm, "type:") === false) { - if (!empty($sSearchTerm)) { - //check if the term exists, if not, add it, else increment its count: - $rTermCheckQuery = db_query("SELECT * FROM {searchcloud} WHERE searchcloud_term='%s'", $sSearchTerm); - if (db_num_rows($rTermCheckQuery) > 0) { - // get the count, and add 1: - $iSearchTermCount = (int)db_fetch_object($rTermCheckQuery)->searchcloud_count+1; - // update the count: - db_query("UPDATE {searchcloud} SET searchcloud_count=%d WHERE searchcloud_term='%s'", $iSearchTermCount, $sSearchTerm); - } - else { - // add the term: - if (drupal_strlen($sSearchTerm)>=variable_get('minimum_word_size', 3)) { - db_query("INSERT INTO {searchcloud} (searchcloud_term, searchcloud_count) VALUES ('%s',%d)", $sSearchTerm, 1); - } - } - } - } - break; - } - } + //drupal_set_message('searchcloud_search'); + $args = func_get_args(); + //drupal_set_message('args =
'. print_r($args, true) .''); + + if (module_exists("search")) { + switch ($op) { + case 'name'; + //print_r(search_get_keys()); + $s_search_term = trim(search_get_keys()); + if (strpos($s_search_term, "type:") === FALSE) { + if (!empty($s_search_term)) { + //check if the term exists, if not, add it, else increment its count: + $r_term_check_query = db_result(db_query("SELECT searchcloud_count FROM {searchcloud} WHERE searchcloud_term='%s'", $s_search_term)); + if ($r_term_check_query > 0) { + // get the count, and add 1: + $i_search_term_count = $r_term_check_query + 1; + // update the count: + db_query("UPDATE {searchcloud} SET searchcloud_count=%d WHERE searchcloud_term='%s'", $i_search_term_count, $s_search_term); + } + else { + // add the term: + if (drupal_strlen($s_search_term) >= variable_get('minimum_word_size', 3)) { + db_query("INSERT INTO {searchcloud} (searchcloud_term, searchcloud_count) VALUES ('%s',%d)", $s_search_term, 1); + } + } + } + } + break; + } + } } /** * Implementation of hook_block(). @@ -150,49 +149,52 @@ function searchcloud_block($op = 'list', if (module_exists("search")) { switch ($op) { case 'list': - $info[0]['info'] = t('Search Index Cloud'); - return $info; - break; - + $info[0] = array ( + 'info' => t('Search Index Cloud'), + 'cache' => BLOCK_NO_CACHE, + ); + return $info; + break; case 'view': - if (user_access("search content")) { - // get the stored terms from db: - $iTagLimit = variable_get('searchcloud_tag_limit', 0); - if ($iTagLimit > 0) { - $rTermsQuery = db_query_range("SELECT * FROM {searchcloud} ORDER BY searchcloud_count DESC", 0, $iTagLimit); - } - else { - $rTermsQuery = db_query("SELECT * FROM {searchcloud}"); - } - if (db_num_rows($rTermsQuery) > 0) { - // load the class: - require_once(drupal_get_path('module','searchcloud')."/classes/tagCloud.class.php"); - $aTerms = array(); - while ($term = db_fetch_object($rTermsQuery)) { - $aTerms[] = array( - 'term'=>$term->searchcloud_term, - 'link'=>base_path()."search/node/".urlencode($term->searchcloud_term), - 'count'=>$term->searchcloud_count + if (user_access("search content")) { + // get the stored terms from db: + $i_tag_limit = variable_get('searchcloud_tag_limit', 0); + if ($i_tag_limit > 0) { + $r_terms_query = db_query_range("SELECT * FROM {searchcloud} ORDER BY searchcloud_count DESC", 0, $i_tag_limit); + } + else { + $r_terms_query = db_query("SELECT * FROM {searchcloud}"); + } + $count = db_result(db_query('SELECT COUNT(*) AS count FROM {searchcloud}')); + if ($count > 0) { + // load the class: + require_once(drupal_get_path('module','searchcloud')."/classes/tagCloud.class.php"); + $a_terms = array(); + while ($term = db_fetch_object($r_terms_query)) { + $a_terms[] = array( + 'term' => $term->searchcloud_term, + 'link' => base_path() ."search/node/". urlencode($term->searchcloud_term), + 'count' => $term->searchcloud_count ); } // initialize the class: - $tagCloud = new tagCloud(); + $tag_cloud = new tagCloud(); // set params: - $tagCloud->options['minimum_tag_length'] = variable_get('searchcloud_minimum_tag_length', 3); - $tagCloud->options['underline_links'] = variable_get('searchcloud_underline_links', 0); - $tagCloud->options['use_light_colors'] = variable_get('searchcloud_use_light_colors', 0); - $tagCloud->options['min_font_size'] = variable_get('searchcloud_min_font_size', 14); - $tagCloud->options['max_font_size'] = variable_get('searchcloud_max_font_size', 24); - $tagCloud->options['use_colors'] = variable_get('searchcloud_use_colors', 1); - $tagCloud->options['light_colors'] = variable_get('searchcloud_light_colors', "#00FFFF,#F0F8FF,#FFF0F5,#FFE4B5,#EEE8AA,#98FB98,#B0C4DE,#FF00FF,#0000CD,#FDF5E6"); - $tagCloud->options['dark_colors'] = variable_get('searchcloud_dark_colors', "#0000FF,#FF0000,#00008B,#A52A2A,#FF00FF,#008000,#C71585,#8B4513,#008080,#2F4F4F"); - $tagCloud->options['ignored_words'] = variable_get('searchcloud_ignored_words', "?,of,the,is,off,you,them,then,at,with,i,it,We,we"); - $tagCloud->options['ignored_chars'] = variable_get('searchcloud_ignored_chars', "?,!,.,~,@,#,$,%,^,&,*,(,),-,_,+,=,<,>,/,[,],{,},:,;,~,`"); + $tag_cloud->options['minimum_tag_length'] = variable_get('searchcloud_minimum_tag_length', 3); + $tag_cloud->options['underline_links'] = variable_get('searchcloud_underline_links', 0); + $tag_cloud->options['use_light_colors'] = variable_get('searchcloud_use_light_colors', 0); + $tag_cloud->options['min_font_size'] = variable_get('searchcloud_min_font_size', 14); + $tag_cloud->options['max_font_size'] = variable_get('searchcloud_max_font_size', 24); + $tag_cloud->options['use_colors'] = variable_get('searchcloud_use_colors', 1); + $tag_cloud->options['light_colors'] = variable_get('searchcloud_light_colors', "#00FFFF,#F0F8FF,#FFF0F5,#FFE4B5,#EEE8AA,#98FB98,#B0C4DE,#FF00FF,#0000CD,#FDF5E6"); + $tag_cloud->options['dark_colors'] = variable_get('searchcloud_dark_colors', "#0000FF,#FF0000,#00008B,#A52A2A,#FF00FF,#008000,#C71585,#8B4513,#008080,#2F4F4F"); + $tag_cloud->options['ignored_words'] = variable_get('searchcloud_ignored_words', "?,of,the,is,off,you,them,then,at,with,i,it,We,we"); + $tag_cloud->options['ignored_chars'] = variable_get('searchcloud_ignored_chars', "?,!,.,~,@,#,$,%,^,&,*,(,),-,_,+,=,<,>,/,[,],{,},:,;,~,`"); // load the terms: - $tagCloud->loadTerms($aTerms); + $tag_cloud->loadTerms($a_terms); $block['subject'] = t('Search Cloud'); //$block['content'] = "
".print_r($aTerms, true).""; - $block['content'] = $tagCloud->getCloud(); + $block['content'] = $tag_cloud->getCloud(); return $block; } }