? comments_hack_hack_hack.patch Index: api.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/api/api.install,v retrieving revision 1.11.2.1 diff -u -p -r1.11.2.1 api.install --- api.install 28 Jan 2009 20:52:26 -0000 1.11.2.1 +++ api.install 19 Apr 2009 07:11:15 -0000 @@ -16,7 +16,7 @@ function api_schema() { ); $schema['api_documentation'] = array( 'fields' => array( - 'did' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), + 'did' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), 'object_name' => array('type' => 'varchar', 'length' => '127', 'not null' => TRUE, 'default' => ''), 'branch_name' => array('type' => 'varchar', 'length' => '31', 'not null' => TRUE, 'default' => ''), 'object_type' => array('type' => 'varchar', 'length' => '31', 'not null' => TRUE, 'default' => ''), @@ -73,6 +73,7 @@ function api_schema() { function api_install() { drupal_install_schema('api'); + variable_set('comment_preview_api', COMMENT_PREVIEW_OPTIONAL); } function api_update_1() { @@ -263,6 +264,12 @@ function api_update_13() { return $return; } +function api_update_14() { + // Force re-index. + $ret[] = update_sql("DELETE FROM {api_documentation}"; + return $ret; +} + function api_uninstall() { drupal_uninstall_schema('api'); variable_del('api_default_branch'); @@ -270,4 +277,5 @@ function api_uninstall() { variable_del('api_php_funcpath'); variable_del('api_files_per_cron'); variable_del('api_reference'); + db_query("DELETE FROM {node} WHERE type = 'api'"); } Index: api.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/api/api.module,v retrieving revision 1.88.2.4 diff -u -p -r1.88.2.4 api.module --- api.module 29 Jan 2009 06:00:05 -0000 1.88.2.4 +++ api.module 19 Apr 2009 07:11:16 -0000 @@ -574,6 +574,16 @@ function api_theme() { function api_init() { drupal_add_css(drupal_get_path('module', 'api') .'/api.css'); drupal_add_js(drupal_get_path('module', 'api') .'/api.js'); + if (($node = menu_get_object()) && $node->type == 'api') { + $documentation = db_fetch_object(db_query('SELECT * FROM {api_documentation} WHERE did = %d', $node->nid)); + drupal_goto("api/$documentation->object_type/$documentation->object_name/$documentation->branch_name"); + } +} + +function api_db_rewrite_sql($query, $primary_table, $primary_field) { + if ($primary_table == 'n' && $primary_field == 'nid') { + return array('where' => "type <> 'api'"); + } } function api_block($op, $delta = NULL, $edit = array()) { @@ -988,7 +998,9 @@ function api_page_function($function) { $call = theme('api_expandable', '

'. api_show_l('▸ '. $call_title) .'

', '

'. api_hide_l('▾ '. $call_title) .'

'. theme('api_functions', $call_functions)); } - return theme('api_function_page', $function, $signatures, $documentation, $parameters, $return, $related_topics, $call, $code); + $output = theme('api_function_page', $function, $signatures, $documentation, $parameters, $return, $related_topics, $call, $code); + $output .= _api_add_comments($function); + return $output; } /** @@ -1001,7 +1013,9 @@ function api_page_constant($constant) { $code = api_link_code($constant->code, $constant->branch_name); $related_topics = api_related_topics($constant->did, $constant->branch_name); - return theme('api_constant_page', $constant, $documentation, $code, $related_topics); + $output = theme('api_constant_page', $constant, $documentation, $code, $related_topics); + $output .= _api_add_comments($constant); + return $output; } /** @@ -1014,7 +1028,9 @@ function api_page_global($global) { $related_topics = api_related_topics($global->did, $global->branch_name); $code = api_link_code($global->code, $global->branch_name); - return theme('api_global_page', $global, $documentation, $code, $related_topics); + $output = theme('api_global_page', $global, $documentation, $code, $related_topics); + $output .= _api_add_comments($global); + return $output; } /** @@ -1056,6 +1072,12 @@ function api_page_file($file) { return theme('api_file_page', $file, $documentation, $constants, $globals, $functions); } +function _api_add_comments($documentation_object) { + $output = comment_render(node_load($documentation_object->did)); + $output .= comment_form_box(array('nid' => $documentation_object->did), t('Post new comment')); + return $output; +} + /** * Menu callback; displays source code for a file. */ Index: parser.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/api/parser.inc,v retrieving revision 1.41.2.1 diff -u -p -r1.41.2.1 parser.inc --- parser.inc 28 Jan 2009 21:35:50 -0000 1.41.2.1 +++ parser.inc 19 Apr 2009 07:11:16 -0000 @@ -429,8 +429,13 @@ function api_save_documentation($docbloc db_query("UPDATE {api_documentation} SET title = '%s', file_name = '%s', summary = '%s', documentation = '%s', code = '%s' WHERE did = %d", $docblock['title'], $docblock['file_name'], $docblock['summary'], $docblock['documentation'], $docblock['code'], $did); } else { - db_query("INSERT INTO {api_documentation} (object_name, branch_name, object_type, title, file_name, summary, documentation, code) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", $docblock['object_name'], $docblock['branch_name'], $docblock['object_type'], $docblock['title'], $docblock['file_name'], $docblock['summary'], $docblock['documentation'], $docblock['code']); - $did = db_last_insert_id('api_documentation', 'did'); + $node = new stdClass(); + $node->type = 'api'; + $node->uid = 0; + $node->comment = COMMENT_NODE_READ_WRITE; + node_save($node); + $did = $node->nid; + db_query("INSERT INTO {api_documentation} (did, object_name, branch_name, object_type, title, file_name, summary, documentation, code) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", $did, $docblock['object_name'], $docblock['branch_name'], $docblock['object_type'], $docblock['title'], $docblock['file_name'], $docblock['summary'], $docblock['documentation'], $docblock['code']); } switch ($docblock['object_type']) { @@ -760,12 +765,12 @@ function api_update_branch($branch) { $files = array(); $result = db_query("SELECT f.did, f.modified, d.object_name FROM {api_documentation} d INNER JOIN {api_file} f ON d.did = f.did WHERE d.branch_name = '%s' AND d.object_type = 'file'", $branch->branch_name); while ($file = db_fetch_object($result)) { - $files[$file->object_name] = $file; + $files[$file->object_name] = $file; } foreach (api_scan_directories($branch->directory) as $path => $file_name) { preg_match('!\.([a-z]*)$!', $file_name, $matches); - if (isset($parse_functions[$matches[1]])) { + if (isset($matches[1]) && isset($parse_functions[$matches[1]])) { if (isset($files[$file_name])) { $parse = (filemtime($path) > $files[$file_name]->modified); unset($files[$file_name]); // All remaining files will be removed.