diff -ur api.admin.inc api.admin.inc --- api.admin.inc 2009-01-28 22:24:01.000000000 +0100 +++ api.admin.inc 2009-03-18 19:39:23.000000000 +0100 @@ -75,6 +75,7 @@ $branch->branch_name = ''; $branch->title = ''; $branch->directory = ''; + $branch->exclude_dirs = ''; } else { $branch = $branches[$branch_name]; @@ -101,6 +102,13 @@ '#description' => t('Absolute paths to index, one per line.'), '#required' => TRUE, ); + $form['exclude_dirs'] = array( + '#title' => t('Excluded directories'), + '#type' => 'textarea', + '#default_value' => $branch->exclude_dirs, + '#rows' => 3, + '#description' => t('Absolute paths to exclude from the index, one per line.'), + ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Save branch'), @@ -139,12 +147,23 @@ form_set_error('directory', t('%directory is not readable by PHP.', array('%directory' => $directory))); } } + // Check for valid excluded directories. + foreach (explode("\n", $form_state['values']['exclude_dirs']) as $directory) { + $directory = trim($directory); + if (!is_dir($directory)) { + form_set_error('exclude_dirs', t('%directory is not a directory.', array('%directory' => $directory))); + } + elseif (!is_readable($directory)) { + form_set_error('exclude_dirs', t('%directory is not readable by PHP.', array('%directory' => $directory))); + } + } } function api_branch_edit_form_submit($form, &$form_state) { $branch->branch_name = $form_state['values']['branch_name']; $branch->title = $form_state['values']['title']; $branch->directory = $form_state['values']['directory']; + $branch->exclude_dirs = $form_state['values']['exclude_dirs']; api_save_branch($branch, $form['branch_name']['#default_value']); diff -ur api.install api.install --- api.install 2009-01-28 21:52:26.000000000 +0100 +++ api.install 2009-03-18 19:39:59.000000000 +0100 @@ -8,6 +8,7 @@ 'title' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''), 'directory' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''), 'weight' => array('type' => 'int', 'unsigned' => TRUE, 'size' => 'tiny', 'not null' => TRUE, 'default' => 0), + 'exclude_dirs' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''), ), 'primary key' => array('branch_name'), 'indexes' => array( @@ -262,6 +263,22 @@ return $return; } + +/** + * Add exclude_dirs column. + */ +function api_update_14() { + $return = array(); + + db_add_field($return, 'api_branch', 'exclude_dirs', array( + 'type' => 'varchar', + 'length' => '255', + 'not null' => TRUE, + 'default' => '', + )); + + return $return; +} function api_uninstall() { drupal_uninstall_schema('api'); diff -ur api.module api.module --- api.module 2009-01-28 22:05:03.000000000 +0100 +++ api.module 2009-03-18 19:40:31.000000000 +0100 @@ -93,7 +93,7 @@ static $branches; if (!isset($branches) || $_reset) { - $result = db_query('SELECT branch_name, title, directory FROM {api_branch} ORDER BY weight'); + $result = db_query('SELECT branch_name, title, directory, exclude_dirs FROM {api_branch} ORDER BY weight'); $branches = array(); while ($branch = db_fetch_object($result)) { $branches[$branch->branch_name] = $branch; diff -ur parser.inc parser.inc --- parser.inc 2009-01-28 22:35:50.000000000 +0100 +++ parser.inc 2009-03-18 19:46:40.000000000 +0100 @@ -763,7 +763,7 @@ $files[$file->object_name] = $file; } - foreach (api_scan_directories($branch->directory) as $path => $file_name) { + foreach (api_scan_directories($branch->directory, $branch->exclude_dirs) as $path => $file_name) { preg_match('!\.([a-z]*)$!', $file_name, $matches); if (isset($parse_functions[$matches[1]])) { if (isset($files[$file_name])) { @@ -796,10 +796,14 @@ /** * Find all the files in the directories specified for a branch. */ -function api_scan_directories($directories) { +function api_scan_directories($directories, $exclude_dirs) { $directory_array = explode("\n", $directories); foreach ($directory_array as $key => $directory) { - $directory_array[$key] = trim($directory); + $directory_array[$key] = rtrim(trim($directory), '/'); + } + $excluded_array = explode("\n", $exclude_dirs); + foreach ($excluded_array as $key => $directory) { + $excluded_array[$key] = rtrim(trim($directory), '/'); } if (count($directory_array) > 1) { @@ -829,9 +833,18 @@ if (strpos($path, '/.') !== FALSE) { continue; } - $file_name = substr($path, strlen($common_ancestor) + 1); + $excluded = FALSE; + // If the file is in an excluded path, ignore it + foreach ($excluded_array as $excluded_path) { + if (!empty($excluded_path) && (strpos($path, $excluded_path) === 0)) { + $excluded = TRUE; + } + } + if (!$excluded) { + $file_name = substr($path, strlen($common_ancestor) + 1); - $source_files[$path] = $file_name; + $source_files[$path] = $file_name; + } } } return $source_files;