diff --git a/Source/Source.FilterAPI.php b/Source/Source.FilterAPI.php
new file mode 100644
index 0000000..1a0dba8
--- /dev/null
+++ b/Source/Source.FilterAPI.php
@@ -0,0 +1,189 @@
+ 0 ) {
+ $this->how = $args[0];
+ }
+
+ if ( $count == 2 ) {
+ $this->value = $args[1];
+ }
+ else if ( $count > 2 ) {
+ $this->value = array_slice( $args, 1 );
+ }
+ }
+}
+
+class SourceFilter {
+ var $filters;
+
+ function __construct( $init = true ) {
+ if ( $init ) {
+ $this->filters['c.author'] = new SourceFilterOption();
+ $this->filters['c.message'] = new SourceFilterOption();
+ $this->filters['c.repo_id'] = new SourceFilterOption();
+ $this->filters['r.type'] = new SourceFilterOption();
+ $this->filters['b.bug_id'] = new SourceFilterOption();
+ $this->filters['f.filename'] = new SourceFilterOption();
+ }
+ }
+
+ function find( $p_page=1, $p_limit=25 ) {
+ list( $t_filters, $t_filter_params ) = twomap( 'Source_Process_FilterOption', $this->filters );
+ list ( $t_query_tail, $t_params ) = Source_Process_Filters( $t_filters, $t_filter_params );
+
+ $t_count_query = "SELECT COUNT(c.id) $t_query_tail";
+ $t_full_query = "SELECT c.* $t_query_tail";
+
+ $t_count = db_result( db_query_bound( $t_count_query, $t_params ) );
+
+ if ( is_null( $p_page ) ) {
+ $t_result = db_query_bound( $t_full_query, $t_params );
+ } else {
+ $t_result = db_query_bound( $t_full_query, $t_params, $p_limit, ( $p_page - 1 ) * $p_limit );
+ }
+
+ $t_changesets = array();
+ while( $t_row = db_fetch_array( $t_result ) ) {
+ $t_changeset = new SourceChangeset( $t_row['repo_id'], $t_row['revision'], $t_row['branch'],
+ $t_row['timestamp'], $t_row['author'], $t_row['message'], $t_row['user_id'] );
+ $t_changeset->id = $t_row['id'];
+
+ $t_changesets[] = $t_changeset;
+ }
+
+ return array( $t_changesets, $t_count );
+ }
+}
+
+function Source_Process_Filters( $p_filters, $p_filter_params ) {
+ $t_changeset_table = plugin_table( 'changeset', 'Source' );
+ $t_repo_table = plugin_table( 'repository', 'Source' );
+ $t_bug_table = plugin_table( 'bug', 'Source' );
+ $t_file_table = plugin_table( 'file', 'Source' );
+
+ $t_join_file_table = false;
+ $t_join_bug_table = false;
+
+ $t_where = array();
+ $t_params = array();
+
+ foreach( $p_filters as $key => $value ) {
+ if ( is_null( $value ) ) {
+ continue;
+ }
+
+ $t_table = substr( $key, 0, 1 );
+ switch( $t_table ) {
+ case 'b':
+ $t_join_bug_table = true;
+ break;
+ case 'f':
+ $t_join_file_table = true;
+ break;
+ }
+
+ $t_where[] = $value;
+
+ if ( is_array( $p_filter_params[$key] ) ) {
+ $t_params = array_merge( $t_params, $p_filter_params[$key] );
+ } else {
+ $t_params[] = $p_filter_params[$key];
+ }
+ }
+
+ $t_join = "FROM $t_changeset_table AS c LEFT JOIN $t_repo_table AS r ON c.repo_id=r.id" .
+ ( $t_join_bug_table ? ' LEFT JOIN $t_bug_table AS b ON c.id=b.change_id' : '' ) .
+ ( $t_join_file_table ? ' LEFT JOIN $t_file_table AS f ON c.id=f.change_id' : '' );
+
+ if ( count( $t_where ) > 0 ) {
+ $t_where = 'WHERE ' . implode( ' AND ', $t_where );
+ }
+
+ $t_order = 'ORDER BY c.timestamp DESC';
+
+ return array( "$t_join $t_where $t_order", $t_params );
+}
+
+function Source_Process_FilterOption( $key, $option ) {
+ if ( !is_a( $option, 'SourceFilterOption' ) ) {
+ return null;
+ } else {
+ $how = $option->how;
+ $var = $option->value;
+ }
+
+ if ( is_null( $var ) ) {
+ return array( null, null );
+ }
+
+ $value = null;
+ $text = false;
+
+ if ( in_array( $key, array( 'c.author', 'c.message', 'c.revision',
+ 'c.branch', 'f.filename', 'f.revision' ) ) ) {
+ $text = true;
+
+ if ( !is_array( $var ) ) {
+ $var = explode( ' ', $var );
+ }
+
+ $wc = map( 'db_aparam', $var );
+ $wc = map( create_function( '$item','return "' . $key . ' LIKE $item";' ), $wc );
+ $var = map( create_function( '$item', 'return "%$item%";' ), $var );
+
+ $value = '(' . implode( ' OR ', $wc ) . ')';
+
+ return array( $value, $var );
+ }
+
+ if ( is_array( $var ) ) {
+ $wc = map( 'db_aparam', $var );
+
+ if ( count( $var ) > 1 ) {
+ if ( SOURCE_ANY == $how ) {
+ $value = $key . ' IN (' . implode( ',', $wc ) . ')';
+ } else {
+ $value = $key . ' NOT IN (' . implode( ',', $wc ) . ')';
+ }
+ } else {
+ if ( SOURCE_ANY == $how ) {
+ $value = "$key = $wc";
+ } else {
+ $value = "$key != $wc";
+ }
+ }
+ } else {
+ $wc = db_aparam();
+
+ if ( SOURCE_ANY == $how ) {
+ $value = "$key = $wc";
+ } else {
+ $value = "$key != $wc";
+ }
+ }
+
+ return array( $value, $var );
+}
+
diff --git a/Source/pages/search.php b/Source/pages/search.php
index cc8156a..c5831cb 100644
--- a/Source/pages/search.php
+++ b/Source/pages/search.php
@@ -13,15 +13,97 @@
access_ensure_global_level( plugin_config_get( 'view_threshold' ) );
+$f_offset = gpc_get_int( 'offset', 1 );
+$f_perpage = 25;
+
html_page_top1( plugin_lang_get( 'title' ) );
html_page_top2();
+
+require_once( config_get( 'plugin_path' ) . 'Source' . DIRECTORY_SEPARATOR . 'Source.FilterAPI.php' );
+
+$t_filter = new SourceFilter();
+
+$t_filter->filters['c.author']->value = "jreese";
+$t_filter->filters['c.message']->value = "test";
+
+list( $t_changesets, $t_count ) = $t_filter->find( $f_offset );
+$t_repos = SourceRepo::load_by_changesets( $t_changesets );
+
?>
-
+ | + | |
+ name ), ' ', event_signal( 'EVENT_SOURCE_SHOW_CHANGESET', array( $t_repo, $t_changeset ) ) ?> + timestamp ?> + author ?> + |
+message ) ?> | +|
+ | + + + | +|
+
+ $f_perpage ) {
+ $t_page = 1;
+ while( $t_count > 0 ) {
+ if ( $t_page > 1 && $t_page % 15 != 1 ) {
+ echo ', ';
+ }
+
+ if ( $t_page == $f_offset ) {
+ echo " $t_page";
+ } else {
+ echo ' ', $t_page, '';
+ }
+
+ if ( $t_page % 15 == 0 ) {
+ echo ' '; + } + + $t_count -= $f_perpage; + $t_page ++; + } +} +?> + |